Browse code

Two configuration variables are introduced that can help troubleshooting memory leaks: mem_dump_pkg, and mem_dump_shm Useage:

sercmd cfg.set_now_int mem_dump_pkg <pid_number>
Dumps the pkg memory status of the given processs

sercmd cfg.set_now_int mem_dump_shm 1
Dumps the shm memory status

Miklos Tirpak authored on 04/04/2008 08:40:53
Showing 4 changed files
... ...
@@ -38,6 +38,9 @@
38 38
 #ifdef USE_DNS_CACHE
39 39
 #include "dns_cache.h"
40 40
 #endif
41
+#if defined PKG_MALLOC || defined SHM_MEM
42
+#include "pt.h"
43
+#endif
41 44
 #include "cfg/cfg.h"
42 45
 #include "cfg_core.h"
43 46
 
... ...
@@ -78,6 +81,12 @@ struct cfg_group_core default_core_cfg = {
78 81
 	DEFAULT_DNS_MAX_MEM, /* dns_cache_max_mem */
79 82
 	0, /* dns_cache_del_nonexp -- delete only expired entries by default */
80 83
 #endif
84
+#ifdef PKG_MALLOC
85
+	0, /* mem_dump_pkg */
86
+#endif
87
+#ifdef SHM_MEM
88
+	0, /* mem_dump_shm */
89
+#endif
81 90
 };
82 91
 
83 92
 void	*core_cfg = &default_core_cfg;
... ...
@@ -156,6 +165,14 @@ cfg_def_t core_cfg_def[] = {
156 165
 	{"dns_cache_del_nonexp",	CFG_VAR_INT,	0, 1, 0, 0,
157 166
 		"allow deletion of non-expired records from the cache when "
158 167
 		"there is no more space left for new ones"},
168
+#endif
169
+#ifdef PKG_MALLOC
170
+	{"mem_dump_pkg",	CFG_VAR_INT,	0, 0, 0, mem_dump_pkg_cb,
171
+		"dump process memory status, parameter: pid_number"},
172
+#endif
173
+#ifdef SHM_MEM
174
+	{"mem_dump_shm",	CFG_VAR_INT,	0, 0, mem_dump_shm_fixup, 0,
175
+		"dump shared memory status"},
159 176
 #endif
160 177
 	{0, 0, 0, 0, 0, 0}
161 178
 };
... ...
@@ -78,6 +78,12 @@ struct cfg_group_core {
78 78
 	unsigned int dns_cache_max_mem;
79 79
 	int dns_cache_del_nonexp;
80 80
 #endif
81
+#ifdef PKG_MALLOC
82
+	int mem_dump_pkg;
83
+#endif
84
+#ifdef SHM_MEM
85
+	int mem_dump_shm;
86
+#endif
81 87
 };
82 88
 
83 89
 extern struct cfg_group_core default_core_cfg;
... ...
@@ -44,6 +44,15 @@
44 44
 #include "sr_module.h"
45 45
 #include "socket_info.h"
46 46
 #include "rand/fastrand.h"
47
+#ifdef PKG_MALLOC
48
+#include "mem/mem.h"
49
+#endif
50
+#ifdef SHM_MEM
51
+#include "mem/shm_mem.h"
52
+#endif
53
+#if defined PKG_MALLOC || defined SHM_MEM
54
+#include "cfg_core.h"
55
+#endif
47 56
 
48 57
 #include <stdio.h>
49 58
 #include <time.h> /* time(), used to initialize random numbers */
... ...
@@ -506,3 +515,51 @@ end:
506 515
 	return ret;
507 516
 }
508 517
 #endif
518
+
519
+#ifdef PKG_MALLOC
520
+/* Dumps pkg memory status.
521
+ * Per-child process callback that is called
522
+ * when mem_dump_pkg cfg var is changed.
523
+ */
524
+void mem_dump_pkg_cb(str *name)
525
+{
526
+	int	old_memlog;
527
+
528
+	if (cfg_get(core, core_cfg, mem_dump_pkg) == my_pid()) {
529
+		/* set memlog to ALERT level to force
530
+		printing the log messages */
531
+		old_memlog = memlog;
532
+		memlog = L_ALERT;
533
+
534
+		LOG(memlog, "Memory status (pkg) of process %d:\n", my_pid());
535
+		pkg_status();
536
+
537
+		memlog = old_memlog;
538
+	}
539
+}
540
+#endif
541
+
542
+#ifdef SHM_MEM
543
+/* Dumps shm memory status.
544
+ * fixup function that is called
545
+ * when mem_dump_shm cfg var is set.
546
+ */
547
+int mem_dump_shm_fixup(void *handle, str *name, void **val)
548
+{
549
+	int	old_memlog;
550
+
551
+	if ((long)(void*)(*val)) {
552
+		/* set memlog to ALERT level to force
553
+		printing the log messages */
554
+		old_memlog = memlog;
555
+		memlog = L_ALERT;
556
+
557
+		LOG(memlog, "Memory status (shm)\n");
558
+		shm_status();
559
+
560
+		memlog = old_memlog;
561
+		*val = (void*)(long)0;
562
+	}
563
+	return 0;
564
+}
565
+#endif
... ...
@@ -100,4 +100,12 @@ int fork_process(int child_id,char *desc,int make_sock);
100 100
 int fork_tcp_process(int child_id,char *desc,int r,int *reader_fd_1);
101 101
 #endif
102 102
 
103
+#ifdef PKG_MALLOC
104
+void mem_dump_pkg_cb(str *name);
105
+#endif
106
+
107
+#ifdef SHM_MEM
108
+int mem_dump_shm_fixup(void *handle, str *name, void **val);
109
+#endif
110
+
103 111
 #endif