Source-Changes-HG archive

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

[src/trunk]: src/sys/kern skip redzone on pools with the allocation (includin...



details:   https://anonhg.NetBSD.org/src/rev/eb2c0568236e
branches:  trunk
changeset: 953044:eb2c0568236e
user:      mrg <mrg%NetBSD.org@localhost>
date:      Wed Feb 24 05:36:02 2021 +0000

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

diffstat:

 sys/kern/subr_pool.c |  11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)

diffs (34 lines):

diff -r 48159da52711 -r eb2c0568236e sys/kern/subr_pool.c
--- a/sys/kern/subr_pool.c      Wed Feb 24 02:33:56 2021 +0000
+++ b/sys/kern/subr_pool.c      Wed Feb 24 05:36:02 2021 +0000
@@ -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 @@
        /*
         * 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;



Home | Main Index | Thread Index | Old Index