[lkml]   [2003]   [Mar]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Subjectmmap(.., .., PROT_READ, MAP_PRIVATE, .., ..) functionality question
Please email me directly (or CC me) since I am not subscribed to the mail

I have a question on the functionality of mmap() when used with PROT_READ,
and MAP_PRIVATE flag.

Currently I am reading in the entire contents of a file into memory and
processing it thru "zlib" compression library. In order to create RFC1952
compatible data the file's contents has to be read once by the compression
routine and once by the checksum routine. "zlib" provides a simple
implementation where it uses mmap() to map the file into memory and passes
that address off to the two routines. This brings up my design
consideration and thus my question.

Doesn't mmap(), mind you with PROT_READ and MAP_PRIVATE, first copy the
contents of the file into the swap space and then when the data is accessed
into physical RAM before the CPU can get to it? If so, in essence wouldn't
I be doubling the disk access time??? I have found numerous messages
talking about mmap() but only with read/write considerations.

I'm trying to decide whether or not using read() to copy the contents into
system memory (heavy on the physical memory) is worth the sacrifice of
having the extra disk access (light on the physical memory). So how does
mmap() handle the mapped file?

Imagine for a moment it does not first copy the file contents to swap space.
The fact that I would need to read the data twice, once for each function;
wouldn't the memory access to the file contents cause mmap() to access the
file twice from the hard drive be a draw back or does it somehow cache it in
memory after the first access? If it did cache it, is it going to cache it
on the swap partition or in memory?

I list a few links that I found references to mmap() discussions, that of
course didn't specifically answer my question.

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

 \ /
  Last update: 2005-03-22 13:33    [W:0.024 / U:3.360 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site