PERFORCE change 179119 for review
Marko Zec
zec at FreeBSD.org
Wed Jun 2 22:24:45 UTC 2010
http://p4web.freebsd.org/@@179119?ac=10
Change 179119 by zec at zec_tpx32 on 2010/06/02 22:24:22
Dynamically allocate memory for bw_meter_timers[] and bw_upcalls[]
arrays, and do so only when a multicast routing socket gets
opened in a vnet, instead of having those arrays statically
declared. This should save us around 4 pages of memory per vnet,
which was previously wasted in all vnet instances which didn't perform
multicast routing. This should also allow us to kldload ip_mroute.ko
at runtime without rebuilding the kernel with increased VNET_MODMIN
spare buffers.
Most importantly, this change is completely untested.
Affected files ...
.. //depot/projects/vimage/src/sys/netinet/ip_mroute.c#44 edit
Differences ...
==== //depot/projects/vimage/src/sys/netinet/ip_mroute.c#44 (text+ko) ====
@@ -206,7 +206,7 @@
* expiration time. Periodically, the entries are analysed and processed.
*/
#define BW_METER_BUCKETS 1024
-static VNET_DEFINE(struct bw_meter*, bw_meter_timers[BW_METER_BUCKETS]);
+static VNET_DEFINE(struct bw_meter *, *bw_meter_timers);
#define V_bw_meter_timers VNET(bw_meter_timers)
static VNET_DEFINE(struct callout, bw_meter_ch);
#define V_bw_meter_ch VNET(bw_meter_ch)
@@ -216,7 +216,8 @@
* Pending upcalls are stored in a vector which is flushed when
* full, or periodically
*/
-static VNET_DEFINE(struct bw_upcall, bw_upcalls[BW_UPCALLS_MAX]);
+static MALLOC_DEFINE(M_BWUPCALL, "bwupcall", "multicast upcall vector");
+static VNET_DEFINE(struct bw_upcall, *bw_upcalls);
#define V_bw_upcalls VNET(bw_upcalls)
static VNET_DEFINE(u_int, bw_upcalls_n); /* # of pending upcalls */
#define V_bw_upcalls_n VNET(bw_upcalls_n)
@@ -679,7 +680,30 @@
V_mfchashtbl = hashinit_flags(mfchashsize, M_MRTABLE, &V_mfchash,
HASH_NOWAIT);
+ if (V_mfchashtbl == NULL) {
+ MROUTER_UNLOCK();
+ return (ENOMEM);
+ }
+
+ MALLOC(V_bw_upcalls, struct bw_upcall *,
+ BW_UPCALLS_MAX * sizeof(struct bw_upcall), M_BWUPCALL,
+ M_NOWAIT|M_ZERO);
+ if (V_bw_meter_timers == NULL) {
+ hashdestroy(V_mfchashtbl, M_MRTABLE, V_mfchash);
+ MROUTER_UNLOCK();
+ return (ENOMEM);
+ }
+ MALLOC(V_bw_meter_timers, struct bw_meter **,
+ BW_METER_BUCKETS * sizeof(struct bw_meter *), M_BWMETER,
+ M_NOWAIT|M_ZERO);
+ if (V_bw_meter_timers == NULL) {
+ FREE(V_bw_upcalls, M_BWUPCALL);
+ hashdestroy(V_mfchashtbl, M_MRTABLE, V_mfchash);
+ MROUTER_UNLOCK();
+ return (ENOMEM);
+ }
+
callout_reset(&V_expire_upcalls_ch, EXPIRE_TIMEOUT, expire_upcalls,
curvnet);
callout_reset(&V_bw_upcalls_ch, BW_UPCALLS_PERIOD, expire_bw_upcalls_send,
@@ -769,7 +793,10 @@
bzero(V_nexpire, sizeof(V_nexpire[0]) * mfchashsize);
V_bw_upcalls_n = 0;
- bzero(V_bw_meter_timers, sizeof(V_bw_meter_timers));
+ FREE(V_bw_meter_timers, M_BWMETER);
+ V_bw_meter_timers = NULL;
+ FREE(V_bw_upcalls, M_BWUPCALL);
+ V_bw_upcalls = NULL;
MFC_UNLOCK();
@@ -2816,7 +2843,6 @@
{
MALLOC(V_nexpire, u_char *, mfchashsize, M_MRTABLE, M_WAITOK|M_ZERO);
- bzero(V_bw_meter_timers, sizeof(V_bw_meter_timers));
callout_init(&V_expire_upcalls_ch, CALLOUT_MPSAFE);
callout_init(&V_bw_upcalls_ch, CALLOUT_MPSAFE);
callout_init(&V_bw_meter_ch, CALLOUT_MPSAFE);
More information about the p4-projects
mailing list