Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/sys slightly change and fix the semantics of pool_set*wa...



details:   https://anonhg.NetBSD.org/src/rev/9622a46832d3
branches:  trunk
changeset: 971068:9622a46832d3
user:      chs <chs%NetBSD.org@localhost>
date:      Mon Apr 13 00:27:16 2020 +0000

description:
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.

diffstat:

 share/man/man9/pool.9              |  77 +++++++++++++++++--------------------
 share/man/man9/pool_cache.9        |  41 +++++++++++--------
 sys/arch/arm/arm32/pmap.c          |   6 +-
 sys/arch/xen/x86/xen_shm_machdep.c |   9 +--
 sys/arch/xen/xen/xbdback_xenbus.c  |  15 ++----
 sys/dev/ic/ncr53c9x.c              |   8 +--
 sys/dev/raidframe/rf_netbsdkintf.c |   9 +--
 sys/dev/raidframe/rf_reconmap.c    |   9 +--
 sys/dev/scsipi/scsipi_base.c       |   9 +--
 sys/kern/subr_pool.c               |  69 +++++++++++----------------------
 sys/opencrypto/cryptodev.c         |  10 +--
 sys/sys/pool.h                     |  12 +++--
 12 files changed, 118 insertions(+), 156 deletions(-)

diffs (truncated from 702 to 300 lines):

diff -r 36501d6e6c81 -r 9622a46832d3 share/man/man9/pool.9
--- a/share/man/man9/pool.9     Sun Apr 12 23:52:20 2020 +0000
+++ b/share/man/man9/pool.9     Mon Apr 13 00:27:16 2020 +0000
@@ -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 @@
 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 @@
 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 @@
 .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 @@
 .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 @@
 .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.
diff -r 36501d6e6c81 -r 9622a46832d3 share/man/man9/pool_cache.9
--- a/share/man/man9/pool_cache.9       Sun Apr 12 23:52:20 2020 +0000
+++ b/share/man/man9/pool_cache.9       Mon Apr 13 00:27:16 2020 +0000
@@ -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 @@
 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 @@
 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
diff -r 36501d6e6c81 -r 9622a46832d3 sys/arch/arm/arm32/pmap.c
--- a/sys/arch/arm/arm32/pmap.c Sun Apr 12 23:52:20 2020 +0000
+++ b/sys/arch/arm/arm32/pmap.c Mon Apr 13 00:27:16 2020 +0000
@@ -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 @@
        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
diff -r 36501d6e6c81 -r 9622a46832d3 sys/arch/xen/x86/xen_shm_machdep.c
--- a/sys/arch/xen/x86/xen_shm_machdep.c        Sun Apr 12 23:52:20 2020 +0000
+++ b/sys/arch/xen/x86/xen_shm_machdep.c        Mon Apr 13 00:27:16 2020 +0000
@@ -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 @@
        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");
-       }



Home | Main Index | Thread Index | Old Index