Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2345472
  • 博文数量: 141
  • 博客积分: 3552
  • 博客等级: 中校
  • 技术积分: 4148
  • 用 户 组: 普通用户
  • 注册时间: 2009-07-15 14:39
个人简介

熟悉Linux下程序设计及各种应用程序 熟悉C Language 熟悉Glusterfs、FFmpeg、CDN 系统设计,计算机图形系统设计、分布式程序设计 目前主要研究方向:流媒体

文章分类

全部博文(141)

分类: LINUX

2010-08-08 18:37:29

#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");



KERNELDIR = /lib/modules/`uname -r`/build
PWD := $(shell pwd)
obj-m := slab.o

modules:
        $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
clean:
        rm -rf *.o *.ko Module.* module* *.mod.c


阅读(4038) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~