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 <folly/Format.h>
21 #include <folly/MemoryMapping.h>
22 #include <folly/Range.h>
23 #include <folly/experimental/io/HugePages.h>
24 #include <folly/portability/GFlags.h>
26 DEFINE_bool(cp, false, "Copy file");
28 using namespace folly;
32 [[noreturn]] void usage(const char* name) {
33 std::cerr << folly::format(
35 " list all huge page sizes and their mount points\n"
36 " {0} -cp <src_file> <dest_nameprefix>\n"
37 " copy src_file to a huge page file\n",
42 void copy(const char* srcFile, const char* dest) {
43 fs::path destPath(dest);
44 if (!destPath.is_absolute()) {
45 auto hp = getHugePageSize();
46 CHECK(hp) << "no huge pages available";
47 destPath = fs::canonical_parent(destPath, hp->mountPoint);
50 mmapFileCopy(srcFile, destPath.c_str());
54 for (const auto& p : getHugePageSizes()) {
55 std::cout << p.size << " " << p.mountPoint << "\n";
61 int main(int argc, char* argv[]) {
62 gflags::ParseCommandLineFlags(&argc, &argv, true);
67 copy(argv[1], argv[2]);