From patchwork Thu Mar 21 18:25:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Johannes Weiner X-Patchwork-Id: 13599277 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 97AADC6FD1F for ; Thu, 21 Mar 2024 18:25:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D1C426B0085; Thu, 21 Mar 2024 14:25:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CCECE6B008C; Thu, 21 Mar 2024 14:25:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B94A96B0092; Thu, 21 Mar 2024 14:25:40 -0400 (EDT) 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 A97A36B0085 for ; Thu, 21 Mar 2024 14:25:40 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 823A5C04E1 for ; Thu, 21 Mar 2024 18:25:40 +0000 (UTC) X-FDA: 81921874440.22.BABEF88 Received: from mail-qk1-f176.google.com (mail-qk1-f176.google.com [209.85.222.176]) by imf21.hostedemail.com (Postfix) with ESMTP id 9668C1C0005 for ; Thu, 21 Mar 2024 18:25:38 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=JPUdzvnP; spf=pass (imf21.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.222.176 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org; dmarc=pass (policy=none) header.from=cmpxchg.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711045538; 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=/N8O7+oWMYcfdby+p0lm0Df2Q9f94VlAjnDmiCzjw4E=; b=GdL2BYAg5cV5w6RHT/SGJH1JiIkTvjFB3f0Ujh1rONTt/Y99fNdsG7rRPa8hCX/6n3PYp6 Fi63lnB7oEW0dG1jRNVc+CGcaag4dlBjzKOXQ5BUKAXCDZ9Ah/MWOmgmp/vhwsf4lHeFKI rksa2hBETiiM241Vkv6Q0fExFzIbpfw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711045538; a=rsa-sha256; cv=none; b=fKKGV5V0wCo4XAJE93/ryhaKGVRf1gKgU4JZhlVXV4RvHz0zRi2QniS0EPkO715aEEvAQa +TfVDdgYpnXKioN0vUgSBxRf/wImxqzu3JsxsCnz+T6ECkjIwKNaKKfPZNEIZnNkwKBoHA JDmAsbj4avETm+P8v5GP5oPs5RAs4Uo= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=JPUdzvnP; spf=pass (imf21.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.222.176 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org; dmarc=pass (policy=none) header.from=cmpxchg.org Received: by mail-qk1-f176.google.com with SMTP id af79cd13be357-78a2093cd44so104342585a.0 for ; Thu, 21 Mar 2024 11:25:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20230601.gappssmtp.com; s=20230601; t=1711045537; x=1711650337; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=/N8O7+oWMYcfdby+p0lm0Df2Q9f94VlAjnDmiCzjw4E=; b=JPUdzvnPLvzq+LGtaqPg6mEXKmVSlf39PGMB6vkNaH99OTiY5YLS0miKAoDFZ8lKEU isO8nZq5wXPfmHhKZ1Y3Rmz1pvtAZiKfAqvG2WHuJLXoIG9D3YWRsv3QssRG9KpPOiFk 2CaRgzKewHfv7odppC/JUbLnIcFg4fmraRRbpr7mvCoJMxehDXV3Qk7F3WVLO+nyYMNU BcWImCmj5Zq2vwR0D3qW7VPRpV5ciaqgwlWERuJ6mM9X16eCzhLjN8v4obZigSr0CszO OlLdsubfNu6Es1rwTc0CM+DrH5plhGudEbplhr/jtfXWj5KoE0m6RDt2YuNHLyWi5ptV G3Sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711045537; x=1711650337; 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=/N8O7+oWMYcfdby+p0lm0Df2Q9f94VlAjnDmiCzjw4E=; b=D7HXD1OyzeycGJB/E3PpQJzUitt+tnfWyYxYTYMV1iU0QxTjPg2bUDzxOvhghYYWXG IaRDUoJzXYNdeMTj4gvplYk81SNSaU+y0S3RdExGb0kyrGITW6t+9NIb90VrBOyYsqRZ yC0LYWFNY8TJvsL+DafZP6FuCon1FuHwqMHA+2l/0hwGo9sQDnM3ElnVpJKwyk+A65ua 5OvO0Gyt1mY7oNi6iB5loWV0m5RgGiT2H8aL9bPn0D+/L+TIbcQCVvy+MmBxFTWP5/GA 0tarV1AHTV3CNdWQKgbiI+A8SbQJCEHBbYbnglEuzVSbMLXmoTyv3Yd5V6Osj7HzedCW H1yg== X-Forwarded-Encrypted: i=1; AJvYcCXavHAXxH04LPptiMGpnkFWIzz7A9LySGCYY2kZy9/ifxhIW5BYGilzX58cPA8hl5zQhky16E8Mj+aG2yv9fRe1/kE= X-Gm-Message-State: AOJu0YyQBFRNfLAogT/LJ85Z106XSI9C9rMAxzqPwUSNqJmaAwe90Ltx FWwrhtbNQw5bgAKLYpoIA5wWiVk6p7crscBGXm7OmWXBlbrfnRzm1Ag8ESZgO9k= X-Google-Smtp-Source: AGHT+IEse7B1NYDndrw9NXwdauLfoIqRPAn4cgINmWelWR7WD1qMnJ8xgQB+4hbQOKGMWCWUmWb7+w== X-Received: by 2002:a05:6214:130f:b0:696:4771:e009 with SMTP id pn15-20020a056214130f00b006964771e009mr3328164qvb.4.1711045537648; Thu, 21 Mar 2024 11:25:37 -0700 (PDT) Received: from localhost ([2620:10d:c091:400::5:6036]) by smtp.gmail.com with ESMTPSA id r5-20020ad45765000000b0069019c6eff1sm151086qvx.31.2024.03.21.11.25.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 11:25:36 -0700 (PDT) From: Johannes Weiner To: Andrew Morton Cc: Kent Overstreet , Chengming Zhou , Nhat Pham , Yosry Ahmed , linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH] mm: zswap: fix writeback shinker GFP_NOIO/GFP_NOFS recursion Date: Thu, 21 Mar 2024 14:25:32 -0400 Message-ID: <20240321182532.60000-1-hannes@cmpxchg.org> X-Mailer: git-send-email 2.44.0 MIME-Version: 1.0 X-Rspamd-Queue-Id: 9668C1C0005 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: yto9t7eqoong7y5jghq86ydi848zfbnp X-HE-Tag: 1711045538-155519 X-HE-Meta: U2FsdGVkX1+9NcO5sId2wHnhBUVK9Ecf4OIJ9aBWtj93XF7K0eo2ko5zU0o6M4DfCSqki4Pomckin/0s13/v4hJ0Pqkgrcv+nY6tzTa5aBoj0r7JMD5TylkYE40UwjICWOkCq6r4nFddSU3Ih2FDMw0sCn9it7JyXbCY9xGWNmiovr4i7XHGxKv1EgwGLEAk8J9E/7XBqkD/rC1j8vAbzP0l9J4x8g5rSjCZL1KCQfY7wuLn4qwv1+8ooE1ib5cbTw9rSkmLRIecP8ZGrITgS+Gt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iGSU6Wi7ZCcvEjgB1i2OUMHzfHdLDGtne+MOIXWXTum17hABvEq0aDTmtbE2mARCQIMOp0FvVZW1q0XYBTDLdqVWMHo6nWd8NAmz+1K7jM+bxjoqGT26txMX4buscs6lfZuRjGGEfQPG7+V2Mp7tmrOUXb6pannW1P7k7Lebk0L71W5AbdGxA83iQ6UFpYxksc7UwrKfVbFCojpcmxK14QQyV5kmnyk+QwcXHGifJp6A0eFa2Kxf4TAuw/Vh75FbBI= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000006, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Kent forwards this bug report of zswap re-entering the block layer from an IO request allocation and locking up: [10264.128242] sysrq: Show Blocked State [10264.128268] task:kworker/20:0H state:D stack:0 pid:143 tgid:143 ppid:2 flags:0x00004000 [10264.128271] Workqueue: bcachefs_io btree_write_submit [bcachefs] [10264.128295] Call Trace: [10264.128295] [10264.128297] __schedule+0x3e6/0x1520 [10264.128303] schedule+0x32/0xd0 [10264.128304] schedule_timeout+0x98/0x160 [10264.128308] io_schedule_timeout+0x50/0x80 [10264.128309] wait_for_completion_io_timeout+0x7f/0x180 [10264.128310] submit_bio_wait+0x78/0xb0 [10264.128313] swap_writepage_bdev_sync+0xf6/0x150 [10264.128317] zswap_writeback_entry+0xf2/0x180 [10264.128319] shrink_memcg_cb+0xe7/0x2f0 [10264.128322] __list_lru_walk_one+0xb9/0x1d0 [10264.128325] list_lru_walk_one+0x5d/0x90 [10264.128326] zswap_shrinker_scan+0xc4/0x130 [10264.128327] do_shrink_slab+0x13f/0x360 [10264.128328] shrink_slab+0x28e/0x3c0 [10264.128329] shrink_one+0x123/0x1b0 [10264.128331] shrink_node+0x97e/0xbc0 [10264.128332] do_try_to_free_pages+0xe7/0x5b0 [10264.128333] try_to_free_pages+0xe1/0x200 [10264.128334] __alloc_pages_slowpath.constprop.0+0x343/0xde0 [10264.128337] __alloc_pages+0x32d/0x350 [10264.128338] allocate_slab+0x400/0x460 [10264.128339] ___slab_alloc+0x40d/0xa40 [10264.128345] kmem_cache_alloc+0x2e7/0x330 [10264.128348] mempool_alloc+0x86/0x1b0 [10264.128349] bio_alloc_bioset+0x200/0x4f0 [10264.128352] bio_alloc_clone+0x23/0x60 [10264.128354] alloc_io+0x26/0xf0 [dm_mod 7e9e6b44df4927f93fb3e4b5c782767396f58382] [10264.128361] dm_submit_bio+0xb8/0x580 [dm_mod 7e9e6b44df4927f93fb3e4b5c782767396f58382] [10264.128366] __submit_bio+0xb0/0x170 [10264.128367] submit_bio_noacct_nocheck+0x159/0x370 [10264.128368] bch2_submit_wbio_replicas+0x21c/0x3a0 [bcachefs 85f1b9a7a824f272eff794653a06dde1a94439f2] [10264.128391] btree_write_submit+0x1cf/0x220 [bcachefs 85f1b9a7a824f272eff794653a06dde1a94439f2] [10264.128406] process_one_work+0x178/0x350 [10264.128408] worker_thread+0x30f/0x450 [10264.128409] kthread+0xe5/0x120 The zswap shrinker resumes the swap_writepage()s that were intercepted by the zswap store. This will enter the block layer, and may even enter the filesystem depending on the swap backing file. Make it respect GFP_NOIO and GFP_NOFS. Link: https://lore.kernel.org/linux-mm/rc4pk2r42oyvjo4dc62z6sovquyllq56i5cdgcaqbd7wy3hfzr@n4nbxido3fme/ Reported-by: Kent Overstreet Fixes: b5ba474f3f51 ("zswap: shrink zswap pool based on memory pressure") Cc: stable@vger.kernel.org [v6.8] Signed-off-by: Johannes Weiner Acked-by: Yosry Ahmed Reported-by: Jérôme Poulin Reviewed-by: Chengming Zhou Reviewed-by: Nhat Pham --- mm/zswap.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mm/zswap.c b/mm/zswap.c index b31c977f53e9..535c907345e0 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1303,6 +1303,14 @@ static unsigned long zswap_shrinker_count(struct shrinker *shrinker, if (!zswap_shrinker_enabled || !mem_cgroup_zswap_writeback_enabled(memcg)) return 0; + /* + * The shrinker resumes swap writeback, which will enter block + * and may enter fs. XXX: Harmonize with vmscan.c __GFP_FS + * rules (may_enter_fs()), which apply on a per-folio basis. + */ + if (!gfp_has_io_fs(sc->gfp_mask)) + return 0; + #ifdef CONFIG_MEMCG_KMEM mem_cgroup_flush_stats(memcg); nr_backing = memcg_page_state(memcg, MEMCG_ZSWAP_B) >> PAGE_SHIFT;