X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2Fexperimental%2Fio%2FHugePages.h;h=dcf07e7c06021da1a04cd2f84c5dd943a16542a6;hb=7fda1f29212ba8402e8b43c08e1c66dd1e8e7c95;hp=ef7dcffae79b236b51b75ed74e57ee9d624a6e96;hpb=30be8ac1ced8cb583ed9ac1d894506341e7c77d1;p=folly.git diff --git a/folly/experimental/io/HugePages.h b/folly/experimental/io/HugePages.h index ef7dcffa..dcf07e7c 100644 --- a/folly/experimental/io/HugePages.h +++ b/folly/experimental/io/HugePages.h @@ -17,8 +17,11 @@ #ifndef FOLLY_IO_HUGEPAGES_H_ #define FOLLY_IO_HUGEPAGES_H_ +#include +#include #include #include +#include #include #include @@ -30,10 +33,15 @@ namespace folly { struct HugePageSize : private boost::totally_ordered { - HugePageSize() : size(0) { } explicit HugePageSize(size_t s) : size(s) { } - size_t size; + + fs::path filePath(const fs::path& relpath) const { + return mountPoint / relpath; + } + + size_t size = 0; fs::path mountPoint; + dev_t device = 0; }; inline bool operator<(const HugePageSize& a, const HugePageSize& b) { @@ -52,50 +60,23 @@ inline bool operator==(const HugePageSize& a, const HugePageSize& b) { typedef std::vector HugePageSizeVec; /** - * Class to interface with Linux huge pages (hugetlbfs). + * Get list of supported huge page sizes and their mount points, if + * hugetlbfs file systems are mounted for those sizes. */ -class HugePages { - public: - HugePages(); - - /** - * Get list of supported huge page sizes and their mount points, if - * hugetlbfs file systems are mounted for those sizes. - */ - const HugePageSizeVec& sizes() const { return sizes_; } - - /** - * Return the mount point for the requested huge page size. - * 0 = use smallest available. - * Throws on error. - */ - const HugePageSize& getSize(size_t hugePageSize = 0) const; - - /** - * Create a file on a huge page filesystem containing a copy of the data - * from data. If multiple huge page sizes are allowed, we - * pick the smallest huge page size available, unless you request one - * explicitly with the hugePageSize argument. - * - * The "path" argument must be rooted under the mount point for the - * selected huge page size. If relative, it is considered relative to the - * mount point. - * - * We return a struct File structure containing the full path and size - * (rounded up to a multiple of the huge page size) - */ - struct File { - File() : size(0) { } - fs::path path; - size_t size; - }; - File create( - ByteRange data, const fs::path& path, - HugePageSize hugePageSize = HugePageSize()) const; - - private: - HugePageSizeVec sizes_; -}; +const HugePageSizeVec& getHugePageSizes(); + +/** + * Return the mount point for the requested huge page size. + * 0 = use smallest available. + * Returns nullptr if the requested huge page size is not available. + */ +const HugePageSize* getHugePageSize(size_t size = 0); + +/** + * Return the huge page size for a device. + * returns nullptr if device does not refer to a huge page filesystem. + */ +const HugePageSize* getHugePageSizeForDevice(dev_t device); } // namespace folly