[BACK]Return to subr_pool.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / kern

Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /src/sys/kern/subr_pool.c between version 1.133.4.3 and 1.133.4.4

version 1.133.4.3, 2007/12/27 00:46:08 version 1.133.4.4, 2008/02/18 21:06:47
Line 52  __KERNEL_RCSID(0, "$NetBSD$");
Line 52  __KERNEL_RCSID(0, "$NetBSD$");
 #include <sys/errno.h>  #include <sys/errno.h>
 #include <sys/kernel.h>  #include <sys/kernel.h>
 #include <sys/malloc.h>  #include <sys/malloc.h>
 #include <sys/lock.h>  
 #include <sys/pool.h>  #include <sys/pool.h>
 #include <sys/syslog.h>  #include <sys/syslog.h>
 #include <sys/debug.h>  #include <sys/debug.h>
 #include <sys/lockdebug.h>  #include <sys/lockdebug.h>
 #include <sys/xcall.h>  #include <sys/xcall.h>
 #include <sys/cpu.h>  #include <sys/cpu.h>
   #include <sys/atomic.h>
   
 #include <uvm/uvm.h>  #include <uvm/uvm.h>
   
Line 76  __KERNEL_RCSID(0, "$NetBSD$");
Line 76  __KERNEL_RCSID(0, "$NetBSD$");
  */   */
   
 /* List of all pools */  /* List of all pools */
 LIST_HEAD(,pool) pool_head = LIST_HEAD_INITIALIZER(pool_head);  TAILQ_HEAD(,pool) pool_head = TAILQ_HEAD_INITIALIZER(pool_head);
   
 /* List of all caches. */  
 LIST_HEAD(,pool_cache) pool_cache_head =  
     LIST_HEAD_INITIALIZER(pool_cache_head);  
   
 /* Private pool for page header structures */  /* Private pool for page header structures */
 #define PHPOOL_MAX      8  #define PHPOOL_MAX      8
Line 126  struct pool_item_header {
Line 122  struct pool_item_header {
         SPLAY_ENTRY(pool_item_header)          SPLAY_ENTRY(pool_item_header)
                                 ph_node;        /* Off-page page headers */                                  ph_node;        /* Off-page page headers */
         void *                  ph_page;        /* this page's address */          void *                  ph_page;        /* this page's address */
         struct timeval          ph_time;        /* last referenced */          uint32_t                ph_time;        /* last referenced */
         uint16_t                ph_nmissing;    /* # of chunks in use */          uint16_t                ph_nmissing;    /* # of chunks in use */
         uint16_t                ph_off;         /* start offset in page */          uint16_t                ph_off;         /* start offset in page */
         union {          union {
Line 186  static struct pool pcg_large_pool;
Line 182  static struct pool pcg_large_pool;
 static struct pool cache_pool;  static struct pool cache_pool;
 static struct pool cache_cpu_pool;  static struct pool cache_cpu_pool;
   
   /* List of all caches. */
   TAILQ_HEAD(,pool_cache) pool_cache_head =
       TAILQ_HEAD_INITIALIZER(pool_cache_head);
   
   int pool_cache_disable;
   
   
 static pool_cache_cpu_t *pool_cache_put_slow(pool_cache_cpu_t *, int *,  static pool_cache_cpu_t *pool_cache_put_slow(pool_cache_cpu_t *, int *,
                                              void *, paddr_t);                                               void *, paddr_t);
 static pool_cache_cpu_t *pool_cache_get_slow(pool_cache_cpu_t *, int *,  static pool_cache_cpu_t *pool_cache_get_slow(pool_cache_cpu_t *, int *,
Line 626  void
Line 629  void
 pool_init(struct pool *pp, size_t size, u_int align, u_int ioff, int flags,  pool_init(struct pool *pp, size_t size, u_int align, u_int ioff, int flags,
     const char *wchan, struct pool_allocator *palloc, int ipl)      const char *wchan, struct pool_allocator *palloc, int ipl)
 {  {
 #ifdef DEBUG  
         struct pool *pp1;          struct pool *pp1;
 #endif  
         size_t trysize, phsize;          size_t trysize, phsize;
         int off, slack;          int off, slack;
   
Line 637  pool_init(struct pool *pp, size_t size, 
Line 638  pool_init(struct pool *pp, size_t size, 
          * Check that the pool hasn't already been initialised and           * Check that the pool hasn't already been initialised and
          * added to the list of all pools.           * added to the list of all pools.
          */           */
         LIST_FOREACH(pp1, &pool_head, pr_poollist) {          TAILQ_FOREACH(pp1, &pool_head, pr_poollist) {
                 if (pp == pp1)                  if (pp == pp1)
                         panic("pool_init: pool %s already initialised",                          panic("pool_init: pool %s already initialised",
                             wchan);                              wchan);
Line 863  pool_init(struct pool *pp, size_t size, 
Line 864  pool_init(struct pool *pp, size_t size, 
                     "pcglarge", &pool_allocator_meta, IPL_VM);                      "pcglarge", &pool_allocator_meta, IPL_VM);
         }          }
   
         if (__predict_true(!cold)) {          /* Insert into the list of all pools. */
                 /* Insert into the list of all pools. */          if (__predict_true(!cold))
                 mutex_enter(&pool_head_lock);                  mutex_enter(&pool_head_lock);
                 LIST_INSERT_HEAD(&pool_head, pp, pr_poollist);          TAILQ_FOREACH(pp1, &pool_head, pr_poollist) {
                   if (strcmp(pp1->pr_wchan, pp->pr_wchan) > 0)
                           break;
           }
           if (pp1 == NULL)
                   TAILQ_INSERT_TAIL(&pool_head, pp, pr_poollist);
           else
                   TAILQ_INSERT_BEFORE(pp1, pp, pr_poollist);
           if (__predict_true(!cold))
                 mutex_exit(&pool_head_lock);                  mutex_exit(&pool_head_lock);
   
                 /* Insert this into the list of pools using this allocator. */                  /* Insert this into the list of pools using this allocator. */
           if (__predict_true(!cold))
                 mutex_enter(&palloc->pa_lock);                  mutex_enter(&palloc->pa_lock);
                 TAILQ_INSERT_TAIL(&palloc->pa_list, pp, pr_alloc_list);          TAILQ_INSERT_TAIL(&palloc->pa_list, pp, pr_alloc_list);
           if (__predict_true(!cold))
                 mutex_exit(&palloc->pa_lock);                  mutex_exit(&palloc->pa_lock);
         } else {  
                 LIST_INSERT_HEAD(&pool_head, pp, pr_poollist);  
                 TAILQ_INSERT_TAIL(&palloc->pa_list, pp, pr_alloc_list);  
         }  
   
         pool_reclaim_register(pp);          pool_reclaim_register(pp);
 }  }
Line 894  pool_destroy(struct pool *pp)
Line 901  pool_destroy(struct pool *pp)
         mutex_enter(&pool_head_lock);          mutex_enter(&pool_head_lock);
         while (pp->pr_refcnt != 0)          while (pp->pr_refcnt != 0)
                 cv_wait(&pool_busy, &pool_head_lock);                  cv_wait(&pool_busy, &pool_head_lock);
         LIST_REMOVE(pp, pr_poollist);          TAILQ_REMOVE(&pool_head, pp, pr_poollist);
         if (drainpp == pp)          if (drainpp == pp)
                 drainpp = NULL;                  drainpp = NULL;
         mutex_exit(&pool_head_lock);          mutex_exit(&pool_head_lock);
Line 1293  pool_do_put(struct pool *pp, void *v, st
Line 1300  pool_do_put(struct pool *pp, void *v, st
                          * be idle for some period of time before it can                           * be idle for some period of time before it can
                          * be reclaimed by the pagedaemon.  This minimizes                           * be reclaimed by the pagedaemon.  This minimizes
                          * ping-pong'ing for memory.                           * ping-pong'ing for memory.
                            *
                            * note for 64-bit time_t: truncating to 32-bit is not
                            * a problem for our usage.
                          */                           */
                         getmicrotime(&ph->ph_time);                          ph->ph_time = time_uptime;
                 }                  }
                 pool_update_curpage(pp);                  pool_update_curpage(pp);
         }          }
Line 1446  pool_prime_page(struct pool *pp, void *s
Line 1456  pool_prime_page(struct pool *pp, void *s
         LIST_INIT(&ph->ph_itemlist);          LIST_INIT(&ph->ph_itemlist);
         ph->ph_page = storage;          ph->ph_page = storage;
         ph->ph_nmissing = 0;          ph->ph_nmissing = 0;
         getmicrotime(&ph->ph_time);          ph->ph_time = time_uptime;
         if ((pp->pr_roflags & PR_PHINPAGE) == 0)          if ((pp->pr_roflags & PR_PHINPAGE) == 0)
                 SPLAY_INSERT(phtree, &pp->pr_phtree, ph);                  SPLAY_INSERT(phtree, &pp->pr_phtree, ph);
   
Line 1607  pool_reclaim(struct pool *pp)
Line 1617  pool_reclaim(struct pool *pp)
 {  {
         struct pool_item_header *ph, *phnext;          struct pool_item_header *ph, *phnext;
         struct pool_pagelist pq;          struct pool_pagelist pq;
         struct timeval curtime, diff;          uint32_t curtime;
         bool klock;          bool klock;
         int rv;          int rv;
   
Line 1644  pool_reclaim(struct pool *pp)
Line 1654  pool_reclaim(struct pool *pp)
   
         LIST_INIT(&pq);          LIST_INIT(&pq);
   
         getmicrotime(&curtime);          curtime = time_uptime;
   
         for (ph = LIST_FIRST(&pp->pr_emptypages); ph != NULL; ph = phnext) {          for (ph = LIST_FIRST(&pp->pr_emptypages); ph != NULL; ph = phnext) {
                 phnext = LIST_NEXT(ph, ph_pagelist);                  phnext = LIST_NEXT(ph, ph_pagelist);
Line 1654  pool_reclaim(struct pool *pp)
Line 1664  pool_reclaim(struct pool *pp)
                         break;                          break;
   
                 KASSERT(ph->ph_nmissing == 0);                  KASSERT(ph->ph_nmissing == 0);
                 timersub(&curtime, &ph->ph_time, &diff);                  if (curtime - ph->ph_time < pool_inactive_time
                 if (diff.tv_sec < pool_inactive_time  
                     && !pa_starved_p(pp->pr_alloc))                      && !pa_starved_p(pp->pr_alloc))
                         continue;                          continue;
   
Line 1701  pool_drain_start(struct pool **ppp, uint
Line 1710  pool_drain_start(struct pool **ppp, uint
 {  {
         struct pool *pp;          struct pool *pp;
   
         KASSERT(!LIST_EMPTY(&pool_head));          KASSERT(!TAILQ_EMPTY(&pool_head));
   
         pp = NULL;          pp = NULL;
   
Line 1709  pool_drain_start(struct pool **ppp, uint
Line 1718  pool_drain_start(struct pool **ppp, uint
         mutex_enter(&pool_head_lock);          mutex_enter(&pool_head_lock);
         do {          do {
                 if (drainpp == NULL) {                  if (drainpp == NULL) {
                         drainpp = LIST_FIRST(&pool_head);                          drainpp = TAILQ_FIRST(&pool_head);
                 }                  }
                 if (drainpp != NULL) {                  if (drainpp != NULL) {
                         pp = drainpp;                          pp = drainpp;
                         drainpp = LIST_NEXT(pp, pr_poollist);                          drainpp = TAILQ_NEXT(pp, pr_poollist);
                 }                  }
                 /*                  /*
                  * Skip completely idle pools.  We depend on at least                   * Skip completely idle pools.  We depend on at least
Line 1769  pool_printall(const char *modif, void (*
Line 1778  pool_printall(const char *modif, void (*
 {  {
         struct pool *pp;          struct pool *pp;
   
         LIST_FOREACH(pp, &pool_head, pr_poollist) {          TAILQ_FOREACH(pp, &pool_head, pr_poollist) {
                 pool_printit(pp, modif, pr);                  pool_printit(pp, modif, pr);
         }          }
 }  }
Line 1796  pool_print_pagelist(struct pool *pp, str
Line 1805  pool_print_pagelist(struct pool *pp, str
 #endif  #endif
   
         LIST_FOREACH(ph, pl, ph_pagelist) {          LIST_FOREACH(ph, pl, ph_pagelist) {
                 (*pr)("\t\tpage %p, nmissing %d, time %lu,%lu\n",                  (*pr)("\t\tpage %p, nmissing %d, time %" PRIu32 "\n",
                     ph->ph_page, ph->ph_nmissing,                      ph->ph_page, ph->ph_nmissing, ph->ph_time);
                     (u_long)ph->ph_time.tv_sec,  
                     (u_long)ph->ph_time.tv_usec);  
 #ifdef DIAGNOSTIC  #ifdef DIAGNOSTIC
                 if (!(pp->pr_roflags & PR_NOTOUCH)) {                  if (!(pp->pr_roflags & PR_NOTOUCH)) {
                         LIST_FOREACH(pi, &ph->ph_itemlist, pi_list) {                          LIST_FOREACH(pi, &ph->ph_itemlist, pi_list) {
Line 2059  pool_cache_bootstrap(pool_cache_t pc, si
Line 2066  pool_cache_bootstrap(pool_cache_t pc, si
     void *arg)      void *arg)
 {  {
         CPU_INFO_ITERATOR cii;          CPU_INFO_ITERATOR cii;
           pool_cache_t pc1;
         struct cpu_info *ci;          struct cpu_info *ci;
         struct pool *pp;          struct pool *pp;
   
Line 2115  pool_cache_bootstrap(pool_cache_t pc, si
Line 2123  pool_cache_bootstrap(pool_cache_t pc, si
                         pool_cache_cpu_init1(ci, pc);                          pool_cache_cpu_init1(ci, pc);
                 }                  }
         }          }
   
         if (__predict_true(!cold)) {          /* Add to list of all pools. */
                 mutex_enter(&pp->pr_lock);          if (__predict_true(!cold))
                 pp->pr_cache = pc;  
                 mutex_exit(&pp->pr_lock);  
                 mutex_enter(&pool_head_lock);                  mutex_enter(&pool_head_lock);
                 LIST_INSERT_HEAD(&pool_cache_head, pc, pc_cachelist);          TAILQ_FOREACH(pc1, &pool_cache_head, pc_cachelist) {
                 mutex_exit(&pool_head_lock);                  if (strcmp(pc1->pc_pool.pr_wchan, pc->pc_pool.pr_wchan) > 0)
         } else {                          break;
                 pp->pr_cache = pc;  
                 LIST_INSERT_HEAD(&pool_cache_head, pc, pc_cachelist);  
         }          }
           if (pc1 == NULL)
                   TAILQ_INSERT_TAIL(&pool_cache_head, pc, pc_cachelist);
           else
                   TAILQ_INSERT_BEFORE(pc1, pc, pc_cachelist);
           if (__predict_true(!cold))
                   mutex_exit(&pool_head_lock);
   
           membar_sync();
           pp->pr_cache = pc;
 }  }
   
 /*  /*
Line 2146  pool_cache_destroy(pool_cache_t pc)
Line 2159  pool_cache_destroy(pool_cache_t pc)
         mutex_enter(&pool_head_lock);          mutex_enter(&pool_head_lock);
         while (pc->pc_refcnt != 0)          while (pc->pc_refcnt != 0)
                 cv_wait(&pool_busy, &pool_head_lock);                  cv_wait(&pool_busy, &pool_head_lock);
         LIST_REMOVE(pc, pc_cachelist);          TAILQ_REMOVE(&pool_cache_head, pc, pc_cachelist);
         mutex_exit(&pool_head_lock);          mutex_exit(&pool_head_lock);
   
         /* First, invalidate the entire cache. */          /* First, invalidate the entire cache. */
Line 2237  pool_cache_cpu_init(struct cpu_info *ci)
Line 2250  pool_cache_cpu_init(struct cpu_info *ci)
         pool_cache_t pc;          pool_cache_t pc;
   
         mutex_enter(&pool_head_lock);          mutex_enter(&pool_head_lock);
         LIST_FOREACH(pc, &pool_cache_head, pc_cachelist) {          TAILQ_FOREACH(pc, &pool_cache_head, pc_cachelist) {
                 pc->pc_refcnt++;                  pc->pc_refcnt++;
                 mutex_exit(&pool_head_lock);                  mutex_exit(&pool_head_lock);
   
Line 2521  pool_cache_get_paddr(pool_cache_t pc, in
Line 2534  pool_cache_get_paddr(pool_cache_t pc, in
                         object = pcg->pcg_objects[--pcg->pcg_avail].pcgo_va;                          object = pcg->pcg_objects[--pcg->pcg_avail].pcgo_va;
                         if (pap != NULL)                          if (pap != NULL)
                                 *pap = pcg->pcg_objects[pcg->pcg_avail].pcgo_pa;                                  *pap = pcg->pcg_objects[pcg->pcg_avail].pcgo_pa;
   #if defined(DIAGNOSTIC)
                         pcg->pcg_objects[pcg->pcg_avail].pcgo_va = NULL;                          pcg->pcg_objects[pcg->pcg_avail].pcgo_va = NULL;
   #endif /* defined(DIAGNOSTIC) */
                         KASSERT(pcg->pcg_avail <= pcg->pcg_size);                          KASSERT(pcg->pcg_avail <= pcg->pcg_size);
                         KASSERT(object != NULL);                          KASSERT(object != NULL);
                         cc->cc_hits++;                          cc->cc_hits++;
Line 2592  pool_cache_put_slow(pool_cache_cpu_t *cc
Line 2607  pool_cache_put_slow(pool_cache_cpu_t *cc
                 /*                  /*
                  * If there's a empty group, release our full                   * If there's a empty group, release our full
                  * group back to the cache.  Install the empty                   * group back to the cache.  Install the empty
                  * group as cc_current and return.                   * group and return.
                  */                   */
                 if ((cur = cc->cc_current) != NULL) {  
                         KASSERT(cur->pcg_avail == pcg->pcg_size);  
                         cur->pcg_next = pc->pc_fullgroups;  
                         pc->pc_fullgroups = cur;  
                         pc->pc_nfull++;  
                 }  
                 KASSERT(pcg->pcg_avail == 0);                  KASSERT(pcg->pcg_avail == 0);
                 cc->cc_current = pcg;  
                 pc->pc_emptygroups = pcg->pcg_next;                  pc->pc_emptygroups = pcg->pcg_next;
                   if (cc->cc_previous == NULL) {
                           cc->cc_previous = pcg;
                   } else {
                           if ((cur = cc->cc_current) != NULL) {
                                   KASSERT(cur->pcg_avail == pcg->pcg_size);
                                   cur->pcg_next = pc->pc_fullgroups;
                                   pc->pc_fullgroups = cur;
                                   pc->pc_nfull++;
                           }
                           cc->cc_current = pcg;
                   }
                 pc->pc_hits++;                  pc->pc_hits++;
                 pc->pc_nempty--;                  pc->pc_nempty--;
                 mutex_exit(&pc->pc_lock);                  mutex_exit(&pc->pc_lock);
Line 2623  pool_cache_put_slow(pool_cache_cpu_t *cc
Line 2642  pool_cache_put_slow(pool_cache_cpu_t *cc
          * object away.           * object away.
          */           */
         nobj = pc->pc_pcgsize;          nobj = pc->pc_pcgsize;
         if (nobj == PCG_NOBJECTS_LARGE) {          if (pool_cache_disable) {
                   pcg = NULL;
           } else if (nobj == PCG_NOBJECTS_LARGE) {
                 pcg = pool_get(&pcg_large_pool, PR_NOWAIT);                  pcg = pool_get(&pcg_large_pool, PR_NOWAIT);
         } else {          } else {
                 pcg = pool_get(&pcg_normal_pool, PR_NOWAIT);                  pcg = pool_get(&pcg_normal_pool, PR_NOWAIT);
Line 2979  pool_whatis(uintptr_t addr, void (*pr)(c
Line 3000  pool_whatis(uintptr_t addr, void (*pr)(c
 {  {
         struct pool *pp;          struct pool *pp;
   
         LIST_FOREACH(pp, &pool_head, pr_poollist) {          TAILQ_FOREACH(pp, &pool_head, pr_poollist) {
                 struct pool_item_header *ph;                  struct pool_item_header *ph;
                 uintptr_t item;                  uintptr_t item;
                 bool allocated = true;                  bool allocated = true;

Legend:
Removed from v.1.133.4.3  
changed lines
  Added in v.1.133.4.4

CVSweb <webmaster@jp.NetBSD.org>