From patchwork Fri Nov 15 22:44:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joanne Koong X-Patchwork-Id: 13877386 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 91B60D68BDA for ; Fri, 15 Nov 2024 22:46:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 19BF86B00B9; Fri, 15 Nov 2024 17:46:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 14BDB6B00BA; Fri, 15 Nov 2024 17:46:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F05A96B00BC; Fri, 15 Nov 2024 17:46:58 -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 CF7906B00B9 for ; Fri, 15 Nov 2024 17:46:58 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 9992A1A0706 for ; Fri, 15 Nov 2024 22:46:58 +0000 (UTC) X-FDA: 82789812924.20.6B7E671 Received: from mail-yb1-f181.google.com (mail-yb1-f181.google.com [209.85.219.181]) by imf11.hostedemail.com (Postfix) with ESMTP id A72AB40006 for ; Fri, 15 Nov 2024 22:45:59 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=kXH68CDx; spf=pass (imf11.hostedemail.com: domain of joannelkoong@gmail.com designates 209.85.219.181 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=1731710639; 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=KaJOCXiq+oAY6E09D60BMxslFUVmtN8uELYvwrLg+b4=; b=a6DzDJJn74J/BIo9TSiNXZ0AEgjAbABoy1PLEkmf3bz0ksEqDe80xPSD2cNiEawmqvZTOi tzIDbwz07CJ/8LgaBZed3ljnucBdL5lDFlvMGOM1yGQZ4GoUBfY2SRqxHHlb5y3s+HV53X RKlKM7bkSClnFADbohqzobKkdW76Jlk= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=kXH68CDx; spf=pass (imf11.hostedemail.com: domain of joannelkoong@gmail.com designates 209.85.219.181 as permitted sender) smtp.mailfrom=joannelkoong@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731710639; a=rsa-sha256; cv=none; b=JWFN8G1npxO/1VI4zTGtY40iJmUmtxiGnFrIut1gg0e38CwHt4oD1UD6pNMrCcvVPDIX8j AuGc8Z8L4wFU8/kqQNu/ES+jBRXkaWXbE2C+jhgZD3aQYrbKYdNsPGV9GjJlCoCMWMIW3N mADfFAC4rru/ypQI8oE47C9w8SP1vv8= Received: by mail-yb1-f181.google.com with SMTP id 3f1490d57ef6-e3876e6bae2so852113276.1 for ; Fri, 15 Nov 2024 14:46:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731710815; x=1732315615; 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=KaJOCXiq+oAY6E09D60BMxslFUVmtN8uELYvwrLg+b4=; b=kXH68CDxBz2bu39KrYUlYieVqJRWEMc+erkaBC1xow5u+Ljtk4yVwNPHuCiudaRRp2 kCJpax620ZTY7efGEg5q7KWEHldYtrvRuyOKnLMX0f/FTO8Dmy/Qnn4AUVccDgxlaWLo ERWrfAynuQBiBGo+/36v396BWC2Qfatk356BHSAko1b1mizoVz6f07rjwRPszcQxKr1l 5hvLEUTgzYOhhFhmMWZRlCohbgmTFTRnIqxK+zN7yRVRt+QC3vQNeAO4Nora8qh6xkNy 24VzJlOFLGw7RdzpcuZ7IBd4UJO17qI/A80QIOLbctmseEOwNGzuAb7xlHUqhnBbWGhC KLAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731710815; x=1732315615; 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=KaJOCXiq+oAY6E09D60BMxslFUVmtN8uELYvwrLg+b4=; b=Bgyqo30GKxKB7fkFV57+05oDCqCooPu64VlvT8J8QzPikBQRjM6ENy7xBTWQXMRWod Pzcxg1HT+/rVTa9BN9ZaxrrkkomDX7mvfwyHhhcURcIjlwql92eArdaPp+qZamwtyyS5 JWt7vlNHyveNsdSklJaPMFTfJpQ0g6s6AsHXvm2MxdXUd8goEziB6FVsB9vpC9UidXUS nrjXc4ExrYxD4rG/likUi8ollpcYKFA9V//DLaWb7kk5jadKNCYPZkCsMPRPpmGfjdFw FdYD4t4mOoOHcxGCBs+FXlleZAtDaJcMDptsAe/8/Rx1f7V+Bb8/G4WZDT4YZknu2oOu 5WkA== X-Forwarded-Encrypted: i=1; AJvYcCWmCDloYviOrBPI7Cu62ll+BNR+qO/8ARffgPynqSLW7SZ9Z7SBEnLgzOOqcL7KAoI+wLKkydMCXg==@kvack.org X-Gm-Message-State: AOJu0YzE7KuGJyvknS4GHLudFsZ1IxpLeg3sMytMI8ks2kwTWAmWx15M OcYfalThuo+BSP56HG2MnQQyPIC/BUwPn0gD5aIWGISZXuORUFXI X-Google-Smtp-Source: AGHT+IFmiXgnWZZs1gqt0JF4hZXzFNRdwrn1XSh3VQKDL/elFzc3Ebo+JLJ62nqDeTWVLJwJ3hwfzw== X-Received: by 2002:a05:690c:9682:b0:6db:db51:c02d with SMTP id 00721157ae682-6ee55c53b57mr48257857b3.25.1731710815490; Fri, 15 Nov 2024 14:46:55 -0800 (PST) Received: from localhost (fwdproxy-nha-011.fbsv.net. [2a03:2880:25ff:b::face:b00c]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6ee712c2c9fsm857617b3.54.2024.11.15.14.46.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 14:46:55 -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 1/5] mm: add AS_WRITEBACK_INDETERMINATE mapping flag Date: Fri, 15 Nov 2024 14:44:55 -0800 Message-ID: <20241115224459.427610-2-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: rspam09 X-Rspamd-Queue-Id: A72AB40006 X-Stat-Signature: gkbj1yn7yr1epbpq7dykgt7jjodinko6 X-Rspam-User: X-HE-Tag: 1731710759-144799 X-HE-Meta: U2FsdGVkX18mEpeos8Z9PzGEOk4riKCCVGpobJ3EWNMD7mwi4duA/iLC405Cl4lML2CeW+UIHlYm1aSlmLhJCMswhG/7uE5OFlOKEOKvcrcXe8hH5dQSJ3wbqJsDojbYlvcdVqW+62hj12LqbvQT+WIhZaiDe+RDwJPdgz8qcJ5r7A0rX5lahEviZ/9xsCmi5zUuGYLjSVgNScDZ5HNN0n8gEq2fcBbaf169KkD6isNDim8n14askapqNNijBMZB889d1qrjCn0sNfat5275yqUCnBAWtpMATtP9kshLRwSL+96W8npWMAReLuyX5VcvwD+BrLNKDzIOA7ojA/hqktRfKBDiXcX6UvtYL1QTSL4JLczpCmqCjCtEjXnH+YlJoYbGi9mXC7Xp2bcyz3c53+dLwJ5ZcJhaqngzrYz5d0HwiB/NqYp7kpY2vdXMIT9hl+GmPuuHZVu8QAYiEX7oXD87ApDlG9C3KplkCBCacYQkfsIhBvOFgsVC2JEp1DN/kUfuM5Pfe+wLj6Xo6WmO/OzqB5t2GFL9yz6JkOb3I8OzQfS9wkB4k9PRweIh6AMWtcXjPJNMraEZJm/bzgayV5AXwBTUkAYiMS9q8mxEDKT3R9OCgSlgDI0HjH/U8O2VHAgAbJQSEu5R7pHi0ZLzpktWWWdYVZ4lGl8XW+goFf/NiaQuAXuvLOfhyRiNBNpXvJS6hRXYBZXvZI8BI91WsYOjZY3Vt7i1lzMeNeQWGTVz8KSix7J5xrQsrgxK29oAepAKe/aW6s/SGPSZJV34IF0U8i2m4jWJHc7Hwk8+FTzCGwZJAFIbF8xAX2bJTzvpWZDTjkzATvjbas8i/uSRRN2MRPXzcbOBKQvUHe4iJbU5eeh7kgTuVI81wHooyoG9/I5VtY4GMPpc88QJzGeeVBs5Yg4UpA8qfGHf7JHoldLNNHclZpf+5Mg1MTu4sBJET2TEYw3wywq5TnWzmI0 91by9YRZ CjY6Za+RdqwG2i/ETKFSl3lhuHkNRRQeF5B4VaKrb2QL+WTMcuBS7j7BOJ2oUA2SFm7lKtEQtd6dfMSx4vD0RBUCSVDxaFd0/amCTJ0gTbdN3FfxVl2/Ma1gI5yP4tLX5QrNbGGZAjpezR4CzvOhRXcCOWKV2LocROl35xSu0C74c805pNa0YWnPtiIR4xm7QD99CJIkVfmmhkSomrLPOCyJfu1tX52YnpL23VmPoomswkXgRZrp4AkF8Yr0tvLCOkM1Mg2w+fhsfbHns48MRO7pdX/lfvWJlq75Dc6t/hIbuIRLwdjmdoHR5qG1l/eCDPh0RA5KS117G9bAuygnAFV/wq37THRYZRa/8k2y4HZtAreJiWiDbM5ULQPVSoqDCp8mIRxB0t7BrYM8k45IePenWkQ== 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: Add a new mapping flag AS_WRITEBACK_INDETERMINATE which filesystems may set to indicate that writing back to disk may take an indeterminate amount of time to complete. Extra caution should be taken when waiting on writeback for folios belonging to mappings where this flag is set. Signed-off-by: Joanne Koong Reviewed-by: Shakeel Butt --- include/linux/pagemap.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 68a5f1ff3301..fcf7d4dd7e2b 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -210,6 +210,7 @@ enum mapping_flags { AS_STABLE_WRITES = 7, /* must wait for writeback before modifying folio contents */ AS_INACCESSIBLE = 8, /* Do not attempt direct R/W access to the mapping */ + AS_WRITEBACK_INDETERMINATE = 9, /* Use caution when waiting on writeback */ /* Bits 16-25 are used for FOLIO_ORDER */ AS_FOLIO_ORDER_BITS = 5, AS_FOLIO_ORDER_MIN = 16, @@ -335,6 +336,16 @@ static inline bool mapping_inaccessible(struct address_space *mapping) return test_bit(AS_INACCESSIBLE, &mapping->flags); } +static inline void mapping_set_writeback_indeterminate(struct address_space *mapping) +{ + set_bit(AS_WRITEBACK_INDETERMINATE, &mapping->flags); +} + +static inline bool mapping_writeback_indeterminate(struct address_space *mapping) +{ + return test_bit(AS_WRITEBACK_INDETERMINATE, &mapping->flags); +} + static inline gfp_t mapping_gfp_mask(struct address_space * mapping) { return mapping->gfp_mask; 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+IrHOLZhN6vxQsAnOhxHIp7PFHjDQ99JpIUMmKiCQ+xCZS+4IUt2a//RqXsWChmCvkQwEdt1YtszOFoRSENEAjk+1+tXwRt8n/xwdjJwymH+8bb6i/ZNw9hbQMAUnxSvKQ0rzWBNBf0cdKftOq07CaqxqZxVRRl79e5mV/bfWmNqdIacPMcFQ6GjEDGmvvimLV1TgE/JBHueyDyhw3ZKiuI0XCy22jkqWstbn6RA3xFQf+MkZmuvek+ND1MRzu2nJXwAGYBHqYg8ftoAKv9pmN2B8usLgJ3XF0CIm3FYH/V0ZumnIw31UU0lR9Aq06/Vq/xKb6B5cXxrbjRA2gEWRO+RLXZVcelQSLXrzj0KERa32Jz9Bw8dQ1Wyw6x02tBYY/F1OKOUD34Ml901SDGfBm9LE9CPkrQSyL67PoDlYjBE1D6NdyMq1kyJFNuV+5x8hbtDDeiixj2Un/BzmhB/NHiV7aSDDN0yKCjHpey7zd/Giias+7aFXu6kPz8RA/KV7bzfEdQijfRGPHTos+7JxfEUXc/0z8Gdjxb5ErzuJKKMY2ClcaXV0vTntSFzc8Ldr0+bEz2T1XZyNvbFi+N35LhzE2IHTbqxLxaLTG2C2qRcDqcM48V3Ib0FZTxRivje69HwyJzXWOM9N9suUar10Ls2tttVGADI2MK4h45kX8Ap0r8kqYyoIreuNQQe4knEIWigIliyq6ZfRbY17HbYHsfYdUvLtA8ceOnasvOH7LbtFJtQ7 Kg3cvK7m W9TH17wJydeHeyZMCatbcV5Dntj7LHopceNxHSRE2i7j44nOg+AToCOpFJ5L2PRALhxsglSQaj/3Ki7RF3YWUfelkRo/zGxh8NTnm10CqAmQDpHFgJoZ3golbAENOS46b0WT1VVoFCO7FJ86cAYGxrLwR8X2siPhNBVuRfRMBL/wQp5lnI1PCBNpl/ORZF82fZaXiCDqrc4+JOsN+L/d0F/QSzsdz7RtRjKAcgvIVvLJSHV6NyoFEF6ijTl832dLw/KmUihOgGwdRo8QB/qx3R9bLEJpry+REcArN2fSFQkT/UPyXS6u7Wy9mpxBoHZ9ehR34xmj42o/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 From patchwork Fri Nov 15 22:44:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joanne Koong X-Patchwork-Id: 13877388 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 088FDD68BDA for ; Fri, 15 Nov 2024 22:47:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 67E096B00BD; Fri, 15 Nov 2024 17:47:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5DECF6B00BE; Fri, 15 Nov 2024 17:47:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 284916B00BF; Fri, 15 Nov 2024 17:47:01 -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 0996D6B00BD for ; Fri, 15 Nov 2024 17:47:01 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id B4A99A0683 for ; Fri, 15 Nov 2024 22:47:00 +0000 (UTC) X-FDA: 82789815108.15.4D0DB49 Received: from mail-yw1-f181.google.com (mail-yw1-f181.google.com [209.85.128.181]) by imf05.hostedemail.com (Postfix) with ESMTP id 3BF2F100003 for ; Fri, 15 Nov 2024 22:45:32 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=aL1sOIGY; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf05.hostedemail.com: domain of joannelkoong@gmail.com designates 209.85.128.181 as permitted sender) smtp.mailfrom=joannelkoong@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731710687; a=rsa-sha256; cv=none; b=7XE8sSfHwXKLAfc5JH+x4mM6jNz/ZZTSOwwN+5VNqXuIerqI29MqsxBk4+HfdU3AOtlewm 7b+lA9AK19PFv6zIL+doLk6gM04fc693Ob24+gq/aV5snqgQp/+DhUQ6qF4y1iVZgQqbh7 T/zdiBhvJsQjEHLUJVuflN09EvOpjs0= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=aL1sOIGY; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf05.hostedemail.com: domain of joannelkoong@gmail.com designates 209.85.128.181 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=1731710687; 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=fqTpYYj0xuVtKi0W3IidBx7k3eo4EvWfLhMFNi1N48k=; b=dXLMJ9GEKefcfMg0P9M9UMQQWqrjazkvapGp3Gg3Ycrz0jd6HsaZB13mMNPIX7Tor5Eog3 m8QSQWO2VEyBspvLkjbiXtEdISovHZ3GuiiXrREjJeHbA+YK75YUEXvzCL5ysQPzHKrFq8 39yTPspt68x71TDC2RySyZt4OlRozVM= Received: by mail-yw1-f181.google.com with SMTP id 00721157ae682-6ea7c26e195so13701847b3.0 for ; Fri, 15 Nov 2024 14:46:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731710818; x=1732315618; 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=fqTpYYj0xuVtKi0W3IidBx7k3eo4EvWfLhMFNi1N48k=; b=aL1sOIGYQ2FMpZQfO4hT4CI4WfGwzI18JDseXvx5XqNu+Wl5ek2N7ibySx5Uu50yNn XaHN1alSQpDrxAoITD5OJnPWB1WjbiHJoI+poP/l7+0jQ+RfJ4FNs3l+pPQW+70yRhQG nVJ2M32n97pAdkeKIeFRHjp8erUu8YCVmu27FnYkX3O9gx2E8eLeCV3HEkb5s1c/byE8 vH1wXGzuI3zaVfhzH6mFqBKeArfKbrOkdEzesHMgGAdpy1LJDR06jkJWCOr6FrXz8Q2n AnAYCnRpAYUQe1SccLkg8bgZsIwd+Iijrf0H+GedcrBj6fVHXIfmaCuoUo/Vw4epiGVo W3kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731710818; x=1732315618; 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=fqTpYYj0xuVtKi0W3IidBx7k3eo4EvWfLhMFNi1N48k=; b=vgTiXqi1AKwE1u+SHmKzBhfbmxHTWYrHuSRksGXmDl5Mn5QJpNCyCnN7PZ4QN5N633 f6Y6qUTR/j6xgV6MiI5gvXQhZd7G2ljnQPKqyc5THVW+xxDknTvx99gpU1+hhbH44HBg omJerQ9rIJ+S6/Wr8wx/5xMkhgqHOz265ecOpTFN07FYbkGnOaKa42aG6EQ8brr7GHCx uGcfnPpy1zIA3rP3MzXVMtigyrztecWftUf9dybaX2Tt3TaGo8GD11oPZ6IodleDA42n JY38q5L4xK5/A7h6rMfmuT26T5hv/7xlo0J+fz4wFg8uJapVUoyRtCYsJ7MyK01XKQ6O FeSw== X-Forwarded-Encrypted: i=1; AJvYcCVL63q5FHe5gKjhvKtr8Jw++4weeEMEV+XYA1bRrlK3mWRGM+m5Xq6FMXLU53FQLsiyMxzqVIbaKA==@kvack.org X-Gm-Message-State: AOJu0YznC4NQQ/Ss6mpMqRj5GZQl+z+4yxGqOwHWRT+AUyIG5hP2xl7t AmAV4lZqSn2mv/L1b0cAKRSZaeU+vodDQhZFocZS0VzWS1p7duEA X-Google-Smtp-Source: AGHT+IHG2B4pBIMlMPyc7j9/RbvQB2IU9wmY3MOJI56h25nmFtflz9zG3n4erefydZn7TRsiabBC0g== X-Received: by 2002:a05:690c:6486:b0:6db:ddea:eab4 with SMTP id 00721157ae682-6ee55c7897dmr58857977b3.37.1731710818032; Fri, 15 Nov 2024 14:46:58 -0800 (PST) Received: from localhost (fwdproxy-nha-007.fbsv.net. [2a03:2880:25ff:7::face:b00c]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6ee7127890dsm879117b3.11.2024.11.15.14.46.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 14:46:57 -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 3/5] fs/writeback: in wait_sb_inodes(), skip wait for AS_WRITEBACK_INDETERMINATE mappings Date: Fri, 15 Nov 2024 14:44:57 -0800 Message-ID: <20241115224459.427610-4-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-Queue-Id: 3BF2F100003 X-Stat-Signature: w6dtcuty9fcx7rq76bppxteq6y53c5ge X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1731710732-436596 X-HE-Meta: U2FsdGVkX1+lpK9vh6nAFmF5O6cBJtEUqzNZviOIA00jFQveS09bqoSo5GFOqr+FRCqMJxdFpttMlIvbr74dJkc7N4idYfSo3mCyJUBFwyq2inHiYfFxoVV9q5UyPyYXQOMmzqxkRTCm/m04KLasTGIYPlZ3dVI8JqyA0q1Xp6CGdVIJ4PLpJde/uFcY4pt2GkNM88/9k5UNzqe+knuw2bG+Ppz3REA4A174ObY1HM4azwQwjcsLeLfqIeUc+mhqAn7RVRGJx6D6lRkvmGeCABYJFuL1smIB4v5lAHTUnD7+Lqvsw8d4oM/qpebgRo/3uZwHSXaonvK014hM8/kRVrvut8CKCsHxXu3nbibDV3vEXu5oHJs6hDl+4YDiAK4DtYq7UWRak26CwaHmUD8Jn+YKnRJprfcwJr/geFhWtrk1OZczPv0nhHZf6ppfDNjb3G66KleB8Ytjwaaccf6J6bliV4FakUv42MFyspnnt371TYV1LuV93PsfsmQCESYUr7YR4s8xwnJFOslUlgUM02fAzryZVE1+dt/XgsC52HpNMBKbxxgoTV9gdayEsdzF86+UcWgZVSVKT2LM+qi0AcTGJo3xiMqQCluOqzawmrtmZi14lt2A2MyHP2b+sQStvMm1ZM/FnCsb4OEpf3S0ExhEBzpURXnJD4+Pjq8N2ZXTi0VfljsENUi04ulPVtLRNXGJ3OFx911S9qkZdOwjRFHIxH0C80ESS0wy6841LqA1UsxQX5h0iGcpVPbmFq3vdb5jYHw6+9T2PcvTZwOm+IBfXFDRHC0yaZTQMa4wm8Z6tJeN79bZpcKaBqpLw4VlaaIeQrVCrJ4R8+Y6LqOGSdLvrF0deClOqY0FB88DSpYaLm+QlcWYoin8V/Rw2o474xN21dzFs5XqTQV6o0rdaL0/z9JWo6tQR8Yt30LEFJfXUCGsaCYMZpyMFJw+NUHRMaE7QneD0/u8ZculcIa SCnM4Vam dwgv8q4UbCeSvfxMGTlX5XBffRe5FZuhRC9m7OtmetgKaSiVWIqkYQffKVHkeCMSqCfqTRuzF7G6CkANGsMGhO/F3tHgZEweLWPmsTdGJfPqe/XP9ezr86Ecb2xUNWI09OZZa8QnldMLaAWnbTgFRWI8KuOHJ/VSIJwZ3zDnJ1keoTII6fohYWKTlzQIqs3W1/GliWQlTyoWDILltEpF8UbcNKkTRJmxs2BnBfDx+FNgmHbLxh3r0A5uhgYwpa6hJZkcxL2U2qgnFdjPCbLt4FEJ5fWLDfz5EjTzEe/JFhUXUlueJ9iRurGh6RQdW52GOy2o24K9XC/AQYULCO+WTIFS5mEtd7XFS6yFi6LKJOi+uaVy/OQO5Ntbf8lE9/DnVAahfYpqL8AjY+pS2s4sax9gdUQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000002, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: For filesystems with the AS_WRITEBACK_INDETERMINATE flag set, writeback operations may take an indeterminate time to complete. For example, writing data back to disk in FUSE filesystems depends on the userspace server successfully completing writeback. In this commit, wait_sb_inodes() skips waiting on writeback if the inode's mapping has AS_WRITEBACK_INDETERMINATE set, else sync(2) may take an indeterminate amount of time to complete. If the caller wishes to ensure the data for a mapping with the AS_WRITEBACK_INDETERMINATE flag set has actually been written back to disk, they should use fsync(2)/fdatasync(2) instead. Signed-off-by: Joanne Koong Reviewed-by: Jingbo Xu --- fs/fs-writeback.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c index d8bec3c1bb1f..ad192db17ce4 100644 --- a/fs/fs-writeback.c +++ b/fs/fs-writeback.c @@ -2659,6 +2659,9 @@ static void wait_sb_inodes(struct super_block *sb) if (!mapping_tagged(mapping, PAGECACHE_TAG_WRITEBACK)) continue; + if (mapping_writeback_indeterminate(mapping)) + continue; + spin_unlock_irq(&sb->s_inode_wblist_lock); spin_lock(&inode->i_lock); From patchwork Fri Nov 15 22:44:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joanne Koong X-Patchwork-Id: 13877389 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 874EBD68BDC for ; Fri, 15 Nov 2024 22:47:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EBCB59C001A; Fri, 15 Nov 2024 17:47:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E6BBF9C0018; Fri, 15 Nov 2024 17:47:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D0D6C9C001A; Fri, 15 Nov 2024 17:47:02 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id AB8A29C0018 for ; Fri, 15 Nov 2024 17:47:02 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 2A2A98012C for ; Fri, 15 Nov 2024 22:47:02 +0000 (UTC) X-FDA: 82789814520.25.B2CFC7D Received: from mail-yb1-f181.google.com (mail-yb1-f181.google.com [209.85.219.181]) by imf27.hostedemail.com (Postfix) with ESMTP id 716F140009 for ; Fri, 15 Nov 2024 22:46:13 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=UbQ81sPN; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf27.hostedemail.com: domain of joannelkoong@gmail.com designates 209.85.219.181 as permitted sender) smtp.mailfrom=joannelkoong@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731710756; a=rsa-sha256; cv=none; b=psmbAOwvPb9B/m97fZR6ysIvIkDvE5HH9/ryaW1yveftLnG9Iem0NT6C8vXrJFwRNSWOCk LxaMXgp+2C9lP6uIcU4q9u8HR8Y1Al09VVx+gWTZ3nu1DjJNQKBQDr0dVLP6/UGIebuTG4 A05XPC8vb9SudAh8VZ9qzhpm4NTDBec= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=UbQ81sPN; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf27.hostedemail.com: domain of joannelkoong@gmail.com designates 209.85.219.181 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=1731710756; 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=sEjWA6vn5Xh3CAWPzY0RXH9AbB2HGrSJFRDx463rkA0=; b=5Dc6ut+HDwWsmeFIUVQXwFN5rgqgU2PyQ9BnZDQGZ/RFAPD5mtFEgitoeYYN2k1fQFVvO5 ewdauiQLFu3rwltf4ewgrEKSflS+87EZbKe5uM39DZ6qqn6TloedL/1vgVw3U61WAKSUm5 w4/v6ONm7o4disCUvffCe0KJkN0awRE= Received: by mail-yb1-f181.google.com with SMTP id 3f1490d57ef6-e383bbcef9dso974916276.3 for ; Fri, 15 Nov 2024 14:47:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731710819; x=1732315619; 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=sEjWA6vn5Xh3CAWPzY0RXH9AbB2HGrSJFRDx463rkA0=; b=UbQ81sPNF42Mjq19hm/+fg4x7MUE4sQTU9VZib1Io7GRwNiojEkgTuE+kEflaldmRw nkauGbo/p+TBQ8KBSUdpVfECen88TfIzdhaSsQvPMbf5XUxHQEXykvQ52/2VHJXpGsXD ONbanwBmbjs1G0B9Aq6LKt72j9tydtjFHgEfz0no70Jrbv+bsi5hqyUk8vr7cYXp5jmP Oyf05NlvcdbyeFnwLkf9XsFo8R+qSYurme3WhuKd8sl69Tgfx42fWTgAZdnXg7BZBUl8 wXoEqcNNm1PVG3/zoqPjat7Sc6YvwzLYQcjI9EbndENPYRil4TepJqNXPM/EdOvjK37/ +Z8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731710819; x=1732315619; 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=sEjWA6vn5Xh3CAWPzY0RXH9AbB2HGrSJFRDx463rkA0=; b=cuTdtvx2WzSK4A7ygxzOBED8Yk/jyNSYvNs7fClqklb7ltESoLMS8rzhGFLT6UDG5B ZhFEvZ5eAztuzzxO4WppuPhcgho+WKNgQn6cZGoQ7aXiLDOvHzlLtOEV3AwFCjTL6/cf w+BkL+Tq2mtoPcf3O5CP4sDTVtYueRvKH8jOQNVuAH9+aRoZKcpWmJE9T+Gz1ETGDRAr BEQUpKPXoKpq3mEjQ0umQu0IVVFdaJ/5M1A367tLdkKHziH3pfTOYUdHq9BwNqNqfKqj sxj5NzBQjp3XtTv2K+v6DQk/YwO+V2tUSnVIUASg/F7EgVVOMR+OtRLgIe5neBCIQ9Ix mo3g== X-Forwarded-Encrypted: i=1; AJvYcCVAmoXpJChiqu1n5MKg1lmqr+qmsY5Tnnfw32piZU2/6Nm+y5aV0uijGZbNO9nbgJSAq4rCgSrJhw==@kvack.org X-Gm-Message-State: AOJu0Yx2nXhuTqbgsj+tGwWpZeW+/T+S9RjxutaXxYMb0m24K6iqjkYi Ckhk5JC+SJslMGwPyifR2iv+1euwIOkB8413CNoVyWRWng0IGKLCVugHdQ== X-Google-Smtp-Source: AGHT+IEkqbH2Xska95WleqplmUzi/TR1yFbkmLL2aUtOgoFdVaSIwP8XGbBOoG841NmPls+jC0AzZg== X-Received: by 2002:a05:6902:114c:b0:e33:2605:f80b with SMTP id 3f1490d57ef6-e38263f1251mr3757204276.42.1731710819349; Fri, 15 Nov 2024 14:46:59 -0800 (PST) Received: from localhost (fwdproxy-nha-005.fbsv.net. [2a03:2880:25ff:5::face:b00c]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e387e7419ffsm115897276.22.2024.11.15.14.46.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 14:46:59 -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 4/5] mm/migrate: skip migrating folios under writeback with AS_WRITEBACK_INDETERMINATE mappings Date: Fri, 15 Nov 2024 14:44:58 -0800 Message-ID: <20241115224459.427610-5-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-Rspam-User: X-Rspamd-Queue-Id: 716F140009 X-Rspamd-Server: rspam01 X-Stat-Signature: rcyn543rrbx6hp86ra3enqx3uf3jtb6x X-HE-Tag: 1731710773-453579 X-HE-Meta: U2FsdGVkX1+pWH4i3hvAI5I2O5LrEpovwbWir+WQucnj4gkGnCXddg8QMrMgG+n4j++HHf//lK5NSNdija7hYcT/SkBzkQE+okVwMEwSkyL2WH6YnaIzIbYs6sGbzl8N0fYIBuaclqf8biQh4xZB+Zd6oVuf1vLCr0NealDSYve2yfu+5ZO7gm52SHq+CCIcSDxIuzmOZv+/DZmDcRtpOyoR7DR9zkQ5yJk7je/go2LhvxOz888xMfFbKVZwsCKsG9dcUr2vIMMpDgHkczq7yN+Xnglw7YW5MTtsw0Ka4PQy0fqEcd+CmYK741HmY7QqnzpRqyHon/xUX2vISWO/BKG358zvAl/D0M2RPyij4Q+1A3KO8uQiSuz1x14yJ2EZynteO9Qn4sJ/PRxlBb6FctDShl53G4JU8C8k5F7uKyD2bO+bJXmGKcdbspNAU6rnA+yifGRJAxKS90axZNL50IOe/ys1t2kJHt8A1ecvVwqHyM3cjW5U5oOyaiz17KxZ4zIIAKRoQo6xmf2jDB837bmFOumZ155xcLxLArb4NNL8F0M6TUXwQQLcjPJsxopQuy58onK8fFxIa6lWhHmcb9aKI4CsmJ+MhpLYyUxRHEu1zEVF2Bb433L9gVrhv8tXGW5D2HRLHRu63NrCqzPpagLMwseofD9zjbX1bc14mmkgO4bFayVAy/tG5TBNn5lu+acEooFV6ZR/MwkpV+qaEN3aIyFqikQJ8p9JvayTI9rwpz6prOpLc+FueCuVqKZmpTySDO/+JMgxSvVerJ2jKgkQYaeUbB83kZ9OkAX5P9SL8j8fmQlPfqzrXDNYzb0jIhbSxvkKyltV3MvDyEUaPJlRvbDPu3xSnfRL5PGl118+nYSzpEwFXt7/+TOu+sJqd6laHdMLvRWGFr30gOSR2m5GI30ChHsEu4X+eAFiNACApnoJnWBLTH3M5rOOjj0+yfn+ih/9upqzM6sqvG9 xKH86ppD g0F4jDMYVZ1clqD/j1p3jWxSIixv3KgJ1waPI5uVAkdg+HpSE2ND3051DwqPyV0wTgpUXAO7KRK0nA75fx4YLEctLBrngSXagse2WvmtpqoBhS5Qo/C+wUx9qX63xOA5bzYrt/tB2Oh2twyEleypBhl+spJ6PNLOxPbsRccLu4fDWQSGjArOEpgTl7gGVSWPHmmeVIAVgPuFk/ivuDImcGdkDNdauOR2dN9f6UTGPZAXechBDONNC2sIZzfkhqxAeqvLOEjyDGWkd0COwGdIsU7AVi+ogm+C6SvzMZGF0YJdPA+oBnsWrjQO/6+Qkjf/OoZh3IKsVCoqGacJa5KnWX66nsHRP9YPoY+wOQs+3WhOwkhBn/Yzhqo6Q6/PfHXTcmkn5jmNh3OWkXL5jeWIskbIQ1Q== X-Bogosity: Ham, tests=bogofilter, spamicity=0.016292, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: For migrations called in MIGRATE_SYNC mode, skip migrating the folio if it is under writeback and has the AS_WRITEBACK_INDETERMINATE flag set on its mapping. If the AS_WRITEBACK_INDETERMINATE flag is set on the mapping, the writeback may take an indeterminate amount of time to complete, and waits may get stuck. Signed-off-by: Joanne Koong Reviewed-by: Shakeel Butt --- mm/migrate.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mm/migrate.c b/mm/migrate.c index df91248755e4..fe73284e5246 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1260,7 +1260,10 @@ static int migrate_folio_unmap(new_folio_t get_new_folio, */ switch (mode) { case MIGRATE_SYNC: - break; + if (!src->mapping || + !mapping_writeback_indeterminate(src->mapping)) + break; + fallthrough; default: rc = -EBUSY; goto out; From patchwork Fri Nov 15 22:44:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joanne Koong X-Patchwork-Id: 13877390 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 439BCD68BDC for ; Fri, 15 Nov 2024 22:47:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 989F29C001B; Fri, 15 Nov 2024 17:47:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 912E19C0018; Fri, 15 Nov 2024 17:47:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 717C69C001B; Fri, 15 Nov 2024 17:47:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 4C0859C0018 for ; Fri, 15 Nov 2024 17:47:04 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id F00A1407BA for ; Fri, 15 Nov 2024 22:47:03 +0000 (UTC) X-FDA: 82789815402.18.8C1B699 Received: from mail-yb1-f169.google.com (mail-yb1-f169.google.com [209.85.219.169]) by imf30.hostedemail.com (Postfix) with ESMTP id 8A9F180004 for ; Fri, 15 Nov 2024 22:45:35 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=V2Er0xVQ; spf=pass (imf30.hostedemail.com: domain of joannelkoong@gmail.com designates 209.85.219.169 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=1731710625; 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=qy4s7iJDV3qe45TyStvv2BTPUXnZXHyPJpi2dhigRt0=; b=gOGhcR5uSqe5dbK4zh5jsEh5JtIqCGLDAjRw/95sFhrbgsl8DXvCy5i9A7Nti/uZPmnlx9 /RnvwJEQC29GjMYp7ugrMIzQbTvcOP1Ul97U0CJkkwfldWf8iTJ03nXlJDmTnLriPcT2uE mA42UNpQ0Ey+LK0dsM9wfRAybuLeXSY= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=V2Er0xVQ; spf=pass (imf30.hostedemail.com: domain of joannelkoong@gmail.com designates 209.85.219.169 as permitted sender) smtp.mailfrom=joannelkoong@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731710625; a=rsa-sha256; cv=none; b=mJR14aFlEsgk2H9M5kdaDkqkiy2db4I2L8IRw3z2s6D9F+376EI2vCQ30+icN6QUp4buJJ 1+V43ure7dWDlkmcj9R/B/oXKFNd28LFxigoVdkyDBuj+EL8sllKxger8AJVFjcWZaVFG3 NIAdOFf9tkeIY+mI8ronDbh3qI284n4= Received: by mail-yb1-f169.google.com with SMTP id 3f1490d57ef6-e29218d34f8so1701248276.1 for ; Fri, 15 Nov 2024 14:47:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731710821; x=1732315621; 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=qy4s7iJDV3qe45TyStvv2BTPUXnZXHyPJpi2dhigRt0=; b=V2Er0xVQ+5UESz3Vy5AQtrUNv+OoBPP5rezxV7lpf0cIY9eoa3dUr+dalesQb07REN B3vJ17KMqox7BZDqL2MyuuIxO0IUHzjL6njEaHrwTWzmA5s0HVi64Y+AIQPPUnfoXY7K xA0jLsLm2qLEOOPa5LjtT+iz0wW+rFvuU6htirPUhrMQJxHfwhdJEADnRgNrU2Ai9mvW 43LOzzpdxZsgxpjYe48IyWoH1IksuzU8MaPR4Iak0TO1KkfEvPJCnaRbMusRvyUxHpSd hrUx6mPICmGnWfb44iLbXuSB9Hw+ry+C7sAbITn9f9yklzmO690vO0IAhjl/nOt7zqQl Vk/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731710821; x=1732315621; 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=qy4s7iJDV3qe45TyStvv2BTPUXnZXHyPJpi2dhigRt0=; b=bE/q3+XIy83p2VK1pYF/0wvoaEyjYlyIb8rV126EkF+i4wGTdz/s601jpI3cZD559Y paKDxlpOQOQuMeuIzh5W14ZUKnc/1LUWY7fS/WvNgY6nbVI+kRkHSxR5/xnIqWG5Aooy PCe1aG+joIPo0j/n8wpZg0Tk4eOFpaCnwwNKykEgm1SmNjy9MrNfubwrWwcgn50NtKch 3BYY1gzhcjwyxhXHBL5Qi7BQIxRJeUcEZnks1zjAlYTtsy/ngVey3jDtbLvSy+3u5Tjy Wub/W0gU7ygWxlbRJ9KYaO0fyHlU2mI4NL8Z21xUiNtMLV0E6+xA0YAy901ez6zlHhDt lsxw== X-Forwarded-Encrypted: i=1; AJvYcCWXwUJUj2B+jFI5vaXpFSoF3luevSqpGsoovgguvBZJdM4YhRjyBFhLT7AXNbT45eSnGKnd17IFMw==@kvack.org X-Gm-Message-State: AOJu0YxHjkcpa1aQsjnE4c243NgvPPFBxN+5StrjJg8ukK06V3IGOXX4 fzxAzLX/YL/ryHotIlm+503jL+ZcW8zLafIMaqg92dBwAbY4/P8M X-Google-Smtp-Source: AGHT+IGZ7kVAa/AZTPUzamvW569Ak/MPcUBU3EdEjXoBhOC8Q6ya+wE0uTDItno3ZD6CD1/wAPiNcg== X-Received: by 2002:a25:ac56:0:b0:e38:7d21:3b53 with SMTP id 3f1490d57ef6-e387d213cfdmr1063327276.22.1731710821074; Fri, 15 Nov 2024 14:47:01 -0800 (PST) Received: from localhost (fwdproxy-nha-116.fbsv.net. [2a03:2880:25ff:74::face:b00c]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e387e754792sm115631276.26.2024.11.15.14.47.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 14:47:00 -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 5/5] fuse: remove tmp folio for writebacks and internal rb tree Date: Fri, 15 Nov 2024 14:44:59 -0800 Message-ID: <20241115224459.427610-6-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: rspam07 X-Rspamd-Queue-Id: 8A9F180004 X-Stat-Signature: ojqj5154mwu8rek7kf6tf4fsbqk9tqhk X-Rspam-User: X-HE-Tag: 1731710735-113467 X-HE-Meta: U2FsdGVkX1/exysrSbdVJSbJn3lmT38xcKyt/sHo43khZP4VrJ92wSQqa5GO8D7bV5jFAdp4BC8MNl8/iCxsQ6QzRgqXDTJUTda4ntxYXpvKSGRxQjvkzs2hbC2QwODOSHMLO+XYaQvliH7AxLNRZFtJbseYyrkjLq83C9XFwy56lVvunFlt2xifuUbw8qe595Oicv30SGPzNYDs01eErxO+d3lfpFIDXCMOO5xNwssY/Ot5nyqj4OqhuDQTWEN1zaviEL6pegrZysJqMWQfBEiXEdpqI7uMhJvRlyGWG6O5ztedi09ZQxRFVNw2OPd0Cu4F15zZqB1l1Sa7sh+VPSxhe1qEmbFFPg/rD6eq5em2R6j31eL4b/WEJ5nznoWDAzYCCCQ1l+VTkwyhOHAi0uUMjM9xZiPAwSuNR/rDZjuaTE2f5+hQxPuv73pqBaatI4yEsPfISuGrzPGqyr98cgn/wj/PF7lRGA+nm1hROZHorNOV4rK/VT70NF9wBSUUA/byBF5BbknbvmEX6S4F7yfFSgDH4ft9cqF0+gjwFD6ptLKZlFbmglRRM0VLnyO2wWA1axakNHOSFvFIk5JEdkr/cAm8QI11u7QEL+aKzzBzikpbJOOeToiUES9UD8oZvAbNiD4oUUq3p48v1Y+GQNULz3emz5ohBptI4dXpWAFpe4jzKMAq6zoi2D+g6y+lkVNWZOzJCJDy/hqO6EiXJ4+jc7dlQHbKqPArXFhUlR9QdN+cvMxqT71bzjuj8aSI98hVkb0YZcttjO0tyFI/XQ1EguVBpzdFdFn4DS7crpoAHOHrazVsa7bK2+GE/tFci8vooH3Hj8hzUiuznzRVkqnVOHK1lctqVjz8Ok21lGPx0BaJMliDOQahk1Np3tD8seaBp7ZtuWgM5F5qiPa6ILgDDN9cWJEMEBMGlWoxIaTUkINlQeMHpN03G1NgFvYU5QI+Vy3m2NAcXNz4qM/ tJjIkJo7 Ea5MrTCb6dABRsA3Tk+5aCmkKHSjnJjWMqyEF7eFGgKo2XLqEMmN5VJWlKmA/lw+QY3MnVZ8Z42iaF1hce9I9uE5yVr7OTX3PH6MhuCBnhWNYQYlPbexaNv5wPHPiUXcZBVE1oP2dFoMaro8ZvUJ6U4BOnOXHTWCwmap/PzQcvEjPiSSf4JxU5AiN6dsubj/hgq5ajswfvinWdPER5rYKdNUY11/KDR0bs0FobUKB/yax264G/K1y6miUJaJ9XCVxLTU5N2ERxBJ78eAxv0h+teWF/eU7wv4y86XGy8Giwjql3PthqbOCurt7G5aAfLIH1hsN9f3pAa09YIA0d3kq5W4nQTAYXcHs5mJqhR1b9+1zFAw= 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: In the current FUSE writeback design (see commit 3be5a52b30aa ("fuse: support writable mmap")), a temp page is allocated for every dirty page to be written back, the contents of the dirty page are copied over to the temp page, and the temp page gets handed to the server to write back. This is done so that writeback may be immediately cleared on the dirty page, and this in turn is done for two reasons: a) in order to mitigate the following deadlock scenario that may arise if reclaim waits on writeback on the dirty page to complete: * single-threaded FUSE server is in the middle of handling a request that needs a memory allocation * memory allocation triggers direct reclaim * direct reclaim waits on a folio under writeback * the FUSE server can't write back the folio since it's stuck in direct reclaim b) in order to unblock internal (eg sync, page compaction) waits on writeback without needing the server to complete writing back to disk, which may take an indeterminate amount of time. With a recent change that added AS_WRITEBACK_INDETERMINATE and mitigates the situations described above, FUSE writeback does not need to use temp pages if it sets AS_WRITEBACK_INDETERMINATE on its inode mappings. This commit sets AS_WRITEBACK_INDETERMINATE on the inode mappings and removes the temporary pages + extra copying and the internal rb tree. fio benchmarks -- (using averages observed from 10 runs, throwing away outliers) Setup: sudo mount -t tmpfs -o size=30G tmpfs ~/tmp_mount ./libfuse/build/example/passthrough_ll -o writeback -o max_threads=4 -o source=~/tmp_mount ~/fuse_mount fio --name=writeback --ioengine=sync --rw=write --bs={1k,4k,1M} --size=2G --numjobs=2 --ramp_time=30 --group_reporting=1 --directory=/root/fuse_mount bs = 1k 4k 1M Before 351 MiB/s 1818 MiB/s 1851 MiB/s After 341 MiB/s 2246 MiB/s 2685 MiB/s % diff -3% 23% 45% Signed-off-by: Joanne Koong --- fs/fuse/file.c | 339 +++---------------------------------------------- 1 file changed, 20 insertions(+), 319 deletions(-) diff --git a/fs/fuse/file.c b/fs/fuse/file.c index 88d0946b5bc9..56289ac58596 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -415,89 +415,11 @@ u64 fuse_lock_owner_id(struct fuse_conn *fc, fl_owner_t id) struct fuse_writepage_args { struct fuse_io_args ia; - struct rb_node writepages_entry; struct list_head queue_entry; - struct fuse_writepage_args *next; struct inode *inode; struct fuse_sync_bucket *bucket; }; -static struct fuse_writepage_args *fuse_find_writeback(struct fuse_inode *fi, - pgoff_t idx_from, pgoff_t idx_to) -{ - struct rb_node *n; - - n = fi->writepages.rb_node; - - while (n) { - struct fuse_writepage_args *wpa; - pgoff_t curr_index; - - wpa = rb_entry(n, struct fuse_writepage_args, writepages_entry); - WARN_ON(get_fuse_inode(wpa->inode) != fi); - curr_index = wpa->ia.write.in.offset >> PAGE_SHIFT; - if (idx_from >= curr_index + wpa->ia.ap.num_folios) - n = n->rb_right; - else if (idx_to < curr_index) - n = n->rb_left; - else - return wpa; - } - return NULL; -} - -/* - * Check if any page in a range is under writeback - */ -static bool fuse_range_is_writeback(struct inode *inode, pgoff_t idx_from, - pgoff_t idx_to) -{ - struct fuse_inode *fi = get_fuse_inode(inode); - bool found; - - if (RB_EMPTY_ROOT(&fi->writepages)) - return false; - - spin_lock(&fi->lock); - found = fuse_find_writeback(fi, idx_from, idx_to); - spin_unlock(&fi->lock); - - return found; -} - -static inline bool fuse_page_is_writeback(struct inode *inode, pgoff_t index) -{ - return fuse_range_is_writeback(inode, index, index); -} - -/* - * Wait for page writeback to be completed. - * - * Since fuse doesn't rely on the VM writeback tracking, this has to - * use some other means. - */ -static void fuse_wait_on_page_writeback(struct inode *inode, pgoff_t index) -{ - struct fuse_inode *fi = get_fuse_inode(inode); - - wait_event(fi->page_waitq, !fuse_page_is_writeback(inode, index)); -} - -static inline bool fuse_folio_is_writeback(struct inode *inode, - struct folio *folio) -{ - pgoff_t last = folio_next_index(folio) - 1; - return fuse_range_is_writeback(inode, folio_index(folio), last); -} - -static void fuse_wait_on_folio_writeback(struct inode *inode, - struct folio *folio) -{ - struct fuse_inode *fi = get_fuse_inode(inode); - - wait_event(fi->page_waitq, !fuse_folio_is_writeback(inode, folio)); -} - /* * Wait for all pending writepages on the inode to finish. * @@ -886,13 +808,6 @@ static int fuse_do_readfolio(struct file *file, struct folio *folio) ssize_t res; u64 attr_ver; - /* - * With the temporary pages that are used to complete writeback, we can - * have writeback that extends beyond the lifetime of the folio. So - * make sure we read a properly synced folio. - */ - fuse_wait_on_folio_writeback(inode, folio); - attr_ver = fuse_get_attr_version(fm->fc); /* Don't overflow end offset */ @@ -1003,17 +918,12 @@ static void fuse_send_readpages(struct fuse_io_args *ia, struct file *file) static void fuse_readahead(struct readahead_control *rac) { struct inode *inode = rac->mapping->host; - struct fuse_inode *fi = get_fuse_inode(inode); struct fuse_conn *fc = get_fuse_conn(inode); unsigned int max_pages, nr_pages; - pgoff_t first = readahead_index(rac); - pgoff_t last = first + readahead_count(rac) - 1; if (fuse_is_bad(inode)) return; - wait_event(fi->page_waitq, !fuse_range_is_writeback(inode, first, last)); - max_pages = min_t(unsigned int, fc->max_pages, fc->max_read / PAGE_SIZE); @@ -1172,7 +1082,7 @@ static ssize_t fuse_send_write_pages(struct fuse_io_args *ia, int err; for (i = 0; i < ap->num_folios; i++) - fuse_wait_on_folio_writeback(inode, ap->folios[i]); + folio_wait_writeback(ap->folios[i]); fuse_write_args_fill(ia, ff, pos, count); ia->write.in.flags = fuse_write_flags(iocb); @@ -1622,7 +1532,7 @@ ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter, return res; } } - if (!cuse && fuse_range_is_writeback(inode, idx_from, idx_to)) { + if (!cuse && filemap_range_has_writeback(mapping, pos, (pos + count - 1))) { if (!write) inode_lock(inode); fuse_sync_writes(inode); @@ -1825,7 +1735,7 @@ static void fuse_writepage_free(struct fuse_writepage_args *wpa) fuse_sync_bucket_dec(wpa->bucket); for (i = 0; i < ap->num_folios; i++) - folio_put(ap->folios[i]); + folio_end_writeback(ap->folios[i]); fuse_file_put(wpa->ia.ff, false); @@ -1838,7 +1748,7 @@ static void fuse_writepage_finish_stat(struct inode *inode, struct folio *folio) struct backing_dev_info *bdi = inode_to_bdi(inode); dec_wb_stat(&bdi->wb, WB_WRITEBACK); - node_stat_sub_folio(folio, NR_WRITEBACK_TEMP); + node_stat_sub_folio(folio, NR_WRITEBACK); wb_writeout_inc(&bdi->wb); } @@ -1861,7 +1771,6 @@ static void fuse_send_writepage(struct fuse_mount *fm, __releases(fi->lock) __acquires(fi->lock) { - struct fuse_writepage_args *aux, *next; struct fuse_inode *fi = get_fuse_inode(wpa->inode); struct fuse_write_in *inarg = &wpa->ia.write.in; struct fuse_args *args = &wpa->ia.ap.args; @@ -1898,19 +1807,8 @@ __acquires(fi->lock) out_free: fi->writectr--; - rb_erase(&wpa->writepages_entry, &fi->writepages); fuse_writepage_finish(wpa); spin_unlock(&fi->lock); - - /* After rb_erase() aux request list is private */ - for (aux = wpa->next; aux; aux = next) { - next = aux->next; - aux->next = NULL; - fuse_writepage_finish_stat(aux->inode, - aux->ia.ap.folios[0]); - fuse_writepage_free(aux); - } - fuse_writepage_free(wpa); spin_lock(&fi->lock); } @@ -1938,43 +1836,6 @@ __acquires(fi->lock) } } -static struct fuse_writepage_args *fuse_insert_writeback(struct rb_root *root, - struct fuse_writepage_args *wpa) -{ - pgoff_t idx_from = wpa->ia.write.in.offset >> PAGE_SHIFT; - pgoff_t idx_to = idx_from + wpa->ia.ap.num_folios - 1; - struct rb_node **p = &root->rb_node; - struct rb_node *parent = NULL; - - WARN_ON(!wpa->ia.ap.num_folios); - while (*p) { - struct fuse_writepage_args *curr; - pgoff_t curr_index; - - parent = *p; - curr = rb_entry(parent, struct fuse_writepage_args, - writepages_entry); - WARN_ON(curr->inode != wpa->inode); - curr_index = curr->ia.write.in.offset >> PAGE_SHIFT; - - if (idx_from >= curr_index + curr->ia.ap.num_folios) - p = &(*p)->rb_right; - else if (idx_to < curr_index) - p = &(*p)->rb_left; - else - return curr; - } - - rb_link_node(&wpa->writepages_entry, parent, p); - rb_insert_color(&wpa->writepages_entry, root); - return NULL; -} - -static void tree_insert(struct rb_root *root, struct fuse_writepage_args *wpa) -{ - WARN_ON(fuse_insert_writeback(root, wpa)); -} - static void fuse_writepage_end(struct fuse_mount *fm, struct fuse_args *args, int error) { @@ -1994,41 +1855,6 @@ static void fuse_writepage_end(struct fuse_mount *fm, struct fuse_args *args, if (!fc->writeback_cache) fuse_invalidate_attr_mask(inode, FUSE_STATX_MODIFY); spin_lock(&fi->lock); - rb_erase(&wpa->writepages_entry, &fi->writepages); - while (wpa->next) { - struct fuse_mount *fm = get_fuse_mount(inode); - struct fuse_write_in *inarg = &wpa->ia.write.in; - struct fuse_writepage_args *next = wpa->next; - - wpa->next = next->next; - next->next = NULL; - tree_insert(&fi->writepages, next); - - /* - * Skip fuse_flush_writepages() to make it easy to crop requests - * based on primary request size. - * - * 1st case (trivial): there are no concurrent activities using - * fuse_set/release_nowrite. Then we're on safe side because - * fuse_flush_writepages() would call fuse_send_writepage() - * anyway. - * - * 2nd case: someone called fuse_set_nowrite and it is waiting - * now for completion of all in-flight requests. This happens - * rarely and no more than once per page, so this should be - * okay. - * - * 3rd case: someone (e.g. fuse_do_setattr()) is in the middle - * of fuse_set_nowrite..fuse_release_nowrite section. The fact - * that fuse_set_nowrite returned implies that all in-flight - * requests were completed along with all of their secondary - * requests. Further primary requests are blocked by negative - * writectr. Hence there cannot be any in-flight requests and - * no invocations of fuse_writepage_end() while we're in - * fuse_set_nowrite..fuse_release_nowrite section. - */ - fuse_send_writepage(fm, next, inarg->offset + inarg->size); - } fi->writectr--; fuse_writepage_finish(wpa); spin_unlock(&fi->lock); @@ -2115,19 +1941,17 @@ static void fuse_writepage_add_to_bucket(struct fuse_conn *fc, } static void fuse_writepage_args_page_fill(struct fuse_writepage_args *wpa, struct folio *folio, - struct folio *tmp_folio, uint32_t folio_index) + uint32_t folio_index) { struct inode *inode = folio->mapping->host; struct fuse_args_pages *ap = &wpa->ia.ap; - folio_copy(tmp_folio, folio); - - ap->folios[folio_index] = tmp_folio; + ap->folios[folio_index] = folio; ap->descs[folio_index].offset = 0; ap->descs[folio_index].length = PAGE_SIZE; inc_wb_stat(&inode_to_bdi(inode)->wb, WB_WRITEBACK); - node_stat_add_folio(tmp_folio, NR_WRITEBACK_TEMP); + node_stat_add_folio(folio, NR_WRITEBACK); } static struct fuse_writepage_args *fuse_writepage_args_setup(struct folio *folio, @@ -2162,18 +1986,12 @@ static int fuse_writepage_locked(struct folio *folio) struct fuse_inode *fi = get_fuse_inode(inode); struct fuse_writepage_args *wpa; struct fuse_args_pages *ap; - struct folio *tmp_folio; struct fuse_file *ff; - int error = -ENOMEM; - - tmp_folio = folio_alloc(GFP_NOFS | __GFP_HIGHMEM, 0); - if (!tmp_folio) - goto err; + int error = -EIO; - error = -EIO; ff = fuse_write_file_get(fi); if (!ff) - goto err_nofile; + goto err; wpa = fuse_writepage_args_setup(folio, ff); error = -ENOMEM; @@ -2184,22 +2002,17 @@ static int fuse_writepage_locked(struct folio *folio) ap->num_folios = 1; folio_start_writeback(folio); - fuse_writepage_args_page_fill(wpa, folio, tmp_folio, 0); + fuse_writepage_args_page_fill(wpa, folio, 0); spin_lock(&fi->lock); - tree_insert(&fi->writepages, wpa); list_add_tail(&wpa->queue_entry, &fi->queued_writes); fuse_flush_writepages(inode); spin_unlock(&fi->lock); - folio_end_writeback(folio); - return 0; err_writepage_args: fuse_file_put(ff, false); -err_nofile: - folio_put(tmp_folio); err: mapping_set_error(folio->mapping, error); return error; @@ -2209,7 +2022,6 @@ struct fuse_fill_wb_data { struct fuse_writepage_args *wpa; struct fuse_file *ff; struct inode *inode; - struct folio **orig_folios; unsigned int max_folios; }; @@ -2244,69 +2056,11 @@ static void fuse_writepages_send(struct fuse_fill_wb_data *data) struct fuse_writepage_args *wpa = data->wpa; struct inode *inode = data->inode; struct fuse_inode *fi = get_fuse_inode(inode); - int num_folios = wpa->ia.ap.num_folios; - int i; spin_lock(&fi->lock); list_add_tail(&wpa->queue_entry, &fi->queued_writes); fuse_flush_writepages(inode); spin_unlock(&fi->lock); - - for (i = 0; i < num_folios; i++) - folio_end_writeback(data->orig_folios[i]); -} - -/* - * Check under fi->lock if the page is under writeback, and insert it onto the - * rb_tree if not. Otherwise iterate auxiliary write requests, to see if there's - * one already added for a page at this offset. If there's none, then insert - * this new request onto the auxiliary list, otherwise reuse the existing one by - * swapping the new temp page with the old one. - */ -static bool fuse_writepage_add(struct fuse_writepage_args *new_wpa, - struct folio *folio) -{ - struct fuse_inode *fi = get_fuse_inode(new_wpa->inode); - struct fuse_writepage_args *tmp; - struct fuse_writepage_args *old_wpa; - struct fuse_args_pages *new_ap = &new_wpa->ia.ap; - - WARN_ON(new_ap->num_folios != 0); - new_ap->num_folios = 1; - - spin_lock(&fi->lock); - old_wpa = fuse_insert_writeback(&fi->writepages, new_wpa); - if (!old_wpa) { - spin_unlock(&fi->lock); - return true; - } - - for (tmp = old_wpa->next; tmp; tmp = tmp->next) { - pgoff_t curr_index; - - WARN_ON(tmp->inode != new_wpa->inode); - curr_index = tmp->ia.write.in.offset >> PAGE_SHIFT; - if (curr_index == folio->index) { - WARN_ON(tmp->ia.ap.num_folios != 1); - swap(tmp->ia.ap.folios[0], new_ap->folios[0]); - break; - } - } - - if (!tmp) { - new_wpa->next = old_wpa->next; - old_wpa->next = new_wpa; - } - - spin_unlock(&fi->lock); - - if (tmp) { - fuse_writepage_finish_stat(new_wpa->inode, - folio); - fuse_writepage_free(new_wpa); - } - - return false; } static bool fuse_writepage_need_send(struct fuse_conn *fc, struct folio *folio, @@ -2315,15 +2069,6 @@ static bool fuse_writepage_need_send(struct fuse_conn *fc, struct folio *folio, { WARN_ON(!ap->num_folios); - /* - * Being under writeback is unlikely but possible. For example direct - * read to an mmaped fuse file will set the page dirty twice; once when - * the pages are faulted with get_user_pages(), and then after the read - * completed. - */ - if (fuse_folio_is_writeback(data->inode, folio)) - return true; - /* Reached max pages */ if (ap->num_folios == fc->max_pages) return true; @@ -2333,7 +2078,7 @@ static bool fuse_writepage_need_send(struct fuse_conn *fc, struct folio *folio, return true; /* Discontinuity */ - if (data->orig_folios[ap->num_folios - 1]->index + 1 != folio_index(folio)) + if (ap->folios[ap->num_folios - 1]->index + 1 != folio_index(folio)) return true; /* Need to grow the pages array? If so, did the expansion fail? */ @@ -2352,7 +2097,6 @@ static int fuse_writepages_fill(struct folio *folio, struct inode *inode = data->inode; struct fuse_inode *fi = get_fuse_inode(inode); struct fuse_conn *fc = get_fuse_conn(inode); - struct folio *tmp_folio; int err; if (!data->ff) { @@ -2367,54 +2111,23 @@ static int fuse_writepages_fill(struct folio *folio, data->wpa = NULL; } - err = -ENOMEM; - tmp_folio = folio_alloc(GFP_NOFS | __GFP_HIGHMEM, 0); - if (!tmp_folio) - goto out_unlock; - - /* - * The page must not be redirtied until the writeout is completed - * (i.e. userspace has sent a reply to the write request). Otherwise - * there could be more than one temporary page instance for each real - * page. - * - * This is ensured by holding the page lock in page_mkwrite() while - * checking fuse_page_is_writeback(). We already hold the page lock - * since clear_page_dirty_for_io() and keep it held until we add the - * request to the fi->writepages list and increment ap->num_folios. - * After this fuse_page_is_writeback() will indicate that the page is - * under writeback, so we can release the page lock. - */ if (data->wpa == NULL) { err = -ENOMEM; wpa = fuse_writepage_args_setup(folio, data->ff); - if (!wpa) { - folio_put(tmp_folio); + if (!wpa) goto out_unlock; - } fuse_file_get(wpa->ia.ff); data->max_folios = 1; ap = &wpa->ia.ap; } folio_start_writeback(folio); - fuse_writepage_args_page_fill(wpa, folio, tmp_folio, ap->num_folios); - data->orig_folios[ap->num_folios] = folio; + fuse_writepage_args_page_fill(wpa, folio, ap->num_folios); err = 0; - if (data->wpa) { - /* - * Protected by fi->lock against concurrent access by - * fuse_page_is_writeback(). - */ - spin_lock(&fi->lock); - ap->num_folios++; - spin_unlock(&fi->lock); - } else if (fuse_writepage_add(wpa, folio)) { + ap->num_folios++; + if (!data->wpa) data->wpa = wpa; - } else { - folio_end_writeback(folio); - } out_unlock: folio_unlock(folio); @@ -2441,13 +2154,6 @@ static int fuse_writepages(struct address_space *mapping, data.wpa = NULL; data.ff = NULL; - err = -ENOMEM; - data.orig_folios = kcalloc(fc->max_pages, - sizeof(struct folio *), - GFP_NOFS); - if (!data.orig_folios) - goto out; - err = write_cache_pages(mapping, wbc, fuse_writepages_fill, &data); if (data.wpa) { WARN_ON(!data.wpa->ia.ap.num_folios); @@ -2456,7 +2162,6 @@ static int fuse_writepages(struct address_space *mapping, if (data.ff) fuse_file_put(data.ff, false); - kfree(data.orig_folios); out: return err; } @@ -2481,8 +2186,6 @@ static int fuse_write_begin(struct file *file, struct address_space *mapping, if (IS_ERR(folio)) goto error; - fuse_wait_on_page_writeback(mapping->host, folio->index); - if (folio_test_uptodate(folio) || len >= folio_size(folio)) goto success; /* @@ -2545,13 +2248,9 @@ static int fuse_launder_folio(struct folio *folio) { int err = 0; if (folio_clear_dirty_for_io(folio)) { - struct inode *inode = folio->mapping->host; - - /* Serialize with pending writeback for the same page */ - fuse_wait_on_page_writeback(inode, folio->index); err = fuse_writepage_locked(folio); if (!err) - fuse_wait_on_page_writeback(inode, folio->index); + folio_wait_writeback(folio); } return err; } @@ -2595,7 +2294,7 @@ static vm_fault_t fuse_page_mkwrite(struct vm_fault *vmf) return VM_FAULT_NOPAGE; } - fuse_wait_on_folio_writeback(inode, folio); + folio_wait_writeback(folio); return VM_FAULT_LOCKED; } @@ -3413,9 +3112,12 @@ static const struct address_space_operations fuse_file_aops = { void fuse_init_file_inode(struct inode *inode, unsigned int flags) { struct fuse_inode *fi = get_fuse_inode(inode); + struct fuse_conn *fc = get_fuse_conn(inode); inode->i_fop = &fuse_file_operations; inode->i_data.a_ops = &fuse_file_aops; + if (fc->writeback_cache) + mapping_set_writeback_indeterminate(&inode->i_data); INIT_LIST_HEAD(&fi->write_files); INIT_LIST_HEAD(&fi->queued_writes); @@ -3423,7 +3125,6 @@ void fuse_init_file_inode(struct inode *inode, unsigned int flags) fi->iocachectr = 0; init_waitqueue_head(&fi->page_waitq); init_waitqueue_head(&fi->direct_io_waitq); - fi->writepages = RB_ROOT; if (IS_ENABLED(CONFIG_FUSE_DAX)) fuse_dax_inode_init(inode, flags);