Article View: news.software.nntp
Article #30032madvise() works (!)
From: Matt Dillon
Date: Sun, 26 Jul 1998 00:00
Date: Sun, 26 Jul 1998 00:00
87 lines
4718 bytes
4718 bytes
I've started messing with calling madvise() after mmap(). It
actually works! At least on FreeBSD systems.
Without calling madvise() I get page faults accessing the newly
minted mmap of a file.
If I call madvise() for the address range with MADV_WILLNEED, the
OS will pre-fault (fill in the page table) for any pages related
to the file that it finds in the buffer cache.
If I *also* call madvise() for the address range with MADV_SEQUENTIAL,
the OS increases the number of pages read-ahead when a page-fault
does occur in the mmap.
I see a major increase in disk efficiency and a noticeable decrease in
dnewslink latencies. On news1.best.com with 76+ dnewslink's running each
disk was saturating at around 1000 sps (essentially a seek-bound situation)
After changing dnewslink to call madvise with MADV_SEQUENTIAL, each disk
is now saturating at 1800 sps. (I am presuming that the extra information
read from disk is being put to good use since dnewslink dumps the whole
article over the network).
news1:/news> iostat 1
tty sd0 sd1 sd2 cpu
tin tout sps tps msps sps tps msps sps tps msps us ni sy in id
0 8 227 47 0.0 -304 68 0.3 -303 68 0.3 22 0 23 9 47
0 671321 79 0.0 1851 75 0.0 1189 56 0.0 48 0 32 12 8
0 671216 71 0.0 1357 75 0.0 826 44 0.0 42 0 36 9 13
0 671187 78 0.0 1596 83 0.0 1135 101 0.0 48 0 44 5 2
0 671246 64 0.0 1591 76 0.0 1528 135 0.0 33 0 35 15 18
0 671276 64 0.0 1621 69 0.0 1955 125 0.0 36 0 32 8 23
0 671111 62 0.0 1977 189 0.0 2044 95 0.0 20 0 29 9 42
0 67 889 47 0.0 1205 70 0.0 1885 80 0.0 39 0 35 9 18
^^^^^^^^^^^^^^^^^^^^^^^^^^^
CCD's /news/spool/news (Diablo spool)
The effect MADV_WILLNEED has on the system is just as pronounced.
The dnewslink processes are taking fewer page faults.
Example where no page fault occurs:
23192 dnewslink 0.000013 CALL mmap(0,0x2000,0x1,0x1,0xe,0,0xf000,0)
23192 dnewslink 0.000039 RET mmap 537149440/0x20044000
23192 dnewslink 0.000020 CALL madvise(0x20044a44,0x614,0x3)
23192 dnewslink 0.000020 RET madvise 0
23192 dnewslink 0.000016 CALL madvise(0x20044a44,0x614,0x2)
23192 dnewslink 0.000013 RET madvise 0
(internal buffer copy)
23192 dnewslink 0.000097 CALL munmap(0x20044000,0x2000)
23192 dnewslink 0.000025 RET munmap 0
Example where I/O fault occurs:
23192 dnewslink 0.000018 CALL mmap(0,0x2000,0x1,0x1,0x10,0,0x19000,0)
23192 dnewslink 0.000055 RET mmap 537149440/0x20044000
23192 dnewslink 0.000019 CALL madvise(0x20044ae5,0x7c6,0x3)
23192 dnewslink 0.000026 RET madvise 0
23192 dnewslink 0.000015 CALL madvise(0x20044ae5,0x7c6,0x2)
23192 dnewslink 0.000015 RET madvise 0
(internal buffer copy)
23192 dnewslink 0.094233 CALL munmap(0x20044000,0x2000) <<<<<<<<<<<<
23192 dnewslink 0.002245 RET munmap 0
But... no more page faults are occuring that aren't I/O faults. And when an
I/O fault *does* occur the system is reading in more pages... 32K worth
instead of 16K. AND it's even streaming a little... on an I/O fault it reads
8 (x4K) pages but only maps 7 of them in order to force a normal page fault
(that can be resolved from the buffer cache) on the 8th page which it can
use to bootstrap the read-ahead for next 8 pages.
madvise() MADV_FREE is also very interesting. I may start calling it in the
memory allocation module for bestwwwd rather then munmap(). Using mmap() with
MAP_ANON is a great way to allocate memory, but it causes page faults.
MADV_FREE solves this problem by allowing me to put in more hysteresis
when dealing with multiple memory segments yet still giving the system the
ability to throw away the page.
This is *very* cool stuff.
-Matt
--
Matthew Dillon Engineering, HiWay Technologies, Inc. & BEST Internet
Communications
<dillon@best.net> (Please include original email in any response)
Technical Details
Message-ID:
<6pg4rq$drt$1@flea.best.net>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mailShow Full Headers
Complete Article Headers
Message-ID: <6pg4rq$drt$1@flea.best.net> Subject: madvise() works (!) Date: Sun, 26 Jul 1998 00:00:00 +0000 From: dillon@best.net (Matt Dillon) Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mail X-Deja-AN: 375114797 X-Trace: 901486269 27299 dillon 206.184.139.131 Organization: Best Internet Communications, Inc. Newsgroups: news.software.nntp,comp.unix.bsd.freebsd.misc