Upgrade to Pro — share decks privately, control downloads, hide ads and more …

114-ファイルのshallow_copy.pdf

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers.

 114-ファイルのshallow_copy.pdf

Avatar for Satoru Takeuchi

Satoru Takeuchi PRO

May 27, 2026

More Decks by Satoru Takeuchi

Other Decks in Technology

Transcript

  1. まずはデカいファイルを作る • VMではなく物理マシン上のシステムで実験 ◦ 📝 ホスト側のキャッシュメモリの影響を受けないようにするため ▪ そのうち別の動画で詳細を説明するかも • /mnt以下にXFSがマウントされているとする

    • 1GiBのファイルを作ってキャッシュメモリを捨てる ◦ こうしないと後の実験でディスク上のデータではなくメモリ上のデータを読み書きするだけになってし まうので性能測定の意味が無くなる 3 # dd if=/dev/random of=/mnt/test.data bs=1M count=1024 oflag=sync … # echo 3 >/proc/sys/vm/drop_caches
  2. shallow copyの性能測定 • 以下の処理にかかる時間を測定 1. /mnt/test.dataを同じファイルシステム上の別のファイルに shallow copy ▪ cpコマンドに--reflinkオプションを付ける

    2. コピーするだけだとキャッシュメモリに書くだけなので、その後 fsyncシステムコールを発行してデー タをディスクに同期 5 # time (cp --reflink /mnt/test.data /mnt/shallow.data; xfs_io -c fsync /mnt/shallow.data) real 0m0.048s user 0m0.005s sys 0m0.009s # cmp /mnt/test.data /mnt/shallow.data # cmp /mnt/deep.data /mnt/shallow.data
  3. それぞれの違い 6 test.dataの メタデータ test.dataの データ deep.dataの メタデータ deep.dataの データ

    コピーする shallowコピー test.dataの メタデータ test.dataの データ shallow.dataの メタデータ 普通のコピー データはコピーせずリ ンクを張るだけ