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

Commit 5dbcfa78 authored by Cody Northrop's avatar Cody Northrop
Browse files

EGL BlobCache: Update multifile key and value size

Make it clearer what the key and value size limits are.
Base the hot cache on those values, rather than the
other way around.

Test: pubg_mobile_launch ANGLE trace
Test: /data/nativetest64/EGL_test/EGL_test
Test: /data/nativetest64/libEGL_test/libEGL_test
Bug: b/266725576
Change-Id: I337beaf0e01c6497f619c29c01f94242c7b5c959
parent f2588a81
Loading
Loading
Loading
Loading
+9 −7
Original line number Diff line number Diff line
@@ -62,12 +62,14 @@ void freeHotCacheEntry(android::MultifileHotCache& entry) {

namespace android {

MultifileBlobCache::MultifileBlobCache(size_t maxTotalSize, size_t maxHotCacheSize,
MultifileBlobCache::MultifileBlobCache(size_t maxKeySize, size_t maxValueSize, size_t maxTotalSize,
                                       const std::string& baseDir)
      : mInitialized(false),
        mMaxKeySize(maxKeySize),
        mMaxValueSize(maxValueSize),
        mMaxTotalSize(maxTotalSize),
        mTotalCacheSize(0),
        mHotCacheLimit(maxHotCacheSize),
        mHotCacheLimit(0),
        mHotCacheSize(0),
        mWorkerThreadIdle(true) {
    if (baseDir.empty()) {
@@ -78,9 +80,9 @@ MultifileBlobCache::MultifileBlobCache(size_t maxTotalSize, size_t maxHotCacheSi
    // Establish the name of our multifile directory
    mMultifileDirName = baseDir + ".multifile";

    // Set a limit for max key and value, ensuring at least one entry can always fit in hot cache
    mMaxKeySize = mHotCacheLimit / 4;
    mMaxValueSize = mHotCacheLimit / 2;
    // Set the hotcache limit to be large enough to contain one max entry
    // This ensure the hot cache is always large enough for single entry
    mHotCacheLimit = mMaxKeySize + mMaxValueSize + sizeof(MultifileHeader);

    ALOGV("INIT: Initializing multifile blobcache with maxKeySize=%zu and maxValueSize=%zu",
          mMaxKeySize, mMaxValueSize);
@@ -254,7 +256,7 @@ void MultifileBlobCache::set(const void* key, EGLsizeiANDROID keySize, const voi

    // Ensure key and value are under their limits
    if (keySize > mMaxKeySize || valueSize > mMaxValueSize) {
        ALOGV("SET: keySize (%lu vs %zu) or valueSize (%lu vs %zu) too large", keySize, mMaxKeySize,
        ALOGW("SET: keySize (%lu vs %zu) or valueSize (%lu vs %zu) too large", keySize, mMaxKeySize,
              valueSize, mMaxValueSize);
        return;
    }
@@ -326,7 +328,7 @@ EGLsizeiANDROID MultifileBlobCache::get(const void* key, EGLsizeiANDROID keySize

    // Ensure key and value are under their limits
    if (keySize > mMaxKeySize || valueSize > mMaxValueSize) {
        ALOGV("GET: keySize (%lu vs %zu) or valueSize (%lu vs %zu) too large", keySize, mMaxKeySize,
        ALOGW("GET: keySize (%lu vs %zu) or valueSize (%lu vs %zu) too large", keySize, mMaxKeySize,
              valueSize, mMaxValueSize);
        return 0;
    }
+2 −1
Original line number Diff line number Diff line
@@ -91,7 +91,8 @@ private:

class MultifileBlobCache {
public:
    MultifileBlobCache(size_t maxTotalSize, size_t maxHotCacheSize, const std::string& baseDir);
    MultifileBlobCache(size_t maxKeySize, size_t maxValueSize, size_t maxTotalSize,
                       const std::string& baseDir);
    ~MultifileBlobCache();

    void set(const void* key, EGLsizeiANDROID keySize, const void* value,
+4 −5
Original line number Diff line number Diff line
@@ -28,17 +28,16 @@ namespace android {
template <typename T>
using sp = std::shared_ptr<T>;

constexpr size_t kMaxKeySize = 2 * 1024;
constexpr size_t kMaxValueSize = 6 * 1024;
constexpr size_t kMaxTotalSize = 32 * 1024;
constexpr size_t kMaxPreloadSize = 8 * 1024;

constexpr size_t kMaxKeySize = kMaxPreloadSize / 4;
constexpr size_t kMaxValueSize = kMaxPreloadSize / 2;

class MultifileBlobCacheTest : public ::testing::Test {
protected:
    virtual void SetUp() {
        mTempFile.reset(new TemporaryFile());
        mMBC.reset(new MultifileBlobCache(kMaxTotalSize, kMaxPreloadSize, &mTempFile->path[0]));
        mMBC.reset(new MultifileBlobCache(kMaxKeySize, kMaxValueSize, kMaxTotalSize,
                                          &mTempFile->path[0]));
    }

    virtual void TearDown() { mMBC.reset(); }
+7 −5
Original line number Diff line number Diff line
@@ -38,8 +38,9 @@ static const size_t kMaxMonolithicTotalSize = 2 * 1024 * 1024;
static const unsigned int kDeferredMonolithicSaveDelay = 4;

// Multifile cache size limits
constexpr uint32_t kMultifileHotCacheLimit = 8 * 1024 * 1024;
constexpr uint32_t kMultifileCacheByteLimit = 32 * 1024 * 1024;
constexpr uint32_t kMaxMultifileKeySize = 1 * 1024 * 1024;
constexpr uint32_t kMaxMultifileValueSize = 8 * 1024 * 1024;
constexpr uint32_t kMaxMultifileTotalSize = 32 * 1024 * 1024;

namespace android {

@@ -250,7 +251,7 @@ void egl_cache_t::updateMode() {
    if (mMultifileMode) {
        mCacheByteLimit = static_cast<size_t>(
                base::GetUintProperty<uint32_t>("ro.egl.blobcache.multifile_limit",
                                                kMultifileCacheByteLimit));
                                                kMaxMultifileTotalSize));

        // Check for a debug value
        int debugCacheSize = base::GetIntProperty("debug.egl.blobcache.multifile_limit", -1);
@@ -274,8 +275,9 @@ BlobCache* egl_cache_t::getBlobCacheLocked() {

MultifileBlobCache* egl_cache_t::getMultifileBlobCacheLocked() {
    if (mMultifileBlobCache == nullptr) {
        mMultifileBlobCache.reset(
                new MultifileBlobCache(mCacheByteLimit, kMultifileHotCacheLimit, mFilename));
        mMultifileBlobCache.reset(new MultifileBlobCache(kMaxMultifileKeySize,
                                                         kMaxMultifileValueSize, mCacheByteLimit,
                                                         mFilename));
    }
    return mMultifileBlobCache.get();
}