All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jiri Olsa <olsajiri@gmail.com>
To: Song Liu <song@kernel.org>
Cc: Kumar Kartikeya Dwivedi <memxor@gmail.com>,
	Jiri Olsa <olsajiri@gmail.com>,
	bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net,
	andrii@kernel.org, eddyz87@gmail.com, kernel-team@meta.com
Subject: Re: [PATCH bpf-next 2/2] selftests/bpf: Add mmap/munmap benchmark for array maps
Date: Wed, 29 Jul 2026 12:30:13 +0200	[thread overview]
Message-ID: <amnWNTIQm4F_AzjS@krava> (raw)
In-Reply-To: <CAPhsuW5RC9JkLwfc2V-iO0pw5ggsrrwamJGRL_haN5fs8KRLkQ@mail.gmail.com>

On Tue, Jul 28, 2026 at 01:11:49PM -0700, Song Liu wrote:
> On Mon, Jul 27, 2026 at 5:19 PM Song Liu <song@kernel.org> wrote:
> [...]
> > > I think it would make sense to compare cumulative cost of mmap+read-every-page.
> > > I am sure it would also be lower before this change, due to the added context
> > > switches for fault on every page access that would be amortized before this, but
> > > may give a better picture about the difference.
> > >
> > > I do feel like it's a corner case realistically, and after the first fault the
> > > page remains mapped (and users who care about pages being present can go the
> > > route of passing MAP_POPULATE). I am assuming passing that before was a noop, so
> > > it can be added to code in a backwards compatible fashion if someone really
> > > depends on this?
> >
> > Given there is MAP_POPULATE flag, yes, the user can preserve the old
> > behavior with this flag. While this requires users to make changes for
> > this corner case, I think it is still cleaner than adding a BPF map flag
> > for this. If there are no strong objections, I will keep this behavior in v3.
> 
> This turns out to be a little more complicated:
> 
> 1. Bad news: MAP_POPULATE is not a noop for old kernels. The pre
>    fault mechanism still adds some overhead (for almost no gain). For
>    8MiB mmap, MAP_POPULATE addes about 80us (raw data below).
> 
> 2. Good news: We can further improve MAP_POPULATE with a batch
>    pre fault (vm_operations_struct->map_pages). With batch pre fault,
>    mmap then accessing 8MiB is about 34us slower than the best
>    option before the set:
>    (before: no MAP_POPULATE => access all pages: 252us;
>    after: MAP_POPULATE => access all pages: 286us).
> 
> Note that, all the above are worst cases: we need to access all pages
> and fill the page table one way or another. If we don't need to access
> all pages, the change saves a lot (220us => 1.2us) for the mmap.
> 
> Overall, I think this is a net win for most use cases.

sounds good, thanks for all the details

jirka

> 
> Thanks,
> Song
> 
> Raw data:
> 
> All of the following are for 8MiB, access times are in microseconds (us).
> 
> Before:
> no MAP_POPULATE (do not access pages) 220us
> no MAP_POPULATE => access all pages: 252us
> MAP_POPULATE (do not access pages) 304us
> MAP_POPULATE => access all pages: 334us
> 
> After:
> no MAP_POPULATE (do not access pages): 1.2us
> no MAP_POPULATE => access all pages: 543us
> MAP_POPULATE (do not access pages): 262us
> MAP_POPULATE => access all pages: 286us

      parent reply	other threads:[~2026-07-29 10:30 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-22  6:53 [PATCH bpf-next 0/2] bpf: Populate mmap-able array maps lazily Song Liu
2026-07-22  6:53 ` [PATCH bpf-next 1/2] bpf: Populate mmap-able array map memory lazily Song Liu
2026-07-22  7:16   ` sashiko-bot
2026-07-22  6:53 ` [PATCH bpf-next 2/2] selftests/bpf: Add mmap/munmap benchmark for array maps Song Liu
2026-07-22  7:05   ` sashiko-bot
2026-07-23 18:46   ` Jiri Olsa
2026-07-23 21:58     ` Song Liu
2026-07-24  8:53       ` Jiri Olsa
2026-07-25  0:13         ` Song Liu
2026-07-25  1:43           ` Kumar Kartikeya Dwivedi
2026-07-28  0:19             ` Song Liu
2026-07-28 20:11               ` Song Liu
2026-07-28 20:18                 ` Kumar Kartikeya Dwivedi
2026-07-29 10:30                 ` Jiri Olsa [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=amnWNTIQm4F_AzjS@krava \
    --to=olsajiri@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=kernel-team@meta.com \
    --cc=memxor@gmail.com \
    --cc=song@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.