歡迎您光臨本站 註冊首頁

linux kernel常用編碼模式

←手機掃碼閱讀     火星人 @ 2014-03-26 , reply:0

Memory Caches
當需要經常分配和釋放內存時,內核通常使用cache進行管理。而不是使用開銷非常大的kmalloc和kfee。

kmem_cache_alloc
kmem_cache_free

更多詳細的內容應該查看slab分配器。

向量定位
QUOTE:
struct abc {
int age;
char *name[20];
...
char placeholder[0];
}

The optional block starts with placeholder. Note that placeholder is defined as a vector of size 0. This means that when abc is allocated with the optional block, placeholder points to the beginning of the block. When no optional block is required, placeholder is just a pointer to the end of the structure;

條件語句優化
對於if判斷語句,根據概率可以使用likely and unlikely 進行優化,當true的概率大時使用likely,否則使用unlikely

捕捉bug
當BUG_TRAP 的條件 為false時,kernel將會列印警告信息。

[火星人 ] linux kernel常用編碼模式已經有502次圍觀

http://coctec.com/docs/linux/show-post-185599.html