On Thu, 2008-09-04 at 14:18 -0700, Stephen Hemminger wrote:
> Reduce snmpd memory usage.
> 
> The route table can grow very large and existing code is a major
> performance problem since it wastes half of its memory and copies
> each time.
>     
> 1. Grow expanding table by 1.5 rather 2x per step

You need to make sure that the table grows at all.

Additionally, at the moment the table never shrinks, I think that is a
obvious potential improvment for memory usage.

>    Perhaps the increment should just be PAGESIZE

This is interesting - the effect is that it changes the insert from O(n)
to O(n*n) but for small tables I think it would be a gain anyway and you
do avoid the problem of the big growth.

> 2. Use realloc rather than copying, this allows for possible
>    inplace growth and smart allocation.

This I think sounds like an excellent idea and it do lessen some of the
+PAGESIZE cost.

> --- a/snmplib/container_binary_array.c        2008-09-04 11:47:25.000000000 
> -0700
> +++ b/snmplib/container_binary_array.c        2008-09-04 12:26:14.000000000 
> -0700
> @@ -357,19 +357,15 @@ netsnmp_binary_array_insert(netsnmp_cont
>          /*
>           * Table is full, so extend it to double the size
>           */
> -        new_max = 2 * t->max_size;
> +        new_max = t->max_size + t->max_size / 2;
>          if (new_max == 0)
>              new_max = 10;       /* Start with 10 entries */
>  
> -        new_data = (void *) calloc(new_max, t->data_size);
> +        new_data = realloc(t->data, new_max * t->data_size);
>          if (new_data == NULL)
>              return -1;
>  
> -        if (t->data) {
> -            memcpy(new_data, t->data, t->max_size * t->data_size);
> -            SNMP_FREE(t->data);
> -        }
> -        t->data = (void**)new_data;
> +        t->data = new_data;
>          t->max_size = new_max;
>      }
>  
> 
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
> Build the coolest Linux based applications with Moblin SDK & win great prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> Net-snmp-coders mailing list
> Net-snmp-coders@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/net-snmp-coders


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Net-snmp-coders mailing list
Net-snmp-coders@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to