Contents
How is memory allocated in the Linux kernel?
Linux provides a variety of APIs for memory allocation. You can allocate small chunks using kmalloc or kmem_cache_alloc families, large virtually contiguous areas using vmalloc and its derivatives, or you can directly request pages from the page allocator with alloc_pages .
How to allocate memory in kvmalloc in Linux?
Note that kvmalloc may return memory that is not physically contiguous. If you need to allocate many identical objects you can use the slab cache allocator. The cache should be set up with kmem_cache_create () or kmem_cache_create_usercopy () before it can be used.
When to use GFP _ kernel in memory allocation?
Note, that using GFP_KERNEL implies GFP_RECLAIM, which means that direct reclaim may be triggered under memory pressure; the calling context must be allowed to sleep. If the allocation is performed from an atomic context, e.g interrupt handler, use GFP_NOWAIT.
How to account for untrusted memory allocations in Linux?
Untrusted allocations triggered from userspace should be a subject of kmem accounting and must have __GFP_ACCOUNT bit set. There is the handy GFP_KERNEL_ACCOUNT shortcut for GFP_KERNEL allocations that should be accounted.
What does it mean to allocate non cached memory?
Non-cached memory means the CPU never uses the onboard cache, and always goes out on the main memory bus. You do want to allocate memory and probe and lock it, but not non-cached memory.
How to allocate memory in kernel mode under x64?
Ok, under x64 I can just use ExAllocatePoolWithTag. I read another thread and wrote this test function: I hoped, MmProbeAndLockPages () would make the allocated buffer unoupageable and fast, but it is actually slower as a buffer in paged pool allocated with ExAllocatePoolWithTag even without MmProbeAndLockPages ().
Why does the definition of kernel include bandwidth?
MSE-equivalent bandwidths (for different kernels) are proportional to σ K R ( K) which is scale invariant and for our kernels equal to R ( K). Saying this in plain English: different kernels, in their “raw” form, have different standard deviations σ K.
How to find the size of a kernel module?
Also we can get a size value for Kernel modules (unclear whether it’s their size from on disk or when in RAM) by pulling these values from /proc/modules: Much of the details about the SLAB are accessible in this proc structure, /proc/slabinfo: