Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1280328
| From | Jens Axboe <axboe@fb.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH] null_blk: use sector_div instead of do_div |
| Date | 2015-11-30 23:00 +0100 |
| Message-ID | <qAEEh-FH-11@gated-at.bofh.it> (permalink) |
| References | <qzrJ8-3Bb-3@gated-at.bofh.it> <qzvD4-6jW-15@gated-at.bofh.it> <qzyUi-8cQ-31@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
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 <arnd@arndb.de> 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/
Back to linux.kernel | Previous | Next — Previous in thread | Find similar | Unroll thread
[PATCH] null_blk: use sector_div instead of do_div Arnd Bergmann <arnd@arndb.de> - 2015-11-27 15:00 +0100
Re: [PATCH] null_blk: use sector_div instead of do_div Linus Torvalds <torvalds@linux-foundation.org> - 2015-11-27 19:10 +0100
Re: [PATCH] null_blk: use sector_div instead of do_div Arnd Bergmann <arnd@arndb.de> - 2015-11-27 22:40 +0100
Re: [PATCH] null_blk: use sector_div instead of do_div Matias Bjørling <m@bjorling.me> - 2015-11-28 09:10 +0100
Re: [PATCH] null_blk: use sector_div instead of do_div Jens Axboe <axboe@fb.com> - 2015-11-30 23:00 +0100
csiph-web