env: Remove old translation reference counting

Memory is now reference counted at a higher level.

Change-Id: I61b24db7b92a129686775eddbff3a48814c842fe
Signed-off-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-on: https://review.gerrithub.io/375644
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
This commit is contained in:
Ben Walker 2017-08-24 14:43:34 -07:00 committed by Jim Harris
parent 3f09f0f98a
commit 01bed940fe
2 changed files with 2 additions and 34 deletions

View File

@ -57,9 +57,6 @@
#define MAP_128TB_IDX(vfn_2mb) ((vfn_2mb) >> (SHIFT_1GB - SHIFT_2MB)) #define MAP_128TB_IDX(vfn_2mb) ((vfn_2mb) >> (SHIFT_1GB - SHIFT_2MB))
#define MAP_1GB_IDX(vfn_2mb) ((vfn_2mb) & ((1ULL << (SHIFT_1GB - SHIFT_2MB + 1)) - 1)) #define MAP_1GB_IDX(vfn_2mb) ((vfn_2mb) & ((1ULL << (SHIFT_1GB - SHIFT_2MB + 1)) - 1))
/* Max value for a 16-bit ref count. */
#define VTOPHYS_MAX_REF_COUNT (0xFFFF)
/* Translation of a single 2MB page. */ /* Translation of a single 2MB page. */
struct map_2mb { struct map_2mb {
uint64_t translation_2mb; uint64_t translation_2mb;
@ -71,7 +68,6 @@ struct map_2mb {
*/ */
struct map_1gb { struct map_1gb {
struct map_2mb map[1ULL << (SHIFT_1GB - SHIFT_2MB + 1)]; struct map_2mb map[1ULL << (SHIFT_1GB - SHIFT_2MB + 1)];
uint16_t ref_count[1ULL << (SHIFT_1GB - SHIFT_2MB + 1)];
}; };
/* Top-level map table indexed by bits [30..46] of the virtual address. /* Top-level map table indexed by bits [30..46] of the virtual address.
@ -378,7 +374,6 @@ spdk_mem_map_get_map_1gb(struct spdk_mem_map *map, uint64_t vfn_2mb)
for (i = 0; i < SPDK_COUNTOF(map_1gb->map); i++) { for (i = 0; i < SPDK_COUNTOF(map_1gb->map); i++) {
map_1gb->map[i].translation_2mb = map->default_translation; map_1gb->map[i].translation_2mb = map->default_translation;
} }
memset(map_1gb->ref_count, 0, sizeof(map_1gb->ref_count));
map->map_128tb.map[idx_128tb] = map_1gb; map->map_128tb.map[idx_128tb] = map_1gb;
} }
} }
@ -402,7 +397,6 @@ spdk_mem_map_set_translation(struct spdk_mem_map *map, uint64_t vaddr, uint64_t
struct map_1gb *map_1gb; struct map_1gb *map_1gb;
uint64_t idx_1gb; uint64_t idx_1gb;
struct map_2mb *map_2mb; struct map_2mb *map_2mb;
uint16_t *ref_count;
/* For now, only 2 MB-aligned registrations are supported */ /* For now, only 2 MB-aligned registrations are supported */
if ((uintptr_t)vaddr & ~MASK_128TB) { if ((uintptr_t)vaddr & ~MASK_128TB) {
@ -427,18 +421,8 @@ spdk_mem_map_set_translation(struct spdk_mem_map *map, uint64_t vaddr, uint64_t
idx_1gb = MAP_1GB_IDX(vfn_2mb); idx_1gb = MAP_1GB_IDX(vfn_2mb);
map_2mb = &map_1gb->map[idx_1gb]; map_2mb = &map_1gb->map[idx_1gb];
ref_count = &map_1gb->ref_count[idx_1gb];
if (*ref_count == VTOPHYS_MAX_REF_COUNT) {
DEBUG_PRINT("ref count for %p already at %d\n",
(void *)vaddr, VTOPHYS_MAX_REF_COUNT);
return -EBUSY;
}
map_2mb->translation_2mb = translation; map_2mb->translation_2mb = translation;
(*ref_count)++;
size -= VALUE_2MB; size -= VALUE_2MB;
vfn_2mb++; vfn_2mb++;
} }
@ -453,7 +437,6 @@ spdk_mem_map_clear_translation(struct spdk_mem_map *map, uint64_t vaddr, uint64_
struct map_1gb *map_1gb; struct map_1gb *map_1gb;
uint64_t idx_1gb; uint64_t idx_1gb;
struct map_2mb *map_2mb; struct map_2mb *map_2mb;
uint16_t *ref_count;
/* For now, only 2 MB-aligned registrations are supported */ /* For now, only 2 MB-aligned registrations are supported */
if ((uintptr_t)vaddr & ~MASK_128TB) { if ((uintptr_t)vaddr & ~MASK_128TB) {
@ -478,17 +461,7 @@ spdk_mem_map_clear_translation(struct spdk_mem_map *map, uint64_t vaddr, uint64_
idx_1gb = MAP_1GB_IDX(vfn_2mb); idx_1gb = MAP_1GB_IDX(vfn_2mb);
map_2mb = &map_1gb->map[idx_1gb]; map_2mb = &map_1gb->map[idx_1gb];
ref_count = &map_1gb->ref_count[idx_1gb]; map_2mb->translation_2mb = map->default_translation;
if (*ref_count == 0) {
DEBUG_PRINT("vaddr %p not registered\n", (void *)vaddr);
return -EINVAL;
}
(*ref_count)--;
if (*ref_count == 0) {
map_2mb->translation_2mb = map->default_translation;
}
size -= VALUE_2MB; size -= VALUE_2MB;
vfn_2mb++; vfn_2mb++;

View File

@ -134,12 +134,7 @@ test_mem_map_translation(void)
rc = spdk_mem_map_set_translation(map, 0, 3 * VALUE_2MB, 0); rc = spdk_mem_map_set_translation(map, 0, 3 * VALUE_2MB, 0);
CU_ASSERT(rc == 0); CU_ASSERT(rc == 0);
/* /* Clear translation for the middle page of the larger region. */
* Clear translation for the middle page of the larger region.
* It was set twice, so clear it twice.
*/
rc = spdk_mem_map_clear_translation(map, VALUE_2MB, VALUE_2MB);
CU_ASSERT(rc == 0);
rc = spdk_mem_map_clear_translation(map, VALUE_2MB, VALUE_2MB); rc = spdk_mem_map_clear_translation(map, VALUE_2MB, VALUE_2MB);
CU_ASSERT(rc == 0); CU_ASSERT(rc == 0);