diff -urNp 2.4.19pre10aa3/fs/proc/proc_misc.c buddy/fs/proc/proc_misc.c --- 2.4.19pre10aa3/fs/proc/proc_misc.c Thu Jun 20 03:33:28 2002 +++ buddy/fs/proc/proc_misc.c Thu Jun 20 03:34:42 2002 @@ -213,6 +213,21 @@ static int meminfo_read_proc(char *page, #undef K } +extern int buddyinfo(char *buf, int node_id); + +int buddyinfo_read_proc(char *page, char **start, off_t off, + int count, int *eof, void *data) +{ + int node_id; + int len = 0; + + for (node_id = 0; node_id < numnodes; node_id++) { + len += buddyinfo(page+len, node_id); + } + + return proc_calc_metrics(page, start, off, count, eof, len); +} + static int version_read_proc(char *page, char **start, off_t off, int count, int *eof, void *data) { @@ -675,4 +690,7 @@ void __init proc_misc_init(void) entry->proc_fops = &ppc_htab_operations; } #endif + + create_proc_read_entry("buddyinfo", S_IWUSR | S_IRUGO, NULL, + buddyinfo_read_proc, NULL); } diff -urNp 2.4.19pre10aa3/mm/page_alloc.c buddy/mm/page_alloc.c --- 2.4.19pre10aa3/mm/page_alloc.c Thu Jun 20 03:33:24 2002 +++ buddy/mm/page_alloc.c Thu Jun 20 03:33:42 2002 @@ -1039,3 +1039,38 @@ static int __init setup_lower_zone_reser } __setup("lower_zone_reserve=", setup_lower_zone_reserve); + +/* + * This walks the freelist for each zone. Whilst this is slow, I'd rather + * be slow here than slow down the fast path by keeping stats - mjbligh + */ +int buddyinfo(char *buf, int node_id) +{ + int zone_id, order, free, len = 0; + unsigned long flags; + zone_t *zone; + free_area_t * area; + struct list_head *head, *curr; + + for (zone_id = 0; zone_id < MAX_NR_ZONES; ++zone_id) { + zone = &(NODE_DATA(node_id)->node_zones[zone_id]); + if (zone->size == 0) + continue; + spin_lock_irqsave(&zone->lock, flags); + len += sprintf(buf+len, "Node %d, Zone %8s, ", + node_id, zone->name); + for (order = 0; order < MAX_ORDER; ++order) { + area = zone->free_area + order; + head = &area->free_list; + free = 0; + for (curr = head->next; curr != head; curr = curr->next) + ++free; + len += sprintf(buf+len, "%d ", free); + } + len += sprintf(buf+len, "\n"); + spin_unlock_irqrestore(&zone->lock, flags); + } + + return len; +} +