From 50de561ac4837edfa81abd36df0bae2ecb62bc20 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Mon, 23 Feb 2026 11:13:09 +0000 Subject: nvmutil: explain a few parts in nvmalloc the current code is optimised for speed, but it's a bit esoteric, so make it easier to understand. Signed-off-by: Leah Rowe --- util/nvmutil/nvmutil.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'util/nvmutil/nvmutil.c') diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index 99900878..360febca 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -197,19 +197,24 @@ openFiles(const char *path) void nvmalloc(void) { + /* same operations need the full block, others only 128 bytes */ if ((cmd == cmd_swap) || (cmd == cmd_copy)) nf = SIZE_4KB; else nf = NVM_SIZE; + /* only read the part specified, for copy/setchecksum/brick */ if ((cmd == cmd_copy) || (cmd == cmd_setchecksum) || (cmd == cmd_brick)) do_read[part ^ 1] = 0; + /* only allocate one block if only one part being read */ char *buf = malloc(nf << (do_read[0] & do_read[1])); if (buf == NULL) err(errno, NULL); gbe[0] = (size_t) buf; + + /* speedhack: for cmd copy, both pointers are set the same */ gbe[1] = gbe[0] + (nf * (do_read[0] & do_read[1])); } -- cgit v1.2.1