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--;
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to