From b127640eeda3578be73dbe76484cfcb8f5bdd45f Mon Sep 17 00:00:00 2001 From: Keith Busch Date: Thu, 16 Jul 2020 06:33:28 -0700 Subject: [PATCH] use normal alloc for fw download Huge pages are only helpful for large transfers that may exceed the driver's max segment limit. Unless a fw download wants to exceed that transfer length, use normal allocation. Link: https://github.com/linux-nvme/nvme-cli/issues/775 Signed-off-by: Keith Busch --- nvme.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/nvme.c b/nvme.c index 6d160ed1..e08351c0 100644 --- a/nvme.c +++ b/nvme.c @@ -99,9 +99,9 @@ static void *__nvme_alloc(size_t len, bool *huge) return NULL; } -#ifdef LIBHUGETLBFS #define HUGE_MIN 0x80000 +#ifdef LIBHUGETLBFS void nvme_free(void *p, bool huge) { if (huge) @@ -2262,7 +2262,14 @@ static int fw_download(int argc, char **argv, struct command *cmd, struct plugin goto close_fw_fd; } - fw_buf = nvme_alloc(fw_size, &huge); + if (cfg.xfer == 0 || cfg.xfer % 4096) + cfg.xfer = 4096; + + if (cfg.xfer < HUGE_MIN) + fw_buf = __nvme_alloc(fw_size, &huge); + else + fw_buf = nvme_alloc(fw_size, &huge); + if (!fw_buf) { fprintf(stderr, "No memory for f/w size:%d\n", fw_size); err = -ENOMEM; @@ -2270,8 +2277,6 @@ static int fw_download(int argc, char **argv, struct command *cmd, struct plugin } buf = fw_buf; - if (cfg.xfer == 0 || cfg.xfer % 4096) - cfg.xfer = 4096; if (read(fw_fd, fw_buf, fw_size) != ((ssize_t)(fw_size))) { err = -errno; fprintf(stderr, "read :%s :%s\n", cfg.fw, strerror(errno)); -- 2.50.1