📄 erl_alloc_util.c
字号:
#ifdef DEBUG for (atom = (Eterm *) &am; atom < &am.end_of_atoms; atom++) { ASSERT(*atom != THE_NON_VALUE); }#endif } if (allctr) { make_name_atoms(allctr); (*allctr->init_atoms)();#ifdef USE_THREADS if (allctr->thread_safe) erts_mtx_lock(&allctr->mutex);#endif allctr->atoms_initialized = 1; } atoms_initialized = 1; erts_mtx_unlock(&init_atoms_mtx);}static ERTS_INLINE voidensure_atoms_initialized(Allctr_t *allctr){ if (!allctr || !allctr->atoms_initialized) init_atoms(allctr);}#define bld_uint erts_bld_uint#define bld_cons erts_bld_cons#define bld_tuple erts_bld_tuple#define bld_string erts_bld_string/* * bld_unstable_uint() (instead bld_uint()) is used when values may * change between size check and actual build. This because a value * that would fit a small when size check is done may need to be built * as a big when the actual build is performed. Caller is required to * HRelease after build. */static ERTS_INLINE Etermbld_unstable_uint(Uint **hpp, Uint *szp, Uint ui){ Eterm res = THE_NON_VALUE; if (szp) *szp += BIG_UINT_HEAP_SIZE; if (hpp) { if (IS_USMALL(0, ui)) res = make_small(ui); else { res = uint_to_big(ui, *hpp); *hpp += BIG_UINT_HEAP_SIZE; } } return res;}static ERTS_INLINE voidadd_2tup(Uint **hpp, Uint *szp, Eterm *lp, Eterm el1, Eterm el2){ *lp = bld_cons(hpp, szp, bld_tuple(hpp, szp, 2, el1, el2), *lp);}static ERTS_INLINE voidadd_3tup(Uint **hpp, Uint *szp, Eterm *lp, Eterm el1, Eterm el2, Eterm el3){ *lp = bld_cons(hpp, szp, bld_tuple(hpp, szp, 3, el1, el2, el3), *lp);}static ERTS_INLINE voidadd_4tup(Uint **hpp, Uint *szp, Eterm *lp, Eterm el1, Eterm el2, Eterm el3, Eterm el4){ *lp = bld_cons(hpp, szp, bld_tuple(hpp, szp, 4, el1, el2, el3, el4), *lp);}static Eterminfo_carriers(Allctr_t *allctr, CarriersStats_t *cs, char *prefix, int *print_to_p, void *print_to_arg, Uint **hpp, Uint *szp){ Eterm res = THE_NON_VALUE; Uint curr_no = cs->curr_mseg.no + cs->curr_sys_alloc.no; Uint curr_size = cs->curr_mseg.size + cs->curr_sys_alloc.size; if (print_to_p) { int to = *print_to_p; void *arg = print_to_arg; erts_print(to, arg, "%sblocks: %bpu %bpu %bpu\n", prefix, cs->blocks.curr.no, cs->blocks.max.no, cs->blocks.max_ever.no); erts_print(to, arg, "%sblocks size: %bpu %bpu %bpu\n", prefix, cs->blocks.curr.size, cs->blocks.max.size, cs->blocks.max_ever.size); erts_print(to, arg, "%scarriers: %bpu %bpu %bpu\n", prefix, curr_no, cs->max.no, cs->max_ever.no);#if HAVE_ERTS_MSEG erts_print(to, arg, "%smseg carriers: %bpu\n", prefix, cs->curr_mseg.no);#endif erts_print(to, arg, "%ssys_alloc carriers: %bpu\n", prefix, cs->curr_sys_alloc.no); erts_print(to, arg, "%scarriers size: %bpu %bpu %bpu\n", prefix, curr_size, cs->max.size, cs->max_ever.size);#if HAVE_ERTS_MSEG erts_print(to, arg, "%smseg carriers size: %bpu\n", prefix, cs->curr_mseg.size);#endif erts_print(to, arg, "%ssys_alloc carriers size: %bpu\n", prefix, cs->curr_sys_alloc.size); } if (hpp || szp) { res = NIL; add_2tup(hpp, szp, &res, am.sys_alloc_carriers_size, bld_unstable_uint(hpp, szp, cs->curr_sys_alloc.size));#if HAVE_ERTS_MSEG add_2tup(hpp, szp, &res, am.mseg_alloc_carriers_size, bld_unstable_uint(hpp, szp, cs->curr_mseg.size));#endif add_4tup(hpp, szp, &res, am.carriers_size, bld_unstable_uint(hpp, szp, curr_size), bld_unstable_uint(hpp, szp, cs->max.size), bld_unstable_uint(hpp, szp, cs->max_ever.size)); add_2tup(hpp, szp, &res, am.sys_alloc_carriers, bld_unstable_uint(hpp, szp, cs->curr_sys_alloc.no));#if HAVE_ERTS_MSEG add_2tup(hpp, szp, &res, am.mseg_alloc_carriers, bld_unstable_uint(hpp, szp, cs->curr_mseg.no));#endif add_4tup(hpp, szp, &res, am.carriers, bld_unstable_uint(hpp, szp, curr_no), bld_unstable_uint(hpp, szp, cs->max.no), bld_unstable_uint(hpp, szp, cs->max_ever.no)); add_4tup(hpp, szp, &res, am.blocks_size, bld_unstable_uint(hpp, szp, cs->blocks.curr.size), bld_unstable_uint(hpp, szp, cs->blocks.max.size), bld_unstable_uint(hpp, szp, cs->blocks.max_ever.size)); add_4tup(hpp, szp, &res, am.blocks, bld_unstable_uint(hpp, szp, cs->blocks.curr.no), bld_unstable_uint(hpp, szp, cs->blocks.max.no), bld_unstable_uint(hpp, szp, cs->blocks.max_ever.no)); } return res;}static voidmake_name_atoms(Allctr_t *allctr){ char alloc[] = "alloc"; char realloc[] = "realloc"; char free[] = "free"; char buf[MAX_ATOM_LENGTH]; size_t prefix_len = strlen(allctr->name_prefix); if (prefix_len > MAX_ATOM_LENGTH + sizeof(realloc) - 1) erl_exit(1,"Too long allocator name: %salloc\n",allctr->name_prefix); memcpy((void *) buf, (void *) allctr->name_prefix, prefix_len); memcpy((void *) &buf[prefix_len], (void *) alloc, sizeof(alloc) - 1); allctr->name.alloc = am_atom_put(buf, prefix_len + sizeof(alloc) - 1); memcpy((void *) &buf[prefix_len], (void *) realloc, sizeof(realloc) - 1); allctr->name.realloc = am_atom_put(buf, prefix_len + sizeof(realloc) - 1); memcpy((void *) &buf[prefix_len], (void *) free, sizeof(free) - 1); allctr->name.free = am_atom_put(buf, prefix_len + sizeof(free) - 1);}static Eterminfo_calls(Allctr_t *allctr, int *print_to_p, void *print_to_arg, Uint **hpp, Uint *szp){ Eterm res = THE_NON_VALUE; if (print_to_p) {#define PRINT_CC_4(TO, TOA, NAME, CC) \ if ((CC).giga_no == 0) \ erts_print(TO, TOA, "%s calls: %bpu\n", NAME, CC.no); \ else \ erts_print(TO, TOA, "%s calls: %bpu%09lu\n", NAME, CC.giga_no, CC.no)#define PRINT_CC_5(TO, TOA, PRFX, NAME, CC) \ if ((CC).giga_no == 0) \ erts_print(TO, TOA, "%s%s calls: %bpu\n",PRFX,NAME,CC.no); \ else \ erts_print(TO, TOA, "%s%s calls: %bpu%09lu\n",PRFX,NAME,CC.giga_no,CC.no) char *prefix = allctr->name_prefix; int to = *print_to_p; void *arg = print_to_arg; PRINT_CC_5(to, arg, prefix, "alloc", allctr->calls.this_alloc); PRINT_CC_5(to, arg, prefix, "free", allctr->calls.this_free); PRINT_CC_5(to, arg, prefix, "realloc", allctr->calls.this_realloc);#if HAVE_ERTS_MSEG PRINT_CC_4(to, arg, "mseg_alloc", allctr->calls.mseg_alloc); PRINT_CC_4(to, arg, "mseg_dealloc", allctr->calls.mseg_dealloc); PRINT_CC_4(to, arg, "mseg_realloc", allctr->calls.mseg_realloc);#endif PRINT_CC_4(to, arg, "sys_alloc", allctr->calls.sys_alloc); PRINT_CC_4(to, arg, "sys_free", allctr->calls.sys_free); PRINT_CC_4(to, arg, "sys_realloc", allctr->calls.sys_realloc);#undef PRINT_CC_4#undef PRINT_CC_5 } if (hpp || szp) { ASSERT(allctr->name.alloc != THE_NON_VALUE); ASSERT(allctr->name.realloc != THE_NON_VALUE); ASSERT(allctr->name.free != THE_NON_VALUE); res = NIL; add_3tup(hpp, szp, &res, am.sys_realloc, bld_unstable_uint(hpp, szp, allctr->calls.sys_realloc.giga_no), bld_unstable_uint(hpp, szp, allctr->calls.sys_realloc.no)); add_3tup(hpp, szp, &res, am.sys_free, bld_unstable_uint(hpp, szp, allctr->calls.sys_free.giga_no), bld_unstable_uint(hpp, szp, allctr->calls.sys_free.no)); add_3tup(hpp, szp, &res, am.sys_alloc, bld_unstable_uint(hpp, szp, allctr->calls.sys_alloc.giga_no), bld_unstable_uint(hpp, szp, allctr->calls.sys_alloc.no));#if HAVE_ERTS_MSEG add_3tup(hpp, szp, &res, am.mseg_realloc, bld_unstable_uint(hpp, szp, allctr->calls.mseg_realloc.giga_no), bld_unstable_uint(hpp, szp, allctr->calls.mseg_realloc.no)); add_3tup(hpp, szp, &res, am.mseg_dealloc, bld_unstable_uint(hpp, szp, allctr->calls.mseg_dealloc.giga_no), bld_unstable_uint(hpp, szp, allctr->calls.mseg_dealloc.no)); add_3tup(hpp, szp, &res, am.mseg_alloc, bld_unstable_uint(hpp, szp, allctr->calls.mseg_alloc.giga_no), bld_unstable_uint(hpp, szp, allctr->calls.mseg_alloc.no));#endif add_3tup(hpp, szp, &res, allctr->name.realloc, bld_unstable_uint(hpp, szp, allctr->calls.this_realloc.giga_no), bld_unstable_uint(hpp, szp, allctr->calls.this_realloc.no)); add_3tup(hpp, szp, &res, allctr->name.free, bld_unstable_uint(hpp, szp, allctr->calls.this_free.giga_no), bld_unstable_uint(hpp, szp, allctr->calls.this_free.no)); add_3tup(hpp, szp, &res, allctr->name.alloc, bld_unstable_uint(hpp, szp, allctr->calls.this_alloc.giga_no), bld_unstable_uint(hpp, szp, allctr->calls.this_alloc.no)); } return res;}static Eterminfo_options(Allctr_t *allctr, int *print_to_p, void *print_to_arg, Uint **hpp, Uint *szp){ Eterm res = THE_NON_VALUE; if (!allctr) { if (print_to_p) erts_print(*print_to_p, print_to_arg, "option e: false\n"); if (hpp || szp) { res = NIL; add_2tup(hpp, szp, &res, am.e, am_false); } return res; } if (print_to_p) { erts_print(*print_to_p, print_to_arg, "option e: true\n" "option sbct: %bpu\n"#if HAVE_ERTS_MSEG "option asbcst: %bpu\n" "option rsbcst: %bpu\n"#endif "option rsbcmt: %bpu\n" "option mmbcs: %bpu\n"#if HAVE_ERTS_MSEG "option mmsbc: %bpu\n" "option mmmbc: %bpu\n"#endif "option lmbcs: %bpu\n" "option smbcs: %bpu\n" "option mbcgs: %bpu\n", allctr->sbc_threshold,#if HAVE_ERTS_MSEG allctr->mseg_opt.abs_shrink_th, allctr->mseg_opt.rel_shrink_th,#endif allctr->sbc_move_threshold, allctr->main_carrier_size,#if HAVE_ERTS_MSEG allctr->max_mseg_sbcs, allctr->max_mseg_mbcs,#endif allctr->largest_mbc_size, allctr->smallest_mbc_size, allctr->mbc_growth_stages); } res = (*allctr->info_options)(allctr, "option ", print_to_p, print_to_arg, hpp, szp); if (hpp || szp) { add_2tup(hpp, szp, &res, am.mbcgs, bld_uint(hpp, szp, allctr->mbc_growth_stages)); add_2tup(hpp, szp, &res, am.smbcs, bld_uint(hpp, szp, allctr->smallest_mbc_size)); add_2tup(hpp, szp, &res, am.lmbcs, bld_uint(hpp, szp, allctr->largest_mbc_size));#if HAVE_ERTS_MSEG add_2tup(hpp, szp, &res, am.mmsbc, bld_uint(hpp, szp, allctr->max_mseg_sbcs)); add_2tup(hpp, szp, &res, am.mmmbc, bld_uint(hpp, szp, allctr->max_mseg_mbcs));#endif add_2tup(hpp, szp, &res, am.mmbcs, bld_uint(hpp, szp, allctr->main_carrier_size)); add_2tup(hpp, szp, &res, am.rsbcmt, bld_uint(hpp, szp, allctr->sbc_move_threshold));#if HAVE_ERTS_MSEG add_2tup(hpp, szp, &res, am.rsbcst, bld_uint(hpp, szp, allctr->mseg_opt.rel_shrink_th)); add_2tup(hpp, szp, &res, am.asbcst, bld_uint(hpp, szp, allctr->mseg_opt.abs_shrink_th));#endif add_2tup(hpp, szp, &res, am.sbct, bld_uint(hpp, szp, allctr->sbc_threshold)); add_2tup(hpp, szp, &res, am.e, am_true); } return res;}static ERTS_INLINE voidupdate_max_ever_values(CarriersStats_t *cs){ if (cs->max_ever.no < cs->max.no) cs->max_ever.no = cs->max.no; if (cs->max_ever.size < cs->max.size) cs->max_ever.size = cs->max.size; if (cs->blocks.max_ever.no < cs->blocks.max.no) cs->blocks.max_ever.no = cs->blocks.max.no; if (cs->blocks.max_ever.size < cs->blocks.max.size) cs->blocks.max_ever.size = cs->blocks.max.size;}static ERTS_INLINE voidreset_max_values(CarriersStats_t *cs){ cs->max.no = cs->curr_mseg.no + cs->curr_sys_alloc.no; cs->max.size = cs->curr_mseg.size + cs->curr_sys_alloc.size; cs->blocks.max.no = cs->blocks.curr.no; cs->blocks.max.size = cs->blocks.curr.size;}/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\ * Exported functions *\* */Etermerts_alcu_au_info_options(int *print_to_p, void *print_to_arg, Uint **hpp, Uint *szp){ Eterm res = THE_NON_VALUE; if (print_to_p) { erts_print(*print_to_p, print_to_arg,#if HAVE_ERTS_MSEG "option mmc: %bpu\n"#endif "option ycs: %bpu\n",#if HAVE_ERTS_MSEG max_mseg_carriers,#endif sys_alloc_carrier_size); } if (hpp || szp) { res = NIL; ensure_atoms_initialized(NULL); add_2tup(hpp, szp, &res, am.ycs, bld_uint(hpp, szp, sys_alloc_carrier_size));#if HAVE_ERTS_MSEG add_2tup(hpp, szp, &res, am.mmc, bld_uint(hpp, szp, max_mseg_carriers));#endif } return res;}Etermerts_alcu_info_options(Allctr_t *allctr, int *print_to_p, void *print_to_arg, Uint **hpp, Uint *szp){ Eterm res;#ifdef USE_THREADS if (allctr->thread_safe) erts_mtx_lock(&allctr->mutex);#endif if (hpp || szp) ensure_atoms_initialized(allctr); res = info_options(allctr, print_to_p, print_to_arg, hpp, szp);#ifdef USE_THREADS if (allctr->thread_safe) erts_mtx_unlock(&allctr->mutex);#endif return res;}/* ----------------------------------------------------------------------- */Etermerts_alcu_info(Allctr_t *allctr, int begin_max_period, int *print_to_p, void *print_to_arg, Uint **hpp, Uint *szp){ Eterm res, sett, mbcs, sbcs, calls;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -