Skip to contentSkip to conversation

Delay accounting: Page fault delays

PATCH In review Shailabh Nagar 1 participant 1 message Nov 15, 2005

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

PATCH 3/4 Delay accounting: Page fault delays

delayacct-pgflt.patch

Record time spent by a task waiting for page fault completion.

 include/linux/delayacct.h |   20 ++++++++++++++++++++
 include/linux/sched.h     |    2 ++
 mm/memory.c               |   17 ++++++++++++++---
 3 files changed, 36 insertions(+), 3 deletions(-)
include/linux/delayacct.h +20 -0
Index: linux-2.6.14/include/linux/delayacct.h
===================================================================
@@ -56,6 +56,24 @@ static inline void delayacct_blkio(unsig
 	spin_unlock(&current->delays.lock);
 }
 
+static inline void delayacct_pgflt(unsigned long long ts)
+{
+	unsigned long long now = sched_clock();
+
+	if (!test_ts_integrity(ts, now))
+		return;
+
+	/* Lock and pgflt_count may be unnecessary.
+	 * pgflt_count is equivalent to current->min_flt+current->maj_flt
+	 * but if the sum cannot be safely taken when current->delays is read
+	 * the lock and redundant addition may still be needed.
+	 */
+	spin_lock(&current->delays.lock);
+	current->delays.pgflt_delay += now - ts;
+	current->delays.pgflt_count++;
+	spin_unlock(&current->delays.lock);
+}
+
 #else
 
 static inline void delayacct_init(struct task_struct *tsk)
@@ -65,6 +83,8 @@ static inline void delayacct_timestamp(u
 {}
 static inline void delayacct_blkio(unsigned long long ts)
 {}
+static inline void delayacct_pgflt(unsigned long long ts)
+{}
 #endif /* CONFIG_DELAY_ACCT */
 
 
include/linux/sched.h +2 -0
Index: linux-2.6.14/include/linux/sched.h
===================================================================
@@ -504,6 +504,8 @@ struct task_delay_info {
 	/* Add stats in pairs: uint64_t delay, uint32_t count */
 	uint64_t blkio_delay;	/* wait for block io completion */
 	uint32_t blkio_count;
+	uint64_t pgflt_delay;	/* wait for page fault completion */
+	uint32_t pgflt_count;
 };
 #endif
 
mm/memory.c +14 -3
Index: linux-2.6.14/mm/memory.c
===================================================================
@@ -48,6 +48,8 @@
 #include <linux/rmap.h>
 #include <linux/module.h>
 #include <linux/init.h>
+#include <linux/sched.h>
+#include <linux/delayacct.h>
 
 #include <asm/pgalloc.h>
 #include <asm/uaccess.h>
@@ -2040,13 +2042,19 @@ int __handle_mm_fault(struct mm_struct *
 	pud_t *pud;
 	pmd_t *pmd;
 	pte_t *pte;
+	int rc;
+	delayacct_def_var(ts);
 
+	delayacct_timestamp(&ts);
 	__set_current_state(TASK_RUNNING);
 
 	inc_page_state(pgfault);
 
-	if (unlikely(is_vm_hugetlb_page(vma)))
-		return hugetlb_fault(mm, vma, address, write_access);
+	if (unlikely(is_vm_hugetlb_page(vma))) {
+		rc = hugetlb_fault(mm, vma, address, write_access);
+		delayacct_pgflt(ts);
+		return rc;
+	}
 
 	/*
 	 * We need the page table lock to synchronize with kswapd
@@ -2067,10 +2075,13 @@ int __handle_mm_fault(struct mm_struct *
 	if (!pte)
 		goto oom;
 	
-	return handle_pte_fault(mm, vma, address, write_access, pte, pmd);
+	rc = handle_pte_fault(mm, vma, address, write_access, pte, pmd);
+	delayacct_pgflt(ts);
+	return rc;
 
  oom:
 	spin_unlock(&mm->page_table_lock);
+	delayacct_pgflt(ts);
 	return VM_FAULT_OOM;
 }