From daaa881cfe3466c298fa44812b8477a23d25b756 Mon Sep 17 00:00:00 2001 From: Sergey Vojtovich Date: Tue, 4 Feb 2020 22:30:08 +0400 Subject: [PATCH] libpmem cmake macros Also added support for MAP_SYNC. It allows to achieve decent performance with DAX devices even when libpmem is unavailable. Fixed Windows version of my_msync(): according to manual FlushViewOfFile() may return before flush is actually completed. It is advised to issue FlushFileBuffers() after FlushViewOfFile(). --- CMakeLists.txt | 1 + cmake/pmem.cmake | 13 +++++++++++++ include/my_sys.h | 7 +++++++ mysys/my_mmap.c | 19 ++++++++++++++++++- 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 cmake/pmem.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index ce5b45aaae1..cf8b42d0430 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -168,6 +168,7 @@ INCLUDE(mysql_add_executable) INCLUDE(symlinks) INCLUDE(compile_flags) INCLUDE(crc32) +INCLUDE(pmem) # Handle options OPTION(DISABLE_SHARED diff --git a/cmake/pmem.cmake b/cmake/pmem.cmake new file mode 100644 index 00000000000..b59db3cc1f9 --- /dev/null +++ b/cmake/pmem.cmake @@ -0,0 +1,13 @@ +INCLUDE(CheckIncludeFiles) +OPTION(WITH_PMEM "Enable persistent memory features" OFF) +IF(WITH_PMEM) + FIND_LIBRARY(LIBPMEM pmem) + CHECK_INCLUDE_FILES(libpmem.h HAVE_LIBPMEM_H) + IF (NOT LIBPMEM) + MESSAGE(FATAL_ERROR "Can't find libpmem") + ELSEIF(NOT HAVE_LIBPMEM_H) + MESSAGE(FATAL_ERROR "Can't find libpmem.h") + ELSE() + ADD_DEFINITIONS(-DHAVE_PMEM) + ENDIF() +ENDIF() diff --git a/include/my_sys.h b/include/my_sys.h index f20bbc700b3..c2ba72b4d66 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -964,6 +964,13 @@ extern ulonglong my_getcputime(void); #define available_stack_size(CUR,END) (long) ((char*)(END) - (char*)(CUR)) #endif +#ifndef MAP_SYNC +#define MAP_SYNC 0x80000 +#endif +#ifndef MAP_SHARED_VALIDATE +#define MAP_SHARED_VALIDATE 0x03 +#endif + #ifdef HAVE_SYS_MMAN_H #ifndef MAP_NOSYNC #define MAP_NOSYNC 0 diff --git a/mysys/my_mmap.c b/mysys/my_mmap.c index 9d84c1c76f6..e04f4addd3d 100644 --- a/mysys/my_mmap.c +++ b/mysys/my_mmap.c @@ -29,6 +29,10 @@ int my_msync(int fd, void *addr, size_t len, int flags) #elif defined(_WIN32) +#ifndef FILE_DAX_VOLUME +#define FILE_DAX_VOLUME 0x20000000 +#endif + static SECURITY_ATTRIBUTES mmap_security_attributes= {sizeof(SECURITY_ATTRIBUTES), 0, TRUE}; @@ -61,6 +65,18 @@ void *my_mmap(void *addr, size_t len, int prot, */ CloseHandle(hFileMap); + if (flags & MAP_SYNC) + { + DWORD filesystemFlags; + if (!GetVolumeInformationByHandleW(hFile, NULL, 0, NULL, NULL, + &filesystemFlags, NULL, 0) || + !(filesystemFlags & FILE_DAX_VOLUME)) + { + UnmapViewOfFile(ptr); + ptr= NULL; + } + } + if (ptr) { DBUG_PRINT("mysys", ("mapped addr: %p", ptr)); @@ -79,7 +95,8 @@ int my_munmap(void *addr, size_t len) int my_msync(int fd, void *addr, size_t len, int flags) { - return FlushViewOfFile(addr, len) ? 0 : -1; + return FlushViewOfFile(addr, len) && + FlushFileBuffers(my_get_osfhandle(fd)) ? 0 : -1; } #else