Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Ledest:erlang:25
erlang
2572-Refactor-erts_max_heap_size_map-with-ErtsH...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 2572-Refactor-erts_max_heap_size_map-with-ErtsHeapFactory.patch of Package erlang
From 8d5f5ef0b5bd87a79390fe767cbfed9827ba66fe Mon Sep 17 00:00:00 2001 From: Sverker Eriksson <sverker@erlang.org> Date: Mon, 2 Jan 2023 13:26:11 +0100 Subject: [PATCH 2/3] Refactor erts_max_heap_size_map() with ErtsHeapFactory to call erts_map_from_ks_and_vs() and not assume flatmap. --- erts/emulator/beam/bif.c | 24 ++++++++++++---------- erts/emulator/beam/erl_bif_info.c | 31 +++++++++++----------------- erts/emulator/beam/erl_gc.c | 34 ++++++++++++------------------- erts/emulator/beam/erl_gc.h | 2 +- 4 files changed, 39 insertions(+), 52 deletions(-) diff --git a/erts/emulator/beam/bif.c b/erts/emulator/beam/bif.c index 8d27d0b080..909382d125 100644 --- a/erts/emulator/beam/bif.c +++ b/erts/emulator/beam/bif.c @@ -1898,8 +1898,8 @@ BIF_RETTYPE process_flag_2(BIF_ALIST_2) BIF_RET(old_value); } else if (BIF_ARG_1 == am_max_heap_size) { - Eterm *hp; - Uint sz = 0, max_heap_size, max_heap_flags; + ErtsHeapFactory factory; + Uint max_heap_size, max_heap_flags; if (!erts_max_heap_size(BIF_ARG_2, &max_heap_size, &max_heap_flags)) goto error; @@ -1907,9 +1907,11 @@ BIF_RETTYPE process_flag_2(BIF_ALIST_2) if ((max_heap_size < MIN_HEAP_SIZE(BIF_P) && max_heap_size != 0)) goto error; - erts_max_heap_size_map(MAX_HEAP_SIZE_GET(BIF_P), MAX_HEAP_SIZE_FLAGS_GET(BIF_P), NULL, &sz); - hp = HAlloc(BIF_P, sz); - old_value = erts_max_heap_size_map(MAX_HEAP_SIZE_GET(BIF_P), MAX_HEAP_SIZE_FLAGS_GET(BIF_P), &hp, NULL); + erts_factory_proc_init(&factory, BIF_P); + old_value = erts_max_heap_size_map(&factory, + MAX_HEAP_SIZE_GET(BIF_P), + MAX_HEAP_SIZE_FLAGS_GET(BIF_P)); + erts_factory_close(&factory); MAX_HEAP_SIZE_SET(BIF_P, max_heap_size); MAX_HEAP_SIZE_FLAGS_SET(BIF_P, max_heap_flags); BIF_RET(old_value); @@ -5080,9 +5082,9 @@ BIF_RETTYPE system_flag_2(BIF_ALIST_2) BIF_RET(make_small(oval)); } else if (BIF_ARG_1 == am_max_heap_size) { - - Eterm *hp, old_value; - Uint sz = 0, max_heap_size, max_heap_flags; + ErtsHeapFactory factory; + Eterm old_value; + Uint max_heap_size, max_heap_flags; if (!erts_max_heap_size(BIF_ARG_2, &max_heap_size, &max_heap_flags)) goto error; @@ -5090,9 +5092,9 @@ BIF_RETTYPE system_flag_2(BIF_ALIST_2) if (max_heap_size < H_MIN_SIZE && max_heap_size != 0) goto error; - erts_max_heap_size_map(H_MAX_SIZE, H_MAX_FLAGS, NULL, &sz); - hp = HAlloc(BIF_P, sz); - old_value = erts_max_heap_size_map(H_MAX_SIZE, H_MAX_FLAGS, &hp, NULL); + erts_factory_proc_init(&factory, BIF_P); + old_value = erts_max_heap_size_map(&factory, H_MAX_SIZE, H_MAX_FLAGS); + erts_factory_close(&factory); erts_proc_unlock(BIF_P, ERTS_PROC_LOCK_MAIN); erts_thr_progress_block(); diff --git a/erts/emulator/beam/erl_bif_info.c b/erts/emulator/beam/erl_bif_info.c index a0abf8d50f..475b570be1 100644 --- a/erts/emulator/beam/erl_bif_info.c +++ b/erts/emulator/beam/erl_bif_info.c @@ -1873,14 +1873,9 @@ process_info_aux(Process *c_p, } case ERTS_PI_IX_MAX_HEAP_SIZE: { - Uint hsz = 0; - (void) erts_max_heap_size_map(MAX_HEAP_SIZE_GET(rp), - MAX_HEAP_SIZE_FLAGS_GET(rp), - NULL, &hsz); - hp = erts_produce_heap(hfact, hsz, reserve_size); - res = erts_max_heap_size_map(MAX_HEAP_SIZE_GET(rp), - MAX_HEAP_SIZE_FLAGS_GET(rp), - &hp, NULL); + res = erts_max_heap_size_map(hfact, + MAX_HEAP_SIZE_GET(rp), + MAX_HEAP_SIZE_FLAGS_GET(rp)); break; } @@ -1937,12 +1932,12 @@ process_info_aux(Process *c_p, case ERTS_PI_IX_GARBAGE_COLLECTION: { DECL_AM(minor_gcs); - Eterm t; - Uint map_sz = 0; + Eterm t, mhs_map; - erts_max_heap_size_map(MAX_HEAP_SIZE_GET(rp), MAX_HEAP_SIZE_FLAGS_GET(rp), NULL, &map_sz); + mhs_map = erts_max_heap_size_map(hfact, MAX_HEAP_SIZE_GET(rp), + MAX_HEAP_SIZE_FLAGS_GET(rp)); - hp = erts_produce_heap(hfact, 3+2 + 3+2 + 3+2 + 3+2 + 3+2 + map_sz, reserve_size); + hp = erts_produce_heap(hfact, 5*(3+2), reserve_size); t = TUPLE2(hp, AM_minor_gcs, make_small(GEN_GCS(rp))); hp += 3; res = CONS(hp, t, NIL); hp += 2; @@ -1954,10 +1949,8 @@ process_info_aux(Process *c_p, t = TUPLE2(hp, am_min_bin_vheap_size, make_small(rp->min_vheap_size)); hp += 3; res = CONS(hp, t, res); hp += 2; - t = erts_max_heap_size_map(MAX_HEAP_SIZE_GET(rp), MAX_HEAP_SIZE_FLAGS_GET(rp), &hp, NULL); - t = TUPLE2(hp, am_max_heap_size, t); hp += 3; - res = CONS(hp, t, res); hp += 2; + res = CONS(hp, mhs_map, res); hp += 2; break; } @@ -2748,10 +2741,10 @@ BIF_RETTYPE system_info_1(BIF_ALIST_1) res = TUPLE2(hp, am_min_heap_size,make_small(H_MIN_SIZE)); BIF_RET(res); } else if (BIF_ARG_1 == am_max_heap_size) { - Uint sz = 0; - erts_max_heap_size_map(H_MAX_SIZE, H_MAX_FLAGS, NULL, &sz); - hp = HAlloc(BIF_P, sz); - res = erts_max_heap_size_map(H_MAX_SIZE, H_MAX_FLAGS, &hp, NULL); + ErtsHeapFactory factory; + erts_factory_proc_init(&factory, BIF_P); + res = erts_max_heap_size_map(&factory, H_MAX_SIZE, H_MAX_FLAGS); + erts_factory_close(&factory); BIF_RET(res); } else if (BIF_ARG_1 == am_min_bin_vheap_size) { hp = HAlloc(BIF_P, 3); diff --git a/erts/emulator/beam/erl_gc.c b/erts/emulator/beam/erl_gc.c index 88f09c7f7c..2e2a028fc8 100644 --- a/erts/emulator/beam/erl_gc.c +++ b/erts/emulator/beam/erl_gc.c @@ -3739,28 +3739,20 @@ reached_max_heap_size(Process *p, Uint total_heap_size, } Eterm -erts_max_heap_size_map(Sint max_heap_size, Uint max_heap_flags, - Eterm **hpp, Uint *sz) +erts_max_heap_size_map(ErtsHeapFactory *factory, + Sint max_heap_size, Uint max_heap_flags) { - if (!hpp) { - *sz += ERTS_MAX_HEAP_SIZE_MAP_SZ; - return THE_NON_VALUE; - } else { - Eterm *hp = *hpp; - Eterm keys = TUPLE3(hp, am_error_logger, am_kill, am_size); - flatmap_t *mp; - hp += 4; - mp = (flatmap_t*) hp; - mp->thing_word = MAP_HEADER_FLATMAP; - mp->size = 3; - mp->keys = keys; - hp += MAP_HEADER_FLATMAP_SZ; - *hp++ = max_heap_flags & MAX_HEAP_SIZE_LOG ? am_true : am_false; - *hp++ = max_heap_flags & MAX_HEAP_SIZE_KILL ? am_true : am_false; - *hp++ = make_small(max_heap_size); - *hpp = hp; - return make_flatmap(mp); - } + Eterm keys[] = { + am_error_logger, am_kill, am_size + }; + Eterm values[] = { + max_heap_flags & MAX_HEAP_SIZE_LOG ? am_true : am_false, + max_heap_flags & MAX_HEAP_SIZE_KILL ? am_true : am_false, + make_small(max_heap_size) + }; + ERTS_CT_ASSERT(sizeof(keys) == sizeof(values)); + return erts_map_from_ks_and_vs(factory, keys, values, + sizeof(keys) / sizeof(keys[0])); } int diff --git a/erts/emulator/beam/erl_gc.h b/erts/emulator/beam/erl_gc.h index fab739c538..262c040974 100644 --- a/erts/emulator/beam/erl_gc.h +++ b/erts/emulator/beam/erl_gc.h @@ -186,7 +186,7 @@ void erts_offset_off_heap(struct erl_off_heap*, Sint, Eterm*, Eterm*); void erts_offset_heap_ptr(Eterm*, Uint, Sint, Eterm*, Eterm*); void erts_offset_heap(Eterm*, Uint, Sint, Eterm*, Eterm*); void erts_free_heap_frags(struct process* p); -Eterm erts_max_heap_size_map(Sint, Uint, Eterm **, Uint *); +Eterm erts_max_heap_size_map(ErtsHeapFactory *factory, Sint, Uint); int erts_max_heap_size(Eterm, Uint *, Uint *); void erts_deallocate_young_generation(Process *c_p); void erts_copy_one_frag(Eterm** hpp, ErlOffHeap* off_heap, -- 2.35.3
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor