From patchwork Thu Nov 7 23:56:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joanne Koong X-Patchwork-Id: 13867333 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 4A5EBD5D695 for ; Thu, 7 Nov 2024 23:56:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CA3976B00A6; Thu, 7 Nov 2024 18:56:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C53176B00A7; Thu, 7 Nov 2024 18:56:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AF59E6B00A8; Thu, 7 Nov 2024 18:56:32 -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 94E2B6B00A6 for ; Thu, 7 Nov 2024 18:56:32 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 4E6D31A03C3 for ; Thu, 7 Nov 2024 23:56:32 +0000 (UTC) X-FDA: 82760959386.08.8BE8078 Received: from mail-yw1-f171.google.com (mail-yw1-f171.google.com [209.85.128.171]) by imf14.hostedemail.com (Postfix) with ESMTP id 4681B100004 for ; Thu, 7 Nov 2024 23:55:50 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=YAUU2NUl; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf14.hostedemail.com: domain of joannelkoong@gmail.com designates 209.85.128.171 as permitted sender) smtp.mailfrom=joannelkoong@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731023665; a=rsa-sha256; cv=none; b=6MLy9tT6BtTb+t5XKnxNfx0I/Oo/P5BCb1o3oIGf3Eh4xP/CozNxTOpAyt7BokTxlGU7da 64hGyMhyJxZhPLgaxWFypZnXwusBdLvLfTMuhQEO8BXXHtPNVVhB0pqQj6xTAJ43GZiIUe F842i5HCD6JOfXlLkBIpaGKFKAomZl4= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=YAUU2NUl; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf14.hostedemail.com: domain of joannelkoong@gmail.com designates 209.85.128.171 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=1731023665; 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=ikpYM/WWgMZzee5LK9ccNIkwppCcSDNp4r5PwHAnOS0=; b=C2aGz5m/2pcam65PrrvhOBwu4/e8+3+G+8IG2iXK/LUiZMpmdHh13BpRBCQbRUfGuzz/p0 wCS+bxIrb6edpMMFV6uNdIWXb45aiPnSM3J42Fy/0TAwXY/bi57QDhoebbbGRTU1o0BGk/ 8nC+KnQPaw25oLRCXxj6kFZbK9zeztw= Received: by mail-yw1-f171.google.com with SMTP id 00721157ae682-6e5e5c43497so12746867b3.3 for ; Thu, 07 Nov 2024 15:56:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731023789; x=1731628589; 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=ikpYM/WWgMZzee5LK9ccNIkwppCcSDNp4r5PwHAnOS0=; b=YAUU2NUlNMAuzxayfZx4BhAbDHwVgG5hyjkyga5pA1bEZtGjaExci+P04Ca4H+Mnal X28kbcEkrcHJ+liH4h+Xvn6WVl87mYOT6/Ll80f4GC7A5HC5HRmT2/4D7FjQDz9vKsiB 7VqoqKqN6G145o/0HObOcKyTW1jKxcEshqWjG1XYd4dsneWQ9scVhzt874rjav0161jZ D+Ptld5nbySQnm6mrpno4+RkUx4CggM6zc71a+WCZEV253PNrW75ZQdVujgVu2CBfbXN icMJdL2yRr5xD3ENNOqv0CEfGfs+k30cPa9bto4Rj/UqNo7Vf1WC/RlAGKCP+m9tB7+M eRXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731023789; x=1731628589; 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=ikpYM/WWgMZzee5LK9ccNIkwppCcSDNp4r5PwHAnOS0=; b=bZJE8BBW9QC/2tSkcHsdWDZafSR7hA5lTRc8ZpjdZOCM1Jzlug8o+22EBVH4z3coF7 cVH2ZOWCcyK2ddJKJYMlWcWYWmh9BwM5Hz7XuXupGcZ8gcyrwNGYlFdK4tThJgpDrsJs Lw3azCE7WpCki/X2k3vyliNxTb2bSoR0P5hwZYauWB93/wXhHVGXpaMcMPl2Q+XLvVpm KojLklmwY4HztDAz2d9URUKRbmSyMdSAthnuVEF3s4iy6mojgp6DRfBWvK0N21XRLIIS htKtAEU7hUKi2E1rNTzV1N/sh98lfCqsx0XbKVmTH1v5kV2rwGGM6PxDk1417G9t+caC 6ucQ== X-Forwarded-Encrypted: i=1; AJvYcCXgELfyDehhot7VwHCofgQN2G49Ino9x/9glqw9acMYYWy2VWOAExsMwrcqghqRH5Xa5+JI/2RQ3A==@kvack.org X-Gm-Message-State: AOJu0YxkAF7lCdBTyGNHf3p/ta8KrQzofcKoNJdufZ64mJ34c/YLLAmk VQ/IB4Ji6fxSTSO3Qwb9hmOEIm5MjPTU8ELIm/e/SkqFz4oaRTjm X-Google-Smtp-Source: AGHT+IE1RwTd0+7DYupIY1PYmqJOKwOZCXsEe05QepgoB+3JP5jig5elKW2UZmO9v9UgGqA6cNuR5A== X-Received: by 2002:a05:690c:6886:b0:6e5:b6a7:1640 with SMTP id 00721157ae682-6eaddfa967fmr10156897b3.42.1731023789401; Thu, 07 Nov 2024 15:56:29 -0800 (PST) Received: from localhost (fwdproxy-nha-002.fbsv.net. [2a03:2880:25ff:2::face:b00c]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6eaceb7b234sm5007697b3.98.2024.11.07.15.56.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2024 15:56:29 -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 v4 1/6] mm: add AS_WRITEBACK_MAY_BLOCK mapping flag Date: Thu, 7 Nov 2024 15:56:09 -0800 Message-ID: <20241107235614.3637221-2-joannelkoong@gmail.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241107235614.3637221-1-joannelkoong@gmail.com> References: <20241107235614.3637221-1-joannelkoong@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4681B100004 X-Stat-Signature: np765b3fajsanjaod6eqeg3qwga7t673 X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1731023750-463570 X-HE-Meta: U2FsdGVkX18xIuV1Tu2kMDcAPEb9BtIzqsVoi1ltEL9sO2uUnIcNQm8RPB8ye2YXN9oO7LbMHuW/eRcnx79IENmoutj31PBlcXD0Um78q7uOGW7nwLIXEiKzZbT02x4jnX35kiBBeneC6ZO1a/R6d7yu6GUNNPd4uC+8DlzDnbDEhUJIsPKNtE5j3F9o+wxwj6Mhc0jpzBxza2jgguNh16ZsQFBh7hGV3NmAmS0BM7pTcHmB7E0GcM9unxMfilQGZrUJeCj6Myo0Rv4pOug7MkSe9PoUsCVjc0Y8v1FrBn7Xg3RUmOeKF1rp+KEDQa4dLkxCAIqFhS4DbM3FmMFc+YvrGFnshsk3iK0RvN4RfZhpbpY0w583Id68kZ41h81m+b1pNIREg2CWwzzsY1Wqik+IJK2PnPd1aTuBzI3G50xQINjn48RV3hA3EBgBUO/4Sdg2zHzVOJ+Nrm3izJgulcuXzEj43I+eglu8/+EzHCE1O08rJpcRXLN20zMNbGYG8nnU6fb0pK0J86jQSCJ8Gpdi7YuqeSv8khtH8SBZ14ZvVSBWwnlsHUpkIko1ELfwQdc9OnYxTBwBPOZPauut9iUQZC/SVyGowodAH0tX4oNK23Fzc3igYQzE+QYr3pI/Bmpl1JIk6zStQ10VlDtIMmgUIWb3dBc8dsHRAPmD4ukowFCJSUrREuMWPtejWyHbTVaMdCdD8/en9gOHl2Tp1DdusXPUINVuR8LwDbd8jRFztUgrCbhkYyD1rxPfroav6UST4g8fBuXcpqavb0iUyjfI+YPCZXu2CEJkRE9ks5J6g2DirWCVfk5uBAczkKQM22VPzSK7Vcp7CGGpJtx/7E3yWM8viPH/PLsHUGnlX+Q7CDo05bCVvycFVYzllgBjbM4iFpVE4FlbPEae/XBYez2kPVFyGFC502Kr5UeZ0bcaTTnp9RuAtez56q/nHx9AM+S++CYUpo1shlnasOu DH66miXr 0myxoQ2ydiCUA44K5m0SQ8YeuxKIcxLAyY/ZJNur03FD0Is2a0jr4GHC8+MaZUTIRptKQaITKJB2aLH57jjrnC4n6dHWqfeO6CqYTaL4M1BC48AhYzsWGJheXiJPxtmPIo7PZIcwxr8BsVR2PaWZvB/GEkyvwiHWzwZlE49DIayjeSNuoUt5Pz6r5zgevW8HmiGHCusvqz0MEd/kSRtw4SZnNkgaDFvfRauTD+TBjH4Mz5YNqTIQ0138a2PyEAOilYC6KnLs2a83PTcemlgRzuzTna+NDDaa9ZC/C39c46eNDGKIhoGaToOq130aGYsc45NOcMw81yzUjqWxaR49Zzk71q5OpbVGoLDK3YmFnojSNimpVSWHJaYhOcSkCjK+HZ+C3BXr/kLve2IxetfMkDNcutA== 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_MAY_BLOCK which filesystems may set to indicate that writeback operations may block or 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 --- include/linux/pagemap.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 68a5f1ff3301..eb5a7837e142 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_MAY_BLOCK = 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_may_block(struct address_space *mapping) +{ + set_bit(AS_WRITEBACK_MAY_BLOCK, &mapping->flags); +} + +static inline bool mapping_writeback_may_block(struct address_space *mapping) +{ + return test_bit(AS_WRITEBACK_MAY_BLOCK, &mapping->flags); +} + static inline gfp_t mapping_gfp_mask(struct address_space * mapping) { return mapping->gfp_mask; From patchwork Thu Nov 7 23:56:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joanne Koong X-Patchwork-Id: 13867334 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 54D41D5D699 for ; Thu, 7 Nov 2024 23:56:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9E52B6B00A8; Thu, 7 Nov 2024 18:56:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9955E6B00A9; Thu, 7 Nov 2024 18:56:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7E79A8D0001; Thu, 7 Nov 2024 18:56:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 5A1AF6B00A8 for ; Thu, 7 Nov 2024 18:56:34 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id C1DF01605FA for ; Thu, 7 Nov 2024 23:56:33 +0000 (UTC) X-FDA: 82760959470.19.5680FF5 Received: from mail-yw1-f174.google.com (mail-yw1-f174.google.com [209.85.128.174]) by imf13.hostedemail.com (Postfix) with ESMTP id 9F07B2001E for ; Thu, 7 Nov 2024 23:55:54 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=axR6ouNE; spf=pass (imf13.hostedemail.com: domain of joannelkoong@gmail.com designates 209.85.128.174 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=1731023565; 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=kGp398/OGKFadKTdBHGJCLRTWw479TJgb4XjwbwuJpk=; b=shaEv7NmPyIt9iS/5O2MvswxYaAj3fIfVEsDIKvk8twb/T1ORbS9m6yP1k86/er5rIrhZM /OQYXmVFEOW93o4VTQO7Dznv+0moKBn2jDReBQfED4C7KwhtTuWepS4uJkA4LmAL8ibuuL 56vTK4fd15zkSGQ4u/y70zBX5LcRzq0= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=axR6ouNE; spf=pass (imf13.hostedemail.com: domain of joannelkoong@gmail.com designates 209.85.128.174 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=1731023565; a=rsa-sha256; cv=none; b=YeX3fbEPde8I2Fk21qIZoce69OKKnC+x4Tm1YEX8LQLQXJIkrPGqy5JAstuJbulR/dF7eq O0Ug77BzjU2hekU8rsiAL5h3PUBbRbzUQP00LVLUVs0wiTBNBa2xgYeWYMahz28rliXsFn dLsLLH5J1H9/oXx1/vvVJcejMW4z2/Y= Received: by mail-yw1-f174.google.com with SMTP id 00721157ae682-6ea85f7f445so17443587b3.0 for ; Thu, 07 Nov 2024 15:56:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731023791; x=1731628591; 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=kGp398/OGKFadKTdBHGJCLRTWw479TJgb4XjwbwuJpk=; b=axR6ouNESfopspILGv1fTFH/331srqGO2wcRMCTwNLxXCsZ+D6t6hmoBT/tJ18vFVm db11DJkyExMfjsfnv4fp7ji8pbXckRITQbMnP8+8WDTnlk90JwGEDIRyB2yUzG+rxcoE ZhbMLDGw8GIXjNBbwx+4dPvw2AmBzR7siqRndGc7IhhOdSq9UN1l+opk91pcVh+p5PLO frABI5MrIiejqsfYMF50W/LYOT58YUAFiX//o1D9mAF9MoErXxZYf3YjymLHueNJq9Hp b+LWoGVUc4ytqtng4o6nR/SXG62xB2FHH2GPGWpj2a9M/eMQYorsn2rlCtVmcmMXVkDx 00sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731023791; x=1731628591; 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=kGp398/OGKFadKTdBHGJCLRTWw479TJgb4XjwbwuJpk=; b=gHBBy6K9K3zq/G9RQw2m6u2RMspcJunPLNxZcR3kdaz2/sa4HgR4Uak2UMWMdKIMYq YUSTb5oZqHyt5Diavxw54oJKhQb5e6tzG+dDdnUNDYbmC3T55Ojzk0pLAhg1e0HQQrS7 iFmsUTIyXTn3racljhDCxa4s5YzorcPtvtMdI3U7I4VIzL5OjNlZJxJyou4Z55AgDs0B hVk9A5GbfcwoHIPl12XO5mCW6uoqtOt2WXYEvFT7G/UAwWGGl2MhgpARhznkSnGgCu7r 2TJJfg6/L6I3QUf7kBsquMo9n7CG/cpjbXo9ZNxLl0tJa2/Zeqpj7g+9U7kOD7a8hWXi jAMw== X-Forwarded-Encrypted: i=1; AJvYcCWHqvn/v+TtRvw6pHhb8+UJWMKZ2PRvuMmV4/qDCUjBKRWbMu1pJnawzx2Lhyc/k8pUzSW/DqhebA==@kvack.org X-Gm-Message-State: AOJu0YzrwpoiKIgAEud2FcFtawI22n7n9tbTNBvRiIdpGsjXp2CMqjfM EgEg9FsW/MFP8EC37WRYYM4bX9AeQ1gQzmeIUCOHXKlCA2Uh4Ur9 X-Google-Smtp-Source: AGHT+IGtwXdTUWVou6799sIkHT1OBBdHpywl7x1G3IHz/NTXy8iOQgd0OjfXXOssI2uPEUYjyoyP1g== X-Received: by 2002:a05:690c:4b8d:b0:6e3:8ecc:bb0e with SMTP id 00721157ae682-6eaddd94248mr12819677b3.11.1731023790878; Thu, 07 Nov 2024 15:56:30 -0800 (PST) Received: from localhost (fwdproxy-nha-012.fbsv.net. [2a03:2880:25ff:c::face:b00c]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6eaceb6563bsm4999937b3.77.2024.11.07.15.56.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2024 15:56:30 -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 v4 2/6] mm: skip reclaiming folios in legacy memcg writeback contexts that may block Date: Thu, 7 Nov 2024 15:56:10 -0800 Message-ID: <20241107235614.3637221-3-joannelkoong@gmail.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241107235614.3637221-1-joannelkoong@gmail.com> References: <20241107235614.3637221-1-joannelkoong@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 9F07B2001E X-Stat-Signature: 4eezd9m7eo1kck1r87o84hst8sfem4bi X-Rspam-User: X-HE-Tag: 1731023754-654727 X-HE-Meta: U2FsdGVkX18Ph/w4Hlay6mw527rOizT83fyBlTL6K/32TidvEpU8GZeqQKyGWCVKa2wPgX89+XzwiBDr1bpulLrHW9rYlW/2hZgYohcusb/eum50GOeIVJFcRu8YJoc7ncPY/3OhkZcJl54TDKRRWU2w4tCJDsWV6d0gmZaejNT3Y7v/eGM/ol5c3QYJrcMYq2FyIuImhD4tzRdMqSMSMY3Qv4pBIvPyNyjdz1OvWOOAihIhVLVXjhigJnd7hG+aCoUAxQ7x9sY17/dGzha09Jz4evztFKXjwk7174vP/7e5nVYFbTFOggbOCtQor5YccemLoLUxiPT6WZk9E/91+F0jg7AX/aaA+vLY+wGATBIYRC//IDKcTu3YVKLAXg+AxhSBa729RkolsolOLeV8FQHOm6t06fJgDL+wK7HuTGnY3w0KjAlxAFSGFGOO+L1zfR0YLBANgiAQ1hS51zMs5VzzLo5JcU1hfogOf74jrI33E/AlviQruuxGUV404uXtue3ZL/J9Gczhx4AbcT2XOdDBLct9K8I1SciCjjE5XRhXUkVljHEfCuHAkHEOFYgUanBOPxFkuAIC6l4izvHZSYnFj8iBBXggi9FkolWPkVZ11VH0eE04K/BhaUVVMCsGEHoiVxqiLk5PLR7OdstOldf7t6tdANEt5qJNblOPGU0aXiyRt2OIIrQK+DupWvKU1k5I2lVWKHZHLLUgRb1WvGxHYynu3ZFDq90JeYujTK9qHSw4ex8s5AHBcWk69Xhg1Akhaw1YsnK5PbxadL/rdEua8TVNtCgkwkQoKvfoC1Ditmihlvfyi4Iz3m2WQOiGXaXcKyTXtXo4CbsNszVfAS4qYBK3xpPkl2TSk8WhMrnSSv17qFTw6XXS7rShAVhNWJPg6i65OnyhG0YfZKimq9m4zxAEs4TCj5F0rZT4tlCIwjy8kLb7SBf7XiJaRlcL7lFQSkuyWWP7sf0JPFy U1YfIDgp BnkNKJdVlvbcXVJhDJEfBnQmuBvvheTBggOWraQoYFTSByniPZtbJMhEppFKiU2kNpP5wSk5akaV9ObQlIFj+rM+oTcBkZs5ZkB3mbH5GUPv1tU7cTasRG0HaYo3EDizQMILdo7NA9FMncEpKL6JEBw+8AV/HDoqdvCpmwvqdRTrMKEzyaJVPd7S+fUOibB9weV0jJsKoKgUW9XT/RmVY6ebg06Q65nexgFanPAXKkWCtNCaNx7G1+J1qwa8Ay7Elkw0+vd5gqD0TDmXwZFMiQdxExWmmhkeQB+ufEdX84RAoInMC9Yl1VcTtIa9Q8QNUQXsk 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. The issue is that for filesystems where writeback may block, sub-optimal workarounds may need to be put in place to avoid a potential deadlock that may arise from reclaim waiting on writeback. (Even though case 3 above is rare given that legacy cgroupv1 is on its way to being deprecated, this case still needs to be accounted for). For example, for FUSE filesystems, a temp page gets allocated per dirty page and the contents of the dirty page are copied over to the temp page so that writeback can be immediately cleared on the dirty page in order to avoid the following deadlock: * 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 (eg falls into case 3 above) that needs to be written back to the FUSE server * the FUSE server can't write back the folio since it's stuck in direct 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_MAY_BLOCK flag set, the folio will be activated and skip reclaim (eg default to behavior in case 2) instead. This allows for the suboptimal workarounds added to address the "reclaim wait on writeback" deadlock scenario to be removed. Signed-off-by: Joanne Koong --- mm/vmscan.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 749cdc110c74..e9755cb7211b 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1110,6 +1110,8 @@ static unsigned int shrink_folio_list(struct list_head *folio_list, if (writeback && folio_test_reclaim(folio)) stat->nr_congested += nr_pages; + mapping = folio_mapping(folio); + /* * If a folio at the tail of the LRU is under writeback, there * are three cases to consider. @@ -1129,8 +1131,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 writebacks in the mapping may block. + * 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 @@ -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_may_block(mapping))) { /* * This is slightly racy - * folio_end_writeback() might have From patchwork Thu Nov 7 23:56:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joanne Koong X-Patchwork-Id: 13867335 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 A6DEDD5D695 for ; Thu, 7 Nov 2024 23:56:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B956F6B00A9; Thu, 7 Nov 2024 18:56:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id ACFE48D0001; Thu, 7 Nov 2024 18:56:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9491A6B00AB; Thu, 7 Nov 2024 18:56:35 -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 6D75C6B00A9 for ; Thu, 7 Nov 2024 18:56:35 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 25886120369 for ; Thu, 7 Nov 2024 23:56:35 +0000 (UTC) X-FDA: 82760959512.19.34D5EE1 Received: from mail-yw1-f173.google.com (mail-yw1-f173.google.com [209.85.128.173]) by imf12.hostedemail.com (Postfix) with ESMTP id DC06D4001B for ; Thu, 7 Nov 2024 23:56:16 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=UQFFhQEi; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf12.hostedemail.com: domain of joannelkoong@gmail.com designates 209.85.128.173 as permitted sender) smtp.mailfrom=joannelkoong@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731023733; a=rsa-sha256; cv=none; b=I3iW8INN1fBqiY0LBkR9THQI4JCZRDHJZOqcJ47H4CZaHPU56I+ME6cMEGkS+G6rZco0A3 uFh7FjispY28doqFuPhS4i5T5tGjSn1oj29Qa82jWVXU6N5Q5PAVB13rmt1/QEKR7f0pTK ekCHh0FFs8tnAd0aVqrw2XOSyQeGAf0= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=UQFFhQEi; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf12.hostedemail.com: domain of joannelkoong@gmail.com designates 209.85.128.173 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=1731023733; 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=ZnCvLTbTmq6xS6wpFSTKmY1gePcY6efLtCHlkRWy6SY=; b=J+pWt891pklLQsIbGotEtXl+DQA0xZyf33pBISCVbza6Vstx2DSU6V9QmdZfIRlAh7k5S8 YRXoTT/aZ40Ak9mZbMy+oVj5MMuEVReyInL+QQpgIzacZ2szrD5c21RkkIa/NqZLAl/7/t nnrK0aSH0fGBMe4ffLupe9Zlx3FT8Ws= Received: by mail-yw1-f173.google.com with SMTP id 00721157ae682-6e38fc62b9fso13756777b3.2 for ; Thu, 07 Nov 2024 15:56:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731023792; x=1731628592; 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=ZnCvLTbTmq6xS6wpFSTKmY1gePcY6efLtCHlkRWy6SY=; b=UQFFhQEisMiAQYyrwkEOwQl8XA4S5pBoB2TAzva/d9XiJ2aAw2tIEKXE3Q5Zqy3TAc +ZF2yYMr2w/jgAzUsN3zUL89pf6erldGWxk2q3nvNpABURx9Xh+nDPf7/xQo4A/NIgdY BUOhZKkJayv0GbO1JDZz5+E3acPZJ7prDSWU9rbZ7T/wrMfof807ogxWUfNvMcdagMDV TceX2xCmqSuHfZEsQx4dt0VCJm6kDV3f+I/pzSt39aKuHvTzpBzufPelqS6rjbp59/OY rsDIb+zLi5N2V+Y/aiwxWwUYY7kRn96wPxWDKx8W0bkea0c6xj94fy5mnRorp5FYPmfU LwAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731023792; x=1731628592; 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=ZnCvLTbTmq6xS6wpFSTKmY1gePcY6efLtCHlkRWy6SY=; b=liUwIL9frwGCv5uEZg64Zz7PcJluxkNVOyyTe8XrXBDCvP3ca6DUA+5vKWGiDJsNoJ Y++pDHx1s5YH6RWPBcAS0oDRoHgxQcFVsy1KJ9TqbpcHep5GlxBL5Ig7LTh0fA+jWR0l VGyJ9SBCirDz1/lfZxRSYDpeNqqC0rg9MGhihCKhuu78Tr7HIuK4Ez/LJOXUfW+Jk7sK EKk0rPz6jAMtK4tr4BFgWJcBcjyLOxkiL6ozEiRXE8nNU4Nw+3UH5CNQGWc59RbRuB3e lR5DSO3QsdgvDLYNvcjr7AepL61Oz95XD6HbsNGT3y2zZo+AvcBjYNHlP1XPi6/sffiX mg3g== X-Forwarded-Encrypted: i=1; AJvYcCUJ4ihLnXfsagqhRKYchdRc0PpsDG1sTsV9DJqaMdlz9UNYlSoQH1WskRS/wWzs9P6MGS67zeDuGQ==@kvack.org X-Gm-Message-State: AOJu0Yxag3u9xwgY/f0D2IGBwngZoKa45pJlrKtrI1YA5nwQTLm04YOp SqqMceJ6havEoaif1Phdo4mSZ6wpme/7R2gaeBlm+YkszEtx6P47 X-Google-Smtp-Source: AGHT+IGJ7XIGDH3gjwhwJwxg42yQL0oNlE1U9fJsXrX1XmblFbwOlYN4FwmU8RXv5pchaNWEiPA4dQ== X-Received: by 2002:a05:690c:6e03:b0:6e6:248:3496 with SMTP id 00721157ae682-6eaddd91bf5mr13056217b3.11.1731023792342; Thu, 07 Nov 2024 15:56:32 -0800 (PST) Received: from localhost (fwdproxy-nha-011.fbsv.net. [2a03:2880:25ff:b::face:b00c]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6eace8ee1cbsm4999917b3.29.2024.11.07.15.56.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2024 15:56:32 -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 v4 3/6] fs/writeback: in wait_sb_inodes(), skip wait for AS_WRITEBACK_MAY_BLOCK mappings Date: Thu, 7 Nov 2024 15:56:11 -0800 Message-ID: <20241107235614.3637221-4-joannelkoong@gmail.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241107235614.3637221-1-joannelkoong@gmail.com> References: <20241107235614.3637221-1-joannelkoong@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: DC06D4001B X-Rspamd-Server: rspam11 X-Stat-Signature: u4uq6qwbup4pkqjsrgxjmez4pbnfaaik X-HE-Tag: 1731023776-603691 X-HE-Meta: U2FsdGVkX18VVaw7F87wPped+zu2yDQ8CDcInIKubCv3pm7/S8k31EVJKo+/lVqYAYam4wZZfRBGKR5Y7/yNIhWWSXoeNm8aukx4MlAPcYZixNBcJrmFt/CRCSiuoIf0CksP8hNcBZtg8RlUgncnzds2A2DnoUntJ7EHigUH5SimemrU0gpUCh8Hp6K8mvCEa/LlrGSgedgs4XH3FZ/86hUlX4PBFdCMF2OafeUwtOaTvSxXeqC/a0BQuXSlRU2JWDXvuimxM8nhvGjMjS3G7rkuJmTn637g6YxK5IUvDjNxWMNgi+ACVJWfhYTRNRuUIZ5gsFyIjtxLe01g3AT4GaE3B2+v6s4PNQDiV7aP/MszsEv64/S0AvwFY5hClaK1YfYnwwsS2vbLFh92yHcsg6dztHZBNtUM2ikTZhIxWx/lnPnHGplwxKs1hc2GD3Dm++R3pxaFodNP/bzdScbh6mpgnDJ9MEqrdcAoJvGeXVnIlSbxy05Cx5LmA2IVJHnzv1WNDRDZqi2gEiR2YQrJcfAMoaqBy4yQrvSXV4s4wkPkU6x5e88Lf9XeDDG11EMzRAblWC5mqO/3raGU/dq7WKG1/Yx2WN6pjjefdis6ya9SJEsMTk4yTvIHODwCOuYUn/xdE6Xiir+G/0KDkyBPsw15YI+XGmPdaYr1YXh6lZ+t+PU9uJPmkJ2syesdSuDgzEBwwxy2hJT6ekZxn6YFe7BCsmGgFKK/y/Otp1RBwJLAndeYLFPB+VaZH6JvvZmjqd/nokMicXPQBryy4yPO14wUtsmRSbnnEiN5o9jw/Te7LdSOMy16X4ogywP1Yu4QkGDKomXqJkuIy0qcuZPUHENBYYQLFzg1GX2xT3e80w3l9QVSIl73haQdp9Vt4Ap1jiXXamJF2bshagWigid8GN/K33JiBePM0lRKW28afYHhjEV1dELEfkfIQPgI7HAvVveMRByhYkGPToOe4TD Tg9O//x9 Ed6TQkO2T4wMS3ph1Jfvpsm2V0vSUCdqhSzZCHoFovIDWbSsvaXRUzkJvwID8u6+vbYK8F3nv59sAOlwguVdfXLBTC8g+cEyp/3lyLjTK520hbxflMMThHzEMIDf/2dNibzI9EwPurtVXKdgFHIKF5eJ/JaqoqmwaTICJXXcB/QW+MKCag8KrDDOuG4uIfHMORxPvug7bfk9sGohMBJ5DO1eHSBWvb7eMSpLwxrD2ACnpAkRk+Bpu22J5oUiFFJILvcqGj27TmztKppwvDkaZIqq5Is3K3NaoAOb4CkWYz3d/nwxadMHBJnuCV8ZQanVVbk1SWaFOmmV7VBWdUqE2AsTUnMwAgKtsWpl2O+YwpfGZ20iGtD65OefqUW2f+oTiF78Z6EFzG5Hptfgfc6dNB6Uckw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.002608, 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_MAY_BLOCK flag set, writeback operations may block or 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_MAY_BLOCK 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_MAY_BLOCK flag set has actually been written back to disk, they should use fsync(2)/fdatasync(2) instead. Signed-off-by: Joanne Koong --- fs/fs-writeback.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c index d8bec3c1bb1f..c80c45972162 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_may_block(mapping)) + continue; + spin_unlock_irq(&sb->s_inode_wblist_lock); spin_lock(&inode->i_lock); From patchwork Thu Nov 7 23:56:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joanne Koong X-Patchwork-Id: 13867336 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 644AAD5D695 for ; Thu, 7 Nov 2024 23:56:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4425A6B00AB; Thu, 7 Nov 2024 18:56:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3A3F96B00AC; Thu, 7 Nov 2024 18:56:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1CC8B6B00AD; Thu, 7 Nov 2024 18:56:37 -0500 (EST) 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 E98176B00AB for ; Thu, 7 Nov 2024 18:56:36 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 93C4C14060E for ; Thu, 7 Nov 2024 23:56:36 +0000 (UTC) X-FDA: 82760960100.23.00DAB57 Received: from mail-yw1-f182.google.com (mail-yw1-f182.google.com [209.85.128.182]) by imf28.hostedemail.com (Postfix) with ESMTP id 050CBC000A for ; Thu, 7 Nov 2024 23:55:57 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="bQrlBYi/"; spf=pass (imf28.hostedemail.com: domain of joannelkoong@gmail.com designates 209.85.128.182 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=1731023607; 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=u2CBAn6giMXXiKhPOgLeKDCo9Vrjd3aYf+IrGQBfRgc=; b=aH90anb35MTHtquH17yrkZRcgyvxZKJbH0eHi/2lrfqnSKYV7l2zJ8zqk/XFITt8Ry4FKi ean6LrUFPvvsq8SgkiW+s43eqW5jdQ3uSCPWAvhtAakIvRQL22JQs1V0JBarwSG9zGPAxp VXr3vBmXnlxXTjf/YW8DEIhBbziwppk= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="bQrlBYi/"; spf=pass (imf28.hostedemail.com: domain of joannelkoong@gmail.com designates 209.85.128.182 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=1731023607; a=rsa-sha256; cv=none; b=vGEUHzM2b38z2Exfo1vAPdb+lqhUy2aMWIJPu2a0s/VliWqHwq4v0YtpNGux4e8+IjGwAs blLb2bHl9/Qxul0k+QaRrr2K7JLv9qmWYA0PszbidXzgVPiiLzosHIF0gJPcNzT3y83Q+m zeU08oevs1+tV/aW4+4NG1TMrvjAt/w= Received: by mail-yw1-f182.google.com with SMTP id 00721157ae682-6e34339d41bso13495917b3.0 for ; Thu, 07 Nov 2024 15:56:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731023794; x=1731628594; 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=u2CBAn6giMXXiKhPOgLeKDCo9Vrjd3aYf+IrGQBfRgc=; b=bQrlBYi/QAkUvF9w42JNRIANR/z00Tvo794yKwzpWmdHqoUKNy8+JhHbmAJvEFwrHM 7SA/D3xFyi9aTP6PzT3xiLL/zVJeIyoVe12uPG4GAHivCcuPuCtPgyQITd1rA8/tvT1D M1CA15KUwTAKg8fkv8RQWoUKF2bS45mYBl0TJ7j5/5ER5fWY3qP8ZkgXKSyARWLT5fL+ v5OD9awzPA8FJdmmTBeREQH0MgORMZfau+r5qQlupNj7kOHaKfOhqzXLBFpXQqVbIvyn jVcPNaZjUzRZ8+lDyPtPbjQQeOJ3CfRn9CANDUccBvIFxQnN/f+krVRF/kOKxNDuelrV Pb8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731023794; x=1731628594; 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=u2CBAn6giMXXiKhPOgLeKDCo9Vrjd3aYf+IrGQBfRgc=; b=jh2xdPt6YKZzLlBUfng3Arm0SpfYL4EeDKt8m88AxAtKmpRfmi5bvYEJkPnivWkSDs YhEKW15Zrxt1m/i1Ah2xyz3aDIVQKyjBmRS+aoFEOjfSQXDZgu72aURWUtQx1iXGHiPP WvHCfN/hKze06eYpKAQLd7SS6aE5q0+ey8ODB/jeEjW6bsqxWRD5nZbSBcB/beGnn4IW +LWK0I5twxlOf2M0xXU8xNkO8sQ5W5s6IW1VXNZgb6/hJD70Si1af141fCSiyJA8O3oc hGCxMZIqe07+/FHI4swmzczHmv5jRklhQkCCcRdZX6ihg8z0SrcXwkBFNauUvqXhI2uD 71eA== X-Forwarded-Encrypted: i=1; AJvYcCXMnNeSDNSOYQ1ICij5FsO1Ph9y4/vYUl8qoH7TrAGX0K+le6xNpFJOQq+6KKpcHfvUhOAgNzHXxQ==@kvack.org X-Gm-Message-State: AOJu0YwY582LDy4xgeIqATIOxbhYAnFLAVewm59u0CWhElfz3BsGIoOg 4KJnGxAglUZtHGONHeNrW4b7pzBuhvYWP72zAc4Nu9DC1sxKqL0t X-Google-Smtp-Source: AGHT+IEFzO2Zgam/gnWf8Abfux5tkvxODQuWALP1dfzNCjLg2EJGoSDqARXu4PrQApxNEjREq7Rfug== X-Received: by 2002:a05:690c:46c6:b0:6ea:95f5:25fb with SMTP id 00721157ae682-6eaddd704c0mr12260067b3.3.1731023793872; Thu, 07 Nov 2024 15:56:33 -0800 (PST) Received: from localhost (fwdproxy-nha-014.fbsv.net. [2a03:2880:25ff:e::face:b00c]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6eaceb09a6fsm5009617b3.68.2024.11.07.15.56.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2024 15:56:33 -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 v4 4/6] mm/memory-hotplug: add finite retries in offline_pages() if migration fails Date: Thu, 7 Nov 2024 15:56:12 -0800 Message-ID: <20241107235614.3637221-5-joannelkoong@gmail.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241107235614.3637221-1-joannelkoong@gmail.com> References: <20241107235614.3637221-1-joannelkoong@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 050CBC000A X-Stat-Signature: rqw7ocab59iiesrod4gm4zmsraznfwdm X-Rspam-User: X-HE-Tag: 1731023757-436086 X-HE-Meta: U2FsdGVkX1/PLpJWemJR1X1xSh1ZXuRl6eJe/KXO5qtCFS+Qrwwu++AN49ag75e34FC7OADHFoslNadDs2AOWMUnqXBXSL8X2GAmEVsovjXIQZ6FPbs4KqeQJo54a6gqGXykVqYYrdsQxX516twtjmEcBzDVFyjPm/A80QpJkMY7qha0pGg8jiTKg6qndbrWv0V7AfoqrHiCL5B9GjN5KRXizJqldKkY2N0frlizVQ6ZLiO2b2HkZ3QweZ/Rzo56sRPmfdeIV7u+7ca5vXs8KZ8A+7eHzY5UH9IsFYtwqN7lvuNy5lsEy8ew+lw7TBu+fCBfdTkoLVPg7bH4ND+z1f8+vQ9ZZiM0P8Imr7lJmiq06OjmkI/To/N6b2nYMP9sbG4kDL5Bl/Ku/5zW0u2po6jkNlqMRwIrrENEqRKdbpdW7V1fvhOyFHnM4RlaYPCRwOuLtjZ+QZqpEFPSM4NYqsMW4MpsP8k5ERdKx5eTtMJbFcQClumJbPbpMrwq8XEtERmJhcu5Moq0IHDoR/Aqe3Vb/+TEnHa3nq8E9fwn221Nt9SyYOLTugGXIxEZqDK4tbZ4XmwkBq2MM4NDHSHZpOw7TNSAvX8lztddlwVGgevTGTmvAOs2qXKp1/J/dvyEajzgkk/Im07AYUK3yVZvCbI6XSd2RNeWQ5mjZmG1ssQ7hXdY2K0eOM4QSM892ZIMw9W3eFVzLGDWMh0icGyG5DIqdoYM5mVjoseeeMIhQnRI1nQhf72fqW3FOpbGB1+H0YyM4eSEhU8JammPYorAlDKSGphyZEtnGZw+wsF9YVqDKKFVJ54ZnyCHBH/3CmOKdXgDa0h8uKBfoeqzRbUaN+pN/9fiBOEBp8M0pP4BPeTmGzaHDUv1c+zco8np5yGQRRRzGU0GvOd45EY9Mqnff06svyIj+L/5GMmhOJcXUSy2Y/TQXLqRgSbtQzTcm8r/1cnGtlmb1jsGj8uSeZ6 f/zjGjuH pmn5o8drbWqbHd5ZkKA41sNApPQquXWyCCOkJ3BMlE67hm0jPJ4afTn6ImeRqsg+fb4URA8PrpcSe2IfF16bWleTFzc2hww7oa9CdXaoR+eSLwA/Mhg4Culh2oAT4aQOtREBHEMEAsp9z+tqxGEpBaE/xxDVxmPCrTptRCbRvMdDdM3wSAdUdxCmR367Z7mqdoETaHgviKEV3xPJmbCa857J6yJS80v7WqniN9PpL/ODknOeXwpfdCusKMHi4YE2ReAZpx+R6ENSOsK5VL5S0lqHKFutSYZPQa9GDhFfvyV11ubhyPAHpeqVsOVMXF0O3x7VQ0pMtJhWFi+u1omYA4gF/6mnIHlwIcU5LBdrYJoPgNI4rye8+Q3jAY/+wdw3QUJujWBUx/BrDKXxQIRk2bXvj5w== 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 offline_pages(), do_migrate_range() may potentially retry forever if the migration fails. Add a return value for do_migrate_range(), and allow offline_page() to try migrating pages 5 times before erroring out, similar to how migration failures in __alloc_contig_migrate_range() is handled. Signed-off-by: Joanne Koong --- mm/memory_hotplug.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 621ae1015106..49402442ea3b 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1770,13 +1770,14 @@ static int scan_movable_pages(unsigned long start, unsigned long end, return 0; } -static void do_migrate_range(unsigned long start_pfn, unsigned long end_pfn) +static int do_migrate_range(unsigned long start_pfn, unsigned long end_pfn) { struct folio *folio; unsigned long pfn; LIST_HEAD(source); static DEFINE_RATELIMIT_STATE(migrate_rs, DEFAULT_RATELIMIT_INTERVAL, DEFAULT_RATELIMIT_BURST); + int ret = 0; for (pfn = start_pfn; pfn < end_pfn; pfn++) { struct page *page; @@ -1833,7 +1834,6 @@ static void do_migrate_range(unsigned long start_pfn, unsigned long end_pfn) .gfp_mask = GFP_USER | __GFP_MOVABLE | __GFP_RETRY_MAYFAIL, .reason = MR_MEMORY_HOTPLUG, }; - int ret; /* * We have checked that migration range is on a single zone so @@ -1863,6 +1863,7 @@ static void do_migrate_range(unsigned long start_pfn, unsigned long end_pfn) putback_movable_pages(&source); } } + return ret; } static int __init cmdline_parse_movable_node(char *p) @@ -1940,6 +1941,7 @@ int offline_pages(unsigned long start_pfn, unsigned long nr_pages, const int node = zone_to_nid(zone); unsigned long flags; struct memory_notify arg; + unsigned int tries = 0; char *reason; int ret; @@ -2028,11 +2030,8 @@ int offline_pages(unsigned long start_pfn, unsigned long nr_pages, ret = scan_movable_pages(pfn, end_pfn, &pfn); if (!ret) { - /* - * TODO: fatal migration failures should bail - * out - */ - do_migrate_range(pfn, end_pfn); + if (do_migrate_range(pfn, end_pfn) && ++tries == 5) + ret = -EBUSY; } } while (!ret); From patchwork Thu Nov 7 23:56:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joanne Koong X-Patchwork-Id: 13867337 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 54C01D5D695 for ; Thu, 7 Nov 2024 23:56:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7C3246B00AC; Thu, 7 Nov 2024 18:56:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 774626B00AD; Thu, 7 Nov 2024 18:56:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 613106B00AE; Thu, 7 Nov 2024 18:56:38 -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 415DD6B00AC for ; Thu, 7 Nov 2024 18:56:38 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id DFBC680669 for ; Thu, 7 Nov 2024 23:56:37 +0000 (UTC) X-FDA: 82760960520.18.6E8AD6D Received: from mail-yb1-f177.google.com (mail-yb1-f177.google.com [209.85.219.177]) by imf21.hostedemail.com (Postfix) with ESMTP id 975B11C000E for ; Thu, 7 Nov 2024 23:55:27 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=YC4U7l1D; spf=pass (imf21.hostedemail.com: domain of joannelkoong@gmail.com designates 209.85.219.177 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=1731023710; 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=lr8JpF5lWbeUzT238/bHr55gxwNV9GQSeDBdKh6actU=; b=yjwSvr9ahqfqf1PmobXFVESgyv71a9Znc81gwCzDhP/W2KLHfAvkRB0CYEfYC2pvN2/IwE rOb68wZcKkwMtYtfLKIbCkj6b6BJdSy7ClCJFaLnoHutIZ+HengqIcMEoEqekQeqR5Caz4 mqGLGL5edKh03F3aLx+R2NPur9bUHy0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731023710; a=rsa-sha256; cv=none; b=VJE36DsZ/TXcdKN0ABWezbpmbu8Y/IueGBWh4i1Orq6RUrlp4PkeG0ANOpKmBOLB3io9Sd pm3zIhMtKoVEfDIYCAIMim1Ir88c1uKoBX3kceSWuszDpaYP7zfeXQpeJ6FeAGZxaK9fg2 zH52GZz0LdA2pAS9UWoYQtrehFSCtyE= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=YC4U7l1D; spf=pass (imf21.hostedemail.com: domain of joannelkoong@gmail.com designates 209.85.219.177 as permitted sender) smtp.mailfrom=joannelkoong@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-yb1-f177.google.com with SMTP id 3f1490d57ef6-e29047bec8fso2183052276.0 for ; Thu, 07 Nov 2024 15:56:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731023795; x=1731628595; 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=lr8JpF5lWbeUzT238/bHr55gxwNV9GQSeDBdKh6actU=; b=YC4U7l1DAX2vTyRS5dWoSZC2NFFc8xsXYPt6acPimXvPXbX+r0et8Gi4EBdKTqKhe+ CisfsSIGV8x0I310HAhUqcXzVTKP0V+J1t51A+91xefNoLJOKPrA9fv0YHB2jD3bHCmV sPcK1s8JL5acYEF9oZt+j5lhJ5Q4qdMx46h9r6lkIVmlHLTaS+oj2p9VQhyLb8lGoiB2 HidasDzMZuZ6bGAB5a81LhGpsQGR3yzI2BYx//m6XPMVp9UcNtxW17+FpsAsAmFVZHHO /tk881UfI1zFcIUp4StlY4vZhgamCwjqSPMqDiwMt8Kl2bPw2caREKyH0v+JGyIVTil3 1Ymg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731023795; x=1731628595; 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=lr8JpF5lWbeUzT238/bHr55gxwNV9GQSeDBdKh6actU=; b=kcgZMi3YPdVhfSV0MoSPzARj7ds9wK0RhXgsaME2Uac4/T+E0+wXIjWssNCJeA4eiR TNjanN3VckhpkS1SVEBFU7Va8HEEooqLqSpNHDo/A3x9MYr4znLg+UERpfP4/nQaxa8B eBi7AydUI+6yD/i6p0rT8Mggp0BHZdRbBbN+10lA/wQZTSYjw+lzzW+QKqgwJdG1X2pJ HXjUBB2Tr1adGKR7DJoFmB1eQEs8JN+7VK9x5g6FVw2F7QHPr/vXIJPKAikpddar0TQq jUu7DE95ZLGnjuWw2qMgY+6zgCDyXWi6ZPO8lXBSTa+EUv7MPitpqVeLDOzGuIOGXqnc 23/w== X-Forwarded-Encrypted: i=1; AJvYcCWrktszOmHgOJ+eOEqmKlZdPh/kmbt2OciCfLKJkJGFloAGBLSBNhYfqoVe2vgzh1UCFhVLFvUGBA==@kvack.org X-Gm-Message-State: AOJu0YyWj+/MOm2CylMW+kqhnU8OFQJsaBR7sBOVVOsF6grgFnuhQsSP SPjTQZZmBhdUXoUufclwdWPHVR2ahIXzY1Sk6UFI2X8y6rJ5MXLV X-Google-Smtp-Source: AGHT+IGOIT3+Xy+DzAbYdTcJrTAKRDTg3sonybdp7wxjtEbgM1bVGNx6YfgaqkWqC5P3MjLQHVppoA== X-Received: by 2002:a05:690c:d8f:b0:6e3:ceb:9e5c with SMTP id 00721157ae682-6eade52f876mr6909907b3.17.1731023795158; Thu, 07 Nov 2024 15:56:35 -0800 (PST) Received: from localhost (fwdproxy-nha-014.fbsv.net. [2a03:2880:25ff:e::face:b00c]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6eaceb96901sm4840707b3.131.2024.11.07.15.56.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2024 15:56:34 -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 v4 5/6] mm/migrate: skip migrating folios under writeback with AS_WRITEBACK_MAY_BLOCK mappings Date: Thu, 7 Nov 2024 15:56:13 -0800 Message-ID: <20241107235614.3637221-6-joannelkoong@gmail.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241107235614.3637221-1-joannelkoong@gmail.com> References: <20241107235614.3637221-1-joannelkoong@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam10 X-Stat-Signature: 9zpstd71ujfc7exco7bkutpq81fgdjdi X-Rspamd-Queue-Id: 975B11C000E X-Rspam-User: X-HE-Tag: 1731023727-63556 X-HE-Meta: U2FsdGVkX1+qsUf/MSqT/TUPq2eDOzFdHd3F50moXTLRGvVuw5+rRlN0e73vwPv64q9jEdKr8odjhyD3hS/UjcZIq+9YmjEt3wHkgf2OJeTm+5icm3KyC3XGLuJWT455D+Q8xGsp+xuDi9Nb7YqaO+qtMmyqyL5xbyPkW46fZ+4J0cNSsnoRoetK6OtrbUZmixSCs6ICMCdt2P2Y6BoJZHX9mg/1CPhZrenLajyuWn5Zv5GgahCnQMcWgRHmzF+cvce2Xt0rzYnynw5rVlgSdUIWniNWUMuXdHhDbffLgWbx7mszR262Xdnd+V4jIv2WWCCL9+pnZruGUpKRXYqVsL2HrxbcgQlLdd5g7QAJSlpJj18IpQC33LuODIhN1c6nCSBjwwJrn46NzI3BI8ffLYqIf94Vp81XoTUYTiLgmvcGeRouTRdhgOQ6JIWfQwDQzmHSfggN51Y82FbDqojd6vbqfrYvOutNjEnAqN5bJ7hf+jL03oJAzKV2wVwyqBBLpEwc8J1nLnYR574oN5D5C0d3D1tmgHf3AZ4/+tCl035qFsDwF+fCgHTYpMYkMnAyl7U6LFa1vPvDmzwRYrbDxpn9KA4r/3+0l1bfsrcVesMkQSWmppi8lZeK9G2z6mVdHZB4Xc761vxUVNrGh2XNyRDXMMPea5RvVkZladVyTgTCVzLEKa9zqThWT38nH5y2MjlFs3jC9LGF5pBabcBZOA6Kfl2m9xW2wyQZEaoQIPrIYa00RxNQOixtkDcfGnXnFah6jfBRGnoLa1UFWCpT9FwZ7bw49et62ehnLkjRTVpKkiawe5arThy2/srL2cbdDd4oiz+WcxG005PH7zknpYSY2Hb47CQMxsR6i7DgIwbJXnZMOYB8iRE2t1dhOTyeGc3xyfE1eW4SFwYrycS59iEQ4oN2dXBP19x4e04hiNZ8nDCPcb8QZg8gEIKqRhzP8h/rmgbkbAY5agj1OSD XzDzuLOU RiOZhvSHLhY66dX8i3WJ2V3As7Skk+7IUcAPUp74NifhBxjtXhGCZy9d2faLRABkhzIdk7zWM7CeUI5QOfH42x0EncOV2Cr5YfXLTh6bm2JsxCpKOmgdRfocn2D8dOKPH7aEgdkr+QRojssWr05osCj/teKzaQ4NyGvSxrW8Nf+T57iPxANvMqS4L7VonUBlVn8IRAueJldQ/PwKp6BOQ2rCbt8fQ9vDfyWCOURVc5VxV09dCxmQH26oepGSxhPRlQaIPVxbuqeM7kHO5Ff7rk4K/uUBK+hBNgFQn08XA8D/Ub1HJMMh2CTreiJ5rjpuejJBPTMdS3+WcIuR+/7zx+nK4FResIJVlLa6hsKe8mLMC17cNy4PNc4NZYUn1LzXq+TPJrT3/CnBllJyjIh1RzEeRxQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000054, 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_MAY_BLOCK flag set on its mapping. If the AS_WRITEBACK_MAY_BLOCK flag is set on the mapping, the writeback may take an indeterminate amount of time to complete, so we should not wait. Signed-off-by: Joanne Koong --- mm/migrate.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mm/migrate.c b/mm/migrate.c index df91248755e4..1d038a4202ae 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_may_block(src->mapping)) + break; + fallthrough; default: rc = -EBUSY; goto out; From patchwork Thu Nov 7 23:56:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joanne Koong X-Patchwork-Id: 13867338 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 1FA14D5D695 for ; Thu, 7 Nov 2024 23:56:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E7B706B00AD; Thu, 7 Nov 2024 18:56:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DDD516B00AE; Thu, 7 Nov 2024 18:56:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C15966B00AF; Thu, 7 Nov 2024 18:56:40 -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 910CC6B00AD for ; Thu, 7 Nov 2024 18:56:40 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 230E91C5499 for ; Thu, 7 Nov 2024 23:56:40 +0000 (UTC) X-FDA: 82760959848.27.4180B90 Received: from mail-yb1-f181.google.com (mail-yb1-f181.google.com [209.85.219.181]) by imf08.hostedemail.com (Postfix) with ESMTP id 2A869160002 for ; Thu, 7 Nov 2024 23:56:13 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=GrKwD1GT; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf08.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=1731023738; a=rsa-sha256; cv=none; b=RFWv6Hu9FmOmQs/xc+k5hhUMMibd9Tmef5qdWFPw1WzTznoitCLdEkD5pgT8BOOmkYotrs o4gzvvmbCd+9qfvcC0Q/v6v+K+Nf7M+biUmj4q425290v4XzlLmaZSdXrVpkkg09j+uG3S h8MTcjgDgK8kKspVaDeMq3xOYx/C5oQ= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=GrKwD1GT; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf08.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=1731023738; 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=K2zQ4cbFB7mO03fKPcDd4nTcilpBp/JPN/aDuEpSydU=; b=N+Kg1Clot5+rhCg1dUqv4kg1dqjiGkNqMpZ1hV5RHi5SRNvRpszUVYDRpc6jTBKRAtLU/b Fcf3eKPw2RrOPZYz2XDdLmtwgc/PykQPRq6eCqeVS2AN5RPP/m10oxb7AK3Pyeddf/QY8g cqsSLvLd1mbdUzxcN4wvh/P+mEl/oio= Received: by mail-yb1-f181.google.com with SMTP id 3f1490d57ef6-e330f2e9fc0so1738531276.2 for ; Thu, 07 Nov 2024 15:56:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731023797; x=1731628597; 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=K2zQ4cbFB7mO03fKPcDd4nTcilpBp/JPN/aDuEpSydU=; b=GrKwD1GTzRIwKmsOwuDbQvKDk9flZRg2qADIjja3YmTMhsSNawfXP4+N7e3/QY/6pG Fpd3mGmnjXeOrOUkirKEFRfgb+9/Vp4I6gP3kuYTThI17tDD49uSSwEI33dBp056+Tgk KJjiomb+iiEeELkZ5u7vFve0SNTpzXmuVvRTmbjqeWffxTgWTuD2rKNquwdzxJ0GLTyU H7sroFM0QdbT/yFnVjOnHAbKZRcVHciIIYY8EaLylQ0PNgzyNq2QGPdINHr/KyeH8lEE zr2nfXDWrlLwPYV4mU+9WXg0o/lVDfR14Gwa9uj36vlr5sa58Wh7MEJ5Otb3HB9QSRjm W3WA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731023797; x=1731628597; 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=K2zQ4cbFB7mO03fKPcDd4nTcilpBp/JPN/aDuEpSydU=; b=p8bvUoNgpWvRgLoSfVx4g3lCy7XWfocq1Xc5K0UGbqO62ZrsNsM3uiWpL6DOky90KJ 4BqdRY0olqzhHBm9GZgwAkqyvMei+y/rVFvM/zkniMurOopwttuPKm+UXyBjaIsFJu80 EZt1+acraw3kFJqCfGQVS68BtGPH87ZeCbYcHaGTzdv2mVYImq+t9h1irmEFfJXWrb0r ohoNv/HOL2F0JHl/CxGsp1w8JV0O5BNy6kauH99kU2TIOxSPFkdmJ6QBrsQlRT48Thiz 5ZnTluFvg2A0LIpb5OIrhO/ctyIJHU4qIMcFhbAuHfN/LrjTnMcufr7YPiF3vYbkliwr xJzA== X-Forwarded-Encrypted: i=1; AJvYcCURlXNigCcokUN0uQn6e2p0TcZ2/p2CpMBJjmgD6TW0VMZECzLdiFUYq0/pCWIrXHgSeZ7HGoo3Kw==@kvack.org X-Gm-Message-State: AOJu0Yz12AmhvoX3ELW5l+NAZy5gsR0ouL73b32LwWfqGezoZTHGYAuZ 3nv1BvHpWv9wC5cis6vd67r2RQAy/WROL0Se8FBuKcRD8vZqjGcN X-Google-Smtp-Source: AGHT+IE9t5iIJx0IaACQdPkFtV/8bJVKL4KVKCbG5Ac7SyO1FbJ7WNLKXvJDB23wfO80Nf5v/CwNSg== X-Received: by 2002:a05:6902:1026:b0:e2b:dd34:9a3f with SMTP id 3f1490d57ef6-e337f84a377mr1030919276.2.1731023797208; Thu, 07 Nov 2024 15:56:37 -0800 (PST) Received: from localhost (fwdproxy-nha-114.fbsv.net. [2a03:2880:25ff:72::face:b00c]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e336f1ba68dsm477764276.48.2024.11.07.15.56.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2024 15:56:36 -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 v4 6/6] fuse: remove tmp folio for writebacks and internal rb tree Date: Thu, 7 Nov 2024 15:56:14 -0800 Message-ID: <20241107235614.3637221-7-joannelkoong@gmail.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241107235614.3637221-1-joannelkoong@gmail.com> References: <20241107235614.3637221-1-joannelkoong@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 2A869160002 X-Rspamd-Server: rspam01 X-Stat-Signature: r45gxwxarp1uwbsgng7qy4jj55fqdy1b X-HE-Tag: 1731023773-19729 X-HE-Meta: U2FsdGVkX18c/CjXEYGoU1sPePfw36v8/9+y2bhyrthyfwepLZIBHyp3JW3tS2agtvR+e1dISrACcKCKN/3HJgkSqaF8BQ7Xad1fR89yp+j44Ujbo4UlhM4pJJkcpXWm5LVxyRX1tplge9y2LD3HVDe6lJUxV4L3pE/OAT/FvETSk8CPuTEm4iru7umw2BmJb1uEgxYbHTTljtXskeHZeNCF4ScCvhNZBaEJre7ramJNcmfpglAGTkJS1yPOAAK4D+uJ5+//TBXudLE8s0PQCBMdTtToconX3YRkJTLRWlQz+ewTU82DACjulk5Ah8dmhAmfgDCo6J5YpN5/TcX7Nhsru9O/Xf2i/yIZeaF85japRzhcEwx+gDBbZ5HZTQ1tFQZTvATCfv9OhTTBOAwLauXnPxd8WEPa8q3lmeO/SBUXxQRxEwXBlK1IZkQah3ZxQtgZIYhwc2B5d5AGYGUEyMloh7rpTcpeyNzR6w1X5E0day47Jg08GFdz62DyNjGlRiju1eFf7fORQBAbtLFirEpAOqgosYQua1cpnlXZBjp/RW91pC5/ZfyajihBxdPVtC00EFylsD+MWTU+jiO1a4LVgW7ogdaVPLir15hmO6RAW3KMOk7WagmQY/2A4ewleqEXRGP4/osekR3ve0yO4bPKKYNZsmG7s1Tz2woHkGLMynqHBfv9Gdy//979VmLne5oK+h2SdEI7vYUFrdybpk4ga89FzyYd5DShTEaPYhT5lNmpRRuf3ZW1hcKij27Q+KjYwWBzAa1SvLHUQNrqb/io70yw0Qd+7JGDzYXAFVVYKYmY9mDYlfMGdQdPOyMCjOvbVIetHs90T+zQDkNtEn3CKlhuU9c9AHdDaddquP8ei4Lt+aLQHMPkBeDdOB7CFbQ8nu1KeIJ2U8c1fG/EXnllSE44MWFN1Z1u0CMdgCCtLnhusv0ofZdwq0PbytDT7HRpiZikbSLjhhXHseg 2dtNNe5/ 3IyVPiK5iVbhyt+7zqMWGGmtRygOvUf9chZbubDX15T/vBs0kH83z7cYJIKDW/OnbOZSvr8d9eyvhUWgW9sgs3UTr3sUuwurkofLa2ECS6T7GRGEfoxJSB1b2Ehuswk55DyjMyu1Znj8egiDgFhAZYcbcArKp9M+GkyloYZOE+MRJqEsN2KOfFaL3OUyas+NW5l+c+Pqp3Bpf2rvHI5y3BBpmAxeghkg/SQ6Vv+deflI5f08QRSHN2x4Q8glWQa9LIT2UakecsOtalgROX2mdS6Co+57Lit7UBtaIYHJ5RM7mnWQv4tsWhghqf98nzhUGPbEfRVmw/+lTIQGpWYJRxSWxTGsEUmA6nitR 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, we allocate and copy data to a temporary folio when handling writeback in order to mitigate the following deadlock scenario that may arise if reclaim waits on writeback 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 To work around this, we allocate a temporary folio and copy over the original folio to the temporary folio so that writeback can be immediately cleared on the original folio. This additionally requires us to maintain an internal rb tree to keep track of writeback state on the temporary folios. A recent change prevents reclaim logic from waiting on writeback for folios whose mappings have the AS_WRITEBACK_MAY_BLOCK flag set in it. This commit sets AS_WRITEBACK_MAY_BLOCK on FUSE inode mappings (which will prevent FUSE folios from running into the reclaim deadlock described above) and removes the temporary folio + 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, 29 insertions(+), 310 deletions(-) diff --git a/fs/fuse/file.c b/fs/fuse/file.c index 88d0946b5bc9..f8719d8c56ca 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. * @@ -891,7 +813,7 @@ static int fuse_do_readfolio(struct file *file, struct folio *folio) * 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); + folio_wait_writeback(folio); attr_ver = fuse_get_attr_version(fm->fc); @@ -1003,16 +925,15 @@ 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; + loff_t first = readahead_pos(rac); + loff_t last = first + readahead_length(rac) - 1; if (fuse_is_bad(inode)) return; - wait_event(fi->page_waitq, !fuse_range_is_writeback(inode, first, last)); + filemap_fdatawait_range(inode->i_mapping, first, last); max_pages = min_t(unsigned int, fc->max_pages, fc->max_read / PAGE_SIZE); @@ -1172,7 +1093,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 +1543,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); @@ -1824,8 +1745,10 @@ static void fuse_writepage_free(struct fuse_writepage_args *wpa) if (wpa->bucket) fuse_sync_bucket_dec(wpa->bucket); - for (i = 0; i < ap->num_folios; i++) + for (i = 0; i < ap->num_folios; i++) { + folio_end_writeback(ap->folios[i]); folio_put(ap->folios[i]); + } fuse_file_put(wpa->ia.ff, false); @@ -1838,7 +1761,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 +1784,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 +1820,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 +1849,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 +1868,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 +1954,18 @@ 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; + folio_get(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 +2000,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 +2016,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 +2036,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 +2070,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 +2083,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 +2092,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 +2111,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 +2125,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 +2168,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 +2176,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,7 +2200,7 @@ 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); + folio_wait_writeback(folio); if (folio_test_uptodate(folio) || len >= folio_size(folio)) goto success; @@ -2545,13 +2264,11 @@ 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); + folio_wait_writeback(folio); err = fuse_writepage_locked(folio); if (!err) - fuse_wait_on_page_writeback(inode, folio->index); + folio_wait_writeback(folio); } return err; } @@ -2595,7 +2312,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 +3130,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_may_block(&inode->i_data); INIT_LIST_HEAD(&fi->write_files); INIT_LIST_HEAD(&fi->queued_writes); @@ -3423,7 +3143,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);