Skip to content

Commit

Permalink
Maintenance: Replace MEM_MD5_DIGEST memory pool
Browse files Browse the repository at this point in the history
... with generic 16 byte buffer.
  • Loading branch information
yadij committed Jul 30, 2024
1 parent 61ddaf9 commit 832f1e5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/mem/forward.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ typedef void FREE(void *);
/// Types of memory pool which do not yet use MEMPROXY_CLASS() API
typedef enum {
MEM_NONE,
MEM_16B_BUF,
MEM_32B_BUF,
MEM_64B_BUF,
MEM_128B_BUF,
Expand All @@ -53,7 +54,6 @@ typedef enum {
MEM_64K_BUF,
MEM_DREAD_CTRL,
MEM_DWRITE_Q,
MEM_MD5_DIGEST,
MEM_MAX
} mem_type;

Expand Down
18 changes: 15 additions & 3 deletions src/mem/old_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <iomanip>

/* forward declarations */
static void memFree16B(void *);
static void memFree32B(void *);
static void memFree64B(void *);
static void memFree128B(void *);
Expand Down Expand Up @@ -140,7 +141,10 @@ memFindBufSizeType(size_t net_size, size_t * gross_size)
mem_type type;
size_t size;

if (net_size <= 32) {
if (net_size <= 16) {
type = MEM_16B_BUF;
size = 16;
} else if (net_size <= 32) {
type = MEM_32B_BUF;
size = 32;
} else if (net_size <= 64) {
Expand Down Expand Up @@ -295,6 +299,7 @@ Mem::Init(void)
* that are never used or used only once; perhaps we should simply use
* malloc() for those? @?@
*/
memDataInit(MEM_16B_BUF, "16B Buffer", 16, 10, false);
memDataInit(MEM_32B_BUF, "32B Buffer", 32, 10, false);
memDataInit(MEM_64B_BUF, "64B Buffer", 64, 10, false);
memDataInit(MEM_128B_BUF, "128B Buffer", 128, 10, false);
Expand All @@ -310,8 +315,6 @@ Mem::Init(void)
// TODO: Carefully stop zeroing these objects memory and drop the doZero parameter
memDataInit(MEM_DREAD_CTRL, "dread_ctrl", sizeof(dread_ctrl), 0, true);
memDataInit(MEM_DWRITE_Q, "dwrite_q", sizeof(dwrite_q), 0, true);
memDataInit(MEM_MD5_DIGEST, "MD5 digest", SQUID_MD5_DIGEST_LENGTH, 0, true);
GetPool(MEM_MD5_DIGEST)->setChunkSize(512 * 1024);

// Test that all entries are initialized
for (auto t = MEM_NONE; ++t < MEM_MAX;) {
Expand Down Expand Up @@ -350,6 +353,12 @@ memInUse(mem_type type)

/* ick */

void
memFree16B(void *p)
{
memFree(p, MEM_16B_BUF);
}

void
memFree32B(void *p)
{
Expand Down Expand Up @@ -433,6 +442,9 @@ memFreeBufFunc(size_t size)
{
switch (size) {

case 16:
return memFree16B;

case 32:
return memFree32B;

Expand Down
4 changes: 2 additions & 2 deletions src/store_key_md5.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ storeKeyPublicByRequestMethod(HttpRequest * request, const HttpRequestMethod& me
cache_key *
storeKeyDup(const cache_key * key)
{
cache_key *dup = (cache_key *)memAllocate(MEM_MD5_DIGEST);
cache_key *dup = (cache_key *)memAllocBuf(SQUID_MD5_DIGEST_LENGTH, nullptr);
memcpy(dup, key, SQUID_MD5_DIGEST_LENGTH);
return dup;
}
Expand All @@ -153,7 +153,7 @@ storeKeyCopy(cache_key * dst, const cache_key * src)
void
storeKeyFree(const cache_key * key)
{
memFree((void *) key, MEM_MD5_DIGEST);
memFreeBuf(SQUID_MD5_DIGEST_LENGTH, const_cast<cache_key *>(key));
}

int
Expand Down

0 comments on commit 832f1e5

Please sign in to comment.