diff options
Diffstat (limited to 'vespamalloc/src/vespamalloc/util/osmem.h')
-rw-r--r-- | vespamalloc/src/vespamalloc/util/osmem.h | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/vespamalloc/src/vespamalloc/util/osmem.h b/vespamalloc/src/vespamalloc/util/osmem.h new file mode 100644 index 00000000000..f5c51c2000d --- /dev/null +++ b/vespamalloc/src/vespamalloc/util/osmem.h @@ -0,0 +1,54 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#pragma once + +#include <ctype.h> +#include <stdlib.h> +#include <unistd.h> +#include <assert.h> +#include <string.h> +#include <algorithm> + +namespace vespamalloc { + +class Memory +{ +public: + Memory(size_t blockSize) : _blockSize(std::max(blockSize, size_t(getpagesize()))), _start(NULL), _end(NULL) { } + virtual ~Memory() { } + void * getStart() const { return _start; } + void * getEnd() const { return _end; } + size_t getMinBlockSize() const { return _blockSize; } + static size_t getMinPreferredStartAddress() { return 0x10000000000; } // 1T + static size_t getBlockAlignment() { return 0x200000; } //2M +protected: + void setStart(void * v) { _start = v; } + void setEnd(void * v) { _end = v; } + size_t _blockSize; + void * _start; + void * _end; +}; + +class MmapMemory : public Memory +{ +public: + MmapMemory(size_t blockSize); + virtual ~MmapMemory(); + void *reserve(size_t & len); + void *get(size_t len); + bool release(void * mem, size_t len); + bool reclaim(void * mem, size_t len); + bool freeTail(void * mem, size_t len); +private: + void * getHugePages(size_t len); + void * getNormalPages(size_t len); + void * getBasePages(size_t len, int mmapOpt, int fd, size_t offset); + void setupFAdvise(); + void setupHugePages(); + size_t _useMAdvLimit; + int _hugePagesFd; + size_t _hugePagesOffset; + size_t _hugePageSize; + char _hugePagesFileName[256]; +}; + +} |