From patchwork Tue Dec 15 03:11:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 11973865 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 45FEBC4361B for ; Tue, 15 Dec 2020 03:11:12 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id F27DA224B0 for ; Tue, 15 Dec 2020 03:11:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F27DA224B0 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 93AA48D0049; Mon, 14 Dec 2020 22:11:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 912618D001C; Mon, 14 Dec 2020 22:11:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 850BB8D0049; Mon, 14 Dec 2020 22:11:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0205.hostedemail.com [216.40.44.205]) by kanga.kvack.org (Postfix) with ESMTP id 6E2818D001C for ; Mon, 14 Dec 2020 22:11:11 -0500 (EST) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 40BA01F06 for ; Tue, 15 Dec 2020 03:11:11 +0000 (UTC) X-FDA: 77594040342.26.wind33_1d0b40e27420 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin26.hostedemail.com (Postfix) with ESMTP id 225A81804B660 for ; Tue, 15 Dec 2020 03:11:11 +0000 (UTC) X-HE-Tag: wind33_1d0b40e27420 X-Filterd-Recvd-Size: 3081 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf50.hostedemail.com (Postfix) with ESMTP for ; Tue, 15 Dec 2020 03:11:10 +0000 (UTC) Date: Mon, 14 Dec 2020 19:11:09 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1608001869; bh=me3P6xy3I8JGn5T/2uCGRbNH+FzwyVezfIHnwi1XWqg=; h=From:To:Subject:In-Reply-To:From; b=Umrxgl82IUAvww5lcZKQAj7OnV7NqA9afIiyzLZrIedspe9jBtcVy7NO6O9SPtdfu /17QLMehHR0qfKJCsJ5YrhQ1UDtNMc+uwZGlhPyIh0F/6e+a1MUPxMCrEtjRdboM0B fi5j+SePb+Tf9sX658gD1VCCgNktX1i7JEhBdH/k= From: Andrew Morton To: akpm@linux-foundation.org, linux-mm@kvack.org, mm-commits@vger.kernel.org, rppt@linux.ibm.com, torvalds@linux-foundation.org, vbabka@suse.cz, william.kucharski@oracle.com, willy@infradead.org Subject: [patch 132/200] mm/page_alloc: add __free_pages() documentation Message-ID: <20201215031109.HETudzx-2%akpm@linux-foundation.org> In-Reply-To: <20201214190237.a17b70ae14f129e2dca3d204@linux-foundation.org> User-Agent: s-nail v14.8.16 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: From: "Matthew Wilcox (Oracle)" Subject: mm/page_alloc: add __free_pages() documentation Provide some guidance towards when this might not be the right interface to use. Link: https://lkml.kernel.org/r/20201027025523.3235-1-willy@infradead.org Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: William Kucharski Acked-by: Vlastimil Babka Reviewed-by: Mike Rapoport Signed-off-by: Andrew Morton --- mm/page_alloc.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) --- a/mm/page_alloc.c~mm-page_alloc-add-__free_pages-documentation +++ a/mm/page_alloc.c @@ -5043,6 +5043,26 @@ static inline void free_the_page(struct __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))