From patchwork Wed Jun 7 00:58:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timofey Titovets X-Patchwork-Id: 9770395 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 25FE460393 for ; Wed, 7 Jun 2017 01:00:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0842627E63 for ; Wed, 7 Jun 2017 01:00:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F1374284A8; Wed, 7 Jun 2017 01:00:19 +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=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2B35728528 for ; Wed, 7 Jun 2017 01:00:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751463AbdFGBAG (ORCPT ); Tue, 6 Jun 2017 21:00:06 -0400 Received: from mail-wr0-f196.google.com ([209.85.128.196]:35628 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751437AbdFGBAE (ORCPT ); Tue, 6 Jun 2017 21:00:04 -0400 Received: by mail-wr0-f196.google.com with SMTP id g76so11546681wrd.2 for ; Tue, 06 Jun 2017 18:00:03 -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; bh=lHiY5iE4ymLiaxdpHBgM77V8GvdLaCiMB7LhU5Y2eKo=; b=TJGNUNecZFfSXLjLQxJfIJTPDwlnF/2pAXayBS66v8JWtOjMNFACDrzEd/mBPy1I0R oXV+WOOldTpSvx+RBjpxoaNnQLJ9sw/02KjYBtA3sP+pph3RcFtJmxxyTGpbP0qsRDiG XKVQCxSs8DotYvpit3FoGsl27qgVJP/ie6IwomGMQxk22lS6SKUPA2v0wWUdME7DiaqV wYjCt/gfh4OrJrbq4s2NjvO0VaUD5/Eu4YAMPmfb2mSmL11QOmAQFVxfe0mT5Oym0UYS AGBhf90nqT6rdUOxEV2is7j0DCtNaUWjnhLkCVoLgEzf5IKd2DsuHIVmammW7jxH+FJE ywag== 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; bh=lHiY5iE4ymLiaxdpHBgM77V8GvdLaCiMB7LhU5Y2eKo=; b=U68CgD0W+x7bel2W2BZevPRbZRHPGRprzl7vvUF3ay2+BLMx4MvSV7ohhfn54x7P8i RUtlnY4VcUcNYoISRaPi2nx3C0+x0UNbEmP4alpSq55gruLdYSya3HLxdqMkFipgdxIn w53yaPHHTmWtV5KU8KcJZK5J9QYoP1uhr8XKWFxsJujAgZW+jfU21Hl8BeVhHqKORqSH uVWe6la069h2rGd83BuZpxMHBzJbqZRPFmKSh82PJieKTVkwDwRWMPvCGExwCw9yRoCp rUkZKKVrkCj9uU+/eQadFI1QW4RZcO8hkk3ssZpxlUzGbcHyTfc20Shyc6Y7MWQp0OdZ IQ/w== X-Gm-Message-State: AODbwcDm7kOdz0DiR2lqXCgR2xldVn4pEC47tTjSxlj46/R0ZxuwUhx5 u3hn2Y72xEk6sMKx X-Received: by 10.223.130.199 with SMTP id 65mr19483305wrc.150.1496797202530; Tue, 06 Jun 2017 18:00:02 -0700 (PDT) Received: from localhost.localdomain ([91.215.176.151]) by smtp.gmail.com with ESMTPSA id q16sm338101wmg.2.2017.06.06.18.00.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Jun 2017 18:00:01 -0700 (PDT) From: Timofey Titovets To: linux-btrfs@vger.kernel.org Cc: Timofey Titovets Subject: [PATCH 1/7] Btrfs: __compare_inode_defrag decrease max compare count Date: Wed, 7 Jun 2017 03:58:38 +0300 Message-Id: <20170607005844.2078-2-nefelim4ag@gmail.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170607005844.2078-1-nefelim4ag@gmail.com> References: <20170607005844.2078-1-nefelim4ag@gmail.com> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In worst case code do 4 comparison, just add some new checks to switch check branch faster now in worst case code do 3 comparison Signed-off-by: Timofey Titovets --- fs/btrfs/file.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index da1096eb1..39efda26c 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -71,16 +71,17 @@ struct inode_defrag { static int __compare_inode_defrag(struct inode_defrag *defrag1, struct inode_defrag *defrag2) { - if (defrag1->root > defrag2->root) - return 1; - else if (defrag1->root < defrag2->root) + if (defrag1->root != defrag2->root) { + if (defrag1->root > defrag2->root) + return 1; return -1; - else if (defrag1->ino > defrag2->ino) - return 1; - else if (defrag1->ino < defrag2->ino) + } + if (defrag1->ino != defrag2->ino) { + if (defrag1->ino > defrag2->ino) + return 1; return -1; - else - return 0; + } + return 0; } /* pop a record for an inode into the defrag tree. The lock