remove eof whitespace lines
[folly.git] / folly / experimental / io / HugePages.h
index 321024c9dc8a314d13be7688f978b43a748d9747..3e5a7b59351cb3398aee41fdbfde3cac1d4b47be 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2012 Facebook, Inc.
+ * Copyright 2014 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 #ifndef FOLLY_IO_HUGEPAGES_H_
 #define FOLLY_IO_HUGEPAGES_H_
 
+#include <sys/stat.h>
+#include <sys/types.h>
 #include <cstddef>
 #include <string>
+#include <unistd.h>
 #include <utility>
 #include <vector>
 
 #include <boost/operators.hpp>
 
-#include "folly/Range.h"
-#include "folly/experimental/io/FsUtil.h"
+#include <folly/Range.h>
+#include <folly/experimental/io/FsUtil.h>
 
 namespace folly {
 
 struct HugePageSize : private boost::totally_ordered<HugePageSize> {
-  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,52 +60,24 @@ 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_; }
-
-  /**
-   * 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
 
 #endif /* FOLLY_IO_HUGEPAGES_H_ */
-