From: Daniel Wagner Date: Thu, 14 Sep 2023 08:12:56 +0000 (+0200) Subject: nvme: append huge to nvme_{alloc|free} function X-Git-Tag: v2.6~29 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=d126dee19dd60c0b69f22c8274db2c01a59ee33e;p=users%2Fsagi%2Fnvme-cli.git nvme: append huge to nvme_{alloc|free} function These two function are abstracting the libhugebtl API. Let's rename Rename these functions because we want to introduce a generic alloc function with alignment support. Signed-off-by: Daniel Wagner --- diff --git a/nvme.c b/nvme.c index d13eee73..354c6dad 100644 --- a/nvme.c +++ b/nvme.c @@ -184,6 +184,7 @@ static const char space[51] = {[0 ... 49] = ' ', '\0'}; static void *mmap_registers(nvme_root_t r, struct nvme_dev *dev); static void *__nvme_alloc(size_t len, bool *huge) +static void *__nvme_alloc_huge(size_t len, bool *huge) { void *p; @@ -198,7 +199,7 @@ static void *__nvme_alloc(size_t len, bool *huge) #define HUGE_MIN 0x80000 #ifdef CONFIG_LIBHUGETLBFS -void nvme_free(void *p, bool huge) +void nvme_free_huge(void *p, bool huge) { if (huge) { if (p) @@ -208,29 +209,29 @@ void nvme_free(void *p, bool huge) } } -void *nvme_alloc(size_t len, bool *huge) +void *nvme_alloc_huge(size_t len, bool *huge) { void *p; if (len < HUGE_MIN) - return __nvme_alloc(len, huge); + return __nvme_alloc_huge(len, huge); p = get_hugepage_region(len, GHR_DEFAULT); if (!p) - return __nvme_alloc(len, huge); + return __nvme_alloc_huge(len, huge); *huge = true; return p; } #else -void nvme_free(void *p, bool huge) +void nvme_free_huge(void *p, bool huge) { free(p); } -void *nvme_alloc(size_t len, bool *huge) +void *nvme_alloc_huge(size_t len, bool *huge) { - return __nvme_alloc(len, huge); + return __nvme_alloc_huge(len, huge); } #endif @@ -1569,7 +1570,7 @@ static int get_persistent_event_log(int argc, char **argv, if (cfg.action == NVME_PEVENT_LOG_EST_CTX_AND_READ) cfg.action = NVME_PEVENT_LOG_READ; - pevent_log_info = nvme_alloc(cfg.log_len, &huge); + pevent_log_info = nvme_alloc_huge(cfg.log_len, &huge); if (!pevent_log_info) { err = -ENOMEM; goto free_pevent; @@ -1603,7 +1604,7 @@ static int get_persistent_event_log(int argc, char **argv, } free: - nvme_free(pevent_log_info, huge); + nvme_free_huge(pevent_log_info, huge); free_pevent: free(pevent); close_dev: @@ -5037,7 +5038,7 @@ static int fw_download(int argc, char **argv, struct command *cmd, struct plugin } else if (cfg.xfer % 4096) cfg.xfer = 4096; - fw_buf = nvme_alloc(fw_size, &huge); + fw_buf = nvme_alloc_huge(fw_size, &huge); if (!fw_buf) { err = -ENOMEM; @@ -5070,7 +5071,7 @@ static int fw_download(int argc, char **argv, struct command *cmd, struct plugin } free: - nvme_free(fw_buf, huge); + nvme_free_huge(fw_buf, huge); close_fw_fd: close(fw_fd); close_dev: @@ -7570,7 +7571,7 @@ static int submit_io(int opcode, char *command, const char *desc, int argc, char /* Update the data size based on the required block count */ buffer_size = (nblocks + 1) * logical_block_size; - buffer = nvme_alloc(buffer_size, &huge); + buffer = nvme_alloc_huge(buffer_size, &huge); if (!buffer) { err = -ENOMEM; goto close_mfd; @@ -7692,7 +7693,7 @@ static int submit_io(int opcode, char *command, const char *desc, int argc, char free_mbuffer: free(mbuffer); free_buffer: - nvme_free(buffer, huge); + nvme_free_huge(buffer, huge); close_mfd: if (strlen(cfg.metadata)) close(mfd); @@ -8540,7 +8541,7 @@ static int passthru(int argc, char **argv, bool admin, } if (cfg.data_len) { - data = nvme_alloc(cfg.data_len, &huge); + data = nvme_alloc_huge(cfg.data_len, &huge); if (!data) { err = -ENOMEM; goto free_metadata; @@ -8625,7 +8626,7 @@ static int passthru(int argc, char **argv, bool admin, free_metadata: free(mdata); free_data: - nvme_free(data, huge); + nvme_free_huge(data, huge); close_dfd: if (strlen(cfg.input_file)) close(dfd); @@ -9336,7 +9337,7 @@ static int nvme_mi(int argc, char **argv, __u8 admin_opcode, const char *desc) } if (cfg.data_len) { - data = nvme_alloc(cfg.data_len, &huge); + data = nvme_alloc_huge(cfg.data_len, &huge); if (!data) { err = -ENOMEM; goto close_fd; @@ -9372,7 +9373,7 @@ static int nvme_mi(int argc, char **argv, __u8 admin_opcode, const char *desc) } free_data: - nvme_free(data, huge); + nvme_free_huge(data, huge); close_fd: if (strlen(cfg.input_file)) close(fd); diff --git a/nvme.h b/nvme.h index d859983e..e5f0b186 100644 --- a/nvme.h +++ b/nvme.h @@ -107,8 +107,8 @@ int __id_ctrl(int argc, char **argv, struct command *cmd, struct plugin *plugin, void (*vs)(uint8_t *vs, struct json_object *root)); extern int current_index; -void *nvme_alloc(size_t len, bool *huge); -void nvme_free(void *p, bool huge); +void *nvme_alloc_huge(size_t len, bool *huge); +void nvme_free_huge(void *p, bool huge); const char *nvme_strerror(int errnum); unsigned long long elapsed_utime(struct timeval start_time, diff --git a/plugins/micron/micron-nvme.c b/plugins/micron/micron-nvme.c index d6fb6017..195c971e 100644 --- a/plugins/micron/micron-nvme.c +++ b/plugins/micron/micron-nvme.c @@ -1799,7 +1799,7 @@ static void GetGenericLogs(int fd, const char *dir) } log_len = le64_to_cpu(pevent_log.tll); - pevent_log_info = nvme_alloc(log_len, &huge); + pevent_log_info = nvme_alloc_huge(log_len, &huge); if (!pevent_log_info) { perror("could not alloc buffer for persistent event log page (ignored)!\n"); return; @@ -1809,7 +1809,7 @@ static void GetGenericLogs(int fd, const char *dir) if (!err) WriteData((__u8 *)pevent_log_info, log_len, dir, "persistent_event_log.bin", "persistent event log"); - nvme_free(pevent_log_info, huge); + nvme_free_huge(pevent_log_info, huge); } static void GetNSIDDInfo(int fd, const char *dir, int nsid) diff --git a/plugins/scaleflux/sfx-nvme.c b/plugins/scaleflux/sfx-nvme.c index 01867c71..e7f3b990 100644 --- a/plugins/scaleflux/sfx-nvme.c +++ b/plugins/scaleflux/sfx-nvme.c @@ -1410,7 +1410,7 @@ static int nvme_dump_evtlog(struct nvme_dev *dev, __u32 namespace_id, __u32 stor if (log_len % 4) log_len = (log_len / 4 + 1) * 4; - pevent_log_info = nvme_alloc(single_len, &huge); + pevent_log_info = nvme_alloc_huge(single_len, &huge); if (!pevent_log_info) { err = -ENOMEM; goto free_pevent; @@ -1453,8 +1453,8 @@ static int nvme_dump_evtlog(struct nvme_dev *dev, __u32 namespace_id, __u32 stor printf("\nDump-evtlog: Success\n"); if (parse) { - nvme_free(pevent_log_info, huge); - pevent_log_info = nvme_alloc(log_len, &huge); + nvme_free_huge(pevent_log_info, huge); + pevent_log_info = nvme_alloc_huge(log_len, &huge); if (!pevent_log_info) { fprintf(stderr, "Failed to alloc enough memory 0x%x to parse evtlog\n", log_len); err = -ENOMEM; @@ -1479,7 +1479,7 @@ static int nvme_dump_evtlog(struct nvme_dev *dev, __u32 namespace_id, __u32 stor close_fd: fclose(fd); free: - nvme_free(pevent_log_info, huge); + nvme_free_huge(pevent_log_info, huge); free_pevent: free(pevent); ret: diff --git a/plugins/wdc/wdc-nvme.c b/plugins/wdc/wdc-nvme.c index 49ede5c3..ae57e85f 100644 --- a/plugins/wdc/wdc-nvme.c +++ b/plugins/wdc/wdc-nvme.c @@ -10386,7 +10386,7 @@ static int wdc_vs_pcie_stats(int argc, char **argv, struct command *command, goto out; } - pcieStatsPtr = nvme_alloc(pcie_stats_size, &huge); + pcieStatsPtr = nvme_alloc_huge(pcie_stats_size, &huge); if (!pcieStatsPtr) { fprintf(stderr, "ERROR: WDC: PCIE Stats alloc: %s\n", strerror(errno)); ret = -1; @@ -10417,7 +10417,7 @@ static int wdc_vs_pcie_stats(int argc, char **argv, struct command *command, } } - nvme_free(pcieStatsPtr, huge); + nvme_free_huge(pcieStatsPtr, huge); out: nvme_free_tree(r); diff --git a/plugins/zns/zns.c b/plugins/zns/zns.c index f88ad8bd..7b1b191b 100644 --- a/plugins/zns/zns.c +++ b/plugins/zns/zns.c @@ -949,7 +949,7 @@ static int report_zones(int argc, char **argv, struct command *cmd, struct plugi log_len = sizeof(struct nvme_zone_report) + ((sizeof(struct nvme_zns_desc) * nr_zones_chunks) + (nr_zones_chunks * zdes)); report_size = log_len; - report = nvme_alloc(report_size, &huge); + report = nvme_alloc_huge(report_size, &huge); if (!report) { perror("alloc"); err = -ENOMEM; @@ -997,7 +997,7 @@ static int report_zones(int argc, char **argv, struct command *cmd, struct plugi ops->zns_finish_zone_list(total_nr_zones, zone_list); } - nvme_free(report, huge); + nvme_free_huge(report, huge); free_buff: free(buff);