The patch titled Light weight counters: framework has been added to the -mm tree. Its filename is light-weight-counters-framework.patch See http://www.zip.com.au/~akpm/linux/patches/stuff/added-to-mm.txt to find out what to do about this ------------------------------------------------------ Subject: Light weight counters: framework From: Christoph Lameter <clameter@xxxxxxx> The remaining counters in page_state after the zoned VM counter patch has been applied are all just for show in /proc/vmstat. They have no essential function for the VM and therefore maybe we can make these counters lightweight by making them per cpu and ignoring races. We can then get away without disabling interrupts for these counters. The patchset also adds an off switch for embedded systems that allows a building of linux kernels without these counters. This may be one case in which perhaps Andi's local_t can come into play to avoid per cpu races on x86_64 and i386 in a light weight way. However, for all other platforms we would not want the fallback to an atomic type. The implementation of these counters is through inline code that typically results in a simple increment of a global memory locations. Also - Rename page_state to event_state - Make event state an array indexed by the event item like the zoned counters. Caveat: If user space tools rely on these counters being accurate on SMP and UP then this won't work. Signed-off-by: Christoph Lameter <clameter@xxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxx> --- include/linux/page-flags.h | 167 ++++++++++++----------------------- init/Kconfig | 9 + mm/page_alloc.c | 101 ++++++++------------- 3 files changed, 107 insertions(+), 170 deletions(-) diff -puN include/linux/page-flags.h~light-weight-counters-framework include/linux/page-flags.h --- 25/include/linux/page-flags.h~light-weight-counters-framework Fri Jun 9 15:01:26 2006 +++ 25-akpm/include/linux/page-flags.h Fri Jun 9 15:01:26 2006 @@ -102,121 +102,70 @@ #define PG_uncached 31 /* Page has been mapped as uncached */ #endif +#ifdef CONFIG_VM_EVENT_COUNTERS /* - * Global page accounting. One instance per CPU. Only unsigned longs are - * allowed. + * Light weight per cpu counter implementation. * - * - Fields can be modified with xxx_page_state and xxx_page_state_zone at - * any time safely (which protects the instance from modification by - * interrupt. - * - The __xxx_page_state variants can be used safely when interrupts are - * disabled. - * - The __xxx_page_state variants can be used if the field is only - * modified from process context and protected from preemption, or only - * modified from interrupt context. In this case, the field should be - * commented here. + * Note that these can race. We do not bother to enable preemption + * or care about interrupt races. All we care about is to have some + * approximate count of events. + * + * Counters should only be incremented and no critical kernel component + * should rely on the counter values. + * + * Counters are handled completely inline. On many platforms the code + * generated will simply be the increment of a global address. */ -struct page_state { - /* - * The below are zeroed by get_page_state(). Use get_full_page_state() - * to add up all these. - */ - unsigned long pgpgin; /* Disk reads */ - unsigned long pgpgout; /* Disk writes */ - unsigned long pswpin; /* swap reads */ - unsigned long pswpout; /* swap writes */ - - unsigned long pgalloc_high; /* page allocations */ - unsigned long pgalloc_normal; - unsigned long pgalloc_dma32; - unsigned long pgalloc_dma; - - unsigned long pgfree; /* page freeings */ - unsigned long pgactivate; /* pages moved inactive->active */ - unsigned long pgdeactivate; /* pages moved active->inactive */ - - unsigned long pgfault; /* faults (major+minor) */ - unsigned long pgmajfault; /* faults (major only) */ - - unsigned long pgrefill_high; /* inspected in refill_inactive_zone */ - unsigned long pgrefill_normal; - unsigned long pgrefill_dma32; - unsigned long pgrefill_dma; - - unsigned long pgsteal_high; /* total highmem pages reclaimed */ - unsigned long pgsteal_normal; - unsigned long pgsteal_dma32; - unsigned long pgsteal_dma; - - unsigned long pgscan_kswapd_high;/* total highmem pages scanned */ - unsigned long pgscan_kswapd_normal; - unsigned long pgscan_kswapd_dma32; - unsigned long pgscan_kswapd_dma; - - unsigned long pgscan_direct_high;/* total highmem pages scanned */ - unsigned long pgscan_direct_normal; - unsigned long pgscan_direct_dma32; - unsigned long pgscan_direct_dma; - - unsigned long pginodesteal; /* pages reclaimed via inode freeing */ - unsigned long slabs_scanned; /* slab objects scanned */ - unsigned long kswapd_steal; /* pages reclaimed by kswapd */ - unsigned long kswapd_inodesteal;/* reclaimed via kswapd inode freeing */ - unsigned long pageoutrun; /* kswapd's calls to page reclaim */ - unsigned long allocstall; /* direct reclaim calls */ +#define FOR_ALL_ZONES(x) x##_DMA, x##_DMA32, x##_NORMAL, x##_HIGH + +enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT, + FOR_ALL_ZONES(PGALLOC), + PGFREE, PGACTIVATE, PGDEACTIVATE, + PGFAULT, PGMAJFAULT, + FOR_ALL_ZONES(PGREFILL), + FOR_ALL_ZONES(PGSTEAL), + FOR_ALL_ZONES(PGSCAN_KSWAPD), + FOR_ALL_ZONES(PGSCAN_DIRECT), + PGINODESTEAL, SLABS_SCANNED, KSWAPD_STEAL, KSWAPD_INODESTEAL, + PAGEOUTRUN, ALLOCSTALL, PGROTATED, + NR_VM_EVENT_ITEMS +}; - unsigned long pgrotated; /* pages rotated to tail of the LRU */ +struct vm_event_state { + unsigned long event[NR_VM_EVENT_ITEMS]; }; -extern void get_full_page_state(struct page_state *ret); -extern unsigned long read_page_state_offset(unsigned long offset); -extern void mod_page_state_offset(unsigned long offset, unsigned long delta); -extern void __mod_page_state_offset(unsigned long offset, unsigned long delta); - -#define read_page_state(member) \ - read_page_state_offset(offsetof(struct page_state, member)) - -#define mod_page_state(member, delta) \ - mod_page_state_offset(offsetof(struct page_state, member), (delta)) - -#define __mod_page_state(member, delta) \ - __mod_page_state_offset(offsetof(struct page_state, member), (delta)) - -#define inc_page_state(member) mod_page_state(member, 1UL) -#define dec_page_state(member) mod_page_state(member, 0UL - 1) -#define add_page_state(member,delta) mod_page_state(member, (delta)) -#define sub_page_state(member,delta) mod_page_state(member, 0UL - (delta)) - -#define __inc_page_state(member) __mod_page_state(member, 1UL) -#define __dec_page_state(member) __mod_page_state(member, 0UL - 1) -#define __add_page_state(member,delta) __mod_page_state(member, (delta)) -#define __sub_page_state(member,delta) __mod_page_state(member, 0UL - (delta)) - -#define page_state(member) (*__page_state(offsetof(struct page_state, member))) - -#define state_zone_offset(zone, member) \ -({ \ - unsigned offset; \ - if (is_highmem(zone)) \ - offset = offsetof(struct page_state, member##_high); \ - else if (is_normal(zone)) \ - offset = offsetof(struct page_state, member##_normal); \ - else if (is_dma32(zone)) \ - offset = offsetof(struct page_state, member##_dma32); \ - else \ - offset = offsetof(struct page_state, member##_dma); \ - offset; \ -}) - -#define __mod_page_state_zone(zone, member, delta) \ - do { \ - __mod_page_state_offset(state_zone_offset(zone, member), (delta)); \ - } while (0) - -#define mod_page_state_zone(zone, member, delta) \ - do { \ - mod_page_state_offset(state_zone_offset(zone, member), (delta)); \ - } while (0) +DECLARE_PER_CPU(struct vm_event_state, vm_event_states); + +extern unsigned long get_global_vm_events(enum vm_event_item e); +extern void sum_vm_events(unsigned long *r, cpumask_t *cpumask); +extern void all_vm_events(unsigned long *r); + +static inline unsigned long get_cpu_vm_events(enum vm_event_item item) +{ + return __get_cpu_var(vm_event_states).event[item]; +} + +static inline void count_vm_event(enum vm_event_item item) +{ + __get_cpu_var(vm_event_states).event[item]++; +} + +static inline void count_vm_events(enum vm_event_item item, long delta) +{ + __get_cpu_var(vm_event_states).event[item] += delta; +} + +#else +/* Disable counters */ +#define get_cpu_vm_events(e) 0L +#define get_global_vm_events(e) 0L +#define count_vm_event(e) do { } while (0) +#define count_vm_events(e,d) do { } while (0) +#endif + +#define count_zone_vm_event(item, zone) count_vm_event(item##_DMA + zone_idx(zone)) +#define count_zone_vm_events(item, zone, delta) count_vm_events(item##_DMA + zone_idx(zone), delta) /* * Zone based accounting with per cpu differentials. diff -puN init/Kconfig~light-weight-counters-framework init/Kconfig --- 25/init/Kconfig~light-weight-counters-framework Fri Jun 9 15:01:26 2006 +++ 25-akpm/init/Kconfig Fri Jun 9 15:01:26 2006 @@ -387,6 +387,15 @@ config SLOB default !SLAB bool +config VM_EVENT_COUNTERS + default y + bool "Enable event counters for /proc/vmstat" if EMBEDDED + help + Event counters are only needed to display statistics. They + have no function for the kernel itself. This option allows + the disabling of the event counters. /proc/vmstat will only + contain essential counters. + menu "Loadable module support" config MODULES diff -puN mm/page_alloc.c~light-weight-counters-framework mm/page_alloc.c --- 25/mm/page_alloc.c~light-weight-counters-framework Fri Jun 9 15:01:26 2006 +++ 25-akpm/mm/page_alloc.c Fri Jun 9 15:01:26 2006 @@ -1509,79 +1509,50 @@ static void show_node(struct zone *zone) #define show_node(zone) do { } while (0) #endif -/* - * Accumulate the page_state information across all CPUs. - * The result is unavoidably approximate - it can change - * during and after execution of this function. - */ -static DEFINE_PER_CPU(struct page_state, page_states) = {0}; +#ifdef CONFIG_VM_EVENT_COUNTERS +DEFINE_PER_CPU(struct vm_event_state, vm_event_states) = {{0}}; -static void __get_page_state(struct page_state *ret, int nr, cpumask_t *cpumask) +void sum_vm_events(unsigned long *ret, cpumask_t *cpumask) { - unsigned cpu; + int cpu = 0; + int i; - memset(ret, 0, nr * sizeof(unsigned long)); - cpus_and(*cpumask, *cpumask, cpu_online_map); + memset(ret, 0, NR_VM_EVENT_ITEMS * sizeof(unsigned long)); - for_each_cpu_mask(cpu, *cpumask) { - unsigned long *in; - unsigned long *out; - unsigned off; - unsigned next_cpu; + cpu = first_cpu(*cpumask); + while (cpu < NR_CPUS) { + struct vm_event_state *this = &per_cpu(vm_event_states, cpu); - in = (unsigned long *)&per_cpu(page_states, cpu); + cpu = next_cpu(cpu, *cpumask); - next_cpu = next_cpu(cpu, *cpumask); - if (likely(next_cpu < NR_CPUS)) - prefetch(&per_cpu(page_states, next_cpu)); + if (cpu < NR_CPUS) + prefetch(&per_cpu(vm_event_states, cpu)); - out = (unsigned long *)ret; - for (off = 0; off < nr; off++) - *out++ += *in++; + + for (i=0; i< NR_VM_EVENT_ITEMS; i++) + ret[i] += this->event[i]; } } +EXPORT_SYMBOL(sum_vm_events); -void get_full_page_state(struct page_state *ret) +void all_vm_events(unsigned long *ret) { - cpumask_t mask = CPU_MASK_ALL; - - __get_page_state(ret, sizeof(*ret) / sizeof(unsigned long), &mask); + sum_vm_events(ret, &cpu_online_map); } +EXPORT_SYMBOL(all_vm_events); -unsigned long read_page_state_offset(unsigned long offset) +unsigned long get_global_vm_events(enum vm_event_item e) { unsigned long ret = 0; int cpu; - for_each_online_cpu(cpu) { - unsigned long in; + for_each_possible_cpu(cpu) + ret += per_cpu(vm_event_states, cpu).event[e]; - in = (unsigned long)&per_cpu(page_states, cpu) + offset; - ret += *((unsigned long *)in); - } return ret; } - -void __mod_page_state_offset(unsigned long offset, unsigned long delta) -{ - void *ptr; - - ptr = &__get_cpu_var(page_states); - *(unsigned long *)(ptr + offset) += delta; -} -EXPORT_SYMBOL(__mod_page_state_offset); - -void mod_page_state_offset(unsigned long offset, unsigned long delta) -{ - unsigned long flags; - void *ptr; - - local_irq_save(flags); - ptr = &__get_cpu_var(page_states); - *(unsigned long *)(ptr + offset) += delta; - local_irq_restore(flags); -} -EXPORT_SYMBOL(mod_page_state_offset); +EXPORT_SYMBOL(get_global_vm_events); +#endif void __get_zone_counts(unsigned long *active, unsigned long *inactive, unsigned long *free, struct pglist_data *pgdat) @@ -2700,7 +2671,7 @@ static char *vmstat_text[] = { "nr_unstable", "nr_bounce", - /* Page state */ +#ifdef CONFIG_VM_EVENT_COUNTERS "pgpgin", "pgpgout", "pswpin", @@ -2746,28 +2717,36 @@ static char *vmstat_text[] = { "allocstall", "pgrotated" +#endif }; static void *vmstat_start(struct seq_file *m, loff_t *pos) { unsigned long *v; - struct page_state *ps; +#ifdef CONFIG_VM_EVENT_COUNTERS + unsigned long *e; +#endif int i; if (*pos >= ARRAY_SIZE(vmstat_text)) return NULL; - +#ifdef CONFIG_VM_EVENT_COUNTERS v = kmalloc(NR_STAT_ITEMS * sizeof(unsigned long) - + sizeof(struct page_state), GFP_KERNEL); + + sizeof(struct vm_event_state), GFP_KERNEL); +#else + v = kmalloc(NR_STAT_ITEMS * sizeof(unsigned long), GFP_KERNEL); +#endif m->private = v; if (!v) return ERR_PTR(-ENOMEM); for (i = 0; i < NR_STAT_ITEMS; i++) v[i] = global_page_state(i); - ps = (struct page_state *)(v + NR_STAT_ITEMS); - get_full_page_state(ps); - ps->pgpgin /= 2; /* sectors -> kbytes */ - ps->pgpgout /= 2; +#ifdef CONFIG_VM_EVENT_COUNTERS + e = v + NR_STAT_ITEMS; + all_vm_events(e); + e[PGPGIN] /= 2; /* sectors -> kbytes */ + e[PGPGOUT] /= 2; +#endif return v + *pos; } _ Patches currently in -mm which might be from clameter@xxxxxxx are page-migration-make-do_swap_page-redo-the-fault.patch slab-extract-cache_free_alien-from-__cache_free.patch migration-remove-unnecessary-pageswapcache-checks.patch page-migration-cleanup-rename-ignrefs-to-migration.patch page-migration-cleanup-group-functions.patch page-migration-cleanup-remove-useless-definitions.patch page-migration-cleanup-drop-nr_refs-in-remove_references.patch page-migration-cleanup-extract-try_to_unmap-from-migration-functions.patch page-migration-cleanup-pass-mapping-to-migration-functions.patch page-migration-cleanup-move-fallback-handling-into-special-function.patch swapless-pm-add-r-w-migration-entries.patch swapless-page-migration-rip-out-swap-based-logic.patch swapless-page-migration-modify-core-logic.patch more-page-migration-do-not-inc-dec-rss-counters.patch more-page-migration-use-migration-entries-for-file-pages.patch page-migration-update-documentation.patch mm-remove-vm_locked-before-remap_pfn_range-and-drop-vm_shm.patch page-migration-simplify-migrate_pages.patch page-migration-simplify-migrate_pages-tweaks.patch page-migration-handle-freeing-of-pages-in-migrate_pages.patch page-migration-use-allocator-function-for-migrate_pages.patch page-migration-support-moving-of-individual-pages.patch page-migration-detailed-status-for-moving-of-individual-pages.patch page-migration-support-moving-of-individual-pages-fixes.patch page-migration-support-moving-of-individual-pages-x86_64-support.patch page-migration-support-moving-of-individual-pages-x86-support.patch page-migration-support-a-vma-migration-function.patch allow-migration-of-mlocked-pages.patch zoned-vm-counters-per-zone-counter-functionality.patch zoned-vm-counters-per-zone-counter-functionality-tidy.patch zoned-vm-counters-per-zone-counter-functionality-fix-fix.patch zoned-vm-counters-include-per-zone-counters-in-proc-vmstat.patch zoned-vm-counters-conversion-of-nr_mapped-to-per-zone-counter.patch zoned-vm-counters-conversion-of-nr_pagecache-to-per-zone-counter.patch zoned-vm-counters-conversion-of-nr_pagecache-to-per-zone-counter-fix.patch zoned-vm-counters-use-per-zone-counters-to-remove-zone_reclaim_interval.patch zoned-vm-counters-add-per-zone-counters-to-zone-node-and-global-vm-statistics.patch zoned-vm-counters-conversion-of-nr_slab-to-per-zone-counter.patch zoned-vm-counters-conversion-of-nr_pagetable-to-per-zone-counter.patch zoned-vm-counters-conversion-of-nr_dirty-to-per-zone-counter.patch zoned-vm-counters-conversion-of-nr_writeback-to-per-zone-counter.patch zoned-vm-counters-conversion-of-nr_unstable-to-per-zone-counter.patch zoned-vm-counters-remove-unused-get_page_stat-functions.patch zoned-vm-counters-conversion-of-nr_bounce-to-per-zone-counter.patch zoned-vm-counters-remove-useless-writeback-structure.patch zoned-vm-stats-remove-nr_mapped-from-zone-reclaim.patch zoned-vm-stats-add-nr_anon.patch light-weight-counters-framework.patch light-weight-counters-counter-conversion.patch cpuset-remove-extra-cpuset_zone_allowed-check-in-__alloc_pages.patch swap_prefetch-conversion-of-nr_mapped-to-per-zone-counter.patch swap_prefetch-conversion-of-nr_slab-to-per-zone-counter.patch swap_prefetch-conversion-of-nr_dirty-to-per-zone-counter.patch swap_prefetch-conversion-of-nr_writeback-to-per-zone-counter.patch swap_prefetch-conversion-of-nr_unstable-to-per-zone-counter.patch swap_prefetch-remove-unused-get_page_stat-functions.patch zoned-vm-stats-nr_slab-is-accurate-fix-comment.patch swap_prefetch-zoned-vm-stats-add-nr_anon.patch reiser4-conversion-of-nr_dirty-to-per-zone-counter.patch - To unsubscribe from this list: send the line "unsubscribe mm-commits" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html