XMLWordPrintable

    • b14
    • x86_64, aarch64
    • linux

      A DESCRIPTION OF THE PROBLEM :
      Modern Linux file systems like XFS, BTRFS and so on support copy-on-write for files. A file copy made using this support to a destination on the same filesystem completes "instantly" and uses no additional disk space. If/when the new or old copy is changed, only then will disk space used go up. This differs from hard-linking because the new file is indistinguishable from a unique, independent file save for the effects on disk space.

      Ref-linking is basically always a superior option for file copies when available. For this reason coreutils changed the default for the GNU "cp" command in June 2020, with the remark that it was "long overdue":

      https://github.com/coreutils/coreutils/commit/25725f9d41735d176d73a757430739fb71c7d043

      Although there was an argument that changing the default in this way may cause problems due to the altered rules around disk space usage, it was eventually decided that the huge speed and storage improvements this feature makes available outweighed it. Given the default copy behavior for Linux shell scripts is now to reflink when possible, Java should follow and do the same thing.

      The underlying kernel API is calling ioctl(FICLONE) as can be seen here:

      https://github.com/coreutils/coreutils/blob/e3766c5db176ca7abbb8212d5b0b7862fb98a5be/src/copy.c#L405

      A reasonable implementation might be to introduce a new StandardCopyOption called ALWAYS_DUPLICATE. When not specified, COW is used if possible. If specified, COW will never be used, even on a system that supports it. The new behaviour could also be controlled using a system property. This would be backwards compatible and allow apps to opt-out if for some reason it's very important to them that COW not be used (e.g. they want to be sure there will be sufficient free disk space to rewrite the file in place, up front).


            bpb Brian Burkhalter
            webbuggrp Webbug Group
            Votes:
            1 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: