From eb1fe09eb038283a49109063c455d036b1fc2dc3 Mon Sep 17 00:00:00 2001 From: mou Date: Wed, 5 Apr 2023 15:33:40 +0800 Subject: [PATCH] set memory with mmap --- benchmarks/warm_benchmark.cpp | 10 +++++++--- rfaas/include/rfaas/rdma_allocator.hpp | 22 +++++++++++++++++++--- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/benchmarks/warm_benchmark.cpp b/benchmarks/warm_benchmark.cpp index ad45b6d..b323a18 100644 --- a/benchmarks/warm_benchmark.cpp +++ b/benchmarks/warm_benchmark.cpp @@ -71,13 +71,17 @@ int main(int argc, char ** argv) // FIXME: move me to a memory allocator rfaas::RdmaAllocator > rdmaAllocator(executor); - rdmalib::Buffer* in = rdmaAllocator.allocate(opts.input_size, IBV_ACCESS_LOCAL_WRITE, - rdmalib::functions::Submission::DATA_HEADER_SIZE); - rdmalib::Buffer* out = rdmaAllocator.allocate(opts.input_size, IBV_ACCESS_LOCAL_WRITE | IBV_ACCESS_REMOTE_WRITE); + rdmalib::Buffer* in = rdmaAllocator.allocate(opts.input_size); + rdmaAllocator.construct(in, IBV_ACCESS_LOCAL_WRITE); + rdmalib::Buffer* out = rdmaAllocator.allocate(opts.input_size); + rdmaAllocator.construct(out, IBV_ACCESS_LOCAL_WRITE | IBV_ACCESS_REMOTE_WRITE); // rdmalib::Buffer in(opts.input_size, rdmalib::functions::Submission::DATA_HEADER_SIZE), out(opts.input_size); // in.register_memory(executor._state.pd(), IBV_ACCESS_LOCAL_WRITE); // out.register_memory(executor._state.pd(), IBV_ACCESS_LOCAL_WRITE | IBV_ACCESS_REMOTE_WRITE); +// const rfaas::RdmaAllocator > &rdmaAllocator1 = rdmaAllocator; + std::vector, rfaas::RdmaAllocator>> v(8, rdmaAllocator); + // TODO: Since the for loop writes a value of 1 to each byte of the in buffer, // it overwrites all bytes previously set to 0 by the memset() function. memset(in->data(), 0, opts.input_size); diff --git a/rfaas/include/rfaas/rdma_allocator.hpp b/rfaas/include/rfaas/rdma_allocator.hpp index de1d30b..78f8032 100644 --- a/rfaas/include/rfaas/rdma_allocator.hpp +++ b/rfaas/include/rfaas/rdma_allocator.hpp @@ -5,6 +5,7 @@ #ifndef __RFAAS_RDMA_ALLOCATOR_HPP__ #define __RFAAS_RDMA_ALLOCATOR_HPP__ +#include #include #include #include @@ -20,19 +21,34 @@ namespace rfaas { template constexpr RdmaAllocator(const RdmaAllocator &) noexcept {} - [[nodiscard]] inline T *allocate(const std::size_t &size, const int &access, int header = 0) { + [[nodiscard]] inline T *allocate(const size_t &size) { if (size > std::numeric_limits::max() / sizeof(T)) throw std::bad_array_new_length(); // Maybe we could directly call the memset function here - if (auto buffer = new rdmalib::Buffer(size, header)) { + mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); + if (auto buffer = static_cast(std::malloc(size * sizeof(T)))){ report(buffer, size); - buffer->register_memory(_executor._state.pd(), access); return buffer; } throw std::bad_alloc(); } + template + void construct (U* p, arg1 access) + { + std::cout << "constructor" << std::endl; + p->register_memory(_executor._state.pd(), access); + } + + template + void construct (U* p, arg1 access, arg2 head) + { + std::cout << "constructor" << std::endl; + p->register_memory(_executor._state.pd(), access, head); + } +// [[nodiscard]] inline T *construct(const std::size_t &size, const int &access, int header = 0) { + inline void deallocate(T *p, std::size_t size) noexcept { report(p, size, 0); std::free(p);