open()
, read()
and write()
methods for constant objects that have names. From the point of view of object-oriented programming , the kernel defines a generic filesystem (generic filesystem) as an abstract interface, and these three big functions are considered “virtual” and have no specific definition. Accordingly, the default file system implementation is called a virtual file system (VFS).read()
method of one file system, and then use the write()
method of another file system to output data.fs/
subdirectories contain certain file systems. The kernel also contains entities, such as cgroups
, /dev
and tmpfs
, which are required during the boot process and are therefore defined in the init/
kernel subdirectory. Note that cgroups
, /dev
and tmpfs
do not call the “big three” file_operations
functions, but directly read and write to memory.pipes
, dmesg
and POSIX clocks
, which also implement the file_operations
structure, access to which passes through the VFS layer, are not shown.file_operations
, such as ext4
and procfs
. The file_operations
functions can communicate with either device drivers or memory access devices. tmpfs
, devtmpfs
and cgroups
do not use file_operations
, but directly access memory.mount | grep -v sd | grep -v :/
mount | grep -v sd | grep -v :/
mount | grep -v sd | grep -v :/
, which will show all mounted ( mounted
) file systems that are not resident on disk and not NFS, which is true on most computers. One of the listed VFS mounts is undoubtedly /tmp
, right?/tmp
on physical media is insane! Source of/tmp
on physical media? Because the files in /tmp
are temporary, and storage devices are slower than the memory where tmpfs is created. Moreover, physical media is more subject to wear when overwriting than memory. Finally, files in / tmp may contain sensitive information, so their disappearance at every reboot is an essential function.tmpfs
becomes inaccessible for other purposes. In other words, a system with gigantic tmpfs and large files in it can use up all the memory and fall. Another hint: while editing the /etc/fstab
, remember that it should end with a new line, otherwise your system will not boot./tmp
, VFS (virtual file systems) that are most familiar to Linux users are /proc
and /sys
. ( /dev
resides in shared memory and does not have file_operations
). Why these two components? Let's understand this question.procfs
takes a snapshot of the instantaneous state of the kernel and the processes it controls for userspace
. In /proc
kernel displays information about the means it has, for example, interrupts, virtual memory, and the scheduler. In addition, /proc/sys
is the place where the settings configured with the sysctl
command are available to the userspace
. The status and statistics of individual processes are displayed in the /proc/
directories./proc/meminfo
is an empty file, which nevertheless contains valuable information./proc
files shows how dissimilar VFS disk file systems can be. On the one hand, /proc/meminfo
contain information that can be viewed with the free
command. On the other hand, there is empty! How is it going? The situation resembles the famous article entitled “Does the moon exist when no one is looking at it? Reality and Quantum Theory ” , written in 1985 by David Mermin, a professor of physics at Cornell University. The point is that the kernel collects memory statistics when a request to /proc
occurs, and in fact there is nothing in the /proc
files when no one is looking there. As Mermin said, “The fundamental quantum doctrine says that measurement, as a rule, does not reveal the pre-existing value of the property being measured.” (Think about the moon as a homework task!)procfs
makes sense, since the information located there is dynamic. A slightly different situation with sysfs
. Let's compare how many files of at least one byte are in /proc
and in /sys
.Procfs
has one file, namely the exported kernel configuration, which is an exception, since it needs to be generated only once per download. On the other hand, /sys
contains many more large files, many of which occupy a whole page of memory. Usually, sysfs
files contain exactly one number or string, unlike tables of information obtained when reading files such as /proc/meminfo
.sysfs
is to provide properties that can be read and written to what the kernel calls «kobjects»
in userspace. The only purpose of kobjects
is reference counting: when the last link to a kobject is deleted, the system will recover the resources associated with it. However, /sys
makes up most of the famous “stable ABI for userspace” kernel, which no one can, under any circumstances, “break” . This does not mean that the files in sysfs are static, which would contradict the counting of references to unstable objects./sys
, not what is actually present at this particular moment. Listing permissions on files in sysfs provides an understanding of how the configurable parameters of devices, modules, file systems, etc. can be customized or read. We make a logical conclusion that procfs is also part of the stable ABI kernel, although this is not explicitly stated in the documentation .sysfs
describe one specific property for each entity and can be readable, rewritable, or both. A “0” in the file indicates that the SSD cannot be deleted.Source: https://habr.com/ru/post/446614/
All Articles