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?

メモリマップファイル

Last updated at Posted at 2024-05-26

メモリマップファイルとは

ファイルの領域を仮想アドレス空間上にマップする。
mmap()関数を所定の方法で呼び出すことで、ファイルの内容をメモリに読み出して、その領域を仮想アドレス空間にマップできます。

データを変更した場合は、後ほどストレージデバイス上のファイルに所定のタイミングで書き戻します。

データ変更後のストレージデバイスへの書き戻し

root@***********:***********# echo hello >testfile
root@***********:***********# go build filemap.go
root@***********:***********# ./filemap
*** testfileのメモリマップ前のプロセスの仮想アドレス空間 ***
00400000-004aa000 r-xp 00000000 08:05 402438                             /***********/filemap
....

testfileをマップしたアドレス: 0x7f26cfa74000

*** testfileのメモリマップ後のプロセスの仮想アドレス空間 ***
00400000-004aa000 r-xp 00000000 08:05 402438                             ***********/filemap
...
7f26cfa74000-7f26cfa75000 rw-s 00000000 08:05 796044                     ***********/testfile
...

root@***********:***********# cat testfile
HELLO

気づき

ファイルの上書きをしている。
ストレージデバイスが仮想メモリにマップして(実際はページテーブルに対応する物理メモリにマップする)ファイルの変更があれば仮想メモリ→物理メモリ→ストレージデバイスという流れでファイルの上書きがされるのか。

出典

感想

取り敢えず断片的に理解しよう

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?