From patchwork Sun May 14 00:28:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tetsuo Handa X-Patchwork-Id: 13240372 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 ED628C77B7D for ; Sun, 14 May 2023 00:29:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0905D6B0071; Sat, 13 May 2023 20:29:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 040036B0072; Sat, 13 May 2023 20:29:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E70F36B0074; Sat, 13 May 2023 20:29:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id D00706B0071 for ; Sat, 13 May 2023 20:29:05 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 9C4ADAF097 for ; Sun, 14 May 2023 00:29:04 +0000 (UTC) X-FDA: 80786975808.01.68B4F03 Received: from www262.sakura.ne.jp (www262.sakura.ne.jp [202.181.97.72]) by imf11.hostedemail.com (Postfix) with ESMTP id 595194000C for ; Sun, 14 May 2023 00:29:00 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=none; dmarc=none; spf=none (imf11.hostedemail.com: domain of penguin-kernel@I-love.SAKURA.ne.jp has no SPF policy when checking 202.181.97.72) smtp.mailfrom=penguin-kernel@I-love.SAKURA.ne.jp ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684024141; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=U9Q1qhcueE72Cs1xsewYojadsR3S/wbgq+pHgf6k1D0=; b=j0m8RLDHgwpBRIcTjTbnMMqJwKpIy51vRVlDjE5awyZUJmLybbPiaKu9I90Vaiy5rgyao+ OPHzxMdbU3JZoNNzXHvLmZdS0yLQG7Plux9TfUdS/St/EGkXv1JCFvLZry8KyNPUDnwYL6 5JTGUaPHIjPSorALxrLZNSI7alwe7H4= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=none; dmarc=none; spf=none (imf11.hostedemail.com: domain of penguin-kernel@I-love.SAKURA.ne.jp has no SPF policy when checking 202.181.97.72) smtp.mailfrom=penguin-kernel@I-love.SAKURA.ne.jp ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684024141; a=rsa-sha256; cv=none; b=tlaTWbO3gBSSOIy1coM6N0G61dGTDTGSTIEofyn5jg6Ne4oJ/3KaT+KS8TlKtNpbMHvwDx 1Y2pgSogY/sM0nTOlVEUFzhBeeqI5Wc6G+zrU/jO3lqh5iwq+S269VxPMOVmWQicbqrPVQ quet9O1SNs2Njhr7L2JIP0HQTZj2cXE= Received: from fsav113.sakura.ne.jp (fsav113.sakura.ne.jp [27.133.134.240]) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTP id 34E0Sun3026896; Sun, 14 May 2023 09:28:56 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Received: from www262.sakura.ne.jp (202.181.97.72) by fsav113.sakura.ne.jp (F-Secure/fsigk_smtp/550/fsav113.sakura.ne.jp); Sun, 14 May 2023 09:28:56 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/550/fsav113.sakura.ne.jp) Received: from [192.168.1.6] (M106072142033.v4.enabler.ne.jp [106.72.142.33]) (authenticated bits=0) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTPSA id 34E0SuHg026892 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NO); Sun, 14 May 2023 09:28:56 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Message-ID: Date: Sun, 14 May 2023 09:28:56 +0900 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.10.1 Subject: [PATCH v2] mm/page_alloc: don't wake kswapd from rmqueue() unless __GFP_KSWAPD_RECLAIM is specified Content-Language: en-US To: Mel Gorman , Andrew Morton Cc: Vlastimil Babka , linux-mm References: <6d6fb601-6100-92b9-cea3-e7ebacc7693a@I-love.SAKURA.ne.jp> <20230513102314.md5ugj22xnv6mxob@techsingularity.net> From: Tetsuo Handa In-Reply-To: <20230513102314.md5ugj22xnv6mxob@techsingularity.net> X-Stat-Signature: juw6njd5tmp6zyu1y6931utwqotfnbyj X-Rspam-User: X-Rspamd-Queue-Id: 595194000C X-Rspamd-Server: rspam07 X-HE-Tag: 1684024140-932713 X-HE-Meta: U2FsdGVkX18vFys8/TVcypeEzDHnFdIIMaL1wFQL+BShSo/ER4OEFq48Mr02/myDwmd3o0LkPvBP3EfJpyZcVWi0eOYHLqhe5y0zUMWnFb70QBAAyMGt79JfwYvPlYaIfBcWhBMSSLfjeODEgeFdZnq64XNgFqyB1UKbyLT05N6HYe7P8NZa9ItmdRUh9pgXenD+nUaPICV2sRAGUU98/EDASXBv87RgYhe5RtNzV/9Kgzq0YYdsGlgcYrGSRf9OfUBXZtkVyWfNJb+D9xLAK5T0SyfxKH1QYFF44s3BenPtlTa1NviLyPXr9wbfuqyCIk7tl9YQH6lPdxaxPONJtz8oPf2gvtY3oQKVYk9CLuV0QL+PT5/XwBy/DaU39tdmSG+5+1jF4FQ6ga8xqK3eIv9L09DIKHAmRGtp3sufCh3kZuZ94QXAIIJ+m0Q3UWtJX/xAMuNNdinXdvAtjBenRc/cXcfZzjYn/x5HW3tduhmcvA66uxh/SCwsBSRHSZct+Gq9aEFHsTL7Oez1bc0cg2dDdP/zPCKT3zZkzCn85fEQTJMlrVz86dQg1nfkItttEtDqVqLVCLgAatRleN/TCqcQoFgNG+ZI4NBJqa/BKkdV6/NvyNe2NBBfJa4BRmntHXMlNOJcE7ckPZgZyWkNdzTMCEJbcke8jJpZE0Frq9MZSiRgHnAdYXF+6/4QolkuZ+zsLxmRjQdVkQ143z87HAu3SSlCALdh6EV0QMT28klASZwLTR1LkpJ32XHQW64oh2wFuhvIGdO8QKgghGb7ZE0Xv5kQiQQBlWvVoJcKY8UzzyJsDXx9YysGMtGOwI367xTszHTAEn3xdWeaic7GrXrixBmMAo60bQqb+7uv9TaPsDeJQmjZUd3E0b0LUgw+7Bb/H8wOnrnsvP1dZuKhBiP0jmCOXvHUK6O0yD94n2d+KjVdyd3+SrsjHbkCbrrzir5yFpyT6KLTixPuz6Y bI3VX8a5 vO+fkQ5Tgohxvn8GAOqeLAPceA87TxUw2GPZsamRfeC8qH6+Ks1Xk+BN+aIvkOdMqVolaBTNEi0147UXH3GRD+7WkA7uW6JaRWwZANeDFiWnD0T6regrglqA+oSHpatuuBJPQSRGKEcJC1OZgtct8YcGvY6bl/EnB7ikSYqsSuChtX94zWvOIXebpk9OS24vFNUC9tQ/0lCpfuBXQY293DqnrG/OBSZNbJXgiXcXDdrHd8V1r9uaxjPMLghVio0e8I2jDYTMj0lQ02PBFSJ/8WLShG/1TmvoHAu/eNpH9I5LlQ8UDmufdpp49lL69rYnpL9AN X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Commit 73444bc4d8f9 ("mm, page_alloc: do not wake kswapd with zone lock held") moved wakeup_kswapd() from steal_suitable_fallback() to rmqueue() using ZONE_BOOSTED_WATERMARK flag. Only allocation contexts that include ALLOC_KSWAPD (which corresponds to __GFP_KSWAPD_RECLAIM) should wake kswapd, for callers are supposed to remove __GFP_KSWAPD_RECLAIM if trying to hold pgdat->kswapd_wait has a risk of deadlock. But since zone->flags is a shared variable, a thread doing !__GFP_KSWAPD_RECLAIM allocation request might observe this flag being set immediately after another thread doing __GFP_KSWAPD_RECLAIM allocation request set this flag, causing possibility of deadlock. Signed-off-by: Tetsuo Handa Fixes: 73444bc4d8f9 ("mm, page_alloc: do not wake kswapd with zone lock held") Acked-by: Mel Gorman --- Changes in v2: Check ALLOC_KSWAPD before checking ZONE_BOOSTED_WATERMARK and update description, suggested by Mel Gorman . mm/page_alloc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 47421bedc12b..ecad680cec53 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -3052,7 +3052,8 @@ struct page *rmqueue(struct zone *preferred_zone, out: /* Separate test+clear to avoid unnecessary atomics */ - if (unlikely(test_bit(ZONE_BOOSTED_WATERMARK, &zone->flags))) { + if ((alloc_flags & ALLOC_KSWAPD) && + unlikely(test_bit(ZONE_BOOSTED_WATERMARK, &zone->flags))) { clear_bit(ZONE_BOOSTED_WATERMARK, &zone->flags); wakeup_kswapd(zone, 0, 0, zone_idx(zone)); }