Skip to content

Commit

Permalink
ext4: Use schedule_timeout_interruptible() for waiting in lazyinit th…
Browse files Browse the repository at this point in the history
…read

commit 4ed5c03 upstream.

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.

Addresses-Red-Hat-Bugzilla: #699708

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Lukas Czerner authored and gregkh committed Jun 3, 2011
1 parent abe87a0 commit ad106f8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 29 deletions.
4 changes: 0 additions & 4 deletions fs/ext4/ext4.h
Expand Up @@ -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;
};
Expand Down
31 changes: 6 additions & 25 deletions fs/ext4/super.c
Expand Up @@ -2645,12 +2645,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)
{
Expand Down Expand Up @@ -2698,7 +2692,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)
{
Expand Down Expand Up @@ -2744,14 +2738,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);

Expand Down Expand Up @@ -2785,19 +2775,15 @@ static int ext4_lazyinit_thread(void *arg)
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;
Expand All @@ -2821,12 +2807,10 @@ static int ext4_lazyinit_thread(void *arg)
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);

Expand Down Expand Up @@ -2854,7 +2838,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 "
Expand Down Expand Up @@ -2903,9 +2886,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;
Expand Down

0 comments on commit ad106f8

Please sign in to comment.