Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp1117718ybh; Wed, 11 Mar 2020 18:01:02 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvZZBpQjJCtoLoTPgAUbSAtdRb1L0E+e8fGTm/xqzcpGF9Ca4J8YDnD+yxXj9Lmy/fPddV6 X-Received: by 2002:a9d:7a47:: with SMTP id z7mr4672060otm.341.1583974862053; Wed, 11 Mar 2020 18:01:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583974862; cv=none; d=google.com; s=arc-20160816; b=A20VUj+BEyjhgTU98CrlIOeW7uC5OQ7NDsdqj7INlRxkTNsAa5SQzZt3Q63vGygRSU 0ZWDULLJYauV+MMWO+vvJZP/tV/9MJSAz5VcA0amJj2OR1BKmKSu1lMdie8/YgstJTfR FVWaBhq3NxjMHPueQO0SrTgnigHzi8c1qyy917T/ynauQMCizbkk5uvxjnhPIMBW8fhG 5qjGDmoU4ElTueicsAN/MJAKFtXHXHtxZd4pK+YyAb2UN1s8JYQFyXkWmu4ZRU7vS1lM ux5byprh4NY+8MWib/nZQuSBNiMvi/BABdR2o6yF0a85Z3d8vR5GhiqnGqyfKGZiuZAv MYoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=0BRRxHeaW9XSh06Fq3bhWdjhrDMwKJsSc+XfP8ee0XE=; b=dDTAB/MPZ6Zb9zBwSq9UdXix9WxlJ6Dodb2k4QOazmLVwBxu4riBVGZDUjHy0xW0bO Pr1hJLASbHRP4ZmypxqfPpuZgtmodYYT+Xmii4Q2t/QYZOFmo+tvZVdW9cpp8Ota8638 sCtPwasDU6/iUqI7o4FmafzOJKXyO0qPOWLOpyMRDRJRDg5emg2oC8b7qQvfRNgOb8si csg9OH2Nouu4hXqVatyf5+DQQj8xrBxPVrrpyxL1rOpo2IzVbnALVxCdCp0T5Y6yeHoh 7meqNJUJmWFaM4T92NVFaJKGdzQS9EKoO7Rjcwbe9L1qrRE5bsEJQ78UXTJiIbP7ezVF eKmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dljkngR2; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e4si1905688otj.242.2020.03.11.18.00.49; Wed, 11 Mar 2020 18:01:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dljkngR2; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387590AbgCLA7V (ORCPT + 99 others); Wed, 11 Mar 2020 20:59:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:39002 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387518AbgCLA7V (ORCPT ); Wed, 11 Mar 2020 20:59:21 -0400 Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7B0D520734; Thu, 12 Mar 2020 00:59:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583974760; bh=JABgZCHmEBb3tn/P9d99r9kBtaxONATZlzJZzI6/7h4=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=dljkngR2apT/UPuwBHxo/d8Tb+tarA2I5DfIGV5mm0seMImzOdeOOyzU3ZheyPq4B mzK2fcyoCMlaF9y1ccJ5JxNstj7+bz3gA4xqrc7sVXAMGPrELUUNEIf9hLVaW+Ocer SJ0ooQgN9AgmmZ6r2ObKEfsiuWWZ2xP5MyamOCmI= Date: Wed, 11 Mar 2020 17:59:19 -0700 From: Andrew Morton To: Jules Irenge 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() Message-Id: <20200311175919.30523d55b2e5307ba22bbdc0@linux-foundation.org> In-Reply-To: <20200312002156.49023-2-jbi.octave@gmail.com> References: <20200312002156.49023-1-jbi.octave@gmail.com> <20200312002156.49023-2-jbi.octave@gmail.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 12 Mar 2020 00:21:56 +0000 Jules Irenge 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)?