Commit 01bed940 authored by Ben Walker's avatar Ben Walker Committed by Jim Harris
Browse files

env: Remove old translation reference counting



Memory is now reference counted at a higher level.

Change-Id: I61b24db7b92a129686775eddbff3a48814c842fe
Signed-off-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-on: https://review.gerrithub.io/375644


Reviewed-by: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
parent 3f09f0f9
Loading
Loading
Loading
Loading
+1 −28
Original line number Diff line number Diff line
@@ -57,9 +57,6 @@
#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))

/* Max value for a 16-bit ref count. */
#define VTOPHYS_MAX_REF_COUNT (0xFFFF)

/* Translation of a single 2MB page. */
struct map_2mb {
	uint64_t translation_2mb;
@@ -71,7 +68,6 @@ struct map_2mb {
 */
struct map_1gb {
	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.
@@ -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++) {
					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;
			}
		}
@@ -402,7 +397,6 @@ spdk_mem_map_set_translation(struct spdk_mem_map *map, uint64_t vaddr, uint64_t
	struct map_1gb *map_1gb;
	uint64_t idx_1gb;
	struct map_2mb *map_2mb;
	uint16_t *ref_count;

	/* For now, only 2 MB-aligned registrations are supported */
	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);
		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;

		(*ref_count)++;

		size -= VALUE_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;
	uint64_t idx_1gb;
	struct map_2mb *map_2mb;
	uint16_t *ref_count;

	/* For now, only 2 MB-aligned registrations are supported */
	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);
		map_2mb = &map_1gb->map[idx_1gb];
		ref_count = &map_1gb->ref_count[idx_1gb];

		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;
		vfn_2mb++;
+1 −6
Original line number Diff line number Diff line
@@ -134,12 +134,7 @@ test_mem_map_translation(void)
	rc = spdk_mem_map_set_translation(map, 0, 3 * VALUE_2MB, 0);
	CU_ASSERT(rc == 0);

	/*
	 * 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);
	/* Clear translation for the middle page of the larger region. */
	rc = spdk_mem_map_clear_translation(map, VALUE_2MB, VALUE_2MB);
	CU_ASSERT(rc == 0);