From: Alex Rousskov Date: Fri, 4 Nov 2016 21:14:54 +0000 (-0600) Subject: Honor SBufReservationRequirements::minSize regardless of idealSize. X-Git-Tag: SQUID_4_0_17~40 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ecf0d881cd83551f374d720bb1f8624ad4ed6f24;p=thirdparty%2Fsquid.git Honor SBufReservationRequirements::minSize regardless of idealSize. 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. --- diff --git a/src/sbuf/SBuf.cc b/src/sbuf/SBuf.cc index 663477fc5b..927a21b855 100644 --- a/src/sbuf/SBuf.cc +++ b/src/sbuf/SBuf.cc @@ -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); diff --git a/src/sbuf/SBuf.h b/src/sbuf/SBuf.h index 7b5e0a038c..cda0f8bfeb 100644 --- a/src/sbuf/SBuf.h +++ b/src/sbuf/SBuf.h @@ -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 }; diff --git a/src/tests/testSBuf.cc b/src/tests/testSBuf.cc index 23dd6b6396..4f29d29550 100644 --- a/src/tests/testSBuf.cc +++ b/src/tests/testSBuf.cc @@ -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