Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755063AbbK3Vug (ORCPT ); Mon, 30 Nov 2015 16:50:36 -0500 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:23910 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752861AbbK3Vub (ORCPT ); Mon, 30 Nov 2015 16:50:31 -0500 Subject: Re: [PATCH] null_blk: use sector_div instead of do_div To: Arnd Bergmann , References: <3768541.ja0r6f0Odi@wuerfel> <4449032.oPBtpzlXyB@wuerfel> CC: Linus Torvalds , Matias Bjorling , Linux Kernel Mailing List From: Jens Axboe Message-ID: <565CC47E.9020209@fb.com> Date: Mon, 30 Nov 2015 14:49:50 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: <4449032.oPBtpzlXyB@wuerfel> Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [192.168.54.13] X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2015-11-30_06:,, signatures=0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1752 Lines: 37 On 11/27/2015 02:31 PM, Arnd Bergmann wrote: > 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. We can use the shift, but honestly, it's just setup code. For hot paths, avoiding the div is definitely of higher priority. And for the sake of people copy/pasting or similar, making it a shift is probably a good idea. -- Jens Axboe -- 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/