2 * Copyright 2014 Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef FOLLY_IO_HUGEPAGES_H_
18 #define FOLLY_IO_HUGEPAGES_H_
21 #include <sys/types.h>
28 #include <boost/operators.hpp>
30 #include <folly/Range.h>
31 #include <folly/experimental/io/FsUtil.h>
35 struct HugePageSize : private boost::totally_ordered<HugePageSize> {
36 explicit HugePageSize(size_t s) : size(s) { }
38 fs::path filePath(const fs::path& relpath) const {
39 return mountPoint / relpath;
47 inline bool operator<(const HugePageSize& a, const HugePageSize& b) {
48 return a.size < b.size;
51 inline bool operator==(const HugePageSize& a, const HugePageSize& b) {
52 return a.size == b.size;
56 * Vector of (huge_page_size, mount_point), sorted by huge_page_size.
57 * mount_point might be empty if no hugetlbfs file system is mounted for
60 typedef std::vector<HugePageSize> HugePageSizeVec;
63 * Get list of supported huge page sizes and their mount points, if
64 * hugetlbfs file systems are mounted for those sizes.
66 const HugePageSizeVec& getHugePageSizes();
69 * Return the mount point for the requested huge page size.
70 * 0 = use smallest available.
71 * Returns nullptr if the requested huge page size is not available.
73 const HugePageSize* getHugePageSize(size_t size = 0);
76 * Return the huge page size for a device.
77 * returns nullptr if device does not refer to a huge page filesystem.
79 const HugePageSize* getHugePageSizeForDevice(dev_t device);
83 #endif /* FOLLY_IO_HUGEPAGES_H_ */