diff options
author | dg <dg@FreeBSD.org> | 1995-07-13 08:48:48 +0000 |
---|---|---|
committer | dg <dg@FreeBSD.org> | 1995-07-13 08:48:48 +0000 |
commit | c8b0a7332c667c4216e12358b63e61fad9031a55 (patch) | |
tree | c6f2eefb41eadd82d51ecb0deced0d6d361765ee /sys/vm/vm_mmap.c | |
parent | f4ec3663dfda604a39dab484f7714e57488bc2c4 (diff) | |
download | FreeBSD-src-c8b0a7332c667c4216e12358b63e61fad9031a55.zip FreeBSD-src-c8b0a7332c667c4216e12358b63e61fad9031a55.tar.gz |
NOTE: libkvm, w, ps, 'top', and any other utility which depends on struct
proc or any VM system structure will have to be rebuilt!!!
Much needed overhaul of the VM system. Included in this first round of
changes:
1) Improved pager interfaces: init, alloc, dealloc, getpages, putpages,
haspage, and sync operations are supported. The haspage interface now
provides information about clusterability. All pager routines now take
struct vm_object's instead of "pagers".
2) Improved data structures. In the previous paradigm, there is constant
confusion caused by pagers being both a data structure ("allocate a
pager") and a collection of routines. The idea of a pager structure has
escentially been eliminated. Objects now have types, and this type is
used to index the appropriate pager. In most cases, items in the pager
structure were duplicated in the object data structure and thus were
unnecessary. In the few cases that remained, a un_pager structure union
was created in the object to contain these items.
3) Because of the cleanup of #1 & #2, a lot of unnecessary layering can now
be removed. For instance, vm_object_enter(), vm_object_lookup(),
vm_object_remove(), and the associated object hash list were some of the
things that were removed.
4) simple_lock's removed. Discussion with several people reveals that the
SMP locking primitives used in the VM system aren't likely the mechanism
that we'll be adopting. Even if it were, the locking that was in the code
was very inadequate and would have to be mostly re-done anyway. The
locking in a uni-processor kernel was a no-op but went a long way toward
making the code difficult to read and debug.
5) Places that attempted to kludge-up the fact that we don't have kernel
thread support have been fixed to reflect the reality that we are really
dealing with processes, not threads. The VM system didn't have complete
thread support, so the comments and mis-named routines were just wrong.
We now use tsleep and wakeup directly in the lock routines, for instance.
6) Where appropriate, the pagers have been improved, especially in the
pager_alloc routines. Most of the pager_allocs have been rewritten and
are now faster and easier to maintain.
7) The pagedaemon pageout clustering algorithm has been rewritten and
now tries harder to output an even number of pages before and after
the requested page. This is sort of the reverse of the ideal pagein
algorithm and should provide better overall performance.
8) Unnecessary (incorrect) casts to caddr_t in calls to tsleep & wakeup
have been removed. Some other unnecessary casts have also been removed.
9) Some almost useless debugging code removed.
10) Terminology of shadow objects vs. backing objects straightened out.
The fact that the vm_object data structure escentially had this
backwards really confused things. The use of "shadow" and "backing
object" throughout the code is now internally consistent and correct
in the Mach terminology.
11) Several minor bug fixes, including one in the vm daemon that caused
0 RSS objects to not get purged as intended.
12) A "default pager" has now been created which cleans up the transition
of objects to the "swap" type. The previous checks throughout the code
for swp->pg_data != NULL were really ugly. This change also provides
the rudiments for future backing of "anonymous" memory by something
other than the swap pager (via the vnode pager, for example), and it
allows the decision about which of these pagers to use to be made
dynamically (although will need some additional decision code to do
this, of course).
13) (dyson) MAP_COPY has been deprecated and the corresponding "copy
object" code has been removed. MAP_COPY was undocumented and non-
standard. It was furthermore broken in several ways which caused its
behavior to degrade to MAP_PRIVATE. Binaries that use MAP_COPY will
continue to work correctly, but via the slightly different semantics
of MAP_PRIVATE.
14) (dyson) Sharing maps have been removed. It's marginal usefulness in a
threads design can be worked around in other ways. Both #12 and #13
were done to simplify the code and improve readability and maintain-
ability. (As were most all of these changes)
TODO:
1) Rewrite most of the vnode pager to use VOP_GETPAGES/PUTPAGES. Doing
this will reduce the vnode pager to a mere fraction of its current size.
2) Rewrite vm_fault and the swap/vnode pagers to use the clustering
information provided by the new haspage pager interface. This will
substantially reduce the overhead by eliminating a large number of
VOP_BMAP() calls. The VOP_BMAP() filesystem interface should be
improved to provide both a "behind" and "ahead" indication of
contiguousness.
3) Implement the extended features of pager_haspage in swap_pager_haspage().
It currently just says 0 pages ahead/behind.
4) Re-implement the swap device (swstrategy) in a more elegant way, perhaps
via a much more general mechanism that could also be used for disk
striping of regular filesystems.
5) Do something to improve the architecture of vm_object_collapse(). The
fact that it makes calls into the swap pager and knows too much about
how the swap pager operates really bothers me. It also doesn't allow
for collapsing of non-swap pager objects ("unnamed" objects backed by
other pagers).
Diffstat (limited to 'sys/vm/vm_mmap.c')
-rw-r--r-- | sys/vm/vm_mmap.c | 195 |
1 files changed, 34 insertions, 161 deletions
diff --git a/sys/vm/vm_mmap.c b/sys/vm/vm_mmap.c index 106b62b..3beba3c 100644 --- a/sys/vm/vm_mmap.c +++ b/sys/vm/vm_mmap.c @@ -38,7 +38,7 @@ * from: Utah $Hdr: vm_mmap.c 1.6 91/10/21$ * * @(#)vm_mmap.c 8.4 (Berkeley) 1/12/94 - * $Id: vm_mmap.c,v 1.24 1995/05/30 08:16:09 rgrimes Exp $ + * $Id: vm_mmap.c,v 1.25 1995/07/09 06:58:01 davidg Exp $ */ /* @@ -62,14 +62,6 @@ #include <vm/vm_pageout.h> #include <vm/vm_prot.h> -#ifdef DEBUG -int mmapdebug; - -#define MDB_FOLLOW 0x01 -#define MDB_SYNC 0x02 -#define MDB_MAPIT 0x04 -#endif - void pmap_object_init_pt(); struct sbrk_args { @@ -149,12 +141,6 @@ mmap(p, uap, retval) prot = uap->prot & VM_PROT_ALL; flags = uap->flags; -#ifdef DEBUG - if (mmapdebug & MDB_FOLLOW) - printf("mmap(%d): addr %x len %x pro %x flg %x fd %d pos %x\n", - p->p_pid, uap->addr, uap->len, prot, - flags, uap->fd, (vm_offset_t) uap->pos); -#endif /* * Address (if FIXED) must be page aligned. Size is implicitly rounded * to a page boundary. @@ -318,12 +304,6 @@ msync(p, uap, retval) vm_map_t map; int rv; -#ifdef DEBUG - if (mmapdebug & (MDB_FOLLOW | MDB_SYNC)) - printf("msync(%d): addr %x len %x\n", - p->p_pid, uap->addr, uap->len); -#endif - map = &p->p_vmspace->vm_map; addr = (vm_offset_t) uap->addr; size = (vm_size_t) uap->len; @@ -352,12 +332,6 @@ msync(p, uap, retval) size = entry->end - entry->start; } -#ifdef DEBUG - if (mmapdebug & MDB_SYNC) - printf("msync: cleaning/flushing address range [%x-%x)\n", - addr, addr + size); -#endif - /* * Clean the pages and interpret the return value. */ @@ -392,12 +366,6 @@ munmap(p, uap, retval) vm_size_t size; vm_map_t map; -#ifdef DEBUG - if (mmapdebug & MDB_FOLLOW) - printf("munmap(%d): addr %x len %x\n", - p->p_pid, uap->addr, uap->len); -#endif - addr = (vm_offset_t) uap->addr; if ((addr & PAGE_MASK) || uap->len < 0) return (EINVAL); @@ -432,11 +400,6 @@ munmapfd(p, fd) struct proc *p; int fd; { -#ifdef DEBUG - if (mmapdebug & MDB_FOLLOW) - printf("munmapfd(%d): fd %d\n", p->p_pid, fd); -#endif - /* * XXX should unmap any regions mapped to this file */ @@ -458,12 +421,6 @@ mprotect(p, uap, retval) vm_size_t size; register vm_prot_t prot; -#ifdef DEBUG - if (mmapdebug & MDB_FOLLOW) - printf("mprotect(%d): addr %x len %x prot %d\n", - p->p_pid, uap->addr, uap->len, uap->prot); -#endif - addr = (vm_offset_t) uap->addr; if ((addr & PAGE_MASK) || uap->len < 0) return (EINVAL); @@ -530,11 +487,6 @@ mlock(p, uap, retval) vm_size_t size; int error; -#ifdef DEBUG - if (mmapdebug & MDB_FOLLOW) - printf("mlock(%d): addr %x len %x\n", - p->p_pid, uap->addr, uap->len); -#endif addr = (vm_offset_t) uap->addr; if ((addr & PAGE_MASK) || uap->addr + uap->len < uap->addr) return (EINVAL); @@ -569,11 +521,6 @@ munlock(p, uap, retval) vm_size_t size; int error; -#ifdef DEBUG - if (mmapdebug & MDB_FOLLOW) - printf("munlock(%d): addr %x len %x\n", - p->p_pid, uap->addr, uap->len); -#endif addr = (vm_offset_t) uap->addr; if ((addr & PAGE_MASK) || uap->addr + uap->len < uap->addr) return (EINVAL); @@ -603,11 +550,10 @@ vm_mmap(map, addr, size, prot, maxprot, flags, handle, foff) caddr_t handle; /* XXX should be vp */ vm_offset_t foff; { - register vm_pager_t pager; boolean_t fitit; vm_object_t object; struct vnode *vp = NULL; - int type; + objtype_t type; int rv = KERN_SUCCESS; vm_size_t objsize; struct proc *p = curproc; @@ -639,12 +585,10 @@ vm_mmap(map, addr, size, prot, maxprot, flags, handle, foff) } /* - * Lookup/allocate pager. All except an unnamed anonymous lookup gain - * a reference to ensure continued existance of the object. (XXX the - * exception is to appease the pageout daemon) + * Lookup/allocate object. */ if (flags & MAP_ANON) { - type = PG_DFLT; + type = OBJT_SWAP; /* * Unnamed anonymous regions always start at 0. */ @@ -653,7 +597,7 @@ vm_mmap(map, addr, size, prot, maxprot, flags, handle, foff) } else { vp = (struct vnode *) handle; if (vp->v_type == VCHR) { - type = PG_DEVICE; + type = OBJT_DEVICE; handle = (caddr_t) vp->v_rdev; } else { struct vattr vat; @@ -663,45 +607,23 @@ vm_mmap(map, addr, size, prot, maxprot, flags, handle, foff) if (error) return (error); objsize = vat.va_size; - type = PG_VNODE; + type = OBJT_VNODE; } } - pager = vm_pager_allocate(type, handle, objsize, prot, foff); - if (pager == NULL) - return (type == PG_DEVICE ? EINVAL : ENOMEM); - /* - * Guarantee that the pager has an object. - */ - object = vm_object_lookup(pager); - if (object == NULL) { - if (handle != NULL) - panic("vm_mmap: pager didn't allocate an object (and should have)"); - /* - * Should only happen for unnamed anonymous regions. - */ - object = vm_object_allocate(size); - object->pager = pager; - } else { - /* - * Lose vm_object_lookup() reference. Retain reference - * gained by vm_pager_allocate(). - */ - vm_object_deallocate(object); - } - /* - * At this point, our actions above have gained a total of - * one reference to the object, and we have a pager. - */ + object = vm_pager_allocate(type, handle, objsize, prot, foff); + if (object == NULL) + return (type == OBJT_DEVICE ? EINVAL : ENOMEM); /* * Anonymous memory, shared file, or character special file. */ - if ((flags & (MAP_ANON|MAP_SHARED)) || (type == PG_DEVICE)) { + if ((flags & (MAP_ANON|MAP_SHARED)) || (type == OBJT_DEVICE)) { rv = vm_map_find(map, object, foff, addr, size, fitit); if (rv != KERN_SUCCESS) { /* - * Lose the object reference. This will also destroy - * the pager if there are no other references. + * Lose the object reference. Will destroy the + * object if it's an unnamed anonymous mapping + * or named anonymous without other references. */ vm_object_deallocate(object); goto out; @@ -711,76 +633,31 @@ vm_mmap(map, addr, size, prot, maxprot, flags, handle, foff) * mmap a COW regular file */ else { - vm_map_t tmap; - vm_offset_t off; vm_map_entry_t entry; + vm_object_t private_object; - if (flags & MAP_COPY) { - /* locate and allocate the target address space */ - rv = vm_map_find(map, NULL, 0, addr, size, fitit); - if (rv != KERN_SUCCESS) { - vm_object_deallocate(object); - goto out; - } - - off = VM_MIN_ADDRESS; - tmap = vm_map_create(NULL, off, off + size, TRUE); - rv = vm_map_find(tmap, object, foff, &off, size, FALSE); - if (rv != KERN_SUCCESS) { - /* - * Deallocate and delete the temporary map. - * Note that since the object insertion - * above has failed, the vm_map_deallocate - * doesn't lose the object reference - we - * must do it explicitly. - */ - vm_object_deallocate(object); - vm_map_deallocate(tmap); - goto out; - } - rv = vm_map_copy(map, tmap, *addr, size, off, - FALSE, FALSE); - /* - * Deallocate temporary map. XXX - depending - * on events, this may leave the object with - * no net gain in reference count! ...this - * needs to be looked at! - */ - vm_map_deallocate(tmap); - if (rv != KERN_SUCCESS) - goto out; - - } else { - vm_object_t user_object; - - /* - * Create a new object and make the original object - * the backing object. NOTE: the object reference gained - * above is now changed into the reference held by - * user_object. Since we don't map 'object', we want - * only this one reference. - */ - user_object = vm_object_allocate(object->size); - user_object->shadow = object; - TAILQ_INSERT_TAIL(&object->reverse_shadow_head, - user_object, reverse_shadow_list); - - rv = vm_map_find(map, user_object, foff, addr, size, fitit); - if( rv != KERN_SUCCESS) { - vm_object_deallocate(user_object); - goto out; - } + /* + * Create a new object and make the original object + * the backing object. NOTE: the object reference gained + * above is now changed into the reference held by + * private_object. Since we don't map 'object', we want + * only this one reference. + */ + private_object = vm_object_allocate(OBJT_DEFAULT, object->size); + private_object->backing_object = object; + TAILQ_INSERT_TAIL(&object->shadow_head, + private_object, shadow_list); - /* - * this is a consistancy check, gets the map entry, and should - * never fail - */ - if (!vm_map_lookup_entry(map, *addr, &entry)) { - panic("vm_mmap: missing map entry!!!"); - } + rv = vm_map_find(map, private_object, foff, addr, size, fitit); + if (rv != KERN_SUCCESS) { + vm_object_deallocate(private_object); + goto out; + } - entry->copy_on_write = TRUE; + if (!vm_map_lookup_entry(map, *addr, &entry)) { + panic("vm_mmap: missing map entry!!!"); } + entry->copy_on_write = TRUE; /* * set pages COW and protect for read access only @@ -792,7 +669,7 @@ vm_mmap(map, addr, size, prot, maxprot, flags, handle, foff) /* * "Pre-fault" resident pages. */ - if ((type == PG_VNODE) && (map->pmap != NULL)) { + if ((type == OBJT_VNODE) && (map->pmap != NULL)) { pmap_object_init_pt(map->pmap, *addr, object, foff, size); } @@ -820,10 +697,6 @@ vm_mmap(map, addr, size, prot, maxprot, flags, handle, foff) } } out: -#ifdef DEBUG - if (mmapdebug & MDB_MAPIT) - printf("vm_mmap: rv %d\n", rv); -#endif switch (rv) { case KERN_SUCCESS: return (0); |