Linux Memory Management: Difference between revisions
(One intermediate revision by the same user not shown) | |||
Line 25: | Line 25: | ||
=Resident Size of a Process= | =Resident Size of a Process= | ||
The resident size of a process, as reported by the [[top]] [[Top#RES|RES]] column, or the [[Linux_Process_Information#VmRSS|VmRSS entry in /proc/<pid>/status | The resident size of a process, also known as resident set, is reported by the [[top]] [[Top#RES|RES]] column, or the [[Linux_Process_Information#VmRSS|VmRSS entry]] in /proc/<pid>/status and represents an accurate representation of how much physical memory is the actual process consuming. | ||
=Shareable Size of a Process= | =Shareable Size of a Process= |
Latest revision as of 15:22, 29 December 2020
External
Internal
Getting Information about Memory
Java Linux Memory
Virtual Size of a Process
The virtual size of a process, as reported by top VIRT column, represents the size of the program's entire addressable space at the present moment. The value has does not represent physical memory, or RAM space, and most of the amount comes from file-backed address regions.
Resident Size of a Process
The resident size of a process, also known as resident set, is reported by the top RES column, or the VmRSS entry in /proc/<pid>/status and represents an accurate representation of how much physical memory is the actual process consuming.
The shareable size of a process, as reported by the top SHR column, represents how much of the virtual size of the process is actually shareable, as memory or libraries. In case of libraries, it does not necessarily mean that the entire library is resident and counted agains the resident size. For example, if a program only uses a few functions in a library, the whole library is mapped and will be counted against the virtual size and shareable size, but only the parts of the library file containing the functions being used will actually be loaded in and be counted under resident size.
Swap
Swap is enabled at boot by the swapon command, which is invoked by the startup scripts if swap devices are listed in /etc/fstab.
Swap Info
Information about swap in use is available in /proc/swaps.
An indication that swap is enabled is whether top displays a non-zero total swap space.
Swappinness
Swappiness is a property for the Linux kernel that changes the balance between swapping out runtime memory, as opposed to dropping pages from the system page cache. Swappiness can be set to values between 0 and 100 inclusive. A low value means the kernel will try to avoid swapping as much as possible where a higher value instead will make the kernel aggressively try to use swap space. The default value is 60, and for most desktop systems, setting it to 100 may affect the overall performance, whereas setting it lower (even 0) may improve interactivity (by decreasing response latency.)
Value vm.swappiness = 0, Strategy: The kernel will swap only to avoid an out of memory condition.
Value vm.swappiness = 60 (default)
Value vm.swappiness = 100, Strategy: The kernel will swap aggressively which may affect over all performance.
Thrashing
The condition in which the content of the memory is swapped out only to be swapped back in.
Swap Operations
Caches
Linux will always try to use free physical memory to cache data, so the reported "free" memory will always be very low. Aside from memory used by processes, the operating system uses physical memory for buffers and page cache. When processes need memory, heuristics that frees cache and allocates the space to those processes kicks in.
The following expression is true for metrics reported by top:
total memory = free + used + buffers/cache
Buffers
The "buffers", or the "buffer cache" is represented by areas in the physical memory where the kernel maintains data buffers that are used by block device drivers. These buffers are of fixed size and contain blocks of information that have either been read from a block device or are being written to it. The buffer cache is indexed via the device identifier and the desired block number, so the data is accessed fast. Block devices are only accessed via the buffer cache, so if data is found in the buffer cache, the system can be sure that it is the authoritative version and a physical access to the device is not necessary.
Current value for memory allocated to buffers is available as /proc/meminfo buffers.
Cache
It is also known as the "page cache". The page cache is used to read content from disk in memory, so it can be accessed faster, when the access is done repeatedly.
Current value for memory allocated to cache is available as /proc/meminfo cached.