MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / mi_segment_free

Function mi_segment_free

3rd/mimalloc-2.0.9/src/segment.c:948–975  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

946
947
948static void mi_segment_free(mi_segment_t* segment, bool force, mi_segments_tld_t* tld) {
949 MI_UNUSED(force);
950 mi_assert_internal(segment != NULL);
951 mi_assert_internal(segment->next == NULL);
952 mi_assert_internal(segment->used == 0);
953
954 // Remove the free pages
955 mi_slice_t* slice = &segment->slices[0];
956 const mi_slice_t* end = mi_segment_slices_end(segment);
957 size_t page_count = 0;
958 while (slice < end) {
959 mi_assert_internal(slice->slice_count > 0);
960 mi_assert_internal(slice->slice_offset == 0);
961 mi_assert_internal(mi_slice_index(slice)==0 || slice->xblock_size == 0); // no more used pages ..
962 if (slice->xblock_size == 0 && segment->kind != MI_SEGMENT_HUGE) {
963 mi_segment_span_remove_from_queue(slice, tld);
964 }
965 page_count++;
966 slice = slice + slice->slice_count;
967 }
968 mi_assert_internal(page_count == 2); // first page is allocated by the segment itself
969
970 // stats
971 _mi_stat_decrease(&tld->stats->page_committed, mi_segment_info_size(segment));
972
973 // return it to the OS
974 mi_segment_os_free(segment, tld);
975}
976
977
978/* -----------------------------------------------------------

Callers 2

_mi_segment_page_freeFunction · 0.85
mi_segment_reclaimFunction · 0.85

Calls 6

mi_segment_slices_endFunction · 0.85
mi_slice_indexFunction · 0.85
_mi_stat_decreaseFunction · 0.85
mi_segment_info_sizeFunction · 0.85
mi_segment_os_freeFunction · 0.85

Tested by

no test coverage detected