From 39c73ac77e4aa3b464eba41d5bf747e695f91b02 Mon Sep 17 00:00:00 2001 From: mpi Date: Wed, 31 Mar 2021 08:53:39 +0000 Subject: [PATCH] Introduce UAO_USES_SWHASH() and use tabs instead of spaces in #defines. No functionnal change, reduce the difference with NetBSD. ok jmatthew@ --- sys/uvm/uvm_aobj.c | 51 +++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/sys/uvm/uvm_aobj.c b/sys/uvm/uvm_aobj.c index db74848643e..f95b127900e 100644 --- a/sys/uvm/uvm_aobj.c +++ b/sys/uvm/uvm_aobj.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uvm_aobj.c,v 1.93 2021/03/26 13:40:05 mpi Exp $ */ +/* $OpenBSD: uvm_aobj.c,v 1.94 2021/03/31 08:53:39 mpi Exp $ */ /* $NetBSD: uvm_aobj.c,v 1.39 2001/02/18 21:19:08 chs Exp $ */ /* @@ -58,38 +58,39 @@ * Note: for hash tables, we break the address space of the aobj into blocks * of UAO_SWHASH_CLUSTER_SIZE pages, which shall be a power of two. */ -#define UAO_SWHASH_CLUSTER_SHIFT 4 -#define UAO_SWHASH_CLUSTER_SIZE (1 << UAO_SWHASH_CLUSTER_SHIFT) +#define UAO_SWHASH_CLUSTER_SHIFT 4 +#define UAO_SWHASH_CLUSTER_SIZE (1 << UAO_SWHASH_CLUSTER_SHIFT) /* Get the "tag" for this page index. */ -#define UAO_SWHASH_ELT_TAG(PAGEIDX) \ - ((PAGEIDX) >> UAO_SWHASH_CLUSTER_SHIFT) +#define UAO_SWHASH_ELT_TAG(idx) ((idx) >> UAO_SWHASH_CLUSTER_SHIFT) +#define UAO_SWHASH_ELT_PAGESLOT_IDX(idx) \ + ((idx) & (UAO_SWHASH_CLUSTER_SIZE - 1)) /* Given an ELT and a page index, find the swap slot. */ -#define UAO_SWHASH_ELT_PAGESLOT_IDX(PAGEIDX) \ - ((PAGEIDX) & (UAO_SWHASH_CLUSTER_SIZE - 1)) -#define UAO_SWHASH_ELT_PAGESLOT(ELT, PAGEIDX) \ - ((ELT)->slots[(PAGEIDX) & (UAO_SWHASH_CLUSTER_SIZE - 1)]) +#define UAO_SWHASH_ELT_PAGESLOT(elt, idx) \ + ((elt)->slots[UAO_SWHASH_ELT_PAGESLOT_IDX(idx)]) /* Given an ELT, return its pageidx base. */ -#define UAO_SWHASH_ELT_PAGEIDX_BASE(ELT) \ - ((ELT)->tag << UAO_SWHASH_CLUSTER_SHIFT) +#define UAO_SWHASH_ELT_PAGEIDX_BASE(elt) \ + ((elt)->tag << UAO_SWHASH_CLUSTER_SHIFT) /* The hash function. */ -#define UAO_SWHASH_HASH(AOBJ, PAGEIDX) \ - (&(AOBJ)->u_swhash[(((PAGEIDX) >> UAO_SWHASH_CLUSTER_SHIFT) \ - & (AOBJ)->u_swhashmask)]) +#define UAO_SWHASH_HASH(aobj, idx) \ + (&(aobj)->u_swhash[(((idx) >> UAO_SWHASH_CLUSTER_SHIFT) \ + & (aobj)->u_swhashmask)]) /* * The threshold which determines whether we will use an array or a * hash table to store the list of allocated swap blocks. */ -#define UAO_SWHASH_THRESHOLD (UAO_SWHASH_CLUSTER_SIZE * 4) +#define UAO_SWHASH_THRESHOLD (UAO_SWHASH_CLUSTER_SIZE * 4) +#define UAO_USES_SWHASH(aobj) \ + ((aobj)->u_pages > UAO_SWHASH_THRESHOLD) /* The number of buckets in a hash, with an upper bound. */ -#define UAO_SWHASH_MAXBUCKETS 256 -#define UAO_SWHASH_BUCKETS(pages) \ - (min((pages) >> UAO_SWHASH_CLUSTER_SHIFT, UAO_SWHASH_MAXBUCKETS)) +#define UAO_SWHASH_MAXBUCKETS 256 +#define UAO_SWHASH_BUCKETS(pages) \ + (min((pages) >> UAO_SWHASH_CLUSTER_SHIFT, UAO_SWHASH_MAXBUCKETS)) /* @@ -253,7 +254,7 @@ uao_find_swslot(struct uvm_aobj *aobj, int pageidx) /* * if hashing, look in hash table. */ - if (aobj->u_pages > UAO_SWHASH_THRESHOLD) { + if (UAO_USES_SWHASH(aobj)) { struct uao_swhash_elt *elt = uao_find_swhash_elt(aobj, pageidx, FALSE); @@ -299,7 +300,7 @@ uao_set_swslot(struct uvm_object *uobj, int pageidx, int slot) /* * are we using a hash table? if so, add it in the hash. */ - if (aobj->u_pages > UAO_SWHASH_THRESHOLD) { + if (UAO_USES_SWHASH(aobj)) { /* * Avoid allocating an entry just to free it again if * the page had not swap slot in the first place, and @@ -351,7 +352,7 @@ static void uao_free(struct uvm_aobj *aobj) { - if (aobj->u_pages > UAO_SWHASH_THRESHOLD) { + if (UAO_USES_SWHASH(aobj)) { int i, hashbuckets = aobj->u_swhashmask + 1; /* @@ -441,7 +442,7 @@ uao_shrink_hash(struct uvm_object *uobj, int pages) unsigned long new_hashmask; int i; - KASSERT(aobj->u_pages > UAO_SWHASH_THRESHOLD); + KASSERT(UAO_USES_SWHASH(aobj)); /* * If the size of the hash table doesn't change, all we need to do is @@ -743,7 +744,7 @@ uao_create(vsize_t size, int flags) mflags = M_WAITOK; /* allocate hash table or array depending on object size */ - if (aobj->u_pages > UAO_SWHASH_THRESHOLD) { + if (UAO_USES_SWHASH(aobj)) { aobj->u_swhash = hashinit(UAO_SWHASH_BUCKETS(pages), M_UVMAOBJ, mflags, &aobj->u_swhashmask); if (aobj->u_swhash == NULL) { @@ -1370,7 +1371,7 @@ uao_pagein(struct uvm_aobj *aobj, int startslot, int endslot) { boolean_t rv; - if (aobj->u_pages > UAO_SWHASH_THRESHOLD) { + if (UAO_USES_SWHASH(aobj)) { struct uao_swhash_elt *elt; int bucket; @@ -1504,7 +1505,7 @@ uao_dropswap_range(struct uvm_object *uobj, voff_t start, voff_t end) end = INT64_MAX; } - if (aobj->u_pages > UAO_SWHASH_THRESHOLD) { + if (UAO_USES_SWHASH(aobj)) { int i, hashbuckets = aobj->u_swhashmask + 1; voff_t taghi; voff_t taglo; -- 2.20.1