From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C80A0C433E0 for ; Mon, 29 Jun 2020 02:43:12 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8939120675 for ; Mon, 29 Jun 2020 02:43:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="Sk970az7" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8939120675 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 169CC6B0003; Sun, 28 Jun 2020 22:43:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 118F86B0005; Sun, 28 Jun 2020 22:43:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 006AD6B0006; Sun, 28 Jun 2020 22:43:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0047.hostedemail.com [216.40.44.47]) by kanga.kvack.org (Postfix) with ESMTP id DEB2F6B0003 for ; Sun, 28 Jun 2020 22:43:11 -0400 (EDT) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 69474180AD801 for ; Mon, 29 Jun 2020 02:43:11 +0000 (UTC) X-FDA: 76980702582.11.talk12_1a090b726e6b Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin11.hostedemail.com (Postfix) with ESMTP id 463DA180F8B81 for ; Mon, 29 Jun 2020 02:43:11 +0000 (UTC) X-HE-Tag: talk12_1a090b726e6b X-Filterd-Recvd-Size: 3493 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf09.hostedemail.com (Postfix) with ESMTP for ; Mon, 29 Jun 2020 02:43:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=yQyPEA4fwxkaL2Sv58MpobbVI0aOCnfA9ig8/eIofc4=; b=Sk970az7hnYAcjWTyGRiUoVN9O tQtxlUTlo/8U5dc3sGFbFmflvvI2Wex6C9zPV7+J2Gkcc9UulOy4vL3t1O6rLgHOcSR2L5HYVFVoC jnupRvZRp8u78yS0A7oalZT7fRBlft4E4VVtN/Qrs24w4g81UUSDz0R1U0VvglyW2J7vymqsPbY1D b1Of+pOkbouxk4ZUag321o8xceZTyxKucZR2yDMXwKc++LHrTHech+P/vm4ItfZPw6IsjIHzECCj9 yEx94aoZHo11vausSXGtPLPwK7cMB4ZMgmGPHL2Jsj2BnQmODaHiq76yV1gSM8JW1LmXwUDeAz7Bq Ef4rDsWw==; Received: from willy by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1jpjl0-0002B1-0p; Mon, 29 Jun 2020 02:42:54 +0000 Date: Mon, 29 Jun 2020 03:42:53 +0100 From: Matthew Wilcox To: Long Li Cc: cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v1] mm:free unused pages in kmalloc_order Message-ID: <20200629024253.GB25523@casper.infradead.org> References: <20200627045507.GA57675@lilong> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200627045507.GA57675@lilong> X-Rspamd-Queue-Id: 463DA180F8B81 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 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: On Sat, Jun 27, 2020 at 04:55:07AM +0000, Long Li wrote: > Environment using the slub allocator, 1G memory in my ARM32. > kmalloc(1024, GFP_HIGHUSER) can allocate memory normally, > kmalloc(64*1024, GFP_HIGHUSER) will cause a memory leak, because > alloc_pages returns highmem physical pages, but it cannot be directly > converted into a virtual address and return NULL, the pages has not > been released. Usually driver developers will not use the > GFP_HIGHUSER flag to allocate memory in kmalloc, but I think this > memory leak is not perfect, it is best to be fixed. This is the > first time I have posted a patch, there may be something wrong. Slab used to disallow GFP_HIGHMEM allocations earlier than this, so you'd never get here. See one moron's patch here, 20 years ago ... https://lore.kernel.org/lkml/20001228145801.C19693@parcelfarce.linux.theplanet.co.uk/ Things changed a bit since then. SLAB_LEVEL_MASK became GFP_SLAB_BUG_MASK, then GFP_SLAB_BUG_MASK moved to mm/internal.h. Nowadays, GFP_SLAB_BUG_MASK is checked only in new_slab(), and it is definitely skipped when we go through the kmalloc_large() patch. Could you send a replacement patch which checks GFP_SLAB_BUG_MASK before calling alloc_pages()? > +++ b/mm/slab_common.c > @@ -819,8 +819,12 @@ void *kmalloc_order(size_t size, gfp_t flags, unsigned int order) > page = alloc_pages(flags, order); > if (likely(page)) { > ret = page_address(page); > - mod_node_page_state(page_pgdat(page), NR_SLAB_UNRECLAIMABLE_B, > - PAGE_SIZE << order); > + if (ret) > + mod_node_page_state(page_pgdat(page), > + NR_SLAB_UNRECLAIMABLE_B, > + PAGE_SIZE << order); > + else > + __free_pages(page, order); > } > ret = kasan_kmalloc_large(ret, size, flags); > /* As ret might get tagged, call kmemleak hook after KASAN. */ > -- > 2.17.1 > >