libmemifo: x86_64: 16K: No-op PFN APIs
When emulating the page size on a x86_64 device, pagemap
PFN bits are zeroed (not supported) [1] and kernel APIs that
consume PFNs from pagemap are also not available [2].
However we still want to be able to account memory from
libmeminfo (although missing some categorization).
Instead of erroring out, for PFN APIs in libmeminfo return
the the default values (success).
[1] https://r.android.com/3460337
[2] https://r.android.com/3471048
Test: atest libmeminfo_test
Bug: 385167611
Signed-off-by: Kalesh Singh <[email protected]>
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:10c7af7b9f269a1e160eada788bfefc8d0a28f5f)
Merged-In: I44b301a67bda19f363c2e59e1bc01255169215de
Change-Id: I44b301a67bda19f363c2e59e1bc01255169215de
diff --git a/pageacct.cpp b/pageacct.cpp
index cb17af8..7049459 100644
--- a/pageacct.cpp
+++ b/pageacct.cpp
@@ -32,12 +32,19 @@
return static_cast<off64_t>((pfn >> 6) << 3);
}
-uint64_t pagesize(void) {
- static uint64_t pagesize = sysconf(_SC_PAGE_SIZE);
- return pagesize;
+static bool is_page_size_emulated() {
+#if defined (__x86_64__)
+ return getpagesize() != 4096;
+#else
+ return false;
+#endif
}
bool PageAcct::InitPageAcct(bool pageidle_enable) {
+ if (is_page_size_emulated()) {
+ return true;
+ }
+
if (pageidle_enable && !PageAcct::KernelHasPageIdle()) {
LOG(ERROR) << "Idle page tracking is not supported by the kernel";
return false;
@@ -77,6 +84,11 @@
bool PageAcct::PageFlags(uint64_t pfn, uint64_t* flags) {
if (!flags) return false;
+ if (is_page_size_emulated()) {
+ *flags = 0;
+ return true;
+ }
+
if (kpageflags_fd_ < 0) {
if (!InitPageAcct()) return false;
}
@@ -92,6 +104,11 @@
bool PageAcct::PageMapCount(uint64_t pfn, uint64_t* mapcount) {
if (!mapcount) return false;
+ if (is_page_size_emulated()) {
+ *mapcount = 1;
+ return true;
+ }
+
if (kpagecount_fd_ < 0) {
if (!InitPageAcct()) return false;
}
@@ -105,6 +122,10 @@
}
int PageAcct::IsPageIdle(uint64_t pfn) {
+ if (is_page_size_emulated()) {
+ return 0;
+ }
+
if (pageidle_fd_ < 0) {
if (!InitPageAcct(true)) return -EOPNOTSUPP;
}