From: Henrik Nordstrom Date: Mon, 27 Jul 2009 12:35:50 +0000 (+0200) Subject: Make room for data being read in from disk, to avoid overflowing cache_mem X-Git-Tag: SQUID_3_2_0_1~795^2~19 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6d3c275803e606136ee7e46d834b17a0d2f53e62;p=thirdparty%2Fsquid.git Make room for data being read in from disk, to avoid overflowing cache_mem --- diff --git a/src/Store.h b/src/Store.h index fde6afcb33..0a6d7601e6 100644 --- a/src/Store.h +++ b/src/Store.h @@ -384,6 +384,9 @@ extern FREE destroyStoreEntry; */ SQUIDCEXTERN void packerToStoreInit(Packer * p, StoreEntry * e); +/// \ingroup StoreAPI +SQUIDCEXTERN void storeGetMemSpace(int size); + #ifdef _USE_INLINE_ #include "Store.cci" #endif diff --git a/src/store.cc b/src/store.cc index 5d0baa815f..ca7f056559 100644 --- a/src/store.cc +++ b/src/store.cc @@ -99,7 +99,6 @@ static storerepl_entry_t *storerepl_list = NULL; /* * local function prototypes */ -static void storeGetMemSpace(int); static int getKeyCounter(void); static OBJH storeCheckCachableStats; static EVH storeLateRelease; @@ -1112,8 +1111,10 @@ StoreEntry::abort() unlock(); /* unlock */ } -/* Clear Memory storage to accommodate the given object len */ -static void +/** + * Clear Memory storage to accommodate the given object len + */ +void storeGetMemSpace(int size) { PROF_start(storeGetMemSpace); diff --git a/src/store_client.cc b/src/store_client.cc index 5b6c5f7081..e951bab6f1 100644 --- a/src/store_client.cc +++ b/src/store_client.cc @@ -500,18 +500,20 @@ store_client::readBody(const char *buf, ssize_t len) const HttpReply *rep = entry->getReply(); if (len > 0 && rep && entry->mem_obj->inmem_lo == 0 && entry->objectLen() <= (int64_t)Config.Store.maxInMemObjSize) { - /* Copy read data back into memory. - * but first we need to adjust offset.. some parts of the code - * counts offset including headers, some parts count offset as - * withing the body.. copyInto is including headers, but the mem - * cache expects offset without headers (using negative for headers) - * eventually not storing packed headers in memory at all. - */ - int64_t mem_offset = entry->mem_obj->endOffset() + rep->hdr_sz; - if ((copyInto.offset == mem_offset) || (parsed_header && mem_offset == rep->hdr_sz)) { - StoreIOBuffer tmp = copyInto; - tmp.offset -= rep->hdr_sz; - entry->mem_obj->write(tmp, storeClientMemWriteComplete, this); + storeGetMemSpace(len); + // The above may start to free our object so we need to check again + if (entry->mem_obj->inmem_lo == 0) { + /* Copy read data back into memory. + * but first we need to adjust offset.. some parts of the code + * counts offset including headers, some parts count offset as + * withing the body.. copyInto is including headers, but the mem + * cache expects offset without headers (using negative for headers) + * eventually not storing packed headers in memory at all. + */ + int64_t mem_offset = entry->mem_obj->endOffset() + rep->hdr_sz; + if ((copyInto.offset == mem_offset) || (parsed_header && mem_offset == rep->hdr_sz)) { + entry->mem_obj->write(StoreIOBuffer(len, copyInto.offset - rep->hdr_sz, copyInto.data), storeClientMemWriteComplete, this); + } } }