Skip to content

Conversation

puranjaymohan
Copy link
Contributor

vm_area_map_pages() may allocate memory while inserting pages into bpf arena's vm_area. In order to make bpf_arena_alloc_pages() kfunc non-sleepable change bpf arena to populate pages without allocating memory:

  • at arena creation time populate all page table levels except the last level
  • when new pages need to be inserted call apply_to_page_range() again which will only set_pte_at() those pages and will not allocate memory
  • when freeing pages, the work is deferred and apply_to_existing_page_range() is used to reset the pte entry and free the page. This way the intermediate page table levels are not freed until the arena is destroyed.

Co-developed-by: Alexei Starovoitov [email protected]

vm_area_map_pages() may allocate memory while inserting pages into bpf
arena's vm_area. In order to make bpf_arena_alloc_pages() kfunc
non-sleepable change bpf arena to populate pages without
allocating memory:
- at arena creation time populate all page table levels except
  the last level
- when new pages need to be inserted call apply_to_page_range()
  again which will only set_pte_at() those pages and will not
  allocate memory
- when freeing pages, the work is deferred and apply_to_existing_page_range()
  is used to reset the pte entry and free the page. This way the intermediate
  page table levels are not freed until the arena is destroyed.

Co-developed-by: Alexei Starovoitov <[email protected]>
Signed-off-by: Puranjay Mohan <[email protected]>
@kernel-patches-daemon-bpf kernel-patches-daemon-bpf bot force-pushed the bpf-next_base branch 8 times, most recently from 6d36951 to 6116807 Compare October 19, 2025 02:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant