[Devel] [PATCH RH8 03/10] vzstat: account "page_in" and "swap_in" in nanoseconds

Andrey Zhadchenko andrey.zhadchenko at virtuozzo.com
Wed May 26 17:56:11 MSK 2021


From: Konstantin Khorenko <khorenko at virtuozzo.com>

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 at virtuozzo.com>

(cherry-picked from aedfe36c7fc590da6c0da3f68818d521fc90028e)
Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko at virtuozzo.com>

diff --git a/mm/memory.c b/mm/memory.c
index 9ee4c80..f13349d 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"
 
@@ -3019,6 +3020,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.
@@ -3229,7 +3232,8 @@ vm_fault_t do_swap_page(struct vm_fault *vmf)
 	pte_unmap_unlock(vmf->pte, vmf->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;
@@ -3415,7 +3419,8 @@ static vm_fault_t __do_fault(struct vm_fault *vmf)
 		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();
 
 	return ret;
-- 
1.8.3.1



More information about the Devel mailing list