Vstorage wants per-task allocation latencies.
This adds /proc/<pid>/vz_latency which outputs max/total latencies
and count of allocation attempts.

https://jira.sw.ru/browse/PSBM-81395
Signed-off-by: Andrey Ryabinin <aryabi...@virtuozzo.com>
---
 fs/proc/base.c        | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/sched.h |  5 +++++
 mm/page_alloc.c       |  7 +++++++
 3 files changed, 58 insertions(+)

diff --git a/fs/proc/base.c b/fs/proc/base.c
index 4c29a4f026ab..731876f87d98 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,48 @@ 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, "%-11s %20Lu %20Lu %20lu\n", name,
+                       snap->maxlat, 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[KSTAT_ALLOCSTAT_NR] = {
+               "alocatomic:",
+               "aloc:",
+               "alocmp:",
+       };
+
+       seq_puts(m, "\nLatencies:\n");
+       seq_printf(m, "%-11s %20s %20s %20s\n",
+                       "Type", "Lat", "Total_lat", "Calls");
+       for (i = 0; i < KSTAT_ALLOCSTAT_NR; i++)
+               lastlat_seq_show(m, alloc_descr[i],
+                               &task->alloc_lat[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 +3054,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..7199c7b3365e 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,10 @@ struct task_struct {
 #ifdef CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH
        struct tlbflush_unmap_batch tlb_ubc;
 #endif
+#ifdef CONFIG_VE
+       unsigned long alloc_fails[KSTAT_ALLOCSTAT_NR];
+       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 9e68b5cac28b..530754e6cf32 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -3156,8 +3156,15 @@ 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);
+
+       if (current->alloc_lat[ind].maxlat < time)
+               current->alloc_lat[ind].maxlat = 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
 }
-- 
2.13.6

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

Reply via email to