linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Jules Irenge <jbi.octave@gmail.com>
Cc: boqun.feng@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/1] backing-dev: refactor wb_congested_put()
Date: Wed, 11 Mar 2020 17:59:19 -0700	[thread overview]
Message-ID: <20200311175919.30523d55b2e5307ba22bbdc0@linux-foundation.org> (raw)
In-Reply-To: <20200312002156.49023-2-jbi.octave@gmail.com>

On Thu, 12 Mar 2020 00:21:56 +0000 Jules Irenge <jbi.octave@gmail.com> wrote:

> wb_congested_put() was written in such a way that made it difficult
> 	for Sparse tool not to complain
> Expanding the function locking block in the if statement improves on
> the readability of the code. Rewritting it  comes with one add-on:
> 
> It fixes a warning reported by Sparse tool at wb_congested_put()
> 
> warning: context imbalance in wb_congested_put() - unexpected unlock
> 
> Refactor the function wb_congested_put()
> 
> ...
>
> --- a/mm/backing-dev.c
> +++ b/mm/backing-dev.c
> @@ -464,18 +464,21 @@ void wb_congested_put(struct bdi_writeback_congested *congested)
>  {
>  	unsigned long flags;
>  
> -	if (!refcount_dec_and_lock_irqsave(&congested->refcnt, &cgwb_lock, &flags))
> -		return;
> -
> +	if (!refcount_dec_not_one(&congested->refcnt)) {
> +		spin_lock_irqsave(&cgwb_lock, flags);
> +		if (!refcount_dec_and_test(&congested->refcnt)) {
> +			spin_unlock_irqrestore(&cgwb_lock, flags);
> +			return;
> +		}
>  	/* bdi might already have been destroyed leaving @congested unlinked */
> -	if (congested->__bdi) {
> -		rb_erase(&congested->rb_node,
> -			 &congested->__bdi->cgwb_congested_tree);
> -		congested->__bdi = NULL;
> +		if (congested->__bdi) {
> +			rb_erase(&congested->rb_node,
> +				 &congested->__bdi->cgwb_congested_tree);
> +			congested->__bdi = NULL;
> +		}
> +		spin_unlock_irqrestore(&cgwb_lock, flags);
> +		kfree(congested);
>  	}
> -
> -	spin_unlock_irqrestore(&cgwb_lock, flags);
> -	kfree(congested);
>  }

hm, it's hard to get excited over this.  Open-coding the
refcount_dec_and_lock_irqsave() internals at a callsite in order to
make sparse happy.

Is there some other way, using __acquires (for example)?


  reply	other threads:[~2020-03-12  0:59 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-12  0:21 [PATCH 0/1] Refactoring wb_congested_put() Jules Irenge
2020-03-12  0:21 ` [PATCH 1/1] backing-dev: refactor wb_congested_put() Jules Irenge
2020-03-12  0:59   ` Andrew Morton [this message]
2020-03-12  2:29     ` Matthew Wilcox
2020-03-12  3:00       ` Andrew Morton
2020-03-12  9:56         ` Jules Irenge

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=20200311175919.30523d55b2e5307ba22bbdc0@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=boqun.feng@gmail.com \
    --cc=jbi.octave@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.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 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).