From: Alex Rousskov Date: Thu, 14 Apr 2011 20:28:39 +0000 (-0600) Subject: Polished desired total memory size calculation. X-Git-Tag: take06~23 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=39c0d9944021564cac20ec094ed1eb23c6efa4fd;p=thirdparty%2Fsquid.git Polished desired total memory size calculation. --- diff --git a/src/ipc/mem/PagePool.cc b/src/ipc/mem/PagePool.cc index 5f270904f0..b698017302 100644 --- a/src/ipc/mem/PagePool.cc +++ b/src/ipc/mem/PagePool.cc @@ -25,7 +25,7 @@ Ipc::Mem::PagePool::PagePool(const String &id, const unsigned int capacity, cons pageIndex(PageIndexId(id), capacity), shm(id.termedBuf()) { - shm.create(sizeof(Shared) + pageSize*capacity); + shm.create(Shared::MemSize(capacity, pageSize)); assert(shm.mem()); shared = new (shm.mem()) Shared(capacity, pageSize); } @@ -81,3 +81,10 @@ Ipc::Mem::PagePool::Shared::Shared(const unsigned int aCapacity, size_t aPageSiz if (LastPagePoolId + 1 == 0) ++LastPagePoolId; // skip zero pool id } + +off_t +Ipc::Mem::PagePool::Shared::MemSize(const unsigned int capacity, const size_t pageSize) +{ + return static_cast(sizeof(Shared)) + + static_cast(pageSize) * capacity; +} diff --git a/src/ipc/mem/PagePool.h b/src/ipc/mem/PagePool.h index ff4693d8b8..9c8d93a297 100644 --- a/src/ipc/mem/PagePool.h +++ b/src/ipc/mem/PagePool.h @@ -41,6 +41,9 @@ private: struct Shared { Shared(const unsigned int aCapacity, const size_t aPageSize); + /// total shared memory size required to share + static off_t MemSize(const unsigned int capacity, const size_t pageSize); + const unsigned int theId; ///< pool id const unsigned int theCapacity; ///< number of pages in the pool const size_t thePageSize; ///< page size @@ -51,7 +54,7 @@ private: PageStack pageIndex; ///< free pages index Segment shm; ///< shared memory segment to store metadata (and pages) - Shared *shared; ///< our metadata and page storage, shared among all stack users + Shared *shared; ///< our metadata and page storage, shared among all pool users }; } // namespace Mem