]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Honor SBufReservationRequirements::minSize regardless of idealSize.
authorAlex Rousskov <rousskov@measurement-factory.com>
Mon, 14 Nov 2016 12:40:51 +0000 (01:40 +1300)
committerAmos Jeffries <squid3@treenet.co.nz>
Mon, 14 Nov 2016 12:40:51 +0000 (01:40 +1300)
  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.cc
src/SBuf.h

index c8172e86b059f12a462f3582bb2608a60e436cfe..1293f70573454482393316606163cb999b38a4dd 100644 (file)
@@ -178,7 +178,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 8a40d2bdc4907a819bf0b82e840a2724598fa5b5..ae8ba7bffc12d6cf20bd3539a40ee13ecbaa4da5 100644 (file)
@@ -635,9 +635,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; ///< if allocating anyway, provide this much space
-    size_type minSpace; ///< allocate if spaceSize() is smaller
+    size_type minSpace; ///< allocate [at least this much] if spaceSize() is smaller
     size_type maxCapacity; ///< do not allocate more than this
     bool allowShared; ///< whether sharing our storage with others is OK
 };