Commit 30ea1fab authored by Brian Geffon's avatar Brian Geffon Committed by Commit Bot

CrOS: memory: Rename pagemap methods and add a helper

Because the pagemap uses the term present instead of in core
we will rename those methods.

Additionally, we add a little helper called IsFullyPresent.

Bug: chromium:1067833
Change-Id: I98099cdd1afa5ed0bc3ded3f22592000719281a1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2462687Reviewed-by: default avatarKuo-Hsin Yang <vovoy@chromium.org>
Commit-Queue: Brian Geffon <bgeffon@chromium.org>
Auto-Submit: Brian Geffon <bgeffon@chromium.org>
Cr-Commit-Position: refs/heads/master@{#815441}
parent 089b32ef
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <string> #include <string>
#include "base/logging.h"
#include "base/memory/aligned_memory.h" #include "base/memory/aligned_memory.h"
#include "base/posix/eintr_wrapper.h" #include "base/posix/eintr_wrapper.h"
#include "base/process/process_metrics.h" #include "base/process/process_metrics.h"
...@@ -78,11 +79,11 @@ bool Pagemap::GetEntries(uint64_t address, ...@@ -78,11 +79,11 @@ bool Pagemap::GetEntries(uint64_t address,
return true; return true;
} }
bool Pagemap::GetNumberOfPagesInCore(uint64_t address, bool Pagemap::GetNumberOfPagesPresent(uint64_t address,
uint64_t length, uint64_t length,
uint64_t* pages_in_core) const { uint64_t* pages_present) const {
DCHECK(pages_in_core); DCHECK(pages_present);
*pages_in_core = 0; *pages_present = 0;
std::vector<Pagemap::PagemapEntry> entries(length / base::GetPageSize()); std::vector<Pagemap::PagemapEntry> entries(length / base::GetPageSize());
if (!GetEntries(address, length, &entries)) { if (!GetEntries(address, length, &entries)) {
...@@ -91,11 +92,21 @@ bool Pagemap::GetNumberOfPagesInCore(uint64_t address, ...@@ -91,11 +92,21 @@ bool Pagemap::GetNumberOfPagesInCore(uint64_t address,
for (const Pagemap::PagemapEntry& entry : entries) { for (const Pagemap::PagemapEntry& entry : entries) {
if (entry.page_present) if (entry.page_present)
(*pages_in_core)++; (*pages_present)++;
} }
return true; return true;
} }
bool Pagemap::IsFullyPresent(uint64_t address, uint64_t length) const {
const size_t kPageSize = base::GetPageSize();
uint64_t pages_present = 0;
if (!GetNumberOfPagesPresent(address, length, &pages_present)) {
LOG(WARNING) << "Unable to get pagemap entry";
return false;
}
return (length / kPageSize) == pages_present;
}
} // namespace memory } // namespace memory
} // namespace chromeos } // namespace chromeos
...@@ -49,13 +49,17 @@ class CHROMEOS_EXPORT Pagemap { ...@@ -49,13 +49,17 @@ class CHROMEOS_EXPORT Pagemap {
uint64_t length, uint64_t length,
std::vector<PagemapEntry>* entries) const; std::vector<PagemapEntry>* entries) const;
// GetNumberOfPagesInCore is a helper which makes it easy to quickly determine // GetNumberOfPagesPresent is a helper which makes it easy to quickly
// the number of pages in core for the region specified by |address| and // determine the number of pages in core for the region specified by |address|
// |length|. On success the function will return true and pages_in_core will // and |length|. On success the function will return true and pages_present
// be set accordingly. // will be set accordingly.
bool GetNumberOfPagesInCore(uint64_t address, bool GetNumberOfPagesPresent(uint64_t address,
uint64_t length, uint64_t length,
uint64_t* pages_in_core) const; uint64_t* pages_present) const;
// IsFullyPresent is a small helper around GetNumberOfPagesPresent which
// returns true if every page in the range is presnt.
bool IsFullyPresent(uint64_t address, uint64_t length) const;
private: private:
friend class PagemapTest; friend class PagemapTest;
......
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