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_
25 #include <boost/operators.hpp>
27 #include "folly/Range.h"
28 #include "folly/experimental/io/FsUtil.h"
32 struct HugePageSize : private boost::totally_ordered<HugePageSize> {
33 HugePageSize() : size(0) { }
34 explicit HugePageSize(size_t s) : size(s) { }
39 inline bool operator<(const HugePageSize& a, const HugePageSize& b) {
40 return a.size < b.size;
43 inline bool operator==(const HugePageSize& a, const HugePageSize& b) {
44 return a.size == b.size;
48 * Vector of (huge_page_size, mount_point), sorted by huge_page_size.
49 * mount_point might be empty if no hugetlbfs file system is mounted for
52 typedef std::vector<HugePageSize> HugePageSizeVec;
55 * Class to interface with Linux huge pages (hugetlbfs).
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& sizes() const { return sizes_; }
68 * Return the mount point for the requested huge page size.
69 * 0 = use smallest available.
72 const HugePageSize& getSize(size_t hugePageSize = 0) const;
75 * Create a file on a huge page filesystem containing a copy of the data
76 * from data. If multiple huge page sizes are allowed, we
77 * pick the smallest huge page size available, unless you request one
78 * explicitly with the hugePageSize argument.
80 * The "path" argument must be rooted under the mount point for the
81 * selected huge page size. If relative, it is considered relative to the
84 * We return a struct File structure containing the full path and size
85 * (rounded up to a multiple of the huge page size)
93 ByteRange data, const fs::path& path,
94 HugePageSize hugePageSize = HugePageSize()) const;
97 HugePageSizeVec sizes_;
102 #endif /* FOLLY_IO_HUGEPAGES_H_ */