* [PATCH] ubifs: Move update of cnt in get_znodes_to_commit
@ 2024-10-17 18:41 Waqar Hameed
2024-10-18 1:24 ` Zhihao Cheng
0 siblings, 1 reply; 3+ messages in thread
From: Waqar Hameed @ 2024-10-17 18:41 UTC (permalink / raw)
To: Richard Weinberger, Zhihao Cheng; +Cc: kernel, linux-mtd, linux-kernel
There is no need to update `cnt` for the first dirty node just before
the loop, and then again update it at the end of each iteration for the
next dirty nodes. Just update `cnt` at the beginning of each iteration
instead. This way, the first iteration will count the first dirty node
and any subsequent iterations will count the next dirty nodes.
Signed-off-by: Waqar Hameed <waqar.hameed@axis.com>
---
fs/ubifs/tnc_commit.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/fs/ubifs/tnc_commit.c b/fs/ubifs/tnc_commit.c
index a55e04822d16..d42f7829389c 100644
--- a/fs/ubifs/tnc_commit.c
+++ b/fs/ubifs/tnc_commit.c
@@ -650,8 +650,8 @@ static int get_znodes_to_commit(struct ubifs_info *c)
dbg_cmt("no znodes to commit");
return 0;
}
- cnt += 1;
while (1) {
+ cnt += 1;
ubifs_assert(c, !ubifs_zn_cow(znode));
__set_bit(COW_ZNODE, &znode->flags);
znode->alt = 0;
@@ -664,7 +664,6 @@ static int get_znodes_to_commit(struct ubifs_info *c)
znode->ciip = znode->iip;
znode->cnext = cnext;
znode = cnext;
- cnt += 1;
}
dbg_cmt("committing %d znodes", cnt);
ubifs_assert(c, cnt == atomic_long_read(&c->dirty_zn_cnt));
--
2.39.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] ubifs: Move update of cnt in get_znodes_to_commit
2024-10-17 18:41 [PATCH] ubifs: Move update of cnt in get_znodes_to_commit Waqar Hameed
@ 2024-10-18 1:24 ` Zhihao Cheng
2024-11-06 16:48 ` Waqar Hameed
0 siblings, 1 reply; 3+ messages in thread
From: Zhihao Cheng @ 2024-10-18 1:24 UTC (permalink / raw)
To: Waqar Hameed, Richard Weinberger; +Cc: kernel, linux-mtd, linux-kernel
在 2024/10/18 2:41, Waqar Hameed 写道:
> There is no need to update `cnt` for the first dirty node just before
> the loop, and then again update it at the end of each iteration for the
> next dirty nodes. Just update `cnt` at the beginning of each iteration
> instead. This way, the first iteration will count the first dirty node
> and any subsequent iterations will count the next dirty nodes.
Well, from my own view, I prefer the orignal style because it looks more
readable.
c->cnext = find_first_dirty(c->zroot.znode);
znode = c->enext = c->cnext;
cnt += 1; // We get the first one.
while (1) {
cnext = find_next_dirty(znode);
znode = cnext;
cnt += 1; // We get another one.
}
After applying this patch, the intention of 'cnt' updating is not so
obviously. However, it does reduce the duplicated codes. I will add an
acked-by to let Richard determine whether or not apply this patch.
Acked-by: Zhihao Cheng <chengzhihao1@huawei.com>
>
> Signed-off-by: Waqar Hameed <waqar.hameed@axis.com>
> ---
> fs/ubifs/tnc_commit.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/fs/ubifs/tnc_commit.c b/fs/ubifs/tnc_commit.c
> index a55e04822d16..d42f7829389c 100644
> --- a/fs/ubifs/tnc_commit.c
> +++ b/fs/ubifs/tnc_commit.c
> @@ -650,8 +650,8 @@ static int get_znodes_to_commit(struct ubifs_info *c)
> dbg_cmt("no znodes to commit");
> return 0;
> }
> - cnt += 1;
> while (1) {
> + cnt += 1;
> ubifs_assert(c, !ubifs_zn_cow(znode));
> __set_bit(COW_ZNODE, &znode->flags);
> znode->alt = 0;
> @@ -664,7 +664,6 @@ static int get_znodes_to_commit(struct ubifs_info *c)
> znode->ciip = znode->iip;
> znode->cnext = cnext;
> znode = cnext;
> - cnt += 1;
> }
> dbg_cmt("committing %d znodes", cnt);
> ubifs_assert(c, cnt == atomic_long_read(&c->dirty_zn_cnt));
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] ubifs: Move update of cnt in get_znodes_to_commit
2024-10-18 1:24 ` Zhihao Cheng
@ 2024-11-06 16:48 ` Waqar Hameed
0 siblings, 0 replies; 3+ messages in thread
From: Waqar Hameed @ 2024-11-06 16:48 UTC (permalink / raw)
To: Zhihao Cheng; +Cc: Richard Weinberger, kernel, linux-mtd, linux-kernel
On Fri, Oct 18, 2024 at 09:24 +0800 Zhihao Cheng <chengzhihao1@huawei.com> wrote:
> 在 2024/10/18 2:41, Waqar Hameed 写道:
>> There is no need to update `cnt` for the first dirty node just before
>> the loop, and then again update it at the end of each iteration for the
>> next dirty nodes. Just update `cnt` at the beginning of each iteration
>> instead. This way, the first iteration will count the first dirty node
>> and any subsequent iterations will count the next dirty nodes.
>
> Well, from my own view, I prefer the orignal style because it looks more
> readable.
> c->cnext = find_first_dirty(c->zroot.znode);
> znode = c->enext = c->cnext;
> cnt += 1; // We get the first one.
>
> while (1) {
> cnext = find_next_dirty(znode);
> znode = cnext;
> cnt += 1; // We get another one.
> }
>
> After applying this patch, the intention of 'cnt' updating is not so obviously.
> However, it does reduce the duplicated codes. I will add an acked-by to let
> Richard determine whether or not apply this patch.
>
> Acked-by: Zhihao Cheng <chengzhihao1@huawei.com>
[...]
As you say, there could be a subjective argument here (for me it was the
other way around :) ), and that the objective argument is that it
reduces the code.
I'm fine with either! Richard, you decide then.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-11-06 16:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-17 18:41 [PATCH] ubifs: Move update of cnt in get_znodes_to_commit Waqar Hameed
2024-10-18 1:24 ` Zhihao Cheng
2024-11-06 16:48 ` Waqar Hameed
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).