@@ -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.
0 commit comments