Memory File System
A virtual Kernel File System (virtualkernel file systems) is a file system generated by the kernel but not stored on the hard disk (in memory. For example
1. Proc
The proc file system provides a secure interface for communications between the operating system and applications. Through some files in it, you can obtain the system status information and modify the configuration information of some systems. When we add new functions or device drivers to the kernel, we often need to get information about the system status. Generally, such functions need to be called by systems like IOCTL.
2. devfs
We know that each file in the/dev directory corresponds to a device, and devfs is also mounted to the/dev directory. Before kernel 2.6, devfs was used to provide a file-like method to manage all devices in the/dev directory. However, the devfs file system has some disadvantages. Sometimes the device files mapped by a device may be different. For example, my USB flash drive may correspond to SDA, SDB, and does not have enough primary/secondary device numbers. When there are too many devices, this is obviously a problem.
3. sysfs
To overcome the above problems of devfs, the 2.6 kernel introduced a new file system sysfs, Which is mounted to the/sys directory. The sysfs file system organizes the devices and bus connected to the system into a hierarchical file. The user space program can also use this information to achieve interaction with the kernel. The sysfs file system is an intuitive reflection of the actual device tree on the current system. It establishes this information through the kobject subsystem. When a kobject is created, the corresponding files and directories are created.
4. tmpfs
Tmpfs (temporary filesystem) is a Linux-specific file system. The standard mount point is/dev/SHM. The default size is half of the actual memory, as shown in. Of course, you can also mount tmpfs elsewhere. Tmpfs can use physical memory or swap space.
Tmpfs is somewhat like a virtual disk (ramdisk), but ramdisk is a block device and can be used only after a command such as mkfs is formatted. Tmpfs is an independent file system, not a block device. It can be used immediately as long as it is mounted. The following are the main features of tmpfs:
Ø temporary: Because tmpfs is built in the memory, all data stored in tmpfs will be lost after uninstallation or power failure;
Ø fast read/write capability: memory access speed is much faster than disk I/O operations. Even if swap is used, the performance is still very high;
Ø dynamic contraction: tmpfs uses a small amount of space at the beginning. However, as files are copied and created, the tmpfs file system allocates more memory, and dynamically increase the space of the file system as needed. In addition, when a file in tmpfs is deleted, the tmpfs file system dynamically reduces the file size and releases memory resources.
Tmpfs is an ideal practice for file caching and temporary data. Now suppose you want to save a file in/var/www/www.example.com/cachedirectory for a large-traffic website.
First, create a cache directory:
Mkdir-P/var/www. example. Cache
If necessary, you can change the owner of the directory, for example:
Chownproxy: proxy/var/www/www.example.com/cache
Now we load the directory to the memory device (755 MB in size and the permission is ):
Mount-ttmpfs-O size = 100 m, mode = 0755 tmpfs/var/www/www.example.com/cache
To adjust the memory used by the cache directory to 200 MB, run the following command:
Mount-O remount, size = 200 m/var/www/www.example.com/cache
If you want to automatically cache this directory when the system starts, edit/etc/fstab and add the following content
Tmpfs/var/www/www.example.com/cache tmpfssize = 100 m, mode = 0755 0 0