vm_map.c (38135) | vm_map.c (38517) |
---|---|
1/* 2 * Copyright (c) 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * The Mach Operating System project at Carnegie-Mellon University. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 47 unchanged lines hidden (view full) --- 56 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 57 * School of Computer Science 58 * Carnegie Mellon University 59 * Pittsburgh PA 15213-3890 60 * 61 * any improvements or extensions that they make and grant Carnegie the 62 * rights to redistribute these changes. 63 * | 1/* 2 * Copyright (c) 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * The Mach Operating System project at Carnegie-Mellon University. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 47 unchanged lines hidden (view full) --- 56 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 57 * School of Computer Science 58 * Carnegie Mellon University 59 * Pittsburgh PA 15213-3890 60 * 61 * any improvements or extensions that they make and grant Carnegie the 62 * rights to redistribute these changes. 63 * |
64 * $Id: vm_map.c,v 1.132 1998/07/14 12:14:58 bde Exp $ | 64 * $Id: vm_map.c,v 1.133 1998/08/06 08:33:19 dfr Exp $ |
65 */ 66 67/* 68 * Virtual memory mapping module. 69 */ 70 71#include <sys/param.h> 72#include <sys/systm.h> --- 464 unchanged lines hidden (view full) --- 537 new_entry->start = start; 538 new_entry->end = end; 539 540 new_entry->eflags = protoeflags; 541 new_entry->object.vm_object = object; 542 new_entry->offset = offset; 543 if (object) { 544 if ((object->ref_count > 1) || (object->shadow_count != 0)) { | 65 */ 66 67/* 68 * Virtual memory mapping module. 69 */ 70 71#include <sys/param.h> 72#include <sys/systm.h> --- 464 unchanged lines hidden (view full) --- 537 new_entry->start = start; 538 new_entry->end = end; 539 540 new_entry->eflags = protoeflags; 541 new_entry->object.vm_object = object; 542 new_entry->offset = offset; 543 if (object) { 544 if ((object->ref_count > 1) || (object->shadow_count != 0)) { |
545 object->flags &= ~OBJ_ONEMAPPING; | 545 vm_object_clear_flag(object, OBJ_ONEMAPPING); |
546 } else { | 546 } else { |
547 object->flags |= OBJ_ONEMAPPING; | 547 vm_object_set_flag(object, OBJ_ONEMAPPING); |
548 } 549 } 550 551 if (map->is_main_map) { 552 new_entry->inheritance = VM_INHERIT_DEFAULT; 553 new_entry->protection = prot; 554 new_entry->max_protection = max; 555 new_entry->wired_count = 0; --- 197 unchanged lines hidden (view full) --- 753 * the specified address; if necessary, 754 * it splits the entry into two. 755 */ 756#define vm_map_clip_start(map, entry, startaddr) \ 757{ \ 758 if (startaddr > entry->start) \ 759 _vm_map_clip_start(map, entry, startaddr); \ 760 else if (entry->object.vm_object && (entry->object.vm_object->ref_count == 1)) \ | 548 } 549 } 550 551 if (map->is_main_map) { 552 new_entry->inheritance = VM_INHERIT_DEFAULT; 553 new_entry->protection = prot; 554 new_entry->max_protection = max; 555 new_entry->wired_count = 0; --- 197 unchanged lines hidden (view full) --- 753 * the specified address; if necessary, 754 * it splits the entry into two. 755 */ 756#define vm_map_clip_start(map, entry, startaddr) \ 757{ \ 758 if (startaddr > entry->start) \ 759 _vm_map_clip_start(map, entry, startaddr); \ 760 else if (entry->object.vm_object && (entry->object.vm_object->ref_count == 1)) \ |
761 entry->object.vm_object->flags |= OBJ_ONEMAPPING; \ | 761 vm_object_set_flag(entry->object.vm_object, OBJ_ONEMAPPING); \ |
762} 763 764/* 765 * This routine is called only when it is known that 766 * the entry must be split. 767 */ 768static void 769_vm_map_clip_start(map, entry, start) --- 33 unchanged lines hidden (view full) --- 803 new_entry->end = start; 804 entry->offset += (start - entry->start); 805 entry->start = start; 806 807 vm_map_entry_link(map, entry->prev, new_entry); 808 809 if ((entry->eflags & (MAP_ENTRY_IS_A_MAP|MAP_ENTRY_IS_SUB_MAP)) == 0) { 810 if (new_entry->object.vm_object->ref_count == 1) | 762} 763 764/* 765 * This routine is called only when it is known that 766 * the entry must be split. 767 */ 768static void 769_vm_map_clip_start(map, entry, start) --- 33 unchanged lines hidden (view full) --- 803 new_entry->end = start; 804 entry->offset += (start - entry->start); 805 entry->start = start; 806 807 vm_map_entry_link(map, entry->prev, new_entry); 808 809 if ((entry->eflags & (MAP_ENTRY_IS_A_MAP|MAP_ENTRY_IS_SUB_MAP)) == 0) { 810 if (new_entry->object.vm_object->ref_count == 1) |
811 new_entry->object.vm_object->flags |= OBJ_ONEMAPPING; | 811 vm_object_set_flag(new_entry->object.vm_object, 812 OBJ_ONEMAPPING); |
812 vm_object_reference(new_entry->object.vm_object); 813 } 814} 815 816/* 817 * vm_map_clip_end: [ internal use only ] 818 * 819 * Asserts that the given entry ends at or before 820 * the specified address; if necessary, 821 * it splits the entry into two. 822 */ 823 824#define vm_map_clip_end(map, entry, endaddr) \ 825{ \ 826 if (endaddr < entry->end) \ 827 _vm_map_clip_end(map, entry, endaddr); \ 828 else if (entry->object.vm_object && (entry->object.vm_object->ref_count == 1)) \ | 813 vm_object_reference(new_entry->object.vm_object); 814 } 815} 816 817/* 818 * vm_map_clip_end: [ internal use only ] 819 * 820 * Asserts that the given entry ends at or before 821 * the specified address; if necessary, 822 * it splits the entry into two. 823 */ 824 825#define vm_map_clip_end(map, entry, endaddr) \ 826{ \ 827 if (endaddr < entry->end) \ 828 _vm_map_clip_end(map, entry, endaddr); \ 829 else if (entry->object.vm_object && (entry->object.vm_object->ref_count == 1)) \ |
829 entry->object.vm_object->flags |= OBJ_ONEMAPPING; \ | 830 vm_object_set_flag(entry->object.vm_object, OBJ_ONEMAPPING); \ |
830} 831 832/* 833 * This routine is called only when it is known that 834 * the entry must be split. 835 */ 836static void 837_vm_map_clip_end(map, entry, end) --- 28 unchanged lines hidden (view full) --- 866 867 new_entry->start = entry->end = end; 868 new_entry->offset += (end - entry->start); 869 870 vm_map_entry_link(map, entry, new_entry); 871 872 if ((entry->eflags & (MAP_ENTRY_IS_A_MAP|MAP_ENTRY_IS_SUB_MAP)) == 0) { 873 if (new_entry->object.vm_object->ref_count == 1) | 831} 832 833/* 834 * This routine is called only when it is known that 835 * the entry must be split. 836 */ 837static void 838_vm_map_clip_end(map, entry, end) --- 28 unchanged lines hidden (view full) --- 867 868 new_entry->start = entry->end = end; 869 new_entry->offset += (end - entry->start); 870 871 vm_map_entry_link(map, entry, new_entry); 872 873 if ((entry->eflags & (MAP_ENTRY_IS_A_MAP|MAP_ENTRY_IS_SUB_MAP)) == 0) { 874 if (new_entry->object.vm_object->ref_count == 1) |
874 new_entry->object.vm_object->flags |= OBJ_ONEMAPPING; | 875 vm_object_set_flag(new_entry->object.vm_object, 876 OBJ_ONEMAPPING); |
875 vm_object_reference(new_entry->object.vm_object); 876 } 877} 878 879/* 880 * VM_MAP_RANGE_CHECK: [ internal use only ] 881 * 882 * Asserts that the starting and ending region --- 882 unchanged lines hidden (view full) --- 1765 /* 1766 * Find the start of the region, and clip it 1767 */ 1768 1769 if (!vm_map_lookup_entry(map, start, &first_entry)) { 1770 entry = first_entry->next; 1771 object = entry->object.vm_object; 1772 if (object && (object->ref_count == 1) && (object->shadow_count == 0)) | 877 vm_object_reference(new_entry->object.vm_object); 878 } 879} 880 881/* 882 * VM_MAP_RANGE_CHECK: [ internal use only ] 883 * 884 * Asserts that the starting and ending region --- 882 unchanged lines hidden (view full) --- 1767 /* 1768 * Find the start of the region, and clip it 1769 */ 1770 1771 if (!vm_map_lookup_entry(map, start, &first_entry)) { 1772 entry = first_entry->next; 1773 object = entry->object.vm_object; 1774 if (object && (object->ref_count == 1) && (object->shadow_count == 0)) |
1773 object->flags |= OBJ_ONEMAPPING; | 1775 vm_object_set_flag(object, OBJ_ONEMAPPING); |
1774 } else { 1775 entry = first_entry; 1776 vm_map_clip_start(map, entry, start); 1777 /* 1778 * Fix the lookup hint now, rather than each time though the 1779 * loop. 1780 */ 1781 SAVE_HINT(map, entry->prev); --- 185 unchanged lines hidden (view full) --- 1967 if (new_object == NULL) 1968 return; 1969 1970 source = orig_object->backing_object; 1971 if (source != NULL) { 1972 vm_object_reference(source); /* Referenced by new_object */ 1973 TAILQ_INSERT_TAIL(&source->shadow_head, 1974 new_object, shadow_list); | 1776 } else { 1777 entry = first_entry; 1778 vm_map_clip_start(map, entry, start); 1779 /* 1780 * Fix the lookup hint now, rather than each time though the 1781 * loop. 1782 */ 1783 SAVE_HINT(map, entry->prev); --- 185 unchanged lines hidden (view full) --- 1969 if (new_object == NULL) 1970 return; 1971 1972 source = orig_object->backing_object; 1973 if (source != NULL) { 1974 vm_object_reference(source); /* Referenced by new_object */ 1975 TAILQ_INSERT_TAIL(&source->shadow_head, 1976 new_object, shadow_list); |
1975 source->flags &= ~OBJ_ONEMAPPING; | 1977 vm_object_clear_flag(source, OBJ_ONEMAPPING); |
1976 new_object->backing_object_offset = 1977 orig_object->backing_object_offset + offidxstart; 1978 new_object->backing_object = source; 1979 source->shadow_count++; 1980 source->generation++; 1981 } 1982 1983 for (idx = 0; idx < size; idx++) { 1984 vm_page_t m; 1985 1986 retry: 1987 m = vm_page_lookup(orig_object, offidxstart + idx); 1988 if (m == NULL) 1989 continue; 1990 if (m->flags & PG_BUSY) { | 1978 new_object->backing_object_offset = 1979 orig_object->backing_object_offset + offidxstart; 1980 new_object->backing_object = source; 1981 source->shadow_count++; 1982 source->generation++; 1983 } 1984 1985 for (idx = 0; idx < size; idx++) { 1986 vm_page_t m; 1987 1988 retry: 1989 m = vm_page_lookup(orig_object, offidxstart + idx); 1990 if (m == NULL) 1991 continue; 1992 if (m->flags & PG_BUSY) { |
1991 m->flags |= PG_WANTED; | 1993 PAGE_SET_FLAG(m, PG_WANTED); |
1992 tsleep(m, PVM, "spltwt", 0); 1993 goto retry; 1994 } 1995 | 1994 tsleep(m, PVM, "spltwt", 0); 1995 goto retry; 1996 } 1997 |
1996 m->flags |= PG_BUSY; | 1998 PAGE_SET_FLAG(m, PG_BUSY); |
1997 vm_page_protect(m, VM_PROT_NONE); 1998 vm_page_rename(m, new_object, idx); 1999 m->dirty = VM_PAGE_BITS_ALL; | 1999 vm_page_protect(m, VM_PROT_NONE); 2000 vm_page_rename(m, new_object, idx); 2001 m->dirty = VM_PAGE_BITS_ALL; |
2000 m->flags |= PG_BUSY; | 2002 PAGE_SET_FLAG(m, PG_BUSY); |
2001 } 2002 2003 if (orig_object->type == OBJT_SWAP) { 2004 vm_object_pip_add(orig_object, 1); 2005 /* 2006 * copy orig_object pages into new_object 2007 * and destroy unneeded pages in 2008 * shadow object. --- 58 unchanged lines hidden (view full) --- 2067 if ((src_object->flags & (OBJ_NOSPLIT|OBJ_ONEMAPPING)) == OBJ_ONEMAPPING) { 2068 vm_map_split(src_entry); 2069 src_map->timestamp++; 2070 src_object = src_entry->object.vm_object; 2071 } 2072 } 2073 2074 vm_object_reference(src_object); | 2003 } 2004 2005 if (orig_object->type == OBJT_SWAP) { 2006 vm_object_pip_add(orig_object, 1); 2007 /* 2008 * copy orig_object pages into new_object 2009 * and destroy unneeded pages in 2010 * shadow object. --- 58 unchanged lines hidden (view full) --- 2069 if ((src_object->flags & (OBJ_NOSPLIT|OBJ_ONEMAPPING)) == OBJ_ONEMAPPING) { 2070 vm_map_split(src_entry); 2071 src_map->timestamp++; 2072 src_object = src_entry->object.vm_object; 2073 } 2074 } 2075 2076 vm_object_reference(src_object); |
2075 src_object->flags &= ~OBJ_ONEMAPPING; | 2077 vm_object_clear_flag(src_object, OBJ_ONEMAPPING); |
2076 dst_entry->object.vm_object = src_object; 2077 src_entry->eflags |= (MAP_ENTRY_COW|MAP_ENTRY_NEEDS_COPY); 2078 dst_entry->eflags |= (MAP_ENTRY_COW|MAP_ENTRY_NEEDS_COPY); 2079 dst_entry->offset = src_entry->offset; 2080 } else { 2081 dst_entry->object.vm_object = NULL; 2082 dst_entry->offset = 0; 2083 } --- 62 unchanged lines hidden (view full) --- 2146 old_entry->offset = (vm_offset_t) 0; 2147 } else if (old_entry->eflags & MAP_ENTRY_NEEDS_COPY) { 2148 vm_object_shadow(&old_entry->object.vm_object, 2149 &old_entry->offset, 2150 atop(old_entry->end - old_entry->start)); 2151 old_entry->eflags &= ~MAP_ENTRY_NEEDS_COPY; 2152 object = old_entry->object.vm_object; 2153 } | 2078 dst_entry->object.vm_object = src_object; 2079 src_entry->eflags |= (MAP_ENTRY_COW|MAP_ENTRY_NEEDS_COPY); 2080 dst_entry->eflags |= (MAP_ENTRY_COW|MAP_ENTRY_NEEDS_COPY); 2081 dst_entry->offset = src_entry->offset; 2082 } else { 2083 dst_entry->object.vm_object = NULL; 2084 dst_entry->offset = 0; 2085 } --- 62 unchanged lines hidden (view full) --- 2148 old_entry->offset = (vm_offset_t) 0; 2149 } else if (old_entry->eflags & MAP_ENTRY_NEEDS_COPY) { 2150 vm_object_shadow(&old_entry->object.vm_object, 2151 &old_entry->offset, 2152 atop(old_entry->end - old_entry->start)); 2153 old_entry->eflags &= ~MAP_ENTRY_NEEDS_COPY; 2154 object = old_entry->object.vm_object; 2155 } |
2154 object->flags &= ~OBJ_ONEMAPPING; | 2156 vm_object_clear_flag(object, OBJ_ONEMAPPING); |
2155 2156 /* 2157 * Clone the entry, referencing the sharing map. 2158 */ 2159 new_entry = vm_map_entry_create(new_map); 2160 *new_entry = *old_entry; 2161 new_entry->wired_count = 0; 2162 vm_object_reference(object); --- 442 unchanged lines hidden (view full) --- 2605 /* 2606 * Point the object appropriately 2607 */ 2608 if (oldobject != srcobject) { 2609 2610 /* 2611 * Set the object optimization hint flag 2612 */ | 2157 2158 /* 2159 * Clone the entry, referencing the sharing map. 2160 */ 2161 new_entry = vm_map_entry_create(new_map); 2162 *new_entry = *old_entry; 2163 new_entry->wired_count = 0; 2164 vm_object_reference(object); --- 442 unchanged lines hidden (view full) --- 2607 /* 2608 * Point the object appropriately 2609 */ 2610 if (oldobject != srcobject) { 2611 2612 /* 2613 * Set the object optimization hint flag 2614 */ |
2613 srcobject->flags |= OBJ_OPT; | 2615 vm_object_set_flag(srcobject, OBJ_OPT); |
2614 vm_object_reference(srcobject); 2615 entry->object.vm_object = srcobject; 2616 2617 if (oldobject) { 2618 vm_object_deallocate(oldobject); 2619 } 2620 } 2621 --- 41 unchanged lines hidden (view full) --- 2663 /* 2664 * Point the object appropriately 2665 */ 2666 if (oldobject != srcobject) { 2667 2668 /* 2669 * Set the object optimization hint flag 2670 */ | 2616 vm_object_reference(srcobject); 2617 entry->object.vm_object = srcobject; 2618 2619 if (oldobject) { 2620 vm_object_deallocate(oldobject); 2621 } 2622 } 2623 --- 41 unchanged lines hidden (view full) --- 2665 /* 2666 * Point the object appropriately 2667 */ 2668 if (oldobject != srcobject) { 2669 2670 /* 2671 * Set the object optimization hint flag 2672 */ |
2671 srcobject->flags |= OBJ_OPT; | 2673 vm_object_set_flag(srcobject, OBJ_OPT); |
2672 vm_object_reference(srcobject); 2673 2674 if (oldobject) { 2675 TAILQ_REMOVE(&oldobject->shadow_head, 2676 first_object, shadow_list); 2677 oldobject->shadow_count--; 2678 vm_object_deallocate(oldobject); 2679 } --- 9 unchanged lines hidden (view full) --- 2689 } else { 2690 pmap_remove (map->pmap, uaddr, tend); 2691 } 2692/* 2693 * Otherwise, we have to do a logical mmap. 2694 */ 2695 } else { 2696 | 2674 vm_object_reference(srcobject); 2675 2676 if (oldobject) { 2677 TAILQ_REMOVE(&oldobject->shadow_head, 2678 first_object, shadow_list); 2679 oldobject->shadow_count--; 2680 vm_object_deallocate(oldobject); 2681 } --- 9 unchanged lines hidden (view full) --- 2691 } else { 2692 pmap_remove (map->pmap, uaddr, tend); 2693 } 2694/* 2695 * Otherwise, we have to do a logical mmap. 2696 */ 2697 } else { 2698 |
2697 srcobject->flags |= OBJ_OPT; | 2699 vm_object_set_flag(srcobject, OBJ_OPT); |
2698 vm_object_reference(srcobject); 2699 2700 pmap_remove (map->pmap, uaddr, tend); 2701 2702 vm_object_pmap_copy_1 (srcobject, oindex, oindex + osize); 2703 vm_map_lock_upgrade(map); 2704 2705 if (entry == &map->header) { --- 110 unchanged lines hidden (view full) --- 2816 TAILQ_REMOVE(&object->shadow_head, robject, shadow_list); 2817 robject->backing_object = NULL; 2818 robject->backing_object_offset = 0; 2819 2820 vm_object_pip_wakeup(robject); 2821 vm_object_deallocate(robject); 2822 } 2823 | 2700 vm_object_reference(srcobject); 2701 2702 pmap_remove (map->pmap, uaddr, tend); 2703 2704 vm_object_pmap_copy_1 (srcobject, oindex, oindex + osize); 2705 vm_map_lock_upgrade(map); 2706 2707 if (entry == &map->header) { --- 110 unchanged lines hidden (view full) --- 2818 TAILQ_REMOVE(&object->shadow_head, robject, shadow_list); 2819 robject->backing_object = NULL; 2820 robject->backing_object_offset = 0; 2821 2822 vm_object_pip_wakeup(robject); 2823 vm_object_deallocate(robject); 2824 } 2825 |
2824 object->flags &= ~OBJ_OPT; | 2826 vm_object_clear_flag(object, OBJ_OPT); |
2825} 2826 2827#include "opt_ddb.h" 2828#ifdef DDB 2829#include <sys/kernel.h> 2830 2831#include <ddb/ddb.h> 2832 --- 110 unchanged lines hidden --- | 2827} 2828 2829#include "opt_ddb.h" 2830#ifdef DDB 2831#include <sys/kernel.h> 2832 2833#include <ddb/ddb.h> 2834 --- 110 unchanged lines hidden --- |