Date: Sun, 31 Jan 2010 11:34:45 +0000 (UTC) From: Luigi Rizzo <luigi@FreeBSD.org> To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r203275 - user/luigi/ipfw3-head/sys/netinet/ipfw Message-ID: <201001311134.o0VBYjvn011425@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: luigi Date: Sun Jan 31 11:34:44 2010 New Revision: 203275 URL: http://svn.freebsd.org/changeset/base/203275 Log: round heap size to powers of 2, so we save an expensive modulo op. Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/dn_heap.c Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/dn_heap.c ============================================================================== --- user/luigi/ipfw3-head/sys/netinet/ipfw/dn_heap.c Sun Jan 31 11:30:28 2010 (r203274) +++ user/luigi/ipfw3-head/sys/netinet/ipfw/dn_heap.c Sun Jan 31 11:34:44 2010 (r203275) @@ -78,7 +78,15 @@ heap_resize(struct dn_heap *h, int new_s if (h->size >= new_size ) /* have enough room */ return 0; +#if 1 /* round to the next power of 2 */ + new_size |= new_size >> 1; + new_size |= new_size >> 2; + new_size |= new_size >> 4; + new_size |= new_size >> 8; + new_size |= new_size >> 16; +#else new_size = (new_size + HEAP_INCREMENT ) & ~HEAP_INCREMENT; +#endif p = malloc(new_size * sizeof(*p), M_DN_HEAP, M_NOWAIT); if (p == NULL) { printf("--- %s, resize %d failed\n", __func__, new_size );
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201001311134.o0VBYjvn011425>