From owner-svn-src-head@FreeBSD.ORG Tue Jan 15 10:42:57 2013 Return-Path: Delivered-To: svn-src-head@FreeBSD.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id ECE653E0; Tue, 15 Jan 2013 10:42:57 +0000 (UTC) (envelope-from glebius@FreeBSD.org) Received: from cell.glebius.int.ru (glebius.int.ru [81.19.69.10]) by mx1.freebsd.org (Postfix) with ESMTP id 3E3D0B41; Tue, 15 Jan 2013 10:42:56 +0000 (UTC) Received: from cell.glebius.int.ru (localhost [127.0.0.1]) by cell.glebius.int.ru (8.14.5/8.14.5) with ESMTP id r0FAgnPM089544; Tue, 15 Jan 2013 14:42:49 +0400 (MSK) (envelope-from glebius@FreeBSD.org) Received: (from glebius@localhost) by cell.glebius.int.ru (8.14.5/8.14.5/Submit) id r0FAgmto089543; Tue, 15 Jan 2013 14:42:48 +0400 (MSK) (envelope-from glebius@FreeBSD.org) X-Authentication-Warning: cell.glebius.int.ru: glebius set sender to glebius@FreeBSD.org using -f Date: Tue, 15 Jan 2013 14:42:48 +0400 From: Gleb Smirnoff To: Bruce Evans Subject: Re: svn commit: r245222 - head/sys/sys Message-ID: <20130115104248.GI79056@FreeBSD.org> References: <201301090909.r09999kV013794@svn.freebsd.org> <20130109091217.GL66284@FreeBSD.org> <20130110081336.L967@besplex.bde.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="LQksG6bCIzRHxTLp" Content-Disposition: inline In-Reply-To: <20130110081336.L967@besplex.bde.org> User-Agent: Mutt/1.5.21 (2010-09-15) Cc: svn-src-head@FreeBSD.org, svn-src-all@FreeBSD.org, src-committers@FreeBSD.org, Hans Petter Selasky X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Jan 2013 10:42:58 -0000 --LQksG6bCIzRHxTLp Content-Type: text/plain; charset=koi8-r Content-Disposition: inline On Thu, Jan 10, 2013 at 09:31:28AM +1100, Bruce Evans wrote: B> > On Wed, Jan 09, 2013 at 09:09:09AM +0000, Hans Petter Selasky wrote: B> > H> Log: B> > H> Fix compile warning when using GCC: B> > H> Comparison between signed and unsigned. B> B> o Add 3 style bugs: B> 2 sets of excessive parentheses B> 1 line longer than 80 columns Bruce, can you please look at attached patch, that fixes problems you describe? It - fixes mentioned style bugs in param.h - adds int casts to MHLEN and MLEN - removes extra casts from (void *) to (struct mbuf *) - removes extra declarations of inlined functions - uninlines and moves m_get2() and m_getjcl() to uipc_mbuf.c - size argument of m_get2() swicthed back to int -- Totus tuus, Glebius. --LQksG6bCIzRHxTLp Content-Type: text/x-diff; charset=koi8-r Content-Disposition: attachment; filename="mbuf.diff" Index: sys/param.h =================================================================== --- sys/param.h (revision 245450) +++ sys/param.h (working copy) @@ -156,8 +156,8 @@ * MCLBYTES must be no larger than PAGE_SIZE. */ #ifndef MSIZE -#define MSIZE 256 /* size of an mbuf */ -#endif /* MSIZE */ +#define MSIZE 256 /* size of an mbuf */ +#endif #ifndef MCLSHIFT #define MCLSHIFT 11 /* convert bytes to mbuf clusters */ Index: sys/mbuf.h =================================================================== --- sys/mbuf.h (revision 245450) +++ sys/mbuf.h (working copy) @@ -52,11 +52,14 @@ * stored. Additionally, it is possible to allocate a separate buffer * externally and attach it to the mbuf in a way similar to that of mbuf * clusters. + * + * MLEN is data length in a normal mbuf. + * MHLEN is data length in an mbuf with pktheader. + * MINCLSIZE is a smallest amount of data that should be put into cluster. */ -#define MLEN (MSIZE - sizeof(struct m_hdr)) /* normal data len */ -#define MHLEN (MLEN - sizeof(struct pkthdr)) /* data len w/pkthdr */ -#define MINCLSIZE (MHLEN + 1) /* smallest amount to put in cluster */ -#define M_MAXCOMPRESS (MHLEN / 2) /* max amount to copy for compression */ +#define MLEN ((int)(MSIZE - sizeof(struct m_hdr))) +#define MHLEN ((int)(MLEN - sizeof(struct pkthdr))) +#define MINCLSIZE (MHLEN + 1) #ifdef _KERNEL /*- @@ -393,23 +396,10 @@ extern uma_zone_t zone_jumbo16; extern uma_zone_t zone_ext_refcnt; -static __inline struct mbuf *m_getcl(int how, short type, int flags); -static __inline struct mbuf *m_get(int how, short type); -static __inline struct mbuf *m_get2(int how, short type, int flags, - u_int size); -static __inline struct mbuf *m_gethdr(int how, short type); -static __inline struct mbuf *m_getjcl(int how, short type, int flags, - int size); -static __inline struct mbuf *m_getclr(int how, short type); /* XXX */ -static __inline int m_init(struct mbuf *m, uma_zone_t zone, - int size, int how, short type, int flags); -static __inline struct mbuf *m_free(struct mbuf *m); -static __inline void m_clget(struct mbuf *m, int how); -static __inline void *m_cljget(struct mbuf *m, int how, int size); -static __inline void m_chtype(struct mbuf *m, short new_type); -void mb_free_ext(struct mbuf *); -static __inline struct mbuf *m_last(struct mbuf *m); -int m_pkthdr_init(struct mbuf *m, int how); +struct mbuf *m_get2(int how, short type, int flags, int size); +struct mbuf *m_getjcl(int how, short type, int flags, int size); +void mb_free_ext(struct mbuf *); +int m_pkthdr_init(struct mbuf *m, int how); static __inline int m_gettype(int size) @@ -502,7 +492,7 @@ args.flags = 0; args.type = type; - return ((struct mbuf *)(uma_zalloc_arg(zone_mbuf, &args, how))); + return (uma_zalloc_arg(zone_mbuf, &args, how)); } /* @@ -529,7 +519,7 @@ args.flags = M_PKTHDR; args.type = type; - return ((struct mbuf *)(uma_zalloc_arg(zone_mbuf, &args, how))); + return (uma_zalloc_arg(zone_mbuf, &args, how)); } static __inline struct mbuf * @@ -539,87 +529,9 @@ args.flags = flags; args.type = type; - return ((struct mbuf *)(uma_zalloc_arg(zone_pack, &args, how))); + return (uma_zalloc_arg(zone_pack, &args, how)); } -/* - * m_get2() allocates minimum mbuf that would fit "size" argument. - * - * XXX: This is rather large, should be real function maybe. - */ -static __inline struct mbuf * -m_get2(int how, short type, int flags, u_int size) -{ - struct mb_args args; - struct mbuf *m, *n; - uma_zone_t zone; - - args.flags = flags; - args.type = type; - - if (size <= MHLEN || (size <= MLEN && (flags & M_PKTHDR) == 0)) - return ((struct mbuf *)(uma_zalloc_arg(zone_mbuf, &args, how))); - if (size <= MCLBYTES) - return ((struct mbuf *)(uma_zalloc_arg(zone_pack, &args, how))); - - if (size > MJUM16BYTES) - return (NULL); - - m = uma_zalloc_arg(zone_mbuf, &args, how); - if (m == NULL) - return (NULL); - -#if MJUMPAGESIZE != MCLBYTES - if (size <= MJUMPAGESIZE) - zone = zone_jumbop; - else -#endif - if (size <= MJUM9BYTES) - zone = zone_jumbo9; - else - zone = zone_jumbo16; - - n = uma_zalloc_arg(zone, m, how); - if (n == NULL) { - uma_zfree(zone_mbuf, m); - return (NULL); - } - - return (m); -} - -/* - * m_getjcl() returns an mbuf with a cluster of the specified size attached. - * For size it takes MCLBYTES, MJUMPAGESIZE, MJUM9BYTES, MJUM16BYTES. - * - * XXX: This is rather large, should be real function maybe. - */ -static __inline struct mbuf * -m_getjcl(int how, short type, int flags, int size) -{ - struct mb_args args; - struct mbuf *m, *n; - uma_zone_t zone; - - if (size == MCLBYTES) - return m_getcl(how, type, flags); - - args.flags = flags; - args.type = type; - - m = uma_zalloc_arg(zone_mbuf, &args, how); - if (m == NULL) - return (NULL); - - zone = m_getzone(size); - n = uma_zalloc_arg(zone, m, how); - if (n == NULL) { - uma_zfree(zone_mbuf, m); - return (NULL); - } - return (m); -} - static __inline void m_free_fast(struct mbuf *m) { Index: kern/uipc_mbuf.c =================================================================== --- kern/uipc_mbuf.c (revision 245450) +++ kern/uipc_mbuf.c (working copy) @@ -85,6 +85,79 @@ #endif /* + * m_get2() allocates minimum mbuf that would fit "size" argument. + */ +struct mbuf * +m_get2(int how, short type, int flags, int size) +{ + struct mb_args args; + struct mbuf *m, *n; + uma_zone_t zone; + + args.flags = flags; + args.type = type; + + if (size <= MHLEN || (size <= MLEN && (flags & M_PKTHDR) == 0)) + return (uma_zalloc_arg(zone_mbuf, &args, how)); + if (size <= MCLBYTES) + return (uma_zalloc_arg(zone_pack, &args, how)); + if (size > MJUM16BYTES) + return (NULL); + + m = uma_zalloc_arg(zone_mbuf, &args, how); + if (m == NULL) + return (NULL); + +#if MJUMPAGESIZE != MCLBYTES + if (size <= MJUMPAGESIZE) + zone = zone_jumbop; + else +#endif + if (size <= MJUM9BYTES) + zone = zone_jumbo9; + else + zone = zone_jumbo16; + + n = uma_zalloc_arg(zone, m, how); + if (n == NULL) { + uma_zfree(zone_mbuf, m); + return (NULL); + } + + return (m); +} + +/* + * m_getjcl() returns an mbuf with a cluster of the specified size attached. + * For size it takes MCLBYTES, MJUMPAGESIZE, MJUM9BYTES, MJUM16BYTES. + */ +struct mbuf * +m_getjcl(int how, short type, int flags, int size) +{ + struct mb_args args; + struct mbuf *m, *n; + uma_zone_t zone; + + if (size == MCLBYTES) + return m_getcl(how, type, flags); + + args.flags = flags; + args.type = type; + + m = uma_zalloc_arg(zone_mbuf, &args, how); + if (m == NULL) + return (NULL); + + zone = m_getzone(size); + n = uma_zalloc_arg(zone, m, how); + if (n == NULL) { + uma_zfree(zone_mbuf, m); + return (NULL); + } + return (m); +} + +/* * Allocate a given length worth of mbufs and/or clusters (whatever fits * best) and return a pointer to the top of the allocated chain. If an * existing mbuf chain is provided, then we will append the new chain --LQksG6bCIzRHxTLp--