From bcabde67531bda3abd3b81aab12d87ed154fdb45 Mon Sep 17 00:00:00 2001 From: Petros Angelatos Date: Sun, 8 Oct 2017 15:26:23 -0700 Subject: [PATCH] pkg/archive: sync files before issuing the fadvise syscall 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 --- pkg/archive/archive.go | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/pkg/archive/archive.go b/pkg/archive/archive.go index 5765a24506..ee599f3244 100644 --- a/pkg/archive/archive.go +++ b/pkg/archive/archive.go @@ -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: @@ -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 }