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: 10658735 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 18AB0109C for ; Mon, 29 Oct 2018 02:17:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 055D4298ED for ; Mon, 29 Oct 2018 02:17:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E8A09298EF; Mon, 29 Oct 2018 02:17:05 +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,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9A699298ED for ; Mon, 29 Oct 2018 02:17:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 60FF96B0355; Sun, 28 Oct 2018 22:17:02 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 5BD476B0357; Sun, 28 Oct 2018 22:17:02 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4D3D96B0358; Sun, 28 Oct 2018 22:17:02 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) by kanga.kvack.org (Postfix) with ESMTP id 0F2ED6B0355 for ; Sun, 28 Oct 2018 22:17:02 -0400 (EDT) Received: by mail-pf1-f199.google.com with SMTP id l15-v6so1624089pff.5 for ; Sun, 28 Oct 2018 19:17:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:mime-version; bh=NKbBtVtjcVKDa4Mo4cpdJY+mZSbBCRSk+5ds6R/y06g=; b=plpjpQNYaHvK5jPa53oilJJ8Uu6CuX0aVRLpoRqqEO0FQ3i7iP4U4whuWU+vYh/hX9 WuZHKbmtlZGv0efpTKdvToL5InwoR19cC14yFKICDIcLWCKve0TtifgCiOb/nMmt9FUS /QvcLkmJlgNZlCSo1JKGbuCjU3UGjvGdh5dASTb4XapsZ7zpEADBaE1MMkR9fGIvUji/ xzALyMfyUJ4R/wp1LQI/9GdEx4Ft/kUKY8T80p90J3Io3E53zsr0JAtRRg7o6YxTWP2/ yRkDyaJj238eJFKUKMWzrno8+pexlAP2BOHn9OYZtPi4v9SVRgFkQTI141itH177wKPz nJxQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of miles.chen@mediatek.com designates 210.61.82.184 as permitted sender) smtp.mailfrom=miles.chen@mediatek.com X-Gm-Message-State: AGRZ1gJsfPiT2c6WHpJSPHYhW2LI4J81BflQWmc0iQgbuecmPJA641SJ mlb9Kp8iNntuhQ9ozKY98Cl3/1f4E/gcKnET0QFAbmH0kA1EkcocBpR+wpBqFVjvvJkGWvzeUFp rjueKixsN6plrxCejdX4TtYGVntuIPEioNSTXL+dgtApAX3jVirzViTRfqgs3HH8YZw== X-Received: by 2002:aa7:80cd:: with SMTP id a13-v6mr13085967pfn.86.1540779421724; Sun, 28 Oct 2018 19:17:01 -0700 (PDT) X-Google-Smtp-Source: AJdET5cGMW4rnVbaPvc74uQueTbCOrmZ82X8/sp8htxQFwkewKWTGpfn4aBcZ3NMoLfDqUQOLeG4 X-Received: by 2002:aa7:80cd:: with SMTP id a13-v6mr13085916pfn.86.1540779420864; Sun, 28 Oct 2018 19:17:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540779420; cv=none; d=google.com; s=arc-20160816; b=tUXwi1H+/ZManZ4VkV7kut8Pg8GjA0086Ubay8vjjFFwLmv0XH4VVtRg7Wq8kivCwg edY5anuvgdPjDH+DZ8pyeK45Kc3yK+opiMVQR+uTWV7HKqWZqqPTxtjx45q52m8SMqcw 1A3ac8qZ+ipq+r823zDeGDjTZZXTDu5ID4KS/k0LHOwxu9nagCDra9B2CFDRjztxolfh OvdyLQ9S58k6In9XWifn1xbboZZL4hwFH4HwYUToKUb3xGBdj9CvmaOYlm2+99W3cqX4 dsXuVYJ+IDNtjbHB0FGy69Z2Vku+B6PVj/1LO3rWFZt5RrYSFmDms1aIFMizlf6uGwE5 CXuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:message-id:date:subject:cc:to:from; bh=NKbBtVtjcVKDa4Mo4cpdJY+mZSbBCRSk+5ds6R/y06g=; b=aZid9IxumDBQv5ORGQ8bovsaY6uLI0NF5i1XSbjYS+irUUgMAipyvYNDUI/l3goq3p j1GFC1VQ5Lo5bQ/eUwzpO5Opux0UliSD6RvmQ7+mdHZeDIyfuftPGmaZoI+bPwLdrU4+ +AByzUMGgAomP/RlSg+CkOa0aDekf5j++pDN+pa2DNNCdaHMaFNVwvbtgi8SCZjTC9jO CDGyG71DmgkmaZkhMPW0IeRDLsT9YGxvJB6WZJkPzhL3kylnm07DwTtbuN4OC1/bQjio hOZQF6uXsjS9UzHRiLTvcNpWVsKnDLY1MXgRvSW8FAfZ9NUfGH0i5TAYrZC5ZUn4Sjo/ 2oMg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of miles.chen@mediatek.com designates 210.61.82.184 as permitted sender) smtp.mailfrom=miles.chen@mediatek.com Received: from mailgw02.mediatek.com ([210.61.82.184]) by mx.google.com with ESMTPS id k9-v6si18462628pgc.79.2018.10.28.19.17.00 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 28 Oct 2018 19:17:00 -0700 (PDT) Received-SPF: pass (google.com: domain of miles.chen@mediatek.com designates 210.61.82.184 as permitted sender) client-ip=210.61.82.184; Authentication-Results: mx.google.com; spf=pass (google.com: domain of miles.chen@mediatek.com designates 210.61.82.184 as permitted sender) smtp.mailfrom=miles.chen@mediatek.com 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 CC: , , , , , Joe Perches , Michal Hocko , Matthew Wilcox , Miles Chen 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-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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; }