Module Name: src
Committed By: chs
Date: Mon Apr 13 00:27:17 UTC 2020
Modified Files:
src/share/man/man9: pool.9 pool_cache.9
src/sys/arch/arm/arm32: pmap.c
src/sys/arch/xen/x86: xen_shm_machdep.c
src/sys/arch/xen/xen: xbdback_xenbus.c
src/sys/dev/ic: ncr53c9x.c
src/sys/dev/raidframe: rf_netbsdkintf.c rf_reconmap.c
src/sys/dev/scsipi: scsipi_base.c
src/sys/kern: subr_pool.c
src/sys/opencrypto: cryptodev.c
src/sys/sys: pool.h
Log Message:
slightly change and fix the semantics of pool_set*wat(), pool_sethardlimit()
and pool_prime() (and their pool_cache_* counterparts):
- the pool_set*wat() APIs are supposed to specify thresholds for the count of
free items in the pool before pool pages are automatically allocated or freed
during pool_get() / pool_put(), whereas pool_sethardlimit() and pool_prime()
are supposed to specify minimum and maximum numbers of total items
in the pool (both free and allocated). these were somewhat conflated
in the existing code, so separate them as they were intended.
- change pool_prime() to take an absolute number of items to preallocate
rather than an increment over whatever was done before, and wait for
any memory allocations to succeed. since pool_prime() can no longer fail
after this, change its return value to void and adjust all callers.
- pool_setlowat() is documented as not immediately attempting to allocate
any memory, but it was changed some time ago to immediately try to allocate
up to the lowat level, so just fix the manpage to describe the current
behaviour.
- add a pool_cache_prime() to complete the API set.
To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/share/man/man9/pool.9
cvs rdiff -u -r1.20 -r1.21 src/share/man/man9/pool_cache.9
cvs rdiff -u -r1.402 -r1.403 src/sys/arch/arm/arm32/pmap.c
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/xen/x86/xen_shm_machdep.c
cvs rdiff -u -r1.77 -r1.78 src/sys/arch/xen/xen/xbdback_xenbus.c
cvs rdiff -u -r1.152 -r1.153 src/sys/dev/ic/ncr53c9x.c
cvs rdiff -u -r1.381 -r1.382 src/sys/dev/raidframe/rf_netbsdkintf.c
cvs rdiff -u -r1.37 -r1.38 src/sys/dev/raidframe/rf_reconmap.c
cvs rdiff -u -r1.185 -r1.186 src/sys/dev/scsipi/scsipi_base.c
cvs rdiff -u -r1.266 -r1.267 src/sys/kern/subr_pool.c
cvs rdiff -u -r1.104 -r1.105 src/sys/opencrypto/cryptodev.c
cvs rdiff -u -r1.89 -r1.90 src/sys/sys/pool.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/share/man/man9/pool.9
diff -u src/share/man/man9/pool.9:1.47 src/share/man/man9/pool.9:1.48
--- src/share/man/man9/pool.9:1.47 Sun Feb 10 17:15:45 2019
+++ src/share/man/man9/pool.9 Mon Apr 13 00:27:16 2020
@@ -1,4 +1,4 @@
-.\" $NetBSD: pool.9,v 1.47 2019/02/10 17:15:45 christos Exp $
+.\" $NetBSD: pool.9,v 1.48 2020/04/13 00:27:16 chs Exp $
.\"
.\" Copyright (c) 1997, 1998, 2007 The NetBSD Foundation, Inc.
.\" All rights reserved.
@@ -27,7 +27,7 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd February 10, 2019
+.Dd April 12, 2020
.Dt POOL 9
.Os
.Sh NAME
@@ -59,8 +59,8 @@
.Fn pool_get "struct pool *pp" "int flags"
.Ft void
.Fn pool_put "struct pool *pp" "void *item"
-.Ft int
-.Fn pool_prime "struct pool *pp" "int nitems"
+.Ft void
+.Fn pool_prime "struct pool *pp" "int n"
.Ft void
.Fn pool_sethiwat "struct pool *pp" "int n"
.Ft void
@@ -193,28 +193,7 @@ The handle identifying the pool resource
A pointer to a pool item previously obtained by
.Fn pool_get .
.El
-.Ss PRIMING A POOL
-.Fn pool_prime
-adds items to the pool.
-Storage space for the items is allocated by using the page allocation
-routine specified to
-.Fn pool_create .
-.Pp
-The arguments to
-.Fn pool_prime
-are:
-.Bl -tag -offset indent -width "storage"
-.It Fa pp
-The handle identifying the pool resource instance.
-.It Fa nitems
-The number of items to add to the pool.
-.El
.Pp
-This function may return
-.Dv ENOMEM
-in case the requested number of items could not be allocated.
-Otherwise,
-the return value is 0.
.Ss SETTING POOL RESOURCE WATERMARKS AND LIMITS
A pool will attempt to increase its resource usage to keep up with the demand
for its items.
@@ -222,8 +201,8 @@ Conversely,
it will return unused memory to the system should the number of accumulated
unused items in the pool exceed a programmable limit.
.Pp
-The limits for the minimum and maximum number of items which a pool should keep
-at hand are known as the high and low
+The targets for the minimum and maximum number of free items which a pool should
+try to keep available are known as the high and low
.Sy watermarks .
The functions
.Fn pool_sethiwat
@@ -231,20 +210,27 @@ and
.Fn pool_setlowat
set a pool's high and low watermarks, respectively.
.Pp
-The hard limit represents the maximum number of items a pool is allowed
-to allocate at any given time.
-Unless modified via
+The limits for the minimum and maximum number of total items (both free and
+allocated) that the pool can have at any time are specified by the functions
+.Fn pool_prime
+and
.Fn pool_sethardlimit ,
-the hard limit defaults to
-.Dv UINT_MAX .
+respectively.
+The defaults for these limits are
+.Dv 0
+and
+.Dv UINT_MAX ,
+respectively.
+Changing these limits will cause memory to be immediately allocated to the pool
+or freed from the pool as needed.
.Pp
.Fn pool_sethiwat
.Bl -tag -offset indent -width "flags"
.It Fa pp
The handle identifying the pool resource instance.
.It Fa n
-The maximum number of items to keep in the pool.
-As items are returned and the total number of pages in the pool is larger
+The maximum number of free items to keep in the pool.
+As items are returned and the total number of free items in the pool is larger
than the maximum set by this function,
any completely unused pages are released immediately.
If this function is not used to specify a maximum number of items,
@@ -258,12 +244,10 @@ at which point the VM system will try to
.It Fa pp
The handle identifying the pool resource instance.
.It Fa n
-The minimum number of items to keep in the pool.
-The number pages in the pool will not decrease below the required value to
-accommodate the minimum number of items specified by this function.
-Unlike
-.Fn pool_prime ,
-this function does not allocate the necessary memory up-front.
+The minimum number of free items to keep in the pool.
+When the number of free items in the pool drops below this threshold,
+a non-blocking attempt is made to allocate memory for more items.
+The number of free items is not guaranteed to remain above this threshold.
.El
.Pp
.Fn pool_sethardlimit
@@ -271,14 +255,23 @@ this function does not allocate the nece
.It Fa pp
The handle identifying the pool resource instance.
.It Fa n
-The maximum number of items to be allocated from the pool (i.e. the
-hard limit).
+The maximum number of total items in the pool (i.e. the hard limit).
.It Fa warnmess
The warning message that will be logged when the hard limit is reached.
.It Fa ratecap
The minimal interval (in seconds) after which another warning message
is issued when the pool hits its hard limit again.
.El
+.Pp
+.Fn pool_prime
+.Bl -tag -offset indent -width "storage"
+.It Fa pp
+The handle identifying the pool resource instance.
+.It Fa n
+The minimum number of total items for the pool.
+If the current number of total items is less than the new minimum then new items
+are allocated with blocking allocations.
+.El
.Ss POTENTIAL PITFALLS
Note that undefined behaviour results when mixing the storage providing
methods supported by the pool resource routines.
Index: src/share/man/man9/pool_cache.9
diff -u src/share/man/man9/pool_cache.9:1.20 src/share/man/man9/pool_cache.9:1.21
--- src/share/man/man9/pool_cache.9:1.20 Mon Apr 6 08:26:33 2020
+++ src/share/man/man9/pool_cache.9 Mon Apr 13 00:27:16 2020
@@ -1,4 +1,4 @@
-.\" $NetBSD: pool_cache.9,v 1.20 2020/04/06 08:26:33 rin Exp $
+.\" $NetBSD: pool_cache.9,v 1.21 2020/04/13 00:27:16 chs Exp $
.\"
.\" Copyright (c)2003 YAMAMOTO Takashi,
.\" All rights reserved.
@@ -53,7 +53,7 @@
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.\" ------------------------------------------------------------
-.Dd November 15, 2011
+.Dd April 12, 2020
.Dt POOL_CACHE 9
.Os
.\" ------------------------------------------------------------
@@ -111,13 +111,13 @@
.\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
.Ft void
.Fn pool_cache_sethiwat \
-"pool_cache_t pc" "int nitems"
+"pool_cache_t pc" "int n"
.Ft void
.Fn pool_cache_setlowat \
-"pool_cache_t pc" "int nitems"
+"pool_cache_t pc" "int n"
.Ft void
.Fn pool_cache_sethardlimit \
-"pool_cache_t pc" "int nitems" "const char *warnmess" "int ratecap"
+"pool_cache_t pc" "int n" "const char *warnmess" "int ratecap"
.\" ------------------------------------------------------------
.Sh DESCRIPTION
These utility routines provide management of pools of fixed-sized
@@ -307,21 +307,21 @@ For pool caches that vend constructed ob
must take care to provide proper synchronization between the input to
the constructor and cache invalidation.
.\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-.It Fn pool_cache_sethiwat "pc" "nitems"
+.It Fn pool_cache_sethiwat "pc" "n"
.Pp
A pool will attempt to increase its resource usage to keep up with the demand
for its items.
Conversely,
it will return unused memory to the system should the number of accumulated
-unused items in the pool exceed a programmable limit.
-The limits for the minimum and maximum number of items which a pool should keep
-at hand are known as the high and low
+free items in the pool exceed a programmable limit.
+The limits for the minimum and maximum number of free items which a pool should
+try to keep available are known as the high and low
.Sy watermarks .
.Pp
The function
.Fn pool_cache_sethiwat
sets the backing pool's high water mark.
-As items are returned and the total number of pages in the pool is larger
+As items are freed and the number of free items in the pool is larger
than the maximum set by this function,
any completely unused pages are released immediately.
If this function is not used to specify a maximum number of items,
@@ -329,23 +329,30 @@ the pages will remain associated with th
on memory,
at which point the VM system will try to reclaim unused pages.
.\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-.It Fn pool_cache_setlowat "pc" "nitems"
+.It Fn pool_cache_setlowat "pc" "n"
.Pp
-Set the minimum number of items to keep in the pool.
-The number pages in the pool will not decrease below the required value to
-accommodate the minimum number of items specified by this function.
+Set the minimum number of free items to try to keep in the pool.
+When the number of free items in the pool drops below this threshold,
+a non-blocking attempt is made to allocate memory for more items.
+The number of free items is not guaranteed to remain above this threshold.
.\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-.It Fn pool_cache_sethardlimit "pc" "nitems" "warnmess" "ratecap"
-Set the hard limit for the backing
+.It Fn pool_cache_sethardlimit "pc" "n" "warnmess" "ratecap"
+Set the maximum number of total items (both free and allocated) for the backing
.Xr pool 9
to
-.Fa nitems .
+.Fa n .
When the hard limit is reached, the warning message
.Fa warnmess
will be logged.
.Fa ratecap
represents the minimal interval (in seconds) after which another warning
message is issued when the pool hits its hard limit again.
+.\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+.It Fn pool_cache_prime "pc" "n"
+Set the minimum number of total items (both free and allocated) for the backing
+.Xr pool 9
+to
+.Fa n .
.El
.\" ------------------------------------------------------------
.Sh CODE REFERENCES
Index: src/sys/arch/arm/arm32/pmap.c
diff -u src/sys/arch/arm/arm32/pmap.c:1.402 src/sys/arch/arm/arm32/pmap.c:1.403
--- src/sys/arch/arm/arm32/pmap.c:1.402 Sun Mar 29 09:20:43 2020
+++ src/sys/arch/arm/arm32/pmap.c Mon Apr 13 00:27:16 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.402 2020/03/29 09:20:43 skrll Exp $ */
+/* $NetBSD: pmap.c,v 1.403 2020/04/13 00:27:16 chs Exp $ */
/*
* Copyright 2003 Wasabi Systems, Inc.
@@ -198,7 +198,7 @@
#endif
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.402 2020/03/29 09:20:43 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.403 2020/04/13 00:27:16 chs Exp $");
#include <sys/atomic.h>
#include <sys/param.h>
@@ -1312,7 +1312,7 @@ pmap_maxproc_set(int nmaxproc)
static const char pmap_l1ttpool_warnmsg[] =
"WARNING: l1ttpool limit reached; increase kern.maxproc";
-// pool_cache_setlowat(&pmap_l1tt_cache, nmaxproc);
+ pool_cache_prime(&pmap_l1tt_cache, nmaxproc);
/*
* Set the hard limit on the pmap_l1tt_cache to the number
Index: src/sys/arch/xen/x86/xen_shm_machdep.c
diff -u src/sys/arch/xen/x86/xen_shm_machdep.c:1.13 src/sys/arch/xen/x86/xen_shm_machdep.c:1.14
--- src/sys/arch/xen/x86/xen_shm_machdep.c:1.13 Sun Jan 27 02:08:39 2019
+++ src/sys/arch/xen/x86/xen_shm_machdep.c Mon Apr 13 00:27:16 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: xen_shm_machdep.c,v 1.13 2019/01/27 02:08:39 pgoyette Exp $ */
+/* $NetBSD: xen_shm_machdep.c,v 1.14 2020/04/13 00:27:16 chs Exp $ */
/*
* Copyright (c) 2006 Manuel Bouyer.
@@ -25,7 +25,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xen_shm_machdep.c,v 1.13 2019/01/27 02:08:39 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_shm_machdep.c,v 1.14 2020/04/13 00:27:16 chs Exp $");
#include <sys/types.h>
#include <sys/param.h>
@@ -93,10 +93,7 @@ xen_shm_init(void)
pool_init(&xen_shm_callback_pool, sizeof(struct xen_shm_callback_entry),
0, 0, 0, "xshmc", NULL, IPL_VM);
/* ensure we'll always get items */
- if (pool_prime(&xen_shm_callback_pool,
- PAGE_SIZE / sizeof(struct xen_shm_callback_entry)) != 0) {
- panic("xen_shm_init can't prime pool");
- }
+ pool_prime(&xen_shm_callback_pool, 1);
xen_shm_size = (XENSHM_NPAGES * PAGE_SIZE);
Index: src/sys/arch/xen/xen/xbdback_xenbus.c
diff -u src/sys/arch/xen/xen/xbdback_xenbus.c:1.77 src/sys/arch/xen/xen/xbdback_xenbus.c:1.78
--- src/sys/arch/xen/xen/xbdback_xenbus.c:1.77 Tue Apr 7 14:07:01 2020
+++ src/sys/arch/xen/xen/xbdback_xenbus.c Mon Apr 13 00:27:17 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: xbdback_xenbus.c,v 1.77 2020/04/07 14:07:01 jdolecek Exp $ */
+/* $NetBSD: xbdback_xenbus.c,v 1.78 2020/04/13 00:27:17 chs Exp $ */
/*
* Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.77 2020/04/07 14:07:01 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.78 2020/04/13 00:27:17 chs Exp $");
#include <sys/atomic.h>
#include <sys/buf.h>
@@ -380,13 +380,10 @@ xbdbackattach(int n)
IPL_SOFTBIO, NULL, NULL, NULL);
/* we allocate enough to handle a whole ring at once */
- if (pool_prime(&xbdback_request_pool.pc.pc_pool, BLKIF_RING_SIZE) != 0)
- printf("xbdback: failed to prime request pool\n");
- if (pool_prime(&xbdback_io_pool.pc.pc_pool, BLKIF_RING_SIZE) != 0)
- printf("xbdback: failed to prime io pool\n");
- if (pool_prime(&xbdback_fragment_pool.pc.pc_pool,
- BLKIF_MAX_SEGMENTS_PER_REQUEST * BLKIF_RING_SIZE) != 0)
- printf("xbdback: failed to prime fragment pool\n");
+ pool_prime(&xbdback_request_pool.pc.pc_pool, BLKIF_RING_SIZE);
+ pool_prime(&xbdback_io_pool.pc.pc_pool, BLKIF_RING_SIZE);
+ pool_prime(&xbdback_fragment_pool.pc.pc_pool,
+ BLKIF_MAX_SEGMENTS_PER_REQUEST * BLKIF_RING_SIZE);
xenbus_backend_register(&xbd_backend_driver);
}
Index: src/sys/dev/ic/ncr53c9x.c
diff -u src/sys/dev/ic/ncr53c9x.c:1.152 src/sys/dev/ic/ncr53c9x.c:1.153
--- src/sys/dev/ic/ncr53c9x.c:1.152 Sun Nov 10 21:16:35 2019
+++ src/sys/dev/ic/ncr53c9x.c Mon Apr 13 00:27:17 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: ncr53c9x.c,v 1.152 2019/11/10 21:16:35 chs Exp $ */
+/* $NetBSD: ncr53c9x.c,v 1.153 2020/04/13 00:27:17 chs Exp $ */
/*-
* Copyright (c) 1998, 2002 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ncr53c9x.c,v 1.152 2019/11/10 21:16:35 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ncr53c9x.c,v 1.153 2020/04/13 00:27:17 chs Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -499,9 +499,7 @@ ncr53c9x_init(struct ncr53c9x_softc *sc,
pool_init(&ecb_pool, sizeof(struct ncr53c9x_ecb), 0, 0, 0,
"ncr53c9x_ecb", NULL, IPL_BIO);
/* make sure to always have some items to play with */
- if (pool_prime(&ecb_pool, 1) == ENOMEM) {
- printf("WARNING: not enough memory for ncr53c9x_ecb\n");
- }
+ pool_prime(&ecb_pool, 1);
ecb_pool_initialized = 1;
}
Index: src/sys/dev/raidframe/rf_netbsdkintf.c
diff -u src/sys/dev/raidframe/rf_netbsdkintf.c:1.381 src/sys/dev/raidframe/rf_netbsdkintf.c:1.382
--- src/sys/dev/raidframe/rf_netbsdkintf.c:1.381 Sat Mar 21 06:02:13 2020
+++ src/sys/dev/raidframe/rf_netbsdkintf.c Mon Apr 13 00:27:17 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: rf_netbsdkintf.c,v 1.381 2020/03/21 06:02:13 riastradh Exp $ */
+/* $NetBSD: rf_netbsdkintf.c,v 1.382 2020/04/13 00:27:17 chs Exp $ */
/*-
* Copyright (c) 1996, 1997, 1998, 2008-2011 The NetBSD Foundation, Inc.
@@ -101,7 +101,7 @@
***********************************************************/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rf_netbsdkintf.c,v 1.381 2020/03/21 06:02:13 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rf_netbsdkintf.c,v 1.382 2020/04/13 00:27:17 chs Exp $");
#ifdef _KERNEL_OPT
#include "opt_raid_autoconfig.h"
@@ -3506,13 +3506,10 @@ void
rf_pool_init(struct pool *p, size_t size, const char *w_chan,
size_t xmin, size_t xmax)
{
- int error;
pool_init(p, size, 0, 0, 0, w_chan, NULL, IPL_BIO);
pool_sethiwat(p, xmax);
- if ((error = pool_prime(p, xmin)) != 0)
- panic("%s: failed to prime pool: %d", __func__, error);
- pool_setlowat(p, xmin);
+ pool_prime(p, xmin);
}
/*
Index: src/sys/dev/raidframe/rf_reconmap.c
diff -u src/sys/dev/raidframe/rf_reconmap.c:1.37 src/sys/dev/raidframe/rf_reconmap.c:1.38
--- src/sys/dev/raidframe/rf_reconmap.c:1.37 Sat Feb 9 03:34:00 2019
+++ src/sys/dev/raidframe/rf_reconmap.c Mon Apr 13 00:27:17 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: rf_reconmap.c,v 1.37 2019/02/09 03:34:00 christos Exp $ */
+/* $NetBSD: rf_reconmap.c,v 1.38 2020/04/13 00:27:17 chs Exp $ */
/*
* Copyright (c) 1995 Carnegie-Mellon University.
* All rights reserved.
@@ -34,7 +34,7 @@
*************************************************************************/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rf_reconmap.c,v 1.37 2019/02/09 03:34:00 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rf_reconmap.c,v 1.38 2020/04/13 00:27:17 chs Exp $");
#include "rf_raid.h"
#include <sys/time.h>
@@ -86,7 +86,6 @@ rf_MakeReconMap(RF_Raid_t *raidPtr, RF_S
RF_RaidLayout_t *layoutPtr = &raidPtr->Layout;
RF_ReconUnitCount_t num_rus = layoutPtr->stripeUnitsPerDisk / layoutPtr->SUsPerRU;
RF_ReconMap_t *p;
- int error;
p = RF_Malloc(sizeof(*p));
p->sectorsPerReconUnit = ru_sectors;
@@ -105,8 +104,7 @@ rf_MakeReconMap(RF_Raid_t *raidPtr, RF_S
pool_init(&p->elem_pool, sizeof(RF_ReconMapListElem_t), 0,
0, 0, "raidreconpl", NULL, IPL_BIO);
- if ((error = pool_prime(&p->elem_pool, RF_NUM_RECON_POOL_ELEM)) != 0)
- panic("%s: failed to prime pool: %d", __func__, error);
+ pool_prime(&p->elem_pool, RF_NUM_RECON_POOL_ELEM);
rf_init_mutex2(p->mutex, IPL_VM);
rf_init_cond2(p->cv, "reconupdate");
@@ -399,4 +397,3 @@ rf_PrintReconSchedule(RF_ReconMap_t *map
}
}
#endif
-
Index: src/sys/dev/scsipi/scsipi_base.c
diff -u src/sys/dev/scsipi/scsipi_base.c:1.185 src/sys/dev/scsipi/scsipi_base.c:1.186
--- src/sys/dev/scsipi/scsipi_base.c:1.185 Wed Feb 19 16:05:41 2020
+++ src/sys/dev/scsipi/scsipi_base.c Mon Apr 13 00:27:17 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: scsipi_base.c,v 1.185 2020/02/19 16:05:41 riastradh Exp $ */
+/* $NetBSD: scsipi_base.c,v 1.186 2020/04/13 00:27:17 chs Exp $ */
/*-
* Copyright (c) 1998, 1999, 2000, 2002, 2003, 2004 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: scsipi_base.c,v 1.185 2020/02/19 16:05:41 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: scsipi_base.c,v 1.186 2020/04/13 00:27:17 chs Exp $");
#ifdef _KERNEL_OPT
#include "opt_scsi.h"
@@ -141,10 +141,7 @@ scsipi_init(void)
/* Initialize the scsipi_xfer pool. */
pool_init(&scsipi_xfer_pool, sizeof(struct scsipi_xfer), 0,
0, 0, "scxspl", NULL, IPL_BIO);
- if (pool_prime(&scsipi_xfer_pool,
- PAGE_SIZE / sizeof(struct scsipi_xfer)) == ENOMEM) {
- printf("WARNING: not enough memory for scsipi_xfer_pool\n");
- }
+ pool_prime(&scsipi_xfer_pool, 1);
scsipi_ioctl_init();
}
Index: src/sys/kern/subr_pool.c
diff -u src/sys/kern/subr_pool.c:1.266 src/sys/kern/subr_pool.c:1.267
--- src/sys/kern/subr_pool.c:1.266 Sat Feb 8 07:07:07 2020
+++ src/sys/kern/subr_pool.c Mon Apr 13 00:27:17 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_pool.c,v 1.266 2020/02/08 07:07:07 maxv Exp $ */
+/* $NetBSD: subr_pool.c,v 1.267 2020/04/13 00:27:17 chs Exp $ */
/*
* Copyright (c) 1997, 1999, 2000, 2002, 2007, 2008, 2010, 2014, 2015, 2018
@@ -33,7 +33,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_pool.c,v 1.266 2020/02/08 07:07:07 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_pool.c,v 1.267 2020/04/13 00:27:17 chs Exp $");
#ifdef _KERNEL_OPT
#include "opt_ddb.h"
@@ -293,7 +293,8 @@ struct pool_item {
};
#define POOL_NEEDS_CATCHUP(pp) \
- ((pp)->pr_nitems < (pp)->pr_minitems)
+ ((pp)->pr_nitems < (pp)->pr_minitems || \
+ (pp)->pr_npages < (pp)->pr_minpages)
#define POOL_OBJ_TO_PAGE(pp, v) \
(void *)((uintptr_t)v & pp->pr_alloc->pa_pagemask)
@@ -1261,7 +1262,8 @@ pool_do_put(struct pool *pp, void *v, st
*/
if (ph->ph_nmissing == 0) {
pp->pr_nidle++;
- if (pp->pr_npages > pp->pr_minpages &&
+ if (pp->pr_nitems - pp->pr_itemsperpage >= pp->pr_minitems &&
+ pp->pr_npages > pp->pr_minpages &&
pp->pr_npages > pp->pr_maxpages) {
pr_rmpage(pp, ph, pq);
} else {
@@ -1386,35 +1388,17 @@ out:
return ENOMEM;
}
-/*
- * Add N items to the pool.
- */
-int
+void
pool_prime(struct pool *pp, int n)
{
- int newpages;
- int error = 0;
mutex_enter(&pp->pr_lock);
-
- newpages = roundup(n, pp->pr_itemsperpage) / pp->pr_itemsperpage;
-
- while (newpages > 0) {
- error = pool_grow(pp, PR_NOWAIT);
- if (error) {
- if (error == ERESTART)
- continue;
- break;
- }
- pp->pr_minpages++;
- newpages--;
- }
-
- if (pp->pr_minpages >= pp->pr_maxpages)
+ pp->pr_minpages = roundup(n, pp->pr_itemsperpage) / pp->pr_itemsperpage;
+ if (pp->pr_maxpages <= pp->pr_minpages)
pp->pr_maxpages = pp->pr_minpages + 1; /* XXX */
-
+ while (pp->pr_npages < pp->pr_minpages)
+ (void) pool_grow(pp, PR_WAITOK);
mutex_exit(&pp->pr_lock);
- return error;
}
/*
@@ -1542,11 +1526,7 @@ pool_setlowat(struct pool *pp, int n)
{
mutex_enter(&pp->pr_lock);
-
pp->pr_minitems = n;
- pp->pr_minpages = (n == 0)
- ? 0
- : roundup(n, pp->pr_itemsperpage) / pp->pr_itemsperpage;
/* Make sure we're caught up with the newly-set low water mark. */
if (POOL_NEEDS_CATCHUP(pp) && pool_catchup(pp) != 0) {
@@ -1566,9 +1546,7 @@ pool_sethiwat(struct pool *pp, int n)
mutex_enter(&pp->pr_lock);
- pp->pr_maxpages = (n == 0)
- ? 0
- : roundup(n, pp->pr_itemsperpage) / pp->pr_itemsperpage;
+ pp->pr_maxitems = n;
mutex_exit(&pp->pr_lock);
}
@@ -1585,13 +1563,7 @@ pool_sethardlimit(struct pool *pp, int n
pp->pr_hardlimit_warning_last.tv_sec = 0;
pp->pr_hardlimit_warning_last.tv_usec = 0;
- /*
- * In-line version of pool_sethiwat(), because we don't want to
- * release the lock.
- */
- pp->pr_maxpages = (n == 0)
- ? 0
- : roundup(n, pp->pr_itemsperpage) / pp->pr_itemsperpage;
+ pp->pr_maxpages = roundup(n, pp->pr_itemsperpage) / pp->pr_itemsperpage;
mutex_exit(&pp->pr_lock);
}
@@ -1657,11 +1629,11 @@ pool_reclaim(struct pool *pp)
continue;
/*
- * If freeing this page would put us below
- * the low water mark, stop now.
+ * If freeing this page would put us below the minimum free items
+ * or the minimum pages, stop now.
*/
- if ((pp->pr_nitems - pp->pr_itemsperpage) <
- pp->pr_minitems)
+ if (pp->pr_nitems - pp->pr_itemsperpage < pp->pr_minitems ||
+ pp->pr_npages - 1 < pp->pr_minpages)
break;
pr_rmpage(pp, ph, &pq);
@@ -2428,6 +2400,13 @@ pool_cache_sethardlimit(pool_cache_t pc,
pool_sethardlimit(&pc->pc_pool, n, warnmess, ratecap);
}
+void
+pool_cache_prime(pool_cache_t pc, int n)
+{
+
+ pool_prime(&pc->pc_pool, n);
+}
+
static bool __noinline
pool_cache_get_slow(pool_cache_cpu_t *cc, int s, void **objectp,
paddr_t *pap, int flags)
Index: src/sys/opencrypto/cryptodev.c
diff -u src/sys/opencrypto/cryptodev.c:1.104 src/sys/opencrypto/cryptodev.c:1.105
--- src/sys/opencrypto/cryptodev.c:1.104 Mon Jan 27 02:56:15 2020
+++ src/sys/opencrypto/cryptodev.c Mon Apr 13 00:27:17 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: cryptodev.c,v 1.104 2020/01/27 02:56:15 pgoyette Exp $ */
+/* $NetBSD: cryptodev.c,v 1.105 2020/04/13 00:27:17 chs Exp $ */
/* $FreeBSD: src/sys/opencrypto/cryptodev.c,v 1.4.2.4 2003/06/03 00:09:02 sam Exp $ */
/* $OpenBSD: cryptodev.c,v 1.53 2002/07/10 22:21:30 mickey Exp $ */
@@ -64,7 +64,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.104 2020/01/27 02:56:15 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.105 2020/04/13 00:27:17 chs Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -2117,7 +2117,6 @@ cryptof_poll(struct file *fp, int events
void
cryptoattach(int num)
{
- int error;
crypto_init();
@@ -2135,9 +2134,8 @@ cryptoattach(int num)
* the negotiation, plus HMAC_SHA1 for the actual SSL records,
* consuming one session here for each algorithm.
*/
- if ((error = pool_prime(&fcrpl, 64)) != 0 ||
- (error = pool_prime(&csepl, 64 * 5)) != 0)
- panic("%s: can't prime pool: %d", __func__, error);
+ pool_prime(&fcrpl, 64);
+ pool_prime(&csepl, 64 * 5);
}
void crypto_attach(device_t, device_t, void *);
Index: src/sys/sys/pool.h
diff -u src/sys/sys/pool.h:1.89 src/sys/sys/pool.h:1.90
--- src/sys/sys/pool.h:1.89 Thu May 9 08:16:15 2019
+++ src/sys/sys/pool.h Mon Apr 13 00:27:17 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: pool.h,v 1.89 2019/05/09 08:16:15 skrll Exp $ */
+/* $NetBSD: pool.h,v 1.90 2020/04/13 00:27:17 chs Exp $ */
/*-
* Copyright (c) 1997, 1998, 1999, 2000, 2007 The NetBSD Foundation, Inc.
@@ -126,13 +126,14 @@ struct pool {
unsigned int pr_size; /* Size of item */
unsigned int pr_align; /* Requested alignment, must be 2^n */
unsigned int pr_itemoffset; /* offset of the item space */
- unsigned int pr_minitems; /* minimum # of items to keep */
- unsigned int pr_minpages; /* same in page units */
+ unsigned int pr_minitems; /* minimum # of free items to keep */
+ unsigned int pr_maxitems; /* maximum # of free items to keep */
+ unsigned int pr_minpages; /* minimum # of pages to keep */
unsigned int pr_maxpages; /* maximum # of pages to keep */
unsigned int pr_npages; /* # of pages allocated */
unsigned int pr_itemsperpage;/* # items that fit in a page */
unsigned int pr_poolid; /* id of the pool */
- unsigned int pr_nitems; /* number of available items in pool */
+ unsigned int pr_nitems; /* number of free items in pool */
unsigned int pr_nout; /* # items currently allocated */
unsigned int pr_hardlimit; /* hard limit to number of allocated
items */
@@ -314,7 +315,7 @@ void *pool_get(struct pool *, int);
void pool_put(struct pool *, void *);
int pool_reclaim(struct pool *);
-int pool_prime(struct pool *, int);
+void pool_prime(struct pool *, int);
void pool_setlowat(struct pool *, int);
void pool_sethiwat(struct pool *, int);
void pool_sethardlimit(struct pool *, int, const char *, int);
@@ -353,6 +354,7 @@ void pool_cache_set_drain_hook(pool_cac
void pool_cache_setlowat(pool_cache_t, int);
void pool_cache_sethiwat(pool_cache_t, int);
void pool_cache_sethardlimit(pool_cache_t, int, const char *, int);
+void pool_cache_prime(pool_cache_t, int);
void pool_cache_cpu_init(struct cpu_info *);
#define pool_cache_get(pc, f) pool_cache_get_paddr((pc), (f), NULL)