summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcheloha <cheloha@openbsd.org>2021-01-02 03:23:59 +0000
committercheloha <cheloha@openbsd.org>2021-01-02 03:23:59 +0000
commitcf76921f1fa0fb7980145d9ed240a3541ff2e1fc (patch)
tree61215797571e7f578e268e582a6bec7586c83947
parentbpf(4): remove ticks (diff)
downloadwireguard-openbsd-cf76921f1fa0fb7980145d9ed240a3541ff2e1fc.tar.xz
wireguard-openbsd-cf76921f1fa0fb7980145d9ed240a3541ff2e1fc.zip
pool(9): remove ticks
Change the pool(9) timeouts to use the system uptime instead of ticks. - Change the timeouts from variables to macros so we can use SEC_TO_NSEC(). This means these timeouts are no longer patchable via ddb(4). dlg@ does not think this will be a problem, as the timeout intervals have not changed in years. - Use low-res time to keep things fast. Add a local copy of getnsecuptime() to subr_pool.c to keep the diff small. We will need to move getnsecuptime() into kern_tc.c and document it later if we ever have other users elsewhere in the kernel. - Rename ph_tick -> ph_timestamp and pr_cache_tick -> pr_cache_timestamp. Prompted by tedu@ some time ago, but the effort stalled (may have been my fault). Input from kettenis@ and dlg@. Special thanks to mpi@ for help with struct shuffling. This change does not increase the size of struct pool_page_header or struct pool. ok dlg@ mpi@
-rw-r--r--sys/kern/subr_pool.c37
-rw-r--r--sys/sys/pool.h6
2 files changed, 29 insertions, 14 deletions
diff --git a/sys/kern/subr_pool.c b/sys/kern/subr_pool.c
index a2c941567f9..a233ff5bd8e 100644
--- a/sys/kern/subr_pool.c
+++ b/sys/kern/subr_pool.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: subr_pool.c,v 1.230 2020/01/24 06:31:17 cheloha Exp $ */
+/* $OpenBSD: subr_pool.c,v 1.231 2021/01/02 03:23:59 cheloha Exp $ */
/* $NetBSD: subr_pool.c,v 1.61 2001/09/26 07:14:56 chs Exp $ */
/*-
@@ -41,6 +41,7 @@
#include <sys/syslog.h>
#include <sys/sysctl.h>
#include <sys/task.h>
+#include <sys/time.h>
#include <sys/timeout.h>
#include <sys/percpu.h>
@@ -148,7 +149,7 @@ struct pool_page_header {
caddr_t ph_page; /* this page's address */
caddr_t ph_colored; /* page's colored address */
unsigned long ph_magic;
- int ph_tick;
+ uint64_t ph_timestamp;
};
#define POOL_MAGICBIT (1 << 3) /* keep away from perturbed low bits */
#define POOL_PHPOISON(ph) ISSET((ph)->ph_magic, POOL_MAGICBIT)
@@ -266,8 +267,22 @@ void pool_gc_sched(void *);
struct timeout pool_gc_tick = TIMEOUT_INITIALIZER(pool_gc_sched, NULL);
void pool_gc_pages(void *);
struct task pool_gc_task = TASK_INITIALIZER(pool_gc_pages, NULL);
-int pool_wait_free = 1;
-int pool_wait_gc = 8;
+
+#define POOL_WAIT_FREE SEC_TO_NSEC(1)
+#define POOL_WAIT_GC SEC_TO_NSEC(8)
+
+/*
+ * TODO Move getnsecuptime() to kern_tc.c and document it when we
+ * have callers in other modules.
+ */
+static uint64_t
+getnsecuptime(void)
+{
+ struct timespec now;
+
+ getnanouptime(&now);
+ return TIMESPEC_TO_NSEC(&now);
+}
RBT_PROTOTYPE(phtree, pool_page_header, ph_node, phtree_compare);
@@ -797,7 +812,7 @@ pool_put(struct pool *pp, void *v)
/* is it time to free a page? */
if (pp->pr_nidle > pp->pr_maxpages &&
(ph = TAILQ_FIRST(&pp->pr_emptypages)) != NULL &&
- (ticks - ph->ph_tick) > (hz * pool_wait_free)) {
+ getnsecuptime() - ph->ph_timestamp > POOL_WAIT_FREE) {
freeph = ph;
pool_p_remove(pp, freeph);
}
@@ -864,7 +879,7 @@ pool_do_put(struct pool *pp, void *v)
*/
pp->pr_nidle++;
- ph->ph_tick = ticks;
+ ph->ph_timestamp = getnsecuptime();
TAILQ_REMOVE(&pp->pr_partpages, ph, ph_entry);
TAILQ_INSERT_TAIL(&pp->pr_emptypages, ph, ph_entry);
pool_update_curpage(pp);
@@ -1566,7 +1581,7 @@ pool_gc_pages(void *null)
/* is it time to free a page? */
if (pp->pr_nidle > pp->pr_minpages &&
(ph = TAILQ_FIRST(&pp->pr_emptypages)) != NULL &&
- (ticks - ph->ph_tick) > (hz * pool_wait_gc)) {
+ getnsecuptime() - ph->ph_timestamp > POOL_WAIT_GC) {
freeph = ph;
pool_p_remove(pp, freeph);
} else
@@ -1726,7 +1741,7 @@ pool_cache_init(struct pool *pp)
arc4random_buf(pp->pr_cache_magic, sizeof(pp->pr_cache_magic));
TAILQ_INIT(&pp->pr_cache_lists);
pp->pr_cache_nitems = 0;
- pp->pr_cache_tick = ticks;
+ pp->pr_cache_timestamp = getnsecuptime();
pp->pr_cache_items = 8;
pp->pr_cache_contention = 0;
pp->pr_cache_ngc = 0;
@@ -1829,7 +1844,7 @@ pool_cache_list_free(struct pool *pp, struct pool_cache *pc,
{
pool_list_enter(pp);
if (TAILQ_EMPTY(&pp->pr_cache_lists))
- pp->pr_cache_tick = ticks;
+ pp->pr_cache_timestamp = getnsecuptime();
pp->pr_cache_nitems += POOL_CACHE_ITEM_NITEMS(ci);
TAILQ_INSERT_TAIL(&pp->pr_cache_lists, ci, ci_nextl);
@@ -2006,7 +2021,7 @@ pool_cache_gc(struct pool *pp)
{
unsigned int contention, delta;
- if ((ticks - pp->pr_cache_tick) > (hz * pool_wait_gc) &&
+ if (getnsecuptime() - pp->pr_cache_timestamp > POOL_WAIT_GC &&
!TAILQ_EMPTY(&pp->pr_cache_lists) &&
pl_enter_try(pp, &pp->pr_cache_lock)) {
struct pool_cache_item *pl = NULL;
@@ -2015,7 +2030,7 @@ pool_cache_gc(struct pool *pp)
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_timestamp = getnsecuptime();
pp->pr_cache_ngc++;
}
diff --git a/sys/sys/pool.h b/sys/sys/pool.h
index 7f68d50c5ea..3e64c3c34e5 100644
--- a/sys/sys/pool.h
+++ b/sys/sys/pool.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: pool.h,v 1.77 2019/07/19 09:03:03 bluhm Exp $ */
+/* $OpenBSD: pool.h,v 1.78 2021/01/02 03:23:59 cheloha Exp $ */
/* $NetBSD: pool.h,v 1.27 2001/06/06 22:00:17 rafal Exp $ */
/*-
@@ -201,9 +201,9 @@ struct pool {
u_int pr_cache_items; /* target list length */
u_int pr_cache_contention;
u_int pr_cache_contention_prev;
- int pr_cache_tick; /* time idle list was empty */
- int pr_cache_nout;
+ uint64_t pr_cache_timestamp; /* time idle list was empty */
uint64_t pr_cache_ngc; /* # of times the gc released a list */
+ int pr_cache_nout;
u_int pr_align;
u_int pr_maxcolors; /* Cache coloring */