Diff below makes use of uao_dropswap_range() in uao_free() instead of
duplicating it.  This function has been imported from NetBSD along with
TMPFS.  I'd like to use it to reduce the difference with their tree and
reduce the size of my upcoming `vmobjlock' diff.

ok?

Index: uvm/uvm_aobj.c
===================================================================
RCS file: /cvs/src/sys/uvm/uvm_aobj.c,v
retrieving revision 1.95
diff -u -p -r1.95 uvm_aobj.c
--- uvm/uvm_aobj.c      22 Apr 2021 11:54:32 -0000      1.95
+++ uvm/uvm_aobj.c      11 May 2021 11:26:15 -0000
@@ -351,58 +351,16 @@ uao_set_swslot(struct uvm_object *uobj, 
 static void
 uao_free(struct uvm_aobj *aobj)
 {
+       struct uvm_object *uobj = &aobj->u_obj;
 
-       if (UAO_USES_SWHASH(aobj)) {
-               int i, hashbuckets = aobj->u_swhashmask + 1;
+       uao_dropswap_range(uobj, 0, 0);
 
+       if (UAO_USES_SWHASH(aobj)) {
                /*
-                * free the swslots from each hash bucket,
-                * then the hash bucket, and finally the hash table itself.
+                * free the hash table itself.
                 */
-               for (i = 0; i < hashbuckets; i++) {
-                       struct uao_swhash_elt *elt, *next;
-
-                       for (elt = LIST_FIRST(&aobj->u_swhash[i]);
-                            elt != NULL;
-                            elt = next) {
-                               int j;
-
-                               for (j = 0; j < UAO_SWHASH_CLUSTER_SIZE; j++) {
-                                       int slot = elt->slots[j];
-
-                                       if (slot == 0) {
-                                               continue;
-                                       }
-                                       uvm_swap_free(slot, 1);
-                                       /*
-                                        * this page is no longer
-                                        * only in swap.
-                                        */
-                                       atomic_dec_int(&uvmexp.swpgonly);
-                               }
-
-                               next = LIST_NEXT(elt, list);
-                               pool_put(&uao_swhash_elt_pool, elt);
-                       }
-               }
-
                hashfree(aobj->u_swhash, UAO_SWHASH_BUCKETS(aobj->u_pages), 
M_UVMAOBJ);
        } else {
-               int i;
-
-               /*
-                * free the array
-                */
-               for (i = 0; i < aobj->u_pages; i++) {
-                       int slot = aobj->u_swslots[i];
-
-                       if (slot) {
-                               uvm_swap_free(slot, 1);
-
-                               /* this page is no longer only in swap. */
-                               atomic_dec_int(&uvmexp.swpgonly);
-                       }
-               }
                free(aobj->u_swslots, M_UVMAOBJ, aobj->u_pages * sizeof(int));
        }
 
@@ -1487,9 +1445,6 @@ uao_pagein_page(struct uvm_aobj *aobj, i
 }
 
 /*
- * XXX pedro: Once we are comfortable enough with this function, we can adapt
- * uao_free() to use it.
- *
  * uao_dropswap_range: drop swapslots in the range.
  *
  * => aobj must be locked and is returned locked.

Reply via email to