From: Michal Nazarewicz <mina86@mina86.com>
To: Jaewon Kim <jaewon31.kim@samsung.com>, Michal Hocko <mhocko@kernel.org>
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
Date: Wed, 28 Dec 2016 15:14:06 +0100 [thread overview]
Message-ID: <xa1tk2ak6t01.fsf@mina86.com> (raw)
In-Reply-To: <58634274.5060205@samsung.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 = 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 <jaewon31.kim@samsung.com>
The code itself is good, so
Acked-by: Michal Nazarewicz <mina86@mina86.com>
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: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
>
--
Best regards
ミハウ “𝓶𝓲𝓷𝓪86” ナザレヴイツ
«If at first you don’t succeed, give up skydiving»
next prev parent reply other threads:[~2016-12-28 14:14 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20161226041809epcas5p1981244de55764c10f1a80d80346f3664@epcas5p1.samsung.com>
2016-12-26 4:18 ` [PATCH] lib: bitmap: introduce bitmap_find_next_zero_area_and_size Jaewon Kim
2016-12-26 21:09 ` Michal Nazarewicz
2016-12-27 4:14 ` Jaewon Kim
2016-12-27 10:05 ` Michal Hocko
2016-12-28 4:41 ` Jaewon Kim
2016-12-28 8:32 ` Michal Hocko
2016-12-28 14:14 ` Michal Nazarewicz [this message]
2016-12-29 2:13 ` Jaewon Kim
2017-01-15 7:17 ` Yury Norov
2017-01-17 3:22 ` Jaewon Kim
2017-01-16 17:59 ` Andy Shevchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xa1tk2ak6t01.fsf@mina86.com \
--to=mina86@mina86.com \
--cc=akinobu.mita@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=gregkh@linuxfoundation.org \
--cc=gregory.0xf0@gmail.com \
--cc=jaewon31.kim@gmail.com \
--cc=jaewon31.kim@samsung.com \
--cc=labbott@redhat.com \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=m.szyprowski@samsung.com \
--cc=mhocko@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).