diff --git a/configure.ac b/configure.ac index 0afe270df..4a29b2195 100644 --- a/configure.ac +++ b/configure.ac @@ -1188,6 +1188,7 @@ AC_CHECK_FUNCS([ \ mlock \ mlock2 \ mmap \ + msync \ posix_fadvise \ posix_madvise \ preadv2 \ diff --git a/include/ircd/allocator.h b/include/ircd/allocator.h index ccc19abbf..0b0e20568 100644 --- a/include/ircd/allocator.h +++ b/include/ircd/allocator.h @@ -50,6 +50,8 @@ namespace ircd::allocator size_t advise(const const_buffer &, const int &); size_t prefetch(const const_buffer &); size_t evict(const const_buffer &); + size_t flush(const const_buffer &, const bool invd = false); + size_t sync(const const_buffer &, const bool invd = false); void protect(const const_buffer &, const bool = true); void readonly(const mutable_buffer &, const bool = true); diff --git a/ircd/allocator.cc b/ircd/allocator.cc index 8ec22ef3d..16f8983b0 100644 --- a/ircd/allocator.cc +++ b/ircd/allocator.cc @@ -165,6 +165,46 @@ ircd::allocator::protect(const const_buffer &buf, sys::call(::mprotect, ptr, size(buf), prot); } +size_t +ircd::allocator::sync(const const_buffer &buf, + const bool invd) +{ + assert(aligned(data(buf), info::page_size)); + const prof::syscall_usage_warning message + { + "msync(2) MS_SYNC MS_INVALIDATE:%b", invd + }; + + #if defined(HAVE_MSYNC) + int flags {MS_SYNC}; + flags |= invd? MS_INVALIDATE: 0; + sys::call(::msync, mutable_cast(data(buf)), size(buf), flags); + return size(buf); + #else + return 0; + #endif +} + +size_t +ircd::allocator::flush(const const_buffer &buf, + const bool invd) +{ + assert(aligned(data(buf), info::page_size)); + const prof::syscall_usage_warning message + { + "msync(2) MS_ASYNC MS_INVALIDATE:%b", invd + }; + + #if defined(HAVE_MSYNC) + int flags {MS_ASYNC}; + flags |= invd? MS_INVALIDATE: 0; + sys::call(::msync, mutable_cast(data(buf)), size(buf), flags); + return size(buf); + #else + return 0; + #endif +} + size_t ircd::allocator::evict(const const_buffer &buf) {