Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1551727pxu; Sat, 5 Dec 2020 22:53:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJxbB/V795aKjQWHrE+6toa6HZ4aeteUaf+vqMrQXducaa48UWhG1fy+eKiMeS7s63EhRqI6 X-Received: by 2002:a50:9f4a:: with SMTP id b68mr14662492edf.296.1607237633483; Sat, 05 Dec 2020 22:53:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607237633; cv=none; d=google.com; s=arc-20160816; b=1HlcMMB3eVrqk8HdEpFUiJVos3arCaNtYKSFFToMDJUAGnYDH+CizKVnzKa4zvVPMx LNKq+SE+dYi1ntxEAsUxFJFq+HuJwJMeT5r4Rbc4rvyeHVP2OMvAXEg2VlFaOuG/Ricb pDJPcgb/SECWAKXC87HTjc6icv1jYvZH1sa/KF7AOrZj31rQhnRM5o4xfZ2T6n8sqHnk ikagfWoCeJLqX4mqll5AGETGUPV9P8wqqGTm6Wa/JK6jkpFEgCxPbaL0JpyBtyauBXGY qUur32BaLzuQr5UlbLmFi570sQjiDt/IsV7BOE2u225wLaIlzhD1B+aRgUjG045ZE+a1 yfhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=ypwZ5TJczitF9QTNYb1eQHpigAlJXUjONalTOOQxjJo=; b=McY8OzNuUGSJOrtKByex30wbZvlWyZazlT1Ree9q7GcP4c159Sb4tNTnL/iZH5jRZ3 wu73aUeueTaijPMqUyrJKg+/bI7najpExSfyfxgZxFG+EUJz4YcSndEXyjQAqtDq3Nsy XWQoebJ2UJxr8ymxWSW6/G1kpqjDLeEIqBdfwPGzLIpi4VW1/Ty0mrkQ0bGjSPOFChQP hWC6pZU+I5sSNW7bE6YtAYIByBnoQciM3A90jqIrwxxrPpLxKFyuaABDdaNMUi5/k4Xw CIeWSR1zgYEGx32lj8TrkvS7c4tqQcsgkvDDk9fXt+FZTvHiDdlcWw1L2/OA85nIuauD jUSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=WrIclN8u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t14si6331764edy.67.2020.12.05.22.53.30; Sat, 05 Dec 2020 22:53:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=WrIclN8u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726456AbgLFGuz (ORCPT + 99 others); Sun, 6 Dec 2020 01:50:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725945AbgLFGuy (ORCPT ); Sun, 6 Dec 2020 01:50:54 -0500 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4DECDC0613D1; Sat, 5 Dec 2020 22:50:14 -0800 (PST) Received: by mail-pf1-x441.google.com with SMTP id t7so6834790pfh.7; Sat, 05 Dec 2020 22:50:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition; bh=ypwZ5TJczitF9QTNYb1eQHpigAlJXUjONalTOOQxjJo=; b=WrIclN8u3gJc5aASq2lzZyklgOq9xNWCLtUJH0+9GnBkfEdGqTX0/S1+JuClS02CvS VnTH8WxR0zfyPLUGvor+Gw2FatWRT7JIGjvd4q/YBySUzxX/Jdkm69wRWittEAviR/5c Dj77Jmx2plHcbkp/jr4LOH3ici6sKcY2Vg7oHiFfl2+vdQUiqCn9Qiiq0h8TyKB1P3ct 25ACCGcJViDv08IPCroseyURIxZDB1q75qwFZaMyXyHl0UsxpfQssS8GxrKaT7iC4HRH zUgp7kTMOgc58s9KeS+/CUVqwxzsQWYhPXiZyuyvUDbRzvgl9pdUV3E2ux9F+i4guvJ5 kMsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=ypwZ5TJczitF9QTNYb1eQHpigAlJXUjONalTOOQxjJo=; b=Z/r14tMAuS0SXRcIKyzYJlnh71PAEZjZQtJdJBBleeXnLnKaNhVWz5rNZDdFrJFo8i /dQmcZWgwYZmygL0tOvt6bvsBGbEoISJ4iPQT9AqbMRnrr+Y0XtzsiL0hfJ0XvZhcaEn jX0UnzEeMsSeQ1Rx4wCg7fNyM9yYIs2sZUKxOgYQdYlPQ4CDGuzLqc5Ow7Ka7qUndaWD vg2UK+5aTsKRveXBRUbkjUmAvOsO0cwVfs2TENij22DTbEBPrqM9srVRFYn64hXV8gJl 2WFo0mleQ4F4XW2/lSCdQMFrJI+JhWnfvVEW58dQ79tpUyUIGeWih7XA2VxsXreMLXqt 3Ufw== X-Gm-Message-State: AOAM5326T+877Kd836gPqQVRMgDr+PtvFlts/x7WfDq1BknNbTujY0hM tMD4JqqrgplO+10q+YsW8oA= X-Received: by 2002:a63:1456:: with SMTP id 22mr14010264pgu.108.1607237413841; Sat, 05 Dec 2020 22:50:13 -0800 (PST) Received: from ubuntu ([211.226.85.205]) by smtp.gmail.com with ESMTPSA id 21sm2007441pfx.84.2020.12.05.22.50.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2020 22:50:13 -0800 (PST) Date: Sun, 6 Dec 2020 15:50:04 +0900 From: Levi Yun To: akpm@linux-foundation.org, yury.norov@gmail.com, andriy.shevchenko@linux.intel.com, richard.weiyang@linux.alibaba.com, christian.brauner@ubuntu.com, arnd@arndb.de, jpoimboe@redhat.com, changbin.du@intel.com, rdunlap@infradead.org, masahiroy@kernel.org, gregkh@linuxfoundation.org, peterz@infradead.org, peter.enderborg@sony.com, krzk@kernel.org, brendanhiggins@google.com, keescook@chromium.org, broonie@kernel.org, matti.vaittinen@fi.rohmeurope.com, mhiramat@kernel.org, jpa@git.mail.kapsi.fi, nivedita@alum.mit.edu, glider@google.com, orson.zhai@unisoc.com, takahiro.akashi@linaro.org, clm@fb.com, josef@toxicpanda.com, dsterba@suse.com, dushistov@mail.ru Cc: linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, linux-btrfs@vger.kernel.org Subject: [PATCH v2 7/8] btrfs/free-space-cache.c: Apply find_last_zero_bit Message-ID: <20201206065004.GA6321@ubuntu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In steal_from_bitmap_to_front function, it finds last_zero_bit from i using for_each_clear_bit. But this makes some overhead that it starts from the 0 bit. By adding find_last_zero_bit, I try to remove this overhead and improve readibility. Signed-off-by: Levi Yun --- fs/btrfs/free-space-cache.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index af0013d3df63..6d393c834fdd 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c @@ -2372,7 +2372,6 @@ static bool steal_from_bitmap_to_front(struct btrfs_free_space_ctl *ctl, u64 bitmap_offset; unsigned long i; unsigned long j; - unsigned long prev_j; u64 bytes; bitmap_offset = offset_to_bitmap(ctl, info->offset); @@ -2388,20 +2387,15 @@ static bool steal_from_bitmap_to_front(struct btrfs_free_space_ctl *ctl, return false; i = offset_to_bit(bitmap->offset, ctl->unit, info->offset) - 1; - j = 0; - prev_j = (unsigned long)-1; - for_each_clear_bit_from(j, bitmap->bitmap, BITS_PER_BITMAP) { - if (j > i) - break; - prev_j = j; - } - if (prev_j == i) - return false; + j = find_last_zero_bit(bitmap->bitmap, i); - if (prev_j == (unsigned long)-1) - bytes = (i + 1) * ctl->unit; - else - bytes = (i - prev_j) * ctl->unit; + if (j == i) { + if (!test_bit(i, bitmap->bitmap)) + return false; + else + bytes = (i + 1) * ctl->unit; + } else + bytes = (i - j) * ctl->unit; info->offset -= bytes; info->bytes += bytes; -- 2.27.0