From patchwork Fri Nov 22 23:23:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joanne Koong X-Patchwork-Id: 13883704 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 287A2E6ADCB for ; Fri, 22 Nov 2024 23:24:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E4E436B0085; Fri, 22 Nov 2024 18:24:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DFE726B0089; Fri, 22 Nov 2024 18:24:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C82026B008A; Fri, 22 Nov 2024 18:24:29 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id ABDC56B0085 for ; Fri, 22 Nov 2024 18:24:29 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 69E0180191 for ; Fri, 22 Nov 2024 23:24:29 +0000 (UTC) X-FDA: 82815312258.26.46846B5 Received: from mail-yw1-f179.google.com (mail-yw1-f179.google.com [209.85.128.179]) by imf20.hostedemail.com (Postfix) with ESMTP id 6437B1C0017 for ; Fri, 22 Nov 2024 23:24:27 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=jrKgnh2B; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf20.hostedemail.com: domain of joannelkoong@gmail.com designates 209.85.128.179 as permitted sender) smtp.mailfrom=joannelkoong@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732317867; 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:in-reply-to:references:references:dkim-signature; bh=hqCGll30CJiyTPfCOluQLlSYspNea277q8s6Em+tUXY=; b=7QAa1cDuo3w/Uf73oKFFDmpjSQ1Tgn+EdiGuGstChfiWZORZZvgSwWXP0cSlCo+cJgpztI HQod1D8WFDW44OwPBgtSo/QEy4OzlPBUDPgn8ExZ7wvpIG5sUhWQf4Vw2UbBylk5dgztk2 P3bYo5u+fvNuJ10dYVlvWKGBu3gW3y4= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=jrKgnh2B; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf20.hostedemail.com: domain of joannelkoong@gmail.com designates 209.85.128.179 as permitted sender) smtp.mailfrom=joannelkoong@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732317867; a=rsa-sha256; cv=none; b=erExVjn49NX1HzJ4tfI+uztDDMWsExBn7xX4oY5TS5CK+KV5y+cAyqPTYm02EgXDrkXiSX MWoew3z1o5cEvJSNL1JVqMYS/I+auDx6nRXzAdzos4UmQxTny2Fpk1PETeaaLzaNIj3wDS 3BYz5BUZCZYzDNfhY923xsDU0yi6hHw= Received: by mail-yw1-f179.google.com with SMTP id 00721157ae682-6ee805c96dbso25706007b3.2 for ; Fri, 22 Nov 2024 15:24:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732317867; x=1732922667; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hqCGll30CJiyTPfCOluQLlSYspNea277q8s6Em+tUXY=; b=jrKgnh2BHILi6Moj0yLvA08v7N5PVUTKaZA+T3Q1tRkBaat8wDndswhJd3zui2Yn0E GaMz7NXrw/2xP974ZhwijrAxejw4g0UTBTTLvgt5GBL0s/zjw5KkGUul5JNSgpxJTuLZ Bffza4nbl3odKl/Aor4qF8dMyTCUFOBhD1aj8Wnw31U2XESRFXvueCmpfY6S35Wlq2wm qD2jtu0Pb9e0gm40K0B2urBK1QwwAlfVgKuGYtlICMuUyMjbAT2B6ZmMPvTCiztqbXOz KCzbI2Jo1uMgrWe8VrbllZNgxFRFplaNAjLjSs+p0gtgh55WCLgECs4sUpDNvN++0B7Y f3cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732317867; x=1732922667; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hqCGll30CJiyTPfCOluQLlSYspNea277q8s6Em+tUXY=; b=OBUrszW1NVp2BZny58PyXUNIMFKp+7EsNPqgixqL70Pdth12Sc/5ExYm1gYSgV+n75 zrS26URSJZGNJ8b3rITLOHpqqR2aZUrTxqGyus4twKocGW1hGUtIKCKYLpnN7E72QliO 4uWby9pG/bBj+OEDbs+hdBydYnSdEHLXb1kLSAtL9l7hlqnIHfnh6rEeM4TW3JOhU8FJ 2H7AvLjAcATj97FF0fZIstMRG1iMxvjc5S4nwG3NToFLN0ryP9iMnwkuiOKH7/8NfBTH 28erofOzspPK2PcRDdyAcoGzo6pv70Dhb8FUZc0G3VBJGhW1A37fBPLm+dKbOKTRioXJ Bz+w== X-Forwarded-Encrypted: i=1; AJvYcCW0FmwWujsdghmn0RV8Wa7v2RnKGfZ94cG6UhA3nLLIg9MAYxgRB5PBIfrS3RXyViyrohY03dI8kw==@kvack.org X-Gm-Message-State: AOJu0YwnOpMBXZbDQKE8cpCCO7qfWD7B0gdVhhB2c81HJ3X5OF99XbaE xpr3iSGbcMRz2qm+3NU+YZH0fUR97V1dgMoY/8YJCuOwIhgYMhY0 X-Gm-Gg: ASbGncux0alq7P4UlHyCThISsSlKX9qhJfGrs77KGXKYfEHk4zML3YrAcSIplKbdfG1 3aONtZkmW9xByYQZUX3Zg5G7C+GI90/nNLTpo0/eQ5+semxW4Qpa7omm3yIGLXnyqsvsFla78XZ jA0tDXCTBrlIHGKDyks3c9e5HuzdAAJntUPzNPPnwDyLxNeP7Q8D2MnxSLNxm8vMadSQ7pElU3u teh8XraNyy6mM0YlXfIJQxfj/PqTk3n4XpAgxkws0HI2tRXbfxPB6h+DVdnP0Gp6UTgkeiAxggz txbNu7rw X-Google-Smtp-Source: AGHT+IFKU5jQK1lagqG1ya3hMgLoQLO7xg2eEmLkI7xWE77dGiRpSdFWIYkKQ4nezV34Rrjdl5rIMA== X-Received: by 2002:a05:690c:688a:b0:6ea:96bf:1706 with SMTP id 00721157ae682-6eee07c224emr61916467b3.0.1732317866710; Fri, 22 Nov 2024 15:24:26 -0800 (PST) Received: from localhost (fwdproxy-nha-006.fbsv.net. [2a03:2880:25ff:6::face:b00c]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6eedfe2c142sm6918917b3.48.2024.11.22.15.24.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Nov 2024 15:24:26 -0800 (PST) From: Joanne Koong To: miklos@szeredi.hu, linux-fsdevel@vger.kernel.org Cc: shakeel.butt@linux.dev, jefflexu@linux.alibaba.com, josef@toxicpanda.com, bernd.schubert@fastmail.fm, linux-mm@kvack.org, kernel-team@meta.com Subject: [PATCH v6 2/5] mm: skip reclaiming folios in legacy memcg writeback indeterminate contexts Date: Fri, 22 Nov 2024 15:23:56 -0800 Message-ID: <20241122232359.429647-3-joannelkoong@gmail.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241122232359.429647-1-joannelkoong@gmail.com> References: <20241122232359.429647-1-joannelkoong@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 6437B1C0017 X-Stat-Signature: tw7f7k1zofjywupft3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dFyrsMhqCon23cATCkOmKBqRp2mIg/nFjt7u5ZK4wSeDaCzzL6cH3C8DA/OZdRcacYyFoKzNJ9Gkj9iXxCKrT3IEba4e+IUxi+hwuTyyjPH07z4YxFl93QnmwF1cLrqDEDNFy29gL4FDgJXtbvzrcqwYKjPJ1qA8RxsJPOK7QBOUp9+mjkaw+tl+yoW+eVB4EYF5k8GL4a8mzdZTYpXriYuHVYWAJbtD0Vl4feR0qUEj0ebcUsaEytPtl1dx2oQsME3sr37KgTeeB+bzEikIFFyC+18Eyegjlcc8ByXSqRdWDIW3TsbpUb2vIWm2ag= 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: Currently in shrink_folio_list(), reclaim for folios under writeback falls into 3 different cases: 1) Reclaim is encountering an excessive number of folios under writeback and this folio has both the writeback and reclaim flags set 2) Dirty throttling is enabled (this happens if reclaim through cgroup is not enabled, if reclaim through cgroupv2 memcg is enabled, or if reclaim is on the root cgroup), or if the folio is not marked for immediate reclaim, or if the caller does not have __GFP_FS (or __GFP_IO if it's going to swap) set 3) Legacy cgroupv1 encounters a folio that already has the reclaim flag set and the caller did not have __GFP_FS (or __GFP_IO if swap) set In cases 1) and 2), we activate the folio and skip reclaiming it while in case 3), we wait for writeback to finish on the folio and then try to reclaim the folio again. In case 3, we wait on writeback because cgroupv1 does not have dirty folio throttling, as such this is a mitigation against the case where there are too many folios in writeback with nothing else to reclaim. For filesystems where writeback may take an indeterminate amount of time to write to disk, this has the possibility of stalling reclaim. In this commit, if legacy memcg encounters a folio with the reclaim flag set (eg case 3) and the folio belongs to a mapping that has the AS_WRITEBACK_INDETERMINATE flag set, the folio will be activated and skip reclaim (eg default to behavior in case 2) instead. Signed-off-by: Joanne Koong Reviewed-by: Shakeel Butt --- mm/vmscan.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 749cdc110c74..37ce6b6dac06 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1129,8 +1129,9 @@ static unsigned int shrink_folio_list(struct list_head *folio_list, * 2) Global or new memcg reclaim encounters a folio that is * not marked for immediate reclaim, or the caller does not * have __GFP_FS (or __GFP_IO if it's simply going to swap, - * not to fs). In this case mark the folio for immediate - * reclaim and continue scanning. + * not to fs), or the writeback may take an indeterminate + * amount of time to complete. In this case mark the folio + * for immediate reclaim and continue scanning. * * Require may_enter_fs() because we would wait on fs, which * may not have submitted I/O yet. And the loop driver might @@ -1155,6 +1156,8 @@ static unsigned int shrink_folio_list(struct list_head *folio_list, * takes to write them to disk. */ if (folio_test_writeback(folio)) { + mapping = folio_mapping(folio); + /* Case 1 above */ if (current_is_kswapd() && folio_test_reclaim(folio) && @@ -1165,7 +1168,8 @@ static unsigned int shrink_folio_list(struct list_head *folio_list, /* Case 2 above */ } else if (writeback_throttling_sane(sc) || !folio_test_reclaim(folio) || - !may_enter_fs(folio, sc->gfp_mask)) { + !may_enter_fs(folio, sc->gfp_mask) || + (mapping && mapping_writeback_indeterminate(mapping))) { /* * This is slightly racy - * folio_end_writeback() might have