2020/07/30

WSL2 の Ubuntu18 で ulimit open file を変更したい

開発機って、やっぱりむちゃなことしたいですよね。WSL 2 の Linux は容易にリセットできるので無茶なことがしやすくて素晴らしいです。そして、無茶なことをしていると、すぐ fd 枯渇しますよね。なので ulimit -n したくなるじゃないですか。知らんけど。

自分の環境は WSL 2 + Ubuntu18 です。

/etc/systemd/system.conf

DefaultLimitNOFILE=65535
DefaultLimitNPROC=65535

/etc/security/limits.conf

* soft nproc 65535
* hard nproc 65535
* hard nofile 65535
* soft nofile 65535

root soft nproc 65535
root hard nproc 65535
root soft nofile 65535
root hard nofile 65535

/etc/pam.d/common-session, /etc/pam.d/common-session-noninteractive

session required pam_limits.so

そんで、再起動するんですけど、

wsl -t Ubuntu-18.04

あれ、ぜんぜんだめや。

$ ulimit -n 4097
-bash: ulimit: open files: cannot modify limit: Operation not permitted

ulimit -n っていっつもはまるわーっと思いながらぐぐるけど、設定としてはあってそう。

もしかして WSL 環境なのが関係あるかなと思って調べると、以下の issue があがっていました。

https://github.com/Microsoft/WSL/issues/1688

取り急ぎ workaroundですけど、 su user すれば良いそうですわってことでいけました。

サイト内検索