Author: markj
Date: Fri Nov  2 16:26:44 2018
New Revision: 340064
URL: https://svnweb.freebsd.org/changeset/base/340064

Log:
  Initialize the eflags field of vm_map headers.
  
  Initializing the eflags field of the map->header entry to a value with a
  unique new bit set makes a few comparisons to &map->header unnecessary.
  
  Submitted by: Doug Moore <do...@rice.edu>
  Reviewed by:  alc, kib
  Tested by:    pho
  MFC after:    2 weeks
  Differential Revision:        https://reviews.freebsd.org/D14005

Modified:
  head/sys/kern/sys_process.c
  head/sys/vm/vm_map.c
  head/sys/vm/vm_map.h

Modified: head/sys/kern/sys_process.c
==============================================================================
--- head/sys/kern/sys_process.c Fri Nov  2 16:21:44 2018        (r340063)
+++ head/sys/kern/sys_process.c Fri Nov  2 16:26:44 2018        (r340064)
@@ -387,8 +387,9 @@ ptrace_vm_entry(struct thread *td, struct proc *p, str
                        error = EINVAL;
                        break;
                }
-               while (entry != &map->header &&
-                   (entry->eflags & MAP_ENTRY_IS_SUB_MAP) != 0) {
+               KASSERT((map->header.eflags & MAP_ENTRY_IS_SUB_MAP) == 0,
+                   ("Submap in map header"));
+               while ((entry->eflags & MAP_ENTRY_IS_SUB_MAP) != 0) {
                        entry = entry->next;
                        index++;
                }

Modified: head/sys/vm/vm_map.c
==============================================================================
--- head/sys/vm/vm_map.c        Fri Nov  2 16:21:44 2018        (r340063)
+++ head/sys/vm/vm_map.c        Fri Nov  2 16:26:44 2018        (r340064)
@@ -796,6 +796,7 @@ _vm_map_init(vm_map_t map, pmap_t pmap, vm_offset_t mi
 {
 
        map->header.next = map->header.prev = &map->header;
+       map->header.eflags = MAP_ENTRY_HEADER;
        map->needs_wakeup = FALSE;
        map->system_map = 0;
        map->pmap = pmap;
@@ -1277,8 +1278,8 @@ charged:
                if (object->ref_count > 1 || object->shadow_count != 0)
                        vm_object_clear_flag(object, OBJ_ONEMAPPING);
                VM_OBJECT_WUNLOCK(object);
-       } else if (prev_entry != &map->header &&
-           (prev_entry->eflags & ~MAP_ENTRY_USER_WIRED) == protoeflags &&
+       } else if ((prev_entry->eflags & ~MAP_ENTRY_USER_WIRED) ==
+           protoeflags &&
            (cow & (MAP_STACK_GROWS_DOWN | MAP_STACK_GROWS_UP)) == 0 &&
            prev_entry->end == start && (prev_entry->cred == cred ||
            (prev_entry->object.vm_object != NULL &&
@@ -1708,8 +1709,7 @@ vm_map_simplify_entry(vm_map_t map, vm_map_entry_t ent
                return;
 
        prev = entry->prev;
-       if (prev != &map->header &&
-           vm_map_mergeable_neighbors(prev, entry)) {
+       if (vm_map_mergeable_neighbors(prev, entry)) {
                vm_map_entry_unlink(map, prev);
                entry->start = prev->start;
                entry->offset = prev->offset;
@@ -1719,8 +1719,7 @@ vm_map_simplify_entry(vm_map_t map, vm_map_entry_t ent
        }
 
        next = entry->next;
-       if (next != &map->header &&
-           vm_map_mergeable_neighbors(entry, next)) {
+       if (vm_map_mergeable_neighbors(entry, next)) {
                vm_map_entry_unlink(map, next);
                entry->end = next->end;
                vm_map_entry_resize_free(map, entry);

Modified: head/sys/vm/vm_map.h
==============================================================================
--- head/sys/vm/vm_map.h        Fri Nov  2 16:21:44 2018        (r340063)
+++ head/sys/vm/vm_map.h        Fri Nov  2 16:26:44 2018        (r340064)
@@ -146,6 +146,7 @@ struct vm_map_entry {
 #define        MAP_ENTRY_GUARD                 0x10000
 #define        MAP_ENTRY_STACK_GAP_DN          0x20000
 #define        MAP_ENTRY_STACK_GAP_UP          0x40000
+#define        MAP_ENTRY_HEADER                0x80000
 
 #ifdef _KERNEL
 static __inline u_char
@@ -175,24 +176,22 @@ vm_map_entry_system_wired_count(vm_map_entry_t entry)
  *     list.  Both structures are ordered based upon the start and
  *     end addresses contained within each map entry.
  *
- *     Counterintuitively, the map's min offset value is stored in
- *     map->header.end, and its max offset value is stored in
- *     map->header.start.
- *
- *     The list header has max start value and min end value to act
- *     as sentinels for sequential search of the doubly-linked list.
  *     Sleator and Tarjan's top-down splay algorithm is employed to
  *     control height imbalance in the binary search tree.
  *
+ *     The map's min offset value is stored in map->header.end, and
+ *     its max offset value is stored in map->header.start.  These
+ *     values act as sentinels for any forward or backward address
+ *     scan of the list.  The map header has a special value for the
+ *     eflags field, MAP_ENTRY_HEADER, that is set initially, is
+ *     never changed, and prevents an eflags match of the header
+ *     with any other map entry.
+ *
  *     List of locks
  *     (c)     const until freed
  */
 struct vm_map {
        struct vm_map_entry header;     /* List of entries */
-/*
-       map min_offset  header.end      (c)
-       map max_offset  header.start    (c)
-*/
        struct sx lock;                 /* Lock for map data */
        struct mtx system_mtx;
        int nentries;                   /* Number of entries */
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to