tmpfs

package
v0.0.0-...-3f1f8f2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 23, 2026 License: Apache-2.0, BSD-3-Clause, MIT Imports: 39 Imported by: 19

Documentation

Overview

Package tmpfs provides an in-memory filesystem whose contents are application-mutable, consistent with Linux's tmpfs.

Lock order:

filesystem.mu
	inode.mu
	  regularFileFD.offMu
	    *** "memmap.Mappable/MappingIdentity locks" below this point
	    regularFile.mapsMu
	      *** "memmap.Mappable locks taken by Translate" below this point
	      regularFile.dataMu
	        fs.pagesUsedMu
	    filesystem.ancestryMu
	  directory.iterMu

Index

Constants

View Source
const Name = "tmpfs"

Name is the default filesystem name.

Variables

This section is empty.

Functions

func AddSeals

func AddSeals(fd *vfs.FileDescription, val uint32) error

AddSeals adds new file seals to a memfd inode.

func FSCheckpointWrite

func FSCheckpointWrite(ctx context.Context, vfsfs *vfs.Filesystem, dst io.Writer) error

FSCheckpointWrite serializes the given tmpfs filesystem to dst. The contents of its regular files are not written to dst; instead, callers must separately save and restore the contents of the filesystem's MemoryFile. If vfsfs is not a tmpfs filesystem, FSCheckpointWrite returns an error.

Preconditions: The Kernel must be paused and quiesced.

func GetSeals

func GetSeals(fd *vfs.FileDescription) (uint32, error)

GetSeals returns the current set of seals on a memfd inode.

func MemoryFileOf

func MemoryFileOf(vfsfs *vfs.Filesystem) *pgalloc.MemoryFile

MemoryFileOf returns the pgalloc.MemoryFile used by the given tmpfs filesystem. If vfsfs is not a tmpfs filesystem, MemoryFileOf returns nil.

func NewMemfd

func NewMemfd(ctx context.Context, creds *auth.Credentials, mount *vfs.Mount, allowSeals bool, name string) (*vfs.FileDescription, error)

NewMemfd creates a new regular file and file description as for memfd_create.

Preconditions: mount must be a tmpfs mount.

func NewZeroFile

func NewZeroFile(ctx context.Context, creds *auth.Credentials, mount *vfs.Mount, size uint64) (*vfs.FileDescription, error)

NewZeroFile creates a new regular file and file description as for mmap(MAP_SHARED | MAP_ANONYMOUS). The file has the given size and is initially (implicitly) filled with zeroes.

Preconditions: mount must be a tmpfs mount.

func SetTotalHostMem

func SetTotalHostMem(hostMem uint64)

SetTotalHostMem tells the tmpfs implementation how much physical RAM is available, which is used to calculate size limits for tmpfs mounts. For tmpfs mounts that do not specify a size= mount option, the default is 50% of the available memory. Userspace can also specify a percentage in terms of this value.

Types

type FilesystemOpts

type FilesystemOpts struct {
	// RootFileType is the FileType of the filesystem root. Valid values
	// are: S_IFDIR, S_IFREG, and S_IFLNK. Defaults to S_IFDIR.
	RootFileType uint16

	// RootSymlinkTarget is the target of the root symlink. Only valid if
	// RootFileType == S_IFLNK.
	RootSymlinkTarget string

	// FilesystemType allows setting a different FilesystemType for this
	// tmpfs filesystem. This allows tmpfs to "impersonate" other
	// filesystems, like ramdiskfs and cgroupfs.
	FilesystemType vfs.FilesystemType

	// Usage is the memory accounting category under which pages backing files in
	// the filesystem are accounted.
	Usage *usage.MemoryKind

	// MaxFilenameLen is the maximum filename length allowed by the tmpfs.
	MaxFilenameLen int

	// MemoryFile is the memory file that will be used to store file data. If
	// this is nil, then MemoryFileFromContext() is used.
	MemoryFile *pgalloc.MemoryFile

	// DisableDefaultSizeLimit disables setting a default size limit. In Linux,
	// SB_KERNMOUNT has this effect on tmpfs mounts; see mm/shmem.c:shmem_fill_super().
	DisableDefaultSizeLimit bool

	// AllowXattrPrefix is a set of xattr namespace prefixes that this
	// tmpfs mount will allow.
	AllowXattrPrefix []string

	// SourceTar is the source tar file to be untarred into the tmpfs.
	// Ownership is transferred to GetFilesystem, whether or not it returns an
	// error. If SourceTarFSCheckpoint is true, SourceTar was produced by a
	// call to FSCheckpoint, and the caller is responsible for restoring
	// MemoryFile's contents; otherwise, SourceTar was produced by a call to
	// TarWrite.
	SourceTar             io.ReadCloser
	SourceTarFSCheckpoint bool
}

FilesystemOpts is used to pass configuration data to tmpfs.

+stateify savable

type FilesystemType

type FilesystemType struct{}

FilesystemType implements vfs.FilesystemType.

+stateify savable

func (FilesystemType) GetFilesystem

func (fstype FilesystemType) GetFilesystem(ctx context.Context, vfsObj *vfs.VirtualFilesystem, creds *auth.Credentials, _ string, opts vfs.GetFilesystemOptions) (*vfs.Filesystem, *vfs.Dentry, error)

GetFilesystem implements vfs.FilesystemType.GetFilesystem.

func (FilesystemType) Name

func (FilesystemType) Name() string

Name implements vfs.FilesystemType.Name.

func (FilesystemType) Release

func (FilesystemType) Release(ctx context.Context)

Release implements vfs.FilesystemType.Release.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL