]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Make room for data being read in from disk, to avoid overflowing cache_mem
authorHenrik Nordstrom <henrik@henriknordstrom.net>
Mon, 27 Jul 2009 12:35:50 +0000 (14:35 +0200)
committerHenrik Nordstrom <henrik@henriknordstrom.net>
Mon, 27 Jul 2009 12:35:50 +0000 (14:35 +0200)
src/Store.h
src/store.cc
src/store_client.cc

index fde6afcb3385c02687195cc575b272b40dabb711..0a6d7601e6b6cace65f91c8e940a7d2274c2c2d6 100644 (file)
@@ -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
index 5d0baa815f07ac20955d1cffbba431f5a67f1f60..ca7f0565595af87584d6e9186516bf8e626d3a55 100644 (file)
@@ -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);
index 5b6c5f70815a93f08ffb1725059ee8aee7c23ca1..e951bab6f1030ca855707d0fa0a225d41b109e09 100644 (file)
@@ -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);
+            }
         }
     }