Loading...
src/magazine_tiny.c libmalloc-116 libmalloc-140.50.6
--- libmalloc/libmalloc-116/src/magazine_tiny.c
+++ libmalloc/libmalloc-140.50.6/src/magazine_tiny.c
@@ -256,7 +256,7 @@
  * Assumes szone has been locked
  */
 static void
-tiny_free_list_add_ptr(szone_t *szone, magazine_t *tiny_mag_ptr, void *ptr, msize_t msize)
+tiny_free_list_add_ptr(rack_t *rack, magazine_t *tiny_mag_ptr, void *ptr, msize_t msize)
 {
 	grain_t slot = (!msize || (msize >= NUM_TINY_SLOTS)) ? NUM_TINY_SLOTS - 1 : msize - 1;
 	tiny_free_list_t *free_ptr = ptr;
@@ -267,27 +267,29 @@
 		malloc_printf("in %s, ptr=%p, msize=%d\n", __FUNCTION__, ptr, msize);
 	}
 	if (((uintptr_t)ptr) & (TINY_QUANTUM - 1)) {
-		szone_error(szone, 1, "tiny_free_list_add_ptr: Unaligned ptr", ptr, NULL);
+		szone_error(rack->debug_flags, 1, "tiny_free_list_add_ptr: Unaligned ptr", ptr, NULL);
 	}
 #endif
 	set_tiny_meta_header_free(ptr, msize);
 	if (free_head) {
 #if DEBUG_MALLOC
 		if (free_list_unchecksum_ptr(szone, &free_head->previous)) {
-			szone_error(szone, 1, "tiny_free_list_add_ptr: Internal invariant broken (free_head->previous)", ptr,
+			szone_error(rack->debug_flags, 1,
+						"tiny_free_list_add_ptr: Internal invariant broken (free_head->previous)", ptr,
 						"ptr=%p slot=%d free_head=%p previous=%p\n", ptr, slot, (void *)free_head, free_head->previous.p);
 		}
 		if (!tiny_meta_header_is_free(free_head)) {
-			szone_error(szone, 1, "tiny_free_list_add_ptr: Internal invariant broken (free_head is not a free pointer)", ptr,
+			szone_error(rack->debug_flags, 1,
+						"tiny_free_list_add_ptr: Internal invariant broken (free_head is not a free pointer)", ptr,
 						"ptr=%p slot=%d free_head=%p\n", ptr, slot, (void *)free_head);
 		}
 #endif
-		free_head->previous.u = free_list_checksum_ptr(szone, free_ptr);
+		free_head->previous.u = free_list_checksum_ptr(rack, free_ptr);
 	} else {
 		BITMAPV_SET(tiny_mag_ptr->mag_bitmap, slot);
 	}
-	free_ptr->previous.u = free_list_checksum_ptr(szone, NULL);
-	free_ptr->next.u = free_list_checksum_ptr(szone, free_head);
+	free_ptr->previous.u = free_list_checksum_ptr(rack, NULL);
+	free_ptr->next.u = free_list_checksum_ptr(rack, free_head);
 
 	tiny_mag_ptr->mag_free_list[slot].p = free_ptr;
 }
@@ -297,13 +299,13 @@
  * Assumes szone has been locked
  */
 static void
-tiny_free_list_remove_ptr(szone_t *szone, magazine_t *tiny_mag_ptr, void *ptr, msize_t msize)
+tiny_free_list_remove_ptr(rack_t *rack, magazine_t *tiny_mag_ptr, void *ptr, msize_t msize)
 {
 	grain_t slot = (!msize || (msize >= NUM_TINY_SLOTS)) ? NUM_TINY_SLOTS - 1 : msize - 1;
 	tiny_free_list_t *free_ptr = ptr, *next, *previous;
 
-	next = free_list_unchecksum_ptr(szone, &free_ptr->next);
-	previous = free_list_unchecksum_ptr(szone, &free_ptr->previous);
+	next = free_list_unchecksum_ptr(rack, &free_ptr->next);
+	previous = free_list_unchecksum_ptr(rack, &free_ptr->previous);
 
 #if DEBUG_MALLOC
 	if (LOG(szone, ptr)) {
@@ -314,7 +316,8 @@
 		// The block to remove is the head of the free list
 #if DEBUG_MALLOC
 		if (tiny_mag_ptr->mag_free_list[slot] != ptr) {
-			szone_error(szone, 1, "tiny_free_list_remove_ptr: Internal invariant broken (tiny_mag_ptr->mag_free_list[slot])", ptr,
+			szone_error(rack->debug_flags, 1,
+						"tiny_free_list_remove_ptr: Internal invariant broken (tiny_mag_ptr->mag_free_list[slot])", ptr,
 						"ptr=%p slot=%d msize=%d tiny_mag_ptr->mag_free_list[slot]=%p\n", ptr, slot, msize,
 						(void *)tiny_mag_ptr->mag_free_list[slot]);
 			return;
@@ -337,7 +340,7 @@
 }
 
 void
-tiny_finalize_region(szone_t *szone, magazine_t *tiny_mag_ptr)
+tiny_finalize_region(rack_t *rack, magazine_t *tiny_mag_ptr)
 {
 	void *last_block, *previous_block;
 	uint32_t *last_header;
@@ -377,13 +380,13 @@
 		previous_block = tiny_previous_preceding_free(last_block, &previous_msize);
 		if (previous_block) {
 			set_tiny_meta_header_middle(last_block);
-			tiny_free_list_remove_ptr(szone, tiny_mag_ptr, previous_block, previous_msize);
+			tiny_free_list_remove_ptr(rack, tiny_mag_ptr, previous_block, previous_msize);
 			last_block = previous_block;
 			last_msize += previous_msize;
 		}
 
 		// splice last_block into the free list
-		tiny_free_list_add_ptr(szone, tiny_mag_ptr, last_block, last_msize);
+		tiny_free_list_add_ptr(rack, tiny_mag_ptr, last_block, last_msize);
 		tiny_mag_ptr->mag_bytes_free_at_end = 0;
 	}
 
@@ -402,12 +405,12 @@
 		if (tiny_meta_header_is_free(next_block)) {
 			msize_t next_msize = get_tiny_free_size(next_block);
 			set_tiny_meta_header_middle(next_block);
-			tiny_free_list_remove_ptr(szone, tiny_mag_ptr, next_block, next_msize);
+			tiny_free_list_remove_ptr(rack, tiny_mag_ptr, next_block, next_msize);
 			last_msize += next_msize;
 		}
 
 		// splice last_block into the free list
-		tiny_free_list_add_ptr(szone, tiny_mag_ptr, last_block, last_msize);
+		tiny_free_list_add_ptr(rack, tiny_mag_ptr, last_block, last_msize);
 		tiny_mag_ptr->mag_bytes_free_at_start = 0;
 	}
 #endif
@@ -416,7 +419,7 @@
 }
 
 int
-tiny_free_detach_region(szone_t *szone, magazine_t *tiny_mag_ptr, region_t r)
+tiny_free_detach_region(rack_t *rack, magazine_t *tiny_mag_ptr, region_t r)
 {
 	uintptr_t start = (uintptr_t)TINY_REGION_ADDRESS(r);
 	uintptr_t current = start;
@@ -438,7 +441,7 @@
 			break;
 		}
 		if (is_free) {
-			tiny_free_list_remove_ptr(szone, tiny_mag_ptr, (void *)current, msize);
+			tiny_free_list_remove_ptr(rack, tiny_mag_ptr, (void *)current, msize);
 		} else {
 			total_alloc++;
 		}
@@ -448,7 +451,7 @@
 }
 
 size_t
-tiny_free_reattach_region(szone_t *szone, magazine_t *tiny_mag_ptr, region_t r)
+tiny_free_reattach_region(rack_t *rack, magazine_t *tiny_mag_ptr, region_t r)
 {
 	uintptr_t start = (uintptr_t)TINY_REGION_ADDRESS(r);
 	uintptr_t current = start;
@@ -470,7 +473,7 @@
 			break;
 		}
 		if (is_free) {
-			tiny_free_list_add_ptr(szone, tiny_mag_ptr, (void *)current, msize);
+			tiny_free_list_add_ptr(rack, tiny_mag_ptr, (void *)current, msize);
 		} else {
 			total_alloc += TINY_BYTES_FOR_MSIZE(msize);
 		}
@@ -484,7 +487,7 @@
 } tiny_pg_pair_t;
 
 void
-tiny_free_scan_madvise_free(szone_t *szone, magazine_t *depot_ptr, region_t r)
+tiny_free_scan_madvise_free(rack_t *rack, magazine_t *depot_ptr, region_t r)
 {
 	uintptr_t start = (uintptr_t)TINY_REGION_ADDRESS(r);
 	uintptr_t current = start;
@@ -545,20 +548,20 @@
 		// (1) is ensured by design, (2) and (3) are ensured by bumping the globally visible counter node->pinned_to_depot.
 
 		OSAtomicIncrement32Barrier(&(REGION_TRAILER_FOR_TINY_REGION(r)->pinned_to_depot));
-		SZONE_MAGAZINE_PTR_UNLOCK(szone, depot_ptr);
+		SZONE_MAGAZINE_PTR_UNLOCK(depot_ptr);
 		for (i = 0; i < advisories; ++i) {
 			uintptr_t addr = (advisory[i].pnum << vm_kernel_page_shift) + start;
 			size_t size = advisory[i].size << vm_kernel_page_shift;
 
-			madvise_free_range(szone, r, addr, addr + size, NULL);
-		}
-		SZONE_MAGAZINE_PTR_LOCK(szone, depot_ptr);
+			mvm_madvise_free(rack, r, addr, addr + size, NULL);
+		}
+		SZONE_MAGAZINE_PTR_LOCK(depot_ptr);
 		OSAtomicDecrement32Barrier(&(REGION_TRAILER_FOR_TINY_REGION(r)->pinned_to_depot));
 	}
 }
 
 static region_t
-tiny_find_msize_region(szone_t *szone, magazine_t *tiny_mag_ptr, mag_index_t mag_index, msize_t msize)
+tiny_find_msize_region(rack_t *rack, magazine_t *tiny_mag_ptr, mag_index_t mag_index, msize_t msize)
 {
 	tiny_free_list_t *ptr;
 	grain_t slot = msize - 1;
@@ -618,7 +621,7 @@
 }
 
 static MALLOC_INLINE void
-tiny_madvise_free_range_no_lock(szone_t *szone,
+tiny_madvise_free_range_no_lock(rack_t *rack,
 								magazine_t *tiny_mag_ptr,
 								region_t region,
 								void *headptr,
@@ -651,48 +654,48 @@
 		uintptr_t free_hi = MIN(trunc_extent, hi);
 
 		if (free_lo < free_hi) {
-			tiny_free_list_remove_ptr(szone, tiny_mag_ptr, ptr, msize);
+			tiny_free_list_remove_ptr(rack, tiny_mag_ptr, ptr, msize);
 			set_tiny_meta_header_in_use(ptr, msize);
 
 			OSAtomicIncrement32Barrier(&(node->pinned_to_depot));
-			SZONE_MAGAZINE_PTR_UNLOCK(szone, tiny_mag_ptr);
-			madvise_free_range(szone, region, free_lo, free_hi, &szone->last_tiny_advise);
-			SZONE_MAGAZINE_PTR_LOCK(szone, tiny_mag_ptr);
+			SZONE_MAGAZINE_PTR_UNLOCK(tiny_mag_ptr);
+			mvm_madvise_free(rack, region, free_lo, free_hi, &rack->last_madvise);
+			SZONE_MAGAZINE_PTR_LOCK(tiny_mag_ptr);
 			OSAtomicDecrement32Barrier(&(node->pinned_to_depot));
 
 			set_tiny_meta_header_free(ptr, msize);
-			tiny_free_list_add_ptr(szone, tiny_mag_ptr, ptr, msize);
+			tiny_free_list_add_ptr(rack, tiny_mag_ptr, ptr, msize);
 		}
 	}
 }
 
 static boolean_t
-tiny_get_region_from_depot(szone_t *szone, magazine_t *tiny_mag_ptr, mag_index_t mag_index, msize_t msize)
-{
-	magazine_t *depot_ptr = &(szone->tiny_magazines[DEPOT_MAGAZINE_INDEX]);
+tiny_get_region_from_depot(rack_t *rack, magazine_t *tiny_mag_ptr, mag_index_t mag_index, msize_t msize)
+{
+	magazine_t *depot_ptr = &(rack->magazines[DEPOT_MAGAZINE_INDEX]);
 
 	/* FIXME: Would Uniprocessor benefit from recirc and MADV_FREE? */
-	if (szone->num_tiny_magazines == 1) { // Uniprocessor, single magazine, so no recirculation necessary
+	if (rack->num_magazines == 1) { // Uniprocessor, single magazine, so no recirculation necessary
 		return 0;
 	}
 
 #if DEBUG_MALLOC
 	if (DEPOT_MAGAZINE_INDEX == mag_index) {
-		szone_error(szone, 1, "tiny_get_region_from_depot called for magazine index -1", NULL, NULL);
+		szone_error(rack->debug_flags, 1, "tiny_get_region_from_depot called for magazine index -1", NULL, NULL);
 		return 0;
 	}
 #endif
 
-	SZONE_MAGAZINE_PTR_LOCK(szone, depot_ptr);
+	SZONE_MAGAZINE_PTR_LOCK(depot_ptr);
 
 	// Appropriate a Depot'd region that can satisfy requested msize.
 	region_trailer_t *node;
 	region_t sparse_region;
 
 	while (1) {
-		sparse_region = tiny_find_msize_region(szone, depot_ptr, DEPOT_MAGAZINE_INDEX, msize);
+		sparse_region = tiny_find_msize_region(rack, depot_ptr, DEPOT_MAGAZINE_INDEX, msize);
 		if (NULL == sparse_region) { // Depot empty?
-			SZONE_MAGAZINE_PTR_UNLOCK(szone, depot_ptr);
+			SZONE_MAGAZINE_PTR_UNLOCK(depot_ptr);
 			return 0;
 		}
 
@@ -701,23 +704,23 @@
 			break;
 		}
 
-		SZONE_MAGAZINE_PTR_UNLOCK(szone, depot_ptr);
+		SZONE_MAGAZINE_PTR_UNLOCK(depot_ptr);
 		yield();
-		SZONE_MAGAZINE_PTR_LOCK(szone, depot_ptr);
+		SZONE_MAGAZINE_PTR_LOCK(depot_ptr);
 	}
 
 	// disconnect node from Depot
-	recirc_list_extract(szone, depot_ptr, node);
+	recirc_list_extract(rack, depot_ptr, node);
 
 	// Iterate the region pulling its free entries off the (locked) Depot's free list
-	int objects_in_use = tiny_free_detach_region(szone, depot_ptr, sparse_region);
+	int objects_in_use = tiny_free_detach_region(rack, depot_ptr, sparse_region);
 
 	// Transfer ownership of the region
 	MAGAZINE_INDEX_FOR_TINY_REGION(sparse_region) = mag_index;
 	node->pinned_to_depot = 0;
 
 	// Iterate the region putting its free entries on its new (locked) magazine's free list
-	size_t bytes_inplay = tiny_free_reattach_region(szone, tiny_mag_ptr, sparse_region);
+	size_t bytes_inplay = tiny_free_reattach_region(rack, tiny_mag_ptr, sparse_region);
 
 	depot_ptr->mag_num_bytes_in_objects -= bytes_inplay;
 	depot_ptr->num_bytes_in_magazine -= TINY_REGION_PAYLOAD_BYTES;
@@ -728,59 +731,71 @@
 	tiny_mag_ptr->mag_num_objects += objects_in_use;
 
 	// connect to magazine as first node
-	recirc_list_splice_first(szone, tiny_mag_ptr, node);
-
-	SZONE_MAGAZINE_PTR_UNLOCK(szone, depot_ptr);
+	recirc_list_splice_first(rack, tiny_mag_ptr, node);
+
+	SZONE_MAGAZINE_PTR_UNLOCK(depot_ptr);
 
 	// madvise() outside the Depot lock
-	(void)madvise_reuse_range(szone, sparse_region, (uintptr_t)sparse_region, (uintptr_t)sparse_region + TINY_REGION_PAYLOAD_BYTES);
-
-	MAGMALLOC_DEPOTREGION((void *)szone, (int)mag_index, (void *)sparse_region, TINY_REGION_SIZE,
-						  (int)BYTES_USED_FOR_TINY_REGION(sparse_region)); // DTrace USDT Probe
+	(void)mvm_madvise_reuse(sparse_region, (uintptr_t)sparse_region,
+			(uintptr_t)sparse_region + TINY_REGION_PAYLOAD_BYTES, rack->debug_flags);
+
+	// DTrace USDT Probe
+	MAGMALLOC_DEPOTREGION(TINY_SZONE_FROM_RACK(rack), (int)mag_index, (void *)sparse_region,
+			TINY_REGION_SIZE, (int)BYTES_USED_FOR_TINY_REGION(sparse_region));
 
 	return 1;
 }
 
 #if CONFIG_RECIRC_DEPOT
 static region_t
-tiny_free_try_depot_unmap_no_lock(szone_t *szone, magazine_t *depot_ptr, region_trailer_t *node)
-{
-	if (0 < node->bytes_used || 0 < node->pinned_to_depot || depot_ptr->recirculation_entries < (szone->num_tiny_magazines * 2)) {
+tiny_free_try_depot_unmap_no_lock(rack_t *rack, magazine_t *depot_ptr, region_trailer_t *node)
+{
+	if (0 < node->bytes_used || 0 < node->pinned_to_depot ||
+		depot_ptr->recirculation_entries < (rack->num_magazines * 2))
+	{
 		return NULL;
 	}
 
 	// disconnect node from Depot
-	recirc_list_extract(szone, depot_ptr, node);
+	recirc_list_extract(rack, depot_ptr, node);
 
 	// Iterate the region pulling its free entries off the (locked) Depot's free list
 	region_t sparse_region = TINY_REGION_FOR_PTR(node);
-	int objects_in_use = tiny_free_detach_region(szone, depot_ptr, sparse_region);
+	int objects_in_use = tiny_free_detach_region(rack, depot_ptr, sparse_region);
 
 	if (0 == objects_in_use) {
 		// Invalidate the hash table entry for this region with HASHRING_REGION_DEALLOCATED.
 		// Using HASHRING_REGION_DEALLOCATED preserves the collision chain, using HASHRING_OPEN_ENTRY (0) would not.
-		rgnhdl_t pSlot = hash_lookup_region_no_lock(szone->tiny_region_generation->hashed_regions,
-													szone->tiny_region_generation->num_regions_allocated, szone->tiny_region_generation->num_regions_allocated_shift,
-													sparse_region);
+		rgnhdl_t pSlot = hash_lookup_region_no_lock(rack->region_generation->hashed_regions,
+				rack->region_generation->num_regions_allocated,
+				rack->region_generation->num_regions_allocated_shift,
+				sparse_region);
+
 		if (NULL == pSlot) {
-			szone_error(szone, 1, "tiny_free_try_depot_unmap_no_lock hash lookup failed:", NULL, "%p\n", sparse_region);
+			szone_error(rack->debug_flags, 1, "tiny_free_try_depot_unmap_no_lock hash lookup failed:", NULL, "%p\n", sparse_region);
 			return NULL;
 		}
 		*pSlot = HASHRING_REGION_DEALLOCATED;
 		depot_ptr->num_bytes_in_magazine -= TINY_REGION_PAYLOAD_BYTES;
-		__sync_fetch_and_add(&(szone->num_tiny_regions_dealloc), 1); // Atomically increment num_tiny_regions_dealloc
+
+		// Atomically increment num_regions_dealloc
+#ifdef __LP64___
+		OSAtomicIncrement64(&rack->num_regions_dealloc);
+#else
+		OSAtomicIncrement32((int32_t *)&rack->num_regions_dealloc);
+#endif
 
 		// Caller will transfer ownership of the region back to the OS with no locks held
-		MAGMALLOC_DEALLOCREGION((void *)szone, (void *)sparse_region, TINY_REGION_SIZE); // DTrace USDT Probe
+		MAGMALLOC_DEALLOCREGION(TINY_SZONE_FROM_RACK(rack), (void *)sparse_region, TINY_REGION_SIZE); // DTrace USDT Probe
 		return sparse_region;
 	} else {
-		szone_error(szone, 1, "tiny_free_try_depot_unmap_no_lock objects_in_use not zero:", NULL, "%d\n", objects_in_use);
+		szone_error(rack->debug_flags, 1, "tiny_free_try_depot_unmap_no_lock objects_in_use not zero:", NULL, "%d\n", objects_in_use);
 		return NULL;
 	}
 }
 
 static boolean_t
-tiny_free_do_recirc_to_depot(szone_t *szone, magazine_t *tiny_mag_ptr, mag_index_t mag_index)
+tiny_free_do_recirc_to_depot(rack_t *rack, magazine_t *tiny_mag_ptr, mag_index_t mag_index)
 {
 	// The entire magazine crossed the "emptiness threshold". Transfer a region
 	// from this magazine to the Depot. Choose a region that itself has crossed the emptiness threshold (i.e
@@ -795,7 +810,7 @@
 #if DEBUG_MALLOC
 		malloc_printf("*** tiny_free_do_recirc_to_depot end of list\n");
 #endif
-		return TRUE; // Caller must SZONE_MAGAZINE_PTR_UNLOCK(szone, tiny_mag_ptr);
+		return TRUE; // Caller must SZONE_MAGAZINE_PTR_UNLOCK(tiny_mag_ptr);
 	}
 
 	region_t sparse_region = TINY_REGION_FOR_PTR(node);
@@ -803,58 +818,58 @@
 	// Deal with unclaimed memory -- mag_bytes_free_at_end or mag_bytes_free_at_start
 	if (sparse_region == tiny_mag_ptr->mag_last_region &&
 		(tiny_mag_ptr->mag_bytes_free_at_end || tiny_mag_ptr->mag_bytes_free_at_start)) {
-		tiny_finalize_region(szone, tiny_mag_ptr);
+		tiny_finalize_region(rack, tiny_mag_ptr);
 	}
 
 	// disconnect "suitable" node from magazine
-	recirc_list_extract(szone, tiny_mag_ptr, node);
+	recirc_list_extract(rack, tiny_mag_ptr, node);
 
 	// Iterate the region pulling its free entries off its (locked) magazine's free list
-	int objects_in_use = tiny_free_detach_region(szone, tiny_mag_ptr, sparse_region);
-	magazine_t *depot_ptr = &(szone->tiny_magazines[DEPOT_MAGAZINE_INDEX]);
+	int objects_in_use = tiny_free_detach_region(rack, tiny_mag_ptr, sparse_region);
+	magazine_t *depot_ptr = &(rack->magazines[DEPOT_MAGAZINE_INDEX]);
 
 	// hand over the region to the (locked) Depot
-	SZONE_MAGAZINE_PTR_LOCK(szone, depot_ptr);
+	SZONE_MAGAZINE_PTR_LOCK(depot_ptr);
 	// this will cause tiny_free_list_add_ptr called by tiny_free_reattach_region to use
 	// the depot as its target magazine, rather than magazine formerly associated with sparse_region
 	MAGAZINE_INDEX_FOR_TINY_REGION(sparse_region) = DEPOT_MAGAZINE_INDEX;
 	node->pinned_to_depot = 0;
 
 	// Iterate the region putting its free entries on Depot's free list
-	size_t bytes_inplay = tiny_free_reattach_region(szone, depot_ptr, sparse_region);
+	size_t bytes_inplay = tiny_free_reattach_region(rack, depot_ptr, sparse_region);
 
 	tiny_mag_ptr->mag_num_bytes_in_objects -= bytes_inplay;
 	tiny_mag_ptr->num_bytes_in_magazine -= TINY_REGION_PAYLOAD_BYTES;
 	tiny_mag_ptr->mag_num_objects -= objects_in_use;
 
-	SZONE_MAGAZINE_PTR_UNLOCK(szone, tiny_mag_ptr); // Unlock the originating magazine
+	SZONE_MAGAZINE_PTR_UNLOCK(tiny_mag_ptr); // Unlock the originating magazine
 
 	depot_ptr->mag_num_bytes_in_objects += bytes_inplay;
 	depot_ptr->num_bytes_in_magazine += TINY_REGION_PAYLOAD_BYTES;
 	depot_ptr->mag_num_objects += objects_in_use;
 
 	// connect to Depot as last node
-	recirc_list_splice_last(szone, depot_ptr, node);
-
-	MAGMALLOC_RECIRCREGION((void *)szone, (int)mag_index, (void *)sparse_region, TINY_REGION_SIZE,
+	recirc_list_splice_last(rack, depot_ptr, node);
+
+	MAGMALLOC_RECIRCREGION(TINY_SZONE_FROM_RACK(rack), (int)mag_index, (void *)sparse_region, TINY_REGION_SIZE,
 						   (int)BYTES_USED_FOR_TINY_REGION(sparse_region)); // DTrace USDT Probe
 
 #if !CONFIG_AGGRESSIVE_MADVISE
 	// Mark free'd dirty pages with MADV_FREE to reduce memory pressure
-	tiny_free_scan_madvise_free(szone, depot_ptr, sparse_region);
+	tiny_free_scan_madvise_free(rack, depot_ptr, sparse_region);
 #endif
 
 	// If the region is entirely empty vm_deallocate() it outside the depot lock
-	region_t r_dealloc = tiny_free_try_depot_unmap_no_lock(szone, depot_ptr, node);
-	SZONE_MAGAZINE_PTR_UNLOCK(szone, depot_ptr);
+	region_t r_dealloc = tiny_free_try_depot_unmap_no_lock(rack, depot_ptr, node);
+	SZONE_MAGAZINE_PTR_UNLOCK(depot_ptr);
 	if (r_dealloc) {
-		deallocate_pages(szone, r_dealloc, TINY_REGION_SIZE, 0);
+		mvm_deallocate_pages(r_dealloc, TINY_REGION_SIZE, 0);
 	}
 	return FALSE; // Caller need not unlock the originating magazine
 }
 
 static MALLOC_INLINE boolean_t
-tiny_free_try_recirc_to_depot(szone_t *szone,
+tiny_free_try_recirc_to_depot(rack_t *rack,
 							  magazine_t *tiny_mag_ptr,
 							  mag_index_t mag_index,
 							  region_t region,
@@ -867,9 +882,9 @@
 	size_t bytes_used = node->bytes_used;
 
 	/* FIXME: Would Uniprocessor benefit from recirc and MADV_FREE? */
-	if (szone->num_tiny_magazines == 1) { // Uniprocessor, single magazine, so no recirculation necessary
+	if (rack->num_magazines == 1) { // Uniprocessor, single magazine, so no recirculation necessary
 		/* NOTHING */
-		return TRUE; // Caller must do SZONE_MAGAZINE_PTR_UNLOCK(szone, tiny_mag_ptr)
+		return TRUE; // Caller must do SZONE_MAGAZINE_PTR_UNLOCK(tiny_mag_ptr)
 	} else if (DEPOT_MAGAZINE_INDEX != mag_index) {
 		// Emptiness discriminant
 		if (bytes_used < DENSITY_THRESHOLD(TINY_REGION_PAYLOAD_BYTES)) {
@@ -888,13 +903,13 @@
 		size_t u = tiny_mag_ptr->mag_num_bytes_in_objects; // In use (malloc'd) from this magaqzine
 
 		if (a - u > ((3 * TINY_REGION_PAYLOAD_BYTES) / 2) && u < DENSITY_THRESHOLD(a)) {
-			return tiny_free_do_recirc_to_depot(szone, tiny_mag_ptr, mag_index);
+			return tiny_free_do_recirc_to_depot(rack, tiny_mag_ptr, mag_index);
 		}
 	} else {
 #if !CONFIG_AGGRESSIVE_MADVISE
 		// We are free'ing into the depot, so madvise as we do so unless we were madvising every incoming
 		// allocation anyway.
-		tiny_madvise_free_range_no_lock(szone, tiny_mag_ptr, region, headptr, headsize, ptr, msize);
+		tiny_madvise_free_range_no_lock(rack, tiny_mag_ptr, region, headptr, headsize, ptr, msize);
 #endif
 
 		if (0 < bytes_used || 0 < node->pinned_to_depot) {
@@ -903,20 +918,20 @@
 			 * with detach_region/reattach_region */
 		} else {
 			/* Depot'd region is just now empty. Consider return to OS. */
-			region_t r_dealloc = tiny_free_try_depot_unmap_no_lock(szone, tiny_mag_ptr, node);
-			SZONE_MAGAZINE_PTR_UNLOCK(szone, tiny_mag_ptr);
+			region_t r_dealloc = tiny_free_try_depot_unmap_no_lock(rack, tiny_mag_ptr, node);
+			SZONE_MAGAZINE_PTR_UNLOCK(tiny_mag_ptr);
 			if (r_dealloc) {
-				deallocate_pages(szone, r_dealloc, TINY_REGION_SIZE, 0);
+				mvm_deallocate_pages(r_dealloc, TINY_REGION_SIZE, 0);
 			}
 			return FALSE; // Caller need not unlock
 		}
 	}
-	return TRUE; // Caller must do SZONE_MAGAZINE_PTR_UNLOCK(szone, tiny_mag_ptr)
+	return TRUE; // Caller must do SZONE_MAGAZINE_PTR_UNLOCK(tiny_mag_ptr)
 }
 #endif // CONFIG_RECIRC_DEPOT
 
 boolean_t
-tiny_free_no_lock(szone_t *szone, magazine_t *tiny_mag_ptr, mag_index_t mag_index, region_t region, void *ptr, msize_t msize)
+tiny_free_no_lock(rack_t *rack, magazine_t *tiny_mag_ptr, mag_index_t mag_index, region_t region, void *ptr, msize_t msize)
 {
 	void *original_ptr = ptr;
 	size_t original_size = TINY_BYTES_FOR_MSIZE(msize);
@@ -932,7 +947,7 @@
 		malloc_printf("in tiny_free_no_lock(), ptr=%p, msize=%d\n", ptr, msize);
 	}
 	if (!msize) {
-		szone_error(szone, 1, "trying to free tiny block that is too small", ptr, "in tiny_free_no_lock(), ptr=%p, msize=%d\n", ptr,
+		szone_error(rack->debug_flags, 1, "trying to free tiny block that is too small", ptr, "in tiny_free_no_lock(), ptr=%p, msize=%d\n", ptr,
 					msize);
 	}
 #endif
@@ -948,7 +963,7 @@
 
 		// clear the meta_header since this is no longer the start of a block
 		set_tiny_meta_header_middle(ptr);
-		tiny_free_list_remove_ptr(szone, tiny_mag_ptr, previous, previous_msize);
+		tiny_free_list_remove_ptr(rack, tiny_mag_ptr, previous, previous_msize);
 		ptr = previous;
 		msize += previous_msize;
 	}
@@ -969,17 +984,17 @@
 			msize += next_msize;
 
 			big_free_block = (tiny_free_list_t *)next_block;
-			after_next_block = free_list_unchecksum_ptr(szone, &big_free_block->next);
-			before_next_block = free_list_unchecksum_ptr(szone, &big_free_block->previous);
+			after_next_block = free_list_unchecksum_ptr(rack, &big_free_block->next);
+			before_next_block = free_list_unchecksum_ptr(rack, &big_free_block->previous);
 
 			if (!before_next_block) {
 				tiny_mag_ptr->mag_free_list[NUM_TINY_SLOTS - 1].p = ptr;
 			} else {
-				before_next_block->next.u = free_list_checksum_ptr(szone, ptr);
+				before_next_block->next.u = free_list_checksum_ptr(rack, ptr);
 			}
 
 			if (after_next_block) {
-				after_next_block->previous.u = free_list_checksum_ptr(szone, ptr);
+				after_next_block->previous.u = free_list_checksum_ptr(rack, ptr);
 			}
 
 			// we don't need to checksum these since they are already checksummed
@@ -992,18 +1007,18 @@
 
 			goto tiny_free_ending;
 		}
-		tiny_free_list_remove_ptr(szone, tiny_mag_ptr, next_block, next_msize);
+		tiny_free_list_remove_ptr(rack, tiny_mag_ptr, next_block, next_msize);
 		set_tiny_meta_header_middle(next_block); // clear the meta_header to enable coalescing backwards
 		msize += next_msize;
 	}
 
 	// The tiny cache already scribbles free blocks as they go through the
 	// cache whenever msize < TINY_QUANTUM , so we do not need to do it here.
-	if ((szone->debug_flags & MALLOC_DO_SCRIBBLE) && msize && (msize >= TINY_QUANTUM)) {
+	if ((rack->debug_flags & MALLOC_DO_SCRIBBLE) && msize && (msize >= TINY_QUANTUM)) {
 		memset(ptr, SCRABBLE_BYTE, TINY_BYTES_FOR_MSIZE(msize));
 	}
 
-	tiny_free_list_add_ptr(szone, tiny_mag_ptr, ptr, msize);
+	tiny_free_list_add_ptr(rack, tiny_mag_ptr, ptr, msize);
 
 tiny_free_ending:
 
@@ -1019,22 +1034,22 @@
 #if CONFIG_AGGRESSIVE_MADVISE
 	// Platforms that want to madvise every freed allocation do so here, even if we continue
 	// on to use the recirc depot after.
-	tiny_madvise_free_range_no_lock(szone, tiny_mag_ptr, region, original_ptr, original_size, ptr, msize);
-#endif
-
-	// Caller must do SZONE_MAGAZINE_PTR_UNLOCK(szone, tiny_mag_ptr) if this function
+	tiny_madvise_free_range_no_lock(rack, tiny_mag_ptr, region, original_ptr, original_size, ptr, msize);
+#endif
+
+	// Caller must do SZONE_MAGAZINE_PTR_UNLOCK(tiny_mag_ptr) if this function
 	// returns TRUE.
 	boolean_t needs_unlock = TRUE;
 
 #if CONFIG_RECIRC_DEPOT
-	needs_unlock = tiny_free_try_recirc_to_depot(szone, tiny_mag_ptr, mag_index, region, original_ptr, original_size, ptr, msize);
+	needs_unlock = tiny_free_try_recirc_to_depot(rack, tiny_mag_ptr, mag_index, region, original_ptr, original_size, ptr, msize);
 #endif
 	return needs_unlock;
 }
 
 // Allocates from the last region or a freshly allocated region
 static void *
-tiny_malloc_from_region_no_lock(szone_t *szone,
+tiny_malloc_from_region_no_lock(rack_t *rack,
 								magazine_t *tiny_mag_ptr,
 								mag_index_t mag_index,
 								msize_t msize,
@@ -1044,59 +1059,29 @@
 
 	// Deal with unclaimed memory -- mag_bytes_free_at_end or mag_bytes_free_at_start
 	if (tiny_mag_ptr->mag_bytes_free_at_end || tiny_mag_ptr->mag_bytes_free_at_start) {
-		tiny_finalize_region(szone, tiny_mag_ptr);
+		tiny_finalize_region(rack, tiny_mag_ptr);
 	}
 
 	// We set the unused bits of the header in the last pair to be all ones, and those of the inuse to zeroes.
-	((tiny_region_t)aligned_address)->pairs[CEIL_NUM_TINY_BLOCKS_WORDS - 1].header =
-	(NUM_TINY_BLOCKS & 31) ? (0xFFFFFFFFU << (NUM_TINY_BLOCKS & 31)) : 0;
+#if NUM_TINY_BLOCKS & 31
+	const uint32_t header = 0xFFFFFFFFU << (NUM_TINY_BLOCKS & 31);
+#else
+	const uint32_t header = 0;
+#endif
+	((tiny_region_t)aligned_address)->pairs[CEIL_NUM_TINY_BLOCKS_WORDS - 1].header = header;
 	((tiny_region_t)aligned_address)->pairs[CEIL_NUM_TINY_BLOCKS_WORDS - 1].inuse = 0;
 
-	// Here find the only place in tinyland that (infrequently) takes the tiny_regions_lock.
-	// Only one thread at a time should be permitted to assess the density of the hash
-	// ring and adjust if needed.
-	// Only one thread at a time should be permitted to insert its new region on
-	// the hash ring.
-	// It is safe for all other threads to read the hash ring (hashed_regions) and
-	// the associated sizes (num_regions_allocated and num_tiny_regions).
-
-	_malloc_lock_lock(&szone->tiny_regions_lock);
-
-	// Check to see if the hash ring of tiny regions needs to grow.  Try to
-	// avoid the hash ring becoming too dense.
-	if (szone->tiny_region_generation->num_regions_allocated < (2 * szone->num_tiny_regions)) {
-		region_t *new_regions;
-		size_t new_size;
-		size_t new_shift = szone->tiny_region_generation->num_regions_allocated_shift; // In/Out parameter
-		new_regions = hash_regions_grow_no_lock(szone, szone->tiny_region_generation->hashed_regions,
-												szone->tiny_region_generation->num_regions_allocated, &new_shift, &new_size);
-		// Do not deallocate the current hashed_regions allocation since someone may
-		// be iterating it.  Instead, just leak it.
-
-		// Prepare to advance to the "next generation" of the hash ring.
-		szone->tiny_region_generation->nextgen->hashed_regions = new_regions;
-		szone->tiny_region_generation->nextgen->num_regions_allocated = new_size;
-		szone->tiny_region_generation->nextgen->num_regions_allocated_shift = new_shift;
-
-		// Throw the switch to atomically advance to the next generation.
-		szone->tiny_region_generation = szone->tiny_region_generation->nextgen;
-		// Ensure everyone sees the advance.
-		OSMemoryBarrier();
-	}
 	// Tag the region at "aligned_address" as belonging to us,
 	// and so put it under the protection of the magazine lock we are holding.
 	// Do this before advertising "aligned_address" on the hash ring(!)
 	MAGAZINE_INDEX_FOR_TINY_REGION(aligned_address) = mag_index;
 
-	// Insert the new region into the hash ring, and update malloc statistics
-	hash_region_insert_no_lock(szone->tiny_region_generation->hashed_regions, szone->tiny_region_generation->num_regions_allocated,
-							   szone->tiny_region_generation->num_regions_allocated_shift, aligned_address);
-
-	szone->num_tiny_regions++;
-	_malloc_lock_unlock(&szone->tiny_regions_lock);
+	// Insert the new region into the hash ring
+	rack_region_insert(rack, (region_t)aligned_address);
 
 	tiny_mag_ptr->mag_last_region = aligned_address;
 	BYTES_USED_FOR_TINY_REGION(aligned_address) = TINY_BYTES_FOR_MSIZE(msize);
+
 #if CONFIG_ASLR_INTERNAL
 	int offset_msize = malloc_entropy[0] & TINY_ENTROPY_MASK;
 #if DEBUG_MALLOC
@@ -1131,7 +1116,7 @@
 #endif
 
 	// connect to magazine as last node
-	recirc_list_splice_last(szone, tiny_mag_ptr, REGION_TRAILER_FOR_TINY_REGION(aligned_address));
+	recirc_list_splice_last(rack, tiny_mag_ptr, REGION_TRAILER_FOR_TINY_REGION(aligned_address));
 
 #if DEBUG_MALLOC
 	if (LOG(szone, ptr)) {
@@ -1162,8 +1147,9 @@
 		void *q = (void *)(((uintptr_t)p) + pad);
 
 		// Mark q as a block header and in-use, thus creating two blocks.
-		magazine_t *tiny_mag_ptr = mag_lock_zine_for_region_trailer(szone, szone->tiny_magazines,
-																	REGION_TRAILER_FOR_TINY_REGION(TINY_REGION_FOR_PTR(p)), MAGAZINE_INDEX_FOR_TINY_REGION(TINY_REGION_FOR_PTR(p)));
+		magazine_t *tiny_mag_ptr = mag_lock_zine_for_region_trailer(szone->tiny_rack.magazines,
+				REGION_TRAILER_FOR_TINY_REGION(TINY_REGION_FOR_PTR(p)),
+				MAGAZINE_INDEX_FOR_TINY_REGION(TINY_REGION_FOR_PTR(p)));
 		set_tiny_meta_header_in_use(q, msize);
 		tiny_mag_ptr->mag_num_objects++;
 
@@ -1172,7 +1158,7 @@
 		if (mwaste > 0) {
 			BITARRAY_SET(TINY_INUSE_FOR_HEADER(TINY_BLOCK_HEADER_FOR_PTR(q)), TINY_INDEX_FOR_PTR(q) + msize);
 		}
-		SZONE_MAGAZINE_PTR_UNLOCK(szone, tiny_mag_ptr);
+		SZONE_MAGAZINE_PTR_UNLOCK(tiny_mag_ptr);
 
 		// Give up mpad blocks beginning at p to the tiny free list
 		// region_t r = TINY_REGION_FOR_PTR(p);
@@ -1184,11 +1170,12 @@
 	if (mwaste > 0) {
 		void *q = (void *)(((uintptr_t)p) + TINY_BYTES_FOR_MSIZE(msize));
 		// Mark q as block header and in-use, thus creating two blocks.
-		magazine_t *tiny_mag_ptr = mag_lock_zine_for_region_trailer(szone, szone->tiny_magazines,
-																	REGION_TRAILER_FOR_TINY_REGION(TINY_REGION_FOR_PTR(p)), MAGAZINE_INDEX_FOR_TINY_REGION(TINY_REGION_FOR_PTR(p)));
+		magazine_t *tiny_mag_ptr = mag_lock_zine_for_region_trailer(szone->tiny_rack.magazines,
+				REGION_TRAILER_FOR_TINY_REGION(TINY_REGION_FOR_PTR(p)),
+				MAGAZINE_INDEX_FOR_TINY_REGION(TINY_REGION_FOR_PTR(p)));
 		set_tiny_meta_header_in_use(q, mwaste);
 		tiny_mag_ptr->mag_num_objects++;
-		SZONE_MAGAZINE_PTR_UNLOCK(szone, tiny_mag_ptr);
+		SZONE_MAGAZINE_PTR_UNLOCK(tiny_mag_ptr);
 
 		// Give up mwaste blocks beginning at q to the tiny free list
 		// region_t r = TINY_REGION_FOR_PTR(q);
@@ -1199,28 +1186,29 @@
 }
 
 void *
-tiny_try_shrink_in_place(szone_t *szone, void *ptr, size_t old_size, size_t new_good_size)
+tiny_try_shrink_in_place(rack_t *rack, void *ptr, size_t old_size, size_t new_good_size)
 {
 	msize_t new_msize = TINY_MSIZE_FOR_BYTES(new_good_size);
 	msize_t mshrinkage = TINY_MSIZE_FOR_BYTES(old_size) - new_msize;
 
 	if (mshrinkage) {
 		void *q = (void *)((uintptr_t)ptr + TINY_BYTES_FOR_MSIZE(new_msize));
-		magazine_t *tiny_mag_ptr = mag_lock_zine_for_region_trailer(szone, szone->tiny_magazines,
-																	REGION_TRAILER_FOR_TINY_REGION(TINY_REGION_FOR_PTR(ptr)), MAGAZINE_INDEX_FOR_TINY_REGION(TINY_REGION_FOR_PTR(ptr)));
+		magazine_t *tiny_mag_ptr = mag_lock_zine_for_region_trailer(rack->magazines,
+				REGION_TRAILER_FOR_TINY_REGION(TINY_REGION_FOR_PTR(ptr)),
+				MAGAZINE_INDEX_FOR_TINY_REGION(TINY_REGION_FOR_PTR(ptr)));
 
 		// Mark q as block header and in-use, thus creating two blocks.
 		set_tiny_meta_header_in_use(q, mshrinkage);
 		tiny_mag_ptr->mag_num_objects++;
 
-		SZONE_MAGAZINE_PTR_UNLOCK(szone, tiny_mag_ptr);
-		szone_free(szone, q); // avoid inlining free_tiny(szone, q, ...);
+		SZONE_MAGAZINE_PTR_UNLOCK(tiny_mag_ptr);
+		free_tiny(rack, q, TINY_REGION_FOR_PTR(q), 0);
 	}
 	return ptr;
 }
 
 boolean_t
-tiny_try_realloc_in_place(szone_t *szone, void *ptr, size_t old_size, size_t new_size)
+tiny_try_realloc_in_place(rack_t *rack, void *ptr, size_t old_size, size_t new_size)
 {
 	// returns 1 on success
 	msize_t index;
@@ -1240,11 +1228,12 @@
 	}
 	next_block = (char *)ptr + old_size;
 
-	magazine_t *tiny_mag_ptr = mag_lock_zine_for_region_trailer(szone, szone->tiny_magazines,
-																REGION_TRAILER_FOR_TINY_REGION(TINY_REGION_FOR_PTR(ptr)), MAGAZINE_INDEX_FOR_TINY_REGION(TINY_REGION_FOR_PTR(ptr)));
+	magazine_t *tiny_mag_ptr = mag_lock_zine_for_region_trailer(rack->magazines,
+			REGION_TRAILER_FOR_TINY_REGION(TINY_REGION_FOR_PTR(ptr)),
+			MAGAZINE_INDEX_FOR_TINY_REGION(TINY_REGION_FOR_PTR(ptr)));
 
 	if (DEPOT_MAGAZINE_INDEX == MAGAZINE_INDEX_FOR_TINY_REGION(TINY_REGION_FOR_PTR(ptr))) {
-		SZONE_MAGAZINE_PTR_UNLOCK(szone, tiny_mag_ptr);
+		SZONE_MAGAZINE_PTR_UNLOCK(tiny_mag_ptr);
 		return 0;
 	}
 
@@ -1254,19 +1243,19 @@
 	 */
 	is_free = tiny_meta_header_is_free(next_block);
 	if (!is_free) {
-		SZONE_MAGAZINE_PTR_UNLOCK(szone, tiny_mag_ptr);
+		SZONE_MAGAZINE_PTR_UNLOCK(tiny_mag_ptr);
 		return 0; // next_block is in use;
 	}
 	next_msize = get_tiny_free_size(next_block);
 	if (old_size + TINY_BYTES_FOR_MSIZE(next_msize) < new_size) {
-		SZONE_MAGAZINE_PTR_UNLOCK(szone, tiny_mag_ptr);
+		SZONE_MAGAZINE_PTR_UNLOCK(tiny_mag_ptr);
 		return 0; // even with next block, not enough
 	}
 	/*
 	 * The following block is big enough; pull it from its freelist and chop off enough to satisfy
 	 * our needs.
 	 */
-	tiny_free_list_remove_ptr(szone, tiny_mag_ptr, next_block, next_msize);
+	tiny_free_list_remove_ptr(rack, tiny_mag_ptr, next_block, next_msize);
 	set_tiny_meta_header_middle(next_block); // clear the meta_header to enable coalescing backwards
 	coalesced_msize = TINY_MSIZE_FOR_BYTES(new_size - old_size + TINY_QUANTUM - 1);
 	leftover_msize = next_msize - coalesced_msize;
@@ -1274,7 +1263,7 @@
 		/* there's some left, so put the remainder back */
 		leftover = (void *)((uintptr_t)next_block + TINY_BYTES_FOR_MSIZE(coalesced_msize));
 
-		tiny_free_list_add_ptr(szone, tiny_mag_ptr, leftover, leftover_msize);
+		tiny_free_list_add_ptr(rack, tiny_mag_ptr, leftover, leftover_msize);
 	}
 	set_tiny_meta_header_in_use(ptr, old_msize + coalesced_msize);
 #if DEBUG_MALLOC
@@ -1299,13 +1288,13 @@
 		node->recirc_suitable = FALSE;
 	}
 
-	SZONE_MAGAZINE_PTR_UNLOCK(szone, tiny_mag_ptr);
+	SZONE_MAGAZINE_PTR_UNLOCK(tiny_mag_ptr);
 	CHECK(szone, __PRETTY_FUNCTION__);
 	return 1;
 }
 
 boolean_t
-tiny_check_region(szone_t *szone, region_t region)
+tiny_check_region(rack_t *rack, region_t region)
 {
 	uintptr_t start, ptr, region_end;
 	boolean_t prev_free = 0;
@@ -1314,7 +1303,7 @@
 	tiny_free_list_t *free_head;
 	void *follower, *previous, *next;
 	mag_index_t mag_index = MAGAZINE_INDEX_FOR_TINY_REGION(region);
-	magazine_t *tiny_mag_ptr = &(szone->tiny_magazines[mag_index]);
+	magazine_t *tiny_mag_ptr = &(rack->magazines[mag_index]);
 
 	// Assumes locked
 	CHECK_MAGAZINE_PTR_LOCKED(szone, tiny_mag_ptr, __PRETTY_FUNCTION__);
@@ -1394,8 +1383,8 @@
 			 * Check the integrity of this block's entry in its freelist.
 			 */
 			free_head = (tiny_free_list_t *)ptr;
-			previous = free_list_unchecksum_ptr(szone, &free_head->previous);
-			next = free_list_unchecksum_ptr(szone, &free_head->next);
+			previous = free_list_unchecksum_ptr(rack, &free_head->previous);
+			next = free_list_unchecksum_ptr(rack, &free_head->next);
 			if (previous && !tiny_meta_header_is_free(previous)) {
 				malloc_printf("*** invariant broken for %p (previous %p is not a free pointer)\n", ptr, previous);
 				return 0;
@@ -1470,7 +1459,7 @@
 	magazine_t *tiny_mag_base = NULL;
 
 	region_hash_generation_t *trg_ptr;
-	err = reader(task, (vm_address_t)szone->tiny_region_generation, sizeof(region_hash_generation_t), (void **)&trg_ptr);
+	err = reader(task, (vm_address_t)szone->tiny_rack.region_generation, sizeof(region_hash_generation_t), (void **)&trg_ptr);
 	if (err) {
 		return err;
 	}
@@ -1483,7 +1472,7 @@
 
 	if (type_mask & MALLOC_PTR_IN_USE_RANGE_TYPE) {
 		// Map in all active magazines. Do this outside the iteration over regions.
-		err = reader(task, (vm_address_t)(szone->tiny_magazines), szone->num_tiny_magazines * sizeof(magazine_t),
+		err = reader(task, (vm_address_t)(szone->tiny_rack.magazines), szone->tiny_rack.num_magazines * sizeof(magazine_t),
 					 (void **)&tiny_mag_base);
 		if (err) {
 			return err;
@@ -1525,7 +1514,7 @@
 						mag_last_free_msize = (uintptr_t)mag_last_free & (TINY_QUANTUM - 1);
 					}
 				} else {
-					for (mag_index = 0; mag_index < szone->num_tiny_magazines; mag_index++) {
+					for (mag_index = 0; mag_index < szone->tiny_rack.num_magazines; mag_index++) {
 						if ((void *)range.address == (tiny_mag_base + mag_index)->mag_last_free_rgn) {
 							mag_last_free = (tiny_mag_base + mag_index)->mag_last_free;
 							if (mag_last_free) {
@@ -1603,7 +1592,7 @@
 }
 
 void *
-tiny_malloc_from_free_list(szone_t *szone, magazine_t *tiny_mag_ptr, mag_index_t mag_index, msize_t msize)
+tiny_malloc_from_free_list(rack_t *rack, magazine_t *tiny_mag_ptr, mag_index_t mag_index, msize_t msize)
 {
 	tiny_free_list_t *ptr;
 	msize_t this_msize;
@@ -1627,7 +1616,7 @@
 	//
 	ptr = the_slot->p;
 	if (ptr) {
-		next = free_list_unchecksum_ptr(szone, &ptr->next);
+		next = free_list_unchecksum_ptr(rack, &ptr->next);
 		if (next) {
 			next->previous = ptr->previous;
 		} else {
@@ -1662,7 +1651,7 @@
 	if (free_list < limit) {
 		ptr = free_list->p;
 		if (ptr) {
-			next = free_list_unchecksum_ptr(szone, &ptr->next);
+			next = free_list_unchecksum_ptr(rack, &ptr->next);
 			free_list->p = next;
 			if (next) {
 				next->previous = ptr->previous;
@@ -1684,7 +1673,7 @@
 	ptr = limit->p;
 	if (ptr) {
 		this_msize = get_tiny_free_size(ptr);
-		next = free_list_unchecksum_ptr(szone, &ptr->next);
+		next = free_list_unchecksum_ptr(rack, &ptr->next);
 		if (this_msize - msize >= NUM_TINY_SLOTS) {
 			// the leftover will go back to the free list, so we optimize by
 			// modifying the free list rather than a pop and push of the head
@@ -1692,7 +1681,7 @@
 			leftover_ptr = (tiny_free_list_t *)((unsigned char *)ptr + TINY_BYTES_FOR_MSIZE(msize));
 			limit->p = leftover_ptr;
 			if (next) {
-				next->previous.u = free_list_checksum_ptr(szone, leftover_ptr);
+				next->previous.u = free_list_checksum_ptr(rack, leftover_ptr);
 			}
 			leftover_ptr->previous = ptr->previous;
 			leftover_ptr->next = ptr->next;
@@ -1761,7 +1750,7 @@
 			malloc_printf("in tiny_malloc_from_free_list(), adding leftover ptr=%p, this_msize=%d\n", ptr, this_msize);
 		}
 #endif
-		tiny_free_list_add_ptr(szone, tiny_mag_ptr, leftover_ptr, leftover_msize);
+		tiny_free_list_add_ptr(rack, tiny_mag_ptr, leftover_ptr, leftover_msize);
 		this_msize = msize;
 	}
 
@@ -1797,27 +1786,27 @@
 }
 
 void *
-tiny_malloc_should_clear(szone_t *szone, msize_t msize, boolean_t cleared_requested)
+tiny_malloc_should_clear(rack_t *rack, msize_t msize, boolean_t cleared_requested)
 {
 	void *ptr;
-	mag_index_t mag_index = mag_get_thread_index(szone);
-	magazine_t *tiny_mag_ptr = &(szone->tiny_magazines[mag_index]);
-
-	MALLOC_TRACE(TRACE_tiny_malloc, (uintptr_t)szone, TINY_BYTES_FOR_MSIZE(msize), (uintptr_t)tiny_mag_ptr, cleared_requested);
+	mag_index_t mag_index = mag_get_thread_index() % rack->num_magazines;
+	magazine_t *tiny_mag_ptr = &(rack->magazines[mag_index]);
+
+	MALLOC_TRACE(TRACE_tiny_malloc, (uintptr_t)rack, TINY_BYTES_FOR_MSIZE(msize), (uintptr_t)tiny_mag_ptr, cleared_requested);
 
 #if DEBUG_MALLOC
 	if (DEPOT_MAGAZINE_INDEX == mag_index) {
-		szone_error(szone, 1, "malloc called for magazine index -1", NULL, NULL);
+		szone_error(rack->debug_flags, 1, "malloc called for magazine index -1", NULL, NULL);
 		return (NULL);
 	}
 
 	if (!msize) {
-		szone_error(szone, 1, "invariant broken (!msize) in allocation (region)", NULL, NULL);
+		szone_error(rack->debug_flags, 1, "invariant broken (!msize) in allocation (region)", NULL, NULL);
 		return (NULL);
 	}
 #endif
 
-	SZONE_MAGAZINE_PTR_LOCK(szone, tiny_mag_ptr);
+	SZONE_MAGAZINE_PTR_LOCK(tiny_mag_ptr);
 
 #if CONFIG_TINY_CACHE
 	ptr = tiny_mag_ptr->mag_last_free;
@@ -1826,7 +1815,7 @@
 		// we have a winner
 		tiny_mag_ptr->mag_last_free = NULL;
 		tiny_mag_ptr->mag_last_free_rgn = NULL;
-		SZONE_MAGAZINE_PTR_UNLOCK(szone, tiny_mag_ptr);
+		SZONE_MAGAZINE_PTR_UNLOCK(tiny_mag_ptr);
 		CHECK(szone, __PRETTY_FUNCTION__);
 		ptr = (void *)((uintptr_t)ptr & ~(TINY_QUANTUM - 1));
 		if (cleared_requested) {
@@ -1842,9 +1831,9 @@
 #endif /* CONFIG_TINY_CACHE */
 
 	while (1) {
-		ptr = tiny_malloc_from_free_list(szone, tiny_mag_ptr, mag_index, msize);
+		ptr = tiny_malloc_from_free_list(rack, tiny_mag_ptr, mag_index, msize);
 		if (ptr) {
-			SZONE_MAGAZINE_PTR_UNLOCK(szone, tiny_mag_ptr);
+			SZONE_MAGAZINE_PTR_UNLOCK(tiny_mag_ptr);
 			CHECK(szone, __PRETTY_FUNCTION__);
 			if (cleared_requested) {
 				memset(ptr, 0, TINY_BYTES_FOR_MSIZE(msize));
@@ -1852,10 +1841,10 @@
 			return ptr;
 		}
 
-		if (tiny_get_region_from_depot(szone, tiny_mag_ptr, mag_index, msize)) {
-			ptr = tiny_malloc_from_free_list(szone, tiny_mag_ptr, mag_index, msize);
+		if (tiny_get_region_from_depot(rack, tiny_mag_ptr, mag_index, msize)) {
+			ptr = tiny_malloc_from_free_list(rack, tiny_mag_ptr, mag_index, msize);
 			if (ptr) {
-				SZONE_MAGAZINE_PTR_UNLOCK(szone, tiny_mag_ptr);
+				SZONE_MAGAZINE_PTR_UNLOCK(tiny_mag_ptr);
 				CHECK(szone, __PRETTY_FUNCTION__);
 				if (cleared_requested) {
 					memset(ptr, 0, TINY_BYTES_FOR_MSIZE(msize));
@@ -1876,54 +1865,95 @@
 			// time to create a new region (do this outside the magazine lock)
 			tiny_mag_ptr->alloc_underway = TRUE;
 			OSMemoryBarrier();
-			SZONE_MAGAZINE_PTR_UNLOCK(szone, tiny_mag_ptr);
-			fresh_region = allocate_pages_securely(szone, TINY_REGION_SIZE, TINY_BLOCKS_ALIGN, VM_MEMORY_MALLOC_TINY);
-			SZONE_MAGAZINE_PTR_LOCK(szone, tiny_mag_ptr);
-
-			MAGMALLOC_ALLOCREGION((void *)szone, (int)mag_index, fresh_region, TINY_REGION_SIZE); // DTrace USDT Probe
+			SZONE_MAGAZINE_PTR_UNLOCK(tiny_mag_ptr);
+			fresh_region = mvm_allocate_pages_securely(TINY_REGION_SIZE, TINY_BLOCKS_ALIGN, VM_MEMORY_MALLOC_TINY, rack->debug_flags);
+			SZONE_MAGAZINE_PTR_LOCK(tiny_mag_ptr);
+
+			// DTrace USDT Probe
+			MAGMALLOC_ALLOCREGION(TINY_SZONE_FROM_RACK(rack), (int)mag_index, fresh_region, TINY_REGION_SIZE);
 
 			if (!fresh_region) { // out of memory!
 				tiny_mag_ptr->alloc_underway = FALSE;
 				OSMemoryBarrier();
-				SZONE_MAGAZINE_PTR_UNLOCK(szone, tiny_mag_ptr);
+				SZONE_MAGAZINE_PTR_UNLOCK(tiny_mag_ptr);
 				return NULL;
 			}
 
-			ptr = tiny_malloc_from_region_no_lock(szone, tiny_mag_ptr, mag_index, msize, fresh_region);
+			ptr = tiny_malloc_from_region_no_lock(rack, tiny_mag_ptr, mag_index, msize, fresh_region);
 
 			// we don't clear because this freshly allocated space is pristine
 			tiny_mag_ptr->alloc_underway = FALSE;
 			OSMemoryBarrier();
-			SZONE_MAGAZINE_PTR_UNLOCK(szone, tiny_mag_ptr);
+			SZONE_MAGAZINE_PTR_UNLOCK(tiny_mag_ptr);
 			CHECK(szone, __PRETTY_FUNCTION__);
 			return ptr;
 		} else {
-			SZONE_MAGAZINE_PTR_UNLOCK(szone, tiny_mag_ptr);
+			SZONE_MAGAZINE_PTR_UNLOCK(tiny_mag_ptr);
 			yield();
-			SZONE_MAGAZINE_PTR_LOCK(szone, tiny_mag_ptr);
+			SZONE_MAGAZINE_PTR_LOCK(tiny_mag_ptr);
 		}
 	}
 	/* NOTREACHED */
 }
 
+size_t
+tiny_size(rack_t *rack, const void *ptr)
+{
+	if (tiny_region_for_ptr_no_lock(rack, ptr)) {
+		if (TINY_INDEX_FOR_PTR(ptr) >= NUM_TINY_BLOCKS) {
+			return 0;
+		}
+
+		boolean_t is_free;
+		msize_t msize = get_tiny_meta_header(ptr, &is_free);
+		if (is_free) {
+			return 0;
+		}
+
+#if CONFIG_TINY_CACHE
+		{
+			mag_index_t mag_index = MAGAZINE_INDEX_FOR_TINY_REGION(TINY_REGION_FOR_PTR(ptr));
+			if (DEPOT_MAGAZINE_INDEX != mag_index) {
+				magazine_t *tiny_mag_ptr = &rack->magazines[mag_index];
+
+				if (msize < TINY_QUANTUM && ptr == (void *)((uintptr_t)(tiny_mag_ptr->mag_last_free) & ~(TINY_QUANTUM - 1))) {
+					return 0;
+				}
+			} else {
+				for (mag_index = 0; mag_index < rack->num_magazines; mag_index++) {
+					magazine_t *tiny_mag_ptr = &(rack->magazines[mag_index]);
+
+					if (msize < TINY_QUANTUM && ptr == (void *)((uintptr_t)(tiny_mag_ptr->mag_last_free) & ~(TINY_QUANTUM - 1))) {
+						return 0;
+					}
+				}
+			}
+		}
+#endif
+		return TINY_BYTES_FOR_MSIZE(msize);
+	}
+
+	return 0;
+}
+
 static MALLOC_NOINLINE void
-free_tiny_botch(szone_t *szone, tiny_free_list_t *ptr)
+free_tiny_botch(rack_t *rack, tiny_free_list_t *ptr)
 {
 	mag_index_t mag_index = MAGAZINE_INDEX_FOR_TINY_REGION(TINY_REGION_FOR_PTR(ptr));
-	magazine_t *tiny_mag_ptr = &(szone->tiny_magazines[mag_index]);
-	SZONE_MAGAZINE_PTR_UNLOCK(szone, tiny_mag_ptr);
-	szone_error(szone, 1, "double free", ptr, NULL);
+	magazine_t *tiny_mag_ptr = &(rack->magazines[mag_index]);
+	SZONE_MAGAZINE_PTR_UNLOCK(tiny_mag_ptr);
+	szone_error(rack->debug_flags, 1, "double free", ptr, NULL);
 }
 
 void
-free_tiny(szone_t *szone, void *ptr, region_t tiny_region, size_t known_size)
+free_tiny(rack_t *rack, void *ptr, region_t tiny_region, size_t known_size)
 {
 	msize_t msize;
 	boolean_t is_free;
 	mag_index_t mag_index = MAGAZINE_INDEX_FOR_TINY_REGION(tiny_region);
-	magazine_t *tiny_mag_ptr = &(szone->tiny_magazines[mag_index]);
-
-	MALLOC_TRACE(TRACE_tiny_free, (uintptr_t)szone, (uintptr_t)ptr, (uintptr_t)tiny_mag_ptr, known_size);
+	magazine_t *tiny_mag_ptr = &(rack->magazines[mag_index]);
+
+	MALLOC_TRACE(TRACE_tiny_free, (uintptr_t)rack, (uintptr_t)ptr, (uintptr_t)tiny_mag_ptr, known_size);
 
 	// ptr is known to be in tiny_region
 	if (known_size) {
@@ -1931,7 +1961,7 @@
 	} else {
 		msize = get_tiny_meta_header(ptr, &is_free);
 		if (is_free) {
-			free_tiny_botch(szone, ptr);
+			free_tiny_botch(rack, ptr);
 			return;
 		}
 	}
@@ -1942,7 +1972,7 @@
 	}
 #endif
 
-	SZONE_MAGAZINE_PTR_LOCK(szone, tiny_mag_ptr);
+	SZONE_MAGAZINE_PTR_LOCK(tiny_mag_ptr);
 
 #if CONFIG_TINY_CACHE
 	// Depot does not participate in CONFIG_TINY_CACHE since it can't be directly malloc()'d
@@ -1953,11 +1983,11 @@
 
 			/* check that we don't already have this pointer in the cache */
 			if (ptr == (void *)((uintptr_t)ptr2 & ~(TINY_QUANTUM - 1))) {
-				free_tiny_botch(szone, ptr);
+				free_tiny_botch(rack, ptr);
 				return;
 			}
 
-			if ((szone->debug_flags & MALLOC_DO_SCRIBBLE) && msize) {
+			if ((rack->debug_flags & MALLOC_DO_SCRIBBLE) && msize) {
 				memset(ptr, SCRABBLE_BYTE, TINY_BYTES_FOR_MSIZE(msize));
 			}
 
@@ -1965,7 +1995,7 @@
 			tiny_mag_ptr->mag_last_free_rgn = tiny_region;
 
 			if (!ptr2) {
-				SZONE_MAGAZINE_PTR_UNLOCK(szone, tiny_mag_ptr);
+				SZONE_MAGAZINE_PTR_UNLOCK(tiny_mag_ptr);
 				CHECK(szone, __PRETTY_FUNCTION__);
 				return;
 			}
@@ -1985,23 +2015,21 @@
 	mag_index_t refreshed_index;
 
 	while (mag_index != (refreshed_index = trailer->mag_index)) { // Note assignment
-
-		SZONE_MAGAZINE_PTR_UNLOCK(szone, tiny_mag_ptr);
-
+		SZONE_MAGAZINE_PTR_UNLOCK(tiny_mag_ptr);
 		mag_index = refreshed_index;
-		tiny_mag_ptr = &(szone->tiny_magazines[mag_index]);
-		SZONE_MAGAZINE_PTR_LOCK(szone, tiny_mag_ptr);
-	}
-
-	if (tiny_free_no_lock(szone, tiny_mag_ptr, mag_index, tiny_region, ptr, msize)) {
-		SZONE_MAGAZINE_PTR_UNLOCK(szone, tiny_mag_ptr);
+		tiny_mag_ptr = &(rack->magazines[mag_index]);
+		SZONE_MAGAZINE_PTR_LOCK(tiny_mag_ptr);
+	}
+
+	if (tiny_free_no_lock(rack, tiny_mag_ptr, mag_index, tiny_region, ptr, msize)) {
+		SZONE_MAGAZINE_PTR_UNLOCK(tiny_mag_ptr);
 	}
 
 	CHECK(szone, __PRETTY_FUNCTION__);
 }
 
 void
-print_tiny_free_list(szone_t *szone)
+print_tiny_free_list(rack_t *rack)
 {
 	tiny_free_list_t *ptr;
 	_SIMPLE_STRING b = _simple_salloc();
@@ -2009,14 +2037,14 @@
 
 	if (b) {
 		_simple_sappend(b, "tiny free sizes:\n");
-		for (mag_index = -1; mag_index < szone->num_tiny_magazines; mag_index++) {
+		for (mag_index = -1; mag_index < rack->num_magazines; mag_index++) {
 			grain_t slot = 0;
 			_simple_sprintf(b, "\tMagazine %d: ", mag_index);
 			while (slot < NUM_TINY_SLOTS) {
-				ptr = szone->tiny_magazines[mag_index].mag_free_list[slot].p;
+				ptr = rack->magazines[mag_index].mag_free_list[slot].p;
 				if (ptr) {
 					_simple_sprintf(b, "%s%y[%d]; ", (slot == NUM_TINY_SLOTS - 1) ? ">=" : "", (slot + 1) * TINY_QUANTUM,
-									free_list_count(szone, (free_list_t){ .p = ptr }));
+									free_list_count(rack, (free_list_t){ .p = ptr }));
 				}
 				slot++;
 			}
@@ -2112,16 +2140,16 @@
 }
 
 boolean_t
-tiny_free_list_check(szone_t *szone, grain_t slot)
+tiny_free_list_check(rack_t *rack, grain_t slot)
 {
 	mag_index_t mag_index;
 
-	for (mag_index = -1; mag_index < szone->num_tiny_magazines; mag_index++) {
-		magazine_t *tiny_mag_ptr = &(szone->tiny_magazines[mag_index]);
-		SZONE_MAGAZINE_PTR_LOCK(szone, tiny_mag_ptr);
+	for (mag_index = -1; mag_index < rack->num_magazines; mag_index++) {
+		magazine_t *tiny_mag_ptr = &(rack->magazines[mag_index]);
+		SZONE_MAGAZINE_PTR_LOCK(tiny_mag_ptr);
 
 		unsigned count = 0;
-		tiny_free_list_t *ptr = szone->tiny_magazines[mag_index].mag_free_list[slot].p;
+		tiny_free_list_t *ptr = rack->magazines[mag_index].mag_free_list[slot].p;
 		boolean_t is_free;
 		tiny_free_list_t *previous = NULL;
 
@@ -2129,30 +2157,30 @@
 			is_free = tiny_meta_header_is_free(ptr);
 			if (!is_free) {
 				malloc_printf("*** in-use ptr in free list slot=%d count=%d ptr=%p\n", slot, count, ptr);
-				SZONE_MAGAZINE_PTR_UNLOCK(szone, tiny_mag_ptr);
+				SZONE_MAGAZINE_PTR_UNLOCK(tiny_mag_ptr);
 				return 0;
 			}
 			if (((uintptr_t)ptr) & (TINY_QUANTUM - 1)) {
 				malloc_printf("*** unaligned ptr in free list slot=%d  count=%d ptr=%p\n", slot, count, ptr);
-				SZONE_MAGAZINE_PTR_UNLOCK(szone, tiny_mag_ptr);
+				SZONE_MAGAZINE_PTR_UNLOCK(tiny_mag_ptr);
 				return 0;
 			}
-			if (!tiny_region_for_ptr_no_lock(szone, ptr)) {
+			if (!tiny_region_for_ptr_no_lock(rack, ptr)) {
 				malloc_printf("*** ptr not in szone slot=%d  count=%d ptr=%p\n", slot, count, ptr);
-				SZONE_MAGAZINE_PTR_UNLOCK(szone, tiny_mag_ptr);
+				SZONE_MAGAZINE_PTR_UNLOCK(tiny_mag_ptr);
 				return 0;
 			}
-			if (free_list_unchecksum_ptr(szone, &ptr->previous) != previous) {
+			if (free_list_unchecksum_ptr(rack, &ptr->previous) != previous) {
 				malloc_printf("*** previous incorrectly set slot=%d  count=%d ptr=%p\n", slot, count, ptr);
-				SZONE_MAGAZINE_PTR_UNLOCK(szone, tiny_mag_ptr);
+				SZONE_MAGAZINE_PTR_UNLOCK(tiny_mag_ptr);
 				return 0;
 			}
 			previous = ptr;
-			ptr = free_list_unchecksum_ptr(szone, &ptr->next);
+			ptr = free_list_unchecksum_ptr(rack, &ptr->next);
 			count++;
 		}
 		
-		SZONE_MAGAZINE_PTR_UNLOCK(szone, tiny_mag_ptr);
+		SZONE_MAGAZINE_PTR_UNLOCK(tiny_mag_ptr);
 	}
 	return 1;
 }