Skip to contentSkip to conversation

powerpc/mm: Lockless get_user_pages_fast() for 64-bit (v3)

PATCH New Benjamin Herrenschmidt 1 participant 1 message Jul 30, 2008

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

PATCH 1/1 powerpc/mm: Lockless get_user_pages_fast() for 64-bit (v3)

From: Nick Piggin <[email protected]>

Implement lockless get_user_pages_fast for 64-bit powerpc.

Page table existence is guaranteed with RCU, and speculative page references are used to take a reference to the pages without having a prior existence guarantee on them.

---

v3.
Fix compile without hugetlbfs

v2.
Fix makefile to only build gup.o on 64 bits and fix a bug with huge pages where we would oops (null dereference) if huge_pte_offset() returns NULL (ie, not populated yet).

v1.
I'm going to merge this, sending it to the list for reference, it was in -mm , minus some changes/fixes I did to solve conflicts with the new multiple huge page sizes.

arch/powerpc/Kconfig +3 -0
Index: linux-work/arch/powerpc/Kconfig
===================================================================
@@ -42,6 +42,9 @@ config GENERIC_HARDIRQS
 	bool
 	default y
 
+config HAVE_GET_USER_PAGES_FAST
+	def_bool PPC64
+
 config HAVE_SETUP_PER_CPU_AREA
 	def_bool PPC64
 
arch/powerpc/mm/Makefile +2 -1
Index: linux-work/arch/powerpc/mm/Makefile
===================================================================
@@ -12,7 +12,8 @@ obj-y				:= fault.o mem.o \
 				   mmu_context_$(CONFIG_WORD_SIZE).o
 hash-$(CONFIG_PPC_NATIVE)	:= hash_native_64.o
 obj-$(CONFIG_PPC64)		+= hash_utils_64.o \
-				   slb_low.o slb.o stab.o mmap.o $(hash-y)
+				   slb_low.o slb.o stab.o \
+				   gup.o mmap.o $(hash-y)
 obj-$(CONFIG_PPC_STD_MMU_32)	+= ppc_mmu_32.o
 obj-$(CONFIG_PPC_STD_MMU)	+= hash_low_$(CONFIG_WORD_SIZE).o \
 				   tlb_$(CONFIG_WORD_SIZE).o
arch/powerpc/mm/gup.c new file +280 -0

280 lines not on this page · raw message

include/asm-powerpc/pgtable-ppc64.h +2 -0
Index: linux-work/include/asm-powerpc/pgtable-ppc64.h
===================================================================
@@ -461,6 +461,8 @@ void pgtable_cache_init(void);
 	return pt;
 }
 
+pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long address);
+
 #endif /* __ASSEMBLY__ */
 
 #endif /* _ASM_POWERPC_PGTABLE_PPC64_H_ */
include/linux/pagemap.h +23 -0
Index: linux-work/include/linux/pagemap.h
===================================================================
@@ -142,6 +142,29 @@ static inline int page_cache_get_specula
 	return 1;
 }
 
+/*
+ * Same as above, but add instead of inc (could just be merged)
+ */
+static inline int page_cache_add_speculative(struct page *page, int count)
+{
+	VM_BUG_ON(in_interrupt());
+
+#if !defined(CONFIG_SMP) && defined(CONFIG_CLASSIC_RCU)
+# ifdef CONFIG_PREEMPT
+	VM_BUG_ON(!in_atomic());
+# endif
+	VM_BUG_ON(page_count(page) == 0);
+	atomic_add(count, &page->_count);
+
+#else
+	if (unlikely(!atomic_add_unless(&page->_count, count, 0)))
+		return 0;
+#endif
+	VM_BUG_ON(PageCompound(page) && page != compound_head(page));
+
+	return 1;
+}
+
 static inline int page_freeze_refs(struct page *page, int count)
 {
 	return likely(atomic_cmpxchg(&page->_count, count, 0) == count);