File 4493-Make-ETS-hash-use-decentralized-ctrs-when-w.c.-is-no.patch of Package erlang
From f6e1cb0385a8cbbc7138a1f299cf992376a793b5 Mon Sep 17 00:00:00 2001
From: Kjell Winblad <kjellwinblad@gmail.com>
Date: Wed, 15 Sep 2021 13:33:59 +0200
Subject: [PATCH 3/8] Make ETS hash use decentralized ctrs when w.c. is not
true or false
This commit makes sure that the decentralized_counters ETS option is
turned on by default for all tables that has the write_concurrency
option set to something else than true or false. As before the
decentralized_counters option is still turned on by default when the
table type is set to ordered_set and the write concurrency option is
set to true.
---
erts/emulator/beam/erl_db.c | 5 +++++
lib/stdlib/doc/src/ets.xml | 26 ++++++++++++--------------
lib/stdlib/test/ets_SUITE.erl | 13 ++++++++++---
3 files changed, 27 insertions(+), 17 deletions(-)
diff --git a/erts/emulator/beam/erl_db.c b/erts/emulator/beam/erl_db.c
index 3826e2189c..a047c6ecb5 100644
--- a/erts/emulator/beam/erl_db.c
+++ b/erts/emulator/beam/erl_db.c
@@ -2313,16 +2313,21 @@ BIF_RETTYPE ets_new_2(BIF_ALIST_2)
term_to_Sint(tp[2], &no_locks_param) &&
no_locks_param >= 1 &&
no_locks_param <= 32768) {
+ is_decentralized_counters = 1;
is_fine_locked = 1;
is_explicit_lock_granularity = 1;
is_write_concurrency_auto = 0;
no_locks = no_locks_param;
} else if (tp[2] == am_auto) {
+ is_decentralized_counters = 1;
is_write_concurrency_auto = 1;
is_fine_locked = 1;
is_explicit_lock_granularity = 0;
no_locks = -1;
} else if (tp[2] == am_true) {
+ if (!(status & DB_ORDERED_SET)) {
+ is_decentralized_counters = 0;
+ }
is_fine_locked = 1;
is_explicit_lock_granularity = 0;
is_write_concurrency_auto = 0;
diff --git a/lib/stdlib/doc/src/ets.xml b/lib/stdlib/doc/src/ets.xml
index e68cf23517..16b8739780 100644
--- a/lib/stdlib/doc/src/ets.xml
+++ b/lib/stdlib/doc/src/ets.xml
@@ -1306,14 +1306,9 @@ ets:select(Table, MatchSpec),</code>
concurrent read bursts and large concurrent
write bursts are common; for more information, see option
<seeerl marker="#new_2_read_concurrency">
- <c>read_concurrency</c></seeerl>. The
- <c>decentralized_counters</c> option is turned on by
- default for tables of type <c>ordered_set</c> with any
- of the <c>write_concurrency</c> options expcept
- <c>false</c> enabled, and the
- <c>decentralized_counters</c> option is turned
- <em>off</em> by default for all other table types. For
- more information, see the documentation for the
+ <c>read_concurrency</c></seeerl>. It is almost always a
+ good idea to combine the <c>write_concurrency</c> option
+ with the
<seeerl marker="#new_2_decentralized_counters">
<c>decentralized_counters</c></seeerl> option.</p>
<p>Notice that this option does not change any guarantees about
@@ -1366,12 +1361,15 @@ ets:select(Table, MatchSpec),</code>
<tag><c>{decentralized_counters,boolean()}</c></tag>
<item>
<p>
- Performance tuning. Defaults to <c>true</c> for tables
- of type <c>ordered_set</c> with the
- <seeerl marker="#new_2_write_concurrency">
- <c>write_concurrency</c></seeerl> option enabled, and defaults to
- false for all other table types. This option has no effect if
- the <c>write_concurrency</c> option is set to <c>false</c>.</p>
+ Performance tuning. Defaults to <c>true</c> for all
+ tables with the <c>write_concurrency</c> option set
+ to something else than <c>true</c> or <c>false</c>. For
+ tables of type <c>ordered_set</c> the option also
+ defaults to true when the <c>write_concurrency</c> option
+ is set to <c>true</c>. The option defaults to
+ <c>false</c> for all other configurations. This option
+ has no effect if the <c>write_concurrency</c> option is
+ set to <c>false</c>.</p>
<p>
When this option is set to <c>true</c>, the table is optimized for
frequent concurrent calls to operations that modify the tables
diff --git a/lib/stdlib/test/ets_SUITE.erl b/lib/stdlib/test/ets_SUITE.erl
index 86f1dff196..b44d67aec4 100644
--- a/lib/stdlib/test/ets_SUITE.erl
+++ b/lib/stdlib/test/ets_SUITE.erl
@@ -5238,8 +5238,13 @@ do_test_decentralized_counters_setting(TableType) ->
check_decentralized_counters(T1, false, FlxCtrMemUsage),
ets:delete(T1)
end,
- [[{write_concurrency, false}],
- [{write_concurrency, true}, {decentralized_counters, false}]]),
+ [[{write_concurrency, false}]] ++
+ case TableType of
+ set ->
+ [[{write_concurrency, true}, {decentralized_counters, false}],
+ [{write_concurrency, 1024}, {write_concurrency, true}]];
+ ordered_set -> []
+ end),
lists:foreach(
fun(OptList) ->
T1 = ets:new(t1, [public,
@@ -5250,7 +5255,9 @@ do_test_decentralized_counters_setting(TableType) ->
wait_for_memory_deallocations(),
FlxCtrMemUsage = erts_debug:get_internal_state(flxctr_memory_usage)
end,
- [[{decentralized_counters, true}]]),
+ [[{decentralized_counters, true}],
+ [{write_concurrency, 1024}],
+ [{write_concurrency, auto}]]),
ok.
do_test_decentralized_counters_default_setting() ->
--
2.31.1