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

Commit c4524997 authored by Cody Northrop's avatar Cody Northrop
Browse files

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
parent 34dfbf0c
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -569,6 +569,14 @@ void GraphicsEnv::setDebugLayersGLES(const std::string layers) {
    mDebugLayersGLES = layers;
}

int64_t GraphicsEnv::getBlobCacheQuotaBytes() {
    return mBlobCacheQuotaBytes;
}

void GraphicsEnv::setBlobCacheQuotaBytes(int64_t cacheBytes) {
    mBlobCacheQuotaBytes = cacheBytes;
}

// Return true if all the required libraries from vndk and sphal namespace are
// linked to the updatable gfx driver namespace correctly.
bool GraphicsEnv::linkDriverNamespaceLocked(android_namespace_t* vndkNamespace) {
+5 −0
Original line number Diff line number Diff line
@@ -143,6 +143,9 @@ public:
    // Get the debug layers to load.
    const std::string& getDebugLayersGLES();

    int64_t getBlobCacheQuotaBytes();
    void setBlobCacheQuotaBytes(int64_t cacheBytes);

private:
    enum UseAngle { UNKNOWN, YES, NO };

@@ -188,6 +191,8 @@ private:
    std::string mDebugLayersGLES;
    // Additional debug layers search path.
    std::string mLayerPaths;
    // Blob cache quota bytes
    int64_t mBlobCacheQuotaBytes;
    // This mutex protects the namespace creation.
    std::mutex mNamespaceMutex;
    // Updatable driver namespace.
+1 −0
Original line number Diff line number Diff line
@@ -160,6 +160,7 @@ cc_library_shared {
    srcs: [
        "EGL/egl_tls.cpp",
        "EGL/egl_cache.cpp",
        "EGL/egl_cache_multifile.cpp",
        "EGL/egl_display.cpp",
        "EGL/egl_object.cpp",
        "EGL/egl_layers.cpp",
+6 −0
Original line number Diff line number Diff line
@@ -185,4 +185,10 @@ void FileBlobCache::writeToFile() {
    }
}

size_t FileBlobCache::getSize() {
    if (mFilename.length() > 0) {
        return getFlattenedSize() + cacheFileHeaderSize;
    }
    return 0;
}
}
+3 −0
Original line number Diff line number Diff line
@@ -33,6 +33,9 @@ public:
    // disk.
    void writeToFile();

    // Return the total size of the cache
    size_t getSize();

private:
    // mFilename is the name of the file for storing cache contents.
    std::string mFilename;
Loading