Skip to content

Commit ab44079

Browse files
Darksonnojeda
authored andcommitted
rust: alloc: add __GFP_HIGHMEM flag
Make it possible to allocate memory that doesn't need to mapped into the kernel's address space. This flag is useful together with Page::alloc_page [1]. Rust Binder needs this for the memory that holds incoming transactions for each process. Each process will have a few megabytes of memory allocated with this flag, which is mapped into the process using vm_insert_page. When the kernel copies data for an incoming transaction into a process's memory region, it will use kmap_local_page to temporarily map pages that are being modified. There is no need for them to take up address space in the kernel when the kernel is not writing an incoming transaction into the page. Link: https://lore.kernel.org/all/[email protected]/ [1] Signed-off-by: Alice Ryhl <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Miguel Ojeda <[email protected]>
1 parent d3ee24c commit ab44079

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

rust/bindings/bindings_helper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ const gfp_t RUST_CONST_HELPER_GFP_KERNEL = GFP_KERNEL;
2525
const gfp_t RUST_CONST_HELPER_GFP_KERNEL_ACCOUNT = GFP_KERNEL_ACCOUNT;
2626
const gfp_t RUST_CONST_HELPER_GFP_NOWAIT = GFP_NOWAIT;
2727
const gfp_t RUST_CONST_HELPER___GFP_ZERO = __GFP_ZERO;
28+
const gfp_t RUST_CONST_HELPER___GFP_HIGHMEM = ___GFP_HIGHMEM;

rust/kernel/alloc.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ pub mod flags {
5252
/// This is normally or'd with other flags.
5353
pub const __GFP_ZERO: Flags = Flags(bindings::__GFP_ZERO);
5454

55+
/// Allow the allocation to be in high memory.
56+
///
57+
/// Allocations in high memory may not be mapped into the kernel's address space, so this can't
58+
/// be used with `kmalloc` and other similar methods.
59+
///
60+
/// This is normally or'd with other flags.
61+
pub const __GFP_HIGHMEM: Flags = Flags(bindings::__GFP_HIGHMEM);
62+
5563
/// Users can not sleep and need the allocation to succeed.
5664
///
5765
/// A lower watermark is applied to allow access to "atomic reserves". The current

0 commit comments

Comments
 (0)