From patchwork Thu Apr 25 13:31:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huaisheng Ye X-Patchwork-Id: 10918903 X-Patchwork-Delegate: snitzer@redhat.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E18EA933 for ; Fri, 26 Apr 2019 08:50:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CFC9328DA5 for ; Fri, 26 Apr 2019 08:50:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C420128DA7; Fri, 26 Apr 2019 08:50:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6A14528DA5 for ; Fri, 26 Apr 2019 08:50:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B1EACCF4AF; Fri, 26 Apr 2019 08:50:23 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8E05F60F8E; Fri, 26 Apr 2019 08:50:23 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 55D023FB14; Fri, 26 Apr 2019 08:50:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x3PDWeY2012755 for ; Thu, 25 Apr 2019 09:32:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id 97CB25C652; Thu, 25 Apr 2019 13:32:40 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx18.extmail.prod.ext.phx2.redhat.com [10.5.110.47]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1CCD161D34; Thu, 25 Apr 2019 13:32:33 +0000 (UTC) Received: from sender4-pp-o95.zoho.com (sender4-pp-o95.zoho.com [136.143.188.95]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C71DC308B798; Thu, 25 Apr 2019 13:32:24 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; t=1556199127; cv=none; d=zoho.com; s=zohoarc; b=a6S501wnq0WxXo5JP1mk9blEP9wWdxvfLkrAgJ4PBLcYoDgejfkStul6vH8IEyXTAYtjRyMJTYev6i3MULyHzMOoGzM6ap7e4jyOBls9FG68ShRKxyGhMETU7ucTipHhNI4OzfyJyKRsMMjWKi1VsnMEJe3JwWvw0zVous7Xdhw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556199127; h=Cc:Date:From:In-Reply-To:Message-ID:References:Subject:To:ARC-Authentication-Results; bh=FyEDAx0dBD84M+NBbPh51XO5Ixmi4K5yOWlO3BekT1Y=; b=Cr9MfuwQxdAUqwurmo/vWNXgs47vuYDp8xTbwj4rMqiRkMp64lgIvMOGZCrBcw6HulFpEezubEDD7R+vHVmdv80XjH66yiPgZLKdLRnLoxcXYZjWuru+vNYSubyZOdvhZgxuEC9Hn0DZ90LHHrQGAYA+wjFbObRs+QrNKyHZDPs= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass header.i=zoho.com; spf=pass smtp.mailfrom=yehs2007@zoho.com; dmarc=pass header.from= header.from= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=zapps768; d=zoho.com; h=from:to:cc:subject:date:message-id:in-reply-to:references; b=oOlHQabxwPZPe9eqdhl78i9rU5RXbSUKXrUvLgT9IpL2SQ8gT0Uv3YpRlYAeMOUrdltC8EzjZ9cs dym2llJBlXdT0YcaRklsbtWT7Qb95guYkMYFR9vssHr46nm7CDLl DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1556199127; s=default; d=zoho.com; i=yehs2007@zoho.com; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; l=1206; bh=FyEDAx0dBD84M+NBbPh51XO5Ixmi4K5yOWlO3BekT1Y=; b=BtkK5IuR3pAUKiy/7blmxkaebOjFjTgHK+ADvGv4dpgPlT2f0pf4o8p3BZBnCXN3 qxXKmY+JkJIqB4cC9VgrndqyNld/ma8aIpVsB4Vwkir2nGi/DFpEd6TKm7oD/G39bSd eNDAeSDfl/HCRg9d2QT8boqWDJHkoZunFB3YS5Wc= Received: from YEHS1XR3054QMS.lenovo.com (123.120.108.196 [123.120.108.196]) by mx.zohomail.com with SMTPS id 155619912704786.25566430035269; Thu, 25 Apr 2019 06:32:07 -0700 (PDT) From: Huaisheng Ye To: mpatocka@redhat.com, snitzer@redhat.com, agk@redhat.com Date: Thu, 25 Apr 2019 21:31:18 +0800 Message-Id: <20190425133120.13088-3-yehs2007@zoho.com> In-Reply-To: <20190425133120.13088-1-yehs2007@zoho.com> References: <20190425133120.13088-1-yehs2007@zoho.com> X-ZohoMailClient: External X-Greylist: Sender passed SPF test, ACL 242 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Thu, 25 Apr 2019 13:32:25 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Thu, 25 Apr 2019 13:32:25 +0000 (UTC) for IP:'136.143.188.95' DOMAIN:'sender4-pp-o95.zoho.com' HELO:'sender4-pp-o95.zoho.com' FROM:'yehs2007@zoho.com' RCPT:'' X-RedHat-Spam-Score: 0.14 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_PASS) 136.143.188.95 sender4-pp-o95.zoho.com 136.143.188.95 sender4-pp-o95.zoho.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.47 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: dm-devel@redhat.com X-Mailman-Approved-At: Fri, 26 Apr 2019 04:49:58 -0400 Cc: prarit@redhat.com, chengnt@lenovo.com, dm-devel@redhat.com, linux-kernel@vger.kernel.org, Huaisheng Ye Subject: [dm-devel] [PATCH v2 2/4] dm writecache: add unlikely for returned value of rb_next/prev X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 26 Apr 2019 08:50:24 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP From: Huaisheng Ye In functions writecache_discard() and writecache_find_entry() there is a high probablity that the pointer of structure rb_node won't equal NULL. Add unlikely for the pointer node NULL. Signed-off-by: Huaisheng Ye Acked-by: Mikulas Patocka Signed-off-by: Mike Snitzer --- drivers/md/dm-writecache.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/md/dm-writecache.c b/drivers/md/dm-writecache.c index 5b4d1c1..cfbbfbc 100644 --- a/drivers/md/dm-writecache.c +++ b/drivers/md/dm-writecache.c @@ -571,7 +571,7 @@ static struct wc_entry *writecache_find_entry(struct dm_writecache *wc, node = rb_prev(&e->rb_node); else node = rb_next(&e->rb_node); - if (!node) + if (unlikely(!node)) return e; e2 = container_of(node, struct wc_entry, rb_node); if (read_original_sector(wc, e2) != block) @@ -804,7 +804,7 @@ static void writecache_discard(struct dm_writecache *wc, sector_t start, sector_ writecache_free_entry(wc, e); } - if (!node) + if (unlikely(!node)) break; e = container_of(node, struct wc_entry, rb_node);