Commit 79da826aee6a10902ef411bc65864bd02102fa83

Authored by Michael Rubin
Committed by Linus Torvalds
1 parent 2ac390370a

writeback: report dirty thresholds in /proc/vmstat

The kernel already exposes the user desired thresholds in /proc/sys/vm
with dirty_background_ratio and background_ratio.  But the kernel may
alter the number requested without giving the user any indication that is
the case.

Knowing the actual ratios the kernel is honoring can help app developers
understand how their buffered IO will be sent to the disk.

        $ grep threshold /proc/vmstat
        nr_dirty_threshold 409111
        nr_dirty_background_threshold 818223

Signed-off-by: Michael Rubin <mrubin@google.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Dave Chinner <david@fromorbit.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Nick Piggin <nickpiggin@yahoo.com.au>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 1 changed file with 25 additions and 14 deletions Side-by-side Diff

... ... @@ -17,6 +17,7 @@
17 17 #include <linux/vmstat.h>
18 18 #include <linux/sched.h>
19 19 #include <linux/math64.h>
  20 +#include <linux/writeback.h>
20 21  
21 22 #ifdef CONFIG_VM_EVENT_COUNTERS
22 23 DEFINE_PER_CPU(struct vm_event_state, vm_event_states) = {{0}};
... ... @@ -747,6 +748,8 @@
747 748 "nr_shmem",
748 749 "nr_dirtied",
749 750 "nr_written",
  751 + "nr_dirty_threshold",
  752 + "nr_dirty_background_threshold",
750 753  
751 754 #ifdef CONFIG_NUMA
752 755 "numa_hit",
753 756  
754 757  
755 758  
756 759  
757 760  
758 761  
759 762  
... ... @@ -907,36 +910,44 @@
907 910 .release = seq_release,
908 911 };
909 912  
  913 +enum writeback_stat_item {
  914 + NR_DIRTY_THRESHOLD,
  915 + NR_DIRTY_BG_THRESHOLD,
  916 + NR_VM_WRITEBACK_STAT_ITEMS,
  917 +};
  918 +
910 919 static void *vmstat_start(struct seq_file *m, loff_t *pos)
911 920 {
912 921 unsigned long *v;
913   -#ifdef CONFIG_VM_EVENT_COUNTERS
914   - unsigned long *e;
915   -#endif
916   - int i;
  922 + int i, stat_items_size;
917 923  
918 924 if (*pos >= ARRAY_SIZE(vmstat_text))
919 925 return NULL;
  926 + stat_items_size = NR_VM_ZONE_STAT_ITEMS * sizeof(unsigned long) +
  927 + NR_VM_WRITEBACK_STAT_ITEMS * sizeof(unsigned long);
920 928  
921 929 #ifdef CONFIG_VM_EVENT_COUNTERS
922   - v = kmalloc(NR_VM_ZONE_STAT_ITEMS * sizeof(unsigned long)
923   - + sizeof(struct vm_event_state), GFP_KERNEL);
924   -#else
925   - v = kmalloc(NR_VM_ZONE_STAT_ITEMS * sizeof(unsigned long),
926   - GFP_KERNEL);
  930 + stat_items_size += sizeof(struct vm_event_state);
927 931 #endif
  932 +
  933 + v = kmalloc(stat_items_size, GFP_KERNEL);
928 934 m->private = v;
929 935 if (!v)
930 936 return ERR_PTR(-ENOMEM);
931 937 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
932 938 v[i] = global_page_state(i);
  939 + v += NR_VM_ZONE_STAT_ITEMS;
  940 +
  941 + global_dirty_limits(v + NR_DIRTY_BG_THRESHOLD,
  942 + v + NR_DIRTY_THRESHOLD);
  943 + v += NR_VM_WRITEBACK_STAT_ITEMS;
  944 +
933 945 #ifdef CONFIG_VM_EVENT_COUNTERS
934   - e = v + NR_VM_ZONE_STAT_ITEMS;
935   - all_vm_events(e);
936   - e[PGPGIN] /= 2; /* sectors -> kbytes */
937   - e[PGPGOUT] /= 2;
  946 + all_vm_events(v);
  947 + v[PGPGIN] /= 2; /* sectors -> kbytes */
  948 + v[PGPGOUT] /= 2;
938 949 #endif
939   - return v + *pos;
  950 + return m->private + *pos;
940 951 }
941 952  
942 953 static void *vmstat_next(struct seq_file *m, void *arg, loff_t *pos)