From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) (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 A853C376BD3 for ; Fri, 8 May 2026 06:15:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.196 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778220946; cv=none; b=EhHlHcg4YdUK+LRCztyBvJM8fhmX3AowrxR9lZgR11pg4SKOZF37evtWZ7AB3PCJ6hBQGwPXGlbiZDvZ+BceBZa40L0aZwcCgx/s4fi9oKGWLHd9Fr0jAOZCA4Ecw9dsLWJzNtfw2MD/fhuIjmHB0C8m3cBGOg3PU3w4Xuphf/U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778220946; c=relaxed/simple; bh=X/UwBiqYJJsZdLIhzNbBhdHndZA/DHq8ISQzw6+43nQ=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=F0tpHmI6eO+/7Fehk5xTKGkIDqOArHhzUHCU5J+276RICks2lk5Ec/RfGw6A2PSQfgKJEyr7bSbN+w8m0SlmQeHTWgtmmK6k+F3KGkHcirlx6CSLpznYq74nT3BiXByuS6pOJ5sEu6gglY/tWspXk4fMZtPHisUhabTDSihDXCA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=MOxKgS0f; arc=none smtp.client-ip=209.85.210.196 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MOxKgS0f" Received: by mail-pf1-f196.google.com with SMTP id d2e1a72fcca58-82748257f5fso1726301b3a.1 for ; Thu, 07 May 2026 23:15:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778220936; x=1778825736; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=rTA4CLloFA4PwQRrVh0QkmYUnMpU+ksh9ffBPHB3lKQ=; b=MOxKgS0fwrByji1o9c+g9YVl0zcgayKX+eVmzFysIZzE9wjv1n6gCZepL1qlCevm1K 3OPdzM506A0HEZBMJuXtiCozaVZvPc6hXRlvzfAUFk3FoZCPtoB6mK70PF50Be86jOTS JKpErMtA4XHQBYFZ1+b+nfqKgVCJ/fcw8uCm/sdNGrY9CDu3IrD0J8bPDFd6JzjSd9Xy gtlv+JMsULKjeJPI23elYRnds0EuI+jdWtMVOQWCjvlDyXSw/irmXByDoaNmLpi4Gl6l K5ekaSDE/XGHD+CV+/BXELZS91Tg6p0d7nt84tX76U37rkZAQVv7haO3tptHF4W8fvTj LMbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778220936; x=1778825736; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=rTA4CLloFA4PwQRrVh0QkmYUnMpU+ksh9ffBPHB3lKQ=; b=aM/ATC1aT1UJEzH0YwB1B5asFWXt66P6ni6e/BqiX63ejBSgv5HtWoMsRxPeyfsU1O 0JCVJ4W+dOu+NPNOgfdqRHJI+mUyioeuBRevZmTEoU7LZHEmKqx4ebWIKSQSID4c6HcB lVITdGg32p+owPgR3PcmgF8kCsTAPPiORH/Hukji+PiFZ5eUApsY6XgdXx9ThLHJNplr 60qTBYvKImQDeTvawjoEgaqNjfSTbZrG+WN9sAEWGAqYtXJHfcsLGhOFGAKhfrG2+n8u 9mGW9+BoYAfaVu0x1AfGYAz5TBmbQ5iT206rHCBTOf2+6GDWeUI26Aj0tYHqgCa704tZ 7Z5w== X-Forwarded-Encrypted: i=1; AFNElJ+FzqO8OAfT2fEejErghDMjE14NmBypTNlSbJfN0V1+p/EbZXbnr9apko4zmtWfTtv40GfKy0/bUWcu4Tk=@vger.kernel.org X-Gm-Message-State: AOJu0YwAPXW8rQlgDWKZcmcdAfbw+73rtoaKCooNNMO8VTsJJN0fzq6s al5ZWGuYJcu3HOfRaK4A0olweauXKdUyrt/T+yA7yH7oR9TZW9BHNK7G X-Gm-Gg: AeBDietHniSjghgMq1UcQdTFxyAavoIEHf/0AfT/lME8/oSSv6822VX5eNApqS5tUFE Ap2qQX9HN8uVkTdd2r/Fh3Bo9yvP+3DrC7KkE74CdgewSn3yCx/Xr8OcCjAyoUk+EuA+lcpBc+S ePHXu/rotPol2qQgzwH2oeU00GxJzX1A2ACswcseEICrmpIpzQg32C3GZJ/hmVC4GLyNioKMtD2 6VJ2AhCRvLS6TkwvNQCUkw2b++QrqA3M1Yx6oVsEiLftXvGeC7pJWYGCEqJw4bLZfYKySL1G48G JcO3J4BN/k2q9uyxcjdaBfVII2qk6oLkLUsznFD0mPnnWwrW1D3JV55Pt571Pa0FedivpnhnXcp DIEUVtrjo7UpSVjmP2NVTo2mkN3epOof5PD8lmofPKAdWFumnRf08Bwc1IndVLpNF0p4MOzLzyX n5fc0Om/Rro7hwV5g7+9PzjbBkX45Kibs= X-Received: by 2002:a05:6a00:2e96:b0:81f:4e1c:1d3b with SMTP id d2e1a72fcca58-83bb8b74857mr5006976b3a.23.1778220936181; Thu, 07 May 2026 23:15:36 -0700 (PDT) Received: from [10.125.112.20] ([210.184.73.204]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-839682a52cesm10551955b3a.57.2026.05.07.23.15.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 07 May 2026 23:15:35 -0700 (PDT) Message-ID: <407ab4a5-87e5-4eca-99d3-baa031935702@gmail.com> Date: Fri, 8 May 2026 14:15:28 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] cgroup/cpuset: move PF_EXITING check before __GFP_HARDWALL in cpuset_current_node_allowed() To: Chen Ridong Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, longman@redhat.com, tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com References: <20260507105434.3266234-1-chenwandun@lixiang.com> <02352ad2-9c85-4825-82b6-49c6a4b081d8@huaweicloud.com> Content-Language: en-US From: Wandun In-Reply-To: <02352ad2-9c85-4825-82b6-49c6a4b081d8@huaweicloud.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 5/8/26 09:39, Chen Ridong wrote: > > On 2026/5/7 18:54, Chen Wandun wrote: >> Since prepare_alloc_pages() unconditionally adds __GFP_HARDWALL for the >> fast path when cpusets are enabled, the __GFP_HARDWALL check in >> cpuset_current_node_allowed() causes the PF_EXITING escape path to be >> skipped on the first allocation attempt. This makes it unreachable in >> the common case, so dying tasks can get stuck in direct reclaim or even >> trigger OOM while trying to exit, despite being allowed to allocate from >> any node. >> >> Move the PF_EXITING check before __GFP_HARDWALL so that dying tasks >> can allocate memory from any node to exit quickly, even when cpusets >> are enabled. >> >> Also update the function comment to reflect the actual behavior of >> prepare_alloc_pages() and the corrected check ordering. >> >> Signed-off-by: Chen Wandun >> --- >> kernel/cgroup/cpuset.c | 14 ++++++++------ >> 1 file changed, 8 insertions(+), 6 deletions(-) >> >> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c >> index e3a081a07c6d..a48901a0416a 100644 >> --- a/kernel/cgroup/cpuset.c >> +++ b/kernel/cgroup/cpuset.c >> @@ -4176,11 +4176,11 @@ static struct cpuset *nearest_hardwall_ancestor(struct cpuset *cs) >> * current's mems_allowed, yes. If it's not a __GFP_HARDWALL request and this >> * node is set in the nearest hardwalled cpuset ancestor to current's cpuset, >> * yes. If current has access to memory reserves as an oom victim, yes. >> - * Otherwise, no. >> + * If the current task is PF_EXITING, yes. Otherwise, no. >> * >> * GFP_USER allocations are marked with the __GFP_HARDWALL bit, >> * and do not allow allocations outside the current tasks cpuset >> - * unless the task has been OOM killed. >> + * unless the task has been OOM killed or is exiting. >> * GFP_KERNEL allocations are not so marked, so can escape to the >> * nearest enclosing hardwalled ancestor cpuset. >> * >> @@ -4194,7 +4194,9 @@ static struct cpuset *nearest_hardwall_ancestor(struct cpuset *cs) >> * The first call here from mm/page_alloc:get_page_from_freelist() >> * has __GFP_HARDWALL set in gfp_mask, enforcing hardwall cpusets, >> * so no allocation on a node outside the cpuset is allowed (unless >> - * in interrupt, of course). >> + * in interrupt, of course). The PF_EXITING check must therefore >> + * come before the __GFP_HARDWALL check, otherwise a dying task >> + * would be blocked on the fast path. >> * >> * The second pass through get_page_from_freelist() doesn't even call >> * here for GFP_ATOMIC calls. For those calls, the __alloc_pages() >> @@ -4204,6 +4206,7 @@ static struct cpuset *nearest_hardwall_ancestor(struct cpuset *cs) >> * in_interrupt - any node ok (current task context irrelevant) >> * GFP_ATOMIC - any node ok >> * tsk_is_oom_victim - any node ok >> + * PF_EXITING - any node ok (let dying task exit quickly) >> * GFP_KERNEL - any node in enclosing hardwalled cpuset ok >> * GFP_USER - only nodes in current tasks mems allowed ok. >> */ >> @@ -4223,11 +4226,10 @@ bool cpuset_current_node_allowed(int node, gfp_t gfp_mask) >> */ >> if (unlikely(tsk_is_oom_victim(current))) >> return true; >> - if (gfp_mask & __GFP_HARDWALL) /* If hardwall request, stop here */ >> - return false; >> - >> if (current->flags & PF_EXITING) /* Let dying task have memory */ >> return true; >> + if (gfp_mask & __GFP_HARDWALL) /* If hardwall request, stop here */ >> + return false; >> >> /* Not hardwall and node outside mems_allowed: scan up cpusets */ >> spin_lock_irqsave(&callback_lock, flags); > Make sense. > > BTW, how did you find this issue? I found this while reviewing the cpuset node-allowed logic during an investigation into a memory allocation issue (not the root cause of that investigation). > > Reviewed-by: Chen Ridong >