From owner-p4-projects@FreeBSD.ORG Wed Jun 2 22:24:45 2010 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 9C90C1065673; Wed, 2 Jun 2010 22:24:44 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 490751065670 for ; Wed, 2 Jun 2010 22:24:44 +0000 (UTC) (envelope-from zec@fer.hr) Received: from repoman.freebsd.org (unknown [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 2EF0F8FC08 for ; Wed, 2 Jun 2010 22:24:44 +0000 (UTC) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id o52MOhVH055791 for ; Wed, 2 Jun 2010 22:24:43 GMT (envelope-from zec@fer.hr) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id o52MOhPE055789 for perforce@freebsd.org; Wed, 2 Jun 2010 22:24:43 GMT (envelope-from zec@fer.hr) Date: Wed, 2 Jun 2010 22:24:43 GMT Message-Id: <201006022224.o52MOhPE055789@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to zec@fer.hr using -f From: Marko Zec To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 179119 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Jun 2010 22:24:45 -0000 http://p4web.freebsd.org/@@179119?ac=10 Change 179119 by zec@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);