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 D5B0729C35A for ; Mon, 27 Apr 2026 07:02:43 +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=1777273365; cv=none; b=LgtV3jozXjJhO4Gbu3Al0NZU+yyLwbg7lypMVd7NawVNgh6chlI+Er6o+4c/WBpj2UAnvZ78xIKjw8bZeoYiSa1uc0w9GD5k53TED41pvE0iHijwFgikQDQjRpRLqwMNVXsBd5oPZY9gCDgRe5v7dcAIaujSlP0//QGmXG0bxCY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777273365; c=relaxed/simple; bh=O1Neb1cMq/5Ua5L4bvOIeXlM5Z9FvKq8FR62IYKwOkU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Wkgfyk+OC8pFS62utIf32AWc9QKkf/q6ee3VLkFmqHLuuZcvDu7SU4hz6xyYDNuYbIJu2VJ09uQt3h15jEGWcG6PR+/Wklkgdw77AwwxZnQ0x/ffxrGo1AK8GF4H1uDTaz7akb/ets2xPgPd+ZxLvegCWLlkU/yRgcqjXSOh2R8= 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=M7JxHddX; 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="M7JxHddX" Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-43fe62837baso5742807f8f.3 for ; Mon, 27 Apr 2026 00:02:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1777273362; x=1777878162; 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=d+yQBCe0d4ZRJ5bPsrJ9MMnmzAXjuvRB9nOtpkyNZnw=; b=M7JxHddX8/5F//QExpiNaZplhwQrbE2mIPMx8dfxHrxnn5Da0wIyLM02Eb37ZhQidv wg4pcX2r75cxvrl08f82T9Se4kpsFMEPeYJvvOuchWTR4yMx40elgmATLiBNcr++CfPc zu6hDSuVBeEX1/xOegxBt00ah0stHaGmIXwE9tBcXBZpSFmlu74khvWtVEQyjOhqm2ir P/1KHGMMTdyAVY16+qtH6M0tq8MQUS9uwnKvgMMMJ/0WST8tmB5yHyzDGENVxxNvPji9 sr6RCTynTwfxcYkiDMmFKSJISlrpvmeOrlfNVsV7Pp2heCeiilTN1c1ewGIyY1ZhQ19Q /ICg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777273362; x=1777878162; 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=d+yQBCe0d4ZRJ5bPsrJ9MMnmzAXjuvRB9nOtpkyNZnw=; b=cpJXI88KgNAKpmq4StJinRVJuWxpyJGTdGOluKdUMf+9gbE4eRbIKCMcIjFMkzZlCd SOqL7SCNjEmiKdleuv9dJlVHO4X2hEigtvhk7GA790CZDgk06nkanslbm7/zTjIzbODg E8xsr6dhNYCSnjhZlnJfj5ETkj0cnCRN3Acx/ZDcwcG12b4seNVq+TPU8qh5iBEHNT0C Qe6AXsTIv3oKv8TDqB1fHjIkX1FESsPK5QNLWIEUQ7lmh4e9/u5EiZTltEwTGot4bTbR UiUpdDjhp2TJeqF7PUIL5F3ATfAC2Td/D6wqP5JLVfCYshYfITkLazVmMF3WLaqyvReL T55w== X-Forwarded-Encrypted: i=1; AFNElJ8yEQEMF03cQdOs/eqYCI3je55EbkH2LihJDTS4HSWpnTjAKhr67/wsT4LCWCZ6s8uFSziZKr0SmQMdtuE=@vger.kernel.org X-Gm-Message-State: AOJu0YymET9PhlQ0UdsRFn4UcnMULJGzYjbsC+gMxDr3xHMdKuwr1Clo lUWuBD4VwqT6mwg+Wpfh5+oo0rHhripxElk71UOPJk+LRSk6OtxplUONReEynEYy8PoNe+KpTmO Vo6TMlGs= X-Gm-Gg: AeBDievu0jJDDbVugjSvgM1DZwQxwfLz/bXHOQV4wu48tfgYeDTct4LIR8b20LVIdZF Z8VBUTkya3pUJ9WZJh8rEAAtyhLNh/uRjl/aVpo2q2i8id6+qfIIAMXko4GzRYd9+ylqBoJP/5u Z0/sa2g11k9SelBHprX4IP7m11eAIlm43M9tFLwCu3JzacxOSlsFaisTjDCLsFwoemZPISbLnGk KlyH9+hmroYqEcjhh/TccqPLAYjrkIXMMFnBJFKJlDBCdQmxCqeJPYHi6WjZCIUdl3NtbToUKrs 6ixOkWzrFE0/g1RVM0NqY4lUtI2ArnGeqtWvgj2xEAvYUfEfzZoc0YCTgZ8GPuTnZqSJ6ezRLDT SB9z2YXq7jNUy5JqlEbwI5Galy+BeMru2FIBFFDx4ezdkKPHv8NlaJagYDi4jqO69vNgBY78NNO d8x/z14Fr/VtjkHOrOEyAHDz6Q/YpdnHsW1wHC4TcvsWAkuzA= X-Received: by 2002:a5d:64e7:0:b0:43d:5ec9:246 with SMTP id ffacd0b85a97d-43fe3db2d0fmr64773276f8f.12.1777273362099; Mon, 27 Apr 2026 00:02:42 -0700 (PDT) Received: from localhost (109-81-17-171.rct.o2.cz. [109.81.17.171]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43fe4cc2cacsm79101146f8f.13.2026.04.27.00.02.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Apr 2026 00:02:41 -0700 (PDT) Date: Mon, 27 Apr 2026 09:02:39 +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 Fri 24-04-26 15:49:19, Minchan Kim wrote: > On Fri, Apr 24, 2026 at 09:57:20AM +0200, Michal Hocko wrote: > > On Tue 21-04-26 16:02:39, Minchan Kim wrote: > > > Currently, process_mrelease() requires userspace to send a SIGKILL signal > > > prior to the call. 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 Android, arbitrary reference counts > > > (e.g., async I/O, reading /proc//cmdline, or various other remote > > > VM accesses) frequently delay this teardown indefinitely, defeating the > > > purpose of expedited reclamation. > > > > > > 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. > > > > Thanks, this makes the motivation much more clear and usecase very > > sound. > > > > > 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. > > > > > > To solve the race condition deterministically, we grab the mm reference > > > via mmget() and set the MMF_UNSTABLE flag *before* sending the SIGKILL. > > > Using mmget() instead of mmgrab() keeps mm_users > 0, preventing the > > > victim from calling exit_mmap() in its own exit path. > > > > Why is this needed? Address space tear down is an operation that can run > > from several execution contexts. > > Agreed. > > > > > > This ensures that > > > the memory is reclaimed synchronously and deterministically by the reaper > > > in the context of process_mrelease(), avoiding delays caused by > > > non-deterministic scheduling of the victim task. > > > > The memory is still reclaimed synchronously from the mrelease context. > > This is really confusing. > > > > Please also explain why do you need to do all that ugly > > task_will_free_mem hoops. Why cannot you simply kill the task if > > task_will_free_mem fails (if PROCESS_MRELEASE_REAP_KILL is used). > > I wanted to handle shared address spaces. > Even though we are okay with the target task not being in a SIGKILL > state yet (since we are about to kill it), we must ensure that all > *other* processes sharing the same mm are also dying. Then just bail out when the mm is shared accross thread groups, rather than kill just one of them. Or kill all of them. There is no reason to play around that on the task_will_free_mem level. -- Michal Hocko SUSE Labs