]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Honor SBufReservationRequirements::minSize regardless of idealSize.
authorAlex Rousskov <rousskov@measurement-factory.com>
Fri, 4 Nov 2016 21:14:54 +0000 (15:14 -0600)
committerAlex Rousskov <rousskov@measurement-factory.com>
Fri, 4 Nov 2016 21:14:54 +0000 (15:14 -0600)
In a fully specified SBufReservationRequirements, idealSize would
naturally match or exceed minSize. However, the idealSize default value
(zero) may not. We should honor minSize regardless of idealSize, just as
the API documentation promises to do.

No runtime changes expected right now because the only existing user of
SBufReservationRequirements sets .idealSize to CLIENT_REQ_BUF_SZ (4096)
and .minSize to 1024.

src/sbuf/SBuf.cc
src/sbuf/SBuf.h
src/tests/testSBuf.cc

index 663477fc5b80ca5fa5c59d0fb26dee839b843b01..927a21b855e6434e8517b9d1c559898fc44c6354 100644 (file)
@@ -139,7 +139,8 @@ SBuf::reserve(const SBufReservationRequirements &req)
     if (!mustRealloc && len_ >= req.maxCapacity)
         return spaceSize(); // but we cannot reallocate
 
-    const size_type newSpace = std::min(req.idealSpace, maxSize - len_);
+    const size_type desiredSpace = std::max(req.minSpace, req.idealSpace);
+    const size_type newSpace = std::min(desiredSpace, maxSize - len_);
     reserveCapacity(std::min(len_ + newSpace, req.maxCapacity));
     debugs(24, 7, id << " now: " << off_ << '+' << len_ << '+' << spaceSize() <<
            '=' << store_->capacity);
index 7b5e0a038cc509e02a4ea760323cb42dd1de9587..cda0f8bfeb817b331d30eb7bb9660ac39543b646 100644 (file)
@@ -696,9 +696,10 @@ public:
     /*
      * Parameters are listed in the reverse order of importance: Satisfaction of
      * the lower-listed requirements may violate the higher-listed requirements.
+     * For example, idealSpace has no effect unless it exceeds minSpace.
      */
     size_type idealSpace = 0; ///< if allocating anyway, provide this much space
-    size_type minSpace = 0; ///< allocate if spaceSize() is smaller
+    size_type minSpace = 0; ///< allocate [at least this much] if spaceSize() is smaller
     size_type maxCapacity = SBuf::maxSize; ///< do not allocate more than this
     bool allowShared = true; ///< whether sharing our storage with others is OK
 };
index 23dd6b6396434ed340d9a29951725f41e70cc143..4f29d2955095dfcaa306022f6ce22bd78834bebb 100644 (file)
@@ -839,6 +839,15 @@ testSBuf::testReserve()
                 b.append('X');
         }
     }
+
+    // the minimal space requirement should overwrite idealSpace preferences
+    requirements.minSpace = 10;
+    for (const int delta: {-1,0,+1}) {
+        requirements.idealSpace = requirements.minSpace + delta;
+        SBuf buffer;
+        buffer.reserve(requirements);
+        CPPUNIT_ASSERT(buffer.spaceSize() >= requirements.minSpace);
+    }
 }
 
 void