All of lore.kernel.org
 help / color / mirror / Atom feed
From: Fengguang Wu <fengguang.wu@intel.com>
To: Jan Kara <jack@suse.cz>
Cc: Peter Zijlstra <peterz@infradead.org>,
	Sasha Levin <levinsasha928@gmail.com>,
	linux-mm@kvack.org, LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 2/2] block: Convert BDI proportion calculations to flexible proportions
Date: Fri, 1 Jun 2012 11:10:15 +0800	[thread overview]
Message-ID: <20120601031015.GB7896@localhost> (raw)
In-Reply-To: <20120531224206.GC19050@quack.suse.cz>

On Fri, Jun 01, 2012 at 12:42:06AM +0200, Jan Kara wrote:
> On Fri 01-06-12 00:26:05, Peter Zijlstra wrote:
> > On Fri, 2012-06-01 at 00:11 +0200, Jan Kara wrote:
> > >  bool fprop_new_period(struct fprop_global *p, int periods)
> > >  {
> > > -       u64 events = percpu_counter_sum(&p->events);
> > > +       u64 events;
> > > +       unsigned long flags;
> > >  
> > > +       local_irq_save(flags);
> > > +       events = percpu_counter_sum(&p->events);
> > > +       local_irq_restore(flags);
> > >         /*
> > >          * Don't do anything if there are no events.
> > >          */
> > > @@ -73,7 +77,9 @@ bool fprop_new_period(struct fprop_global *p, int periods)
> > >         if (periods < 64)
> > >                 events -= events >> periods;
> > >         /* Use addition to avoid losing events happening between sum and set */
> > > +       local_irq_save(flags);
> > >         percpu_counter_add(&p->events, -events);
> > > +       local_irq_restore(flags);
> > >         p->period += periods;
> > >         write_seqcount_end(&p->sequence); 
> > 
> > Uhm, why bother enabling it in between? Just wrap the whole function in
> > a single IRQ disable.
>   I wanted to have interrupts disabled for as short as possible but if you
> think it doesn't matter, I'll take your advice. The result is attached.

Thank you! I applied this incremental fix next to the commit
"lib: Proportions with flexible period".

Thanks,
Fengguang

> From: Jan Kara <jack@suse.cz>
> Subject: lib: Fix possible deadlock in flexible proportion code
> 
> When percpu counter function in fprop_new_period() is interrupted by an
> interrupt while holding counter lock, it can cause deadlock when the
> interrupt wants to take the lock as well. Fix the problem by disabling
> interrupts when calling percpu counter functions.
> 
> Signed-off-by: Jan Kara <jack@suse.cz>
> 
> diff -u b/lib/flex_proportions.c b/lib/flex_proportions.c
> --- b/lib/flex_proportions.c
> +++ b/lib/flex_proportions.c
> @@ -62,13 +62,18 @@
>   */
>  bool fprop_new_period(struct fprop_global *p, int periods)
>  {
> -	u64 events = percpu_counter_sum(&p->events);
> +	u64 events;
> +	unsigned long flags;
>  
> +	local_irq_save(flags);
> +	events = percpu_counter_sum(&p->events);
>  	/*
>  	 * Don't do anything if there are no events.
>  	 */
> -	if (events <= 1)
> +	if (events <= 1) {
> +		local_irq_restore(flags);
>  		return false;
> +	}
>  	write_seqcount_begin(&p->sequence);
>  	if (periods < 64)
>  		events -= events >> periods;
> @@ -76,6 +81,7 @@
>  	percpu_counter_add(&p->events, -events);
>  	p->period += periods;
>  	write_seqcount_end(&p->sequence);
> +	local_irq_restore(flags);
>  
>  	return true;
>  }

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

WARNING: multiple messages have this Message-ID (diff)
From: Fengguang Wu <fengguang.wu@intel.com>
To: Jan Kara <jack@suse.cz>
Cc: Peter Zijlstra <peterz@infradead.org>,
	Sasha Levin <levinsasha928@gmail.com>,
	linux-mm@kvack.org, LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 2/2] block: Convert BDI proportion calculations to flexible proportions
Date: Fri, 1 Jun 2012 11:10:15 +0800	[thread overview]
Message-ID: <20120601031015.GB7896@localhost> (raw)
In-Reply-To: <20120531224206.GC19050@quack.suse.cz>

On Fri, Jun 01, 2012 at 12:42:06AM +0200, Jan Kara wrote:
> On Fri 01-06-12 00:26:05, Peter Zijlstra wrote:
> > On Fri, 2012-06-01 at 00:11 +0200, Jan Kara wrote:
> > >  bool fprop_new_period(struct fprop_global *p, int periods)
> > >  {
> > > -       u64 events = percpu_counter_sum(&p->events);
> > > +       u64 events;
> > > +       unsigned long flags;
> > >  
> > > +       local_irq_save(flags);
> > > +       events = percpu_counter_sum(&p->events);
> > > +       local_irq_restore(flags);
> > >         /*
> > >          * Don't do anything if there are no events.
> > >          */
> > > @@ -73,7 +77,9 @@ bool fprop_new_period(struct fprop_global *p, int periods)
> > >         if (periods < 64)
> > >                 events -= events >> periods;
> > >         /* Use addition to avoid losing events happening between sum and set */
> > > +       local_irq_save(flags);
> > >         percpu_counter_add(&p->events, -events);
> > > +       local_irq_restore(flags);
> > >         p->period += periods;
> > >         write_seqcount_end(&p->sequence); 
> > 
> > Uhm, why bother enabling it in between? Just wrap the whole function in
> > a single IRQ disable.
>   I wanted to have interrupts disabled for as short as possible but if you
> think it doesn't matter, I'll take your advice. The result is attached.

Thank you! I applied this incremental fix next to the commit
"lib: Proportions with flexible period".

Thanks,
Fengguang

> From: Jan Kara <jack@suse.cz>
> Subject: lib: Fix possible deadlock in flexible proportion code
> 
> When percpu counter function in fprop_new_period() is interrupted by an
> interrupt while holding counter lock, it can cause deadlock when the
> interrupt wants to take the lock as well. Fix the problem by disabling
> interrupts when calling percpu counter functions.
> 
> Signed-off-by: Jan Kara <jack@suse.cz>
> 
> diff -u b/lib/flex_proportions.c b/lib/flex_proportions.c
> --- b/lib/flex_proportions.c
> +++ b/lib/flex_proportions.c
> @@ -62,13 +62,18 @@
>   */
>  bool fprop_new_period(struct fprop_global *p, int periods)
>  {
> -	u64 events = percpu_counter_sum(&p->events);
> +	u64 events;
> +	unsigned long flags;
>  
> +	local_irq_save(flags);
> +	events = percpu_counter_sum(&p->events);
>  	/*
>  	 * Don't do anything if there are no events.
>  	 */
> -	if (events <= 1)
> +	if (events <= 1) {
> +		local_irq_restore(flags);
>  		return false;
> +	}
>  	write_seqcount_begin(&p->sequence);
>  	if (periods < 64)
>  		events -= events >> periods;
> @@ -76,6 +81,7 @@
>  	percpu_counter_add(&p->events, -events);
>  	p->period += periods;
>  	write_seqcount_end(&p->sequence);
> +	local_irq_restore(flags);
>  
>  	return true;
>  }


  reply	other threads:[~2012-06-01  3:10 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-24 16:59 [PATCH 0/2 v4] Flexible proportions Jan Kara
2012-05-24 16:59 ` Jan Kara
2012-05-24 16:59 ` [PATCH 1/2] lib: Proportions with flexible period Jan Kara
2012-05-24 16:59   ` Jan Kara
2012-05-24 16:59 ` [PATCH 2/2] block: Convert BDI proportion calculations to flexible proportions Jan Kara
2012-05-24 16:59   ` Jan Kara
2012-05-28 15:49   ` Sasha Levin
2012-05-28 15:49     ` Sasha Levin
2012-05-29 12:34     ` Jan Kara
2012-05-29 12:34       ` Jan Kara
2012-05-29 12:38       ` Peter Zijlstra
2012-05-29 12:38         ` Peter Zijlstra
2012-05-29 12:54         ` Jan Kara
2012-05-29 12:54           ` Jan Kara
2012-05-31 22:11           ` Jan Kara
2012-05-31 22:26             ` Peter Zijlstra
2012-05-31 22:26               ` Peter Zijlstra
2012-05-31 22:42               ` Jan Kara
2012-06-01  3:10                 ` Fengguang Wu [this message]
2012-06-01  3:10                   ` Fengguang Wu
2012-06-01 10:13                 ` Peter Zijlstra
2012-06-01 10:13                   ` Peter Zijlstra
2012-05-25  9:12 ` [PATCH 0/2 v4] Flexible proportions Peter Zijlstra
2012-05-25  9:12   ` Peter Zijlstra
2012-05-25  9:29   ` Fengguang Wu
2012-05-25  9:29     ` Fengguang Wu
  -- strict thread matches above, loose matches on Subject: below --
2012-05-15 15:43 [PATCH 0/2 v3] " Jan Kara
2012-05-15 15:43 ` [PATCH 2/2] block: Convert BDI proportion calculations to flexible proportions Jan Kara
2012-05-15 15:43   ` Jan Kara
2012-05-17 22:04   ` Peter Zijlstra
2012-05-17 22:04     ` Peter Zijlstra
2012-05-18 14:24     ` Jan Kara
2012-05-18 14:24       ` Jan Kara
2012-05-18 14:34       ` Peter Zijlstra
2012-05-18 14:34         ` Peter Zijlstra
2012-05-03 22:39 [PATCH 0/2 v2] Flexible proportions for BDIs Jan Kara
2012-05-03 22:39 ` [PATCH 2/2] block: Convert BDI proportion calculations to flexible proportions Jan Kara
2012-05-07 14:47   ` Fengguang Wu
2012-05-07 15:21     ` Peter Zijlstra
2012-05-09 11:38       ` Jan Kara

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=20120601031015.GB7896@localhost \
    --to=fengguang.wu@intel.com \
    --cc=jack@suse.cz \
    --cc=levinsasha928@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=peterz@infradead.org \
    /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.