stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 5.4] ext4: fix lazy initialization next schedule time computation in more granular unit
@ 2021-11-15 21:42 Shaoying Xu
  2021-11-17 18:02 ` Greg KH
  0 siblings, 1 reply; 4+ messages in thread
From: Shaoying Xu @ 2021-11-15 21:42 UTC (permalink / raw)
  To: stable; +Cc: shaoyi

commit 39fec6889d15a658c3a3ebb06fd69d3584ddffd3 upstream.

Ext4 file system has default lazy inode table initialization setup once
it is mounted. However, it has issue on computing the next schedule time
that makes the timeout same amount in jiffies but different real time in
secs if with various HZ values. Therefore, fix by measuring the current
time in a more granular unit nanoseconds and make the next schedule time
independent of the HZ value.

Fixes: bfff68738f1c ("ext4: add support for lazy inode table initialization")
Signed-off-by: Shaoying Xu <shaoyi@amazon.com>
Cc: stable@vger.kernel.org
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Link: https://lore.kernel.org/r/20210902164412.9994-2-shaoyi@amazon.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
---
Member lr_sbi was removed from the struct ext4_li_request since kernel 5.9 
so the way to access s_li_wait_mult was also changed. To adapt to the old 
kernel versions, adjust the upstream fix by following the old ext4_li_request
strucutre. 

 fs/ext4/super.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 1211ae203fac..f68dfef5939f 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -3071,8 +3071,8 @@ static int ext4_run_li_request(struct ext4_li_request *elr)
 	struct ext4_group_desc *gdp = NULL;
 	ext4_group_t group, ngroups;
 	struct super_block *sb;
-	unsigned long timeout = 0;
 	int ret = 0;
+	u64 start_time;
 
 	sb = elr->lr_super;
 	ngroups = EXT4_SB(sb)->s_groups_count;
@@ -3092,13 +3092,12 @@ static int ext4_run_li_request(struct ext4_li_request *elr)
 		ret = 1;
 
 	if (!ret) {
-		timeout = jiffies;
+		start_time = ktime_get_real_ns();
 		ret = ext4_init_inode_table(sb, group,
 					    elr->lr_timeout ? 0 : 1);
 		if (elr->lr_timeout == 0) {
-			timeout = (jiffies - timeout) *
-				  elr->lr_sbi->s_li_wait_mult;
-			elr->lr_timeout = timeout;
+			elr->lr_timeout = nsecs_to_jiffies((ktime_get_real_ns() - start_time) *
+				  elr->lr_sbi->s_li_wait_mult);
 		}
 		elr->lr_next_sched = jiffies + elr->lr_timeout;
 		elr->lr_next_group = group + 1;
-- 
2.16.6


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 5.4] ext4: fix lazy initialization next schedule time computation in more granular unit
  2021-11-15 21:42 [PATCH 5.4] ext4: fix lazy initialization next schedule time computation in more granular unit Shaoying Xu
@ 2021-11-17 18:02 ` Greg KH
  2021-11-17 23:20   ` Shaoying Xu
  0 siblings, 1 reply; 4+ messages in thread
From: Greg KH @ 2021-11-17 18:02 UTC (permalink / raw)
  To: Shaoying Xu; +Cc: stable

On Mon, Nov 15, 2021 at 09:42:12PM +0000, Shaoying Xu wrote:
> commit 39fec6889d15a658c3a3ebb06fd69d3584ddffd3 upstream.
> 
> Ext4 file system has default lazy inode table initialization setup once
> it is mounted. However, it has issue on computing the next schedule time
> that makes the timeout same amount in jiffies but different real time in
> secs if with various HZ values. Therefore, fix by measuring the current
> time in a more granular unit nanoseconds and make the next schedule time
> independent of the HZ value.
> 
> Fixes: bfff68738f1c ("ext4: add support for lazy inode table initialization")
> Signed-off-by: Shaoying Xu <shaoyi@amazon.com>
> Cc: stable@vger.kernel.org
> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
> Link: https://lore.kernel.org/r/20210902164412.9994-2-shaoyi@amazon.com
> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
> ---
> Member lr_sbi was removed from the struct ext4_li_request since kernel 5.9 
> so the way to access s_li_wait_mult was also changed. To adapt to the old 
> kernel versions, adjust the upstream fix by following the old ext4_li_request
> strucutre. 

Now queued up, thanks.

greg k-h

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 5.4] ext4: fix lazy initialization next schedule time computation in more granular unit
  2021-11-17 18:02 ` Greg KH
@ 2021-11-17 23:20   ` Shaoying Xu
  2021-11-18  8:20     ` Greg KH
  0 siblings, 1 reply; 4+ messages in thread
From: Shaoying Xu @ 2021-11-17 23:20 UTC (permalink / raw)
  To: Greg KH; +Cc: stable

Thank you! Can the patch also be added to kernel 4.19 and 4.14 please? 

On Wed, Nov 17, 2021 at 07:02:26PM +0100, Greg KH wrote:
> CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.
> 
> 
> 
> On Mon, Nov 15, 2021 at 09:42:12PM +0000, Shaoying Xu wrote:
> > commit 39fec6889d15a658c3a3ebb06fd69d3584ddffd3 upstream.
> >
> > Ext4 file system has default lazy inode table initialization setup once
> > it is mounted. However, it has issue on computing the next schedule time
> > that makes the timeout same amount in jiffies but different real time in
> > secs if with various HZ values. Therefore, fix by measuring the current
> > time in a more granular unit nanoseconds and make the next schedule time
> > independent of the HZ value.
> >
> > Fixes: bfff68738f1c ("ext4: add support for lazy inode table initialization")
> > Signed-off-by: Shaoying Xu <shaoyi@amazon.com>
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Theodore Ts'o <tytso@mit.edu>
> > Link: https://lore.kernel.org/r/20210902164412.9994-2-shaoyi@amazon.com
> > Signed-off-by: Theodore Ts'o <tytso@mit.edu>
> > ---
> > Member lr_sbi was removed from the struct ext4_li_request since kernel 5.9
> > so the way to access s_li_wait_mult was also changed. To adapt to the old
> > kernel versions, adjust the upstream fix by following the old ext4_li_request
> > strucutre.
> 
> Now queued up, thanks.
> 
> greg k-h

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 5.4] ext4: fix lazy initialization next schedule time computation in more granular unit
  2021-11-17 23:20   ` Shaoying Xu
@ 2021-11-18  8:20     ` Greg KH
  0 siblings, 0 replies; 4+ messages in thread
From: Greg KH @ 2021-11-18  8:20 UTC (permalink / raw)
  To: Shaoying Xu; +Cc: stable

On Wed, Nov 17, 2021 at 11:20:36PM +0000, Shaoying Xu wrote:
> Thank you! Can the patch also be added to kernel 4.19 and 4.14 please? 

Now queued up, thanks.

greg k-h

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-11-18  8:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-15 21:42 [PATCH 5.4] ext4: fix lazy initialization next schedule time computation in more granular unit Shaoying Xu
2021-11-17 18:02 ` Greg KH
2021-11-17 23:20   ` Shaoying Xu
2021-11-18  8:20     ` Greg KH

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).