Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ed3f60fe authored by Yan Han's avatar Yan Han
Browse files

Use MemAvailable to better estimate free memory

Apps can call ActivityManager#getMemoryInfo to get an estimate for the
amount of free memory in the system. This is calculated as
MemFree + Cached, from /proc/meminfo.

However, /proc/meminfo also exposes MemAvailable, which more accurately
estimates free memory. For details, see
https://git.kernel.org/torvalds/c/34e431b.

On low-RAM TV devices, MemFree + Cached significantly overestimates
free memory, so switching to MemAvailable would improve performance
by encouraging apps to use a more appropriate amount of memory.

Bug: 340918025
Test: manual - with logging in ActivityManagerService#getMemoryInfo

Change-Id: I477b6ea944993627a5af6603256ebaaaffb84778
parent a90e5fb3
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -656,9 +656,8 @@ static int pid_compare(const void* v1, const void* v2)

static jlong android_os_Process_getFreeMemory(JNIEnv* env, jobject clazz)
{
    std::array<std::string_view, 2> memFreeTags = {
        ::android::meminfo::SysMemInfo::kMemFree,
        ::android::meminfo::SysMemInfo::kMemCached,
    std::array<std::string_view, 1> memFreeTags = {
            ::android::meminfo::SysMemInfo::kMemAvailable,
    };
    std::vector<uint64_t> mem(memFreeTags.size());
    ::android::meminfo::SysMemInfo smi;