Download raw body.
Fix pool_sethardlimit(9) for pool caches
Hi, when an item is returned from a pool cache to the underlying pool the count of currently allocated items is not decremented. This can cause pool_get calls to fail if the pool has a hard limit configured even when there are actually less items allocated than specified by the limit. To fix this simply move the 'pr_nout--' statement into the pool_do_put function which is used by the pool cache garbage collector. Note: According to pool_cache_init(9) any limits set on the pool with pool_sethardlimit(9) are ignored. This is currently not the case though and fixing hard limits to work with pool caches and removing the caveat from the man page seems better than ignoring the limits in my opinion. diff --git share/man/man9/pool_cache_init.9 share/man/man9/pool_cache_init.9 index 69536e6d440..a9e3e3b6f69 100644 --- share/man/man9/pool_cache_init.9 +++ share/man/man9/pool_cache_init.9 @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: January 12 2018 $ +.Dd $Mdocdate: August 05 2024 $ .Dt POOL_CACHE_INIT 9 .Os .Sh NAME @@ -183,16 +183,3 @@ The pool implementation is in the file .Xr systat 1 , .Xr sysctl 2 , .Xr pool_get 9 -.Sh CAVEATS -Because the intention of per CPU pool caches is to avoid having -all CPUs coordinate via shared data structures for handling -.Xr pool_get 9 -and -.Xr pool_put 9 -operations, any limits set on the pool with -.Xr pool_sethardlimit 9 -are ignored. -If limits on the memory used by a pool with per CPU caches enabled -are needed, they must be enforced by a page allocator specified -when a pool is set up with -.Xr pool_init 9 . diff --git sys/kern/subr_pool.c sys/kern/subr_pool.c index 587eff13676..d461558569e 100644 --- sys/kern/subr_pool.c +++ sys/kern/subr_pool.c @@ -796,7 +796,6 @@ pool_put(struct pool *pp, void *v) pool_do_put(pp, v); - pp->pr_nout--; pp->pr_nput++; /* is it time to free a page? */ @@ -833,6 +832,8 @@ pool_do_put(struct pool *pp, void *v) splassert(pp->pr_ipl); + pp->pr_nout--; + ph = pr_find_pagehead(pp, v); #ifdef DIAGNOSTIC
Fix pool_sethardlimit(9) for pool caches