From patchwork Tue Nov 26 15:06:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Seiji Nishikawa X-Patchwork-Id: 13886107 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 ECB86D3B99E for ; Tue, 26 Nov 2024 15:06:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 83B0E6B0092; Tue, 26 Nov 2024 10:06:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7C5166B0093; Tue, 26 Nov 2024 10:06:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 68B7E6B0095; Tue, 26 Nov 2024 10:06:26 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 435B56B0092 for ; Tue, 26 Nov 2024 10:06:26 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 0A0D7AE22B for ; Tue, 26 Nov 2024 15:06:26 +0000 (UTC) X-FDA: 82828572036.27.0330429 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf04.hostedemail.com (Postfix) with ESMTP id 599844001B for ; Tue, 26 Nov 2024 15:06:18 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=J4SVtbVO; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf04.hostedemail.com: domain of snishika@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=snishika@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732633582; a=rsa-sha256; cv=none; b=qmrfp1r9r8YDaJe7XzIXAKnvijB6dfjit6e5vwYE2fQVPVgpVb3HS7aWhYizXAn5H6Sclb NpVbjAa/Z3zhxYelqldVaNQhKit4oCX8b25LxeI0C0Tbp9IzmidSd9dFlJdt0EMe7+hCEd VoGxT9qMXLqKhHoRnRBkfTwZe+9coC0= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=J4SVtbVO; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf04.hostedemail.com: domain of snishika@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=snishika@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732633582; 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:dkim-signature; bh=aWtzZaH0bLct3rhvon/rPVAtnCGovq5FTEt4jgcwO18=; b=fCXmD65eyBNpvnMBWz0i6zcEySUYHE9lf6Doe+lfsLpsMLnDWE6vrU0SBR1nU7D8AwK9+3 OmemL47A2C7J16ecblpi+Togd/hkYcCgWKYKyl838DXDbjP4+ZpeKnmls3iB+lzZhy8VH7 LfwaSTnkuxFvTw32TB0mHu4hsk/Ta/U= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732633583; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=aWtzZaH0bLct3rhvon/rPVAtnCGovq5FTEt4jgcwO18=; b=J4SVtbVOMWqOG0m+t6zr8CGHco5sLIOF6FgkMWXynb9fOtdEwX/V9ip4Dd7PdukAe1HOCZ 4xUPERe6+PeELptGYzvfXCPuDdF/SqNpoLR5Lfhh5wEPzxIK3K0pkPmu/hpBl401krcpOr wTAJSLmtjBD1yrWpUETyWkpj4JM+2DU= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-644-igZIsYMENM6pU3lOFbNPrg-1; Tue, 26 Nov 2024 10:06:19 -0500 X-MC-Unique: igZIsYMENM6pU3lOFbNPrg-1 X-Mimecast-MFC-AGG-ID: igZIsYMENM6pU3lOFbNPrg Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B3F471955F45; Tue, 26 Nov 2024 15:06:18 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.64.33]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id CEFA7196BC05; Tue, 26 Nov 2024 15:06:16 +0000 (UTC) From: Seiji Nishikawa To: akpm@linux-foundation.org, linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, snishika@redhat.com Subject: [PATCH] mm: vmscan: ensure kswapd is woken up if the wait queue is active Date: Wed, 27 Nov 2024 00:06:12 +0900 Message-ID: <20241126150612.114561-1-snishika@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Rspam-User: X-Rspamd-Queue-Id: 599844001B X-Rspamd-Server: rspam11 X-Stat-Signature: hhwoqoit7n8dd5kmfywp14y8iab8amp7 X-HE-Tag: 1732633578-2694 X-HE-Meta: U2FsdGVkX1/UmXdAVp/VBEmlu7+tzEF0L7DKot0gc6sV4MbXjsPScaNd7w/w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Lob2QANBlbGeENZE8ArjXdnUUOdXR8FXxbwEWfA+TjGxRd9l+V0sfB94RoxEV/ehmCziD3LmS1IlU69G7uIAcbW69lx0mIOMthNVT8QM/AGNbt3V7Pf22YJFISJa/z13SRdDtKnwu3i4TZMMNc6u8LX5z6Uf/fy/HEHzIBsJ0zkpy2YQ3VdlOrwg 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: List-Subscribe: List-Unsubscribe: Even after commit 501b26510ae3 ("vmstat: allow_direct_reclaim should use zone_page_state_snapshot"), a task may remain indefinitely stuck in throttle_direct_reclaim() while holding mm->rwsem. __alloc_pages_nodemask try_to_free_pages throttle_direct_reclaim This can cause numerous other tasks to wait on the same rwsem, leading to severe system hangups: [1088963.358712] INFO: task python3:1670971 blocked for more than 120 seconds. [1088963.365653] Tainted: G OE -------- - - 4.18.0-553.el8_10.aarch64 #1 [1088963.373887] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. [1088963.381862] task:python3 state:D stack:0 pid:1670971 ppid:1667117 flags:0x00800080 [1088963.381869] Call trace: [1088963.381872] __switch_to+0xd0/0x120 [1088963.381877] __schedule+0x340/0xac8 [1088963.381881] schedule+0x68/0x118 [1088963.381886] rwsem_down_read_slowpath+0x2d4/0x4b8 The issue arises when allow_direct_reclaim(pgdat) returns false, preventing progress even when the pgdat->pfmemalloc_wait wait queue is empty. Despite the wait queue being empty, the condition, allow_direct_reclaim(pgdat), may still be returning false, causing it to continue looping. In some cases, reclaimable pages exist (zone_reclaimable_pages() returns > 0), but calculations of pfmemalloc_reserve and free_pages result in wmark_ok being false. And then, despite the pgdat->kswapd_wait queue being non-empty, kswapd is not woken up, further exacerbating the problem: crash> px ((struct pglist_data *) 0xffff00817fffe540)->kswapd_highest_zoneidx $775 = __MAX_NR_ZONES This patch modifies allow_direct_reclaim() to wake kswapd if the pgdat->kswapd_wait queue is active, regardless of whether wmark_ok is true or false. This change ensures kswapd does not miss wake-ups under high memory pressure, reducing the risk of task stalls in the throttled reclaim path. Signed-off-by: Seiji Nishikawa --- mm/vmscan.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 76378bc257e3..b1b3e5a116a8 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -6389,8 +6389,8 @@ static bool allow_direct_reclaim(pg_data_t *pgdat) wmark_ok = free_pages > pfmemalloc_reserve / 2; - /* kswapd must be awake if processes are being throttled */ - if (!wmark_ok && waitqueue_active(&pgdat->kswapd_wait)) { + /* Always wake up kswapd if the wait queue is not empty */ + if (waitqueue_active(&pgdat->kswapd_wait)) { if (READ_ONCE(pgdat->kswapd_highest_zoneidx) > ZONE_NORMAL) WRITE_ONCE(pgdat->kswapd_highest_zoneidx, ZONE_NORMAL);