[lug] shmem/mmap/HUGETLB question

Jonathan Corbet corbet-bldrlug at lwn.net
Sat Oct 15 18:12:24 MDT 2011

On Sat, 15 Oct 2011 15:36:13 -0600
"Doug Pintar" <ratnip3 at gmail.com> wrote:

> My question  is, is  there any way  to keep  the system from  marking the
> pages mapped to the output file as new and just keep the data around that
> had already  been loaded  into them  from the input  file? It  seems this
> would be a great way to  copy stuff with no memory-memory data copying at
> all, and should be slicker than, as they say, owl shit.

madvise() will clear the young bit and put the pages onto the active list.
But... trying to outsmart the page cache in this way is just never going to
lead to great joy; you're trying to out-optimize some of the most heavily
optimized code in the whole system.  Basic streaming I/O is a pretty common
use case, after all.

If you're having performance problems, it is almost certainly at a lower
level.  Which filesystem are you using on each side?  Are there a lot of
seeks going on?  Are your disks reasonable, and are you getting a whole lot
worse bandwidth than hdparm tells you is possible?  Is the CPU pegged?  If
not, no amount of MM trickery will help you.  Run iostat and see if one
drive is far busier than the other.  You will almost certainly find that
your problem is not copying pages.

But, should I be wrong and you *really* think you need to do zerocopy file
copies, have a look at the splice() system call.


More information about the LUG mailing list