* [PATCH] mm/page_alloc: Add __free_pages documentation
@ 2020-10-27 2:55 Matthew Wilcox (Oracle)
2020-10-27 19:03 ` William Kucharski
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Matthew Wilcox (Oracle) @ 2020-10-27 2:55 UTC (permalink / raw)
To: linux-mm; +Cc: Matthew Wilcox (Oracle)
Provide some guidance towards when this might not be the right interface
to use.
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
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))
--
2.28.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] mm/page_alloc: Add __free_pages documentation
2020-10-27 2:55 [PATCH] mm/page_alloc: Add __free_pages documentation Matthew Wilcox (Oracle)
@ 2020-10-27 19:03 ` William Kucharski
2020-10-27 19:22 ` Vlastimil Babka
2020-10-28 8:35 ` Mike Rapoport
2 siblings, 0 replies; 4+ messages in thread
From: William Kucharski @ 2020-10-27 19:03 UTC (permalink / raw)
To: Matthew Wilcox (Oracle); +Cc: linux-mm
I like the explanation.
Reviewed-by: William Kucharski <william.kucharski@oracle.com>
> On Oct 26, 2020, at 8:55 PM, Matthew Wilcox (Oracle) <willy@infradead.org> wrote:
>
> Provide some guidance towards when this might not be the right interface
> to use.
>
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> ---
> 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))
> --
> 2.28.0
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mm/page_alloc: Add __free_pages documentation
2020-10-27 2:55 [PATCH] mm/page_alloc: Add __free_pages documentation Matthew Wilcox (Oracle)
2020-10-27 19:03 ` William Kucharski
@ 2020-10-27 19:22 ` Vlastimil Babka
2020-10-28 8:35 ` Mike Rapoport
2 siblings, 0 replies; 4+ messages in thread
From: Vlastimil Babka @ 2020-10-27 19:22 UTC (permalink / raw)
To: Matthew Wilcox (Oracle), linux-mm
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) <willy@infradead.org>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
> ---
> 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))
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mm/page_alloc: Add __free_pages documentation
2020-10-27 2:55 [PATCH] mm/page_alloc: Add __free_pages documentation Matthew Wilcox (Oracle)
2020-10-27 19:03 ` William Kucharski
2020-10-27 19:22 ` Vlastimil Babka
@ 2020-10-28 8:35 ` Mike Rapoport
2 siblings, 0 replies; 4+ messages in thread
From: Mike Rapoport @ 2020-10-28 8:35 UTC (permalink / raw)
To: Matthew Wilcox (Oracle); +Cc: linux-mm
On Tue, Oct 27, 2020 at 02:55:23AM +0000, Matthew Wilcox (Oracle) wrote:
> Provide some guidance towards when this might not be the right interface
> to use.
>
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Mike Rapoport <rppt@linux.ibm.com>
> ---
> 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))
> --
> 2.28.0
>
>
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-10-28 8:35 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-27 2:55 [PATCH] mm/page_alloc: Add __free_pages documentation Matthew Wilcox (Oracle)
2020-10-27 19:03 ` William Kucharski
2020-10-27 19:22 ` Vlastimil Babka
2020-10-28 8:35 ` Mike Rapoport
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.