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=-13.4 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham 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 B55BFC4363A for ; Tue, 27 Oct 2020 19:22:48 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id F23802076D for ; Tue, 27 Oct 2020 19:22:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F23802076D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 5EB246B0083; Tue, 27 Oct 2020 15:22:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 59CDC6B0085; Tue, 27 Oct 2020 15:22:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4B1DE6B0087; Tue, 27 Oct 2020 15:22:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0139.hostedemail.com [216.40.44.139]) by kanga.kvack.org (Postfix) with ESMTP id 1A4556B0083 for ; Tue, 27 Oct 2020 15:22:47 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id A0DCA3629 for ; Tue, 27 Oct 2020 19:22:46 +0000 (UTC) X-FDA: 77418677532.25.shelf27_2a081e72727e Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin25.hostedemail.com (Postfix) with ESMTP id 7B49C1804E3A8 for ; Tue, 27 Oct 2020 19:22:46 +0000 (UTC) X-HE-Tag: shelf27_2a081e72727e X-Filterd-Recvd-Size: 2836 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf38.hostedemail.com (Postfix) with ESMTP for ; Tue, 27 Oct 2020 19:22:45 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 8D9F4B286; Tue, 27 Oct 2020 19:22:44 +0000 (UTC) Subject: Re: [PATCH] mm/page_alloc: Add __free_pages documentation To: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org References: <20201027025523.3235-1-willy@infradead.org> From: Vlastimil Babka Message-ID: Date: Tue, 27 Oct 2020 20:22:44 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.3.3 MIME-Version: 1.0 In-Reply-To: <20201027025523.3235-1-willy@infradead.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit 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 10/27/20 3:55 AM, Matthew Wilcox (Oracle) wrote: > Provide some guidance towards when this might not be the right interface > to use. > > Signed-off-by: Matthew Wilcox (Oracle) Acked-by: Vlastimil Babka > --- > mm/page_alloc.c | 20 ++++++++++++++++++++ > 1 file changed, 20 insertions(+) > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index 23f5066bd4a5..e613177b8041 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -5007,6 +5007,26 @@ static inline void free_the_page(struct page *page, unsigned int order) > __free_pages_ok(page, order, FPI_NONE); > } > > +/** > + * __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 while holding a normal > + * spinlock, but not in NMI context or while holding a raw spinlock. > + */ > void __free_pages(struct page *page, unsigned int order) > { > if (put_page_testzero(page)) >