Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755564AbbK0VcR (ORCPT ); Fri, 27 Nov 2015 16:32:17 -0500 Received: from mout.kundenserver.de ([212.227.126.187]:64760 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755307AbbK0Vb6 (ORCPT ); Fri, 27 Nov 2015 16:31:58 -0500 From: Arnd Bergmann To: linux-arm-kernel@lists.infradead.org Cc: Linus Torvalds , Jens Axboe , Matias Bjorling , Linux Kernel Mailing List Subject: Re: [PATCH] null_blk: use sector_div instead of do_div Date: Fri, 27 Nov 2015 22:31:26 +0100 Message-ID: <4449032.oPBtpzlXyB@wuerfel> User-Agent: KMail/4.11.5 (Linux/3.16.0-10-generic; KDE/4.11.5; x86_64; ; ) In-Reply-To: References: <3768541.ja0r6f0Odi@wuerfel> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Provags-ID: V03:K0:3UvOirtU1yD6JGvqZ1cDAaBzmGXPTwmHkMJyQzWgDc0RFtK96h2 wY9y9UYqH5Wh6mFZEur+DNlawWr8+reZSuGqUCSk4wT41FUkyKS9abdMXORcg9bqBa9BP7P QWncJo7BYs0r8doXQhALFoVTB5NBCY84yj3UslBU89yF6iezc2quiwR0WWlBGxu9UoFexqK f4HMlVaLIENKhh0tLsmmA== X-UI-Out-Filterresults: notjunk:1;V01:K0:U7EBPG6ro8E=:Vd2BoSQJn1AX2jmKQBP3tb EeMQVcj5JLQufddld+qpuxAotrONUkCBumK0dP3lnoJaJH/4izYY5BV3+z2Kx4sJ43OTL1v1U OX2Fq7EfrscMWKKwiv+difftr5aGNNTKRvzzK0+wv5TdOxlVdqiHoF/VZd2ps5rGOAjbkRdB3 q61amC9ccDnywzN9UAnIScNBgbpV+3XtnsgUlDyUyIquFh1MJjsco5/g3F3jaGg3yj6V/Gcfk 3C49OlZ9xMATPbHl8TROkTdgOMVyM1ODhVmYpc3dVS4/3Tc5NyEVKwwHWxHMGoZ4p753mXINz r9ByHV2qv9wHb6ZjKsWCyfcB14i6aDGVT/Rspd3SnQGQuVN6G78mox4DMJdScW6BVMWHL3+UQ ETHp2yFRKrqFN+ilOtPps59SDn5F/TD4uVKr4KwYeGJVyBR9ccVnkdSPUHC7Y0b+FMfaADZy0 mO6M5aE6ouJ2c+isXd4RAbWu6W+ZLgAbyRcaFZhhzb6yk44fsQvRfv8D2OI3NE8GJFWBiyCDm dZTkKUgM8/HiugT2Bm9OgFt5ULZIUL7rZqQpHLKX37qnZN8rFxbPVstqZaihhY2c/ErUfOQW3 kLyLyNBYYP+4GbxDu29C7iQCtUHoZBnPTeTGePGhFvOA4+vko5/B+RM+/4OTvaj06qjgfDzw2 4aLHJUQ1LgWQYrHm5X53VB5v6Ih4s+XgUMbFP/Cgxlh572bbxUv/9ai4KRWRqar+AqNSOpx4W 4gD8BKz26WqgDcbV Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2151 Lines: 52 On Friday 27 November 2015 10:07:54 Linus Torvalds wrote: > On Fri, Nov 27, 2015 at 5:49 AM, Arnd Bergmann wrote: > > - do_div(size, bs); /* convert size to pages */ > > - do_div(size, 256); /* concert size to pgs pr blk */ > > + sector_div(size, bs); /* convert size to pages */ > > + sector_div(size, 256); /* concert size to pgs pr blk */ > > Ugh. > > Dividing by 256 should never be done with do_div() *or* sector-div. You are right, I missed what should have been an obvious simplification. FWIW, the division by 256 should now be optimized automatically when the new asm-generic do_div() implementation is used (which in turn caused the type mismatch warning that I'm trying to avoid). Of course that is no excuse for writing silly code like that, and it doesn't catch the cases where the argument is a power-of-two variable number. The first do_div() is also questionable: 'bs' is a global variable from a module parameter that defaults to 512 and is fixed to 4096 when the device is used for lightnvm. I would guess that we run into bugs if this is ever set to a number that is not a power of two, smaller than 512, or larger than PAGE_SIZE. > Same goes for this, which is just obnoxiously idiotic: > > > - do_div(size, (1 << 16)); > > + sector_div(size, (1 << 16)); > > WTF? It explicitly divides by a particular power-of-two? > > Has nobody ever heard of expensive divide operations? Sure, for the > cases where we *don't* do this with inline asm etc because it's > already fairly cheap, the compiler will DTRT. But that "divide by (1 > << 16)" is just a sign of insanity. > > Why is that not just > > size >>= 16; > > instead, which is certainly not any less legible, and won't generate > potentially crap code? I'll wait for Matias or Jens to comment on the blocksize, but can do a new patch unless they beat me to it. Arnd -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/