]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Shuffle MemAllocator to Mem namespace (#1181)
authorAmos Jeffries <yadij@users.noreply.github.com>
Mon, 28 Nov 2022 14:46:51 +0000 (14:46 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Mon, 28 Nov 2022 22:44:14 +0000 (22:44 +0000)
Update and add missing documentation for class members.

Update syntax to latest standard compliance and Squid
coding guideline style.

21 files changed:
src/DiskIO/DiskThreads/aiops.cc
src/DiskIO/DiskThreads/aiops_win32.cc
src/Store.h
src/auth/digest/Config.cc
src/cbdata.cc
src/mem/Allocator.h [new file with mode: 0644]
src/mem/AllocatorProxy.cc
src/mem/AllocatorProxy.h
src/mem/Makefile.am
src/mem/Pool.cc
src/mem/Pool.h
src/mem/PoolChunked.cc
src/mem/PoolChunked.h
src/mem/PoolMalloc.h
src/mem/minimal.cc
src/mem/old_api.cc
src/pconn.cc
src/repl/lru/store_repl_lru.cc
src/store.cc
src/tests/stub_libmem.cc
src/tests/testMem.cc

index c39de151ee01370705ab42c5ee8c31e034a3b704..e3b4ba3875d0ccad2611d6fedbcbb5e650da5342 100644 (file)
@@ -111,15 +111,15 @@ static int squidaio_initialised = 0;
 #define AIO_TINY_BUFS   AIO_LARGE_BUFS >> 3
 #define AIO_MICRO_BUFS  128
 
-static MemAllocator *squidaio_large_bufs = nullptr;    /* 16K */
-static MemAllocator *squidaio_medium_bufs = nullptr;   /* 8K */
-static MemAllocator *squidaio_small_bufs = nullptr;    /* 4K */
-static MemAllocator *squidaio_tiny_bufs = nullptr; /* 2K */
-static MemAllocator *squidaio_micro_bufs = nullptr;    /* 128K */
+static Mem::Allocator *squidaio_large_bufs = nullptr; /* 16K */
+static Mem::Allocator *squidaio_medium_bufs = nullptr; /* 8K */
+static Mem::Allocator *squidaio_small_bufs = nullptr; /* 4K */
+static Mem::Allocator *squidaio_tiny_bufs = nullptr; /* 2K */
+static Mem::Allocator *squidaio_micro_bufs = nullptr; /* 128K */
 
 static int request_queue_len = 0;
-static MemAllocator *squidaio_request_pool = nullptr;
-static MemAllocator *squidaio_thread_pool = nullptr;
+static Mem::Allocator *squidaio_request_pool = nullptr;
+static Mem::Allocator *squidaio_thread_pool = nullptr;
 static squidaio_request_queue_t request_queue;
 
 static struct {
@@ -147,7 +147,7 @@ static struct sched_param globsched;
 #endif
 static pthread_t main_thread;
 
-static MemAllocator *
+static Mem::Allocator *
 squidaio_get_pool(int size)
 {
     if (size <= AIO_LARGE_BUFS) {
@@ -170,9 +170,8 @@ void *
 squidaio_xmalloc(int size)
 {
     void *p;
-    MemAllocator *pool;
 
-    if ((pool = squidaio_get_pool(size)) != nullptr) {
+    if (const auto pool = squidaio_get_pool(size)) {
         p = pool->alloc();
     } else
         p = xmalloc(size);
@@ -195,9 +194,7 @@ squidaio_xstrdup(const char *str)
 void
 squidaio_xfree(void *p, int size)
 {
-    MemAllocator *pool;
-
-    if ((pool = squidaio_get_pool(size)) != nullptr) {
+    if (const auto pool = squidaio_get_pool(size)) {
         pool->freeOne(p);
     } else
         xfree(p);
@@ -206,10 +203,9 @@ squidaio_xfree(void *p, int size)
 static void
 squidaio_xstrfree(char *str)
 {
-    MemAllocator *pool;
     int len = strlen(str) + 1;
 
-    if ((pool = squidaio_get_pool(len)) != nullptr) {
+    if (const auto pool = squidaio_get_pool(len)) {
         pool->freeOne(str);
     } else
         xfree(str);
index a03bec906bfe3a52db33b0eaa3ab6414d94f8e17..24f8b3144f6b7372685ed754d379cec3dc5e6bc3 100644 (file)
@@ -102,15 +102,15 @@ static int squidaio_initialised = 0;
 #define AIO_TINY_BUFS   AIO_LARGE_BUFS >> 3
 #define AIO_MICRO_BUFS  128
 
-static MemAllocator *squidaio_large_bufs = NULL;    /* 16K */
-static MemAllocator *squidaio_medium_bufs = NULL;   /* 8K */
-static MemAllocator *squidaio_small_bufs = NULL;    /* 4K */
-static MemAllocator *squidaio_tiny_bufs = NULL; /* 2K */
-static MemAllocator *squidaio_micro_bufs = NULL;    /* 128K */
+static Mem::Allocator *squidaio_large_bufs = nullptr; /* 16K */
+static Mem::Allocator *squidaio_medium_bufs = nullptr; /* 8K */
+static Mem::Allocator *squidaio_small_bufs = nullptr; /* 4K */
+static Mem::Allocator *squidaio_tiny_bufs = nullptr; /* 2K */
+static Mem::Allocator *squidaio_micro_bufs = nullptr; /* 128K */
 
 static int request_queue_len = 0;
-static MemAllocator *squidaio_request_pool = NULL;
-static MemAllocator *squidaio_thread_pool = NULL;
+static Mem::Allocator *squidaio_request_pool = nullptr;
+static Mem::Allocator *squidaio_thread_pool = nullptr;
 static squidaio_request_queue_t request_queue;
 
 static struct {
@@ -134,7 +134,7 @@ done_requests = {
 
 static HANDLE main_thread;
 
-static MemAllocator *
+static Mem::Allocator *
 squidaio_get_pool(int size)
 {
     if (size <= AIO_LARGE_BUFS) {
@@ -157,9 +157,7 @@ void *
 squidaio_xmalloc(int size)
 {
     void *p;
-    MemAllocator *pool;
-
-    if ((pool = squidaio_get_pool(size)) != NULL) {
+    if (const auto pool = squidaio_get_pool(size)) {
         p = pool->alloc();
     } else
         p = xmalloc(size);
@@ -182,9 +180,7 @@ squidaio_xstrdup(const char *str)
 void
 squidaio_xfree(void *p, int size)
 {
-    MemAllocator *pool;
-
-    if ((pool = squidaio_get_pool(size)) != NULL) {
+    if (const auto pool = squidaio_get_pool(size)) {
         pool->freeOne(p);
     } else
         xfree(p);
@@ -193,10 +189,9 @@ squidaio_xfree(void *p, int size)
 static void
 squidaio_xstrfree(char *str)
 {
-    MemAllocator *pool;
     int len = strlen(str) + 1;
 
-    if ((pool = squidaio_get_pool(len)) != NULL) {
+    if (const auto pool = squidaio_get_pool(len)) {
         pool->freeOne(str);
     } else
         xfree(str);
index 62894acffac428a7cc47fb0536ce0091b7504f85..15102c12d339916f813c0e4587857f5c4d76a997 100644 (file)
@@ -319,7 +319,7 @@ private:
     /// flags [truncated or too big] entry with ENTRY_BAD_LENGTH and releases it
     void lengthWentBad(const char *reason);
 
-    static MemAllocator *pool;
+    static Mem::Allocator *pool;
 
     unsigned short lock_count;      /* Assume < 65536! */
 
index b725f0329734cb3cb336df7b00220acb52bfbacd..1b9aa4943d269ca6bca3052e23556b8cf7e82498 100644 (file)
@@ -50,7 +50,7 @@ helper *digestauthenticators = nullptr;
 static hash_table *digest_nonce_cache;
 
 static int authdigest_initialised = 0;
-static MemAllocator *digest_nonce_pool = nullptr;
+static Mem::Allocator *digest_nonce_pool = nullptr;
 
 enum http_digest_attr_type {
     DIGEST_USERNAME,
index d464b883b3ede0d600a6715d9eae6ef4957d54af..9a9b892d3f883711dc93c5f4672f0713a8a79f54 100644 (file)
@@ -132,7 +132,7 @@ static OBJH cbdataDumpHistory;
 #endif
 
 struct CBDataIndex {
-    MemAllocator *pool;
+    Mem::Allocator *pool;
 }
 *cbdata_index = nullptr;
 
@@ -476,9 +476,7 @@ cbdataDump(StoreEntry * sentry)
     storeAppendPrintf(sentry, "types\tsize\tallocated\ttotal\n");
 
     for (int i = 1; i < cbdata_types; ++i) {
-        MemAllocator *pool = cbdata_index[i].pool;
-
-        if (pool) {
+        if (const auto pool = cbdata_index[i].pool) {
 #if WITH_VALGRIND
             int obj_size = pool->objectSize();
 #else
diff --git a/src/mem/Allocator.h b/src/mem/Allocator.h
new file mode 100644 (file)
index 0000000..19403db
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 1996-2022 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
+#ifndef SQUID_SRC_MEM_ALLOCATOR_H
+#define SQUID_SRC_MEM_ALLOCATOR_H
+
+#include "base/TypeTraits.h"
+#include "mem/forward.h"
+
+namespace Mem
+{
+
+/// An interface for memory allocators that deal with fixed-size objects.
+/// Allocators may optimize repeated de/allocations using memory pools.
+class Allocator : public Interface
+{
+public:
+    explicit Allocator(const char * const aLabel): label(aLabel) {}
+
+    // TODO make this method const
+    /**
+     * fill the given object with statistical data about pool
+     * \returns Number of objects in use, ie. allocated.
+     */
+    virtual int getStats(MemPoolStats *, int accumulate = 0) = 0;
+
+    virtual PoolMeter const &getMeter() const = 0;
+
+    /// provide (and reserve) memory suitable for storing one object
+    virtual void *alloc() = 0;
+
+    /// return memory reserved by alloc()
+    virtual void freeOne(void *) = 0;
+
+    /// brief description of objects returned by alloc()
+    virtual char const *objectType() const { return label; }
+
+    /// the size (in bytes) of objects managed by this allocator
+    virtual size_t objectSize() const = 0;
+
+    /// the difference between the number of alloc() and freeOne() calls
+    virtual int getInUseCount() = 0;
+
+    /// \see doZero
+    void zeroBlocks(const bool doIt) { doZero = doIt; }
+
+    int inUseCount() { return getInUseCount(); } // XXX: drop redundant?
+
+    /// XXX: Misplaced -- not all allocators have a notion of a "chunk". See MemPoolChunked.
+    virtual void setChunkSize(size_t) {}
+
+    /**
+     * \param minSize Minimum size needed to be allocated.
+     * \retval n Smallest size divisible by sizeof(void*)
+     */
+    static size_t RoundedSize(const size_t minSize) { return ((minSize + sizeof(void*) - 1) / sizeof(void*)) * sizeof(void*); }
+
+protected:
+    /**
+     * Whether to zero memory on initial allocation and on return to the pool.
+     *
+     * We do this on some pools because many object constructors are/were incomplete
+     * and we are afraid some code may use the object after free.
+     * When possible, set this to false to avoid zeroing overheads.
+     */
+    bool doZero = true;
+
+private:
+    const char *label = nullptr;
+};
+
+} // namespace Mem
+
+#endif /* SQUID_SRC_MEM_ALLOCATOR_H */
index a7ebe0e2e1577f0750ad5569a32e855cc1189b81..cc6a33c366ce02a427d1bb2069ff7967c947016b 100644 (file)
@@ -26,7 +26,7 @@ Mem::AllocatorProxy::freeOne(void *address)
      */
 }
 
-MemAllocator *
+Mem::Allocator *
 Mem::AllocatorProxy::getAllocator() const
 {
     if (!theAllocator) {
index 00209aa31f6a4ff436cc6e4154b38a0c44068f02..a778964561d6cfdf26e25e2be293af2b947a12a6 100644 (file)
@@ -9,7 +9,10 @@
 #ifndef _SQUID_SRC_MEM_ALLOCATORPROXY_H
 #define _SQUID_SRC_MEM_ALLOCATORPROXY_H
 
-class MemAllocator;
+// XXX: remove AllocatorProxy.h include from mem/forward.h
+namespace Mem {
+class Allocator;
+}
 class MemPoolStats;
 
 /**
@@ -80,11 +83,11 @@ public:
     void zeroBlocks(bool doIt);
 
 private:
-    MemAllocator *getAllocator() const;
+    Allocator *getAllocator() const;
 
     const char *label;
     size_t size;
-    mutable MemAllocator *theAllocator;
+    mutable Allocator *theAllocator;
     bool doZero;
 };
 
index 68760861d7d73825b37a76e34cb824ea409f8290..230314395334053fbde8573337b011fd38b12e09 100644 (file)
@@ -19,6 +19,7 @@ noinst_HEADERS = \
 
 # a full-featured memory management library for sbin/squid use
 libmem_la_SOURCES = \
+       Allocator.h \
        AllocatorProxy.cc \
        Meter.h \
        Pool.cc \
index 1f5c32f621ffc17a720a280f7b4d073644ad1b46..f213a8ba0db6cc0225bb4f244adc5c3520c697e0 100644 (file)
@@ -90,18 +90,6 @@ MemPools::setDefaultPoolChunking(bool const &aBool)
     defaultIsChunked = aBool;
 }
 
-char const *
-MemAllocator::objectType() const
-{
-    return label;
-}
-
-int
-MemAllocator::inUseCount()
-{
-    return getInUseCount();
-}
-
 void
 MemImplementingAllocator::flushMeters()
 {
@@ -216,7 +204,6 @@ int
 memPoolGetGlobalStats(MemPoolGlobalStats * stats)
 {
     int pools_inuse = 0;
-    MemAllocator *pool;
     MemPoolIterator *iter;
 
     memset(stats, 0, sizeof(MemPoolGlobalStats));
@@ -226,7 +213,7 @@ memPoolGetGlobalStats(MemPoolGlobalStats * stats)
 
     /* gather all stats for Totals */
     iter = memPoolIterate();
-    while ((pool = memPoolIterateNext(iter))) {
+    while (const auto pool = memPoolIterateNext(iter)) {
         if (pool->getStats(&pp_stats, 1) > 0)
             ++pools_inuse;
     }
@@ -246,21 +233,12 @@ memPoolGetGlobalStats(MemPoolGlobalStats * stats)
     stats->tot_items_inuse = pp_stats.items_inuse;
     stats->tot_items_idle = pp_stats.items_idle;
 
-    stats->tot_overhead += pp_stats.overhead + MemPools::GetInstance().poolCount * sizeof(MemAllocator *);
+    stats->tot_overhead += pp_stats.overhead + MemPools::GetInstance().poolCount * sizeof(Mem::Allocator *);
     stats->mem_idle_limit = MemPools::GetInstance().idleLimit();
 
     return pools_inuse;
 }
 
-MemAllocator::MemAllocator(char const *aLabel) : doZero(true), label(aLabel)
-{
-}
-
-size_t MemAllocator::RoundedSize(size_t s)
-{
-    return ((s + sizeof(void*) - 1) / sizeof(void*)) * sizeof(void*);
-}
-
 int
 memPoolsTotalAllocated(void)
 {
@@ -269,7 +247,8 @@ memPoolsTotalAllocated(void)
     return stats.TheMeter->alloc.currentLevel();
 }
 
-MemImplementingAllocator::MemImplementingAllocator(char const *aLabel, size_t aSize) : MemAllocator(aLabel),
+MemImplementingAllocator::MemImplementingAllocator(char const * const aLabel, const size_t aSize):
+    Mem::Allocator(aLabel),
     next(nullptr),
     alloc_calls(0),
     free_calls(0),
index d4d217960cc4670d3f4ddaeb2e53e19c22a5c0ca..1087c6cb82bf9e61967f285da2eb0715e0a50e1c 100644 (file)
@@ -28,6 +28,7 @@
  *     might be the way to go.
  */
 
+#include "mem/Allocator.h"
 #include "mem/Meter.h"
 #include "util.h"
 
@@ -139,100 +140,28 @@ private:
     ssize_t idleLimit_ = (2 << 20);
 };
 
-/**
- \ingroup MemPoolsAPI
- * a pool is a [growing] space for objects of the same size
- */
-class MemAllocator
-{
-public:
-    typedef Mem::PoolMeter PoolMeter; // TODO remove
-
-    MemAllocator (char const *aLabel);
-    virtual ~MemAllocator() {}
-
-    /**
-     \param stats   Object to be filled with statistical data about pool.
-     \retval        Number of objects in use, ie. allocated.
-     */
-    virtual int getStats(MemPoolStats * stats, int accumulate = 0) = 0;
-
-    virtual PoolMeter const &getMeter() const = 0;
-
-    /**
-     * Allocate one element from the pool
-     */
-    virtual void *alloc() = 0;
-
-    /**
-     * Free a element allocated by MemAllocator::alloc()
-     */
-    virtual void freeOne(void *) = 0;
-
-    virtual char const *objectType() const;
-    virtual size_t objectSize() const = 0;
-    virtual int getInUseCount() = 0;
-    void zeroBlocks(bool doIt) {doZero = doIt;}
-    int inUseCount();
-
-    /**
-     * Allows you tune chunk size of pooling. Objects are allocated in chunks
-     * instead of individually. This conserves memory, reduces fragmentation.
-     * Because of that memory can be freed also only in chunks. Therefore
-     * there is tradeoff between memory conservation due to chunking and free
-     * memory fragmentation.
-     *
-     \note  As a general guideline, increase chunk size only for pools that keep
-     *      very many items for relatively long time.
-     */
-    virtual void setChunkSize(size_t) {}
-
-    /**
-     \param minSize Minimum size needed to be allocated.
-     \retval n Smallest size divisible by sizeof(void*)
-     */
-    static size_t RoundedSize(size_t minSize);
-
-protected:
-    /** Whether to zero memory on initial allocation and on return to the pool.
-     *
-     * We do this on some pools because many object constructors are/were incomplete
-     * and we are afraid some code may use the object after free.
-     * These probems are becoming less common, so when possible set this to false.
-     */
-    bool doZero;
-
-private:
-    const char *label;
-};
-
 /// \ingroup MemPoolsAPI
-class MemImplementingAllocator : public MemAllocator
+class MemImplementingAllocator : public Mem::Allocator
 {
 public:
     typedef Mem::PoolMeter PoolMeter; // TODO remove
 
     MemImplementingAllocator(char const *aLabel, size_t aSize);
     virtual ~MemImplementingAllocator();
-    virtual PoolMeter const &getMeter() const;
+
     virtual PoolMeter &getMeter();
     virtual void flushMetersFull();
     virtual void flushMeters();
+    virtual bool idleTrigger(int shift) const = 0;
+    virtual void clean(time_t maxage) = 0;
 
-    /**
-     * Allocate one element from the pool
-     */
+    /* Mem::Allocator API */
+    virtual PoolMeter const &getMeter() const;
     virtual void *alloc();
-
-    /**
-     * Free a element allocated by MemImplementingAllocator::alloc()
-     */
     virtual void freeOne(void *);
-
-    virtual bool idleTrigger(int shift) const = 0;
-    virtual void clean(time_t maxage) = 0;
     virtual size_t objectSize() const;
     virtual int getInUseCount() = 0;
+
 protected:
     virtual void *allocate() = 0;
     virtual void deallocate(void *, bool aggressive) = 0;
@@ -252,8 +181,9 @@ class MemPoolStats
 {
 public:
     typedef Mem::PoolMeter PoolMeter; // TODO remove
+    typedef Mem::Allocator Allocator; // TODO remove
 
-    MemAllocator *pool;
+    Allocator *pool;
     const char *label;
     PoolMeter *meter;
     int obj_size;
index e34a324633bd760297c283c7125350ed8b226a6f..30d9a8c1d9bfc2bb3a0cdcf04adebd0c411a44b9 100644 (file)
@@ -248,6 +248,16 @@ MemPoolChunked::createChunk()
     chunk->next = newChunk;
 }
 
+/**
+ * Allows you tune chunk size of pooling. Objects are allocated in chunks
+ * instead of individually. This conserves memory, reduces fragmentation.
+ * Because of that memory can be freed also only in chunks. Therefore
+ * there is tradeoff between memory conservation due to chunking and free
+ * memory fragmentation.
+ *
+ * \note  As a general guideline, increase chunk size only for pools that keep
+ *        very many items for relatively long time.
+ */
 void
 MemPoolChunked::setChunkSize(size_t chunksize)
 {
index 6b245b48be1941b517f47a9a227ce0355a300374..6f38b5d09997b24bd45051eeae36f2a223c1de36 100644 (file)
@@ -27,32 +27,19 @@ public:
     void convertFreeCacheToChunkFreeCache();
     virtual void clean(time_t maxage);
 
-    /**
-     \param stats   Object to be filled with statistical data about pool.
-     \retval        Number of objects in use, ie. allocated.
-     */
-    virtual int getStats(MemPoolStats * stats, int accumulate);
-
     void createChunk();
     void *get();
     void push(void *obj);
+
+    /* Mem::Allocator API */
+    virtual int getStats(MemPoolStats *, int);
     virtual int getInUseCount();
+    virtual void setChunkSize(size_t);
+
 protected:
     virtual void *allocate();
     virtual void deallocate(void *, bool aggressive);
 public:
-    /**
-     * Allows you tune chunk size of pooling. Objects are allocated in chunks
-     * instead of individually. This conserves memory, reduces fragmentation.
-     * Because of that memory can be freed also only in chunks. Therefore
-     * there is tradeoff between memory conservation due to chunking and free
-     * memory fragmentation.
-     *
-     \note  As a general guideline, increase chunk size only for pools that keep
-     *      very many items for relatively long time.
-     */
-    virtual void setChunkSize(size_t chunksize);
-
     virtual bool idleTrigger(int shift) const;
 
     size_t chunk_size;
index 5a08b006b9ecd2f9b825d6573533d8053fa1dfb0..d92e13d9e679bc82e221301642b760c6e20e448a 100644 (file)
@@ -41,13 +41,10 @@ public:
     virtual bool idleTrigger(int shift) const;
     virtual void clean(time_t maxage);
 
-    /**
-     \param stats   Object to be filled with statistical data about pool.
-     \retval        Number of objects in use, ie. allocated.
-     */
-    virtual int getStats(MemPoolStats * stats, int accumulate);
-
+    /* Mem::Allocator API */
+    virtual int getStats(MemPoolStats *, int);
     virtual int getInUseCount();
+
 protected:
     virtual void *allocate();
     virtual void deallocate(void *, bool aggressive);
index b766e2de3d6cd032e61c2fad1fd8a8e49f0fb5a6..6efaac70e44b31b7785df17c4b372ac646433ce1 100644 (file)
@@ -12,7 +12,7 @@
 
 /// The number of currently alive objects (poor man's meter.alloc=meter.inuse).
 /// Technically, this is supposed to be a per-allocator statistics, but
-/// AllocatorProxy is not a MemAllocator so we maintain a global counter
+/// AllocatorProxy is not a Mem::Allocator so we maintain a global counter
 /// instead. We probably do not have to maintain this statistics at all.
 static int Alive = 0;
 
index f003e0750e8d976c449b8ce60c3d884a6fd212db..ce9062e17f2a325d4d98ee8bb5b14668ac045a3f 100644 (file)
@@ -59,10 +59,10 @@ static Mem::Meter HugeBufVolumeMeter;
 
 // XXX: refactor objects using these pools to use MEMPROXY classes instead
 // then remove this function entirely
-static MemAllocator *&
+static Mem::Allocator *&
 GetPool(size_t type)
 {
-    static MemAllocator *pools[MEM_MAX];
+    static Mem::Allocator *pools[MEM_MAX];
     static bool initialized = false;
 
     if (!initialized) {
@@ -76,19 +76,19 @@ GetPool(size_t type)
     return pools[type];
 }
 
-static MemAllocator &
+static Mem::Allocator &
 GetStrPool(size_t type)
 {
-    static MemAllocator *strPools[mem_str_pool_count];
+    static Mem::Allocator *strPools[mem_str_pool_count];
     static bool initialized = false;
 
     static const PoolMeta PoolAttrs[mem_str_pool_count] = {
-        {"Short Strings", MemAllocator::RoundedSize(36)},      /* to fit rfc1123 and similar */
-        {"Medium Strings", MemAllocator::RoundedSize(128)},    /* to fit most urls */
-        {"Long Strings", MemAllocator::RoundedSize(512)},
-        {"1KB Strings", MemAllocator::RoundedSize(1024)},
-        {"4KB Strings", MemAllocator::RoundedSize(4*1024)},
-        {"16KB Strings", MemAllocator::RoundedSize(16*1024)}
+        {"Short Strings", Mem::Allocator::RoundedSize(36)}, /* to fit rfc1123 and similar */
+        {"Medium Strings", Mem::Allocator::RoundedSize(128)}, /* to fit most urls */
+        {"Long Strings", Mem::Allocator::RoundedSize(512)},
+        {"1KB Strings", Mem::Allocator::RoundedSize(1024)},
+        {"4KB Strings", Mem::Allocator::RoundedSize(4*1024)},
+        {"16KB Strings", Mem::Allocator::RoundedSize(16*1024)}
     };
 
     if (!initialized) {
@@ -113,7 +113,7 @@ GetStrPool(size_t type)
 }
 
 /// \returns the best-fit string pool or nil
-static MemAllocator *
+static Mem::Allocator *
 memFindStringPool(size_t net_size, bool fuzzy)
 {
     for (unsigned int i = 0; i < mem_str_pool_count; ++i) {
@@ -674,7 +674,6 @@ Mem::Report(std::ostream &stream)
     static MemPoolGlobalStats mp_total;
     int not_used = 0;
     MemPoolIterator *iter;
-    MemAllocator *pool;
 
     /* caption */
     stream << "Current memory usage:\n";
@@ -708,7 +707,7 @@ Mem::Report(std::ostream &stream)
     /* main table */
     iter = memPoolIterate();
 
-    while ((pool = memPoolIterateNext(iter))) {
+    while (const auto pool = memPoolIterateNext(iter)) {
         pool->getStats(&mp_stats);
 
         if (!mp_stats.pool) /* pool destroyed */
index cc17acd49a2fa0695c4d5657764ac969bdb15b7c..525ae268ecfb49079e033001d1ad55017c20dafa 100644 (file)
@@ -25,7 +25,7 @@
 
 #define PCONN_FDS_SZ    8   /* pconn set size, increase for better memcache hit rate */
 
-//TODO: re-attach to MemPools. WAS: static MemAllocator *pconn_fds_pool = NULL;
+//TODO: re-attach to MemPools. WAS: static Mem::Allocator *pconn_fds_pool = NULL;
 PconnModule * PconnModule::instance = nullptr;
 CBDATA_CLASS_INIT(IdleConnList);
 
index e8cc7726304c7c464be5c2bee616ea0ebbce2652..72892130a2cbec151b4a727c9eeba35fe33888dc 100644 (file)
@@ -74,7 +74,7 @@ struct _LruNode {
     dlink_node node;
 };
 
-static MemAllocator *lru_node_pool = nullptr;
+static Mem::Allocator *lru_node_pool = nullptr;
 static int nr_lru_policies = 0;
 
 static void
index 175774ffe6177a89963400df2572cf99d596e58d..06fc1b0d9320e1451afa96710347a700f3536dbd 100644 (file)
@@ -117,7 +117,7 @@ static EVH storeLateRelease;
  * local variables
  */
 static std::stack<StoreEntry*> LateReleaseStack;
-MemAllocator *StoreEntry::pool = nullptr;
+Mem::Allocator *StoreEntry::pool = nullptr;
 
 void
 Store::Stats(StoreEntry * output)
index 8ea7216d3fe0d70d3610f15d76bc9b56027980e8..93b764abfbff9ac8410acedf7625184caeb67bd5 100644 (file)
@@ -11,6 +11,8 @@
 #define STUB_API "mem/libmem.la"
 #include "tests/STUB.h"
 
+#include "mem/Allocator.h"
+
 #include "mem/AllocatorProxy.h"
 #include "mem/forward.h"
 
@@ -84,11 +86,6 @@ MemImplementingAllocator * MemPools::create(const char *, size_t) STUB_RETVAL(nu
 void MemPools::clean(time_t) STUB
 void MemPools::setDefaultPoolChunking(bool const &) STUB
 
-//MemAllocator::MemAllocator(char const *aLabel);
-char const *MemAllocator::objectType() const STUB_RETVAL(nullptr)
-int MemAllocator::inUseCount() STUB_RETVAL(0)
-size_t MemAllocator::RoundedSize(size_t minSize) STUB_RETVAL(minSize)
-
 //MemImplementingAllocator::MemImplementingAllocator(char const *, size_t) STUB_NOP
 //MemImplementingAllocator::~MemImplementingAllocator();
 Mem::PoolMeter const &MemImplementingAllocator::getMeter() const STUB_RETSTATREF(PoolMeter)
index db74a2c989f0fae3b1657257fc00da653686ed4f..8dd435cc4ecb145580f5fa35e29eca175d69720a 100644 (file)
@@ -34,7 +34,7 @@ public:
 void
 testMem::testMemPool()
 {
-    MemAllocator *Pool = memPoolCreate("Test Pool", sizeof(SomethingToAlloc));
+    const auto Pool = memPoolCreate("Test Pool", sizeof(SomethingToAlloc));
     CPPUNIT_ASSERT(Pool);
 
     auto *something = static_cast<SomethingToAlloc *>(Pool->alloc());