Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/uvm - Adjust uvmexp.swpgonly with atomics, and make uvm_...



details:   https://anonhg.NetBSD.org/src/rev/65374964cd52
branches:  trunk
changeset: 465655:65374964cd52
user:      ad <ad%NetBSD.org@localhost>
date:      Sun Dec 01 14:40:31 2019 +0000

description:
- Adjust uvmexp.swpgonly with atomics, and make uvm_swap_data_lock static.
- A bit more __cacheline_aligned on mutexes.

diffstat:

 sys/uvm/uvm.h         |   3 +--
 sys/uvm/uvm_anon.c    |   8 +++-----
 sys/uvm/uvm_aobj.c    |   8 +++-----
 sys/uvm/uvm_km.c      |   9 +++------
 sys/uvm/uvm_loan.c    |   6 +++---
 sys/uvm/uvm_pager.c   |  10 ++++------
 sys/uvm/uvm_pdaemon.c |  11 ++++-------
 sys/uvm/uvm_swap.c    |  13 ++++++-------
 8 files changed, 27 insertions(+), 41 deletions(-)

diffs (267 lines):

diff -r f935b8b54835 -r 65374964cd52 sys/uvm/uvm.h
--- a/sys/uvm/uvm.h     Sun Dec 01 14:30:01 2019 +0000
+++ b/sys/uvm/uvm.h     Sun Dec 01 14:40:31 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uvm.h,v 1.68 2017/01/02 20:08:32 cherry Exp $  */
+/*     $NetBSD: uvm.h,v 1.69 2019/12/01 14:40:31 ad Exp $      */
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -126,7 +126,6 @@
 extern kmutex_t uvm_pageqlock;         /* lock for active/inactive page q */
 extern kmutex_t uvm_fpageqlock;                /* lock for free page q */
 extern kmutex_t uvm_kentry_lock;
-extern kmutex_t uvm_swap_data_lock;
 
 #endif /* _KERNEL */
 
diff -r f935b8b54835 -r 65374964cd52 sys/uvm/uvm_anon.c
--- a/sys/uvm/uvm_anon.c        Sun Dec 01 14:30:01 2019 +0000
+++ b/sys/uvm/uvm_anon.c        Sun Dec 01 14:40:31 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uvm_anon.c,v 1.64 2017/10/28 00:37:13 pgoyette Exp $   */
+/*     $NetBSD: uvm_anon.c,v 1.65 2019/12/01 14:40:31 ad Exp $ */
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uvm_anon.c,v 1.64 2017/10/28 00:37:13 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_anon.c,v 1.65 2019/12/01 14:40:31 ad Exp $");
 
 #include "opt_uvmhist.h"
 
@@ -172,10 +172,8 @@
 #if defined(VMSWAP)
        if (pg == NULL && anon->an_swslot > 0) {
                /* This page is no longer only in swap. */
-               mutex_enter(&uvm_swap_data_lock);
                KASSERT(uvmexp.swpgonly > 0);
-               uvmexp.swpgonly--;
-               mutex_exit(&uvm_swap_data_lock);
+               atomic_dec_uint(&uvmexp.swpgonly);
        }
 #endif
 
diff -r f935b8b54835 -r 65374964cd52 sys/uvm/uvm_aobj.c
--- a/sys/uvm/uvm_aobj.c        Sun Dec 01 14:30:01 2019 +0000
+++ b/sys/uvm/uvm_aobj.c        Sun Dec 01 14:40:31 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uvm_aobj.c,v 1.128 2019/07/28 05:28:53 msaitoh Exp $   */
+/*     $NetBSD: uvm_aobj.c,v 1.129 2019/12/01 14:40:31 ad Exp $        */
 
 /*
  * Copyright (c) 1998 Chuck Silvers, Charles D. Cranor and
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uvm_aobj.c,v 1.128 2019/07/28 05:28:53 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_aobj.c,v 1.129 2019/12/01 14:40:31 ad Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_uvmhist.h"
@@ -1491,10 +1491,8 @@
         */
 
        if (swpgonlydelta > 0) {
-               mutex_enter(&uvm_swap_data_lock);
                KASSERT(uvmexp.swpgonly >= swpgonlydelta);
-               uvmexp.swpgonly -= swpgonlydelta;
-               mutex_exit(&uvm_swap_data_lock);
+               atomic_add_int(&uvmexp.swpgonly, -swpgonlydelta);
        }
 }
 
diff -r f935b8b54835 -r 65374964cd52 sys/uvm/uvm_km.c
--- a/sys/uvm/uvm_km.c  Sun Dec 01 14:30:01 2019 +0000
+++ b/sys/uvm/uvm_km.c  Sun Dec 01 14:40:31 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uvm_km.c,v 1.147 2019/11/14 16:23:53 maxv Exp $        */
+/*     $NetBSD: uvm_km.c,v 1.148 2019/12/01 14:40:31 ad Exp $  */
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -152,7 +152,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uvm_km.c,v 1.147 2019/11/14 16:23:53 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_km.c,v 1.148 2019/12/01 14:40:31 ad Exp $");
 
 #include "opt_uvmhist.h"
 
@@ -481,10 +481,7 @@
        mutex_exit(uobj->vmobjlock);
 
        if (swpgonlydelta > 0) {
-               mutex_enter(&uvm_swap_data_lock);
-               KASSERT(uvmexp.swpgonly >= swpgonlydelta);
-               uvmexp.swpgonly -= swpgonlydelta;
-               mutex_exit(&uvm_swap_data_lock);
+               atomic_add_int(&uvmexp.swpgonly, -swpgonlydelta);
        }
 }
 
diff -r f935b8b54835 -r 65374964cd52 sys/uvm/uvm_loan.c
--- a/sys/uvm/uvm_loan.c        Sun Dec 01 14:30:01 2019 +0000
+++ b/sys/uvm/uvm_loan.c        Sun Dec 01 14:40:31 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uvm_loan.c,v 1.87 2018/05/25 20:11:03 jdolecek Exp $   */
+/*     $NetBSD: uvm_loan.c,v 1.88 2019/12/01 14:40:31 ad Exp $ */
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uvm_loan.c,v 1.87 2018/05/25 20:11:03 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_loan.c,v 1.88 2019/12/01 14:40:31 ad Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -837,7 +837,7 @@
  */
 
 static struct uvm_object uvm_loanzero_object;
-static kmutex_t uvm_loanzero_lock;
+static kmutex_t uvm_loanzero_lock __cacheline_aligned;
 
 static int
 uvm_loanzero(struct uvm_faultinfo *ufi, void ***output, int flags)
diff -r f935b8b54835 -r 65374964cd52 sys/uvm/uvm_pager.c
--- a/sys/uvm/uvm_pager.c       Sun Dec 01 14:30:01 2019 +0000
+++ b/sys/uvm/uvm_pager.c       Sun Dec 01 14:40:31 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uvm_pager.c,v 1.111 2017/10/28 00:37:13 pgoyette Exp $ */
+/*     $NetBSD: uvm_pager.c,v 1.112 2019/12/01 14:40:31 ad Exp $       */
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uvm_pager.c,v 1.111 2017/10/28 00:37:13 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_pager.c,v 1.112 2019/12/01 14:40:31 ad Exp $");
 
 #include "opt_uvmhist.h"
 #include "opt_readahead.h"
@@ -77,7 +77,7 @@
  */
 
 struct vm_map *pager_map;              /* XXX */
-kmutex_t pager_map_wanted_lock;
+kmutex_t pager_map_wanted_lock __cacheline_aligned;
 bool pager_map_wanted; /* locked by pager map */
 static vaddr_t emergva;
 static int emerg_ncolors;
@@ -467,12 +467,10 @@
                KASSERT(write);
 
                /* these pages are now only in swap. */
-               mutex_enter(&uvm_swap_data_lock);
                if (error != ENOMEM) {
                        KASSERT(uvmexp.swpgonly + npages <= uvmexp.swpginuse);
-                       uvmexp.swpgonly += npages;
+                       atomic_add_int(&uvmexp.swpgonly, npages);
                }
-               mutex_exit(&uvm_swap_data_lock);
                if (error) {
                        if (error != ENOMEM)
                                uvm_swap_markbad(swslot, npages);
diff -r f935b8b54835 -r 65374964cd52 sys/uvm/uvm_pdaemon.c
--- a/sys/uvm/uvm_pdaemon.c     Sun Dec 01 14:30:01 2019 +0000
+++ b/sys/uvm/uvm_pdaemon.c     Sun Dec 01 14:40:31 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uvm_pdaemon.c,v 1.111 2019/10/01 17:40:22 chs Exp $    */
+/*     $NetBSD: uvm_pdaemon.c,v 1.112 2019/12/01 14:40:31 ad Exp $     */
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -66,7 +66,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uvm_pdaemon.c,v 1.111 2019/10/01 17:40:22 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_pdaemon.c,v 1.112 2019/12/01 14:40:31 ad Exp $");
 
 #include "opt_uvmhist.h"
 #include "opt_readahead.h"
@@ -825,15 +825,12 @@
                        } else {
                                slot = uao_find_swslot(uobj, pageidx);
                        }
-                       mutex_exit(slock);
-
                        if (slot > 0) {
                                /* this page is now only in swap. */
-                               mutex_enter(&uvm_swap_data_lock);
                                KASSERT(uvmexp.swpgonly < uvmexp.swpginuse);
-                               uvmexp.swpgonly++;
-                               mutex_exit(&uvm_swap_data_lock);
+                               atomic_inc_uint(&uvmexp.swpgonly);
                        }
+                       mutex_exit(slock);
                        continue;
                }
 
diff -r f935b8b54835 -r 65374964cd52 sys/uvm/uvm_swap.c
--- a/sys/uvm/uvm_swap.c        Sun Dec 01 14:30:01 2019 +0000
+++ b/sys/uvm/uvm_swap.c        Sun Dec 01 14:40:31 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uvm_swap.c,v 1.181 2019/10/06 05:48:00 mlelstv Exp $   */
+/*     $NetBSD: uvm_swap.c,v 1.182 2019/12/01 14:40:31 ad Exp $        */
 
 /*
  * Copyright (c) 1995, 1996, 1997, 2009 Matthew R. Green
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uvm_swap.c,v 1.181 2019/10/06 05:48:00 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_swap.c,v 1.182 2019/12/01 14:40:31 ad Exp $");
 
 #include "opt_uvmhist.h"
 #include "opt_compat_netbsd.h"
@@ -190,6 +190,7 @@
 static struct swap_priority swap_priority;
 
 /* locks */
+static kmutex_t uvm_swap_data_lock __cacheline_aligned;
 static krwlock_t swap_syscall_lock;
 
 /* workqueue and use counter for swap to regular files */
@@ -1069,7 +1070,7 @@
        struct vnode *vp;
        int error;
 
-       printf("turning of swap...");
+       printf("turning off swap...");
        rw_enter(&swap_syscall_lock, RW_WRITER);
        mutex_enter(&uvm_swap_data_lock);
 again:
@@ -1663,7 +1664,7 @@
         */
 
        KASSERT(uvmexp.swpgonly >= nslots);
-       uvmexp.swpgonly -= nslots;
+       atomic_add_int(&uvmexp.swpgonly, -nslots);
        sdp->swd_npgbad += nslots;
        UVMHIST_LOG(pdhist, "now %jd bad", sdp->swd_npgbad, 0,0,0);
        mutex_exit(&uvm_swap_data_lock);
@@ -1750,10 +1751,8 @@
                 * this page is no longer only in swap.
                 */
 
-               mutex_enter(&uvm_swap_data_lock);
                KASSERT(uvmexp.swpgonly > 0);
-               uvmexp.swpgonly--;
-               mutex_exit(&uvm_swap_data_lock);
+               atomic_dec_uint(&uvmexp.swpgonly);
        }
        return error;
 }



Home | Main Index | Thread Index | Old Index