Skip to content

Commit 91ca65c

Browse files
committed
Merging branch/2023-05-31/hash-arrays for GitHub pull request #230 <#230>.
2 parents 7721525 + eecc0be commit 91ca65c

File tree

4 files changed

+69
-1
lines changed

4 files changed

+69
-1
lines changed

code/mps.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,9 @@ extern const struct mps_key_s _mps_key_FMT_PAD;
259259
extern const struct mps_key_s _mps_key_FMT_CLASS;
260260
#define MPS_KEY_FMT_CLASS (&_mps_key_FMT_CLASS)
261261
#define MPS_KEY_FMT_CLASS_FIELD fmt_class
262+
extern const struct mps_key_s _mps_key_ap_hash_arrays;
263+
#define MPS_KEY_AP_HASH_ARRAYS (&_mps_key_ap_hash_arrays)
264+
#define MPS_KEY_AP_HASH_ARRAYS_FIELD b
262265

263266
/* Maximum length of a keyword argument list. */
264267
#define MPS_ARGS_MAX 32

code/poolamc.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,6 @@ static Res AMCBufInit(Buffer buffer, Pool pool, Bool isMutator, ArgList args)
513513
if (ArgPick(&arg, args, amcKeyAPHashArrays))
514514
forHashArrays = arg.val.b;
515515

516-
/* call next method */
517516
res = NextMethod(Buffer, amcBuf, init)(buffer, pool, isMutator, args);
518517
if(res != ResOK)
519518
return res;

manual/source/pool/amc.rst

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,63 @@ AMC interface
139139
MPS_ARGS_ADD(args, MPS_KEY_FORMAT, fmt);
140140
res = mps_pool_create_k(&pool, arena, mps_class_amc(), args);
141141
} MPS_ARGS_END(args);
142+
143+
When creating an :term:`allocation point` on an AMC pool,
144+
:c:func:`mps_ap_create_k` accepts one optional keyword argument:
145+
146+
* :c:macro:`MPS_KEY_AP_HASH_ARRAYS` (type :c:type:`mps_bool_t`,
147+
defaulting to false) specifies (if true) that blocks allocated
148+
from the allocation point do not contribute to the *new size* of
149+
the :term:`nursery space` for the purposes of deciding whether
150+
to start a collection of that generation. See
151+
:ref:`pool-amc-hash-arrays`.
152+
153+
154+
.. index::
155+
pair: AMC pool class; hash arrays
156+
157+
.. _pool-amc-hash-arrays:
158+
159+
Hash arrays
160+
-----------
161+
162+
The :term:`location dependency` feature of the MPS allows the
163+
:term:`client program` to implement address-based hash tables in pools
164+
like AMC that use a :term:`moving memory manager`, re-hashing the
165+
tables when the addresses they contain might have moved.
166+
167+
However, when a frequently-used hash table grows large enough, the
168+
following sequence of events may take place:
169+
170+
1. The hash table discovers that its location dependency is stale.
171+
172+
2. A new array is allocated to contain the re-hashed keys.
173+
174+
3. The new array is large enough to push the *new size* of the
175+
:term:`nursery space` (that is, the amount of newly allocated
176+
memory since the last collection in the first :term:`generation` in
177+
the :term:`generation chain` for the pool containing the array)
178+
close to its capacity.
179+
180+
4. A small amount of additional allocation causes the new size of the
181+
nursery generation to exceed its capacity, which causes the MPS to
182+
start a new collection of that generation. This in turn causes the
183+
hash table to become stale again.
184+
185+
When the hash table reaches this critical size, the client program may
186+
find that a large fraction of its time is being spent re-hashing the
187+
table.
188+
189+
In order to avoid this happening, the MPS provides a mechanism for
190+
specifying that the newly allocated array does not contribute to the
191+
new size of the nursery space: this cuts off the vicious cycle at step
192+
3.
193+
194+
To enable this mechanism, use the optional :c:macro:`MPS_KEY_AP_HASH_ARRAYS`
195+
keyword argument when creating an allocation point with
196+
:c:func:`mps_ap_create_k`. This interface is documented in the AMC Interface
197+
section of the :ref:`pool-amc` documentation above.
198+
199+
See :ref:`topic-collection-schedule` for an explanation of the *new
200+
size* of a generation, and how the MPS uses this to determine when to
201+
start a collection of that generation.

manual/source/release.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ New features
4747
:ref:`topic-scanning-protocol`. This allows the client program to
4848
safely update references in the visited objects.
4949

50+
#. An :term:`allocation point` for a pool belonging to the class
51+
:ref:`pool-amc` can now be configured so that allocations do not
52+
provoke garbage collections, reducing the amount of re-hashing for
53+
address-based hash tables using :term:`location dependency`. See
54+
:ref:`pool-amc-hash-arrays`.
55+
5056
#. The new function :c:func:`mps_addr_object` allows clients to
5157
discover the base pointer of an object from a pointer to anywhere
5258
inside the object. This is intended to support stack tracing and

0 commit comments

Comments
 (0)