Repository navigation
Conversation
Since the release binary became position independent (ClickHouse#117449, ClickHouse#119284), the kernel draws its load address at every start in steps of the largest PT_LOAD alignment: 64 KiB on AArch64 (lld default) and 4 KiB on x86-64. The address of the code modulo 2 MiB therefore changed with every start, and on AArch64 CI the per-start slow mode of some performance tests is a function of the build and of that residue (e.g. json_to_string ClickHouse#1: 22 of 22 runs of one build with the base in [0x140000, 0x190000) mod 2 MiB were 1.5x slower, the other 99 were within 5%). Link the `clickhouse` target with `-z max-page-size=0x200000` on Linux x86-64 and AArch64, so every PT_LOAD is 2 MiB aligned and the kernel aligns the random base to 2 MiB: the layout modulo 2 MiB is fixed per build again while the binary stays PIE with a random base (2^19 positions on the CI kernels instead of 2^24 on AArch64 and 2^28 on x86-64). Other executables keep the default. The file grows by about 2.6 MiB of unmapped padding. Add a Compatibility check row that checks the largest PT_LOAD alignment of the packaged binary, since nothing in the build fails when the linker silently uses a smaller one. Decided in ClickHouse#125278 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
A larger PT_LOAD alignment makes the kernel align the random base to that value, which would silently cost more ASLR entropy than intended, so the row now fails on anything other than exactly 2 MiB. The CMake comment now says that the base alignment applies on Linux 5.10 and newer. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review (click to expand)Two rounds, each with one cold review plus one independent model review.
|
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20261015-034800 |
|
Workflow [PR], commit [2efed57] Summary: ✅
AI ReviewSummaryThe PR links Linux x86-64 and AArch64 Missing context / blind spots
Final VerdictStatus: ✅ Approve. No review changes requested; normal CI completion remains pending. |
|
cc @Algunenano, could you review this? It keeps the |
|
@groeneai You keep linking all performance regression/changes to PIE without a real investigation. We had the same issues way before we enabled PIE, and in most of the cases it was related to things like tests using random, using LIMIT (which gives you a non deterministic subset), etc. Please investigate each case separately instead of saying it's PIE without any research. |
|
No, there is nothing more the linker can do: Linux has no ELF flag that requests huge pages (
So |
|
Result for the
With this PR every start of a build lands at the same base residue, so a PR build and its reference keep their speed across restarts, but their code still starts at different positions. Two builds of the same flavour at the same base residue were more than 10% apart in 26 of 967 pairs, about as often as two starts of one build, so for this query the reference also has to be built like the PR build (#124676, or option 4 there). |
|
Result for the
Bases come from the jobs' |
|
@groeneai, let's answer the main question - does it make performance tests more stable? |
|
On AArch64 it does when both servers run the same kind of build, which is the case in master runs. In PR checks it does not by itself. I took 6947 arm Performance Comparison jobs from Sep 26 to Oct 16. The load addresses of both servers come from the jobs'
So when the code of both servers sits at the same position modulo 2 MiB, about a quarter fewer queries differ.
The other ~4 queries per job that differ by more than 10% remain when the placement is equal, so placement does not explain them. On x86-64 I have not found a query whose speed follows the load address, so I don't expect a change there. |
|
@groeneai We keep circling around and it seems to me that the core issue we need to fix is in the PR you linked: #124676 We need to make sure that the binaries created by the PR and the binary it's compared against are equivalent. They need to use the same build flags (include debug and PGO). The question about what link segment we need to use seems secondary to that and I feel that it's not solving the general problem, just reducing it. There is no guarantee that both binaries will keep the same distance between 2 functions, since by definition they will be different. OTOH, it will undoubtfully reduce noise in the case where it's the same binary/code and when the code didn't change significantly. |
|
Marking as draft to compare after #124676 |
|
Agreed, the same-flags reference comes first. I'll rework #124676 as you described there: a separate |
|
@groeneai The perf reference binary changes have been merged. Can you verify if this PR is still necessary please? Also, we 100% do not need a check like |
Not needed, as asked in review. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Yes, it is still needed on AArch64. I measured the 277 AArch64 Performance Comparison jobs of PRs that used the new reference today:
With this PR the code starts at the same position in every job, once the reference is built with it too. On x86-64 I have no measurement showing a gain (40 jobs since the merge, none with matching positions, and at least 99% of the remapped code is on huge pages either way). If you prefer, I can limit the flag to AArch64 and keep the x86-64 ASLR entropy. I dropped |
|
I have serious concerns about the security implications of this PR and the weaking of ASLR. We currently have some address oracles (working on fixing them, see #126748, #126760 and others) and this makes them way more practical to exploit. I plan to work on addressing those issues first and then re-evaluate, as right now the impact of the 2 together seems too high. |
|
Understood, I'll keep it as a draft and not push to it until you re-evaluate. If you'd rather not touch the release binaries at all, the perf tests can get the same effect from the harness alone: |
|
@groeneai Yes, that looks much more preferable and worth doing / testing. We'd need to apply it to both performance_tests.py and compare.sh, and verify that the executable base of the 2 running servers is the same (and fail the run if not to alert and address it in the scripts). |
|
Acknowledged. I'm preparing a separate PR that starts both servers under |
|
The separate PR is #126977: both launchers start the server under |
|
Closing in favor of #126977 for now. Thanks |
Related: #125278
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
The
clickhousebinary on Linux x86-64 and AArch64 is linked with 2 MiB segment alignment. Its load address is still random, but on Linux 5.10 and newer (6.11 for the static musl build) the position of the code relative to 2 MiB boundaries is now the same at every server start, so the speed of some queries no longer depends on the restart: on AArch64 some of them ran about 1.5 times slower after some restarts.Description
Since the release binary became position independent (#117449, #119284), the kernel picks its load address in steps of the largest segment alignment: 64 KiB on AArch64 and 4 KiB on x86-64. So the address of the code modulo 2 MiB changes with every start. On AArch64 CI the slow starts follow it: for build
010807a35d71,json_to_string #1was slow in 22 of 22 runs whose base fell in[0x140000, 0x190000)modulo 2 MiB (median 1.51x) and at most 1.05x in the other 99 (findings, decision).Change: the
clickhousetarget is linked with-z max-page-size=0x200000, so everyPT_LOADis 2 MiB-aligned and the kernel (Linux 5.10+, 6.11+ for static musl) aligns the random base to 2 MiB. The binary staysET_DYNwithDF_1_PIE; other executables keep the default.Cost: the base stays random over the same range, but in 2^19 positions instead of 2^24 (AArch64) and 2^28 (x86-64) on the CI kernels, i.e. 5 and 9 bits less entropy for the executable. Libraries, heap, stacks and mmap are unchanged. The x86-64 file grows by 2.6 MiB of unmapped padding (11 KB after zstd).
Tested on a local x86-64 release build: 20 of 20 starts at a 2 MiB-aligned base with 20 distinct bases (before: 0 of 20);
remap_executablestill puts all 470 MiB of code on huge pages; the stack trace and file offset tests pass. On AArch64 with the same-flags reference of #124676, PR Performance Comparison jobs whose two servers had the start of the code within 64 KiB of the same position modulo 2 MiB had 2.4 queries per job more than 10% apart (20 jobs), the others 5.2 (257 jobs, 2026-10-20); with this PR the position is the same in every job.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/125949]