From patchwork Wed Aug 21 07:42:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Efremov X-Patchwork-Id: 11105857 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 6FB30184E for ; Wed, 21 Aug 2019 07:50:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4F039233FE for ; Wed, 21 Aug 2019 07:50:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726389AbfHUHuE (ORCPT ); Wed, 21 Aug 2019 03:50:04 -0400 Received: from mail.ispras.ru ([83.149.199.45]:50720 "EHLO mail.ispras.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726028AbfHUHuE (ORCPT ); Wed, 21 Aug 2019 03:50:04 -0400 X-Greylist: delayed 459 seconds by postgrey-1.27 at vger.kernel.org; Wed, 21 Aug 2019 03:50:03 EDT Received: from localhost.localdomain (broadband-188-32-48-208.ip.moscow.rt.ru [188.32.48.208]) by mail.ispras.ru (Postfix) with ESMTPSA id 1679B540081; Wed, 21 Aug 2019 10:42:23 +0300 (MSK) From: Denis Efremov To: akpm@linux-foundation.org Cc: Denis Efremov , Akinobu Mita , Jan Kara , Matthew Wilcox , linux-kernel@vger.kernel.org, dm-devel@redhat.com, linux-fsdevel@vger.kernel.org, linux-media@vger.kernel.org, Erdem Tumurov , Vladimir Shelekhov Subject: [PATCH] lib/memweight.c: optimize by inlining bitmap_weight() Date: Wed, 21 Aug 2019 10:42:00 +0300 Message-Id: <20190821074200.2203-1-efremov@ispras.ru> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org This patch inlines bitmap_weight() call. Thus, removing the BUG_ON, and 'longs to bits -> bits to longs' conversion by directly calling hweight_long(). ./scripts/bloat-o-meter lib/memweight.o.old lib/memweight.o.new add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-10 (-10) Function old new delta memweight 162 152 -10 Co-developed-by: Erdem Tumurov Co-developed-by: Vladimir Shelekhov Signed-off-by: Erdem Tumurov Signed-off-by: Vladimir Shelekhov Signed-off-by: Denis Efremov --- lib/memweight.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/memweight.c b/lib/memweight.c index 94dd72ccaa7f..f050b2b4c5e2 100644 --- a/lib/memweight.c +++ b/lib/memweight.c @@ -20,11 +20,13 @@ size_t memweight(const void *ptr, size_t bytes) longs = bytes / sizeof(long); if (longs) { - BUG_ON(longs >= INT_MAX / BITS_PER_LONG); - ret += bitmap_weight((unsigned long *)bitmap, - longs * BITS_PER_LONG); + const unsigned long *bitmap_long = + (const unsigned long *)bitmap; + bytes -= longs * sizeof(long); - bitmap += longs * sizeof(long); + for (; longs > 0; longs--, bitmap_long++) + ret += hweight_long(*bitmap_long); + bitmap = (const unsigned char *)bitmap_long; } /* * The reason that this last loop is distinct from the preceding