2 * Copyright 2017 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.
20 #include <sys/types.h>
26 #include <boost/operators.hpp>
28 #include <folly/Range.h>
29 #include <folly/experimental/io/FsUtil.h>
30 #include <folly/portability/Unistd.h>
34 struct HugePageSize : private boost::totally_ordered<HugePageSize> {
35 explicit HugePageSize(size_t s) : size(s) { }
37 fs::path filePath(const fs::path& relpath) const {
38 return mountPoint / relpath;
46 inline bool operator<(const HugePageSize& a, const HugePageSize& b) {
47 return a.size < b.size;
50 inline bool operator==(const HugePageSize& a, const HugePageSize& b) {
51 return a.size == b.size;
55 * Vector of (huge_page_size, mount_point), sorted by huge_page_size.
56 * mount_point might be empty if no hugetlbfs file system is mounted for
59 typedef std::vector<HugePageSize> HugePageSizeVec;
62 * Get list of supported huge page sizes and their mount points, if
63 * hugetlbfs file systems are mounted for those sizes.
65 const HugePageSizeVec& getHugePageSizes();
68 * Return the mount point for the requested huge page size.
69 * 0 = use smallest available.
70 * Returns nullptr if the requested huge page size is not available.
72 const HugePageSize* getHugePageSize(size_t size = 0);
75 * Return the huge page size for a device.
76 * returns nullptr if device does not refer to a huge page filesystem.
78 const HugePageSize* getHugePageSizeForDevice(dev_t device);