Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753523AbcL3HYE (ORCPT ); Fri, 30 Dec 2016 02:24:04 -0500 Received: from mailout1.samsung.com ([203.254.224.24]:59306 "EHLO mailout1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752945AbcL3HYD (ORCPT ); Fri, 30 Dec 2016 02:24:03 -0500 MIME-version: 1.0 Content-type: text/plain; charset=utf-8 X-AuditID: b6c32a59-f79486d000002ff5-55-58660b90057e Content-transfer-encoding: 8BIT Subject: Re: [PATCH] mm: cma: print allocation failure reason and bitmap status To: Michal Nazarewicz , Michal Hocko Cc: gregkh@linuxfoundation.org, akpm@linux-foundation.org, labbott@redhat.com, m.szyprowski@samsung.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, jaewon31.kim@gmail.com From: Jaewon Kim Message-id: <58660BBE.1040807@samsung.com> Date: Fri, 30 Dec 2016 16:24:46 +0900 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2 In-reply-to: X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrCJsWRmVeSWpSXmKPExsWy7bCmlu4E7rQIg4tTTC3mrF/DZtG8eD2b RffmmYwWK/f8YLK4vGsOm8W9Nf9ZLdYeuctu8frbMmaLBcdbWB04PXbOusvusWlVJ5vHpk+T 2D1OzPjN4rF/7hp2j3V/XjF5vN93lc2jb8sqRo/Pm+QCOKNSbTJSE1NSixRS85LzUzLz0m2V vIPjneNNzQwMdQ0tLcyVFPISc1NtlVx8AnTdMnOAjlRSKEvMKQUKBSQWFyvp29kU5ZeWpCpk 5BeX2CpFGxoa6RkamOsZGRnpmZjHWhmZApUkpGZsOihR8Mi04siys4wNjGc0uxg5OSQETCTm 7JvMBmGLSVy4tx7MFhJYyihx8IlXFyMXkN3OJHFtwzNWmIYPUxcxQxQtZ5T415IDYvMKCEr8 mHyPpYuRg4NZQF7iyKVskDCzgKbEiy+TWC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RSLizgL7Hg1iYwW0TAW+LBtpUsEEXPGCUev/7OCuIwC2xl lNh2di87SBWbgLbE+wWTWCGWaUlc2jEXzGYRUJW4u2YfWI2oQITE6nXXwA7iBKq5t/w32wRG gVlI7puFcN8shPsWMDKvYpRILUguKE5KzzXKSy3XK07MLS7NS9dLzs/dxAiOzWfSOxgP73I/ xCjAwajEw/ujLDVCiDWxrLgy9xCjBAezkghvDUdahBBvSmJlVWpRfnxRaU5q8SFGU6ATJzJL iSbnA9NGXkm8oYm5ibmxgYW5paWJkZI4b+PsZ+FCAumJJanZqakFqUUwfUwcnFINjII9Lp/F IxtX3N1QvevTjCvq9rrsHOEbzzU08Mg0/zY52bbluOWX6q4ZR92EG4Q1wx0SHhdectf8pC85 8XPcB947wndrtfTrNisvPqJ6/OlV64dLxZ8v0rpVuXq69voWu5Tnv6Ytt/DU5uHll794rerp 55JTzXNnR+kWLZ7nHqRdseMa4zYvQyWW4oxEQy3mouJEAAQHtOjjAgAA X-MTR: 20000000000000000@CPGS X-CMS-MailID: 20161230072400epcas5p1b4e1cfd5f499167efaa76027595bfad5 X-Msg-Generator: CA X-Sender-IP: 203.254.230.27 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: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-HopCount: 7 X-CMS-RootMailID: 20161229022722epcas5p4be0e1924f3c8d906cbfb461cab8f0374 X-RootMTR: 20161229022722epcas5p4be0e1924f3c8d906cbfb461cab8f0374 References: <1482978482-14007-1-git-send-email-jaewon31.kim@samsung.com> <20161229091449.GG29208@dhcp22.suse.cz> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 6700 Lines: 181 Hello Michal Hocko and and Michal Nazarewichz On 2016년 12월 29일 23:20, Michal Nazarewicz wrote: > On Thu, Dec 29 2016, Michal Hocko wrote: >> On Thu 29-12-16 11:28:02, Jaewon Kim wrote: >>> There are many reasons of CMA allocation failure such as EBUSY, ENOMEM, EINTR. >>> This patch prints the error value and bitmap status to know available pages >>> regarding fragmentation. >>> >>> This is an ENOMEM example with this patch. >>> [ 11.616321] [2: Binder:711_1: 740] cma: cma_alloc: alloc failed, req-size: 256 pages, ret: -12 >>> [ 11.616365] [2: Binder:711_1: 740] number of available pages: 4+7+7+8+38+166+127=>357 pages, total: 2048 pages >> Could you be more specific why this part is useful? The first line is useful to know why the allocation failed. Actually CMA internally try all available regions because some regions can be failed because of EBUSY. The second showing bitmap status is useful to know in detail on both ENONEM and EBUSY; ENOMEM: not tried at all because of no available region EBUSY: tried some region but all failed >>> Signed-off-by: Jaewon Kim >>> --- >>> mm/cma.c | 29 ++++++++++++++++++++++++++++- >>> 1 file changed, 28 insertions(+), 1 deletion(-) >>> >>> diff --git a/mm/cma.c b/mm/cma.c >>> index c960459..535aa39 100644 >>> --- a/mm/cma.c >>> +++ b/mm/cma.c >>> @@ -369,7 +369,7 @@ struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align) >>> unsigned long start = 0; >>> unsigned long bitmap_maxno, bitmap_no, bitmap_count; >>> struct page *page = NULL; >>> - int ret; >>> + int ret = -ENOMEM; >>> >>> if (!cma || !cma->count) >>> return NULL; >>> @@ -427,6 +427,33 @@ struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align) >>> trace_cma_alloc(pfn, page, count, align); >>> >>> pr_debug("%s(): returned %p\n", __func__, page); >>> + >>> + if (ret != 0) { >>> + unsigned int nr, nr_total = 0; >>> + unsigned long next_set_bit; >>> + >>> + pr_info("%s: alloc failed, req-size: %zu pages, ret: %d\n", >>> + __func__, count, ret); >>> + mutex_lock(&cma->lock); >>> + printk("number of available pages: "); >>> + start = 0; >>> + for (;;) { >>> + bitmap_no = find_next_zero_bit(cma->bitmap, cma->count, start); >>> + next_set_bit = find_next_bit(cma->bitmap, cma->count, bitmap_no); >>> + nr = next_set_bit - bitmap_no; >>> + if (bitmap_no >= cma->count) >>> + break; > Put this just next to ‘bitmap_no = …’ line. No need to call > find_next_bit if we’re gonna break anyway. thank you I fixed >>> + if (nr_total == 0) >>> + printk("%u", nr); >>> + else >>> + printk("+%u", nr); > Perhaps also include location of the hole? Something like: > > pr_cont("%s%u@%u", nr_total ? "+" : "", nr, bitmap_no); Thank you I fixed with @%lu > >>> + nr_total += nr; >>> + start = bitmap_no + nr; >>> + } >>> + printk("=>%u pages, total: %lu pages\n", nr_total, cma->count); >>> + mutex_unlock(&cma->lock); >>> + } >>> + > I wonder if this should be wrapped in > > #ifdef CMA_DEBUG > … > #endif > > On one hand it’s relatively expensive (even involving mutex locking) on > the other it’s in allocation failure path. bitmap status, I think, could be in side of CMA_DEBUG with the mutex but the first error log, I hope, to be out of CMA_DEBUG. > >>> return page; >>> } >>> >>> -- >>> 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 >> -- >> Michal Hocko >> SUSE Labs This is fixed patch following your comment. Please review again If it is OK, let me know whether I need to resend this patch as a new mail thread. >From 7577cc94da3af27907aa6eec590d2ef51e4b9d80 Mon Sep 17 00:00:00 2001 From: Jaewon Kim Date: Thu, 29 Dec 2016 11:00:16 +0900 Subject: [PATCH] mm: cma: print allocation failure reason and bitmap status There are many reasons of CMA allocation failure such as EBUSY, ENOMEM, EINTR. But we did not know error reason so far. This patch prints the error value. Additionally if CONFIG_CMA_DEBUG is enabled, this patch shows bitmap status to know available pages. Actually CMA internally try all available regions because some regions can be failed because of EBUSY. Bitmap status is useful to know in detail on both ENONEM and EBUSY; ENOMEM: not tried at all because of no available region it could be too small total region or could be fragmentation issue EBUSY: tried some region but all failed This is an ENOMEM example with this patch. [ 13.250961] [1: Binder:715_1: 846] cma: cma_alloc: alloc failed, req-size: 256 pages, ret: -12 Avabile pages also will be shown if CONFIG_CMA_DEBUG is enabled [ 13.251052] [1: Binder:715_1: 846] cma: number of available pages: 4@572+7@585+7@601+8@632+38@730+166@1114+127@1921=>357 pages, total: 2048 pages Signed-off-by: Jaewon Kim --- mm/cma.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/mm/cma.c b/mm/cma.c index c960459..1bcd9db 100644 --- a/mm/cma.c +++ b/mm/cma.c @@ -369,7 +369,7 @@ struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align) unsigned long start = 0; unsigned long bitmap_maxno, bitmap_no, bitmap_count; struct page *page = NULL; - int ret; + int ret = -ENOMEM; if (!cma || !cma->count) return NULL; @@ -427,6 +427,33 @@ struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align) trace_cma_alloc(pfn, page, count, align); pr_debug("%s(): returned %p\n", __func__, page); + + if (ret != 0) + pr_info("%s: alloc failed, req-size: %zu pages, ret: %d\n", + __func__, count, ret); +#ifdef CONFIG_CMA_DEBUG + if (ret != 0) { + unsigned int nr, nr_total = 0; + unsigned long next_set_bit; + + mutex_lock(&cma->lock); + pr_info("number of available pages: "); + start = 0; + for (;;) { + bitmap_no = find_next_zero_bit(cma->bitmap, cma->count, start); + if (bitmap_no >= cma->count) + break; + next_set_bit = find_next_bit(cma->bitmap, cma->count, bitmap_no); + nr = next_set_bit - bitmap_no; + pr_cont("%s%u@%lu", nr_total ? "+" : "", nr, bitmap_no); + nr_total += nr; + start = bitmap_no + nr; + } + pr_cont("=>%u pages, total: %lu pages\n", nr_total, cma->count); + mutex_unlock(&cma->lock); + } +#endif + return page; } -- 1.9.1