Files
scylladb/core/memory.hh
Avi Kivity 4453fd1d6a memory: add support for allocating memory via hugetlbfs
This is a little tricky, since we only know we want hugetlbfs after memory
has been initialized, so we start up in anonymous memory, and later
switch to hugetlbfs by copying it to hugetlb-backed memory and mremap()ing
it back into place.
2014-12-11 12:25:31 +02:00

57 lines
1.3 KiB
C++

/*
* Copyright (C) 2014 Cloudius Systems, Ltd.
*/
#ifndef MEMORY_HH_
#define MEMORY_HH_
#include "resource.hh"
#include <new>
#include <functional>
#include <vector>
namespace memory {
void configure(std::vector<resource::memory> m,
std::experimental::optional<std::string> hugetlbfs_path = {});
void* allocate_reclaimable(size_t size);
class reclaimer {
std::function<void ()> _reclaim;
public:
reclaimer(std::function<void ()> reclaim);
~reclaimer();
void do_reclaim() { _reclaim(); }
};
// We don't want the memory code calling back into the rest of
// the system, so allow the rest of the system to tell the memory
// code how to initiate reclaim.
//
// When memory is low, calling hook(fn) will result in fn being called
// in a safe place wrt. allocations.
void set_reclaim_hook(
std::function<void (std::function<void ()>)> hook);
class statistics;
statistics stats();
class statistics {
uint64_t _mallocs;
uint64_t _frees;
private:
statistics(uint64_t mallocs, uint64_t frees)
: _mallocs(mallocs), _frees(frees) {}
public:
uint64_t mallocs() const { return _mallocs; }
uint64_t frees() const { return _frees; }
size_t live_objects() const { return mallocs() - frees(); }
friend statistics stats();
};
}
#endif /* MEMORY_HH_ */