====== Linux Virtual Memory ====== ===== Diagnosi di Out of Memory Killer ===== Come diagnosticare problemi //Out of Memory Killer//? Nel syslog si legge quanto segue: kernel: apache2 invoked oom-killer: gfp_mask=0x100cca(GFP_HIGHUSER_MOVABLE), order=0, oom_score_adj=0 ... kernel: Mem-Info: kernel: active_anon:31868 inactive_anon:3867772 isolated_anon:0 kernel: active_file:196 inactive_file:169 isolated_file:0 kernel: unevictable:3724 dirty:0 writeback:0 kernel: slab_reclaimable:8784 slab_unreclaimable:23394 kernel: mapped:32570 shmem:33575 pagetables:16400 bounce:0 kernel: free:33008 free_pcp:981 free_cma:0 ... kernel: Tasks state (memory values in pages): kernel: [ pid ] uid tgid total_vm rss pgtables_bytes swapents oom_score_adj name kernel: [ 279] 0 279 54600 891 462848 0 -250 systemd-journal ... kernel: [2109336] 33 2109336 77411 14582 282624 0 0 apache2 kernel: [2109339] 33 2109339 76387 14063 274432 0 0 apache2 kernel: [2109340] 33 2109340 75360 12557 262144 0 0 apache2 ... kernel: Out of memory: Killed process 1102 (mariadbd) total-vm:2663252kB, anon-rss:429744kB, file-rss:0kB, shmem-rss:0kB, UID:106 pgtables:1172kB oom_score_adj:0 Quindi una richiesta di allocazione memoria da parte del processo **apache2** ha causato il kill del processo **mariadbd**. Anche l'elenco dei processi //Tasks state// evidenzia la presenza di **151 processi** apache2. vmstat -s cat /proc/meminfo Oltre all'ovvio **MemFree**, è forse più importante il valore di **MemAvailable**. Il primo valore infatti tenderà normalmente ad avvicinarsi allo zero: tutta la RAM verrà infatti utilizzata ad esempio per il caching delle pagine lette da disco. Tale memoria in genere non viene rilasciata se non quando serve per altri scopi. Per diagnosticare problemi di //Out of Memory Killer// è più importante il valore di //MemAvailable//, poiché esso contiene una stima di quanta memoria è disponibile per avviare nuovi processi. Un parametro da tenere sotto osservazione è la memoria **Active** (composta da **Active(anon)** e **Active(file)**). In generale questo parametro dovrebbe rimanere costante nel tempo e non dovrebbe presentare un grafico a scalini crescenti. ^ MemFree | The amount of physical RAM, in kibibytes, left unused by the system. | ^ MemAvailable | An estimate of how much memory is available for starting new applications, without swapping. | ^ Active | The amount of memory, in kibibytes, that has been used more recently and is usually not reclaimed unless absolutely necessary. | ^ Active(anon) | The amount of anonymous and tmpfs/shmem memory, in kibibytes, that is in active use, or was in active use since the last time the system moved something to swap. | ^ Active(file) | The amount of file cache memory, in kibibytes, that is in active use, or was in active use since the last time the system reclaimed memory. | ===== Come rilasciare la cache ===== Per rilasciare le **PageCache** si può usare il comando: sync; echo 1 > /proc/sys/vm/drop_caches Dovrebbero andare a zero diversi contatori, tra cui quello della **Active** memory. Il parametro **1** scritto nello pseudofile può assumere valori diversi, a seconda di cosa si voglia rilasciare: ^ 1 | Clears only the page cache. | ^ 2 | Clears dentries and inodes. | ^ 3 | Clears page cache, dentries, and inodes. | ===== Web References ===== * **[[https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/deployment_guide/s2-proc-meminfo|/proc/meminfo]]** * **[[https://access.redhat.com/solutions/406773|Interpreting /proc/meminfo and free output for Red Hat Enterprise 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]]**