From patchwork Fri Nov 15 22:44: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: 13877387 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 7E0BAD68BDD for ; Fri, 15 Nov 2024 22:47:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 592A96B00BC; Fri, 15 Nov 2024 17:47:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 542996B00BD; Fri, 15 Nov 2024 17:47:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3BED46B00BE; Fri, 15 Nov 2024 17:47:00 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 107FE6B00BC for ; Fri, 15 Nov 2024 17:47:00 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 9B644C05AC for ; Fri, 15 Nov 2024 22:46:59 +0000 (UTC) X-FDA: 82789814814.24.B9FA183 Received: from mail-yw1-f171.google.com (mail-yw1-f171.google.com [209.85.128.171]) by imf30.hostedemail.com (Postfix) with ESMTP id 2E57280021 for ; Fri, 15 Nov 2024 22:45:31 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=SsJeT+A6; spf=pass (imf30.hostedemail.com: domain of joannelkoong@gmail.com designates 209.85.128.171 as permitted sender) smtp.mailfrom=joannelkoong@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731710728; 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=5ErAIIi8jdB+XShdXI5EM6hrDpLbTBwefrYJ1KtzcWNtIqgmaqWFN/7/I4R/kQaw6Q23m0 yH0MUCaxCYHg9mzdYoHv+KcgBjHeXgJOcThLRdSlj2C5qx6XqYjGYHWTyUNfCA48bWszyd epVnCoePVI4zCwA8mRF6YENx54uSxK4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731710728; a=rsa-sha256; cv=none; b=rXVHoSg68iCgQv9rIIBGVaVWWUXjLvEaV0jTooLnTSy5qda94y/4lTaQjLBRk1NcwEOMCH yE+bGho0UclCi1IAtSsGXS0kgDdBwlJi1fZ/zXxqpcPjYBqtfzWGy+Pr9T8mIeoQvA0yjI ljMwL1cA9aXgf4HdU2gvuljO6/J3sio= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=SsJeT+A6; spf=pass (imf30.hostedemail.com: domain of joannelkoong@gmail.com designates 209.85.128.171 as permitted sender) smtp.mailfrom=joannelkoong@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-yw1-f171.google.com with SMTP id 00721157ae682-6e3cdbc25a0so1523027b3.2 for ; Fri, 15 Nov 2024 14:46:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731710817; x=1732315617; 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=SsJeT+A6IyYrm9QXE6B5QBJKpjDt9ZiQqHduR5togDLrZeIUDiFcLpeA84m05nL5Gf eopcXNrmdGnHrq9JWTpVa2Bubf7Auj55gtEUGkZMXnr4sPtd/rhQBAW+gsNbH1DreNbe fDY/ig5htUZ8k8sXAEt3PnNQqZuv5WORf8cpVvo2xh560lfdDyJGHpQkt/lwomJfKvsE ihJ8/LnDheDtqdHJZ2ahxA9vpSwvs7Dk96xkFG3sX7iDyKCodAaXDrxI8NxNKc9c/EY8 e89OD71MzDqwHGjyjemd1gRrYIlo9iNqIG7C34nFU/Gi7Ech+w1oOWrmwtv+3GxdfFN0 6ygg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731710817; x=1732315617; 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=v17cHZM0ibaO5eA45wNwxLPfVvF3hpoRr8MwNKwqFI/Bn6CvV26KUU1+CFffy9mqAs d2CXrwfQSrhHh/v26GO8HreNbxyQVFE3qyqiPQZwD8omo5Krj2Qn9RCL1uoy6ZllnPxP VoLw4KmxTepZEiODpoyJF1qn+vQQEKYUBhjuoHGIElFI8B9QVnh/5j/OwrSebhC6H8gp LYqFeZcIFV7d2Z0hvtbux+ynbcnpgbMq/+t3CjOGxD6MZRTAfzlIi1fq1L+HCnJKdBX+ 0UDZcL+r4ty8OG0VrJpQu+QVEMZq3mtr8bV5EIWnXSErOEFq10qyqy55LmPKghqYPSWy uEFA== X-Forwarded-Encrypted: i=1; AJvYcCVRLy3bLTboU+q4elAWfUdtIZczOo67BBQL3tG7d7uixUMH5c1qH/VW+b9SI8tfSu8Otis48DpZog==@kvack.org X-Gm-Message-State: AOJu0Yx4M0YcOhsFrBJtZDdpOaBmnT6BtfvOeOQC8kCnqLJUwoH7qm8G p5PEg885nc3cZc/vx3l7W1ZS/oW86UBgU27eyhnvT2auWbOgU6B3 X-Google-Smtp-Source: AGHT+IGSzVy1omnfV54BrGGJewgAW0DzxvxC726Kb7oZp1Mtso6nZFjz9TE4rzvmjlUt+ijR0WPOQw== X-Received: by 2002:a05:690c:688a:b0:6ea:7c46:8c23 with SMTP id 00721157ae682-6ee55ef8021mr61486187b3.35.1731710816774; Fri, 15 Nov 2024 14:46:56 -0800 (PST) Received: from localhost (fwdproxy-nha-001.fbsv.net. [2a03:2880:25ff:1::face:b00c]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6ee7129dc7esm875747b3.40.2024.11.15.14.46.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 14:46:56 -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, linux-mm@kvack.org, bernd.schubert@fastmail.fm, kernel-team@meta.com Subject: [PATCH v5 2/5] mm: skip reclaiming folios in legacy memcg writeback indeterminate contexts Date: Fri, 15 Nov 2024 14:44:56 -0800 Message-ID: <20241115224459.427610-3-joannelkoong@gmail.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241115224459.427610-1-joannelkoong@gmail.com> References: <20241115224459.427610-1-joannelkoong@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam10 X-Stat-Signature: 8bb5t84bsj4b3xjwwe7gczpnqum9acsf X-Rspamd-Queue-Id: 2E57280021 X-Rspam-User: X-HE-Tag: 1731710731-300667 X-HE-Meta: U2FsdGVkX18khwewPJnAgZzQCQG5VVP9P2Pz5smcWD5WkSHFRRXAabgNPQU5ZGOxxToNxFFARJlP/UIVp4wZL5rPjIcddmfsaa1IHKbwrJrd2RAd9NMAWNK4DZ9oFATq/fMjN+v1xTgTvz0oEHCksX5rHh5Jm8wo+K9/tJjklgyel5vw8IBbLvkAZx0t8fI9XXDgyM7oK02HQ/oJq1rzh/xJ6sCavPF3jI+IrHOLZhN6vxQsAnOhxHI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/A93j0xwVbZolQJ+Tlvx8ipq8TsOv9k8rmAPs= 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