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

Commit 282cf6ea authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Fix missing incremental process starting position of LRU list

When searching insertion position for a process with clients activities,
if the position goes to mLruProcessActivityStart but we don't increase
mLruProcessActivityStart, it will be like hide a slot. Then when removing
the process from LRU, the starting position will be decreased, that causes
a slot is lost. After this condition happens many times, the starting
position (mLruProcessServiceStart in the practical case) becomes a negative
number which leads to IndexOutOfBoundsException.

The expected example:
 Assume to insert a new process X to [2]:
  [0]A
  [1]B
  [2]C <- mLruProcess(Activity/Service)Start
  [3]D
 After insertion, the starting position increased:
  [0]A
  [1]B
  [2]X
  [3]C <- mLruProcess(Activity/Service)Start
  [4]D

Bug: 126427214
Test: Build system/extras/tests/memeater and push to device.
      Execute multiple memeater instances to consume most of RAM.
      Observe home is being killed and restarted frequently for a
      long time without IndexOutOfBoundsException from LRU list.

Change-Id: I8a925aa320141e55e18fa4312ba91cb628bcc47d
parent 5af401bd
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -2852,6 +2852,15 @@ public final class ProcessList {
                    pos--;
                }
                mLruProcesses.add(pos, app);
                if (pos == mLruProcessActivityStart) {
                    mLruProcessActivityStart++;
                }
                if (pos == mLruProcessServiceStart) {
                    // Unless {@code #hasService} is implemented, currently the starting position
                    // for activity and service are the same, so the incoming position may equal to
                    // the starting position of service.
                    mLruProcessServiceStart++;
                }
                // If this process is part of a group, need to pull up any other processes
                // in that group to be with it.
                int endIndex = pos - 1;