: Adding a counter in vma to indicate the number of physical pages backing it
Subsystems (10)
PATCH 1/1 : Adding a counter in vma to indicate the number of physical pages backing it
Below is a patch that adds number of physical pages that each vma is using in a process. Exporting this information to user space using /proc/<pid>/maps interface.
There is currently /proc/<pid>/smaps that prints the detailed information about the usage of physical pages but that is a very expensive operation as it traverses all the PTs (for some one who is just interested in getting that data for each vma).
fs/exec.c | 1 + fs/proc/task_mmu.c | 4 ++-- include/linux/mm.h | 1 + mm/fremap.c | 2 ++ mm/hugetlb.c | 3 +++ mm/memory.c | 5 +++++ mm/migrate.c | 1 + mm/rmap.c | 2 ++ mm/swapfile.c | 1 + 9 files changed, 18 insertions(+), 2 deletions(-)
fs/exec.c +1 -0
@@ -326,6 +326,7 @@set_pte_at (mm, address, pte,pte_mkdirty (pte_mkwrite (mk_pte ( page, vma->vm_page_prot))));page_add_new_anon_rmap (page, vma, address); + vma->nphys++;pte_unmap_unlock (pte, ptl);/* no need for flush_tlb */
fs/proc/task_mmu.c +2 -2
@@ -145,14 +145,14 @@ ino = inode->i_ino; } -seq_printf (m,"%08lx-%08lx %c%c%c%c %08lx %02x:%02x %lu %n" , +seq_printf (m,"%08lx-%08lx %c%c%c%c %08lx %08lu %02x:%02x %lu %n" , vma->vm_start, vma->vm_end, flags &VM_READ ?'r' :'-' , flags &VM_WRITE ?'w' :'-' , flags &VM_EXEC ?'x' :'-' , flags &VM_MAYSHARE ?'s' :'p' , - vma->vm_pgoff <<PAGE_SHIFT , + vma->vm_pgoff <<PAGE_SHIFT , vma->nphys,MAJOR (dev),MINOR (dev), ino, &len);/*
include/linux/mm.h +1 -0
@@ -111,6 +111,7 @@#ifdef CONFIG_NUMA struct mempolicy *vm_policy;/* NUMA policy for the VMA */ #endif +unsigned long nphys;/* Num phys pages backing this vma */ };/*
mm/migrate.c +1 -0
@@ -181,6 +181,7 @@/* No need to invalidate - it was non-present before */ update_mmu_cache (vma, addr, pte);lazy_mmu_prot_update (pte); + vma->nphys++; out:pte_unmap_unlock (ptep, ptl);
mm/swapfile.c +1 -0
@@ -500,6 +500,7 @@* immediately swapped out again after swapon. */ activate_page (page); + vma->nphys++; } static int unuse_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
mm/rmap.c +2 -0
@@ -620,6 +620,7 @@dec_mm_counter (mm, file_rss); + vma->nphys--;page_remove_rmap (page);page_cache_release (page);
@@ -710,6 +711,7 @@if (pte_dirty (pteval))set_page_dirty (page); + vma->nphys--;page_remove_rmap (page);page_cache_release (page);dec_mm_counter (mm, file_rss);
mm/memory.c +5 -0
@@ -677,6 +677,7 @@mark_page_accessed (page); file_rss--; } + vma->nphys--;page_remove_rmap (page);tlb_remove_page (tlb, page);continue ;
@@ -2001,6 +2002,7 @@/* No need to invalidate - it was non-present before */ update_mmu_cache (vma, address, pte);lazy_mmu_prot_update (pte); + vma->nphys++; unlock:pte_unmap_unlock (page_table, ptl); out:
@@ -2063,6 +2065,7 @@/* No need to invalidate - it was non-present before */ update_mmu_cache (vma, address, entry);lazy_mmu_prot_update (entry); + vma->nphys++; unlock:pte_unmap_unlock (page_table, ptl);return VM_FAULT_MINOR ;
@@ -2201,6 +2204,7 @@/* no need to invalidate: a not-present page shouldn't be cached */ update_mmu_cache (vma, address, entry);lazy_mmu_prot_update (entry); + vma->nphys++; unlock:pte_unmap_unlock (page_table, ptl);return ret;
@@ -2480,6 +2484,7 @@ gate_vma.vm_end =FIXADDR_USER_END ; gate_vma.vm_page_prot =PAGE_READONLY ; gate_vma.vm_flags =0 ; + gate_vma.nphys =1 ;return 0 ; }__initcall (gate_vma_init);
mm/fremap.c +2 -0
@@ -35,6 +35,7 @@set_page_dirty (page);page_remove_rmap (page);page_cache_release (page); + vma->nphys--; } }else {if (!pte_file (pte))
@@ -84,6 +85,7 @@ pte_val = *pte;update_mmu_cache (vma, addr, pte_val);lazy_mmu_prot_update (pte_val); + vma->nphys++; err =0 ; unlock:pte_unmap_unlock (pte, ptl);
mm/hugetlb.c +3 -0
@@ -346,6 +346,7 @@get_page (ptepage);add_mm_counter (dst, file_rss,HPAGE_SIZE /PAGE_SIZE );set_huge_pte_at (dst, addr, dst_pte, entry); + vma->nphys += (HPAGE_SIZE /PAGE_SIZE ); }spin_unlock (&src->page_table_lock);spin_unlock (&dst->page_table_lock);
@@ -386,6 +387,7 @@ page =pte_page (pte);put_page (page);add_mm_counter (mm, file_rss, (int ) -(HPAGE_SIZE /PAGE_SIZE )); + vma->nphys -= (HPAGE_SIZE /PAGE_SIZE ); }spin_unlock (&mm->page_table_lock);
@@ -493,6 +495,7 @@ && (vma->vm_flags & VM_SHARED)));set_huge_pte_at (mm, address, ptep, new_pte); + vma->nphys += (HPAGE_SIZE /PAGE_SIZE );if (write_access && !(vma->vm_flags &VM_SHARED )) {/* Optimization, do the COW without a second fault */ ret =hugetlb_cow (mm, vma, address, ptep, new_pte);
--
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 3 lines · On Fri, 09 Jun 2006 18:33:55 -0700 Rohit Seth <[email protected]> wrote:
Below is a patch that adds number of physical pages that each vma is using in a process. Exporting this information to user space using /proc/<pid>/maps interface.
Ouch, that's an awful lot of open-coded incs and decs. Isn't there some more centralised place we can do this?
What locking protects vma.nphys (can we call this nr_present or something?)
Will this patch do the right thing with weird vmas such as the gate vma and mmaps of device memory, etc?
--
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 10 lines · Andrew Morton
Quoted 3 lines · On Fri, 09 Jun 2006 18:33:55 -0700 Rohit Seth <[email protected]> wrote:
Below is a patch that adds number of physical pages that each vma is using in a process. Exporting this information to user space using /proc/<pid>/maps interface.
Ouch, that's an awful lot of open-coded incs and decs. Isn't there some more centralised place we can do this?
I'll look into this. Possibly combining it with mm counters.
Quoted 2 lines
What locking protects vma.nphys (can we call this
nr_presentor something?)
I'll need to use the same atomic counters as mm. And Yes nr_present is
a better name.
Quoted 3 lines
Will this patch do the right thing with weird vmas such as the gate vma and mmaps of device memory, etc?
I think so. (though strictly speaking those special vmas are less interesting). But final solution (if we do decide to implement this counter) will address that.
-rohit
--
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 · Rohit Seth
Below is a patch that adds number of physical pages that each vma is using in a process. Exporting this information to user space using /proc/<pid>/maps interface.
There is currently /proc/<pid>/smaps that prints the detailed information about the usage of physical pages but that is a very expensive operation as it traverses all the PTs (for some one who is just interested in getting that data for each vma).
Yet more cacheline footprint in the page fault and unmap paths...
What is this used for and why do we want it? Could you do some smaps-like interface that can work on ranges of memory, and continue to walk pagetables instead?
Signature · 8 lines
SUSE Labs, Novell Inc. Send instant messages to your online friends http://au.messenger.yahoo.com -- 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
Quoted 4 lines
There is currently /proc/<pid>/smaps that prints the detailed information about the usage of physical pages but that is a very expensive operation as it traverses all the PTs (for some one who is just interested in getting that data for each vma).
Yet more cacheline footprint in the page fault and unmap paths...
What is this used for and why do we want it? Could you do some smaps-like interface that can work on ranges of memory, and continue to walk pagetables instead?
BTW, what is smaps used for (who uses it), anyway?
Jan Engelhardt
Signature · 5 lines
-- 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 · Nick Piggin
Quoted 4 lines · Rohit Seth
Below is a patch that adds number of physical pages that each vma is using in a process. Exporting this information to user space using /proc/<pid>/maps interface.
Quoted 7 lines
Quoted 4 lines
There is currently /proc/<pid>/smaps that prints the detailed information about the usage of physical pages but that is a very expensive operation as it traverses all the PTs (for some one who is just interested in getting that data for each vma).
Yet more cacheline footprint in the page fault and unmap paths...
Not necessarily. If I'm doing calculation right then vm_struct is currently 176 bytes (without the addition of nphys) on my x86_64 box. So in this case addition would not result in bigger cache foot print of page fulats. Also currently two adjacent vmas share a cache line. So there is already that much of cache line ping pong going on.
Though I agree that we should try to not extend this size beyond absolutely necessary.
Quoted 4 lines
What is this used for and why do we want it? Could you do some smaps-like interface that can work on ranges of memory, and continue to walk pagetables instead?
It is just the price of those walks that makes smaps not an attractive solution for monitoring purposes.
I'm thinking if it is possible to extend current interfaces (possibly having a new system call) in such a way that a user land process can give some hints/preferences to kernel in terms of <pid, virtual_range> to remove/inactivate. This can help in keeping the current kernel behavior for vmscans but at the same time provide little bit of non-symmetry for user land applications. Thoughts?
-rohit
--
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 2 lines
It is just the price of those walks that makes smaps not an attractive solution for monitoring purposes.
It just shouldn't be used for that. It's a debugging hack and not really suitable for monitoring even with optimizations.
For monitoring if the current numa statistics are not good enough you should probably propose new counters.
-Andi
--
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 · Andi Kleen
Quoted 2 lines
It is just the price of those walks that makes smaps not an attractive solution for monitoring purposes.
It just shouldn't be used for that. It's a debugging hack and not really suitable for monitoring even with optimizations.
For monitoring if the current numa statistics are not good enough you should probably propose new counters.
numa stats are giving different data. The proposed vma->nr_phys is the new counter that can provide a detailed information about physical mem usage at each virtual mem segment level. I think having this information in each vma keeps the impact (of adding new counter) to very low.
Second question is to advertize this value to user space. Please let me know what suites the most among /proc, /sys or system call (or if there is any other mechanism then let me know) for a per process per segment related information.
-rohit
--
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 7 lines · Rohit Seth
Quoted 6 lines · Andi Kleen
Quoted 2 lines
It is just the price of those walks that makes smaps not an attractive solution for monitoring purposes.
It just shouldn't be used for that. It's a debugging hack and not really suitable for monitoring even with optimizations.
Quoted 7 lines
Quoted 2 lines
For monitoring if the current numa statistics are not good enough you should probably propose new counters.
numa stats are giving different data. The proposed
vma->nr_physis the new counter that can provide a detailed information about physical mem usage at each virtual mem segment level.
And for what do you need that?
It's somewhat useful to debug the NUMA tuning of your app (although there are other ways to do that too) but do you
really need it for normal runtime monitoring?
Quoted 8 lines
I think having this
information in each vma keeps the impact (of adding new counter) to very low.Second question is to advertize this value to user space. Please let me know what suites the most among /proc, /sys or system call (or if there is any other mechanism then let me know) for a per process per segment related information.
I think we first need to identify the basic need. Don't see why we even need per VMA information so far.
-Andi
--
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 · Andi Kleen
Quoted 3 lines · Rohit Seth
I think having this information in each vma keeps the impact (of adding new counter) to very low.
Quoted 9 lines
Quoted 5 lines
Second question is to advertize this value to user space. Please let me know what suites the most among /proc, /sys or system call (or if there is any other mechanism then let me know) for a per process per segment related information.
I think we first need to identify the basic need. Don't see why we even need per VMA information so far.
Exactly. There is no question that walking page tables will be slower than having a counter like your patch does; the question is why we need it.
--
Send instant messages to your online friends http://au.messenger.yahoo.com
--
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 · Andi Kleen
Quoted 3 lines · Rohit Seth
I think having this information in each vma keeps the impact (of adding new counter) to very low.
Quoted 7 lines
Quoted 4 lines
Second question is to advertize this value to user space. Please let me know what suites the most among /proc, /sys or system call (or if there is any other mechanism then let me know) for a per process per segment related information.
I think we first need to identify the basic need. Don't see why we even need per VMA information so far.
This information is for user land applications to have the knowledge of which virtual ranges are getting actively used and which are not. This information then can be fed into a new system call sys_change_page_activation(pid, start_va, len, flag). The purpose of this system call would be to give hints to kernel that certain physical pages are okay to be inactivated (or vice versa).
-rohit
--
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 · Rohit Seth
Quoted 3 lines · Andi Kleen
I think we first need to identify the basic need. Don't see why we even need per VMA information so far.
This information is for user land applications to have the knowledge of which virtual ranges are getting actively used and which are not. This information then can be fed into a new system call
sys_change_page_activation(pid, start_va, len, flag). The purpose of this system call would be to give hints to kernel that certain physical pages are okay to be inactivated (or vice versa).
Then perhaps you want a sys_report_page_activation(pid, start_va, len, ...) which would examine and report on the range in question, instead of adding your count to so many vmas on which this will never be used.
Though your syscall sounds like pid_madvise: perhaps the call name should be less specific and left to the flags (come, gentle syscall multiplexing flames, and warm me).
Looking through the existing fields of a vma, it seems a vm_area_struct would commonly be on clean cachelines: your count making one of them now commonly and bouncily dirty.
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 13 lines · Hugh Dickins
Quoted 11 lines · Rohit Seth
Quoted 3 lines · Andi Kleen
I think we first need to identify the basic need. Don't see why we even need per VMA information so far.
This information is for user land applications to have the knowledge of which virtual ranges are getting actively used and which are not. This information then can be fed into a new system call
sys_change_page_activation(pid, start_va, len, flag). The purpose of this system call would be to give hints to kernel that certain physical pages are okay to be inactivated (or vice versa).
Quoted 4 lines
Then perhaps you want a
sys_report_page_activation(pid, start_va, len, ...)which would examine and report on the range in question, instead of adding your count to so many vmas on which this will never be used.
That will reduce the cost of not traversing the whole process address space. But still for a given length, we will need to traverse the PTs. On a positive side, this interface can give more specific information to user in terms of page attributes. I'm fine with this interface if others are okay. Andi?
Quoted 4 lines
Though your syscall sounds like
pid_madvise: perhaps the call name should be less specific and left to the flags (come, gentle syscall multiplexing flames, and warm me).
Agreed.
Quoted 3 lines
Looking through the existing fields of a vma, it seems a
vm_area_structwould commonly be on clean cachelines: your count making one of them now commonly and bouncily dirty.
The additional cost of this counter will be long size of extra memory per segment, an atomic operation when ptl is used and dirtying an additional cache line. I overlooked the last two cost factors earlier.
-rohit
--
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 3 lines
This information is for user land applications to have the knowledge of which virtual ranges are getting actively used and which are not.
If you think the kernel needs better information on that wouldn't it be better to use the page accessed bits of the hardware more aggressively?
Before giving up and adding hacks like you're proposing it would be better to explore fully automatic mechanisms fully.
-Andi
--
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 3 lines · Rohit Seth
Below is a patch that adds number of physical pages that each vma is using in a process. Exporting this information to user space using /proc/<pid>/maps interface.
is it really worth bloating the vma struct for this? there are quite a few workloads that have a gazilion vma's, and this patch adds both memory usage and cache pressure to those workloads...
--
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 · Arjan van de Ven
Quoted 3 lines · Rohit Seth
Below is a patch that adds number of physical pages that each vma is using in a process. Exporting this information to user space using /proc/<pid>/maps interface.
is it really worth bloating the vma struct for this? there are quite a few workloads that have a gazilion vma's, and this patch adds both memory usage and cache pressure to those workloads...
I agree it's a bad idea. smaps is only a debugging kludge anyways and it's not a good idea to we bloat core data structures for it.
-Andi
--
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 4 lines
I agree it's a bad idea. smaps is only a debugging kludge anyways and it's not a good idea to we bloat core data structures for it.
Is there a way to disable it (smaps), then?
Jan Engelhardt
Signature · 5 lines
-- 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 · Jan Engelhardt
Quoted 4 lines
I agree it's a bad idea. smaps is only a debugging kludge anyways and it's not a good idea to we bloat core data structures for it.
Is there a way to disable it (smaps), then?
Just don't use it?
Not set CONFIG_NUMA?
-Andi
--
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 4 lines · Rohit Seth
There is currently /proc/<pid>/smaps that prints the detailed information about the usage of physical pages but that is a very expensive operation as it traverses all the PTs (for some one who is just interested in getting that data for each vma).
Adding a new counter to a vma may cause a bouncing cacheline etc. I would think that such a counter is far more expensive than occasional scans through the page table because someone is curious about the number of page in use. /proc/<pid>/numa_maps also uses these scans to determine dirty pages etc.
--
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>