Swap
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 1 line
I bet they're getting mmap()d, like all mp3 programs seem to do
Just a note here - I see much fewer buffer underruns and more consistent read-ahead/drop-behind behavior (i.e. no paging of other programs) when using plain read(), as opposed to mmap(). This is in a video playback program that pumps 3.6MB/sec!
MP3 datarates are less than 50KB/sec, so I don't really see why they stand to benefit from mmap()... With mmap() you pay the extra cost of setting up/tearing down the mapping, and the kernel->user copy is virtually insignificant anyway (you already are paying for a single copy plus cache pollution when moving the data from filesystem buffer to sound card DMA buffer, so a second copy isn't a big deal)...
Regards,
Dan
Quoted 5 lines · Dan Maas
Quoted 1 line
I bet they're getting mmap()d, like all mp3 programs seem to do
Just a note here - I see much fewer buffer underruns and more consistent read-ahead/drop-behind behavior (i.e. no paging of other programs) when using plain
read(), as opposed tommap().
Consider this a VM bug, mmap() really should be more efficient.
regards,
Rik
Signature · 3 lines
Shortwave goes a long way: irc.starchat.net #swl http://www.surriel.com/ http://distro.conectiva.com/
From: Rik van Riel <[email protected]>
Date: Tue, 20 Nov 2001 20:05:05 -0200 (BRST)
Consider this a VM bug, mmap() really should be more efficient.
read() is always going to be faster until mmap() can use large page mappings for the user. This is why mmap() is slower.
Even if the whole thing is cached in memory, read() will always be faster.
Quoted 8 lines · David S. Miller
From: Rik van Riel <[email protected]>
Date: Tue, 20 Nov 2001 20:05:05 -0200 (BRST)Consider this a VM bug,
mmap()really should be more efficient.
read()is always going to be faster untilmmap()can use large page mappings for the user. This is whymmap()is slower.
Uhhhh, read his original mail. When using mmap() he had problems with the VM doing bad page replacement, while read() was smooth.
Rik
Signature · 3 lines
Shortwave goes a long way: irc.starchat.net #swl http://www.surriel.com/ http://distro.conectiva.com/
Quoted 3 lines
Uhhhh, read his original mail. When using
mmap()he had problems with the VM doing bad page replacement, whileread()was smooth.
I should add that I did experiment with madvise(MADV_SEQUENTIAL) on the mapping, and with madvise(MADV_WILLNEED) on pages about to be needed. These had no effect. What *did* help with underruns was pre-touching each page in a large block (120KB), before sending that block to the output device. At that point I thought the mmap() code was getting to be more complicated that it was worth so I just dropped back to read()...
The other day I recorded and played a seven-minute animation (1.6GB) on my 512MB machine, with only 240KB of buffering. Much to my surprise and delight, there were no underruns, and the large sequential passes through the file hadn't pushed anything else out of RAM.
BTW, all of the above pertains to one large mapping of the entire file to be played. I didn't try mmap()/munmap() on a sliding window... I seem to remember an MP3 player doing that. (I just tried looking at XMMS and Freeamp - I *think* they are using read(), but strace seems to do bad things with threaded programs, argh...)
Regards,
Dan
Quoted 11 lines · Dan Maas
Quoted 4 lines
Uhhhh, read his original mail. When using
mmap()he had problems with the VM doing bad page replacement, whileread()was smooth.I should add that I did experiment with
madvise(MADV_SEQUENTIAL)on the mapping, and withmadvise(MADV_WILLNEED)on pages about to be needed. These had no effect. What *did* help with underruns was pre-touching each page in a large block (120KB), before sending that block to the output device. At that point I thought themmap()code was getting to be more complicated that it was worth so I just dropped back toread()...
There's a new system call, sys_readahead() which does what you want.
It would be nice to make the pagein code smarter though.
-
Quoted 4 lines
(I just tried looking at XMMS and Freeamp - I *think* they are using
read(), but strace seems to do bad things with threaded programs, argh...)
You are right about XMMS, it uses read(). I'm not sure about Freeamp.
Signature · 1 line
Håvard Kvålen
Quoted 5 lines · Håvard Kvålen
Quoted 3 lines
(I just tried looking at XMMS and Freeamp - I *think* they are using
read(), but strace seems to do bad things with threaded programs, argh...)You are right about XMMS, it uses
read(). I'm not sure about Freeamp.
When I was hacking on mpg123, it was using mmap by default unless it was unable to mmap the file (e.g. stdin) where it uses read. You could turn this off at compile time, so it only uses read. I found that to work better on low memory machines.
Cheers, Andreas
--
Andreas Dilger
http://sourceforge.net/projects/ext2resize/
http://www-mddsp.enel.ucalgary.ca/People/adilger/
Quoted 4 lines · David S. Miller
From: Rik van Riel <[email protected]>
Date: Tue, 20 Nov 2001 20:05:05 -0200 (BRST)
Quoted 8 lines
Consider this a VM bug,
mmap()really should be more efficient.
read()is always going to be faster untilmmap()can use large page mappings for the user. This is whymmap()is slower.Even if the whole thing is cached in memory,
read()will always be faster.
Could you please explain further? What's more expensive than the copy?
From: Andrew Morton <[email protected]>
Date: Tue, 20 Nov 2001 14:23:38 -0800
Could you please explain further? What's more expensive than the copy?
TLB misses add to the cost, and this overhead is more than "noise".
The Apache guys were playing with using mmap() for page contents and it was always slower than read() into a static buffer.
Quoted 8 lines · David S. Miller
From: Andrew Morton <[email protected]>
Date: Tue, 20 Nov 2001 14:23:38 -0800Could you please explain further? What's more expensive than the copy?
TLB misses add to the cost, and this overhead is more than "noise".
Well, this could have something to do with the fact that our page fault handler only maps in _1_ page at a time, so we're trapping into the pagefault handler every 4kB...
Rik
Signature · 3 lines
Shortwave goes a long way: irc.starchat.net #swl http://www.surriel.com/ http://distro.conectiva.com/
From: Rik van Riel <[email protected]>
Date: Tue, 20 Nov 2001 21:35:40 -0200 (BRST)
Quoted 2 lines · David S. Miller
TLB misses add to the cost, and this overhead is more than "noise".
Well, this could have something to do with the fact that our page fault handler only maps in _1_ page at a time, so we're trapping into the pagefault handler every 4kB...
The Apache folks were keeping it mapped across requests, so even if it was "primed" (ie. pre-faulted), a read() into a static buffer was still significantly faster.
Quoted 10 lines · David S. Miller
From: Rik van Riel <[email protected]>
Date: Tue, 20 Nov 2001 21:35:40 -0200 (BRST)Quoted 2 lines · David S. Miller
TLB misses add to the cost, and this overhead is more than "noise".
The Apache folks were keeping it mapped across requests, so even if it was "primed" (ie. pre-faulted), a
read()into a static buffer was still significantly faster.
Interesting. I wonder how read() and mmap() compare when the data is in highmem pages and we're facing a kmap()/kunmap() for read() ...
regards,
Rik
Signature · 3 lines
Shortwave goes a long way: irc.starchat.net #swl http://www.surriel.com/ http://distro.conectiva.com/
From: Rik van Riel <[email protected]>
Date: Tue, 20 Nov 2001 22:19:26 -0200 (BRST)
Quoted 3 lines · David S. Miller
The Apache folks were keeping it mapped across requests, so even if it was "primed" (ie. pre-faulted), a
read()into a static buffer was still significantly faster.
Interesting. I wonder how read() and mmap() compare when the data is in highmem pages and we're facing a kmap()/kunmap() for read() ...
Probably, the performance drops for read() to be equivalent, or slightly below, mmap() peformance. That would be my guess.
Franks a lot,
David S. Miller
[email protected]