LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Question on mmap() to rollback to previous contents (https://www.linuxquestions.org/questions/programming-9/question-on-mmap-to-rollback-to-previous-contents-4175458620/)

polisetty_ram 04-18-2013 07:03 AM

Question on mmap() to rollback to previous contents
 
Hi,

My requirement is, when I get a signal from a process, my process should load a file using mmap() and update its data/contents and waits for further signals. After some-time I will get another signal from that process saying either proceed further or discard the previously made changes.

Initially I wanted to use MAP_PRIVATE, but if I load a region with MAP_PRIVATE the contents are never written to underlying disk.

MS_INVALIDATE never discards the contents loaded with MAP_SHARED.

So my requirement is if I get a failure message from that process after updating my mmap region contents, I should be able to rollback to previous contents.


Any help on this would be highly appreciated.

ntubski 04-20-2013 08:18 AM

Quote:

Originally Posted by polisetty_ram (Post 4933970)
MS_INVALIDATE never discards the contents loaded with MAP_SHARED.

That's not what MS_INVALIDATE is for, msync(2):
Quote:

MS_INVALIDATE asks to invalidate other mappings of the same file (so that they can be updated with the fresh values just written).
To make changes to a file atomically you should write the new version to a temp file, and then rename it over the original when you commit (or delete the temp if you abort). It doesn't really matter whether you write the file with mmap() or write().

bigearsbilly 04-20-2013 10:21 AM

agreed.
mmap does not confer any performance advantage in practice.
keep it simple.


All times are GMT -5. The time now is 10:53 AM.