Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add compile option WITH_PMEM and runtime config enable_pmem #329

Merged
merged 3 commits into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 32 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@ jobs:
- name: Install packages
run: sudo apt install make clang-format-9 pkg-config g++ autoconf libtool asciidoctor libkmod-dev libudev-dev uuid-dev libjson-c-dev libkeyutils-dev pandoc libhwloc-dev libgflags-dev libtext-diff-perl bash-completion systemd wget git

- name: Init submodules
run: git submodule update --init --recursive

- name: Check codestyle & Build without libpmem
run: |
mkdir -p build && cd build
rm -rf ../build/*
cmake .. -DCMAKE_BUILD_TYPE=Debug -DCHECK_CPP_STYLE=ON -DWITH_JNI=ON -DWITH_PMEM=OFF
make -j

# # This requires AVX512 which is not supported by Github hosted runners
# - name: C++ unit tests without libpmem
# run: |
# export PMEM_IS_PMEM_FORCE=1
# ./tests/dbtest

- name: Install ndctl
run: |
cd /tmp; git clone https://github.com/pmem/ndctl.git; cd ndctl; git checkout v70.1
Expand All @@ -26,19 +42,26 @@ jobs:
cd /tmp; git clone https://github.com/pmem/pmdk.git; cd pmdk; git checkout 1.11.1
make -j && sudo make install

- name: Init submodules
run: git submodule update --init --recursive

- name: Check codestyle & Build
- name: Check codestyle & Build with libpmem
run: |
mkdir -p build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DCHECK_CPP_STYLE=ON -DWITH_JNI=ON
rm -rf ../build/*
cmake .. -DCMAKE_BUILD_TYPE=Debug -DCHECK_CPP_STYLE=ON -DWITH_JNI=ON -DWITH_PMEM=ON
make -j

# The example program requires AVX512 which is not supported by Github hosted runners
# - name: Run example
# # This requires AVX512 which is not supported by Github hosted runners
# - name: Run C++ examples
# run: |
# export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib:/usr/local/lib64
# export PMEM_IS_PMEM_FORCE=1
# sudo mkdir /mnt/pmem0
# ./build/examples/cpp_api_tutorial
# sudo mkdir -p /mnt/pmem0
# current_user=`whoami`
# echo $current_user
# sudo chown -R $current_user:$current_user /mnt/pmem0
# ./build/examples/tutorial/cpp_api_tutorial

# # This requires AVX512 which is not supported by Github hosted runners
# - name: Java unit tests
# run: |
# cd java
# mvn clean test
38 changes: 31 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,24 @@ if (COVERAGE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage -fprofile-arcs -ftest-coverage")
endif()

set (KVDK_SHARED_LIB_LINK_LIBS pthread gflags hwloc atomic)
set (KVDK_STATIC_LIB_LINK_LIBS ${KVDK_SHARED_LIB_LINK_LIBS})

option(WITH_PMEM "Build with libpmem to support persistent storage" ON)
if (WITH_PMEM)
message(STATUS "PMem support is enabled")
find_library(LIBPMEM_LIB pmem)
if(NOT LIBPMEM_LIB)
message(FATAL_ERROR "libpmem library not found")
else()
message(STATUS "Found libpmem: ${LIBPMEM_LIB}")
endif()
list(APPEND KVDK_SHARED_LIB_LINK_LIBS pmem)
add_compile_definitions(KVDK_WITH_PMEM)
else ()
message(STATUS "PMem support is disabled")
endif ()

# source files
set(SOURCES
engine/c/kvdk_basic_op.cpp
Expand Down Expand Up @@ -80,7 +98,7 @@ set(SOURCES
# .so library
add_library(engine SHARED ${SOURCES})
target_include_directories(engine PUBLIC ./include ./extern)
target_link_libraries(engine PUBLIC pthread pmem gflags hwloc atomic)
target_link_libraries(engine PUBLIC ${KVDK_SHARED_LIB_LINK_LIBS})

configure_file(kvdk.pc.in kvdk.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/kvdk.pc
Expand Down Expand Up @@ -164,10 +182,12 @@ if(WITH_JNI OR JNI)

include(FindPackageHandleStandardArgs)

find_library(LIBPMEM_STATIC_LIB NAMES "${CMAKE_STATIC_LIBRARY_PREFIX}pmem${CMAKE_STATIC_LIBRARY_SUFFIX}")
find_package_handle_standard_args(libpmem REQUIRED_VARS LIBPMEM_STATIC_LIB)
if(NOT libpmem_FOUND)
message(FATAL_ERROR "libpmem.a not found")
if(WITH_PMEM)
find_library(LIBPMEM_STATIC_LIB NAMES "${CMAKE_STATIC_LIBRARY_PREFIX}pmem${CMAKE_STATIC_LIBRARY_SUFFIX}")
find_package_handle_standard_args(libpmem REQUIRED_VARS LIBPMEM_STATIC_LIB)
if(NOT libpmem_FOUND)
message(FATAL_ERROR "libpmem.a not found")
endif()
endif()

find_library(ATOMIC_SHARED_LIB NAMES "${CMAKE_SHARED_LIBRARY_PREFIX}atomic${CMAKE_SHARED_LIBRARY_SUFFIX}.1")
Expand All @@ -184,9 +204,13 @@ if(WITH_JNI OR JNI)

add_library(${KVDK_STATIC_LIB} STATIC ${SOURCES})
target_include_directories(${KVDK_STATIC_LIB} PUBLIC ./include ./extern)
target_link_libraries(${KVDK_STATIC_LIB} PRIVATE ${LIBPMEM_STATIC_LIB})
target_link_libraries(${KVDK_STATIC_LIB} PRIVATE pthread gflags hwloc atomic)
target_link_libraries(${KVDK_STATIC_LIB} PRIVATE ${KVDK_STATIC_LIB_LINK_LIBS})
if(WITH_PMEM)
target_link_libraries(${KVDK_STATIC_LIB} PRIVATE ${LIBPMEM_STATIC_LIB})
endif()
set_property(TARGET ${KVDK_STATIC_LIB} PROPERTY POSITION_INDEPENDENT_CODE ON)


add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/java)

add_cppstyle(jni_src
Expand Down
3 changes: 2 additions & 1 deletion engine/alias.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ namespace KVDK_NAMESPACE {
enum class WriteOp { Put, Delete };

// Internal types
using PMemOffsetType = std::uint64_t;
using MemoryOffsetType = std::uint64_t;
using PMemOffsetType = MemoryOffsetType;
using TimestampType = std::uint64_t;

const uint64_t kMaxCachedOldRecords = 1024;
Expand Down