[Devel] [PATCH RHEL8 COMMIT] vzstat: account "page_in" and "swap_in" in nanoseconds

Konstantin Khorenko khorenko at virtuozzo.com
Tue Jun 1 20:29:50 MSK 2021


The commit is pushed to "branch-rh8-4.18.0-240.1.1.vz8.5.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh8-4.18.0-240.1.1.vz8.5.34
------>
commit bfe8875275e22909544cea951830951969a27a69
Author: Konstantin Khorenko <khorenko at virtuozzo.com>
Date:   Tue Jun 1 20:29:50 2021 +0300

    vzstat: account "page_in" and "swap_in" in nanoseconds
    
    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>
    
    Fixes: 928833c25f22 ("core: Add glob_kstat, percpu kstat and account mm stat")
    Fixes: c30a7bebb0e7 ("kstat: Make kstat_glob::swap_in percpu")
    
    (cherry-picked from vz7 commit aedfe36c7fc5 ("vzstat: account "page_in" and
    "swap_in" in nanoseconds"))
    Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko at virtuozzo.com>
---
 mm/memory.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/mm/memory.c b/mm/memory.c
index 9ee4c80bcd0c..f13349d74a06 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;


More information about the Devel mailing list