Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752298AbcL2C1j (ORCPT ); Wed, 28 Dec 2016 21:27:39 -0500 Received: from mailout4.samsung.com ([203.254.224.34]:51939 "EHLO mailout4.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752271AbcL2C1h (ORCPT ); Wed, 28 Dec 2016 21:27:37 -0500 X-AuditID: b6c32a58-f79726d000001ac1-5d-5864748befbe From: Jaewon Kim To: gregkh@linuxfoundation.org, akpm@linux-foundation.org Cc: labbott@redhat.com, mhocko@kernel.org, mina86@mina86.com, m.szyprowski@samsung.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, jaewon31.kim@gmail.com, Jaewon Kim Subject: [PATCH] mm: cma: print allocation failure reason and bitmap status Date: Thu, 29 Dec 2016 11:28:02 +0900 Message-id: <1482978482-14007-1-git-send-email-jaewon31.kim@samsung.com> X-Mailer: git-send-email 1.9.1 X-Brightmail-Tracker: H4sIAAAAAAAAAzWSa0gUURTHvTM7s6O4Oq2WFyVZBvug5eaujx1TexODZllGLZXY4F5c0X20 s0r2aSnzvWpKlGWp5APF3Nys7KmZphWCECUVWkFaKrWQFYG9dh399rv3/H+cew+HwuWviGAq x2hFFiOfx5A+kluPw8MjK6w6bdSlUT+2wdFFsqevOki24kY9YO2uOYztuP8LY1/cbSDZqa5/ BHttaFLKzv9sw9mmkSJiqw935+KklHN2lpGc81utlBu9sCjh+i93Sbnu33MY53r4kuSqejsB t+AMTfM+jBL1iNchiwIZs0y6HGN2EpOSnrkjMzYuShWpimc1jMLIG1ASs3N3WuSunDz3SxlF AZ+X775K4wWB2bg50WLKtyKF3iRYk5gjKpVaqYrSKNVqtTJGk7FJHeuOHEP6tpkBwtzvf8J+ 6hlhA42+5cCbgnQMbK+ykSKvgeNTjiWW060ALp4PKwc+bi7B4IvqKrAivH5XQoqFBgDt3+eX DRsGZ2bSPUzS66GrqZbwcCAdDx1jRZhHwOnnANZP9GCeQgCdAo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1c+UIg3JbGyKrUoP76oNCe1+BCjKdD+ icxSosn5wDjMK4k3NDE3MTc2sDC3tDQxUhLnbZz9LFxIID2xJDU7NbUgtQimj4mDU6qBUeLF zptCgvP/xjJpPXXKdFd64f3y02Oz20oz65i8DMp/3Lhm0nlmimqg4jwh99IDXZun9i6P5How pdSQ2+sll2+J0Pbru2+pXhIzmjl32g8nz7v6PTtfCpjNejf7wYsm0Qy9Sbe3rUngdjxg/1qq tlBl8SLmkvQFmdMzYl21dyzkfX/WvWnZCSWW4oxEQy3mouJEADEJ6cyLAgAA X-MTR: 20000000000000000@CPGS X-CMS-MailID: 20161229022722epcas5p4be0e1924f3c8d906cbfb461cab8f0374 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: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1919 Lines: 62 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 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; + 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); + mutex_unlock(&cma->lock); + } + return page; } -- 1.9.1