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=-12.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT 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 ABDA3C4363A for ; Tue, 27 Oct 2020 02:55:31 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C074820872 for ; Tue, 27 Oct 2020 02:55:28 +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="PMc8etdK" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C074820872 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 4229B6B005D; Mon, 26 Oct 2020 22:55:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3D25B6B0062; Mon, 26 Oct 2020 22:55:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2C2C46B006C; Mon, 26 Oct 2020 22:55:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0231.hostedemail.com [216.40.44.231]) by kanga.kvack.org (Postfix) with ESMTP id F365B6B005D for ; Mon, 26 Oct 2020 22:55:27 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 95080181AC9CB for ; Tue, 27 Oct 2020 02:55:27 +0000 (UTC) X-FDA: 77416189494.27.board07_0217b1727278 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin27.hostedemail.com (Postfix) with ESMTP id 6626B3D668 for ; Tue, 27 Oct 2020 02:55:27 +0000 (UTC) X-HE-Tag: board07_0217b1727278 X-Filterd-Recvd-Size: 3060 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf15.hostedemail.com (Postfix) with ESMTP for ; Tue, 27 Oct 2020 02:55:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:In-Reply-To:References; bh=QG3pqD4H+Wsf+tgr+7FLN2xIooqH29H5SRVgEJmt54A=; b=PMc8etdKhnJ3h1sr/aHg0UV8wa X1RvSWohJI211TDu9gPsqX9IuqieH5RdM2JEZS0958GsPgf31ygEpCfKBFJvDaNDyW3eiiaghZEuL MtvGqq701orbqh7as0WHGn2xtqez7HOt+PdrVtArrRsQn5N4Un9Sbnq7BNCazFvR17nsEX++8QLCS ULSb70Dtf487YLZnO286Yp3QBKcVXlpC+Sx6OUail+Lsf/slbE2s5NjEPTQ3ummsa5GYifXnHu2jC tp0NmisWoSV/MqVCvsYuLGpQ3sSeNge/OD+bBnz0EpTewlEc0nXzUZVZjIUYoTeMe3tNKkQYnvI6Q 2PwTgqhA==; Received: from willy by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1kXF8v-0000rc-3r; Tue, 27 Oct 2020 02:55:25 +0000 From: "Matthew Wilcox (Oracle)" To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" Subject: [PATCH] mm/page_alloc: Add __free_pages documentation Date: Tue, 27 Oct 2020 02:55:23 +0000 Message-Id: <20201027025523.3235-1-willy@infradead.org> X-Mailer: git-send-email 2.21.3 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: Provide some guidance towards when this might not be the right interface to use. Signed-off-by: Matthew Wilcox (Oracle) --- 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); } =20 +/** + * __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 release= d + * by put_page() which only frees the first page of a non-compound + * allocation. To prevent the remaining pages from being leaked, we fre= e + * 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)) --=20 2.28.0