Module Name: src
Committed By: mrg
Date: Wed Feb 24 05:36:02 UTC 2021
Modified Files:
src/sys/kern: subr_pool.c
Log Message:
skip redzone on pools with the allocation (including all overhead)
on anything greater than half the pool pagesize.
this stops 4KiB being used per allocation from the kmem-02048 pool,
and 64KiB per allocation from the buf32k pool.
we're still wasting 1/4 of space for overhead on eg, the buf1k or
kmem-01024 pools. however, including overhead costs, the amount of
useless space (not used by consumer or overhead) reduces from 47%
to 18%, so this is far less bad overall.
there are a couple of ideas on solving this less ugly:
- pool redzones are enabled with DIAGNOSTIC kernels, which is
defined as being "fast, cheap". this is not cheap (though it
is relatively fast if you don't run out of memory) so it does
not really belong here as is, but DEBUG or a special option
would work for it.
- if we increase the "pool page" size for these pools, such that
the overhead over pool page is reduced to 5% or less, we can
have redzones for more allocations without using more space.
also, see this thread:
https://mail-index.netbsd.org/tech-kern/2021/02/23/msg027130.html
To generate a diff of this commit:
cvs rdiff -u -r1.275 -r1.276 src/sys/kern/subr_pool.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/kern/subr_pool.c
diff -u src/sys/kern/subr_pool.c:1.275 src/sys/kern/subr_pool.c:1.276
--- src/sys/kern/subr_pool.c:1.275 Sat Dec 19 23:38:21 2020
+++ src/sys/kern/subr_pool.c Wed Feb 24 05:36:02 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_pool.c,v 1.275 2020/12/19 23:38:21 mrg Exp $ */
+/* $NetBSD: subr_pool.c,v 1.276 2021/02/24 05:36:02 mrg 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.275 2020/12/19 23:38:21 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_pool.c,v 1.276 2021/02/24 05:36:02 mrg Exp $");
#ifdef _KERNEL_OPT
#include "opt_ddb.h"
@@ -3096,9 +3096,14 @@ pool_redzone_init(struct pool *pp, size_
/*
* No space in the natural padding; check if we can extend a
* bit the size of the pool.
+ *
+ * Avoid using redzone for allocations half of a page or larger.
+ * For pagesize items, we'd waste a whole new page (could be
+ * unmapped?), and for half pagesize items, approximately half
+ * the space is lost (eg, 4K pages, you get one 2K allocation.)
*/
nsz = roundup(pp->pr_size + redzsz, pp->pr_align);
- if (nsz <= pp->pr_alloc->pa_pagesz) {
+ if (nsz <= (pp->pr_alloc->pa_pagesz / 2)) {
/* Ok, we can */
pp->pr_size = nsz;
pp->pr_reqsize_with_redzone = requested_size + redzsz;