From owner-svn-src-all@FreeBSD.ORG Wed Nov 5 02:08:38 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id D33CC7BA; Wed, 5 Nov 2014 02:08:38 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id A70679B0; Wed, 5 Nov 2014 02:08:38 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id sA528chb051740; Wed, 5 Nov 2014 02:08:38 GMT (envelope-from mjg@FreeBSD.org) Received: (from mjg@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id sA528cPs051738; Wed, 5 Nov 2014 02:08:38 GMT (envelope-from mjg@FreeBSD.org) Message-Id: <201411050208.sA528cPs051738@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: mjg set sender to mjg@FreeBSD.org using -f From: Mateusz Guzik Date: Wed, 5 Nov 2014 02:08:38 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r274122 - in head/sys: kern sys X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18-1 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, 05 Nov 2014 02:08:38 -0000 Author: mjg Date: Wed Nov 5 02:08:37 2014 New Revision: 274122 URL: https://svnweb.freebsd.org/changeset/base/274122 Log: Extend struct ucred with group table. This saves one malloc + free with typical cases and better utilizes memory. Submitted by: Tiwei Bie (slightly modified) X-Additional: JuniorJobs project Modified: head/sys/kern/kern_prot.c head/sys/sys/ucred.h Modified: head/sys/kern/kern_prot.c ============================================================================== --- head/sys/kern/kern_prot.c Wed Nov 5 01:57:32 2014 (r274121) +++ head/sys/kern/kern_prot.c Wed Nov 5 02:08:37 2014 (r274122) @@ -1817,7 +1817,9 @@ crget(void) #ifdef MAC mac_cred_init(cr); #endif - crextend(cr, XU_NGROUPS); + cr->cr_groups = cr->cr_smallgroups; + cr->cr_agroups = + sizeof(cr->cr_smallgroups) / sizeof(cr->cr_smallgroups[0]); return (cr); } @@ -1864,7 +1866,8 @@ crfree(struct ucred *cr) #ifdef MAC mac_cred_destroy(cr); #endif - free(cr->cr_groups, M_CRED); + if (cr->cr_groups != cr->cr_smallgroups) + free(cr->cr_groups, M_CRED); free(cr, M_CRED); } } @@ -1997,7 +2000,7 @@ crextend(struct ucred *cr, int n) cnt = roundup2(n, PAGE_SIZE / sizeof(gid_t)); /* Free the old array. */ - if (cr->cr_groups) + if (cr->cr_groups != cr->cr_smallgroups) free(cr->cr_groups, M_CRED); cr->cr_groups = malloc(cnt * sizeof(gid_t), M_CRED, M_WAITOK | M_ZERO); Modified: head/sys/sys/ucred.h ============================================================================== --- head/sys/sys/ucred.h Wed Nov 5 01:57:32 2014 (r274121) +++ head/sys/sys/ucred.h Wed Nov 5 02:08:37 2014 (r274122) @@ -37,6 +37,8 @@ struct loginclass; +#define XU_NGROUPS 16 + /* * Credentials. * @@ -64,13 +66,12 @@ struct ucred { struct auditinfo_addr cr_audit; /* Audit properties. */ gid_t *cr_groups; /* groups */ int cr_agroups; /* Available groups */ + gid_t cr_smallgroups[XU_NGROUPS]; /* storage for small groups */ }; #define NOCRED ((struct ucred *)0) /* no credential available */ #define FSCRED ((struct ucred *)-1) /* filesystem credential */ #endif /* _KERNEL || _WANT_UCRED */ -#define XU_NGROUPS 16 - /* * Flags for cr_flags. */