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

Commit 05a0f0fa authored by Fyodor Kupolov's avatar Fyodor Kupolov
Browse files

Disable lookaside allocator on low-RAM devices

Also dump lookaside config if it's different from the default.

Test: adb shell setprop debug.force_low_ram 1
      adb shell stop/start
      adb shell dumpsys meminfo system  // no lookaside allocations
Bug: 62877322

Change-Id: I152dae9714e7e55f93af3311b7387a6ac816e8f6
parent 49e6000f
Loading
Loading
Loading
Loading
+12 −3
Original line number Diff line number Diff line
@@ -16,8 +16,7 @@

package android.database.sqlite;

import dalvik.system.CloseGuard;

import android.app.ActivityManager;
import android.database.sqlite.SQLiteDebug.DbStats;
import android.os.CancellationSignal;
import android.os.OperationCanceledException;
@@ -26,6 +25,8 @@ import android.util.Log;
import android.util.PrefixPrinter;
import android.util.Printer;

import dalvik.system.CloseGuard;

import java.io.Closeable;
import java.util.ArrayList;
import java.util.Map;
@@ -147,6 +148,11 @@ public final class SQLiteConnectionPool implements Closeable {

    private SQLiteConnectionPool(SQLiteDatabaseConfiguration configuration) {
        mConfiguration = new SQLiteDatabaseConfiguration(configuration);
        // Disable lookaside allocator on low-RAM devices
        if (ActivityManager.isLowRamDeviceStatic()) {
            mConfiguration.lookasideSlotCount = 0;
            mConfiguration.lookasideSlotSize = 0;
        }
        setMaxConnectionPoolSizeLocked();
    }

@@ -1004,7 +1010,10 @@ public final class SQLiteConnectionPool implements Closeable {
            printer.println("Connection pool for " + mConfiguration.path + ":");
            printer.println("  Open: " + mIsOpen);
            printer.println("  Max connections: " + mMaxConnectionPoolSize);

            if (mConfiguration.isLookasideConfigSet()) {
                printer.println("  Lookaside config: sz=" + mConfiguration.lookasideSlotSize
                        + " cnt=" + mConfiguration.lookasideSlotCount);
            }
            printer.println("  Available primary connection:");
            if (mAvailablePrimaryConnection != null) {
                mAvailablePrimaryConnection.dump(indentedPrinter, verbose);
+4 −0
Original line number Diff line number Diff line
@@ -2366,6 +2366,10 @@ public final class SQLiteDatabase extends SQLiteClosable {
             * <p>SQLite default settings will be used, if this method isn't called.
             * Use {@code setLookasideConfig(0,0)} to disable lookaside
             *
             * <p><strong>Note:</strong> Provided slotSize/slotCount configuration is just a
             * recommendation. The system may choose different values depending on a device, e.g.
             * lookaside allocations can be disabled on low-RAM devices
             *
             * @param slotSize The size in bytes of each lookaside slot.
             * @param slotCount The total number of lookaside memory slots per database connection.
             */
+4 −0
Original line number Diff line number Diff line
@@ -180,4 +180,8 @@ public final class SQLiteDatabaseConfiguration {
        }
        return EMAIL_IN_DB_PATTERN.matcher(path).replaceAll("XX@YY");
    }

    boolean isLookasideConfigSet() {
        return lookasideSlotCount >= 0 && lookasideSlotSize >= 0;
    }
}
+4 −0
Original line number Diff line number Diff line
@@ -176,6 +176,10 @@ public abstract class SQLiteOpenHelper {
     * <p>SQLite default settings will be used, if this method isn't called.
     * Use {@code setLookasideConfig(0,0)} to disable lookaside
     *
     * <p><strong>Note:</strong> Provided slotSize/slotCount configuration is just a recommendation.
     * The system may choose different values depending on a device, e.g. lookaside allocations
     * can be disabled on low-RAM devices
     *
     * @param slotSize The size in bytes of each lookaside slot.
     * @param slotCount The total number of lookaside memory slots per database connection.
     */