void *obj_alloc( void ) { switch( mode ) { case 0: return mempool_alloc_slab( GFP_KERNEL, cache ); case 1: return mempool_kmalloc( GFP_KERNEL, (void*)size ); } return NULL; };
int __init mempool_kmalloc_init(void) { pool_data = (int *)8192; //设置分配的内存空间大小 element = mempool_kmalloc( GFP_KERNEL ,pool_data ); //分配一个内存元素 if( element != NULL ) printk("<0>element = 0x%lx\n",(unsigned long)element); //输出起始地址 else printk("<0>mempool_kmalloc failed!\n"); return 0; }