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

cpコマンドはディスク上でデータを コピーしないことがある

cpコマンドはディスク上でデータを コピーしないことがある

以下動画のスライドです。
https://youtu.be/p6mLpGBa19o

Avatar for Satoru Takeuchi

Satoru Takeuchi PRO

June 21, 2026

More Decks by Satoru Takeuchi

Other Decks in Technology

Transcript

  1. • man cpより抜粋 ◦ cp - copy files and directories

    • “cp src dest”を実行した場合に、なんとなくユーザが脳裏に描いているもの cpコマンド 2 srcのinode srcのデータ destのinode destのデータ 1. inode作成 2. データコピー cp - copy files and directories
  2. • man cpより抜粋 ◦ cp - copy files and directories

    • “cp src dest”を実行した場合に、なんとなくユーザが脳裏に描いているもの cpコマンド 3 srcのinode srcのデータ destのinode destのデータ 1. inode作成 2. データコピー cp - copy files and directories こうなるとは限らない
  3. GNU coreutilsのcpの仕様(man cpより抜粋) 4 --reflink[=WHEN] control clone/CoW copies. See below

    … When --reflink[=always] is specified, perform a lightweight copy, where the data blocks are copied only when modified. If this is not possible the copy fails, or if --reflink=auto is specified, fall back to a standard copy. Use --reflink=never to ensure a standard copy is performed.
  4. GNU coreutilsのcpの仕様(man cpより抜粋) • デフォルトでは--reflink=auto • この場合、使えたらreflinkを使ってshallow copyする 5 --reflink[=WHEN]

    control clone/CoW copies. See below … When --reflink[=always] is specified, perform a lightweight copy, where the data blocks are copied only when modified. If this is not possible the copy fails, or if --reflink=auto is specified, fall back to a standard copy. Use --reflink=never to ensure a standard copy is performed.
  5. どうしてこうなった • GNU coreutilsの開発用MLでの議論の結果 ◦ https://lists.gnu.org/archive/html/coreutils/2015-05/msg00040.html • 理由の要約 ◦ write時のデータ断片化やデータが二重化されていないことを気にするのはレアケースである。そう

    いう人は明示的に--reflink=neverを使えばいい ◦ データ断片化の性能劣化は SSDでは影響が小さい ◦ dedup機能が普及してきているので、データ二重化のメリットはさらに薄れる 8
  6. まとめ • GNU coreutilsのcpコマンドはデフォルトでshallow copyする ◦ Btrfsおよび、殆どの場合で XFSが該当 ◦ 📝

    Ubuntu 26.04で採用されたRust製のuutils/coreutilsに同梱されているcpも同じ挙動 • この挙動は--reflinkオプションで変更できる 9