EGL BlobCache: Support multifile cache and flexible size limit
This CL introduces the ability to support EGL blob cache using
multiple files. This allows us to increase the amount of cache
available to applications, without increasing process memory
used to get/set from the cache.
In order to support this, entries will be written to a new
directory in the same location:
$ adb shell
# cd /data/user_de/0/<packge_name>/code_cache
# ls -la com.android.opengl.shaders_cache.multifile
total 53M
drwx--S--- 2 u0_a276 u0_a276_cache 248K 2022-12-13 15:45 .
drwxrws--x 3 u0_a276 u0_a276_cache 404K 2022-12-13 11:26 ..
-rw------- 1 u0_a276 u0_a276_cache 7.1K 2022-12-13 15:43 1000572839
-rw------- 1 u0_a276 u0_a276_cache 8.9K 2022-12-13 15:43 1000616115
-rw------- 1 u0_a276 u0_a276_cache 5.0K 2022-12-13 15:43 1001816402
-rw------- 1 u0_a276 u0_a276_cache 4.3K 2022-12-13 15:44 1002265221
-rw------- 1 u0_a276 u0_a276_cache 8.2K 2022-12-13 15:44 1002773033
-rw------- 1 u0_a276 u0_a276_cache 2.8K 2022-12-13 15:45 1004532460
-rw------- 1 u0_a276 u0_a276_cache 4.3K 2022-12-13 15:45 1005120329
...
The filenames are generated by hashing the incoming key.
The cache limit is set in ag/20506291 by GraphicsEnvironment based on
getCacheQuotaBytes from StorageManager. If exceeded, we invoke an LRU
that clears files, oldest first, until under the cap.
The new mode is enable by default, but can be disabled with:
adb shell setprop debug.egl.blobcache.multifilemode false
The cache limit can also be modified with debug properties:
adb shell setprop debug.egl.blobcache.bytelimit <bytes>
Test: Multiple apps and ANGLE traces
Test: /data/nativetest64/EGL_test/EGL_test
Bug: b/246966894
Change-Id: I5e946d43728fdcea7dad08a4283129490893a122
diff --git a/opengl/libs/EGL/egl_cache.h b/opengl/libs/EGL/egl_cache.h
index d10a615..2dcd803 100644
--- a/opengl/libs/EGL/egl_cache.h
+++ b/opengl/libs/EGL/egl_cache.h
@@ -64,6 +64,12 @@
// cache contents from one program invocation to another.
void setCacheFilename(const char* filename);
+ // Allow the fixed cache limit to be overridden
+ void setCacheLimit(int64_t cacheByteLimit);
+
+ // Return the byte total for cache file(s)
+ size_t getCacheSize();
+
private:
// Creation and (the lack of) destruction is handled internally.
egl_cache_t();
@@ -112,6 +118,16 @@
// sCache is the singleton egl_cache_t object.
static egl_cache_t sCache;
+
+ // Whether to use multiple files to store cache entries
+ bool mMultifileMode;
+
+ // Cache limit
+ int64_t mCacheByteLimit;
+
+ // Whether we've kicked off a side thread that will check the multifile
+ // cache size and remove entries if needed.
+ bool mMultifileCleanupPending;
};
}; // namespace android