手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

Linux平台上几个常见内核内存分配函数

[日期:2010-02-07] 来源:Linux社区  作者:Linux [字体:大 中 小]

  * kmalloc

  Prototype:

  #include <linux/slab.h>

  void *kmalloc(size_t size, int flags);

  Kmalloc分配一段未清0的连续物理内存页,并返回虚存地址。有点是快,并且可指定flag,如DMA内存,高地址区域内存等。缺点是不能分配大于128KB(处于跨平台考虑),几个重要的flag:

  GFP_ATOMIC

  Used to allocate memory from interrupt handlers and other code outside of a process context. Never sleeps.

  GFP_KERNEL

  Normal allocation of kernel memory. May sleep.

  GFP_USER

  Used to allocate memory for user-space pages; it may sleep.

  GFP_HIGHUSER

  Like GFP_USER, but allocates from high memory, if any. High memory is described in the next subsection.

  * slab allocator(lookaside cache)

  从Memcached的实现知道有这么一个内存管理策略,其显着特点是分配一组相同大小的内存块作为内存池,其实现对应于源代码中的<linux/slab.h>和mm/slab.c。

  Prototype:

  #include <linux/malloc.h>

  kmem_cache_t *kmem_cache_create(char *name, size_t size, size_t offset,

  unsigned long flags, constructor( ), destructor( ));

  int kmem_cache_destroy(kmem_cache_t *cache);

  /proc/slabinfo

  A virtual file containing statistics on slab cache usage.

  *__get_free_pages

  Prototype:

  _ _get_free_pages(unsigned int flags, unsigned int order);

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款