Skip to content

Commit 672b8e8

Browse files
committed
erts: Report the effective atom_limit
erts_index_init() grows its table one INDEX_PAGE_SIZE page at a time and only checks the limit when allocating a new page, so the effective limit is the requested value rounded up to a whole number of pages. Store that rounded value in t->limit so that erlang:system_info(atom_limit) reports the limit actually enforced, like process_limit and port_limit do, rather than echoing back the raw +t value.
1 parent 3511f2a commit 672b8e8

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

erts/emulator/beam/index.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,15 @@ IndexTable*
6060
erts_index_init(ErtsAlcType_t type, IndexTable* t, char* name,
6161
int size, int limit, HashFunctions fun)
6262
{
63-
Uint base_size = (((Uint)limit+INDEX_PAGE_SIZE-1)/INDEX_PAGE_SIZE)*sizeof(IndexSlot*);
63+
/* Round up to a whole number of pages; the table only enforces its limit at
64+
* a page boundary, so this is the effective limit reported to the user. */
65+
Uint pages = ((Uint)limit+INDEX_PAGE_SIZE-1)/INDEX_PAGE_SIZE;
66+
Uint effective_limit = pages*INDEX_PAGE_SIZE;
67+
Uint base_size = pages*sizeof(IndexSlot*);
6468
hash_init(type, &t->htable, name, 3*size/4, fun);
6569

6670
t->size = 0;
67-
t->limit = limit;
71+
t->limit = effective_limit <= INT_MAX ? (int)effective_limit : limit;
6872
t->entries = 0;
6973
t->type = type;
7074
t->seg_table = (IndexSlot***) erts_alloc(type, base_size);

erts/emulator/test/system_info_SUITE.erl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -537,11 +537,13 @@ get_ets_limit(EtsMax) ->
537537
Res.
538538

539539

540-
%% Verify system_info(atom_limit) reflects max atoms settings
541-
%% (using " +t").
540+
%% Verify system_info(atom_limit) reflects max atoms settings (using " +t"),
541+
%% reported as the effective limit (the requested size rounded up to a whole
542+
%% number of index-table pages of 1024 entries).
542543
atom_limit(Config0) when is_list(Config0) ->
543544
{ok, Peer, Node} = ?CT_PEER(["+t", "2186042"]),
544-
2186042 = rpc:call(Node, erlang, system_info, [atom_limit]),
545+
%% 2186042 rounded up to a multiple of 1024 = 2135 * 1024.
546+
2186240 = rpc:call(Node, erlang, system_info, [atom_limit]),
545547
peer:stop(Peer).
546548

547549
%% Verify that system_info(atom_count) works.

0 commit comments

Comments
 (0)