Skip to content

Commit

Permalink
Maintenance: Upgrade MEM_DREAD_CTRL memory pool
Browse files Browse the repository at this point in the history
 ... to a MEMPROXY class pool.

Replacing memory allocate and destruct with C++ new/delete
and in-class initialization.
  • Loading branch information
yadij committed Oct 28, 2024
1 parent 240efcb commit 2bf5061
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
8 changes: 3 additions & 5 deletions src/fs_io.cc
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ diskHandleRead(int fd, void *data)
*/

if (fd < 0) {
memFree(ctrl_dat, MEM_DREAD_CTRL);
delete ctrl_dat;
return;
}

Expand Down Expand Up @@ -414,7 +414,7 @@ diskHandleRead(int fd, void *data)

cbdataReferenceDone(ctrl_dat->client_data);

memFree(ctrl_dat, MEM_DREAD_CTRL);
delete ctrl_dat;
}

/* start read operation */
Expand All @@ -424,14 +424,12 @@ diskHandleRead(int fd, void *data)
void
file_read(int fd, char *buf, int req_len, off_t offset, DRCB * handler, void *client_data)
{
dread_ctrl *ctrl_dat;
assert(fd >= 0);
ctrl_dat = (dread_ctrl *)memAllocate(MEM_DREAD_CTRL);
auto *ctrl_dat = new dread_ctrl;
ctrl_dat->fd = fd;
ctrl_dat->offset = offset;
ctrl_dat->req_len = req_len;
ctrl_dat->buf = buf;
ctrl_dat->end_of_file = 0;
ctrl_dat->handler = handler;
ctrl_dat->client_data = cbdataReference(client_data);
diskHandleRead(fd, ctrl_dat);
Expand Down
17 changes: 9 additions & 8 deletions src/fs_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@

class MemBuf;

// POD
class dread_ctrl
{
MEMPROXY_CLASS(dread_ctrl);

public:
int fd;
off_t offset;
int req_len;
char *buf;
int end_of_file;
DRCB *handler;
void *client_data;
int fd = -1;
off_t offset = 0;
int req_len = 0;
char *buf = nullptr;
int end_of_file = 0;
DRCB *handler = {};
void *client_data = {};
};

class dwrite_q
Expand Down
1 change: 0 additions & 1 deletion src/mem/forward.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ typedef enum {
MEM_16K_BUF,
MEM_32K_BUF,
MEM_64K_BUF,
MEM_DREAD_CTRL,
MEM_MD5_DIGEST,
MEM_MAX
} mem_type;
Expand Down
1 change: 0 additions & 1 deletion src/mem/old_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,6 @@ Mem::Init(void)
memDataInit(MEM_32K_BUF, "32K Buffer", 32768, 10, false);
memDataInit(MEM_64K_BUF, "64K Buffer", 65536, 10, false);
// 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_MD5_DIGEST, "MD5 digest", SQUID_MD5_DIGEST_LENGTH, 0, true);
GetPool(MEM_MD5_DIGEST)->setChunkSize(512 * 1024);

Expand Down

0 comments on commit 2bf5061

Please sign in to comment.