LoginSignup
0
0

[Linux] build するとき、とまっちゃう OOM のあれこれ

Posted at

はしがき

うちの会社はサービス向けのサーバー以外にも、サービスするためのテスト向けのサーバーも運用しています。

仕事をしながら、テスト向けのサーバーから build しましたが、終わるまで、時間がかなり長くかかりました。
終わったとしても、build は失敗でした。

上司にきいたら、OOM らしいでした。
「OOM」という言葉は初耳でしたが、このような現象は以前の CICD のことを実装するときも( https://qiita.com/dkdidudtn/items/45f06b741bda7a14b838 )経験したことです。

swap を使って、解決した記憶がありますが、この時は自分の権限がないので、上司から swap もらいました。

OOM ってなに?

Out of memory (OOM) is an often undesired state of computer operation where no additional memory can be allocated for use by programs or the operating system.

OS もしくは program に追加メモリーを与えられない状態です。
システムにメモリが足りなくなって、OS による program がシャットダウンされます。

Historically, the out-of-memory condition was more common than it is now, since early computers and operating systems were limited to small amounts of physical random-access memory (RAM) due to the inability of early processors to address large amounts of memory, as well as cost considerations. Since the advent of virtual memory opened the door for the usage of swap space, the condition is less frequent.

昔からは結構 OOM がありましたが、VM の発展による swap memory を使えるようになって、最近はどんどんなくなる状態ということです。

「どんどんなくなる」といっても、cloud computing service を使うことによって、サーバーを運用にある程度ピッタリする VM を使うので、場合によって、発生する可能性があります。

swap space/memory

物理 disk(SSD, hard disk)に RAM 機能を拡張することです。

解決方法

image.png

aws の free tier の ec2 を使いました。

いかのコードで memory を確認できます。

$ free -h

image.png

free tier なので、949MiB です。
この状態で、ある git repository から clone して、npm install したら、すぐ止まってしまいます。

ec2 の size を upscale する方法もあると予想しますが、今回は swap memory を追加する方法を使います。
swap memory を使うために disk の size を確認する必要があります。

$ df . -h

image.png

使える部分が 6.5GB で、十分だと思います。

$ sudo dd if=/dev/zero of=/swapfile bs=1M count=1024
$ sudo mkswap /swapfile
$ sudo swapon /swapfile
$ echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

これで、1GB ぐらいの swap memory を追加しました。

free -m

image.png

ちゃんと追加されました。
これで小さい project ではmodule install できるはずです。

参考&関連 URL

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0