Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 28 Oct 1997 03:06:45 -0800
From:      Don Lewis <Don.Lewis@tsc.tdk.com>
To:        Dave Andersen <angio@angio.net>, Alfred Perlstein <perlsta@cs.sunyit.edu>
Cc:        hackers@FreeBSD.ORG
Subject:   Re: help with fstat?
Message-ID:  <199710281106.DAA25277@salsa.gv.tsc.tdk.com>
In-Reply-To: Dave Andersen <angio@angio.net> "Re: help with fstat?" (Oct 26,  7:58pm)

next in thread | previous in thread | raw e-mail | index | archive | help
On Oct 26,  7:58pm, Dave Andersen wrote:
} Subject: Re: help with fstat?
} > i don't want to exhaust the virtual memory on the machine, just get
} > optimal transfers.
} 
}    mmap will give you optimal transfers since you won't have the
} additional overhead of additional memory copies inside your machine.

Actually it really depends on the OS.  There's no reason the OS can't
avoid memory to memory copies when reading a file if you use a page
aligned buffer and read multiples of the page size.  The kernel can just
fiddle with the page table for the process to map pages from the buffer
cache into the user space with the copy-on-write flag set.  If the kernel
is smart enough to detect that the process is doing sequential reads and
the process is consuming the data more slowly that it can be read from
disk, it may be possible for the kernel to perform readahead so that it
always has the next chunk of data from the file loaded into the buffer
cache before the process asks for it so that the process never blocks
waiting for the disk.  One variation I've seen DMAs data directly from
the disk into user space on large enough requests, bypassing the buffer
cache.  Another doesn't actually copy the data into user space during
the read() call, but page faults it in as the buffer is accessed.

If you mmap the file, the process may block each time a new page is
accessed to allow that page to be faulted in from the disk.  Of course
the kernel may still be able to do readahead to avoid blocking the
process if the kernel is able to detect that the process is accessing
the pages sequentually.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199710281106.DAA25277>