From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751068AbcL1OOY (ORCPT ); Wed, 28 Dec 2016 09:14:24 -0500 Received: from mail-lf0-f50.google.com ([209.85.215.50]:35622 "EHLO mail-lf0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750870AbcL1OOW (ORCPT ); Wed, 28 Dec 2016 09:14:22 -0500 From: Michal Nazarewicz To: Jaewon Kim , Michal Hocko Cc: gregkh@linuxfoundation.org, akpm@linux-foundation.org, 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 Subject: Re: [PATCH] lib: bitmap: introduce bitmap_find_next_zero_area_and_size In-Reply-To: <58634274.5060205@samsung.com> Organization: http://mina86.com/ References: <1482725891-10866-1-git-send-email-jaewon31.kim@samsung.com> <20161227100535.GB7662@dhcp22.suse.cz> <58634274.5060205@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:161228:linux-mm@kvack.org::a4tejJJkh5Bd9824:00000000000000000000000000000000000000000000pra X-Hashcash: 1:20:161228:akinobu.mita@gmail.com::vMlWUZ1azl1eENMC:0000000000000000000000000000000000000000m28 X-Hashcash: 1:20:161228:gregory.0xf0@gmail.com::gbxJW7sRatPGdy6I:0000000000000000000000000000000000000000dd5 X-Hashcash: 1:20:161228:m.szyprowski@samsung.com::rWDA6nPjgevun3Zo:00000000000000000000000000000000000000yRj X-Hashcash: 1:20:161228:jaewon31.kim@gmail.com::D11IK0mr6IqvL17s:0000000000000000000000000000000000000001EZt X-Hashcash: 1:20:161228:jaewon31.kim@samsung.com::Yk9fSIlLd2MPC2pk:00000000000000000000000000000000000001TfJ X-Hashcash: 1:20:161228:labbott@redhat.com::b7ioTbsy9ue0N2xg:00000000000000000000000000000000000000000002EEr X-Hashcash: 1:20:161228:laurent.pinchart@ideasonboard.com::CpM9+VX5ZX8ZJ8Qf:00000000000000000000000000002ZWK X-Hashcash: 1:20:161228:linux-kernel@vger.kernel.org::KY9+tcF+v5py4mZC:00000000000000000000000000000000043IT X-Hashcash: 1:20:161228:akpm@linux-foundation.org::MTBtbZQyMXQrp1C/:00000000000000000000000000000000000052Wh X-Hashcash: 1:20:161228:mhocko@kernel.org::IOqUyePJ2xhp+xFP:000000000000000000000000000000000000000000007Uhh X-Hashcash: 1:20:161228:gregkh@linuxfoundation.org::f2KlD2nO8cNGeeDd:00000000000000000000000000000000000Hx7E Date: Wed, 28 Dec 2016 15:14:06 +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 uBSEES2x014887 On Wed, Dec 28 2016, Jaewon Kim wrote: > I did not add caller in this patch. > I am using the patch in cma_alloc function like below to show > available page status. > > + printk("number of available pages: "); > + start = 0; > + for (;;) { > + bitmap_no = bitmap_find_next_zero_area_and_size(cma->bitmap, > + cma->count, start, &nr); > + if (bitmap_no >= cma->count) > + break; > + if (nr_total == 0) > + printk("%u", nr); > + else > + printk("+%u", nr); > + nr_total += nr; > + start = bitmap_no + nr; > + } > + printk("=>%u pages, total: %lu pages\n", nr_total, cma->count); I would be happier should you find other existing places where this function can be used. With just one caller, I’m not convinced it is worth it. >>> Signed-off-by: Jaewon Kim The code itself is good, so Acked-by: Michal Nazarewicz and I’ll leave deciding whether it improves the kernel overall to maintainers. ;) >>> --- >>> 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 would remove this check. find_next_bit handles situation when index == size and without this early return, *nr is always set. >>> + 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 >>> >>> -- >>> To unsubscribe, send a message with 'unsubscribe linux-mm' in >>> the body to majordomo@kvack.org. For more info on Linux MM, >>> see: http://www.linux-mm.org/ . >>> Don't email: email@kvack.org > -- Best regards ミハウ “𝓶𝓲𝓷𝓪86” ナザレヴイツ «If at first you don’t succeed, give up skydiving» From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf0-f72.google.com (mail-lf0-f72.google.com [209.85.215.72]) by kanga.kvack.org (Postfix) with ESMTP id 97A096B025E for ; Wed, 28 Dec 2016 09:14:13 -0500 (EST) Received: by mail-lf0-f72.google.com with SMTP id c13so127760199lfg.4 for ; Wed, 28 Dec 2016 06:14:13 -0800 (PST) Received: from mail-lf0-x22a.google.com (mail-lf0-x22a.google.com. [2a00:1450:4010:c07::22a]) by mx.google.com with ESMTPS id 9si29100809lji.85.2016.12.28.06.14.11 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Dec 2016 06:14:11 -0800 (PST) Received: by mail-lf0-x22a.google.com with SMTP id b14so204961102lfg.2 for ; Wed, 28 Dec 2016 06:14:11 -0800 (PST) From: Michal Nazarewicz Subject: Re: [PATCH] lib: bitmap: introduce bitmap_find_next_zero_area_and_size In-Reply-To: <58634274.5060205@samsung.com> References: <1482725891-10866-1-git-send-email-jaewon31.kim@samsung.com> <20161227100535.GB7662@dhcp22.suse.cz> <58634274.5060205@samsung.com> Date: Wed, 28 Dec 2016 15:14:06 +0100 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Sender: owner-linux-mm@kvack.org List-ID: To: Jaewon Kim , Michal Hocko Cc: gregkh@linuxfoundation.org, akpm@linux-foundation.org, 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 On Wed, Dec 28 2016, Jaewon Kim wrote: > I did not add caller in this patch. > I am using the patch in cma_alloc function like below to show > available page status. > > + printk("number of available pages: "); > + start =3D 0; > + for (;;) { > + bitmap_no =3D bitmap_find_next_zero_area_and_size= (cma->bitmap, > + cma->count, start, &nr); > + if (bitmap_no >=3D cma->count) > + break; > + if (nr_total =3D=3D 0) > + printk("%u", nr); > + else > + printk("+%u", nr); > + nr_total +=3D nr; > + start =3D bitmap_no + nr; > + } > + printk("=3D>%u pages, total: %lu pages\n", nr_total, cma-= >count); I would be happier should you find other existing places where this function can be used. With just one caller, I=E2=80=99m not convinced it is worth it. >>> Signed-off-by: Jaewon Kim The code itself is good, so Acked-by: Michal Nazarewicz and I=E2=80=99ll leave deciding whether it improves the kernel overall to maintainers. ;) >>> --- >>> 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 ar= ea >>> * 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 bi= t free area and its size >>> * bitmap_shift_right(dst, src, n, nbits) *dst =3D *src >> n >>> * bitmap_shift_left(dst, src, n, nbits) *dst =3D *src << n >>> * bitmap_remap(dst, src, old, new, nbits) *dst =3D map(old, new)(src) >>> @@ -123,6 +124,11 @@ extern unsigned long bitmap_find_next_zero_area_of= f(unsigned long *map, >>> unsigned long align_mask, >>> unsigned long align_offset); >>>=20=20 >>> +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(unsig= ned long *map, >>> } >>> EXPORT_SYMBOL(bitmap_find_next_zero_area_off); >>>=20=20 >>> +/** >>> + * bitmap_find_next_zero_area_and_size - find a contiguous aligned zer= o 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 =3D 0; >>> + index =3D find_next_zero_bit(map, size, start); >>> + >>> + if (index >=3D size) >>> + return index; I would remove this check. find_next_bit handles situation when index =3D=3D size and without this early return, *nr is always set. >>> + i =3D find_next_bit(map, size, index); >>> + *nr =3D 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. >>> --=20 >>> 1.9.1 >>> >>> -- >>> To unsubscribe, send a message with 'unsubscribe linux-mm' in >>> the body to majordomo@kvack.org. For more info on Linux MM, >>> see: http://www.linux-mm.org/ . >>> Don't email: email@kvack.org > --=20 Best regards =E3=83=9F=E3=83=8F=E3=82=A6 =E2=80=9C=F0=9D=93=B6=F0=9D=93=B2=F0=9D=93=B7= =F0=9D=93=AA86=E2=80=9D =E3=83=8A=E3=82=B6=E3=83=AC=E3=83=B4=E3=82=A4=E3=83= =84 =C2=ABIf at first you don=E2=80=99t succeed, give up skydiving=C2=BB -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org