From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (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 0C980371CE3 for ; Fri, 24 Apr 2026 07:57:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777017447; cv=none; b=Zp7lHHGetFU2A6wIsMjd0j6mITvDEQzub679eGSb/IBfBp90G5EpTQ5cWEA5z1yjBqCVrHtgThI7rwsq2bxAEfCvwjIx3CVKYgb8UA5190MQStHTfehv1vIy9w94zokvsDgy6+U0ZViGAY5lrz1Fr22TzbiKngdqnoagtY0BAjg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777017447; c=relaxed/simple; bh=PIeHOAwGv7BR2+lUgKRtaZEi63/Z6vyq4F9Xa9F8Rio=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=LZOJ+/WBdLWEdztrmV3ytI5zIwNCXqXH7Hp9Fm/Ls6vJfYptBp4yS+tBz4AgPlZrpz6VlPW+mo59Q7+RzT5PRhfdilCc4JbbN8KQo/dOZGCDw7+92tDoAdTi/tEq7fbJyDq2bgP1BxISfi3ek41Ju/8Ebu+VoXEGFBYrE7rG7z8= 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=c21f8Acl; arc=none smtp.client-ip=209.85.221.43 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="c21f8Acl" Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-43eada6d900so7336937f8f.0 for ; Fri, 24 Apr 2026 00:57:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1777017442; x=1777622242; 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=PQWnF9NzCxgEjMbfmZKZ7IVW4SmCDS5kYe81JwXOOKY=; b=c21f8Aclt6aiqnDVWqWomBX9AbFYWVgPJs9lJOWJLIjBJhP/5Pove9nLakDpOJ2d/9 IMcUzmePKPz7EYoNbcVjYas9dWVNPdrhqqW0YZ45+XVkX12pE2eunK8Xy1GFxQd0yi+g 7L3IPno53KfUY8MacNHAIe70ER4s1evFGUawKdIeoqJRkcJcj6azUPUL6svNfHelnzjz x/kBJt9VNSeK8HyYtDl2P8A1Il2rBO6Sj5PhKwpEzuW5/efFSAjBg5gDVcnj9cTciPjm jDF4PVhO8+QvDLSbxcL69GYIoEBsJUF8iaOjPocM8bL23mtCRhWlGis5I7wr0xoTD5Fs PVbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777017442; x=1777622242; 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=PQWnF9NzCxgEjMbfmZKZ7IVW4SmCDS5kYe81JwXOOKY=; b=rI8oF2HAmH5TsuFKP1P8HenzECYODQcLbDFFlP2rxKrhWSImv5JV9TRHa1pSCMV5nL sKEpy5Oj5zUbQ6Nr5mzgKi1/ekP2dxqFSaC5iNNHb1qA8s1Nt40BE0FrsGGlnbSz6c3W SniPrN/4N5KrgsdYM27VTqYdtZ0OMzIgnnq/5NZPaPo9E3JImO+ysG8+w3PG1RuHSITd UHOWoKgmpz7XqS0ER7W+tq/81tamGLMvyeg6U76CovXj/cVp4EINeMq0AxF6OhyLCYQi L2ERFiUO8J2JzOxMwLsEFUVzycKDFicnbRm87Ej1Dx6YFWrloWJrR8ZOBe3cvz4xFSxS reug== X-Forwarded-Encrypted: i=1; AFNElJ8zmMnCqeIqdjSOnLnPvgCUPd+P/CLeqSzws9E1cKSsYFIMFockRHSWn6WLF26O6EsqWrpgCyapjlFdaTU=@vger.kernel.org X-Gm-Message-State: AOJu0YwwOlqRAFpwE4W31xeqzgt2WjeGyy+EG5AuAcM7w5974Bpxvg8v RbtTMeJLW2zbw9Ce3nKGW/M+l7/dUizyX9HxowenJbRLQemZ379d/2jPruolXTuYwy0= X-Gm-Gg: AeBDiet5npSyAwev0UMVhaji2o+DPRFEqc6LhVts4QvWV61F4JnaDjHN88d5vlG9XEK QtYrlmKMSsUXjdspiFm01joQElU+Ms5wIH4jC98r9i2q7mfMnz8cUsTmuLzzElyWAGb9dNo7nbN EPYlOGUh0YzR5spgKCWh72RCvXqdiznyfCRJOO3okcc2nFW5dIsJSs5ikfWzimgd4BY38Kr9+On S7NKtYBu/sJai9dUMOoO/zOruWeFqwJByQN8uz3nWLAoP20gVpeAxxZmnHwVy/zTMPOOa/KIjAQ j2pW2vnEvjaYfxJgFjiE5aCCnH5uu1ubLeDrSZJw+opOnAQnG0vz7LWqSP1fzXQf8x9tOy1wGWa ejHfaPEs5V2XWOHMt+U98h2twt+58G2I310cGDY1iMJL+NjAARWRFMUjTGBttoh16q8Nj+23BCf mKvPNiXo/meh8E0Jdy7M92qUs0+1qe/lzJn8gohzHr81oxL80= X-Received: by 2002:a05:6000:4283:b0:43d:73ff:fd59 with SMTP id ffacd0b85a97d-43fe3db9bc9mr46929495f8f.10.1777017441623; Fri, 24 Apr 2026 00:57:21 -0700 (PDT) Received: from localhost (109-81-17-171.rct.o2.cz. [109.81.17.171]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43fe4cc0d51sm59342251f8f.10.2026.04.24.00.57.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Apr 2026 00:57:20 -0700 (PDT) Date: Fri, 24 Apr 2026 09:57:20 +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, Minchan Kim 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: <20260421230239.172582-4-minchan@kernel.org> 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. > 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). -- Michal Hocko SUSE Labs