From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) (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 7B9E23A8742 for ; Wed, 29 Apr 2026 08:25:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777451153; cv=none; b=R+3+nE/TdkfFB2nTF98ke+W6d5QniI7Zas81FfyQJIcx4i1G+OwSHX8jv/o5/F8dbUuMa3GKbaTL+h+CuN7H2EdhdIUKqveq6m/IqkDkNXZ4gu7bo2ny7sm7qI7XEuM3VdDUHwAbLw2Rdhkksx8sJh7azVaPGgYxv9szlG7VclU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777451153; c=relaxed/simple; bh=+tpUQisjen8Gwmt1CYAmzHpIbM0Er/xztnTt3NR51sA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=k0mZ19SmYYj52R5BDD81xKuXgppKu1AgSp9UKkoQSV85YdTRR7ZP9o5iF0focguZuqv6+Oq1tjsoG7xqytaOB9bjxhwUrhMfTmaz9xydtJMt91EGhGnjj8wcdexENP0/Nw9doTCBJKpjpnmetJyfNz/UFcAfKb24m54d6oOVnsc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=W+hLOkel; arc=none smtp.client-ip=209.85.221.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="W+hLOkel" Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-43d6fbd0954so9270864f8f.1 for ; Wed, 29 Apr 2026 01:25:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1777451150; x=1778055950; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=xevsexu3UbZ8Pxbz/hjTHebmPREf3aJf4+wnjlsTUo8=; b=W+hLOkelS2fk8nkXfkTjUlJSvlmpTnh+k4TUold91FnUgHpNEY7oDYkAnG5RRMz+yC aAFn8GzXpU42aaxZmh3s1cwMTIZJ2rGdRyqA7lMNViTNDuOWxLSVRd2B15tONmFY+o1u 9KyG2Gj6dhOcg34sjBc13phUPEs3Yd6/PUzC02XpGGJkw1IUC53+mL1ui9kd4kx1/1Mp u6s7KmWKRrIT/ttXyBUxqEko0En9QrxoMLJvcXadKWrmgXZiYG7yn1W80VDnG0XWmKH1 8GXT0BdncWqp0sibgjQummbGw+pV6EKL6ZiKKUr6eBxQWedGP4qiVAE3xcpGWZ56PbFV WRuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777451150; x=1778055950; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xevsexu3UbZ8Pxbz/hjTHebmPREf3aJf4+wnjlsTUo8=; b=HaMxzmfuSd95KTTvoDW4KJkhyPuujjvyQMAQfhqpB1MLZi1xXfJv85BTmH2TKUFDXQ mTJWACc+JrVj7L8IcXOVHPEUuWhJ8QdqGzgr4lWPq0Rlk1FsNsRmcmE+UqBhgfHSOI1s fD39ey94tYWNrqYHqD6qXjDSIu2er+UYCInbgJu98vN8p8E4jU7iD1nYef5TMA1SZKlu cMUobrI6ORFuSVGjk+V5Wxd5BAkTu5KGTVf8RuckwTBdzNK4sBNKEsJ9J5Y8ahKWuw55 4OLtOIRptD6xO3yznSXlYH5TVywGMyaekBCYz/n7MscpnORzv8QxCOcvIJWXtVKjqKMi 8Jjg== X-Forwarded-Encrypted: i=1; AFNElJ+SBtEd5M7qlDBo99bpFBuZ+See7UKcwG+8zlapLfQz4POIL5UsTrhBsHu9BgR28nZxGJ3xlKbr3uBffRo=@vger.kernel.org X-Gm-Message-State: AOJu0YzbHv2UZLYYR5NyBQqaEtMxbheed0jphU00DiRGLTSGvG9YNNMJ yYZT+f0VLZJeu9LWnoS4YZQ5atJ2Kmg8AXXMhCzA+W2z+UC+ZZCiR3AfKUrq0++4W8k= X-Gm-Gg: AeBDieuLaJveoDUwbkuV8fg7NyNULjmHp0j+d8GU6k1y1D33MXFhbL4qlQNJlxoq0Rg yb3c7VntBYQE7rkm+YloIcv4Az7AGXOgEwsXsYkqHP0CoKN0ZXSmSYe2NcwpMNK4+4oY+gQpQRN rSVsL7ydX2JrZAQw8idDeeo5K1F+1wK2PRpJHmIXrXeVlKHRIansOrAgdNlzxjZhmC0BLc0IAvq MtonNDisbGhLtEkpwv+lPce3HyumrS4tsXDF2ZlO3oC+FyInDp4OFg2aOWAvdJ/i9HIOzWjCvHp 9Du5gqhkkzysZTiUuyaZbfWe7a66jHDobXmpClW1UoxHl97qxUYkNo9i3jHzQiIwx0n2TqshEye cxb0jTZgvoRazQuI5HyoX7GXG8FPdVOe//RGXVyBvgxzSAyffplniyOB4K9As2+FHzS1wEZqa+j GRaaszyCOs40gJPSQFIrzOlFqn68KaWM/VjNlcDhMg6hG27mdKe49bBRwlAw== X-Received: by 2002:a5d:5d0f:0:b0:43c:fc5c:aa0b with SMTP id ffacd0b85a97d-44790d12a8fmr4412927f8f.42.1777451149563; Wed, 29 Apr 2026 01:25:49 -0700 (PDT) Received: from localhost (109-81-86-177.rct.o2.cz. [109.81.86.177]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-447b7217a57sm3805010f8f.24.2026.04.29.01.25.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Apr 2026 01:25:49 -0700 (PDT) Date: Wed, 29 Apr 2026 10:25:47 +0200 From: Michal Hocko To: Minchan Kim Cc: 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, surenb@google.com, timmurray@google.com Subject: Re: [PATCH v1 3/3] mm: process_mrelease: introduce PROCESS_MRELEASE_REAP_KILL flag Message-ID: References: <20260421230239.172582-1-minchan@kernel.org> <20260421230239.172582-4-minchan@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 signal > prior to invocation. This separation introduces a scheduling race window > 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 its > task->mm immediately. This causes process_mrelease() to fail with -ESRCH, > leaving the actual address space teardown (exit_mmap) to be deferred until > the mm's reference count drops to zero. In the field (e.g., Android), > arbitrary reference counts (reading /proc//cmdline, or various other > 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, forcing > the system to unnecessarily kill additional innocent background apps before > the memory from the first victim is recovered. > > This patch introduces the PROCESS_MRELEASE_REAP_KILL UAPI flag to support > an integrated auto-kill mode. When specified, process_mrelease() directly > injects a SIGKILL into the target task after finding its mm. > > To solve the race condition, we grab the mm reference via mmgrab() before > 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 simple > as reap = reap_kill || task_will_free_mem(p). > > To handle shared address spaces safely in the auto-kill mode, we bail out > immediately if the mm is marked with MMF_MULTIPROCESS when > PROCESS_MRELEASE_REAP_KILL is specified. This protects existing users of > process_mrelease() from behavior changes while preventing unsafe reaping 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 memory > 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. -- Michal Hocko SUSE Labs