内存分配(memory allocation)

kmalloc()

  • 除非被阻塞,函数运行的很快;
  • 不会对所申请的内存空间清零,也就是说仍然保持原有数据;
  • 分配的区域在物理内存是连续的;

void *kmalloc(size_t size, int flag);

flag有很多可选符合,常用的有GFP_KERENL,GFP_ATOMIC

GFP_KERNEL:用于内核内存的通常分配方法,可能会睡眠;

GFP_ATOMIC:用于中断处理例程或其他运行于进程上下文之外的代码中分配内存,不会休眠;

后备高速缓存

linux内核的高速缓存管理有时候称为“slab分配器”。slab分配器实现的高速缓存具有kmem_cache_t类型,

可通过调用kmem_cache_creat创建:

  keme_cache_t *kmem_cache_creat(const char *name, size_t size, size_t offset, unsigned long flags,

                    void (*constructor)(), void (*destructor)());

————————

kmalloc()

  • Unless blocked, the function runs very fast;
  • The requested memory space will not be cleared, that is, the original data will still be maintained;
  • The allocated area is continuous in physical memory;

void *kmalloc(size_t size, int flag);

Flag has many options, including GFP_ KERENL,GFP_ ATOMIC

GFP_ Kernel: the usual allocation method for kernel memory, which may cause sleep;

GFP_ Atomic: used to allocate memory in interrupt processing routines or other code running outside the process context and will not sleep;

< strong > backup cache < / strong >

The cache management of Linux kernel is sometimes called “slab allocator”. The cache implemented by slab allocator has kmem_ cache_ T type,

You can call kmem_ cache_ Create:

  keme_cache_t *kmem_cache_creat(const char *name, size_t size, size_t offset, unsigned long flags,

void (*constructor)(), void (*destructor)());