Loading...
--- libmalloc/libmalloc-374.60.3/src/magazine_malloc.c
+++ libmalloc/libmalloc-166.251.2/src/magazine_malloc.c
@@ -26,12 +26,10 @@
/*
* Multithread enhancements for "tiny" allocations introduced February 2008.
* These are in the spirit of "Hoard". See:
- * Emery D. Berger, Kathryn S. McKinley, Robert D. Blumofe, and Paul R. Wilson. 2000.
- * Hoard: a scalable memory allocator for multithreaded applications.
- * In Proceedings of the ninth international conference on Architectural support for
- * programming languages and operating systems (ASPLOS IX).
- * ACM, New York, NY, USA, 117-128.
- * DOI: https://doi.org/10.1145/378993.379232
+ * Berger, E.D.; McKinley, K.S.; Blumofe, R.D.; Wilson, P.R. (2000).
+ * "Hoard: a scalable memory allocator for multithreaded applications".
+ * ACM SIGPLAN Notices 35 (11): 117-128. Berger2000.
+ * <http://portal.acm.org/citation.cfm?id=356989.357000>
* Retrieved on 2008-02-22.
*/
@@ -52,29 +50,6 @@
// Control the DRAM limit at which medium kicks in.
uint64_t magazine_medium_active_threshold = MEDIUM_ACTIVATION_THRESHOLD;
-
-#if CONFIG_MEDIUM_ALLOCATOR
-
-// Control the dram divisor that's used to scale up medium's madvise window.
-// We'll double the window for each multiple of magazine_medium_madvise_dram_scale_divisor
-// bytes of dram on the system rounded down to the neareast power of 2.
-// This is done by setting magazine_medium_madvise_window_scale_factor.
-uint64_t magazine_medium_madvise_dram_scale_divisor = MEDIUM_MADVISE_DRAM_SCALE_DIVISOR;
-
-// Controls how much to scale up medium's madvise window.
-uint64_t magazine_medium_madvise_window_scale_factor = 1;
-#endif // CONFIG_MEDIUM_ALLOCATOR
-
-// Control the DRAM limit at which the expanded large cache kicks in.
-uint64_t magazine_large_expanded_cache_threshold = LARGE_CACHE_EXPANDED_THRESHOLD;
-
-#if CONFIG_AGGRESSIVE_MADVISE
-bool aggressive_madvise_enabled = DEFAULT_AGGRESSIVE_MADVISE_ENABLED;
-#endif // CONFIG_AGGRESSIVE_MADVISE
-
-#if CONFIG_LARGE_CACHE
-bool large_cache_enabled = DEFAULT_LARGE_CACHE_ENABLED;
-#endif // CONFIG_LARGE_CACHE
// <rdar://problem/47353961> Maximum number of magzines that the medium
// allocator will use. This addresses a 32-bit load-offset range issue found
@@ -116,7 +91,7 @@
malloc_zone_error(szone->debug_flags, true, "Pointer %p to metadata being freed\n", ptr);
return;
}
- free_tiny(&szone->tiny_rack, ptr, tiny_region, 0, false);
+ free_tiny(&szone->tiny_rack, ptr, tiny_region, 0);
return;
}
@@ -188,7 +163,7 @@
malloc_zone_error(szone->debug_flags, true, "Pointer %p to metadata being freed\n", ptr);
return;
}
- free_tiny(&szone->tiny_rack, ptr, TINY_REGION_FOR_PTR(ptr), size, false);
+ free_tiny(&szone->tiny_rack, ptr, TINY_REGION_FOR_PTR(ptr), size);
return;
}
@@ -257,7 +232,7 @@
ptr = medium_malloc_should_clear(&szone->medium_rack, msize, cleared_requested);
#endif
} else {
- size_t num_kernel_pages = round_large_page_quanta(size) >> large_vm_page_quanta_shift;
+ size_t num_kernel_pages = round_page_quanta(size) >> vm_page_quanta_shift;
if (num_kernel_pages == 0) { /* Overflowed */
ptr = 0;
} else {
@@ -305,7 +280,7 @@
} else {
size_t num_kernel_pages;
- num_kernel_pages = round_large_page_quanta(size) >> large_vm_page_quanta_shift;
+ num_kernel_pages = round_page_quanta(size) >> vm_page_quanta_shift;
ptr = large_malloc(szone, num_kernel_pages, 0, 0);
}
@@ -613,8 +588,8 @@
return szone_malloc(szone, size);
}
// ensure block allocated by large does not have a small-possible size
- size_t num_kernel_pages = round_large_page_quanta(MAX(LARGE_THRESHOLD(szone) + 1,
- size)) >> large_vm_page_quanta_shift;
+ size_t num_kernel_pages = round_page_quanta(MAX(LARGE_THRESHOLD(szone) + 1,
+ size)) >> vm_page_quanta_shift;
if (num_kernel_pages == 0) { /* Overflowed */
return NULL;
} else {
@@ -674,36 +649,34 @@
vm_range_t range_to_deallocate;
#if CONFIG_LARGE_CACHE
- if (large_cache_enabled) {
- SZONE_LOCK(szone);
-
- /* disable any memory pressure responder */
- szone->flotsam_enabled = FALSE;
-
- // stack allocated copy of the death-row cache
- int idx = szone->large_entry_cache_oldest, idx_max = szone->large_entry_cache_newest;
- large_entry_t local_entry_cache[LARGE_ENTRY_CACHE_SIZE_HIGH];
-
- memcpy((void *)local_entry_cache, (void *)szone->large_entry_cache, sizeof(local_entry_cache));
-
- szone->large_entry_cache_oldest = szone->large_entry_cache_newest = 0;
- szone->large_entry_cache[0].address = 0x0;
- szone->large_entry_cache[0].size = 0;
- szone->large_entry_cache_bytes = 0;
- szone->large_entry_cache_reserve_bytes = 0;
-
- SZONE_UNLOCK(szone);
-
- // deallocate the death-row cache outside the zone lock
- while (idx != idx_max) {
- mvm_deallocate_pages((void *)local_entry_cache[idx].address, local_entry_cache[idx].size, szone->debug_flags);
- if (++idx == szone->large_cache_depth) {
- idx = 0;
- }
- }
- if (0 != local_entry_cache[idx].address && 0 != local_entry_cache[idx].size) {
- mvm_deallocate_pages((void *)local_entry_cache[idx].address, local_entry_cache[idx].size, szone->debug_flags);
- }
+ SZONE_LOCK(szone);
+
+ /* disable any memory pressure responder */
+ szone->flotsam_enabled = FALSE;
+
+ // stack allocated copy of the death-row cache
+ int idx = szone->large_entry_cache_oldest, idx_max = szone->large_entry_cache_newest;
+ large_entry_t local_entry_cache[LARGE_ENTRY_CACHE_SIZE];
+
+ memcpy((void *)local_entry_cache, (void *)szone->large_entry_cache, sizeof(local_entry_cache));
+
+ szone->large_entry_cache_oldest = szone->large_entry_cache_newest = 0;
+ szone->large_entry_cache[0].address = 0x0;
+ szone->large_entry_cache[0].size = 0;
+ szone->large_entry_cache_bytes = 0;
+ szone->large_entry_cache_reserve_bytes = 0;
+
+ SZONE_UNLOCK(szone);
+
+ // deallocate the death-row cache outside the zone lock
+ while (idx != idx_max) {
+ mvm_deallocate_pages((void *)local_entry_cache[idx].address, local_entry_cache[idx].size, 0);
+ if (++idx == LARGE_ENTRY_CACHE_SIZE) {
+ idx = 0;
+ }
+ }
+ if (0 != local_entry_cache[idx].address && 0 != local_entry_cache[idx].size) {
+ mvm_deallocate_pages((void *)local_entry_cache[idx].address, local_entry_cache[idx].size, 0);
}
#endif
@@ -718,7 +691,7 @@
}
large_entries_free_no_lock(szone, szone->large_entries, szone->num_large_entries, &range_to_deallocate);
if (range_to_deallocate.size) {
- mvm_deallocate_pages((void *)range_to_deallocate.address, (size_t)range_to_deallocate.size, szone->debug_flags);
+ mvm_deallocate_pages((void *)range_to_deallocate.address, (size_t)range_to_deallocate.size, 0);
}
/* destroy allocator regions */
@@ -774,7 +747,7 @@
// Check for integer overflow on the size, since unlike the two cases above,
// there is no upper bound on allocation size at this point.
- if (size > round_large_page_quanta(size)) {
+ if (size > round_page_quanta(size)) {
return (size_t)(-1LL);
}
@@ -786,7 +759,7 @@
malloc_report(ASL_LEVEL_INFO, "szone_good_size() invariant broken %y\n", size);
}
#endif
- return round_large_page_quanta(size);
+ return round_page_quanta(size);
}
boolean_t
@@ -922,10 +895,6 @@
return szone_check_all(szone, "");
}
-// To support the quarantine zone, we need to be able to perform zone enumeration across different
-// architecture slices on macOS, because ReportCrash is always running as a native (arm64e) process,
-// but we also need to be able to inspect x86_64 targets that are running under Rosetta. So the data
-// layout and zone logic needs to match between x86_64 and arm64(e).
static kern_return_t
szone_ptr_in_use_enumerator(task_t task,
void *context,
@@ -938,7 +907,7 @@
kern_return_t err;
if (!reader) {
- reader = _malloc_default_reader;
+ reader = _szone_default_reader;
}
err = reader(task, zone_address, sizeof(szone_t), (void **)&szone);
@@ -970,9 +939,9 @@
return err;
}
-static boolean_t
-scalable_zone_info_task(task_t task, memory_reader_t reader,
- malloc_zone_t *zone, unsigned *info_to_fill, unsigned count)
+// Following method is deprecated: use scalable_zone_statistics instead
+void
+scalable_zone_info(malloc_zone_t *zone, unsigned *info_to_fill, unsigned count)
{
szone_t *szone = (void *)zone;
unsigned info[13];
@@ -984,30 +953,21 @@
size_t u = 0;
mag_index_t mag_index;
- magazine_t *mapped_magazines;
- if (reader(task, (vm_address_t)szone->tiny_rack.magazines,
- sizeof(magazine_t), (void **)&mapped_magazines)) {
- return false;
- }
for (mag_index = -1; mag_index < szone->tiny_rack.num_magazines; mag_index++) {
- s += mapped_magazines[mag_index].mag_bytes_free_at_start;
- s += mapped_magazines[mag_index].mag_bytes_free_at_end;
- t += mapped_magazines[mag_index].mag_num_objects;
- u += mapped_magazines[mag_index].mag_num_bytes_in_objects;
+ s += szone->tiny_rack.magazines[mag_index].mag_bytes_free_at_start;
+ s += szone->tiny_rack.magazines[mag_index].mag_bytes_free_at_end;
+ t += szone->tiny_rack.magazines[mag_index].mag_num_objects;
+ u += szone->tiny_rack.magazines[mag_index].mag_num_bytes_in_objects;
}
info[4] = (unsigned)t;
info[5] = (unsigned)u;
- if (reader(task, (vm_address_t)szone->small_rack.magazines,
- sizeof(magazine_t), (void **)&mapped_magazines)) {
- return false;
- }
for (t = 0, u = 0, mag_index = -1; mag_index < szone->small_rack.num_magazines; mag_index++) {
- s += mapped_magazines[mag_index].mag_bytes_free_at_start;
- s += mapped_magazines[mag_index].mag_bytes_free_at_end;
- t += mapped_magazines[mag_index].mag_num_objects;
- u += mapped_magazines[mag_index].mag_num_bytes_in_objects;
+ s += szone->small_rack.magazines[mag_index].mag_bytes_free_at_start;
+ s += szone->small_rack.magazines[mag_index].mag_bytes_free_at_end;
+ t += szone->small_rack.magazines[mag_index].mag_num_objects;
+ u += szone->small_rack.magazines[mag_index].mag_num_bytes_in_objects;
}
info[6] = (unsigned)t;
@@ -1029,266 +989,86 @@
info[2] = info[3] - (unsigned)s;
memcpy(info_to_fill, info, sizeof(unsigned) * count);
-
- return true;
-}
-
-// Following method is deprecated: use scalable_zone_statistics instead
-// Required for backward compatibility.
-void
-scalable_zone_info(malloc_zone_t *zone, unsigned *info_to_fill, unsigned count) {
- scalable_zone_info_task(mach_task_self(), _malloc_default_reader, zone,
- info_to_fill, count);
}
// FIXME: consistent picture requires locking!
static MALLOC_NOINLINE void
-szone_print(task_t task, unsigned level, vm_address_t zone_address,
- memory_reader_t reader, print_task_printer_t printer)
+szone_print(szone_t *szone, boolean_t verbose)
{
unsigned info[13];
size_t index;
region_t region;
- region_t mapped_region;
-
- szone_t *szone = (szone_t *)zone_address;
- szone_t *mapped_szone;
- if (reader(task, zone_address, sizeof(szone_t), (void **)&mapped_szone)) {
- printer("Failed to read szone structure\n");
- return;
- }
-
- if (!scalable_zone_info_task(task, reader, (void *)mapped_szone, info, 13)) {
- printer("Failed to get scalable zone info\n");
- return;
- }
- printer("Scalable zone %p: inUse=%u(%u) touched=%u allocated=%u flags=0x%x\n",
- zone_address, info[0], info[1], info[2], info[3], info[12]);
- printer("\ttiny=%u(%u) small=%u(%u) large=%u(%u)\n", info[4],
- info[5], info[6], info[7], info[8], info[9]);
+
+ scalable_zone_info((void *)szone, info, 13);
+ malloc_report(MALLOC_REPORT_NOLOG | MALLOC_REPORT_NOPREFIX,
+ "Scalable zone %p: inUse=%u(%y) touched=%y allocated=%y flags=%d\n", szone, info[0], info[1], info[2], info[3],
+ info[12]);
+ malloc_report(MALLOC_REPORT_NOLOG | MALLOC_REPORT_NOPREFIX, "\ttiny=%u(%y) small=%u(%y) large=%u(%y) huge=%u(%y)\n", info[4],
+ info[5], info[6], info[7], info[8], info[9], info[10], info[11]);
// tiny
- printer("%lu tiny regions:\n", mapped_szone->tiny_rack.num_regions);
- if (mapped_szone->tiny_rack.num_regions_dealloc) {
- printer("[%lu tiny regions have been vm_deallocate'd]\n",
- mapped_szone->tiny_rack.num_regions_dealloc);
- }
-
- region_hash_generation_t *mapped_region_generation;
- region_t *mapped_hashed_regions;
- magazine_t *mapped_magazines;
- if (reader(task, (vm_address_t)mapped_szone->tiny_rack.region_generation,
- sizeof(region_hash_generation_t), (void **)&mapped_region_generation)) {
- printer("Failed to map tiny rack region_generation\n");
- return;
- }
- if (reader(task, (vm_address_t)mapped_region_generation->hashed_regions,
- sizeof(region_t), (void **)&mapped_hashed_regions)) {
- printer("Failed to map tiny rack hashed_regions\n");
- return;
- }
- if (reader(task, (vm_address_t)mapped_szone->tiny_rack.magazines,
- mapped_szone->tiny_rack.num_magazines * sizeof(magazine_t),
- (void **)&mapped_magazines)) {
- printer("Failed to map tiny rack magazines\n");
- return;
- }
-
- int recirc_regions = 0;
- for (index = 0; index < mapped_region_generation->num_regions_allocated; ++index) {
- region = mapped_hashed_regions[index];
+ malloc_report(MALLOC_REPORT_NOLOG | MALLOC_REPORT_NOPREFIX, "%lu tiny regions:\n", szone->tiny_rack.num_regions);
+ if (szone->tiny_rack.num_regions_dealloc) {
+ malloc_report(MALLOC_REPORT_NOLOG | MALLOC_REPORT_NOPREFIX, "[%lu tiny regions have been vm_deallocate'd]\n",
+ szone->tiny_rack.num_regions_dealloc);
+ }
+ for (index = 0; index < szone->tiny_rack.region_generation->num_regions_allocated; ++index) {
+ region = szone->tiny_rack.region_generation->hashed_regions[index];
if (HASHRING_OPEN_ENTRY != region && HASHRING_REGION_DEALLOCATED != region) {
- if (reader(task, (vm_address_t)region, sizeof(struct tiny_region),
- (void **)&mapped_region)) {
- printer("Failed to map region %p\n", region);
- return;
- }
- mag_index_t mag_index = MAGAZINE_INDEX_FOR_TINY_REGION(mapped_region);
- if (mag_index == DEPOT_MAGAZINE_INDEX) {
- recirc_regions++;
- }
- print_tiny_region(task, reader, printer, level, region,
- (region == mapped_magazines[mag_index].mag_last_region)
- ? mapped_magazines[mag_index].mag_bytes_free_at_start
- : 0,
- (region == mapped_magazines[mag_index].mag_last_region)
- ? mapped_magazines[mag_index].mag_bytes_free_at_end
- : 0);
- }
- }
-
-#if CONFIG_RECIRC_DEPOT
- magazine_t *mapped_recirc_depot = &mapped_magazines[DEPOT_MAGAZINE_INDEX];
- if (mapped_recirc_depot->mag_num_bytes_in_objects) {
- printer("Tiny recirc depot: total bytes: %llu, in-use bytes: %llu, "
- "allocations: %llu, regions: %d (min # retained regions: %d)\n",
- mapped_recirc_depot->num_bytes_in_magazine,
- mapped_recirc_depot->mag_num_bytes_in_objects,
- mapped_recirc_depot->mag_num_objects, recirc_regions,
- recirc_retained_regions);
- } else {
- printer("Tiny recirc depot is empty\n");
- }
-#else // CONFIG_RECIRC_DEPOT
- printer("Tiny recirc depot not configured\n");
-#endif // CONFIG_RECIRC_DEPOT
-
- if (level > 0) {
- print_tiny_free_list(task, reader, printer, &szone->tiny_rack);
- }
-
+ mag_index_t mag_index = MAGAZINE_INDEX_FOR_TINY_REGION(region);
+ print_tiny_region(verbose, region, (region == szone->tiny_rack.magazines[mag_index].mag_last_region)
+ ? szone->tiny_rack.magazines[mag_index].mag_bytes_free_at_start
+ : 0,
+ (region == szone->tiny_rack.magazines[mag_index].mag_last_region)
+ ? szone->tiny_rack.magazines[mag_index].mag_bytes_free_at_end
+ : 0);
+ }
+ }
+ if (verbose) {
+ print_tiny_free_list(&szone->tiny_rack);
+ }
// small
- printer("%lu small regions:\n", mapped_szone->small_rack.num_regions);
- if (mapped_szone->small_rack.num_regions_dealloc) {
- printer("[%lu small regions have been vm_deallocate'd]\n",
- mapped_szone->small_rack.num_regions_dealloc);
- }
- if (reader(task, (vm_address_t)mapped_szone->small_rack.region_generation,
- sizeof(region_hash_generation_t), (void **)&mapped_region_generation)) {
- printer("Failed to map small rack region_generation\n");
- return;
- }
- if (reader(task, (vm_address_t)mapped_region_generation->hashed_regions,
- sizeof(region_t), (void **)&mapped_hashed_regions)) {
- printer("Failed to map small rack hashed_regions\n");
- return;
- }
- if (reader(task, (vm_address_t)mapped_szone->small_rack.magazines,
- mapped_szone->small_rack.num_magazines * sizeof(magazine_t),
- (void **)&mapped_magazines)) {
- printer("Failed to map small rack magazines\n");
- return;
- }
-
- recirc_regions = 0;
- for (index = 0; index < mapped_region_generation->num_regions_allocated; ++index) {
- region = mapped_hashed_regions[index];
+ malloc_report(MALLOC_REPORT_NOLOG | MALLOC_REPORT_NOPREFIX, "%lu small regions:\n", szone->small_rack.num_regions);
+ if (szone->small_rack.num_regions_dealloc) {
+ malloc_report(MALLOC_REPORT_NOLOG | MALLOC_REPORT_NOPREFIX, "[%lu small regions have been vm_deallocate'd]\n",
+ szone->small_rack.num_regions_dealloc);
+ }
+ for (index = 0; index < szone->small_rack.region_generation->num_regions_allocated; ++index) {
+ region = szone->small_rack.region_generation->hashed_regions[index];
if (HASHRING_OPEN_ENTRY != region && HASHRING_REGION_DEALLOCATED != region) {
- if (reader(task, (vm_address_t)region, sizeof(struct small_region),
- (void **)&mapped_region)) {
- printer("Failed to map region %p\n", region);
- return;
- }
- mag_index_t mag_index = MAGAZINE_INDEX_FOR_SMALL_REGION(mapped_region);
- if (mag_index == DEPOT_MAGAZINE_INDEX) {
- recirc_regions++;
- }
- print_small_region(task, reader, printer, mapped_szone, level, region,
- (region == mapped_magazines[mag_index].mag_last_region)
- ? mapped_magazines[mag_index].mag_bytes_free_at_start
- : 0,
- (region == mapped_magazines[mag_index].mag_last_region)
- ? mapped_magazines[mag_index].mag_bytes_free_at_end
- : 0);
- }
- }
-
-#if CONFIG_RECIRC_DEPOT
- mapped_recirc_depot = &mapped_magazines[DEPOT_MAGAZINE_INDEX];
- if (mapped_recirc_depot->mag_num_bytes_in_objects) {
- printer("Small recirc depot: total bytes: %llu, in-use bytes: %llu, "
- "allocations: %llu, regions: %d (min # retained regions: %d)\n",
- mapped_recirc_depot->num_bytes_in_magazine,
- mapped_recirc_depot->mag_num_bytes_in_objects,
- mapped_recirc_depot->mag_num_objects, recirc_regions,
- recirc_retained_regions);
- } else {
- printer("Small recirc depot is empty\n");
- }
-#else // CONFIG_RECIRC_DEPOT
- printer("Small recirc depot not configured\n");
-#endif // CONFIG_RECIRC_DEPOT
-
- if (level > 0) {
- print_small_free_list(task, reader, printer, &szone->small_rack);
- }
-
+ mag_index_t mag_index = MAGAZINE_INDEX_FOR_SMALL_REGION(region);
+ print_small_region(szone, verbose, region, (region == szone->small_rack.magazines[mag_index].mag_last_region)
+ ? szone->small_rack.magazines[mag_index].mag_bytes_free_at_start
+ : 0,
+ (region == szone->small_rack.magazines[mag_index].mag_last_region)
+ ? szone->small_rack.magazines[mag_index].mag_bytes_free_at_end
+ : 0);
+ }
+ }
#if CONFIG_MEDIUM_ALLOCATOR
if (szone->is_medium_engaged) {
// medium
- printer("%lu medium regions:\n", mapped_szone->medium_rack.num_regions);
- if (mapped_szone->medium_rack.num_regions_dealloc) {
- printer("[%lu medium regions have been vm_deallocate'd]\n",
- mapped_szone->medium_rack.num_regions_dealloc);
- }
- if (reader(task, (vm_address_t)mapped_szone->medium_rack.region_generation,
- sizeof(region_hash_generation_t), (void **)&mapped_region_generation)) {
- printer("Failed to map medium rack region_generation\n");
- return;
- }
- if (reader(task, (vm_address_t)mapped_region_generation->hashed_regions,
- sizeof(region_t), (void **)&mapped_hashed_regions)) {
- printer("Failed to map medium rack hashed_regions\n");
- return;
- }
- if (reader(task, (vm_address_t)mapped_szone->medium_rack.magazines,
- mapped_szone->medium_rack.num_magazines * sizeof(magazine_t),
- (void **)&mapped_magazines)) {
- printer("Failed to map medium rack magazines\n");
- return;
- }
-
- recirc_regions = 0;
- for (index = 0; index < mapped_region_generation->num_regions_allocated; ++index) {
- region = mapped_hashed_regions[index];
+ malloc_report(MALLOC_REPORT_NOLOG | MALLOC_REPORT_NOPREFIX, "%lu medium regions:\n", szone->medium_rack.num_regions);
+ if (szone->medium_rack.num_regions_dealloc) {
+ malloc_report(MALLOC_REPORT_NOLOG | MALLOC_REPORT_NOPREFIX, "[%lu medium regions have been vm_deallocate'd]\n",
+ szone->medium_rack.num_regions_dealloc);
+ }
+ for (index = 0; index < szone->medium_rack.region_generation->num_regions_allocated; ++index) {
+ region = szone->medium_rack.region_generation->hashed_regions[index];
if (HASHRING_OPEN_ENTRY != region && HASHRING_REGION_DEALLOCATED != region) {
- if (reader(task, (vm_address_t)region, sizeof(struct medium_region),
- (void **)&mapped_region)) {
- printer("Failed to map region %p\n", region);
- return;
- }
- mag_index_t mag_index = MAGAZINE_INDEX_FOR_MEDIUM_REGION(mapped_region);
- if (mag_index == DEPOT_MAGAZINE_INDEX) {
- recirc_regions++;
- }
- print_medium_region(task, reader, printer, mapped_szone, level,
- region,
- (region == mapped_magazines[mag_index].mag_last_region)
- ? mapped_magazines[mag_index].mag_bytes_free_at_start
- : 0,
- (region == mapped_magazines[mag_index].mag_last_region)
- ? mapped_magazines[mag_index].mag_bytes_free_at_end
- : 0);
+ mag_index_t mag_index = MAGAZINE_INDEX_FOR_MEDIUM_REGION(region);
+ print_medium_region(szone, verbose, region, (region == szone->medium_rack.magazines[mag_index].mag_last_region)
+ ? szone->medium_rack.magazines[mag_index].mag_bytes_free_at_start
+ : 0,
+ (region == szone->medium_rack.magazines[mag_index].mag_last_region)
+ ? szone->medium_rack.magazines[mag_index].mag_bytes_free_at_end
+ : 0);
}
}
-
-#if CONFIG_RECIRC_DEPOT
- mapped_recirc_depot = &mapped_magazines[DEPOT_MAGAZINE_INDEX];
- if (mapped_recirc_depot->mag_num_bytes_in_objects) {
- printer("Medium recirc depot: total bytes: %llu, in-use bytes: %llu, "
- "allocations: %llu, regions: %d (min # retained regions: %d)\n",
- mapped_recirc_depot->num_bytes_in_magazine,
- mapped_recirc_depot->mag_num_bytes_in_objects,
- mapped_recirc_depot->mag_num_objects, recirc_regions,
- recirc_retained_regions);
- } else {
- printer("Medium recirc depot is empty\n");
- }
-#else // CONFIG_RECIRC_DEPOT
- printer("Medium recirc depot not configured\n");
-#endif // CONFIG_RECIRC_DEPOT
-
- if (level > 0) {
- print_medium_free_list(task, reader, printer, &szone->medium_rack);
- }
- }
-#endif // CONFIG_MEDIUM_ALLOCATOR
-
- // Large
- large_debug_print(task, level, zone_address, reader, printer);
-}
-
-static void
-szone_print_self(szone_t *szone, boolean_t verbose)
-{
- szone_print(mach_task_self(), verbose ? MALLOC_VERBOSE_PRINT_LEVEL : 0,
- (vm_address_t)szone, _malloc_default_reader, malloc_report_simple);
-}
-
-static void
-szone_print_task(task_t task, unsigned level, vm_address_t zone_address,
- memory_reader_t reader, print_task_printer_t printer)
-{
- szone_print(task, level, zone_address, reader, printer);
+ }
+#endif // CONFIG_MEDIUM_ALLOCATOR
+ if (verbose) {
+ print_small_free_list(&szone->small_rack);
+ }
}
static void
@@ -1452,12 +1232,12 @@
#endif // CONFIG_MADVISE_PRESSURE_RELIEF
#if CONFIG_LARGE_CACHE
- if (large_cache_enabled && szone->flotsam_enabled) {
+ if (szone->flotsam_enabled) {
SZONE_LOCK(szone);
// stack allocated copy of the death-row cache
int idx = szone->large_entry_cache_oldest, idx_max = szone->large_entry_cache_newest;
- large_entry_t local_entry_cache[LARGE_ENTRY_CACHE_SIZE_HIGH];
+ large_entry_t local_entry_cache[LARGE_ENTRY_CACHE_SIZE];
memcpy((void *)local_entry_cache, (void *)szone->large_entry_cache, sizeof(local_entry_cache));
@@ -1474,14 +1254,14 @@
// deallocate the death-row cache outside the zone lock
size_t total = 0;
while (idx != idx_max) {
- mvm_deallocate_pages((void *)local_entry_cache[idx].address, local_entry_cache[idx].size, szone->debug_flags);
+ mvm_deallocate_pages((void *)local_entry_cache[idx].address, local_entry_cache[idx].size, 0);
total += local_entry_cache[idx].size;
- if (++idx == szone->large_cache_depth) {
+ if (++idx == LARGE_ENTRY_CACHE_SIZE) {
idx = 0;
}
}
if (0 != local_entry_cache[idx].address && 0 != local_entry_cache[idx].size) {
- mvm_deallocate_pages((void *)local_entry_cache[idx].address, local_entry_cache[idx].size, szone->debug_flags);
+ mvm_deallocate_pages((void *)local_entry_cache[idx].address, local_entry_cache[idx].size, 0);
total += local_entry_cache[idx].size;
}
}
@@ -1576,43 +1356,28 @@
return 0;
}
-static kern_return_t
-szone_statistics_task(task_t task, vm_address_t zone_address,
- memory_reader_t reader, malloc_statistics_t *stats)
-{
- reader = !reader && task == mach_task_self() ? _malloc_default_reader : reader;
-
- szone_t *szone;
- kern_return_t err;
-
- err = reader(task, zone_address, sizeof(szone_t), (void**)&szone);
- if (err) return err;
-
+static void
+szone_statistics(szone_t *szone, malloc_statistics_t *stats)
+{
size_t large;
+
size_t s = 0;
unsigned t = 0;
size_t u = 0;
mag_index_t mag_index;
- magazine_t *mags;
- err = reader(task, (vm_address_t)szone->tiny_rack.magazines, sizeof(magazine_t) * szone->tiny_rack.num_magazines, (void**)&mags);
- if (err) return err;
-
for (mag_index = -1; mag_index < szone->tiny_rack.num_magazines; mag_index++) {
- s += mags[mag_index].mag_bytes_free_at_start;
- s += mags[mag_index].mag_bytes_free_at_end;
- t += mags[mag_index].mag_num_objects;
- u += mags[mag_index].mag_num_bytes_in_objects;
- }
-
- err = reader(task, (vm_address_t)szone->small_rack.magazines, sizeof(magazine_t) * szone->small_rack.num_magazines, (void**)&mags);
- if (err) return err;
+ s += szone->tiny_rack.magazines[mag_index].mag_bytes_free_at_start;
+ s += szone->tiny_rack.magazines[mag_index].mag_bytes_free_at_end;
+ t += szone->tiny_rack.magazines[mag_index].mag_num_objects;
+ u += szone->tiny_rack.magazines[mag_index].mag_num_bytes_in_objects;
+ }
for (mag_index = -1; mag_index < szone->small_rack.num_magazines; mag_index++) {
- s += mags[mag_index].mag_bytes_free_at_start;
- s += mags[mag_index].mag_bytes_free_at_end;
- t += mags[mag_index].mag_num_objects;
- u += mags[mag_index].mag_num_bytes_in_objects;
+ s += szone->small_rack.magazines[mag_index].mag_bytes_free_at_start;
+ s += szone->small_rack.magazines[mag_index].mag_bytes_free_at_end;
+ t += szone->small_rack.magazines[mag_index].mag_num_objects;
+ u += szone->small_rack.magazines[mag_index].mag_num_bytes_in_objects;
}
#if CONFIG_MEDIUM_ALLOCATOR
@@ -1626,9 +1391,9 @@
}
#endif // CONFIG_MEDIUM_ALLOCATOR
- large = szone->num_bytes_in_large_objects;
-
- stats->blocks_in_use = t + szone->num_large_objects_in_use;
+ large = szone->num_bytes_in_large_objects + 0; // DEPRECATED szone->num_bytes_in_huge_objects;
+
+ stats->blocks_in_use = t + szone->num_large_objects_in_use + 0; // DEPRECATED szone->num_huge_entries;
stats->size_in_use = u + large;
stats->max_size_in_use = stats->size_allocated =
(szone->tiny_rack.num_regions - szone->tiny_rack.num_regions_dealloc) * TINY_REGION_SIZE +
@@ -1642,23 +1407,13 @@
#endif
// Now we account for the untouched areas
stats->max_size_in_use -= s;
-
- return KERN_SUCCESS;
-}
-
-static void
-szone_statistics(szone_t *szone, malloc_statistics_t *stats)
-{
- szone_statistics_task(mach_task_self(), (vm_address_t)szone, NULL, stats);
}
const struct malloc_introspection_t szone_introspect = {
- (void *)szone_ptr_in_use_enumerator, (void *)szone_good_size, (void *)szone_check, (void *)szone_print_self, szone_log,
+ (void *)szone_ptr_in_use_enumerator, (void *)szone_good_size, (void *)szone_check, (void *)szone_print, szone_log,
(void *)szone_force_lock, (void *)szone_force_unlock, (void *)szone_statistics, (void *)szone_locked, NULL, NULL, NULL,
NULL, /* Zone enumeration version 7 and forward. */
- (void *)szone_reinit_lock, // reinit_lock version 9 and forward
- (void *)szone_print_task, // print task, version 11 and forward
- (void *)szone_statistics_task // stats for task, version 12 and forward
+ (void *)szone_reinit_lock, // reinit_lock version 9 and foward
}; // marked as const to spare the DATA section
szone_t *
@@ -1673,7 +1428,7 @@
#endif
/* get memory for the zone. */
- szone = mvm_allocate_pages(SZONE_PAGED_SIZE, 0, DISABLE_ASLR, VM_MEMORY_MALLOC);
+ szone = mvm_allocate_pages(SZONE_PAGED_SIZE, 0, 0, VM_MEMORY_MALLOC);
if (!szone) {
return NULL;
}
@@ -1723,31 +1478,22 @@
#endif // CONFIG_MEDIUM_ALLOCATOR
#if CONFIG_LARGE_CACHE
- if (large_cache_enabled) {
- // madvise(..., MADV_REUSABLE) death-row arrivals above this threshold [~0.1%]
- szone->large_entry_cache_reserve_limit = (size_t)(memsize >> 10);
- if (memsize >= magazine_large_expanded_cache_threshold) {
- szone->large_cache_depth = LARGE_ENTRY_CACHE_SIZE_HIGH;
- szone->large_cache_entry_limit = LARGE_ENTRY_SIZE_ENTRY_LIMIT_HIGH;
- } else {
- szone->large_cache_depth = LARGE_ENTRY_CACHE_SIZE_LOW;
- szone->large_cache_entry_limit = LARGE_ENTRY_SIZE_ENTRY_LIMIT_LOW;
- }
-
- /* <rdar://problem/6610904> Reset protection when returning a previous large allocation? */
- int32_t libSystemVersion = NSVersionOfLinkTimeLibrary("System");
- if ((-1 != libSystemVersion) && ((libSystemVersion >> 16) < 112) /* CFSystemVersionSnowLeopard */) {
- szone->large_legacy_reset_mprotect = TRUE;
- } else {
- szone->large_legacy_reset_mprotect = FALSE;
- }
+ // madvise(..., MADV_REUSABLE) death-row arrivals above this threshold [~0.1%]
+ szone->large_entry_cache_reserve_limit = (size_t)(memsize >> 10);
+
+ /* <rdar://problem/6610904> Reset protection when returning a previous large allocation? */
+ int32_t libSystemVersion = NSVersionOfLinkTimeLibrary("System");
+ if ((-1 != libSystemVersion) && ((libSystemVersion >> 16) < 112) /* CFSystemVersionSnowLeopard */) {
+ szone->large_legacy_reset_mprotect = TRUE;
+ } else {
+ szone->large_legacy_reset_mprotect = FALSE;
}
#endif
// Initialize the security token.
szone->cookie = (uintptr_t)malloc_entropy[0];
- szone->basic_zone.version = 12;
+ szone->basic_zone.version = 10;
szone->basic_zone.size = (void *)szone_size;
szone->basic_zone.malloc = (void *)szone_malloc;
szone->basic_zone.calloc = (void *)szone_calloc;