linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next v5 0/7] bpf, mm: Introduce try_alloc_pages()
@ 2025-01-15  2:17 Alexei Starovoitov
  2025-01-15  2:17 ` [PATCH bpf-next v5 1/7] mm, bpf: Introduce try_alloc_pages() for opportunistic page allocation Alexei Starovoitov
                   ` (6 more replies)
  0 siblings, 7 replies; 37+ messages in thread
From: Alexei Starovoitov @ 2025-01-15  2:17 UTC (permalink / raw)
  To: bpf
  Cc: andrii, memxor, akpm, peterz, vbabka, bigeasy, rostedt, houtao1,
	hannes, shakeel.butt, mhocko, willy, tglx, jannh, tj, linux-mm,
	kernel-team

From: Alexei Starovoitov <ast@kernel.org>

Hi All,

The main motivation is to make alloc page and slab reentrant and
remove bpf_mem_alloc.

v4->v5:
- Fixed patch 1 and 4 commit logs and comments per Michal suggestions.
  Added Acks.
- Added patch 6 to make failslab, kfence, kmemleak complaint
  with trylock mode. It's a prerequisite for reentrant slab patches.

v4:
https://lore.kernel.org/bpf/20250114021922.92609-1-alexei.starovoitov@gmail.com/

v3->v4:
Addressed feedback from Michal and Shakeel:
- GFP_TRYLOCK flag is gone. gfpflags_allow_spinning() is used instead.
- Improved comments and commit logs.

v3:
https://lore.kernel.org/bpf/20241218030720.1602449-1-alexei.starovoitov@gmail.com/

v2->v3:
To address the issues spotted by Sebastian, Vlastimil, Steven:
- Made GFP_TRYLOCK internal to mm/internal.h
  try_alloc_pages() and free_pages_nolock() are the only interfaces.
- Since spin_trylock() is not safe in RT from hard IRQ and NMI
  disable such usage in lock_trylock and in try_alloc_pages().
  In such case free_pages_nolock() falls back to llist right away.
- Process trylock_free_pages llist when preemptible.
- Check for things like unaccepted memory and order <= 3 early.
- Don't call into __alloc_pages_slowpath() at all.
- Inspired by Vlastimil's struct local_tryirq_lock adopted it in
  local_lock_t. Extra 4 bytes in !RT in local_lock_t shouldn't
  affect any of the current local_lock_t users. This is patch 3.
- Tested with bpf selftests in RT and !RT and realized how much
  more work is necessary on bpf side to play nice with RT.
  The urgency of this work got higher. The alternative is to
  convert bpf bits left and right to bpf_mem_alloc.

v2:
https://lore.kernel.org/bpf/20241210023936.46871-1-alexei.starovoitov@gmail.com/

v1->v2:
- fixed buggy try_alloc_pages_noprof() in PREEMPT_RT. Thanks Peter.
- optimize all paths by doing spin_trylock_irqsave() first
  and only then check for gfp_flags & __GFP_TRYLOCK.
  Then spin_lock_irqsave() if it's a regular mode.
  So new gfp flag will not add performance overhead.
- patches 2-5 are new. They introduce lockless and/or trylock free_pages_nolock()
  and memcg support. So it's in usable shape for bpf in patch 6.

v1:
https://lore.kernel.org/bpf/20241116014854.55141-1-alexei.starovoitov@gmail.com/

Alexei Starovoitov (7):
  mm, bpf: Introduce try_alloc_pages() for opportunistic page allocation
  mm, bpf: Introduce free_pages_nolock()
  locking/local_lock: Introduce local_trylock_irqsave()
  memcg: Use trylock to access memcg stock_lock.
  mm, bpf: Use memcg in try_alloc_pages().
  mm: Make failslab, kfence, kmemleak aware of trylock mode
  bpf: Use try_alloc_pages() to allocate pages for bpf needs.

 include/linux/gfp.h                 |  23 ++++
 include/linux/local_lock.h          |   9 ++
 include/linux/local_lock_internal.h |  76 ++++++++++--
 include/linux/mm_types.h            |   4 +
 include/linux/mmzone.h              |   3 +
 kernel/bpf/syscall.c                |   4 +-
 mm/failslab.c                       |   3 +
 mm/internal.h                       |   1 +
 mm/kfence/core.c                    |   4 +
 mm/kmemleak.c                       |   3 +
 mm/memcontrol.c                     |  24 +++-
 mm/page_alloc.c                     | 183 ++++++++++++++++++++++++++--
 12 files changed, 313 insertions(+), 24 deletions(-)

-- 
2.43.5



^ permalink raw reply	[flat|nested] 37+ messages in thread

end of thread, other threads:[~2025-01-22  1:36 UTC | newest]

Thread overview: 37+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-15  2:17 [PATCH bpf-next v5 0/7] bpf, mm: Introduce try_alloc_pages() Alexei Starovoitov
2025-01-15  2:17 ` [PATCH bpf-next v5 1/7] mm, bpf: Introduce try_alloc_pages() for opportunistic page allocation Alexei Starovoitov
2025-01-15 11:19   ` Vlastimil Babka
2025-01-15 23:00     ` Alexei Starovoitov
2025-01-15 23:47       ` Shakeel Butt
2025-01-16  2:44         ` Alexei Starovoitov
2025-01-15 23:16     ` Shakeel Butt
2025-01-17 18:19   ` Sebastian Andrzej Siewior
2025-01-15  2:17 ` [PATCH bpf-next v5 2/7] mm, bpf: Introduce free_pages_nolock() Alexei Starovoitov
2025-01-15 11:47   ` Vlastimil Babka
2025-01-15 23:15     ` Alexei Starovoitov
2025-01-16  8:31       ` Vlastimil Babka
2025-01-17 18:20   ` Sebastian Andrzej Siewior
2025-01-15  2:17 ` [PATCH bpf-next v5 3/7] locking/local_lock: Introduce local_trylock_irqsave() Alexei Starovoitov
2025-01-15  2:23   ` Alexei Starovoitov
2025-01-15  7:22     ` Sebastian Sewior
2025-01-15 14:22   ` Vlastimil Babka
2025-01-16  2:20     ` Alexei Starovoitov
2025-01-17 20:33   ` Sebastian Andrzej Siewior
2025-01-21 15:59     ` Vlastimil Babka
2025-01-21 16:43       ` Sebastian Andrzej Siewior
2025-01-22  1:35         ` Alexei Starovoitov
2025-01-15  2:17 ` [PATCH bpf-next v5 4/7] memcg: Use trylock to access memcg stock_lock Alexei Starovoitov
2025-01-15 16:07   ` Vlastimil Babka
2025-01-16  0:12   ` Shakeel Butt
2025-01-16  2:22     ` Alexei Starovoitov
2025-01-16 20:07       ` Joshua Hahn
2025-01-17 17:36         ` Johannes Weiner
2025-01-15  2:17 ` [PATCH bpf-next v5 5/7] mm, bpf: Use memcg in try_alloc_pages() Alexei Starovoitov
2025-01-15 17:51   ` Vlastimil Babka
2025-01-16  0:24   ` Shakeel Butt
2025-01-15  2:17 ` [PATCH bpf-next v5 6/7] mm: Make failslab, kfence, kmemleak aware of trylock mode Alexei Starovoitov
2025-01-15 17:57   ` Vlastimil Babka
2025-01-16  2:23     ` Alexei Starovoitov
2025-01-15  2:17 ` [PATCH bpf-next v5 7/7] bpf: Use try_alloc_pages() to allocate pages for bpf needs Alexei Starovoitov
2025-01-15 18:02   ` Vlastimil Babka
2025-01-16  2:25     ` Alexei Starovoitov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox