Add a flag to distinguish shared VMAs
This flag is required to filter out shared VMAs when compacting memory
using process_madvise.
Test: built and flashed
Bug: 173258203
Change-Id: I0438432000ffe464b9d8f8a7770a7302bddfb78e
diff --git a/include/meminfo/meminfo.h b/include/meminfo/meminfo.h
index 2fc7867..79ae619 100644
--- a/include/meminfo/meminfo.h
+++ b/include/meminfo/meminfo.h
@@ -66,10 +66,13 @@
uint64_t offset;
uint16_t flags;
std::string name;
+ uint64_t inode;
+ bool is_shared;
- Vma() : start(0), end(0), offset(0), flags(0), name("") {}
- Vma(uint64_t s, uint64_t e, uint64_t off, uint16_t f, const char* n)
- : start(s), end(e), offset(off), flags(f), name(n) {}
+ Vma() : start(0), end(0), offset(0), flags(0), name(""), inode(0), is_shared(false) {}
+ Vma(uint64_t s, uint64_t e, uint64_t off, uint16_t f, const std::string& n,
+ uint64_t iNode, bool is_shared)
+ : start(s), end(e), offset(off), flags(f), name(n), inode(iNode), is_shared(is_shared) {}
~Vma() = default;
void clear() { memset(&usage, 0, sizeof(usage)); }
diff --git a/libdmabufinfo/dmabufinfo.cpp b/libdmabufinfo/dmabufinfo.cpp
index 9c85db4..426c131 100644
--- a/libdmabufinfo/dmabufinfo.cpp
+++ b/libdmabufinfo/dmabufinfo.cpp
@@ -177,22 +177,24 @@
// Process the map if it is dmabuf. Add map reference to existing object in 'dmabufs'
// if it was already found. If it wasn't create a new one and append it to 'dmabufs'
- auto account_dmabuf = [&](uint64_t start, uint64_t end, uint16_t /* flags */,
- uint64_t /* pgoff */, ino_t inode, const char* name) {
+ auto account_dmabuf = [&](const android::procinfo::MapInfo& mapinfo) {
// no need to look into this mapping if it is not dmabuf
- if (!FileIsDmaBuf(std::string(name))) {
+ if (!FileIsDmaBuf(mapinfo.name)) {
return;
}
auto buf = std::find_if(dmabufs->begin(), dmabufs->end(),
- [&inode](const DmaBuffer& dbuf) { return dbuf.inode() == inode; });
+ [&mapinfo](const DmaBuffer& dbuf) {
+ return dbuf.inode() == mapinfo.inode;
+ });
if (buf != dmabufs->end()) {
buf->AddMapRef(pid);
return;
}
// We have a new buffer, but unknown count and name
- DmaBuffer& dbuf = dmabufs->emplace_back(inode, end - start, 0, "<unknown>", "<unknown>");
+ DmaBuffer& dbuf = dmabufs->emplace_back(mapinfo.inode, mapinfo.end - mapinfo.start,
+ 0, "<unknown>", "<unknown>");
dbuf.AddMapRef(pid);
};
diff --git a/procmeminfo.cpp b/procmeminfo.cpp
index 93e6b02..7455ead 100644
--- a/procmeminfo.cpp
+++ b/procmeminfo.cpp
@@ -280,11 +280,13 @@
// parse and read /proc/<pid>/maps
std::string maps_file = ::android::base::StringPrintf("/proc/%d/maps", pid_);
if (!::android::procinfo::ReadMapFile(
- maps_file, [&](uint64_t start, uint64_t end, uint16_t flags, uint64_t pgoff, ino_t,
- const char* name) {
- if (std::find(g_excluded_vmas.begin(), g_excluded_vmas.end(), name) ==
+ maps_file, [&](const android::procinfo::MapInfo& mapinfo) {
+ if (std::find(g_excluded_vmas.begin(), g_excluded_vmas.end(), mapinfo.name) ==
g_excluded_vmas.end()) {
- maps_.emplace_back(Vma(start, end, pgoff, flags, name));
+ maps_.emplace_back(Vma(mapinfo.start, mapinfo.end,
+ mapinfo.pgoff, mapinfo.flags,
+ mapinfo.name,
+ mapinfo.inode, mapinfo.shared));
}
})) {
LOG(ERROR) << "Failed to parse " << maps_file;
@@ -471,13 +473,14 @@
// If it has, we are looking for the vma stats
// 00400000-00409000 r-xp 00000000 fc:00 426998 /usr/lib/gvfs/gvfsd-http
if (!::android::procinfo::ReadMapFileContent(
- line, [&](uint64_t start, uint64_t end, uint16_t flags, uint64_t pgoff, ino_t,
- const char* name) {
- vma.start = start;
- vma.end = end;
- vma.flags = flags;
- vma.offset = pgoff;
- vma.name = name;
+ line, [&](const android::procinfo::MapInfo& mapinfo) {
+ vma.start = mapinfo.start;
+ vma.end = mapinfo.end;
+ vma.flags = mapinfo.flags;
+ vma.offset = mapinfo.pgoff;
+ vma.name = mapinfo.name;
+ vma.inode = mapinfo.inode;
+ vma.is_shared = mapinfo.shared;
})) {
LOG(ERROR) << "Failed to parse " << path;
return false;