Skip to content

Commit

Permalink
insert full pages at the end of the queue; only override page candida…
Browse files Browse the repository at this point in the history
…te if the page is not too full
  • Loading branch information
daanx committed Dec 20, 2024
1 parent df82338 commit f3d83e5
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 7 deletions.
6 changes: 3 additions & 3 deletions ide/vs2022/mimalloc-test.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -272,14 +272,14 @@
<SubSystem>Console</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\test\main-override-static.c" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="mimalloc.vcxproj">
<Project>{abb5eae7-b3e6-432e-b636-333449892ea6}</Project>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\test\main-override-static.c" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
Expand Down
2 changes: 1 addition & 1 deletion include/mimalloc/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ static inline bool mi_page_immediate_available(const mi_page_t* page) {
}

// is more than 7/8th of a page in use?
static inline bool mi_page_mostly_used(const mi_page_t* page) {
static inline bool mi_page_is_mostly_used(const mi_page_t* page) {
if (page==NULL) return true;
uint16_t frac = page->reserved / 8U;
return (page->reserved - page->used <= frac);
Expand Down
2 changes: 1 addition & 1 deletion src/page-queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ static void mi_page_queue_enqueue_from(mi_page_queue_t* to, mi_page_queue_t* fro

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

// Only called from `mi_heap_absorb`.
Expand Down
3 changes: 2 additions & 1 deletion src/page.c
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,8 @@ static mi_page_t* mi_page_queue_find_free_ex(mi_heap_t* heap, mi_page_queue_t* p
page_candidate = page;
candidate_count = 0;
}
else if (!mi_page_mostly_used(page) && page->used >= page_candidate->used) {
// prefer to reuse fuller pages (in the hope the less used page gets freed)
else if (page->used >= page_candidate->used && !mi_page_is_mostly_used(page) && !mi_page_is_expandable(page)) {
page_candidate = page;
}
// if we find a non-expandable candidate, or searched for N pages, return with the best candidate
Expand Down
2 changes: 1 addition & 1 deletion test/test-stress.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ int main(int argc, char** argv) {
mi_collect(true);
#endif
#endif
//mi_stats_print(NULL);
mi_stats_print(NULL);
//bench_end_program();
return 0;
}
Expand Down

0 comments on commit f3d83e5

Please sign in to comment.