msync() more expensive than fsync()?

Chris Friesen (cfriesen@nortelnetworks.com)
Tue, 08 Apr 2003 12:37:58 -0400


I have some code that runs on a ramdisk-based filesystem. Through a special
device it mmaps a section of memory that is persistant over reboots, to be used
for logging. In order to guarantee that the logs were flushed to the memory
area, I assume that I need to use some kind of sync operation. This is where
things get a bit odd.

I did some testing with relatively small messages, 50 bytes or so, with results
as follows:

Without any explicit flushing it takes 8 usec to log a message.

If I msync() only the pages that were touched in writing (usually 3 pages) it
takes 39 usecs to log a message.

If I fsync() the entire file (200KB) it takes 12 usec to log a message.

Why the additional cost for msync()? I would have thought it would be faster
since it is explicitely for mmapped memory areas. As a side note, the
difference is even more extreme if a file is used on a disk-backed filesystem.

The kernel was 2.4.18.

Chris

-- 
Chris Friesen                    | MailStop: 043/33/F10
Nortel Networks                  | work: (613) 765-0557
3500 Carling Avenue              | fax:  (613) 765-2986
Nepean, ON K2H 8E9 Canada        | email: cfriesen@nortelnetworks.com

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/