linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Alexei Starovoitov <alexei.starovoitov@gmail.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: bpf <bpf@vger.kernel.org>, Daniel Borkmann <daniel@iogearbox.net>,
	 Andrii Nakryiko <andrii@kernel.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	 Barret Rhoden <brho@google.com>,
	Johannes Weiner <hannes@cmpxchg.org>,
	 Andrew Morton <akpm@linux-foundation.org>,
	Uladzislau Rezki <urezki@gmail.com>,
	 Christoph Hellwig <hch@infradead.org>,
	linux-mm <linux-mm@kvack.org>, Kernel Team <kernel-team@fb.com>
Subject: Re: [PATCH v3 bpf-next 01/14] bpf: Introduce bpf_arena.
Date: Mon, 11 Mar 2024 17:47:39 -0700	[thread overview]
Message-ID: <CAADnVQLWm=S_kMYJ58g==PgYKvVmPB8qF3vHc+d3BWPSFOxK5g@mail.gmail.com> (raw)
In-Reply-To: <CAEf4BzbAxEVYHtdqK8tWD8Fr_OaTxuhg4t7g4VfAAL61KoLJsA@mail.gmail.com>

On Mon, Mar 11, 2024 at 3:59 PM Andrii Nakryiko
<andrii.nakryiko@gmail.com> wrote:
>
>
> no, I get that, my point was a bit different and purely pedantic. It
> doesn't overflow 32-bit only when viewed from user-space addresses
> POV.
>
> It seems like it can overflow when we translate it into kernel address
> by adding kernel_vm_start (`kern_vm = get_vm_area(KERN_VM_SZ,
> VM_SPARSE | VM_USERMAP)` doesn't guarantee 4GB alignment, IIUC). But I
> don't see what kernel-side overflow matters (yet the comment is next
> to the code that does kernel-side range mapping, which is why I
> commented, the placement of the comment is what makes it a bit more
> confusing).

Got it. Ok. Will rephrase the comment.

> But I was pointing out that if the user-requested area is exactly 4GB
> and user_vm_start is aligned at the 4GB boundary, then user_vm_start +
> 4GB, technically is incrementing the upper 32 bits of user_vm_start.
> Which I don't think matters because it's the exclusive end of range.

yes. should be fine. I didn't add a selftest for 4Gb, because
not every CI has runners with this much memory.
I guess selftest can try to allocate and skip the test
if enomem without failing it.
Will add it in the follow up.

> > > The way you split these zap_pages for page_cnt == 1 and page_cnt > 1
> > > is quite confusing. Why can't you just unconditionally zap_pages()
> > > regardless of page_cnt before this loop? And why for page_cnt == 1 we
> > > have `page_mapped(page)` check, but it's ok to not check this for
> > > page_cnt>1 case?
> > >
> > > This asymmetric handling is confusing and suggests something more is
> > > going on here. Or am I overthinking it?
> >
> > It's an important optimization for the common case of page_cnt==1.
> > If page wasn't mapped into some user vma there is no need to call zap_pages
> > which is slow.
> > But when page_cnt is big it's much faster to do the batched zap
> > which is what this code does.
> > For the case of page_cnt=2 or small number there is no good optimization
> > to do other than try to count whether all pages in this range are
> > not page_mapped() and omit zap_page().
> > I don't think it's worth doing such optimization at this point,
> > since page_cnt=1 is likely the most common case.
> > If it changes, it can be optimized later.
>
> yep, makes sense, and a small comment stating that would be useful, IMO :)

Ok. Will add that too.


  reply	other threads:[~2024-03-12  0:47 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-08  1:07 [PATCH v3 bpf-next 00/14] bpf: Introduce BPF arena Alexei Starovoitov
2024-03-08  1:07 ` [PATCH v3 bpf-next 01/14] bpf: Introduce bpf_arena Alexei Starovoitov
2024-03-11 22:01   ` Andrii Nakryiko
2024-03-11 22:41     ` Alexei Starovoitov
2024-03-11 22:59       ` Andrii Nakryiko
2024-03-12  0:47         ` Alexei Starovoitov [this message]
2024-03-08  1:08 ` [PATCH v3 bpf-next 02/14] bpf: Disasm support for addr_space_cast instruction Alexei Starovoitov
2024-03-08  1:08 ` [PATCH v3 bpf-next 03/14] bpf: Add x86-64 JIT support for PROBE_MEM32 pseudo instructions Alexei Starovoitov
2024-03-11 22:05   ` Andrii Nakryiko
2024-03-11 22:44     ` Alexei Starovoitov
2024-03-08  1:08 ` [PATCH v3 bpf-next 04/14] bpf: Add x86-64 JIT support for bpf_addr_space_cast instruction Alexei Starovoitov
2024-03-08  1:08 ` [PATCH v3 bpf-next 05/14] bpf: Recognize addr_space_cast instruction in the verifier Alexei Starovoitov
2024-03-08  1:08 ` [PATCH v3 bpf-next 06/14] bpf: Recognize btf_decl_tag("arg:arena") as PTR_TO_ARENA Alexei Starovoitov
2024-03-08  1:08 ` [PATCH v3 bpf-next 07/14] libbpf: Add __arg_arena to bpf_helpers.h Alexei Starovoitov
2024-03-08  1:08 ` [PATCH v3 bpf-next 08/14] libbpf: Add support for bpf_arena Alexei Starovoitov
2024-03-08  1:08 ` [PATCH v3 bpf-next 09/14] bpftool: Recognize arena map type Alexei Starovoitov
2024-03-11 17:08   ` Quentin Monnet
2024-03-08  1:08 ` [PATCH v3 bpf-next 10/14] libbpf: Recognize __arena global varaibles Alexei Starovoitov
2024-03-11 17:09   ` Quentin Monnet
2024-03-08  1:08 ` [PATCH v3 bpf-next 11/14] bpf: Add helper macro bpf_addr_space_cast() Alexei Starovoitov
2024-03-08  1:08 ` [PATCH v3 bpf-next 12/14] selftests/bpf: Add unit tests for bpf_arena_alloc/free_pages Alexei Starovoitov
2024-03-08  1:08 ` [PATCH v3 bpf-next 13/14] selftests/bpf: Add bpf_arena_list test Alexei Starovoitov
2024-03-08  1:08 ` [PATCH v3 bpf-next 14/14] selftests/bpf: Add bpf_arena_htab test Alexei Starovoitov
2024-03-11 22:45 ` [PATCH v3 bpf-next 00/14] bpf: Introduce BPF arena Andrii Nakryiko
2024-03-11 23:02   ` Alexei Starovoitov
2024-03-11 22:50 ` patchwork-bot+netdevbpf

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='CAADnVQLWm=S_kMYJ58g==PgYKvVmPB8qF3vHc+d3BWPSFOxK5g@mail.gmail.com' \
    --to=alexei.starovoitov@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=andrii.nakryiko@gmail.com \
    --cc=andrii@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=brho@google.com \
    --cc=daniel@iogearbox.net \
    --cc=hannes@cmpxchg.org \
    --cc=hch@infradead.org \
    --cc=kernel-team@fb.com \
    --cc=linux-mm@kvack.org \
    --cc=torvalds@linux-foundation.org \
    --cc=urezki@gmail.com \
    /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