linux内核函数kmalloc,Linux_Linux平台上几个常见内核内存分配函数,* kmallocPrototype:#incl - phpStudy...
Linux平臺(tái)上幾個(gè)常見內(nèi)核內(nèi)存分配函數(shù)
* kmalloc
Prototype:
#include
void *kmalloc(size_t size, int flags);
Kmalloc分配一段未清0的連續(xù)物理內(nèi)存頁,并返回虛存地址。有點(diǎn)是快,并且可指定flag,如DMA內(nèi)存,高地址區(qū)域內(nèi)存等。缺點(diǎn)是不能分配大于128KB(處于跨平臺(tái)考慮),幾個(gè)重要的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的實(shí)現(xiàn)知道有這么一個(gè)內(nèi)存管理策略,其顯著特點(diǎn)是分配一組相同大小的內(nèi)存塊作為內(nèi)存池,其實(shí)現(xiàn)對(duì)應(yīng)于源代碼中的和mm/slab.c。
Prototype:
#include
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);
返回2^order個(gè)未清0連續(xù)物理頁面,flags與kmalloc中flags一致,允許的最大order值為10或者11(根據(jù)體系結(jié)構(gòu)不同)
*alloc_pages
Prototype:
struct page *alloc_pages_node(int nid, unsigned int flags,
unsigned int order);
Kernel中頁分配器實(shí)現(xiàn),__get_free_pages即調(diào)用alloc_pages實(shí)現(xiàn)的
The real core of the Linux page allocator is a function called alloc_pages_node:
*vmalloc
分配地址連續(xù)虛存,而不保證物理地址連續(xù),大部分情況下適合“軟件”,而不是驅(qū)動(dòng)程序。相對(duì)而言,kmalloc和__get_free_pages虛存map到物理內(nèi)存只需要增減一個(gè)偏移,而使用vmalloc分配需要修改頁表,故vmalloc的開銷較大,分配少數(shù)幾個(gè)頁面的效率太低。
*per-cpu variables
Each cpu hold an independant copy in their respective processor's caches, so there is no lock required and improve better performance, implemented as a linux 2.6 feature. Defined in .
DEFINE_PER_CPU(type, name);
get_cpu_var(sockets_in_use)++;
put_cpu_var(sockets_in_use);相關(guān)閱讀:
PHP完整的日歷類(CLASS)
function, new function, new Function之間的區(qū)別
解析CSS列表樣式屬性list-style
discuz7 phpMysql操作類
LumaQQ的安裝和使用
MYSQL導(dǎo)入導(dǎo)出命令詳解
css利用A標(biāo)簽的背景可能作出很有意思的效果
javascript做的日歷,完全對(duì)象化,望高手提出改進(jìn)意見。(1/3,將3部分拼成一個(gè)html文件瀏覽)_QQGB.co
在Access2007中使用“多值”實(shí)現(xiàn)文字的sum
oracle時(shí)間用法
JavaScript教程:淺析JS運(yùn)行機(jī)制
GhostXP裝機(jī)版v3.0
查找亂碼字符串的SQL
Vormetric推出Oracle和SQL Server數(shù)據(jù)庫安全包
總結(jié)
以上是生活随笔為你收集整理的linux内核函数kmalloc,Linux_Linux平台上几个常见内核内存分配函数,* kmallocPrototype:#incl - phpStudy...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 一套 89 元,小米无线键鼠套装 2 今
- 下一篇: linux7.0ftp,Linux(Ce