Transparent Hugepage Support #32
Subsystems (35)
Re: [PATCH 03 of 66] transparent hugepage support documentation
In reply to Mel GormanQuoted 10 lines · Mel Gorman
libhugetlbfs can also automatically back shared memory, text and data with huge pages which THP cannot do. libhugetlbfs cannot demote and promote memory where THP can. They are not exactly like-with-like comparisons. How about;
"Transparent Hugepage Support is an alternative means of using huge pages for the backing of anonymous memory with huge pages that supports the automatic promotion and demotion of page sizes."
?
Ok I changed it like this:
Documentation/vm/transhuge.txt +6 -5
@@ -4,12 +4,13 @@ Performance critical computing applications dealing with large memory working sets are already running on top of libhugetlbfs and in turn -hugetlbfs. Transparent Hugepage Support is an alternative to -libhugetlbfs that offers the same feature of libhugetlbfs but without -the shortcomings of hugetlbfs (for KVM, JVM, HPC, even gcc etc..). +hugetlbfs. Transparent Hugepage Support is an alternative means of +using huge pages for the backing of virtual memory with huge pages +that supports the automatic promotion and demotion of page sizes and +without the shortcomings of hugetlbfs. -In the future it can expand over the pagecache layer starting with -tmpfs to reduce even further the hugetlbfs usages. +Currently it only works for anonymous memory mappings but in the +future it can expand over the pagecache layer starting with tmpfs. The reason applications are running faster is because of two factors. The first factor is almost completely irrelevant and it's not
Quoted 24 lines
Quoted 7 lines
(quoted diff) +7
-0+In the future it can expand over the pagecache layer starting with +tmpfs to reduce even further the hugetlbfs usages. + +The reason applications are running faster is because of two +factors. The first factor is almost completely irrelevant and it's not +of significant interest because it'll also have the downside of +requiring larger clear-page copy-page in page faults which is aReview
Quoted 10 lines
(quoted diff) +10
-0+potentially negative effect. The first factor consists in taking a +single page fault for each 2M virtual region touched by userland (so +reducing the enter/exit kernel frequency by a 512 times factor). This +only matters the first time the memory is accessed for the lifetime of +a memory mapping. The second long lasting and much more important +factor will affect all subsequent accesses to the memory for the whole +runtime of the application. The second factor consist of two +components: 1) the TLB miss will run faster (especially with +virtualization using nested pagetables but also on bare metal without +virtualization)Careful on that first statement. It's not necessarily true for bare metal as some processors show that the TLB miss handler for huge pages is slower than base pages. Not sure why but it seemed to be the case on P4 anyway (at least the one I have). Maybe it was a measurement error but on chips with split TLBs for page sizes, there is no guarantee they are the same speed.
Quoted 5 lines
It's probably true for virtualisation though considering the vastly reduced number of cache lines required to translate an address.
I'd weaken the language for bare metal to say "almost always" but it's not a big deal.
Agreed.
Documentation/vm/transhuge.txt +8 -8
@@ -23,14 +24,14 @@ a memory mapping. The second long lastin factor will affect all subsequent accesses to the memory for the whole runtime of the application. The second factor consist of two components: 1) the TLB miss will run faster (especially with -virtualization using nested pagetables but also on bare metal without -virtualization) and 2) a single TLB entry will be mapping a much -larger amount of virtual memory in turn reducing the number of TLB -misses. With virtualization and nested pagetables the TLB can be -mapped of larger size only if both KVM and the Linux guest are using -hugepages but a significant speedup already happens if only one of the -two is using hugepages just because of the fact the TLB miss is going -to run faster. +virtualization using nested pagetables but almost always also on bare +metal without virtualization) and 2) a single TLB entry will be +mapping a much larger amount of virtual memory in turn reducing the +number of TLB misses. With virtualization and nested pagetables the +TLB can be mapped of larger size only if both KVM and the Linux guest +are using hugepages but a significant speedup already happens if only +one of the two is using hugepages just because of the fact the TLB +miss is going to run faster. == Design ==
Quoted 4 lines
Quoted 4 lines
(quoted diff) +4
-0+With virtualization and nested pagetables the TLB can be +mapped of larger size only if both KVM and the Linux guest are using +hugepages but a significant speedup already happens if only one of the +two is using hugepages just because of the fact the TLB miss is going
Quoted 8 lines
Review
Quoted 6 lines
(quoted diff) +6
-0+to run faster. + +== Design == + +- "graceful fallback": mm components which don't have transparent + hugepage knownledge fall back to breaking a transparent hugepage and%s/knownledge/knowledge/
corrected.
Quoted 6 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+ working on the regular pages and their respective regular pmd/pte + mappings + +- if an hugepage allocation fails because of memory fragmentation,s/an/a/
I'll trust you on this one ;).
Quoted 7 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+ regular pages should be gracefully allocated instead and mixed in + the same vma without any failure or significant delay and generally + without userland noticing +why "generally"? At worst the application will see varying performance characteristics but that applies to a lot more than THP.
Removed "generally".
Quoted 21 lines
Review
Quoted 6 lines
+- if some task quits and more hugepages become available (either
(quoted diff) +5
-0+ immediately in the buddy or through the VM), guest physical memory + backed by regular pages should be relocated on hugepages + automatically (with khugepaged) + +- it doesn't require boot-time memory reservation and in turn it usesneither does hugetlbfs.
Quoted 12 lines
(quoted diff) +12
-0+ hugepages whenever possible (the only possible reservation here is + kernelcore= to avoid unmovable pages to fragment all the memory but + such a tweak is not specific to transparent hugepage support and + it's a generic feature that applies to all dynamic high order + allocations in the kernel) + +- this initial support only offers the feature in the anonymous memory + regions but it'd be ideal to move it to tmpfs and the pagecache + later + +Transparent Hugepage Support maximizes the usefulness of free memory +if compared to the reservation approach of hugetlbfs by allowing all
Quoted 8 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+unused memory to be used as cache or other movable (or even unmovable +entities).hugetlbfs with memory overcommit offers something similar, particularly in combination with libhugetlbfs with can automatically fall back to base pages. I've run benchmarks comparing hugetlbfs using a static hugepage pool with hugetlbfs dynamically allocating hugepages as required with no discernable performance difference. So this statement is not strictly accurate.
Ok, but without libhugetlbfs fallback to regular pages splitting the vma and creating a no-hugetlbfs one in the middle, it really requires memory reservation to be _sure_ (libhugtlbfs runs outside of hugetlbfs and I doubt it allows later collapsing like khugepaged provides, furthermore I'm comparing kernel vs kernel not kernel vs kernel+userlandwrapping)... So I think mentioning the fact THP doesn't require memory reservation is more or less fair enough. I removed "boot-time" though.
Quoted 37 lines
Quoted 37 lines
(quoted diff) +37
-0+It doesn't require reservation to prevent hugepage +allocation failures to be noticeable from userland. It allows paging +and all other advanced VM features to be available on the +hugepages. It requires no modifications for applications to take +advantage of it. + +Applications however can be further optimized to take advantage of +this feature, like for example they've been optimized before to avoid +a flood of mmap system calls for every malloc(4k). Optimizing userland +is by far not mandatory and khugepaged already can take care of long +lived page allocations even for hugepage unaware applications that +deals with large amounts of memory. + +In certain cases when hugepages are enabled system wide, application +may end up allocating more memory resources. An application may mmap a +large region but only touch 1 byte of it, in that case a 2M page might +be allocated instead of a 4k page for no good. This is why it's +possible to disable hugepages system-wide and to only have them inside +MADV_HUGEPAGE madvise regions. + +Embedded systems should enable hugepages only inside madvise regions +to eliminate any risk of wasting any precious byte of memory and to +only run faster. + +Applications that gets a lot of benefit from hugepages and that don't +risk to lose memory by using hugepages, should use +madvise(MADV_HUGEPAGE) on their critical mmapped regions. + +== sysfs == + +Transparent Hugepage Support can be entirely disabled (mostly for +debugging purposes) or only enabled inside MADV_HUGEPAGE regions (to +avoid the risk of consuming more memory resources) or enabled system +wide. This can be achieved with one of: + +echo always >/sys/kernel/mm/transparent_hugepage/enabled +echo madvise >/sys/kernel/mm/transparent_hugepage/enabled
Quoted 8 lines
Review
Quoted 6 lines
(quoted diff) +6
-0+echo never >/sys/kernel/mm/transparent_hugepage/enabled + +It's also possible to limit defrag efforts in the VM to generate +hugepages in case they're not immediately free to madvise regions or +to never try to defrag memory and simply fallback to regular pages +unless hugepages are immediately available.This is the first mention of defrag but hey, it's not a paper :)
Not sure I get it this, is this too early or too late to mention defrag? But yes this is not a paper so I guess I don't need to care ;)
Quoted 4 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+and how many milliseconds to wait in khugepaged between each pass (you +can se this to 0 to run khugepaged at 100% utilization of one core):s/se/set/
good eye ;)
Quoted 28 lines
Quoted 15 lines
(quoted diff) +15
-0+ +/sys/kernel/mm/transparent_hugepage/khugepaged/scan_sleep_millisecs + +and how many milliseconds to wait in khugepaged if there's an hugepage +allocation failure to throttle the next allocation attempt. + +/sys/kernel/mm/transparent_hugepage/khugepaged/alloc_sleep_millisecs + +The khugepaged progress can be seen in the number of pages collapsed: + +/sys/kernel/mm/transparent_hugepage/khugepaged/pages_collapsed + +for each pass: + +/sys/kernel/mm/transparent_hugepage/khugepaged/full_scansReview
Quoted 10 lines
(quoted diff) +10
-0+ +== Boot parameter == + +You can change the sysfs boot time defaults of Transparent Hugepage +Support by passing the parameter "transparent_hugepage=always" or +"transparent_hugepage=madvise" or "transparent_hugepage=never" +(without "") to the kernel command line. + +== Need of restart == +Need of application restart?
Quoted 2 lines
A casual reader might otherwise interpret it as a system restart for some godawful reason of their own.
Agreed.
Quoted 4 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+The transparent_hugepage/enabled values only affect future +behavior. So to make them effective you need to restart anys/behavior/behaviour/
Funny, after this change my spell checker asks me to rename behaviour back to behavior. I'll stick to the spell checker, they are synonymous anyway.
Quoted 8 lines
Review
Quoted 6 lines
(quoted diff) +6
-0+In case you can't handle compound pages if they're returned by +follow_page, the FOLL_SPLIT bit can be specified as parameter to +follow_page, so that it will split the hugepages before returning +them. Migration for example passes FOLL_SPLIT as parameter to +follow_page because it's not hugepage aware and in fact it can't work +at all on hugetlbfs (but it instead works fine on transparenthugetlbfs pages can now migrate although it's only used by hwpoison.
Yep. I'll need to teach migrate to avoid splitting the hugepage to migrate it too... (especially for numa, not much for hwpoison). And the migration support for hugetlbfs now makes it more complicated to migrate transhuge pages too with the same function because that code isn't inside a VM_HUGETLB check... Worst case we can check the hugepage destructor to differentiate the two, I've yet to check that. Surely it's feasible and mostly an implementation issue.
Quoted 4 lines
Quoted 4 lines
(quoted diff) +4
-0+Code walking pagetables but unware about huge pmds can simply call +split_huge_page_pmd(mm, pmd) where the pmd is the one returned by +pmd_offset. It's trivial to make the code transparent hugepage aware +by just grepping for "pmd_offset" and adding split_huge_page_pmd where
Quoted 8 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+missing after pmd_offset returns the pmd. Thanks to the graceful +fallback design, with a one liner change, you can avoid to write +hundred if not thousand of lines of complex code to make your code +hugepage aware. +It'd be nice if you could point to a specific example but by no means mandatory.
Ok:
Documentation/vm/transhuge.txt +14 -0
@@ -226,6 +226,20 @@ but you can't handle it natively in your calling split_huge_page(page). This is what the Linux VM does before it tries to swapout the hugepage for example. +Example to make mremap.c transparent hugepage aware with a one liner +change: + +diff --git a/mm/mremap.c b/mm/mremap.c +--- a/mm/mremap.c ++++ b/mm/mremap.c +@@ -41,6 +41,7 @@ static pmd_t *get_old_pmd(struct mm_stru + return NULL; + + pmd = pmd_offset(pud, addr); ++ split_huge_page_pmd(mm, pmd); + if (pmd_none_or_clear_bad(pmd)) + return NULL; + == Locking in hugepage aware code == We want as much code as possible hugepage aware, as calling
Quoted 6 lines
Ok, I'll need to read the rest of the series to verify if this is correct but by and large it looks good. I think some of the language is stronger than it should be and some of the comparisons with libhugetlbfs are a bit off but I'd be naturally defensive on that topic. Make the suggested changes if you like but if you don't, it shouldn't affect the series.
I hope it looks better now, thanks!
---------
= Transparent Hugepage Support =
== Objective ==
Performance critical computing applications dealing with large memory working sets are already running on top of libhugetlbfs and in turn hugetlbfs. Transparent Hugepage Support is an alternative means of using huge pages for the backing of virtual memory with huge pages that supports the automatic promotion and demotion of page sizes and without the shortcomings of hugetlbfs.
Currently it only works for anonymous memory mappings but in the future it can expand over the pagecache layer starting with tmpfs.
The reason applications are running faster is because of two factors. The first factor is almost completely irrelevant and it's not of significant interest because it'll also have the downside of requiring larger clear-page copy-page in page faults which is a potentially negative effect. The first factor consists in taking a single page fault for each 2M virtual region touched by userland (so reducing the enter/exit kernel frequency by a 512 times factor). This only matters the first time the memory is accessed for the lifetime of a memory mapping. The second long lasting and much more important factor will affect all subsequent accesses to the memory for the whole runtime of the application. The second factor consist of two
components: 1) the TLB miss will run faster (especially with virtualization using nested pagetables but almost always also on bare metal without virtualization) and 2) a single TLB entry will be mapping a much larger amount of virtual memory in turn reducing the number of TLB misses. With virtualization and nested pagetables the TLB can be mapped of larger size only if both KVM and the Linux guest are using hugepages but a significant speedup already happens if only one of the two is using hugepages just because of the fact the TLB miss is going to run faster.
== Design ==
- "graceful fallback": mm components which don't have transparent hugepage knowledge fall back to breaking a transparent hugepage and working on the regular pages and their respective regular pmd/pte mappings
- if a hugepage allocation fails because of memory fragmentation, regular pages should be gracefully allocated instead and mixed in the same vma without any failure or significant delay and without userland noticing
- if some task quits and more hugepages become available (either immediately in the buddy or through the VM), guest physical memory backed by regular pages should be relocated on hugepages automatically (with khugepaged)
- it doesn't require memory reservation and in turn it uses hugepages whenever possible (the only possible reservation here is kernelcore= to avoid unmovable pages to fragment all the memory but such a tweak is not specific to transparent hugepage support and it's a generic feature that applies to all dynamic high order allocations in the kernel)
- this initial support only offers the feature in the anonymous memory regions but it'd be ideal to move it to tmpfs and the pagecache later
Transparent Hugepage Support maximizes the usefulness of free memory if compared to the reservation approach of hugetlbfs by allowing all unused memory to be used as cache or other movable (or even unmovable entities). It doesn't require reservation to prevent hugepage allocation failures to be noticeable from userland. It allows paging and all other advanced VM features to be available on the hugepages. It requires no modifications for applications to take advantage of it.
Applications however can be further optimized to take advantage of this feature, like for example they've been optimized before to avoid a flood of mmap system calls for every malloc(4k). Optimizing userland is by far not mandatory and khugepaged already can take care of long lived page allocations even for hugepage unaware applications that deals with large amounts of memory.
In certain cases when hugepages are enabled system wide, application may end up allocating more memory resources. An application may mmap a large region but only touch 1 byte of it, in that case a 2M page might be allocated instead of a 4k page for no good. This is why it's possible to disable hugepages system-wide and to only have them inside MADV_HUGEPAGE madvise regions.
Embedded systems should enable hugepages only inside madvise regions to eliminate any risk of wasting any precious byte of memory and to only run faster.
Applications that gets a lot of benefit from hugepages and that don't risk to lose memory by using hugepages, should use madvise(MADV_HUGEPAGE) on their critical mmapped regions.
== sysfs ==
Transparent Hugepage Support can be entirely disabled (mostly for debugging purposes) or only enabled inside MADV_HUGEPAGE regions (to avoid the risk of consuming more memory resources) or enabled system wide. This can be achieved with one of:
echo always >/sys/kernel/mm/transparent_hugepage/enabled echo madvise >/sys/kernel/mm/transparent_hugepage/enabled echo never >/sys/kernel/mm/transparent_hugepage/enabled
It's also possible to limit defrag efforts in the VM to generate hugepages in case they're not immediately free to madvise regions or to never try to defrag memory and simply fallback to regular pages unless hugepages are immediately available. Clearly if we spend CPU time to defrag memory, we would expect to gain even more by the fact we use hugepages later instead of regular pages. This isn't always guaranteed, but it may be more likely in case the allocation is for a MADV_HUGEPAGE region.
echo always >/sys/kernel/mm/transparent_hugepage/defrag echo madvise >/sys/kernel/mm/transparent_hugepage/defrag echo never >/sys/kernel/mm/transparent_hugepage/defrag
khugepaged will be automatically started when transparent_hugepage/enabled is set to "always" or "madvise, and it'll be automatically shutdown if it's set to "never".
khugepaged runs usually at low frequency so while one may not want to invoke defrag algorithms synchronously during the page faults, it should be worth invoking defrag at least in khugepaged. However it's also possible to disable defrag in khugepaged:
echo yes >/sys/kernel/mm/transparent_hugepage/khugepaged/defrag echo no >/sys/kernel/mm/transparent_hugepage/khugepaged/defrag
You can also control how many pages khugepaged should scan at each pass:
/sys/kernel/mm/transparent_hugepage/khugepaged/pages_to_scan
and how many milliseconds to wait in khugepaged between each pass (you can set this to 0 to run khugepaged at 100% utilization of one core):
/sys/kernel/mm/transparent_hugepage/khugepaged/scan_sleep_millisecs
and how many milliseconds to wait in khugepaged if there's an hugepage allocation failure to throttle the next allocation attempt.
/sys/kernel/mm/transparent_hugepage/khugepaged/alloc_sleep_millisecs
The khugepaged progress can be seen in the number of pages collapsed:
/sys/kernel/mm/transparent_hugepage/khugepaged/pages_collapsed
for each pass:
/sys/kernel/mm/transparent_hugepage/khugepaged/full_scans
== Boot parameter ==
You can change the sysfs boot time defaults of Transparent Hugepage Support by passing the parameter "transparent_hugepage=always" or "transparent_hugepage=madvise" or "transparent_hugepage=never" (without "") to the kernel command line.
== Need of application restart ==
The transparent_hugepage/enabled values only affect future behavior. So to make them effective you need to restart any application that could have been using hugepages. This also applies to the regions registered in khugepaged.
== get_user_pages and follow_page ==
get_user_pages and follow_page if run on a hugepage, will return the head or tail pages as usual (exactly as they would do on hugetlbfs). Most gup users will only care about the actual physical address of the page and its temporary pinning to release after the I/O is complete, so they won't ever notice the fact the page is huge. But if any driver is going to mangle over the page structure of the tail page (like for checking page->mapping or other bits that are relevant for the head page and not the tail page), it should be updated to jump to check head page instead (while serializing properly against split_huge_page() to avoid the head and tail pages to disappear from under it, see the futex code to see an example of that, hugetlbfs also needed special handling in futex code for similar reasons).
NOTE: these aren't new constraints to the GUP API, and they match the same constrains that applies to hugetlbfs too, so any driver capable of handling GUP on hugetlbfs will also work fine on transparent hugepage backed mappings.
In case you can't handle compound pages if they're returned by follow_page, the FOLL_SPLIT bit can be specified as parameter to follow_page, so that it will split the hugepages before returning them. Migration for example passes FOLL_SPLIT as parameter to follow_page because it's not hugepage aware and in fact it can't work at all on hugetlbfs (but it instead works fine on transparent hugepages thanks to FOLL_SPLIT). migration simply can't deal with hugepages being returned (as it's not only checking the pfn of the page and pinning it during the copy but it pretends to migrate the memory in regular page sizes and with regular pte/pmd mappings).
== Optimizing the applications ==
To be guaranteed that the kernel will map a 2M page immediately in any memory region, the mmap region has to be hugepage naturally aligned. posix_memalign() can provide that guarantee.
== Hugetlbfs ==
You can use hugetlbfs on a kernel that has transparent hugepage support enabled just fine as always. No difference can be noted in hugetlbfs other than there will be less overall fragmentation. All usual features belonging to hugetlbfs are preserved and unaffected. libhugetlbfs will also work fine as usual.
== Graceful fallback ==
Code walking pagetables but unware about huge pmds can simply call split_huge_page_pmd(mm, pmd) where the pmd is the one returned by pmd_offset. It's trivial to make the code transparent hugepage aware by just grepping for "pmd_offset" and adding split_huge_page_pmd where missing after pmd_offset returns the pmd. Thanks to the graceful fallback design, with a one liner change, you can avoid to write hundred if not thousand of lines of complex code to make your code hugepage aware.
If you're not walking pagetables but you run into a physical hugepage but you can't handle it natively in your code, you can split it by calling split_huge_page(page). This is what the Linux VM does before it tries to swapout the hugepage for example.
Example to make mremap.c transparent hugepage aware with a one liner change:
mm/mremap.c +1 -0
@@ -41,6 +41,7 @@ static pmd_t *get_old_pmd(struct mm_strureturn NULL ; pmd =pmd_offset (pud, addr); +split_huge_page_pmd (mm, pmd);if (pmd_none_or_clear_bad (pmd))return NULL ;
== Locking in hugepage aware code ==
We want as much code as possible hugepage aware, as calling split_huge_page() or split_huge_page_pmd() has a cost.
To make pagetable walks huge pmd aware, all you need to do is to call pmd_trans_huge() on the pmd returned by pmd_offset. You must hold the mmap_sem in read (or write) mode to be sure an huge pmd cannot be created from under you by khugepaged (khugepaged collapse_huge_page takes the mmap_sem in write mode in addition to the anon_vma lock). If pmd_trans_huge returns false, you just fallback in the old code paths. If instead pmd_trans_huge returns true, you have to take the mm->page_table_lock and re-run pmd_trans_huge. Taking the page_table_lock will prevent the huge pmd to be converted into a regular pmd from under you (split_huge_page can run in parallel to the pagetable walk). If the second pmd_trans_huge returns false, you should just drop the page_table_lock and fallback to the old code as before. Otherwise you should run pmd_trans_splitting on the pmd. In case pmd_trans_splitting returns true, it means split_huge_page is already in the middle of splitting the page. So if pmd_trans_splitting returns true it's enough to drop the page_table_lock and call wait_split_huge_page and then fallback the old code paths. You are guaranteed by the time wait_split_huge_page returns, the pmd isn't huge anymore. If pmd_trans_splitting returns false, you can proceed to process the huge pmd and the hugepage natively. Once finished you can drop the page_table_lock.
== compound_lock, get_user_pages and put_page ==
split_huge_page internally has to distribute the refcounts in the head page to the tail pages before clearing all PG_head/tail bits from the page structures. It can do that easily for refcounts taken by huge pmd mappings. But the GUI API as created by hugetlbfs (that returns head and tail pages if running get_user_pages on an address backed by any hugepage), requires the refcount to be accounted on the tail pages and not only in the head pages, if we want to be able to run split_huge_page while there are gup pins established on any tail page. Failure to be able to run split_huge_page if there's any gup pin on any tail page, would mean having to split all hugepages upfront in get_user_pages which is unacceptable as too many gup users are performance critical and they must work natively on hugepages like they work natively on hugetlbfs already (hugetlbfs is simpler because hugetlbfs pages cannot be splitted so there wouldn't be requirement of accounting the pins on the tail pages for hugetlbfs). If we wouldn't account the gup refcounts on the tail pages during gup, we won't know anymore which tail page is pinned by gup and which is not while we run split_huge_page. But we still have to add the gup pin to the head page too, to know when we can free the compound page in case it's never splitted during its lifetime. That requires changing not just get_page, but put_page as well so that when put_page runs on a tail page (and only on a tail page) it will find its respective head page, and then it will decrease the head page refcount in addition to the tail page refcount. To obtain a head page reliably and to decrease its refcount without race conditions, put_page has to serialize against __split_huge_page_refcount using a special per-page lock called compound_lock.
--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 05 of 66] compound_lock
In reply to Linus TorvaldsQuoted 17 lines · Linus Torvalds
Quoted 7 lines · Mel Gorman
Quoted 7 lines
(quoted diff) +7
-0+ +static inline void compound_lock_irqsave(struct page *page, + unsigned long *flagsp) +{ +#ifdef CONFIG_TRANSPARENT_HUGEPAGE + unsigned long flags; + local_irq_save(flags);Quoted 8 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ compound_lock(page); + *flagsp = flags; +#endif +} +The pattern for spinlock irqsave passes in unsigned long, not unsigned long *. It'd be nice if they matched.
Quoted 2 lines
Indeed. Just make the thing return the flags the way the normal
spin_lock_irqsave()function does.
Done.
include/linux/mm.h +3 -4
@@ -320,15 +320,14 @@ static inline void compound_unlock(struc#endif } -static inline void compound_lock_irqsave (struct page *page, -unsigned long *flagsp) +static inline unsigned long compound_lock_irqsave (struct page *page) { +unsigned long uninitialized_var (flags );#ifdef CONFIG_TRANSPARENT_HUGEPAGE -unsigned long flags;local_irq_save (flags);compound_lock (page); - *flagsp = flags;#endif +return flags; } static inline void compound_unlock_irqrestore(struct page *page,
mm/swap.c +1 -1
@@ -94,7 +94,7 @@ static void put_compound_page(struct pag*/ smp_mb ();/* page_head wasn't a dangling pointer */ -compound_lock_irqsave (page_head, &flags); + flags =compound_lock_irqsave (page_head);if (unlikely (!PageTail (page))) {/* __split_huge_page_refcount run before us */ compound_unlock_irqrestore (page_head, flags);
Thanks,
Andrea
--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 06 of 66] alter compound get_page/put_page
In reply to Mel GormanQuoted 16 lines · Mel Gorman
Quoted 15 lines · Andrea Arcangeli
From: Andrea Arcangeli <[email protected]>
Alter compound get_page/put_page to keep references on subpages too, in order to allow
__split_huge_page_refcountto split an hugepage even while subpages have been pinned by one of theget_user_pages()variants.Signed-off-by Andrea Arcangeli <[email protected]>Acked-by Rik van Riel <[email protected]>---
arch/powerpc/mm/gup.c +0
-0@@ -16,6 +16,16 @@
Quoted 8 lines
arch/powerpc/mm/gup.c line 20
Quoted 4 lines
arch/powerpc/mm/gup.c +2
-0#ifdef __HAVE_ARCH_PTE_SPECIAL +static inline void pin_huge_page_tail (struct page *page) +{Minor nit, but
get_huge_page_tail?Even though "pin" is what it does, pin isn't used elsewhere in naming.
Agreed.
arch/powerpc/mm/gup.c +2 -2
@@ -16,7 +16,7 @@#ifdef __HAVE_ARCH_PTE_SPECIAL -static inline void pin_huge_page_tail (struct page *page) +static inline void get_huge_page_tail (struct page *page) {/* * __split_huge_page_refcount() cannot run
@@ -58,7 +58,7 @@ static noinline int gup_pte_range(pmd_treturn 0 ; }if (PageTail (page)) -pin_huge_page_tail (page); +get_huge_page_tail (page); pages[*nr] = page; (*nr)++;
arch/x86/mm/gup.c +2 -2
@@ -105,7 +105,7 @@ static inline void get_head_page_multiplatomic_add (nr, &page->_count); } -static inline void pin_huge_page_tail (struct page *page) +static inline void get_huge_page_tail (struct page *page) {/* * __split_huge_page_refcount() cannot run
@@ -139,7 +139,7 @@ static noinline int gup_huge_pmd(pmd_t pVM_BUG_ON (compound_head (page) != head); pages[*nr] = page;if (PageTail (page)) -pin_huge_page_tail (page); +get_huge_page_tail (page); (*nr)++; page++; refs++;
Quoted 7 lines
Quoted 7 lines
arch/x86/mm/gup.c +0
-0@@ -105,6 +105,16 @@ static inline void get_head_page_multiplatomic_add (nr, &page->_count); }
Quoted 13 lines
arch/x86/mm/gup.c static inline void get_head_page_multipl · line 117
Quoted 10 lines
arch/x86/mm/gup.c +10
-0+static inline void pin_huge_page_tail (struct page *page) +{ +/* +* __split_huge_page_refcount() cannot run +* from under us. +*/ +VM_BUG_ON (atomic_read (&page->_count) <0 ); +atomic_inc (&page->_count); +} +This is identical to the x86 implementation. Any possibility they can be shared?
There is no place for me today to put gup_fast "equal" bits so I'd need to create it and just doing it for a single inline function sounds overkill. I could add a asm-generic/gup_fast.h add move that function there and include the asm-generic/gup_fast.h from asm*/include/gup_fast.h, is that what we want just for one function? With all #ifdefs included I would end up writing more code than the function itself. No problem with me in doing it though.
Quoted 17 lines
Quoted 17 lines
arch/x86/mm/gup.c +2
-0static noinline int gup_huge_pmd(pmd_t pmd, unsigned long addr,unsigned long end,int write,struct page **pages,int *nr) {@@ -128,6 +138,8 @@ static noinline int gup_huge_pmd(pmd_t p do { VM_BUG_ON(compound_head(page) != head); pages[*nr] = page; + if (PageTail(page)) + pin_huge_page_tail(page); (*nr)++; page++; refs++;include/linux/mm.h +0
-0@@ -351,9 +351,17 @@ static inline int page_count(struct page
Quoted 10 lines
include/linux/mm.h static inline int page_count(struct page · line 354
Quoted 5 lines
include/linux/mm.h +1
-2static inline void get_page (struct page *page) { - page =compound_head (page); -VM_BUG_ON (atomic_read (&page->_count) ==0 ); +VM_BUG_ON (atomic_read (&page->_count) < !PageTail (page));Oof, this might need a comment. It's saying that getting a normal page or the head of a compound page must already have an elevated reference count. If we are getting a tail page, the reference count is stored in both the head and the tail so the BUG check does not apply.
Ok.
include/linux/mm.h +12 -0
@@ -353,8 +353,20 @@ static inline int page_count(struct pagestatic inline void get_page (struct page *page) { +/* +* Getting a normal page or the head of a compound page +* requires to already have an elevated page->_count. Only if +* we're getting a tail page, the elevated page->_count is +* required only in the head page, so for tail pages the +* bugcheck only verifies that the page->_count isn't +* negative. +*/ VM_BUG_ON (atomic_read (&page->_count) < !PageTail (page));atomic_inc (&page->_count); +/* +* Getting a tail page will elevate both the head and tail +* page->_count(s). +*/ if (unlikely (PageTail (page))) {/* * This is safe only because
Quoted 30 lines
Quoted 30 lines
mm/swap.c +14
-4@@ -56,17 +56,83 @@ static void __page_cache_release(structdel_page_from_lru (zone, page);spin_unlock_irqrestore (&zone->lru_lock, flags); } +} + +static void __put_single_page (struct page *page) +{ +__page_cache_release (page);free_hot_cold_page (page,0 ); } +static void __put_compound_page (struct page *page) +{ +compound_page_dtor *dtor; + +__page_cache_release (page); + dtor =get_compound_page_dtor (page); + (*dtor)(page); +} +static void put_compound_page (struct page *page) { - page =compound_head (page); -if (put_page_testzero (page)) { -compound_page_dtor *dtor; -
Quoted 8 lines
mm/swap.c static void __page_cache_release(struct · line 79
Quoted 4 lines
mm/swap.c +2
-2- dtor =get_compound_page_dtor (page); - (*dtor)(page); +if (unlikely (PageTail (page))) { +/* __split_huge_page_refcount can run under us */ So what? The fact you check PageTail twice is a hint as to what is happening and that we are depending on the order of when the head and tails bits get cleared but it's hard to be certain of that.
This is correct, we depend on the split_huge_page_refcount to clear PageTail before overwriting first_page.
+ /*
+ * 1) clear PageTail before overwriting first_page
+ * 2) clear PageTail before clearing PageHead for VM_BUG_ON
+ */
+ smp_wmb();
The first PageTail check is just to define the fast path and skip reading page->first_page and doing smb_rmb() for the much more common head pages (we're in unlikely branch).
So then we read first_page, we smb_rmb() and if pagetail is still set after that, we can be sure first_page isn't a dangling pointer.
Quoted 72 lines
Quoted 61 lines
mm/swap.c +56
-0+struct page *page_head = page->first_page; +smp_rmb (); +if (likely (PageTail (page) &&get_page_unless_zero (page_head))) { +unsigned long flags; +if (unlikely (!PageHead (page_head))) { +/* PageHead is cleared after PageTail */ +smp_rmb (); +VM_BUG_ON (PageTail (page)); + goto out_put_head; + } +/* +* Only run compound_lock on a valid PageHead, +* after having it pinned with +* get_page_unless_zero() above. +*/ +smp_mb (); +/* page_head wasn't a dangling pointer */ +compound_lock_irqsave (page_head, &flags); +if (unlikely (!PageTail (page))) { +/* __split_huge_page_refcount run before us */ +compound_unlock_irqrestore (page_head, flags); +VM_BUG_ON (PageHead (page_head)); + out_put_head: +if (put_page_testzero (page_head)) +__put_single_page (page_head); + out_put_single: +if (put_page_testzero (page)) +__put_single_page (page); +return ; + } +VM_BUG_ON (page_head != page->first_page); +/* +* We can release the refcount taken by +* get_page_unless_zero now that +* split_huge_page_refcount is blocked on the +* compound_lock. +*/ +if (put_page_testzero (page_head)) +VM_BUG_ON (1 ); +/* __split_huge_page_refcount will wait now */ +VM_BUG_ON (atomic_read (&page->_count) <=0 ); +atomic_dec (&page->_count); +VM_BUG_ON (atomic_read (&page_head->_count) <=0 ); +compound_unlock_irqrestore (page_head, flags); +if (put_page_testzero (page_head)) +__put_compound_page (page_head); + }else { +/* page_head is a dangling pointer */ +VM_BUG_ON (PageTail (page)); + goto out_put_single; + } + }else if (put_page_testzero (page)) { +if (PageHead (page)) +__put_compound_page (page); +else +__put_single_page (page); } }mm/swap.c void put_page(struct page *page) · line 147
Quoted 8 lines
mm/swap.c +1
-1@@ -75,7 +141,7 @@ void put_page(struct page *page)if (unlikely (PageCompound (page)))put_compound_page (page);else if (put_page_testzero (page)) -__page_cache_release (page); +__put_single_page (page); }EXPORT_SYMBOL (put_page);Functionally, I don't see a problem so
Quoted 4 lines
Acked-by Mel Gorman <[email protected]>but some expansion on the leader and the comment, even if done as a follow-on patch, would be nice.
mm/swap.c +10 -0
@@ -79,8 +79,18 @@ static void put_compound_page(struct pag/* __split_huge_page_refcount can run under us */ struct page *page_head = page->first_page;smp_rmb (); +/* +* If PageTail is still set after smp_rmb() we can be sure +* that the page->first_page we read wasn't a dangling pointer. +* See __split_huge_page_refcount() smp_wmb(). +*/ if (likely (PageTail (page) &&get_page_unless_zero (page_head))) {unsigned long flags; +/* +* Verify that our page_head wasn't converted +* to a a regular page before we got a +* reference on it. +*/ if (unlikely (!PageHead (page_head))) {/* PageHead is cleared after PageTail */ smp_rmb ();
--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 16 of 66] special pmd_trans_* functions
In reply to Mel GormanQuoted 11 lines · Mel Gorman
Usually it is insisted upon that this looks like
static inline int pmd_trans_huge(pmd) { return 0; }I understand it's to avoid any possibility of side-effets though to have type checking and I am 99% certain the compiler still does the right thing. Still, with no obvious side-effects here;
Acked-by Mel Gorman <[email protected]>
It doesn't seem to fail build on x86-64 and x86, so it should build for all other archs too. I'm keeping this incremental at the end just in case.
include/asm-generic/pgtable.h +13 -3
@@ -471,10 +471,20 @@ extern void untrack_pfn_vma(struct vm_ar#endif #ifndef CONFIG_TRANSPARENT_HUGEPAGE -#define pmd_trans_huge (pmd) 0 -#define pmd_trans_splitting (pmd) 0 +static inline int pmd_trans_huge (pmd_t pmd) +{ +return 0 ; +} +static inline int pmd_trans_splitting (pmd_t pmd) +{ +return 0 ; +}#ifndef __HAVE_ARCH_PMD_WRITE -#define pmd_write (pmd) ({ BUG(); 0; }) +static inline int pmd_write (pmd_t pmd) +{ +BUG (); +return 0 ; +}#endif /* __HAVE_ARCH_PMD_WRITE */ #endif
--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 17 of 66] add pmd mangling generic functions
In reply to Linus TorvaldsQuoted 3 lines · Linus Torvalds
I dunno. Those macros are _way_ too big and heavy to be macros or inline functions. Why aren't
pmdp_splitting_flush()etc just functions?
That's because ptep_clear_flush and everything else in that file named with ptep_* and doing expensive tlb flushes was a macro.
Quoted 5 lines
There is no performance advantage to inlining them - the TLB flush is going to be expensive enough that there's no point in avoiding a function call. And that header file really does end up being _really_ ugly.
I agree but to me it looks like your compliant applies to the current include/asm-generic/pgtable.h. My changes that simply mirrors closely the style of that file to avoid altering coding style just for the new stuff. That is compact code that I'm not even sure if anybody is using, most certainly x86 isn't using that code so the .text bloat isn't a practical concern.
Do you like me to do a cleanup of the asm-generic/pgtable.h and move the tlb flushes to lib/pgtable.c? (ideally the pgtable.o file should be empty after the preprocessor runs on x86*)
--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 03 of 66] transparent hugepage support documentation
In reply to Andrea ArcangeliQuoted 1 line · Andrea Arcangeli
Quoted 1 line
<SNIP>
I agree with all the changes you made up to this point.
Quoted 30 lines
Quoted 21 lines
Review
Quoted 6 lines
+- if some task quits and more hugepages become available (either
(quoted diff) +5
-0+ immediately in the buddy or through the VM), guest physical memory + backed by regular pages should be relocated on hugepages + automatically (with khugepaged) + +- it doesn't require boot-time memory reservation and in turn it usesneither does hugetlbfs.
Quoted 12 lines
(quoted diff) +12
-0+ hugepages whenever possible (the only possible reservation here is + kernelcore= to avoid unmovable pages to fragment all the memory but + such a tweak is not specific to transparent hugepage support and + it's a generic feature that applies to all dynamic high order + allocations in the kernel) + +- this initial support only offers the feature in the anonymous memory + regions but it'd be ideal to move it to tmpfs and the pagecache + later + +Transparent Hugepage Support maximizes the usefulness of free memory +if compared to the reservation approach of hugetlbfs by allowing allQuoted 8 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+unused memory to be used as cache or other movable (or even unmovable +entities).hugetlbfs with memory overcommit offers something similar, particularly in combination with libhugetlbfs with can automatically fall back to base pages. I've run benchmarks comparing hugetlbfs using a static hugepage pool with hugetlbfs dynamically allocating hugepages as required with no discernable performance difference. So this statement is not strictly accurate.
Quoted 7 lines
Ok, but without libhugetlbfs fallback to regular pages splitting the vma and creating a no-hugetlbfs one in the middle, it really requires memory reservation to be _sure_ (libhugtlbfs runs outside of hugetlbfs and I doubt it allows later collapsing like khugepaged provides, furthermore I'm comparing kernel vs kernel not kernel vs kernel+userlandwrapping)...So I think mentioning the fact THP doesn't require memory reservation is more or less fair enough.
Ok, what you say is true. There is no collapsing of huge pages in hugetlbfs and reservations are required to be sure.
Quoted 49 lines
I removed
"boot-time" though.Quoted 37 lines
Quoted 37 lines
(quoted diff) +37
-0+It doesn't require reservation to prevent hugepage +allocation failures to be noticeable from userland. It allows paging +and all other advanced VM features to be available on the +hugepages. It requires no modifications for applications to take +advantage of it. + +Applications however can be further optimized to take advantage of +this feature, like for example they've been optimized before to avoid +a flood of mmap system calls for every malloc(4k). Optimizing userland +is by far not mandatory and khugepaged already can take care of long +lived page allocations even for hugepage unaware applications that +deals with large amounts of memory. + +In certain cases when hugepages are enabled system wide, application +may end up allocating more memory resources. An application may mmap a +large region but only touch 1 byte of it, in that case a 2M page might +be allocated instead of a 4k page for no good. This is why it's +possible to disable hugepages system-wide and to only have them inside +MADV_HUGEPAGE madvise regions. + +Embedded systems should enable hugepages only inside madvise regions +to eliminate any risk of wasting any precious byte of memory and to +only run faster. + +Applications that gets a lot of benefit from hugepages and that don't +risk to lose memory by using hugepages, should use +madvise(MADV_HUGEPAGE) on their critical mmapped regions. + +== sysfs == + +Transparent Hugepage Support can be entirely disabled (mostly for +debugging purposes) or only enabled inside MADV_HUGEPAGE regions (to +avoid the risk of consuming more memory resources) or enabled system +wide. This can be achieved with one of: + +echo always >/sys/kernel/mm/transparent_hugepage/enabled +echo madvise >/sys/kernel/mm/transparent_hugepage/enabledQuoted 8 lines
Review
Quoted 6 lines
(quoted diff) +6
-0+echo never >/sys/kernel/mm/transparent_hugepage/enabled + +It's also possible to limit defrag efforts in the VM to generate +hugepages in case they're not immediately free to madvise regions or +to never try to defrag memory and simply fallback to regular pages +unless hugepages are immediately available.This is the first mention of defrag but hey, it's not a paper :)
Quoted 3 lines
Not sure I get it this, is this too early or too late to mention defrag? But yes this is not a paper so I guess I don't need to care ;)
You don't need to care. The reader just has to know what defrag means here. It's not worth sweating over.
Quoted 1 line
Quoted 1 line
Quoted 1 line
<SNIP>
I agree with all the changes.
Quoted 10 lines
Quoted 5 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+The transparent_hugepage/enabled values only affect future +behavior. So to make them effective you need to restart anys/behavior/behaviour/
Funny, after this change my spell checker asks me to rename behaviour back to behavior. I'll stick to the spell checker, they are synonymous anyway.
They are. Might be a difference in UK and US spelling again.
Quoted 9 lines
Quoted 8 lines
Review
Quoted 6 lines
(quoted diff) +6
-0+In case you can't handle compound pages if they're returned by +follow_page, the FOLL_SPLIT bit can be specified as parameter to +follow_page, so that it will split the hugepages before returning +them. Migration for example passes FOLL_SPLIT as parameter to +follow_page because it's not hugepage aware and in fact it can't work +at all on hugetlbfs (but it instead works fine on transparenthugetlbfs pages can now migrate although it's only used by hwpoison.
Quoted 8 lines
Yep. I'll need to teach migrate to avoid splitting the hugepage to migrate it too... (especially for numa, not much for hwpoison). And the migration support for hugetlbfs now makes it more complicated to migrate transhuge pages too with the same function because that code isn't inside a
VM_HUGETLBcheck... Worst case we can check the hugepage destructor to differentiate the two, I've yet to check that. Surely it's feasible and mostly an implementation issue.
It should be feasible.
Quoted 28 lines
Quoted 4 lines
Quoted 4 lines
(quoted diff) +4
-0+Code walking pagetables but unware about huge pmds can simply call +split_huge_page_pmd(mm, pmd) where the pmd is the one returned by +pmd_offset. It's trivial to make the code transparent hugepage aware +by just grepping for "pmd_offset" and adding split_huge_page_pmd whereQuoted 8 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+missing after pmd_offset returns the pmd. Thanks to the graceful +fallback design, with a one liner change, you can avoid to write +hundred if not thousand of lines of complex code to make your code +hugepage aware. +It'd be nice if you could point to a specific example but by no means mandatory.
Ok:
Documentation/vm/transhuge.txt +6
-0@@ -226,6 +226,20 @@ but you can't handle it natively in your calling split_huge_page(page). This is what the Linux VM does before it tries to swapout the hugepage for example. +Example to make mremap.c transparent hugepage aware with a one liner +change: + +diff --git a/mm/mremap.c b/mm/mremap.c +--- a/mm/mremap.c ++++ b/mm/mremap.c
Documentation/vm/transhuge.txt but you can't handle it natively in your · line 244
Quoted 10 lines
Documentation/vm/transhuge.txt +8
-0+@@ -41,6 +41,7 @@ static pmd_t *get_old_pmd(struct mm_stru + return NULL; + + pmd = pmd_offset(pud, addr); ++ split_huge_page_pmd(mm, pmd); + if (pmd_none_or_clear_bad(pmd)) + return NULL; + == Locking in hugepage aware code ==
Perfect.
Quoted 12 lines
Documentation/vm/transhuge.txt +0
-0We want as much code as possible hugepage aware, as callingQuoted 8 lines
Ok, I'll need to read the rest of the series to verify if this is correct but by and large it looks good. I think some of the language is stronger than it should be and some of the comparisons with libhugetlbfs are a bit off but I'd be naturally defensive on that topic. Make the suggested changes if you like but if you don't, it shouldn't affect the series.
I hope it looks better now, thanks!
It does, thanks.
Signature · 3 lines
Mel Gorman Part-time Phd Student Linux Technology Center University of Limerick IBM Dublin Software Lab
Re: [PATCH 06 of 66] alter compound get_page/put_page
In reply to Andrea ArcangeliQuoted 1 line · Andrea Arcangeli
Quoted 1 line
Quoted 1 line
<SNIP>
The updates are fine.
Quoted 21 lines
Quoted 7 lines
Quoted 7 lines
arch/x86/mm/gup.c +0
-0@@ -105,6 +105,16 @@ static inline void get_head_page_multiplatomic_add (nr, &page->_count); }Quoted 13 lines
arch/x86/mm/gup.c static inline void get_head_page_multipl · line 117
Quoted 10 lines
arch/x86/mm/gup.c +10
-0+static inline void pin_huge_page_tail (struct page *page) +{ +/* +* __split_huge_page_refcount() cannot run +* from under us. +*/ +VM_BUG_ON (atomic_read (&page->_count) <0 ); +atomic_inc (&page->_count); +} +This is identical to the x86 implementation. Any possibility they can be shared?
Quoted 8 lines
There is no place for me today to put
gup_fast"equal" bits so I'd need to create it and just doing it for a single inline function sounds overkill. I could add aasm-generic/gup_fast.hadd move that function there and include theasm-generic/gup_fast.hfromasm*/include/gup_fast.h, is that what we want just for one function? With all #ifdefs included I would end up writing more code than the function itself. No problem with me in doing it though.
Now that you've explained what is necessary, it's not worth it as part of the series. It's sizable enough as it is for review. Consider it as a follow-up patch maybe.
Quoted 44 lines
Quoted 17 lines
Quoted 17 lines
arch/x86/mm/gup.c +2
-0static noinline int gup_huge_pmd(pmd_t pmd, unsigned long addr,unsigned long end,int write,struct page **pages,int *nr) {@@ -128,6 +138,8 @@ static noinline int gup_huge_pmd(pmd_t p do { VM_BUG_ON(compound_head(page) != head); pages[*nr] = page; + if (PageTail(page)) + pin_huge_page_tail(page); (*nr)++; page++; refs++;include/linux/mm.h +0
-0@@ -351,9 +351,17 @@ static inline int page_count(struct pageQuoted 10 lines
include/linux/mm.h static inline int page_count(struct page · line 354
Quoted 5 lines
include/linux/mm.h +1
-2static inline void get_page (struct page *page) { - page =compound_head (page); -VM_BUG_ON (atomic_read (&page->_count) ==0 ); +VM_BUG_ON (atomic_read (&page->_count) < !PageTail (page));Oof, this might need a comment. It's saying that getting a normal page or the head of a compound page must already have an elevated reference count. If we are getting a tail page, the reference count is stored in both the head and the tail so the BUG check does not apply.
Ok.
include/linux/mm.h +7
-0@@ -353,8 +353,20 @@ static inline int page_count(struct pagestatic inline void get_page (struct page *page) { +/* +* Getting a normal page or the head of a compound page +* requires to already have an elevated page->_count. Only if +* we're getting a tail page, the elevated page->_count is +* required only in the head page, so for tail pages the +* bugcheck only verifies that the page->_count isn't +* negative.
include/linux/mm.h static inline int page_count(struct page · line 372
Quoted 10 lines
include/linux/mm.h +5
-0+*/ VM_BUG_ON (atomic_read (&page->_count) < !PageTail (page));atomic_inc (&page->_count); +/* +* Getting a tail page will elevate both the head and tail +* page->_count(s). +*/ if (unlikely (PageTail (page))) {/* * This is safe only because
Much better.
Quoted 44 lines
Quoted 31 lines
Quoted 31 lines
mm/swap.c +14
-4@@ -56,17 +56,83 @@ static void __page_cache_release(structdel_page_from_lru (zone, page);spin_unlock_irqrestore (&zone->lru_lock, flags); } +} + +static void __put_single_page (struct page *page) +{ +__page_cache_release (page);free_hot_cold_page (page,0 ); } +static void __put_compound_page (struct page *page) +{ +compound_page_dtor *dtor; + +__page_cache_release (page); + dtor =get_compound_page_dtor (page); + (*dtor)(page); +} +static void put_compound_page (struct page *page) { - page =compound_head (page); -if (put_page_testzero (page)) { -compound_page_dtor *dtor; -Quoted 8 lines
mm/swap.c static void __page_cache_release(struct · line 79
Quoted 4 lines
mm/swap.c +2
-2- dtor =get_compound_page_dtor (page); - (*dtor)(page); +if (unlikely (PageTail (page))) { +/* __split_huge_page_refcount can run under us */ So what? The fact you check PageTail twice is a hint as to what is happening and that we are depending on the order of when the head and tails bits get cleared but it's hard to be certain of that.
This is correct, we depend on the
split_huge_page_refcountto clear PageTail before overwritingfirst_page.
include/linux/mm.h
Quoted 5 lines
include/linux/mm.h +5
-0+/* +* 1) clear PageTail before overwriting first_page +* 2) clear PageTail before clearing PageHead for VM_BUG_ON +*/ +smp_wmb ();
This helps. Less guesswork involved :)
Quoted 97 lines
The first PageTail check is just to define the fast path and skip reading
page->first_pageand doingsmb_rmb()for the much more common head pages (we're in unlikely branch).So then we read
first_page, wesmb_rmb()and if pagetail is still set after that, we can be surefirst_pageisn't a dangling pointer.Quoted 76 lines
Quoted 61 lines
mm/swap.c +56
-0+struct page *page_head = page->first_page; +smp_rmb (); +if (likely (PageTail (page) &&get_page_unless_zero (page_head))) { +unsigned long flags; +if (unlikely (!PageHead (page_head))) { +/* PageHead is cleared after PageTail */ +smp_rmb (); +VM_BUG_ON (PageTail (page)); + goto out_put_head; + } +/* +* Only run compound_lock on a valid PageHead, +* after having it pinned with +* get_page_unless_zero() above. +*/ +smp_mb (); +/* page_head wasn't a dangling pointer */ +compound_lock_irqsave (page_head, &flags); +if (unlikely (!PageTail (page))) { +/* __split_huge_page_refcount run before us */ +compound_unlock_irqrestore (page_head, flags); +VM_BUG_ON (PageHead (page_head)); + out_put_head: +if (put_page_testzero (page_head)) +__put_single_page (page_head); + out_put_single: +if (put_page_testzero (page)) +__put_single_page (page); +return ; + } +VM_BUG_ON (page_head != page->first_page); +/* +* We can release the refcount taken by +* get_page_unless_zero now that +* split_huge_page_refcount is blocked on the +* compound_lock. +*/ +if (put_page_testzero (page_head)) +VM_BUG_ON (1 ); +/* __split_huge_page_refcount will wait now */ +VM_BUG_ON (atomic_read (&page->_count) <=0 ); +atomic_dec (&page->_count); +VM_BUG_ON (atomic_read (&page_head->_count) <=0 ); +compound_unlock_irqrestore (page_head, flags); +if (put_page_testzero (page_head)) +__put_compound_page (page_head); + }else { +/* page_head is a dangling pointer */ +VM_BUG_ON (PageTail (page)); + goto out_put_single; + } + }else if (put_page_testzero (page)) { +if (PageHead (page)) +__put_compound_page (page); +else +__put_single_page (page); } }mm/swap.c void put_page(struct page *page) · line 147
Quoted 8 lines
mm/swap.c +1
-1@@ -75,7 +141,7 @@ void put_page(struct page *page)if (unlikely (PageCompound (page)))put_compound_page (page);else if (put_page_testzero (page)) -__page_cache_release (page); +__put_single_page (page); }EXPORT_SYMBOL (put_page);Functionally, I don't see a problem so
Acked-by Mel Gorman <[email protected]>but some expansion on the leader and the comment, even if done as a follow-on patch, would be nice.
mm/swap.c +5
-0@@ -79,8 +79,18 @@ static void put_compound_page(struct pag/* __split_huge_page_refcount can run under us */ struct page *page_head = page->first_page;smp_rmb (); +/* +* If PageTail is still set after smp_rmb() we can be sure +* that the page->first_page we read wasn't a dangling pointer. +* See __split_huge_page_refcount() smp_wmb(). +*/
mm/swap.c static void put_compound_page(struct pag · line 96
Quoted 10 lines
mm/swap.c +5
-0if (likely (PageTail (page) &&get_page_unless_zero (page_head))) {unsigned long flags; +/* +* Verify that our page_head wasn't converted +* to a a regular page before we got a +* reference on it. +*/ if (unlikely (!PageHead (page_head))) {/* PageHead is cleared after PageTail */ smp_rmb ();
Thanks
Signature · 10 lines
Mel Gorman Part-time Phd Student Linux Technology Center University of Limerick IBM Dublin Software Lab -- 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/ . Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 18 of 66] add pmd mangling functions to x86
In reply to Mel GormanQuoted 6 lines · Mel Gorman
Quoted 3 lines · Andrea Arcangeli
From: Andrea Arcangeli <[email protected]>
Add needed pmd mangling functions with simmetry with their pte counterparts.
symmetry
Fixed.
Quoted 11 lines
Quoted 6 lines
pmdp_freeze_flushis the only exception only present on the pmd side and it's needed to serialize the VM againstsplit_huge_page, it simply atomically clears the present bit in the same waypmdp_clear_flush_youngatomically clears the accessed bit (and both need to flush the tlb to make it effective, which is mandatory to happen synchronously forpmdp_freeze_flush).I don't see a
pmdp_freeze_flushdefined in the patch. Did yu meanpmdp_splitting_flush? Even if it is, it's the splitting bit you are dealing with which isn't the same as the present bit. I'm missing something.
Well the comment went out of sync with the code sorry. I updated it:
=======
Add needed pmd mangling functions with symmetry with their pte counterparts. pmdp_splitting_flush() is the only new addition on the pmd_ methods and it's needed to serialize the VM against split_huge_page. It simply atomically sets the splitting bit in a similar way pmdp_clear_flush_young atomically clears the accessed bit. pmdp_splitting_flush() also has to flush the tlb to make it effective against gup_fast, but it wouldn't really require to flush the tlb too. Just the tlb flush is the simplest operation we can invoke to serialize pmdp_splitting_flush() against gup_fast.
=======
Quoted 20 lines
Quoted 20 lines
Signed-off-by Andrea Arcangeli <[email protected]>Acked-by Rik van Riel <[email protected]>---
arch/x86/include/asm/pgtable.h +3
-0@@ -302,15 +302,15 @@ pmd_t *populate_extra_pmd(unsigned longpte_t *populate_extra_pte (unsigned long vaddr);#endif /* __ASSEMBLY__ */ +#ifndef __ASSEMBLY__ +#include <linux/mm_types.h> +#ifdef CONFIG_X86_32 # include "pgtable_32.h" #else # include "pgtable_64.h" #endif
Quoted 5 lines
arch/x86/include/asm/pgtable.h pmd_t *populate_extra_pmd(unsigned long · line 313
Quoted 3 lines
arch/x86/include/asm/pgtable.h +0
-3-#ifndef __ASSEMBLY__ -#include <linux/mm_types.h> -Stupid quetion: Why is this move necessary?
That's not a stupid question, it seems to build in all configurations even with this part backed out. I'll try to reverse this one in the hope that it won't break build. I suppose some earlier version of the patchset required this to build (I would never make a gratuitous change like this if it wasn't needed at some point) but it seems not be required anymore according to my build tests. If I'm wrong and some build breaks I'll reintroduce it later.
Quoted 4 lines
Quoted 4 lines
arch/x86/include/asm/pgtable.h +0
-0static inline int pte_none (pte_t pte) {return !pte.pte;@@ -353,7 +353,7 @@ static inline unsigned long pmd_page_vad
Quoted 8 lines
arch/x86/include/asm/pgtable.h static inline unsigned long pmd_page_vad · line 357
Quoted 6 lines
arch/x86/include/asm/pgtable.h +1
-1* Currently stuck as a macro due to indirect forward reference to * linux/mmzone.h's __section_mem_map_addr() definition: */ -#define pmd_page (pmd) pfn_to_page(pmd_val(pmd) >> PAGE_SHIFT) +#define pmd_page (pmd) pfn_to_page((pmd_val(pmd) & PTE_PFN_MASK) >> PAGE_SHIFT)Why is it now necessary to use
PTE_PFN_MASK?
Just for the NX bit, that couldn't be set before the pmd could be marked PSE.
Quoted 2 lines
The implementations look fine but I'm having trouble reconsiling what the leader says with the patch :(
Yes because it was out of sync, the new version is above.
Thanks,
Andrea
--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 11 of 66] add pmd paravirt ops
In reply to Andrea ArcangeliQuoted 9 lines · Andrea Arcangeli
(quoted diff) +5
-0@@ -543,6 +554,18 @@ static inline void set_pte_at(struct mm_ PVOP_VCALL4(pv_mmu_ops.set_pte_at, mm, addr, ptep, pte.pte); } +#ifdef CONFIG_TRANSPARENT_HUGEPAGE +static inline void set_pmd_at(struct mm_struct *mm, unsigned long addr, + pmd_t *pmdp, pmd_t pmd) +{ + if (sizeof(pmdval_t) > sizeof(long))
Review static inline void set_pte_at(struct mm_ · line 571
Quoted 10 lines
(quoted diff) +7
-0+ /* 5 arg words */ + pv_mmu_ops.set_pmd_at(mm, addr, pmdp, pmd); + else + PVOP_VCALL4(pv_mmu_ops.set_pmd_at, mm, addr, pmdp, pmd.pmd); +} +#endif + static inline void set_pmd(pmd_t *pmdp, pmd_t pmd) { pmdval_t val = native_pmd_val(pmd);
btw, I noticed the 32bit build with HIGHMEM off, paravirt on, and THP on fails without this below change (that configuration clearly has never been tested for build), so I'm merging this in the above quoted patch.
arch/x86/include/asm/paravirt.h +2 -0
@@ -558,11 +558,13 @@ static inline void set_pte_at(struct mm_static inline void set_pmd_at (struct mm_struct *mm,unsigned long addr,pmd_t *pmdp,pmd_t pmd) { +#if PAGETABLE_LEVELS >=3 if (sizeof (pmdval_t) >sizeof (long ))/* 5 arg words */ pv_mmu_ops.set_pmd_at (mm, addr, pmdp, pmd);else PVOP_VCALL4 (pv_mmu_ops.set_pmd_at, mm, addr, pmdp, pmd.pmd); +#endif }#endif
--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 17 of 66] add pmd mangling generic functions
In reply to Andrea ArcangeliQuoted 7 lines · Andrea Arcangeli
Quoted 3 lines · Linus Torvalds
I dunno. Those macros are _way_ too big and heavy to be macros or inline functions. Why aren't
pmdp_splitting_flush()etc just functions?That's because
ptep_clear_flushand everything else in that file named with ptep_* and doing expensive tlb flushes was a macro.
That may be, and you needn't necessarily clean up old use (although that might be nice as a separate thing), but I wish we didn't make what is already messy bigger and messier.
Linus
--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 53 of 66] add numa awareness to hugepage allocations
In reply to Andrea ArcangeliQuoted 18 lines
mm/huge_memory.c +5
-0@@ -1655,7 +1672,11 @@ static void collapse_huge_page(struct mmunsigned long hstart, hend;VM_BUG_ON (address & ~HPAGE_PMD_MASK ); +#ifndef CONFIG_NUMA VM_BUG_ON (!*hpage); +#else +VM_BUG_ON (*hpage); +#endif /* * Prevent all access to pagetables with the exception of @@ -1693,7 +1714,15 @@ static void collapse_huge_page(struct mmif (!pmd_present (*pmd) ||pmd_trans_huge (*pmd)) goto out; +#ifndef CONFIG_NUMA new_page = *hpage;
mm/huge_memory.c static void collapse_huge_page(struct mm · line 1728
Quoted 10 lines
mm/huge_memory.c +7
-0+#else + new_page =alloc_hugepage_vma (khugepaged_defrag (), vma, address); +if (unlikely (!new_page)) { + *hpage =ERR_PTR (-ENOMEM ); + goto out; + } +#endif if (unlikely (mem_cgroup_newpage_charge (new_page, mm,GFP_KERNEL ))) goto out;
I think this should be:
if (unlikely(mem_cgroup_newpage_charge(new_page, mm, GFP_KERNEL))) {
#ifdef CONFIG_NUMA
put_page(new_page);
#endif
goto out;
}Thanks,
Daisuke Nishimura.
Quoted 20 lines
mm/huge_memory.c +5
-0@@ -1724,6 +1753,9 @@ static void collapse_huge_page(struct mmspin_unlock (&mm->page_table_lock);anon_vma_unlock (vma->anon_vma);mem_cgroup_uncharge_page (new_page); +#ifdef CONFIG_NUMA +put_page (new_page); +#endif goto out; }@@ -1759,7 +1791,9 @@ static void collapse_huge_page(struct mm mm->nr_ptes--;spin_unlock (&mm->page_table_lock); +#ifndef CONFIG_NUMA *hpage =NULL ; +#endif khugepaged_pages_collapsed++; out:up_write (&mm->mmap_sem);
Re: [PATCH 18 of 66] add pmd mangling functions to x86
In reply to Andrea ArcangeliQuoted 24 lines · Andrea Arcangeli
Quoted 6 lines · Mel Gorman
Quoted 3 lines · Andrea Arcangeli
From: Andrea Arcangeli <[email protected]>
Add needed pmd mangling functions with simmetry with their pte counterparts.
symmetry
Fixed.
Quoted 11 lines
Quoted 6 lines
pmdp_freeze_flushis the only exception only present on the pmd side and it's needed to serialize the VM againstsplit_huge_page, it simply atomically clears the present bit in the same waypmdp_clear_flush_youngatomically clears the accessed bit (and both need to flush the tlb to make it effective, which is mandatory to happen synchronously forpmdp_freeze_flush).I don't see a
pmdp_freeze_flushdefined in the patch. Did yu meanpmdp_splitting_flush? Even if it is, it's the splitting bit you are dealing with which isn't the same as the present bit. I'm missing something.Well the comment went out of sync with the code sorry. I updated it:
Quoted 11 lines
=======
Add needed pmd mangling functions with symmetry with their pte counterparts.pmdp_splitting_flush()is the only new addition on thepmd_methods and it's needed to serialize the VM againstsplit_huge_page. It simply atomically sets the splitting bit in a similar waypmdp_clear_flush_youngatomically clears the accessed bit.pmdp_splitting_flush()also has to flush the tlb to make it effective againstgup_fast, but it wouldn't really require to flush the tlb too. Just the tlb flush is the simplest operation we can invoke to serializepmdp_splitting_flush()againstgup_fast.
=======
Much clearer, thanks.
Quoted 26 lines
Quoted 20 lines
Quoted 20 lines
Signed-off-by Andrea Arcangeli <[email protected]>Acked-by Rik van Riel <[email protected]>---
arch/x86/include/asm/pgtable.h +3
-0@@ -302,15 +302,15 @@ pmd_t *populate_extra_pmd(unsigned longpte_t *populate_extra_pte (unsigned long vaddr);#endif /* __ASSEMBLY__ */ +#ifndef __ASSEMBLY__ +#include <linux/mm_types.h> +#ifdef CONFIG_X86_32 # include "pgtable_32.h" #else # include "pgtable_64.h" #endif Quoted 5 lines
arch/x86/include/asm/pgtable.h pmd_t *populate_extra_pmd(unsigned long · line 313
Quoted 3 lines
arch/x86/include/asm/pgtable.h +0
-3-#ifndef __ASSEMBLY__ -#include <linux/mm_types.h> -Stupid quetion: Why is this move necessary?
Quoted 8 lines
That's not a stupid question, it seems to build in all configurations even with this part backed out. I'll try to reverse this one in the hope that it won't break build. I suppose some earlier version of the patchset required this to build (I would never make a gratuitous change like this if it wasn't needed at some point) but it seems not be required anymore according to my build tests. If I'm wrong and some build breaks I'll reintroduce it later.
Ok.
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
arch/x86/include/asm/pgtable.h +0
-0static inline int pte_none (pte_t pte) {return !pte.pte;@@ -353,7 +353,7 @@ static inline unsigned long pmd_page_vadQuoted 8 lines
arch/x86/include/asm/pgtable.h static inline unsigned long pmd_page_vad · line 357
Quoted 6 lines
arch/x86/include/asm/pgtable.h +1
-1* Currently stuck as a macro due to indirect forward reference to * linux/mmzone.h's __section_mem_map_addr() definition: */ -#define pmd_page (pmd) pfn_to_page(pmd_val(pmd) >> PAGE_SHIFT) +#define pmd_page (pmd) pfn_to_page((pmd_val(pmd) & PTE_PFN_MASK) >> PAGE_SHIFT)Why is it now necessary to use
PTE_PFN_MASK?
Quoted 3 lines
Just for the NX bit, that couldn't be set before the pmd could be marked PSE.
Sorry, I still am missing something. PTE_PFN_MASK is this
#define PTE_PFN_MASK ((pteval_t)PHYSICAL_PAGE_MASK)
#define PHYSICAL_PAGE_MASK (((signed long)PAGE_MASK) & __PHYSICAL_MASK)
I'm not seeing how PTE_PFN_MASK affects the NX bit (bit 63).
Quoted 5 lines
Quoted 2 lines
The implementations look fine but I'm having trouble reconsiling what the leader says with the patch :(
Yes because it was out of sync, the new version is above.
Thanks
Signature · 10 lines
Mel Gorman Part-time Phd Student Linux Technology Center University of Limerick IBM Dublin Software Lab -- 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/ . Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 53 of 66] add numa awareness to hugepage allocations
In reply to Daisuke NishimuraQuoted 8 lines · Daisuke Nishimura
I think this should be:
if (unlikely(mem_cgroup_newpage_charge(new_page, mm, GFP_KERNEL))) { #ifdef CONFIG_NUMA put_page(new_page); #endif goto out; }
Hmm no, the change you suggest would generate memory corruption with use after free.
--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 18 of 66] add pmd mangling functions to x86
In reply to Mel GormanQuoted 14 lines · Mel Gorman
Quoted 10 lines
Quoted 9 lines
arch/x86/include/asm/pgtable.h static inline unsigned long pmd_page_vad · line 357
Quoted 7 lines
arch/x86/include/asm/pgtable.h +1
-1@@ -353,7 +353,7 @@ static inline unsigned long pmd_page_vad* Currently stuck as a macro due to indirect forward reference to * linux/mmzone.h's __section_mem_map_addr() definition: */ -#define pmd_page (pmd) pfn_to_page(pmd_val(pmd) >> PAGE_SHIFT) +#define pmd_page (pmd) pfn_to_page((pmd_val(pmd) & PTE_PFN_MASK) >> PAGE_SHIFT)Why is it now necessary to use
PTE_PFN_MASK?Quoted 3 lines
Just for the NX bit, that couldn't be set before the pmd could be marked PSE.
Quoted 6 lines
Sorry, I still am missing something.
PTE_PFN_MASKis this#define
PTE_PFN_MASK((pteval_t)PHYSICAL_PAGE_MASK)
#definePHYSICAL_PAGE_MASK(((signed long)PAGE_MASK) &__PHYSICAL_MASK)I'm not seeing how
PTE_PFN_MASKaffects the NX bit (bit 63).
It simply clears it by doing & 0000... otherwise bit 51 would remain erroneously set on the pfn passed to pfn_to_page.
Clearing bit 63 wasn't needed before because bit 63 couldn't be set on a not huge pmd.
--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 28 of 66] _GFP_NO_KSWAPD
In reply to Mel GormanQuoted 8 lines · Mel Gorman
This is not an exact merge with what's currently in mm. Look at the top of
gfp.hand see "Plain integer GFP bitmasks. Do not use this directly.". The0x400000udefinition needs to go there and this becomes#define
__GFP_NO_KSWAPD((__force_gfp_t)____0x400000u)What you have just generates sparse warnings (I believe) so it's harmless.
Agreed.
include/linux/gfp.h +2 -1
@@ -34,6 +34,7 @@ struct vm_area_struct;#else #define ___GFP_NOTRACK 0#endif +#define ___GFP_NO_KSWAPD 0x400000u/* * GFP bitmasks..
@@ -81,7 +82,7 @@ struct vm_area_struct;#define __GFP_RECLAIMABLE ((__force gfp_t)___GFP_RECLAIMABLE)/* Page is reclaimable */ #define __GFP_NOTRACK ((__force gfp_t)___GFP_NOTRACK)/* Don't track with kmemcheck */ -#define __GFP_NO_KSWAPD ((__force gfp_t)0x400000u) +#define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)/* * This may seem redundant, but it's a way of annotating false positives vs.
Quoted 1 line
Other than needing to define
____GFP_NO_KSWAPD
3 underscores.
Quoted 1 line
Acked-by Mel Gorman <[email protected]>
Added, thanks!
Andrea
--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 53 of 66] add numa awareness to hugepage allocations
In reply to Andrea ArcangeliQuoted 10 lines · On Mon, 29 Nov 2010 17:11:03 +0100 Andrea Arcangeli <[email protected]> wrote:
Quoted 8 lines · Daisuke Nishimura
I think this should be:
if (unlikely(mem_cgroup_newpage_charge(new_page, mm, GFP_KERNEL))) { #ifdef CONFIG_NUMA put_page(new_page); #endif goto out; }
Quoted 2 lines
Hmm no, the change you suggest would generate memory corruption with use after free.
I'm sorry if I miss something, "new_page" will be reused in !CONFIG_NUMA case as you say, but, in CONFIG_NUMA case, it is allocated in this function (collapse_huge_page()) by alloc_hugepage_vma(), and is not freed when memcg's charge failed.
Actually, we do in collapse_huge_page():
if (unlikely(!isolated)) {
...
#ifdef CONFIG_NUMA
put_page(new_page);
#endif
goto out;
}later. I think we need a similar logic in memcg's failure path too.
Thanks,
Daisuke Nishimura.
Re: [PATCH 53 of 66] add numa awareness to hugepage allocations
Quoted 5 lines · Daisuke Nishimura
I'm sorry if I miss something, "
new_page" will be reused in !CONFIG_NUMA case as you say, but, inCONFIG_NUMAcase, it is allocated in this function (collapse_huge_page()) byalloc_hugepage_vma(), and is not freed when memcg's charge failed.
Actually, we do incollapse_huge_page():
Quoted 8 lines
if (unlikely(!isolated)) { ... #ifdef CONFIG_NUMA put_page(new_page); #endif goto out; }later. I think we need a similar logic in memcg's failure path too.
Apologies, you really found a minor memleak in case of memcg accounting failure.
mm/huge_memory.c +9 -5
@@ -1726,7 +1726,7 @@ static void collapse_huge_page(struct mm }#endif if (unlikely (mem_cgroup_newpage_charge (new_page, mm,GFP_KERNEL ))) - goto out; + goto out_put_page;anon_vma_lock (vma->anon_vma);
@@ -1755,10 +1755,7 @@ static void collapse_huge_page(struct mmspin_unlock (&mm->page_table_lock);anon_vma_unlock (vma->anon_vma);mem_cgroup_uncharge_page (new_page); -#ifdef CONFIG_NUMA -put_page (new_page); -#endif - goto out; + goto out_put_page; }/*
@@ -1799,6 +1796,13 @@ static void collapse_huge_page(struct mm khugepaged_pages_collapsed++; out:up_write (&mm->mmap_sem); +return ; + +out_put_page: +#ifdef CONFIG_NUMA +put_page (new_page ); +#endif + goto out; } static int khugepaged_scan_pmd(struct mm_struct *mm,
I was too optimistic that there wasn't really a bug, I thought it was some confusion about the hpage usage that differs with numa and not numa.
On a side note, the CONFIG_NUMA case will later change further to move the allocation out of the mmap_sem write mode to make the fs submitting I/O from userland and doing memory allocations in the I/O paths happier.
--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 17 of 66] add pmd mangling generic functions
In reply to Linus TorvaldsHello,
Quoted 3 lines · Linus Torvalds
That may be, and you needn't necessarily clean up old use (although that might be nice as a separate thing), but I wish we didn't make what is already messy bigger and messier.
Ok I cleaned up most of the old code in asm-generic/pgtable.h too. Let me know if you like further changes in this area. I embedded the cleanups of the pmd_trans_huge/pmd_trans_splitting inside the previous patch (16) too (not at the end anymore).
Thanks,
Andrea
=====
Subject: add pmd mangling generic functions
From: Andrea Arcangeli <[email protected]>
Some are needed to build but not actually used on archs not supporting transparent hugepages. Others like pmdp_clear_flush are used by x86 too.
---
include/asm-generic/pgtable.h +154 -60
@@ -5,67 +5,108 @@ #ifdef CONFIG_MMU #ifndef __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS -/* -* Largely same as above, but only sets the access flags (dirty, -* accessed, and writable). Furthermore, we know it always gets set -* to a "more permissive" setting, which allows most architectures -* to optimize this. We return whether the PTE actually changed, which -* in turn instructs the caller to do things like update__mmu_cache. -* This used to be done in the caller, but sparc needs minor faults to -* force that call on sun4c so we changed this macro slightly -*/ -#define ptep_set_access_flags (__vma, __address, __ptep, __entry, __dirty) \ -({ \ - int __changed = !pte_same(*(__ptep), __entry); \ - if (__changed) { \ - set_pte_at((__vma)->vm_mm, (__address), __ptep, __entry); \ - flush_tlb_page(__vma, __address); \ - } \ - __changed; \ -}) +extern int ptep_set_access_flags(struct vm_area_struct *vma, + unsigned long address, pte_t *ptep, + pte_t entry, int dirty); +#endif + +#ifndef __HAVE_ARCH_PMDP_SET_ACCESS_FLAGS +extern int pmdp_set_access_flags(struct vm_area_struct *vma, + unsigned long address, pmd_t *pmdp, + pmd_t entry, int dirty); #endif #ifndef __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG -#define ptep_test_and_clear_young (__vma, __address, __ptep) \ -({ \ - pte_t __pte = *(__ptep); \ - int r = 1; \ - if (!pte_young(__pte)) \ - r = 0; \ - else \ - set_pte_at((__vma)->vm_mm, (__address), \ - (__ptep), pte_mkold(__pte)); \ - r; \ -}) +static inline int ptep_test_and_clear_young(struct vm_area_struct *vma, + unsigned long address, + pte_t *ptep) +{ + pte_t pte = *ptep; + int r = 1; + if (!pte_young(pte)) + r = 0; + else + set_pte_at(vma->vm_mm, address, ptep, pte_mkold(pte)); + return r; +} +#endif + +#ifndef __HAVE_ARCH_PMDP_TEST_AND_CLEAR_YOUNG +#ifdef CONFIG_TRANSPARENT_HUGEPAGE +static inline int pmdp_test_and_clear_young(struct vm_area_struct *vma, + unsigned long address, + pmd_t *pmdp) +{ + pmd_t pmd = *pmdp; + int r = 1; + if (!pmd_young(pmd)) + r = 0; + else + set_pmd_at(vma->vm_mm, address, pmdp, pmd_mkold(pmd)); + return r; +} +#else /* CONFIG_TRANSPARENT_HUGEPAGE */ +static inline int pmdp_test_and_clear_young(struct vm_area_struct *vma, + unsigned long address, + pmd_t *pmdp) +{ + BUG(); + return 0; +} +#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ #endif #ifndef __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH -#define ptep_clear_flush_young (__vma, __address, __ptep) \ -({ \ - int __young; \ - __young = ptep_test_and_clear_young(__vma, __address, __ptep); \ - if (__young) \ - flush_tlb_page(__vma, __address); \ - __young; \ -}) +int ptep_clear_flush_young(struct vm_area_struct *vma, + unsigned long address, pte_t *ptep); +#endif + +#ifndef __HAVE_ARCH_PMDP_CLEAR_YOUNG_FLUSH +int pmdp_clear_flush_young(struct vm_area_struct *vma, + unsigned long address, pmd_t *pmdp); #endif #ifndef __HAVE_ARCH_PTEP_GET_AND_CLEAR -#define ptep_get_and_clear (__mm, __address, __ptep) \ -({ \ - pte_t __pte = *(__ptep); \ - pte_clear((__mm), (__address), (__ptep)); \ - __pte; \ +static inline pte_t ptep_get_and_clear(struct mm_struct *mm, + unsigned long address, + pte_t *ptep) +{ + pte_t pte = *ptep; + pte_clear(mm, address, ptep); + return pte; +) +#endif + +#ifndef __HAVE_ARCH_PMDP_GET_AND_CLEAR +#ifdef CONFIG_TRANSPARENT_HUGEPAGE +static inline pmd_t pmdp_get_and_clear(struct mm_struct *mm, + unsigned long address, + pmd_t *pmdp) +{ + pmd_t pmd = *pmdp; + pmd_clear(mm, address, pmdp); + return pmd; }) +#else /* CONFIG_TRANSPARENT_HUGEPAGE */ +static inline pmd_t pmdp_get_and_clear(struct mm_struct *mm, + unsigned long address, + pmd_t *pmdp) +{ + BUG(); + return 0; +} +#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ #endif #ifndef __HAVE_ARCH_PTEP_GET_AND_CLEAR_FULL -#define ptep_get_and_clear_full (__mm, __address, __ptep, __full) \ -({ \ - pte_t __pte; \ - __pte = ptep_get_and_clear((__mm), (__address), (__ptep)); \ - __pte; \ -}) +static inline pte_t ptep_get_and_clear_full(struct mm_struct *mm, + unsigned long address, pte_t *ptep, + int full) +{ + pte_t pte; + pte = ptep_get_and_clear(mm, address, ptep); + return pte; +} #endif /*
@@ -74,20 +115,25 @@* not present, or in the process of an address space destruction. */ #ifndef __HAVE_ARCH_PTE_CLEAR_NOT_PRESENT_FULL -#define pte_clear_not_present_full (__mm, __address, __ptep, __full) \ -do { \ - pte_clear((__mm), (__address), (__ptep)); \ -} while (0) +static inline void pte_clear_not_present_full (struct mm_struct *mm, +unsigned long address, +pte_t *ptep, +int full) +{ +pte_clear (mm, address, ptep); +}#endif #ifndef __HAVE_ARCH_PTEP_CLEAR_FLUSH -#define ptep_clear_flush (__vma, __address, __ptep) \ -({ \ - pte_t __pte; \ - __pte = ptep_get_and_clear((__vma)->vm_mm, __address, __ptep); \ - flush_tlb_page(__vma, __address); \ - __pte; \ -}) +extern pte_t ptep_clear_flush (struct vm_area_struct *vma, +unsigned long address, +pte_t *ptep); +#endif + +#ifndef __HAVE_ARCH_PMDP_CLEAR_FLUSH +extern pmd_t pmdp_clear_flush (struct vm_area_struct *vma, +unsigned long address, +pmd_t *pmdp);#endif #ifndef __HAVE_ARCH_PTEP_SET_WRPROTECT
@@ -99,8 +145,49 @@ static inline void ptep_set_wrprotect(st }#endif +#ifndef __HAVE_ARCH_PMDP_SET_WRPROTECT +#ifdef CONFIG_TRANSPARENT_HUGEPAGE +static inline void pmdp_set_wrprotect (struct mm_struct *mm, +unsigned long address,pmd_t *pmdp) +{ +pmd_t old_pmd = *pmdp; +set_pmd_at (mm, address, pmdp,pmd_wrprotect (old_pmd)); +} +#else /* CONFIG_TRANSPARENT_HUGEPAGE */ +static inline void pmdp_set_wrprotect (struct mm_struct *mm, +unsigned long address,pmd_t *pmdp) +{ +BUG (); +} +#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ +#endif + +#ifndef __HAVE_ARCH_PMDP_SPLITTING_FLUSH +extern pmd_t pmdp_clear_flush (struct vm_area_struct *vma, +unsigned long address, +pmd_t *pmdp); +#endif +#ifndef __HAVE_ARCH_PTE_SAME -#define pte_same (A ,B ) (pte_val(A) == pte_val(B)) +static inline int pte_same (pte_t pte_a,pte_t pte_b) +{ +return pte_val (pte_a) ==pte_val (pte_b); +} +#endif + +#ifndef __HAVE_ARCH_PMD_SAME +#ifdef CONFIG_TRANSPARENT_HUGEPAGE +static inline int pmd_same (pmd_t pmd_a,pmd_t pmd_b) +{ +return pmd_val (pmd_a) ==pmd_val (pmd_b); +} +#else /* CONFIG_TRANSPARENT_HUGEPAGE */ +static inline int pmd_same (pmd_t pmd_a,pmd_t pmd_b) +{ +BUG (); +return 0 ; +} +#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ #endif #ifndef __HAVE_ARCH_PAGE_TEST_DIRTY
@@ -357,6 +444,13 @@ static inline int pmd_trans_splitting(pm {return 0 ; } +#ifndef __HAVE_ARCH_PMD_WRITE +static inline int pmd_write (pmd_t pmd) +{ +BUG (); +return 0 ; +} +#endif /* __HAVE_ARCH_PMD_WRITE */ #endif #endif /* !__ASSEMBLY__ */
mm/Makefile +1 -1
@@ -5,7 +5,7 @@ mmu-y := nommu.o mmu-$(CONFIG_MMU) := fremap.o highmem.o madvise.o memory.o mincore.o \ mlock.o mmap.o mprotect.o mremap.o msync.o rmap.o \ - vmalloc.o pagewalk.o + vmalloc.o pagewalk.o pgtable-generic.o obj-y := bootmem.o filemap.o mempool.o oom_kill.o fadvise.o \ maccess.o page_alloc.o page-writeback.o \
mm/pgtable-generic.c new file +124 -0
124 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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 30 of 66] transparent hugepage core
In reply to Mel GormanQuoted 2 lines · Mel Gorman
All that seems fine to me. Nits in part that are simply not worth calling out. In principal, I Agree With This :)
I didn't understand what is not worth calling out, but I like the end of your sentence ;).
Quoted 14 lines
Review
Quoted 9 lines
(quoted diff) +9
-0+#define wait_split_huge_page(__anon_vma, __pmd) \ + do { \ + pmd_t *____pmd = (__pmd); \ + spin_unlock_wait(&(__anon_vma)->root->lock); \ + /* \ + * spin_unlock_wait() is just a loop in C and so the \ + * CPU can reorder anything around it. \ + */ \ + smp_mb(); \Just a note as I see nothing wrong with this but that's a good spot. The unlock isn't a memory barrier. Out of curiousity, does it really need to be a full barrier or would a write barrier have been enough?
Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ BUG_ON(pmd_trans_splitting(*____pmd) || \ + pmd_trans_huge(*____pmd)); \
spin_unlock reads, the BUG_ON reads, so even if we ignore what happens before and after wait_split_huge_page(), at most it could be a read memory barrier. It can't be a write memory barrier as the spin_unlock_wait would pass it too.
I think it better be a full memory barrier to be sure the writes after wait_split_huge_page return don't happen before spin_unlock_wait. It's hard to see how that could happen though.
Quoted 17 lines
Review
Quoted 13 lines
(quoted diff) +13
-0+ } while (0) +#define HPAGE_PMD_ORDER (HPAGE_PMD_SHIFT-PAGE_SHIFT) +#define HPAGE_PMD_NR (1<<HPAGE_PMD_ORDER) +#if HPAGE_PMD_ORDER > MAX_ORDER +#error "hugepages can't be allocated by the buddy allocator" +#endif + +extern unsigned long vma_address(struct page *page, struct vm_area_struct *vma); +static inline int PageTransHuge(struct page *page) +{ + VM_BUG_ON(PageTail(page)); + return PageHead(page); +}
gfp.hseems an odd place for these. Should the flags go inpage-flags.hand maybe putvma_address()ininternal.h?
Quoted 1 line
Not a biggie.
Cleaned up thanks.
include/linux/huge_mm.h +0 -8
@@ -97,13 +97,6 @@ extern void __split_huge_page_pmd(struct#if HPAGE_PMD_ORDER >MAX_ORDER #error "hugepages can't be allocated by the buddy allocator"#endif - -extern unsigned long vma_address (struct page *page,struct vm_area_struct *vma); -static inline int PageTransHuge (struct page *page) -{ -VM_BUG_ON (PageTail (page)); -return PageHead (page); -}#else /* CONFIG_TRANSPARENT_HUGEPAGE */ #define HPAGE_PMD_SHIFT ({ BUG(); 0; })#define HPAGE_PMD_MASK ({ BUG(); 0; })
@@ -120,7 +113,6 @@ static inline int split_huge_page(struct do { } while (0)#define wait_split_huge_page (__anon_vma, __pmd) \ do { } while (0) -#define PageTransHuge (page) 0#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ #endif /* _LINUX_HUGE_MM_H */
include/linux/page-flags.h +13 -0
@@ -409,6 +409,19 @@ static inline void ClearPageCompound(str#endif /* !PAGEFLAGS_EXTENDED */ +#ifdef CONFIG_TRANSPARENT_HUGEPAGE +static inline int PageTransHuge (struct page *page) +{ +VM_BUG_ON (PageTail (page)); +return PageHead (page); +} +#else +static inline int PageTransHuge (struct page *page) +{ +return 0 ; +} +#endif +#ifdef CONFIG_MMU #define __PG_MLOCKED (1 << PG_mlocked)#else
mm/internal.h +4 -0
@@ -134,6 +134,10 @@ static inline void mlock_migrate_page(st } } +#ifdef CONFIG_TRANSPARENT_HUGEPAGE +extern unsigned long vma_address (struct page *page, +struct vm_area_struct *vma); +#endif #else /* !CONFIG_MMU */ static inline int is_mlocked_vma (struct vm_area_struct *v,struct page *p) {
Quoted 19 lines
Quoted 19 lines
include/linux/mm_inline.h +9
-1@@ -20,11 +20,18 @@ static inline int page_is_file_cache(str }static inline void +__add_page_to_lru_list (struct zone *zone,struct page *page,enum lru_list l, +struct list_head *head) +{ +list_add (&page->lru, head); +__inc_zone_state (zone,NR_LRU_BASE + l); +mem_cgroup_add_lru_list (page, l); +} + +static inline void add_page_to_lru_list (struct zone *zone,struct page *page,enum lru_list l) { -list_add (&page->lru, &zone->lru[l].list);
Quoted 8 lines
include/linux/mm_inline.h static inline int page_is_file_cache(str · line 36
Quoted 5 lines
include/linux/mm_inline.h +1
-2-__inc_zone_state (zone,NR_LRU_BASE + l); -mem_cgroup_add_lru_list (page, l); +__add_page_to_lru_list (zone, page, l, &zone->lru[l].list); }Do these really need to be in a public header or can they move to
mm/swap.c?
The above quoted change is a noop as far as the old code is concerned, and moving it to swap.c would alter the old code. I think list_add and __mod_zone_page_state is pretty small and fast so probably it's worth keeping it as inline.
Quoted 7 lines
include/linux/mm_inline.h static inline int page_is_file_cache(str
Quoted 5 lines
include/linux/mm_inline.h +5
-0+static void prepare_pmd_huge_pte (pgtable_t pgtable, +struct mm_struct *mm) +{ +VM_BUG_ON (spin_can_lock (&mm->page_table_lock)); +
assert_spin_locked()?
Changed.
Quoted 13 lines
Quoted 13 lines
include/linux/mm_inline.h +4
-2+int handle_pte_fault (struct mm_struct *mm, +struct vm_area_struct *vma,unsigned long address, +pte_t *pte,pmd_t *pmd,unsigned int flags) {pte_t entry;spinlock_t *ptl;@@ -3222,9 +3257,40 @@ int handle_mm_fault(struct mm_struct *mm pmd =pmd_alloc (mm, pud, address);if (!pmd)return VM_FAULT_OOM ; - pte =pte_alloc_map (mm, vma, pmd, address); -if (!pte) +if (pmd_none (*pmd) &&transparent_hugepage_enabled (vma)) {
Quoted 8 lines
include/linux/mm_inline.h int handle_mm_fault(struct mm_struct *mm · line 3266
Quoted 6 lines
include/linux/mm_inline.h +6
-0+if (!vma->vm_ops) +return do_huge_pmd_anonymous_page (mm, vma, address, + pmd, flags); + }else { +pmd_t orig_pmd = *pmd; +barrier ();What is this barrier for?
This is to be guaranteed gcc doesn't re-read the *pmd after the barrier and it instead always read it from orig_pmd variable on the local kernel stack. gcc doesn't know *pmd can still change from under us until after we take some lock and the code relies on orig_pmd not to change after barrier().
Quoted 5 lines
Other than a few minor questions, these seems very similar to what you had before. There is a lot going on in this patch but I did not find anything wrong.
Acked-by Mel Gorman <[email protected]>
Great thanks!
Andrea
--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 33 of 66] madvise(MADV_HUGEPAGE)
In reply to Mel GormanQuoted 10 lines · Mel Gorman
include/linux/huge_mm.h static inline int split_huge_page(struct · line 127
Quoted 7 lines · Andrea Arcangeli
include/linux/huge_mm.h +3
-0@@ -121,6 +122,11 @@ static inline int split_huge_page(struct#define wait_split_huge_page (__anon_vma, __pmd) \ do { } while (0)#define PageTransHuge (page) 0 +static inline int hugepage_madvise (unsigned long *vm_flags) +{ +BUG_ON (0 );What's
BUG_ON(0)in aid of?
When CONFIG_TRANSPARENT_HUGEPAGE is disabled, nothing must call that function (madvise must return -EINVAL like older kernels instead). But I guess you meant I should convert the BUG_ON(0) to a BUG() instead? (done)
Quoted 3 lines
I should have said it at patch 4 but don't forget that Michael Kerrisk should be made aware of
MADV_HUGEPAGEso it makes it to a manual page at some point.
Ok, I'll forward patch 4.
Thanks,
Andrea
--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 44 of 66] skip transhuge pages in ksm for now
In reply to Mel GormanQuoted 8 lines · Mel Gorman
Quoted 6 lines · Andrea Arcangeli
From: Andrea Arcangeli <[email protected]>
Skip transhuge pages in ksm for now.
Signed-off-by Andrea Arcangeli <[email protected]>Reviewed-by Rik van Riel <[email protected]>
Quoted 8 lines
Acked-by Mel Gorman <[email protected]>This is an idle concern that I haven't looked into but is there any conflict between khugepaged scanning the KSM scanning?
Specifically, I *think* the impact of this patch is that KSM will not accidentally split a huge page. Is that right? If so, it could do with being included in the changelog.
KSM wasn't aware about hugepages and in turn it'd never split them anyway. We want KSM to split hugepages only when if finds two equal subpages. That will happen later.
Right now there is no collision of ksmd and khugepaged, regular pages, hugepages and ksm pages will co-exist fine in the same vma. The only problem is that the system has now to start swapping before KSM has a chance to find equal pages and we'll fix it in the future so KSM can scan inside hugepages too and split them and merge the subpages as needed before the memory pressure starts.
Quoted 2 lines
On the other hand, can khugepaged be prevented from promoting a hugepage because of KSM?
Sure, khugepaged won't promote if there's any ksm page in the range. That's not going to change. When KSM is started, the priority remains in saving memory. If people uses enabled=madvise and MADV_HUGEPAGE+MADV_MERGEABLE there is actually zero memory loss because of THP and there is a speed improvement for all pages that aren't equal. So it's an ideal setup even for embedded. Regular cloud setup would be enabled=always + MADV_MERGEABLE (with enabled=always MADV_HUGEPAGE becomes a noop).
On a related note I'm also going to introduce a MADV_NO_HUGEPAGE, is that a good name for it? cloud management wants to be able to disable THP per-VM basis (when the VM are totally idle, and low priority, this currently also helps to maximize the power of KSM that would otherwise be activated only after initial sawpping, but the KSM part will be fixed). It could be achieved also with enabled=madvise and MADV_HUGEPAGE but we don't want to change the system wide default in order to disable THP on a per-VM basis: it's much nicer if the default behavior of the host remains the same in case it's not a pure hypervisor usage but there are other loads running in parallel to the virt load. In theory a prctl(PR_NO_HUGEPAGE) could also do it and it'd be possible to use from a wrapper (madvise can't be wrapped), but I think MADV_NO_HUGEPAGE is cleaner and it won't require brand new per-process info.
--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 45 of 66] remove PG_buddy
In reply to Mel GormanQuoted 11 lines · Mel Gorman
Quoted 9 lines · Andrea Arcangeli
From: Andrea Arcangeli <[email protected]>
PG_buddycan be converted to_mapcount== -2. So thePG_compound_lockcan be added topage->flagswithout overflowing (because of the sparse section bits increasing) withCONFIG_X86_PAE=yandCONFIG_X86_PAT=y. This also has to move the memory hotplug code from_mapcountto lru.next to avoid any risk of clashes. We can't use lru.next forPG_buddyremoval, but memory hotplug can use lru.next even more easily than the mapcount instead.
Quoted 2 lines
Does this make much of a difference? I confess I didn't read the patch closely because I didn't get the motivation.
The motivation is described in the first line. If I wouldn't remove PG_buddy, introducing PG_compound_lock would overflow the 32bit build with CONFIG_X86_PAE=y and CONFIG_X86_PAT=y. The bitflag easier to nuke was PG_buddy.
--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 51 of 66] set recommended min free kbytes
In reply to Mel GormanQuoted 38 lines · Mel Gorman
Review
Quoted 3 lines
(quoted diff) +3
-0+ /* Make sure at least 2 hugepages are free for MIGRATE_RESERVE */ + recommended_min = HPAGE_PMD_NR * nr_zones * 2; +The really important value is
pageblock_nr_pageshere. It'll just happen to work on x86 and x86-64 but anti-fragmentation is really about pageblocks, not PMDs.Review
Quoted 8 lines
(quoted diff) +8
-0+ /* + * Make sure that on average at least two pageblocks are almost free + * of another type, one for a migratetype to fall back to and a + * second to avoid subsequent fallbacks of other types There are 3 + * MIGRATE_TYPES we care about. + */ + recommended_min += HPAGE_PMD_NR * nr_zones * 3 * 3; +Same on the use of
pageblock_nr_pages. Also, you can replace 3 withMIGRATE_PCPTYPES.Review
Quoted 9 lines
(quoted diff) +9
-0+ /* don't ever allow to reserve more than 5% of the lowmem */ + recommended_min = min(recommended_min, + (unsigned long) nr_free_buffer_pages() / 20); + recommended_min <<= (PAGE_SHIFT-10); + + if (recommended_min > min_free_kbytes) { + min_free_kbytes = recommended_min; + setup_per_zone_wmarks(); + }The timing this is called is important. Would you mind doing a quick debugging check by adding a printk to
setup_zone_migrate_reserve()to ensureMIGRATE_RESERVEis getting set on sensible pageblocks? (see where the comment Suitable for reserving if this block is movable is) IfMIGRATE_RESERVEblocks are not being created in a sensible fashion, atomic high-order allocations will suffer in mysterious ways.
Quoted 3 lines
SEtting the higher min free kbytes from userspace happens to work because the system is initialised and
MIGRATE_MOVABLEexists but that might not be the case when automatically set like this patch.
When min_free_kbytes doesn't need to be increased (like huge system with lots of ram) setup_per_zone_wmarks wasn't called in the late_initcall where this code runs, and the original setup_per_zone_wmarks apparently wasn't calling setup_zone_migrate_reserve (how can it be?).
Anyway now I patched it like this and it seems to work properly with the unconditional setup_per_zone_wmarks in late_initcall(set_recommended_min_free_kbytes).
mm/huge_memory.c +5 -5
@@ -103,7 +103,7 @@ static int set_recommended_min_free_kbyt nr_zones++;/* Make sure at least 2 hugepages are free for MIGRATE_RESERVE */ - recommended_min =HPAGE_PMD_NR * nr_zones *2 ; + recommended_min = pageblock_nr_pages * nr_zones *2 ;/* * Make sure that on average at least two pageblocks are almost free
@@ -111,17 +111,17 @@ static int set_recommended_min_free_kbyt* second to avoid subsequent fallbacks of other types There are 3 * MIGRATE_TYPES we care about. */ - recommended_min +=HPAGE_PMD_NR * nr_zones *3 *3 ; + recommended_min += pageblock_nr_pages * nr_zones * +MIGRATE_PCPTYPES *MIGRATE_PCPTYPES ;/* don't ever allow to reserve more than 5% of the lowmem */ recommended_min =min (recommended_min, (unsigned long )nr_free_buffer_pages () /20 ); recommended_min <<= (PAGE_SHIFT -10 ); -if (recommended_min > min_free_kbytes) { +if (recommended_min > min_free_kbytes) min_free_kbytes = recommended_min; -setup_per_zone_wmarks (); - } +setup_per_zone_wmarks ();return 0 ; }late_initcall (set_recommended_min_free_kbytes);
mm/page_alloc.c +2 -0
@@ -3188,6 +3188,7 @@ static void setup_zone_migrate_reserve(s*/ reserve =min (2 , reserve); +printk ("reserve start %d\n" , reserve);for (pfn = start_pfn; pfn < end_pfn; pfn += pageblock_nr_pages) {if (!pfn_valid (pfn))continue ;
@@ -3226,6 +3227,7 @@ static void setup_zone_migrate_reserve(smove_freepages_block (zone, page,MIGRATE_MOVABLE ); } } +printk ("reserve end %d\n" , reserve); }/*
hugeadm with CONFIG_TRANSPARENT_HUGEPAGE=n leads to:
reserve start 1
reserve end 0
reserve start 2
reserve end 0
reserve start 2
reserve end 0
reserve start 0
reserve end 0
reserve start 0
reserve end 0
reserve start 0
reserve end 0
reserve start 2
reserve end 0
reserve start 0
reserve end 0
With CONFIG_TRANSPARENT_HUGEPAGE=Y I boot I see:
reserve start 1
reserve end 0
reserve start 2
reserve end 0
reserve start 2
reserve end 0
reserve start 0
reserve end 0
reserve start 0
reserve end 0
reserve start 0
reserve end 0
reserve start 2
reserve end 0
reserve start 0
--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 52 of 66] enable direct defrag
In reply to Mel GormanQuoted 8 lines · Mel Gorman
Quoted 3 lines · Andrea Arcangeli
From: Andrea Arcangeli <[email protected]>
With memory compaction in, and lumpy-reclaim removed, it seems safe enough to
While I'm hoping that my series on using compaction will be used instead of outright deletion of lumpy reclaim, this patch would still make sense.
Ok :), s/removed/disabled/
--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 55 of 66] select CONFIG_COMPACTION if TRANSPARENT_HUGEPAGE enabled
In reply to Mel GormanQuoted 2 lines · Mel Gorman
Just to confirm - by hang, you mean grinds to a slow pace as opposed to coming to a complete stop and having to restart?
Hmm it's like if you're gigabytes in swap and apps hangs for a while and system is not really usable and it swaps for most new memory allocations despite there's plenty of memory free, but it's not a deadlock of course.
BTW, alternatively I could:
unsigned long transparent_hugepage_flags __read_mostly =
(1<<TRANSPARENT_HUGEPAGE_FLAG)|
+#ifdef CONFIG_COMPACTION
+ (1<<TRANSPARENT_HUGEPAGE_DEFRAG_FLAG)|
+#endif
(1<<TRANSPARENT_HUGEPAGE_DEFRAG_KHUGEPAGED_FLAG);That would adds GFP_ATOMIC to THP allocation if compaction wasn't selected, but I think having compaction enabled diminish the risk of misconfigured kernels leading to unexpected measurements and behavior, so I feel much safer to keep the select COMPACTION in this patch.
Quoted 1 line
Acked-by Mel Gorman <[email protected]>
Added.
Thanks,
Andrea
--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 61 of 66] use compaction for GFP_ATOMIC order > 0
In reply to Mel GormanQuoted 4 lines · Mel Gorman
I don't think this is related to THP although I see what you're doing. It should be handled on its own. I'd also wonder if some of the tg3 failures are due to
MIGRATE_RESERVEnot being set properly whenmin_free_kbytesis automatically resized.
The failures also happened on older kernels except they wouldn't print it in the kernel logs, but you're right we may get better with migrate reserve enabled also on huge systems (it seems hugeadm --set_recommended-min_free_kbytes was doing a little more than its kernel counterpart with large systems with tons of ram, now fixed).
My status as far as this patch is concerned:
=========
Subject: use compaction for all allocation orders
From: Andrea Arcangeli <[email protected]>
It makes no sense not to enable compaction for small order pages as we don't want to end up with bad order 2 allocations and good and graceful order 9 allocations.
---
mm/compaction.c +1 -1
@@ -476,7 +495,7 @@ unsigned long try_to_compact_pages(struc* made because an assumption is made that the page allocator can satisfy * the "cheaper" orders without taking special steps */ -if (order <=PAGE_ALLOC_COSTLY_ORDER || !may_enter_fs || !may_perform_io) +if (!order || !may_enter_fs || !may_perform_io)return rc;count_vm_event (COMPACTSTALL );
===========
Subject: use compaction in kswapd for GFP_ATOMIC order > 0
From: Andrea Arcangeli <[email protected]>
This takes advantage of memory compaction to properly generate pages of order > 0 if regular page reclaim fails and priority level becomes more severe and we don't reach the proper watermarks.
---
include/linux/compaction.h +13 -0
@@ -11,6 +11,9 @@/* The full zone was compacted */ #define COMPACT_COMPLETE 3 +#define COMPACT_MODE_DIRECT_RECLAIM 0 +#define COMPACT_MODE_KSWAPD 1 +#ifdef CONFIG_COMPACTION extern int sysctl_compact_memory; extern int sysctl_compaction_handler(struct ctl_table *table, int write,
@@ -20,6 +23,9 @@ extern int sysctl_extfrag_handler(struct void __user *buffer, size_t *length, loff_t *ppos);extern int fragmentation_index (struct zone *zone,unsigned int order); +extern unsigned long compact_zone_order (struct zone *zone, +int order,gfp_t gfp_mask, +int compact_mode);extern unsigned long try_to_compact_pages (struct zonelist *zonelist,int order,gfp_t gfp_mask,nodemask_t *mask);
@@ -59,6 +65,13 @@ static inline unsigned long try_to_compareturn COMPACT_CONTINUE ; } +static inline unsigned long compact_zone_order (struct zone *zone, +int order,gfp_t gfp_mask, +int compact_mode) +{ +return COMPACT_CONTINUE ; +} +static inline void defer_compaction (struct zone *zone) { }
mm/compaction.c +26 -5
@@ -38,6 +38,8 @@ struct compact_control {unsigned int order;/* order a direct compactor needs */ int migratetype;/* MOVABLE, RECLAIMABLE etc */ struct zone *zone; + +int compact_mode; };static unsigned long release_freepages (struct list_head *freelist)
@@ -357,10 +359,10 @@ static void update_nr_listpages(struct c }static int compact_finished (struct zone *zone, -struct compact_control *cc) +struct compact_control *cc) {unsigned int order; -unsigned long watermark =low_wmark_pages (zone) + (1 << cc->order); +unsigned long watermark;if (fatal_signal_pending (current))return COMPACT_PARTIAL ;
@@ -370,12 +372,27 @@ static int compact_finished(struct zonereturn COMPACT_COMPLETE ;/* Compaction run is not finished if the watermark is not met */ +if (cc->compact_mode !=COMPACT_MODE_KSWAPD ) + watermark =low_wmark_pages (zone); +else + watermark =high_wmark_pages (zone); + watermark += (1 << cc->order); +if (!zone_watermark_ok (zone, cc->order, watermark,0 ,0 ))return COMPACT_CONTINUE ;if (cc->order ==-1 )return COMPACT_CONTINUE ; +/* +* Generating only one page of the right order is not enough +* for kswapd, we must continue until we're above the high +* watermark as a pool for high order GFP_ATOMIC allocations +* too. +*/ +if (cc->compact_mode ==COMPACT_MODE_KSWAPD ) +return COMPACT_CONTINUE ; +/* Direct compactor: Is a suitable page free? */ for (order = cc->order; order <MAX_ORDER ; order++) {/* Job done if page is free of the right migratetype */
@@ -433,8 +450,9 @@ static int compact_zone(struct zone *zonreturn ret; } -static unsigned long compact_zone_order (struct zone *zone, -int order,gfp_t gfp_mask) +unsigned long compact_zone_order (struct zone *zone, +int order,gfp_t gfp_mask, +int compact_mode) {struct compact_control cc = { .nr_freepages =0 ,
@@ -442,6 +460,7 @@ static unsigned long compact_zone_order( .order = order, .migratetype = allocflags_to_migratetype(gfp_mask), .zone = zone, + .compact_mode = compact_mode, };INIT_LIST_HEAD (&cc.freepages);INIT_LIST_HEAD (&cc.migratepages);
@@ -517,7 +536,8 @@ unsigned long try_to_compact_pages(strucbreak ; } - status =compact_zone_order (zone, order, gfp_mask); + status =compact_zone_order (zone, order, gfp_mask, +COMPACT_MODE_DIRECT_RECLAIM ); rc =max (status, rc);if (zone_watermark_ok (zone, order, watermark,0 ,0 ))
@@ -547,6 +567,7 @@ static int compact_node(int nid) .nr_freepages = 0, .nr_migratepages = 0, .order = -1, + .compact_mode = COMPACT_MODE_DIRECT_RECLAIM, }; zone = &pgdat->node_zones[zoneid];
mm/vmscan.c +20 -1
@@ -40,6 +40,7 @@#include <linux/memcontrol.h> #include <linux/delayacct.h> #include <linux/sysctl.h> +#include <linux/compaction.h> #include <asm/tlbflush.h> #include <asm/div64.h>
@@ -2148,6 +2149,7 @@ loop_again:* cause too much scanning of the lower zones. */ for (i =0 ; i <= end_zone; i++) { +int compaction;struct zone *zone = pgdat->node_zones + i;int nr_slab;
@@ -2177,9 +2179,26 @@ loop_again: lru_pages); sc.nr_reclaimed += reclaim_state->reclaimed_slab; total_scanned += sc.nr_scanned; + + compaction =0 ; +if (order && +zone_watermark_ok (zone,0 , +high_wmark_pages (zone), + end_zone,0 ) && + !zone_watermark_ok (zone, order, +high_wmark_pages (zone), + end_zone,0 )) { +compact_zone_order (zone, + order, + sc.gfp_mask, +COMPACT_MODE_KSWAPD ); + compaction =1 ; + } +if (zone->all_unreclaimable)continue ; -if (nr_slab ==0 && !zone_reclaimable (zone)) +if (!compaction && nr_slab ==0 && + !zone_reclaimable (zone)) zone->all_unreclaimable =1 ;/* * If we've done a decent amount of scanning and
--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 44 of 66] skip transhuge pages in ksm for now
In reply to Andrea ArcangeliQuoted 14 lines · Andrea Arcangeli
Quoted 13 lines · Mel Gorman
Quoted 6 lines · Andrea Arcangeli
From: Andrea Arcangeli <[email protected]>
Skip transhuge pages in ksm for now.
Signed-off-by Andrea Arcangeli <[email protected]>Reviewed-by Rik van Riel <[email protected]>Acked-by Mel Gorman <[email protected]>This is an idle concern that I haven't looked into but is there any conflict between khugepaged scanning the KSM scanning?
Quoted 8 lines
Quoted 3 lines
Specifically, I *think* the impact of this patch is that KSM will not accidentally split a huge page. Is that right? If so, it could do with being included in the changelog.
KSM wasn't aware about hugepages and in turn it'd never split them anyway. We want KSM to split hugepages only when if finds two equal subpages. That will happen later.
Ok.
Quoted 7 lines
Right now there is no collision of ksmd and khugepaged, regular pages, hugepages and ksm pages will co-exist fine in the same vma. The only problem is that the system has now to start swapping before KSM has a chance to find equal pages and we'll fix it in the future so KSM can scan inside hugepages too and split them and merge the subpages as needed before the memory pressure starts.
Ok. So it's not a perfect mesh but it's not broken either.
Quoted 12 lines
Quoted 2 lines
On the other hand, can khugepaged be prevented from promoting a hugepage because of KSM?
Sure, khugepaged won't promote if there's any ksm page in the range. That's not going to change. When KSM is started, the priority remains in saving memory. If people uses enabled=madvise and MADV_HUGEPAGE+MADV_MERGEABLE there is actually zero memory loss because of THP and there is a speed improvement for all pages that aren't equal. So it's an ideal setup even for embedded. Regular cloud setup would be enabled=always +
MADV_MERGEABLE(with enabled=alwaysMADV_HUGEPAGEbecomes a noop).
That's a reasonable compromise. Thanks for clarifying.
Quoted 6 lines
On a related note I'm also going to introduce a
MADV_NO_HUGEPAGE, is that a good name for it? cloud management wants to be able to disable THP per-VM basis (when the VM are totally idle, and low priority, this currently also helps to maximize the power of KSM that would otherwise be activated only after initial sawpping, but the KSM part will be fixed). It could be achieved also with enabled=madvise and
Quoted 9 lines
MADV_HUGEPAGEbut we don't want to change the system wide default in order to disable THP on a per-VM basis: it's much nicer if the default behavior of the host remains the same in case it's not a pure hypervisor usage but there are other loads running in parallel to the virt load. In theory aprctl(PR_NO_HUGEPAGE)could also do it and it'd be possible to use from a wrapper (madvise can't be wrapped), but I thinkMADV_NO_HUGEPAGEis cleaner and it won't require brand new per-process info.
I see no problem with the proposal. The name seems as good as any other name. I guess the only other sensible alternative might be MADV_BASEPAGE.
Signature · 10 lines
Mel Gorman Part-time Phd Student Linux Technology Center University of Limerick IBM Dublin Software Lab -- 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/ . Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 55 of 66] select CONFIG_COMPACTION if TRANSPARENT_HUGEPAGE enabled
In reply to Andrea ArcangeliQuoted 9 lines · Andrea Arcangeli
Quoted 2 lines · Mel Gorman
Just to confirm - by hang, you mean grinds to a slow pace as opposed to coming to a complete stop and having to restart?
Hmm it's like if you're gigabytes in swap and apps hangs for a while and system is not really usable and it swaps for most new memory allocations despite there's plenty of memory free, but it's not a deadlock of course.
Ok, but it's likely to be kswapd being very aggressive because it's woken up frequently and tries to balance all zones. Once it's not deadlocking entirely, there isn't a more fundamental bug hiding in there somewhere.
Quoted 11 lines
BTW, alternatively I could:
unsigned long
transparent_hugepage_flags__read_mostly=(1<<TRANSPARENT_HUGEPAGE_FLAG)|(quoted diff) +3
-0+#ifdef CONFIG_COMPACTION + (1<<TRANSPARENT_HUGEPAGE_DEFRAG_FLAG)| +#endif (1<<TRANSPARENT_HUGEPAGE_DEFRAG_KHUGEPAGED_FLAG);That would adds
GFP_ATOMICto THP allocation if compaction wasn't selected,
With GFP_NO_KSWAPD, it would stop trashing I suspect the success rate would be extremely low as nothing will be defragmenting memory.
Quoted 4 lines
but I think having compaction enabled diminish the risk of misconfigured kernels leading to unexpected measurements and behavior, so I feel much safer to keep the select COMPACTION in this patch.
Agreed.
Signature · 10 lines
Mel Gorman Part-time Phd Student Linux Technology Center University of Limerick IBM Dublin Software Lab -- 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/ . Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 55 of 66] select CONFIG_COMPACTION if TRANSPARENT_HUGEPAGE enabled
Hi Mel,
Quoted 11 lines · Mel Gorman
Quoted 9 lines · Andrea Arcangeli
Quoted 2 lines · Mel Gorman
Just to confirm - by hang, you mean grinds to a slow pace as opposed to coming to a complete stop and having to restart?
Hmm it's like if you're gigabytes in swap and apps hangs for a while and system is not really usable and it swaps for most new memory allocations despite there's plenty of memory free, but it's not a deadlock of course.
Quoted 4 lines
Ok, but it's likely to be kswapd being very aggressive because it's woken up frequently and tries to balance all zones. Once it's not deadlocking entirely, there isn't a more fundamental bug hiding in there somewhere.
kswapd isn't activated by transhuge allocations because there's khugepaged for that and it's throttle to try a 2m alloc only once per minute if there's fragmentation.
So the reason of the trashing is the direct lumpy.
--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 38 of 66] memcontrol: try charging huge pages from stock
In reply to KAMEZAWA HiroyukiQuoted 8 lines · KAMEZAWA Hiroyuki
Quoted 5 lines · On Wed, 03 Nov 2010 16:28:13 +0100 Andrea Arcangeli <[email protected]> wrote:
From: Johannes Weiner <[email protected]>
The stock unit is just bytes, there is no reason to only take normal pages from it.
Quoted 8 lines
Quoted 2 lines
Signed-off-by Johannes Weiner <[email protected]>Signed-off-by Andrea Arcangeli <[email protected]>nonsense. The stock size is CHARGE_SIZE=32*PAGE_SIZE at maximum. When we make this to be larger than HUGEPAGE size, 2M per cpu at least. This means memcg's resource "usage" accounting will have 128MB inaccuracy.
Nack.
Removed, thanks!
--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 36 of 66] memcg compound
In reply to KAMEZAWA HiroyukiHello Kame,
Quoted 1 line · KAMEZAWA Hiroyuki
If there are requirements of big page > 4GB, unsigned long should be used.
There aren't, it's unthinkable at the moment even 1G (besides it seems on some implementations the CPU lacks a real 1G tlb and just prefetch the same 2M tlb so making the tlb miss read one less cacheline but in practice 1G don't seem to provide any measurable runtime compared to 2M THP). Things will always be exponential, the benefit provided going from 4k to 2M will always be an order of magnitude bigger than the benefit from 2M to 1G, no matter how much the hardware is handling the 1G pages natively.
Quoted 8 lines
Quoted 6 lines
Review
Quoted 6 lines
(quoted diff) +1
-1int nr_oom_retries = MEM_CGROUP_RECLAIM_RETRIES; struct mem_cgroup *mem = NULL; int ret; - int csize = CHARGE_SIZE; + int csize = max(CHARGE_SIZE, (unsigned long) page_size);unsigned long here.
This is to shut off a warning because CHARGE_SIZE is calculated as multiple of PAGE_SIZE which is unsigned long. csize was already int but unsigned long is not required. Like you point out it's not worth batching even pages as small as 2G, so no need of unsigned long.
Quoted 8 lines
Quoted 6 lines
Review __do_uncharge(struct mem_cgroup *mem, co · line 2506
Quoted 6 lines
(quoted diff) +1
-1@@ -2491,14 +2503,14 @@ __do_uncharge(struct mem_cgroup *mem, co if (batch->memcg != mem) goto direct_uncharge; /* remember freed charge and uncharge it later */ - batch->bytes += PAGE_SIZE; + batch->bytes += page_size;Hmm, isn't it simpler to avoid batched-uncharge when
page_size>PAGE_SIZE?
As you wish, so I'm changing it like this.
archs where the pmd is implemented purely in software might actually be able to use page sizes smaller than 2M that may make sense to batch, but for now if you think this is simpler I'll go for it. We need simple.
mm/memcontrol.c +5 -2
@@ -2503,6 +2503,9 @@ __do_uncharge(struct mem_cgroup *mem, coif (!batch->do_batch ||test_thread_flag (TIF_MEMDIE )) goto direct_uncharge; +if (page_size !=PAGE_SIZE ) + goto direct_uncharge; +/* * In typical case, batch->memcg == mem. This means we can * merge a series of uncharges to an uncharge of res_counter.
@@ -2511,9 +2514,9 @@ __do_uncharge(struct mem_cgroup *mem, coif (batch->memcg != mem) goto direct_uncharge;/* remember freed charge and uncharge it later */ - batch->bytes += page_size; + batch->bytes +=PAGE_SIZE ;if (uncharge_memsw) - batch->memsw_bytes += page_size; + batch->memsw_bytes +=PAGE_SIZE ;return ; direct_uncharge:res_counter_uncharge (&mem->res, page_size);
--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 39 of 66] memcg huge memory
In reply to KAMEZAWA HiroyukiQuoted 21 lines · KAMEZAWA Hiroyuki
Quoted 5 lines · On Wed, 03 Nov 2010 16:28:14 +0100 Andrea Arcangeli <[email protected]> wrote:
(quoted diff) +0
-1@@ -402,9 +408,15 @@ static int do_huge_pmd_wp_page_fallback( for (i = 0; i < HPAGE_PMD_NR; i++) { pages[i] = alloc_page_vma(GFP_HIGHUSER_MOVABLE, vma, address); - if (unlikely(!pages[i])) {Review static int do_huge_pmd_wp_page_fallback( · line 419
Quoted 10 lines
(quoted diff) +8
-1- while (--i >= 0) + if (unlikely(!pages[i] || + mem_cgroup_newpage_charge(pages[i], mm, + GFP_KERNEL))) { + if (pages[i]) put_page(pages[i]); + while (--i >= 0) { + mem_cgroup_uncharge_page(pages[i]); + put_page(pages[i]); + }Maybe you can use batched-uncharge here.
==mem_cgroup_uncharge_start()
Quoted 6 lines
{ do loop; }
mem_cgroup_uncharge_end();
==
Then, many atomic ops can be reduced.
Cute!
mm/huge_memory.c +2 -0
@@ -413,10 +413,12 @@ static int do_huge_pmd_wp_page_fallback( GFP_KERNEL))) {if (pages[i])put_page (pages[i]); +mem_cgroup_uncharge_start ();while (--i >=0 ) {mem_cgroup_uncharge_page (pages[i]);put_page (pages[i]); } +mem_cgroup_uncharge_end ();kfree (pages); ret |=VM_FAULT_OOM ; goto out;
Quoted 7 lines
Quoted 7 lines
(quoted diff) +0
-0kfree(pages); ret |= VM_FAULT_OOM; goto out;@@ -455,8 +467,10 @@ out:
Quoted 9 lines
Review out: · line 473
Quoted 7 lines
(quoted diff) +3
-1out_free_pages: spin_unlock(&mm->page_table_lock); - for (i = 0; i < HPAGE_PMD_NR; i++) + for (i = 0; i < HPAGE_PMD_NR; i++) { + mem_cgroup_uncharge_page(pages[i]); put_page(pages[i]); + }here, too.
This is actually a very unlikely path handling a thread race condition, but I'll add it any way.
mm/huge_memory.c +2 -0
@@ -469,10 +469,12 @@ out: out_free_pages:spin_unlock (&mm->page_table_lock); +mem_cgroup_uncharge_start ();for (i =0 ; i <HPAGE_PMD_NR ; i++) {mem_cgroup_uncharge_page (pages[i]);put_page (pages[i]); } +mem_cgroup_uncharge_end ();kfree (pages); goto out; }
Quoted 2 lines
Hmm...it seems there are no codes for
move_account()hugepage in series. I think it needs some complicated work to walk page table.
Agreed.
Re: [PATCH 36 of 66] memcg compound
In reply to Andrea ArcangeliQuoted 9 lines · On Tue, 14 Dec 2010 18:38:17 +0100 Andrea Arcangeli <[email protected]> wrote:
Quoted 8 lines
Quoted 6 lines
mm/memcontrol.c __do_uncharge(struct mem_cgroup *mem, co · line 2506
Quoted 6 lines
mm/memcontrol.c +1
-1@@ -2491,14 +2503,14 @@ __do_uncharge(struct mem_cgroup *mem, coif (batch->memcg != mem) goto direct_uncharge;/* remember freed charge and uncharge it later */ - batch->bytes +=PAGE_SIZE ; + batch->bytes += page_size;Hmm, isn't it simpler to avoid batched-uncharge when
page_size>PAGE_SIZE?
Quoted 7 lines
As you wish, so I'm changing it like this.
archs where the pmd is implemented purely in software might actually be able to use page sizes smaller than 2M that may make sense to batch, but for now if you think this is simpler I'll go for it. We need simple.
Thank you. Hmm,..seems not very simple :( I'm sorry. Please do as you want.
-Kame
Quoted 17 lines
mm/memcontrol.c +3
-0@@ -2503,6 +2503,9 @@ __do_uncharge(struct mem_cgroup *mem, coif (!batch->do_batch ||test_thread_flag (TIF_MEMDIE )) goto direct_uncharge; +if (page_size !=PAGE_SIZE ) + goto direct_uncharge; +/* * In typical case, batch->memcg == mem. This means we can * merge a series of uncharges to an uncharge of res_counter. @@ -2511,9 +2514,9 @@ __do_uncharge(struct mem_cgroup *mem, coif (batch->memcg != mem)
mm/memcontrol.c __do_uncharge(struct mem_cgroup *mem, co · line 2522
Quoted 10 lines
mm/memcontrol.c +2
-2goto direct_uncharge;/* remember freed charge and uncharge it later */ - batch->bytes += page_size; + batch->bytes +=PAGE_SIZE ;if (uncharge_memsw) - batch->memsw_bytes += page_size; + batch->memsw_bytes +=PAGE_SIZE ;return ; direct_uncharge:res_counter_uncharge (&mem->res, page_size);
--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 36 of 66] memcg compound
Hello,
Quoted 2 lines · KAMEZAWA Hiroyuki
Thank you. Hmm,..seems not very simple :( I'm sorry. Please do as you want.
I did the below change, let me know if there's any problem with it.
What's left is mem_cgroup_move_parent...
Quoted 19 lines
Quoted 19 lines
mm/memcontrol.c +4
-1@@ -2503,6 +2503,9 @@ __do_uncharge(struct mem_cgroup *mem, coif (!batch->do_batch ||test_thread_flag (TIF_MEMDIE )) goto direct_uncharge; +if (page_size !=PAGE_SIZE ) + goto direct_uncharge; +/* * In typical case, batch->memcg == mem. This means we can * merge a series of uncharges to an uncharge of res_counter. @@ -2511,9 +2514,9 @@ __do_uncharge(struct mem_cgroup *mem, coif (batch->memcg != mem) goto direct_uncharge;/* remember freed charge and uncharge it later */ - batch->bytes += page_size; + batch->bytes +=PAGE_SIZE ;
Quoted 9 lines
mm/memcontrol.c __do_uncharge(struct mem_cgroup *mem, co · line 2522
Quoted 8 lines
mm/memcontrol.c +1
-1if (uncharge_memsw) - batch->memsw_bytes += page_size; + batch->memsw_bytes +=PAGE_SIZE ;return ; direct_uncharge:res_counter_uncharge (&mem->res, page_size);
--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 13 of 66] export maybe_mkwrite
In reply to Andrea ArcangeliQuoted 8 lines · Andrea Arcangeli
From: Andrea Arcangeli <[email protected]>
huge_memory.cneeds it too when it fallbacks in copying hugepages into regular fragmented pages if hugepage allocation fails during COW.Signed-off-by Andrea Arcangeli <[email protected]>Acked-by Rik van Riel <[email protected]>Acked-by Mel Gorman <[email protected]>
It wasn't good idea to do it. mm/memory.c is used only for system with MMU. System without MMU are broken.
Not sure what the right fix is but anyway I think use one ifdef make sense (git patch in attachment).
Regards,
Michal
include/linux/mm.h +2 -0
@@ -470,6 +470,7 @@ static inline void set_compound_order(struct page *page, unsigned long order) page[1 ].lru.prev = (void *)order; } +#ifdef CONFIG_MMU /* * Do pte_mkwrite, but only if the vma says VM_WRITE. We do this when * servicing faults for write access. In the normal case, do always want
@@ -482,6 +483,7 @@ static inline pte_t maybe_mkwrite(pte_t pte, struct vm_area_struct *vma) pte =pte_mkwrite (pte); return pte; } +#endif /* * Multiple processes may "see" the same page. E.g. for untouched
Quoted 53 lines
---
include/linux/mm.h +13
-0@@ -416,6 +416,19 @@ static inline void set_compound_order(st }/* +* Do pte_mkwrite, but only if the vma says VM_WRITE. We do this when +* servicing faults for write access. In the normal case, do always want +* pte_mkwrite. But get_user_pages can cause write faults for mappings +* that do not have writing enabled, when used by access_process_vm. +*/ +static inline pte_t maybe_mkwrite (pte_t pte,struct vm_area_struct *vma) +{ +if (likely (vma->vm_flags &VM_WRITE )) + pte =pte_mkwrite (pte); +return pte; +} + +/* * Multiple processes may "see" the same page. E.g. for untouched * mappings of /dev/null, all processes see the same page full of * zeroes, and text pages of executables and shared libraries have mm/memory.c +0
-14@@ -2048,19 +2048,6 @@ static inline int pte_unmap_same(structreturn same; } -/* -* Do pte_mkwrite, but only if the vma says VM_WRITE. We do this when -* servicing faults for write access. In the normal case, do always want -* pte_mkwrite. But get_user_pages can cause write faults for mappings -* that do not have writing enabled, when used by access_process_vm. -*/ -static inline pte_t maybe_mkwrite (pte_t pte,struct vm_area_struct *vma) -{ -if (likely (vma->vm_flags &VM_WRITE )) - pte =pte_mkwrite (pte); -return pte; -} -static inline void cow_user_page (struct page *dst,struct page *src,unsigned long va,struct vm_area_struct *vma) {/* -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Signature · 3 lines
Michal Simek, Ing. (M.Eng) PetaLogix - Linux Solutions for a Reconfigurable World w: www.petalogix.com p: +61-7-30090663,+42-0-721842854 f: +61-7-30090663
Quoted 1 line
From
9d09534daec636eafed279352c6b34d3b47c3a09Mon Sep 17 00:00:00 2001
From: Michal Simek <[email protected]>
Date: Mon, 17 Jan 2011 15:09:36 +0100
Subject: [PATCH] mm: System without MMU do not need pte_mkwrite
The patch "thp: export maybe_mkwrite"
(sha1 14fd403f2146f740942d78af4e0ee59396ad8eab)
break systems without MMU.
--- include/linux/mm.h | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
include/linux/mm.h +2 -0
@@ -470,6 +470,7 @@ static inline void set_compound_order(struct page *page, unsigned long order) page[1 ].lru.prev = (void *)order; } +#ifdef CONFIG_MMU /* * Do pte_mkwrite, but only if the vma says VM_WRITE. We do this when * servicing faults for write access. In the normal case, do always want
@@ -482,6 +483,7 @@ static inline pte_t maybe_mkwrite(pte_t pte, struct vm_area_struct *vma) pte =pte_mkwrite (pte); return pte; } +#endif /* * Multiple processes may "see" the same page. E.g. for untouched
Signature · 1 line
1.5.5.6
Re: [PATCH 13 of 66] export maybe_mkwrite
Hi Michal,
Quoted 10 lines · Michal Simek
Quoted 8 lines · Andrea Arcangeli
From: Andrea Arcangeli <[email protected]>
huge_memory.cneeds it too when it fallbacks in copying hugepages into regular fragmented pages if hugepage allocation fails during COW.Signed-off-by Andrea Arcangeli <[email protected]>Acked-by Rik van Riel <[email protected]>Acked-by Mel Gorman <[email protected]>
Quoted 5 lines
It wasn't good idea to do it.
mm/memory.cis used only for system with MMU. System without MMU are broken.Not sure what the right fix is but anyway I think use one ifdef make sense (git patch in attachment).
Can you show the build failure with CONFIG_MMU=n so I can understand better? Other places in mm.h depends on pte_t/vm_area_struct/VM_WRITE to be defined, if a system is without MMU nobody should call it simply. Not saying your patch is wrong, but I'm trying to understand how exactly it got broken and the gcc error would show it immediately.
This is only called by memory.o and huge_memory.o and they both are built only if MMU=y.
Thanks!
Andrea
Re: [PATCH 13 of 66] export maybe_mkwrite
Quoted 16 lines · Andrea Arcangeli
Hi Michal,
Quoted 6 lines · Michal Simek
Quoted 5 lines · Andrea Arcangeli
From: Andrea Arcangeli <[email protected]>
huge_memory.cneeds it too when it fallbacks in copying hugepages into regular fragmented pages if hugepage allocation fails during COW.Quoted 6 lines
Quoted 3 lines
Signed-off-by Andrea Arcangeli <[email protected]>Acked-by Rik van Riel <[email protected]>Acked-by Mel Gorman <[email protected]>It wasn't good idea to do it.
mm/memory.cis used only for system with MMU. System without MMU are broken.Not sure what the right fix is but anyway I think use one ifdef make sense (git patch in attachment).
Quoted 8 lines
Can you show the build failure with
CONFIG_MMU=nso I can understand better? Other places inmm.hdepends on pte_t/vm_area_struct/VM_WRITE to be defined, if a system is without MMU nobody should call it simply. Not saying your patch is wrong, but I'm trying to understand how exactly it got broken and the gcc error would show it immediately.This is only called by memory.o and huge_memory.o and they both are built only if MMU=y.
Of course: Look for example at this page:
http://www.monstr.eu/wiki/doku.php?id=log:2011-01-18_11_51_49#linux_next
Thanks,
Michal
Signature · 11 lines
Michal Simek, Ing. (M.Eng) w: www.monstr.eu p: +42-0-721842854 Maintainer of Linux kernel 2.6 Microblaze Linux - http://www.monstr.eu/fdt/ Microblaze U-BOOT custodian -- 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/ . Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 13 of 66] export maybe_mkwrite
Quoted 2 lines · Michal Simek
Of course: Look for example at this page:
http://www.monstr.eu/wiki/doku.php?id=log:2011-01-18_11_51_49#linux_next
Ok now I see, the problem is the lack of pte_mkwrite with MMU=n.
So either we apply your patch or we move the maybe_mkwrite at the top of huge_mm.h (before #ifdef CONFIG_TRANSPARENT_HUGEPAGE), it's up to you...
--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 13 of 66] export maybe_mkwrite
Quoted 9 lines · Andrea Arcangeli
Quoted 2 lines · Michal Simek
Of course: Look for example at this page:
http://www.monstr.eu/wiki/doku.php?id=log:2011-01-18_11_51_49#linux_nextOk now I see, the problem is the lack of
pte_mkwritewith MMU=n.So either we apply your patch or we move the
maybe_mkwriteat the top ofhuge_mm.h(before #ifdefCONFIG_TRANSPARENT_HUGEPAGE), it's up to you...
If you mean me, IRC there are some !MMU that's why I prefer to use my origin version.
Who kill take care about this fix? I prefer to add it to mainline ASAP to fix all noMMU platforms.
Thanks,
Michal
Signature · 11 lines
Michal Simek, Ing. (M.Eng) w: www.monstr.eu p: +42-0-721842854 Maintainer of Linux kernel 2.6 Microblaze Linux - http://www.monstr.eu/fdt/ Microblaze U-BOOT custodian -- 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/ . Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>