Repository navigation
feat: configure shared memory for singleuser pods - #246
Keerthirajan58 wants to merge 11 commits into
Conversation
pmeier
left a comment
There was a problem hiding this comment.
Thanks @Keerthirajan58 for the PR. I've added some high level comments that we need to address before going any further.
| # avoids the container runtime's 64 MiB default, which can make Ray fall back | ||
| # to disk and can crash multiprocessing PyTorch DataLoader workers. | ||
| sharedMemory: | ||
| enabled: true |
There was a problem hiding this comment.
When would someone disable this?
There was a problem hiding this comment.
An operator might already define a /dev/shm mount through their profile's
volume overrides. Turning this off lets them keep that mount without the chart
replacing it. I've added a test for that case and explained it in the docs.
Without a custom mount, disabling it leaves the runtime's default in place.
|
@pmeier, I've pushed the changes discussed above and brought the branch up to date I also tested it in kind. The notebook wrote 128 MiB successfully, while the same |
Sprig's quote renders nil as nothing, so `sizeLimit: null` left `"shared-memory-size-limit": ,` in 00-chart-derived.py and the hub failed with a SyntaxError, even with shared memory disabled. Default it to "" like the neighbouring shutdown-no-activity-timeout key. When enabled, the spawner now stops with its own "must be a non-empty string" error; when disabled, the hub loads normally.
An invalid per-profile shm_size_limit raised inside _filter_profiles, which runs on every profile-list render. One bad value broke the spawn page and spawns for every user who could see that profile, and the translation and its warnings repeated on each render. Translate profiles once when _profiles is built, next to _resolve_image_variants, and follow that function's rule: a bad value logs a warning naming the profile and falls back to the chart-wide size. Also drop a test for singleuser.extraVolumes, a key 01-spawner.py never reads, and stop a test comment from claiming when overrides are reapplied.
The shared-memory constants, helpers and settings sat between the Storage comment and the storage code it explains. Move them into a "Shared memory" section after the base volume lists, next to the append that uses them. Build the dshm volume and mount in one place so the base append and the profile overrides share the same definition. No behavior change.
List sharedMemory after networkPolicy in values.yaml so the block's network-access header stays next to the entries it describes, and replace the long values-reference paragraph with a link to the Shared memory section of server-profiles.md, which already covers it.
An empty, null or non-string singleuser.sharedMemory.sizeLimit raised ValueError when 01-spawner.py loaded, which stopped the hub. Other bad deployer values in this file only warn: the code-server idle timeout, _resolve_image_variants, and a profile's shm_size_limit. Do the same for the chart-wide size: log a warning that names singleuser.sharedMemory.sizeLimit and use the chart default of 8Gi. One helper now checks both the chart-wide size and a profile's shm_size_limit, so the two paths follow the same rule. A null sizeLimit is still ignored when shared memory is disabled.
Assert that a disabled chart still warns when a profile sets shm_size_limit, and run the invalid profile size test with a chart-wide size other than 8Gi so it shows the profile falls back to that size rather than the chart default. Also name shm_size_limit and _translate_profile_shared_memory in the comment that lists the chart-only profile keys.
The chart-wide size is only validated when shared memory is enabled. Assert that a disabled chart with sizeLimit null logs no sizeLimit warning, so moving the validation outside that check fails a test.
|
@pmeier, I merged the latest main to resolve the conflict with #226. Both PRs added entries to While doing that I found a bug in my own change. #226 guards its new value against I also moved the shared-memory helpers into their own section, so the storage code reads the same as on main, and removed the leftover The September workflow runs expired before they were approved, so the runs for this push need approval. If you'd rather always mount |
The small
/dev/shmdescribed in #54 can cause PyTorch DataLoader workers tocrash and Ray to fall back to disk. This adds a memory-backed mount for singleuser
pods, with an 8 GiB cap that operators can change through
singleuser.sharedMemory.Profiles can set their own limit with
shm_size_limit. If either size is emptyor not a string, the hub logs a warning and falls back instead of failing to
start: a profile uses the chart-wide size, and the chart-wide size uses 8 GiB.
I've kept the existing home and config volumes unchanged and added the
shared-memory entries to those lists. The
enabledswitch lets operators keepthe runtime default or use a mount they already define through profile overrides.
Profiles never get a second shared-memory volume or mount.
shm_size_limitchanges the size of the chart's
dshmvolume, and if a profile mounts somethingelse at
/dev/shm, the chart's mount replaces it unlessenabledis false.Testing
In September I ran the shared-memory test in kind using the chart's notebook
image at the time (
sha-740eafb). It successfully wrote a 128 MiB shared-memorysegment. A separate pod using the same image without the new mount had the usual
64 MiB
/dev/shmand failed the same write with SIGBUS.That run caught a mistake in my original test: I expected the filesystem to be
exactly 8 GiB, but Kubernetes capped it at the smaller node's memory capacity.
The test now checks the configured cap separately from the filesystem capacity
and still requires the full 128 MiB write.
All 242 unit tests pass on Python 3.10, including checks that render the Helm
values and generate pods through KubeSpawner. Ruff, Helm lint, the nine docs
tests, the docs build, and internal links also pass.
For the local kind run, I disabled unrelated NFS shared storage because its test
image is AMD64-only and this machine is ARM64. I ran only the shared-memory e2e
test locally; the full suite still needs to run in CI.
Closes #54.