[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.111.4.3 and 1.126

version 1.111.4.3, 2006/06/01 22:38:09 version 1.126, 2007/02/21 23:00:05
Line 1 
Line 1 
 /*      $NetBSD$        */  /*      $NetBSD$        */
   
 /*-  /*-
  * Copyright (c) 1997, 1999, 2000 The NetBSD Foundation, Inc.   * Copyright (c) 1997, 1999, 2000, 2002 The NetBSD Foundation, Inc.
  * All rights reserved.   * All rights reserved.
  *   *
  * This code is derived from software contributed to The NetBSD Foundation   * This code is derived from software contributed to The NetBSD Foundation
Line 53  __KERNEL_RCSID(0, "$NetBSD$");
Line 53  __KERNEL_RCSID(0, "$NetBSD$");
 #include <sys/lock.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 <uvm/uvm.h>  #include <uvm/uvm.h>
   
Line 364  pr_item_notouch_get(const struct pool *p
Line 365  pr_item_notouch_get(const struct pool *p
 static inline int  static inline int
 phtree_compare(struct pool_item_header *a, struct pool_item_header *b)  phtree_compare(struct pool_item_header *a, struct pool_item_header *b)
 {  {
   
           /*
            * we consider pool_item_header with smaller ph_page bigger.
            * (this unnatural ordering is for the benefit of pr_find_pagehead.)
            */
   
         if (a->ph_page < b->ph_page)          if (a->ph_page < b->ph_page)
                 return (-1);  
         else if (a->ph_page > b->ph_page)  
                 return (1);                  return (1);
           else if (a->ph_page > b->ph_page)
                   return (-1);
         else          else
                 return (0);                  return (0);
 }  }
Line 376  SPLAY_PROTOTYPE(phtree, pool_item_header
Line 383  SPLAY_PROTOTYPE(phtree, pool_item_header
 SPLAY_GENERATE(phtree, pool_item_header, ph_node, phtree_compare);  SPLAY_GENERATE(phtree, pool_item_header, ph_node, phtree_compare);
   
 /*  /*
  * Return the pool page header based on page address.   * Return the pool page header based on item address.
  */   */
 static inline struct pool_item_header *  static inline struct pool_item_header *
 pr_find_pagehead(struct pool *pp, caddr_t page)  pr_find_pagehead(struct pool *pp, void *v)
 {  {
         struct pool_item_header *ph, tmp;          struct pool_item_header *ph, tmp;
   
         if ((pp->pr_roflags & PR_PHINPAGE) != 0)          if ((pp->pr_roflags & PR_NOALIGN) != 0) {
                 return ((struct pool_item_header *)(page + pp->pr_phoffset));                  tmp.ph_page = (caddr_t)(uintptr_t)v;
                   ph = SPLAY_FIND(phtree, &pp->pr_phtree, &tmp);
                   if (ph == NULL) {
                           ph = SPLAY_ROOT(&pp->pr_phtree);
                           if (ph != NULL && phtree_compare(&tmp, ph) >= 0) {
                                   ph = SPLAY_NEXT(phtree, &pp->pr_phtree, ph);
                           }
                           KASSERT(ph == NULL || phtree_compare(&tmp, ph) < 0);
                   }
           } else {
                   caddr_t page =
                       (caddr_t)((uintptr_t)v & pp->pr_alloc->pa_pagemask);
   
         tmp.ph_page = page;                  if ((pp->pr_roflags & PR_PHINPAGE) != 0) {
         ph = SPLAY_FIND(phtree, &pp->pr_phtree, &tmp);                          ph = (void *)(page + pp->pr_phoffset);
                   } else {
                           tmp.ph_page = page;
                           ph = SPLAY_FIND(phtree, &pp->pr_phtree, &tmp);
                   }
           }
   
           KASSERT(ph == NULL || ((pp->pr_roflags & PR_PHINPAGE) != 0) ||
               (ph->ph_page <= (char *)v &&
               (char *)v < ph->ph_page + pp->pr_alloc->pa_pagesz));
         return ph;          return ph;
 }  }
   
Line 447  pr_rmpage(struct pool *pp, struct pool_i
Line 474  pr_rmpage(struct pool *pp, struct pool_i
         pool_update_curpage(pp);          pool_update_curpage(pp);
 }  }
   
 static boolean_t  static bool
 pa_starved_p(struct pool_allocator *pa)  pa_starved_p(struct pool_allocator *pa)
 {  {
   
Line 611  pool_init(struct pool *pp, size_t size, 
Line 638  pool_init(struct pool *pp, size_t size, 
         if (align == 0)          if (align == 0)
                 align = ALIGN(1);                  align = ALIGN(1);
   
         if (size < sizeof(struct pool_item))          if ((flags & PR_NOTOUCH) == 0 && size < sizeof(struct pool_item))
                 size = sizeof(struct pool_item);                  size = sizeof(struct pool_item);
   
         size = roundup(size, align);          size = roundup(size, align);
 #ifdef DIAGNOSTIC  #ifdef DIAGNOSTIC
         if (size > palloc->pa_pagesz)          if (size > palloc->pa_pagesz)
                 panic("pool_init: pool item size (%lu) too large",                  panic("pool_init: pool item size (%zu) too large", size);
                       (u_long)size);  
 #endif  #endif
   
         /*          /*
Line 649  pool_init(struct pool *pp, size_t size, 
Line 675  pool_init(struct pool *pp, size_t size, 
         pp->pr_hardlimit_warning_last.tv_usec = 0;          pp->pr_hardlimit_warning_last.tv_usec = 0;
         pp->pr_drain_hook = NULL;          pp->pr_drain_hook = NULL;
         pp->pr_drain_hook_arg = NULL;          pp->pr_drain_hook_arg = NULL;
           pp->pr_freecheck = NULL;
   
         /*          /*
          * Decide whether to put the page header off page to avoid           * Decide whether to put the page header off page to avoid
Line 667  pool_init(struct pool *pp, size_t size, 
Line 694  pool_init(struct pool *pp, size_t size, 
         /* See the comment below about reserved bytes. */          /* See the comment below about reserved bytes. */
         trysize = palloc->pa_pagesz - ((align - ioff) % align);          trysize = palloc->pa_pagesz - ((align - ioff) % align);
         phsize = ALIGN(sizeof(struct pool_item_header));          phsize = ALIGN(sizeof(struct pool_item_header));
         if ((pp->pr_roflags & PR_NOTOUCH) == 0 &&          if ((pp->pr_roflags & (PR_NOTOUCH | PR_NOALIGN)) == 0 &&
             (pp->pr_size < MIN(palloc->pa_pagesz / 16, phsize << 3) ||              (pp->pr_size < MIN(palloc->pa_pagesz / 16, phsize << 3) ||
             trysize / pp->pr_size == (trysize - phsize) / pp->pr_size)) {              trysize / pp->pr_size == (trysize - phsize) / pp->pr_size)) {
                 /* Use the end of the page for the page header */                  /* Use the end of the page for the page header */
Line 903  pool_get(struct pool *pp, int flags)
Line 930  pool_get(struct pool *pp, int flags)
 #endif /* DIAGNOSTIC */  #endif /* DIAGNOSTIC */
 #ifdef LOCKDEBUG  #ifdef LOCKDEBUG
         if (flags & PR_WAITOK)          if (flags & PR_WAITOK)
                 simple_lock_only_held(NULL, "pool_get(PR_WAITOK)");                  ASSERT_SLEEPABLE(NULL, "pool_get(PR_WAITOK)");
         SCHED_ASSERT_UNLOCKED();  
 #endif  #endif
   
         simple_lock(&pp->pr_slock);          simple_lock(&pp->pr_slock);
Line 1110  pool_get(struct pool *pp, int flags)
Line 1136  pool_get(struct pool *pp, int flags)
         }          }
   
         simple_unlock(&pp->pr_slock);          simple_unlock(&pp->pr_slock);
           KASSERT((((vaddr_t)v + pp->pr_itemoffset) & (pp->pr_align - 1)) == 0);
           FREECHECK_OUT(&pp->pr_freecheck, v);
         return (v);          return (v);
 }  }
   
Line 1121  pool_do_put(struct pool *pp, void *v, st
Line 1149  pool_do_put(struct pool *pp, void *v, st
 {  {
         struct pool_item *pi = v;          struct pool_item *pi = v;
         struct pool_item_header *ph;          struct pool_item_header *ph;
         caddr_t page;  
   
         LOCK_ASSERT(simple_lock_held(&pp->pr_slock));          LOCK_ASSERT(simple_lock_held(&pp->pr_slock));
         SCHED_ASSERT_UNLOCKED();          FREECHECK_IN(&pp->pr_freecheck, v);
   
         page = (caddr_t)((u_long)v & pp->pr_alloc->pa_pagemask);  
   
 #ifdef DIAGNOSTIC  #ifdef DIAGNOSTIC
         if (__predict_false(pp->pr_nout == 0)) {          if (__predict_false(pp->pr_nout == 0)) {
Line 1136  pool_do_put(struct pool *pp, void *v, st
Line 1161  pool_do_put(struct pool *pp, void *v, st
         }          }
 #endif  #endif
   
         if (__predict_false((ph = pr_find_pagehead(pp, page)) == NULL)) {          if (__predict_false((ph = pr_find_pagehead(pp, v)) == NULL)) {
                 pr_printlog(pp, NULL, printf);                  pr_printlog(pp, NULL, printf);
                 panic("pool_put: %s: page header missing", pp->pr_wchan);                  panic("pool_put: %s: page header missing", pp->pr_wchan);
         }          }
Line 1349  pool_prime_page(struct pool *pp, caddr_t
Line 1374  pool_prime_page(struct pool *pp, caddr_t
 {  {
         struct pool_item *pi;          struct pool_item *pi;
         caddr_t cp = storage;          caddr_t cp = storage;
         unsigned int align = pp->pr_align;          const unsigned int align = pp->pr_align;
         unsigned int ioff = pp->pr_itemoffset;          const unsigned int ioff = pp->pr_itemoffset;
         int n;          int n;
   
         LOCK_ASSERT(simple_lock_held(&pp->pr_slock));          LOCK_ASSERT(simple_lock_held(&pp->pr_slock));
   
 #ifdef DIAGNOSTIC  #ifdef DIAGNOSTIC
         if (((u_long)cp & (pp->pr_alloc->pa_pagesz - 1)) != 0)          if ((pp->pr_roflags & PR_NOALIGN) == 0 &&
               ((uintptr_t)cp & (pp->pr_alloc->pa_pagesz - 1)) != 0)
                 panic("pool_prime_page: %s: unaligned page", pp->pr_wchan);                  panic("pool_prime_page: %s: unaligned page", pp->pr_wchan);
 #endif  #endif
   
Line 1386  pool_prime_page(struct pool *pp, caddr_t
Line 1412  pool_prime_page(struct pool *pp, caddr_t
         if (ioff != 0)          if (ioff != 0)
                 cp = (caddr_t)(cp + (align - ioff));                  cp = (caddr_t)(cp + (align - ioff));
   
           KASSERT((((vaddr_t)cp + ioff) & (align - 1)) == 0);
   
         /*          /*
          * Insert remaining chunks on the bucket list.           * Insert remaining chunks on the bucket list.
          */           */
Line 1413  pool_prime_page(struct pool *pp, caddr_t
Line 1441  pool_prime_page(struct pool *pp, caddr_t
                         pi->pi_magic = PI_MAGIC;                          pi->pi_magic = PI_MAGIC;
 #endif  #endif
                         cp = (caddr_t)(cp + pp->pr_size);                          cp = (caddr_t)(cp + pp->pr_size);
   
                           KASSERT((((vaddr_t)cp + ioff) & (align - 1)) == 0);
                 }                  }
         }          }
   
Line 1763  pool_print1(struct pool *pp, const char 
Line 1793  pool_print1(struct pool *pp, const char 
         (*pr)("\n");          (*pr)("\n");
         if ((pp->pr_roflags & PR_LOGGING) == 0)          if ((pp->pr_roflags & PR_LOGGING) == 0)
                 (*pr)("\tno log\n");                  (*pr)("\tno log\n");
         else          else {
                 pr_printlog(pp, NULL, pr);                  pr_printlog(pp, NULL, pr);
           }
   
  skip_log:   skip_log:
         if (print_cache == 0)          if (print_cache == 0)
Line 1815  pool_chk_page(struct pool *pp, const cha
Line 1846  pool_chk_page(struct pool *pp, const cha
         caddr_t page;          caddr_t page;
         int n;          int n;
   
         page = (caddr_t)((u_long)ph & pp->pr_alloc->pa_pagemask);          if ((pp->pr_roflags & PR_NOALIGN) == 0) {
         if (page != ph->ph_page &&                  page = (caddr_t)((uintptr_t)ph & pp->pr_alloc->pa_pagemask);
             (pp->pr_roflags & PR_PHINPAGE) != 0) {                  if (page != ph->ph_page &&
                 if (label != NULL)                      (pp->pr_roflags & PR_PHINPAGE) != 0) {
                         printf("%s: ", label);                          if (label != NULL)
                 printf("pool(%p:%s): page inconsistency: page %p;"                                  printf("%s: ", label);
                        " at page head addr %p (p %p)\n", pp,                          printf("pool(%p:%s): page inconsistency: page %p;"
                         pp->pr_wchan, ph->ph_page,                                 " at page head addr %p (p %p)\n", pp,
                         ph, page);                                  pp->pr_wchan, ph->ph_page,
                 return 1;                                  ph, page);
                           return 1;
                   }
         }          }
   
         if ((pp->pr_roflags & PR_NOTOUCH) != 0)          if ((pp->pr_roflags & PR_NOTOUCH) != 0)
Line 1839  pool_chk_page(struct pool *pp, const cha
Line 1872  pool_chk_page(struct pool *pp, const cha
                         if (label != NULL)                          if (label != NULL)
                                 printf("%s: ", label);                                  printf("%s: ", label);
                         printf("pool(%s): free list modified: magic=%x;"                          printf("pool(%s): free list modified: magic=%x;"
                                " page %p; item ordinal %d;"                                 " page %p; item ordinal %d; addr %p\n",
                                " addr %p (p %p)\n",  
                                 pp->pr_wchan, pi->pi_magic, ph->ph_page,                                  pp->pr_wchan, pi->pi_magic, ph->ph_page,
                                 n, pi, page);                                  n, pi);
                         panic("pool");                          panic("pool");
                 }                  }
 #endif  #endif
                 page =                  if ((pp->pr_roflags & PR_NOALIGN) != 0) {
                     (caddr_t)((u_long)pi & pp->pr_alloc->pa_pagemask);                          continue;
                   }
                   page = (caddr_t)((uintptr_t)pi & pp->pr_alloc->pa_pagemask);
                 if (page == ph->ph_page)                  if (page == ph->ph_page)
                         continue;                          continue;
   
Line 2011  pool_cache_get_paddr(struct pool_cache *
Line 2045  pool_cache_get_paddr(struct pool_cache *
   
 #ifdef LOCKDEBUG  #ifdef LOCKDEBUG
         if (flags & PR_WAITOK)          if (flags & PR_WAITOK)
                 simple_lock_only_held(NULL, "pool_cache_get(PR_WAITOK)");                  ASSERT_SLEEPABLE(NULL, "pool_cache_get(PR_WAITOK)");
 #endif  #endif
   
         simple_lock(&pc->pc_slock);          simple_lock(&pc->pc_slock);
Line 2041  pool_cache_get_paddr(struct pool_cache *
Line 2075  pool_cache_get_paddr(struct pool_cache *
                                 return (NULL);                                  return (NULL);
                         }                          }
                 }                  }
                   KASSERT((((vaddr_t)object + pc->pc_pool->pr_itemoffset) &
                       (pc->pc_pool->pr_align - 1)) == 0);
                 if (object != NULL && pap != NULL) {                  if (object != NULL && pap != NULL) {
 #ifdef POOL_VTOPHYS  #ifdef POOL_VTOPHYS
                         *pap = POOL_VTOPHYS(object);                          *pap = POOL_VTOPHYS(object);
Line 2048  pool_cache_get_paddr(struct pool_cache *
Line 2084  pool_cache_get_paddr(struct pool_cache *
                         *pap = POOL_PADDR_INVALID;                          *pap = POOL_PADDR_INVALID;
 #endif  #endif
                 }                  }
   
                   FREECHECK_OUT(&pc->pc_freecheck, object);
                 return (object);                  return (object);
         }          }
   
Line 2061  pool_cache_get_paddr(struct pool_cache *
Line 2099  pool_cache_get_paddr(struct pool_cache *
         }          }
         simple_unlock(&pc->pc_slock);          simple_unlock(&pc->pc_slock);
   
           KASSERT((((vaddr_t)object + pc->pc_pool->pr_itemoffset) &
               (pc->pc_pool->pr_align - 1)) == 0);
           FREECHECK_OUT(&pc->pc_freecheck, object);
         return (object);          return (object);
 }  }
   
Line 2076  pool_cache_put_paddr(struct pool_cache *
Line 2117  pool_cache_put_paddr(struct pool_cache *
         struct pool_cache_group *pcg;          struct pool_cache_group *pcg;
         int s;          int s;
   
           FREECHECK_IN(&pc->pc_freecheck, object);
   
         if (__predict_false((pc->pc_pool->pr_flags & PR_WANTED) != 0)) {          if (__predict_false((pc->pc_pool->pr_flags & PR_WANTED) != 0)) {
                 goto destruct;                  goto destruct;
         }          }
Line 2328  pool_allocator_free(struct pool *pp, voi
Line 2371  pool_allocator_free(struct pool *pp, voi
 void *  void *
 pool_page_alloc(struct pool *pp, int flags)  pool_page_alloc(struct pool *pp, int flags)
 {  {
         boolean_t waitok = (flags & PR_WAITOK) ? TRUE : FALSE;          bool waitok = (flags & PR_WAITOK) ? TRUE : FALSE;
   
         return ((void *) uvm_km_alloc_poolpage_cache(kmem_map, waitok));          return ((void *) uvm_km_alloc_poolpage_cache(kmem_map, waitok));
 }  }
Line 2343  pool_page_free(struct pool *pp, void *v)
Line 2386  pool_page_free(struct pool *pp, void *v)
 static void *  static void *
 pool_page_alloc_meta(struct pool *pp, int flags)  pool_page_alloc_meta(struct pool *pp, int flags)
 {  {
         boolean_t waitok = (flags & PR_WAITOK) ? TRUE : FALSE;          bool waitok = (flags & PR_WAITOK) ? TRUE : FALSE;
   
         return ((void *) uvm_km_alloc_poolpage(kmem_map, waitok));          return ((void *) uvm_km_alloc_poolpage(kmem_map, waitok));
 }  }
Line 2395  pool_subpage_free_nointr(struct pool *pp
Line 2438  pool_subpage_free_nointr(struct pool *pp
 void *  void *
 pool_page_alloc_nointr(struct pool *pp, int flags)  pool_page_alloc_nointr(struct pool *pp, int flags)
 {  {
         boolean_t waitok = (flags & PR_WAITOK) ? TRUE : FALSE;          bool waitok = (flags & PR_WAITOK) ? TRUE : FALSE;
   
         return ((void *) uvm_km_alloc_poolpage_cache(kernel_map, waitok));          return ((void *) uvm_km_alloc_poolpage_cache(kernel_map, waitok));
 }  }

Legend:
Removed from v.1.111.4.3  
changed lines
  Added in v.1.126

CVSweb <webmaster@jp.NetBSD.org>