LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-18-2013, 07:03 AM   #1
polisetty_ram
LQ Newbie
 
Registered: Apr 2013
Posts: 1

Rep: Reputation: Disabled
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.
 
Old 04-20-2013, 08:18 AM   #2
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,784

Rep: Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083
Quote:
Originally Posted by polisetty_ram View Post
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().
 
Old 04-20-2013, 10:21 AM   #3
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
agreed.
mmap does not confer any performance advantage in practice.
keep it simple.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
mmap question Manjunath1847 Linux - General 2 01-20-2011 08:33 AM
[SOLVED] How to save the output to a log file without wiping the previous contents greatcz Linux - Newbie 2 07-25-2010 10:14 AM
Question on using mmap to access physical memory Gnu2Linux2 Linux - Embedded & Single-board computer 1 10-05-2009 03:54 AM
rsync question - rollback to backup? Evil Otto Linux - Server 2 08-24-2006 01:08 PM
Newbie question about usage of mmap justin8086 Linux - Hardware 1 11-22-2005 01:10 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:54 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration