* [PATCH] mm: do not acquire zone lock in is_free_buddy_page()
@ 2021-09-22 15:28 Eric Dumazet
2021-09-22 23:23 ` Hugh Dickins
0 siblings, 1 reply; 2+ messages in thread
From: Eric Dumazet @ 2021-09-22 15:28 UTC (permalink / raw)
To: Andrew Morton
Cc: linux-kernel, linux-mm, Eric Dumazet, Eric Dumazet, Hugh Dickins
From: Eric Dumazet <edumazet@google.com>
Grabbing zone lock in is_free_buddy_page() gives a wrong sense of safety,
and has potential performance implications when zone is experiencing
lock contention.
In any case, if a caller needs a stable result, it should grab zone
lock before calling this function.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Hugh Dickins <hughd@google.com>
---
mm/page_alloc.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index e115e21524739341d409b28379942241ed403060..cd8a72372b047e55c4cde80fe6b7a428d7721027 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -9354,21 +9354,21 @@ void __offline_isolated_pages(unsigned long start_pfn, unsigned long end_pfn)
}
#endif
+/*
+ * This function returns a stable result only if called under zone lock.
+ */
bool is_free_buddy_page(struct page *page)
{
- struct zone *zone = page_zone(page);
unsigned long pfn = page_to_pfn(page);
- unsigned long flags;
unsigned int order;
- spin_lock_irqsave(&zone->lock, flags);
for (order = 0; order < MAX_ORDER; order++) {
struct page *page_head = page - (pfn & ((1 << order) - 1));
- if (PageBuddy(page_head) && buddy_order(page_head) >= order)
+ if (PageBuddy(page_head) &&
+ buddy_order_unsafe(page_head) >= order)
break;
}
- spin_unlock_irqrestore(&zone->lock, flags);
return order < MAX_ORDER;
}
--
2.33.0.464.g1972c5931b-goog
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] mm: do not acquire zone lock in is_free_buddy_page()
2021-09-22 15:28 [PATCH] mm: do not acquire zone lock in is_free_buddy_page() Eric Dumazet
@ 2021-09-22 23:23 ` Hugh Dickins
0 siblings, 0 replies; 2+ messages in thread
From: Hugh Dickins @ 2021-09-22 23:23 UTC (permalink / raw)
To: Eric Dumazet
Cc: Andrew Morton, linux-kernel, linux-mm, Eric Dumazet, Hugh Dickins
On Wed, 22 Sep 2021, Eric Dumazet wrote:
> From: Eric Dumazet <edumazet@google.com>
>
> Grabbing zone lock in is_free_buddy_page() gives a wrong sense of safety,
> and has potential performance implications when zone is experiencing
> lock contention.
>
> In any case, if a caller needs a stable result, it should grab zone
> lock before calling this function.
>
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Cc: Hugh Dickins <hughd@google.com>
Yes indeed, and you have already explained it well above: thanks.
Acked-by: Hugh Dickins <hughd@google.com>
> ---
> mm/page_alloc.c | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index e115e21524739341d409b28379942241ed403060..cd8a72372b047e55c4cde80fe6b7a428d7721027 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -9354,21 +9354,21 @@ void __offline_isolated_pages(unsigned long start_pfn, unsigned long end_pfn)
> }
> #endif
>
> +/*
> + * This function returns a stable result only if called under zone lock.
> + */
> bool is_free_buddy_page(struct page *page)
> {
> - struct zone *zone = page_zone(page);
> unsigned long pfn = page_to_pfn(page);
> - unsigned long flags;
> unsigned int order;
>
> - spin_lock_irqsave(&zone->lock, flags);
> for (order = 0; order < MAX_ORDER; order++) {
> struct page *page_head = page - (pfn & ((1 << order) - 1));
>
> - if (PageBuddy(page_head) && buddy_order(page_head) >= order)
> + if (PageBuddy(page_head) &&
> + buddy_order_unsafe(page_head) >= order)
> break;
> }
> - spin_unlock_irqrestore(&zone->lock, flags);
>
> return order < MAX_ORDER;
> }
> --
> 2.33.0.464.g1972c5931b-goog
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-09-22 23:23 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-22 15:28 [PATCH] mm: do not acquire zone lock in is_free_buddy_page() Eric Dumazet
2021-09-22 23:23 ` Hugh Dickins
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).