RE: Shared mmap and data consistency upon a crash
RE: Shared mmap and data consistency upon a crash
- Subject: RE: Shared mmap and data consistency upon a crash
- From: "Sanjay Mishra" <email@hidden>
- Date: Wed, 10 May 2006 14:45:55 +0530
- Thread-topic: Shared mmap and data consistency upon a crash
Hi Felix,
You need to msync() to get your data into your file soon after you
changed the data in the shared file. You have to certainly do it before
the point where you assume probable crash lurks.
--Sanjay
-----Original Message-----
From: darwin-dev-bounces+samishra=email@hidden
[mailto:darwin-dev-bounces+samishra=email@hidden] On Behalf
Of Felix Schwarz
Sent: Wednesday, May 10, 2006 2:32 PM
To: email@hidden
Subject: Shared mmap and data consistency upon a crash
Hello,
I am currently exploring the possibilites to use mmap to speed up some
of my most critical I/O, but am wondering about the reliability of mmap
and the durability of changes made to a file this way for one particular
edge case:
If
1) I mmap() a file using MAP_SHARED, PROT_READ and PROT_WRITE
2) I write into the returned address space
3) my app crashes prior to reaching munmap() and close()
Pseudocode:
// mmap file (1)
p_m = fopen(..)
mptr = mmap(..p_m..)
// Modify the file (2)
*mptr = 0xBEEF;
// Crash here (3)
*((int *) 0) = 1;
// Memory would have been unmapped and the corresponding file
closed here
// However, this shall not be reached in this example
munmap();
fclose(p_m);
Will the data written in 2) actually show up in the file?
Does mmap() take care that mapped memory and the file it is mapped to
are synced in the event of a crash?
Felix
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden