From patchwork Thu Mar 12 00:21:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jules Irenge X-Patchwork-Id: 11433077 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5135D921 for ; Thu, 12 Mar 2020 00:22:11 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CA7262074E for ; Thu, 12 Mar 2020 00:22:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YBCJcKO7" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CA7262074E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 245026B0006; Wed, 11 Mar 2020 20:22:09 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 1A5066B0007; Wed, 11 Mar 2020 20:22:09 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 01FF46B0008; Wed, 11 Mar 2020 20:22:08 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0126.hostedemail.com [216.40.44.126]) by kanga.kvack.org (Postfix) with ESMTP id DE52C6B0006 for ; Wed, 11 Mar 2020 20:22:08 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id A460A5825 for ; Thu, 12 Mar 2020 00:22:08 +0000 (UTC) X-FDA: 76584807936.19.toy88_4ce22bcc2a215 X-Spam-Summary: 2,0,0,efccec0dec3766bf,d41d8cd98f00b204,jbi.octave@gmail.com,,RULES_HIT:41:69:355:379:541:800:960:966:973:988:989:1260:1311:1314:1345:1359:1437:1515:1534:1541:1711:1730:1747:1777:1792:2196:2199:2393:2559:2562:3138:3139:3140:3141:3142:3352:3865:3866:3867:3870:3872:3874:4385:5007:6261:6653:7514:7875:7903:9413:9592:10004:11026:11658:11914:12043:12296:12297:12438:12517:12519:12555:12679:12895:13069:13161:13229:13311:13357:13894:14096:14181:14384:14394:14687:14721:21080:21433:21444:21451:21627:21666:21740:21987:21990:30012:30054:30070,0,RBL:209.85.221.67:@gmail.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:23,LUA_SUMMARY:none X-HE-Tag: toy88_4ce22bcc2a215 X-Filterd-Recvd-Size: 4633 Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by imf48.hostedemail.com (Postfix) with ESMTP for ; Thu, 12 Mar 2020 00:22:08 +0000 (UTC) Received: by mail-wr1-f67.google.com with SMTP id p2so5131670wrw.7 for ; Wed, 11 Mar 2020 17:22:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XMQYZ+6NFPRcSEcavCV/oXjjG97VYnibSYtGEAw9FKE=; b=YBCJcKO7WMERIDKhjn9c2ArgxPEQrxYKQEQ6LEfLaxrvuoz6rScdfqIJUaX/XDRZny brr2Fvy1Sghb7FOcgZLndwtSBycagaPxcRLChohsdVmGmuJKinJ3Fv/UY+FUdT1CGwow qeYRKy9iruEhap5M+4IhNnTM94la8flsSvACVFbjxmIblKzpQuxUjPg/puovL1noOdlb 7opS1YDKCcch3XvJe31/eHlb7ES3VRqmIcVcKefQZ2GrEuNx7y3T+nEsWOOgNNdDPIOV SKeLbUsxg4iEOonOYb5ImSQZTmzPPzAGf5KFWeiZaZ1B4kU3KN0X3+vB7XcXs0dIlP51 mQGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XMQYZ+6NFPRcSEcavCV/oXjjG97VYnibSYtGEAw9FKE=; b=cCJxFdUaR9DQBNNL1PXwuoVqKEP9P2AN2pJxDPN5Jddu3FxgJsFmYWmxZeFfVtbaIX YdAiUMwoPhzAIlVz/oeywubTaVaPkb6WM73H4fZX+HmPmlAXpxJ1v1gsRTJtaBSLqSkQ SmxxPDghVygh+XVI2Jyv4Xe2nh9B6kccBDgzG7ZJ0lHgY3yIaE1AEV2zjTGJ1BmkMPyW iVqE7qSusLt4lwV80ld2yf+kJ/pxm3+pgbV6JTvbG768xXG+EMgWGSAprbeHBunCezZX Dd/ddfGQ74mXt69SLuRbd3tXUmd++gT0qeZSonke1gX9U53MpWewrr5V3KnhOFf3Q30e MnEQ== X-Gm-Message-State: ANhLgQ0754dgFeqq3n1yYiQ2+M7QHLQckF2tHnRR63JEGJOz7vRhXQof WlsxhSBvshfk5DzCz4ccNg== X-Google-Smtp-Source: ADFU+vvHuG1Q+7bqN43LnZR4hfTQIj8sE/4uXvN+STf+QvB2YqxjAzzHIOIClefMyg4+5nuJtTiiOQ== X-Received: by 2002:adf:f0c8:: with SMTP id x8mr7543466wro.58.1583972527134; Wed, 11 Mar 2020 17:22:07 -0700 (PDT) Received: from ninjahost.lan (host-2-102-15-144.as13285.net. [2.102.15.144]) by smtp.googlemail.com with ESMTPSA id w9sm35254337wrn.35.2020.03.11.17.22.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Mar 2020 17:22:06 -0700 (PDT) From: Jules Irenge To: boqun.feng@gmail.com Cc: linux-mm@kvack.org, akpm@linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/1] backing-dev: refactor wb_congested_put() Date: Thu, 12 Mar 2020 00:21:56 +0000 Message-Id: <20200312002156.49023-2-jbi.octave@gmail.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200312002156.49023-1-jbi.octave@gmail.com> References: <20200312002156.49023-1-jbi.octave@gmail.com> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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() Signed-off-by: Jules Irenge --- mm/backing-dev.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/mm/backing-dev.c b/mm/backing-dev.c index 62f05f605fb5..9d47c0b6a42c 100644 --- 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); } static void cgwb_release_workfn(struct work_struct *work)