Linux memory: Difference between revisions

From DWIKI
 
(20 intermediate revisions by the same user not shown)
Line 3: Line 3:
= Links =
= Links =


*[http://www.linuxatemyram.com/ Linux ate my RAM!]
*[http://www.linuxatemyram.com/ Linux ate my RAM!]
*[https://www.thegeekdiary.com/understanding-proc-meminfo-file-analyzing-memory-utilization-in-linux/ Understanding /proc/meminfo]
*[https://www.tecmint.com/clear-ram-memory-cache-buffer-and-swap-space-on-linux/ How to Clear RAM Memory Cache, Buffer and Swap Space on Linux]  
*[https://www.tecmint.com/clear-ram-memory-cache-buffer-and-swap-space-on-linux/ How to Clear RAM Memory Cache, Buffer and Swap Space on Linux]  
*[http://serverfault.com/questions/377617/how-to-interpret-output-from-linux-top-command How to interpret output from Linux 'top' command?]  
*[http://serverfault.com/questions/377617/how-to-interpret-output-from-linux-top-command How to interpret output from Linux 'top' command?]  
*[https://linuxhint.com/understanding_vm_swappiness/ Understanding VM swappiness]
*[https://linuxhint.com/understanding_vm_swappiness/ Understanding VM swappiness]
*[https://www.howtogeek.com/449691/what-is-swapiness-on-linux-and-how-to-change-it/ What is swappiness on Linux]
*https://www.kernel.org/doc/html/latest/filesystems/proc.html The /proc Filesystem]
*[https://www.fosslinux.com/47145/swappiness-linux.htm Swappiness in Linux: Everything you need to know]
*[https://www.fosslinux.com/47145/swappiness-linux.htm Swappiness in Linux: Everything you need to know]
*[https://serverfault.com/questions/85470/meaning-of-the-buffers-cache-line-in-the-output-of-free https://serverfault.com/questions/85470/meaning-of-the-buffers-cache-line-in-the-output-of-free]  
*[https://serverfault.com/questions/85470/meaning-of-the-buffers-cache-line-in-the-output-of-free https://serverfault.com/questions/85470/meaning-of-the-buffers-cache-line-in-the-output-of-free]  
Line 13: Line 14:
*[https://web.archive.org/web/20120520221529/http://emilics.com/blog/article/mconsumption.html Memory Consumption in Linux]
*[https://web.archive.org/web/20120520221529/http://emilics.com/blog/article/mconsumption.html Memory Consumption in Linux]
*[https://www.studytonight.com/operating-system/difference-between-paging-and-swapping Difference between Paging and Swapping]
*[https://www.studytonight.com/operating-system/difference-between-paging-and-swapping Difference between Paging and Swapping]
*[https://www.baeldung.com/linux/swap-space-use The Use of Swap Space in Modern Linux Systems]
*[https://unix.stackexchange.com/questions/2658/why-use-swap-when-there-is-more-than-enough-free-space-in-ram Why is system using swap when there is enough free space in ram?]
*[https://www.thomas-krenn.com/en/wiki/Linux_Page_Cache_Basics Linux page cache basics]
 
==/proc/meminfo==
*[https://www.thegeekdiary.com/understanding-proc-meminfo-file-analyzing-memory-utilization-in-linux/ Understanding /proc/meminfo]
*[https://www.baeldung.com/linux/proc-meminfo The /proc/meminfo File in Linux]


= Documentation =
= Documentation =
==Output of 'free' command==
===available===
MemAvailable in /proc/meminfo


  man 5 proc
  man 5 proc
Line 39: Line 52:
'''Resident Set Size'''
'''Resident Set Size'''


[https://stackoverflow.com/questions/7880784/what-is-rss-and-vsz-in-linux-memory-management RSS and VSZ inLinux memory management]
[https://stackoverflow.com/questions/7880784/what-is-rss-and-vsz-in-linux-memory-management RSS and VSZ in Linux memory management]


"memory is allocated to that process and is in RAM. It does not include memory that is swapped out. It does include memory from shared libraries as long as the pages from those libraries are actually in memory. It does include all stack and heap memory."
"memory is allocated to that process and is in RAM. It does not include memory that is swapped out. It does include memory from shared libraries as long as the pages from those libraries are actually in memory. It does include all stack and heap memory."
Line 46: Line 59:
'''Virtual Memory Size'''
'''Virtual Memory Size'''
It includes all memory that the process can access, including memory that is swapped out, memory that is allocated, but not used, and memory that is from shared libraries.
It includes all memory that the process can access, including memory that is swapped out, memory that is allocated, but not used, and memory that is from shared libraries.
*[https://www.baeldung.com/linux/resident-set-vs-virtual-memory-size RSS vs VmSize]
==ZFS and arc==
===Tools===
*arc_summary
===Links===
*[https://superuser.com/questions/1137416/how-can-i-determine-the-current-size-of-the-arc-in-zfs-and-how-does-the-arc-rel Determine arc usage]
*[https://pve.proxmox.com/wiki/ZFS_on_Linux Proxmox: ZFS on Linux]
*[https://openzfs.org/wiki/Documentation/DnodeSync arc dnode]
===Changing arc sizes in runtime===
#in bytes
echo 1024 > /sys/module/zfs/parameters/zfs_arc_min
echo 2048 > /sys/module/zfs/parameters/zfs_arc_max
===Changing arc settings===
In /etc/modprobe.d/zfs.conf:
options zfs zfs_arc_max=4294967296
options zfs zfs_arc_min=1073741824
'''If root on ZFS''' (really?)
update-initramfs -u -k all


= FAQ =
= FAQ =
Line 55: Line 93:


==What is using all my swap? ==
==What is using all my swap? ==
https://www.cyberciti.biz/faq/linux-which-process-is-using-swap/
  for file in /proc/*/status ; do awk '/VmSwap|Name/{printf $2 " " $3}END{ print ""}' $file; done | sort -k 2 -n -r | less
  for file in /proc/*/status ; do awk '/VmSwap|Name/{printf $2 " " $3}END{ print ""}' $file; done | sort -k 2 -n -r | less
or to just list top 3
or to just list top 3
  for file in /proc/*/status ; do awk '/VmSwap|Name/{printf $2 " " $3}END{ print ""}' $file; done | sort -k 2 -n -r | head -n 3
  for file in /proc/*/status ; do awk '/VmSwap|Name/{printf $2 " " $3}END{ print ""}' $file; done | sort -k 2 -n -r | head -n 3
==Watch buffer/cache activity==
https://www.heroix.com/blog/linux-memory-use/
sar -B
==What is in buffer/cache?==
===Tools===
*[https://github.com/brendangregg/perf-tools perf-tools]
*https://www.brendangregg.com/blog/2014-12-31/linux-page-cache-hit-ratio.html


== Clear buffer/cache ==
== Clear buffer/cache ==


  sync; echo 3 > /proc/sys/vm/drop_caches
  sync; echo 3 > /proc/sys/vm/drop_caches

Latest revision as of 13:07, 15 November 2023


Links

/proc/meminfo

Documentation

Output of 'free' command

available

MemAvailable in /proc/meminfo


man 5 proc

see /proc/meminfo

total

Is MemTotal in /proc/meminfo

Total usable ram (i.e. physical ram minus a few reserved bits and the kernel binary code)

used

total - free - buffers - cache

unused

MemFree

RSS

Resident Set Size

RSS and VSZ in Linux memory management

"memory is allocated to that process and is in RAM. It does not include memory that is swapped out. It does include memory from shared libraries as long as the pages from those libraries are actually in memory. It does include all stack and heap memory."

VSZ / VmSize

Virtual Memory Size It includes all memory that the process can access, including memory that is swapped out, memory that is allocated, but not used, and memory that is from shared libraries.


ZFS and arc

Tools

  • arc_summary

Links


Changing arc sizes in runtime

#in bytes
echo 1024 > /sys/module/zfs/parameters/zfs_arc_min
echo 2048 > /sys/module/zfs/parameters/zfs_arc_max

Changing arc settings

In /etc/modprobe.d/zfs.conf:

options zfs zfs_arc_max=4294967296
options zfs zfs_arc_min=1073741824


If root on ZFS (really?)

update-initramfs -u -k all

FAQ

What is using all my memory?

smem -r -s swap| head -n3


What is using all my swap?

https://www.cyberciti.biz/faq/linux-which-process-is-using-swap/

for file in /proc/*/status ; do awk '/VmSwap|Name/{printf $2 " " $3}END{ print ""}' $file; done | sort -k 2 -n -r | less

or to just list top 3

for file in /proc/*/status ; do awk '/VmSwap|Name/{printf $2 " " $3}END{ print ""}' $file; done | sort -k 2 -n -r | head -n 3


Watch buffer/cache activity

https://www.heroix.com/blog/linux-memory-use/

sar -B


What is in buffer/cache?

Tools

Clear buffer/cache

sync; echo 3 > /proc/sys/vm/drop_caches