diff options
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | src/include/platform.h | 3 | ||||
-rw-r--r-- | src/nse/gnunet-service-nse.c | 17 | ||||
-rw-r--r-- | src/statistics/gnunet-service-statistics.c | 15 | ||||
-rw-r--r-- | src/statistics/statistics_api.c | 54 | ||||
-rw-r--r-- | src/topology/gnunet-daemon-topology.c | 15 | ||||
-rw-r--r-- | src/util/gnunet-service-resolver.c | 15 |
7 files changed, 120 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac index 165e66d44..151d76d2d 100644 --- a/configure.ac +++ b/configure.ac | |||
@@ -733,7 +733,7 @@ AC_FUNC_VPRINTF | |||
733 | AC_HEADER_SYS_WAIT | 733 | AC_HEADER_SYS_WAIT |
734 | AC_TYPE_OFF_T | 734 | AC_TYPE_OFF_T |
735 | AC_TYPE_UID_T | 735 | AC_TYPE_UID_T |
736 | AC_CHECK_FUNCS([atoll stat64 strnlen mremap setrlimit sysconf initgroups strndup gethostbyname2 getpeerucred getpeereid setresuid $funcstocheck getifaddrs freeifaddrs getresgid mallinfo malloc_size malloc_usable_size]) | 736 | AC_CHECK_FUNCS([atoll stat64 strnlen mremap setrlimit sysconf initgroups strndup gethostbyname2 getpeerucred getpeereid setresuid $funcstocheck getifaddrs freeifaddrs getresgid mallinfo malloc_size malloc_usable_size getrusage]) |
737 | 737 | ||
738 | # restore LIBS | 738 | # restore LIBS |
739 | LIBS=$SAVE_LIBS | 739 | LIBS=$SAVE_LIBS |
diff --git a/src/include/platform.h b/src/include/platform.h index d0591b107..8bd2e6706 100644 --- a/src/include/platform.h +++ b/src/include/platform.h | |||
@@ -111,6 +111,9 @@ | |||
111 | #ifdef WINDOWS | 111 | #ifdef WINDOWS |
112 | #include <malloc.h> /* for alloca(), on other OSes it's in stdlib.h */ | 112 | #include <malloc.h> /* for alloca(), on other OSes it's in stdlib.h */ |
113 | #endif | 113 | #endif |
114 | #ifdef HAVE_MALLOC_H | ||
115 | #include <malloc.h> /* for mallinfo on GNU */ | ||
116 | #endif | ||
114 | #ifndef _MSC_VER | 117 | #ifndef _MSC_VER |
115 | #include <unistd.h> /* KLB_FIX */ | 118 | #include <unistd.h> /* KLB_FIX */ |
116 | #endif | 119 | #endif |
diff --git a/src/nse/gnunet-service-nse.c b/src/nse/gnunet-service-nse.c index d7fb439e2..9a9f50a96 100644 --- a/src/nse/gnunet-service-nse.c +++ b/src/nse/gnunet-service-nse.c | |||
@@ -1519,4 +1519,21 @@ main (int argc, char *const *argv) | |||
1519 | &run, NULL)) ? 0 : 1; | 1519 | &run, NULL)) ? 0 : 1; |
1520 | } | 1520 | } |
1521 | 1521 | ||
1522 | |||
1523 | #ifdef LINUX | ||
1524 | #include <malloc.h> | ||
1525 | |||
1526 | /** | ||
1527 | * MINIMIZE heap size (way below 128k) since this process doesn't need much. | ||
1528 | */ | ||
1529 | void __attribute__ ((constructor)) GNUNET_ARM_memory_init () | ||
1530 | { | ||
1531 | mallopt (M_TRIM_THRESHOLD, 4 * 1024); | ||
1532 | mallopt (M_TOP_PAD, 1 * 1024); | ||
1533 | malloc_trim (0); | ||
1534 | } | ||
1535 | #endif | ||
1536 | |||
1537 | |||
1538 | |||
1522 | /* end of gnunet-service-nse.c */ | 1539 | /* end of gnunet-service-nse.c */ |
diff --git a/src/statistics/gnunet-service-statistics.c b/src/statistics/gnunet-service-statistics.c index efd834624..beb3d5135 100644 --- a/src/statistics/gnunet-service-statistics.c +++ b/src/statistics/gnunet-service-statistics.c | |||
@@ -849,4 +849,19 @@ main (int argc, char *const *argv) | |||
849 | GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN, &run, NULL)) ? 0 : 1; | 849 | GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN, &run, NULL)) ? 0 : 1; |
850 | } | 850 | } |
851 | 851 | ||
852 | #ifdef LINUX | ||
853 | #include <malloc.h> | ||
854 | |||
855 | /** | ||
856 | * MINIMIZE heap size (way below 128k) since this process doesn't need much. | ||
857 | */ | ||
858 | void __attribute__ ((constructor)) GNUNET_ARM_memory_init () | ||
859 | { | ||
860 | mallopt (M_TRIM_THRESHOLD, 4 * 1024); | ||
861 | mallopt (M_TOP_PAD, 1 * 1024); | ||
862 | malloc_trim (0); | ||
863 | } | ||
864 | #endif | ||
865 | |||
866 | |||
852 | /* end of gnunet-service-statistics.c */ | 867 | /* end of gnunet-service-statistics.c */ |
diff --git a/src/statistics/statistics_api.c b/src/statistics/statistics_api.c index e1b3698e6..79d9604c7 100644 --- a/src/statistics/statistics_api.c +++ b/src/statistics/statistics_api.c | |||
@@ -236,6 +236,16 @@ struct GNUNET_STATISTICS_Handle | |||
236 | struct GNUNET_TIME_Relative backoff; | 236 | struct GNUNET_TIME_Relative backoff; |
237 | 237 | ||
238 | /** | 238 | /** |
239 | * Maximum heap size observed so far (if available). | ||
240 | */ | ||
241 | uint64_t peak_heap_size; | ||
242 | |||
243 | /** | ||
244 | * Maximum resident set side observed so far (if available). | ||
245 | */ | ||
246 | uint64_t peak_rss; | ||
247 | |||
248 | /** | ||
239 | * Size of the 'watches' array. | 249 | * Size of the 'watches' array. |
240 | */ | 250 | */ |
241 | unsigned int watches_size; | 251 | unsigned int watches_size; |
@@ -255,6 +265,49 @@ struct GNUNET_STATISTICS_Handle | |||
255 | 265 | ||
256 | 266 | ||
257 | /** | 267 | /** |
268 | * Obtain statistics about this process's memory consumption and | ||
269 | * report those as well (if they changed). | ||
270 | */ | ||
271 | static void | ||
272 | update_memory_statistics (struct GNUNET_STATISTICS_Handle *h) | ||
273 | { | ||
274 | uint64_t current_heap_size = 0; | ||
275 | uint64_t current_rss = 0; | ||
276 | |||
277 | if (GNUNET_NO != h->do_destroy) | ||
278 | return; | ||
279 | #if HAVE_MALLINFO | ||
280 | { | ||
281 | struct mallinfo mi; | ||
282 | |||
283 | mi = mallinfo(); | ||
284 | current_heap_size = mi.uordblks + mi.fordblks; | ||
285 | } | ||
286 | #endif | ||
287 | #if HAVE_GETRUSAGE | ||
288 | { | ||
289 | struct rusage ru; | ||
290 | |||
291 | if (0 == getrusage (RUSAGE_SELF, &ru)) | ||
292 | { | ||
293 | current_rss = 1024LL * ru.ru_maxrss; | ||
294 | } | ||
295 | } | ||
296 | #endif | ||
297 | if (current_heap_size > h->peak_heap_size) | ||
298 | { | ||
299 | h->peak_heap_size = current_heap_size; | ||
300 | GNUNET_STATISTICS_set (h, "# peak heap size", current_heap_size, GNUNET_NO); | ||
301 | } | ||
302 | if (current_rss > h->peak_rss) | ||
303 | { | ||
304 | h->peak_rss = current_rss; | ||
305 | GNUNET_STATISTICS_set (h, "# peak resident set size", current_rss, GNUNET_NO); | ||
306 | } | ||
307 | } | ||
308 | |||
309 | |||
310 | /** | ||
258 | * Schedule the next action to be performed. | 311 | * Schedule the next action to be performed. |
259 | * | 312 | * |
260 | * @param h statistics handle to reconnect | 313 | * @param h statistics handle to reconnect |
@@ -820,6 +873,7 @@ transmit_set (struct GNUNET_STATISTICS_Handle *handle, size_t size, void *buf) | |||
820 | GNUNET_assert (NULL == handle->current->cont); | 873 | GNUNET_assert (NULL == handle->current->cont); |
821 | free_action_item (handle->current); | 874 | free_action_item (handle->current); |
822 | handle->current = NULL; | 875 | handle->current = NULL; |
876 | update_memory_statistics (handle); | ||
823 | return nsize; | 877 | return nsize; |
824 | } | 878 | } |
825 | 879 | ||
diff --git a/src/topology/gnunet-daemon-topology.c b/src/topology/gnunet-daemon-topology.c index 2dc3c148b..682ad417c 100644 --- a/src/topology/gnunet-daemon-topology.c +++ b/src/topology/gnunet-daemon-topology.c | |||
@@ -1367,4 +1367,19 @@ main (int argc, char *const *argv) | |||
1367 | return ret; | 1367 | return ret; |
1368 | } | 1368 | } |
1369 | 1369 | ||
1370 | |||
1371 | #ifdef LINUX | ||
1372 | #include <malloc.h> | ||
1373 | |||
1374 | /** | ||
1375 | * MINIMIZE heap size (way below 128k) since this process doesn't need much. | ||
1376 | */ | ||
1377 | void __attribute__ ((constructor)) GNUNET_ARM_memory_init () | ||
1378 | { | ||
1379 | mallopt (M_TRIM_THRESHOLD, 4 * 1024); | ||
1380 | mallopt (M_TOP_PAD, 1 * 1024); | ||
1381 | malloc_trim (0); | ||
1382 | } | ||
1383 | #endif | ||
1384 | |||
1370 | /* end of gnunet-daemon-topology.c */ | 1385 | /* end of gnunet-daemon-topology.c */ |
diff --git a/src/util/gnunet-service-resolver.c b/src/util/gnunet-service-resolver.c index 97eba6d11..507ecf661 100644 --- a/src/util/gnunet-service-resolver.c +++ b/src/util/gnunet-service-resolver.c | |||
@@ -577,4 +577,19 @@ main (int argc, char *const *argv) | |||
577 | return ret; | 577 | return ret; |
578 | } | 578 | } |
579 | 579 | ||
580 | #ifdef LINUX | ||
581 | #include <malloc.h> | ||
582 | |||
583 | /** | ||
584 | * MINIMIZE heap size (way below 128k) since this process doesn't need much. | ||
585 | */ | ||
586 | void __attribute__ ((constructor)) GNUNET_ARM_memory_init () | ||
587 | { | ||
588 | mallopt (M_TRIM_THRESHOLD, 4 * 1024); | ||
589 | mallopt (M_TOP_PAD, 1 * 1024); | ||
590 | malloc_trim (0); | ||
591 | } | ||
592 | #endif | ||
593 | |||
594 | |||
580 | /* end of gnunet-service-resolver.c */ | 595 | /* end of gnunet-service-resolver.c */ |