Source-Changes-HG archive

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

[src/trunk]: src/sys "Make NetBSD great again!"



details:   https://anonhg.NetBSD.org/src/rev/f617064bd844
branches:  trunk
changeset: 819918:f617064bd844
user:      cherry <cherry%NetBSD.org@localhost>
date:      Fri Dec 23 07:15:27 2016 +0000

description:
"Make NetBSD great again!"

Introduce uvm_hotplug(9) to the kernel.

Many thanks, in no particular order to:

TNF, for funding the project.

Chuck Silvers - for multiple API reviews and feedback.
Nick Hudson - for testing on multiple architectures and bugfix patches.
Everyone who helped with boot testing.

KeK (http://www.kek.org.in) for hosting the primary developers.

diffstat:

 sys/arch/acorn26/acorn26/pmap.c       |   21 +-
 sys/arch/alpha/alpha/machdep.c        |   26 +-
 sys/arch/alpha/alpha/pmap.c           |   50 +--
 sys/arch/amd64/amd64/machdep.c        |   91 +++----
 sys/arch/arm/arm32/bus_dma.c          |   10 +-
 sys/arch/arm/arm32/pmap.c             |    8 +-
 sys/arch/i386/i386/machdep.c          |   69 +---
 sys/arch/ia64/ia64/machdep.c          |   19 +-
 sys/arch/ia64/ia64/pmap.c             |   68 ++---
 sys/arch/m68k/m68k/pmap_motorola.c    |   41 ++-
 sys/arch/mips/include/pmap.h          |    6 +-
 sys/arch/mips/mips/mips_machdep.c     |   35 +-
 sys/arch/mips/mips/pmap_machdep.c     |   17 +-
 sys/arch/powerpc/ibm4xx/pmap.c        |    8 +-
 sys/arch/powerpc/isa/isadma_machdep.c |   20 +-
 sys/arch/powerpc/oea/pmap.c           |   70 ++---
 sys/arch/powerpc/powerpc/bus_dma.c    |   19 +-
 sys/arch/sh3/sh3/pmap.c               |   40 +--
 sys/arch/sh3/sh3/vm_machdep.c         |    7 +-
 sys/arch/vax/vax/ka650.c              |    6 +-
 sys/arch/vax/vax/pmap.c               |   12 +-
 sys/arch/x68k/x68k/machdep.c          |   52 ++-
 sys/uvm/files.uvm                     |    4 +-
 sys/uvm/pmap/pmap.c                   |   71 ++---
 sys/uvm/uvm_init.c                    |    6 +-
 sys/uvm/uvm_page.c                    |  423 +++++----------------------------
 sys/uvm/uvm_page.h                    |   40 +--
 sys/uvm/uvm_pglist.c                  |  147 ++++++-----
 sys/uvm/uvm_physseg.h                 |    4 +-
 29 files changed, 518 insertions(+), 872 deletions(-)

diffs (truncated from 2706 to 300 lines):

diff -r c4db660ca40c -r f617064bd844 sys/arch/acorn26/acorn26/pmap.c
--- a/sys/arch/acorn26/acorn26/pmap.c   Fri Dec 23 06:22:00 2016 +0000
+++ b/sys/arch/acorn26/acorn26/pmap.c   Fri Dec 23 07:15:27 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.36 2012/05/11 15:39:17 skrll Exp $ */
+/* $NetBSD: pmap.c,v 1.37 2016/12/23 07:15:27 cherry Exp $ */
 /*-
  * Copyright (c) 1997, 1998, 2000 Ben Harris
  * All rights reserved.
@@ -102,7 +102,7 @@
 
 #include <sys/param.h>
 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.36 2012/05/11 15:39:17 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.37 2016/12/23 07:15:27 cherry Exp $");
 
 #include <sys/kernel.h> /* for cold */
 #include <sys/kmem.h>
@@ -293,19 +293,26 @@
 vaddr_t
 pmap_steal_memory(vsize_t size, vaddr_t *vstartp, vaddr_t *vendp)
 {
-       int i;
        vaddr_t addr;
+       uvm_physseg_t bank;
+
        UVMHIST_FUNC("pmap_steal_memory");
 
        UVMHIST_CALLED(pmaphist);
        addr = 0;
        size = round_page(size);
-       for (i = 0; i < vm_nphysseg; i++) {
-               if (VM_PHYSMEM_PTR(i)->avail_start < VM_PHYSMEM_PTR(i)->avail_end) {
+       for (bank = uvm_physseg_get_first();
+            uvm_physseg_valid_p(bank);
+            bank = uvm_physseg_get_next(bank)) {
+               if (uvm_physseg_get_avail_start(bank) < uvm_physseg_get_avail_end(bank)) {
+                       paddr_t avail_start = uvm_physseg_get_avail_start(bank);
+
                        addr = (vaddr_t)
                            ((char*)MEMC_PHYS_BASE +
-                               ptoa(VM_PHYSMEM_PTR(i)->avail_start));
-                       VM_PHYSMEM_PTR(i)->avail_start++;
+                               ptoa(avail_start));
+                       avail_start++;
+                       uvm_physseg_set_avail_start(avail_start);
+
                        break;
                }
        }
diff -r c4db660ca40c -r f617064bd844 sys/arch/alpha/alpha/machdep.c
--- a/sys/arch/alpha/alpha/machdep.c    Fri Dec 23 06:22:00 2016 +0000
+++ b/sys/arch/alpha/alpha/machdep.c    Fri Dec 23 07:15:27 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.c,v 1.348 2016/12/22 14:47:54 cherry Exp $ */
+/* $NetBSD: machdep.c,v 1.349 2016/12/23 07:15:27 cherry Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
 
 #include <sys/cdefs.h>                 /* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.348 2016/12/22 14:47:54 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.349 2016/12/23 07:15:27 cherry Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -227,7 +227,6 @@
        struct mddt *mddtp;
        struct mddt_cluster *memc;
        int i, mddtweird;
-       struct vm_physseg *vps;
        struct pcb *pcb0;
        vaddr_t kernstart, kernend, v;
        paddr_t kernstartpfn, kernendpfn, pfn0, pfn1;
@@ -611,24 +610,25 @@
         * Initialize error message buffer (at end of core).
         */
        {
+               paddr_t end;
                vsize_t sz = (vsize_t)round_page(MSGBUFSIZE);
                vsize_t reqsz = sz;
+               uvm_physseg_t bank;
 
-               vps = VM_PHYSMEM_PTR(vm_nphysseg - 1);
+               bank = uvm_physseg_get_last();
 
                /* shrink so that it'll fit in the last segment */
-               if ((vps->avail_end - vps->avail_start) < atop(sz))
-                       sz = ptoa(vps->avail_end - vps->avail_start);
+               if (uvm_physseg_get_avail_end(bank) - uvm_physseg_get_avail_start(bank) < atop(sz))
+                       sz = ptoa(uvm_physseg_get_avail_end(bank) - uvm_physseg_get_avail_start(bank));
 
-               vps->end -= atop(sz);
-               vps->avail_end -= atop(sz);
-               msgbufaddr = (void *) ALPHA_PHYS_TO_K0SEG(ptoa(vps->end));
+               end = uvm_physseg_get_end(bank);
+               end -= atop(sz);
+
+               uvm_physseg_unplug(end, atop(sz));
+               msgbufaddr = (void *) ALPHA_PHYS_TO_K0SEG(ptoa(end));
+
                initmsgbuf(msgbufaddr, sz);
 
-               /* Remove the last segment if it now has no pages. */
-               if (vps->start == vps->end)
-                       vm_nphysseg--;
-
                /* warn if the message buffer had to be shrunk */
                if (sz != reqsz)
                        printf("WARNING: %ld bytes not available for msgbuf "
diff -r c4db660ca40c -r f617064bd844 sys/arch/alpha/alpha/pmap.c
--- a/sys/arch/alpha/alpha/pmap.c       Fri Dec 23 06:22:00 2016 +0000
+++ b/sys/arch/alpha/alpha/pmap.c       Fri Dec 23 07:15:27 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.260 2015/11/05 06:26:15 pgoyette Exp $ */
+/* $NetBSD: pmap.c,v 1.261 2016/12/23 07:15:27 cherry Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001, 2007, 2008 The NetBSD Foundation, Inc.
@@ -140,7 +140,7 @@
 
 #include <sys/cdefs.h>                 /* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.260 2015/11/05 06:26:15 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.261 2016/12/23 07:15:27 cherry Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -784,8 +784,8 @@
         * the fact that BSEARCH sorts the vm_physmem[] array
         * for us.
         */
-       avail_start = ptoa(VM_PHYSMEM_PTR(0)->start);
-       avail_end = ptoa(VM_PHYSMEM_PTR(vm_nphysseg - 1)->end);
+       avail_start = ptoa(uvm_physseg_get_avail_start(uvm_physseg_get_first()));
+       avail_end = ptoa(uvm_physseg_get_avail_end(uvm_physseg_get_last()));
        virtual_end = VM_MIN_KERNEL_ADDRESS + lev3mapsize * PAGE_SIZE;
 
 #if 0
@@ -1007,9 +1007,11 @@
 vaddr_t
 pmap_steal_memory(vsize_t size, vaddr_t *vstartp, vaddr_t *vendp)
 {
-       int bank, npgs, x;
+       int npgs;
        vaddr_t va;
-       paddr_t pa;
+       paddr_t pa; 
+
+       uvm_physseg_t bank;
 
        size = round_page(size);
        npgs = atop(size);
@@ -1018,50 +1020,36 @@
        printf("PSM: size 0x%lx (npgs 0x%x)\n", size, npgs);
 #endif
 
-       for (bank = 0; bank < vm_nphysseg; bank++) {
+       for (bank = uvm_physseg_get_first();
+            uvm_physseg_valid_p(bank);
+            bank = uvm_physseg_get_next(bank)) {
                if (uvm.page_init_done == true)
                        panic("pmap_steal_memory: called _after_ bootstrap");
 
 #if 0
-               printf("     bank %d: avail_start 0x%lx, start 0x%lx, "
-                   "avail_end 0x%lx\n", bank, VM_PHYSMEM_PTR(bank)->avail_start,
+               printf("     bank %d: avail_start 0x%"PRIxPADDR", start 0x%"PRIxPADDR", "
+                   "avail_end 0x%"PRIxPADDR"\n", bank, VM_PHYSMEM_PTR(bank)->avail_start,
                    VM_PHYSMEM_PTR(bank)->start, VM_PHYSMEM_PTR(bank)->avail_end);
 #endif
 
-               if (VM_PHYSMEM_PTR(bank)->avail_start != VM_PHYSMEM_PTR(bank)->start ||
-                   VM_PHYSMEM_PTR(bank)->avail_start >= VM_PHYSMEM_PTR(bank)->avail_end)
+               if (uvm_physseg_get_avail_start(bank) != uvm_physseg_get_start(bank) ||
+                   uvm_physseg_get_avail_start(bank) >= uvm_physseg_get_avail_end(bank))
                        continue;
 
 #if 0
-               printf("             avail_end - avail_start = 0x%lx\n",
+               printf("             avail_end - avail_start = 0x%"PRIxPADDR"\n",
                    VM_PHYSMEM_PTR(bank)->avail_end - VM_PHYSMEM_PTR(bank)->avail_start);
 #endif
 
-               if ((VM_PHYSMEM_PTR(bank)->avail_end - VM_PHYSMEM_PTR(bank)->avail_start)
+               if (uvm_physseg_get_avail_end(bank) - uvm_physseg_get_avail_start(bank)
                    < npgs)
                        continue;
 
                /*
                 * There are enough pages here; steal them!
                 */
-               pa = ptoa(VM_PHYSMEM_PTR(bank)->avail_start);
-               VM_PHYSMEM_PTR(bank)->avail_start += npgs;
-               VM_PHYSMEM_PTR(bank)->start += npgs;
-
-               /*
-                * Have we used up this segment?
-                */
-               if (VM_PHYSMEM_PTR(bank)->avail_start == VM_PHYSMEM_PTR(bank)->end) {
-                       if (vm_nphysseg == 1)
-                               panic("pmap_steal_memory: out of memory!");
-
-                       /* Remove this segment from the list. */
-                       vm_nphysseg--;
-                       for (x = bank; x < vm_nphysseg; x++) {
-                               /* structure copy */
-                               VM_PHYSMEM_PTR_SWAP(x, x + 1);
-                       }
-               }
+               pa = ptoa(uvm_physseg_get_start(bank));
+               uvm_physseg_unplug(atop(pa), npgs);
 
                va = ALPHA_PHYS_TO_K0SEG(pa);
                memset((void *)va, 0, size);
diff -r c4db660ca40c -r f617064bd844 sys/arch/amd64/amd64/machdep.c
--- a/sys/arch/amd64/amd64/machdep.c    Fri Dec 23 06:22:00 2016 +0000
+++ b/sys/arch/amd64/amd64/machdep.c    Fri Dec 23 07:15:27 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: machdep.c,v 1.242 2016/12/22 16:29:05 bouyer Exp $     */
+/*     $NetBSD: machdep.c,v 1.243 2016/12/23 07:15:27 cherry Exp $     */
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -111,7 +111,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.242 2016/12/22 16:29:05 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.243 2016/12/23 07:15:27 cherry Exp $");
 
 /* #define XENDEBUG_LOW  */
 
@@ -789,6 +789,7 @@
        paddr_t p, pstart, pend;
        struct vm_page *pg;
        int i;
+       uvm_physseg_t upm;
 
        /*
         * Mark all memory pages, then unmark pages that are uninteresting.
@@ -805,10 +806,25 @@
                        setbit(sparse_dump_physmap, p);
                }
        }
-       for (i = 0; i < vm_nphysseg; i++) {
-               struct vm_physseg *seg = VM_PHYSMEM_PTR(i);
+        for (upm = uvm_physseg_get_first();
+            uvm_physseg_valid_p(upm);
+            upm = uvm_physseg_get_next(upm)) {
+               paddr_t pfn;
+
+               if (uvm_physseg_valid_p(upm) == false)
+                       break;
 
-               for (pg = seg->pgs; pg < seg->lastpg; pg++) {
+               const paddr_t startpfn = uvm_physseg_get_start(upm);
+               const paddr_t endpfn = uvm_physseg_get_end(upm);
+
+               KASSERT(startpfn != -1 && endpfn != -1);
+
+               /*
+                * We assume that seg->start to seg->end are
+                * uvm_page_physload()ed
+                */
+               for (pfn = startpfn; pfn <= endpfn; pfn++) {
+                       pg = PHYS_TO_VM_PAGE(ptoa(pfn));
                        if (pg->uanon || (pg->pqflags & PQ_FREE) ||
                            (pg->uobject && pg->uobject->pgops)) {
                                p = VM_PAGE_TO_PHYS(pg) / PAGE_SIZE;
@@ -1452,57 +1468,30 @@
 static void
 init_x86_64_msgbuf(void)
 {
-       /* Message buffer is located at end of core. */
-       struct vm_physseg *vps;
-       psize_t sz = round_page(MSGBUFSIZE);
-       psize_t reqsz = sz;
-       int x;
-               
- search_again:
-       vps = NULL;
+        /* Message buffer is located at end of core. */
+       psize_t reqsz = round_page(MSGBUFSIZE);
+       psize_t sz = 0;
 
-       for (x = 0; x < vm_nphysseg; x++) {
-               vps = VM_PHYSMEM_PTR(x);
-               if (ctob(vps->avail_end) == avail_end)
+       for (sz = 0; sz < reqsz; sz += PAGE_SIZE) {
+               paddr_t stolenpa;
+
+               if (!uvm_page_physget(&stolenpa))
                        break;
-       }
-       if (x == vm_nphysseg)
-               panic("init_x86_64: can't find end of memory");
 



Home | Main Index | Thread Index | Old Index