From nobody Fri Oct 18 08:32:25 2024 Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E25211BC49 for ; Fri, 26 Jul 2024 03:06:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721963162; cv=none; b=gihD6LTFLSIN9EzQieuccWdyrlLLQ7Uq3PRy5uM7G/3/lc63YmCPoXB+6jHD4p75eOF3Vi+7POGbypYz6zoRJkB7m6Hx2SzoTxHTJpuPnfAhzRgBR/bro3Hdbl57Mo7GMxZDijuxEUqoD5E7djxO3WrYhiya0TMrjpCj+eA9iNk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721963162; c=relaxed/simple; bh=quLpI2hmZVxke/lF3DDSHfy9b3cBQdbVSjdUv4HeYak=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=CbVdCpmbb2Yx+YCPzB2JgXrrEZtPaUzQXZJN3Erx8FlMWcUpq3JhsktkW4EkhZO7XzhBx1LarTf4NK3FGBTSLdseni3l9PAD1vZ/pBILuMu76mMSt0l8kg8r28pAEsSgMQrLdbOO/pkIjlFq++NSn5N9iuOUx/UpCQ8JPYja79U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=shopee.com; spf=pass smtp.mailfrom=shopee.com; dkim=pass (2048-bit key) header.d=shopee.com header.i=@shopee.com header.b=DBkVFoXt; arc=none smtp.client-ip=209.85.215.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=shopee.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=shopee.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=shopee.com header.i=@shopee.com header.b="DBkVFoXt" Received: by mail-pg1-f173.google.com with SMTP id 41be03b00d2f7-7a10b293432so391319a12.0 for ; Thu, 25 Jul 2024 20:06:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shopee.com; s=shopee.com; t=1721963160; x=1722567960; darn=vger.kernel.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=0zMy6Wm4Xr4VmqiEPea2U7nMauV7O2Gfn+WgAXgyr3U=; b=DBkVFoXtO/VB9UG5jdoMKGqAjuOKUt2cJ1yjOm8MyeeHTTTCea7IjrEy9eePHng4ut K/a+Z4qCiVJPn+7FLwmScnrpbbVphPrSN0PrbcorQcvRz1QxMmbBC2OSAY8R8iOil1tz GFFxnbhw+VNaV0mVjr0lxUW1aamLvmEMF+B5hMkvKGw2ktO5kZOctwxP+DOIBD2m9XGL a7GMwgTpV17b1iGVyR7yWTYS8Wc8Q+5po7K1P8lbWnNw8eQ8HV5A/hDLw7pF7qBfF9yY HHXzMfgvCHI7D79apr4fDKbdMRqNy5KAMsqSIHoRL6CLT5F6pM6Id9mdRjZDa+tea4AE S4NQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721963160; x=1722567960; 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=0zMy6Wm4Xr4VmqiEPea2U7nMauV7O2Gfn+WgAXgyr3U=; b=rMRT3kKQFRvW5/IugsCBW0EXiQaaVk5gjqZFTWWJD7yq9L8/ixhAuL9fXlrzOwaPvD nwSUnBCR5ygdVtPkUNmKIDPcnRaFgCjRxY4yp1NTXbyd+saT+IrkIyj6jaMXLrFZjCEj onG+9zed0GYP9ytOhT1zGulIGXIq7v5FUfM5faI7JrigxgCxNOFwQZAvYzGzDvx/G1GM uXgMv8pKU0tD+ebIzfVxn8QTdkyTqq2RvYI4j4XPrxHslZWtqk3O/izqEMUIKrEyyao+ B51S851pgS1ryfOzTXXjoZwU5Bcjl1VckmOVWCKNcSRcDEiI0G+MTx2AO0TAhDtKld0y 4cTg== X-Forwarded-Encrypted: i=1; AJvYcCWzcoCqNtdgqTtRpoORNSySHCMaJrJMfaeO2S4dX5k+28fsDwa11t6Coymhme/vR0VIkRWnvop89BA66tF2yZAPoVdOFYUnxvA/dZ/B X-Gm-Message-State: AOJu0YxUQYlTRJ2ADYC/gP2iL7wkTlqmqfpZuHQPpJDW7lSbnZjEVFt1 jHBuEWJ57yTuB2VCkBAv0G9t9YQW4bnnI0SuWKg0YwTnSP/tWVs6zIumq0N7NS8= X-Google-Smtp-Source: AGHT+IGpxwOy71N55NwgyOQ41ABsR85yT6e4HPAsYRwjPO/GciuqVW0ATMQ5DpYETORlfje8rrIXtg== X-Received: by 2002:a17:90b:4b09:b0:2c4:ee14:94a2 with SMTP id 98e67ed59e1d1-2cf238ccadamr5760863a91.27.1721963160112; Thu, 25 Jul 2024 20:06:00 -0700 (PDT) Received: from localhost.localdomain ([143.92.64.20]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2cd8f7692f0sm3435117a91.1.2024.07.25.20.05.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jul 2024 20:05:59 -0700 (PDT) From: Haifeng Xu To: jack@suse.cz Cc: axboe@kernel.dk, brauner@kernel.org, tj@kernel.org, viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Haifeng Xu Subject: [PATCH v2] fs: don't flush in-flight wb switches for superblocks without cgroup writeback Date: Fri, 26 Jul 2024 11:05:25 +0800 Message-Id: <20240726030525.180330-1-haifeng.xu@shopee.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240725084232.bj7apjqqowae575c@quack3> References: <20240725084232.bj7apjqqowae575c@quack3> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When deactivating any type of superblock, it had to wait for the in-flight wb switches to be completed. wb switches are executed in inode_switch_wbs_w= ork_fn() which needs to acquire the wb_switch_rwsem and races against sync_inodes_sb= (). If there are too much dirty data in the superblock, the waiting time may in= crease significantly. For superblocks without cgroup writeback such as tmpfs, they have nothing to do with the wb swithes, so the flushing can be avoided. Signed-off-by: Haifeng Xu Suggested-by: Jan Kara Reviewed-by: Jan Kara --- Changes since v1: - do the check in cgroup_writeback_umount(). - check the capabilities of bdi. --- fs/fs-writeback.c | 6 +++++- fs/super.c | 2 +- include/linux/writeback.h | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c index 92a5b8283528..09facd4356d9 100644 --- a/fs/fs-writeback.c +++ b/fs/fs-writeback.c @@ -1140,8 +1140,12 @@ int cgroup_writeback_by_id(u64 bdi_id, int memcg_id, * rare occurrences and synchronize_rcu() can take a while, perform * flushing iff wb switches are in flight. */ -void cgroup_writeback_umount(void) +void cgroup_writeback_umount(struct super_block *sb) { + + if (!(sb->s_bdi->capabilities & BDI_CAP_WRITEBACK)) + return; + /* * SB_ACTIVE should be reliably cleared before checking * isw_nr_in_flight, see generic_shutdown_super(). diff --git a/fs/super.c b/fs/super.c index 095ba793e10c..acc16450da0e 100644 --- a/fs/super.c +++ b/fs/super.c @@ -621,7 +621,7 @@ void generic_shutdown_super(struct super_block *sb) sync_filesystem(sb); sb->s_flags &=3D ~SB_ACTIVE; =20 - cgroup_writeback_umount(); + cgroup_writeback_umount(sb); =20 /* Evict all inodes with zero refcount. */ evict_inodes(sb); diff --git a/include/linux/writeback.h b/include/linux/writeback.h index 112d806ddbe4..d78d3dce4ede 100644 --- a/include/linux/writeback.h +++ b/include/linux/writeback.h @@ -217,7 +217,7 @@ void wbc_account_cgroup_owner(struct writeback_control = *wbc, struct page *page, size_t bytes); int cgroup_writeback_by_id(u64 bdi_id, int memcg_id, enum wb_reason reason, struct wb_completion *done); -void cgroup_writeback_umount(void); +void cgroup_writeback_umount(struct super_block *sb); bool cleanup_offline_cgwb(struct bdi_writeback *wb); =20 /** @@ -324,7 +324,7 @@ static inline void wbc_account_cgroup_owner(struct writ= eback_control *wbc, { } =20 -static inline void cgroup_writeback_umount(void) +static inline void cgroup_writeback_umount(struct super_block *sb) { } =20 --=20 2.25.1