]> Zhao Yanbai Git Server - minix.git/commitdiff
VM: memtype fix 16/416/6
authorBen Gras <ben@minix3.org>
Wed, 20 Mar 2013 19:09:01 +0000 (19:09 +0000)
committerBen Gras <ben@minix3.org>
Wed, 24 Apr 2013 10:18:15 +0000 (10:18 +0000)
Memory types in VM are described by methods. Each mapped region has
a type, and all pages instantiated get that type on creation.
Individual page types has to be able to change though. This commit
changes the code to use the memory types of the individual pages,
where appropriate, instead of just the higher-level region, in case
it has changed. This is needed to e.g. support future copy-on-write
MAP_PRIVATE mmap modes.

Change-Id: I5523db14ac036ec774a54392fb67f9acb8725731

servers/vm/mem_shared.c
servers/vm/pb.c
servers/vm/phys_region.h
servers/vm/region.c
servers/vm/region.h

index 17252efe5893cb7ade720e73a4df39d45ce17e0a..a8349b69ba1369ee898bac3c06017d253a18c381 100644 (file)
@@ -52,9 +52,9 @@ static int getsrc(struct vir_region *region,
 {
        int srcproc;
 
-       if(region->memtype != &mem_type_shared) {
+       if(region->def_memtype != &mem_type_shared) {
                printf("shared region hasn't shared type but %s.\n",
-                       region->memtype->name);
+                       region->def_memtype->name);
                return EINVAL;
        }
 
@@ -78,9 +78,9 @@ static int getsrc(struct vir_region *region,
                 return EINVAL;
        }
 
-       if((*r)->memtype != &mem_type_anon) {
+       if((*r)->def_memtype != &mem_type_anon) {
                printf("source region hasn't anon type but %s.\n",
-                       (*r)->memtype->name);
+                       (*r)->def_memtype->name);
                return EINVAL;
        }
 
@@ -162,7 +162,7 @@ void shared_setsource(struct vir_region *vr, endpoint_t ep,
        int id = src_vr->id;
        vir_bytes vaddr = src_vr->vaddr;
 
-       assert(vr->memtype == &mem_type_shared);
+       assert(vr->def_memtype == &mem_type_shared);
 
        if(!ep || !vaddr || !id) {
                printf("VM: shared_setsource: zero ep/vaddr/id - ignoring\n");
index b2d33c1bfe64f96902878d6578eb5eabead03bd3..90884048598c13b9915b13b5e8077239eb91c385 100644 (file)
@@ -65,7 +65,7 @@ USE(newphysr,
        newphysr->ph = newpb;
        newphysr->parent = parent;
        newphysr->next_ph_list = newpb->firstregion;
-       newphysr->memtype = parent->memtype;
+       newphysr->memtype = parent->def_memtype;
        newpb->firstregion = newphysr;);
        newpb->refcount++;
 }
@@ -120,7 +120,7 @@ void pb_unreferenced(struct vir_region *region, struct phys_region *pr, int rm)
        if(pb->refcount == 0) {
                assert(!pb->firstregion);
                int r;
-               if((r = region->memtype->ev_unreference(pr)) != OK)
+               if((r = region->def_memtype->ev_unreference(pr)) != OK)
                        panic("unref failed, %d", r);
 
                SLABFREE(pb);
index f8e1b5e0dbd1de999836faf65dd1cc9e8fbf9869..ced41f20840f8c76952224625eb8e030bb251d89 100644 (file)
@@ -13,7 +13,8 @@ typedef struct phys_region {
        int                     written;        /* written to pagetable */
 #endif
 
-       mem_type_t              *memtype;
+       /* what kind of memory is it? */
+       mem_type_t              *memtype;
 
        /* list of phys_regions that reference the same phys_block */
        struct phys_region      *next_ph_list;  
index 0f362e98d15753645622a23853b5f049900ab9e3..a7ed1ec58bebe478b31325b1dc46fc1065628a1b 100644 (file)
@@ -44,9 +44,9 @@ void map_printregion(struct vir_region *vr)
 {
        int i;
        struct phys_region *ph;
-       printf("map_printmap: map_name: %s\n", vr->memtype->name);
+       printf("map_printmap: map_name: %s\n", vr->def_memtype->name);
        printf("\t%lx (len 0x%lx, %lukB), %p\n",
-               vr->vaddr, vr->length, vr->length/1024, vr->memtype->name);
+               vr->vaddr, vr->length, vr->length/1024, vr->def_memtype->name);
        printf("\t\tphysblocks:\n");
        for(i = 0; i < vr->length/VM_PAGE_SIZE; i++) {
                if(!(ph=vr->physblocks[i])) continue;
@@ -122,8 +122,8 @@ static struct vir_region *getnextvr(struct vir_region *vr)
 
 int pr_writable(struct vir_region *vr, struct phys_region *pr)
 {
-       assert(vr->memtype->writable);
-       return ((vr->flags & VR_WRITABLE) && vr->memtype->writable(pr));
+       assert(vr->def_memtype->writable);
+       return ((vr->flags & VR_WRITABLE) && vr->def_memtype->writable(pr));
 }
 
 #if SANITYCHECKS
@@ -434,7 +434,7 @@ USE(newregion,
        newregion->vaddr = startv;
        newregion->length = length;
        newregion->flags = flags;
-       newregion->memtype = memtype;
+       newregion->def_memtype = memtype;
        newregion->remaps = 0;
        newregion->id = id++;
        newregion->lower = newregion->higher = NULL;
@@ -482,8 +482,8 @@ mem_type_t *memtype;
        }
 
        /* If a new event is specified, invoke it. */
-       if(newregion->memtype->ev_new) {
-               if(newregion->memtype->ev_new(newregion) != OK) {
+       if(newregion->def_memtype->ev_new) {
+               if(newregion->def_memtype->ev_new(newregion) != OK) {
                        /* ev_new will have freed and removed the region */
                        return NULL;
                }
@@ -576,8 +576,8 @@ int map_free(struct vir_region *region)
                return r;
        }
 
-       if(region->memtype->ev_delete)
-               region->memtype->ev_delete(region);
+       if(region->def_memtype->ev_delete)
+               region->def_memtype->ev_delete(region);
        free(region->physblocks);
        region->physblocks = NULL;
        SLABFREE(region);
@@ -711,13 +711,13 @@ int write;
         * writable, nothing to do.
         */
 
-       assert(region->memtype->writable);
+       assert(region->def_memtype->writable);
 
-       if(!write || !region->memtype->writable(ph)) {
-               assert(region->memtype->ev_pagefault);
+       if(!write || !region->def_memtype->writable(ph)) {
+               assert(region->def_memtype->ev_pagefault);
                assert(ph->ph);
 
-               if((r = region->memtype->ev_pagefault(vmp,
+               if((r = region->def_memtype->ev_pagefault(vmp,
                        region, ph, write)) == SUSPEND) {
                        panic("map_pf: memtype->ev_pagefault returned SUSPEND\n");
                        return SUSPEND;
@@ -819,10 +819,10 @@ static struct vir_region *map_copy_region(struct vmproc *vmp, struct vir_region
 #endif
        vir_bytes p;
 
-       if(!(newvr = region_new(vr->parent, vr->vaddr, vr->length, vr->flags, vr->memtype)))
+       if(!(newvr = region_new(vr->parent, vr->vaddr, vr->length, vr->flags, vr->def_memtype)))
                return NULL;
 
-       if(vr->memtype->ev_copy && (r=vr->memtype->ev_copy(vr, newvr)) != OK) {
+       if(vr->def_memtype->ev_copy && (r=vr->def_memtype->ev_copy(vr, newvr)) != OK) {
                map_free(newvr);
                printf("VM: memtype-specific copy failed (%d)\n", r);
                return NULL;
@@ -1033,12 +1033,12 @@ int map_region_extend_upto_v(struct vmproc *vmp, vir_bytes v)
                return ENOMEM;
        }
 
-       if(!vr->memtype->ev_resize) {
+       if(!vr->def_memtype->ev_resize) {
                printf("VM: can't resize this type of memory\n");
                return ENOMEM;
        }
 
-       return vr->memtype->ev_resize(vmp, vr, offset - vr->vaddr);
+       return vr->def_memtype->ev_resize(vmp, vr, offset - vr->vaddr);
 }
 
 /*========================================================================*
@@ -1129,11 +1129,11 @@ int map_get_phys(struct vmproc *vmp, vir_bytes addr, phys_bytes *r)
                (vr->vaddr != addr))
                return EINVAL;
 
-       if (!vr->memtype->regionid)
+       if (!vr->def_memtype->regionid)
                return EINVAL;
 
        if(r)
-               *r = vr->memtype->regionid(vr);
+               *r = vr->def_memtype->regionid(vr);
 
        return OK;
 }
@@ -1146,11 +1146,11 @@ int map_get_ref(struct vmproc *vmp, vir_bytes addr, u8_t *cnt)
        struct vir_region *vr;
 
        if (!(vr = map_lookup(vmp, addr, NULL)) ||
-               (vr->vaddr != addr) || !vr->memtype->refcount)
+               (vr->vaddr != addr) || !vr->def_memtype->refcount)
                return EINVAL;
 
        if (cnt)
-               *cnt = vr->memtype->refcount(vr);
+               *cnt = vr->def_memtype->refcount(vr);
 
        return OK;
 }
index 6899339d9074202d3addc5c2d4aa65c89c4b69e3..6db556dc1dc6c040ab53600b131e57a9d52adf05 100644 (file)
@@ -25,13 +25,11 @@ struct phys_block {
        u32_t                   seencount;
 #endif
        phys_bytes              phys;   /* physical memory */
-       u8_t                    refcount;       /* Refcount of these pages */
-
-       /* what kind of memory is it? */
-       mem_type_t              *memtype;
 
        /* first in list of phys_regions that reference this block */
        struct phys_region      *firstregion;   
+       u8_t                    refcount;       /* Refcount of these pages */
+       u8_t                    flags;
 };
 
 typedef struct vir_region {
@@ -40,7 +38,7 @@ typedef struct vir_region {
        struct phys_region      **physblocks;
        u16_t           flags;
        struct vmproc *parent;  /* Process that owns this vir_region. */
-       mem_type_t      *memtype; /* Default instantiated memory type. */
+       mem_type_t      *def_memtype; /* Default instantiated memory type. */
        int             remaps;
        u32_t           id;     /* unique id */