[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250815163207.7078-1-zhongjinji@honor.com>
Date: Sat, 16 Aug 2025 00:32:07 +0800
From: zhongjinji <zhongjinji@...or.com>
To: <akpm@...ux-foundation.org>
CC: <andrealmeid@...lia.com>, <dave@...olabs.net>, <dvhart@...radead.org>,
<feng.han@...or.com>, <liam.howlett@...cle.com>,
<linux-kernel@...r.kernel.org>, <linux-mm@...ck.org>, <liulu.liu@...or.com>,
<mhocko@...e.com>, <mingo@...hat.com>, <npache@...hat.com>,
<peterz@...radead.org>, <rientjes@...gle.com>, <shakeel.butt@...ux.dev>,
<tglx@...utronix.de>, <zhongjinji@...or.com>
Subject: Re: [PATCH v4 3/3] mm/oom_kill: Have the OOM reaper and exit_mmap() traverse the maple tree in opposite orders
On Thu, 14 Aug 2025 21:55:55 +0800 <zhongjinji@...or.com> wrote:
> > When a process is OOM killed, if the OOM reaper and the thread running
> > exit_mmap() execute at the same time, both will traverse the vma's maple
> > tree along the same path. They may easily unmap the same vma, causing them
> > to compete for the pte spinlock. This increases unnecessary load, causing
> > the execution time of the OOM reaper and the thread running exit_mmap() to
> > increase.
>
> Please tell me what I'm missing here.
>
> OOM kills are a rare event. And this race sounds like it will rarely
> occur even if an oom-killing is happening. And the delay will be
> relatively short.
>
> If I'm correct then we're addressing rare*rare*small, so why bother?
When there are apps that consume a large amount of memory, encountering OOM on
low-memory Android devices is not uncommon. On Android devices, programs like lmkd
(a user-space daemon in the Android system) also call process_mrelease() to reap
memory when an app is killed.
> > When a process exits, exit_mmap() traverses the vma's maple tree from low to high
> > address. To reduce the chance of unmapping the same vma simultaneously,
> > the OOM reaper should traverse vma's tree from high to low address. This reduces
> > lock contention when unmapping the same vma.
>
> Sharing some before-and-after runtime measurements would be useful. Or
> at least, detailed anecdotes.
Here is my test data on Android. The test process is as follows: start the same app,
then kill it, and finally capture the perfetto trace.
In the test, the way to trigger the OOM reaper is: intercept the kill signal and
actively add the process to the OOM reaper queue as what OOM does.
Note: #RxComputationT, vdp:vidtask:m, and tp-background are threads of the same process,
and they are the last threads to exit.
Thread TID State Wall duration (ms)
# with oom reaper and traverse reverse
#RxComputationT 13708 Running 60.690572
oom_reaper 81 Running 46.492032
# with oom reaper but traverses
vdp:vidtask:m 14040 Running 81.848297
oom_reaper 81 Running 69.32
# without oom reaper
tp-background 12424 Running 106.021874
Powered by blists - more mailing lists