Skip to content

Commit

Permalink
set memory with mmap
Browse files Browse the repository at this point in the history
  • Loading branch information
mou authored and mou committed Apr 5, 2023
1 parent 889333e commit eb1fe09
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
10 changes: 7 additions & 3 deletions benchmarks/warm_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,17 @@ int main(int argc, char ** argv)
// FIXME: move me to a memory allocator

rfaas::RdmaAllocator<rdmalib::Buffer<char> > rdmaAllocator(executor);
rdmalib::Buffer<char>* in = rdmaAllocator.allocate(opts.input_size, IBV_ACCESS_LOCAL_WRITE,
rdmalib::functions::Submission::DATA_HEADER_SIZE);
rdmalib::Buffer<char>* out = rdmaAllocator.allocate(opts.input_size, IBV_ACCESS_LOCAL_WRITE | IBV_ACCESS_REMOTE_WRITE);
rdmalib::Buffer<char>* in = rdmaAllocator.allocate(opts.input_size);
rdmaAllocator.construct(in, IBV_ACCESS_LOCAL_WRITE);
rdmalib::Buffer<char>* out = rdmaAllocator.allocate(opts.input_size);
rdmaAllocator.construct(out, IBV_ACCESS_LOCAL_WRITE | IBV_ACCESS_REMOTE_WRITE);
// rdmalib::Buffer<char> 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<rdmalib::Buffer<char> > &rdmaAllocator1 = rdmaAllocator;
std::vector<rdmalib::Buffer<char>, rfaas::RdmaAllocator<rdmalib::Buffer<char>>> 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);
Expand Down
22 changes: 19 additions & 3 deletions rfaas/include/rfaas/rdma_allocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#ifndef __RFAAS_RDMA_ALLOCATOR_HPP__
#define __RFAAS_RDMA_ALLOCATOR_HPP__

#include <sys/mman.h>
#include <cstddef>
#include <rdmalib/buffer.hpp>
#include <rfaas/executor.hpp>
Expand All @@ -20,19 +21,34 @@ namespace rfaas {
template<class U>
constexpr RdmaAllocator(const RdmaAllocator<U> &) 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<std::size_t>::max() / sizeof(T))
throw std::bad_array_new_length();

// Maybe we could directly call the memset function here
if (auto buffer = new rdmalib::Buffer<char>(size, header)) {
mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
if (auto buffer = static_cast<T*>(std::malloc(size * sizeof(T)))){
report(buffer, size);
buffer->register_memory(_executor._state.pd(), access);
return buffer;
}
throw std::bad_alloc();
}

template <class U, class arg1>
void construct (U* p, arg1 access)
{
std::cout << "constructor" << std::endl;
p->register_memory(_executor._state.pd(), access);
}

template <class U, class arg1 , class arg2>
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);
Expand Down

0 comments on commit eb1fe09

Please sign in to comment.