From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qt1-f169.google.com (mail-qt1-f169.google.com [209.85.160.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4A4591ADC7E for ; Wed, 29 Apr 2026 20:01:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=209.85.160.169 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777492898; cv=pass; b=e9cJg7XHmyW8KXwwRbusVghJOTqqrd9o7txXByz7oqa7c3v7DRc/jSwU2GIeDD8V8bF9ut4aLkyXjz9stCIjhxHV/DGw6ndY/s0t0tfdMzM44FcEo0oTfoKlRNoNVVrxLFarGAyjVj84FcICM8e6lgGkmlLVmAA9caSp4dMih+k= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777492898; c=relaxed/simple; bh=V2Ac/uiBGQ9ycw7pF0zjaEaqOT6k7YYrX3oTcJlTaSI=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=ceM7GMM7HJJeJtDKETB4mTRHI3LwJdV5X16bmRanAVjhtYDvwWFiuZoFLW+l4eZaQrzP33OZaQNdMBAlvA7hHPrphJQJ+DCoFBWueelk060RKkEgQcsynWHkNQFHJI0hCAG0lxec4roHl/mECSCkOFthS7xAzCPVgm0jblC3GTs= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=bSO6lczy; arc=pass smtp.client-ip=209.85.160.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="bSO6lczy" Received: by mail-qt1-f169.google.com with SMTP id d75a77b69052e-50d864c23bdso36331cf.1 for ; Wed, 29 Apr 2026 13:01:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1777492896; cv=none; d=google.com; s=arc-20240605; b=OrDlvFRSYm3q9pEdaN9MML0yhjkYH5en3Y9EtTNvktL+gckY6GfBlXSxz0ttnr4Fvn 4u8IymwWmUdB/6n2H5MGRMcJHBAgGvYt5nFbVS4ajrJSCkGC43/iW0KQV6PbiC5aMWMT MNqk3PowD45Dbw4RvlGgkRNyrMzuA52kWopgX1n7kltUPjQGHVBttYVsBGGPwsWSkoXm +ptxaG8f0PKaZa9nKNfyX2SgSQCwUhWrB/5zCdAKvvgmGQDHHFhfKUGSYuL+vdlLpHY2 mEL/W/4xNW3xB2FcLup9Rnv4lr7lJiJJgPfVhpGmSaeFGvoDNwCXlgCO5T2on4+8oNy0 UDfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=VrOQ5IvMm/7ol/RYFa/eoVS5wWzM8D3GvmLp87Y+8Zs=; fh=IITxmOrVZOD5FravY4tliVoe4rGVKaRUyM1RIfD0GAU=; b=DaOVsU76XP85XQ3eeEeN6rN8NBAe8sSfIzuAOlynO8hO9ALdBgDqtnSHbFiTZngLxr hxufyK8WJF6zmEDMSdP/4gKcnl9bGrYJz5iF/WrqR1ts8aph1hCMYjlXrKa/bt/KzyQC QijlqBX/TeAMwOEHPK80EcIIVMhxWEHoFATqv7HN+xeHqFKEbKkPSE4Czuir+hXUo9Ua yHdfkmDrwi3vmGC/G9P7ELRGhFx0c2vw6DludJYWFmqPQi1Pj5XxSyrBY9EmGvZI7mM9 KfsMEhZguzJ80CRkLvWBZIzy8sIY9gVLzdeC7uoRGfwfl62SeaeHQds9f+iQrz5sjtQ6 IvPw==; darn=vger.kernel.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1777492896; x=1778097696; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=VrOQ5IvMm/7ol/RYFa/eoVS5wWzM8D3GvmLp87Y+8Zs=; b=bSO6lczyf392BjTX6jz2nODvGIM0WU1KcxjEi6jZIa7czYGfrjQLUz1nHtEVCkuHjM kBSoLsbFEME5MJv1flaM+YhYsFbw27bqXXfGHjRmMWrbtXP3hRnOWCU6Aat7Pbco5G+O E2wkQiXxY/oBNxiWoTv3k0GqCyzzRsAk2n0dqCnBuR/jFi20TQ/NMAWyqD3yIhv/sdHk nQrz2iNJ+WChV/6eE7YY3Tix16p2CtH3P/AtQ4boL270aRbc1v+6zNYXsB0QlhF4QBfn 8tb62wI4EIudLRrKLe62eVkDBarl/Y9gVsUyXwh+OsXjRAWpjOMHkMwwqX5G/FzzSBT0 hE3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777492896; x=1778097696; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=VrOQ5IvMm/7ol/RYFa/eoVS5wWzM8D3GvmLp87Y+8Zs=; b=ac9ThCzgY3Zd+QduMfLmPFbGuFVlYi4+x5P4CViG6V3EnGo5Zx+2Xch51zfjGMMurZ Lnt9HVEEW3hQPnI0fdrcoymuB7snOMUGoepcbrjRwY9pzJX5jorjVZHIOAyR7hPQ1XQr A2zwdK5w2+pfvfyVPBkwZehC9i1WkyZGz7DQrABBvF92xAKPhidL/Jh5VY3YInSdiaBj 2rgqM+cEhah4wokLhRgGPBOd/bRAAP1o8PbUyYC7aGJiAMSzjX4KLRZGoewWoAFNgMRR gSBUYhGayQ/YCFMjYbXvRASyydIaGmb9vNV/DIOd9RFeMNnDue6jWA+FKGS1ZaVI3YBo l3PQ== X-Forwarded-Encrypted: i=1; AFNElJ9Mz9AKIIpxpoMPLqGOPUNGgE1AdpA4uZTN61fUFlbDw3NVZ6dObE9P3ovHmDL5q4LapIGYUY9jAsKS7/M=@vger.kernel.org X-Gm-Message-State: AOJu0YwHwQt0LXpad4Giqy4diIx/CBZEELUX41cbaNw4ONRJNmjQmcl/ wiXiyIl8m8f8T5ugDkvkCSoC3eHXcbAYH6W38jOSIBI2TzkuXUjy07V/l4rVwPDm0IqzM78163v f/GIIAQ8wmW/I5dKCh1uSo5YVENEzYfWZqGYC67Jo X-Gm-Gg: AeBDietvOkc9W5Jgyn9NEz2Vktyld79wkcbSNuN+IPyoaQ54eEucJDPL73sr7NWbkFQ NSHdst2uJcQUJ11Nk8eYnMfq8Rud2kOtH9Sjh0k/MLcScKE9O+W08pXes/sraIuojGELkXw/J97 CEa/LXceANdPHyQXdtAtsX/EuLlXbtOGcpP5gfE12wr09lce7g+6W/MteVA6K/dYg8OoY/meYch hy4IEuqEF+atDP4vvgJMVSTWZmHfQ17ji2PEHXi6D1M/icUbLYoqUoAWY/IxuyPykyFwFDsJZJQ Id6gXPfxotNmT7d9wfVqTRs1TsFOS2bMbNT/bI5kCC5JxS2c+grBDmot2ME= X-Received: by 2002:a05:622a:8c14:b0:50e:5eba:cadd with SMTP id d75a77b69052e-51027e357d9mr3118471cf.2.1777492895598; Wed, 29 Apr 2026 13:01:35 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20260421230239.172582-1-minchan@kernel.org> <20260421230239.172582-4-minchan@kernel.org> In-Reply-To: From: Suren Baghdasaryan Date: Wed, 29 Apr 2026 13:01:21 -0700 X-Gm-Features: AVHnY4LMZ-82kW3kGAJM8IvAKr1aRLzXrcRnIEAnRwPkwO2cxXsJngduRgWjvXs Message-ID: Subject: Re: [PATCH v1 3/3] mm: process_mrelease: introduce PROCESS_MRELEASE_REAP_KILL flag To: Michal Hocko Cc: Minchan Kim , akpm@linux-foundation.org, hca@linux.ibm.com, linux-s390@vger.kernel.org, david@kernel.org, brauner@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, timmurray@google.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Apr 29, 2026 at 1:25=E2=80=AFAM Michal Hocko wrot= e: > > On Tue 28-04-26 15:37:57, Minchan Kim wrote: > [...] > > >From be4bd22a100ed6be2d1d2599ddb9da04043143eb Mon Sep 17 00:00:00 2001 > > From: Minchan Kim > > Date: Fri, 24 Apr 2026 14:27:08 -0700 > > Subject: [PATCH] mm: process_mrelease: introduce PROCESS_MRELEASE_REAP_= KILL > > flag > > > > Currently, process_mrelease() requires userspace to send a SIGKILL sign= al > > prior to invocation. This separation introduces a scheduling race windo= w > > where the victim task may receive the signal and enter the exit path > > before the reaper can invoke process_mrelease(). > > > > When the victim enters the exit path (do_exit -> exit_mm), it clears it= s > > task->mm immediately. This causes process_mrelease() to fail with -ESRC= H, > > leaving the actual address space teardown (exit_mmap) to be deferred un= til > > the mm's reference count drops to zero. In the field (e.g., Android), > > arbitrary reference counts (reading /proc//cmdline, or various oth= er > > remote VM accesses) frequently delay this teardown indefinitely, > > defeating the purpose of expedited reclamation. > > > > In Android's LMKD scenarios, this delay keeps memory pressure high, for= cing > > the system to unnecessarily kill additional innocent background apps be= fore > > the memory from the first victim is recovered. > > > > This patch introduces the PROCESS_MRELEASE_REAP_KILL UAPI flag to suppo= rt > > an integrated auto-kill mode. When specified, process_mrelease() direct= ly > > injects a SIGKILL into the target task after finding its mm. > > > > To solve the race condition, we grab the mm reference via mmgrab() befo= re > > sending the SIGKILL. If the user passed PROCESS_MRELEASE_REAP_KILL, we = assume > > it will free its memory and proceed with reaping, making the logic as s= imple > > as reap =3D reap_kill || task_will_free_mem(p). > > > > To handle shared address spaces safely in the auto-kill mode, we bail o= ut > > immediately if the mm is marked with MMF_MULTIPROCESS when > > PROCESS_MRELEASE_REAP_KILL is specified. This protects existing users o= f > > process_mrelease() from behavior changes while preventing unsafe reapin= g of > > shared memory. > > Please explain why this is a different behavior from the global oom > killer and how do you intend to deal with those mm shared process > groups. I am not saying this is a wrong behavior but it will be hard to > change once in place. > > > Fundamentally, this allows process_mrelease() to trigger targeted memor= y > > reclaim (via oom_reaper infrastructure) quickly, even if the victim is > > not yet in the exit path, while reusing existing race handling between > > reaper and exit_mmap. > > > > Signed-off-by: Minchan Kim > > Other than the above looks ok to me. Implementation looks good to me. After addressing Michal's comment please split this patch from the series and feel free to add: Reviewed-by: Suren Baghdasaryan > > -- > Michal Hocko > SUSE Labs