From c737c3a8d047d27204ce0ea76e9c0a94187c9567 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn-Egil=20Dahlberg?= Date: Wed, 11 Jan 2012 10:19:11 +0100 Subject: [PATCH] erts: Organize limits as its own group --- erts/emulator/beam/atom.names | 1 + erts/emulator/beam/bif.c | 6 ++--- erts/emulator/beam/erl_bif_info.c | 39 ++++++++++++++++++++++++------- erts/emulator/beam/erl_gc.c | 2 +- erts/emulator/beam/erl_process.c | 24 +++++++++++-------- erts/emulator/beam/erl_process.h | 13 +++++++++-- erts/emulator/beam/erl_vm.h | 2 +- 7 files changed, 61 insertions(+), 26 deletions(-) diff --git a/erts/emulator/beam/atom.names b/erts/emulator/beam/atom.names index 6ae623eaa444..4ed71c0181a1 100644 --- a/erts/emulator/beam/atom.names +++ b/erts/emulator/beam/atom.names @@ -290,6 +290,7 @@ atom last_calls atom latin1 atom Le='=<' atom lf +atom limits atom line atom line_length atom linked_in_driver diff --git a/erts/emulator/beam/bif.c b/erts/emulator/beam/bif.c index a9940d30d08a..1b102eabfeb7 100644 --- a/erts/emulator/beam/bif.c +++ b/erts/emulator/beam/bif.c @@ -1615,11 +1615,11 @@ BIF_RETTYPE process_flag_2(BIF_ALIST_2) if (i < H_MIN_SIZE || i > H_DEFAULT_LIMIT_SIZE) { goto error; } - old_value = make_small(BIF_P->max_heap_size); + old_value = make_small(LIMIT_HEAP_SIZE(BIF_P)); if (i > H_MAX_SIZE) { - BIF_P->max_heap_size = H_MAX_SIZE; + LIMIT_HEAP_SIZE(BIF_P) = H_MAX_SIZE; } else { - BIF_P->max_heap_size = erts_next_heap_size(i, 0); + LIMIT_HEAP_SIZE(BIF_P) = erts_next_heap_size(i, 0); } BIF_RET(old_value); } diff --git a/erts/emulator/beam/erl_bif_info.c b/erts/emulator/beam/erl_bif_info.c index 3ac4927f8722..edad7038683d 100644 --- a/erts/emulator/beam/erl_bif_info.c +++ b/erts/emulator/beam/erl_bif_info.c @@ -568,6 +568,7 @@ static Eterm pi_args[] = { am_min_bin_vheap_size, am_current_location, am_current_stacktrace, + am_limits, #ifdef HYBRID am_message_binary #endif @@ -618,8 +619,9 @@ pi_arg2ix(Eterm arg) case am_min_bin_vheap_size: return 28; case am_current_location: return 29; case am_current_stacktrace: return 30; + case am_limits: return 31; #ifdef HYBRID - case am_message_binary: return 31; + case am_message_binary: return 32; #endif default: return -1; } @@ -643,7 +645,8 @@ static Eterm pi_1_keys[] = { am_stack_size, am_reductions, am_garbage_collection, - am_suspending + am_suspending, + am_limits }; #define ERTS_PI_1_NO_OF_KEYS (sizeof(pi_1_keys)/sizeof(Eterm)) @@ -1466,11 +1469,21 @@ process_info_aux(Process *BIF_P, break; } + case am_limits: { + Eterm t; + + hp = HAlloc(BIF_P, 3+2 + 3); /* last "3" is for outside tuple */ + + t = TUPLE2(hp, am_heap_size, make_small(LIMIT_HEAP_SIZE(rp))); hp += 3; + res = CONS(hp, t, NIL); hp += 2; + break; + } + case am_garbage_collection: { DECL_AM(minor_gcs); Eterm t; - hp = HAlloc(BIF_P, 3+2 + 3+2 + 3+2 + 3+2 + 3+2 + 3); /* last "3" is for outside tuple */ + hp = HAlloc(BIF_P, 3+2 + 3+2 + 3+2 + 3+2 + 3); /* last "3" is for outside tuple */ t = TUPLE2(hp, AM_minor_gcs, make_small(GEN_GCS(rp))); hp += 3; res = CONS(hp, t, NIL); hp += 2; @@ -1479,8 +1492,6 @@ process_info_aux(Process *BIF_P, t = TUPLE2(hp, am_min_heap_size, make_small(MIN_HEAP_SIZE(rp))); hp += 3; res = CONS(hp, t, res); hp += 2; - t = TUPLE2(hp, am_max_heap_size, make_small(MAX_HEAP_SIZE(rp))); hp += 3; - res = CONS(hp, t, res); hp += 2; t = TUPLE2(hp, am_min_bin_vheap_size, make_small(MIN_VHEAP_SIZE(rp))); hp += 3; res = CONS(hp, t, res); hp += 2; break; @@ -2148,18 +2159,28 @@ BIF_RETTYPE system_info_1(BIF_ALIST_1) ASSERT(is_internal_pid(val) || is_internal_port(val) || val==am_false) hp = HAlloc(BIF_P, 3); res = TUPLE2(hp, am_sequential_tracer, val); + BIF_RET(res); + } else if (BIF_ARG_1 == am_limits){ + Eterm tup, proc = NIL; + hp = HAlloc(BIF_P, 3+2 /* process tuple and cons */ + 3+2); + + /* process limits */ + tup = TUPLE2(hp, am_heap_size, make_small(H_MAX_SIZE)); hp += 3; + proc = CONS(hp, tup, NIL); hp += 2; + + /* resulting limits */ + tup = TUPLE2(hp, am_process, proc); hp += 3; + res = CONS(hp, tup, NIL); hp += 2; + BIF_RET(res); } else if (BIF_ARG_1 == am_garbage_collection){ Uint val = (Uint) erts_smp_atomic32_read_nob(&erts_max_gen_gcs); Eterm tup; - hp = HAlloc(BIF_P, 3+2 + 3+2 + 3+2 + 3+2); + hp = HAlloc(BIF_P, 3+2 + 3+2 + 3+2); tup = TUPLE2(hp, am_fullsweep_after, make_small(val)); hp += 3; res = CONS(hp, tup, NIL); hp += 2; - tup = TUPLE2(hp, am_max_heap_size, make_small(H_MAX_SIZE)); hp += 3; - res = CONS(hp, tup, res); hp += 2; - tup = TUPLE2(hp, am_min_heap_size, make_small(H_MIN_SIZE)); hp += 3; res = CONS(hp, tup, res); hp += 2; diff --git a/erts/emulator/beam/erl_gc.c b/erts/emulator/beam/erl_gc.c index 11210ba464f9..d8300e705287 100644 --- a/erts/emulator/beam/erl_gc.c +++ b/erts/emulator/beam/erl_gc.c @@ -415,7 +415,7 @@ erts_garbage_collect(Process* p, int need, Eterm* objv, int nobj) monitor_large_heap(p); } - if ( (HEAP_SIZE(p) + OLD_HEAP(p) ? OLD_HEND(p) - OLD_HEAP(p) : 0) > MAX_HEAP_SIZE(p)) { + if ( (HEAP_SIZE(p) + OLD_HEAP(p) ? OLD_HEND(p) - OLD_HEAP(p) : 0) > LIMIT_HEAP_SIZE(p)) { ErtsProcLocks locks; locks = ERTS_PROC_LOCKS_XSIG_SEND; diff --git a/erts/emulator/beam/erl_process.c b/erts/emulator/beam/erl_process.c index b1bf0ec57297..561ead15ff68 100644 --- a/erts/emulator/beam/erl_process.c +++ b/erts/emulator/beam/erl_process.c @@ -6761,17 +6761,21 @@ erl_create_process(Process* parent, /* Parent of process (default group leader). * noone except us has access to the process. */ if (so->flags & SPO_USE_ARGS) { - p->min_heap_size = so->min_heap_size; - p->max_heap_size = so->max_heap_size; - p->min_vheap_size = so->min_vheap_size; - p->prio = so->priority; - p->max_gen_gcs = so->max_gen_gcs; + p->min_heap_size = so->min_heap_size; + p->min_vheap_size = so->min_vheap_size; + p->prio = so->priority; + p->max_gen_gcs = so->max_gen_gcs; + + /* limits */ + LIMIT_HEAP_SIZE(p) = so->max_heap_size; } else { - p->min_heap_size = H_MIN_SIZE; - p->max_heap_size = H_MAX_SIZE; - p->min_vheap_size = BIN_VH_MIN_SIZE; - p->prio = PRIORITY_NORMAL; - p->max_gen_gcs = (Uint16) erts_smp_atomic32_read_nob(&erts_max_gen_gcs); + p->min_heap_size = H_MIN_SIZE; + p->min_vheap_size = BIN_VH_MIN_SIZE; + p->prio = PRIORITY_NORMAL; + p->max_gen_gcs = (Uint16) erts_smp_atomic32_read_nob(&erts_max_gen_gcs); + + /* limits */ + LIMIT_HEAP_SIZE(p) = H_MAX_SIZE; } p->skipped = 0; ASSERT(p->min_heap_size == erts_next_heap_size(p->min_heap_size, 0)); diff --git a/erts/emulator/beam/erl_process.h b/erts/emulator/beam/erl_process.h index 874a695ce198..9cbc57740d05 100644 --- a/erts/emulator/beam/erl_process.h +++ b/erts/emulator/beam/erl_process.h @@ -474,6 +474,13 @@ extern ErtsAlignedSchedulerData *erts_aligned_scheduler_data; extern ErtsSchedulerData *erts_scheduler_data; #endif +/* All limits within a process */ + +typedef struct { + Uint heap_size; +} ErlProcessLimits; + + /* * Process Specific Data. * @@ -578,7 +585,6 @@ struct ErtsPendingSuspend_ { # define MBUF_SIZE(p) (p)->mbuf_sz # define MSO(p) (p)->off_heap # define MIN_HEAP_SIZE(p) (p)->min_heap_size -# define MAX_HEAP_SIZE(p) (p)->max_heap_size # define MIN_VHEAP_SIZE(p) (p)->min_vheap_size # define BIN_VHEAP_SZ(p) (p)->bin_vheap_sz @@ -586,6 +592,9 @@ struct ErtsPendingSuspend_ { # define BIN_OLD_VHEAP_SZ(p) (p)->bin_old_vheap_sz # define BIN_OLD_VHEAP(p) (p)->bin_old_vheap +/* Define easy access to process limits */ +# define LIMIT_HEAP_SIZE(p) (p)->limits.heap_size + struct process { /* All fields in the PCB that differs between different heap * architectures, have been moved to the end of this struct to @@ -600,7 +609,6 @@ struct process { Eterm* hend; /* Heap end */ Uint heap_sz; /* Size of heap in words */ Uint min_heap_size; /* Minimum size of heap (in words). */ - Uint max_heap_size; /* Max size of heap (in words). */ Uint min_vheap_size; /* Minimum size of virtual heap (in words). */ #if !defined(NO_FPE_SIGNALS) || defined(HIPE) @@ -716,6 +724,7 @@ struct process { } u; ErtsRunQueue *bound_runq; + ErlProcessLimits limits; #ifdef ERTS_SMP erts_proc_lock_t lock; diff --git a/erts/emulator/beam/erl_vm.h b/erts/emulator/beam/erl_vm.h index 17ce169b39c9..2af7f3d1ce65 100644 --- a/erts/emulator/beam/erl_vm.h +++ b/erts/emulator/beam/erl_vm.h @@ -68,7 +68,7 @@ #define INPUT_REDUCTIONS (2 * CONTEXT_REDS) #define H_DEFAULT_SIZE 233 /* default (heap + stack) min size */ -#define H_DEFAULT_LIMIT_SIZE 536870912 /* default (heap + stack) min size */ +#define H_DEFAULT_LIMIT_SIZE 536870902 /* default (heap + stack) min size */ #define VH_DEFAULT_SIZE 32768 /* default virtual (bin) heap min size (words) */ #ifdef HYBRID