/*
- * Copyright 2013 Facebook, Inc.
+ * Copyright 2012-present Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* limitations under the License.
*/
-#ifndef FOLLY_IO_HUGEPAGES_H_
-#define FOLLY_IO_HUGEPAGES_H_
+#pragma once
+#include <sys/stat.h>
+#include <sys/types.h>
#include <cstddef>
#include <string>
#include <utility>
#include <boost/operators.hpp>
-#include "folly/Range.h"
-#include "folly/experimental/io/FsUtil.h"
+#include <folly/Range.h>
+#include <folly/experimental/io/FsUtil.h>
+#include <folly/portability/Unistd.h>
namespace folly {
struct HugePageSize : private boost::totally_ordered<HugePageSize> {
- HugePageSize() : size(0) { }
- explicit HugePageSize(size_t s) : size(s) { }
- size_t size;
+ explicit HugePageSize(size_t s) : size(s) {}
+
+ 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) {
typedef std::vector<HugePageSize> 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_; }
+const HugePageSizeVec& getHugePageSizes();
- /**
- * 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_;
-};
-
-} // namespace folly
+/**
+ * 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);
-#endif /* FOLLY_IO_HUGEPAGES_H_ */
+/**
+ * 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