tech:memoire_linux
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| tech:memoire_linux [2026/05/30 22:34] – Jean-Baptiste | tech:memoire_linux [2026/09/18 10:19] (Version actuelle) – Jean-Baptiste | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| + | < | ||
| + | {{tag> | ||
| + | |||
| + | # Mémoire Linux | ||
| + | |||
| + | Voir : | ||
| + | * [[Supervision - sonde Nagios - Memoire Linux]] | ||
| + | * psacct [[Suivre la conso CPU par utilisateurs]] | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * / | ||
| + | * procmap | ||
| + | * pmap | ||
| + | * lsmem / chmem | ||
| + | * https:// | ||
| + | * slabtop | ||
| + | * memstrack | ||
| + | * smem - memory reporting tool | ||
| + | * smemcap - data collection tool for memory reporting | ||
| + | * smemstat - memory usage monitoring tool | ||
| + | * SLAB / SLUB / SLOB | ||
| + | |||
| + | |||
| + | Linux Memory Management : | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * [Vidéo - The Linux Foundation - Introduction à la gestion de la mémoire sous Linux ](https:// | ||
| + | * http:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | |||
| + | Exemples : | ||
| + | * http:// | ||
| + | |||
| + | |||
| + | |||
| + | ## Fuite mémoire | ||
| + | |||
| + | Voir : | ||
| + | * Valgrind | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * http:// | ||
| + | * [Atop - Case study with atop: memory leakage](https:// | ||
| + | * https:// | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | ## Config | ||
| + | |||
| + | ### Kernel Linux param | ||
| + | |||
| + | #### NUMA (Non-Uniform Memory Access) | ||
| + | |||
| + | Voir : | ||
| + | * [What is NUMA ? | ||
| + | * [La mémoire : numactl, lstopo, perf, etc.](https:// | ||
| + | * '' | ||
| + | |||
| + | Disable NUMA (Pour Oracle DB) | ||
| + | / | ||
| + | ~~~ini | ||
| + | numa=off | ||
| + | ~~~ | ||
| + | |||
| + | Vérif | ||
| + | |||
| + | '' | ||
| + | |||
| + | ~~~ | ||
| + | # 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 '' | ||
| + | |||
| + | If the number of available nodes is '' | ||
| + | |||
| + | Voir aussi : | ||
| + | * numastat | ||
| + | * numademo | ||
| + | |||
| + | |||
| + | #### NUMA (Non-Uniform Memory Access) - Useful Commands | ||
| + | |||
| + | To identify NUMA nodes, socket memory and CPU core allocation | ||
| + | ~~~bash | ||
| + | numactl -H | ||
| + | ~~~ | ||
| + | |||
| + | To identify the NUMA node local to an adapter | ||
| + | ~~~bash | ||
| + | cat / | ||
| + | ~~~ | ||
| + | |||
| + | To identify memory allocation and use on a particular NUMA node: | ||
| + | ~~~bash | ||
| + | cat / | ||
| + | ~~~ | ||
| + | |||
| + | To identify NUMA node mapping to cores, use one of the following | ||
| + | ~~~bash | ||
| + | numactl --hardware | ||
| + | cat / | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | Driver Loading - NUMA Node | ||
| + | |||
| + | ~~~bash | ||
| + | numactl --cpunodebind=1 onload_tool reload | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | |||
| + | ### Memory usage per user | ||
| + | |||
| + | ~~~bash | ||
| + | smem -u | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ### Transparent HugePages (THP) | ||
| + | |||
| + | Voir | ||
| + | * https:// | ||
| + | * https:// | ||
| + | |||
| + | |||
| + | #### Désactiver **Transparent HugePages (THP)** | ||
| + | |||
| + | ~~~bash | ||
| + | cat / | ||
| + | ~~~ | ||
| + | |||
| + | 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 | ||
| + | ~~~ini | ||
| + | transparent_hugepage=never | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | ## Notes Free / Aviable | ||
| + | |||
| + | ~~~ | ||
| + | $ ./ | ||
| + | ... | ||
| + | --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 | ||
| + | |||
| + | Voir psacct [[Suivre la conso CPU par utilisateurs]] | ||
| + | |||
| + | ~~~bash | ||
| + | free -mt | ||
| + | ps aux --sort=-%mem | head -n 11 | ||
| + | vmstat -SM 45 10 | ||
| + | vmstat -SM -a 45 10 | ||
| + | ps -C apache2 -o rss --no-headers | tr " | ||
| + | ps -e -o pid, | ||
| + | ps -e -o pid, | ||
| + | ps -u $USER -o comm, | ||
| + | ps -eo comm, | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | |||
| + | ~~~bash | ||
| + | read CommitLimit Committed_AS <<< | ||
| + | echo $(( Committed_AS * 100 / CommitLimit)) | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | memused=$(free | ||
| + | memtotal=$(free | grep ^Mem | awk ' | ||
| + | echo $(( memused * 100 / memtotal)) | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | memFree=$(free | grep ^- | awk ' | ||
| + | memTot=$(free | grep ^Mem | awk ' | ||
| + | memUsed=$(echo " | ||
| + | echo " | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ~~~bash | ||
| + | ps -C apache2 -o rss --no-headers | tr " | ||
| + | read CommitLimit Committed_AS <<< | ||
| + | echo $(( Committed_AS * 100 / CommitLimit)) | ||
| + | memused=$(free | ||
| + | memtotal=$(free | grep ^Mem | awk ' | ||
| + | echo $(( memused * 100 / memtotal)) | ||
| + | ps -e -o pid, | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | 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 / | ||
| + | MemTotal: | ||
| + | |||
| + | # awk '/ | ||
| + | 65391036 | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | ## Fonctionnement | ||
| + | |||
| + | Voir : | ||
| + | OOM Killer et Overcommit Memory | ||
| + | http:// | ||
| + | |||
| + | ## Autres | ||
| + | |||
| + | Clearing KernelCare Cache | ||
| + | |||
| + | Source : https:// | ||
| + | |||
| + | ~~~bash | ||
| + | rm -rf / | ||
| + | echo 1 > / | ||
| + | echo 3 > / | ||
| + | kcarectl –update | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | |||
| + | ----------------- | ||
| + | |||
| + | * https:// | ||
| + | Overcommit Memory | ||
| + | Overcommit Accounting | ||
| + | |||
| + | Voir : | ||
| + | * https:// | ||
| + | |||
| + | 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 / | ||
| + | |||
| + | A la place de overcommit_ratio | ||
| + | Il est possible d' | ||
| + | |||
| + | |||
| + | OOM | ||
| + | ~~~bash | ||
| + | echo -1000 > / | ||
| + | |||
| + | cat / | ||
| + | echo -1000 > / | ||
| + | ~~~ | ||
| + | |||
| + | Or in a specific cgroup, set oom_kill_disable to 1. | ||
| + | ~~~bash | ||
| + | echo 1000 > / | ||
| + | ~~~ | ||
| + | |||
| + | For systemd services, use `OOMScoreAdjust=-1000` in the unit file to protect critical processes. | ||
| + | `cgroup_enable=memory swapaccount=1` | ||
| + | |||
| + | ~~~ | ||
| + | $ echo $(($(cat / | ||
| + | 11389 MB | ||
| + | $ cat / | ||
| + | ~~~ | ||
| + | |||
| + | ---- | ||
| + | |||
| + | OOM is not invoked when memory.high is reached. | ||
| + | However, if cgroup memory.max is reached then OOM is invoked. | ||
| + | TLB hit TLB miss | ||
| + | |||
| + | ~~~bash | ||
| + | sudo perf stat -e dTLB-loads, | ||
| + | |||
| + | perf list | grep -i tlb | ||
| + | ~~~ | ||
| + | |||
| + | Slub | ||
| + | ~~~bash | ||
| + | slabtop --sort=1 | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | slabinfo -v | ||
| + | ~~~ | ||
| + | |||
| + | access.redhat.com/ | ||
| + | page_owner=on | ||
| + | |||
| + | |||
| + | ## Premature swapping while there is still plenty of pagecache to be reclaimed | ||
| + | |||
| + | Cgroup v1 | ||
| + | |||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * [Change in swap behavior between RHEL 7 and RHEL 8 kernels](https:// | ||
| + | |||
