0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ユーザー権限で使える memdisk(ramdisk) 領域 `/run/user/$uid` のメモ

Posted at

背景

  • 画像処理とかレンダリングや機械学習で, 中間の計算結果(数 MB ~ 数 GB)を多量に生成する必要がある.
  • SSD だと読み書き頻繁にすると寿命が気になる...

Linux だと tmpfs で memdisk(ramdisk) を作ることができますが, root 権限が必要になります.

共有サーバとかで, ユーザ権限で memdisk を作りたいときがあります.

systemd 環境(Ubuntu, CentOS 7+)

systemd 環境だと, /run が tmpfs でマウントさており, /run/user/$uid でユーザごとにアクセスできる領域があります.

df -h で確認できます.

tmpfs           9.5G   24K  9.5G   1% /run/user/121
tmpfs           9.5G  8.0K  9.5G   1% /run/user/1000

インストール環境などにもよるかもですが, 概ね総メモリ量の 10% が確保されます.

この領域を使うとよいでしょう!

/dev/shm?

Ubuntu 環境ですと /dev/shm も, ユーザ権限で直接読み書きできました(こちらは総メモリ量の半分が確保されている)

容量大きめなデータですとこちらを使ってみるのもよさそうです!

その他

go とかで FUSE でユーザー権限で memdisk 作れるライブラリあるようです.

https://github.com/bbengfort/memfs
(2017 で開発止まっているので今だと動かないかも)

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?