documentation:memory_allocation
=>  Releases

Current version
Git/Latestdiff: 1.5.6

Latest Snapshots
Produced after each commit or rebase to new upstream version

GIT
RSBAC source code, can be unstable sometimes

=>  Events

No events planned

Basics

For different tasks it is necessary to allocate a chunk of memory. Especially in the Linux kernel, stack space is pretty tight, so you quite often cannot simply declare some large variable and hope it works out.

The usual way to allocate kernel memory is using kmalloc/kfree for rather small amounts (allocated continuously as real memory) and vmalloc/vfree (virtual memory) for large sizes. Unfortunately, you have to find out yourself, which method is better. kmalloc will fail, if you try to allocate more than 128M - anyway, continous memory of several pages might be difficult to get.

RSBAC memory allocation

RSBAC provides some own memory management functions. These functions also get exported for modules, if REG support has been enabled.

In kernel versions from 2.4.0, separate RSBAC memory slabs are used for kmalloc style memory to provide better control of memory usage through /proc/slabinfo.

  • All functions are defined here:
#include <rsbac/rkmem.h>
  • rsbac_kmalloc works like kmalloc with second parameter GFP_KERNEL.
void * rsbac_kmalloc (size_t size);
  • rsbac_kfree is used like kfree - please make sure you do not call it with wrong pointers
void rsbac_kfree (const void *objp);
  • rsbac_vkmalloc allocates via rsbac_kmalloc for small sizes (up to RSBAC_MAX_KMALLOC) and via vmalloc for larger sizes. Whether vmalloc has been used is put into *vmalloc_used_p as boolean value TRUE or FALSE
void * rsbac_vkmalloc
 (size_t size, boolean * vmalloc_used_p);
  • rsbac_vkfree is used to free such memory. To know the memory type, it needs the boolean value vmalloc_used from rsbac_vkmalloc
void rsbac_vkfree (void *objp, boolean vmalloc_used);
//
documentation/memory_allocation.txt · Last modified: 2006/05/02 15:40 (external edit)

documentation/memory_allocation.txt · Last modified: 2006/05/02 15:40 (external edit)
This website is kindly hosted by m-privacy