The code for reading /proc files guesses at an initial size buffer,
then has to retry if the buffer isn't big enough. This slows boot
since it has to repeat several time. It was a penny wise (save memory)
but pound foolish (cpu) choice in initial design. Instead choose size
that gets rounded up to page size (4K).
--- a/agent/mibgroup/hardware/cpu/cpu_linux.c 2009-03-17 09:21:46.243479880
-0700
+++ b/agent/mibgroup/hardware/cpu/cpu_linux.c 2009-03-17 09:31:07.615230114
-0700
@@ -111,11 +111,11 @@ int netsnmp_cpu_arch_load( netsnmp_cache
return -1;
}
if (bsize == 0) {
- bsize = 255;
+ bsize = getpagesize()-1;
buff = malloc(bsize+1);
}
while ((bytes_read = read(statfd, buff, bsize)) == bsize) {
- bsize += 256;
+ bsize += BUFSIZ;
buff = realloc(buff, bsize+1);
DEBUGMSGTL(("cpu", "/proc/stat buffer increased to %d\n", bsize));
close(statfd);
@@ -207,11 +207,11 @@ void _cpu_load_swap_etc( char *buff, net
if (has_vmstat && (vmstatfd = open(VMSTAT_FILE, O_RDONLY, 0)) != -1) {
if (vmbsize == 0) {
- vmbsize = 255;
+ vmbsize = getpagesize()-1;
vmbuff = malloc(vmbsize+1);
}
while ((bytes_read = read(vmstatfd, vmbuff, vmbsize)) == vmbsize) {
- vmbsize += 256;
+ vmbsize += BUFSIZ;
vmbuff = realloc(vmbuff, vmbsize);
close(vmstatfd);
vmstatfd = open(VMSTAT_FILE, O_RDONLY, 0);
--- a/agent/mibgroup/hardware/memory/memory_linux.c 2009-03-17
09:20:21.275604222 -0700
+++ b/agent/mibgroup/hardware/memory/memory_linux.c 2009-03-17
09:21:24.510252280 -0700
@@ -10,8 +10,9 @@
* Try to use an initial size that will cover default cases. We aren't talking
* about huge files, so why fiddle about with reallocs?
* I checked /proc/meminfo sizes on 3 different systems: 598, 644, 654
+ * (but now on newer systems size is up to 930)
*/
-#define MEMINFO_INIT_SIZE 768
+#define MEMINFO_INIT_SIZE 1023
#define MEMINFO_STEP_SIZE 256
#define MEMINFO_FILE "/proc/meminfo"
--
------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders