From patchwork Mon Oct 29 02:16:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miles Chen X-Patchwork-Id: 10658739 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 61C73109C for ; Mon, 29 Oct 2018 02:17:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4E646298EF for ; Mon, 29 Oct 2018 02:17:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4276A298F1; Mon, 29 Oct 2018 02:17:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id AA766298EF for ; Mon, 29 Oct 2018 02:17:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=E6KxM85dIGILHx+bsu3dPD8sua0LFuTBvxN5V2IsEZ8=; b=e3/UyHlZD8bB+u 918+w5TcMoRytprFRr7hpdGfAvNeugrPR7Nfnz8QLLPny9HW9YJvZwOZtliBzZg4HqoZMmsZBr9Yp NnKBzDcK6k+1KpxqYQAn6iZZzGZcjUiaMx24g7s7O5vS9kOIyaKQEl1ieURfPdFcJM4D+wGpLVaZL GAnyjBHNU8Lh6WTTjpsxl/HkUOUzo2xK8rUv5IBrhRlcg9rSWcj8QuRnsy9sOLgTffFSizymTm80n 4giXmphOyVkdVbaym4QAjdXVK4A9I9AHuqBXCLGGcVQXDeGItEMVz5Oy0y9M73XxGVjq6CufUFgVD LyDQtYx0QJOwXIPuX4GQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gGx7O-00056F-U3; Mon, 29 Oct 2018 02:17:26 +0000 Received: from [210.61.82.184] (helo=mailgw02.mediatek.com) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gGx7I-0004gG-DQ; Mon, 29 Oct 2018 02:17:22 +0000 X-UUID: 2f5d12a114f64df4890027a0fc7a5d4d-20181029 X-UUID: 2f5d12a114f64df4890027a0fc7a5d4d-20181029 Received: from mtkcas08.mediatek.inc [(172.21.101.126)] by mailgw02.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 606640263; Mon, 29 Oct 2018 10:16:49 +0800 Received: from mtkcas08.mediatek.inc (172.21.101.126) by mtkmbs08n2.mediatek.inc (172.21.101.56) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Mon, 29 Oct 2018 10:16:44 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas08.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Mon, 29 Oct 2018 10:16:45 +0800 From: To: Matthias Brugger Subject: [PATCHv2] mm/page_owner: use kvmalloc instead of kmalloc Date: Mon, 29 Oct 2018 10:16:43 +0800 Message-ID: <1540779403-27622-1-git-send-email-miles.chen@mediatek.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-TM-SNTS-SMTP: 2932E7EEAC6E230EB2461690D3E152278D1DC363304DC491F1C165FE4D5DF8202000:8 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181028_191720_599796_3DCEBF75 X-CRM114-Status: GOOD ( 10.67 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: wsd_upstream@mediatek.com, linux-kernel@vger.kernel.org, Matthew Wilcox , Michal Hocko , linux-mm@kvack.org, Miles Chen , linux-mediatek@lists.infradead.org, Joe Perches , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Miles Chen The kbuf used by page owner is allocated by kmalloc(), which means it can use only normal memory and there might be a "out of memory" issue when we're out of normal memory. Use kvmalloc() so we can also allocate kbuf from normal/hihghmem on 32bit kernel. Clamp the kbuf size to PAGE_SIZE. Change since v1: - use kvmalloc() - clamp buffer size to PAGE_SIZE Signed-off-by: Miles Chen Cc: Joe Perches Cc: Matthew Wilcox Cc: Michal Hocko --- mm/page_owner.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mm/page_owner.c b/mm/page_owner.c index d80adfe..a064cd0 100644 --- a/mm/page_owner.c +++ b/mm/page_owner.c @@ -1,7 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 #include #include -#include #include #include #include @@ -351,7 +350,8 @@ void pagetypeinfo_showmixedcount_print(struct seq_file *m, .skip = 0 }; - kbuf = kmalloc(count, GFP_KERNEL); + count = count > PAGE_SIZE ? PAGE_SIZE : count; + kbuf = kvmalloc(count, GFP_KERNEL); if (!kbuf) return -ENOMEM; @@ -397,11 +397,11 @@ void pagetypeinfo_showmixedcount_print(struct seq_file *m, if (copy_to_user(buf, kbuf, ret)) ret = -EFAULT; - kfree(kbuf); + kvfree(kbuf); return ret; err: - kfree(kbuf); + kvfree(kbuf); return -ENOMEM; }