From: Boris Burkov <boris@bur.io>
To: Qu Wenruo <wqu@suse.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 5/5] btrfs: qgroup: use qgroup_iterator facility to replace @tmp ulist of qgroup_update_refcnt()
Date: Wed, 30 Aug 2023 15:09:20 -0700 [thread overview]
Message-ID: <20230830220920.GC834639@zen> (raw)
In-Reply-To: <e6d30c5f77867f20ca19244e5c37881188855d6e.1693391268.git.wqu@suse.com>
On Wed, Aug 30, 2023 at 06:37:27PM +0800, Qu Wenruo wrote:
> For function qgroup_update_refcnt(), we use @tmp list to iterate all the
> involved qgroups of a subvolume.
>
> It's a perfect match for qgroup_iterator facility, as that @tmp ulist
> has a very limited lifespan (just inside the while() loop).
>
> By migrating to qgroup_iterator, we can get rid of the GFP_ATOMIC memory
> allocation and no more error handling needed.
>
> Signed-off-by: Qu Wenruo <wqu@suse.com>
> ---
> fs/btrfs/qgroup.c | 37 +++++++++++--------------------------
> 1 file changed, 11 insertions(+), 26 deletions(-)
>
> diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
> index 08f4fc622180..6fcf302744e2 100644
> --- a/fs/btrfs/qgroup.c
> +++ b/fs/btrfs/qgroup.c
> @@ -2463,13 +2463,11 @@ int btrfs_qgroup_trace_subtree(struct btrfs_trans_handle *trans,
> * Walk all of the roots that points to the bytenr and adjust their refcnts.
> */
> static int qgroup_update_refcnt(struct btrfs_fs_info *fs_info,
> - struct ulist *roots, struct ulist *tmp,
> - struct ulist *qgroups, u64 seq, int update_old)
> + struct ulist *roots, struct ulist *qgroups,
> + u64 seq, int update_old)
> {
> struct ulist_node *unode;
> struct ulist_iterator uiter;
> - struct ulist_node *tmp_unode;
> - struct ulist_iterator tmp_uiter;
> struct btrfs_qgroup *qg;
> int ret = 0;
>
> @@ -2477,40 +2475,35 @@ static int qgroup_update_refcnt(struct btrfs_fs_info *fs_info,
> return 0;
> ULIST_ITER_INIT(&uiter);
> while ((unode = ulist_next(roots, &uiter))) {
> + LIST_HEAD(tmp);
> +
> qg = find_qgroup_rb(fs_info, unode->val);
> if (!qg)
> continue;
>
> - ulist_reinit(tmp);
> ret = ulist_add(qgroups, qg->qgroupid, qgroup_to_aux(qg),
> GFP_ATOMIC);
> if (ret < 0)
> return ret;
> - ret = ulist_add(tmp, qg->qgroupid, qgroup_to_aux(qg), GFP_ATOMIC);
> - if (ret < 0)
> - return ret;
> - ULIST_ITER_INIT(&tmp_uiter);
> - while ((tmp_unode = ulist_next(tmp, &tmp_uiter))) {
> + qgroup_iterator_add(&tmp, qg);
> + list_for_each_entry(qg, &tmp, iterator) {
> struct btrfs_qgroup_list *glist;
>
> - qg = unode_aux_to_qgroup(tmp_unode);
> if (update_old)
> btrfs_qgroup_update_old_refcnt(qg, seq, 1);
> else
> btrfs_qgroup_update_new_refcnt(qg, seq, 1);
> +
> list_for_each_entry(glist, &qg->groups, next_group) {
> ret = ulist_add(qgroups, glist->group->qgroupid,
> qgroup_to_aux(glist->group),
> GFP_ATOMIC);
Thinking out loud, could we use the same trick and put another global
list on the qgroups to handle this one? Or some other "single global
allocation up to #qgroups" trick.
> if (ret < 0)
> return ret;
> - ret = ulist_add(tmp, glist->group->qgroupid,
> - qgroup_to_aux(glist->group),
> - GFP_ATOMIC);
> - if (ret < 0)
> - return ret;
> + qgroup_iterator_add(&tmp, glist->group);
> }
> }
> + qgroup_iterator_clean(&tmp);
> }
> return 0;
> }
> @@ -2675,7 +2668,6 @@ int btrfs_qgroup_account_extent(struct btrfs_trans_handle *trans, u64 bytenr,
> {
> struct btrfs_fs_info *fs_info = trans->fs_info;
> struct ulist *qgroups = NULL;
> - struct ulist *tmp = NULL;
> u64 seq;
> u64 nr_new_roots = 0;
> u64 nr_old_roots = 0;
> @@ -2714,12 +2706,6 @@ int btrfs_qgroup_account_extent(struct btrfs_trans_handle *trans, u64 bytenr,
> ret = -ENOMEM;
> goto out_free;
> }
> - tmp = ulist_alloc(GFP_NOFS);
> - if (!tmp) {
> - ret = -ENOMEM;
> - goto out_free;
> - }
> -
> mutex_lock(&fs_info->qgroup_rescan_lock);
> if (fs_info->qgroup_flags & BTRFS_QGROUP_STATUS_FLAG_RESCAN) {
> if (fs_info->qgroup_rescan_progress.objectid <= bytenr) {
> @@ -2734,13 +2720,13 @@ int btrfs_qgroup_account_extent(struct btrfs_trans_handle *trans, u64 bytenr,
> seq = fs_info->qgroup_seq;
>
> /* Update old refcnts using old_roots */
> - ret = qgroup_update_refcnt(fs_info, old_roots, tmp, qgroups, seq,
> + ret = qgroup_update_refcnt(fs_info, old_roots, qgroups, seq,
> UPDATE_OLD);
> if (ret < 0)
> goto out;
>
> /* Update new refcnts using new_roots */
> - ret = qgroup_update_refcnt(fs_info, new_roots, tmp, qgroups, seq,
> + ret = qgroup_update_refcnt(fs_info, new_roots, qgroups, seq,
> UPDATE_NEW);
> if (ret < 0)
> goto out;
> @@ -2755,7 +2741,6 @@ int btrfs_qgroup_account_extent(struct btrfs_trans_handle *trans, u64 bytenr,
> out:
> spin_unlock(&fs_info->qgroup_lock);
> out_free:
> - ulist_free(tmp);
> ulist_free(qgroups);
> ulist_free(old_roots);
> ulist_free(new_roots);
> --
> 2.41.0
>
next prev parent reply other threads:[~2023-08-30 22:13 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-30 10:37 [PATCH 0/5] btrfs: qgroup: reduce GFP_ATOMIC usage for ulist Qu Wenruo
2023-08-30 10:37 ` [PATCH 1/5] btrfs: qgroup: iterate qgroups without memory allocation for qgroup_reserve() Qu Wenruo
2023-08-30 21:58 ` Boris Burkov
2023-08-30 10:37 ` [PATCH 2/5] btrfs: qgroup: use qgroup_iterator facility for btrfs_qgroup_free_refroot() Qu Wenruo
2023-08-30 10:37 ` [PATCH 3/5] btrfs: qgroup: use qgroup_iterator facility for qgroup_convert_meta() Qu Wenruo
2023-08-30 10:37 ` [PATCH 4/5] btrfs: qgroup: use qgroup_iterator facility for __qgroup_excl_accounting() Qu Wenruo
2023-08-30 10:37 ` [PATCH 5/5] btrfs: qgroup: use qgroup_iterator facility to replace @tmp ulist of qgroup_update_refcnt() Qu Wenruo
2023-08-30 22:09 ` Boris Burkov [this message]
2023-08-30 22:55 ` Qu Wenruo
2023-09-05 13:07 ` David Sterba
2023-08-30 22:06 ` [PATCH 0/5] btrfs: qgroup: reduce GFP_ATOMIC usage for ulist Boris Burkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230830220920.GC834639@zen \
--to=boris@bur.io \
--cc=linux-btrfs@vger.kernel.org \
--cc=wqu@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.