From owner-svn-src-all@FreeBSD.ORG Wed Feb 4 17:10:02 2009 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4F30C10656F3; Wed, 4 Feb 2009 17:10:02 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 31D1F8FC2C; Wed, 4 Feb 2009 17:10:02 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n14HA2jk082066; Wed, 4 Feb 2009 17:10:02 GMT (envelope-from ed@svn.freebsd.org) Received: (from ed@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n14HA2Wc082064; Wed, 4 Feb 2009 17:10:02 GMT (envelope-from ed@svn.freebsd.org) Message-Id: <200902041710.n14HA2Wc082064@svn.freebsd.org> From: Ed Schouten Date: Wed, 4 Feb 2009 17:10:02 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r188115 - in head/sys: kern sys X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 Feb 2009 17:10:03 -0000 Author: ed Date: Wed Feb 4 17:10:01 2009 New Revision: 188115 URL: http://svn.freebsd.org/changeset/base/188115 Log: Remove slush space from clists. Right now we only have a very small amount of drivers that use clists, but we still allocate 50 cblocks as slush space, which allows drivers to temporarily overcommit their storage. Most of the drivers don't allow this anyway. I've performed the following changes: - We don't allocate any cblocks on startup. - I've removed the DDB command, because it has nothing useful to print now. You can obtain the amount of allocated blocks by running `vmstat -m | grep clist'. - I've removed cfreecount, which is now unused. - The old code first tries to allocate using M_NOWAIT, followed by M_WAITOK. This doesn't make any sense, so just remove this logic. It seems the drivers allow us to sleep anyway. We can even remove ccmax from clist_alloc_cblocks and c_cbmax from struct clist, but this breaks binary compatibility. This reduces the amount of allocated cblocks on my system from 54 to 4. Modified: head/sys/kern/subr_clist.c head/sys/sys/clist.h Modified: head/sys/kern/subr_clist.c ============================================================================== --- head/sys/kern/subr_clist.c Wed Feb 4 15:02:57 2009 (r188114) +++ head/sys/kern/subr_clist.c Wed Feb 4 17:10:01 2009 (r188115) @@ -38,58 +38,15 @@ __FBSDID("$FreeBSD$"); #include #include -static void clist_init(void *); -SYSINIT(clist, SI_SUB_CLIST, SI_ORDER_FIRST, clist_init, NULL); - static MALLOC_DEFINE(M_CLIST, "clist", "clist queue blocks"); static struct cblock *cfreelist = NULL; -int cfreecount = 0; -static int cslushcount; -static int ctotcount; - -#ifndef INITIAL_CBLOCKS -#define INITIAL_CBLOCKS 50 -#endif static struct cblock *cblock_alloc(void); static void cblock_alloc_cblocks(int number); static void cblock_free(struct cblock *cblockp); static void cblock_free_cblocks(int number); -#include "opt_ddb.h" -#ifdef DDB -#include - -DB_SHOW_COMMAND(cbstat, cbstat) -{ - int cbsize = CBSIZE; - - printf( - "tot = %d (active = %d, free = %d (reserved = %d, slush = %d))\n", - ctotcount * cbsize, ctotcount * cbsize - cfreecount, cfreecount, - cfreecount - cslushcount * cbsize, cslushcount * cbsize); -} -#endif /* DDB */ - -/* - * Called from init_main.c - */ -/* ARGSUSED*/ -static void -clist_init(void *dummy) -{ - /* - * Allocate an initial base set of cblocks as a 'slush'. - * We allocate non-slush cblocks with each initial tty_open() and - * deallocate them with each tty_close(). - * We should adjust the slush allocation. This can't be done in - * the i/o routines because they are sometimes called from - * interrupt handlers when it may be unsafe to call malloc(). - */ - cblock_alloc_cblocks(cslushcount = INITIAL_CBLOCKS); -} - /* * Remove a cblock from the cfreelist queue and return a pointer * to it. @@ -104,7 +61,6 @@ cblock_alloc(void) panic("clist reservation botch"); cfreelist = cblockp->c_next; cblockp->c_next = NULL; - cfreecount -= CBSIZE; return (cblockp); } @@ -116,7 +72,6 @@ cblock_free(struct cblock *cblockp) { cblockp->c_next = cfreelist; cfreelist = cblockp; - cfreecount += CBSIZE; } /* @@ -129,19 +84,13 @@ cblock_alloc_cblocks(int number) struct cblock *cbp; for (i = 0; i < number; ++i) { - cbp = malloc(sizeof *cbp, M_CLIST, M_NOWAIT); - if (cbp == NULL) { - printf( -"cblock_alloc_cblocks: M_NOWAIT malloc failed, trying M_WAITOK\n"); - cbp = malloc(sizeof *cbp, M_CLIST, M_WAITOK); - } + cbp = malloc(sizeof *cbp, M_CLIST, M_WAITOK); /* * Freed cblocks have zero quotes and garbage elsewhere. * Set the may-have-quote bit to force zeroing the quotes. */ cblock_free(cbp); } - ctotcount += number; } /* @@ -184,7 +133,6 @@ cblock_free_cblocks(int number) for (i = 0; i < number; ++i) free(cblock_alloc(), M_CLIST); - ctotcount -= number; } /* @@ -237,8 +185,7 @@ getc(struct clist *clistp) clistp->c_cf = clistp->c_cl = NULL; } cblock_free(cblockp); - if (--clistp->c_cbcount >= clistp->c_cbreserved) - ++cslushcount; + --clistp->c_cbcount; } } @@ -285,8 +232,7 @@ q_to_b(struct clist *clistp, char *dest, clistp->c_cf = clistp->c_cl = NULL; } cblock_free(cblockp); - if (--clistp->c_cbcount >= clistp->c_cbreserved) - ++cslushcount; + --clistp->c_cbcount; } } @@ -328,8 +274,7 @@ ndflush(struct clist *clistp, int amount clistp->c_cf = clistp->c_cl = NULL; } cblock_free(cblockp); - if (--clistp->c_cbcount >= clistp->c_cbreserved) - ++cslushcount; + --clistp->c_cbcount; } } @@ -364,12 +309,8 @@ putc(char chr, struct clist *clistp) struct cblock *prev = (cblockp - 1); if (clistp->c_cbcount >= clistp->c_cbreserved) { - if (clistp->c_cbcount >= clistp->c_cbmax - || cslushcount <= 0) { - splx(s); - return (-1); - } - --cslushcount; + splx(s); + return (-1); } cblockp = cblock_alloc(); clistp->c_cbcount++; @@ -430,12 +371,8 @@ b_to_q(char *src, int amount, struct cli struct cblock *prev = cblockp - 1; if (clistp->c_cbcount >= clistp->c_cbreserved) { - if (clistp->c_cbcount >= clistp->c_cbmax - || cslushcount <= 0) { - splx(s); - return (amount); - } - --cslushcount; + splx(s); + return (amount); } cblockp = cblock_alloc(); clistp->c_cbcount++; @@ -510,8 +447,7 @@ unputc(struct clist *clistp) */ clistp->c_cl = (char *)(cbp+1); cblock_free(cblockp); - if (--clistp->c_cbcount >= clistp->c_cbreserved) - ++cslushcount; + --clistp->c_cbcount; cbp->c_next = NULL; } } @@ -523,8 +459,7 @@ unputc(struct clist *clistp) if ((clistp->c_cc == 0) && clistp->c_cl) { cblockp = (struct cblock *)((intptr_t)clistp->c_cl & ~CROUND); cblock_free(cblockp); - if (--clistp->c_cbcount >= clistp->c_cbreserved) - ++cslushcount; + --clistp->c_cbcount; clistp->c_cf = clistp->c_cl = NULL; } Modified: head/sys/sys/clist.h ============================================================================== --- head/sys/sys/clist.h Wed Feb 4 15:02:57 2009 (r188114) +++ head/sys/sys/clist.h Wed Feb 4 17:10:01 2009 (r188115) @@ -54,8 +54,6 @@ struct cblock { }; #ifdef _KERNEL -extern int cfreecount; - int b_to_q(char *cp, int cc, struct clist *q); void clist_alloc_cblocks(struct clist *q, int ccmax, int ccres); void clist_free_cblocks(struct clist *q);