From 4b670dde47e0899370182f85b909bcf1f242b722 Mon Sep 17 00:00:00 2001 From: hunt Date: Mon, 29 Jan 2007 20:42:16 +0000 Subject: [PATCH] 2007-01-29 Martin Hunt * alloc.c (_stp_kmalloc): New function. Call kmalloc with the coirrect flags and track usage. (_stp_kzalloc): Ditto. * map.c: Use new alloc calls. * print.c: Ditto. * stat.c: Ditto. * time.c: Ditto. --- runtime/ChangeLog | 9 +++++++++ runtime/alloc.c | 43 +++++++++++++++++++++++++++++++++++++++++-- runtime/map.c | 14 +++++++++----- runtime/print.c | 1 + runtime/stat.c | 4 ++-- runtime/time.c | 1 + 6 files changed, 63 insertions(+), 9 deletions(-) diff --git a/runtime/ChangeLog b/runtime/ChangeLog index fd7e9e91b..29ef88d4b 100644 --- a/runtime/ChangeLog +++ b/runtime/ChangeLog @@ -1,3 +1,12 @@ +2007-01-29 Martin Hunt + * alloc.c (_stp_kmalloc): New function. Call kmalloc + with the coirrect flags and track usage. + (_stp_kzalloc): Ditto. + * map.c: Use new alloc calls. + * print.c: Ditto. + * stat.c: Ditto. + * time.c: Ditto. + 2007-01-25 Roland McGrath * loc2c-runtime.h (store_deref): Use "Zr" constraint for 64-bit case. diff --git a/runtime/alloc.c b/runtime/alloc.c index 4aecd5a81..fe2c84e03 100644 --- a/runtime/alloc.c +++ b/runtime/alloc.c @@ -1,6 +1,6 @@ /* -*- linux-c -*- * Memory allocation functions - * Copyright (C) 2005, 2006 Red Hat Inc. + * Copyright (C) 2005, 2006, 2007 Red Hat Inc. * * This file is part of systemtap, and is free software. You can * redistribute it and/or modify it under the terms of the GNU General @@ -11,9 +11,46 @@ #ifndef _ALLOC_C_ #define _ALLOC_C_ +/* counters of how much memory has been allocated */ +static int _stp_allocated_memory = 0; +static int _stp_allocated_net_memory = 0; #define STP_ALLOC_FLAGS (GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN) -#define _stp_vmalloc(size) __vmalloc(size, STP_ALLOC_FLAGS, PAGE_KERNEL) + +static void *_stp_kmalloc(size_t size) +{ + void *ret = kmalloc(size, STP_ALLOC_FLAGS); + if (ret) + _stp_allocated_memory += size; + return ret; +} + +static void *_stp_kzalloc(size_t size) +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15) +{ + void *ret = kmalloc(size, STP_ALLOC_FLAGS); + if (ret) { + memset (ret, 0, size); + _stp_allocated_memory += size; + } + return ret; +} +#else +{ + void *ret = kzalloc(size, STP_ALLOC_FLAGS); + if (ret) + _stp_allocated_memory += size; + return ret; +} +#endif + +static void *_stp_vmalloc(unsigned long size) +{ + void *ret = __vmalloc(size, STP_ALLOC_FLAGS, PAGE_KERNEL); + if (ret) + _stp_allocated_memory += size; + return ret; +} /* This file exists because all the NUMA-compatible allocators keep changing in 2.6 */ @@ -47,6 +84,8 @@ void *_stp_alloc_percpu(size_t size) if (!pdata->ptrs[i]) goto unwind_oom; + + _stp_allocated_memory += size; memset(pdata->ptrs[i], 0, size); } diff --git a/runtime/map.c b/runtime/map.c index cb866ffee..86a1b2702 100644 --- a/runtime/map.c +++ b/runtime/map.c @@ -210,8 +210,13 @@ static int _stp_map_init(MAP m, unsigned max_entries, int type, int key_size, in tmp = kmalloc_node(size, STP_ALLOC_FLAGS, cpu); if (!tmp) - return -1;; + return -1; + if (cpu < 0) + _stp_allocated_memory += size; + else + _stp_allocated_memory += size * num_online_cpus(); + dbug ("allocated %lx\n", (long)tmp); list_add((struct list_head *)tmp, &m->pool); ((struct map_node *)tmp)->map = m; @@ -225,11 +230,10 @@ static int _stp_map_init(MAP m, unsigned max_entries, int type, int key_size, in static MAP _stp_map_new(unsigned max_entries, int type, int key_size, int data_size) { - MAP m = (MAP) kmalloc(sizeof(struct map_root), STP_ALLOC_FLAGS); + MAP m = (MAP) _stp_kzalloc(sizeof(struct map_root)); if (m == NULL) return NULL; - memset (m, 0, sizeof(struct map_root)); INIT_LIST_HEAD(&m->pool); INIT_LIST_HEAD(&m->head); if (_stp_map_init(m, max_entries, type, key_size, data_size, -1)) { @@ -244,14 +248,14 @@ static PMAP _stp_pmap_new(unsigned max_entries, int type, int key_size, int data int i; MAP map, m; - PMAP pmap = (PMAP) kmalloc(sizeof(struct pmap), STP_ALLOC_FLAGS); + PMAP pmap = (PMAP) _stp_kzalloc(sizeof(struct pmap)); if (pmap == NULL) return NULL; - memset (pmap, 0, sizeof(struct pmap)); pmap->map = map = (MAP) alloc_percpu (struct map_root); if (map == NULL) goto err; + _stp_allocated_memory += sizeof(struct map_root) * num_online_cpus(); /* initialize the memory lists first so if allocations fail */ /* at some point, it is easy to clean up. */ diff --git a/runtime/print.c b/runtime/print.c index eaea688d9..d305dee89 100644 --- a/runtime/print.c +++ b/runtime/print.c @@ -55,6 +55,7 @@ int _stp_print_init (void) Stp_pbuf = alloc_percpu(_stp_pbuf); if (unlikely(Stp_pbuf == 0)) return -1; + _stp_allocated_memory += sizeof(_stp_pbuf) * num_online_cpus(); return 0; } diff --git a/runtime/stat.c b/runtime/stat.c index c1bf07b12..e00b82201 100644 --- a/runtime/stat.c +++ b/runtime/stat.c @@ -96,7 +96,7 @@ Stat _stp_stat_init (int type, ...) } va_end (ap); } - st = (Stat) kmalloc (sizeof(struct _Stat), STP_ALLOC_FLAGS); + st = (Stat) _stp_kmalloc (sizeof(struct _Stat)); if (st == NULL) return NULL; @@ -115,7 +115,7 @@ Stat _stp_stat_init (int type, ...) } #endif - agg = (stat *)kmalloc (size, STP_ALLOC_FLAGS); + agg = (stat *)_stp_kmalloc(size); if (agg == NULL) goto exit2; diff --git a/runtime/time.c b/runtime/time.c index a6b33aa8c..7f9b5ffae 100644 --- a/runtime/time.c +++ b/runtime/time.c @@ -187,6 +187,7 @@ _stp_init_time(void) stp_time = alloc_percpu(stp_time_t); if (unlikely(stp_time == 0)) return -1; + _stp_allocated_memory += sizeof(stp_time_t) * num_online_cpus(); stp_timer_reregister = 1; ret = on_each_cpu(__stp_init_time, NULL, 0, 1); -- 2.43.5