From patchwork Wed Aug 14 09:18:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: liuye X-Patchwork-Id: 13763138 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 D85F0C3DA4A for ; Wed, 14 Aug 2024 09:19:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 416216B0082; Wed, 14 Aug 2024 05:19:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3C58D6B0083; Wed, 14 Aug 2024 05:19:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 28D496B0085; Wed, 14 Aug 2024 05:19:50 -0400 (EDT) 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 0E3826B0082 for ; Wed, 14 Aug 2024 05:19:50 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 8D31F1C1FA9 for ; Wed, 14 Aug 2024 09:19:49 +0000 (UTC) X-FDA: 82450303698.19.C48BCC4 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) by imf09.hostedemail.com (Postfix) with ESMTP id B808D14000A for ; Wed, 14 Aug 2024 09:19:40 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf09.hostedemail.com: domain of liuye@kylinos.cn designates 124.126.103.232 as permitted sender) smtp.mailfrom=liuye@kylinos.cn ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723627117; 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: references; bh=8L5KgHSyr1g7HCzb6bDxWh3LOc4+elpjaRLJn7T6XKI=; b=PN9kzRTjGZlLxkoYae/QRr+3S5V9eMvkoqME/eh5QJPVuPKsJMYB0b6cqtN2gc8TYFHBsM /0Pe51iMnCiX90irfSEYkZ+VNbwCBdIGY70u10hL9wfgzioWy9XBousNRzUyl0cCZ0NMwN gUuCWjsuTmJ0JoMVcdkVRd9DiWGdgCg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723627117; a=rsa-sha256; cv=none; b=wc+01MA5SfPhIBkAkNWr/K32rCDu446+QaonpHaK6/u0mHvHmA05in7/jZxZmjFJ+ptBPi TS8TSmQ9wc609EAKoy3VQLxdh6l1DtCWT5zAqupDJkSEJQ3GrVyTWEpcOa8K3/IHVBgShZ FdzW7KGrWryrvmfWx0RpLqHsejJL+0Q= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf09.hostedemail.com: domain of liuye@kylinos.cn designates 124.126.103.232 as permitted sender) smtp.mailfrom=liuye@kylinos.cn X-UUID: 509545c05a1e11efa216b1d71e6e1362-20240814 X-CTIC-Tags: HR_CC_COUNT, HR_CC_DOMAIN_COUNT, HR_CC_NO_NAME, HR_CTE_8B, HR_CTT_TXT HR_DATE_H, HR_DATE_WKD, HR_DATE_ZONE, HR_FROM_NAME, HR_SJ_LANG HR_SJ_LEN, HR_SJ_LETTER, HR_SJ_NOR_SYM, HR_SJ_PHRASE, HR_SJ_PHRASE_LEN HR_SJ_WS, HR_TO_COUNT, HR_TO_DOMAIN_COUNT, HR_TO_NO_NAME, IP_TRUSTED SRC_TRUSTED, DN_TRUSTED, SA_UNTRUSTED, SA_UNFAMILIAR, SN_UNTRUSTED SN_UNFAMILIAR, SPF_NOPASS, DKIM_NOPASS, DMARC_NOPASS, CIE_BAD CIE_GOOD, CIE_GOOD_SPF, GTI_FG_BS, GTI_RG_INFO, GTI_C_BU AMN_T1, AMN_GOOD, AMN_C_TI, AMN_C_BU, ABX_MISS_RDNS X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.38,REQID:0e63fb48-8fd2-4258-9a96-6b1e513c1a52,IP:25, URL:0,TC:0,Content:-25,EDM:0,RT:0,SF:-5,FILE:0,BULK:0,RULE:Release_Ham,ACT ION:release,TS:-5 X-CID-INFO: VERSION:1.1.38,REQID:0e63fb48-8fd2-4258-9a96-6b1e513c1a52,IP:25,UR L:0,TC:0,Content:-25,EDM:0,RT:0,SF:-5,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:-5 X-CID-META: VersionHash:82c5f88,CLOUDID:77a89f181d9a5d44dd87b10eda787846,BulkI D:240814164706XOKLLZ1K,BulkQuantity:2,Recheck:0,SF:66|24|72|19|44|102,TC:n il,Content:0,EDM:-3,IP:-2,URL:0,File:nil,RT:nil,Bulk:40,QS:nil,BEC:nil,COL :0,OSI:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_FSD,TF_CID_SPAM_FSI X-UUID: 509545c05a1e11efa216b1d71e6e1362-20240814 X-User: liuye@kylinos.cn Received: from localhost.localdomain [(39.156.73.13)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA with TLSv1.3 TLS_AES_256_GCM_SHA384 256/256) with ESMTP id 268203527; Wed, 14 Aug 2024 17:19:31 +0800 From: liuye To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, liuye@kylinos.cn Subject: [PATCH] mm/vmscan: Fix hard LOCKUP in function isolate_lru_folios Date: Wed, 14 Aug 2024 17:18:25 +0800 Message-Id: <20240814091825.27262-1-liuye@kylinos.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Rspamd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TeWYKgMeaFZQMS Gl07uNYc +SbzQazacB1sGPBXLIRDA/2uJgZSsBL6zGnYWcNYplYhXabh4v8UK+cOV99i8LQHEzjm5pZsAJ9m2hAcoz/6sHnhjJdgaBEoZJf2jbicH5CQQuhCLjJ1Om9Iznw== 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: This fixes the following hard lockup in function isolate_lru_folios when memory reclaim.If the LRU mostly contains ineligible folios May trigger watchdog. watchdog: Watchdog detected hard LOCKUP on cpu 173 RIP: 0010:native_queued_spin_lock_slowpath+0x255/0x2a0 Call Trace: _raw_spin_lock_irqsave+0x31/0x40 folio_lruvec_lock_irqsave+0x5f/0x90 folio_batch_move_lru+0x91/0x150 lru_add_drain_per_cpu+0x1c/0x40 process_one_work+0x17d/0x350 worker_thread+0x27b/0x3a0 kthread+0xe8/0x120 ret_from_fork+0x34/0x50 ret_from_fork_asm+0x1b/0x30 lruvec->lru_lock owner: PID: 2865 TASK: ffff888139214d40 CPU: 40 COMMAND: "kswapd0" #0 [fffffe0000945e60] crash_nmi_callback at ffffffffa567a555 #1 [fffffe0000945e68] nmi_handle at ffffffffa563b171 #2 [fffffe0000945eb0] default_do_nmi at ffffffffa6575920 #3 [fffffe0000945ed0] exc_nmi at ffffffffa6575af4 #4 [fffffe0000945ef0] end_repeat_nmi at ffffffffa6601dde [exception RIP: isolate_lru_folios+403] RIP: ffffffffa597df53 RSP: ffffc90006fb7c28 RFLAGS: 00000002 RAX: 0000000000000001 RBX: ffffc90006fb7c60 RCX: ffffea04a2196f88 RDX: ffffc90006fb7c60 RSI: ffffc90006fb7c60 RDI: ffffea04a2197048 RBP: ffff88812cbd3010 R8: ffffea04a2197008 R9: 0000000000000001 R10: 0000000000000000 R11: 0000000000000001 R12: ffffea04a2197008 R13: ffffea04a2197048 R14: ffffc90006fb7de8 R15: 0000000003e3e937 ORIG_RAX: ffffffffffffffff CS: 0010 SS: 0018 #5 [ffffc90006fb7c28] isolate_lru_folios at ffffffffa597df53 #6 [ffffc90006fb7cf8] shrink_active_list at ffffffffa597f788 #7 [ffffc90006fb7da8] balance_pgdat at ffffffffa5986db0 #8 [ffffc90006fb7ec0] kswapd at ffffffffa5987354 #9 [ffffc90006fb7ef8] kthread at ffffffffa5748238 crash> Fixes: b2e18757f2c9 ("mm, vmscan: begin reclaiming pages on a per-node basis") Signed-off-by: liuye --- include/linux/swap.h | 1 + mm/vmscan.c | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/include/linux/swap.h b/include/linux/swap.h index ba7ea95d1c57..afb3274c90ef 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -223,6 +223,7 @@ enum { }; #define SWAP_CLUSTER_MAX 32UL +#define SWAP_CLUSTER_MAX_SKIPPED (SWAP_CLUSTER_MAX << 10) #define COMPACT_CLUSTER_MAX SWAP_CLUSTER_MAX /* Bit flag in swap_map */ diff --git a/mm/vmscan.c b/mm/vmscan.c index cfa839284b92..02a8f86d4883 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1655,6 +1655,7 @@ static unsigned long isolate_lru_folios(unsigned long nr_to_scan, unsigned long nr_skipped[MAX_NR_ZONES] = { 0, }; unsigned long skipped = 0; unsigned long scan, total_scan, nr_pages; + unsigned long max_nr_skipped = 0; LIST_HEAD(folios_skipped); total_scan = 0; @@ -1669,10 +1670,12 @@ static unsigned long isolate_lru_folios(unsigned long nr_to_scan, nr_pages = folio_nr_pages(folio); total_scan += nr_pages; - if (folio_zonenum(folio) > sc->reclaim_idx || - skip_cma(folio, sc)) { + /* Using max_nr_skipped to prevent hard LOCKUP*/ + if ((max_nr_skipped < SWAP_CLUSTER_MAX_SKIPPED) && + (folio_zonenum(folio) > sc->reclaim_idx || skip_cma(folio, sc))) { nr_skipped[folio_zonenum(folio)] += nr_pages; move_to = &folios_skipped; + max_nr_skipped++; goto move; }