[master] 9c4f3e8 Add a final backstop, so we absolutely 100% certainly do not try to delete a objhead while it still has a waiting list, by forcing the last ref holder to rush the WL.
Poul-Henning Kamp
phk at FreeBSD.org
Thu Jan 7 01:11:05 CET 2016
commit 9c4f3e8097bacaceee647a0e5f01d2323c02421c
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Thu Jan 7 00:03:35 2016 +0000
Add a final backstop, so we absolutely 100% certainly do not
try to delete a objhead while it still has a waiting list,
by forcing the last ref holder to rush the WL.
Since the hasher owns the refcounts on objhead, we cannot just
mingle req and objcore refcounts.
Fortunately we don't need to add another refcounter, because all
we really care about is the wl being empty when we drop the last
ref.
The wl/hsh_rush() mechanism will work differently with different
thread-scheduling schenarios, and I cannot definitively rule out
that we can drop the last ref on an oh, while there are still req's
on the waiting list.
Given that, and the existence proof in ticket #1823's race, this
might have been the indicated memory-trampler.
diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c
index e22289d..12fd0d6 100644
--- a/bin/varnishd/cache/cache_hash.c
+++ b/bin/varnishd/cache/cache_hash.c
@@ -793,10 +793,25 @@ HSH_DerefObjHead(struct worker *wrk, struct objhead **poh)
oh->refcnt--;
Lck_Unlock(&oh->mtx);
return(1);
- } else if (!VTAILQ_EMPTY(&oh->waitinglist)) {
+ }
+
+ /*
+ * Make absolutely certain that we do not let the final ref
+ * disappear until the waitinglist is empty.
+ * This is necessary because the req's on the waiting list do
+ * not hold any ref on the objhead of their own, and we cannot
+ * just make the hold the same ref's as objcore, that would
+ * confuse hashers.
+ */
+ while (!VTAILQ_EMPTY(&oh->waitinglist)) {
Lck_Lock(&oh->mtx);
+ assert(oh->refcnt > 0);
+ r = oh->refcnt;
hsh_rush(wrk, oh);
Lck_Unlock(&oh->mtx);
+ if (r > 1)
+ break;
+ usleep(100000);
}
assert(oh->refcnt > 0);
diff --git a/bin/varnishd/hash/hash_critbit.c b/bin/varnishd/hash/hash_critbit.c
index da671f5..4b9cc6b 100644
--- a/bin/varnishd/hash/hash_critbit.c
+++ b/bin/varnishd/hash/hash_critbit.c
@@ -394,9 +394,7 @@ hcb_start(void)
static int __match_proto__(hash_deref_f)
hcb_deref(struct objhead *oh)
{
- int r;
- r = 1;
CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC);
Lck_Lock(&oh->mtx);
assert(oh->refcnt > 0);
@@ -411,7 +409,7 @@ hcb_deref(struct objhead *oh)
#ifdef PHK
fprintf(stderr, "hcb_defef %d %d <%s>\n", __LINE__, r, oh->hash);
#endif
- return (r);
+ return (1);
}
static struct objhead * __match_proto__(hash_lookup_f)
More information about the varnish-commit
mailing list