Skip to content

Userspace page cache v2#70509

Merged
nikitamikhaylov merged 34 commits intomasterfrom
npc
Mar 4, 2025
Merged

Userspace page cache v2#70509
nikitamikhaylov merged 34 commits intomasterfrom
npc

Conversation

@al13n321
Copy link
Copy Markdown
Member

@al13n321 al13n321 commented Oct 9, 2024

Changelog category (leave one):

  • New Feature

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):

A new implementation of the Userspace Page Cache, which allows caching data in the in-process memory instead of relying on the OS page cache, which is useful when the data is stored on a remote virtual filesystem without backing with the local filesystem cache.

Un-overengineered it: got rid of the madvise(MADV_FREE) stuff, it was slow. It's just a CacheBase now. Size adjusted periodically by MemoryWorker thread, which runs every 50ms by default. Need to also add size adjustment on memory allocation path, similar to overcommit tracker.

@robot-ch-test-poll1 robot-ch-test-poll1 added the pr-not-for-changelog This PR should not be mentioned in the changelog label Oct 9, 2024
@robot-ch-test-poll3
Copy link
Copy Markdown
Contributor

robot-ch-test-poll3 commented Oct 9, 2024

This is an automated comment for commit af4a9e5 with description of existing statuses. It's updated for the latest CI running

❌ Click here to open a full report in a separate page

Check nameDescriptionStatus
Integration testsThe integration tests report. In parenthesis the package type is given, and in square brackets are the optional part/total tests❌ failure
Stateless testsRuns stateless functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc❌ failure
Successful checks
Check nameDescriptionStatus
AST fuzzerRuns randomly generated queries to catch program errors. The build type is optionally given in parenthesis. If it fails, ask a maintainer for help✅ success
BuildsThere's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success
BuzzHouse (asan)There's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success
BuzzHouse (msan)There's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success
BuzzHouse (tsan)There's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success
BuzzHouse (ubsan)There's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success
ClickBenchRuns ClickBench with instant-attach table✅ success
Compatibility checkChecks that clickhouse binary runs on distributions with old libc versions. If it fails, ask a maintainer for help✅ success
Docker keeper imageThe check to build and optionally push the mentioned image to docker hub✅ success
Docker server imageThe check to build and optionally push the mentioned image to docker hub✅ success
Docs checkBuilds and tests the documentation✅ success
Fast testNormally this is the first check that is ran for a PR. It builds ClickHouse and runs most of stateless functional tests, omitting some. If it fails, further checks are not started until it is fixed. Look at the report to see which tests fail, then reproduce the failure locally as described here✅ success
Flaky testsChecks if new added or modified tests are flaky by running them repeatedly, in parallel, with more randomization. Functional tests are run 100 times with address sanitizer, and additional randomization of thread scheduling. Integration tests are run up to 10 times. If at least once a new test has failed, or was too long, this check will be red. We don't allow flaky tests, read the doc✅ success
Install packagesChecks that the built packages are installable in a clear environment✅ success
Performance ComparisonMeasure changes in query performance. The performance test report is described in detail here. In square brackets are the optional part/total tests✅ success
Stress testRuns stateless functional tests concurrently from several clients to detect concurrency-related errors✅ success
Style checkRuns a set of checks to keep the code style clean. If some of tests failed, see the related log from the report✅ success
Unit testsRuns the unit tests for different release types✅ success
Upgrade checkRuns stress tests on server version from last release and then tries to upgrade it to the version from the PR. It checks if the new server can successfully startup without any errors, crashes or sanitizer asserts✅ success

@kssenii kssenii self-assigned this Oct 9, 2024
@al13n321 al13n321 force-pushed the npc branch 2 times, most recently from 799d248 to bc67d1f Compare October 9, 2024 09:12
@al13n321
Copy link
Copy Markdown
Member Author

I don't have good ideas for how to make autoresizing work. Queries fail with out-of-memory errors because MemoryTracker's "rss" adjustment races with memory deallocation, so sometimes MemoryTracker clears the page cache, then updates "rss" to a high value (from before the clearing), then we allocate a little more emory, MemoryTracker clears the cache again but "rss" is still too high and the query fails.

@al13n321
Copy link
Copy Markdown
Member Author

Also not looking forward to dealing with the MergeTree read path and ReadBuffer spaghetti again...

@antonio2368
Copy link
Copy Markdown
Member

antonio2368 commented Oct 10, 2024

Maybe try something purge_mib.run() so you instantly return the dirty pages to jemalloc?
The problem is we don't have control over what jemalloc will reuse from cache and what it will allocate from OS.
But I see you do purge before autoResize
I would just avoid purging every tick of MemoryWorker. We can even introduce a soft limit so we start purging before we hit the hard limit or use allocated amount along RSS to decide when to do it.

@clickhouse-gh
Copy link
Copy Markdown
Contributor

clickhouse-gh bot commented Dec 10, 2024

Dear @al13n321, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message.

@alexey-milovidov alexey-milovidov mentioned this pull request Dec 31, 2024
76 tasks
@al13n321 al13n321 marked this pull request as ready for review January 18, 2025 00:04
@al13n321
Copy link
Copy Markdown
Member Author

Worked fine in a few manual tests in a toy cgroup with 8 GB memory limit, didn't get oom-killed or fail queries unnecessarily. Seems good to go.

(Also tried setting memory_worker_period_ms to 10s to hit the code path that shrinks cache on memory allocation (as opposed to MemoryWorker thread). The shrinking seems to work, but the server gets oom-killed often, even without userspace page cache. I'm not sure exactly why, but it's easy to imagine either jemalloc dirty memory or kernel memory fluctuating enough to explain it.)

@clickhouse-gh
Copy link
Copy Markdown
Contributor

clickhouse-gh bot commented Feb 14, 2025

Workflow [PR], commit [abc94a5]

@antonio2368 antonio2368 self-assigned this Feb 25, 2025
@nikitamikhaylov
Copy link
Copy Markdown
Member

@nikitamikhaylov
Copy link
Copy Markdown
Member

03367_bfloat16_tuple_final is failing in master.

@nikitamikhaylov nikitamikhaylov added this pull request to the merge queue Mar 4, 2025
Merged via the queue into master with commit 825f023 Mar 4, 2025
121 of 126 checks passed
@nikitamikhaylov nikitamikhaylov deleted the npc branch March 4, 2025 15:23
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Mar 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-not-for-changelog This PR should not be mentioned in the changelog pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants