From 1a1fa06aa36b6da41d31a375a0958a6955779826 Mon Sep 17 00:00:00 2001 From: Antonio SJ Musumeci Date: Tue, 11 Apr 2017 09:02:05 -0400 Subject: [PATCH] fadvise cleanup --- src/fs_base_fadvise.cpp | 27 +++++++++++++++++++++++++++ src/fs_base_fadvise.hpp | 15 +++++++++++++++ src/fs_clonefile.cpp | 4 ++-- src/release.cpp | 4 ++-- 4 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/fs_base_fadvise.cpp b/src/fs_base_fadvise.cpp index e276d8ff..31d77537 100644 --- a/src/fs_base_fadvise.cpp +++ b/src/fs_base_fadvise.cpp @@ -21,3 +21,30 @@ #else # include "fs_base_fadvise_unsupported.icpp" #endif + +namespace fs +{ + int + fadvise_dontneed(const int fd, + const off_t offset, + const off_t len) + { + return fs::fadvise(fd,offset,len,POSIX_FADV_DONTNEED); + } + + int + fadvise_willneed(const int fd, + const off_t offset, + const off_t len) + { + return fs::fadvise(fd,offset,len,POSIX_FADV_WILLNEED); + } + + int + fadvise_sequential(const int fd, + const off_t offset, + const off_t len) + { + return fs::fadvise(fd,offset,len,POSIX_FADV_SEQUENTIAL); + } +} diff --git a/src/fs_base_fadvise.hpp b/src/fs_base_fadvise.hpp index 28459d43..4d6910a1 100644 --- a/src/fs_base_fadvise.hpp +++ b/src/fs_base_fadvise.hpp @@ -48,6 +48,21 @@ namespace fs const off_t offset, const off_t len, const int advice); + + int + fadvise_dontneed(const int fd, + const off_t offset = 0, + const off_t len = 0); + + int + fadvise_willneed(const int fd, + const off_t offset = 0, + const off_t len = 0); + + int + fadvise_sequential(const int fd, + const off_t offset = 0, + const off_t len = 0); } #endif // __FS_FADVISE_HPP__ diff --git a/src/fs_clonefile.cpp b/src/fs_clonefile.cpp index ca33b607..68c014f8 100644 --- a/src/fs_clonefile.cpp +++ b/src/fs_clonefile.cpp @@ -122,8 +122,8 @@ copydata(const int fdin, { int rv; - fs::fadvise(fdin,0,count,POSIX_FADV_WILLNEED); - fs::fadvise(fdin,0,count,POSIX_FADV_SEQUENTIAL); + fs::fadvise_willneed(fdin,0,count); + fs::fadvise_sequential(fdin,0,count); fs::fallocate(fdout,0,0,count); diff --git a/src/release.cpp b/src/release.cpp index 63cf3fc2..447e65ec 100644 --- a/src/release.cpp +++ b/src/release.cpp @@ -33,8 +33,8 @@ _release(FileInfo *fi, // https://github.com/Feh/nocache if(dropcacheonclose) { - fs::fadvise(fi->fd,0,0,POSIX_FADV_DONTNEED); - fs::fadvise(fi->fd,0,0,POSIX_FADV_DONTNEED); + fs::fadvise_dontneed(fi->fd); + fs::fadvise_dontneed(fi->fd); } fs::close(fi->fd);