From patchwork Thu Feb 6 12:26:33 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Hocko X-Patchwork-Id: 13962983 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 39258C02194 for ; Thu, 6 Feb 2025 12:26:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8EB006B0082; Thu, 6 Feb 2025 07:26:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 89B306B0083; Thu, 6 Feb 2025 07:26:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 763146B0085; Thu, 6 Feb 2025 07:26:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 58CF46B0082 for ; Thu, 6 Feb 2025 07:26:49 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id BDBC5141210 for ; Thu, 6 Feb 2025 12:26:48 +0000 (UTC) X-FDA: 83089443696.18.2627182 Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) by imf08.hostedemail.com (Postfix) with ESMTP id DC16C16005A for ; Thu, 6 Feb 2025 12:26:46 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=none; spf=pass (imf08.hostedemail.com: domain of mstsxfx@gmail.com designates 209.85.218.43 as permitted sender) smtp.mailfrom=mstsxfx@gmail.com; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=kernel.org (policy=quarantine) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1738844807; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references; bh=ENmojTuiNJJ6xJld5L2Wko62wurcHkgzo9KyUFUcH5Q=; b=RcmeyC73AgAmkNa0qEUED6sxUF6XfK1iCJnciENbtbbtR3REkl2g86TmZgabkRlOCeH4+V 7u0u3KYXp4NWRs1jxiAqWsMXF6ST/KgGs9z6g8yImzMe6O71TY6ws0wMIToqck497k6Iv1 2ixH+UnLzX4uGmOeJEa+858edMqgMSw= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=none; spf=pass (imf08.hostedemail.com: domain of mstsxfx@gmail.com designates 209.85.218.43 as permitted sender) smtp.mailfrom=mstsxfx@gmail.com; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=kernel.org (policy=quarantine) ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738844807; a=rsa-sha256; cv=none; b=Pkz9JO7a+sfuiXYoKAnaV4X7/9iO8eRqdb/4/SKoN4UvDvw5U/fJOylP7SJufSnldKz1zq YZrOBd3zfVnIYYy0PRDWf01ZLSPklb2io1tKbQP/75a2Y0l12w58lnc29NFM7cM1jA3/5I uIb31bCn4LOhI0wCYPnAHj0pIcEosNs= Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-ab737e5674bso164844566b.1 for ; Thu, 06 Feb 2025 04:26:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738844805; x=1739449605; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ENmojTuiNJJ6xJld5L2Wko62wurcHkgzo9KyUFUcH5Q=; b=LWuA8Td7jXMzOGXQWwDegy6NNXVlak+qKfaNk9gtfoppZvjoEpVN21WC+v7EEQ27Lk VRk9ADr1Jxk5P6w+qi1MFd07EWxvKTwv+w/fyrcTWKxDemoOOQL9Za724AvFptQH0r92 D4WDDwISv5e6v0kx+kfB10aPp7fG85iv5zhhc6G5PQ2vqfNa3aMo4erSSdYfq6PQanSe 9kHOLwLocmlJLqqn49NS4Qad7Dc9Q2vm9MwvMmai8wrn/858VrRFLpZvKCB0GHd9u55f PjfliBI2I4DxUg5dIxmNwe5snFDwFFXyRr375JO05CKjZJiCLOMwRlUcVxbCsQZvw6DF j8Yg== X-Forwarded-Encrypted: i=1; AJvYcCV8idHEG/lJgpLz7/jf4xG0UkelVr7tbxRI2CJtLwqw9KAkUL628P2HFNre/zO95K5507mIp7pLpg==@kvack.org X-Gm-Message-State: AOJu0YxyeXeHpXYJX8OiDqI+4Kkd2yJS/5PAPsmzMf9mImJlsLxhfx84 x0SyHokPwlOtE8isbSifzhcfklOrGvUOyfMYq0nAdwxkyqEiUNBr X-Gm-Gg: ASbGncsYBPetlfLnYp7+sdMgh1hzoMxNdwf3sxtOuyM4oXGhUr+ZY3RXOqptGM5CLzq /Vulj/20eELqQ7rqTKYk+tYJLYBZlG1KUkp2BLy/PGW/YIUDwmCyijhYerAFdix86xGHkgLFd6O P/dGjLBADogTlxoPsE+gi7xXcxC45K1I4WJXIWONvMHtElkHFFone4CL+vsfmxjlPFqXZVyO8FM iMkMSkxNB1W2e4yeZz5fBrceXe/kCZK0O+EdaRZniW0ibqBiwEXO0uz9esE+gwBFWEFcnMN5EDI 83XC6lhnzJpZwY4wM13XwFTj+l+OF08KbD9hu5SDrUtH4wg= X-Google-Smtp-Source: AGHT+IH07CTI6uN+Ur6kpagu6CSzX6td+ByTSBwRYy3w/j/PvURMx/eBzeSKS3e+fVQSt/HBfbc9wg== X-Received: by 2002:a17:907:7da0:b0:ab6:ddbc:1488 with SMTP id a640c23a62f3a-ab75e245019mr651564266b.23.1738844804942; Thu, 06 Feb 2025 04:26:44 -0800 (PST) Received: from localhost.localdomain (109-81-84-135.rct.o2.cz. [109.81.84.135]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab772f491dcsm91417066b.22.2025.02.06.04.26.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Feb 2025 04:26:44 -0800 (PST) From: Michal Hocko To: Dennis Zhou , Tejun Heo , Filipe Manana Cc: Andrew Morton , , LKML , Michal Hocko Subject: [PATCH] mm, percpu: do not consider sleepable allocations atomic Date: Thu, 6 Feb 2025 13:26:33 +0100 Message-ID: <20250206122633.167896-1-mhocko@kernel.org> X-Mailer: git-send-email 2.48.1 MIME-Version: 1.0 X-Rspamd-Pre-Result: action=add header; module=dmarc; Action set by DMARC X-Rspam-User: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: DC16C16005A X-Stat-Signature: pkng1t93xq3u5xw8hdegr1b4nip3z7ww X-Rspam: Yes X-HE-Tag: 1738844806-805333 X-HE-Meta: U2FsdGVkX1+0Blw+wPIBUG7pntUWCshymQ4XeSHgyafKWCUGFNLRMivtVcu8aWbkA0mmBYp8LP4YZadvV4TMIjmyGdYRsDQpmYTXkL4Har9sZxCBsiNjl78q1FzezrgH9K1WO51L/r1OXNqngGThtwxywmSwJRSM1pgSZ6J/f0+508pZC0QDpbpSUHgP7umWky6Otpx+Isgh6Bena2hNz+FVK3/S1Ty77iWk26Ud42/RiUZgJIcnCiVLZef4e8vLvVCO1q125F2zEwOnUTFW55cqtnhGHg5HA7iLvUGBKMx3zeHhCUR2gT6MFs1QvsUShsi69VHpTJBYSaU9JtKW1gPx5UL3h2kQRuaOYK/AJdggv52/5BWC634lplEnwt7XFy00zfH72ULX6s+xA8NuizrKIVzjoLcJtfM8yogvl+sWSnf3Lrr2oZKynA+qUayUCYcYFI9v1bZ7hcgKc9uMoVXp5hebmXekjo5Tq1rF1zje2BJEwXpK6CCagXgo1x6LxYjI8ZPJ8g6kZy47d75HGAhQdfNPKDthBLEyABgwKdYnuBZGXum2ldAa396aaRSKvOy0TgAm1hMYKk2fJl7sVG3qztJOdAA4Pv8iA3l3CdUbUbL2/kmSRTb+fhsUR6kXcoeT24Zu3dZ4IlLu+DdFLRoElU4to61BHF03U4uxgZBNH5BSpmD7d6xy3c5deL41e58hpcuZQ9drCenMsO5Sk9s2hQmP4+l7DNbmLuVI0TXsIU+HVIX1ZeT//yiypDcUyXMrYSF5D7197XvCLOPEf4MiMuCwz/izJ9FuubemDMfnQ1/+Fn4BMfjkWKPIclulhFtU+DALf23uanb6uMSHep1IRiRSFQkw6LznL/2/OsUr2tW+Xcpbgt+zSlMkx65f+1rZVXlvAYY/ztQivNRqxwr/ThVlNRAi8Ql4mQU70ctzfNrd8gtJcc4QXiZeteMfXRa1QGpwtVygp6cOBaw gKL0aPvr pbhoUrzrLwWwsIFx1yUBWA9YHsEEFAgwVUz7VuW1bocY+FCWjDMfc+qvNYNMqTfkuOjF0kr48l3w0MhI2ZG2pOIZn0eWCUgfYvQJ0wrreOWxtTC5Pja/xzgIlg5JTKVpA8xEsPBneOA79oscC8QobIVNnnzWC3qoWxCrC+M93a9ylYjSQS8DdeLzCtRGFHuupC5OjnRhfOqAWtgUZ9yBg2zU5twLt0j9nSgci3DSaIeqe7Sy/qQhJSBf8AkyUXoo53PdOq8eyHWxG01CU9mPryeEwfsEwnk6VcFsdjRM1kFlcEnIZ+ga0AIm05zgZA9Jk4in3bXjYI4RnkeHNKXL68cbOu5+DVQt2MiCCnmqZ2WlhYGNTg+niwN4KK7DNXXHPI+yvQP53iP9+TfKYaZJDTEYK6rsblSwGnxnHhpEkG11NRn5iTNLWeYOeHlb3X2NXzWZW X-Bogosity: Ham, tests=bogofilter, spamicity=0.000063, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Michal Hocko 28307d938fb2 ("percpu: make pcpu_alloc() aware of current gfp context") has fixed a reclaim recursion for scoped GFP_NOFS context. It has done that by avoiding taking pcpu_alloc_mutex. This is a correct solution as the worker context with full GFP_KERNEL allocation/reclaim power and which is using the same lock cannot block the NOFS pcpu_alloc caller. On the other hand this is a very conservative approach that could lead to failures because pcpu_alloc lockless implementation is quite limited. We have a bug report about premature failures when scsi array of 193 devices is scanned. Sometimes (not consistently) the scanning aborts because the iscsid daemon fails to create the queue for a random scsi device during the scan. iscsid itslef is running with PR_SET_IO_FLUSHER set so all allocations from this process context are GFP_NOIO. This in turn makes any pcpu_alloc lockless (without pcpu_alloc_mutex) which leads to pre-mature failures. It has turned out that iscsid has worked around this by dropping PR_SET_IO_FLUSHER (https://github.com/open-iscsi/open-iscsi/pull/382) when scanning host. But we can do better in this case on the kernel side and use pcpu_alloc_mutex for NOIO resp. NOFS constrained allocation scopes too. We just need the WQ worker to never trigger IO/FS reclaim. Achieve that by enforcing scoped GFP_NOIO for the whole execution of pcpu_balance_workfn (this will imply NOFS constrain as well). This will remove the dependency chain and preserve the full allocation power of the pcpu_alloc call. While at it make is_atomic really test for blockable allocations. Fixes: 28307d938fb2 ("percpu: make pcpu_alloc() aware of current gfp context Signed-off-by: Michal Hocko Acked-by: Vlastimil Babka --- mm/percpu.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/mm/percpu.c b/mm/percpu.c index d8dd31a2e407..192c2a8e901d 100644 --- a/mm/percpu.c +++ b/mm/percpu.c @@ -1758,7 +1758,7 @@ void __percpu *pcpu_alloc_noprof(size_t size, size_t align, bool reserved, gfp = current_gfp_context(gfp); /* whitelisted flags that can be passed to the backing allocators */ pcpu_gfp = gfp & (GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN); - is_atomic = (gfp & GFP_KERNEL) != GFP_KERNEL; + is_atomic = !gfpflags_allow_blocking(gfp); do_warn = !(gfp & __GFP_NOWARN); /* @@ -2204,7 +2204,12 @@ static void pcpu_balance_workfn(struct work_struct *work) * to grow other chunks. This then gives pcpu_reclaim_populated() time * to move fully free chunks to the active list to be freed if * appropriate. + * + * Enforce GFP_NOIO allocations because we have pcpu_alloc users + * constrained to GFP_NOIO/NOFS contexts and they could form lock + * dependency through pcpu_alloc_mutex */ + unsigned int flags = memalloc_noio_save(); mutex_lock(&pcpu_alloc_mutex); spin_lock_irq(&pcpu_lock); @@ -2215,6 +2220,7 @@ static void pcpu_balance_workfn(struct work_struct *work) spin_unlock_irq(&pcpu_lock); mutex_unlock(&pcpu_alloc_mutex); + memalloc_noio_restore(flags); } /**