Ceci est une ancienne révision du document !
Table des matières
Mémoire Linux
Voir :
- /proc/sys/vm/compact_memory
- procmap
- pmap
- lsmem / chmem
- slabtop
- memstrack
- smem - memory reporting tool
- smemcap - data collection tool for memory reporting
- smemstat - memory usage monitoring tool
- SLAB / SLUB / SLOB
Linux Memory Management :
Exemples :
Fuite mémoire
Voir :
- Valgrind
- https://github.com/iovisor/bcc/blob/master/README.md tools/memleak
Config
Kernel Linux param
NUMA (Non-Uniform Memory Access)
Voir :
numatop
Disable NUMA (Pour Oracle DB) /usr/share/doc/kernel-doc-4.18.0/Documentation/x86/x86_64/boot-options.txt
numa=off Only set up a single NUMA node spanning all memory.
Vérif
numactl command can be used to check the status of NUMA
# numactl -H | grep available available: 8 nodes (0-7)
# numactl -H | grep available available: 2 nodes (0-1)
If the number of available nodes is 2 nodes (0-1) or 8 nodes (0-7) then NUMA is enabled
If the number of available nodes is 1 nodes (0) then NUMA is not enabled.
Voir aussi :
- numastat
- numademo
NUMA (Non-Uniform Memory Access) - Useful Commands
To identify NUMA nodes, socket memory and CPU core allocation
numactl -H
To identify the NUMA node local to an adapter
cat /sys/class/net/<interface>/device/numa_node
To identify memory allocation and use on a particular NUMA node:
cat /sys/devices/system/node/node<N>/numastat
To identify NUMA node mapping to cores, use one of the following
numactl --hardware cat /sys/devices/system/node/node<N>/cpulist
Driver Loading - NUMA Node
numactl --cpunodebind=1 onload_tool reload
Memory usage per user
smem -u
Transparent HugePages (THP)
Voir
Désactiver **Transparent HugePages (THP)**
cat /sys/kernel/mm/transparent_hugepage/enabled
The following is a sample output that shows Transparent HugePages are being used as the [always] flag is enabled.
[always] never
Paramètre Kernel Linux
transparent_hugepage=never
Notes Free / Aviable
$ ./centreon_plugins.pl --plugin os::linux::snmp::plugin --mode memory --hostname localhost --help
...
--patch-redhat
If using Red Hat distribution with net-snmp >= 5.7.2-43 and
net-snmp < 5.7.2-47. But you should update net-snmp!!!!
This version: used = memTotalReal - memAvailReal // free =
memAvailReal
Others versions: used = memTotalReal - memAvailReal - memBuffer
- memCached // free = total - used
Exemple
free -mt vmstat -SM 45 10 vmstat -SM -a 45 10 ps -C apache2 -o rss --no-headers | tr "\n" "+" | sed -e 's/+$/\n/' | bc ps -e -o pid,user,%mem,rss,vsize,cmd --sort rss ps -e -o pid,user,%mem,rss,vsize,cmd --sort vsize ps -u $USER -o comm,vsz,pcpu | sort -nrk2 ps -eo comm,pcpu,pmem,rss --sort rss | tail -n 30 | tac
# sa -u --other-acct-file /var/account/pacct-20260917 sa -u sa -m sa -p
read CommitLimit Committed_AS <<< $(egrep "CommitLimit|Committed_AS" /proc/meminfo | awk '{print $2}') echo $(( Committed_AS * 100 / CommitLimit))
memused=$(free | grep "buffers/cache" | awk '{print $3}') memtotal=$(free | grep ^Mem | awk '{print $2}') echo $(( memused * 100 / memtotal))
memFree=$(free | grep ^- | awk '{print $3}') memTot=$(free | grep ^Mem | awk '{print $2}') memUsed=$(echo "scale=2 ; 100 * $memFree / $memTot" | bc) echo "$memUsed % Mem used" | grep ^[3-9][0-9]
ps -C apache2 -o rss --no-headers | tr "\n" "+" | sed -e 's/+$/\n/' | bc read CommitLimit Committed_AS <<< $(egrep "CommitLimit|Committed_AS" /proc/meminfo | awk '{print $2}') echo $(( Committed_AS * 100 / CommitLimit)) memused=$(free | grep "buffers/cache" | awk '{print $3}') memtotal=$(free | grep ^Mem | awk '{print $2}') echo $(( memused * 100 / memtotal)) ps -e -o pid,user,rss,vsize,cmd --sort rss
smem -u smem -u -t -k top -b -n 1 -u apache
Taille totale de la mémoire physique de la RAM (sans la swap)
# head -1 /proc/meminfo
MemTotal: 65391036 kB
# awk '/MemTotal/ { print $2 }' /proc/meminfo
65391036
Fonctionnement
Voir : OOM Killer et Overcommit Memory http://www.blog.florian-bogey.fr/empecher-les-depassements-de-memoire-sur-un-serveur-linux.html
Autres
Clearing KernelCare Cache
Source : https://www.linuxjournal.com/content/how-install-and-uninstall-kernelcare
rm -rf /var/cache/kcare/patches echo 1 > /proc/sys/vm/compact_memory echo 3 > /proc/sys/vm/drop_caches kcarectl –update
- https://www.postgresql.org/docs/current/kernel-resources.html Overcommit Memory Overcommit Accounting
Voir :
vm.overcommit_memory=0 Default Heuristic overcommit handling
vm.overcommit_memory=1 Always overcommit. Appropriate for some scientific applications. Classic example is code using sparse arrays and just relying on the virtual memory consisting almost entirely of zero pages.
vm.overcommit_memory=2 Strict setting vm.overcommit_memory=2 DOES allow overcommit. If you set overcommit_ratio to (say) 200, then memory can be committed to the extent of swap +(RAM * 200/100).
The current overcommit limit and amount committed are viewable in /proc/meminfo as CommitLimit and Committed_AS
A la place de overcommit_ratio Il est possible d'utiliser vm.overcommit_kbytes
OOM
echo -1000 > /proc/self/oom_score_adj cat /proc/<pid>/oom_score echo -1000 > /proc/<pid>/oom_score_adj # protect from OOM kill
Or in a specific cgroup, set oom_kill_disable to 1.
echo 1000 > /proc/<pid>/oom_score_adj # mark as first target
For systemd services, use OOMScoreAdjust=-1000 in the unit file to protect critical processes. cgroup_enable=memory swapaccount=1
$ echo $(($(cat /sys/fs/cgroup/memory/memory.max_usage_in_bytes) / 2**20)) MB 11389 MB $ cat /sys/fs/cgroup/memory/memory.stat
OOM is not invoked when memory.high is reached. However, if cgroup memory.max is reached then OOM is invoked. TLB hit TLB miss
sudo perf stat -e dTLB-loads,dTLB-load-misses,iTLB-loads,iTLB-load-misses -a sleep 60 perf list | grep -i tlb
Slub
slabtop --sort=1
slabinfo -v
access.redhat.com/ page_owner=on
Premature swapping while there is still plenty of pagecache to be reclaimed
Cgroup v1
