Loading...
tests/magazine_tiny_test.c libmalloc-374.60.3 libmalloc-792.80.2
--- libmalloc/libmalloc-374.60.3/tests/magazine_tiny_test.c
+++ libmalloc/libmalloc-792.80.2/tests/magazine_tiny_test.c
@@ -14,7 +14,11 @@
 // Stubs
 bool aggressive_madvise_enabled = DEFAULT_AGGRESSIVE_MADVISE_ENABLED;
 
-T_GLOBAL_META(T_META_RUN_CONCURRENTLY(true));
+unsigned malloc_zero_on_free_sample_period = 0;
+malloc_zero_policy_t malloc_zero_policy = MALLOC_ZERO_POLICY_DEFAULT;
+
+T_GLOBAL_META(T_META_RUN_CONCURRENTLY(true), T_META_TAG_VM_PREFERRED,
+		T_META_TAG_NO_ALLOCATOR_OVERRIDE);
 
 static inline void
 tiny_test_rack_setup(rack_t *rack)
@@ -125,3 +129,37 @@
 
 	free_tiny(&rack, ptr, TINY_REGION_FOR_PTR(ptr), 0, false);
 }
+
+T_DECL(tiny_free_deallocate, "check tiny regions deallocate when empty")
+{
+	struct rack_s rack;
+	memset(&rack, 'a', sizeof(rack));
+	rack_init(&rack, RACK_TYPE_TINY, 1, 0);
+	// force recirc to be released when empty
+	recirc_retained_regions = 0;
+
+	magazine_t *mag = &rack.magazines[0];
+	T_ASSERT_EQ(mag->mag_last_region, NULL, "no regions before allocation");
+
+	void *ptr = tiny_malloc_should_clear(&rack, 1, false);
+	T_ASSERT_NE(ptr, NULL, "allocate");
+
+	region_t region = TINY_REGION_FOR_PTR(ptr);
+	mag_index_t mag_index = MAGAZINE_INDEX_FOR_TINY_REGION(region);
+	magazine_t *dest_mag = &(rack.magazines[mag_index]);
+	T_ASSERT_GE(mag_index, -1, "assert ptr not in recirc");
+
+	// Is to pass the recirc discriminant in tiny_free_try_recirc_to_depot
+	// which normally prevents recirc unless 1.5x of a region has been
+	// allocated in the magazine as a whole.
+	dest_mag->num_bytes_in_magazine = (5 * TINY_REGION_SIZE);
+
+	SZONE_MAGAZINE_PTR_LOCK(dest_mag);
+	tiny_free_no_lock(&rack, dest_mag, mag_index, region, ptr, 1, false);
+
+	T_ASSERT_EQ(mag->mag_last_region, NULL, "no regions after last free");
+
+	magazine_t *depot = &rack.magazines[DEPOT_MAGAZINE_INDEX];
+	T_ASSERT_EQ(depot->mag_num_objects, 0, "no objects in depot after last free");
+	T_ASSERT_EQ(depot->num_bytes_in_magazine, 0ul, "no region in depot after last free");
+}