From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailout1.samsung.com (mailout1.samsung.com [203.254.224.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 676593126AF for ; Tue, 14 Oct 2025 12:11:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.254.224.24 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760443904; cv=none; b=uovSijNTOv1sf1loZNNWmyS3MpSAbcFtJb7pLJytT6E391lfP1AYPQ/jprbYustrDCyS2k1XPzgPyNl7qoGNRWaFxBzQ9RH3Uvrs1ueAT/B5k8EkI5EDypcEt8SZPSf69toUBPYWQR3hhmINEwBQe7TdyhVEWxpASLoA/Yl8/z8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760443904; c=relaxed/simple; bh=mwJ7fVo6wH6GnrrZ6oCciTIhPSom8JD+XnpoNvDsnxM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=IFDsZr+K6LmmBRycD3BeLX5EtLaFIUCdCY+iu+JshSSZxTg9nyhxqDfC8efeDTHMAv0bQGZiBZpysLbTRSheB4qeQQlWQmCPd6T+22ezpJc4FudKizl2fq1Bs/RHynX3s8hOjvdJpACtLXWBw8oaACZIDLrLVqtXUH2zgoq3HZw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=IZEVWzpU; arc=none smtp.client-ip=203.254.224.24 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="IZEVWzpU" Received: from epcas5p4.samsung.com (unknown [182.195.41.42]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20251014121138epoutp01296176ef3092715e4e95726b445d1859~uWmYKEGu-1133811338epoutp01t for ; Tue, 14 Oct 2025 12:11:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20251014121138epoutp01296176ef3092715e4e95726b445d1859~uWmYKEGu-1133811338epoutp01t DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1760443898; bh=P26ywqsMnB1wfPCMRtpUS0xgTfcL9X0rkalZt4nakI0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IZEVWzpUM/VeejCxB/jGms73fEuWMwgHnd43yIQgt1GWnuFDZiPddMvQlfgmuselr P8CMZVovdo1GkWEFNVldpJQ8snOLCctSBP9XD24zoZGz9iz9Hp6oLEr1bJQ1M6v5Rr O61UQsByvXzJ7XsFA5175gAii6scO4d7O9zrDXY4= Received: from epsnrtp02.localdomain (unknown [182.195.42.154]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPS id 20251014121137epcas5p252ab21a6f213e2a3de40624cc4a06c89~uWmXXMLo33235432354epcas5p2t; Tue, 14 Oct 2025 12:11:37 +0000 (GMT) Received: from epcas5p2.samsung.com (unknown [182.195.38.95]) by epsnrtp02.localdomain (Postfix) with ESMTP id 4cmCkJ5szQz2SSKY; Tue, 14 Oct 2025 12:11:36 +0000 (GMT) Received: from epsmtip1.samsung.com (unknown [182.195.34.30]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPA id 20251014121135epcas5p2aa801677c0561db10291c51d669873e2~uWmVjz9X22441424414epcas5p2q; Tue, 14 Oct 2025 12:11:35 +0000 (GMT) Received: from localhost.localdomain (unknown [107.99.41.245]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20251014121131epsmtip1ababe9c4e8295da908008c77b52ba39e~uWmROln091256112561epsmtip1N; Tue, 14 Oct 2025 12:11:31 +0000 (GMT) From: Kundan Kumar To: jaegeuk@kernel.org, chao@kernel.org, viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.cz, miklos@szeredi.hu, agruenba@redhat.com, trondmy@kernel.org, anna@kernel.org, akpm@linux-foundation.org, willy@infradead.org, mcgrof@kernel.org, clm@meta.com, david@fromorbit.com, amir73il@gmail.com, axboe@kernel.dk, hch@lst.de, ritesh.list@gmail.com, djwong@kernel.org, dave@stgolabs.net, wangyufei@vivo.com Cc: linux-f2fs-devel@lists.sourceforge.net, linux-fsdevel@vger.kernel.org, gfs2@lists.linux.dev, linux-nfs@vger.kernel.org, linux-mm@kvack.org, gost.dev@samsung.com, kundan.kumar@samsung.com, anuj20.g@samsung.com, vishak.g@samsung.com, joshi.k@samsung.com Subject: [PATCH v2 16/16] writeback: added XFS support for matching writeback count to allocation group count Date: Tue, 14 Oct 2025 17:38:45 +0530 Message-Id: <20251014120845.2361-17-kundan.kumar@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20251014120845.2361-1-kundan.kumar@samsung.com> Precedence: bulk X-Mailing-List: gfs2@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CMS-MailID: 20251014121135epcas5p2aa801677c0561db10291c51d669873e2 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" CMS-TYPE: 105P cpgsPolicy: CPGSC10-542,Y X-CFilter-Loop: Reflected X-CMS-RootMailID: 20251014121135epcas5p2aa801677c0561db10291c51d669873e2 References: <20251014120845.2361-1-kundan.kumar@samsung.com> Implemented bdi_inc_writeback() to increase the writeback context count and called this function at XFS mount time to set the desired count. Signed-off-by: Kundan Kumar Signed-off-by: Anuj Gupta --- fs/xfs/xfs_super.c | 2 ++ include/linux/backing-dev.h | 1 + mm/backing-dev.c | 58 +++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c index b3ec9141d902..aa97b59f53c6 100644 --- a/fs/xfs/xfs_super.c +++ b/fs/xfs/xfs_super.c @@ -1783,6 +1783,8 @@ xfs_fs_fill_super( if (error) goto out_free_sb; + bdi_inc_writeback(sb->s_bdi, mp->m_sb.sb_agcount); + /* * V4 support is undergoing deprecation. * diff --git a/include/linux/backing-dev.h b/include/linux/backing-dev.h index 14f53183b8d1..89a465e1964f 100644 --- a/include/linux/backing-dev.h +++ b/include/linux/backing-dev.h @@ -40,6 +40,7 @@ void wb_start_background_writeback(struct bdi_writeback *wb); void wb_workfn(struct work_struct *work); void wb_wait_for_completion(struct wb_completion *done); +int bdi_inc_writeback(struct backing_dev_info *bdi, int nwriteback); extern spinlock_t bdi_lock; extern struct list_head bdi_list; diff --git a/mm/backing-dev.c b/mm/backing-dev.c index 5bfb9bf3ce52..e450b3a9b952 100644 --- a/mm/backing-dev.c +++ b/mm/backing-dev.c @@ -1219,6 +1219,64 @@ struct backing_dev_info *bdi_alloc(int node_id) } EXPORT_SYMBOL(bdi_alloc); +int bdi_inc_writeback(struct backing_dev_info *bdi, int nwritebacks) +{ + struct bdi_writeback_ctx **wb_ctx; + int ret = 0; + + if (nwritebacks <= bdi->nr_wb_ctx) + return ret; + + wb_ctx = kcalloc(nwritebacks, sizeof(struct bdi_writeback_ctx *), + GFP_KERNEL); + if (!wb_ctx) + return -ENOMEM; + + for (int i = 0; i < bdi->nr_wb_ctx; i++) + wb_ctx[i] = bdi->wb_ctx[i]; + + for (int i = bdi->nr_wb_ctx; i < nwritebacks; i++) { + wb_ctx[i] = (struct bdi_writeback_ctx *) + kzalloc(sizeof(struct bdi_writeback_ctx), GFP_KERNEL); + if (!wb_ctx[i]) { + pr_err("Failed to allocate %d", i); + while (--i >= bdi->nr_wb_ctx) + kfree(wb_ctx[i]); + kfree(wb_ctx); + return -ENOMEM; + } + INIT_LIST_HEAD(&wb_ctx[i]->wb_list); + init_waitqueue_head(&wb_ctx[i]->wb_waitq); + +#ifdef CONFIG_CGROUP_WRITEBACK + INIT_RADIX_TREE(&wb_ctx[i]->cgwb_tree, GFP_ATOMIC); + init_rwsem(&wb_ctx[i]->wb_switch_rwsem); +#endif + ret = wb_init(&wb_ctx[i]->wb, wb_ctx[i], bdi, GFP_KERNEL); + if (!ret) { +#ifdef CONFIG_CGROUP_WRITEBACK + wb_ctx[i]->wb.memcg_css = &root_mem_cgroup->css; + wb_ctx[i]->wb.blkcg_css = blkcg_root_css; +#endif + } else { + while (--i >= bdi->nr_wb_ctx) + kfree(wb_ctx[i]); + kfree(wb_ctx); + return ret; + } + cgwb_bdi_register(bdi, wb_ctx[i]); + set_bit(WB_registered, &wb_ctx[i]->wb.state); + } + + spin_lock_bh(&bdi_lock); + kfree(bdi->wb_ctx); + bdi->wb_ctx = wb_ctx; + bdi->nr_wb_ctx = nwritebacks; + spin_unlock_bh(&bdi_lock); + return 0; +} +EXPORT_SYMBOL(bdi_inc_writeback); + static struct rb_node **bdi_lookup_rb_node(u64 id, struct rb_node **parentp) { struct rb_node **p = &bdi_tree.rb_node; -- 2.25.1