Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932470AbcLZVSz (ORCPT ); Mon, 26 Dec 2016 16:18:55 -0500 Received: from mail-lf0-f41.google.com ([209.85.215.41]:34567 "EHLO mail-lf0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932127AbcLZVSx (ORCPT ); Mon, 26 Dec 2016 16:18:53 -0500 From: Michal Nazarewicz To: Jaewon Kim , gregkh@linuxfoundation.org, akpm@linux-foundation.org Cc: labbott@redhat.com, m.szyprowski@samsung.com, gregory.0xf0@gmail.com, laurent.pinchart@ideasonboard.com, akinobu.mita@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, jaewon31.kim@gmail.com, Jaewon Kim Subject: Re: [PATCH] lib: bitmap: introduce bitmap_find_next_zero_area_and_size In-Reply-To: <1482725891-10866-1-git-send-email-jaewon31.kim@samsung.com> Organization: http://mina86.com/ References: <1482725891-10866-1-git-send-email-jaewon31.kim@samsung.com> User-Agent: Notmuch/0.19+53~g2e63a09 (http://notmuchmail.org) Emacs/26.0.50.2 (x86_64-unknown-linux-gnu) Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAJFBMVEWbfGlUPDDHgE57V0jUupKjgIObY0PLrom9mH4dFRK4gmjPs41MxjOgAAACP0lEQVQ4T23Sv2vbQBQHcBk1xE6WyALX107VUEgmn6+ouUwpEQQ6uRjttkWP4CkBg2M0BQLBdPFZYPsyFYo7qEtKDQ7on+t7+nF2Ux8ahD587717OmNYrOvycHsZ+o2r051wHTHysAvGb8ygvgu4QWT0sCmkgZCIEnlV2X8BtyraazFGDuxhmKSQJMlwHQ7v5MHSNxmz78rfElwAa3ieVD9e+hBhjaPDDG6NgFo2f4wBMNIo5YmRtF0RyDgFjJjlMIWbnuM4x9MMfABGTlN4qgIQB4A1DEyA1BHWtfeWNUMwiVJKoqh97KrkOO+qzgluVYLvFCUKAX73nONeBr7BGMdM6Sg0kuep03VywLaIzRiVr+GAzKlpQIsAFnWAG2e6DT5WmWDiudZMIc6hYrMOmeMQK9WX0B+/RfjzL9DI7Y9/Iayn29Ci0r2i4f9gMimMSZLCDMalgQGU5hnUtqAN0OGvEmO1Wnl0C0wWSCEHnuHBqmygxdxA8oWXwbipoc1EoNR9DqOpBpOJrnr0criQab9ZT4LL+wI+K7GBQH30CrhUruilgP9DRTrhVWZCiAyILP+wiuLeCKGTD6r/nc8LOJcAwR6IBTUs+7CASw3QFZ0MdA2PI3zNziH4ZKVhXCRMBjeZ1DWMekKwDCASwExy+NQ86TaykaDAFHO4aP48y4fIcDM5yOG8GcTLbOyp8A8azjJI93JFd1EA6yN8sSxMQJWoABqniRZVykYgRXErzrdqExAoUrRb0xfRp8p2A/4XmfilTtkDZ4cAAAAASUVORK5CYII= X-Face: -TR8(rDTHy/(xl?SfWd1|3:TTgDIatE^t'vop%*gVg[kn$t{EpK(P"VQ=~T2#ysNmJKN$"yTRLB4YQs$4{[.]Fc1)*O]3+XO^oXM>Q#b^ix,O)Zbn)q[y06$`e3?C)`CwR9y5riE=fv^X@x$y?D:XO6L&x4f-}}I4=VRNwiA^t1-ZrVK^07.Pi/57c_du'& X-PGP: 50751FF4 X-PGP-FP: AC1F 5F5C D418 88F8 CC84 5858 2060 4012 5075 1FF4 X-Hashcash: 1:20:161226:akpm@linux-foundation.org::TGXb/KP7YtTFbXg1:00000000000000000000000000000000000009M8 X-Hashcash: 1:20:161226:linux-kernel@vger.kernel.org::eL8p2zdoBtPqlOOo:0000000000000000000000000000000000YSL X-Hashcash: 1:20:161226:m.szyprowski@samsung.com::4V6cTnr+7KtsKhkf:00000000000000000000000000000000000000vws X-Hashcash: 1:20:161226:jaewon31.kim@samsung.com::heob76gy3AarlASV:00000000000000000000000000000000000000rmo X-Hashcash: 1:20:161226:labbott@redhat.com::7ZuX7O5iNN4hBGLU:00000000000000000000000000000000000000000001VT7 X-Hashcash: 1:20:161226:akinobu.mita@gmail.com::WHdFMfYpIqna1fth:0000000000000000000000000000000000000001qpu X-Hashcash: 1:20:161226:jaewon31.kim@gmail.com::Wqlcs+gBmydoiMMy:0000000000000000000000000000000000000001lel X-Hashcash: 1:20:161226:gregkh@linuxfoundation.org::vxaj7Xqmj/iBaoyp:000000000000000000000000000000000003Fum X-Hashcash: 1:20:161226:linux-mm@kvack.org::SAchiVASD9PeKhUe:00000000000000000000000000000000000000000002vns X-Hashcash: 1:20:161226:laurent.pinchart@ideasonboard.com::Ni6IMyjedu1j9jiB:000000000000000000000000000058WB X-Hashcash: 1:20:161226:jaewon31.kim@samsung.com::3aL2LMfe2XdazHRv:00000000000000000000000000000000000004lfK X-Hashcash: 1:20:161226:gregory.0xf0@gmail.com::AkhD5m5hklH2agMe:0000000000000000000000000000000000000006Uev Date: Mon, 26 Dec 2016 22:09:40 +0100 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by mail.home.local id uBQLJ44B031181 Content-Length: 3808 Lines: 113 On Mon, Dec 26 2016, Jaewon Kim wrote: > There was no bitmap API which returns both next zero index and size of zeros > from that index. Is it really needed? Does it noticeably simplifies callers? Why can’t caller get the size by themselves if they need it? > > This is helpful to look fragmentation. This is an test code to look size of zeros. > Test result is '10+9+994=>1013 found of total: 1024' > > unsigned long search_idx, found_idx, nr_found_tot; > unsigned long bitmap_max; > unsigned int nr_found; > unsigned long *bitmap; > > search_idx = nr_found_tot = 0; > bitmap_max = 1024; > bitmap = kzalloc(BITS_TO_LONGS(bitmap_max) * sizeof(long), > GFP_KERNEL); > > /* test bitmap_set offset, count */ > bitmap_set(bitmap, 10, 1); > bitmap_set(bitmap, 20, 10); > > for (;;) { > found_idx = bitmap_find_next_zero_area_and_size(bitmap, > bitmap_max, search_idx, &nr_found); > if (found_idx >= bitmap_max) > break; > if (nr_found_tot == 0) > printk("%u", nr_found); > else > printk("+%u", nr_found); > nr_found_tot += nr_found; > search_idx = found_idx + nr_found; > } > printk("=>%lu found of total: %lu\n", nr_found_tot, bitmap_max); > > Signed-off-by: Jaewon Kim > --- > include/linux/bitmap.h | 6 ++++++ > lib/bitmap.c | 25 +++++++++++++++++++++++++ > 2 files changed, 31 insertions(+) > > diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h > index 3b77588..b724a6c 100644 > --- a/include/linux/bitmap.h > +++ b/include/linux/bitmap.h > @@ -46,6 +46,7 @@ > * bitmap_clear(dst, pos, nbits) Clear specified bit area > * bitmap_find_next_zero_area(buf, len, pos, n, mask) Find bit free area > * bitmap_find_next_zero_area_off(buf, len, pos, n, mask) as above > + * bitmap_find_next_zero_area_and_size(buf, len, pos, n, mask) Find bit free area and its size > * bitmap_shift_right(dst, src, n, nbits) *dst = *src >> n > * bitmap_shift_left(dst, src, n, nbits) *dst = *src << n > * bitmap_remap(dst, src, old, new, nbits) *dst = map(old, new)(src) > @@ -123,6 +124,11 @@ extern unsigned long bitmap_find_next_zero_area_off(unsigned long *map, > unsigned long align_mask, > unsigned long align_offset); > > +extern unsigned long bitmap_find_next_zero_area_and_size(unsigned long *map, > + unsigned long size, > + unsigned long start, > + unsigned int *nr); > + > /** > * bitmap_find_next_zero_area - find a contiguous aligned zero area > * @map: The address to base the search on > diff --git a/lib/bitmap.c b/lib/bitmap.c > index 0b66f0e..d02817c 100644 > --- a/lib/bitmap.c > +++ b/lib/bitmap.c > @@ -332,6 +332,31 @@ unsigned long bitmap_find_next_zero_area_off(unsigned long *map, > } > EXPORT_SYMBOL(bitmap_find_next_zero_area_off); > > +/** > + * bitmap_find_next_zero_area_and_size - find a contiguous aligned zero area > + * @map: The address to base the search on > + * @size: The bitmap size in bits > + * @start: The bitnumber to start searching at > + * @nr: The number of zeroed bits we've found > + */ > +unsigned long bitmap_find_next_zero_area_and_size(unsigned long *map, > + unsigned long size, > + unsigned long start, > + unsigned int *nr) > +{ > + unsigned long index, i; > + > + *nr = 0; > + index = find_next_zero_bit(map, size, start); > + > + if (index >= size) > + return index; > + i = find_next_bit(map, size, index); > + *nr = i - index; > + return index; > +} > +EXPORT_SYMBOL(bitmap_find_next_zero_area_and_size); > + > /* > * Bitmap printing & parsing functions: first version by Nadia Yvette Chambers, > * second version by Paul Jackson, third by Joe Korty. > -- > 1.9.1 > -- Best regards ミハウ “????????????????86” ナザレヴイツ «If at first you don’t succeed, give up skydiving»