Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use file system tmpfs on Linux

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to use file system tmpfs on Linux". In daily operation, I believe many people have doubts about how to use file system tmpfs on Linux. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "how to use file system tmpfs on Linux". Next, please follow the editor to study!

Tmpfs introduction

Tmpfs is a virtual memory file system, not a block device. It is a memory-based file system, which does not need to be initialized with mkfs or other initialization.

Its biggest feature is that its storage space is in VM (virtual memory), and VM is managed by the vm subsystem in the linux kernel.

The size of VM under linux consists of RM (Real Memory) and swap. The size of RM is the size of physical memory, while the size of Swap is determined by yourself.

Swap is a virtual memory space through the hard disk, so its read and write speed is much slower than RM (Real Memory). When a process applies for a certain amount of memory, such as the VM subsystem of the kernel finds that there is not enough RM, it will exchange some uncommonly used data from RM to Swap. If you need to reuse these data, then swap them from Swap to RM. If you have enough physical memory, you can leave the Swap partition undivided.

VM consists of two parts of RM+Swap, so the maximum storage space of tmpfs can reach (The size of RM+ The size of Swap). But for tmpfs itself, it doesn't know whether the space it uses is RM or Swap, all managed by the kernel's vm subsystem.

The default size of tmpfs is half that of RM. If your physical memory is 1024m, then the default size of tmpfs is 512m.

In general, it is configured less than the physical memory size.

The size of the tmpfs configuration does not really take up this piece of memory, if there are no files under / dev/shm/, it actually occupies 0 bytes of memory; if it has a maximum of 1G and contains 100m files, then the remaining 900m can still be used by other applications, but the 100m of memory it occupies will not be reclaimed and redivided by the system.

When you delete files in tmpfs, the tmpfs file system driver dynamically reduces the file system and frees up VM resources.

#

The purpose of tmpfs

For example:

The Automatic Memory Management feature in Oracle uses / dev/shm.

Temporary files of some programs can be placed in tmpfs in LINUX to improve system performance by taking advantage of the fact that tmpfs is faster than hard disk.

There are roughly three ways to resize tmpfs:

1. Mount directly to the desired directory-- such as the temporary directory of the system-- where you can mount the temporary files of a program according to your actual needs.

[root@bys3] # mount-t tmpfs-o size=20m tmpfs / tmp

[root@bys3] # df-h

Filesystem Size Used Avail Use% Mounted on

/ dev/sda2 16G 10G 4.7G 69% /

/ dev/sda1 99m 21m 74m 22% / boot

Tmpfs 502m 0502m 0% / dev/shm

Tmpfs 20m 0 20m 0% / tmp

Since files in the / tmp directory may be in use before mounting, some programs on the system may not work properly after mounting. You can write / etc/fstab, which is also valid after reboot.

2./etc/fstab file to modify the capacity of / dev/shm (add size=100M option). After modification, you can mount it again:

[root@bys3 ~] # cat / etc/fstab

LABEL=/ / ext3 defaults 1 1

LABEL=/boot / boot ext3 defaults 1 2

Tmpfs / dev/shm tmpfs defaults,size=600M 00

Tmpfs / tmp tmpfs defaults,size=25M 0 0

Devpts / dev/pts devpts gid=5,mode=620 0 0

Sysfs / sys sysfs defaults 0 0

Proc / proc proc defaults 0 0

LABEL=SWAP-sda3 swap swap defaults 0 0

/ dev/sda5 swap swap defaults 0 0

[root@bys3 ~] # mount-a-Test / etc/fstab without error, restart OS system

[oracle@bys3 ~] $df-h-- the information after restart is as follows. The corresponding entry of the tmpfs file system has been changed to the configured.

Filesystem Size Used Avail Use% Mounted on

/ dev/sda2 16G 10G 4.7G 69% /

/ dev/sda1 99m 21m 74m 22% / boot

Tmpfs 600m 0 600m 0% / dev/shm

Tmpfs 25m 0 25m 0% / tmp

3./dev/shm builds a tmp currently and binds with / tmp. This method is a bit cumbersome and is not as convenient and fast as method 1.

[root@bys3 ~] # mkdir / dev/shm/tmp

[root@bys3 ~] # chmod 1777 / dev/shm/tmp

[root@bys3] # mount-- bind / dev/shm/tmp / tmp-pay attention to mount-- bind here there are two before bind-

[root@bys3 ~] # ls-ld / tmp

Drwxrwxrwt 2 root root 40 Dec 8 12:15 / tmp

[root@bys3] # df-h

Filesystem Size Used Avail Use% Mounted on

/ dev/sda2 16G 10G 4.7G 69% /

/ dev/sda1 99m 21m 74m 22% / boot

Tmpfs 600m 0 600m 0% / dev/shm

Tmpfs 600m 0600m 0% / tmp-you can see that / tmp uses the space of / dev/shm.

At this point, the study on "how to use the file system tmpfs on Linux" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report