From 9a59f80880a441f001cf639359b5ae85ae51b152 Mon Sep 17 00:00:00 2001 From: dlg Date: Fri, 23 Jun 2017 01:02:18 +0000 Subject: [PATCH] change the semantic for calculating when to grow the size of a cache list. previously it would figure out if there's enough items overall for all the cpus to have full active an inactive free lists. this included currently allocated items, which pools wont actually hold on a free list and cannot predict when they will come back. instead, see if there's enough items in the idle lists in the depot that could instead go on all the free lists on the cpus. if there's enough idle items, then we can grow. tested by hrvoje popovski and amit kulkarni ok visa@ --- share/man/man9/pool_cache_init.9 | 10 +++++----- sys/kern/subr_pool.c | 22 ++++++++-------------- sys/sys/pool.h | 6 +++--- usr.bin/systat/pool.c | 10 +++++----- 4 files changed, 21 insertions(+), 27 deletions(-) diff --git a/share/man/man9/pool_cache_init.9 b/share/man/man9/pool_cache_init.9 index a7c11c65411..f15e8f2bd6b 100644 --- a/share/man/man9/pool_cache_init.9 +++ b/share/man/man9/pool_cache_init.9 @@ -1,4 +1,4 @@ -.\" $OpenBSD: pool_cache_init.9,v 1.6 2017/06/22 02:30:34 dlg Exp $ +.\" $OpenBSD: pool_cache_init.9,v 1.7 2017/06/23 01:02:18 dlg Exp $ .\" .\" Copyright (c) 2017 David Gwynne .\" @@ -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: June 22 2017 $ +.Dd $Mdocdate: June 23 2017 $ .Dt POOL_CACHE_INIT 9 .Os .Sh NAME @@ -99,7 +99,7 @@ MIB hierarchy. struct kinfo_pool_cache { uint64_t pr_ngc; unsigned int pr_len; - unsigned int pr_nlist; + unsigned int pr_nitems; unsigned int pr_contention; }; .Ed @@ -112,8 +112,8 @@ an idle item free list. shows the maximum number of items that can be cached on a CPU's active free list. .Pp -.Va pr_nlist -shows the number of free lists that are currently stored in the +.Va pr_nitems +shows the number of free items that are currently stored in the global depot. .Pp .Va pr_contention diff --git a/sys/kern/subr_pool.c b/sys/kern/subr_pool.c index 72d73633dfc..f2af8219c44 100644 --- a/sys/kern/subr_pool.c +++ b/sys/kern/subr_pool.c @@ -1,4 +1,4 @@ -/* $OpenBSD: subr_pool.c,v 1.215 2017/06/19 23:57:12 dlg Exp $ */ +/* $OpenBSD: subr_pool.c,v 1.216 2017/06/23 01:02:18 dlg Exp $ */ /* $NetBSD: subr_pool.c,v 1.61 2001/09/26 07:14:56 chs Exp $ */ /*- @@ -1647,7 +1647,7 @@ pool_cache_init(struct pool *pp) mtx_init(&pp->pr_cache_mtx, pp->pr_ipl); arc4random_buf(pp->pr_cache_magic, sizeof(pp->pr_cache_magic)); TAILQ_INIT(&pp->pr_cache_lists); - pp->pr_cache_nlist = 0; + pp->pr_cache_nitems = 0; pp->pr_cache_tick = ticks; pp->pr_cache_items = 8; pp->pr_cache_contention = 0; @@ -1729,7 +1729,7 @@ pool_cache_list_alloc(struct pool *pp, struct pool_cache *pc) pl = TAILQ_FIRST(&pp->pr_cache_lists); if (pl != NULL) { TAILQ_REMOVE(&pp->pr_cache_lists, pl, ci_nextl); - pp->pr_cache_nlist--; + pp->pr_cache_nitems -= POOL_CACHE_ITEM_NITEMS(pl); pool_cache_item_magic(pp, pl); @@ -1753,8 +1753,8 @@ pool_cache_list_free(struct pool *pp, struct pool_cache *pc, if (TAILQ_EMPTY(&pp->pr_cache_lists)) pp->pr_cache_tick = ticks; + pp->pr_cache_nitems += POOL_CACHE_ITEM_NITEMS(ci); TAILQ_INSERT_TAIL(&pp->pr_cache_lists, ci, ci_nextl); - pp->pr_cache_nlist++; pc->pc_nlput++; @@ -1936,8 +1936,8 @@ pool_cache_gc(struct pool *pp) pl = TAILQ_FIRST(&pp->pr_cache_lists); if (pl != NULL) { TAILQ_REMOVE(&pp->pr_cache_lists, pl, ci_nextl); + pp->pr_cache_nitems -= POOL_CACHE_ITEM_NITEMS(pl); pp->pr_cache_tick = ticks; - pp->pr_cache_nlist--; pp->pr_cache_ngc++; } @@ -1955,14 +1955,8 @@ pool_cache_gc(struct pool *pp) contention = pp->pr_cache_contention; if ((contention - pp->pr_cache_contention_prev) > 8 /* magic */) { - unsigned int limit = pp->pr_npages * pp->pr_itemsperpage; - unsigned int items = pp->pr_cache_items + 8; - unsigned int cache = ncpusfound * items * 2; - - /* are there enough items around so every cpu can hold some? */ - - if (cache < limit) - pp->pr_cache_items = items; + if ((ncpusfound * 8 * 2) <= pp->pr_cache_nitems) + pp->pr_cache_items += 8; } pp->pr_cache_contention_prev = contention; } @@ -2016,7 +2010,7 @@ pool_cache_info(struct pool *pp, void *oldp, size_t *oldlenp) mtx_enter(&pp->pr_cache_mtx); kpc.pr_ngc = pp->pr_cache_ngc; kpc.pr_len = pp->pr_cache_items; - kpc.pr_nlist = pp->pr_cache_nlist; + kpc.pr_nitems = pp->pr_cache_nitems; kpc.pr_contention = pp->pr_cache_contention; mtx_leave(&pp->pr_cache_mtx); diff --git a/sys/sys/pool.h b/sys/sys/pool.h index e98a9cda75f..c7471664ac6 100644 --- a/sys/sys/pool.h +++ b/sys/sys/pool.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pool.h,v 1.72 2017/06/19 23:57:12 dlg Exp $ */ +/* $OpenBSD: pool.h,v 1.73 2017/06/23 01:02:18 dlg Exp $ */ /* $NetBSD: pool.h,v 1.27 2001/06/06 22:00:17 rafal Exp $ */ /*- @@ -71,7 +71,7 @@ struct kinfo_pool { struct kinfo_pool_cache { uint64_t pr_ngc; /* # of times a list has been gc'ed */ unsigned int pr_len; /* current target for list len */ - unsigned int pr_nlist; /* # of lists in the pool */ + unsigned int pr_nitems; /* # of idle items in the depot */ unsigned int pr_contention; /* # of times mtx was busy */ }; @@ -186,7 +186,7 @@ struct pool { struct mutex pr_cache_mtx; struct pool_cache_lists pr_cache_lists; /* list of idle item lists */ - u_int pr_cache_nlist; /* # of idle lists */ + u_int pr_cache_nitems; /* # of idle items */ u_int pr_cache_items; /* target list length */ u_int pr_cache_contention; u_int pr_cache_contention_prev; diff --git a/usr.bin/systat/pool.c b/usr.bin/systat/pool.c index 0f09237c68b..b6691ae0da6 100644 --- a/usr.bin/systat/pool.c +++ b/usr.bin/systat/pool.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pool.c,v 1.12 2017/06/15 03:47:07 dlg Exp $ */ +/* $OpenBSD: pool.c,v 1.13 2017/06/23 01:02:18 dlg Exp $ */ /* * Copyright (c) 2008 Can Erkin Acar * @@ -142,7 +142,7 @@ int pool_cache_kbd_cb(int); field_def pool_cache_fields[] = { {"NAME", 12, 32, 1, FLD_ALIGN_LEFT, -1, 0, 0, 0}, {"LEN", 4, 4, 1, FLD_ALIGN_RIGHT, -1, 0, 0, 0}, - {"NL", 4, 4, 1, FLD_ALIGN_RIGHT, -1, 0, 0, 0}, + {"IDLE", 4, 4, 1, FLD_ALIGN_RIGHT, -1, 0, 0, 0}, {"NGC", 4, 4, 1, FLD_ALIGN_RIGHT, -1, 0, 0, 0}, {"CPU", 4, 4, 1, FLD_ALIGN_RIGHT, -1, 0, 0, 0}, {"REQ", 8, 12, 1, FLD_ALIGN_RIGHT, -1, 0, 0, 0}, @@ -153,7 +153,7 @@ field_def pool_cache_fields[] = { #define FLD_POOL_CACHE_NAME FIELD_ADDR(pool_cache_fields, 0) #define FLD_POOL_CACHE_LEN FIELD_ADDR(pool_cache_fields, 1) -#define FLD_POOL_CACHE_NL FIELD_ADDR(pool_cache_fields, 2) +#define FLD_POOL_CACHE_IDLE FIELD_ADDR(pool_cache_fields, 2) #define FLD_POOL_CACHE_NGC FIELD_ADDR(pool_cache_fields, 3) #define FLD_POOL_CACHE_CPU FIELD_ADDR(pool_cache_fields, 4) #define FLD_POOL_CACHE_GET FIELD_ADDR(pool_cache_fields, 5) @@ -164,7 +164,7 @@ field_def pool_cache_fields[] = { field_def *view_pool_cache_0[] = { FLD_POOL_CACHE_NAME, FLD_POOL_CACHE_LEN, - FLD_POOL_CACHE_NL, + FLD_POOL_CACHE_IDLE, FLD_POOL_CACHE_NGC, FLD_POOL_CACHE_CPU, FLD_POOL_CACHE_GET, @@ -556,7 +556,7 @@ pool_cache_show(const struct pool_cache_info *pc) print_fld_str(FLD_POOL_CACHE_NAME, pc->name); print_fld_uint(FLD_POOL_CACHE_LEN, kpc->pr_len); - print_fld_uint(FLD_POOL_CACHE_NL, kpc->pr_nlist); + print_fld_uint(FLD_POOL_CACHE_IDLE, kpc->pr_nitems); print_fld_uint(FLD_POOL_CACHE_NGC, kpc->pr_ngc); for (cpu = 0; cpu < ncpusfound; cpu++) { -- 2.20.1