summaryrefslogtreecommitdiffstats
path: root/runtime/alloc.c
diff options
context:
space:
mode:
authorhunt <hunt>2007-01-29 20:42:16 +0000
committerhunt <hunt>2007-01-29 20:42:16 +0000
commit4b670dde47e0899370182f85b909bcf1f242b722 (patch)
treea1e8e144641c70f62dc29e323addc391df94143e /runtime/alloc.c
parent91025d70a6871856fe3fc6be9a0557a3ca2ccea8 (diff)
downloadsystemtap-steved-4b670dde47e0899370182f85b909bcf1f242b722.tar.gz
systemtap-steved-4b670dde47e0899370182f85b909bcf1f242b722.tar.xz
systemtap-steved-4b670dde47e0899370182f85b909bcf1f242b722.zip
2007-01-29 Martin Hunt <hunt@redhat.com>
* 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.
Diffstat (limited to 'runtime/alloc.c')
-rw-r--r--runtime/alloc.c43
1 files changed, 41 insertions, 2 deletions
diff --git a/runtime/alloc.c b/runtime/alloc.c
index 4aecd5a8..fe2c84e0 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);
}