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

Commit 0e54231f authored by Neharika Jali's avatar Neharika Jali
Browse files

Eliminating the concept of reserved cache

Bug: 203649806
Test: atest installd_cache_test
Ignore-AOSP-First: This CL is to be submitted in a topic aimed
for T release
Change-Id: I9e861747c745f711f8d9a1c3c04ef1168a64b415
parent ec5f0e93
Loading
Loading
Loading
Loading
+1 −7
Original line number Original line Diff line number Diff line
@@ -1344,7 +1344,7 @@ binder::Status InstalldNativeService::destroyUserData(const std::optional<std::s
}
}


binder::Status InstalldNativeService::freeCache(const std::optional<std::string>& uuid,
binder::Status InstalldNativeService::freeCache(const std::optional<std::string>& uuid,
        int64_t targetFreeBytes, int64_t cacheReservedBytes, int32_t flags) {
        int64_t targetFreeBytes, int32_t flags) {
    ENFORCE_UID(AID_SYSTEM);
    ENFORCE_UID(AID_SYSTEM);
    CHECK_ARGUMENT_UUID(uuid);
    CHECK_ARGUMENT_UUID(uuid);
    std::lock_guard<std::recursive_mutex> lock(mLock);
    std::lock_guard<std::recursive_mutex> lock(mLock);
@@ -1447,12 +1447,6 @@ binder::Status InstalldNativeService::freeCache(const std::optional<std::string>
                break;
                break;
            }
            }


            // Only keep clearing when we haven't pushed into reserved area
            if (cacheReservedBytes > 0 && cleared >= (cacheTotal - cacheReservedBytes)) {
                LOG(DEBUG) << "Refusing to clear cached data in reserved space";
                break;
            }

            // Find the best tracker to work with; this might involve swapping
            // Find the best tracker to work with; this might involve swapping
            // if the active tracker is no longer the most over quota
            // if the active tracker is no longer the most over quota
            bool nextBetter = active && !queue.empty()
            bool nextBetter = active && !queue.empty()
+1 −1
Original line number Original line Diff line number Diff line
@@ -144,7 +144,7 @@ public:


    binder::Status rmPackageDir(const std::string& packageDir);
    binder::Status rmPackageDir(const std::string& packageDir);
    binder::Status freeCache(const std::optional<std::string>& uuid, int64_t targetFreeBytes,
    binder::Status freeCache(const std::optional<std::string>& uuid, int64_t targetFreeBytes,
            int64_t cacheReservedBytes, int32_t flags);
            int32_t flags);
    binder::Status linkNativeLibraryDirectory(const std::optional<std::string>& uuid,
    binder::Status linkNativeLibraryDirectory(const std::optional<std::string>& uuid,
            const std::string& packageName, const std::string& nativeLibPath32, int32_t userId);
            const std::string& packageName, const std::string& nativeLibPath32, int32_t userId);
    binder::Status createOatDir(const std::string& oatDir, const std::string& instructionSet);
    binder::Status createOatDir(const std::string& oatDir, const std::string& instructionSet);
+1 −2
Original line number Original line Diff line number Diff line
@@ -86,8 +86,7 @@ interface IInstalld {
    void destroyProfileSnapshot(@utf8InCpp String packageName, @utf8InCpp String profileName);
    void destroyProfileSnapshot(@utf8InCpp String packageName, @utf8InCpp String profileName);


    void rmPackageDir(@utf8InCpp String packageDir);
    void rmPackageDir(@utf8InCpp String packageDir);
    void freeCache(@nullable @utf8InCpp String uuid, long targetFreeBytes,
    void freeCache(@nullable @utf8InCpp String uuid, long targetFreeBytes, int flags);
            long cacheReservedBytes, int flags);
    void linkNativeLibraryDirectory(@nullable @utf8InCpp String uuid,
    void linkNativeLibraryDirectory(@nullable @utf8InCpp String uuid,
            @utf8InCpp String packageName, @utf8InCpp String nativeLibPath32, int userId);
            @utf8InCpp String packageName, @utf8InCpp String nativeLibPath32, int userId);
    void createOatDir(@utf8InCpp String oatDir, @utf8InCpp String instructionSet);
    void createOatDir(@utf8InCpp String oatDir, @utf8InCpp String instructionSet);
+35 −8
Original line number Original line Diff line number Diff line
@@ -145,7 +145,7 @@ TEST_F(CacheTest, FreeCache_All) {
    EXPECT_EQ(0, exists("com.example/cache/foo/one"));
    EXPECT_EQ(0, exists("com.example/cache/foo/one"));
    EXPECT_EQ(0, exists("com.example/cache/foo/two"));
    EXPECT_EQ(0, exists("com.example/cache/foo/two"));


    service->freeCache(testUuid, kTbInBytes, 0,
    service->freeCache(testUuid, kTbInBytes,
            FLAG_FREE_CACHE_V2 | FLAG_FREE_CACHE_V2_DEFY_QUOTA);
            FLAG_FREE_CACHE_V2 | FLAG_FREE_CACHE_V2_DEFY_QUOTA);


    EXPECT_EQ(0, exists("com.example/normal"));
    EXPECT_EQ(0, exists("com.example/normal"));
@@ -153,6 +153,33 @@ TEST_F(CacheTest, FreeCache_All) {
    EXPECT_EQ(-1, exists("com.example/cache/foo/two"));
    EXPECT_EQ(-1, exists("com.example/cache/foo/two"));
}
}


TEST_F(CacheTest, FreeCache_NonAggressive) {
    LOG(INFO) << "FreeCache_NonAggressive";

    mkdir("com.example");
    touch("com.example/normal", 1 * kMbInBytes, 60);
    mkdir("com.example/cache");
    mkdir("com.example/cache/foo");
    touch("com.example/cache/foo/one", 65 * kMbInBytes, 60);
    touch("com.example/cache/foo/two", 2 * kMbInBytes, 120);

    EXPECT_EQ(0, exists("com.example/normal"));
    EXPECT_EQ(0, exists("com.example/cache/foo/one"));
    EXPECT_EQ(0, exists("com.example/cache/foo/two"));

    service->freeCache(testUuid, kTbInBytes, FLAG_FREE_CACHE_V2);

    EXPECT_EQ(0, exists("com.example/normal"));
    EXPECT_EQ(-1, exists("com.example/cache/foo/one"));
    EXPECT_EQ(0, exists("com.example/cache/foo/two"));

    service->freeCache(testUuid, kTbInBytes, FLAG_FREE_CACHE_V2);

    EXPECT_EQ(0, exists("com.example/normal"));
    EXPECT_EQ(-1, exists("com.example/cache/foo/one"));
    EXPECT_EQ(0, exists("com.example/cache/foo/two"));
}

TEST_F(CacheTest, FreeCache_Age) {
TEST_F(CacheTest, FreeCache_Age) {
    LOG(INFO) << "FreeCache_Age";
    LOG(INFO) << "FreeCache_Age";


@@ -162,13 +189,13 @@ TEST_F(CacheTest, FreeCache_Age) {
    touch("com.example/cache/foo/one", kMbInBytes, 60);
    touch("com.example/cache/foo/one", kMbInBytes, 60);
    touch("com.example/cache/foo/two", kMbInBytes, 120);
    touch("com.example/cache/foo/two", kMbInBytes, 120);


    service->freeCache(testUuid, free() + kKbInBytes, 0,
    service->freeCache(testUuid, free() + kKbInBytes,
            FLAG_FREE_CACHE_V2 | FLAG_FREE_CACHE_V2_DEFY_QUOTA);
            FLAG_FREE_CACHE_V2 | FLAG_FREE_CACHE_V2_DEFY_QUOTA);


    EXPECT_EQ(-1, exists("com.example/cache/foo/one"));
    EXPECT_EQ(-1, exists("com.example/cache/foo/one"));
    EXPECT_EQ(0, exists("com.example/cache/foo/two"));
    EXPECT_EQ(0, exists("com.example/cache/foo/two"));


    service->freeCache(testUuid, free() + kKbInBytes, 0,
    service->freeCache(testUuid, free() + kKbInBytes,
            FLAG_FREE_CACHE_V2 | FLAG_FREE_CACHE_V2_DEFY_QUOTA);
            FLAG_FREE_CACHE_V2 | FLAG_FREE_CACHE_V2_DEFY_QUOTA);


    EXPECT_EQ(-1, exists("com.example/cache/foo/one"));
    EXPECT_EQ(-1, exists("com.example/cache/foo/one"));
@@ -196,7 +223,7 @@ TEST_F(CacheTest, FreeCache_Tombstone) {
    EXPECT_EQ(2 * kMbInBytes, size("com.example/cache/bar/bar1"));
    EXPECT_EQ(2 * kMbInBytes, size("com.example/cache/bar/bar1"));
    EXPECT_EQ(2 * kMbInBytes, size("com.example/cache/bar/bar2"));
    EXPECT_EQ(2 * kMbInBytes, size("com.example/cache/bar/bar2"));


    service->freeCache(testUuid, kTbInBytes, 0,
    service->freeCache(testUuid, kTbInBytes,
            FLAG_FREE_CACHE_V2 | FLAG_FREE_CACHE_V2_DEFY_QUOTA);
            FLAG_FREE_CACHE_V2 | FLAG_FREE_CACHE_V2_DEFY_QUOTA);


    EXPECT_EQ(-1, exists("com.example/cache/foo/foo1"));
    EXPECT_EQ(-1, exists("com.example/cache/foo/foo1"));
@@ -218,7 +245,7 @@ TEST_F(CacheTest, FreeCache_Group) {


    setxattr("com.example/cache/foo", "user.cache_group");
    setxattr("com.example/cache/foo", "user.cache_group");


    service->freeCache(testUuid, free() + kKbInBytes, 0,
    service->freeCache(testUuid, free() + kKbInBytes,
            FLAG_FREE_CACHE_V2 | FLAG_FREE_CACHE_V2_DEFY_QUOTA);
            FLAG_FREE_CACHE_V2 | FLAG_FREE_CACHE_V2_DEFY_QUOTA);


    EXPECT_EQ(-1, exists("com.example/cache/foo/foo1"));
    EXPECT_EQ(-1, exists("com.example/cache/foo/foo1"));
@@ -263,7 +290,7 @@ TEST_F(CacheTest, FreeCache_GroupTombstone) {
    setxattr("com.example/cache/tomb", "user.cache_tombstone");
    setxattr("com.example/cache/tomb", "user.cache_tombstone");
    setxattr("com.example/cache/tomb/group", "user.cache_group");
    setxattr("com.example/cache/tomb/group", "user.cache_group");


    service->freeCache(testUuid, free() + kKbInBytes, 0,
    service->freeCache(testUuid, free() + kKbInBytes,
            FLAG_FREE_CACHE_V2 | FLAG_FREE_CACHE_V2_DEFY_QUOTA);
            FLAG_FREE_CACHE_V2 | FLAG_FREE_CACHE_V2_DEFY_QUOTA);


    EXPECT_EQ(kMbInBytes, size("com.example/cache/group/file1"));
    EXPECT_EQ(kMbInBytes, size("com.example/cache/group/file1"));
@@ -284,7 +311,7 @@ TEST_F(CacheTest, FreeCache_GroupTombstone) {
    EXPECT_EQ(0, size("com.example/cache/tomb/group/dir/file1"));
    EXPECT_EQ(0, size("com.example/cache/tomb/group/dir/file1"));
    EXPECT_EQ(0, size("com.example/cache/tomb/group/dir/file2"));
    EXPECT_EQ(0, size("com.example/cache/tomb/group/dir/file2"));


    service->freeCache(testUuid, free() + kKbInBytes, 0,
    service->freeCache(testUuid, free() + kKbInBytes,
            FLAG_FREE_CACHE_V2 | FLAG_FREE_CACHE_V2_DEFY_QUOTA);
            FLAG_FREE_CACHE_V2 | FLAG_FREE_CACHE_V2_DEFY_QUOTA);


    EXPECT_EQ(-1, size("com.example/cache/group/file1"));
    EXPECT_EQ(-1, size("com.example/cache/group/file1"));
@@ -305,7 +332,7 @@ TEST_F(CacheTest, FreeCache_GroupTombstone) {
    EXPECT_EQ(0, size("com.example/cache/tomb/group/dir/file1"));
    EXPECT_EQ(0, size("com.example/cache/tomb/group/dir/file1"));
    EXPECT_EQ(0, size("com.example/cache/tomb/group/dir/file2"));
    EXPECT_EQ(0, size("com.example/cache/tomb/group/dir/file2"));


    service->freeCache(testUuid, kTbInBytes, 0,
    service->freeCache(testUuid, kTbInBytes,
            FLAG_FREE_CACHE_V2 | FLAG_FREE_CACHE_V2_DEFY_QUOTA);
            FLAG_FREE_CACHE_V2 | FLAG_FREE_CACHE_V2_DEFY_QUOTA);


    EXPECT_EQ(-1, size("com.example/cache/group/file1"));
    EXPECT_EQ(-1, size("com.example/cache/group/file1"));