v2: fix hugetlb vs. anon-thp copy page
Subsystems (4)
cover v2: fix hugetlb vs. anon-thp copy page
There were only minor comments about this the last time around. Any reason not not merge it?
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 1/2 mm: hugetlbfs: Add some VM_BUG_ON()s to catch non-hugetlbfs pages
From: Dave Hansen <[email protected]>
Dave Jiang reported that he was seeing oopses when running NUMA systems and default_hugepagesz=1G. I traced the issue down to migrate_page_copy() trying to use the same code for hugetlb pages and transparent hugepages. It should not have been trying to pass thp pages in there.
So, add some VM_BUG_ON()s for the next hapless VM developer that tries the same thing.
---
linux.git-davehans/include/linux/hugetlb.h | 1 + linux.git-davehans/mm/hugetlb.c | 1 + 2 files changed, 2 insertions(+)
include/linux/hugetlb.h renamed from include/linux/hugetlb.h~bug-not-hugetlbfs-in-copy_huge_page +1 -0
@@ -355,6 +355,7 @@ static inline pte_t arch_make_huge_pte(pstatic inline struct hstate *page_hstate (struct page *page) { +VM_BUG_ON (!PageHuge (page));return size_to_hstate (PAGE_SIZE <<compound_order (page)); }
mm/hugetlb.c renamed from mm/hugetlb.c~bug-not-hugetlbfs-in-copy_huge_page +1 -0
@@ -498,6 +498,7 @@ void copy_huge_page(struct page *dst, stint i;struct hstate *h =page_hstate (src); +VM_BUG_ON (!h);if (unlikely (pages_per_huge_page (h) >MAX_ORDER_NR_PAGES )) {copy_gigantic_page (dst, src);return ;
_
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 2/2 mm: thp: give transparent hugepage code a separate copy_page
In reply to Dave HansenChanges from v1:
* removed explicit might_sleep() in favor of the one that we get from the cond_resched();
--
From: Dave Hansen <[email protected]>
Right now, the migration code in migrate_page_copy() uses copy_huge_page() for hugetlbfs and thp pages:
if (PageHuge(page) || PageTransHuge(page))
copy_huge_page(newpage, page);So, yay for code reuse. But:
void copy_huge_page(struct page *dst, struct page *src)
{
struct hstate *h = page_hstate(src);and a non-hugetlbfs page has no page_hstate(). This works 99% of the time because page_hstate() determines the hstate from the page order alone. Since the page order of a THP page matches the default hugetlbfs page order, it works.
But, if you change the default huge page size on the boot command-line (say default_hugepagesz=1G), then we might not even *have* a 2MB hstate so page_hstate() returns null and copy_huge_page() oopses pretty fast since copy_huge_page() dereferences the hstate:
void copy_huge_page(struct page *dst, struct page *src)
{
struct hstate *h = page_hstate(src);
if (unlikely(pages_per_huge_page(h) > MAX_ORDER_NR_PAGES)) {...
This patch creates a copy_high_order_page() which can be used on THP pages.
I believe the bug was introduced in b32967ff101:
Author: Mel Gorman <[email protected]>
Date: Mon Nov 19 12:35:47 2012 +0000
mm: numa: Add THP migration for the NUMA working set scanning fault case.
---
linux.git-davehans/include/linux/huge_mm.h | 16 ++++++++++++++++ linux.git-davehans/mm/huge_memory.c | 12 ++++++++++++ linux.git-davehans/mm/migrate.c | 6 ++++-- 3 files changed, 32 insertions(+), 2 deletions(-)
include/linux/huge_mm.h renamed from include/linux/huge_mm.h~copy-huge-separate-from-copy-transhuge +16 -0
@@ -177,6 +177,10 @@ static inline struct page *compound_tranextern int do_huge_pmd_numa_page (struct mm_struct *mm,struct vm_area_struct *vma,unsigned long addr,pmd_t pmd,pmd_t *pmdp); +extern void copy_high_order_page (struct page *newpage, +struct page *oldpage, +int order); +#else /* CONFIG_TRANSPARENT_HUGEPAGE */ #define HPAGE_PMD_SHIFT ({ BUILD_BUG(); 0; })#define HPAGE_PMD_MASK ({ BUILD_BUG(); 0; })
@@ -227,6 +231,18 @@ static inline int do_huge_pmd_numa_page(return 0 ; } +/* +* The non-stub version of this code is probably usable +* generically but its only user is thp at the moment, +* so enforce that with a BUG() +*/ +static inline void copy_high_order_page (struct page *newpage, +struct page *oldpage, +int order) +{ +BUG (); +} +#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ #endif /* _LINUX_HUGE_MM_H */
mm/huge_memory.c renamed from mm/huge_memory.c~copy-huge-separate-from-copy-transhuge +12 -0
@@ -2890,3 +2890,15 @@ void __vma_adjust_trans_huge(struct vm_asplit_huge_page_address (next->vm_mm, nstart); } } + +void copy_high_order_page (struct page *newpage, +struct page *oldpage, +int order) +{ +int i; + +for (i =0 ; i < (1 <<order); i++) { +cond_resched (); +copy_highpage (newpage + i, oldpage + i); + } +}
mm/migrate.c renamed from mm/migrate.c~copy-huge-separate-from-copy-transhuge +4 -2
@@ -447,8 +447,10 @@ void migrate_page_copy(struct page *newp {int cpupid; -if (PageHuge (page) ||PageTransHuge (page)) -copy_huge_page (newpage, page); +if (PageHuge (page)) +copy_huge_page (newpage, page); +else if (PageTransHuge (page)) +copy_high_order_page (newpage, page,HPAGE_PMD_ORDER );else copy_highpage (newpage, page);
_
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 1/2] mm: hugetlbfs: Add some VM_BUG_ON()s to catch non-hugetlbfs pages
In reply to Dave HansenQuoted 9 lines · Dave Hansen
From: Dave Hansen <[email protected]>
Dave Jiang reported that he was seeing oopses when running NUMA systems and default_hugepagesz=1G. I traced the issue down to
migrate_page_copy()trying to use the same code for hugetlb pages and transparent hugepages. It should not have been trying to pass thp pages in there.
Quoted 6 lines
So, add some VM_BUG_ON()s for the next hapless VM developer that tries the same thing.
Signed-off-by Dave Hansen <[email protected]>Reviewed-by Naoya Horiguchi <[email protected]>
Signature · 8 lines
Mel Gorman SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 2/2] mm: thp: give transparent hugepage code a separate copy_page
In reply to Dave HansenQuoted 42 lines · Dave Hansen
Changes from v1:
* removed explicitmight_sleep()in favor of the one that we get from thecond_resched();--
From: Dave Hansen <[email protected]>
Right now, the migration code in
migrate_page_copy()usescopy_huge_page()for hugetlbfs and thp pages:if (PageHuge(page) || PageTransHuge(page)) copy_huge_page(newpage, page);So, yay for code reuse. But:
void
copy_huge_page(struct page *dst, struct page *src){ struct hstate *h = page_hstate(src);and a non-hugetlbfs page has no
page_hstate(). This works 99% of the time becausepage_hstate()determines the hstate from the page order alone. Since the page order of a THP page matches the default hugetlbfs page order, it works.But, if you change the default huge page size on the boot command-line (say default_hugepagesz=1G), then we might not even *have* a 2MB hstate so
page_hstate()returns null andcopy_huge_page()oopses pretty fast sincecopy_huge_page()dereferences the hstate:void
copy_huge_page(struct page *dst, struct page *src){ struct hstate *h = page_hstate(src); if (unlikely(pages_per_huge_page(h) > MAX_ORDER_NR_PAGES)) {...
This patch creates a
copy_high_order_page()which can be used on THP pages.
Quoted 6 lines
I believe the bug was introduced in
b32967ff101:
Author: Mel Gorman <[email protected]>
Date: Mon Nov 19 12:35:47 2012 +0000
mm: numa: Add THP migration for the NUMA working set scanning fault case.Signed-off-by Dave Hansen <[email protected]>
It is a mild pity that there are variants of this like copy_user_huge_page for COW. They could be collapsed but the result API would not be pretty.
A rename of copy_huge_page to copy_hugetlbfs_page is justified to avoid a repeat mistake. Alternatively, there seems to be little reason to add hugetlbfs and thp specific apis when you could just do something like this (untested)
mm/hugetlb.c +0 -34
@@ -476,40 +476,6 @@ static int vma_has_reserves(struct vm_area_struct *vma, long chg)return 0 ; } -static void copy_gigantic_page (struct page *dst,struct page *src) -{ -int i; -struct hstate *h =page_hstate (src); -struct page *dst_base = dst; -struct page *src_base = src; - -for (i =0 ; i <pages_per_huge_page (h); ) { -cond_resched (); -copy_highpage (dst, src); - - i++; - dst =mem_map_next (dst, dst_base, i); - src =mem_map_next (src, src_base, i); - } -} - -void copy_huge_page (struct page *dst,struct page *src) -{ -int i; -struct hstate *h =page_hstate (src); - -if (unlikely (pages_per_huge_page (h) >MAX_ORDER_NR_PAGES )) { -copy_gigantic_page (dst, src); -return ; - } - -might_sleep (); -for (i =0 ; i <pages_per_huge_page (h); i++) { -cond_resched (); -copy_highpage (dst + i, src + i); - } -} -static void enqueue_huge_page (struct hstate *h,struct page *page) {int nid =page_to_nid (page);
mm/migrate.c +43 -0
49 lines not on this page · raw message
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>