RSS | technovelty home | page of ian | ianw@ieee.org
You may have noticed a range of things mounted on a tmpfs file system.
$ mount | grep tmpfs tmpfs on /lib/init/rw type tmpfs (rw,nosuid,mode=0755) udev on /dev type tmpfs (rw,mode=0755) tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
tmpfs is actually more pervasive than it might appear. It was created to build a filesystem interface ontop of shared pages of RAM. This is useful because there are a number of ways to access shared RAM; notably SysV IPC Shared Memory (shmget, shmat, etc) and mmap of anonymous memory (MAP_ANONYMOUS).
In order to have a consistent infrastructure implementing all of this the kernel abstracts RAM as a filesystem and your mapping as a file. To this end the tmpfs filesystem was created to present this abstraction. It deals with issues such as caching, security and the ability to swap pages in a consistent manner (i.e. using the same infrastructure every other file system does).
Overall, tmpfs is implemented in mm/shmem.c. In the initialisation function the file system is mounted internally by the kernel with vfs_kern_mount so it is always around. It gets fairly complicated because it has to keep track of swapped out pages and the general complexity that come with implementing a full filesystem.
As described above, there are several distinct ways to get access to this file system.
static int mmap_zero(struct file * file, struct vm_area_struct * vma)
{
int err;
if (vma->vm_flags & VM_SHARED)
return shmem_zero_setup(vma);
tmpfs: more than meets the eye!
Update: hopefully a little clearer, thanks to Helge Bahmann for comments.
posted at: Thu, 08 Nov 2007 17:11 | in /linux | permalink | add comment (1 others)

This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.