| version 1.30, 1999/08/29 00:26:01 |
version 1.30.2.1, 2000/11/20 18:09:07 |
|
|
| #include <sys/pool.h> |
#include <sys/pool.h> |
| #include <sys/syslog.h> |
#include <sys/syslog.h> |
| |
|
| #include <vm/vm.h> |
|
| #include <vm/vm_kern.h> |
|
| |
|
| #include <uvm/uvm.h> |
#include <uvm/uvm.h> |
| |
|
| /* |
/* |
| Line 97 struct pool_item_header { |
|
| Line 94 struct pool_item_header { |
|
| struct pool_item { |
struct pool_item { |
| #ifdef DIAGNOSTIC |
#ifdef DIAGNOSTIC |
| int pi_magic; |
int pi_magic; |
| #define PI_MAGIC 0xdeadbeef |
|
| #endif |
#endif |
| |
#define PI_MAGIC 0xdeadbeef |
| /* Other entries use only this list entry */ |
/* Other entries use only this list entry */ |
| TAILQ_ENTRY(pool_item) pi_list; |
TAILQ_ENTRY(pool_item) pi_list; |
| }; |
}; |
| Line 215 pr_enter(pp, file, line) |
|
| Line 212 pr_enter(pp, file, line) |
|
| long line; |
long line; |
| { |
{ |
| |
|
| if (pp->pr_entered_file != NULL) { |
if (__predict_false(pp->pr_entered_file != NULL)) { |
| printf("pool %s: reentrancy at file %s line %ld\n", |
printf("pool %s: reentrancy at file %s line %ld\n", |
| pp->pr_wchan, file, line); |
pp->pr_wchan, file, line); |
| printf(" previous entry at file %s line %ld\n", |
printf(" previous entry at file %s line %ld\n", |
|
|
| struct pool *pp; |
struct pool *pp; |
| { |
{ |
| |
|
| if (pp->pr_entered_file == NULL) { |
if (__predict_false(pp->pr_entered_file == NULL)) { |
| printf("pool %s not entered?\n", pp->pr_wchan); |
printf("pool %s not entered?\n", pp->pr_wchan); |
| panic("pr_leave"); |
panic("pr_leave"); |
| } |
} |
| Line 404 pool_init(pp, size, align, ioff, flags, |
|
| Line 401 pool_init(pp, size, align, ioff, flags, |
|
| /* |
/* |
| * Check arguments and construct default values. |
* Check arguments and construct default values. |
| */ |
*/ |
| if (!powerof2(pagesz) || pagesz > PAGE_SIZE) |
if (!powerof2(pagesz)) |
| panic("pool_init: page size invalid (%lx)\n", (u_long)pagesz); |
panic("pool_init: page size invalid (%lx)\n", (u_long)pagesz); |
| |
|
| if (alloc == NULL && release == NULL) { |
if (alloc == NULL && release == NULL) { |
| Line 425 pool_init(pp, size, align, ioff, flags, |
|
| Line 422 pool_init(pp, size, align, ioff, flags, |
|
| if (size < sizeof(struct pool_item)) |
if (size < sizeof(struct pool_item)) |
| size = sizeof(struct pool_item); |
size = sizeof(struct pool_item); |
| |
|
| |
size = ALIGN(size); |
| |
if (size >= pagesz) |
| |
panic("pool_init: pool item size (%lu) too large", |
| |
(u_long)size); |
| |
|
| /* |
/* |
| * Initialize the pool structure. |
* Initialize the pool structure. |
| */ |
*/ |
| Line 436 pool_init(pp, size, align, ioff, flags, |
|
| Line 438 pool_init(pp, size, align, ioff, flags, |
|
| pp->pr_maxpages = UINT_MAX; |
pp->pr_maxpages = UINT_MAX; |
| pp->pr_roflags = flags; |
pp->pr_roflags = flags; |
| pp->pr_flags = 0; |
pp->pr_flags = 0; |
| pp->pr_size = ALIGN(size); |
pp->pr_size = size; |
| pp->pr_align = align; |
pp->pr_align = align; |
| pp->pr_wchan = wchan; |
pp->pr_wchan = wchan; |
| pp->pr_mtype = mtype; |
pp->pr_mtype = mtype; |
| Line 449 pool_init(pp, size, align, ioff, flags, |
|
| Line 451 pool_init(pp, size, align, ioff, flags, |
|
| pp->pr_nout = 0; |
pp->pr_nout = 0; |
| pp->pr_hardlimit = UINT_MAX; |
pp->pr_hardlimit = UINT_MAX; |
| pp->pr_hardlimit_warning = NULL; |
pp->pr_hardlimit_warning = NULL; |
| pp->pr_hardlimit_ratecap = 0; |
pp->pr_hardlimit_ratecap.tv_sec = 0; |
| memset(&pp->pr_hardlimit_warning_last, 0, |
pp->pr_hardlimit_ratecap.tv_usec = 0; |
| sizeof(pp->pr_hardlimit_warning_last)); |
pp->pr_hardlimit_warning_last.tv_sec = 0; |
| |
pp->pr_hardlimit_warning_last.tv_usec = 0; |
| |
|
| /* |
/* |
| * Decide whether to put the page header off page to avoid |
* Decide whether to put the page header off page to avoid |
| Line 581 _pool_get(pp, flags, file, line) |
|
| Line 584 _pool_get(pp, flags, file, line) |
|
| struct pool_item_header *ph; |
struct pool_item_header *ph; |
| |
|
| #ifdef DIAGNOSTIC |
#ifdef DIAGNOSTIC |
| if ((pp->pr_roflags & PR_STATIC) && (flags & PR_MALLOCOK)) { |
if (__predict_false((pp->pr_roflags & PR_STATIC) && |
| |
(flags & PR_MALLOCOK))) { |
| pr_printlog(pp, NULL, printf); |
pr_printlog(pp, NULL, printf); |
| panic("pool_get: static"); |
panic("pool_get: static"); |
| } |
} |
| #endif |
#endif |
| |
|
| if (curproc == NULL && (flags & PR_WAITOK) != 0) |
if (__predict_false(curproc == NULL && doing_shutdown == 0 && |
| |
(flags & PR_WAITOK) != 0)) |
| panic("pool_get: must have NOWAIT"); |
panic("pool_get: must have NOWAIT"); |
| |
|
| simple_lock(&pp->pr_slock); |
simple_lock(&pp->pr_slock); |
| Line 600 _pool_get(pp, flags, file, line) |
|
| Line 605 _pool_get(pp, flags, file, line) |
|
| * the pool. |
* the pool. |
| */ |
*/ |
| #ifdef DIAGNOSTIC |
#ifdef DIAGNOSTIC |
| if (pp->pr_nout > pp->pr_hardlimit) { |
if (__predict_false(pp->pr_nout > pp->pr_hardlimit)) { |
| pr_leave(pp); |
pr_leave(pp); |
| simple_unlock(&pp->pr_slock); |
simple_unlock(&pp->pr_slock); |
| panic("pool_get: %s: crossed hard limit", pp->pr_wchan); |
panic("pool_get: %s: crossed hard limit", pp->pr_wchan); |
| } |
} |
| #endif |
#endif |
| if (pp->pr_nout == pp->pr_hardlimit) { |
if (__predict_false(pp->pr_nout == pp->pr_hardlimit)) { |
| if ((flags & PR_WAITOK) && !(flags & PR_LIMITFAIL)) { |
if ((flags & PR_WAITOK) && !(flags & PR_LIMITFAIL)) { |
| /* |
/* |
| * XXX: A warning isn't logged in this case. Should |
* XXX: A warning isn't logged in this case. Should |
| Line 614 _pool_get(pp, flags, file, line) |
|
| Line 619 _pool_get(pp, flags, file, line) |
|
| */ |
*/ |
| pp->pr_flags |= PR_WANTED; |
pp->pr_flags |= PR_WANTED; |
| pr_leave(pp); |
pr_leave(pp); |
| simple_unlock(&pp->pr_slock); |
ltsleep(pp, PSWP, pp->pr_wchan, 0, &pp->pr_slock); |
| tsleep((caddr_t)pp, PSWP, pp->pr_wchan, 0); |
|
| simple_lock(&pp->pr_slock); |
|
| pr_enter(pp, file, line); |
pr_enter(pp, file, line); |
| goto startover; |
goto startover; |
| } |
} |
| if (pp->pr_hardlimit_warning != NULL) { |
|
| /* |
/* |
| * Log a message that the hard limit has been hit. |
* Log a message that the hard limit has been hit. |
| */ |
*/ |
| struct timeval curtime, logdiff; |
if (pp->pr_hardlimit_warning != NULL && |
| int s = splclock(); |
ratecheck(&pp->pr_hardlimit_warning_last, |
| curtime = mono_time; |
&pp->pr_hardlimit_ratecap)) |
| splx(s); |
log(LOG_ERR, "%s\n", pp->pr_hardlimit_warning); |
| timersub(&curtime, &pp->pr_hardlimit_warning_last, |
|
| &logdiff); |
|
| if (logdiff.tv_sec >= pp->pr_hardlimit_ratecap) { |
|
| pp->pr_hardlimit_warning_last = curtime; |
|
| log(LOG_ERR, "%s\n", pp->pr_hardlimit_warning); |
|
| } |
|
| } |
|
| |
|
| if (flags & PR_URGENT) |
if (flags & PR_URGENT) |
| panic("pool_get: urgent"); |
panic("pool_get: urgent"); |
| Line 708 _pool_get(pp, flags, file, line) |
|
| Line 704 _pool_get(pp, flags, file, line) |
|
| */ |
*/ |
| pp->pr_flags |= PR_WANTED; |
pp->pr_flags |= PR_WANTED; |
| pr_leave(pp); |
pr_leave(pp); |
| simple_unlock(&pp->pr_slock); |
ltsleep(pp, PSWP, pp->pr_wchan, 0, &pp->pr_slock); |
| tsleep((caddr_t)pp, PSWP, pp->pr_wchan, 0); |
|
| simple_lock(&pp->pr_slock); |
|
| pr_enter(pp, file, line); |
pr_enter(pp, file, line); |
| goto startover; |
goto startover; |
| } |
} |
| Line 723 _pool_get(pp, flags, file, line) |
|
| Line 717 _pool_get(pp, flags, file, line) |
|
| goto startover; |
goto startover; |
| } |
} |
| |
|
| if ((v = pi = TAILQ_FIRST(&ph->ph_itemlist)) == NULL) { |
if (__predict_false((v = pi = TAILQ_FIRST(&ph->ph_itemlist)) == NULL)) { |
| pr_leave(pp); |
pr_leave(pp); |
| simple_unlock(&pp->pr_slock); |
simple_unlock(&pp->pr_slock); |
| panic("pool_get: %s: page empty", pp->pr_wchan); |
panic("pool_get: %s: page empty", pp->pr_wchan); |
| } |
} |
| #ifdef DIAGNOSTIC |
#ifdef DIAGNOSTIC |
| if (pp->pr_nitems == 0) { |
if (__predict_false(pp->pr_nitems == 0)) { |
| pr_leave(pp); |
pr_leave(pp); |
| simple_unlock(&pp->pr_slock); |
simple_unlock(&pp->pr_slock); |
| printf("pool_get: %s: items on itemlist, nitems %u\n", |
printf("pool_get: %s: items on itemlist, nitems %u\n", |
| Line 740 _pool_get(pp, flags, file, line) |
|
| Line 734 _pool_get(pp, flags, file, line) |
|
| pr_log(pp, v, PRLOG_GET, file, line); |
pr_log(pp, v, PRLOG_GET, file, line); |
| |
|
| #ifdef DIAGNOSTIC |
#ifdef DIAGNOSTIC |
| if (pi->pi_magic != PI_MAGIC) { |
if (__predict_false(pi->pi_magic != PI_MAGIC)) { |
| pr_printlog(pp, pi, printf); |
pr_printlog(pp, pi, printf); |
| panic("pool_get(%s): free list modified: magic=%x; page %p;" |
panic("pool_get(%s): free list modified: magic=%x; page %p;" |
| " item addr %p\n", |
" item addr %p\n", |
| Line 756 _pool_get(pp, flags, file, line) |
|
| Line 750 _pool_get(pp, flags, file, line) |
|
| pp->pr_nout++; |
pp->pr_nout++; |
| if (ph->ph_nmissing == 0) { |
if (ph->ph_nmissing == 0) { |
| #ifdef DIAGNOSTIC |
#ifdef DIAGNOSTIC |
| if (pp->pr_nidle == 0) |
if (__predict_false(pp->pr_nidle == 0)) |
| panic("pool_get: nidle inconsistent"); |
panic("pool_get: nidle inconsistent"); |
| #endif |
#endif |
| pp->pr_nidle--; |
pp->pr_nidle--; |
| Line 764 _pool_get(pp, flags, file, line) |
|
| Line 758 _pool_get(pp, flags, file, line) |
|
| ph->ph_nmissing++; |
ph->ph_nmissing++; |
| if (TAILQ_FIRST(&ph->ph_itemlist) == NULL) { |
if (TAILQ_FIRST(&ph->ph_itemlist) == NULL) { |
| #ifdef DIAGNOSTIC |
#ifdef DIAGNOSTIC |
| if (ph->ph_nmissing != pp->pr_itemsperpage) { |
if (__predict_false(ph->ph_nmissing != pp->pr_itemsperpage)) { |
| pr_leave(pp); |
pr_leave(pp); |
| simple_unlock(&pp->pr_slock); |
simple_unlock(&pp->pr_slock); |
| panic("pool_get: %s: nmissing inconsistent", |
panic("pool_get: %s: nmissing inconsistent", |
| Line 832 _pool_put(pp, v, file, line) |
|
| Line 826 _pool_put(pp, v, file, line) |
|
| pr_enter(pp, file, line); |
pr_enter(pp, file, line); |
| |
|
| #ifdef DIAGNOSTIC |
#ifdef DIAGNOSTIC |
| if (pp->pr_nout == 0) { |
if (__predict_false(pp->pr_nout == 0)) { |
| printf("pool %s: putting with none out\n", |
printf("pool %s: putting with none out\n", |
| pp->pr_wchan); |
pp->pr_wchan); |
| panic("pool_put"); |
panic("pool_put"); |
| Line 841 _pool_put(pp, v, file, line) |
|
| Line 835 _pool_put(pp, v, file, line) |
|
| |
|
| pr_log(pp, v, PRLOG_PUT, file, line); |
pr_log(pp, v, PRLOG_PUT, file, line); |
| |
|
| if ((ph = pr_find_pagehead(pp, page)) == NULL) { |
if (__predict_false((ph = pr_find_pagehead(pp, page)) == 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 857 _pool_put(pp, v, file, line) |
|
| Line 851 _pool_put(pp, v, file, line) |
|
| * Return to item list. |
* Return to item list. |
| */ |
*/ |
| #ifdef DIAGNOSTIC |
#ifdef DIAGNOSTIC |
| /* XXX Should fill the item. */ |
|
| pi->pi_magic = PI_MAGIC; |
pi->pi_magic = PI_MAGIC; |
| #endif |
#endif |
| |
#ifdef DEBUG |
| |
{ |
| |
int i, *ip = v; |
| |
|
| |
for (i = 0; i < pp->pr_size / sizeof(int); i++) { |
| |
*ip++ = PI_MAGIC; |
| |
} |
| |
} |
| |
#endif |
| |
|
| TAILQ_INSERT_HEAD(&ph->ph_itemlist, pi, pi_list); |
TAILQ_INSERT_HEAD(&ph->ph_itemlist, pi, pi_list); |
| ph->ph_nmissing--; |
ph->ph_nmissing--; |
| pp->pr_nput++; |
pp->pr_nput++; |
| Line 958 pool_prime(pp, n, storage) |
|
| Line 961 pool_prime(pp, n, storage) |
|
| int newnitems, newpages; |
int newnitems, newpages; |
| |
|
| #ifdef DIAGNOSTIC |
#ifdef DIAGNOSTIC |
| if (storage && !(pp->pr_roflags & PR_STATIC)) |
if (__predict_false(storage && !(pp->pr_roflags & PR_STATIC))) |
| panic("pool_prime: static"); |
panic("pool_prime: static"); |
| /* !storage && static caught below */ |
/* !storage && static caught below */ |
| #endif |
#endif |
| Line 1016 pool_prime_page(pp, storage) |
|
| Line 1019 pool_prime_page(pp, storage) |
|
| unsigned int ioff = pp->pr_itemoffset; |
unsigned int ioff = pp->pr_itemoffset; |
| int s, n; |
int s, n; |
| |
|
| |
if (((u_long)cp & (pp->pr_pagesz - 1)) != 0) |
| |
panic("pool_prime_page: %s: unaligned page", pp->pr_wchan); |
| |
|
| if ((pp->pr_roflags & PR_PHINPAGE) != 0) { |
if ((pp->pr_roflags & PR_PHINPAGE) != 0) { |
| ph = (struct pool_item_header *)(cp + pp->pr_phoffset); |
ph = (struct pool_item_header *)(cp + pp->pr_phoffset); |
| } else { |
} else { |
| Line 1118 pool_catchup(pp) |
|
| Line 1124 pool_catchup(pp) |
|
| simple_unlock(&pp->pr_slock); |
simple_unlock(&pp->pr_slock); |
| cp = (*pp->pr_alloc)(pp->pr_pagesz, 0, pp->pr_mtype); |
cp = (*pp->pr_alloc)(pp->pr_pagesz, 0, pp->pr_mtype); |
| simple_lock(&pp->pr_slock); |
simple_lock(&pp->pr_slock); |
| if (cp == NULL) { |
if (__predict_false(cp == NULL)) { |
| error = ENOMEM; |
error = ENOMEM; |
| break; |
break; |
| } |
} |
| Line 1182 pool_sethardlimit(pp, n, warnmess, ratec |
|
| Line 1188 pool_sethardlimit(pp, n, warnmess, ratec |
|
| |
|
| pp->pr_hardlimit = n; |
pp->pr_hardlimit = n; |
| pp->pr_hardlimit_warning = warnmess; |
pp->pr_hardlimit_warning = warnmess; |
| pp->pr_hardlimit_ratecap = ratecap; |
pp->pr_hardlimit_ratecap.tv_sec = ratecap; |
| memset(&pp->pr_hardlimit_warning_last, 0, |
pp->pr_hardlimit_warning_last.tv_sec = 0; |
| sizeof(pp->pr_hardlimit_warning_last)); |
pp->pr_hardlimit_warning_last.tv_usec = 0; |
| |
|
| /* |
/* |
| * In-line version of pool_sethiwat(), because we don't want to |
* In-line version of pool_sethiwat(), because we don't want to |