]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Polished desired total memory size calculation.
authorAlex Rousskov <rousskov@measurement-factory.com>
Thu, 14 Apr 2011 20:28:39 +0000 (14:28 -0600)
committerAlex Rousskov <rousskov@measurement-factory.com>
Thu, 14 Apr 2011 20:28:39 +0000 (14:28 -0600)
src/ipc/mem/PagePool.cc
src/ipc/mem/PagePool.h

index 5f270904f0d580ae6097693a6dcd068f0ba18fd0..b698017302332ebf1f1336c0114f5526f2e09195 100644 (file)
@@ -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<off_t>(sizeof(Shared)) +
+        static_cast<off_t>(pageSize) * capacity;
+}
index ff4693d8b88ca72ac3eadf10a68d4bfc12ee8c81..9c8d93a297ea865daf3076a13f24a1b31e8b551d 100644 (file)
@@ -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