Skip to content

Commit

Permalink
pkg/archive: sync files before issuing the fadvise syscall
Browse files Browse the repository at this point in the history
Linux ignores fadvise for dirty pages so we need to make sure we sync to
have them marked as clean before discarding

Ref: https://github.com/torvalds/linux/blob/v4.13/mm/truncate.c#L489-L493

Signed-off-by: Petros Angelatos <petrosagg@gmail.com>
  • Loading branch information
petrosagg committed Oct 13, 2017
1 parent eeead5b commit bcabde6
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions pkg/archive/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,17 @@ func createTarFile(path, extractDir string, hdr *tar.Header, reader io.Reader, L
file.Close()
return err
}

if err := file.Sync(); err != nil {
file.Close()
return err
}

if err := unix.Fadvise(int(file.Fd()), 0, 0, unix.FADV_DONTNEED); err != nil {
file.Close()
return err
}

file.Close()

case tar.TypeBlock, tar.TypeChar:
Expand Down Expand Up @@ -624,19 +635,6 @@ func createTarFile(path, extractDir string, hdr *tar.Header, reader io.Reader, L
}
}

if hdr.Typeflag == tar.TypeReg || hdr.Typeflag == tar.TypeRegA {
file, err := os.Open(path)
if err != nil {
file.Close()
return err
}
if err := unix.Fadvise(int(file.Fd()), 0, 0, unix.FADV_DONTNEED); err != nil {
file.Close()
return err
}
file.Close()
}

return nil
}

Expand Down

0 comments on commit bcabde6

Please sign in to comment.