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=-3.6 required=3.0 tests=BAYES_00,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 4C8FBC4741F for ; Tue, 29 Sep 2020 14:06:54 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A17AA20848 for ; Tue, 29 Sep 2020 14:06:53 +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="teujRbnG" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A17AA20848 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 F0A21900005; Tue, 29 Sep 2020 10:06:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EB9B88E0001; Tue, 29 Sep 2020 10:06:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DCF5D900005; Tue, 29 Sep 2020 10:06:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0196.hostedemail.com [216.40.44.196]) by kanga.kvack.org (Postfix) with ESMTP id C76BF8E0001 for ; Tue, 29 Sep 2020 10:06:52 -0400 (EDT) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 7CF5E5854 for ; Tue, 29 Sep 2020 14:06:52 +0000 (UTC) X-FDA: 77316275064.26.burst85_541315c2718a Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin26.hostedemail.com (Postfix) with ESMTP id 79E0018021E6A for ; Tue, 29 Sep 2020 14:06:28 +0000 (UTC) X-HE-Tag: burst85_541315c2718a X-Filterd-Recvd-Size: 3327 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf17.hostedemail.com (Postfix) with ESMTP for ; Tue, 29 Sep 2020 14:06:27 +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=viXSxvUTI8HhUOod2bOuMX3/wUHqXf4haaO3VlhNCpQ=; b=teujRbnGhuAVQFaJzPZg7wrFDB 3zeBOvrZ+vk2DrwJw87lkPJjUWurJyxwxPPlhOPyQqvEB/ljnl6sP9jWi+VTcXcy2hFwRjQwCGtbV PQlDh5WBlEJIiU6AQilTAsj+kCeN+iakY4wYjCEfM5W7yXqF0OuamrmxEzFT3AsEbsVRaNH3BwpaM Z+Kqy+tnAHiKrsw6C8zkdDdwXmFy0t3LgtcxhnAjZYrER58he7YhvNkOWPui29sjj1fC7k/NsPEgs qZdGI+Hs77Bc9byL3yHm629h0YxmAdg/BU7yBX2c2M6NCC0J2+GjV2N/Y3OURB+aSCKBRQ3GOPLmV T9WGVDXQ==; Received: from willy by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1kNGGs-0004G1-Op; Tue, 29 Sep 2020 14:06:22 +0000 Date: Tue, 29 Sep 2020 15:06:22 +0100 From: Matthew Wilcox To: Mike Rapoport Cc: Andrew Morton , Nick Piggin , Hugh Dickins , Peter Zijlstra , linux-mm@kvack.org, linux-kernel@vger.kernel.org, hch@lst.de, rdunlap@infradead.org Subject: Re: [PATCH v2] page_alloc: Fix freeing non-compound pages Message-ID: <20200929140622.GE20115@casper.infradead.org> References: <20200926213919.26642-1-willy@infradead.org> <20200928180307.7573f3b6128b5e3007dfc9f0@linux-foundation.org> <20200929034026.GA20115@casper.infradead.org> <20200929072622.GN2645148@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200929072622.GN2645148@linux.ibm.com> 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 Tue, Sep 29, 2020 at 10:26:22AM +0300, Mike Rapoport wrote: > This sentence presumes existing description/prior knowledge about > put_page(). > > Maybe > > This function can free multi-page allocations that were not allocated > with %__GFP_COMP, unlike put_page() that would free only the first page > in such case. __free_pages() does not ... Thanks. After waking up this morning I did a more extensive rewrite: /** * __free_pages - Free pages allocated with alloc_pages(). * @page: The page pointer returned from alloc_pages(). * @order: The order of the allocation. * * This function can free multi-page allocations that are not compound * pages. It does not check that the @order passed in matches that of * the allocation, so it is easy to leak memory. Freeing more memory * than was allocated will probably emit a warning. * * If the last reference to this page is speculative, it will be released * by put_page() which only frees the first page of a non-compound * allocation. To prevent the remaining pages from being leaked, we free * the subsequent pages here. If you want to use the page's reference * count to decide when to free the allocation, you should allocate a * compound page, and use put_page() instead of __free_pages(). * * Context: May be called in interrupt context or holding a normal * spinlock, but not in NMI context or while holding a raw spinlock. */