Delay accounting: Page fault delays
Subsystems (4)
PATCH 3/4 Delay accounting: Page fault delays
delayacct-pgflt.patch
Record time spent by a task waiting for page fault completion.
Signed-off-by Shailabh Nagar <[email protected]>
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
@@ -56,6 +56,24 @@ static inline void delayacct_blkio(unsig spin_unlock(¤t->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 (¤t->delays.lock); + current->delays.pgflt_delay += now - ts; + current->delays.pgflt_count++; +spin_unlock (¤t->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
@@ -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
@@ -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 ; }