Skip to content

gh-113141: Tune MI_SEGMENT_SLICE_SHIFT to 14 for using 16 Kib pages - #160360

Open
corona10 wants to merge 3 commits into
python:mainfrom
corona10:MI_SEGMENT_SLICE_SHIFT-expor
Open

corona10 wants to merge 3 commits into
python:mainfrom
corona10:MI_SEGMENT_SLICE_SHIFT-expor

Conversation

@corona10

@corona10 corona10 commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

@DinoV

DinoV commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

@corona10

Copy link
Copy Markdown
Member Author

Based on an analysis of python -c "import re", with help from a script
written with Claude and run under gdb.

The effect of reducing the page size differs by object size.

Scope AS-IS pages AS-IS resident AS-IS live AS-IS util TO-BE pages TO-BE resident TO-BE live TO-BE util
All heaps 149 5480 KiB 4106 KiB 75 % 309 4964 KiB 4102 KiB 83 %
MEM 46 1668 KiB 1146 KiB 69 % 77 1420 KiB 1142 KiB 80 %
OBJECT 45 1604 KiB 1083 KiB 68 % 88 1344 KiB 1083 KiB 81 %
GC 47 2108 KiB 1841 KiB 87 % 133 2088 KiB 1841 KiB 88 %
GC_PRE 11 100 KiB 35 KiB 35 % 11 112 KiB 35 KiB 32 %
<=256 B 68 2540 KiB 2228 KiB 88 % 174 2556 KiB 2228 KiB 87 %
256 B-2 KiB 47 1636 KiB 1346 KiB 82 % 109 1608 KiB 1346 KiB 84 %
2-64 KiB 30 1088 KiB 315 KiB 29 % 22 584 KiB 311 KiB 53 %
>64 KiB 4 216 KiB 216 KiB 100 % 4 216 KiB 216 KiB 100 %

@corona10

Copy link
Copy Markdown
Member Author

cc @nascheme

@corona10
corona10 requested review from DinoV and nascheme October 22, 2026 23:10
@corona10
corona10 requested a review from mpage October 23, 2026 05:12
@corona10

Copy link
Copy Markdown
Member Author

@DinoV @nascheme @mpage
According to the benchmark results, this change reduces memory usage by 3% compared to the baseline, with no performance regression. Although there is no comparison with the default build, the results do confirm a reduction in memory usage.

@corona10
corona10 marked this pull request as ready for review October 23, 2026 05:13
@corona10

Copy link
Copy Markdown
Member Author

cc @daanx

// Do not use guarded allocations. The free-threaded GC does not support their block layout.
# define MI_GUARDED 0
// Use 16 KiB pages instead of the default 64 KiB in 64-bit platforms.
// TODO: 32-bit platforms may need tuning too.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may need to tune a 32-bit system, but I prefer to pass at this time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants