remove eof whitespace lines
[folly.git] / folly / experimental / io / HugePages.h
index 6ec6a1faf64ed63c572f569c83c5bb89fd6a1459..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.
 
 #include <sys/stat.h>
 #include <sys/types.h>
-#include <fcntl.h>
-
 #include <cstddef>
 #include <string>
+#include <unistd.h>
 #include <utility>
 #include <vector>
 
-#include "folly/Range.h"
+#include <boost/operators.hpp>
+
+#include <folly/Range.h>
+#include <folly/experimental/io/FsUtil.h>
 
 namespace folly {
 
+struct HugePageSize : private boost::totally_ordered<HugePageSize> {
+  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) {
+  return a.size < b.size;
+}
+
+inline bool operator==(const HugePageSize& a, const HugePageSize& b) {
+  return a.size == b.size;
+}
+
 /**
  * Vector of (huge_page_size, mount_point), sorted by huge_page_size.
  * mount_point might be empty if no hugetlbfs file system is mounted for
  * that size.
  */
-typedef std::vector<std::pair<size_t, std::string>> HugePageSizeVec;
+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_; }
-
-  /**
-   * 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.
-   *
-   * We return a struct File structure containing the full path and size
-   * (rounded up to a multiple of the huge page size)
-   */
-  struct File {
-    std::string path;
-    size_t size;
-  };
-  File create(
-      ByteRange data, StringPiece baseName, size_t hugePageSize = 0,
-      mode_t mode = 0644) 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_ */
-