前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >slab的简单使用

slab的简单使用

作者头像
用户3765803
发布2019-03-05 10:11:41
8390
发布2019-03-05 10:11:41
举报
文章被收录于专栏:悟空被FFmpeg玩悟空被FFmpeg玩

#include <linux/module.h> #include <linux/init.h> #include <linux/kernel.h> #include <linux/slab.h> #include <linux/fs.h> #define CUTBAG_DIR "CU_T-bagwell" #define MAX_STRING_TEST 20 static struct kmem_cache *T_bagwell_slab_test; struct test{         int count;         unsigned char test_string[MAX_STRING_TEST]; }; struct test *test_for_cu; static int __init test_init(void) {         T_bagwell_slab_test = kmem_cache_create(CUTBAG_DIR,                         sizeof(struct test),                         0, SLAB_RECLAIM_ACCOUNT, NULL                         );         if(!T_bagwell_slab_test){                 printk(KERN_WARNING "kmem_cache_create faild\n");                 return -1;         }         test_for_cu = kmem_cache_alloc(T_bagwell_slab_test, GFP_KERNEL);         if(!test_for_cu){                 printk(KERN_WARNING "kmem_cache_alloc faild\n");                 kmem_cache_destroy(T_bagwell_slab_test);                 return -1;         }         memset(test_for_cu, 0 ,sizeof(struct test));         test_for_cu->count = 100;         memcpy(test_for_cu->test_string, "test_for_chinaunix", MAX_STRING_TEST);         return 0; } static void __exit test_cleanup(void) {         printk(KERN_WARNING "%s %d\n", test_for_cu->test_string, test_for_cu->count);         kmem_cache_free(T_bagwell_slab_test, test_for_cu);         kmem_cache_destroy(T_bagwell_slab_test); } module_init(test_init); module_exit(test_cleanup); MODULE_LICENSE("GPL");

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2010/08/08 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档