[vz7,v2] vzstat: account "page_in" and "swap_in" in nanoseconds

Submitted by Konstantin Khorenko on Nov. 15, 2018, 9:20 a.m.

Details

Message ID 20181115092008.6108-1-khorenko@virtuozzo.com
State New
Series "Series without cover letter"
Headers show

Commit Message

Konstantin Khorenko Nov. 15, 2018, 9:20 a.m.
Up to now "page_in" and "swap_in" in /proc/vz/latency has been provided
in cpu cycles while other latencies are in nanoseconds there.

Let's make a single measure unit for all latencies, so provide swap_in
and page_in in nanoseconds as well.

Note: we left time accounting using direct rdtsc() with converting to ns
afterwards. We understand there are some issues possible with
correctness and using ktime_to_ns(ktime_get()) would be better (as it's
done for other latencies), but switching to ktime_get() results in 2%
performance loss on first memory access (pagefault + memory read),
so decided not to slowdown fastpath and be aware of possible stats
incorrectness.

https://pmc.acronis.com/browse/VSTOR-16659

Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
---
 mm/memory.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/mm/memory.c b/mm/memory.c
index 3d26170d4529..1601a9752bbb 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -78,6 +78,7 @@ 
 #include <asm/tlb.h>
 #include <asm/tlbflush.h>
 #include <asm/pgtable.h>
+#include <asm/tsc.h>
 
 #include "internal.h"
 
@@ -2602,6 +2603,8 @@  void unmap_mapping_range(struct address_space *mapping,
 }
 EXPORT_SYMBOL(unmap_mapping_range);
 
+#define CLKS2NSEC(c)	((c) * 1000000 / tsc_khz)
+
 /*
  * We enter with non-exclusive mmap_sem (to exclude vma changes,
  * but allow concurrent faults), and pte mapped but not yet locked.
@@ -2781,7 +2784,8 @@  static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
 	pte_unmap_unlock(page_table, ptl);
 out:
 	local_irq_disable();
-	KSTAT_LAT_PCPU_ADD(&kstat_glob.swap_in, get_cycles() - start);
+	KSTAT_LAT_PCPU_ADD(&kstat_glob.swap_in,
+			   CLKS2NSEC(get_cycles() - start));
 	local_irq_enable();
 
 	return ret;
@@ -2926,7 +2930,8 @@  static int __do_fault(struct vm_area_struct *vma, unsigned long address,
 		VM_BUG_ON_PAGE(!PageLocked(vmf.page), vmf.page);
 
 	local_irq_disable();
-	KSTAT_LAT_PCPU_ADD(&kstat_glob.page_in, get_cycles() - start);
+	KSTAT_LAT_PCPU_ADD(&kstat_glob.page_in,
+			   CLKS2NSEC(get_cycles() - start));
 	local_irq_enable();
 
 	*page = vmf.page;