From patchwork Thu Nov 7 19:16: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: 13866967 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 7B8C6D5D683 for ; Thu, 7 Nov 2024 19:17:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C45136B0083; Thu, 7 Nov 2024 14:17:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BCE826B0085; Thu, 7 Nov 2024 14:17:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A20116B0088; Thu, 7 Nov 2024 14:17:26 -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 82C886B0083 for ; Thu, 7 Nov 2024 14:17:26 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 3ED6F1A0B08 for ; Thu, 7 Nov 2024 19:17:26 +0000 (UTC) X-FDA: 82760256600.30.475C3AE Received: from mail-yw1-f174.google.com (mail-yw1-f174.google.com [209.85.128.174]) by imf17.hostedemail.com (Postfix) with ESMTP id BC9DE4002A for ; Thu, 7 Nov 2024 19:16:56 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=W50GZe9t; spf=pass (imf17.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=1731006876; 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=LRqOIFOP4fPvK0VjJEYPYWlKg3WtbX7ZXa3kaUW1+Rv+dTrxUknjRKa3b4gghWNFYkbZM6 3aHmioUulZ0dOscsbyLD/W9Blt4xABY2Boncb7vfniZU6HnskklmOds77AahtqEBx9tTNP m31IG+LJ/bk1PfgAJlNEP7kNTDPo6N0= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=W50GZe9t; spf=pass (imf17.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=1731006876; a=rsa-sha256; cv=none; b=X5Cbpu8J+qbJGmM3cfE8VtsJm+/cyOoFwCwMxv1ClWjnXIgLGm4jhoqYkrguIDjaVTFihj cL2VeuIN87RxUO4XvfL2lJ/6LRDyxo/Ub3x4Oy6HzdIcJohZuDrHyJTyuXYloLgYi91EHX r84OFsD8OO5TActRBALnwnL/ZBxbjpU= Received: by mail-yw1-f174.google.com with SMTP id 00721157ae682-6e377e4aea3so10842427b3.3 for ; Thu, 07 Nov 2024 11:17:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731007043; x=1731611843; 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=W50GZe9txHOTtA2IULv7XdMse2jBMThPkK+CHdHxvXX0TdAJzRI4i81RvVOPcF7Q0+ fTT2ADmcpWQXEX7mOlw0/H9/bORmBMMpS+9uHPXR0Jqt099Mh6wJbu3TYO6OG7hc2G6z KuISNwuYt6/hy6eDJs5fzhYppcbfph7eHEma3A14vcpMU6OR/0rQJ9rtkd1Tl7KXT28y cTMGqM+PpfF0ilmxLVbc+wJ7qNj2vx5mF/a78Rovx4LcTsvfzuc3X2hmIu30e98a8tQt qaQ7cEvC7eXn7ZObUI154y0eSHK4CJtJc4iHqsHjux4BBQGWoNWtTA4WZfooTC1UI24P NegA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731007043; x=1731611843; 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=Lk1nzAK1EVKfWfR0hTUm362VUYRpiIcTUM76t2MpTDIAtfri9qJSoY/Xjo8IrjMqx3 HftD6QsTiq4gOmjl+UGXm2jG0LMHEENxcHNxRPifswMmwNIaX0O8Pn1UsHooPkr0CLvA XQF5v46VuMBMx6JNWYB2iHNcU2iCvXpvyu7f5BmpqlL1SPKsyL6bQPzm2qJi9jlbvAxH ZJvMDCw8Q+vhNUILMWZTzEZWL+AsdPZwC98U+Q2vqlhOTwUaa/s/dn/fl3rKrJQcPDY2 8jYm2jg3f7QWpGPXQLM5iZIyZ+5+4H9DC5mVcS9yXvf/GX+7GXsv2TtW+QkT67VQIsMi R6lQ== X-Forwarded-Encrypted: i=1; AJvYcCUFqyMCvof6038oxu27s7hRHSY+LnLV/yUMuPlfchSiuAWc9gisFg3C4iILUSEyg3kseoAIgpVnuA==@kvack.org X-Gm-Message-State: AOJu0Yw48RqBthGcBlhpJabbjRXLjybfzlAqrgYtQ0CgwaX79nYSuJuJ S46v0WonBZ5W+aNdAUyeB1gkA5/sCzLwZItpXd8NwcjWaB+Fia+8 X-Google-Smtp-Source: AGHT+IFHssVnIsuRtflrMUnmonDOpNMTsU28VnY3e7vVVJcpvOBurpk0sydP4Cx4Ik3eP3kEc+Ijgw== X-Received: by 2002:a05:690c:67c8:b0:6e3:323f:d8fb with SMTP id 00721157ae682-6eaddd994d5mr929977b3.14.1731007043403; Thu, 07 Nov 2024 11:17:23 -0800 (PST) Received: from localhost (fwdproxy-nha-114.fbsv.net. [2a03:2880:25ff:72::face:b00c]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6eace8efa7esm4148957b3.40.2024.11.07.11.17.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2024 11:17:23 -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 v3 1/6] mm: add AS_WRITEBACK_MAY_BLOCK mapping flag Date: Thu, 7 Nov 2024 11:16:12 -0800 Message-ID: <20241107191618.2011146-2-joannelkoong@gmail.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241107191618.2011146-1-joannelkoong@gmail.com> References: <20241107191618.2011146-1-joannelkoong@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: BC9DE4002A X-Stat-Signature: yrkcp3mrfyud8dbks3fj4ogfi9ye3mae X-Rspam-User: X-HE-Tag: 1731007016-666529 X-HE-Meta: U2FsdGVkX18D2YtcjtYBANqJNvva5/fV+j0ixm8L2m/I6irc8+HHvRKRAL8Ob+HxtjwziVuJpJXhf7Fxk1oVUgEKfQSm+Tvt3tThBrqSgChyRXzNiA7f1VZrGZf1J9Ae8cFilJQ5ntWm6+YSNsz2T3Y/jkKFNGwQjtHAHIxEhClbe0YUJ0Ib9gmqVUOt9avmsAJ0i4PRMAW34D8+SU+SdiYCL3ewvo8MzTHsqxysWujgwDhVrRV3zROdMMCK5dLm9wjld4MvjNU2eNY22JeAFcQ7xSv5BIRChdctDancyRqEQfaF2mCx2Kl7FJqXGVMuEdLnTP3QmwXICa6UwbhYMXANCv6YqC0TLEtlwh5dQ+mruJLw18jUtBLUZS/AG3FJKPjIJ1jTTwzF8frIjLk2otUAvH2gEHQrbXdZp+yrLqWA/JLWxBWG1CTPE9jfngA/bltM2QssdvU1lGDzgkUZnPKmblXKqgvlcte8CR9o3W6JzwY5mh1a33aXfIIrEPA4MNqzWlCFtj2LBeKlqw6MuPD55VeWzGuF3NrZPn2geMTEl4VciYj+3GFTf+2A+JosX2/x51PxTpC6mbnDJ8mLjA5Q3R+n/8Xj98vaYQtRbXJjLFJ+kRfAHjc55foawqPMPc57zBO6CZ7auzjk5gM0nNynirr+y/73Nrwx09sy9OAyjTKezdes5dMtFKT+SwhxF3eZXmlu6AJjfdfVMOl+oittcK0bLStVtzyqHIjqjgd1zmpuc+0hSHBqDSO7Nuys9AgBNOH4MpJ1EmqHwhit/lqnwthCKpZWOb6nd0RGf1Lf08p5Q+6c6Ll84xBk3t68C7jnctUaB3izV5YLTcNO+B/LNH4f56yfQZIeCDKzB1IkA5SF/lCFpXJKh867xynQaL1rP75YkEuHL1cNDMwR07+//+cJYp8snw7a4JLwJVHuq8gcVRs/tuLQVzwaLksbBAmO6oamew2B5dDGcKe vZVxM29T HcTP3feCvZnemF/xzdzHHGlY/NEKu5IsDDpaNp8WyB9vUQPPGPhac18OBilpItvswvLvAOuJ1D9aLvEl4iZ945402/rhGr+1jQbRd9MMihdeh9ERRS9WKijI0ULGXLEY4ydBQJWAqVid8pB3HrV7O91z4kk0oGzAJ9nW6/46/EK6B0zy/Jl97F8wTvkRXLt/ABwhz7PfuIV1l52toK941G2KkunU4IfdbvHfmXyFSZ5PPkDXZMyVU1SSCstEsvQ2Su20k/XdWsulfQH5J7/FIKauv8KStVxebmHLGRJR4XUiauqvNtKZ+LhVyJWUgMr4F/i/gkczv+C+12RZkczyxanA1G1xVMMZ2na/K+zP4d5DCGA76ZYpTbeO7bGgQUYkw1MN7LXHK/OZ9F0GuhSZILWrbRw== 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 19:16: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: 13866968 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 2E019D5D685 for ; Thu, 7 Nov 2024 19:17:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 456936B0085; Thu, 7 Nov 2024 14:17:28 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3C4096B0089; Thu, 7 Nov 2024 14:17:28 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1E76B6B008A; Thu, 7 Nov 2024 14:17:28 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id EF7356B0085 for ; Thu, 7 Nov 2024 14:17:27 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 948EC40AE0 for ; Thu, 7 Nov 2024 19:17:27 +0000 (UTC) X-FDA: 82760256684.30.314D185 Received: from mail-yb1-f180.google.com (mail-yb1-f180.google.com [209.85.219.180]) by imf09.hostedemail.com (Postfix) with ESMTP id C8843140002 for ; Thu, 7 Nov 2024 19:17:00 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=KIkqEy35; spf=pass (imf09.hostedemail.com: domain of joannelkoong@gmail.com designates 209.85.219.180 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=1731006820; 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=AU33l8eGsGFt3mrUg215J/PHva5xUvd6aUVSLGKe4nIgDm+czTSpWo45jiMf0Kr/Ls47SU MXuExAEZ2ynBAqkGS+dM5Q6QS2awPCtQMQS2rj0ENkRCWGNs6ZfSsbdLnAvg5rDblqpTlL 1TUcRlkyomkwCEFrBO75q4qVZZlbaSo= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=KIkqEy35; spf=pass (imf09.hostedemail.com: domain of joannelkoong@gmail.com designates 209.85.219.180 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=1731006820; a=rsa-sha256; cv=none; b=AM+Mi88HCe1w0hPbQDaVS8tJY1PrPtoggsEJlV8JCermEX0rLb/iA4noLqNDOIF4COPPUX ctZyCR2VADpDW1rajPv/6HnFVRfsvZfCzk/IBtrU9WxzxhZjCTTvBkcXq864BYoSm23jkX MlzWubm/DDTZFzRm3RfzY501JvtJeZ4= Received: by mail-yb1-f180.google.com with SMTP id 3f1490d57ef6-e28fea0f5b8so1287749276.1 for ; Thu, 07 Nov 2024 11:17:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731007045; x=1731611845; 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=KIkqEy356JYLLvq133g0nG9wYFFazEb+DavGnsw7S/+CWqhircTo7TdNsA6Y627mFt JU829umfICw1s1LXe6O8WGGoIyzok+UlCEjO7SDuLK32x6/vy35VPbMtEndacjRl0FYP 3T6fIAUJPSKZNUV6Y86sfhFvGwuxZqWKb5GFT1NSLg7qKO6gY/zRuoUynNsiF4L20Q10 XFYxnXUFQWb0WbmmD3VIucRTNLyytQhuyRovTCR++VeS9cFKtzvIJu1wLVcq0WlZTPCA M+tZ1nYQHRw/9fXKt8nDWcw7MZQRK2Y+kn9yZFaiydxKNM6mj8WEheXzxY+abv6AHDWt WUVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731007045; x=1731611845; 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=gZRevV263dS4FTEbNLNME1eMjnB5bonn7tjD0s6p7AE3eN875BxYA2GO0BYlLlPPDI +njTSKXV+HeHHoM/i9rSj6faX3RZfyyryrVuqLln4DF4x23WClx9RQNk7rnL7p1XIZwO Xv+nWEqj6gd6nC2YatqZlaUFU3WU/885I5RMAP00ybeIVi8XZu65z+369DkTh7GDdMeu tdT0QtAQQRGBqzWFBTwQu+wZXPO6DVlTPjdpaoXhkR7xxUFiDQ314FV2RPd7kfMJILMQ yKh3btK8cpcuZMoLEB54Sl+aFpMd1zKWU1049A76KRerhBQX80A0uFBNm8UDnB9T54Lx S/1Q== X-Forwarded-Encrypted: i=1; AJvYcCXhKPTbKIXOBF6k6dGCTDi2unnq4PORalnBzeOQZ4j0DnhvUN7mu4JvF8x+VYlCyJDn6IrX9iSCfQ==@kvack.org X-Gm-Message-State: AOJu0YyW5FWsylRnRIZ5LNnmFKhHbcxM/bg+fYRe/hWKPtTHsy+CbCYU oV8h67+7PmhbEfkMPTAnnipjcwOnKAufi+lqQPLxTdd4jJ1+YZ/R X-Google-Smtp-Source: AGHT+IH7Um593vs1SsckKVS39lYFZVnOlvrS2bG7U8disolXAeCbKEgSktqlpWFYBAXGxiiFp/wc6A== X-Received: by 2002:a05:690c:c96:b0:6ea:85ee:b5d4 with SMTP id 00721157ae682-6eaddd86d12mr1008527b3.6.1731007044813; Thu, 07 Nov 2024 11:17:24 -0800 (PST) Received: from localhost (fwdproxy-nha-112.fbsv.net. [2a03:2880:25ff:70::face:b00c]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6eaceb65d6csm4034397b3.72.2024.11.07.11.17.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2024 11:17:24 -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 v3 2/6] mm: skip reclaiming folios in legacy memcg writeback contexts that may block Date: Thu, 7 Nov 2024 11:16:13 -0800 Message-ID: <20241107191618.2011146-3-joannelkoong@gmail.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241107191618.2011146-1-joannelkoong@gmail.com> References: <20241107191618.2011146-1-joannelkoong@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: C8843140002 X-Stat-Signature: c1e5k87bbx5chsn6k8kifbdwtzwpqh64 X-Rspam-User: X-HE-Tag: 1731007020-525002 X-HE-Meta: U2FsdGVkX18UIwgr7MpvbzA9yQtAZDuxxgpD0SvN5wjJIXYaVYr8EptqazvEuLtbmc0lOHnyeKseLAkv+Ewenx3RcINa8zHD5a+ZZj+qsqftMTbQ4dAPoVaFVeAC/xlivvq9ovkjGR2AMYsDLAHb78KB2PnVr1hMEphIRz9FpYCxnX69AOQsp5vtGoWEyUI+WQMHpQChAiezowWCFahTnqTxnNruOZtxlD2nd9fRozGzo/DUcDs9ouJX2L97TL3FAgtCW639RrlbfUmPNNF7gD/OY1bFC/SZx82qJ+I9Fi1aVSrc4PhjSqvSZhG3VQmobAlDXWpLDScnSiZy3VMA2QQhH3beeqTdI0aFKWubAOAoRSclew0EAC4O/SH+tAcBUcIhoDDvpKWeTgsYRYjeCNXzS41Dn/QFDEZe8BW+MLdsk7EoD6tFL36Cz6jQ5Js0SJHF0MDt9RnHKgah5LP05FgrYHRnDmVYInYPm6ZGN3kOlsmYh/DrD7c0Bnps5PBjp1YPLdW154Psil81CfP85dX3AIqmkIkM3/tcqfnrkE+ThL56Ea0AnbFHHbGdqa2DP9h3+UmNGYkFrbi7VFLDxoW/9u3vtX/V7O7+TUO7nOUuCv4hCxfGnAV8SYVrSAoByynpQDGyZ/jG9LZVW0V2jaiTLJJcWFkY2jG/cHIWADIKVoQRwHUhre6zqrmljVWyYApBQ8FLC+YpE96Msrskmh/fu6FkC8DhZjE0Ybr6iYDxg0TREDvUKmdvMNU/H46HUK169ftcL104o/PnseUAOEwyUYwBZoE8RXq3g+nxr3/uREtYoYZ7XiXqLK4kkseRQn/Y/i849M/hOusYiDOw2hAkNh3pHNQYUr7AtMMU+U0b0MsyF90tlBw0Wqb/O4WNsT3IBP9KRVoZDpbxN+Ocfbu9txBiHSSQk8L9TysrWag0LSl8/HpgQ3HUxmKxPDbfFek5uKJJn1su61elOHI vvTH27OS d8cWX585uckfM2oOLVwfa05pE11oz/0K6VwVpp5I0Y0DXGq4iFOm4UUdtLU6tQFJcuUZ8yPQkt5jJReOFAbSfbv3dmQjIqjNIdNP0gVd6tR40Fucq8X3bDZNZr9L4SLHW1iBGnx6dIEh0kQZhjgXWXZF4YlOFOCXDGNchgcMsbtpVoyrkRlGv7WF8CbPB7vDA4Ynok6eQ8AMjxjMhvrtSal16RGS3KrBTcCs8jw1X+L1iIP67Ur/pZLy63llm9pyh0ixpoPGXkJLNfnqxlqiFovyz9Ha0LX4COEMrnmoUcJYUtRIRBuj1W4LDknoPF0G8O2V11G662ubmZAkHiHS7DkjM5zH0CSYhKDm6EVZocdSq6Ow= 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 19:16: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: 13866970 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 0160CD5D683 for ; Thu, 7 Nov 2024 19:17:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0189B6B008C; Thu, 7 Nov 2024 14:17:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E8CBF6B0098; Thu, 7 Nov 2024 14:17:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AE4B96B0092; Thu, 7 Nov 2024 14:17:30 -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 7CD496B008C for ; Thu, 7 Nov 2024 14:17:30 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 15C5FAC33E for ; Thu, 7 Nov 2024 19:17:30 +0000 (UTC) X-FDA: 82760256768.30.51FC89C Received: from mail-yw1-f174.google.com (mail-yw1-f174.google.com [209.85.128.174]) by imf05.hostedemail.com (Postfix) with ESMTP id 733F110002C for ; Thu, 7 Nov 2024 19:16:20 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=aApxmt5F; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf05.hostedemail.com: domain of joannelkoong@gmail.com designates 209.85.128.174 as permitted sender) smtp.mailfrom=joannelkoong@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731006988; a=rsa-sha256; cv=none; b=mI/rXuLknSfCRnRBRsfFpdxClsUWtf9pHCyLPd0RKvfgPc2wNFtJEXpPmBrO5aaxOhRvdI iUNO7Lqx9ueFWoUu/8PzuwV/3S1/rNKm6et/sBwmcFyGz3RdA0zUtQ9MDeXkVW5sISHNso +aqG8oENONAckuMHj+QKNRs/NTav/3Q= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=aApxmt5F; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf05.hostedemail.com: domain of joannelkoong@gmail.com designates 209.85.128.174 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=1731006988; 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=wMQBNrMFU+gnDAgt2L9LnWK0ofPOF28/qSr3DGki4frrjNi8azDRt22JTJ5dc+0TgRqmCd QhUDrDn437HmtUWq/ygRXoE6m1sOk9Bo/onnYZHkYj+lUVjDW+Sw+66jzMLXXVoW4jCvIQ 0rt/k7N5IMv/kCff1a77CnWXThJQI3E= Received: by mail-yw1-f174.google.com with SMTP id 00721157ae682-6e330b7752cso17759677b3.1 for ; Thu, 07 Nov 2024 11:17:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731007047; x=1731611847; 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=aApxmt5FXtn4v5HlccMRGP1nS9eV803kvP2SS25GaPWUKPl2Z3nuOnMCaAMD2uTOQ8 3bBf60FNAehlFof/PrvQ8JOJakzg/+nwpT5NN3A/qUi/02VMilCxkFMw/LbkIRGRoaoi 1WyjRxQTmHyBXDaxZhCDrX8vCgYGWnV/5ZTMkLp9fGMvRju/PT85xh0qhhjvjxegHkTL MNcFqjE2nbVs1rj8CbxzTdBl3OzpH19it4U031EWvcyiwpp3EK0ipVPpEi7koWXkgsZH KrfaN6+OiRa2VpaeNw5N083JvmOygQ2alA4m010qnMZHcYsW28ZYtsB3ILSU1JLpcdZF SnWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731007047; x=1731611847; 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=u2ffFtBYuRsM/42wIOHkSdaLLCeCJEfmM2jwVF7AKpfB2AZf4JYVU5fSV2cfIN8c8H nIDVS6smDKdjBuLTXJ63J7ygw5dLPGppucmu2jxhlmlTdtBdSG6aDWVVTqHZnqk9ro2I 3YbG+SVRyxW1qDtMEPsASg+3W96UY9GcAOwtUSmX+Qh+PdjwJyh4me2d60qfoz4mMnFo JNoGWsbXMkVa4g1twnjurwN1ASfMRA7sIyQZO5ZIegwrA2lgZD2tQK77FthH9VNUHYUd +U+pdqBNqWwnmkV1TAIjLKt7tjj1yAS5KiyRUeZz48S9fvSNOGCkhNhd/05fraHagsgD GUnw== X-Forwarded-Encrypted: i=1; AJvYcCXctKKauNaccIHz6h8TSfikQZx/7NmBTaVipAy950k5Zn+oDvizH73BIOZlz18vtgAZrvPHx9SRSQ==@kvack.org X-Gm-Message-State: AOJu0YxwmJH4ikkb3+E92pI84cwFTqolLI67qX8VDnkdXghG+5B+2jHk i5rq0pWzcgmBnAEUPoU0dK0xshPhWhWPnL94bc/OK0MuYt5VHJ4w X-Google-Smtp-Source: AGHT+IFHLm1F5SVScEjFhzgLOTEvXi9gcszMcWHxca2UHg5tDjnu1mcg7x+SjCqmp89fKz//T9WiJA== X-Received: by 2002:a05:690c:4804:b0:6e9:e097:e9d2 with SMTP id 00721157ae682-6eadc0daba4mr7442157b3.6.1731007045976; Thu, 07 Nov 2024 11:17:25 -0800 (PST) Received: from localhost (fwdproxy-nha-008.fbsv.net. [2a03:2880:25ff:8::face:b00c]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6eaceb65f80sm3999417b3.91.2024.11.07.11.17.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2024 11:17:25 -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 v3 3/6] fs/writeback: in wait_sb_inodes(), skip wait for AS_WRITEBACK_MAY_BLOCK mappings Date: Thu, 7 Nov 2024 11:16:14 -0800 Message-ID: <20241107191618.2011146-4-joannelkoong@gmail.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241107191618.2011146-1-joannelkoong@gmail.com> References: <20241107191618.2011146-1-joannelkoong@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 733F110002C X-Rspamd-Server: rspam11 X-Stat-Signature: ohz57c7b3pyyyzn44uwf83a59s11aqrh X-HE-Tag: 1731006980-471792 X-HE-Meta: U2FsdGVkX18HlTCTC9PcgMBDn0h/rp5JrNtMRAf0uYTtxWwC13YyVO/cVohSMpsTDIaot10BL4rG4YdGqkNt9lGBZI4cvgM157WbAPQN8HYIeG3FjwY7mDPLedMas+yNAGdxRfPWVHbFDC1M63ZGKbFz1bfpZSgrFnvwj6/UosYFoHM+IkLD8Wk66ALbYLAVc9dCCR/ISnl+C5BpsErusUy77LXGLwXSgcd2rrRBwoQFpEPj9A2hefSm9MT/HW+MY41PRk70xKZmvBcdPVarIDxFp/nSeU+R83YxWe83+3apN8sgaEzm6dSCh8Xq9UQN5WQx0W5Kd6ePeSOAwAdoY2aP5+z78FL2BZd79E5go6xSmuH5tUEtSe1LEiKC8dKj9ueWanwSVrdpOY8djL+AyOLYiPEAI5HVQHGJOtssrOeB0IcXATCFC4w/3m0pLzueD367yUw8GGEUG+JykTpUF64iPN8FZDagPufM/pWlWizXejFh1AS6DmEc69+ZLqtImiVuduT5xbdMvnGi8C9e9l/s8q8O9gE3qgu3k6e4QacndVksKv0mJv3dUVXN2s9eamdfJ/P020YI2/c/FyxnMWAfye2uuVeWVM4kYJ0wSFafOtMeVn9Iewh0mASeHTtgqLPL0vvuXl1Yni8iE288h4o6FabUXZHrukghqjlrKm2uH3Uz1P3FW06JBD7fijOE3iFXOurPYAOaqz2ITftS4BkqhyR6eOvMp88wWh2D1v7cNLmeRBUhKJseKR83B37wTYJQohXOn7vz3ekiQAeuyOhnx3g5wbNMllHMR6uHuWyI75FJ3z6TCJN0bQVEIDWaSsTWLcpeKmFq3qzryluUh5byb2yTnUe9UXo07OZrNJYKrEZMNtuYL7wr6AKA8JGHykzBrbQ82t6zFWDlHzMZV9Gd1LD9vBLKNMl7dhHy2x5uFTLuoqgwXt9vtJd2bYgA6xskcxt4vmrUcLTTHjV RG0TFUBE AqlqnFTAKJR760EWat8wbaOgnoL7bq8Ucc/0YhSjahRTZSIGbcevaacHSBE+wSnFVjtCVdMiEhuccUtD2bj30AEkIlGC+N5Dpmo2xXi7ldVkv5cOvanyj4pviaU+BK1ppfIvVodPiB9OQnx1scIcFlzQiCLvPjAISGSzhnho9m1ti3VWhXKatuKDmVRHKRTFClZUwdJneg4I8BdoXLhb5WwXnmPdEW+EVFxyGttoodYC6SR7OGTjNnsrWKT36/Mz+JTca/NLY7Ieerv3rVuLIsVpNbW/7XipA4TVx9jZPIXrjffO68ZKyr+60HFFqjQdk7N0R+Sz77frsnhhi2B7/rJV6qGArTniWlAckx6zmmQ1TnzogjRTdaEh/N+3fmciMQZsvWQCNf8dgNIB0zUEgoRaijA== 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: 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 19:16:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joanne Koong X-Patchwork-Id: 13866969 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 8A1B8D5D683 for ; Thu, 7 Nov 2024 19:17:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CE5286B008A; Thu, 7 Nov 2024 14:17:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C43CA6B008C; Thu, 7 Nov 2024 14:17:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9FA976B0096; Thu, 7 Nov 2024 14:17:30 -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 7BBF86B008A for ; Thu, 7 Nov 2024 14:17:30 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id F16441C622D for ; Thu, 7 Nov 2024 19:17:29 +0000 (UTC) X-FDA: 82760256012.07.80BEF11 Received: from mail-yb1-f176.google.com (mail-yb1-f176.google.com [209.85.219.176]) by imf01.hostedemail.com (Postfix) with ESMTP id 166D640007 for ; Thu, 7 Nov 2024 19:16:59 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=AVWdyhcU; spf=pass (imf01.hostedemail.com: domain of joannelkoong@gmail.com designates 209.85.219.176 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=1731006861; 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=tpY7G7HZyMQ925tY2MOVzqmuZ6ZpdF5L2I8ZthD5Qt2laA/GgyXpHW8nnKCh5cPbOLdyDd swBoL0FziAzzmMN9wv23obNoBlA04OgAfB28pavThgs5GDyRTEzFSyoufax8dB/qqrcn5N HEzdQYzBEHUqYUHJ85j6EGv6qeLq3oU= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=AVWdyhcU; spf=pass (imf01.hostedemail.com: domain of joannelkoong@gmail.com designates 209.85.219.176 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=1731006861; a=rsa-sha256; cv=none; b=KJ4NoxZH0p7bclTjVXrDR3+gUPt0wtWfwVO8Pim9yb/NFZV2+HFxxr8V1wurGyc3Xb7RN/ VRiXxtKq4cjYypHSDNGe66aTZoA2twV3JG1npkzdo/HLqQkeDhIUj8eW576l/bTRk1nYSS xmDwAHoGeBtZCRcWm46+zH3Ns+0ng+I= Received: by mail-yb1-f176.google.com with SMTP id 3f1490d57ef6-e2e444e355fso1999902276.1 for ; Thu, 07 Nov 2024 11:17:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731007047; x=1731611847; 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=AVWdyhcUBlMWdgXq+nzaeC/XweaM6YF7NzpThKkZE/Lqyxjeag/pF/3MApSlIODobT HLeMDwEvgZlh9WPPAKMjNI5Locvx7+mQYMNORPXx3/ZiSRAo0/u9x7OzNfTwsL+Bt4ng FpwvPNRwS1Lm8E+qj0pP3YyThMtKo1SSBT6CKiBFk3uQLwA0q5dlmPWqGIyLcxiV1nUD q7lpV/TYxINLenW62ueRGvRdZlFPj9lSeWwrAlL1L+VUm9EjZVkWjIMoFZVOj/hPsQfU rgIw1G3s3HO9g9GydkOXGv3ZIAD2MmxkLRzdhmw6+tMgko5tQkW0XaAYmI21y1Bh6hSE 60ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731007047; x=1731611847; 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=uW6MpJe1sw+Jp2f2pzaTgykXJ33aQjswPtRXF/Erl1U0Q/7x69mXM0NC6oD9d2KoNm OvFoREPacCB/AVYSRiVQzogd7DQahRMrCL1JC6Nw2vyoZpO5f6DhUyA+u6tjvITnm4HB FGioaCfdYMl6P+kEtwj1X5qSSlVJ6OJSmzbojEdBubfDnhXwLvPESikajL9f81ZU4W4V xvXkHQ48mrFg88BaPjboFi4TudV2+jHx2tvXzrNSgArx2OBdwEstLpAdlmY6wxQESfpt 7hQzBgd2dUTMShCjDhMJTKsQKshfjPQllpXiHNBsVcyzqqCZylBEb2Rf5feELAuPOD5M d+WQ== X-Forwarded-Encrypted: i=1; AJvYcCX9LThpNDEOsElskZbnp8J6BH/GNCmH7PpfbKN9ynogJZOrQpg4i4iqkjVO/oQv373vrdaFBAKewA==@kvack.org X-Gm-Message-State: AOJu0YyNLIUBGNE057qg2P59VJi4cy2FPF6Q70gZpzcI9Tc/it4XGyw4 Kk69NkWiYGqXuDeAqhjI5pqp2E+2LFxWzQ9yDsWqFLRxubWRDlSk1s7Hfw== X-Google-Smtp-Source: AGHT+IEkpWzZirMthRa1KIppd+IoM2B6ZQrYg1W/sBImn83Wn53xX/nxsQKorMCpOKraG2RVdoxyYg== X-Received: by 2002:a05:690c:fd2:b0:6db:e1e0:bf6a with SMTP id 00721157ae682-6eadc0a0bbemr9007977b3.7.1731007047220; Thu, 07 Nov 2024 11:17:27 -0800 (PST) Received: from localhost (fwdproxy-nha-008.fbsv.net. [2a03:2880:25ff:8::face:b00c]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6eace8f1c74sm4067837b3.31.2024.11.07.11.17.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2024 11:17:27 -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 v3 4/6] mm/memory-hotplug: add finite retries in offline_pages() if migration fails Date: Thu, 7 Nov 2024 11:16:15 -0800 Message-ID: <20241107191618.2011146-5-joannelkoong@gmail.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241107191618.2011146-1-joannelkoong@gmail.com> References: <20241107191618.2011146-1-joannelkoong@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 166D640007 X-Stat-Signature: 6x36hmjdpwfrn1fzugxnn9jocfojtpci X-Rspam-User: X-HE-Tag: 1731007019-448224 X-HE-Meta: U2FsdGVkX1/AHDXDpoXnqDN3cTwA2m6lp8BcT8ysBmFo9lJWVwTw1zNT9U0P/L+3VKV2jceTgbQVrnZnP1bREQXwjCJ3Mn5IeOSWtIqrQ/cQ4qQOpkFzyzkrSaLhyLh+21DEkG5mNMfaLGz7AKN1NVeKYKFUN9GRvDWqGdH5SOQW7BwwNGxJKmo9jxRNM3RZn6w2dwJdBMH4mwCMwfEcRTwq5G6uqE0trAkO+bZy9/6K1h/jdynnZbuKuHii0gZol9du7ui2leNBanSbxUrbk/idNyJT7CeW1zCFIR7zCVujrQOtO7Gd6g/rRggmWHTyDhZrwjYl+GQgvgpjwRf29mnhV5bmgtwCFc2inTLVIFz5XCxExNHpnIaqUknfw+q02eFITDAQgpfrIJzZN31SlMf7O0kN9TpjwoeIkOUOS6HJ14QHmfmm2CmOp+sScfgxrZMa91USxmZeDMtR6BhsUpxkuHJXkzsok5aDgRE2xPx2b5VfijCxbu/LM+h5MT/Q7VPo6bEHA4x2PG9EZA/M0RITj1ga01QywmuV3HsUhxpzY/DW2V7YdKAbd2VrlpZq5WM/Y2LMXPjUzZ8IRxlGI8vJridQnl38MfmbYsNAeud2KIPOzvTbWEH7VxB/9AGsyI2P8k7JdoTyRZ/LhA8fhdFWOFUCStDKOUaKd3/hJNhaHiyJ0yMNC1XJM0VqysLJHGC5hI9qMqIUGbW9yth09hfkiEByNgcvNN3OPrYWs1vi+toggtjdos2dta96EkCJ+0ZCGgkzBvKySknrPaMZgJrqYe+2Ph9LsU1+fmpwDRbTPDise4t3a1iw4OeJ+0bhv+3npL30vInCvpxmZ59Qi+uTgtJauJ39ZHRuW/OrGCYh637AmzbroKKNFMvir1oDo4xUluJpkx9ezptVWn0aoNgnOMdZF40lEnjZlHKuyYPFK8ms8dY3Y2lxotBMoxVChp0yo5EGPhihIubHdwM UhaLFMaW BGjkZHRsvO7fIvS4B1R84pTtE759eDa736XcrsAwgole47ok/T+88iOcndSnYCXV7xdyMM5BaXuLKEm3ri4BbXQj9z7AqIYrNtsH7YeZA73XKSssnJ2eqk+ewq4vhnTB160pB/ewn/gVB+Cdhbpcm7aMgzmeK/p3NgroTH+W1DVqrclLbWuhWJ5LVYbiWegoHkXHrj1drY7z/c9ZzCW/06KPvcyyFYxZovc7oANhkPFmfgPuCFTnPI37RdxmghvTdSslgydSJZrjfFH+p4PzyfKmqaUqpsUjAb8owkT8JOTpa5Dq0tdVlHfDo0HTR5rjeAEJVj//nuK0B1yAHhm3vJs/0E3XQk96eCtNkRIIN/l+LKbK4dvxYVK6PqLhj4JgoPh7xKA4VXk6wfKMeOPofjvypsg== 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 19:16:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joanne Koong X-Patchwork-Id: 13866971 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 82D2AD5D683 for ; Thu, 7 Nov 2024 19:17:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DCB596B0092; Thu, 7 Nov 2024 14:17:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D7D766B0096; Thu, 7 Nov 2024 14:17:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BF6166B0098; Thu, 7 Nov 2024 14:17:31 -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 978F56B0092 for ; Thu, 7 Nov 2024 14:17:31 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 5035F140A11 for ; Thu, 7 Nov 2024 19:17:31 +0000 (UTC) X-FDA: 82760256894.12.B830F31 Received: from mail-yb1-f171.google.com (mail-yb1-f171.google.com [209.85.219.171]) by imf14.hostedemail.com (Postfix) with ESMTP id 8224710001C for ; Thu, 7 Nov 2024 19:16:49 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=G+7YNR0+; spf=pass (imf14.hostedemail.com: domain of joannelkoong@gmail.com designates 209.85.219.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=1731006823; 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=MG5iK0PNmiW0m0S9ll/rGoWwCANqU1Z5kMah1Ao73Dk=; b=q9ZmnuI9qA8MxffWybF7oiM04SyGcAycSA9ItjMoPzd9oUFLzvYqJIjqSy4rF/4FUlOdXs x30YM+CDydHG4HuESQlh3sJQfnG6QjTzf5UIBO+3RZZ8E3Q0vPzbhiKBukP6hfW7srwozt +u0zo9kN6aecm8V6fzG9eIhdkuFBSAo= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=G+7YNR0+; spf=pass (imf14.hostedemail.com: domain of joannelkoong@gmail.com designates 209.85.219.171 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=1731006823; a=rsa-sha256; cv=none; b=s203Kpz2+bsPpT3dHOA7L4wohgDmRdfy/iTXxApdBi1BSkW7boDDJoObTgAOnyNPEebDPm UWkafod3WIw7C0GLcjtqNOwccBIXCrp68FwHJL0gxqKqpwWgq2H0LQ+YzCVIUrf1Jdv3rX 5BTD03g9KU7hmRWh29ei/5o6FGlJvok= Received: by mail-yb1-f171.google.com with SMTP id 3f1490d57ef6-e2974743675so1312381276.1 for ; Thu, 07 Nov 2024 11:17:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731007048; x=1731611848; 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=MG5iK0PNmiW0m0S9ll/rGoWwCANqU1Z5kMah1Ao73Dk=; b=G+7YNR0+c6xmgbnZH9dQL2T7rh+4NlbybmjHIv+VXUBO0AJWJBSk/U8cjmyonJ/iOn WQMIxr8Nwaax3gSWof6bmZxjap2MmgDZwBkXP7PJuvGFqCpTnCVsRRUOn5RtETXDoson m71wkN1kxAhhftPFeXN0DlcKueXjbgvuPBUIFhgEydKjIYqteASvGGRDh+F0uzpQAjSI cpQyJXR/HTu86QlCw9WCs+0UDbawDBw2gSIOAb3fyRmRBWBVSgxy2faO1fCVZH8vJbiL ZfH8t2+GLfAaKKhYsXQaSFXwJD/mUhuDbdwPyTfW8qSfyKSd2WvinXzcoY1Vw5JzG11A yOOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731007048; x=1731611848; 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=MG5iK0PNmiW0m0S9ll/rGoWwCANqU1Z5kMah1Ao73Dk=; b=qgkHWrgArvmbI6+mLEnCmru/aIRHtBekXiqB93RuekckBJ3eCI4jYg8qC6k4hYPCT7 JXb4BW+HFNEBjj81yLZdYpi3GNtUwhH7KKm5iZcaP3dxsNJaBTP9sc9nqENYsoB8tq/h NyFwAwwiST1IuAuBrweO+io112ejRsQe0mRStwDki3Ec3tTl2MiCKCAuKIIFb2N2MogB bZCIKNyz8KQSSm9hD3uApnkzyAOdm/JDUhwqxhGCu4MLtvXUp7cj3DSYtJn73Ij4CHZr xZygnkAh7s4KlJx8LXuKblWuTNIB61h3RxO1KqSToDLF5NfSVA3mrfdk9H5W1iRH7fKk +ZRw== X-Forwarded-Encrypted: i=1; AJvYcCXtaJ3H8+5U1IlgorEOl8xKerL3JvlRSkBEcWUWrPGzmwIBBWBNw1OfIyPz7oEQaFAOZyc1yNFMzA==@kvack.org X-Gm-Message-State: AOJu0YwU+nXABu6hPJf5G/DLC5LA5zfbcAszMUGAMuRQIVhdIKcW7JuI UruIu5oG9zUnhuWpMml+oDHvXjsL63b0JsHNvCaSieHpMfJRk8bW X-Google-Smtp-Source: AGHT+IFcIlGFpbiDZRAZoKdELB0Ba2H780dbAB8bPQD2I1i+kogNUBV3Xb4R3gifXVFOfN141DB5Gg== X-Received: by 2002:a05:6902:f84:b0:e29:948:69cc with SMTP id 3f1490d57ef6-e337f844097mr171360276.6.1731007048555; Thu, 07 Nov 2024 11:17:28 -0800 (PST) Received: from localhost (fwdproxy-nha-013.fbsv.net. [2a03:2880:25ff:d::face:b00c]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e336f1ba8e5sm386281276.43.2024.11.07.11.17.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2024 11:17:28 -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 v3 5/6] mm/migrate: fail MIGRATE_SYNC for folios under writeback with AS_WRITEBACK_MAY_BLOCK mappings Date: Thu, 7 Nov 2024 11:16:16 -0800 Message-ID: <20241107191618.2011146-6-joannelkoong@gmail.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241107191618.2011146-1-joannelkoong@gmail.com> References: <20241107191618.2011146-1-joannelkoong@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 8224710001C X-Stat-Signature: 7onfh4e6gkumr9a47orgr3qm8j9c5pxm X-Rspam-User: X-HE-Tag: 1731007009-285813 X-HE-Meta: U2FsdGVkX19hQSQnSx/RROKcDGA3aSBPTi5+RsT0DCpFTYk/1uSrEg+nxM7I+cmuCzIJ8p8vuCUKWY1dYZNn5k3TbwF5IhJgHPrFcjslWjJVvtG3iiXy+HYy9cekeDb57GtvOlvmUeS3YLrNy9mHCYFKNPghrbsV2s8tIMY1s86f41IyyVZ95ZCnz2lXi0k/g+ikLLLIhM69SKGL9aS3G4APRDB05SoGbMifwArUxMajcuz7NWIkHoVSHlGFr6DZsHEew/SF2w3W1DtmKg3Z6RKC550iYALEwI7X9USlEVOe3SIaEHu+VR7JT+JM9z0EjlTSs5yderKEI0GKMcuUjezZcHSuPGC6FBTr0EHxDxTfAjKUBUof+To1qJQEUlXveJvmcvQTMa4di7CMSp179FBl9EQBfabCeXPb/3FfyHl6/O9aZIKMFApF7ZCMlqXrbwlkVuuWTinspg6mN1WTPyMtyjrcc6nUDVTmQYHLuu7lFSKygf2WfMxeV6Q0qzuHgi76sbI4vDzWna6V0PK+eQd3xPr7e3uS9MGvSO43Ha+qQS/1M811LKuSTHukRt4jWi6FBmnOCPpyuPdzjO7YXzROmltxybExV8jGE5xRzqPFPxxXGi9N2SWg5IvkP1RdD1/XXv1LUFdTYDaRhsd23YG/KM7ewXAm+SLxW8X2FJO1tBUg1a6nTRNIWjPPYxKcAy/euooqc/V/qVoNNivDVGRNvIQx4tOQruPqCI4kOBD6AuF4xUr8O18W1PfPg4YVnDNUpvEzee+CXpLZJT3azBJIGARRQ0qnOhFtrwODpirqinxBOZ1k9Mt8I2XskLUeu4rWDM3u85EV2k6JOWrBQGI8+CtpuxVmnXLj3Fz3VgxjgdV0NERhkUIS5ToGKy4mPHXwkv1yv/aoCRk9EuV9CATF6fCpw1b8vZhPZt0mTBVLmldxSDEypKTMLaoas1tqXoy1nrAUE7uz7XcZkgv m8Jy6EvZ 0ObH/ExGnuqmqeJJQAdJp00QnaFsjyNi6MLxNj9d05acWu6NuSvNCpOhiS0Hn1YwUaMD6LSjRmQbRtAhvF0Aws6NeMDWh/DWYqQqpWNbgobAQC8EfzCG+9S7sD9pLi252+CnqTCKPH+hdmYVyN6o0W8csPAJEAl+xcZA8FL90mnGkw7I1c/WjUISY8WYm4WllUidv1jnGa1LwkZokaQIxZXtgKk4GxMoQ2UgIFNBnvMtr0Nyj9svwjwhlf6LUTeCtTlNAQx+Xi92lHHQzRtWJAK97cWtUFPxSc5l461NCkMafj+D9wOA+Vp1OxzOMbMpPj59mhYfOVUIfxm813a2SDwO9ZELLz635u2x0XfdbeaWbryKrVj0VWwO9q3N2Je7NOLAcEdTS/Ip4lq/X1ItGNCo+frTR5Zpnbg13nZ+SKVtygws= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000364, 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 folios with mappings that have the AS_WRITEBACK_MAY_BLOCK flag set on it, fail MIGRATE_SYNC mode migration with -EBUSY if the folio is currently under writeback. 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 cannot wait on writeback. 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 19:16:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joanne Koong X-Patchwork-Id: 13866973 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 978FAD5D685 for ; Thu, 7 Nov 2024 19:17:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 261A98D0001; Thu, 7 Nov 2024 14:17:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1BFCC6B009E; Thu, 7 Nov 2024 14:17:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EB42E8D0001; Thu, 7 Nov 2024 14:17:48 -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 BF53B6B009D for ; Thu, 7 Nov 2024 14:17:48 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 76254C0B69 for ; Thu, 7 Nov 2024 19:17:48 +0000 (UTC) X-FDA: 82760257524.23.30356DA Received: from mail-yb1-f169.google.com (mail-yb1-f169.google.com [209.85.219.169]) by imf23.hostedemail.com (Postfix) with ESMTP id 1F5D414001D for ; Thu, 7 Nov 2024 19:17:22 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=QF264Wq3; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf23.hostedemail.com: domain of joannelkoong@gmail.com designates 209.85.219.169 as permitted sender) smtp.mailfrom=joannelkoong@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731006896; a=rsa-sha256; cv=none; b=cGxHqpER4RwcHl8THUHIAO9rawB12rYdTBWrSDP5KWLmKVemKAC/V5K0kqiLvyPNzQ3HcK r8ptBwK2ogH2tMt5qhGj185ALcZOqk4GpklcYGLc9tYWQQyuDVBtODWXJw5S6ArELYhbaI ZVwIdrScj36ZzCuTaxIs/OUZ1Xy1QW0= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=QF264Wq3; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf23.hostedemail.com: domain of joannelkoong@gmail.com designates 209.85.219.169 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=1731006896; 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=hd9fc4hPdhRnHAoBq+4wrx1ZclXDUb5MhN21NFaoAlY=; b=h+ULe+DHevLwTOBfzVaJ+km3Z87k+l6TyUs/lI+3FzzB2NDnxUkR9gGWk14EnN6+fThqEX HA6sSrSnhXl3dDnJsxCKCUgj15X3sToVQA1hYA0NHozjucJ1VXAX25316Tvg0WM5KSuKR5 68RTIvB2YIkETTseokIubkKQ8Vhnb2Y= Received: by mail-yb1-f169.google.com with SMTP id 3f1490d57ef6-e29218d34f8so1066228276.1 for ; Thu, 07 Nov 2024 11:17:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731007065; x=1731611865; 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=hd9fc4hPdhRnHAoBq+4wrx1ZclXDUb5MhN21NFaoAlY=; b=QF264Wq3t26NjOYCqKw6tbQnjVEuDilVWIhL0fB9R547Q1RhbcwFjgww6Ys89gkj2i kk8x0wO5UldXK4I7jn+lFcayS0GIvCvXnmQFY+xO8MnwFxw4R0gpF0dzQpF/Aaw1gd7r LHZM2C2Mdg/v18C4WJ0gE94SVFUbYK2HoE4cSbGdyDpjusT9OWo7hPNKlMFlYnOtoBtQ Vwr+87f3rJ9xYPNwHsCaGEyau3+E6vlV3WQ2TeslHB8ac7kLCNKeFKnDnjmaSbC8GrxX uTHHulKxC7puWKA2uvzIMfwc/IroBi7E+XROhjFjbXjrNhdg9BXLGEbKkCrBSsttFSps riEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731007065; x=1731611865; 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=hd9fc4hPdhRnHAoBq+4wrx1ZclXDUb5MhN21NFaoAlY=; b=XWqEmOlKJ9EskL+avu8ybaONOx4AZ2mJIvza6t6TnqP+LKFU757QUhOnolQPWhlrXJ ZT7D2AgsAQcLc5E+CzI5DsfK1hQzyQzwy6fhB2zDgR3UmDDWC4xQ32OppvRQ2kLQ5jHo GFCpB9k/qakolB0yPBrB3CyVKrPQp4uksuOTx9twK1J7+ASs9xjDd5lFdptqZbDPsbx4 qmP+ruXsdPXbQFiu63iuxExVHVBdYAywjVhMRyHW+CurIHB+ahDY64O3smjSqGTT3f2z ysSfLYOwBV8s/DRs0EqBdzTcjEVQe3I2pLHIRRRVpRMGUcZGK8wgUcB3VdW9855Zmx+w zNIQ== X-Forwarded-Encrypted: i=1; AJvYcCVf5NvzHQoqZ1fqII1ht7VjahPB1A+xdxJ1DD5fb4veZBvEPitdjTZKmvUpmBdmmua6jo9kw6lX1Q==@kvack.org X-Gm-Message-State: AOJu0YwCB6FmC82pLmGpg7TRODmXCKg8WFECtTTGmMNKs3j8Vx4CcGKZ R05iCEiD37MFPADHtNfCkJungpRN8t4oUnVJq3DfJq/SIwa+ZCI3 X-Google-Smtp-Source: AGHT+IHzjE4uzit81wgdKLtfKGm9hnxE8pRULcxB9Svk1Y0PsQoAtIjJZ+dkV7yShUmT0GvecKkkSw== X-Received: by 2002:a05:6902:1081:b0:e2b:dc72:3bdf with SMTP id 3f1490d57ef6-e337e11f26emr729748276.10.1731007065407; Thu, 07 Nov 2024 11:17:45 -0800 (PST) Received: from localhost (fwdproxy-nha-012.fbsv.net. [2a03:2880:25ff:c::face:b00c]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e336f1baaefsm369181276.44.2024.11.07.11.17.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2024 11:17:45 -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 v3 6/6] fuse: remove tmp folio for writebacks and internal rb tree Date: Thu, 7 Nov 2024 11:16:18 -0800 Message-ID: <20241107191618.2011146-8-joannelkoong@gmail.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241107191618.2011146-1-joannelkoong@gmail.com> References: <20241107191618.2011146-1-joannelkoong@gmail.com> MIME-Version: 1.0 X-Stat-Signature: y85f1n3zab8cfzeftgjbn3ifsa1cukkp X-Rspamd-Queue-Id: 1F5D414001D X-Rspamd-Server: rspam08 X-Rspam-User: X-HE-Tag: 1731007042-206425 X-HE-Meta: U2FsdGVkX18T7uI5ncv9gHPBZlIzvqfGNH5r16IHOhVLkGX8jVxvuIcBYG9T8jitngR175n55kj1x2D4NYw56lFKt/wS/ZozFl2rFz43CV+js8TG/3b4KL2L2QUZpcedYnMoXtjjKQACWUXM/htgKy3gziTKTTdrDtu4k8GAcNaQnQ0CxU/m3xl+nyngAH76BRarHKI5tNlAc4whytyGzRO8k+YlvIoqF8eQ9werfIicu/bRRK8oAUXVlRU8UMC/8a4hgh+5TFFJT3BjRHcFmRB90g3XHTCPNWtD1vpwW+rf/4m4iwZ+sO76Reo22uzvsEv+mxTe+9S6isM/Y35H5pBO3F7JUwc5rvJjuidWpxRekpyv/wKBTOLZ9NQtOHYvPC17AyErQce6GdFRf6VzRiPMJaFV/Y5GYVgQ2nTlyeqwuYhuQuToHiYn0izovcdowrGEOgazZGLzJsPb/KIhA/WIz4OQb0JKpmfeuw+EPULacMj9UAR+tcRnR35IwigGZzEsI7HxLsXS42vBNhpAUuopGpyhcqOjy95+GE36jlxSthBlxxedaBFwYTyr/2Unvf/I81tb8oxAE/5wcoyXjyX/JqUum/uw6xPm8tMI7XjaSmcMmJF3hee0yu0lCN9U5L4tHcBZk+ABJeMuumdz873V+IBxunJ8Y06YgsWneFrds4ZwtVLN8bVImF6deQsv1cA+K/OFoLhwmg5hg9Ib6omtEGbD0a4I7jCHzmyrloXoLHXYcgOddUzbsXIaLPvL27NIkYGg++GQJWsdqqVLNhiBbkXbeTyWKUpJFzmKVW7LI6c4Yds42wtUBB2gjwtwVZ4Rl0ZdTeRPFzvMtMP0/YxMmtaAbtRiD1sttl2zOGsPqqCPl7X/RgnC4XH2Ti0bbeEURmAhQ+mEETGc8GpddVw4oTRtq0GrwHBegEJNUm3VHwAYBGZiQfm3PR8Fz8ix3m+C6YmpYNSdG2fTtGb FTgpPReA HbJuhH+wctMepE39jI2q2P2uFMVpVDYmSaWouid0reLweqDep/G4T2xCYyFwVew10AkoiaPvGaq7w0zeS/nkdQWprqw776+kl/6iZaLvA5YboF/nwEnaI9CG91Hfp5fFg05XgZuejPByFPw0Pl5KFDMTn84SDpddP18J5HHK9H73KBeuoVv4Tub5A9iUn6LmAb3UbNvwqexDIVhuL2hBOhD0TTnCGPYDn0FxIeHqK52O581SMjKohht4kJsaD9CIOriF+SQOLvXmeQdo0uDqt67djfD7sDoPudoYMk3ErOk0SKofi+7sG11aNc4n8cuPDkrOWROw2Axf1ZuXc45aTNGhsq8e/FgO7n95iJx0VpQqlznQ= 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, 30 insertions(+), 309 deletions(-) diff --git a/fs/fuse/file.c b/fs/fuse/file.c index 88d0946b5bc9..a2e91fdd8521 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); @@ -1006,13 +928,14 @@ static void fuse_readahead(struct readahead_control *rac) 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)); + wait_event(fi->page_waitq, + !filemap_range_has_writeback(rac->mapping, first, last)); max_pages = min_t(unsigned int, fc->max_pages, fc->max_read / PAGE_SIZE); @@ -1172,7 +1095,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 +1545,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 +1747,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 +1763,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 +1786,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 +1822,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 +1851,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 +1870,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 +1956,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 +2002,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 +2018,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 +2038,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 +2072,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 +2085,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 +2094,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 +2113,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 +2127,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 +2170,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 +2178,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 +2202,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 +2266,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 +2314,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 +3132,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 +3145,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);