Skip to contentSkip to conversation

Pte drop ptep_get_and_clear paravirt op.patch

PATCH In review Zachary Amsden 2 participants 6 messages Apr 12, 2007 – Apr 18, 2007

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/4 Pte drop ptep_get_and_clear paravirt op.patch

In shadow mode hypervisors, ptep_get_and_clear achieves the desired purpose of keeping the shadows in sync by issuing a native_get_and_clear, followed by a call to pte_update, which indicates the PTE has been modified.

Direct mode hypervisors (Xen) have no need for this anyway, and will trap the update using writable pagetables.

This means no hypervisor makes use of ptep_get_and_clear; there is no reason to have it in the paravirt-ops structure. Change confusing terminology about raw vs. native functions into consistent use of native_pte_xxx for operations which do not invoke paravirt-ops.

arch/i386/kernel/paravirt.c +0 -2
diff -r c02c6f5e882c arch/i386/kernel/paravirt.c
@@ -315,8 +315,6 @@ struct paravirt_ops paravirt_ops = {
 	.pte_update = paravirt_nop,
 	.pte_update_defer = paravirt_nop,
 
-	.ptep_get_and_clear = native_ptep_get_and_clear,
-
 #ifdef CONFIG_HIGHPTE
 	.kmap_atomic_pte = kmap_atomic,
 #endif
include/asm-i386/paravirt.h +1 -12
diff -r c02c6f5e882c include/asm-i386/paravirt.h
@@ -187,8 +187,6 @@ struct paravirt_ops
 	void (*pte_update)(struct mm_struct *mm, unsigned long addr, pte_t *ptep);
 	void (*pte_update_defer)(struct mm_struct *mm,
 				 unsigned long addr, pte_t *ptep);
-
- 	pte_t (*ptep_get_and_clear)(pte_t *ptep);
 
 #ifdef CONFIG_HIGHPTE
 	void *(*kmap_atomic_pte)(struct page *page, enum km_type type);
@@ -859,12 +857,8 @@ static inline void pmd_clear(pmd_t *pmdp
 	PVOP_VCALL1(pmd_clear, pmdp);
 }
 
-static inline pte_t raw_ptep_get_and_clear(pte_t *p)
-{
-	unsigned long long val = PVOP_CALL1(unsigned long long, ptep_get_and_clear, p);
-	return (pte_t) { val, val >> 32 };
-}
 #else  /* !CONFIG_X86_PAE */
+
 static inline pte_t __pte(unsigned long val)
 {
 	return (pte_t) { PVOP_CALL1(unsigned long, make_pte, val) };
@@ -899,11 +893,6 @@ static inline void set_pmd(pmd_t *pmdp, 
 static inline void set_pmd(pmd_t *pmdp, pmd_t pmdval)
 {
 	PVOP_VCALL2(set_pmd, pmdp, pmdval.pud.pgd.pgd);
-}
-
-static inline pte_t raw_ptep_get_and_clear(pte_t *p)
-{
-	return (pte_t) { PVOP_CALL1(unsigned long, ptep_get_and_clear, p) };
 }
 #endif	/* CONFIG_X86_PAE */
 
include/asm-i386/pgtable.h +1 -3
diff -r c02c6f5e882c include/asm-i386/pgtable.h
@@ -265,8 +265,6 @@ static inline pte_t pte_mkhuge(pte_t pte
  */
 #define pte_update(mm, addr, ptep)		do { } while (0)
 #define pte_update_defer(mm, addr, ptep)	do { } while (0)
-
-#define raw_ptep_get_and_clear(xp)     native_ptep_get_and_clear(xp)
 #endif
 
 /*
@@ -340,7 +338,7 @@ do {									\
 #define __HAVE_ARCH_PTEP_GET_AND_CLEAR
 static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
 {
-	pte_t pte = raw_ptep_get_and_clear(ptep);
+	pte_t pte = native_ptep_get_and_clear(ptep);
 	pte_update(mm, addr, ptep);
 	return pte;
 }
Acked-by on v1 1/4
#1 lore raw
Quoted 5 lines · Zachary Amsden

In shadow mode hypervisors, ptep_get_and_clear achieves the desired purpose of keeping the shadows in sync by issuing a native_get_and_clear, followed by a call to pte_update, which indicates the PTE has been modified.

Quoted 8 lines

Direct mode hypervisors (Xen) have no need for this anyway, and will trap the update using writable pagetables.

This means no hypervisor makes use of ptep_get_and_clear; there is no reason to have it in the paravirt-ops structure. Change confusing terminology about raw vs. native functions into consistent use of native_pte_xxx for operations which do not invoke paravirt-ops.

Looks OK to me. Are you going to put this into the pvops queue?

J

#2 lore raw
Quoted 17 lines · Jeremy Fitzhardinge
Quoted 5 lines · Zachary Amsden

In shadow mode hypervisors, ptep_get_and_clear achieves the desired purpose of keeping the shadows in sync by issuing a native_get_and_clear, followed by a call to pte_update, which indicates the PTE has been modified.

Quoted 9 lines

Direct mode hypervisors (Xen) have no need for this anyway, and will trap the update using writable pagetables.

This means no hypervisor makes use of ptep_get_and_clear; there is no reason to have it in the paravirt-ops structure. Change confusing terminology about raw vs. native functions into consistent use of native_pte_xxx for operations which do not invoke paravirt-ops.

Quoted 3 lines

Looks OK to me. Are you going to put this into the pvops queue?

Yes, the rest are still undergoing feedback. I'll kick this in and fixup the damage it causes.

Zach

#3 lore raw
In reply to Zachary Amsden
Quoted 8 lines · Zachary Amsden

In shadow mode hypervisors, ptep_get_and_clear achieves the desired purpose of keeping the shadows in sync by issuing a native_get_and_clear, followed by a call to pte_update, which indicates the PTE has been modified.

Direct mode hypervisors (Xen) have no need for this anyway, and will trap the update using writable pagetables.

Jan Beulich just posted a patch for Xen/linux which specialzes ptep_get_and_clear, which apparently improves kernel-compile performance by 25-30% on some configurations. I think we'll want to keep this.

J

#4 lore raw
Quoted 7 lines · Jeremy Fitzhardinge
Quoted 5 lines · Zachary Amsden

In shadow mode hypervisors, ptep_get_and_clear achieves the desired purpose of keeping the shadows in sync by issuing a native_get_and_clear, followed by a call to pte_update, which indicates the PTE has been modified.

Quoted 9 lines
Quoted 4 lines

Direct mode hypervisors (Xen) have no need for this anyway, and will trap the update using writable pagetables.

Jan Beulich just posted a patch for Xen/linux which specialzes ptep_get_and_clear, which apparently improves kernel-compile performance by 25-30% on some configurations. I think we'll want to keep this.

Are you sure that it still wins even with these patches? I can't see ptep_get_and_clear getting much faster than a pure non-emulated, and the stress case which wins 25-30% is fork/exit being able to drop the pte updates in zap_pte_range from trapping and / or going into a pte update queue. That is what my patches addressed for shadow paging performance - the call to pte_update can be dropped - but you should already be getting this benefit for Xen, since there pte_update is a nop. Are you sure you are unpinning the page tables and mapping them back as writable pages prior to address space destruction?

Or is there another case which exercises zap_pte_range via munmap? In which case, you might be able to do things faster than trap and emulate with a hypercall, but a 25-30% speedup sounds rather para-normal for this type of change. I would like to see a patch and some basic data showing the speedup if possible.

I certainly have no objection to adding back ptep_get_and_clear hook, but we need to fix the naming to be consistent (raw vs. native), which is one thing the patch (dropping the hook) is trying to do. We can always re-add specialization for ptep_get_and_clear; the question is what level is appropriate. Do you allow ptep_get_and_clear itself to be redefined or allow redefine of native_ptep_get_and_clear?

One line of reasoning - for consistency, it seems that native_ptep_get_and_clear should be just that, a non-paravirtualized pte udpate. Then it follows we should not allow native_ptep_get_and_clear to be overridden. In this case, for cleanliness is it better to add a midlevel indirection; use raw_ptep_get_and_clear as the paravirt-hook, which is called from ptep_get_and_clear, and allow access to the non-paravirtualized native functions with native_ptep_get_and_clear. If that sounds agreeable, then this patch should be backed out. I think backing it out will damage the immediately following patches due to sensitivity from code proximity.

Maybe the best strategy is to just re-add ptep_get_and_clear as a paravirt-op after the whole set of patches and before Jan's speedup patch?

Zach

#5 lore raw
Quoted 9 lines · Zachary Amsden

Are you sure that it still wins even with these patches? I can't see ptep_get_and_clear getting much faster than a pure non-emulated, and the stress case which wins 25-30% is fork/exit being able to drop the pte updates in zap_pte_range from trapping and / or going into a pte update queue. That is what my patches addressed for shadow paging performance - the call to pte_update can be dropped - but you should already be getting this benefit for Xen, since there pte_update is a nop. Are you sure you are unpinning the page tables and mapping them back as writable pages prior to address space destruction?

I'll ask Jan for more details later today, but he did this work on xen-unstable. The specific change is that it only bothers to update the pte if it wasn't already not-present. I guess that's a generally applicable optimisation, though it wouldn't do much for native.

Quoted 3 lines

Maybe the best strategy is to just re-add ptep_get_and_clear as a paravirt-op after the whole set of patches and before Jan's speedup patch?

Yes, I'm happy with native_ptep_get_and_clear to be a direct pagetable write for pulldown, and then use ptep_get_and_clear as a hook for manipulating a live pagetable. I don't see any particular need to put Jan's patch into the pvops Xen right now, but it would be nice to have the option.

J

changeset:   14731:14c25e48a557
user:        [email protected]
date:        Thu Apr 05 09:10:33 2007 +0100
files:       linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/pgtable-2level.h linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/pgtable-3level.h linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/pgtable.h linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/pgtable.h

description:
linux: improve x86 page table handling performance

Where possible,
- use hypercalls instead of writing to read-only pages
- fold TLB flushes into page table update hypercalls
- on PAE, use single-access updates instead of two-access ones

The single change to PAE pte_clear() yields a 25-30% boost for kernel builds on a 4x2x2 CPUs, 8Gb box; the other changes together yield improvements of 2-5%.

Also, adjust backward compatibility handling in a few more places.

linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/pgtable-2level.h +30 -2
diff -r 07d3208c0ca3 -r 14c25e48a557 linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/pgtable-2level.h
@@ -36,8 +36,37 @@
 #define pte_clear(mm,addr,xp)	do { set_pte_at(mm, addr, xp, __pte(0)); } while (0)
 #define pmd_clear(xp)	do { set_pmd(xp, __pmd(0)); } while (0)
 
-#define ptep_get_and_clear(mm,addr,xp)	__pte_ma(xchg(&(xp)->pte_low, 0))
+#define pte_none(x) (!(x).pte_low)
+
+static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
+{
+	pte_t pte = *ptep;
+	if (!pte_none(pte)) {
+		if (mm != &init_mm)
+			pte = __pte_ma(xchg(&ptep->pte_low, 0));
+		else
+			HYPERVISOR_update_va_mapping(addr, __pte(0), 0);
+	}
+	return pte;
+}
+
+#define ptep_clear_flush(vma, addr, ptep)			\
+({								\
+	pte_t *__ptep = (ptep);					\
+	pte_t __res = *__ptep;					\
+	if (!pte_none(__res) &&					\
+	    ((vma)->vm_mm != current->mm ||			\
+	     HYPERVISOR_update_va_mapping(addr, __pte(0),	\
+			(unsigned long)(vma)->vm_mm->cpu_vm_mask.bits| \
+				UVMF_INVLPG|UVMF_MULTI))) {	\
+		__ptep->pte_low = 0;				\
+		flush_tlb_page(vma, addr);			\
+	}							\
+	__res;							\
+})
+
 #define pte_same(a, b)		((a).pte_low == (b).pte_low)
+
 #define __pte_mfn(_pte) ((_pte).pte_low >> PAGE_SHIFT)
 #define pte_mfn(_pte) ((_pte).pte_low & _PAGE_PRESENT ? \
 	__pte_mfn(_pte) : pfn_to_mfn(__pte_mfn(_pte)))
@@ -46,7 +75,6 @@
 
 #define pte_page(_pte) pfn_to_page(pte_pfn(_pte))
 
-#define pte_none(x)		(!(x).pte_low)
 #define pfn_pte(pfn, prot)	__pte(((pfn) << PAGE_SHIFT) | pgprot_val(prot))
 #define pfn_pmd(pfn, prot)	__pmd(((pfn) << PAGE_SHIFT) | pgprot_val(prot))
 
linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/pgtable-3level.h +43 -17

84 lines not on this page · raw message

linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/pgtable.h +61 -46

144 lines not on this page · raw message

linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/pgtable.h +88 -73

229 lines not on this page · raw message