Skip to content

Add CacheAllocatorConfig::usePosixShmDirectory() - #520

Open
medjed02 wants to merge 1 commit into
meta:mainfrom
medjed02:posix-shm-directory
Open

medjed02 wants to merge 1 commit into
meta:mainfrom
medjed02:posix-shm-directory

Conversation

@medjed02

Copy link
Copy Markdown

Summary:

usePosixShmDirectory(dir) creates the POSIX shm segments as files in dir instead of /dev/shm. The use case is a persistent cache on a tmpfs volume: the volume survives a container restart, the container's /dev/shm doesn't.

Only normal-page segments are affected; huge-page segments keep using their hugetlbfs mount. Most of the diff passes the directory down to the places that open or remove segments, including ReadOnlySharedCacheView. Cross-host persistence (PersistenceManager) rejects the option, the same way it rejects huge pages.

To keep the change small, the directory is not saved in the shm metadata. If it changes between runs, SharedMemAttach throws as when there is no saved cache, and segment files in the old directory are left for the user to delete. The persistence guide has a short paragraph on the option.

Test Plan:

  • CacheAllocatorConfigTest.PosixShmDirectory: argument checks and serialize().
  • CacheAllocatorConfigTest.PosixShmDirectoryWarmRoll: write an item, shut down, attach read-only and read-write from the directory and read the item back, then cleanupStrayShmSegments() empties the directory.
  • Full ctest passes.

POSIX shm segments always live in /dev/shm, which is lost when it is
replaced, e.g. on container recreation. usePosixShmDirectory(dir) keeps
normal-page segments as files in a user-provided directory (a tmpfs
volume that outlives the container) instead. Huge-page segments keep
using hugePageMountDir, and PosixShmSegment now uses its directory
argument for normal pages too; ShmManager passes one only for huge pages
or with this option.

To keep the change small, the directory is not saved with the cache:
SharedMemAttach with a different directory throws, and the files in the
previous custom directory are left for the user to delete.
Cross-host persistence rejects the option, as it does huge pages.
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 11, 2026
@meta-codesync

meta-codesync Bot commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

@AlnisM has imported this pull request. If you are a Meta employee, you can view this in D131231119.

This branch has not been deployed

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

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant