mmu_gather changes & generalization
Subsystems (8)
So to make things simple: I want to generalize the tlb batch interfaces to all flushing, except single pages and possible kernel page table flushing.
I've discussed a bit with Nick today, and came up with this idea as a first step toward possible bigger changes/cleanups. He told me you have been working around the same lines, so I'd like your feedback there and possibly whatever patches you are already cooking :-)
First, the situation/problems:
- The problems with using the current mmu_gather is the fact that it's
per-cpu, thus needs to be flushed when we do lock dropping and might schedule. That means more work than necessary on things like x86 when using it for fork or mprotect for example.
- Essentially, a simple batch data structure doesn't need to be
per-CPU, it could just be on the stack. However, the current one is per-cpu because of this massive list of struct page's which is too big for a stack allocation.
Now the idea is to turn mmu_gather into a small stack based data structure, with an optional pointer to the list of pages which remains, for now, per-cpu.
The initializer for it (tlb_gather_init ?) would then take a flag/type argument saying whether it is to be used for simple invalidations, or invalidations + pages freeing.
If used for page freeing, that pointer points to the per-cpu list of pages and we do get_cpu (and put_cpu when finishing the batch). If used for simple invalidations, we set that pointer to NULL and don't do get_cpu/put_cpu.
That way, we don't have to finish/restart the batch unless we are freeing pages. Thus users like fork() don't need to finish/restart the batch, and thus, we have no overhead on x86 compared to the current implementation (well, other than setting need_flush to 1 but that's probably not close to measurable).
Thus, the implementation remains as far as unmap_vmas is concerned, essentially the same. We just make it stack based at the top-level and change the init call, and we can avoid passing double indirections down the call chain, which is a nice cleanup.
An additional cleanup that it directly leads to is rather than finish/init when doing lock-break, when can introduce a reinit call that restarts a batch keeping the existing "settings" (We would still call finish, it's just that the call pair would be finish/reinit). That way, we don't have to "remember" things like fullmm like we have to do currently.
Since it's no longer per-cpu, things like fullmm or mm are still valid in the batch structure, and so we don't have to carry "fullmm" around like we do in unmap_vmas (and like we would have to do in other users). In fact, arch implementations can carry around even more state that they might need and keep it around lock breaks that way.
That would provide a good ground for then looking into changing the per-cpu list of pages to something else, as Nick told me you were working on.
Any comment, idea, suggestions ? I will give a go at implementing that sometime this week I hope (I have some urgent stuff to do first) unless you guys convince me it's worthless :-)
Note that I expect some perf. improvements on things like ppc32 on fork due to being able to target for shooting only hash entries for PTEs that have actually be turned into RO. The current ppc32 hash code just basically re-walks the page tables in flush_tlb_mm() and shoots down all PTEs that have been hashed.
Cheers,
Ben.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 9 lines · Benjamin Herrenschmidt
So to make things simple: I want to generalize the tlb batch interfaces to all flushing, except single pages and possible kernel page table flushing.
Note that I expect some perf. improvements on things like ppc32 on fork due to being able to target for shooting only hash entries for PTEs that have actually be turned into RO. The current ppc32 hash code just basically re-walks the page tables in
flush_tlb_mm()and shoots down all PTEs that have been hashed.
I've moved your last paragraph up here: that last sentence makes sense of the whole thing, and I'm now much happier with what you're intending, than when I first just thought you were trying to complicate flush_tlb_mm.
Quoted 5 lines
I've discussed a bit with Nick today, and came up with this idea as a first step toward possible bigger changes/cleanups. He told me you have been working around the same lines, so I'd like your feedback there and possibly whatever patches you are already cooking :-)
I worked on it around 2.6.16, but wasn't satisfied with the result, and then got stalled. What I should do now is update what I had to 2.6.22, and in doing so remind myself of the limitations, and send the results off to you - from what you say, I've a few days for that before you get to work on it.
I think there were two issues that stalled me. One, I was mainly trying to remove that horrid ZAP_BLOCK_SIZE from unmap_vmas, allowing preemption more naturally; but failed to solve the truncation case, when i_mmap_lock is held. Two, I needed to understand the different arches better: though it's grand if you're coming aboard, because powerpc (along with the seemingly similar sparc64) was one of the exceptions, deferring the flush to context switch (I need to remind myself why that was an issue). The other arches, even if not using asm-generic, seemed pretty much generic: arm a little simpler than generic, ia64 a little more baroque but more similar than it looked. Sounds like Martin may be about to take s390 in its own direction.
The only arches I actually converted over were i386 and x86_64 (knowing others would keep changing while I worked on the patch).
Quoted 7 lines
First, the situation/problems:
- The problems with using the current
mmu_gatheris the fact that it's
per-cpu, thus needs to be flushed when we do lock dropping and might schedule. That means more work than necessary on things like x86 when using it for fork or mprotect for example.
Yes, it dates from early 2.4, long before preemption latency placed limits on our use of per-cpu areas.
Quoted 9 lines
- Essentially, a simple batch data structure doesn't need to be
per-CPU, it could just be on the stack. However, the current one is per-cpu because of this massive list of struct page's which is too big for a stack allocation.Now the idea is to turn
mmu_gatherinto a small stack based data structure, with an optional pointer to the list of pages which remains, for now, per-cpu.
What I had was the small stack based data structure, with a small fallback array of struct page pointers built in, and attempts to allocate a full page atomically when this array not big enough - just go slower with the small array when that allocation fails. There may be cleverer approaches, but it seems good enough.
Quoted 4 lines
The initializer for it (
tlb_gather_init?) would then take a flag/type argument saying whether it is to be used for simple invalidations, or invalidations + pages freeing.
Yes, I had some flags too.
Quoted 5 lines
If used for page freeing, that pointer points to the per-cpu list of pages and we do
get_cpu(andput_cpuwhen finishing the batch). If used for simple invalidations, we set that pointer to NULL and don't do get_cpu/put_cpu.
The particularly bad thing about get_cpu/put_cpu there, is that the efficiently big array stores up a lot of work for the future (when swapcached pages are freed), which still has to be done with preemption disabled.
Could the migrate_disable now proposed help there? At the time I had that same idea, but discarded it because of the complication of different tasks (different mms) needing the same per-cpu buffer; but perhaps that isn't much of a complication in fact.
Quoted 6 lines
That way, we don't have to finish/restart the batch unless we are freeing pages. Thus users like
fork()don't need to finish/restart the batch, and thus, we have no overhead on x86 compared to the current implementation (well, other than settingneed_flushto 1 but that's probably not close to measurable).
;)
Quoted 5 lines
Thus, the implementation remains as far as
unmap_vmasis concerned, essentially the same. We just make it stack based at the top-level and change the init call, and we can avoid passing double indirections down the call chain, which is a nice cleanup.
Yes, that cleanup I did do.
Quoted 8 lines
An additional cleanup that it directly leads to is rather than finish/init when doing lock-break, when can introduce a reinit call that restarts a batch keeping the existing "settings" (We would still call finish, it's just that the call pair would be finish/reinit). That way, we don't have to "remember" things like fullmm like we have to do currently.
Quoted 5 lines
Since it's no longer per-cpu, things like fullmm or mm are still valid in the batch structure, and so we don't have to carry "fullmm" around like we do in
unmap_vmas(and like we would have to do in other users). In fact, arch implementations can carry around even more state that they might need and keep it around lock breaks that way.
Yes, more good cleanup that fell out naturally.
Quoted 8 lines
That would provide a good ground for then looking into changing the per-cpu list of pages to something else, as Nick told me you were working on.
Any comment, idea, suggestions ? I will give a go at implementing that sometime this week I hope (I have some urgent stuff to do first) unless you guys convince me it's worthless :-)
So ignore my initial distrust, it all seems reasonable. But please remind me, what other than dup_mmap would you be extending this to?
Hugh
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 8 lines
I think there were two issues that stalled me. One, I was mainly trying to remove that horrid
ZAP_BLOCK_SIZEfromunmap_vmas, allowing preemption more naturally; but failed to solve the truncation case, wheni_mmap_lockis held. Two, I needed to understand the different arches better: though it's grand if you're coming aboard, because powerpc (along with the seemingly similar sparc64) was one of the exceptions, deferring the flush to context switch (I need to remind myself why that was an issue).
Actually, that was broken on ppc64. It really needs to flush before we drop the PTE lock or you may end up with duplicate entries in the hash table which is fatal. I fixed it recently by using a completely different mechanism there. I now use the lazy mmu hooks to start/stop batching of invalidations. But that's temporary. One of the thing I want to do with the batches is to add a hook for use by ppc64 to be called before releasing the PTE lock :-) That or I may do things a bit differently to make it safe to defer the flush.
In any case, that's orthogonal to the changes I'm thinking about.
Quoted 4 lines
The other arches, even if not using
asm-generic, seemed pretty much generic: arm a little simpler than generic, ia64 a little more baroque but more similar than it looked. Sounds like Martin may be about to take s390 in its own direction.
arm and sparc64 have a simpler version, which could be moved to asm-generic/tlb-simple.h or so, for arch that either don't care much or use a different batching mechanism (such as sparc64).
Quoted 2 lines
The only arches I actually converted over were i386 and
x86_64(knowing others would keep changing while I worked on the patch).
That's allright. I can take care of the ppc's and maybe sparc64 too.
.../...
Quoted 9 lines
Quoted 8 lines
- Essentially, a simple batch data structure doesn't need to be
per-CPU, it could just be on the stack. However, the current one is per-cpu because of this massive list of struct page's which is too big for a stack allocation.Now the idea is to turn
mmu_gatherinto a small stack based data structure, with an optional pointer to the list of pages which remains, for now, per-cpu.
Quoted 5 lines
What I had was the small stack based data structure, with a small fallback array of struct page pointers built in, and attempts to allocate a full page atomically when this array not big enough - just go slower with the small array when that allocation fails. There may be cleverer approaches, but it seems good enough.
Yes, that's what Nick described. I had in mind an incremental approach, starting with just splitting the batch into the stack based structure and the page list and keeping the per-cpu page list, and then, letting you change that too separately, but we can do it the other way around.
.../...
Quoted 9 lines
The particularly bad thing about get_cpu/put_cpu there, is that the efficiently big array stores up a lot of work for the future (when swapcached pages are freed), which still has to be done with preemption disabled.
Could the
migrate_disablenow proposed help there? At the time I had that same idea, but discarded it because of the complication of different tasks (different mms) needing the same per-cpu buffer; but perhaps that isn't much of a complication in fact.
I haven't looked at that migrate_disable thing yet. Google time :-)
Quoted 2 lines
So ignore my initial distrust, it all seems reasonable. But please remind me, what other than
dup_mmapwould you be extending this to?
Initially, just that and that gremlin in fs/proc/task_mmu.c... (that is users of flush_tlb_mm(), thus removing it as a generic->arch hook).
Though I was thinking of also taking care of flush_tlb_range(), which would then add mprotect to the list, and some hugetlb stuff.
BTW, talking about MMU interfaces.... I've had a quick look yesterday and there's a load of stuff in the various pgtable.h imeplemtations that isn't used at all anymore ! For example, ptep_test_and_clear_dirty() is no longer used by rmap, and there's a whole lot of others like that.
Also, there are some archs whose implementation is identical to asm-generic for some of these.
I was thinking about doing pass through the whole tree getting rid of everything that's not used or duplicate of asm-generic while at it, unless you have reasons not to do that or you know somebody already doing it.
Cheers,
Ben.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 11 lines · Benjamin Herrenschmidt
Quoted 6 lines
What I had was the small stack based data structure, with a small fallback array of struct page pointers built in, and attempts to allocate a full page atomically when this array not big enough - just go slower with the small array when that allocation fails. There may be cleverer approaches, but it seems good enough.
Yes, that's what Nick described. I had in mind an incremental approach, starting with just splitting the batch into the stack based structure and the page list and keeping the per-cpu page list, and then, letting you change that too separately, but we can do it the other way around.
Oh, whatever I send, you just take it forward if it does look useful to you, or forget it if it's just getting in your way, or mixing what you'd prefer to be separate steps, or more trouble to follow someone else's than do your own: no problems.
There is an overlap of cleanup between what I have and what you're intending (e.g. **tlb -> *tlb), but it's hardly beyond your capability to do that without my patch ;)
Quoted 5 lines
BTW, talking about MMU interfaces.... I've had a quick look yesterday and there's a load of stuff in the various
pgtable.himeplemtations that isn't used at all anymore ! For example,ptep_test_and_clear_dirty()is no longer used by rmap, and there's a whole lot of others like that.
Quoted 7 lines
Also, there are some archs whose implementation is identical to asm-generic for some of these.
I was thinking about doing pass through the whole tree getting rid of everything that's not used or duplicate of asm-generic while at it, unless you have reasons not to do that or you know somebody already doing it.
If you wait for next -mm, I think you'll find Martin Schwidefsky has done a little cleanup (including removing ptep_test_and_clear_dirty, which did indeed pose some problem when it had no examples of use); and Jan Beulich some other cleanups already in the last -mm (removing some unused macros like pte_exec). But it sounds like you want to go a lot further.
Hmm, well, if your cross-building environment is good enough that you won't waste any of Andrew's time with the results, I guess go ahead.
Personally, I'm not in favour of removing every last unused macro:
if only from a debugging or learning point of view, it can be useful to see what pte_exec is on each architecture, and it might be needed again tomorrow. But I am very much in favour of reducing the spread of unnecessary difference between architectures, the quantity of evidence you have to wade through when considering them for changes.
Hugh
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 9 lines
If you wait for next -mm, I think you'll find Martin Schwidefsky has done a little cleanup (including removing
ptep_test_and_clear_dirty, which did indeed pose some problem when it had no examples of use); and Jan Beulich some other cleanups already in the last -mm (removing some unused macros likepte_exec). But it sounds like you want to go a lot further.Hmm, well, if your cross-building environment is good enough that you won't waste any of Andrew's time with the results, I guess go ahead.
I have compilers for x86 (&64) and sparc(&64) at hand (in addition to ppc flavors of course), I'm not sure I have anything else but I can always ask our local toolchain guru to setup something up :-)
I suppose I need at least ia64 and possibly mips & arm (though the later seem to be harder to get the right version of the toolchain).
Quoted 6 lines
Personally, I'm not in favour of removing every last unused macro:
if only from a debugging or learning point of view, it can be useful to see whatpte_execis on each architecture, and it might be needed again tomorrow. But I am very much in favour of reducing the spread of unnecessary difference between architectures, the quantity of evidence you have to wade through when considering them for changes.
I don't care about the small macros that just set/test bits like pte_exec. I want to remove the ones that do more than that and are unused (ptep_test_and_clear_dirty() was a good example, there was some semantics subtleties vs. flushing or not flusing, etc...). Those things need to go if they aren't used.
I'll have a look after the next -mm to see what's left. There may be nothing left to cleanup :-)
Ben.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 6 lines · Benjamin Herrenschmidt
I don't care about the small macros that just set/test bits like
pte_exec. I want to remove the ones that do more than that and are unused (ptep_test_and_clear_dirty()was a good example, there was some semantics subtleties vs. flushing or not flusing, etc...). Those things need to go if they aren't used.
Yes, David Rientjes and Zach Amsden and I kept going back and forth over its sister ptep_test_and_clear_young(): it is hard to work out where to place what kind of flush, particularly when it has no users. Martin eliminating ptep_test_and_clear_dirty looked like a good answer.
Quoted 2 lines
I'll have a look after the next -mm to see what's left. There may be nothing left to cleanup :-)
It sounds like I misunderstood how far your cleanup was to reach. Maybe there isn't such a big multi-arch-build deal as I implied.
Here's the 2.6.22 version of what I worked on just after 2.6.16. As I said before, if you find it useful to build upon, do so; but if not, not. From something you said earlier, I've a feeling we'll be fighting over where to place the TLB flushes, inside or outside the page table lock.
A few notes:
Keep in mind: hard to have low preemption latency with decent throughput in zap_pte_range - easier than it once was now the ptl is taken lower down, but big problem when truncation/invalidation holds i_mmap_lock to scan the vma prio_tree - drop that lock and it has to restart. Not satisfactorily solved yet (sometimes I think we should collapse the prio_tree into a list for the duration of the unmapping: no problem putting a marker in the list).
The mmu_gather of pages to be freed after TLB flush represents a signficant quantity of deferred work, particularly when those pages are in swapcache:
we do want preemption enabled while freeing them, but we don't want to lose our place in the prio_tree very often.
Don't be misled by inclusion of patches to ia64 and powerpc hugetlbpage.c, that's just to replace **tlb by *tlb in one function: the real mmu_gather conversion is yet to be done there.
Only i386 and x86_64 have been converted, built and (inadequately) tested so
far: but most arches shouldn't need more than removing their DEFINE_PER_CPU, with arm and arm26 probably just wanting to use more of the generic code.
sparc64 uses a flush_tlb_pending technique which defers a lot of work until context switch, when it cannot be preempted: I've given little thought to it. powerpc appeared similar to sparc64, but you've changed it since 2.6.16.
I've removed the start,end args to tlb_finish_mmu, and several levels above
it: the tlb_start_valid business in unmap_vmas always seemed ugly to me, only ia64 has made use of them, and I cannot see why it shouldn't just record first and last addr when its tlb_remove_tlb_entry is called. But since ia64 isn't done yet, that end of it isn't seen in the patch.
Hugh
--- arch/i386/mm/init.c | 1 arch/ia64/mm/hugetlbpage.c | 2 arch/powerpc/mm/hugetlbpage.c | 8 - arch/x86_64/mm/init.c | 2 include/asm-generic/pgtable.h | 12 -- include/asm-generic/tlb.h | 109 +++++++++++---------- include/asm-x86_64/tlbflush.h | 4 include/linux/hugetlb.h | 2 include/linux/mm.h | 11 -- include/linux/swap.h | 5 - mm/fremap.c | 2 mm/memory.c | 209 ++++++++++++++++-------------------------- mm/mmap.c | 34 ++---- mm/swap_state.c | 12 -- 14 files changed, 163 insertions(+), 250 deletions(-)
arch/i386/mm/init.c +0 -1
@@ -47,7 +47,6 @@unsigned int __VMALLOC_RESERVE =128 <<20 ; -DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);unsigned long highstart_pfn, highend_pfn; static int noinline do_test_wp_bit(void);
arch/ia64/mm/hugetlbpage.c +1 -1
@@ -114,7 +114,7 @@ follow_huge_pmd(struct mm_struct *mm, unreturn NULL ; } -void hugetlb_free_pgd_range (struct mmu_gather **tlb, +void hugetlb_free_pgd_range (struct mmu_gather *tlb,unsigned long addr,unsigned long end,unsigned long floor,unsigned long ceiling) {
arch/powerpc/mm/hugetlbpage.c +4 -4
@@ -240,7 +240,7 @@ static void hugetlb_free_pud_range(struc* * Must be called with pagetable lock held. */ -void hugetlb_free_pgd_range (struct mmu_gather **tlb, +void hugetlb_free_pgd_range (struct mmu_gather *tlb,unsigned long addr,unsigned long end,unsigned long floor,unsigned long ceiling) {
@@ -300,13 +300,13 @@ void hugetlb_free_pgd_range(struct mmu_greturn ; start = addr; - pgd =pgd_offset ((*tlb)->mm, addr); + pgd =pgd_offset (tlb->mm, addr);do { -BUG_ON (get_slice_psize ((*tlb)->mm, addr) != mmu_huge_psize); +BUG_ON (get_slice_psize (tlb->mm, addr) != mmu_huge_psize); next =pgd_addr_end (addr, end);if (pgd_none_or_clear_bad (pgd))continue ; -hugetlb_free_pud_range (*tlb, pgd, addr, next, floor, ceiling); +hugetlb_free_pud_range (tlb, pgd, addr, next, floor, ceiling); }while (pgd++, addr = next, addr != end); }
arch/x86_64/mm/init.c +0 -2
@@ -53,8 +53,6 @@ EXPORT_SYMBOL(dma_ops);static unsigned long dma_reserve__initdata ; -DEFINE_PER_CPU(struct mmu_gather, mmu_gathers); -/* * NOTE: pagetable_init alloc all the fixmap pagetables contiguous on the * physical space so we can cache the place of the first one and move
include/asm-generic/pgtable.h +0 -12
@@ -111,18 +111,6 @@ do { \ })#endif -/* -* Some architectures may be able to avoid expensive synchronization -* primitives when modifications are made to PTE's which are already -* 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) -#endif -#ifndef __HAVE_ARCH_PTEP_CLEAR_FLUSH#define ptep_clear_flush (__vma, __address, __ptep) \ ({ \
include/asm-generic/tlb.h +57 -52
150 lines not on this page · raw message
include/asm-x86_64/tlbflush.h +0 -4
@@ -86,10 +86,6 @@ static inline void flush_tlb_range(struc#define TLBSTATE_OK 1#define TLBSTATE_LAZY 2 -/* Roughly an IPI every 20MB with 4k pages for freeing page table -ranges. Cost is about 42k of memory for each CPU. */ -#define ARCH_FREE_PTE_NR 5350 -#endif #define flush_tlb_kernel_range (start, end) flush_tlb_all()
include/linux/hugetlb.h +1 -1
@@ -52,7 +52,7 @@ void hugetlb_change_protection(struct vm#ifndef ARCH_HAS_HUGETLB_FREE_PGD_RANGE #define hugetlb_free_pgd_range free_pgd_range#else -void hugetlb_free_pgd_range (struct mmu_gather **tlb,unsigned long addr, +void hugetlb_free_pgd_range (struct mmu_gather *tlb,unsigned long addr,unsigned long end,unsigned long floor,unsigned long ceiling);#endif
include/linux/mm.h +4 -7
@@ -738,15 +738,12 @@ struct zap_details { };struct page *vm_normal_page (struct vm_area_struct *,unsigned long ,pte_t ); -unsigned long zap_page_range (struct vm_area_struct *vma,unsigned long address, +void zap_page_range (struct vm_area_struct *vma,unsigned long address,unsigned long size,struct zap_details *); -unsigned long unmap_vmas (struct mmu_gather **tlb, -struct vm_area_struct *start_vma,unsigned long start_addr, -unsigned long end_addr,unsigned long *nr_accounted, -struct zap_details *); -void free_pgd_range (struct mmu_gather **tlb,unsigned long addr, +void unmap_vmas (struct mmu_gather *tlb,struct vm_area_struct *start_vma); +void free_pgd_range (struct mmu_gather *tlb,unsigned long addr,unsigned long end,unsigned long floor,unsigned long ceiling); -void free_pgtables (struct mmu_gather **tlb,struct vm_area_struct *start_vma, +void free_pgtables (struct mmu_gather *tlb,struct vm_area_struct *start_vma,unsigned long floor,unsigned long ceiling);int copy_page_range (struct mm_struct *dst,struct mm_struct *src,struct vm_area_struct *vma);
include/linux/swap.h +1 -4
@@ -232,7 +232,6 @@ extern void delete_from_swap_cache(strucextern int move_to_swap_cache (struct page *,swp_entry_t );extern int move_from_swap_cache (struct page *,unsigned long ,struct address_space *); -extern void free_page_and_swap_cache (struct page *);extern void free_pages_and_swap_cache (struct page **,int );extern struct page *lookup_swap_cache (swp_entry_t ); extern struct page * read_swap_cache_async(swp_entry_t, struct vm_area_struct *vma,
@@ -287,9 +286,7 @@ static inline void disable_swap_token(vo#define si_swapinfo (val) \ do { (val)->freeswap = (val)->totalswap = 0; } while (0)/* only sparc can not include linux/pagemap.h in this file -* so leave page_cache_release and release_pages undeclared... */ -#define free_page_and_swap_cache (page) \ - page_cache_release(page) +* so leave release_pages undeclared... */ #define free_pages_and_swap_cache (pages, nr) \ release_pages((pages), (nr), 0);
mm/fremap.c +1 -1
@@ -39,7 +39,7 @@ static int zap_pte(struct mm_struct *mm, }else {if (!pte_file (pte))free_swap_and_cache (pte_to_swp_entry (pte)); -pte_clear_not_present_full (mm, addr, ptep,0 ); +pte_clear (mm, addr, ptep); }return !!page; }
mm/memory.c +80 -129
355 lines not on this page · raw message
mm/mmap.c +12 -22
@@ -36,8 +36,7 @@#endif static void unmap_region (struct mm_struct *mm, -struct vm_area_struct *vma,struct vm_area_struct *prev, -unsigned long start,unsigned long end); +struct vm_area_struct *vma,struct vm_area_struct *prev);/* * WARNING: the debugging will use recursive algorithms so never enable this
@@ -1165,7 +1164,7 @@ unmap_and_free_vma:fput (file);/* Undo any partial mapping done by a device driver. */ -unmap_region (mm, vma, prev, vma->vm_start, vma->vm_end); +unmap_region (mm, vma, prev); charged =0 ; free_vma:kmem_cache_free (vm_area_cachep, vma);
@@ -1677,21 +1676,17 @@ static void remove_vma_list(struct mm_st* Called with the mm semaphore held. */ static void unmap_region (struct mm_struct *mm, -struct vm_area_struct *vma,struct vm_area_struct *prev, -unsigned long start,unsigned long end) +struct vm_area_struct *vma,struct vm_area_struct *prev) {struct vm_area_struct *next = prev? prev->vm_next: mm->mmap; -struct mmu_gather *tlb; -unsigned long nr_accounted =0 ; +struct mmu_gather tlb; -lru_add_drain (); - tlb =tlb_gather_mmu (mm,0 ); +tlb_gather_mmu (&tlb, mm,TLB_UNMAP );update_hiwater_rss (mm); -unmap_vmas (&tlb, vma, start, end, &nr_accounted,NULL ); -vm_unacct_memory (nr_accounted); +unmap_vmas (&tlb, vma);free_pgtables (&tlb, vma, prev? prev->vm_end:FIRST_USER_ADDRESS , next? next->vm_start:0 ); -tlb_finish_mmu (tlb, start, end); +tlb_finish_mmu (&tlb); }/*
@@ -1829,7 +1824,7 @@ int do_munmap(struct mm_struct *mm, unsi* Remove the vma's, and unmap the actual pages */ detach_vmas_to_be_unmapped (mm, vma, prev, end); -unmap_region (mm, vma, prev, start, end); +unmap_region (mm, vma, prev);/* Fix up all other VM information */ remove_vma_list (mm, vma);
@@ -1968,23 +1963,18 @@ EXPORT_SYMBOL(do_brk);/* Release all mmaps. */ void exit_mmap (struct mm_struct *mm) { -struct mmu_gather *tlb; +struct mmu_gather tlb;struct vm_area_struct *vma = mm->mmap; -unsigned long nr_accounted =0 ; -unsigned long end;/* mm's last user has gone, and its about to be pulled down */ arch_exit_mmap (mm); -lru_add_drain ();flush_cache_mm (mm); - tlb =tlb_gather_mmu (mm,1 ); +tlb_gather_mmu (&tlb, mm,TLB_EXIT );/* Don't update_hiwater_rss(mm) here, do_exit already did */ -/* Use -1 here to ensure all VMAs in the mm are unmapped */ - end =unmap_vmas (&tlb, vma,0 ,-1 , &nr_accounted,NULL ); -vm_unacct_memory (nr_accounted); +unmap_vmas (&tlb, vma);free_pgtables (&tlb, vma,FIRST_USER_ADDRESS ,0 ); -tlb_finish_mmu (tlb,0 , end); +tlb_finish_mmu (&tlb);/* * Walk the list again, actually closing and freeing it,
mm/swap_state.c +2 -10
@@ -258,16 +258,6 @@ static inline void free_swap_cache(struc } } -/* -* Perform a free_page(), also freeing any swap cache associated with -* this page if it is the last user of the page. -*/ -void free_page_and_swap_cache (struct page *page) -{ -free_swap_cache (page); -page_cache_release (page); -} -/* * Passed an array of pages, drop them all from swapcache and then release * them. They are removed from the LRU and freed if this is their last use.
@@ -286,6 +276,8 @@ void free_pages_and_swap_cache(struct parelease_pages (pagep, todo,0 ); pagep += todo; nr -= todo; +if (nr && !preempt_count ()) +cond_resched (); } }
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 5 lines
Here's the 2.6.22 version of what I worked on just after 2.6.16. As I said before, if you find it useful to build upon, do so; but if not, not. From something you said earlier, I've a feeling we'll be fighting over where to place the TLB flushes, inside or outside the page table lock.
ppc64 needs inside, but I don't want to change the behaviour for others, so I'll probably do a pair of tlb_after_pte_lock and tlb_before_pte_unlock that do nothing by default and that ppc64 can use to do the flush before unlocking.
It seems like virtualization stuff needs that too, thus we could replace a whole lot of the lazy_mmu stuff in there with those 2 hooks, making things a little bit less confusing.
Quoted 8 lines
A few notes:
Keep in mind: hard to have low preemption latency with decent throughput in
zap_pte_range- easier than it once was now the ptl is taken lower down, but big problem when truncation/invalidation holdsi_mmap_lockto scan the vmaprio_tree- drop that lock and it has to restart. Not satisfactorily solved yet (sometimes I think we should collapse theprio_treeinto a list for the duration of the unmapping: no problem putting a marker in the list).
I don't intend to change he behaviour at this stage, only the interfaces, though I expect the new interfaces to make it easier to toy around with the behaviour.
Quoted 4 lines
The
mmu_gatherof pages to be freed after TLB flush represents a signficant quantity of deferred work, particularly when those pages are in swapcache:
we do want preemption enabled while freeing them, but we don't want to lose our place in theprio_treevery often.
Same comment as above :-) I understand the problem but I don't see any magical way of making things better here, so I'll concentrate on cleaning up the interfaces while keeping the exact same behaviour and then I can have a second look see if I come up with some idea on how to make things better.
Quoted 3 lines
Don't be misled by inclusion of patches to ia64 and powerpc
hugetlbpage.c, that's just to replace **tlb by *tlb in one function: the realmmu_gatherconversion is yet to be done there.
Ok.
Quoted 7 lines
Only i386 and
x86_64have been converted, built and (inadequately) tested so
far: but most arches shouldn't need more than removing theirDEFINE_PER_CPU, with arm and arm26 probably just wanting to use more of the generic code.sparc64 uses a
flush_tlb_pendingtechnique which defers a lot of work until context switch, when it cannot be preempted: I've given little thought to it. powerpc appeared similar to sparc64, but you've changed it since 2.6.16.
powerpc64 used to do that, but I had that massive bug because it needs to flush before the page table lock is released (or we might end up with duplicates in the hash table, which is fatal).
Quoted 5 lines
I've removed the start,end args to
tlb_finish_mmu, and several levels above
it: thetlb_start_validbusiness inunmap_vmasalways seemed ugly to me, only ia64 has made use of them, and I cannot see why it shouldn't just record first and last addr when itstlb_remove_tlb_entryis called. But since ia64 isn't done yet, that end of it isn't seen in the patch.
Agreed. I'd rather have archs that care explicitely record start/end.
One thing I'm also thinking about doing is slighlty changing the way the "generic" gather interface is defined. Currently, you have some things you can define in the arch (such as tlb_start/end_vma), some things that are totally defined for you, such as the struct mmu_gather itself, etc... thus some archs have to replace the whole things, some can hook half way through, but in general, I find it confusing.
I think we could do better by having the mmu_gather contain an mmu_gather_arch field (arch defined, for additional fields in there) and use for -all- the mmu_gather functions something like
#ifndef tlb_start_vma
static inline void tlb_start_vma(...)
{
..../...
}#endif
Thus archs that need their own version would just do:
static inline void tlb_start_vma(...)
{
..../...
}#define tlb_start_vma tlb_start_vma
Not sure about that yet, waiting for people to flame me with "that's horrible" :-)
Ben.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 11 lines · Benjamin Herrenschmidt
Quoted 6 lines
Here's the 2.6.22 version of what I worked on just after 2.6.16. As I said before, if you find it useful to build upon, do so; but if not, not. From something you said earlier, I've a feeling we'll be fighting over where to place the TLB flushes, inside or outside the page table lock.
ppc64 needs inside, but I don't want to change the behaviour for others, so I'll probably do a pair of
tlb_after_pte_lockandtlb_before_pte_unlockthat do nothing by default and that ppc64 can use to do the flush before unlocking.
Yeah, something like that, I suppose (better naming!). And I think your ppc64 implementation will do best just to flush TLB in _before, leaving the page freeing to the _after; whereas most will do them both in the _after.
Quoted 4 lines
It seems like virtualization stuff needs that too, thus we could replace a whole lot of the
lazy_mmustuff in there with those 2 hooks, making things a little bit less confusing.
That would be good, I didn't look into those lazy_mmu things at all:
we're in perfect agreement that the fewer such the better.
Quoted 10 lines
Quoted 9 lines
A few notes:
Keep in mind: hard to have low preemption latency with decent throughput in
zap_pte_range- easier than it once was now the ptl is taken lower down, but big problem when truncation/invalidation holdsi_mmap_lockto scan the vmaprio_tree- drop that lock and it has to restart. Not satisfactorily solved yet (sometimes I think we should collapse theprio_treeinto a list for the duration of the unmapping: no problem putting a marker in the list).
Quoted 3 lines
I don't intend to change he behaviour at this stage, only the interfaces, though I expect the new interfaces to make it easier to toy around with the behaviour.
Right, that may lead you to set aside a lot of what I did for now.
..../... (if I may echo you ;)
Quoted 13 lines
I think we could do better by having the
mmu_gathercontain anmmu_gather_archfield (arch defined, for additional fields in there) and use for -all- themmu_gatherfunctions something like#ifndef
tlb_start_vma
static inline voidtlb_start_vma(...){ ..../... }#endif
Thus archs that need their own version would just do:
Quoted 8 lines
static inline void
tlb_start_vma(...){ ..../... }#define
tlb_start_vmatlb_start_vmaNot sure about that yet, waiting for people to flame me with "that's horrible" :-)
No, sounds good to me, no flame from this direction:
it's exactly what Linus prefers to the __HAVE_ARCH... stuff.
Hugh
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>