示例#1
0
static int
glusterfs_ctx_defaults_init (glusterfs_ctx_t *ctx)
{
        cmd_args_t    *cmd_args = NULL;
        struct rlimit  lim = {0, };
        call_pool_t   *pool = NULL;

        xlator_mem_acct_init (THIS, cli_mt_end);

        ctx->process_uuid = generate_uuid ();
        if (!ctx->process_uuid)
                return -1;

        ctx->page_size  = 128 * GF_UNIT_KB;

        ctx->iobuf_pool = iobuf_pool_new (8 * GF_UNIT_MB, ctx->page_size);
        if (!ctx->iobuf_pool)
                return -1;

        ctx->event_pool = event_pool_new (DEFAULT_EVENT_POOL_SIZE);
        if (!ctx->event_pool)
                return -1;

        pool = GF_CALLOC (1, sizeof (call_pool_t),
                          cli_mt_call_pool_t);
        if (!pool)
                return -1;

        /* frame_mem_pool size 112 * 16k */
        pool->frame_mem_pool = mem_pool_new (call_frame_t, 16384);

        if (!pool->frame_mem_pool)
                return -1;

        /* stack_mem_pool size 256 * 8k */
        pool->stack_mem_pool = mem_pool_new (call_stack_t, 8192); 

        if (!pool->stack_mem_pool)
                return -1;

        ctx->stub_mem_pool = mem_pool_new (call_stub_t, 1024);
        if (!ctx->stub_mem_pool)
                return -1;

        INIT_LIST_HEAD (&pool->all_frames);
        LOCK_INIT (&pool->lock);
        ctx->pool = pool;

        pthread_mutex_init (&(ctx->lock), NULL);

        cmd_args = &ctx->cmd_args;

        INIT_LIST_HEAD (&cmd_args->xlator_options);

        lim.rlim_cur = RLIM_INFINITY;
        lim.rlim_max = RLIM_INFINITY;
        setrlimit (RLIMIT_CORE, &lim);

        return 0;
}
示例#2
0
int32_t main(int32_t argc, char **argv)
{
      
    struct mem_pool *test_mem_pool;
    struct mem_pool *test_mem_pool_2;
    struct mem_pool *test_mem_pool_3;
    gf_mem_init_mempool_list();
    gf_mem_acct_enable_set ();
    signals_setup();
    mem_acct_init(gf_common_mt_end+1);
    test_mem_t ** mem_array   = CALLOC(size,sizeof(test_mem_t * )); 
    test_mem_2_t ** mem_array2  = CALLOC(size,sizeof(test_mem_2_t * ));
    test_mem_3_t ** mem_array3  = CALLOC(size,sizeof(test_mem_3_t * ));
    int j;
    int i;
    CPU_TIME_START;
    test_mem_pool = mem_pool_new (test_mem_t, size);
    test_mem_pool_2 = mem_pool_new (test_mem_2_t, size);
    test_mem_pool_3 = mem_pool_new (test_mem_3_t, size);
    CPU_TIME_END_PRINT("mem pool");
    CPU_TIME_START;
    for(j=0; j<10000; j++){    
            if (!test_mem_pool)
            {
                DBG_PRINT("create mem pool error");
                return -1;
            }
        for(i=0; i<size; i++)
            mem_array[i] = (test_mem_t *)mem_get(test_mem_pool);
            mem_array2[i] = (test_mem_2_t *)mem_get(test_mem_pool_2);
            mem_array3[i] = (test_mem_3_t *)mem_get(test_mem_pool_3);
        for(i=0; i<size; i++)
            mem_put(mem_array[i]) ;
            mem_put(mem_array2[i]) ;
            mem_put(mem_array3[i]) ;
        
    }
    CPU_TIME_END_PRINT("mem pool");
    mem_pool_destroy(test_mem_pool);
    mem_pool_destroy(test_mem_pool_2);
    mem_pool_destroy(test_mem_pool_3);
    CPU_TIME_START;
    for(j=0; j<100; j++){
        for(i=0; i<size; i++)
            mem_array[i] = (test_mem_t *)MALLOC(sizeof(test_mem_t));
            mem_array2[i] = (test_mem_2_t *)MALLOC(sizeof(test_mem_2_t));
            mem_array3[i] = (test_mem_3_t *)MALLOC(sizeof(test_mem_3_t));
        for(i=0; i<size; i++)
            free (mem_array[i]);
            free (mem_array2[i]);
            free (mem_array3[i]);
    }
    CPU_TIME_END_PRINT("not mem pool");
    
    //getchar();
    return 0;
}
示例#3
0
int main(int argc, char * argv[]) {
    struct mem_pool * pool = mem_pool_new(4);

    int r1,r2,r3,r4;

    r1 = mem_pool_alloc(pool, 16);
    printb(pool, r1);

    r2 = mem_pool_alloc(pool, 32);
    printb(pool, r2);

    r3 = mem_pool_alloc(pool, 16);
    printb(pool, r3);

    mem_pool_free(pool, r1);
    mem_pool_free(pool, r3);

    r4 = mem_pool_alloc(pool, 32);
    printb(pool, r4);

    mem_pool_destroy(pool);
    return 0;
}
示例#4
0
static int
glusterfs_ctx_defaults_init (glusterfs_ctx_t *ctx)
{
        cmd_args_t    *cmd_args = NULL;
        struct rlimit  lim = {0, };
        call_pool_t   *pool = NULL;
        int            ret         = -1;

        ret = xlator_mem_acct_init (THIS, cli_mt_end);
        if (ret != 0) {
                return ret;
        }

        ctx->process_uuid = generate_glusterfs_ctx_id ();
        if (!ctx->process_uuid)
                return -1;

        ctx->page_size  = 128 * GF_UNIT_KB;

        ctx->iobuf_pool = iobuf_pool_new ();
        if (!ctx->iobuf_pool)
                return -1;

        ctx->event_pool = event_pool_new (DEFAULT_EVENT_POOL_SIZE,
                                          STARTING_EVENT_THREADS);
        if (!ctx->event_pool)
                return -1;

        pool = GF_CALLOC (1, sizeof (call_pool_t),
                          cli_mt_call_pool_t);
        if (!pool)
                return -1;

        /* frame_mem_pool size 112 * 64 */
        pool->frame_mem_pool = mem_pool_new (call_frame_t, 32);
        if (!pool->frame_mem_pool)
                return -1;

        /* stack_mem_pool size 256 * 128 */
        pool->stack_mem_pool = mem_pool_new (call_stack_t, 16);

        if (!pool->stack_mem_pool)
                return -1;

        ctx->stub_mem_pool = mem_pool_new (call_stub_t, 16);
        if (!ctx->stub_mem_pool)
                return -1;

        ctx->dict_pool = mem_pool_new (dict_t, 32);
        if (!ctx->dict_pool)
                return -1;

        ctx->dict_pair_pool = mem_pool_new (data_pair_t, 512);
        if (!ctx->dict_pair_pool)
                return -1;

        ctx->dict_data_pool = mem_pool_new (data_t, 512);
        if (!ctx->dict_data_pool)
                return -1;

        ctx->logbuf_pool = mem_pool_new (log_buf_t, 256);
        if (!ctx->logbuf_pool)
                return -1;

        INIT_LIST_HEAD (&pool->all_frames);
        LOCK_INIT (&pool->lock);
        ctx->pool = pool;

        pthread_mutex_init (&(ctx->lock), NULL);

        cmd_args = &ctx->cmd_args;

        INIT_LIST_HEAD (&cmd_args->xlator_options);

        lim.rlim_cur = RLIM_INFINITY;
        lim.rlim_max = RLIM_INFINITY;
        setrlimit (RLIMIT_CORE, &lim);

        return 0;
}
示例#5
0
rbthash_table_t *
rbthash_table_init (int buckets, rbt_hasher_t hfunc,
                    rbt_data_destroyer_t dfunc,
                    unsigned long expected_entries,
                    struct mem_pool *entrypool)
{
        rbthash_table_t         *newtab = NULL;
        int                     ret = -1;

        if (!hfunc) {
                gf_log (GF_RBTHASH, GF_LOG_ERROR, "Hash function not given");
                return NULL;
        }

        if (!entrypool && !expected_entries) {
                gf_log (GF_RBTHASH, GF_LOG_ERROR,
                        "Both mem-pool and expected entries not provided");
                return NULL;
        }

        if (entrypool && expected_entries) {
                gf_log (GF_RBTHASH, GF_LOG_ERROR,
                        "Both mem-pool and expected entries are provided");
                return NULL;
        }


        newtab = GF_CALLOC (1, sizeof (*newtab),
                            gf_common_mt_rbthash_table_t);
        if (!newtab)
                return NULL;

        newtab->buckets = GF_CALLOC (buckets, sizeof (struct rbthash_bucket),
                                     gf_common_mt_rbthash_bucket);
        if (!newtab->buckets) {
                goto free_newtab;
        }

        if (expected_entries) {
                newtab->entrypool =
                        mem_pool_new (rbthash_entry_t, expected_entries);
                if (!newtab->entrypool) {
                        gf_log (GF_RBTHASH, GF_LOG_ERROR,
                                "Failed to allocate mem-pool");
                        goto free_buckets;
                }
                newtab->pool_alloced = _gf_true;
        } else {
                newtab->entrypool = entrypool;
        }

        LOCK_INIT (&newtab->tablelock);
        newtab->numbuckets = buckets;
        ret = __rbthash_init_buckets (newtab, buckets);

        if (ret == -1) {
                gf_log (GF_RBTHASH, GF_LOG_ERROR, "Failed to init buckets");
                if (newtab->pool_alloced)
                        mem_pool_destroy (newtab->entrypool);
        } else {
                gf_log (GF_RBTHASH, GF_LOG_TRACE, "Inited hash table: buckets:"
                        " %d", buckets);
        }

        newtab->hashfunc = hfunc;
        newtab->dfunc = dfunc;

free_buckets:
        if (ret == -1)
                GF_FREE (newtab->buckets);

free_newtab:
        if (ret == -1) {
                GF_FREE (newtab);
                newtab = NULL;
        }

        return newtab;
}
示例#6
0
static int
glusterfs_ctx_defaults_init (glusterfs_ctx_t *ctx)
{
    cmd_args_t    *cmd_args = NULL;
    struct rlimit  lim = {0, };
    call_pool_t   *pool = NULL;

    xlator_mem_acct_init (THIS, gfd_mt_end);

    ctx->process_uuid = generate_uuid ();
    if (!ctx->process_uuid)
        return -1;

    ctx->page_size  = 128 * GF_UNIT_KB;

    ctx->iobuf_pool = iobuf_pool_new (8 * GF_UNIT_MB, ctx->page_size);
    if (!ctx->iobuf_pool)
        return -1;

    ctx->event_pool = event_pool_new (DEFAULT_EVENT_POOL_SIZE);
    if (!ctx->event_pool)
        return -1;

    pool = GF_CALLOC (1, sizeof (call_pool_t),
                      gfd_mt_call_pool_t);
    if (!pool)
        return -1;

    /* frame_mem_pool size 112 * 16k */
    pool->frame_mem_pool = mem_pool_new (call_frame_t, 16384);

    if (!pool->frame_mem_pool)
        return -1;

    /* stack_mem_pool size 256 * 8k */
    pool->stack_mem_pool = mem_pool_new (call_stack_t, 8192);

    if (!pool->stack_mem_pool)
        return -1;

    ctx->stub_mem_pool = mem_pool_new (call_stub_t, 1024);
    if (!ctx->stub_mem_pool)
        return -1;

    INIT_LIST_HEAD (&pool->all_frames);
    LOCK_INIT (&pool->lock);
    ctx->pool = pool;

    pthread_mutex_init (&(ctx->lock), NULL);

    cmd_args = &ctx->cmd_args;

    /* parsing command line arguments */
    cmd_args->log_level = DEFAULT_LOG_LEVEL;
#ifdef GF_DARWIN_HOST_OS
    cmd_args->mac_compat = GF_OPTION_DEFERRED;
    /* On Darwin machines, O_APPEND is not handled,
     * which may corrupt the data
     */
    cmd_args->fuse_direct_io_mode = GF_OPTION_DISABLE;
#else
    cmd_args->mac_compat = GF_OPTION_DISABLE;
    cmd_args->fuse_direct_io_mode = GF_OPTION_DEFERRED;
#endif
    cmd_args->fuse_attribute_timeout = -1;
    cmd_args->fuse_entry_timeout = -1;

    INIT_LIST_HEAD (&cmd_args->xlator_options);

    lim.rlim_cur = RLIM_INFINITY;
    lim.rlim_max = RLIM_INFINITY;
    setrlimit (RLIMIT_CORE, &lim);

    return 0;
}