Re: [PATCH v4 4/4] mm: Add zap_skip_check_mapping() helper
From: David Hildenbrand <hidden>
Date: 2021-09-24 10:11:22
Also in:
lkml
On 15.09.21 20:15, Peter Xu wrote:
quoted hunk ↗ jump to hunk
Use the helper for the checks. Rename "check_mapping" into "zap_mapping" because "check_mapping" looks like a bool but in fact it stores the mapping itself. When it's set, we check the mapping (it must be non-NULL). When it's cleared we skip the check, which works like the old way. Move the duplicated comments to the helper too. Reviewed-by: Alistair Popple <apopple@nvidia.com> Signed-off-by: Peter Xu <peterx@redhat.com> --- include/linux/mm.h | 16 +++++++++++++++- mm/memory.c | 29 ++++++----------------------- 2 files changed, 21 insertions(+), 24 deletions(-)diff --git a/include/linux/mm.h b/include/linux/mm.h index d1126f731221..ed44f31615d9 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h@@ -1721,10 +1721,24 @@ extern void user_shm_unlock(size_t, struct ucounts *); * Parameter block passed down to zap_pte_range in exceptional cases. */ struct zap_details { - struct address_space *check_mapping; /* Check page->mapping if set */ + struct address_space *zap_mapping; /* Check page->mapping if set */ struct page *single_page; /* Locked page to be unmapped */ }; +/* + * We set details->zap_mappings when we want to unmap shared but keep private + * pages. Return true if skip zapping this page, false otherwise. + */ +static inline bool +zap_skip_check_mapping(struct zap_details *details, struct page *page)
I agree with Hugh that the name of this helper is suboptimal.
What about inverting the conditions and getting
static inline bool should_zap_page()
{
...
}
The calling code is then
if (unlikely(!should_zap_page(details, page)))
continue;
I don't really like renaming "zap_mapping", again, because it's
contained within "struct zap_details" already.
Factoring this out into a helper sounds like a good idea to me. Clear
case of code de-duplication.
--
Thanks,
David / dhildenb