[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHk-=wifQimj2d6npq-wCi5onYPjzQg4vyO4tFcPJJZr268cRw@mail.gmail.com>
Date: Fri, 1 Apr 2022 11:29:17 -0700
From: Linus Torvalds <torvalds@...ux-foundation.org>
To: Zi Yan <ziy@...dia.com>
Cc: Linux-MM <linux-mm@...ck.org>,
Steven Rostedt <rostedt@...dmis.org>,
David Hildenbrand <david@...hat.com>,
Vlastimil Babka <vbabka@...e.cz>,
Mel Gorman <mgorman@...hsingularity.net>,
Mike Rapoport <rppt@...nel.org>,
Oscar Salvador <osalvador@...e.de>,
Andrew Morton <akpm@...ux-foundation.org>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v2 2/2] mm: wrap __find_buddy_pfn() with a necessary buddy
page validation.
On Fri, Apr 1, 2022 at 11:11 AM Zi Yan <zi.yan@...t.com> wrote:
>
> Whenever the buddy of a page is found from __find_buddy_pfn(),
> page_is_buddy() should be used to check its validity. Add a helper
> function find_buddy_page_pfn() to find the buddy page and do the check
> together.
Well, this certainly looks nicer, except now:
> +extern struct page *find_buddy_page_pfn(struct page *page, unsigned int order);
that 'pfn' no longer makes sense in the name, and
> @@ -1075,11 +1118,11 @@ static inline void __free_one_page(struct page *page,
> migratetype);
> return;
> }
> - buddy_pfn = __find_buddy_pfn(pfn, order);
> - buddy = page + (buddy_pfn - pfn);
>
> - if (!page_is_buddy(page, buddy, order))
> + buddy = find_buddy_page_pfn(page, order);
> + if (!buddy)
> goto done_merging;
> + buddy_pfn = page_to_pfn(buddy);
This case now does two "page_to_pfn()" calls (one inside
find_buddy_page_pfn(), and one explicitly on the buddy).
And those page_to_pfn() things can actually be fairly expensive. It
*looks* like just a subtraction, but it's a pointer subtraction that
can end up generating a divide by a non-power-of-two size.
NORMALLY we try very hard to make 'sizeof struct page' be exactly 8
words, but I do not believe this is actually guaranteed.
And yeah, the divide-by-a-constant can be turned into a multiply, but
even that is not necessarily always cheap.
Now, two out of three use-cases didn't actually want the buddy_pfn(),
but this one use-case does look like it might be performance-critical
and a problem.
Linus
Powered by blists - more mailing lists