Skip to content

Commit

Permalink
Merge branch 'rickard/outstanding-cpc-cla-limit/23.3.4/OTP-17796' int…
Browse files Browse the repository at this point in the history
…o maint-23

* rickard/outstanding-cpc-cla-limit/23.3.4/OTP-17796:
  Introduce outstanding requests limit for system processes
  • Loading branch information
Erlang/OTP committed Dec 20, 2021
2 parents 6d3dfad + 2a75073 commit e499973
Show file tree
Hide file tree
Showing 24 changed files with 613 additions and 157 deletions.
11 changes: 11 additions & 0 deletions erts/doc/src/erl_cmd.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1623,6 +1623,17 @@
parameter determines. The lingering prevents repeated
deletions and insertions in the tables from occurring.</p>
</item>
<tag><marker id="+zosrl"/><c>+zosrl limit</c></tag>
<item>
<p>
Sets a limit on the amount of outstanding requests made by
a system process orchestrating system wide changes. Valid
range of this limit is <c>[1, 134217727]</c>. See
<seeerl marker="erts:erlang#system_flag_outstanding_system_requests_limit">
<c>erlang:system_flag(outstanding_system_requests_limit, Limit)</c></seeerl>
for more information.
</p>
</item>
</taglist>
</item>
</taglist>
Expand Down
119 changes: 88 additions & 31 deletions erts/doc/src/erlang.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8079,6 +8079,50 @@ ok

<func>
<name name="system_flag" arity="2" clause_i="11"
anchor="system_flag_outstanding_system_requests_limit"
since="OTP @OTP-17796@"/>
<fsummary>Set limit on outstanding requests for system processes.</fsummary>
<desc>
<p>
Sets a limit on the amount of outstanding requests made by
a system process orchestrating system wide changes. Currently
there are two such processes:
</p>
<taglist>
<tag>The Code Purger</tag>
<item><p>
The code purger orchestrates checking of references to old
code before old code is removed from the system.
</p></item>
<tag>The Literal Area Collector</tag>
<item><p>
The literal area collector orchestrates copying of references
from old literal areas before removal of such areas from the
system.
</p></item>
</taglist>
<p>
Each of these processes are allowed to have as many outstanding
requests as this limit is set to. By default this limit is set
to twice the amount of
<seeerl marker="#system_info_schedulers">schedulers</seeerl>
on the system. This will ensure that schedulers will have enough
work scheduled to perform these operations as quickly as possible
at the same time as other work will be interleaved with this work.
Currently used limit can be checked by calling
<seeerl marker="#system_info_outstanding_system_requests_limit">
<c>erlang:system_info(outstanding_system_requests_limit)</c></seeerl>.
</p>
<p>
This limit can also be set by passing the command line argument
<seecom marker="erts:erl#+zosrl"><c>+zosrl &lt;Limit&gt;</c></seecom>
to <c>erl</c>.
</p>
</desc>
</func>

<func>
<name name="system_flag" arity="2" clause_i="12"
anchor="system_flag_scheduler_bind_type" since=""/>
<fsummary>Set system flag scheduler_bind_type.</fsummary>
<type name="scheduler_bind_type"/>
Expand Down Expand Up @@ -8205,7 +8249,7 @@ ok
</func>

<func>
<name name="system_flag" arity="2" clause_i="12"
<name name="system_flag" arity="2" clause_i="13"
anchor="system_flag_scheduler_wall_time" since="OTP R15B01"/>
<fsummary>Set system flag scheduler_wall_time.</fsummary>
<desc>
Expand All @@ -8218,7 +8262,7 @@ ok
</func>

<func>
<name name="system_flag" arity="2" clause_i="13"
<name name="system_flag" arity="2" clause_i="14"
anchor="system_flag_schedulers_online" since=""/>
<fsummary>Set system flag schedulers_online.</fsummary>
<desc>
Expand Down Expand Up @@ -8247,7 +8291,7 @@ ok
</func>

<func>
<name name="system_flag" arity="2" clause_i="14" since="OTP 21.3"/>
<name name="system_flag" arity="2" clause_i="15" since="OTP 21.3"/>
<fsummary>Set system logger process.</fsummary>
<desc>
<p>Sets the process that will receive the logging
Expand Down Expand Up @@ -8279,7 +8323,7 @@ Metadata = #{ pid => pid(),
</func>

<func>
<name name="system_flag" arity="2" clause_i="15" since=""/>
<name name="system_flag" arity="2" clause_i="16" since=""/>
<fsummary>Set system flag trace_control_word.</fsummary>
<desc>
<p>Sets the value of the node trace control word to
Expand All @@ -8293,7 +8337,7 @@ Metadata = #{ pid => pid(),
</func>

<func>
<name name="system_flag" arity="2" clause_i="16"
<name name="system_flag" arity="2" clause_i="17"
anchor="system_flag_time_offset" since="OTP 18.0"/>
<fsummary>Finalize the time offset.</fsummary>
<desc>
Expand Down Expand Up @@ -8442,6 +8486,7 @@ Metadata = #{ pid => pid(),
<seeerl marker="#system_info_modified_timing_level"><c>modified_timing_level</c></seeerl>,
<seeerl marker="#system_info_nif_version"><c>nif_version</c></seeerl>,
<seeerl marker="#system_info_otp_release"><c>otp_release</c></seeerl>,
<seeerl marker="#system_info_outstanding_system_requests_limit"><c>outstanding_system_requests_limit</c></seeerl>,
<seeerl marker="#system_info_port_parallelism"><c>port_parallelism</c></seeerl>,
<seeerl marker="#system_info_system_architecture"><c>system_architecture</c></seeerl>,
<seeerl marker="#system_info_system_logger"><c>system_logger</c></seeerl>,
Expand Down Expand Up @@ -9627,32 +9672,33 @@ Metadata = #{ pid => pid(),
<name name="system_info" arity="1" clause_i="49" since=""/> <!-- otp_release -->
<!-- <name name="system_info" arity="1" clause_i="50"/> os_monotonic_time_source -->
<!-- <name name="system_info" arity="1" clause_i="51"/> os_system_time_source -->
<name name="system_info" arity="1" clause_i="52" since="OTP R16B"/> <!-- port_parallelism -->
<!-- <name name="system_info" arity="1" clause_i="53"/> port_count -->
<!-- <name name="system_info" arity="1" clause_i="54"/> port_limit -->
<!-- <name name="system_info" arity="1" clause_i="55"/> process_count -->
<!-- <name name="system_info" arity="1" clause_i="56"/> process_limit -->
<!-- <name name="system_info" arity="1" clause_i="57"/> procs -->
<!-- <name name="system_info" arity="1" clause_i="58"/> scheduler_bind_type -->
<!-- <name name="system_info" arity="1" clause_i="59"/> scheduler_bindings -->
<!-- <name name="system_info" arity="1" clause_i="60"/> scheduler_id -->
<!-- <name name="system_info" arity="1" clause_i="61"/> schedulers -->
<!-- <name name="system_info" arity="1" clause_i="62"/> smp_support -->
<!-- <name name="system_info" arity="1" clause_i="63"/> start_time -->
<name name="system_info" arity="1" clause_i="64" since=""/> <!-- system_architecture -->
<name name="system_info" arity="1" clause_i="65" since="OTP 21.3"/> <!-- system_logger -->
<name name="system_info" arity="1" clause_i="66" since=""/> <!-- system_version -->
<!-- <name name="system_info" arity="1" clause_i="67"/> threads -->
<!-- <name name="system_info" arity="1" clause_i="68"/> thread_pool_size -->
<!-- <name name="system_info" arity="1" clause_i="69"/> time_correction -->
<!-- <name name="system_info" arity="1" clause_i="70"/> time_offset -->
<!-- <name name="system_info" arity="1" clause_i="71"/> time_warp_mode -->
<!-- <name name="system_info" arity="1" clause_i="72"/> tolerant_timeofday -->
<name name="system_info" arity="1" clause_i="73" since=""/> <!-- trace_control_word -->
<!-- <name name="system_info" arity="1" clause_i="74"/> update_cpu_info -->
<name name="system_info" arity="1" clause_i="75" since=""/> <!-- version -->
<name name="system_info" arity="1" clause_i="76" since=""/> <!-- wordsize -->
<!-- <name name="system_info" arity="1" clause_i="77"/> overview -->
<name name="system_info" arity="1" clause_i="52" since="OTP @OTP-17796@"/> <!-- outstanding_system_requests_limit -->
<name name="system_info" arity="1" clause_i="53" since="OTP R16B"/> <!-- port_parallelism -->
<!-- <name name="system_info" arity="1" clause_i="54"/> port_count -->
<!-- <name name="system_info" arity="1" clause_i="55"/> port_limit -->
<!-- <name name="system_info" arity="1" clause_i="56"/> process_count -->
<!-- <name name="system_info" arity="1" clause_i="57"/> process_limit -->
<!-- <name name="system_info" arity="1" clause_i="58"/> procs -->
<!-- <name name="system_info" arity="1" clause_i="59"/> scheduler_bind_type -->
<!-- <name name="system_info" arity="1" clause_i="60"/> scheduler_bindings -->
<!-- <name name="system_info" arity="1" clause_i="61"/> scheduler_id -->
<!-- <name name="system_info" arity="1" clause_i="62"/> schedulers -->
<!-- <name name="system_info" arity="1" clause_i="63"/> smp_support -->
<!-- <name name="system_info" arity="1" clause_i="64"/> start_time -->
<name name="system_info" arity="1" clause_i="65" since=""/> <!-- system_architecture -->
<name name="system_info" arity="1" clause_i="66" since="OTP 21.3"/> <!-- system_logger -->
<name name="system_info" arity="1" clause_i="67" since=""/> <!-- system_version -->
<!-- <name name="system_info" arity="1" clause_i="68"/> threads -->
<!-- <name name="system_info" arity="1" clause_i="69"/> thread_pool_size -->
<!-- <name name="system_info" arity="1" clause_i="70"/> time_correction -->
<!-- <name name="system_info" arity="1" clause_i="71"/> time_offset -->
<!-- <name name="system_info" arity="1" clause_i="72"/> time_warp_mode -->
<!-- <name name="system_info" arity="1" clause_i="73"/> tolerant_timeofday -->
<name name="system_info" arity="1" clause_i="74" since=""/> <!-- trace_control_word -->
<!-- <name name="system_info" arity="1" clause_i="75"/> update_cpu_info -->
<name name="system_info" arity="1" clause_i="76" since=""/> <!-- version -->
<name name="system_info" arity="1" clause_i="77" since=""/> <!-- wordsize -->
<!-- <name name="system_info" arity="1" clause_i="78"/> overview -->
<!-- When adding any entry, make sure to update the overview clause_i -->
<fsummary>Information about the system.</fsummary>
<desc>
Expand Down Expand Up @@ -9801,6 +9847,17 @@ Metadata = #{ pid => pid(),
<seeguide marker="system/system_principles:versions">
System principles</seeguide> in System Documentation.</p>
</item>
<tag><marker id="system_info_outstanding_system_requests_limit"/>
<c>outstanding_system_requests_limit</c></tag>
<item>
<p>
Returns the limit on the amount of outstanding requests
made by a system process orchestrating system wide changes.
See <seeerl marker="#system_flag_outstanding_system_requests_limit">
<c>erlang:system_flag(outstanding_system_requests_limit, Limit)</c></seeerl>
for more information.
</p>
</item>
<tag><marker id="system_info_port_parallelism"/>
<c>port_parallelism</c></tag>
<item>
Expand Down
1 change: 1 addition & 0 deletions erts/emulator/beam/atom.names
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ atom out
atom out_exited
atom out_exiting
atom output
atom outstanding_system_requests_limit
atom overlapped_io
atom owner
atom packet
Expand Down
29 changes: 28 additions & 1 deletion erts/emulator/beam/beam_bif_load.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ static void delete_code(Module* modp);
static int any_heap_ref_ptrs(Eterm* start, Eterm* end, char* mod_start, Uint mod_size);
static int any_heap_refs(Eterm* start, Eterm* end, char* mod_start, Uint mod_size);

static erts_atomic_t sys_proc_outstanding_req_limit;

static void
init_purge_state(void)
{
Expand Down Expand Up @@ -100,12 +102,37 @@ static void
init_release_literal_areas(void);

void
erts_beam_bif_load_init(void)
erts_beam_bif_load_init(Uint sys_proc_outst_req_lim)
{
if (sys_proc_outst_req_lim < 1 || ERTS_MAX_PROCESSES < sys_proc_outst_req_lim)
ERTS_INTERNAL_ERROR("invalid system process outstanding requests limit");
erts_atomic_init_nob(&sys_proc_outstanding_req_limit,
(erts_aint_t) sys_proc_outst_req_lim);
init_release_literal_areas();
init_purge_state();
}

Uint
erts_set_outstanding_system_requests_limit(Uint new_val)
{
erts_aint_t old_val;

if (new_val < 1 || ERTS_MAX_PROCESSES < new_val)
return 0;

old_val = erts_atomic_xchg_nob(&sys_proc_outstanding_req_limit,
(erts_aint_t) new_val);
return (Uint) old_val;
}

Uint
erts_get_outstanding_system_requests_limit(void)
{
erts_aint_t val = erts_atomic_read_nob(&sys_proc_outstanding_req_limit);
ASSERT(0 < val && val <= MAX_SMALL);
return (Uint) val;
}

BIF_RETTYPE code_is_module_native_1(BIF_ALIST_1)
{
Module* modp;
Expand Down
4 changes: 3 additions & 1 deletion erts/emulator/beam/beam_load.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ typedef struct beam_code_header {
void erts_release_literal_area(struct ErtsLiteralArea_* literal_area);
int erts_is_module_native(BeamCodeHeader* code);
int erts_is_function_native(ErtsCodeInfo*);
void erts_beam_bif_load_init(void);
void erts_beam_bif_load_init(Uint);
Uint erts_get_outstanding_system_requests_limit(void);
Uint erts_set_outstanding_system_requests_limit(Uint new_val);
struct erl_fun_entry;
void erts_purge_state_add_fun(struct erl_fun_entry *fe);
Export *erts_suspend_process_on_pending_purge_lambda(Process *c_p,
Expand Down
8 changes: 8 additions & 0 deletions erts/emulator/beam/bif.c
Original file line number Diff line number Diff line change
Expand Up @@ -4899,6 +4899,14 @@ BIF_RETTYPE system_flag_2(BIF_ALIST_2)
threads);
}
#endif
} else if (BIF_ARG_1 == am_outstanding_system_requests_limit) {
Uint val;
if (!term_to_Uint(BIF_ARG_2, &val))
goto error;
val = erts_set_outstanding_system_requests_limit(val);
if (!val)
goto error;
BIF_RET(make_small(val));
} else if (ERTS_IS_ATOM_STR("scheduling_statistics", BIF_ARG_1)) {
int what;
if (ERTS_IS_ATOM_STR("disable", BIF_ARG_2))
Expand Down
3 changes: 3 additions & 0 deletions erts/emulator/beam/erl_bif_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -2593,6 +2593,9 @@ BIF_RETTYPE system_info_1(BIF_ALIST_1)
default:
ERTS_INTERNAL_ERROR("Invalid time warp mode");
}
} else if (BIF_ARG_1 == am_outstanding_system_requests_limit) {
Uint val = erts_get_outstanding_system_requests_limit();
BIF_RET(make_small(val));
} else if (BIF_ARG_1 == am_allocated_areas) {
res = erts_allocated_areas(NULL, NULL, BIF_P);
BIF_RET(res);
Expand Down
26 changes: 23 additions & 3 deletions erts/emulator/beam/erl_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ static void erl_init(int ncpu,
int port_tab_sz,
int port_tab_sz_ignore_files,
int legacy_port_tab,
Uint sys_proc_outst_req_lim,
int time_correction,
ErtsTimeWarpMode time_warp_mode,
int node_tab_delete_delay,
Expand Down Expand Up @@ -302,6 +303,7 @@ erl_init(int ncpu,
int port_tab_sz,
int port_tab_sz_ignore_files,
int legacy_port_tab,
Uint sys_proc_outst_req_lim,
int time_correction,
ErtsTimeWarpMode time_warp_mode,
int node_tab_delete_delay,
Expand Down Expand Up @@ -359,7 +361,7 @@ erl_init(int ncpu,
erts_init_unicode(); /* after RE to get access to PCRE unicode */
erts_init_external();
erts_init_map();
erts_beam_bif_load_init();
erts_beam_bif_load_init(sys_proc_outst_req_lim);
erts_delay_trap = erts_export_put(am_erlang, am_delay_trap, 2);
erts_late_init_process();
#if HAVE_ERTS_MSEG
Expand Down Expand Up @@ -713,6 +715,9 @@ void erts_usage(void)
erts_fprintf(stderr, "-zdntgc time set delayed node table gc in seconds\n");
erts_fprintf(stderr, " valid values are infinity or intergers in the range [0-%d]\n",
ERTS_NODE_TAB_DELAY_GC_MAX);
erts_fprintf(stderr, "-zosrl number set outstanding requests limit for system processes,\n");
erts_fprintf(stderr, " valid range [1-%d]\n",
ERTS_MAX_PROCESSES);
#if 0
erts_fprintf(stderr, "-zebwt val set ets busy wait threshold, valid values are:\n");
erts_fprintf(stderr, " none|very_short|short|medium|long|very_long|extremely_long\n");
Expand Down Expand Up @@ -1286,6 +1291,7 @@ erl_start(int argc, char **argv)
int port_tab_sz_ignore_files = 0;
int legacy_proc_tab = 0;
int legacy_port_tab = 0;
Uint sys_proc_outst_req_lim;
int time_correction;
ErtsTimeWarpMode time_warp_mode;
int node_tab_delete_delay = ERTS_NODE_TAB_DELAY_GC_DEFAULT;
Expand Down Expand Up @@ -1327,6 +1333,8 @@ erl_start(int argc, char **argv)

erts_error_logger_warnings = am_warning;

sys_proc_outst_req_lim = 2*erts_no_schedulers;

while (i < argc) {
if (argv[i][0] != '-') {
erts_usage();
Expand Down Expand Up @@ -2215,6 +2223,17 @@ erl_start(int argc, char **argv)
erts_usage();
}
}
else if (has_prefix("osrl", sub_param)) {
long val;
arg = get_arg(sub_param+4, argv[i+1], &i);
errno = 0;
val = strtol(arg, NULL, 10);
if (errno != 0 || val < 1 || ERTS_MAX_PROCESSES < val) {
erts_fprintf(stderr, "Invalid outstanding requests limit %s\n", arg);
erts_usage();
}
sys_proc_outst_req_lim = (Uint) val;
}
else {
erts_fprintf(stderr, "bad -z option %s\n", argv[i]);
erts_usage();
Expand Down Expand Up @@ -2294,6 +2313,7 @@ erl_start(int argc, char **argv)
port_tab_sz,
port_tab_sz_ignore_files,
legacy_port_tab,
sys_proc_outst_req_lim,
time_correction,
time_warp_mode,
node_tab_delete_delay,
Expand All @@ -2318,7 +2338,7 @@ erl_start(int argc, char **argv)

pid = erl_system_process_otp(erts_init_process_id,
"erts_code_purger", !0,
PRIORITY_NORMAL);
PRIORITY_HIGH);
erts_code_purger
= (Process *) erts_ptab_pix2intptr_ddrb(&erts_proc,
internal_pid_index(pid));
Expand All @@ -2327,7 +2347,7 @@ erl_start(int argc, char **argv)

pid = erl_system_process_otp(erts_init_process_id,
"erts_literal_area_collector",
!0, PRIORITY_NORMAL);
!0, PRIORITY_HIGH);
erts_literal_area_collector
= (Process *) erts_ptab_pix2intptr_ddrb(&erts_proc,
internal_pid_index(pid));
Expand Down
Loading

0 comments on commit e499973

Please sign in to comment.