int __init vmm_mbufpool_init(void) { u32 slab, buf_size, buf_count, epool_sz; memset(&mbpctrl, 0, sizeof(mbpctrl)); /* Create mbuf pool */ mbpctrl.mpool = mempool_create(sizeof(struct vmm_mbuf), CONFIG_NET_MBUF_POOL_SIZE); if (!mbpctrl.mpool) { return VMM_ENOMEM; } /* Create ext slab pools */ epool_sz = (CONFIG_NET_MBUF_EXT_POOL_KB * 1024); for (slab = 0; slab < EPOOL_SLAB_COUNT; slab++) { buf_size = epool_slab_buf_size(slab); buf_count = epool_slab_buf_count(epool_sz, slab); if (buf_count && buf_size) { mbpctrl.epool_slabs[slab] = mempool_create(buf_size, buf_count); } else { mbpctrl.epool_slabs[slab] = NULL; } } return VMM_OK; }
/* bench_alltoall_init: */ int bench_alltoall_init(bench_t *bench) { int min, max, step = 0, steptype = -1; commsize = bench->getcommsize(bench); comm = bench->getcomm(bench); min = (mpiperf_param_min == -1) ? 1 : mpiperf_param_min; max = (mpiperf_param_max == -1) ? 1 << 18 : mpiperf_param_max; if (mpiperf_param_step_type == PARAM_STEP_INC) { steptype = SEQ_STEP_INC; step = (mpiperf_param_step == -1 || mpiperf_param_step == 0) ? 64 : mpiperf_param_step; } else if (mpiperf_param_step_type == PARAM_STEP_MUL) { steptype = SEQ_STEP_MUL; step = (mpiperf_param_step == -1 || mpiperf_param_step == 1) ? 2 : mpiperf_param_step; } if (intseq_initialize(bench, min, max, step, steptype) == MPIPERF_FAILURE) return MPIPERF_FAILURE; sbufpool = mempool_create(max * bench->getcommsize(bench), mpiperf_isflushcache); rbufpool = mempool_create(max * bench->getcommsize(bench), mpiperf_isflushcache); if (sbufpool == NULL || rbufpool == NULL) { mempool_free(sbufpool); mempool_free(rbufpool); return MPIPERF_FAILURE; } return MPIPERF_SUCCESS; }
int bench_ireduce_init(nbctest_params_t *params) { int rank; rbufpool = NULL; rbufsize = 0; sbufpool = mempool_create(params->count * sizeof(double), mpiperf_isflushcache); if (sbufpool == NULL) { return MPIPERF_FAILURE; } sbufsize = params->count * sizeof(double); MPI_Comm_rank(params->comm, &rank); if (rank == root) { rbufpool = mempool_create(params->count * sizeof(double), mpiperf_isflushcache); if (rbufpool == NULL) { mempool_free(sbufpool); return MPIPERF_FAILURE; } rbufsize = params->count * sizeof(double); } return MPIPERF_SUCCESS; }
/* initialize a table. */ int ht_init(hashtbl_t * tbl, size_t sz, unsigned int (*hash) (unsigned char *), void (*memfree) (void *)) { /* some things are required */ if (tbl == NULL || sz == 0) return 1; sz = ht_next_prime(sz); tbl->arr = xmalloc(sizeof(bstree_t *) * sz); memset(tbl->arr, 0, sizeof(bstree_t *) * sz); tbl->ht_elem_pool = mempool_create(sizeof(ht_elem_t) * 128); if (tbl->ht_elem_pool == NULL) return -1; /* since keys are free-form text, the pool size is arbitrary. */ tbl->key_pool = mempool_create(4096); if (tbl->key_pool == NULL) return -1; tbl->nelems = 0; tbl->arrsz = sz; tbl->free = memfree; /* NULL ok here */ if (hash) /* set a default hash function if none specified */ tbl->hash = hash; else tbl->hash = BKDRHash; return 0; }
int bench_ireduce_scatter_block_init(nbctest_params_t *params) { sbufpool = mempool_create(params->count * sizeof(double) * params->nprocs, mpiperf_isflushcache); rbufpool = mempool_create(params->count * sizeof(double), mpiperf_isflushcache); if (sbufpool == NULL || rbufpool == NULL) { mempool_free(sbufpool); mempool_free(rbufpool); return MPIPERF_FAILURE; } sbufsize = params->count * sizeof(double) * params->nprocs; rbufsize = params->count * sizeof(double); return MPIPERF_SUCCESS; }
/* bench_scatterv_init: */ int bench_scatterv_init(bench_t *bench) { int min, max, step = 0, steptype = -1; commsize = bench->getcommsize(bench); comm = bench->getcomm(bench); commrank = bench->getrank(bench); min = (mpiperf_param_min == -1) ? 1 : mpiperf_param_min; max = (mpiperf_param_max == -1) ? 1 << 18 : mpiperf_param_max; if (mpiperf_param_step_type == PARAM_STEP_INC) { steptype = SEQ_STEP_INC; step = (mpiperf_param_step == -1 || mpiperf_param_step == 0) ? 64 : mpiperf_param_step; } else if (mpiperf_param_step_type == PARAM_STEP_MUL) { steptype = SEQ_STEP_MUL; step = (mpiperf_param_step == -1 || mpiperf_param_step == 1) ? 2 : mpiperf_param_step; } if (intseq_initialize(bench, min, max, step, steptype) == MPIPERF_FAILURE) return MPIPERF_FAILURE; sendcounts = malloc(sizeof(*sendcounts) * bench->getcommsize(bench)); displs = malloc(sizeof(*displs) * bench->getcommsize(bench)); if (sendcounts == NULL || displs == NULL) { goto errhandler; } rbufpool = mempool_create(max, mpiperf_isflushcache); if (rbufpool == NULL) { goto errhandler; } if (commrank == root) { sbufpool = mempool_create(max * bench->getcommsize(bench), mpiperf_isflushcache); if (sbufpool == NULL) { goto errhandler; } } return MPIPERF_SUCCESS; errhandler: free(sendcounts); free(displs); mempool_free(sbufpool); mempool_free(rbufpool); return MPIPERF_FAILURE; }
/* bench_sendrecv_init: */ int bench_sendrecv_init(pt2pttest_params_t *params) { sbufsize = params->count * sizeof(char); rbufsize = params->count * sizeof(char); sbuf = mempool_create(params->count, mpiperf_isflushcache); rbuf = mempool_create(params->count, mpiperf_isflushcache); if (sbuf == NULL || rbuf == NULL) { mempool_free(sbuf); mempool_free(rbuf); return MPIPERF_FAILURE; } MPI_Comm_rank(params->comm, &rank); return MPIPERF_SUCCESS; }
static command_manager * cmd_mgr_create (aeEventLoop * el, redis_pool * pool, cluster_conf * conf, async_chan * my_async, array_async_chans * worker_asyncs, sbuf_hdr * shared_stream, int type) { command_manager *mgr; mgr = zmalloc (sizeof (command_manager)); mgr->el = el; mgr->cron_teid = aeCreateTimeEvent (el, 1000, cmd_cron, mgr, NULL); mgr->hz = GW_DEFAULT_HZ; mgr->cronloops = 0; mgr->pool = pool; mgr->commands = dictCreate (&commandTableDictType, NULL); populate_command_table (mgr->commands, type); mgr->conf = conf; mgr->my_async = my_async; mgr->worker_asyncs = worker_asyncs; mgr->shared_stream = shared_stream; mgr->idx_helper = index_helper_create (INDEX_HELPER_INIT_SIZE); memset (&mgr->stat, 0, sizeof (mgr->stat)); // Memory pool mgr->mp_cmdctx = mempool_create (sizeof (struct command_context), MEMPOOL_DEFAULT_POOL_SIZE); return mgr; }
void init_mempool() { int ret; ret = mempool_create(MEMPOOL_SIZE); if (ret < 0) dns_error(0, "create mempool failed"); }
int __init metapage_init(void) { /* * Allocate the metapage structures */ metapage_cache = kmem_cache_create("jfs_mp", sizeof(struct metapage), 0, 0, init_once, NULL); if (metapage_cache == NULL) return -ENOMEM; metapage_mempool = mempool_create(METAPOOL_MIN_PAGES, mempool_alloc_slab, mempool_free_slab, metapage_cache); if (metapage_mempool == NULL) { kmem_cache_destroy(metapage_cache); return -ENOMEM; } /* * Now the hash list */ for (hash_order = 0; ((PAGE_SIZE << hash_order) / sizeof(void *)) < HASH_SIZE; hash_order++); hash_table = (struct metapage **) __get_free_pages(GFP_KERNEL, hash_order); assert(hash_table); memset(hash_table, 0, PAGE_SIZE << hash_order); return 0; }
int __init mempool_create_init(void) { //创建一个名为"my_buffer"的slab缓存 kmem = kmem_cache_create("my_buffer",10000,0,SLAB_HWCACHE_ALIGN,NULL); if(kmem == NULL ) { printk("<0>kmem_cache_create failed!\n"); return 0; } else { printk("<0>kmem_cache_create scessfully!\n"); //基于创建的slab缓存创建一个包含5个初始元素的内存池 pool = mempool_create(5, mempool_alloc_slab, mempool_free_slab, kmem); if(pool == NULL ) { printk("<0>mempool_create failed!\n"); return 0; } else { printk("<0>mempool_create scessfully! min_nr = %d\n",pool->min_nr); } } return 0; }
PARSE * parse_make( LIST *(*func)( PARSE *p, LOL *args, int *jmp ), PARSE *left, PARSE *right, PARSE *third, const char *string, const char *string1, int num ) { #ifdef OPT_IMPROVED_MEMUSE_EXT PARSE *p; if (!parse_pool) { parse_pool = mempool_create("PARSE", sizeof(PARSE)); } p = mempool_alloc(parse_pool); #else PARSE *p = (PARSE *)malloc( sizeof( PARSE ) ); #endif p->func = func; p->left = left; p->right = right; p->third = third; p->string = string; p->string1 = string1; p->num = num; /* commented out so jamgram.y can compile #ifdef OPT_ACTION_MAXTARGETS_EXT */ p->num2 = p->num3 = 0; /* commented out so jamgram.y can compile #endif */ p->refs = 1; return p; }
static int cifs_init_mids(void) { cifs_mid_cachep = kmem_cache_create("cifs_mpx_ids", sizeof (struct mid_q_entry), 0, SLAB_HWCACHE_ALIGN, NULL, NULL); if (cifs_mid_cachep == NULL) return -ENOMEM; cifs_mid_poolp = mempool_create(3 /* a reasonable min simultan opers */, mempool_alloc_slab, mempool_free_slab, cifs_mid_cachep); if(cifs_mid_poolp == NULL) { kmem_cache_destroy(cifs_mid_cachep); return -ENOMEM; } cifs_oplock_cachep = kmem_cache_create("cifs_oplock_structs", sizeof (struct oplock_q_entry), 0, SLAB_HWCACHE_ALIGN, NULL, NULL); if (cifs_oplock_cachep == NULL) { kmem_cache_destroy(cifs_mid_cachep); mempool_destroy(cifs_mid_poolp); return -ENOMEM; } return 0; }
/* * Create a client with mempool and bioset. */ struct dm_io_client *dm_io_client_create(unsigned num_pages) { unsigned ios = pages_to_ios(num_pages); struct dm_io_client *client; client = kmalloc(sizeof(*client), GFP_KERNEL); if (!client) return ERR_PTR(-ENOMEM); client->pool = mempool_create(ios, alloc_io, free_io, NULL); if (!client->pool) goto bad; client->bios = bioset_create(16, 16, 4); if (!client->bios) goto bad; return client; bad: if (client->pool) mempool_destroy(client->pool); kfree(client); return ERR_PTR(-ENOMEM); }
mempool_t __export *mempool_create2(int size) { struct _mempool_t *p = (struct _mempool_t *)mempool_create(size); p->mmap = 1; return (mempool_t *)p; }
/* bench_gatherv_init: */ int bench_gatherv_init(colltest_params_t *params) { int rank, i; rbufpool = NULL; rbufsize = 0; recvcounts = NULL; displs = NULL; sbufpool = mempool_create(params->count, mpiperf_isflushcache); if (sbufpool == NULL) { goto errhandler; } sbufsize = params->count * sizeof(char); MPI_Comm_rank(params->comm, &rank); if (rank == root) { recvcounts = malloc(sizeof(*recvcounts) * params->nprocs); displs = malloc(sizeof(*displs) * params->nprocs); if (recvcounts == NULL || displs == NULL) { goto errhandler; } rbufpool = mempool_create(params->count * params->nprocs, mpiperf_isflushcache); if (rbufpool == NULL) { goto errhandler; } rbufsize = params->count * params->nprocs * sizeof(char); for (i = 0; i < params->nprocs; i++) { recvcounts[i] = params->count; } displs[0] = 0; for (i = 1; i < params->nprocs; i++) { displs[i] = displs[i - 1] + recvcounts[i - 1]; } } return MPIPERF_SUCCESS; errhandler: free(recvcounts); free(displs); mempool_free(sbufpool); mempool_free(rbufpool); return MPIPERF_FAILURE; }
/** * Initialize the object system. */ void object_init(void) { toolkit_import(mempool); pool_object = mempool_create("objects", NROF_ITEMS, sizeof(object), MEMPOOL_ALLOW_FREEING, NULL, NULL, NULL, NULL); objects_init(); }
int memp_init_cpu(void) { int cpu = percpu_get(cpu_id); if (mempool_create(&percpu_get(pbuf_mempool),&pbuf_ds,MEMPOOL_SANITY_PERCPU, cpu)) return 1; if (mempool_create(&percpu_get(pbuf_with_payload_mempool), &pbuf_with_payload_ds, MEMPOOL_SANITY_PERCPU, cpu)) return 1; if (mempool_create(&percpu_get(tcp_pcb_mempool), &tcp_pcb_ds, MEMPOOL_SANITY_PERCPU, cpu)) return 1; if (mempool_create(&percpu_get(tcp_seg_mempool), &tcp_seg_ds, MEMPOOL_SANITY_PERCPU, cpu)) return 1; return 0; }
int osInit(void *free_mem_start, u_int heap_size) { _osFreeMemAddr = ARM_MEM_ALIGN(free_mem_start); mempool_create(&systemHeapMemory, (char *)_osFreeMemAddr, heap_size); _osFreeMemAddr += ARM_MEM_ALIGN(heap_size); return TRUE; }
int ceph_msgpool_init(struct ceph_msgpool *pool, int front_len, int size, bool blocking, const char *name) { pool->front_len = front_len; pool->pool = mempool_create(size, alloc_fn, free_fn, pool); if (!pool->pool) return -ENOMEM; pool->name = name; return 0; }
void gui_event_init(void) { gui_epool = mempool_create(sizeof(gevent), CONFIG_GUI_EPSZ); INIT_LIST_HEAD(&gui_equeue_public); #ifdef CONFIG_DRIVER_PD pd_Init(); #endif key_Init(); }
/* alloc_disk and add_disk can sleep */ void aoeblk_gdalloc(void *vp) { struct aoedev *d = vp; struct gendisk *gd; ulong flags; gd = alloc_disk(AOE_PARTITIONS); if (gd == NULL) { printk(KERN_ERR "aoe: aoeblk_gdalloc: cannot allocate disk " "structure for %ld.%ld\n", d->aoemajor, d->aoeminor); spin_lock_irqsave(&d->lock, flags); d->flags &= ~DEVFL_WORKON; spin_unlock_irqrestore(&d->lock, flags); return; } d->bufpool = mempool_create(MIN_BUFS, mempool_alloc_slab, mempool_free_slab, buf_pool_cache); if (d->bufpool == NULL) { printk(KERN_ERR "aoe: aoeblk_gdalloc: cannot allocate bufpool " "for %ld.%ld\n", d->aoemajor, d->aoeminor); put_disk(gd); spin_lock_irqsave(&d->lock, flags); d->flags &= ~DEVFL_WORKON; spin_unlock_irqrestore(&d->lock, flags); return; } spin_lock_irqsave(&d->lock, flags); blk_queue_make_request(&d->blkq, aoeblk_make_request); gd->major = AOE_MAJOR; gd->first_minor = d->sysminor * AOE_PARTITIONS; gd->fops = &aoe_bdops; gd->private_data = d; gd->capacity = d->ssize; snprintf(gd->disk_name, sizeof gd->disk_name, "etherd/e%ld.%ld", d->aoemajor, d->aoeminor); gd->queue = &d->blkq; d->gd = gd; d->flags &= ~DEVFL_WORKON; d->flags |= DEVFL_UP; spin_unlock_irqrestore(&d->lock, flags); add_disk(gd); aoedisk_add_sysfs(d); printk(KERN_INFO "aoe: %012llx e%lu.%lu v%04x has %llu " "sectors\n", (unsigned long long)mac_addr(d->addr), d->aoemajor, d->aoeminor, d->fw_ver, (long long)d->ssize); }
int ceph_msgpool_init(struct ceph_msgpool *pool, int front_len, int size, bool blocking, const char *name) { dout("msgpool %s init\n", name); pool->front_len = front_len; pool->pool = mempool_create(size, msgpool_alloc, msgpool_free, pool); if (!pool->pool) return -ENOMEM; pool->name = name; return 0; }
void server_do() { recvbuf_pool = mempool_create("RECVBUF", recvbuf_size, 0); if(network_tcp_register(&sa, onaccept_proc, NULL)!=ERR_NOERROR) { printf("Failed to network_tcp_register.\n"); exit(0); } getchar(); network_tcp_unregister(&sa); mempool_destroy(recvbuf_pool); }
/* * gets called "every" time someone init's a queue with BLK_BOUNCE_ISA * as the max address, so check if the pool has already been created. */ int init_emergency_isa_pool(void) { if (isa_page_pool) return 0; isa_page_pool = mempool_create(ISA_POOL_SIZE, page_pool_alloc, page_pool_free, (void *) __GFP_DMA); if (!isa_page_pool) BUG(); printk("isa bounce pool size: %d pages\n", ISA_POOL_SIZE); return 0; }
int init_mod(void) { cache_ptr=kmem_cache_create("cache_mem1",var,0,SLAB_HWCACHE_ALIGN,NULL); mem=mempool_create(20,mempool_alloc_slab,mempool_free_slab,cache_ptr); if(mem==NULL) return -ENOMEM; printk("\nModule loaded"); func(); return SUCCESS; }
/* * gets called "every" time someone init's a queue with BLK_BOUNCE_ISA * as the max address, so check if the pool has already been created. */ int init_emergency_isa_pool(void) { if (isa_page_pool) return 0; isa_page_pool = mempool_create(ISA_POOL_SIZE, mempool_alloc_pages_isa, mempool_free_pages, (void *) 0); BUG_ON(!isa_page_pool); pr_info("isa pool size: %d pages\n", ISA_POOL_SIZE); return 0; }
/** Initialize the small allocator. */ void small_alloc_create(struct small_alloc *alloc, struct slab_cache *cache, uint32_t objsize_min, float alloc_factor) { alloc->cache = cache; /* Align sizes. */ objsize_min = small_align(objsize_min, STEP_SIZE); /* Make sure at least 4 largest objects can fit in a slab. */ alloc->objsize_max = mempool_objsize_max(slab_order_size(cache, cache->order_max)); assert(alloc->objsize_max > objsize_min + STEP_POOL_MAX * STEP_SIZE); struct mempool *step_pool; for (step_pool = alloc->step_pools; step_pool < alloc->step_pools + STEP_POOL_MAX; step_pool++) { mempool_create(step_pool, alloc->cache, objsize_min); objsize_min += STEP_SIZE; } alloc->step_pool_objsize_max = (step_pool - 1)->objsize; if (alloc_factor > 2.0) alloc_factor = 2.0; /* * Correct the user-supplied alloc_factor to ensure that * it actually produces growing object sizes. */ if (alloc->step_pool_objsize_max * alloc_factor < alloc->step_pool_objsize_max + STEP_SIZE) { alloc_factor = (alloc->step_pool_objsize_max + STEP_SIZE + 0.5)/ alloc->step_pool_objsize_max; } alloc->factor = alloc_factor; /* Initialize the factored pool cache. */ struct factor_pool *factor_pool = alloc->factor_pool_cache; do { factor_pool->next = factor_pool + 1; factor_pool++; } while (factor_pool != alloc->factor_pool_cache + FACTOR_POOL_MAX - 1); factor_pool->next = NULL; alloc->factor_pool_next = alloc->factor_pool_cache; factor_tree_new(&alloc->factor_pools); (void) factor_pool_create(alloc, NULL, alloc->objsize_max); lifo_init(&alloc->delayed); alloc->is_delayed_free_mode = false; }
LIST * list_new( LIST *head, const char *string, int copy ) { LIST *l; if( DEBUG_LISTS ) printf( "list > %s <\n", string ); /* Copy/newstr as needed */ string = copy ? copystr( string ) : newstr( string ); /* Get list struct from freelist, if one available. */ /* Otherwise allocate. */ /* If from freelist, must free string first */ if( freelist ) { l = freelist; freestr( l->string ); freelist = freelist->next; } else { #ifdef OPT_IMPROVED_MEMUSE_EXT if (!list_pool) { list_pool = mempool_create("LIST", sizeof(LIST)); } l = mempool_alloc(list_pool); #else l = (LIST *)malloc( sizeof( *l ) ); #endif } /* If first on chain, head points here. */ /* If adding to chain, tack us on. */ /* Tail must point to this new, last element. */ if( !head ) head = l; else head->tail->next = l; head->tail = l; l->next = 0; l->string = string; return head; }
/* bench_scatter_init: */ int bench_scatter_init(colltest_params_t *params) { int rank; sbufpool = NULL; sbufsize = 0; MPI_Comm_rank(params->comm, &rank); if (rank == root) { sbufpool = mempool_create(params->count * params->nprocs, mpiperf_isflushcache); if (sbufpool == NULL) { return MPIPERF_FAILURE; } sbufsize = params->count * sizeof(char); } rbufpool = mempool_create(params->count, mpiperf_isflushcache); if (rbufpool == NULL) { mempool_free(sbufpool); return MPIPERF_FAILURE; } rbufsize = params->count * sizeof(char); return MPIPERF_SUCCESS; }