Memory File System (Linux, FreeBSD)
In Linux, part of the memory can be used as a partition, which is called ramdisk. For frequently accessed files that are not changed, you can place them in the memory through ramdisk to significantly improve the system performance. Of course, your memory is large enough. There are two types of ramdisk, one of which can be formatted and loaded. It is supported in Linux kernel 2.0/2.2. Its disadvantage is that the size is fixed. The other is supported by kernel 2.4, which can be implemented through ramfs or tmpfs. They cannot be formatted, but used flexibly, and their size increases or decreases as needed. Here we will mainly introduce ramfs and tmpfs.
Ramfs, as its name implies, is a memory file system that works on the VFS layer. It cannot be formatted. You can create multiple instances. You can specify the maximum memory size that can be used during creation. If your Linux system has compiled ramfs into the kernel, you can easily use ramfs. Create a directory and load ramfs to the directory.
# Mkdir-P/ram1
# Mount-T ramfs NONE/ram1
By default, ramfs is limited to up to half of the memory size. You can use the maxsize (in Kbyte) option to change the value.
Quote:
# Mkdir-P/ram1
# Mount-T ramfs NONE/ram1-O maxsize = 10000
A ramdisk with a maximum memory usage of 10 MB is created.
Tmpfs is a virtual memory file system, which is different from the traditional ramdisk implemented in the form of Block devices, but also from the ramfs for physical memory. Tmpfs can use physical memory or swap partitions. In the Linux kernel, virtual memory resources are composed of physical memory (RAM) and swap partitions. These resources are allocated and managed by the virtual memory subsystem in the kernel. Tmpfs is used to "deal" with the virtual memory subsystem. It requests pages from the virtual memory subsystem to store files. It is the same as other request pages in Linux, I don't know whether the page allocated to myself is in memory or in SWAp partition. Like ramfs, tmpfs is not fixed in size, but dynamically increases or decreases with the required space. When using tmpfs, you must first select "virtual memory file system support (virtual
Memory filesystem Support) ", and then you can load the tmpfs file system.
# Mkdir-P/mnt/tmpfs
# Mount tmpfs/mnt/tmpfs-T tmpfs
To prevent tmpfs from using too many memory resources and causing system performance degradation or crashes, you can specify the maximum size limit of the tmpfs file system during loading.
# Mount tmpfs/mnt/tmpfs-T tmpfs-O size = 32 m
The tmpfs file system created above sets its maximum size to 32 MB. Whether using ramfs or tmpfs, you must understand that once the system is restarted, the content in them will be lost. So those things can be stored in the memory file system according to the specific situation of the system.
Ramfs will only be created in the physical memory, while tmpfs may be created in the physical memory or in the SWAp partition. For applications that want to use high-speed IO of memory to improve efficiency, it is best to use ramfs. For applications that only want to store temporary cache, it is best to use tmpfs to enable memory utilization in advance. FreeBSD: mount_mfs # Mount MFs
/Sbin/mount_mfs-s 131072/dev/da0s1b/data1/apache2/htdocs/Ram can be used as a partition in Linux, which is called ramdisk. For frequently accessed files that are not changed, you can place them in the memory through ramdisk to significantly improve the system performance. Of course, your memory is large enough. There are two types of ramdisk, one of which can be formatted and loaded. It is supported in Linux kernel 2.0/2.2. Its disadvantage is that the size is fixed. The other is supported by kernel 2.4, which can be implemented through ramfs or tmpfs. They cannot be formatted, but used flexibly, and their size increases or decreases as needed. Here we will mainly introduce ramfs and tmpfs.
Ramfs, as its name implies, is a memory file system that works on the VFS layer. It cannot be formatted. You can create multiple instances. You can specify the maximum memory size that can be used during creation. If your Linux system has compiled ramfs into the kernel, you can easily use ramfs. Create a directory and load ramfs to the directory.
# Mkdir-P/ram1
# Mount-T ramfs NONE/ram1
By default, ramfs is limited to up to half of the memory size. You can use the maxsize (in Kbyte) option to change the value.
Quote:
# Mkdir-P/ram1
# Mount-T ramfs NONE/ram1-O maxsize = 10000
A ramdisk with a maximum memory usage of 10 MB is created.
Tmpfs is a virtual memory file system, which is different from the traditional ramdisk implemented in the form of Block devices, but also from the ramfs for physical memory. Tmpfs can use physical memory or swap partitions. In the Linux kernel, virtual memory resources are composed of physical memory (RAM) and swap partitions. These resources are allocated and managed by the virtual memory subsystem in the kernel. Tmpfs is used to "deal" with the virtual memory subsystem. It requests pages from the virtual memory subsystem to store files. It is the same as other request pages in Linux, I don't know whether the page allocated to myself is in memory or in SWAp partition. Like ramfs, tmpfs is not fixed in size, but dynamically increases or decreases with the required space. When using tmpfs, you must first select "virtual memory file system support (virtual
Memory filesystem Support) ", and then you can load the tmpfs file system.
# Mkdir-P/mnt/tmpfs
# Mount tmpfs/mnt/tmpfs-T tmpfs
To prevent tmpfs from using too many memory resources and causing system performance degradation or crashes, you can specify the maximum size limit of the tmpfs file system during loading.
# Mount tmpfs/mnt/tmpfs-T tmpfs-O size = 32 m
The tmpfs file system created above sets its maximum size to 32 MB. Whether using ramfs or tmpfs, you must understand that once the system is restarted, the content in them will be lost. So those things can be stored in the memory file system according to the specific situation of the system.
Ramfs will only be created in the physical memory, while tmpfs may be created in the physical memory or in the SWAp partition. For applications that want to use high-speed IO of memory to improve efficiency, it is best to use ramfs. For applications that only want to store temporary cache, it is best to use tmpfs to enable memory utilization in advance. FreeBSD: mount_mfs # Mount MFs
/Sbin/mount_mfs-s 131072/dev/da0s1b/data1/apache2/htdocs/Ram