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

Commit 59d80a52 authored by Colin Cross's avatar Colin Cross
Browse files

set the extra_free_kbytes kernel vm tunable

Set the sys.sysctl.extra_free_kbytes property, which will proxy
through init to the /proc/sys/vm/extra_free_kbytes tunable (on
kernels where it exists).  This will ask the kernel to keep
more memory free, causing lowmemorykiller to fire earlier and
allocations to succeed faster.

The size is set to 3 full screen 32bpp buffers.  Products can
override the size with an absolute or adjustment value using
overlays config_extraFreeKbytesAbsolute and
config_extraFreeKbytesAdjust.

Bug: 10024467
Change-Id: Ib4d4507513ec3c1f4d4ceeb81ed632d1ad643437
parent 54e5f0eb
Loading
Loading
Loading
Loading
+18 −0
Original line number Original line Diff line number Diff line
@@ -152,6 +152,24 @@
         bucket, and scaled proportionally to the smaller buckets. 0 keeps the default. -->
         bucket, and scaled proportionally to the smaller buckets. 0 keeps the default. -->
    <integer name="config_lowMemoryKillerMinFreeKbytesAdjust">0</integer>
    <integer name="config_lowMemoryKillerMinFreeKbytesAdjust">0</integer>


    <!-- Device configuration setting the /proc/sys/vm/extra_free_kbytes tunable in the kernel
         (if it exists).  A high value will increase the amount of memory that the kernel
         tries to keep free, reducing allocation time and causing the lowmemorykiller to kill
         earlier.  A low value allows more memory to be used by processes but may cause more
         allocations to block waiting on disk I/O or lowmemorykiller.  Overrides the default
         value chosen by ActivityManager based on screen size.  0 prevents keeping any extra
         memory over what the kernel keeps by default.  -1 keeps the default. -->
    <integer name="config_extraFreeKbytesAbsolute">-1</integer>

    <!-- Device configuration adjusting the /proc/sys/vm/extra_free_kbytes tunable in the kernel
         (if it exists).  0 uses the default value chosen by ActivityManager.  A positive value
         will increase the amount of memory that the kernel tries to keep free, reducing
         allocation time and causing the lowmemorykiller to kill earlier.  A negative value
         allows more memory to be used by processes but may cause more allocations to block
         waiting on disk I/O or lowmemorykiller.  Directly added to the default value chosen by
         ActivityManager based on screen size. -->
    <integer name="config_extraFreeKbytesAdjust">0</integer>

    <!-- The duration (in milliseconds) that the radio will scan for a signal
    <!-- The duration (in milliseconds) that the radio will scan for a signal
         when there's no network connection. If the scan doesn't timeout, use zero -->
         when there's no network connection. If the scan doesn't timeout, use zero -->
    <integer name="config_radioScanningTimeout">0</integer>
    <integer name="config_radioScanningTimeout">0</integer>
+2 −0
Original line number Original line Diff line number Diff line
@@ -283,6 +283,8 @@
  <java-symbol type="bool" name="config_useFixedVolume" />
  <java-symbol type="bool" name="config_useFixedVolume" />


  <java-symbol type="integer" name="config_cursorWindowSize" />
  <java-symbol type="integer" name="config_cursorWindowSize" />
  <java-symbol type="integer" name="config_extraFreeKbytesAdjust" />
  <java-symbol type="integer" name="config_extraFreeKbytesAbsolute" />
  <java-symbol type="integer" name="config_longPressOnPowerBehavior" />
  <java-symbol type="integer" name="config_longPressOnPowerBehavior" />
  <java-symbol type="integer" name="config_lowMemoryKillerMinFreeKbytesAdjust" />
  <java-symbol type="integer" name="config_lowMemoryKillerMinFreeKbytesAdjust" />
  <java-symbol type="integer" name="config_lowMemoryKillerMinFreeKbytesAbsolute" />
  <java-symbol type="integer" name="config_lowMemoryKillerMinFreeKbytesAbsolute" />
+19 −0
Original line number Original line Diff line number Diff line
@@ -24,6 +24,7 @@ import com.android.server.wm.WindowManagerService;


import android.content.res.Resources;
import android.content.res.Resources;
import android.graphics.Point;
import android.graphics.Point;
import android.os.SystemProperties;
import android.util.Slog;
import android.util.Slog;
import android.view.Display;
import android.view.Display;


@@ -237,10 +238,28 @@ final class ProcessList {
            memString.append((mOomMinFree[i]*1024)/PAGE_SIZE);
            memString.append((mOomMinFree[i]*1024)/PAGE_SIZE);
        }
        }


        // Ask the kernel to try to keep enough memory free to allocate 3 full
        // screen 32bpp buffers without entering direct reclaim.
        int reserve = displayWidth * displayHeight * 4 * 3 / 1024;
        int reserve_adj = Resources.getSystem().getInteger(com.android.internal.R.integer.config_extraFreeKbytesAdjust);
        int reserve_abs = Resources.getSystem().getInteger(com.android.internal.R.integer.config_extraFreeKbytesAbsolute);

        if (reserve_abs >= 0) {
            reserve = reserve_abs;
        }

        if (reserve_adj != 0) {
            reserve += reserve_adj;
            if (reserve < 0) {
                reserve = 0;
            }
        }

        //Slog.i("XXXXXXX", "******************************* MINFREE: " + memString);
        //Slog.i("XXXXXXX", "******************************* MINFREE: " + memString);
        if (write) {
        if (write) {
            writeFile("/sys/module/lowmemorykiller/parameters/adj", adjString.toString());
            writeFile("/sys/module/lowmemorykiller/parameters/adj", adjString.toString());
            writeFile("/sys/module/lowmemorykiller/parameters/minfree", memString.toString());
            writeFile("/sys/module/lowmemorykiller/parameters/minfree", memString.toString());
            SystemProperties.set("sys.sysctl.extra_free_kbytes", Integer.toString(reserve));
        }
        }
        // GB: 2048,3072,4096,6144,7168,8192
        // GB: 2048,3072,4096,6144,7168,8192
        // HC: 8192,10240,12288,14336,16384,20480
        // HC: 8192,10240,12288,14336,16384,20480