Skip to content

Commit f3d83e5

Browse files
committed
insert full pages at the end of the queue; only override page candidate if the page is not too full
1 parent df82338 commit f3d83e5

File tree

5 files changed

+8
-7
lines changed

5 files changed

+8
-7
lines changed

ide/vs2022/mimalloc-test.vcxproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,14 +272,14 @@
272272
<SubSystem>Console</SubSystem>
273273
</Link>
274274
</ItemDefinitionGroup>
275+
<ItemGroup>
276+
<ClCompile Include="..\..\test\main-override-static.c" />
277+
</ItemGroup>
275278
<ItemGroup>
276279
<ProjectReference Include="mimalloc.vcxproj">
277280
<Project>{abb5eae7-b3e6-432e-b636-333449892ea6}</Project>
278281
</ProjectReference>
279282
</ItemGroup>
280-
<ItemGroup>
281-
<ClCompile Include="..\..\test\main-override-static.c" />
282-
</ItemGroup>
283283
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
284284
<ImportGroup Label="ExtensionTargets">
285285
</ImportGroup>

include/mimalloc/internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ static inline bool mi_page_immediate_available(const mi_page_t* page) {
571571
}
572572

573573
// is more than 7/8th of a page in use?
574-
static inline bool mi_page_mostly_used(const mi_page_t* page) {
574+
static inline bool mi_page_is_mostly_used(const mi_page_t* page) {
575575
if (page==NULL) return true;
576576
uint16_t frac = page->reserved / 8U;
577577
return (page->reserved - page->used <= frac);

src/page-queue.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ static void mi_page_queue_enqueue_from(mi_page_queue_t* to, mi_page_queue_t* fro
343343

344344
static void mi_page_queue_enqueue_from_full(mi_page_queue_t* to, mi_page_queue_t* from, mi_page_t* page) {
345345
// note: we could insert at the front to increase reuse, but it slows down certain benchmarks (like `alloc-test`)
346-
mi_page_queue_enqueue_from_ex(to, from, false /* enqueue at the end of the `to` queue? */, page);
346+
mi_page_queue_enqueue_from_ex(to, from, true /* enqueue at the end of the `to` queue? */, page);
347347
}
348348

349349
// Only called from `mi_heap_absorb`.

src/page.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,8 @@ static mi_page_t* mi_page_queue_find_free_ex(mi_heap_t* heap, mi_page_queue_t* p
783783
page_candidate = page;
784784
candidate_count = 0;
785785
}
786-
else if (!mi_page_mostly_used(page) && page->used >= page_candidate->used) {
786+
// prefer to reuse fuller pages (in the hope the less used page gets freed)
787+
else if (page->used >= page_candidate->used && !mi_page_is_mostly_used(page) && !mi_page_is_expandable(page)) {
787788
page_candidate = page;
788789
}
789790
// if we find a non-expandable candidate, or searched for N pages, return with the best candidate

test/test-stress.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ int main(int argc, char** argv) {
319319
mi_collect(true);
320320
#endif
321321
#endif
322-
//mi_stats_print(NULL);
322+
mi_stats_print(NULL);
323323
//bench_end_program();
324324
return 0;
325325
}

0 commit comments

Comments
 (0)