Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750833AbcL1Eks (ORCPT ); Tue, 27 Dec 2016 23:40:48 -0500 Received: from mailout4.samsung.com ([203.254.224.34]:45362 "EHLO mailout4.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750705AbcL1Ekq (ORCPT ); Tue, 27 Dec 2016 23:40:46 -0500 MIME-version: 1.0 Content-type: text/plain; charset=UTF-8 X-AuditID: b6c32a39-f79256d000001a75-d8-5863424bb28d Content-transfer-encoding: 8BIT Subject: Re: [PATCH] lib: bitmap: introduce bitmap_find_next_zero_area_and_size To: Michal Hocko Cc: gregkh@linuxfoundation.org, akpm@linux-foundation.org, labbott@redhat.com, mina86@mina86.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 From: Jaewon Kim Message-id: <58634274.5060205@samsung.com> Date: Wed, 28 Dec 2016 13:41:24 +0900 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2 In-reply-to: <20161227100535.GB7662@dhcp22.suse.cz> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrFJsWRmVeSWpSXmKPExsWy7bCmvq63U3KEwfG31havDnQwWsxZv4bN onnxejaLadM3sFp0b57JaLFyzw8mi86JS9gtLu+aw2Zxb81/Vou1R+6yW7z+tozZYsHxFlYH Ho+ds+6ye8zumMnqsWlVJ5vHpk+T2D1OzPjN4rF/7hp2j3V/XjF5vN93lc2jb8sqRo/Pm+QC uKJSbTJSE1NSixRS85LzUzLz0m2VvIPjneNNzQwMdQ0tLcyVFPISc1NtlVx8AnTdMnOADldS KEvMKQUKBSQWFyvp29kU5ZeWpCpk5BeX2CpFGxoa6RkamOsZGRnpmZjHWhmZApUkpGa0rm9k K5ihXtF0dT97A2OrbBcjJ4eEgInElgWHmS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fUOClBTKEnNKgTwjAzTg4Bzg Hqykb5fgltG6vpGtYIZ6RdPV/ewNjK2yXYycHBICJhLPrj5hhLDFJC7cW8/WxcjFISSwlFGi 78IyNpAEr4CgxI/J91i6GDk4mAXkJY5cygYJMwuoS0yat4gZov4ho8S7lavBBgkL+Ev0vN3C DGKLCKhIrO+7ww5iCwkcZ5SYtM8cpIFZYC6TxPG+5WAJNgFtifcLJrFCLNOS6DvXAhZnEVCV ePi9D2yQqECExOp118BsTgFjibUtv1gnMArMQnLfLIT7ZiG5bwEj8ypGidSC5ILipPRcw7zU cr3ixNzi0rx0veT83E2M4Dh+JrWD8eAu90OMAhyMSjy8K24kRQixJpYVV+YeYpTgYFYS4eW0 TY4Q4k1JrKxKLcqPLyrNSS0+xGgKdONEZinR5HxgiskriTc0MTcxNzawMLe0NDFSEudtnP0s XEggPbEkNTs1tSC1CKaPiYNTqoFxWn7CRFGn8PJmC6NLJeVCuQ8impe13S09LC70NWFfq6A4 f6c4V72B3xTv308vntiftdL5ZMc0X8F8P5n7OzNW3dzzYmdb2BsTl2Xs/wrYWU+vmxj9lF3P 7JhH2fSC243/P/1+HaG/1F67ovn7PffNq6dtuO4de2G3+NLCyxOq4n94a2/tUDysxFKckWio xVxUnAgAJ9D+zvkCAAA= X-MTR: 20000000000000000@CPGS X-CMS-MailID: 20161228044043epcas1p311848cc83d354444f9822569aa4a1423 X-Msg-Generator: CA X-Sender-IP: 203.254.230.26 X-Local-Sender: =?UTF-8?B?6rmA7J6s7JuQG1N5c3RlbSBTL1fqsJzrsJwy6re466O5KA==?= =?UTF-8?B?66y07ISgKRvsgrzshLHsoITsnpAbUzUo7LGF7J6EKS/ssYXsnoQ=?= X-Global-Sender: =?UTF-8?B?SmFld29uIEtpbRtTeXN0ZW0gUy9XIFImRCBHcm91cCAyG1Nh?= =?UTF-8?B?bXN1bmcgRWxlY3Ryb25pY3MbUzUvU2VuaW9yIEVuZ2luZWVy?= X-Sender-Code: =?UTF-8?B?QzEwG1RFTEUbQzEwRDkxMjI=?= CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-HopCount: 7 X-CMS-RootMailID: 20161226041809epcas5p1981244de55764c10f1a80d80346f3664 X-RootMTR: 20161226041809epcas5p1981244de55764c10f1a80d80346f3664 References: <1482725891-10866-1-git-send-email-jaewon31.kim@samsung.com> <20161227100535.GB7662@dhcp22.suse.cz> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4886 Lines: 132 On 2016년 12월 27일 19:05, Michal Hocko wrote: > On Mon 26-12-16 13:18:11, Jaewon Kim wrote: >> There was no bitmap API which returns both next zero index and size of zeros >> from that index. >> >> 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); > Who is going to use this function? I do not see any caller introduced by > this patch. Hi 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); > >> 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 >> >> -- >> 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