UbuntuでkswapdがCPU使用率100%になる

OS:Ubuntu 18.04

Tensorflowでディープラーニングを行っていた所、学習が始まって数時間放置した頃にモニターを確認してみるとCPU使用率が100%になり、コマンド入力を受け付けない状態になっていた。

nmonではCPU使用率が天井に張り付いており、topではkswapdが異常に高い負荷をかけていることを示していた。

コマンド入力を受け付けていなかったので強制的に再起動。

kswapdは仮想メモリ周りを調整するシステムプロセスらしく、頻繁にスワップが起きるとCPUを独占してしまうよう。

The process you referred to, kswapd0, manages virtual memory and may be having issues due to moving processes to SWAP too frequently, causing cpu spikes and decreased system performance.

https://www.linode.com/community/questions/18027/high-cpu-from-kswapd0

というわけでスワップしにくいように設定する。

sudo echo vm.swappiness=$VALUE | sudo tee -a /etc/sysctl.conf

$VALUEには0〜100の数字を入れる。

例えば10にすると、空きメモリ(Free Memory)が10%を切るまではスワップしないようにできる。

swappiness

This control is used to define how aggressive the kernel will swap
memory pages. Higher values will increase agressiveness, lower values
decrease the amount of swap. A value of 0 instructs the kernel not to
initiate swap until the amount of free and file-backed pages is less
than the high water mark in a zone.

The default value is 60.

https://elixir.bootlin.com/linux/v4.12/source/Documentation/sysctl/vm.txt#L773

次に、drop_cacheでキャッシュを開放する。

sudo echo 1 > /proc/sys/vm/drop_caches

もしpermission deniedが起きたらteeで書き込む。

echo 1 | sudo tee /proc/sys/vm/drop_caches

drop_caches

Writing to this will cause the kernel to drop clean caches, as well as
reclaimable slab objects like dentries and inodes. Once dropped, their
memory becomes free.

To free pagecache:
echo 1 > /proc/sys/vm/drop_caches
To free reclaimable slab objects (includes dentries and inodes):
echo 2 > /proc/sys/vm/drop_caches
To free slab objects and pagecache:
echo 3 > /proc/sys/vm/drop_caches

https://www.kernel.org/doc/Documentation/sysctl/vm.txt

最後に再起動して設定完了。

これでkswapdが暴走しなくなった。

参考

High CPU from kswapd0 | Linode Questions
Our Linode is experiencing high cpu-load on weekly basis. When we run the`top`command, it shows `kswapd0` to be the main...
https://elixir.bootlin.com/linux/v4.12/source/Documentation/sysctl/vm.txt#L773
https://www.kernel.org/doc/Documentation/sysctl/vm.txt

コメント

タイトルとURLをコピーしました