tech:notes_swap_memoire
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Prochaine révision | Révision précédente | ||
| tech:notes_swap_memoire [2025/03/24 15:06] – créée - modification externe 127.0.0.1 | tech:notes_swap_memoire [2026/07/20 09:51] (Version actuelle) – Jean-Baptiste | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| + | < | ||
| + | {{tag> | ||
| + | # Notes swap mémoire | ||
| + | |||
| + | Voir : | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | |||
| + | |||
| + | Voir aussi : | ||
| + | * [[Swap sur ramdisk]] | ||
| + | |||
| + | ~~~bash | ||
| + | systemctl --type swap | ||
| + | cat /proc/swaps | ||
| + | cat / | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | echo 0 > / | ||
| + | # cat / | ||
| + | # sysctl -w vm.vfs_cache_pressure=50 | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | # Allocate storage and restrict access | ||
| + | fallocate --length 4GiB /swapfile | ||
| + | chmod 600 /swapfile | ||
| + | |||
| + | # Format the swap space | ||
| + | mkswap /swapfile | ||
| + | |||
| + | # Activate the swap space for paging | ||
| + | swapon /swapfile | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ## Analyse consommation | ||
| + | |||
| + | Consommation de la SWAP par utilisateur | ||
| + | ~~~bash | ||
| + | smem -u -s swap | ||
| + | ~~~ | ||
| + | |||
| + | Consommation de la SWAP par process | ||
| + | ~~~bash | ||
| + | smem -s swap | ||
| + | ~~~ | ||
| + | |||
| + | ou | ||
| + | ~~~bash | ||
| + | echo -e " | ||
| + | |||
| + | for S_FILE in / | ||
| + | do | ||
| + | S_PPID=" | ||
| + | S_PID=" | ||
| + | S_EXE=" | ||
| + | S_SWAPKB=" | ||
| + | [ ! -z $S_SWAPKB ] && echo -e " | ||
| + | done | sort -n | ||
| + | ~~~ | ||
| + | |||
| + | ou | ||
| + | |||
| + | ~~~bash | ||
| + | for file in / | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ## dphys-swapfile | ||
| + | |||
| + | ~~~bash | ||
| + | dphys-swapfile swapoff | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ## Recommandations SWAP | ||
| + | |||
| + | ### Prereq Oracle | ||
| + | |||
| + | |||
| + | | **RAM** | ||
| + | | ----------------------- | ----------------------------- | | ||
| + | | Between 1 GB and 2 GB | 1.5 times the size of the RAM | | ||
| + | | Between 2 GB and 16 GB | Equal to the size of the RAM | | ||
| + | | More than 16 GB | 16GB | | ||
| + | |||
| + | |||
| + | | **RAM** | ||
| + | | ----------------------- | ----------------------------- | | ||
| + | | Between 8 GB and 16 GB | Equal to the size of the RAM | | ||
| + | | More than 16 GB | 16GB | | ||
| + | |||
| + | |||
| + | ### Recommandations RedHat | ||
| + | |||
| + | Source : https:// | ||
| + | |||
| + | |||
| + | | **Amount of RAM in the system** | **Recommended swap space** | ||
| + | | ------------------------------- | ------------------------------ | ----------------------------------------------------- | | ||
| + | | ⩽ 2 GB | 2 times the amount of RAM | 3 times the amount of RAM | | ||
| + | | > 2 GB – 8 GB | Equal to the amount of RAM | 2 times the amount of RAM | | ||
| + | | > 8 GB – 64 GB | At least 4 GB | 1.5 times the amount of RAM | | ||
| + | | > 64 GB | At least 4 GB | Hibernation not recommended | ||
| + | |||
| + | |||
| + | ## Utilisation de SWAP alors que la RAM n'est que partiellement utilisé | ||
| + | |||
| + | En anglais sur les forums : | ||
| + | * Why is Swap used when there is RAM available? | ||
| + | * Swap being used when RAM is almost half free | ||
| + | * Why linux has enough memory but swap is used | ||
| + | * Why is Linux not using RAM but only Swap ? | ||
| + | * System suddenly using all available swap, but plenty of free memory | ||
| + | * High swap usage in spite of low RAM usage | ||
| + | |||
| + | Voir : | ||
| + | * https:// | ||
| + | * https:// | ||
| + | |||
| + | Voir aussi : | ||
| + | * Shared Memory | ||
| + | * zramctl | ||
| + | |||
| + | ~~~bash | ||
| + | cat / | ||
| + | |||
| + | cat / | ||
| + | cat / | ||
| + | cat / | ||
| + | cat / | ||
| + | ~~~ | ||
| + | |||
| + | Voir VmSwap ou VmSize | ||
| + | ~~~bash | ||
| + | ps -eo pmem, | ||
| + | grep VmSwap / | ||
| + | grep Vm / | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | |||
| + | ## Tests SWAP | ||
| + | |||
| + | |||
| + | Utiliser 2 giga de mémoire | ||
| + | ~~~bash | ||
| + | stress --vm 1 --vm-bytes 2G --timeout 30 | ||
| + | ~~~ | ||
| + | |||
| + | Vérif | ||
| + | ~~~bash | ||
| + | journalctl -k | grep -i "out of memory" | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | Autres test | ||
| + | ~~~c | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | int main() | ||
| + | { | ||
| + | char *p; | ||
| + | size_t s = 100 * 1024 * 1024; | ||
| + | |||
| + | for (;;) | ||
| + | { | ||
| + | p = malloc(s); | ||
| + | bzero(p, s); | ||
| + | sleep(1); | ||
| + | } | ||
| + | |||
| + | /* unreached */ | ||
| + | } | ||
| + | ~~~ | ||
| + | |||
| + | Source : https:// | ||
