From: Alex Rousskov Date: Sat, 25 Mar 2023 03:40:27 +0000 (+0000) Subject: Improve detection of lonely StoreEntry clients (#1312) X-Git-Tag: SQUID_7_0_1~459 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d2000809ffc2bf30545470eb2a91c92c161aa8cb;p=thirdparty%2Fsquid.git Improve detection of lonely StoreEntry clients (#1312) The first storeClientType() call still sees zero nclients because storeClientListAdd() creates a store_client object (which triggers storeClientType()) first and only then adds it to the list of clients (which increases nclients). This off-by-one bug was introduced in commit 528b2c6 that reordered nclients increase and the storeClientType() call. The bug could lead to excessive disk I/O in some environments because Squid could see more STORE_DISK_CLIENT store_client objects, and those may trigger startSwapin() in store_client::doCopy(). However, the exact effects of this bug/fix are difficult to predict because startSwapin() may be separated by async calls and is guarded by additional conditions. A full fix requires refactoring the caller, but there are so many problems associated with storeClientType() and startSwapin() calls that such refactoring deserves a dedicated effort. Technically, this "first" client may be 10th client this StoreEntry has seen, but it is the first one among the _current_ entry clients. --- diff --git a/src/store.cc b/src/store.cc index 44b866582e..2df3a72eba 100644 --- a/src/store.cc +++ b/src/store.cc @@ -290,7 +290,7 @@ StoreEntry::storeClientType() const /* * If this is the first client, let it be the mem client */ - if (mem_obj->nclients == 1) + if (mem_obj->nclients == 0) return STORE_MEM_CLIENT; /*