]>
Commit | Line | Data |
---|---|---|
2d21ac55 A |
1 | /* |
2 | * Copyright (c) 2007 Apple Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
6 | * This file contains Original Code and/or Modifications of Original Code | |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. Please obtain a copy of the License at | |
10 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
11 | * file. | |
12 | * | |
13 | * The Original Code and all software distributed under the License are | |
14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
18 | * Please see the License for the specific language governing rights and | |
19 | * limitations under the License. | |
20 | * | |
21 | * @APPLE_LICENSE_HEADER_END@ | |
22 | */ | |
23 | ||
24 | /* | |
25 | * Purgeable spelling rules | |
26 | * It is believed that the correct spelling is | |
27 | * { 'p', 'u', 'r', 'g', 'e', 'a', 'b', 'l', 'e' }. | |
28 | * However, there is one published API that likes to spell it without the | |
29 | * first 'e', vm_purgable_control(). Since we can't change that API, | |
30 | * here are the rules. | |
31 | * All qualifiers defined in vm_purgable.h are spelled without the e. | |
32 | * All other qualifiers are spelled with the e. | |
33 | * Right now, there are remains of the wrong spelling throughout the code, | |
34 | * vm_object_t.purgable for example. We expect to change these on occasion. | |
35 | */ | |
36 | ||
37 | #ifndef __VM_PURGEABLE_INTERNAL__ | |
38 | #define __VM_PURGEABLE_INTERNAL__ | |
39 | ||
40 | #include <kern/queue.h> | |
41 | ||
42 | enum purgeable_q_type { | |
43 | PURGEABLE_Q_TYPE_OBSOLETE, | |
44 | PURGEABLE_Q_TYPE_FIFO, | |
45 | PURGEABLE_Q_TYPE_LIFO, | |
46 | PURGEABLE_Q_TYPE_MAX | |
47 | }; | |
48 | ||
49 | /* | |
50 | * It appears there's a 16 vs 32 size mismatch when using | |
51 | * CONFIG_TOKEN_QUEUE_SMALL and the resulting math can lead to a large | |
52 | * negative value for new_pages in vm_purgeable.c. | |
53 | */ | |
54 | #if (CONFIG_TOKEN_QUEUE_SMALL == 1) && 0 | |
55 | typedef uint16_t token_idx_t; | |
56 | typedef uint16_t token_cnt_t; | |
57 | #define MAX_VOLATILE 0x01000 | |
58 | #define TOKEN_COUNT_MAX UINT16_MAX | |
59 | #else | |
60 | typedef uint32_t token_idx_t; | |
61 | typedef uint32_t token_cnt_t; | |
62 | #define MAX_VOLATILE 0x10000 | |
63 | #define TOKEN_COUNT_MAX UINT32_MAX | |
64 | #endif | |
65 | ||
66 | #define NUM_VOLATILE_GROUPS 8 | |
67 | struct purgeable_q { | |
68 | token_idx_t token_q_head; /* first token */ | |
69 | token_idx_t token_q_tail; /* last token */ | |
70 | token_idx_t token_q_unripe; /* first token which is not ripe */ | |
71 | int32_t new_pages; | |
72 | queue_head_t objq[NUM_VOLATILE_GROUPS]; | |
73 | enum purgeable_q_type type; | |
74 | #if MACH_ASSERT | |
75 | int debug_count_tokens; | |
76 | int debug_count_objects; | |
77 | #endif | |
78 | }; | |
79 | ||
80 | typedef struct purgeable_q * purgeable_q_t; | |
81 | ||
82 | extern struct purgeable_q purgeable_queues[PURGEABLE_Q_TYPE_MAX]; | |
83 | extern token_cnt_t token_new_pagecount; | |
84 | extern int available_for_purge; | |
85 | ||
86 | ||
87 | /* | |
88 | * Locking: | |
89 | * the token counters are protected by the vm_page_queue_lock, since they're | |
90 | * mostly used in that context and we don't want to do a lot of extra locking | |
91 | * the purgeable page queues are protected by a separate lock since they're | |
92 | * mostly user on a user context and we don't want any contention with the | |
93 | * pageout daemon. | |
94 | */ | |
95 | ||
96 | decl_mutex_data(,vm_purgeable_queue_lock) | |
97 | ||
98 | /* add a new token to queue. called by vm_object_purgeable_control */ | |
99 | /* enter with page queue locked */ | |
100 | kern_return_t vm_purgeable_token_add(purgeable_q_t queue); | |
101 | ||
102 | /* enter with page queue locked */ | |
103 | void vm_purgeable_token_delete_first(purgeable_q_t queue); | |
104 | ||
105 | /* | |
106 | * decrement token counters. the function will call the object purger if a | |
107 | * token expires. | |
108 | */ | |
109 | /* enter with page queue locked */ | |
110 | void vm_purgeable_q_advance_all(uint32_t num_pages); | |
111 | ||
112 | /* the object purger. purges the specified number of objects from memory. */ | |
113 | void vm_purgeable_object_purge_one(void); | |
114 | ||
115 | /* insert purgeable object into queue */ | |
116 | void vm_purgeable_object_add(vm_object_t object, purgeable_q_t queue, int group); | |
117 | ||
118 | /* Look for page belonging to object. If found, put on inactive queue. */ | |
119 | purgeable_q_t vm_purgeable_object_remove(vm_object_t object); | |
120 | ||
121 | #endif /* __VM_PURGEABLE_INTERNAL__ */ |