From b45683c7a383f39846e499b115c26299005dcfc2 Mon Sep 17 00:00:00 2001 From: Darek Stojaczyk Date: Fri, 28 Dec 2018 10:29:42 +0100 Subject: [PATCH] memory: don't zero the translation length for invalid translations In spdk_mem_map_translate() we used to set the translation length to 0 if the provided memory region wasn't registered. This doesn't really have any use case and is now removed, which means that the translation length parameter will only be updated for those memory regions that were successfully translated. This serves as a minor optimization and code cleanup. Change-Id: I4c953f17e3f2181266bdcc71cf7e30c7244541f2 Signed-off-by: Darek Stojaczyk Reviewed-on: https://review.gerrithub.io/c/438446 Tested-by: SPDK CI Jenkins Reviewed-by: Paul Luse Reviewed-by: Ben Walker Reviewed-by: wuzhouhui Reviewed-by: Shuhei Matsumoto Chandler-Test-Pool: SPDK Automated Test System --- include/spdk/env.h | 3 ++- lib/env_dpdk/memory.c | 15 ++++----------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/include/spdk/env.h b/include/spdk/env.h index a3ab17232..fceb814bf 100644 --- a/include/spdk/env.h +++ b/include/spdk/env.h @@ -1084,7 +1084,8 @@ int spdk_mem_map_clear_translation(struct spdk_mem_map *map, uint64_t vaddr, uin * \param map Memory map. * \param vaddr Virtual address. * \param size Contains the size of the memory region pointed to by vaddr. - * Updated with the size of the memory region for which the translation is valid. + * If vaddr is successfully translated, then this is updated with the size of + * the memory region for which the translation is valid. * * \return the translation of vaddr stored in the map, or default_translation * as specified in spdk_mem_map_alloc() if vaddr is not present in the map. diff --git a/lib/env_dpdk/memory.c b/lib/env_dpdk/memory.c index 7cfa5e4aa..02b1286a2 100644 --- a/lib/env_dpdk/memory.c +++ b/lib/env_dpdk/memory.c @@ -591,16 +591,10 @@ spdk_mem_map_translate(const struct spdk_mem_map *map, uint64_t vaddr, uint64_t uint64_t idx_256tb; uint64_t idx_1gb; uint64_t vfn_2mb; - uint64_t total_size = 0; uint64_t cur_size; uint64_t prev_translation; uint64_t orig_translation; - if (size != NULL) { - total_size = *size; - *size = 0; - } - if (spdk_unlikely(vaddr & ~MASK_256TB)) { DEBUG_PRINT("invalid usermode virtual address %p\n", (void *)vaddr); return map->default_translation; @@ -616,19 +610,18 @@ spdk_mem_map_translate(const struct spdk_mem_map *map, uint64_t vaddr, uint64_t } cur_size = VALUE_2MB - _2MB_OFFSET(vaddr); - if (size != NULL) { - *size = cur_size; - } - map_2mb = &map_1gb->map[idx_1gb]; if (size == NULL || map->ops.are_contiguous == NULL || map_2mb->translation_2mb == map->default_translation) { + if (size != NULL) { + *size = cur_size; + } return map_2mb->translation_2mb; } orig_translation = map_2mb->translation_2mb; prev_translation = orig_translation; - while (cur_size < total_size) { + while (cur_size < *size) { vfn_2mb++; idx_256tb = MAP_256TB_IDX(vfn_2mb); idx_1gb = MAP_1GB_IDX(vfn_2mb);