Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp527305ybl; Wed, 21 Aug 2019 01:14:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqxf8IfUskeBw2kGklsgQaWPottWFd4MLB0o5HpRMoEwaJ4WLBzqj/Sy0Ph82Klrj9u1JXLA X-Received: by 2002:a17:902:1122:: with SMTP id d31mr33212149pla.254.1566375252958; Wed, 21 Aug 2019 01:14:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566375252; cv=none; d=google.com; s=arc-20160816; b=EI31rbdfKltZQfRbHYsSpiL2Rekq005gGnFoD7ovwSo5P6PMyLSqVXpAHuwsAn8/ON M1Bn6L84YkNzhW2ZeEJ4asUIguyDP2bNnFKirryMMYO2+QCDeTcq5XuufIwu9CLu8CB5 nyVzFyNTbREm+D+x7Bl+XyGEvwbICVAm+hbDUvwmm3eviU5ScCrIr6Morm9lHoNaCtX+ M0OmaCbZJF3n2l0Rwe9otYS7KOHcPATddHGiAc/AsKPc+xmp1lClUiL5awbQBSxl/RkS 12dFGI36U2v3JbDiHBDQjxi6+jqEaUWdaoSLMobEShbbp3O3JH6RkTEF/9i2oSrVt54M neOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=Ja/pmYIUnyU3y2pFVv+8VV4pdMbpmk85WiIzqI8rfuE=; b=1A5rQYcMCiRX5e1fUdGmKgrpBfX2rssNnuLwN+ANQ9tSZkYZMkBR4ZnrEFD9qo3eYU D6JZMjDftSIz+0kjcRDqoGcuAGvzdVE8qvcwQ2ywB+MR3SZ3njCxqL6+VJJmK9nqEqd3 4C5UdTDCKePm8omwc5kqtqVmApjSG911IYIOEPoTnh1ZFdZu1QFDVUih4g8p8V/38au2 r0/XHzSn6vmY/rTvN0gjzzlbMlWBZevjby61jFs1a1+VR5NR1uylmYkrdD730U/HSclX uRyA2Z3iMCpnzX2yV0SaHmPGyRgz/vV/jqn/7XX760ak1EcdBrXZoTkq/4jE0qs9Iewc wtQw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id gn9si14331930plb.33.2019.08.21.01.13.57; Wed, 21 Aug 2019 01:14:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726437AbfHUHuE (ORCPT + 99 others); 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 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 -- 2.21.0