From: Eric B Munson <emunson@akamai.com>
To: Michal Hocko <mhocko@suse.cz>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Shuah Khan <shuahkh@osg.samsung.com>,
linux-alpha@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-mips@linux-mips.org, linux-parisc@vger.kernel.org,
linuxppc-dev@lists.ozlabs.org, sparclinux@vger.kernel.org,
linux-xtensa@linux-xtensa.org, linux-mm@kvack.org,
linux-arch@vger.kernel.org, linux-api@vger.kernel.org
Subject: Re: [PATCH 0/3] Allow user to request memory to be locked on page fault
Date: Tue, 19 May 2015 16:30:05 -0400 [thread overview]
Message-ID: <20150519203005.GB2454@akamai.com> (raw)
In-Reply-To: <20150515153550.GA2454@akamai.com>
[-- Attachment #1: Type: text/plain, Size: 4761 bytes --]
On Fri, 15 May 2015, Eric B Munson wrote:
> On Thu, 14 May 2015, Michal Hocko wrote:
>
> > On Wed 13-05-15 11:00:36, Eric B Munson wrote:
> > > On Mon, 11 May 2015, Eric B Munson wrote:
> > >
> > > > On Fri, 08 May 2015, Andrew Morton wrote:
> > > >
> > > > > On Fri, 8 May 2015 15:33:43 -0400 Eric B Munson <emunson@akamai.com> wrote:
> > > > >
> > > > > > mlock() allows a user to control page out of program memory, but this
> > > > > > comes at the cost of faulting in the entire mapping when it is
> > > > > > allocated. For large mappings where the entire area is not necessary
> > > > > > this is not ideal.
> > > > > >
> > > > > > This series introduces new flags for mmap() and mlockall() that allow a
> > > > > > user to specify that the covered are should not be paged out, but only
> > > > > > after the memory has been used the first time.
> > > > >
> > > > > Please tell us much much more about the value of these changes: the use
> > > > > cases, the behavioural improvements and performance results which the
> > > > > patchset brings to those use cases, etc.
> > > > >
> > > >
> > > > To illustrate the proposed use case I wrote a quick program that mmaps
> > > > a 5GB file which is filled with random data and accesses 150,000 pages
> > > > from that mapping. Setup and processing were timed separately to
> > > > illustrate the differences between the three tested approaches. the
> > > > setup portion is simply the call to mmap, the processing is the
> > > > accessing of the various locations in that mapping. The following
> > > > values are in milliseconds and are the averages of 20 runs each with a
> > > > call to echo 3 > /proc/sys/vm/drop_caches between each run.
> > > >
> > > > The first mapping was made with MAP_PRIVATE | MAP_LOCKED as a baseline:
> > > > Startup average: 9476.506
> > > > Processing average: 3.573
> > > >
> > > > The second mapping was simply MAP_PRIVATE but each page was passed to
> > > > mlock() before being read:
> > > > Startup average: 0.051
> > > > Processing average: 721.859
> > > >
> > > > The final mapping was MAP_PRIVATE | MAP_LOCKONFAULT:
> > > > Startup average: 0.084
> > > > Processing average: 42.125
> > > >
> > >
> > > Michal's suggestion of changing protections and locking in a signal
> > > handler was better than the locking as needed, but still significantly
> > > more work required than the LOCKONFAULT case.
> > >
> > > Startup average: 0.047
> > > Processing average: 86.431
> >
> > Have you played with batching? Has it helped? Anyway it is to be
> > expected that the overhead will be higher than a single mmap call. The
> > question is whether you can live with it because adding a new semantic
> > to mlock sounds trickier and MAP_LOCKED is tricky enough already...
> >
>
> I reworked the experiment to better cover the batching solution. The
> same 5GB data file is used, however instead of 150,000 accesses at
> regular intervals, the test program now does 15,000,000 accesses to
> random pages in the mapping. The rest of the setup remains the same.
>
> mmap with MAP_LOCKED:
> Setup avg: 11821.193
> Processing avg: 3404.286
>
> mmap with mlock() before each access:
> Setup avg: 0.054
> Processing avg: 34263.201
>
> mmap with PROT_NONE and signal handler and batch size of 1 page:
> With the default value in max_map_count, this gets ENOMEM as I attempt
> to change the permissions, after upping the sysctl significantly I get:
> Setup avg: 0.050
> Processing avg: 67690.625
>
> mmap with PROT_NONE and signal handler and batch size of 8 pages:
> Setup avg: 0.098
> Processing avg: 37344.197
>
> mmap with PROT_NONE and signal handler and batch size of 16 pages:
> Setup avg: 0.0548
> Processing avg: 29295.669
>
> mmap with MAP_LOCKONFAULT:
> Setup avg: 0.073
> Processing avg: 18392.136
>
> The signal handler in the batch cases faulted in memory in two steps to
> avoid having to know the start and end of the faulting mapping. The
> first step covers the page that caused the fault as we know that it will
> be possible to lock. The second step speculatively tries to mlock and
> mprotect the batch size - 1 pages that follow. There may be a clever
> way to avoid this without having the program track each mapping to be
> covered by this handeler in a globally accessible structure, but I could
> not find it.
>
> These results show that if the developer knows that a majority of the
> mapping will be used, it is better to try and fault it in at once,
> otherwise MAP_LOCKONFAULT is significantly faster.
>
> Eric
Is there anything else I can add to the discussion here?
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
prev parent reply other threads:[~2015-05-19 20:30 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-08 19:33 [PATCH 0/3] Allow user to request memory to be locked on page fault Eric B Munson
2015-05-08 19:33 ` [PATCH 1/3] Add flag to request pages are locked after " Eric B Munson
2015-05-08 19:33 ` [PATCH 2/3] Add mlockall flag for locking pages on fault Eric B Munson
[not found] ` <1431113626-19153-1-git-send-email-emunson-JqFfY2XvxFXQT0dZR+AlfA@public.gmane.org>
2015-05-08 19:33 ` [PATCH 3/3] Add tests for lock " Eric B Munson
2015-05-08 19:42 ` [PATCH 0/3] Allow user to request memory to be locked on page fault Andrew Morton
[not found] ` <20150508124203.6679b1d35ad9555425003929-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
2015-05-08 20:06 ` Eric B Munson
2015-05-08 20:15 ` Andrew Morton
2015-05-11 14:36 ` Eric B Munson
2015-05-11 19:12 ` Andrew Morton
2015-05-11 21:05 ` Eric B Munson
2015-05-13 13:58 ` Michal Hocko
2015-05-13 14:14 ` Eric B Munson
2015-05-11 18:06 ` Eric B Munson
2015-05-13 15:00 ` Eric B Munson
[not found] ` <20150513150036.GG1227-JqFfY2XvxFXQT0dZR+AlfA@public.gmane.org>
2015-05-14 8:08 ` Michal Hocko
[not found] ` <20150514080812.GC6433-2MMpYkNvuYDjFM9bn6wA6Q@public.gmane.org>
2015-05-14 13:58 ` Eric B Munson
2015-05-15 15:35 ` Eric B Munson
2015-05-19 20:30 ` Eric B Munson [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150519203005.GB2454@akamai.com \
--to=emunson@akamai.com \
--cc=akpm@linux-foundation.org \
--cc=linux-alpha@vger.kernel.org \
--cc=linux-api@vger.kernel.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mips@linux-mips.org \
--cc=linux-mm@kvack.org \
--cc=linux-parisc@vger.kernel.org \
--cc=linux-xtensa@linux-xtensa.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mhocko@suse.cz \
--cc=shuahkh@osg.samsung.com \
--cc=sparclinux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).