Skip to contentSkip to conversation

28-rc9-mmotm1219 page_fault-retry-with-nopage_retry.patch hoses xmms

DISCUSSION [email protected] 2 participants 2 messages Dec 23, 2008 – Jan 7, 2009

Subsystems (5)
Memory management x86 MM core x86 MM +1 more subsystems
lore
Share & tools
lore
#0 lore raw

OK, here's a weird one.. ;)

Dell Latitude D820 laptop, x86_64 kernel and userspace.

Symptom: The 'xmms' media player will consistently (every time) get stuck and keep repeating the first 1 second or so of the song over and over (sounding very similar to how an audio card will keep looping the ring buffer if the system crashes). However, xmms is responsive. It claims it's making progress through the song - and the spectrum analyzer display is changing, *not* looping the same second over and over.

The spectrum analyzer convinces me that the xmms thread reading from disk is getting new data, but I'm unable to tell if the looping is happening on the xmms->pulseaudio handoff or the pulseaudio->ALSA side.

Bisect results:

shmem-unify-regular-and-tiny-shmem.patch GOOD
#
page_fault-retry-with-nopage_retry.patch
page_fault-retry-with-nopage_retry-fix.patch
page_fault-retry-with-nopage_retry-fix-fix.patch BAD

#1 lore raw

Hi Valdis:
I made a fix for the patch and i tested with xmms on ubuntu8.10.
Please give a try with it. thanks

arch/x86/mm/fault.c +18 -0
index 9e268b6..f4bbd9b 100644
@@ -593,6 +593,7 @@ void __kprobes do_page_fault(struct pt_regs *regs, unsigne
 	unsigned long flags;
 	int sig;
 #endif
+	unsigned int retry_flag = FAULT_FLAG_RETRY;
 
 	tsk = current;
 	mm = tsk->mm;
@@ -690,6 +691,7 @@ void __kprobes do_page_fault(struct pt_regs *regs, unsigne
 		down_read(&mm->mmap_sem);
 	}
 
+retry:
 	vma = find_vma(mm, address);
 	if (!vma)
 		goto bad_area;
@@ -716,6 +718,7 @@ void __kprobes do_page_fault(struct pt_regs *regs, unsigne
 good_area:
 	si_code = SEGV_ACCERR;
 	write = 0;
+	write |= retry_flag;
 	switch (error_code & (PF_PROT|PF_WRITE)) {
 	default:	/* 3: write, present */
 		/* fall through */
@@ -744,6 +747,21 @@ good_area:
 			goto do_sigbus;
 		BUG();
 	}
+
+	/*
+	 * Here we retry fault once and switch to synchronous mode. The
+	 * main reason is to prevent us from the cases of starvation.
+	 * The retry logic open a starvation hole in which case pages might
+	 * be removed or changed after the retry.
+	 */
+	if (fault & VM_FAULT_RETRY) {
+		if (write & FAULT_FLAG_RETRY) {
+			retry_flag &= ~FAULT_FLAG_RETRY;
+			goto retry;
+		}
+		BUG();
+	}
+
 	if (fault & VM_FAULT_MAJOR)
 		tsk->maj_flt++;
 	else
include/linux/mm.h +2 -0
index 4a3d28c..be770f9 100644
@@ -144,6 +144,7 @@ extern pgprot_t protection_map[16];
 
 #define FAULT_FLAG_WRITE	0x01	/* Fault was a write access */
 #define FAULT_FLAG_NONLINEAR	0x02	/* Fault was via a nonlinear mapping */
+#define FAULT_FLAG_RETRY	0x04	/* Retry major fault */
 
 /*
  * This interface is used by x86 PAT code to identify a pfn mapping that is
@@ -707,6 +708,7 @@ static inline int page_mapped(struct page *page)
 
 #define VM_FAULT_MINOR	0 /* For backwards compat. Remove me quickly. */
 
+#define VM_FAULT_RETRY	0x0010
 #define VM_FAULT_OOM	0x0001
 #define VM_FAULT_SIGBUS	0x0002
 #define VM_FAULT_MAJOR	0x0004
mm/filemap.c +82 -4

131 lines not on this page · raw message

mm/memory.c +10 -1
index 3f8fa06..534ba1d 100644
@@ -2572,6 +2572,13 @@ static int __do_fault(struct mm_struct *mm, struct vm_a
 	vmf.page = NULL;
 
 	ret = vma->vm_ops->fault(vma, &vmf);
+
+	/* page may be available, but we have to restart the process
+	 * because mmap_sem was dropped during the ->fault
+	 */
+	if (ret & VM_FAULT_RETRY)
+		return ret;
+
 	if (unlikely(ret & (VM_FAULT_ERROR | VM_FAULT_NOPAGE)))
 		return ret;
 
@@ -2713,8 +2720,10 @@ static int do_linear_fault(struct mm_struct *mm, struct
 {
 	pgoff_t pgoff = (((address & PAGE_MASK)
 			- vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff;
-	unsigned int flags = (write_access ? FAULT_FLAG_WRITE : 0);
+	int write = write_access & ~FAULT_FLAG_RETRY;
+	unsigned int flags = (write ? FAULT_FLAG_WRITE : 0);
 
+	flags |= (write_access & FAULT_FLAG_RETRY);
 	pte_unmap(page_table);
 	return __do_fault(mm, vma, address, pmd, pgoff, flags, orig_pte);
 }