* [patch 1/3] [PATCH] mm: migration -- Do not loose soft dirty bit if page is in migration state
2013-10-08 9:00 [patch 0/3] Soft dirty tracking fixes Cyrill Gorcunov
@ 2013-10-08 9:00 ` Cyrill Gorcunov
2013-10-08 14:11 ` Naoya Horiguchi
2013-10-08 9:00 ` [patch 2/3] [PATCH] mm: pagemap -- Inspect _PAGE_SOFT_DIRTY only on present pages Cyrill Gorcunov
` (2 subsequent siblings)
3 siblings, 1 reply; 11+ messages in thread
From: Cyrill Gorcunov @ 2013-10-08 9:00 UTC (permalink / raw)
To: akpm
Cc: linux-mm, linux-kernel, Cyrill Gorcunov, Pavel Emelyanov,
Andy Lutomirski, Matt Mackall, Xiao Guangrong, Marcelo Tosatti,
KOSAKI Motohiro, Stephen Rothwell, Peter Zijlstra,
Aneesh Kumar K.V
[-- Attachment #1: pte-sft-dirty-migration-fix --]
[-- Type: text/plain, Size: 2803 bytes --]
If page migration is turne on in the config and the page is migrating,
we may loose soft dirty bit. If fork and mprotect if called on migrating
pages (once migration is complete) pages do not obtain soft dirty bit
in correspond pte entries. Fix it adding appropriate test on swap
entries.
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Cc: Pavel Emelyanov <xemul@parallels.com>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Matt Mackall <mpm@selenic.com>
Cc: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@gmail.com>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
---
mm/memory.c | 2 ++
mm/migrate.c | 2 ++
mm/mprotect.c | 7 +++++--
3 files changed, 9 insertions(+), 2 deletions(-)
Index: linux-2.6.git/mm/memory.c
===================================================================
--- linux-2.6.git.orig/mm/memory.c
+++ linux-2.6.git/mm/memory.c
@@ -837,6 +837,8 @@ copy_one_pte(struct mm_struct *dst_mm, s
*/
make_migration_entry_read(&entry);
pte = swp_entry_to_pte(entry);
+ if (pte_swp_soft_dirty(*src_pte))
+ pte = pte_swp_mksoft_dirty(pte);
set_pte_at(src_mm, addr, src_pte, pte);
}
}
Index: linux-2.6.git/mm/migrate.c
===================================================================
--- linux-2.6.git.orig/mm/migrate.c
+++ linux-2.6.git/mm/migrate.c
@@ -161,6 +161,8 @@ static int remove_migration_pte(struct p
get_page(new);
pte = pte_mkold(mk_pte(new, vma->vm_page_prot));
+ if (pte_swp_soft_dirty(*ptep))
+ pte = pte_mksoft_dirty(pte);
if (is_write_migration_entry(entry))
pte = pte_mkwrite(pte);
#ifdef CONFIG_HUGETLB_PAGE
Index: linux-2.6.git/mm/mprotect.c
===================================================================
--- linux-2.6.git.orig/mm/mprotect.c
+++ linux-2.6.git/mm/mprotect.c
@@ -94,13 +94,16 @@ static unsigned long change_pte_range(st
swp_entry_t entry = pte_to_swp_entry(oldpte);
if (is_write_migration_entry(entry)) {
+ pte_t newpte;
/*
* A protection check is difficult so
* just be safe and disable write
*/
make_migration_entry_read(&entry);
- set_pte_at(mm, addr, pte,
- swp_entry_to_pte(entry));
+ newpte = swp_entry_to_pte(entry);
+ if (pte_swp_soft_dirty(oldpte))
+ newpte = pte_swp_mksoft_dirty(newpte);
+ set_pte_at(mm, addr, pte, newpte);
}
pages++;
}
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [patch 1/3] [PATCH] mm: migration -- Do not loose soft dirty bit if page is in migration state
2013-10-08 9:00 ` [patch 1/3] [PATCH] mm: migration -- Do not loose soft dirty bit if page is in migration state Cyrill Gorcunov
@ 2013-10-08 14:11 ` Naoya Horiguchi
2013-10-08 14:40 ` Cyrill Gorcunov
0 siblings, 1 reply; 11+ messages in thread
From: Naoya Horiguchi @ 2013-10-08 14:11 UTC (permalink / raw)
To: Cyrill Gorcunov
Cc: akpm, linux-mm, linux-kernel, Cyrill Gorcunov, Pavel Emelyanov,
Andy Lutomirski, Matt Mackall, Xiao Guangrong, Marcelo Tosatti,
KOSAKI Motohiro, Stephen Rothwell, Peter Zijlstra,
Aneesh Kumar K.V
On Tue, Oct 08, 2013 at 01:00:20PM +0400, Cyrill Gorcunov wrote:
> If page migration is turne on in the config and the page is migrating,
> we may loose soft dirty bit. If fork and mprotect if called on migrating
> pages (once migration is complete) pages do not obtain soft dirty bit
> in correspond pte entries. Fix it adding appropriate test on swap
> entries.
>
> Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
> Cc: Pavel Emelyanov <xemul@parallels.com>
> Cc: Andy Lutomirski <luto@amacapital.net>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Matt Mackall <mpm@selenic.com>
> Cc: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
> Cc: Marcelo Tosatti <mtosatti@redhat.com>
> Cc: KOSAKI Motohiro <kosaki.motohiro@gmail.com>
> Cc: Stephen Rothwell <sfr@canb.auug.org.au>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
> ---
> mm/memory.c | 2 ++
> mm/migrate.c | 2 ++
> mm/mprotect.c | 7 +++++--
> 3 files changed, 9 insertions(+), 2 deletions(-)
>
> Index: linux-2.6.git/mm/memory.c
> ===================================================================
> --- linux-2.6.git.orig/mm/memory.c
> +++ linux-2.6.git/mm/memory.c
> @@ -837,6 +837,8 @@ copy_one_pte(struct mm_struct *dst_mm, s
> */
> make_migration_entry_read(&entry);
> pte = swp_entry_to_pte(entry);
> + if (pte_swp_soft_dirty(*src_pte))
> + pte = pte_swp_mksoft_dirty(pte);
> set_pte_at(src_mm, addr, src_pte, pte);
> }
> }
When we convert pte to swap_entry, we convert soft-dirty bit in
pte_to_swp_entry(). So I think that it's better to convert it back
in swp_entry_to_pte() when we do swap_entry-to-pte conversion.
Thanks,
Naoya Horiguchi
> Index: linux-2.6.git/mm/migrate.c
> ===================================================================
> --- linux-2.6.git.orig/mm/migrate.c
> +++ linux-2.6.git/mm/migrate.c
> @@ -161,6 +161,8 @@ static int remove_migration_pte(struct p
>
> get_page(new);
> pte = pte_mkold(mk_pte(new, vma->vm_page_prot));
> + if (pte_swp_soft_dirty(*ptep))
> + pte = pte_mksoft_dirty(pte);
> if (is_write_migration_entry(entry))
> pte = pte_mkwrite(pte);
> #ifdef CONFIG_HUGETLB_PAGE
> Index: linux-2.6.git/mm/mprotect.c
> ===================================================================
> --- linux-2.6.git.orig/mm/mprotect.c
> +++ linux-2.6.git/mm/mprotect.c
> @@ -94,13 +94,16 @@ static unsigned long change_pte_range(st
> swp_entry_t entry = pte_to_swp_entry(oldpte);
>
> if (is_write_migration_entry(entry)) {
> + pte_t newpte;
> /*
> * A protection check is difficult so
> * just be safe and disable write
> */
> make_migration_entry_read(&entry);
> - set_pte_at(mm, addr, pte,
> - swp_entry_to_pte(entry));
> + newpte = swp_entry_to_pte(entry);
> + if (pte_swp_soft_dirty(oldpte))
> + newpte = pte_swp_mksoft_dirty(newpte);
> + set_pte_at(mm, addr, pte, newpte);
> }
> pages++;
> }
>
> --
> To unsubscribe, send a message with 'unsubscribe linux-mm' in
> the body to majordomo@kvack.org. For more info on Linux MM,
> see: http://www.linux-mm.org/ .
> Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [patch 1/3] [PATCH] mm: migration -- Do not loose soft dirty bit if page is in migration state
2013-10-08 14:11 ` Naoya Horiguchi
@ 2013-10-08 14:40 ` Cyrill Gorcunov
2013-10-08 14:47 ` Naoya Horiguchi
0 siblings, 1 reply; 11+ messages in thread
From: Cyrill Gorcunov @ 2013-10-08 14:40 UTC (permalink / raw)
To: Naoya Horiguchi
Cc: akpm, linux-mm, linux-kernel, Pavel Emelyanov, Andy Lutomirski,
Matt Mackall, Xiao Guangrong, Marcelo Tosatti, KOSAKI Motohiro,
Stephen Rothwell, Peter Zijlstra, Aneesh Kumar K.V
On Tue, Oct 08, 2013 at 10:11:40AM -0400, Naoya Horiguchi wrote:
> > Index: linux-2.6.git/mm/memory.c
> > ===================================================================
> > --- linux-2.6.git.orig/mm/memory.c
> > +++ linux-2.6.git/mm/memory.c
> > @@ -837,6 +837,8 @@ copy_one_pte(struct mm_struct *dst_mm, s
> > */
> > make_migration_entry_read(&entry);
> > pte = swp_entry_to_pte(entry);
> > + if (pte_swp_soft_dirty(*src_pte))
> > + pte = pte_swp_mksoft_dirty(pte);
> > set_pte_at(src_mm, addr, src_pte, pte);
> > }
> > }
>
> When we convert pte to swap_entry, we convert soft-dirty bit in
> pte_to_swp_entry(). So I think that it's better to convert it back
> in swp_entry_to_pte() when we do swap_entry-to-pte conversion.
No, soft dirty bit lays _only_ inside pte entry in memory, iow
swp_entry_t never has this bit, thus to be able to find soft dirty
status in swp_entry_to_pte you need to extend this function and
pass pte entry itself as an argument, which eventually will bring
more massive patch and will be a way more confusing I think.
Or I misunderstood you?
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [patch 1/3] [PATCH] mm: migration -- Do not loose soft dirty bit if page is in migration state
2013-10-08 14:40 ` Cyrill Gorcunov
@ 2013-10-08 14:47 ` Naoya Horiguchi
0 siblings, 0 replies; 11+ messages in thread
From: Naoya Horiguchi @ 2013-10-08 14:47 UTC (permalink / raw)
To: Cyrill Gorcunov
Cc: akpm, linux-mm, linux-kernel, Pavel Emelyanov, Andy Lutomirski,
Matt Mackall, Xiao Guangrong, Marcelo Tosatti, KOSAKI Motohiro,
Stephen Rothwell, Peter Zijlstra, Aneesh Kumar K.V
On Tue, Oct 08, 2013 at 06:40:30PM +0400, Cyrill Gorcunov wrote:
> On Tue, Oct 08, 2013 at 10:11:40AM -0400, Naoya Horiguchi wrote:
> > > Index: linux-2.6.git/mm/memory.c
> > > ===================================================================
> > > --- linux-2.6.git.orig/mm/memory.c
> > > +++ linux-2.6.git/mm/memory.c
> > > @@ -837,6 +837,8 @@ copy_one_pte(struct mm_struct *dst_mm, s
> > > */
> > > make_migration_entry_read(&entry);
> > > pte = swp_entry_to_pte(entry);
> > > + if (pte_swp_soft_dirty(*src_pte))
> > > + pte = pte_swp_mksoft_dirty(pte);
> > > set_pte_at(src_mm, addr, src_pte, pte);
> > > }
> > > }
> >
> > When we convert pte to swap_entry, we convert soft-dirty bit in
> > pte_to_swp_entry(). So I think that it's better to convert it back
> > in swp_entry_to_pte() when we do swap_entry-to-pte conversion.
>
> No, soft dirty bit lays _only_ inside pte entry in memory, iow
> swp_entry_t never has this bit, thus to be able to find soft dirty
> status in swp_entry_to_pte you need to extend this function and
> pass pte entry itself as an argument, which eventually will bring
> more massive patch and will be a way more confusing I think.
OK, you're right. Thanks for explanation.
> Or I misunderstood you?
No, I misread the code, sorry.
Naoya
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 11+ messages in thread
* [patch 2/3] [PATCH] mm: pagemap -- Inspect _PAGE_SOFT_DIRTY only on present pages
2013-10-08 9:00 [patch 0/3] Soft dirty tracking fixes Cyrill Gorcunov
2013-10-08 9:00 ` [patch 1/3] [PATCH] mm: migration -- Do not loose soft dirty bit if page is in migration state Cyrill Gorcunov
@ 2013-10-08 9:00 ` Cyrill Gorcunov
2013-10-08 14:26 ` Naoya Horiguchi
2013-10-08 9:00 ` [patch 3/3] [PATCH -mm] mm: Unify pte_to_pgoff and pgoff_to_pte helpers Cyrill Gorcunov
2013-10-08 19:50 ` [patch 0/3] Soft dirty tracking fixes Andrew Morton
3 siblings, 1 reply; 11+ messages in thread
From: Cyrill Gorcunov @ 2013-10-08 9:00 UTC (permalink / raw)
To: akpm
Cc: linux-mm, linux-kernel, Cyrill Gorcunov, Pavel Emelyanov,
Andy Lutomirski, Matt Mackall, Xiao Guangrong, Marcelo Tosatti,
KOSAKI Motohiro, Stephen Rothwell, Peter Zijlstra,
Aneesh Kumar K.V
[-- Attachment #1: pte-sft-dirty-pagemap-fix-2 --]
[-- Type: text/plain, Size: 1813 bytes --]
In case if a page we are inspecting is laying in swap we may
occasionally report it as having soft dirty bit (even if it
is clean). pte_soft_dirty helper should be called on present
pte only.
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Cc: Pavel Emelyanov <xemul@parallels.com>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Matt Mackall <mpm@selenic.com>
Cc: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@gmail.com>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
---
fs/proc/task_mmu.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
Index: linux-2.6.git/fs/proc/task_mmu.c
===================================================================
--- linux-2.6.git.orig/fs/proc/task_mmu.c
+++ linux-2.6.git/fs/proc/task_mmu.c
@@ -941,6 +941,8 @@ static void pte_to_pagemap_entry(pagemap
frame = pte_pfn(pte);
flags = PM_PRESENT;
page = vm_normal_page(vma, addr, pte);
+ if (pte_soft_dirty(pte))
+ flags2 |= __PM_SOFT_DIRTY;
} else if (is_swap_pte(pte)) {
swp_entry_t entry;
if (pte_swp_soft_dirty(pte))
@@ -960,7 +962,7 @@ static void pte_to_pagemap_entry(pagemap
if (page && !PageAnon(page))
flags |= PM_FILE;
- if ((vma->vm_flags & VM_SOFTDIRTY) || pte_soft_dirty(pte))
+ if ((vma->vm_flags & VM_SOFTDIRTY))
flags2 |= __PM_SOFT_DIRTY;
*pme = make_pme(PM_PFRAME(frame) | PM_STATUS2(pm->v2, flags2) | flags);
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [patch 2/3] [PATCH] mm: pagemap -- Inspect _PAGE_SOFT_DIRTY only on present pages
2013-10-08 9:00 ` [patch 2/3] [PATCH] mm: pagemap -- Inspect _PAGE_SOFT_DIRTY only on present pages Cyrill Gorcunov
@ 2013-10-08 14:26 ` Naoya Horiguchi
0 siblings, 0 replies; 11+ messages in thread
From: Naoya Horiguchi @ 2013-10-08 14:26 UTC (permalink / raw)
To: Cyrill Gorcunov
Cc: akpm, linux-mm, linux-kernel, Cyrill Gorcunov, Pavel Emelyanov,
Andy Lutomirski, Matt Mackall, Xiao Guangrong, Marcelo Tosatti,
KOSAKI Motohiro, Stephen Rothwell, Peter Zijlstra,
Aneesh Kumar K.V
On Tue, Oct 08, 2013 at 01:00:21PM +0400, Cyrill Gorcunov wrote:
> In case if a page we are inspecting is laying in swap we may
> occasionally report it as having soft dirty bit (even if it
> is clean). pte_soft_dirty helper should be called on present
> pte only.
>
> Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
> Cc: Pavel Emelyanov <xemul@parallels.com>
> Cc: Andy Lutomirski <luto@amacapital.net>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Matt Mackall <mpm@selenic.com>
> Cc: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
> Cc: Marcelo Tosatti <mtosatti@redhat.com>
> Cc: KOSAKI Motohiro <kosaki.motohiro@gmail.com>
> Cc: Stephen Rothwell <sfr@canb.auug.org.au>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
Looks nice to me.
Reviewed-by: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
> ---
> fs/proc/task_mmu.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> Index: linux-2.6.git/fs/proc/task_mmu.c
> ===================================================================
> --- linux-2.6.git.orig/fs/proc/task_mmu.c
> +++ linux-2.6.git/fs/proc/task_mmu.c
> @@ -941,6 +941,8 @@ static void pte_to_pagemap_entry(pagemap
> frame = pte_pfn(pte);
> flags = PM_PRESENT;
> page = vm_normal_page(vma, addr, pte);
> + if (pte_soft_dirty(pte))
> + flags2 |= __PM_SOFT_DIRTY;
> } else if (is_swap_pte(pte)) {
> swp_entry_t entry;
> if (pte_swp_soft_dirty(pte))
> @@ -960,7 +962,7 @@ static void pte_to_pagemap_entry(pagemap
>
> if (page && !PageAnon(page))
> flags |= PM_FILE;
> - if ((vma->vm_flags & VM_SOFTDIRTY) || pte_soft_dirty(pte))
> + if ((vma->vm_flags & VM_SOFTDIRTY))
> flags2 |= __PM_SOFT_DIRTY;
>
> *pme = make_pme(PM_PFRAME(frame) | PM_STATUS2(pm->v2, flags2) | flags);
>
> --
> To unsubscribe, send a message with 'unsubscribe linux-mm' in
> the body to majordomo@kvack.org. For more info on Linux MM,
> see: http://www.linux-mm.org/ .
> Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 11+ messages in thread
* [patch 3/3] [PATCH -mm] mm: Unify pte_to_pgoff and pgoff_to_pte helpers
2013-10-08 9:00 [patch 0/3] Soft dirty tracking fixes Cyrill Gorcunov
2013-10-08 9:00 ` [patch 1/3] [PATCH] mm: migration -- Do not loose soft dirty bit if page is in migration state Cyrill Gorcunov
2013-10-08 9:00 ` [patch 2/3] [PATCH] mm: pagemap -- Inspect _PAGE_SOFT_DIRTY only on present pages Cyrill Gorcunov
@ 2013-10-08 9:00 ` Cyrill Gorcunov
2013-10-08 19:50 ` [patch 0/3] Soft dirty tracking fixes Andrew Morton
3 siblings, 0 replies; 11+ messages in thread
From: Cyrill Gorcunov @ 2013-10-08 9:00 UTC (permalink / raw)
To: akpm
Cc: linux-mm, linux-kernel, Cyrill Gorcunov, Pavel Emelyanov,
Andy Lutomirski, Ingo Molnar, H. Peter Anvin, Thomas Gleixner
[-- Attachment #1: pte-sft-dirty-file-cleanup-2 --]
[-- Type: text/plain, Size: 5606 bytes --]
Use unified pte_bitop helper to manipulate bits in pte/pgoff bitfield,
and convert pte_to_pgoff/pgoff_to_pte to inlines.
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Pavel Emelyanov <xemul@parallels.com>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
---
arch/x86/include/asm/pgtable-2level.h | 100 ++++++++++++++++++++--------------
1 file changed, 59 insertions(+), 41 deletions(-)
Index: linux-2.6.git/arch/x86/include/asm/pgtable-2level.h
===================================================================
--- linux-2.6.git.orig/arch/x86/include/asm/pgtable-2level.h
+++ linux-2.6.git/arch/x86/include/asm/pgtable-2level.h
@@ -55,6 +55,13 @@ static inline pmd_t native_pmdp_get_and_
#define native_pmdp_get_and_clear(xp) native_local_pmdp_get_and_clear(xp)
#endif
+/* Bit manipulation helper on pte/pgoff entry */
+static inline unsigned long pte_bitop(unsigned long value, unsigned int rightshift,
+ unsigned long mask, unsigned int leftshift)
+{
+ return ((value >> rightshift) & mask) << leftshift;
+}
+
#ifdef CONFIG_MEM_SOFT_DIRTY
/*
@@ -71,31 +78,34 @@ static inline pmd_t native_pmdp_get_and_
#define PTE_FILE_BITS2 (PTE_FILE_SHIFT3 - PTE_FILE_SHIFT2 - 1)
#define PTE_FILE_BITS3 (PTE_FILE_SHIFT4 - PTE_FILE_SHIFT3 - 1)
-#define pte_to_pgoff(pte) \
- ((((pte).pte_low >> (PTE_FILE_SHIFT1)) \
- & ((1U << PTE_FILE_BITS1) - 1))) \
- + ((((pte).pte_low >> (PTE_FILE_SHIFT2)) \
- & ((1U << PTE_FILE_BITS2) - 1)) \
- << (PTE_FILE_BITS1)) \
- + ((((pte).pte_low >> (PTE_FILE_SHIFT3)) \
- & ((1U << PTE_FILE_BITS3) - 1)) \
- << (PTE_FILE_BITS1 + PTE_FILE_BITS2)) \
- + ((((pte).pte_low >> (PTE_FILE_SHIFT4))) \
- << (PTE_FILE_BITS1 + PTE_FILE_BITS2 + PTE_FILE_BITS3))
-
-#define pgoff_to_pte(off) \
- ((pte_t) { .pte_low = \
- ((((off)) & ((1U << PTE_FILE_BITS1) - 1)) << PTE_FILE_SHIFT1) \
- + ((((off) >> PTE_FILE_BITS1) \
- & ((1U << PTE_FILE_BITS2) - 1)) \
- << PTE_FILE_SHIFT2) \
- + ((((off) >> (PTE_FILE_BITS1 + PTE_FILE_BITS2)) \
- & ((1U << PTE_FILE_BITS3) - 1)) \
- << PTE_FILE_SHIFT3) \
- + ((((off) >> \
- (PTE_FILE_BITS1 + PTE_FILE_BITS2 + PTE_FILE_BITS3))) \
- << PTE_FILE_SHIFT4) \
- + _PAGE_FILE })
+#define PTE_FILE_MASK1 ((1U << PTE_FILE_BITS1) - 1)
+#define PTE_FILE_MASK2 ((1U << PTE_FILE_BITS2) - 1)
+#define PTE_FILE_MASK3 ((1U << PTE_FILE_BITS3) - 1)
+
+#define PTE_FILE_LSHIFT2 (PTE_FILE_BITS1)
+#define PTE_FILE_LSHIFT3 (PTE_FILE_BITS1 + PTE_FILE_BITS2)
+#define PTE_FILE_LSHIFT4 (PTE_FILE_BITS1 + PTE_FILE_BITS2 + PTE_FILE_BITS3)
+
+static __always_inline pgoff_t pte_to_pgoff(pte_t pte)
+{
+ return (pgoff_t)
+ (pte_bitop(pte.pte_low, PTE_FILE_SHIFT1, PTE_FILE_MASK1, 0) +
+ pte_bitop(pte.pte_low, PTE_FILE_SHIFT2, PTE_FILE_MASK2, PTE_FILE_LSHIFT2) +
+ pte_bitop(pte.pte_low, PTE_FILE_SHIFT3, PTE_FILE_MASK3, PTE_FILE_LSHIFT3) +
+ pte_bitop(pte.pte_low, PTE_FILE_SHIFT4, -1UL, PTE_FILE_LSHIFT4));
+}
+
+static __always_inline pte_t pgoff_to_pte(pgoff_t off)
+{
+ return (pte_t){
+ .pte_low =
+ pte_bitop(off, 0, PTE_FILE_MASK1, PTE_FILE_SHIFT1) +
+ pte_bitop(off, PTE_FILE_LSHIFT2, PTE_FILE_MASK2, PTE_FILE_SHIFT2) +
+ pte_bitop(off, PTE_FILE_LSHIFT3, PTE_FILE_MASK3, PTE_FILE_SHIFT3) +
+ pte_bitop(off, PTE_FILE_LSHIFT4, -1UL, PTE_FILE_SHIFT4) +
+ _PAGE_FILE,
+ };
+}
#else /* CONFIG_MEM_SOFT_DIRTY */
@@ -115,22 +125,30 @@ static inline pmd_t native_pmdp_get_and_
#define PTE_FILE_BITS1 (PTE_FILE_SHIFT2 - PTE_FILE_SHIFT1 - 1)
#define PTE_FILE_BITS2 (PTE_FILE_SHIFT3 - PTE_FILE_SHIFT2 - 1)
-#define pte_to_pgoff(pte) \
- ((((pte).pte_low >> PTE_FILE_SHIFT1) \
- & ((1U << PTE_FILE_BITS1) - 1)) \
- + ((((pte).pte_low >> PTE_FILE_SHIFT2) \
- & ((1U << PTE_FILE_BITS2) - 1)) << PTE_FILE_BITS1) \
- + (((pte).pte_low >> PTE_FILE_SHIFT3) \
- << (PTE_FILE_BITS1 + PTE_FILE_BITS2)))
-
-#define pgoff_to_pte(off) \
- ((pte_t) { .pte_low = \
- (((off) & ((1U << PTE_FILE_BITS1) - 1)) << PTE_FILE_SHIFT1) \
- + ((((off) >> PTE_FILE_BITS1) & ((1U << PTE_FILE_BITS2) - 1)) \
- << PTE_FILE_SHIFT2) \
- + (((off) >> (PTE_FILE_BITS1 + PTE_FILE_BITS2)) \
- << PTE_FILE_SHIFT3) \
- + _PAGE_FILE })
+#define PTE_FILE_MASK1 ((1U << PTE_FILE_BITS1) - 1)
+#define PTE_FILE_MASK2 ((1U << PTE_FILE_BITS2) - 1)
+
+#define PTE_FILE_LSHIFT2 (PTE_FILE_BITS1)
+#define PTE_FILE_LSHIFT3 (PTE_FILE_BITS1 + PTE_FILE_BITS2)
+
+static __always_inline pgoff_t pte_to_pgoff(pte_t pte)
+{
+ return (pgoff_t)
+ (pte_bitop(pte.pte_low, PTE_FILE_SHIFT1, PTE_FILE_MASK1, 0) +
+ pte_bitop(pte.pte_low, PTE_FILE_SHIFT2, PTE_FILE_MASK2, PTE_FILE_LSHIFT2) +
+ pte_bitop(pte.pte_low, PTE_FILE_SHIFT3, -1UL, PTE_FILE_LSHIFT3));
+}
+
+static __always_inline pte_t pgoff_to_pte(pgoff_t off)
+{
+ return (pte_t){
+ .pte_low =
+ pte_bitop(off, 0, PTE_FILE_MASK1, PTE_FILE_SHIFT1) +
+ pte_bitop(off, PTE_FILE_LSHIFT2, PTE_FILE_MASK2, PTE_FILE_SHIFT2) +
+ pte_bitop(off, PTE_FILE_LSHIFT3, -1UL, PTE_FILE_SHIFT3) +
+ _PAGE_FILE,
+ };
+}
#endif /* CONFIG_MEM_SOFT_DIRTY */
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [patch 0/3] Soft dirty tracking fixes
2013-10-08 9:00 [patch 0/3] Soft dirty tracking fixes Cyrill Gorcunov
` (2 preceding siblings ...)
2013-10-08 9:00 ` [patch 3/3] [PATCH -mm] mm: Unify pte_to_pgoff and pgoff_to_pte helpers Cyrill Gorcunov
@ 2013-10-08 19:50 ` Andrew Morton
2013-10-08 20:02 ` Cyrill Gorcunov
3 siblings, 1 reply; 11+ messages in thread
From: Andrew Morton @ 2013-10-08 19:50 UTC (permalink / raw)
To: Cyrill Gorcunov; +Cc: linux-mm, linux-kernel
On Tue, 08 Oct 2013 13:00:19 +0400 Cyrill Gorcunov <gorcunov@gmail.com> wrote:
> Hi! Here is a couple of fixes for soft dirty pages tracking.
> While first two patches are adressing issues, the last one
> is rather a cleanup which I've been asked to implement long
> ago, but I'm not sure if anyone picked it up.
>
Do you consider the problems which patches 1 and 2 address to be
sufficiently serious to justify backporting into -stable?
I already have patch 3, as
arch-x86-mnify-pte_to_pgoff-and-pgoff_to_pte-helpers.patch (with
s/m/u). I've queued it for transmission to the x86 guys.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [patch 0/3] Soft dirty tracking fixes
2013-10-08 19:50 ` [patch 0/3] Soft dirty tracking fixes Andrew Morton
@ 2013-10-08 20:02 ` Cyrill Gorcunov
2013-10-08 20:06 ` Andrew Morton
0 siblings, 1 reply; 11+ messages in thread
From: Cyrill Gorcunov @ 2013-10-08 20:02 UTC (permalink / raw)
To: Andrew Morton; +Cc: linux-mm, linux-kernel
On Tue, Oct 08, 2013 at 12:50:13PM -0700, Andrew Morton wrote:
>
> Do you consider the problems which patches 1 and 2 address to be
> sufficiently serious to justify backporting into -stable?
Good question! Yeah, since dirty bit traking is in 3.11 already,
it would be great to merge these two patches into -stable.
Should I resend them with stable team CC'ed?
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [patch 0/3] Soft dirty tracking fixes
2013-10-08 20:02 ` Cyrill Gorcunov
@ 2013-10-08 20:06 ` Andrew Morton
0 siblings, 0 replies; 11+ messages in thread
From: Andrew Morton @ 2013-10-08 20:06 UTC (permalink / raw)
To: Cyrill Gorcunov; +Cc: linux-mm, linux-kernel
On Wed, 9 Oct 2013 00:02:24 +0400 Cyrill Gorcunov <gorcunov@gmail.com> wrote:
> On Tue, Oct 08, 2013 at 12:50:13PM -0700, Andrew Morton wrote:
> >
> > Do you consider the problems which patches 1 and 2 address to be
> > sufficiently serious to justify backporting into -stable?
>
> Good question! Yeah, since dirty bit traking is in 3.11 already,
> it would be great to merge these two patches into -stable.
OK.
> Should I resend them with stable team CC'ed?
Nope, I added cc:stable to the changelogs so they should receive
consideration by Greg automatically.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 11+ messages in thread