ext4: Use schedule_timeout_interruptible() for waiting in lazyinit thread
PATCH v2 1/4 ext4: Use schedule_timeout_interruptible() for waiting in lazyinit thread
In order to make lazyinit eat approx. 10% of io bandwidth at max, we are sleeping between zeroing each single inode table. For that purpose we are using timer which wakes up thread when it expires. It is set via add_timer() and this may cause troubles in the case that thread has been woken up earlier and in next iteration we call add_timer() on still running timer hence hitting BUG_ON in add_timer(). We could fix that by using mod_timer() instead however we can use schedule_timeout_interruptible() for waiting and hence simplifying things a lot.
This commit exchange the old "waiting mechanism" with simple schedule_timeout_interruptible(), setting the time to sleep. Hence we do not longer need li_wait_daemon waiting queue and others, so get rid of it.
This solves Red Hat bug 699708.
---
[v2]: prevent sleepeng for a loong time when jiffies wraps
(Thanks to Eric Sandeen)
fs/ext4/ext4.h | 4 ---- fs/ext4/super.c | 31 ++++++------------------------- 2 files changed, 6 insertions(+), 29 deletions(-)
fs/ext4/ext4.h +0 -4
@@ -1590,12 +1590,8 @@ void ext4_get_group_no_and_offset(struct super_block *sb, ext4_fsblk_t blocknr,*/ struct ext4_lazy_init {unsigned long li_state; - -wait_queue_head_t li_wait_daemon;wait_queue_head_t li_wait_task; -struct timer_list li_timer;struct task_struct *li_task; -struct list_head li_request_list;struct mutex li_list_mtx; };
fs/ext4/super.c +6 -25
@@ -2659,12 +2659,6 @@ static void print_daily_error_info(unsigned long arg)mod_timer (&sbi->s_err_report, jiffies +24 *60 *60 *HZ );/* Once a day */ } -static void ext4_lazyinode_timeout (unsigned long data) -{ -struct task_struct *p = (struct task_struct *)data; -wake_up_process (p); -} -/* Find next suitable group and run ext4_init_inode_table */ static int ext4_run_li_request (struct ext4_li_request *elr) {
@@ -2712,7 +2706,7 @@ static int ext4_run_li_request(struct ext4_li_request *elr)/* * Remove lr_request from the list_request and free the -* request tructure. Should be called with li_list_mtx held +* request structure. Should be called with li_list_mtx held */ static void ext4_remove_li_request (struct ext4_li_request *elr) {
@@ -2756,14 +2750,10 @@ static int ext4_lazyinit_thread(void *arg)struct ext4_lazy_init *eli = (struct ext4_lazy_init *)arg;struct list_head *pos, *n;struct ext4_li_request *elr; -unsigned long next_wakeup; -DEFINE_WAIT (wait); +unsigned long next_wakeup, cur;BUG_ON (NULL == eli); - eli->li_timer.data = (unsigned long )current; - eli->li_timer.function = ext4_lazyinode_timeout; - eli->li_task = current;wake_up (&eli->li_wait_task);
@@ -2797,19 +2787,15 @@ cont_thread:if (freezing (current))refrigerator (); -if ((time_after_eq (jiffies, next_wakeup)) || + cur = jiffies; +if ((time_after_eq (cur, next_wakeup)) || (MAX_JIFFY_OFFSET == next_wakeup)) {cond_resched ();continue ; } - eli->li_timer.expires = next_wakeup; -add_timer (&eli->li_timer); -prepare_to_wait (&eli->li_wait_daemon, &wait, -TASK_INTERRUPTIBLE ); -if (time_before (jiffies, next_wakeup)) -schedule (); -finish_wait (&eli->li_wait_daemon, &wait); +schedule_timeout_interruptible (next_wakeup - cur); +if (kthread_should_stop ()) {ext4_clear_request_list (); goto exit_thread;
@@ -2833,12 +2819,10 @@ exit_thread: goto cont_thread; }mutex_unlock (&eli->li_list_mtx); -del_timer_sync (&ext4_li_info->li_timer); eli->li_task =NULL ;wake_up (&eli->li_wait_task);kfree (ext4_li_info); - ext4_lazyinit_task =NULL ; ext4_li_info =NULL ;mutex_unlock (&ext4_li_mtx);
@@ -2866,7 +2850,6 @@ static int ext4_run_lazyinit_thread(void)if (IS_ERR (ext4_lazyinit_task)) {int err =PTR_ERR (ext4_lazyinit_task);ext4_clear_request_list (); -del_timer_sync (&ext4_li_info->li_timer);kfree (ext4_li_info); ext4_li_info =NULL ; printk(KERN_CRIT "EXT4: error %d creating inode table "
@@ -2915,9 +2898,7 @@ static int ext4_li_info_new(void)INIT_LIST_HEAD (&eli->li_request_list);mutex_init (&eli->li_list_mtx); -init_waitqueue_head (&eli->li_wait_daemon);init_waitqueue_head (&eli->li_wait_task); -init_timer (&eli->li_timer); eli->li_state |=EXT4_LAZYINIT_QUIT ; ext4_li_info = eli;
Signature · 1 line
1.7.4.4
PATCH v2 2/4 ext4: Remove unnecessary wait_event ext4_run_lazyinit_thread()
For some reason we have been waiting for lazyinit thread to start in the ext4_run_lazyinit_thread() but it is not needed anymore so get rid of it. We can also remove li_task and li_wait_task since it is not used anymore.
--- fs/ext4/ext4.h | 2 -- fs/ext4/super.c | 10 ---------- 2 files changed, 0 insertions(+), 12 deletions(-)
fs/ext4/ext4.h +0 -2
@@ -1590,8 +1590,6 @@ void ext4_get_group_no_and_offset(struct super_block *sb, ext4_fsblk_t blocknr,*/ struct ext4_lazy_init {unsigned long li_state; -wait_queue_head_t li_wait_task; -struct task_struct *li_task;struct list_head li_request_list;struct mutex li_list_mtx; };
fs/ext4/super.c +0 -6
@@ -2754,9 +2754,6 @@ static int ext4_lazyinit_thread(void *arg)BUG_ON (NULL == eli); - eli->li_task = current; -wake_up (&eli->li_wait_task); - cont_thread:while (true) { next_wakeup =MAX_JIFFY_OFFSET ;
@@ -2819,9 +2816,6 @@ exit_thread: goto cont_thread; }mutex_unlock (&eli->li_list_mtx); - eli->li_task =NULL ; -wake_up (&eli->li_wait_task); -kfree (ext4_li_info); ext4_li_info =NULL ;mutex_unlock (&ext4_li_mtx);
@@ -2858,8 +2852,6 @@ static int ext4_run_lazyinit_thread(void)return err; } ext4_li_info->li_state |=EXT4_LAZYINIT_RUNNING ;
PATCH 3/4 ext4: fix init_itable=n to work as expected for n=0
In reply to Lukas CzernerFor some reason, when we set mount option init_itable=0 it behaves as we would set init_itable=20 which is not right at all. Basically when we set it to zero we are saying to lazyinit thread not to wait between zeroing the inode table (except of cond_resched()) so this commit fixes that and removes the unnecessary condition. The 'n' should be also properly used on remount.
When the n is not set at all, it means that the default miltiplier EXT4_DEF_LI_WAIT_MULT is set instead.
--- fs/ext4/super.c | 21 +++++++++++++++------ 1 files changed, 15 insertions(+), 6 deletions(-)
fs/ext4/super.c +15 -6
@@ -2690,11 +2690,8 @@ static int ext4_run_li_request(struct ext4_li_request *elr) ret =ext4_init_inode_table (sb, group, elr->lr_timeout ?0 :1 );if (elr->lr_timeout ==0 ) { - timeout = jiffies - timeout; -if (elr->lr_sbi->s_li_wait_mult) - timeout *= elr->lr_sbi->s_li_wait_mult; -else - timeout *=20 ; + timeout = (jiffies - timeout) * + elr->lr_sbi->s_li_wait_mult; elr->lr_timeout = timeout; } elr->lr_next_sched = jiffies + elr->lr_timeout;
@@ -2931,8 +2928,14 @@ static int ext4_register_li_request(struct super_block *sb,ext4_group_t ngroups =EXT4_SB (sb)->s_groups_count;int ret =0 ; -if (sbi->s_li_request !=NULL ) +if (sbi->s_li_request !=NULL ) { +/* +* Reset timeout so it can be computed again, because +* s_li_wait_mult might have changed. +*/ + sbi->s_li_request->lr_timeout =0 ;return 0 ; + } if (first_not_zeroed == ngroups || (sb->s_flags & MS_RDONLY) ||
@@ -3137,6 +3140,12 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) ((def_mount_opts & EXT4_DEFM_NODELALLOC) == 0))set_opt (sb,DELALLOC ); +/* +* set default s_li_wait_mult for lazyinit, for the case there is +* no mount option specified. +*/ + sbi->s_li_wait_mult =EXT4_DEF_LI_WAIT_MULT ; +if (!parse_options ((char *) sbi->s_es->s_mount_opts, sb, &journal_devnum, &journal_ioprio,NULL ,0 )) { ext4_msg(sb, KERN_WARNING,
Signature · 1 line
1.7.4.4
PATCH 4/4 ext4: fix possible use-after-free ext4_remove_li_request()
In reply to Lukas CzernerWe need to take reference to the s_li_request after we take a mutex, because it might be freed since then, hence result in accessing old already freed memory. Also we should protect the whole ext4_remove_li_request() because ext4_li_info might be in the process of being freed in ext4_lazyinit_thread().
--- fs/ext4/super.c | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-)
fs/ext4/super.c +0 -1
@@ -2721,14 +2721,16 @@ static void ext4_remove_li_request(struct ext4_li_request *elr)static void ext4_unregister_li_request (struct super_block *sb) { -struct ext4_li_request *elr =EXT4_SB (sb)->s_li_request;
Quoted 10 lines · Lukas Czerner
In order to make lazyinit eat approx. 10% of io bandwidth at max, we are sleeping between zeroing each single inode table. For that purpose we are using timer which wakes up thread when it expires. It is set via
add_timer()and this may cause troubles in the case that thread has been woken up earlier and in next iteration we calladd_timer()on still running timer hence hittingBUG_ONinadd_timer(). We could fix that by usingmod_timer()instead however we can useschedule_timeout_interruptible()for waiting and hence simplifying things a lot.
Quoted 8 lines
This commit exchange the old "waiting mechanism" with simple
schedule_timeout_interruptible(), setting the time to sleep. Hence we do not longer needli_wait_daemonwaiting queue and others, so get rid of it.This solves Red Hat bug 699708.
Signed-off-by Lukas Czerner <[email protected]>
Thanks Lukas - this looks good to me and takes care of the concern about jiffies wrapping.
Quoted 121 lines
---
[v2]: prevent sleepeng for a loong time when jiffies wraps
(Thanks to Eric Sandeen)fs/ext4/ext4.h | 4 ---- fs/ext4/super.c | 31 ++++++------------------------- 2 files changed, 6 insertions(+), 29 deletions(-)fs/ext4/ext4.h +0
-4@@ -1590,12 +1590,8 @@ void ext4_get_group_no_and_offset(struct super_block *sb, ext4_fsblk_t blocknr,*/ struct ext4_lazy_init {unsigned long li_state; - -wait_queue_head_t li_wait_daemon;wait_queue_head_t li_wait_task; -struct timer_list li_timer;struct task_struct *li_task; -struct list_head li_request_list;struct mutex li_list_mtx; };fs/ext4/super.c +6
-25@@ -2659,12 +2659,6 @@ static void print_daily_error_info(unsigned long arg)mod_timer (&sbi->s_err_report, jiffies +24 *60 *60 *HZ );/* Once a day */ } -static void ext4_lazyinode_timeout (unsigned long data) -{ -struct task_struct *p = (struct task_struct *)data; -wake_up_process (p); -} -/* Find next suitable group and run ext4_init_inode_table */ static int ext4_run_li_request (struct ext4_li_request *elr) {@@ -2712,7 +2706,7 @@ static int ext4_run_li_request(struct ext4_li_request *elr)/* * Remove lr_request from the list_request and free the -* request tructure. Should be called with li_list_mtx held +* request structure. Should be called with li_list_mtx held */ static void ext4_remove_li_request (struct ext4_li_request *elr) {@@ -2756,14 +2750,10 @@ static int ext4_lazyinit_thread(void *arg)struct ext4_lazy_init *eli = (struct ext4_lazy_init *)arg;struct list_head *pos, *n;struct ext4_li_request *elr; -unsigned long next_wakeup; -DEFINE_WAIT (wait); +unsigned long next_wakeup, cur;BUG_ON (NULL == eli); - eli->li_timer.data = (unsigned long )current; - eli->li_timer.function = ext4_lazyinode_timeout; - eli->li_task = current;wake_up (&eli->li_wait_task);@@ -2797,19 +2787,15 @@ cont_thread:if (freezing (current))refrigerator (); -if ((time_after_eq (jiffies, next_wakeup)) || + cur = jiffies; +if ((time_after_eq (cur, next_wakeup)) || (MAX_JIFFY_OFFSET == next_wakeup)) {cond_resched ();continue ; } - eli->li_timer.expires = next_wakeup; -add_timer (&eli->li_timer); -prepare_to_wait (&eli->li_wait_daemon, &wait, -TASK_INTERRUPTIBLE ); -if (time_before (jiffies, next_wakeup)) -schedule (); -finish_wait (&eli->li_wait_daemon, &wait); +schedule_timeout_interruptible (next_wakeup - cur); +if (kthread_should_stop ()) {ext4_clear_request_list (); goto exit_thread;@@ -2833,12 +2819,10 @@ exit_thread: goto cont_thread; }mutex_unlock (&eli->li_list_mtx); -del_timer_sync (&ext4_li_info->li_timer); eli->li_task =NULL ;wake_up (&eli->li_wait_task);kfree (ext4_li_info); - ext4_lazyinit_task =NULL ; ext4_li_info =NULL ;mutex_unlock (&ext4_li_mtx);@@ -2866,7 +2850,6 @@ static int ext4_run_lazyinit_thread(void)if (IS_ERR (ext4_lazyinit_task)) {int err =PTR_ERR (ext4_lazyinit_task);ext4_clear_request_list (); -del_timer_sync (&ext4_li_info->li_timer);kfree (ext4_li_info); ext4_li_info =NULL ; printk(KERN_CRIT "EXT4: error %d creating inode table "@@ -2915,9 +2898,7 @@ static int ext4_li_info_new(void)INIT_LIST_HEAD (&eli->li_request_list);mutex_init (&eli->li_list_mtx); -init_waitqueue_head (&eli->li_wait_daemon);init_waitqueue_head (&eli->li_wait_task); -init_timer (&eli->li_timer); eli->li_state |=EXT4_LAZYINIT_QUIT ; ext4_li_info = eli;
Re: [PATCH 2/4 v2] ext4: Remove unnecessary wait_event ext4_run_lazyinit_thread()
In reply to Lukas CzernerQuoted 6 lines · Lukas Czerner
For some reason we have been waiting for lazyinit thread to start in the
ext4_run_lazyinit_thread()but it is not needed anymore so get rid of it. We can also removeli_taskandli_wait_tasksince it is not used anymore.Signed-off-by Lukas Czerner <[email protected]>
Can you add to the changelog why this is "not needed anymore?" What changed? Was there any reason that it was waiting before, or was that just unnecessary complexity? I don't think there is a need to wait for the thread to ping us back after calling kthread_run() but I just wonder why it was there in the first place...
Other than that, seems fine, so:
Quoted 63 lines
--- fs/ext4/ext4.h | 2 -- fs/ext4/super.c | 10 ---------- 2 files changed, 0 insertions(+), 12 deletions(-)fs/ext4/ext4.h +0
-2@@ -1590,8 +1590,6 @@ void ext4_get_group_no_and_offset(struct super_block *sb, ext4_fsblk_t blocknr,*/ struct ext4_lazy_init {unsigned long li_state; -wait_queue_head_t li_wait_task; -struct task_struct *li_task;struct list_head li_request_list;struct mutex li_list_mtx; };fs/ext4/super.c +0
-10@@ -2754,9 +2754,6 @@ static int ext4_lazyinit_thread(void *arg)BUG_ON (NULL == eli); - eli->li_task = current; -wake_up (&eli->li_wait_task); - cont_thread:while (true) { next_wakeup =MAX_JIFFY_OFFSET ;@@ -2819,9 +2816,6 @@ exit_thread: goto cont_thread; }mutex_unlock (&eli->li_list_mtx); - eli->li_task =NULL ; -wake_up (&eli->li_wait_task); -kfree (ext4_li_info); ext4_li_info =NULL ;mutex_unlock (&ext4_li_mtx);@@ -2858,8 +2852,6 @@ static int ext4_run_lazyinit_thread(void)return err; } ext4_li_info->li_state |=EXT4_LAZYINIT_RUNNING ; - -wait_event (ext4_li_info->li_wait_task, ext4_li_info->li_task !=NULL );return 0 ; }@@ -2894,11 +2886,9 @@ static int ext4_li_info_new(void)if (!eli)return -ENOMEM ; - eli->li_task =NULL ;INIT_LIST_HEAD (&eli->li_request_list);mutex_init (&eli->li_list_mtx); -init_waitqueue_head (&eli->li_wait_task); eli->li_state |=EXT4_LAZYINIT_QUIT ; ext4_li_info = eli;
Re: [PATCH 3/4] ext4: fix init_itable=n to work as expected for n=0
In reply to Lukas CzernerQuoted 7 lines · Lukas Czerner
For some reason, when we set mount option init_itable=0 it behaves as we would set init_itable=20 which is not right at all. Basically when we set it to zero we are saying to lazyinit thread not to wait between zeroing the inode table (except of
cond_resched()) so this commit fixes that and removes the unnecessary condition. The 'n' should be also properly used on remount.
Quoted 5 lines
When the n is not set at all, it means that the default miltiplier
EXT4_DEF_LI_WAIT_MULTis set instead.Signed-off-by Lukas Czerner <[email protected]>Reported-by Eric Sandeen <[email protected]>
This is why last-minute maintainer changes that bypass the list can be dangerous ;) (This code wasn't in Lukas' last version on the list...)
nitpick: Documentation/fs/ext4.txt should probably be updated to clarify that the "=n" value is optional and defaults to 20...
nitpick2: Is there any reason to set the default in parse_options() since it's already set in ext4_fill_super just prior?
i.e. would something like:
case Opt_init_inode_table:
set_opt(sb, INIT_INODE_TABLE);
if (args[0].from) {
if (match_int(&args[0], &option))
return 0;
if (option < 0)
return 0;
sbi->s_li_wait_mult = option;
}
break;suffice?
-Eric
Quoted 51 lines
--- fs/ext4/super.c | 21 +++++++++++++++------ 1 files changed, 15 insertions(+), 6 deletions(-)fs/ext4/super.c +14
-6@@ -2690,11 +2690,8 @@ static int ext4_run_li_request(struct ext4_li_request *elr) ret =ext4_init_inode_table (sb, group, elr->lr_timeout ?0 :1 );if (elr->lr_timeout ==0 ) { - timeout = jiffies - timeout; -if (elr->lr_sbi->s_li_wait_mult) - timeout *= elr->lr_sbi->s_li_wait_mult; -else - timeout *=20 ; + timeout = (jiffies - timeout) * + elr->lr_sbi->s_li_wait_mult; elr->lr_timeout = timeout; } elr->lr_next_sched = jiffies + elr->lr_timeout;@@ -2931,8 +2928,14 @@ static int ext4_register_li_request(struct super_block *sb,ext4_group_t ngroups =EXT4_SB (sb)->s_groups_count;int ret =0 ; -if (sbi->s_li_request !=NULL ) +if (sbi->s_li_request !=NULL ) { +/* +* Reset timeout so it can be computed again, because +* s_li_wait_mult might have changed. +*/ + sbi->s_li_request->lr_timeout =0 ;return 0 ; + } if (first_not_zeroed == ngroups || (sb->s_flags & MS_RDONLY) ||@@ -3137,6 +3140,12 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) ((def_mount_opts & EXT4_DEFM_NODELALLOC) == 0))set_opt (sb,DELALLOC ); +/* +* set default s_li_wait_mult for lazyinit, for the case there is +* no mount option specified. +*/ + sbi->s_li_wait_mult =EXT4_DEF_LI_WAIT_MULT ;if (!parse_options ((char *) sbi->s_es->s_mount_opts, sb, &journal_devnum, &journal_ioprio,NULL ,0 )) { ext4_msg(sb, KERN_WARNING,
Re: [PATCH 4/4] ext4: fix possible use-after-free ext4_remove_li_request()
In reply to Lukas CzernerQuoted 5 lines · Lukas Czerner
We need to take reference to the
s_li_requestafter we take a mutex, because it might be freed since then, hence result in accessing old already freed memory. Also we should protect the wholeext4_remove_li_request()becauseext4_li_infomight be in the process of being freed inext4_lazyinit_thread().
It'd be really great to have some comments which explain just what ext4_li_mtx protects, but I'm working on an add-comments patch for the lazyinit stuff (I commented things a bit as I reviewed your changes) so I'll send that along later.
in any case, the change looks ok, thanks.
Quoted 30 lines
Signed-off-by Lukas Czerner <[email protected]>--- fs/ext4/super.c | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-)fs/ext4/super.c +6
-4@@ -2721,14 +2721,16 @@ static void ext4_remove_li_request(struct ext4_li_request *elr)static void ext4_unregister_li_request (struct super_block *sb) { -struct ext4_li_request *elr =EXT4_SB (sb)->s_li_request; - -if (!ext4_li_info) +mutex_lock (&ext4_li_mtx); +if (!ext4_li_info) { +mutex_unlock (&ext4_li_mtx);return ; + }mutex_lock (&ext4_li_info->li_list_mtx); -ext4_remove_li_request (elr); +ext4_remove_li_request (EXT4_SB (sb)->s_li_request);mutex_unlock (&ext4_li_info->li_list_mtx); +mutex_unlock (&ext4_li_mtx); }static struct task_struct *ext4_lazyinit_task;
Re: [PATCH 2/4 v2] ext4: Remove unnecessary wait_event ext4_run_lazyinit_thread()
In reply to Eric SandeenQuoted 6 lines · Eric Sandeen
Quoted 5 lines · Lukas Czerner
For some reason we have been waiting for lazyinit thread to start in the
ext4_run_lazyinit_thread()but it is not needed anymore so get rid of it. We can also removeli_taskandli_wait_tasksince it is not used anymore.
Quoted 8 lines
Quoted 1 line
Signed-off-by Lukas Czerner <[email protected]>Can you add to the changelog why this is "not needed anymore?" What changed? Was there any reason that it was waiting before, or was that just unnecessary complexity? I don't think there is a need to wait for the thread to ping us back after calling
kthread_run()but I just wonder why it was there in the first place...
Ok, I'll try to figure that out :) But probably just unnecessary complexity :)
Thanks for the review!
-Lukas
Quoted 70 lines
Other than that, seems fine, so:
Reviewed-by Eric Sandeen <[email protected]>Quoted 63 lines
--- fs/ext4/ext4.h | 2 -- fs/ext4/super.c | 10 ---------- 2 files changed, 0 insertions(+), 12 deletions(-)fs/ext4/ext4.h +0
-2@@ -1590,8 +1590,6 @@ void ext4_get_group_no_and_offset(struct super_block *sb, ext4_fsblk_t blocknr,*/ struct ext4_lazy_init {unsigned long li_state; -wait_queue_head_t li_wait_task; -struct task_struct *li_task;struct list_head li_request_list;struct mutex li_list_mtx; };fs/ext4/super.c +0
-10@@ -2754,9 +2754,6 @@ static int ext4_lazyinit_thread(void *arg)BUG_ON (NULL == eli); - eli->li_task = current; -wake_up (&eli->li_wait_task); - cont_thread:while (true) { next_wakeup =MAX_JIFFY_OFFSET ;@@ -2819,9 +2816,6 @@ exit_thread: goto cont_thread; }mutex_unlock (&eli->li_list_mtx); - eli->li_task =NULL ; -wake_up (&eli->li_wait_task); -kfree (ext4_li_info); ext4_li_info =NULL ;mutex_unlock (&ext4_li_mtx);@@ -2858,8 +2852,6 @@ static int ext4_run_lazyinit_thread(void)return err; } ext4_li_info->li_state |=EXT4_LAZYINIT_RUNNING ; - -wait_event (ext4_li_info->li_wait_task, ext4_li_info->li_task !=NULL );return 0 ; }@@ -2894,11 +2886,9 @@ static int ext4_li_info_new(void)if (!eli)return -ENOMEM ; - eli->li_task =NULL ;INIT_LIST_HEAD (&eli->li_request_list);mutex_init (&eli->li_list_mtx); -init_waitqueue_head (&eli->li_wait_task); eli->li_state |=EXT4_LAZYINIT_QUIT ; ext4_li_info = eli;
Re: [PATCH 3/4] ext4: fix init_itable=n to work as expected for n=0
In reply to Eric SandeenQuoted 11 lines · Eric Sandeen
Quoted 10 lines · Lukas Czerner
For some reason, when we set mount option init_itable=0 it behaves as we would set init_itable=20 which is not right at all. Basically when we set it to zero we are saying to lazyinit thread not to wait between zeroing the inode table (except of
cond_resched()) so this commit fixes that and removes the unnecessary condition. The 'n' should be also properly used on remount.When the n is not set at all, it means that the default miltiplier
EXT4_DEF_LI_WAIT_MULTis set instead.
Quoted 8 lines
Quoted 2 lines
Signed-off-by Lukas Czerner <[email protected]>Reported-by Eric Sandeen <[email protected]>This is why last-minute maintainer changes that bypass the list can be dangerous ;) (This code wasn't in Lukas' last version on the list...)
nitpick:
Documentation/fs/ext4.txtshould probably be updated to clarify that the "=n" value is optional and defaults to 20...
Will do.
Quoted 17 lines
nitpick2: Is there any reason to set the default in
parse_options()since it's already set inext4_fill_superjust prior?i.e. would something like:
case Opt_init_inode_table: set_opt(sb, INIT_INODE_TABLE); if (args[0].from) { if (match_int(&args[0], &option)) return 0; if (option < 0) return 0; sbi->s_li_wait_mult = option; } break;
Quoted 1 line
suffice?
Yes, it did not notice that.
Thanks!
-Lukas
Quoted 56 lines
-Eric
Quoted 51 lines
--- fs/ext4/super.c | 21 +++++++++++++++------ 1 files changed, 15 insertions(+), 6 deletions(-)fs/ext4/super.c +14
-6@@ -2690,11 +2690,8 @@ static int ext4_run_li_request(struct ext4_li_request *elr) ret =ext4_init_inode_table (sb, group, elr->lr_timeout ?0 :1 );if (elr->lr_timeout ==0 ) { - timeout = jiffies - timeout; -if (elr->lr_sbi->s_li_wait_mult) - timeout *= elr->lr_sbi->s_li_wait_mult; -else - timeout *=20 ; + timeout = (jiffies - timeout) * + elr->lr_sbi->s_li_wait_mult; elr->lr_timeout = timeout; } elr->lr_next_sched = jiffies + elr->lr_timeout;@@ -2931,8 +2928,14 @@ static int ext4_register_li_request(struct super_block *sb,ext4_group_t ngroups =EXT4_SB (sb)->s_groups_count;int ret =0 ; -if (sbi->s_li_request !=NULL ) +if (sbi->s_li_request !=NULL ) { +/* +* Reset timeout so it can be computed again, because +* s_li_wait_mult might have changed. +*/ + sbi->s_li_request->lr_timeout =0 ;return 0 ; + } if (first_not_zeroed == ngroups || (sb->s_flags & MS_RDONLY) ||@@ -3137,6 +3140,12 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) ((def_mount_opts & EXT4_DEFM_NODELALLOC) == 0))set_opt (sb,DELALLOC ); +/* +* set default s_li_wait_mult for lazyinit, for the case there is +* no mount option specified. +*/ + sbi->s_li_wait_mult =EXT4_DEF_LI_WAIT_MULT ;if (!parse_options ((char *) sbi->s_es->s_mount_opts, sb, &journal_devnum, &journal_ioprio,NULL ,0 )) { ext4_msg(sb, KERN_WARNING,
Re: [PATCH 4/4] ext4: fix possible use-after-free ext4_remove_li_request()
In reply to Eric SandeenQuoted 11 lines · Eric Sandeen
Quoted 5 lines · Lukas Czerner
We need to take reference to the
s_li_requestafter we take a mutex, because it might be freed since then, hence result in accessing old already freed memory. Also we should protect the wholeext4_remove_li_request()becauseext4_li_infomight be in the process of being freed inext4_lazyinit_thread().It'd be really great to have some comments which explain just what
ext4_li_mtxprotects, but I'm working on an add-comments patch for the lazyinit stuff (I commented things a bit as I reviewed your changes) so I'll send that along later.
The ext4_li_mtx is protecting the whole ext4_li_info structure so it can be atomically created and freed.
Quoted 4 lines
in any case, the change looks ok, thanks.
Reviewed-by Eric Sandeen <[email protected]>
Thanks!
-Lukas
Quoted 34 lines
Quoted 32 lines
Signed-off-by Lukas Czerner <[email protected]>--- fs/ext4/super.c | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-)fs/ext4/super.c +6
-4@@ -2721,14 +2721,16 @@ static void ext4_remove_li_request(struct ext4_li_request *elr)static void ext4_unregister_li_request (struct super_block *sb) { -struct ext4_li_request *elr =EXT4_SB (sb)->s_li_request; - -if (!ext4_li_info) +mutex_lock (&ext4_li_mtx); +if (!ext4_li_info) { +mutex_unlock (&ext4_li_mtx);return ; + }mutex_lock (&ext4_li_info->li_list_mtx); -ext4_remove_li_request (elr); +ext4_remove_li_request (EXT4_SB (sb)->s_li_request);mutex_unlock (&ext4_li_info->li_list_mtx); +mutex_unlock (&ext4_li_mtx); }static struct task_struct *ext4_lazyinit_task;
Ted Ts'o
maintainerRe: [PATCH 4/4] ext4: fix possible use-after-free ext4_remove_li_request()
Lukas, are you going to be providing a new version of these patch series or not?
If you are, could you do it as a separate patch series, instead of only updating one patch as a reply to the mail thread. When people do this, I find it painful since I need to figure out, "ok, I need v2 of the 1/4 patch, v3 of the 2/4 patch, v4 of the 3/4 patch, and v3 of of the 4/4 patch. To provide context, please add version descriptors after the --- of the patch. (i.e, "v3 --> v4; fixed commit message")
Also, if we're going to be doing extended review of patches like this, instead of my just fixing things up when I pull stuff in, people need to start authoring patches ***much*** sooner. Doing multiple publish and review cycles now that the merge window is open really doesn't work. One way of solving this in the future is to simply not take any patch that is first submitted after say, -rc5 or -rc6 until the next merge window. But given that some patches didn't *start* getting much review until 2-3 weeks ago, that wouldn't be entirely fair.
But for the next merge window, if this is going to work, we need people submitting patches earlier, and people reviewing patches earlier.
Thanks,
- Ted
Re: [PATCH 4/4] ext4: fix possible use-after-free ext4_remove_li_request()
Quoted 19 lines · Ted Ts'o
Lukas, are you going to be providing a new version of these patch series or not?
If you are, could you do it as a separate patch series, instead of only updating one patch as a reply to the mail thread. When people do this, I find it painful since I need to figure out, "ok, I need v2 of the 1/4 patch, v3 of the 2/4 patch, v4 of the 3/4 patch, and v3 of of the 4/4 patch. To provide context, please add version descriptors after the --- of the patch. (i.e, "v3 --> v4; fixed commit message")
Also, if we're going to be doing extended review of patches like this, instead of my just fixing things up when I pull stuff in, people need to start authoring patches ***much*** sooner. Doing multiple publish and review cycles now that the merge window is open really doesn't work. One way of solving this in the future is to simply not take any patch that is first submitted after say, -rc5 or -rc6 until the next merge window. But given that some patches didn't *start* getting much review until 2-3 weeks ago, that wouldn't be entirely fair.
Quoted 3 lines
But for the next merge window, if this is going to work, we need people submitting patches earlier, and people reviewing patches earlier.
How about a reasonable sounding convention like: if it's non-critical it's too late, but if it's critical you'll try to get it in.
Windows are windows, reviews are reviews, and if it's too late, it's too late ... You ultimately get to decide what goes in and when.
But skipping thorough review simply because the window is open now doesn't make sense to me.
-Eric
Re: [PATCH 4/4] ext4: fix possible use-after-free ext4_remove_li_request()
In reply to Ted Ts'oHi Ted,
Quoted 2 lines · Ted Ts'o
Lukas, are you going to be providing a new version of these patch series or not?
I already did send it as a separate patch series with the version description.
Quoted 8 lines
If you are, could you do it as a separate patch series, instead of only updating one patch as a reply to the mail thread. When people do this, I find it painful since I need to figure out, "ok, I need v2 of the 1/4 patch, v3 of the 2/4 patch, v4 of the 3/4 patch, and v3 of of the 4/4 patch. To provide context, please add version descriptors after the --- of the patch. (i.e, "v3 --> v4; fixed commit message")
Quoted 8 lines
Also, if we're going to be doing extended review of patches like this, instead of my just fixing things up when I pull stuff in, people need to start authoring patches ***much*** sooner. Doing multiple publish and review cycles now that the merge window is open really doesn't work. One way of solving this in the future is to simply not take any patch that is first submitted after say, -rc5 or -rc6 until the next merge window. But given that some patches didn't *start* getting much review until 2-3 weeks ago, that wouldn't be entirely fair.
We all should do better, but I am not sure that limits like that are very useful. Some level of flexibility is always needed.
Quoted 4 lines
But for the next merge window, if this is going to work, we need people submitting patches earlier, and people reviewing patches earlier.
So let's to that people ;).
Quoted 4 lines
Thanks,
- Ted
Thanks Ted!
-Lukas
Quoted 5 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Ted Ts'o
maintainerRe: [PATCH 4/4] ext4: fix possible use-after-free ext4_remove_li_request()
Quoted 3 lines · Lukas Czerner
I already did send it as a separate patch series with the version description.
What, you mean the -v2 patch series?
But Eric has made further suggestions where you said you might try to do more work. Or did I misread the mail thread? This is why I hate it when you reply to the mail thread with an updated patch. It makes it very hard to figure out what's going on....
So let me rephrase the question: Is -v2 your final answer?
- Ted
Ted Ts'o
maintainerRe: [PATCH 4/4] ext4: fix possible use-after-free ext4_remove_li_request()
Quoted 9 lines · Ted Ts'o
Quoted 3 lines · Lukas Czerner
I already did send it as a separate patch series with the version description.
What, you mean the -v2 patch series?
So let me rephrase the question: Is -v2 your final answer?
Ah, never mind. I got confused when with the other patch series where half the patches where -v3, and the other half were -v2. It makes what shows up in patchwork hard to follow. In the future, please bump the version number on the entire series, not just on individual patches, as it makes it a lot easier for me to track what is going on....
- Ted
Ted Ts'o
maintainerRe: [PATCH 4/4] ext4: fix possible use-after-free ext4_remove_li_request()
In reply to Eric SandeenQuoted 3 lines · Eric Sandeen
But skipping thorough review simply because the window is open now doesn't make sense to me.
Sure, but adding a 24-hour turnaround for at least simple fix ups (commit descriptions, comments, white space, etc) doesn't make a lot of sense either.
- Ted
Re: [PATCH 4/4] ext4: fix possible use-after-free ext4_remove_li_request()
Quoted 10 lines · Ted Ts'o
Quoted 3 lines · Eric Sandeen
But skipping thorough review simply because the window is open now doesn't make sense to me.
Sure, but adding a 24-hour turnaround for at least simple fix ups (commit descriptions, comments, white space, etc) doesn't make a lot of sense either.
- Ted
I think you are free to use your discretion for those things :)
I mean if the last review comment is "you have a typo here" and you really want to make the window, it seems quite reasonable to fix it up, with a note in the commit log.
-Eric