From owner-freebsd-hackers@FreeBSD.ORG Thu Apr 5 19:41:28 2012 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id D14E1106566C; Thu, 5 Apr 2012 19:41:28 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from mail.zoral.com.ua (mx0.zoral.com.ua [91.193.166.200]) by mx1.freebsd.org (Postfix) with ESMTP id 604898FC0A; Thu, 5 Apr 2012 19:41:28 +0000 (UTC) Received: from skuns.kiev.zoral.com.ua (localhost [127.0.0.1]) by mail.zoral.com.ua (8.14.2/8.14.2) with ESMTP id q35JfNZ7050764; Thu, 5 Apr 2012 22:41:23 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: from deviant.kiev.zoral.com.ua (kostik@localhost [127.0.0.1]) by deviant.kiev.zoral.com.ua (8.14.5/8.14.5) with ESMTP id q35JfNaw028760; Thu, 5 Apr 2012 22:41:23 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.14.5/8.14.5/Submit) id q35JfMIX028759; Thu, 5 Apr 2012 22:41:22 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: deviant.kiev.zoral.com.ua: kostik set sender to kostikbel@gmail.com using -f Date: Thu, 5 Apr 2012 22:41:22 +0300 From: Konstantin Belousov To: Andrey Zonov Message-ID: <20120405194122.GC2358@deviant.kiev.zoral.com.ua> References: <4F7B495D.3010402@zonov.org> <20120404071746.GJ2358@deviant.kiev.zoral.com.ua> <4F7DC037.9060803@rice.edu> <4F7DF39A.3000500@zonov.org> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="apIra6NYt7mqlw41" Content-Disposition: inline In-Reply-To: <4F7DF39A.3000500@zonov.org> User-Agent: Mutt/1.4.2.3i X-Virus-Scanned: clamav-milter 0.95.2 at skuns.kiev.zoral.com.ua X-Virus-Status: Clean X-Spam-Status: No, score=-4.0 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on skuns.kiev.zoral.com.ua Cc: alc@freebsd.org, freebsd-hackers@freebsd.org, Alan Cox Subject: Re: problems with mmap() and disk caching X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 Apr 2012 19:41:28 -0000 --apIra6NYt7mqlw41 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Apr 05, 2012 at 11:33:46PM +0400, Andrey Zonov wrote: > On 05.04.2012 19:54, Alan Cox wrote: > >On 04/04/2012 02:17, Konstantin Belousov wrote: > >>On Tue, Apr 03, 2012 at 11:02:53PM +0400, Andrey Zonov wrote: > [snip] > >>>This is what I expect. But why this doesn't work without reading file > >>>manually? > >>Issue seems to be in some change of the behaviour of the reserv or > >>phys allocator. I Cc:ed Alan. > > > >I'm pretty sure that the behavior here hasn't significantly changed in > >about twelve years. Otherwise, I agree with your analysis. > > > >On more than one occasion, I've been tempted to change: > > > >pmap_remove_all(mt); > >if (mt->dirty !=3D 0) > >vm_page_deactivate(mt); > >else > >vm_page_cache(mt); > > > >to: > > > >vm_page_dontneed(mt); > > >=20 > Thanks Alan! Now it works as I expect! >=20 > But I have more questions to you and kib@. They are in my test below. >=20 > So, prepare file as earlier, and take information about memory usage=20 > from top(1). After preparation, but before test: > Mem: 80M Active, 55M Inact, 721M Wired, 215M Buf, 46G Free >=20 > First run: > $ ./mmap /mnt/random > mmap: 1 pass took: 7.462865 (none: 0; res: 262144; super:=20 > 0; other: 0) >=20 > No super pages after first run, why?.. >=20 > Mem: 79M Active, 1079M Inact, 722M Wired, 216M Buf, 45G Free >=20 > Now the file is in inactive memory, that's good. >=20 > Second run: > $ ./mmap /mnt/random > mmap: 1 pass took: 0.004191 (none: 0; res: 262144; super:=20 > 511; other: 0) >=20 > All super pages are here, nice. >=20 > Mem: 1103M Active, 55M Inact, 722M Wired, 216M Buf, 45G Free >=20 > Wow, all inactive pages moved to active and sit there even after process= =20 > was terminated, that's not good, what do you think? Why do you think this is 'not good' ? You have plenty of free memory, there is no memory pressure, and all pages were referenced recently. THere is no reason for them to be deactivated. >=20 > Read the file: > $ cat /mnt/random > /dev/null >=20 > Mem: 79M Active, 55M Inact, 1746M Wired, 1240M Buf, 45G Free >=20 > Now the file is in wired memory. I do not understand why so. You do use UFS, right ? There is enough buffer headers and buffer KVA to have buffers allocated for the whole file content. Since buffers wire corresponding pages, you get pages migrated to wired. When there appears a buffer pressure (i.e., any other i/o started), the buffers will be repurposed and pages moved to inactive. >=20 > Could you please give me explanation about active/inactive/wired memory? >=20 >=20 > >because I suspect that the current code does more harm than good. In > >theory, it saves activations of the page daemon. However, more often > >than not, I suspect that we are spending more on page reactivations than > >we are saving on page daemon activations. The sequential access > >detection heuristic is just too easily triggered. For example, I've seen > >it triggered by demand paging of the gcc text segment. Also, I think > >that pmap_remove_all() and especially vm_page_cache() are too severe for > >a detection heuristic that is so easily triggered. > > > [snip] >=20 > --=20 > Andrey Zonov --apIra6NYt7mqlw41 Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (FreeBSD) iEYEARECAAYFAk999WIACgkQC3+MBN1Mb4juYQCgwyIjYQ6mXO30O0w9ktiSiq5p sY0An03Qp2+CcUYdcQ1lHxIbzZ5VCyNG =ehce -----END PGP SIGNATURE----- --apIra6NYt7mqlw41--