From 53d8e34bbb9a0c569ce7daa091d89e729864eb9e Mon Sep 17 00:00:00 2001 From: Olivier Houchard Date: Thu, 14 Mar 2024 00:25:56 +0100 Subject: [PATCH] ck_rhs: Get the right probe to restore on memory failure. In ck_rhs_put_robin_hood(), on memory failure, restore the right probe for each descriptor. Descriptor at index 1 will want the probe at index 0, descriptor at index 2 will want the probe at index 1, etc, etc. And always store the last descriptor slot, so that we know where to put the last probe. --- src/ck_rhs.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/ck_rhs.c b/src/ck_rhs.c index a575ee58..aaf1d71c 100644 --- a/src/ck_rhs.c +++ b/src/ck_rhs.c @@ -915,6 +915,7 @@ ck_rhs_put_robin_hood(struct ck_rhs *hs, void *key; long prevs[CK_RHS_MAX_RH]; int prev_probes[CK_RHS_MAX_RH]; + long last_slot = -1; unsigned int prevs_nb = 0; unsigned int i; @@ -940,10 +941,12 @@ ck_rhs_put_robin_hood(struct ck_rhs *hs, desc->in_rh = false; for (i = 0; i < prevs_nb; i++) { - - ck_rhs_set_probes(map, prevs[i], prev_probes[i]); + if (i > 0) + ck_rhs_set_probes(map, prevs[i], prev_probes[i - 1]); ck_rhs_unset_rh(map, prevs[i]); } + if (last_slot != -1) + ck_rhs_set_probes(map, last_slot, prev_probes[prevs_nb - 1]); return -1; } @@ -955,6 +958,8 @@ ck_rhs_put_robin_hood(struct ck_rhs *hs, desc = ck_rhs_desc(map, first); int old_probes = desc->probes; + last_slot = first; + desc->probes = n_probes; h = ck_rhs_get_first_offset(map, first, n_probes); ck_rhs_map_bound_set(map, h, n_probes);