Commit ab237321 authored by Tiancong Wang's avatar Tiancong Wang Committed by Commit Bot

Only use hugepage when orderfile is present on Chrome OS

This patches removes old hugepage mechanism that works without
orderfiles. So now, enabling orderfile == enabling THP.

Bug: 1100803
Test: Build chrome os locally
Change-Id: Ib4ff215b10ccc4c3c51347357a0cba7f51ec6793
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2369335
Commit-Queue: Tiancong Wang <tcwang@google.com>
Reviewed-by: default avatarGeorge Burgess <gbiv@chromium.org>
Cr-Commit-Position: refs/heads/master@{#800740}
parent 297abb5a
......@@ -16,12 +16,7 @@
#include "base/logging.h"
// CHROMEOS_ORDERFILE_USE is a flag intended to use orderfile
// to link Chrome. The else part of macro check in this code is to
// make sure when the flag is turned off, the code works the same
// as before.
// We plan to turn it on in the future for Chrome OS.
// Therefore, before it's deployed, by default, we turn it off until
// the testing is done.
// to link Chrome. Only when orderfile is used, we will use hugepages.
// These function are here to delimit the start and end of the symbols
// ordered by orderfile.
......@@ -56,6 +51,12 @@ namespace chromeos {
#define MADV_HUGEPAGE 14
#endif
#ifdef CHROMEOS_ORDERFILE_USE
constexpr static bool kIsOrderfileEnabled = true;
#else
constexpr static bool kIsOrderfileEnabled = false;
#endif
const base::Feature kCrOSHugepageRemapAndLockZygote{
"CrOSHugepageRemapAndLockInZygote", base::FEATURE_ENABLED_BY_DEFAULT};
......@@ -219,39 +220,6 @@ static void RemapHugetlbTextWithOrderfileLayout(void* vaddr,
MremapHugetlbText(reinterpret_cast<void*>(mapping_start), hsize);
}
// Top level text remapping function, without orderfile (old code).
//
// Inputs: vaddr, the starting virtual address to remap to hugepage
// segsize, size of the memory segment to remap in bytes
// Return: none
// Effect: physical backing page changed from small page to hugepage. If there
// are error condition, the remaping operation is aborted.
static void RemapHugetlbTextWithoutOrderfileLayout(void* vaddr,
const size_t segsize) {
// The number of hugepages to use if no orderfile is specified
const int kNumHugePages = 15;
// remove unaligned head regions
uintptr_t head_gap =
(kHpageSize - reinterpret_cast<uintptr_t>(vaddr) % kHpageSize) %
kHpageSize;
uintptr_t addr = reinterpret_cast<uintptr_t>(vaddr) + head_gap;
if (segsize < head_gap)
return;
size_t hsize = segsize - head_gap;
hsize = hsize & kHpageMask;
if (hsize > kHpageSize * kNumHugePages)
hsize = kHpageSize * kNumHugePages;
if (hsize == 0)
return;
MremapHugetlbText(reinterpret_cast<void*>(addr), hsize);
}
// For a given ELF program header descriptor, iterates over all segments within
// it and find the first segment that has PT_LOAD and is executable, call
// RemapHugetlbText().
......@@ -277,16 +245,7 @@ static int FilterElfHeader(struct dl_phdr_info* info, size_t size, void* data) {
info->dlpi_phdr[i].p_flags == (PF_R | PF_X)) {
vaddr = bit_cast<void*>(info->dlpi_addr + info->dlpi_phdr[i].p_vaddr);
segsize = info->dlpi_phdr[i].p_filesz;
// The following function is conditionally compiled, so use
// the statements to avoid compiler warnings of unused functions
(void)RemapHugetlbTextWithOrderfileLayout;
(void)RemapHugetlbTextWithoutOrderfileLayout;
#ifdef CHROMEOS_ORDERFILE_USE
RemapHugetlbTextWithOrderfileLayout(vaddr, segsize);
#else
RemapHugetlbTextWithoutOrderfileLayout(vaddr, segsize);
#endif
// Only re-map the first text segment.
return 1;
}
}
......@@ -299,7 +258,10 @@ static int FilterElfHeader(struct dl_phdr_info* info, size_t size, void* data) {
// the hugepages. Any errors will cause the failing piece of this to be rolled
// back, so nothing world-ending can come from this function (hopefully ;) ).
void InitHugepagesAndMlockSelf(void) {
if (base::FeatureList::IsEnabled(chromeos::kCrOSHugepageRemapAndLockZygote)) {
// The following function is conditionally compiled, so use
// the statements to avoid compiler warnings of unused functions
if (kIsOrderfileEnabled &&
base::FeatureList::IsEnabled(chromeos::kCrOSHugepageRemapAndLockZygote)) {
dl_iterate_phdr(FilterElfHeader, 0);
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment