-/* $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 $ */
/*
* 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))
/*
/*
* 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);
/*
* 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
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;
/*
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
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) {
{
boolean_t rv;
- if (aobj->u_pages > UAO_SWHASH_THRESHOLD) {
+ if (UAO_USES_SWHASH(aobj)) {
struct uao_swhash_elt *elt;
int bucket;
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;