Filesystems/tmpfs
From Linux Drivers
Contents |
Overview
Ramfs is a RAM-based filesystem. There is no backing store.
The block size of the filesystem is PAGE_CACHE_SIZE which is same as PAGE_SIZE. Thus each file occupies at least one page of memory.
mounting options
It supports following options. For details, look at shmem_parse_options()
- size=N[KkMmGg] or size=N%: Specifies maximum size of the filesystem. By default, tmpfs filesystem uses up to half of physical memory. max_blocks parameter is calculated out of specified size or percentage. Since size of each block is PAGE_CACHE_SIZE, so max_blocks = size of requested memory / PAGE_CACHE_SIZE.
- nr_blocks=N: Specifies maximum number of blocks in the tmpfs filesystem. Like size option, this sets max_blocks parameter.
- nr_inodes=N: Specifies maximum number of inodes in the filesystem. max_inodes parameter is set to the specified value.
- mode=Octal: Specifies mode parameter. The filesystem is mounted using specified mode.
- uid=N: Sets uid parameter. The mounted filesystem will be owned by specified user.
- gid=N: Sets gid parameter. The mounted filesystem will be owned by specified group.
- mpol=policy: Sets mpol parameter to specified memory policy.
mounting filesystem
Following command mounts a tmpfs filesystem on /tmp.
mount -t tmpfs tmpfs /tmp
To limit the size of tmpfs to 64 MByte,
mount -t tmpfs tmpfs /tmp -o size=64M
To resize the mounted tmpfs to 128 MByte,
mount -t tmpfs tmpfs /tmp -o size=128M,remount
To mount the filesystem on start-up, edit /etc/fstab
none /tmp tmpfs size=64M 0 0
Implementation
ramfs is implemented by files under mm/shmem.c.
Registration of ramfs filesystem
When ramfs module is loaded, it registers ramfs filesystem. inode.c defines an initialization function for the module.
int __init init_tmpfs(void) { ...... error = register_filesystem(&tmpfs_fs_type); ...... }
tmpfs_fs_type is defined as follows.
static struct file_system_type tmpfs_fs_type = { .owner = THIS_MODULE, .name = "tmpfs", .mount = shmem_mount, .kill_sb = kill_litter_super, };
Mounting tmpfs
int shmem_fill_super(struct super_block *sb, void *data, int silent) { ......
Reference
- Kernel documents: [[1]]