From owner-freebsd-hackers@FreeBSD.ORG Thu Mar 27 18:00:16 2014 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 99D6EDF2; Thu, 27 Mar 2014 18:00:16 +0000 (UTC) Received: from bigwig.baldwin.cx (bigwig.baldwin.cx [IPv6:2001:470:1f11:75::1]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 70CE0F91; Thu, 27 Mar 2014 18:00:16 +0000 (UTC) Received: from jhbbsd.localnet (unknown [209.249.190.124]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 41C85B9B9; Thu, 27 Mar 2014 14:00:15 -0400 (EDT) From: John Baldwin To: freebsd-hackers@freebsd.org Subject: Re: madvise() vs posix_fadvise() Date: Thu, 27 Mar 2014 11:41:41 -0400 User-Agent: KMail/1.13.5 (FreeBSD/8.4-CBSD-20130906; KDE/4.5.5; amd64; ; ) References: In-Reply-To: MIME-Version: 1.0 Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <201403271141.41487.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Thu, 27 Mar 2014 14:00:15 -0400 (EDT) Cc: hackers@freebsd.org, Dmitry Sivachenko , Trond =?utf-8?q?Endrest=C3=B8l?= 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: Thu, 27 Mar 2014 18:00:16 -0000 On Monday, March 24, 2014 8:03:04 am Dmitry Sivachenko wrote: >=20 > On 21 =D0=BC=D0=B0=D1=80=D1=82=D0=B0 2014 =D0=B3., at 20:27, Trond Endres= t=C3=B8l=20 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=20 posix_fadvise(POSIX_FADV_WILLNEED)? Right now FADV_WILLNEED is a nop. (I have some patches to implement it for UFS.) I can't recall off the top of my head if MADV_WILLNEED is also a nop. However, if both are fully implemented they should be similar in terms of requesting async read-ahead. MADV_WILLNEED might also conceivably pre-create PTEs while FADV_WILLNEED can be used on a file that isn't mapped but is accessed via read(2). =2D-=20 John Baldwin