Mémoire Linux

Voir :

Supervision - sonde Nagios - Memoire Linux

https://linuxblog.io/free-vs-available-memory-in-linux/

https://en.pingcap.com/blog/linux-kernel-vs-memory-fragmentation-2/

/proc/sys/vm/compact_memory

procmap

pmap

smem

lsmem / chmem

https://linuxfr.org/news/sortie-du-noyau-linux-6-17 damon_stat

Fuite mémoire

Voir :

Valgrind

https://www.hebergementwebs.com/tutoriels/linux-recherche-de-fuites-de-memoire-dans-les-programmes

https://qastack.fr/unix/36450/how-can-i-find-a-memory-leak-of-a-running-process

https://www.linuxtricks.fr/wiki/performance-memoire-avec-free-et-vmstat

http://www.ordinateur.cc/syst%C3%A8mes/Linux/205699.html

Atop - Case study with atop: memory leakage

https://github.com/iovisor/bcc/blob/master/README.md tools/memleak

Config

Kernel Linux param

NUMA (Non-Uniform Memory Access)

Voir :

What is NUMA ?

La mémoire : numactl, lstopo, perf, etc.

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

https://blog.zwindler.fr/2020/02/24/transparent-hugepages-mesurer-limpact-sur-les-performances/

https://www.postgresql.org/docs/9.4/kernel-resources.html

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
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