Bug 81640: Set max cache entry size to be MIN (5MB, 1/8 Cache Capacity)
authorByron Milligan <bmilligan@mozilla.com>
Wed, 01 Sep 2010 14:47:39 -0700
changeset 52138 8a1dd2ad86b51c44d9b1c27bbe3772a45973d0a0
parent 52137 2d00495994f651c5922f2f165612f87456307607
child 52139 a02aee4f7197c336b1307f909fb1c950265cbbd3
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
bugs81640
milestone2.0b5pre
Bug 81640: Set max cache entry size to be MIN (5MB, 1/8 Cache Capacity)
netwerk/cache/nsDiskCacheDevice.cpp
netwerk/cache/nsDiskCacheMap.h
--- a/netwerk/cache/nsDiskCacheDevice.cpp
+++ b/netwerk/cache/nsDiskCacheDevice.cpp
@@ -770,18 +770,18 @@ nsDiskCacheDevice::OnDataSizeChange(nsCa
     if (!binding)  return NS_ERROR_UNEXPECTED;
 
     NS_ASSERTION(binding->mRecord.ValidRecord(), "bad record");
 
     PRUint32  newSize = entry->DataSize() + deltaSize;
     PRUint32  newSizeK =  ((newSize + 0x3FF) >> 10);
 
     // If the new size is larger than max. file size or larger than
-    // half the cache capacity (which is in KiB's), doom the entry and abort
-    if ((newSize > kMaxDataFileSize) || (newSizeK > mCacheCapacity/2)) {
+    // 1/8 the cache capacity (which is in KiB's), doom the entry and abort
+    if ((newSize > kMaxDataFileSize) || (newSizeK > mCacheCapacity/8)) {
 #ifdef DEBUG
         nsresult rv =
 #endif
             nsCacheService::DoomEntry(entry);
         NS_ASSERTION(NS_SUCCEEDED(rv),"DoomEntry() failed.");
         return NS_ERROR_ABORT;
     }
 
--- a/netwerk/cache/nsDiskCacheMap.h
+++ b/netwerk/cache/nsDiskCacheMap.h
@@ -85,17 +85,18 @@ struct nsDiskCacheEntry;
  *****************************************************************************/
 
 #define BLOCK_SIZE_FOR_INDEX(index)  ((index) ? (256 << (2 * ((index) - 1))) : 0)
 
 // Min and max values for the number of records in the DiskCachemap
 #define kMinRecordCount    512
 
 #define kSeparateFile      0
-#define kMaxDataFileSize   0x3FFFC00   // 65535 KiB (see bug #443067)
+// #define must always  be <= 65535KB, or overflow. See bug 443067 Comment 8
+#define kMaxDataFileSize   5 * 1024 * 1024  // 5 MB (in bytes) 
 #define kBuckets           (1 << 5)    // must be a power of 2!
 
 class nsDiskCacheRecord {
 
 private:
     PRUint32    mHashNumber;
     PRUint32    mEvictionRank;
     PRUint32    mDataLocation;