[master] 5c2a682aa sml: Optimize freebehind (transient) memory usage
Nils Goroll
nils.goroll at uplex.de
Mon Sep 30 16:15:05 UTC 2024
commit 5c2a682aa39af1c61e860f3a62a204d200ac3211
Author: Nils Goroll <nils.goroll at uplex.de>
Date: Thu Sep 26 12:06:03 2024 +0200
sml: Optimize freebehind (transient) memory usage
Previously, sml_iterator() could not free the last segment while iterating,
because it could have turned out to be over-allocated at any time and be
removed.
With the change from the previous commit, we can now lift this limitation and
take a reference to also the last segment.
This is relevant because, due to of the race between the fetch and iterator site
of a transient operation, the "is last segment" condition can happen at any
point while an object is busy.
diff --git a/bin/varnishd/storage/storage_simple.c b/bin/varnishd/storage/storage_simple.c
index 74657365a..53eb305de 100644
--- a/bin/varnishd/storage/storage_simple.c
+++ b/bin/varnishd/storage/storage_simple.c
@@ -395,15 +395,14 @@ sml_iterator(struct worker *wrk, struct objcore *oc,
assert(nl > 0);
sl += st->len;
st = VTAILQ_PREV(st, storagehead, list);
- if (VTAILQ_PREV(st, storagehead, list) != NULL) {
- if (final && checkpoint != NULL) {
- VTAILQ_REMOVE(&obj->list,
- checkpoint, list);
- sml_stv_free(stv, checkpoint);
- }
- checkpoint = st;
- checkpoint_len = sl;
+ if (final && checkpoint != NULL) {
+ VTAILQ_REMOVE(&obj->list, checkpoint, list);
+ if (checkpoint == boc->stevedore_priv)
+ boc->stevedore_priv = trim_once;
+ sml_stv_free(stv, checkpoint);
}
+ checkpoint = st;
+ checkpoint_len = sl;
}
CHECK_OBJ_NOTNULL(obj, OBJECT_MAGIC);
CHECK_OBJ_NOTNULL(st, STORAGE_MAGIC);
More information about the varnish-commit
mailing list