From owner-svn-src-all@FreeBSD.ORG Thu Apr 21 13:35:20 2011 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 B23ED106566B; Thu, 21 Apr 2011 13:35:20 +0000 (UTC) (envelope-from pjd@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 8800A8FC1C; Thu, 21 Apr 2011 13:35:20 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id p3LDZKIY098425; Thu, 21 Apr 2011 13:35:20 GMT (envelope-from pjd@svn.freebsd.org) Received: (from pjd@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id p3LDZKb0098423; Thu, 21 Apr 2011 13:35:20 GMT (envelope-from pjd@svn.freebsd.org) Message-Id: <201104211335.p3LDZKb0098423@svn.freebsd.org> From: Pawel Jakub Dawidek Date: Thu, 21 Apr 2011 13:35:20 +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: r220923 - head/sys/geom/eli 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: Thu, 21 Apr 2011 13:35:20 -0000 Author: pjd Date: Thu Apr 21 13:35:20 2011 New Revision: 220923 URL: http://svn.freebsd.org/changeset/base/220923 Log: If number of keys for the given provider doesn't exceed the limit, allocate all of them at attach time. This allows to avoid moving keys around in the most-recently-used queue and needs no mutex synchronization nor refcounting. MFC after: 2 weeks Modified: head/sys/geom/eli/g_eli_key_cache.c Modified: head/sys/geom/eli/g_eli_key_cache.c ============================================================================== --- head/sys/geom/eli/g_eli_key_cache.c Thu Apr 21 13:31:43 2011 (r220922) +++ head/sys/geom/eli/g_eli_key_cache.c Thu Apr 21 13:35:20 2011 (r220923) @@ -217,6 +217,16 @@ g_eli_key_init(struct g_eli_softc *sc) sc->sc_ekeys_allocated = 0; TAILQ_INIT(&sc->sc_ekeys_queue); RB_INIT(&sc->sc_ekeys_tree); + if (sc->sc_ekeys_total <= g_eli_key_cache_limit) { + uint64_t keyno; + + for (keyno = 0; keyno < sc->sc_ekeys_total; keyno++) + (void)g_eli_key_allocate(sc, keyno); + KASSERT(sc->sc_ekeys_total == sc->sc_ekeys_allocated, + ("sc_ekeys_total=%ju != sc_ekeys_allocated=%ju", + (uintmax_t)sc->sc_ekeys_total, + (uintmax_t)sc->sc_ekeys_allocated)); + } } mtx_unlock(&sc->sc_ekeys_lock); } @@ -268,6 +278,13 @@ g_eli_key_hold(struct g_eli_softc *sc, o keysearch.gek_keyno = keyno; + if (sc->sc_ekeys_total == sc->sc_ekeys_allocated) { + /* We have all the keys, so avoid some overhead. */ + key = RB_FIND(g_eli_key_tree, &sc->sc_ekeys_tree, &keysearch); + KASSERT(key != NULL, ("No key %ju found.", (uintmax_t)keyno)); + return (key->gek_key); + } + mtx_lock(&sc->sc_ekeys_lock); key = RB_FIND(g_eli_key_tree, &sc->sc_ekeys_tree, &keysearch); if (key != NULL) { @@ -306,6 +323,9 @@ g_eli_key_drop(struct g_eli_softc *sc, u if ((sc->sc_flags & G_ELI_FLAG_SINGLE_KEY) != 0) return; + if (sc->sc_ekeys_total == sc->sc_ekeys_allocated) + return; + mtx_lock(&sc->sc_ekeys_lock); KASSERT(key->gek_count > 0, ("key->gek_count=%d", key->gek_count)); key->gek_count--;