Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 // Author: Ken Chen <kenchen@google.com> | 4 // Author: Ken Chen <kenchen@google.com> |
| 5 // | 5 // |
| 6 // hugepage text library to remap process executable segment with hugepages. | 6 // hugepage text library to remap process executable segment with hugepages. |
| 7 | 7 |
| 8 #include "chromeos/hugepage_text/hugepage_text.h" | 8 #include "chromeos/hugepage_text/hugepage_text.h" |
| 9 | 9 |
| 10 #include <link.h> | 10 #include <link.h> |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 165 } | 165 } |
| 166 | 166 |
| 167 // Top level text remapping function. | 167 // Top level text remapping function. |
| 168 // | 168 // |
| 169 // Inputs: vaddr, the starting virtual address to remap to hugepage | 169 // Inputs: vaddr, the starting virtual address to remap to hugepage |
| 170 // hsize, size of the memory segment to remap in bytes | 170 // hsize, size of the memory segment to remap in bytes |
| 171 // Return: none | 171 // Return: none |
| 172 // Effect: physical backing page changed from small page to hugepage. If there | 172 // Effect: physical backing page changed from small page to hugepage. If there |
| 173 // are error condition, the remaping operation is aborted. | 173 // are error condition, the remaping operation is aborted. |
| 174 static void RemapHugetlbText(void* vaddr, const size_t segsize) { | 174 static void RemapHugetlbText(void* vaddr, const size_t segsize) { |
| 175 int hsize = segsize; | 175 // remove unaligned head regions |
| 176 size_t head_gap = (kHpageSize - (size_t)addr % kHpageSize) % kHpageSize; | |
|
kenchen
2016/01/22 22:19:42
This should vaddr and the last mod operation is no
yunlian
2016/01/22 22:27:00
Yes, the vaddr is part is done. The last mod is us
| |
| 177 size_t addr = (size_t)vaddr + head_gap; | |
| 178 | |
| 179 int hsize = segsize - head_gap; | |
| 176 if (segsize > kHpageSize * kNumHugePages) | 180 if (segsize > kHpageSize * kNumHugePages) |
| 177 hsize = kHpageSize * kNumHugePages; | 181 hsize = kHpageSize * kNumHugePages; |
| 178 hsize = hsize & kHpageMask; | 182 hsize = hsize & kHpageMask; |
| 179 | 183 |
| 180 if (hsize == 0) | 184 if (hsize == 0) |
| 181 return; | 185 return; |
| 182 | 186 |
| 183 MremapHugetlbText(vaddr, hsize); | 187 MremapHugetlbText((void *)addr, hsize); |
| 184 } | 188 } |
| 185 | 189 |
| 186 // For a given ELF program header descriptor, iterates over all segments within | 190 // For a given ELF program header descriptor, iterates over all segments within |
| 187 // it and find the first segment that has PT_LOAD and is executable, call | 191 // it and find the first segment that has PT_LOAD and is executable, call |
| 188 // RemapHugetlbText(). | 192 // RemapHugetlbText(). |
| 189 // | 193 // |
| 190 // Inputs: info: pointer to a struct dl_phdr_info that describes the DSO. | 194 // Inputs: info: pointer to a struct dl_phdr_info that describes the DSO. |
| 191 // size: size of the above structure (not used in this function). | 195 // size: size of the above structure (not used in this function). |
| 192 // data: user param (not used in this function). | 196 // data: user param (not used in this function). |
| 193 // Return: always return true. The value is propagated by dl_iterate_phdr(). | 197 // Return: always return true. The value is propagated by dl_iterate_phdr(). |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 212 | 216 |
| 213 // Main library function. This function will iterate all ELF segments and | 217 // Main library function. This function will iterate all ELF segments and |
| 214 // attempt to remap text segment from small page to hugepage. | 218 // attempt to remap text segment from small page to hugepage. |
| 215 // If remapping is successful. All error conditions are soft fail such that | 219 // If remapping is successful. All error conditions are soft fail such that |
| 216 // effect will be rolled back and remap operation will be aborted. | 220 // effect will be rolled back and remap operation will be aborted. |
| 217 void ReloadElfTextInHugePages(void) { | 221 void ReloadElfTextInHugePages(void) { |
| 218 dl_iterate_phdr(FilterElfHeader, 0); | 222 dl_iterate_phdr(FilterElfHeader, 0); |
| 219 } | 223 } |
| 220 | 224 |
| 221 } // namespace chromeos | 225 } // namespace chromeos |
| OLD | NEW |