Commit 3ce4fee4 authored by Miaohe Lin's avatar Miaohe Lin Committed by akpm

mm/huge_memory: check pmd_present first in is_huge_zero_pmd

When pmd is non-present, pmd_pfn returns an insane value. So we should
check pmd_present first to avoid acquiring such insane value and also
avoid touching possible cold huge_zero_pfn cache line when pmd isn't
present.

Link: https://lkml.kernel.org/r/20220704132201.14611-11-linmiaohe@huawei.comSigned-off-by: default avatarMiaohe Lin <linmiaohe@huawei.com>
Reviewed-by: default avatarMuchun Song <songmuchun@bytedance.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Yang Shi <shy828301@gmail.com>
Cc: Zach O'Keefe <zokeefe@google.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent 74929079
...@@ -273,7 +273,7 @@ static inline bool is_huge_zero_page(struct page *page) ...@@ -273,7 +273,7 @@ static inline bool is_huge_zero_page(struct page *page)
static inline bool is_huge_zero_pmd(pmd_t pmd) static inline bool is_huge_zero_pmd(pmd_t pmd)
{ {
return READ_ONCE(huge_zero_pfn) == pmd_pfn(pmd) && pmd_present(pmd); return pmd_present(pmd) && READ_ONCE(huge_zero_pfn) == pmd_pfn(pmd);
} }
static inline bool is_huge_zero_pud(pud_t pud) static inline bool is_huge_zero_pud(pud_t pud)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment