From patchwork Tue Oct 27 02:55:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 11859279 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 07BC014B7 for ; Tue, 27 Oct 2020 02:55:30 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2FAC32168B 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 2FAC32168B 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) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 3D25B6B0062; Mon, 26 Oct 2020 22:55:28 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org 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-Original-To: linux-mm@kvack.org 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-Spam-Summary: 30,2,0,a15e35371b77dc88,d41d8cd98f00b204,willy@infradead.org,,RULES_HIT:41:355:379:541:800:960:965:966:973:988:989:1260:1311:1314:1345:1437:1515:1534:1541:1711:1730:1747:1777:1792:2196:2198:2199:2200:2393:2553:2559:2562:2693:2731:2904:3138:3139:3140:3141:3142:3353:3865:3866:3867:3868:3870:3871:3872:3873:3874:4250:4321:4385:4390:4395:5007:6261:6653:7875:7903:10010:11026:11658:11914:12291:12297:12555:12895:12986:13069:13311:13357:13894:14096:14181:14384:14394:14721:21080:21433:21451:21627:21987:30054:30070:30090,0,RBL:90.155.50.34:@infradead.org:.lbl8.mailshell.net-64.201.201.201 62.8.15.100;04yg5m38upa661pfo8oi5wejyo4qeyc6aedb3jq4khs5w9nfdaedsx7h88ig4r5.9c79ry7uijo3brepwgc8wyeg5t3btqhwunoqrhw9hc4rhs6j8zwtkz1ofmfpky7.n-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:neutral,Custom_rules:0:1:0,LFtime:23,LUA_SUMMARY:none 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 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) Reviewed-by: William Kucharski Acked-by: Vlastimil Babka Reviewed-by: Mike Rapoport --- 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))