From owner-freebsd-hackers@FreeBSD.ORG Mon Mar 24 12:12:24 2014 Return-Path: Delivered-To: hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 28E8EAE9 for ; Mon, 24 Mar 2014 12:12:24 +0000 (UTC) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id B835CBAD for ; Mon, 24 Mar 2014 12:12:23 +0000 (UTC) Received: from tom.home (kostik@localhost [127.0.0.1]) by kib.kiev.ua (8.14.8/8.14.8) with ESMTP id s2OCBusU003704; Mon, 24 Mar 2014 14:11:56 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.8.3 kib.kiev.ua s2OCBusU003704 Received: (from kostik@localhost) by tom.home (8.14.8/8.14.8/Submit) id s2OCBurk003703; Mon, 24 Mar 2014 14:11:56 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Mon, 24 Mar 2014 14:11:56 +0200 From: Konstantin Belousov To: Dmitry Sivachenko Subject: Re: madvise() vs posix_fadvise() Message-ID: <20140324121156.GX21331@kib.kiev.ua> References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="D+UG5SQJKkIYNVx0" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on tom.home Cc: hackers@freebsd.org, Trond Endrest??l X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 24 Mar 2014 12:12:24 -0000 --D+UG5SQJKkIYNVx0 Content-Type: text/plain; charset=koi8-r Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Mar 24, 2014 at 04:03:04PM +0400, Dmitry Sivachenko wrote: >=20 > On 21 =CD=C1=D2=D4=C1 2014 =C7., at 20:27, Trond Endrest??l wrote: >=20 > > On Fri, 21 Mar 2014 18:56+0400, Dmitry Sivachenko wrote: > >=20 > >> Hello! > >>=20 > >> I have a program which uses large data files (read-only, via mmap()). > >>=20 > >> These machines have a bit more RAM that these files occupy, so it is= =20 > >> possible to have all these data in memory. > >>=20 > >> What techniques should I use to promote this data not to be purged=20 > >> from RAM: > >>=20 > >> -- madvise(MADV_WILLNEED) > >> -- posix_fadvise(POSIX_FADV_WILLNEED) > >> -- both? > >=20 > > Although a bit dangerous, mlock(2) might be your ticket. That system=20 > > call prevents your memory region from being swapped/paged away from=20 > > physical memory. > >=20 >=20 >=20 > I know about mlock(2), it is a bit overkill. > Can someone please explain the difference between madvise(MADV_WILLNEED) = and posix_fadvise(POSIX_FADV_WILLNEED)? >=20 The difference is only in the way the errors are reported; madvise(2) is the 'classic' syscall which sets errno, while posix_madvise(3) is a trivial wrapper which returns error. You would get the answer yourself in approx. 1 minute if you looked at the man page or code. --D+UG5SQJKkIYNVx0 Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (FreeBSD) iQIcBAEBAgAGBQJTMCELAAoJEJDCuSvBvK1Bh4gP/iGagR41B/Wj+VbwYf/AnSJN arteO7s8odPafp83+bBKl6iT9DgE/SAFMENGmaqpOeehR1VEu7vkwSPBjadSsd9s rKYvOSC6eKGBU2jJNptGYgmR4MqAZzesZjLzkIqEyNfOz/LKFa8uWeTA+/kmdtDt JPb57dY6aYN+BatEzl2aRmsngc/ZQF3SXyqrTIP2Heu+K0P2du8P9R4fw6VYY7jU XOqnShZP7Fb5HSpKcFh+h4Y6WVoS4Yp2ADYqdCF0bytOnT0S3DFnWGkZmTrY95E4 jVQFidpYr9MfoKkDqfiaFzhHZhkSOP5gqM2Y9M9GK2wkLEYKxuREiZFNXjt/BwSn atYtkUmNBzc9+QdfE0wT+0x9V3LLx3QxQX98O5hVYQNYD5q3YvfvOdRx700oCyr2 G3CNwEvXMhOTc2oVh9byaYcqLfxjAWhV6Vku8//pNEYTG4/To41csX8srwpVbMf0 IQ8DUH+dNOfVwV82HBOpanGl/gE1T4Ng4I5b1XescvUbOs+EP0DXFbTZH45A3uGt vxInpRd/83yZNILKznFzX9y5YTSoQnsrUhP/Qe1TslIjUtmUau/wCQyUB+R+GiVJ EwHzs+hpXi7vgX+EpJdI5Xh21qPC1TS8NG+EtNkCpM2DDZ/rloGi4K1XgDEdwkST gA+zNV3Aacc2tI5WGX4T =1gTN -----END PGP SIGNATURE----- --D+UG5SQJKkIYNVx0--