[rh7,v3,3/4] /proc/vz/latency: distinguish atomic allocations in irq from in task atomics.

Submitted by Andrey Ryabinin on Aug. 23, 2018, 4:12 p.m.

Details

Message ID 20180823161248.18657-3-aryabinin@virtuozzo.com
State New
Series "Series without cover letter"
Headers show

Commit Message

Andrey Ryabinin Aug. 23, 2018, 4:12 p.m.
Add to /proc/vz/latency 'alocirq' allocation type which shows allocation latencies
done in irq contexts. 'alocatomic' now shows atomic allocations in task contexts.
Also add 'Per-CPU alloc irq' which shows per-cpu 'alocirq' numbers.

Example of new output:

Version: 2.6

Latencies:
Type                         Lat            Total_lat                Calls
scheduling:                    0                    0                    0
alocatomic:                    0                    0                27615
aloclow:                 2000000            738000000              3166625
alochigh:                      0                    0                    0
aloclowmp:                     0              4000000                15677
alochighmp:                    0                    0                    0
alocirq:                 1000000             81000000               292975
swap_in:                   10710              1553913                   25
page_in:                   50850           1141057002              2092877

Averages:
Type                        Avg1                 Avg5                Avg15
scheduling:                    0                    0                    0
alocatomic:                    0                    0                    0
aloclow:                  558150               313968               165801
alochigh:                      0                    0                    0
aloclowmp:                  5535                 9701                 4629
alochighmp:                    0                    0                    0
alocirq:                  309600               163409                66832
swap_in:                   29962                18540                 7244
page_in:                  177194                60133                29625

Per-CPU alloc irq:
Type                         Lat            Total_lat                Calls
cpu0                           0                    0                    3
cpu1                           0                    0                    0
cpu2                           0                    0                    0
cpu3                     1000000             87000000               316298

https://jira.sw.ru/browse/PSBM-87797
Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
Cc: Pavel Borzenkov <Pavel.Borzenkov@acronis.com>
---
 include/linux/kstat.h |  1 +
 kernel/ve/vzstat.c    | 21 +++++++++++++++++++--
 mm/page_alloc.c       | 10 +++++++---
 3 files changed, 27 insertions(+), 5 deletions(-)

Patch hide | download patch | download mbox

diff --git a/include/linux/kstat.h b/include/linux/kstat.h
index 4fff25bcb93f..b268752f2e15 100644
--- a/include/linux/kstat.h
+++ b/include/linux/kstat.h
@@ -7,6 +7,7 @@  enum {
 	KSTAT_ALLOCSTAT_HIGH,
 	KSTAT_ALLOCSTAT_LOW_MP,
 	KSTAT_ALLOCSTAT_HIGH_MP,
+	KSTAT_ALLOCSTAT_IRQ,
 	KSTAT_ALLOCSTAT_NR,
 };
 
diff --git a/kernel/ve/vzstat.c b/kernel/ve/vzstat.c
index 69cbb38210c0..c8cb0b525aae 100644
--- a/kernel/ve/vzstat.c
+++ b/kernel/ve/vzstat.c
@@ -7,6 +7,7 @@ 
 
 #include <linux/sched.h>
 #include <linux/module.h>
+#include <linux/cpu.h>
 #include <linux/mm.h>
 #include <linux/ve.h>
 #include <linux/ve_proto.h>
@@ -32,7 +33,8 @@  static const char *alloc_descr[KSTAT_ALLOCSTAT_NR] = {
 	"aloclow:",
 	"alochigh:",
 	"aloclowmp:",
-	"alochighmp:"
+	"alochighmp:",
+	"alocirq:"
 };
 
 /*
@@ -175,11 +177,12 @@  static void avglat_seq_show(struct seq_file *m,
 static int latency_seq_show(struct seq_file *m, void *v)
 {
 	int i;
+	int cpu;
 
 	if (!v)
 		return 0;
 
-	seq_puts(m, "Version: 2.5\n");
+	seq_puts(m, "Version: 2.6\n");
 
 	seq_puts(m, "\nLatencies:\n");
 	seq_printf(m, "%-11s %20s %20s %20s\n",
@@ -201,6 +204,20 @@  static int latency_seq_show(struct seq_file *m, void *v)
 	avglat_seq_show(m, "swap_in:", kstat_glob.swap_in.avg);
 	avglat_seq_show(m, "page_in:", kstat_glob.page_in.avg);
 
+	seq_puts(m, "\nPer-CPU alloc irq:\n");
+	seq_printf(m, "%-11s %20s %20s %20s\n",
+			"Type", "Lat", "Total_lat", "Calls");
+
+	get_online_cpus();
+	for_each_online_cpu(cpu) {
+		struct kstat_lat_pcpu_snap_struct *snap;
+
+		snap = per_cpu_ptr(kstat_glob.alloc_lat[KSTAT_ALLOCSTAT_IRQ].cur, cpu);
+		seq_printf(m, "cpu%-8d %20Lu %20Lu %20lu\n", cpu,
+			snap->maxlat, snap->totlat, snap->count);
+	}
+	put_online_cpus();
+
 	return 0;
 }
 
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 179bb0c351b2..9d8c9e4eb970 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -3222,13 +3222,17 @@  static void __alloc_collect_stats(gfp_t gfp_mask, unsigned int order,
 	int ind, cpu;
 
 	time = jiffies_to_usecs(jiffies - time) * 1000;
-	if (!(gfp_mask & __GFP_WAIT))
-		ind = KSTAT_ALLOCSTAT_ATOMIC;
-	else
+	if (!(gfp_mask & __GFP_WAIT)) {
+		if (in_task())
+			ind = KSTAT_ALLOCSTAT_ATOMIC;
+		else
+			ind = KSTAT_ALLOCSTAT_IRQ;
+	} else {
 		if (order > 0)
 			ind = KSTAT_ALLOCSTAT_LOW_MP;
 		else
 			ind = KSTAT_ALLOCSTAT_LOW;
+	}
 
 	local_irq_save(flags);
 	cpu = smp_processor_id();

Comments

Denis V. Lunev Aug. 30, 2018, 11:11 a.m.
On 08/23/2018 07:12 PM, Andrey Ryabinin wrote:
> Add to /proc/vz/latency 'alocirq' allocation type which shows allocation latencies
> done in irq contexts. 'alocatomic' now shows atomic allocations in task contexts.
> Also add 'Per-CPU alloc irq' which shows per-cpu 'alocirq' numbers.
>
> Example of new output:
>
> Version: 2.6
>
> Latencies:
> Type                         Lat            Total_lat                Calls
> scheduling:                    0                    0                    0
> alocatomic:                    0                    0                27615
> aloclow:                 2000000            738000000              3166625
> alochigh:                      0                    0                    0
> aloclowmp:                     0              4000000                15677
> alochighmp:                    0                    0                    0
> alocirq:                 1000000             81000000               292975
> swap_in:                   10710              1553913                   25
> page_in:                   50850           1141057002              2092877
>
> Averages:
> Type                        Avg1                 Avg5                Avg15
> scheduling:                    0                    0                    0
> alocatomic:                    0                    0                    0
> aloclow:                  558150               313968               165801
> alochigh:                      0                    0                    0
> aloclowmp:                  5535                 9701                 4629
> alochighmp:                    0                    0                    0
> alocirq:                  309600               163409                66832
> swap_in:                   29962                18540                 7244
> page_in:                  177194                60133                29625
>
> Per-CPU alloc irq:
> Type                         Lat            Total_lat                Calls
> cpu0                           0                    0                    3
> cpu1                           0                    0                    0
> cpu2                           0                    0                    0
> cpu3                     1000000             87000000               316298
>
> https://jira.sw.ru/browse/PSBM-87797
> Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
> Cc: Pavel Borzenkov <Pavel.Borzenkov@acronis.com>
> ---
>  include/linux/kstat.h |  1 +
>  kernel/ve/vzstat.c    | 21 +++++++++++++++++++--
>  mm/page_alloc.c       | 10 +++++++---
>  3 files changed, 27 insertions(+), 5 deletions(-)
>
> diff --git a/include/linux/kstat.h b/include/linux/kstat.h
> index 4fff25bcb93f..b268752f2e15 100644
> --- a/include/linux/kstat.h
> +++ b/include/linux/kstat.h
> @@ -7,6 +7,7 @@ enum {
>  	KSTAT_ALLOCSTAT_HIGH,
>  	KSTAT_ALLOCSTAT_LOW_MP,
>  	KSTAT_ALLOCSTAT_HIGH_MP,
> +	KSTAT_ALLOCSTAT_IRQ,
>  	KSTAT_ALLOCSTAT_NR,
>  };
>  
> diff --git a/kernel/ve/vzstat.c b/kernel/ve/vzstat.c
> index 69cbb38210c0..c8cb0b525aae 100644
> --- a/kernel/ve/vzstat.c
> +++ b/kernel/ve/vzstat.c
> @@ -7,6 +7,7 @@
>  
>  #include <linux/sched.h>
>  #include <linux/module.h>
> +#include <linux/cpu.h>
>  #include <linux/mm.h>
>  #include <linux/ve.h>
>  #include <linux/ve_proto.h>
> @@ -32,7 +33,8 @@ static const char *alloc_descr[KSTAT_ALLOCSTAT_NR] = {
>  	"aloclow:",
>  	"alochigh:",
>  	"aloclowmp:",
> -	"alochighmp:"
> +	"alochighmp:",
> +	"alocirq:"
>  };
>  
>  /*
> @@ -175,11 +177,12 @@ static void avglat_seq_show(struct seq_file *m,
>  static int latency_seq_show(struct seq_file *m, void *v)
>  {
>  	int i;
> +	int cpu;
>  
>  	if (!v)
>  		return 0;
>  
> -	seq_puts(m, "Version: 2.5\n");
> +	seq_puts(m, "Version: 2.6\n");
>  
>  	seq_puts(m, "\nLatencies:\n");
>  	seq_printf(m, "%-11s %20s %20s %20s\n",
> @@ -201,6 +204,20 @@ static int latency_seq_show(struct seq_file *m, void *v)
>  	avglat_seq_show(m, "swap_in:", kstat_glob.swap_in.avg);
>  	avglat_seq_show(m, "page_in:", kstat_glob.page_in.avg);
>  
> +	seq_puts(m, "\nPer-CPU alloc irq:\n");
> +	seq_printf(m, "%-11s %20s %20s %20s\n",
> +			"Type", "Lat", "Total_lat", "Calls");
> +
> +	get_online_cpus();
> +	for_each_online_cpu(cpu) {
> +		struct kstat_lat_pcpu_snap_struct *snap;
> +
> +		snap = per_cpu_ptr(kstat_glob.alloc_lat[KSTAT_ALLOCSTAT_IRQ].cur, cpu);
> +		seq_printf(m, "cpu%-8d %20Lu %20Lu %20lu\n", cpu,
> +			snap->maxlat, snap->totlat, snap->count);
> +	}
> +	put_online_cpus();
> +
>  	return 0;
>  }
>  
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 179bb0c351b2..9d8c9e4eb970 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -3222,13 +3222,17 @@ static void __alloc_collect_stats(gfp_t gfp_mask, unsigned int order,
>  	int ind, cpu;
>  
>  	time = jiffies_to_usecs(jiffies - time) * 1000;
> -	if (!(gfp_mask & __GFP_WAIT))
> -		ind = KSTAT_ALLOCSTAT_ATOMIC;
> -	else
> +	if (!(gfp_mask & __GFP_WAIT)) {
> +		if (in_task())
> +			ind = KSTAT_ALLOCSTAT_ATOMIC;
> +		else
> +			ind = KSTAT_ALLOCSTAT_IRQ;
> +	} else {
>  		if (order > 0)
>  			ind = KSTAT_ALLOCSTAT_LOW_MP;
>  		else
>  			ind = KSTAT_ALLOCSTAT_LOW;
> +	}
>  
>  	local_irq_save(flags);
>  	cpu = smp_processor_id();
Reviewed-by: Denis V. Lunev <den@openvz.org>