Re: [PATCH 10/10] mm/hugetlb: not necessary to abuse temporary page to workaround the nasty free_huge_page
From: Mike Kravetz
Date: Tue Aug 11 2020 - 17:43:45 EST
On 8/10/20 11:54 PM, Michal Hocko wrote:
>
> I have managed to forgot all the juicy details since I have made that
> change. All that remains is that the surplus pages accounting was quite
> tricky and back then I didn't figure out a simpler method that would
> achieve the consistent look at those counters. As mentioned above I
> suspect this could lead to pre-mature allocation failures while the
> migration is ongoing.
It is likely lost in the e-mail thread, but the suggested change was to
alloc_surplus_huge_page(). The code which allocates the migration target
(alloc_migrate_huge_page) will not be changed. So, this should not be
an issue.
> Sure quite unlikely to happen and the race window
> is likely very small. Maybe this is even acceptable but I would strongly
> recommend to have all this thinking documented in the changelog.
I wrote down a description of what happens in the two different approaches
"temporary page" vs "surplus page". It is at the very end of this e-mail.
When looking at the details, I came up with what may be an even better
approach. Why not just call the low level routine to free the page instead
of going through put_page/free_huge_page? At the very least, it saves a
lock roundtrip and there is no need to worry about the counters/accounting.
Here is a patch to do that. However, we are optimizing a return path in
a race condition that we are unlikely to ever hit. I 'tested' it by allocating
an 'extra' page and freeing it via this method in alloc_surplus_huge_page.