[Devel] [PATCH rh7 v2 3/3] ve/page_alloc, kstat: account allocation latencies per-task

Pavel Borzenkov Pavel.Borzenkov at acronis.com
Thu Feb 15 18:13:40 MSK 2018



> On 15 Feb 2018, at 18:07, Andrey Ryabinin <aryabinin at virtuozzo.com> wrote:
> 
> [pborzenkov at virtuozzo.com didn't work, retrying via Pavel.Borzenkov at acronis.com]
> 
> On 02/15/2018 05:48 PM, Andrey Ryabinin wrote:
>> Vstorage wants per-process allocation latencies:
>> 
>> - total accumulated latency (total time spent inside the kernel allocator)
>> - total alloc attempts (so that average latency can be calculated)
>> 
>> This adds /proc/<pid>/vz_latency file which outputs the numbers:
>> 
>> Type                   Total_lat                Calls
>> allocatomic:                    0                 1334
>> alloc:                    8000000                36643
>> allocmp:                        0                  919
>> 
> 
> Pavel, are you ok with that format? 

Yes

> 
> 
>> https://jira.sw.ru/browse/PSBM-81395
>> Signed-off-by: Andrey Ryabinin <aryabinin at virtuozzo.com>
>> Cc: Pavel Borzenkov <pborzenkov at virtuozzo.com>
>> ---
>> fs/proc/base.c        | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
>> include/linux/sched.h |  4 ++++
>> mm/page_alloc.c       |  5 +++++
>> 3 files changed, 60 insertions(+)
>> 
>> diff --git a/fs/proc/base.c b/fs/proc/base.c
>> index 4c29a4f026ab..5646a351c076 100644
>> --- a/fs/proc/base.c
>> +++ b/fs/proc/base.c
>> @@ -55,6 +55,7 @@
>> #include <linux/stat.h>
>> #include <linux/task_io_accounting_ops.h>
>> #include <linux/init.h>
>> +#include <linux/kstat.h>
>> #include <linux/capability.h>
>> #include <linux/file.h>
>> #include <linux/fdtable.h>
>> @@ -574,6 +575,53 @@ static const struct file_operations proc_lstats_operations = {
>> 
>> #endif
>> 
>> +#ifdef CONFIG_VE
>> +static void lastlat_seq_show(struct seq_file *m,
>> +		const char *name,
>> +		struct kstat_lat_snap_struct *snap)
>> +{
>> +	seq_printf(m, "%-12s %20Lu %20lu\n", name,
>> +			snap->totlat, snap->count);
>> +}
>> +
>> +static int vz_lat_show_proc(struct seq_file *m, void *v)
>> +{
>> +	int i;
>> +	struct inode *inode = m->private;
>> +	struct task_struct *task = get_proc_task(inode);
>> +	static const char *alloc_descr[] = {
>> +		"allocatomic:",
>> +		"alloc:",
>> +		"allocmp:",
>> +	};
>> +	static const int alloc_types[] = {
>> +		KSTAT_ALLOCSTAT_ATOMIC,
>> +		KSTAT_ALLOCSTAT_LOW,
>> +		KSTAT_ALLOCSTAT_LOW_MP,
>> +	};
>> +
>> +	seq_printf(m, "%-11s %20s %20s\n",
>> +			"Type", "Total_lat", "Calls");
>> +
>> +	for (i = 0; i < ARRAY_SIZE(alloc_types); i++)
>> +		lastlat_seq_show(m, alloc_descr[i],
>> +				&task->alloc_lat[alloc_types[i]]);
>> +	return 0;
>> +}
>> +
>> +static int vz_lat_open(struct inode *inode, struct file *file)
>> +{
>> +	return single_open(file, vz_lat_show_proc, inode);
>> +}
>> +
>> +static const struct file_operations proc_vz_lat_operations = {
>> +	.open		= vz_lat_open,
>> +	.read		= seq_read,
>> +	.llseek		= seq_lseek,
>> +	.release	= single_release,
>> +};
>> +#endif
>> +
>> #ifdef CONFIG_CGROUPS
>> static int cgroup_open(struct inode *inode, struct file *file)
>> {
>> @@ -3011,6 +3059,9 @@ static const struct pid_entry tgid_base_stuff[] = {
>> 	REG("timers",	  S_IRUGO, proc_timers_operations),
>> 	REG("aio",	  S_IRUGO|S_IWUSR, proc_aio_operations),
>> #endif
>> +#ifdef CONFIG_VE
>> +	REG("vz_latency", S_IRUGO, proc_vz_lat_operations),
>> +#endif
>> };
>> 
>> static int proc_tgid_base_readdir(struct file * filp,
>> diff --git a/include/linux/sched.h b/include/linux/sched.h
>> index cc52094b4e97..1595be347b6d 100644
>> --- a/include/linux/sched.h
>> +++ b/include/linux/sched.h
>> @@ -30,6 +30,7 @@ struct sched_param {
>> 
>> #include <linux/smp.h>
>> #include <linux/sem.h>
>> +#include <linux/kstat.h>
>> #include <linux/signal.h>
>> #include <linux/compiler.h>
>> #include <linux/completion.h>
>> @@ -1833,6 +1834,9 @@ struct task_struct {
>> #ifdef CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH
>> 	struct tlbflush_unmap_batch tlb_ubc;
>> #endif
>> +#ifdef CONFIG_VE
>> +	struct kstat_lat_snap_struct alloc_lat[KSTAT_ALLOCSTAT_NR];
>> +#endif
>> #if defined(CONFIG_FUNCTION_GRAPH_TRACER) && defined(CONFIG_S390)
>> 	/* Index of current stored address in ret_stack */
>> 	int curr_ret_stack;
>> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
>> index f08ddeb77b82..fed5d879179f 100644
>> --- a/mm/page_alloc.c
>> +++ b/mm/page_alloc.c
>> @@ -3156,8 +3156,13 @@ static void __alloc_collect_stats(gfp_t gfp_mask, unsigned int order,
>> 	local_irq_save(flags);
>> 	cpu = smp_processor_id();
>> 	KSTAT_LAT_PCPU_ADD(&kstat_glob.alloc_lat[ind], time);
>> +
>> +	current->alloc_lat[ind].totlat += time;
>> +	current->alloc_lat[ind].count++;
>> +
>> 	if (!page)
>> 		kstat_glob.alloc_fails[cpu][ind]++;
>> +
>> 	local_irq_restore(flags);
>> #endif
>> }
>> 




More information about the Devel mailing list