]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/vm/task_working_set.h
xnu-344.21.73.tar.gz
[apple/xnu.git] / osfmk / vm / task_working_set.h
index 2eb74691ba3bc649fcb36ad794cc344ed895d9c4..90af7ef03845a631a3ed7260a3f717259016f949 100644 (file)
@@ -3,19 +3,22 @@
  *
  * @APPLE_LICENSE_HEADER_START@
  * 
- * The contents of this file constitute Original Code as defined in and
- * are subject to the Apple Public Source License Version 1.1 (the
- * "License").  You may not use this file except in compliance with the
- * License.  Please obtain a copy of the License at
- * http://www.apple.com/publicsource and read it before using this file.
+ * Copyright (c) 1999-2003 Apple Computer, Inc.  All Rights Reserved.
  * 
- * This Original Code and all software distributed under the License are
- * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ * 
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
- * License for the specific language governing rights and limitations
- * under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
  * 
  * @APPLE_LICENSE_HEADER_END@
  */
 /* of wired memory resource. */
 #define TWS_SMALL_HASH_LINE_COUNT 4 
 
-/*
-#define do_tws_hash(object,offset, rows, lines) \
-               ((((natural_t)(object)) +  \
-               (((natural_t)(offset)) >> 11) + \
-                                       (((natural_t)(offset)) >> 12)) & \
-                       ((2 * rows * lines) -1))
-*/
 /*
  * do not think of changing this hash unless you understand the implications
  * for the hash element page_cache field 
  */
 #define do_tws_hash(object,offset, rows, lines) \
-               (((((natural_t)(object)) >> 2) +  \
-                       ((natural_t)(object) >> 12) + \
-                       ((natural_t)(((vm_object_offset_t)(offset)) >> 12) \
-                                               & 0xFFFFFFFFFFFFFFE0)) & \
-                       ((2 * rows * lines) -1))
-/*
-#define do_tws_hash(object,offset, rows, lines) \
-               (((((natural_t)(object)) >> 2) +  \
-                       ((natural_t)(object) << 5) + \
+               ((((((natural_t)(object)) +  \
+                       (((natural_t)(object)) >> 6) +  \
+                       (((natural_t)(object)) >> 12) +  \
+                       (((natural_t)(object)) >> 18) +  \
+                       (((natural_t)(object)) >> 24)) << 5) +  \
                        ((natural_t)(((vm_object_offset_t)(offset)) >> 17))) & \
-                       ((2 * rows * lines) -1))
-*/
+                       ((rows * lines) -1))
 
 
 #define alt_tws_hash(addr, rows, lines) \
-               ((((natural_t)(addr)) >> 12) & \
-               ((2 * rows * lines) -1))
+               ((((natural_t)(addr)) >> 17) & \
+               ((rows * lines) -1))
+
+
+/* Long term startup data structures for initial cache filling */
+
+#define        TWS_STARTUP_MAX_HASH_RETRY      3
+
+/* 87 is the wrap skew, its based on  RETRY times the RETRY offset of 29 */
+/*
+#define do_startup_hash(addr, hash_size) \
+               ((((((natural_t)(addr)) >> 17) & \
+               ((2 * (hash_size)) -1)) + \
+               (87 * (((addr) & TWS_ADDR_OFF_MASK)/(2 * (hash_size))))) & \
+               ((2 * (hash_size)) -1))
+*/
+#define do_startup_hash(addr, hash_size) \
+               (((((natural_t)(addr)) >> 17) * 3) & \
+               (hash_size -1))
+
+
+
+struct tws_startup_ele {
+       unsigned int            page_cache;
+       vm_offset_t             page_addr;
+};
+
+typedef struct tws_startup_ele *tws_startup_ele_t;
+
+
+struct tws_startup_ptr {
+       tws_startup_ele_t       element;
+       struct tws_startup_ptr  *next;
+};
+
+typedef struct tws_startup_ptr *tws_startup_ptr_t;
+
+struct tws_startup {
+       unsigned int    tws_hash_size;  /* total size of struct in bytes */
+       unsigned int    ele_count;
+       unsigned int    array_size;     /* lines * rows * expansion_count */
+       unsigned int    hash_count;
+       
+       tws_startup_ptr_t       *table; /* hash table */
+       struct tws_startup_ptr  *ele;   /* hash elements */
+       struct  tws_startup_ele *array;
+};
+
+typedef struct tws_startup     *tws_startup_t;
+
+
+/* Dynamic cache data structures for working set */
 
 struct tws_hash_ele {
        vm_object_t             object;
@@ -91,8 +132,15 @@ struct tws_hash_ele {
 typedef struct tws_hash_ele *tws_hash_ele_t;
 
 #define TWS_HASH_OFF_MASK ((vm_object_offset_t)0xFFFFFFFFFFFE0000)
+#define TWS_ADDR_OFF_MASK ((vm_offset_t)0xFFFE0000)
 #define TWS_INDEX_MASK ((vm_object_offset_t)0x000000000001F000)
 
+struct tws_hash_ptr {
+       tws_hash_ele_t          element;
+       struct tws_hash_ptr     *next;
+};
+typedef struct tws_hash_ptr *tws_hash_ptr_t;
+
 struct tws_hash_line {
        int             ele_count;
        struct tws_hash_ele     list[TWS_ARRAY_SIZE];
@@ -104,8 +152,9 @@ typedef struct tws_hash_line *tws_hash_line_t;
 #define TWS_HASH_STYLE_SIGNAL  0x2
 
 
+#define TWS_ADDR_HASH 1
 #define TWS_HASH_EXPANSION_MAX 5
-#define TWS_MAX_REHASH 2
+#define TWS_MAX_REHASH 3
 
 
 struct tws_hash {
@@ -124,8 +173,19 @@ struct tws_hash {
        int             lookup_count;
        int             insert_count;
 
-       tws_hash_ele_t  *table[TWS_HASH_EXPANSION_MAX];
-       tws_hash_ele_t  *alt_table[TWS_HASH_EXPANSION_MAX];
+       tws_startup_t   startup_cache;
+       char            *startup_name;
+       int             startup_name_length;
+       unsigned int    uid;
+       int             mod;
+       int             fid;
+
+       unsigned int    obj_free_count[TWS_HASH_EXPANSION_MAX];
+       unsigned int    addr_free_count[TWS_HASH_EXPANSION_MAX];
+       tws_hash_ptr_t  free_hash_ele[TWS_HASH_EXPANSION_MAX];
+       tws_hash_ptr_t  *table[TWS_HASH_EXPANSION_MAX];
+       tws_hash_ptr_t  table_ele[TWS_HASH_EXPANSION_MAX];
+       tws_hash_ptr_t  alt_ele[TWS_HASH_EXPANSION_MAX];
        struct tws_hash_line    *cache[TWS_HASH_EXPANSION_MAX];
 }; 
 
@@ -179,7 +239,32 @@ kern_return_t      task_working_set_create(
 
 kern_return_t  tws_expand_working_set(
                vm_offset_t     old_tws,
-               int             line_count);
+               int             line_count,
+               boolean_t       dump_data);
+
+kern_return_t  tws_handle_startup_file(
+               task_t          task,
+               unsigned int    uid,
+               char            *app_name,
+               vm_offset_t     app_vp,
+               boolean_t       *new_info);
+
+kern_return_t  tws_write_startup_file(
+               task_t          task,
+               int             fid,
+               int             mod,
+               char            *name,
+               unsigned int    string_length);
+
+kern_return_t  tws_read_startup_file(
+               task_t                  task,
+               tws_startup_t           startup,
+               vm_offset_t             cache_size);
+
+void
+tws_hash_ws_flush(
+       tws_hash_t      tws);
+
 
 
 #endif  /* _VM_TASK_WORKING_SET_H_ */