Last active
November 25, 2022 03:09
-
-
Save denvernine/d0d01a2f12dc6ab81861a037a4a1e3af to your computer and use it in GitHub Desktop.
Revisions
-
denvernine revised this gist
Nov 25, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ # # @(#) display processes with oom_score_adj less than 0. # for process in /proc/[1-9][0-9]*; do if [[ $(cat ${process}/oom_score_adj) -lt 0 ]]; then echo ${process} $(cat ${process}/comm): $(cat ${process}/oom_score_adj) fi -
denvernine created this gist
Nov 25, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ # OOM killerがやってきてsshできなくなったときにやったこと VirtualBox上の開発環境にいつもどおりsshしようとしたある日、まったく反応が返ってこなくなりました。pingは通るので、コンソールからログを見てみたところOOM killerが動いているようでした。 sshできないとどうにもならないので、とりあえず再起動。今後のためにもOOM killerの活動をある程度制御することにしました。 ## `/proc/*/oom_score_adj` 簡単に言えば、OOM killerはメモリを食い散らかすプロセスをkillしてシステム全体を守るものです(詳細は先人の素晴らしい記事を参照してください)。とはいえなんでもかんでもkillされては困るので、優先度を制御します。今回の環境ではsshdもkill対象に入っていたので、今後対象から外れるようにします。 やることは簡単で、 - `ps aux | grep ssh | grep -v grep` などで対象のPIDを検索 - `echo -1000 > /proc/${pid}/oom_score_adj` などでoom_score_adjに-1000と書き込む だけです。 先述のように、今回の環境はsshdのoom_score_adjは0になっており、kill対象になっていました。-1000にすることで `/proc/${pid}/oom_score` を補正し、OOM killerのkill対象から外すことができます。 ## references - その51 プロセスを殺戮する恐怖のOOM killer - YouTube https://www.youtube.com/watch?v=D13PVCaHnk0 This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ #!/bin/bash # # @(#) display processes with oom_score_adj less than 0. # for process in /proc/[0-9]*; do if [[ $(cat ${process}/oom_score_adj) -lt 0 ]]; then echo ${process} $(cat ${process}/comm): $(cat ${process}/oom_score_adj) fi done