]> git.saurik.com Git - apple/xnu.git/blame - osfmk/vm/vm_purgeable_internal.h
xnu-4570.41.2.tar.gz
[apple/xnu.git] / osfmk / vm / vm_purgeable_internal.h
CommitLineData
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
42enum 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
2d21ac55
A
49typedef uint32_t token_idx_t;
50typedef uint32_t token_cnt_t;
2d21ac55 51#define TOKEN_COUNT_MAX UINT32_MAX
2d21ac55
A
52
53#define NUM_VOLATILE_GROUPS 8
54struct purgeable_q {
55 token_idx_t token_q_head; /* first token */
56 token_idx_t token_q_tail; /* last token */
57 token_idx_t token_q_unripe; /* first token which is not ripe */
58 int32_t new_pages;
59 queue_head_t objq[NUM_VOLATILE_GROUPS];
60 enum purgeable_q_type type;
61#if MACH_ASSERT
62 int debug_count_tokens;
63 int debug_count_objects;
64#endif
65};
66
67typedef struct purgeable_q * purgeable_q_t;
68
69extern struct purgeable_q purgeable_queues[PURGEABLE_Q_TYPE_MAX];
fe8ab488
A
70extern queue_head_t purgeable_nonvolatile_queue;
71extern int purgeable_nonvolatile_count;
4a3eedf9 72extern int32_t token_new_pagecount;
cf7d32b8 73#define TOKEN_NEW_PAGECOUNT_MAX INT32_MAX
2d21ac55
A
74extern int available_for_purge;
75
76
77/*
78 * Locking:
79 * the token counters are protected by the vm_page_queue_lock, since they're
80 * mostly used in that context and we don't want to do a lot of extra locking
81 * the purgeable page queues are protected by a separate lock since they're
cf7d32b8 82 * mostly used on a user context and we don't want any contention with the
2d21ac55
A
83 * pageout daemon.
84 */
b0d623f7 85decl_lck_mtx_data(extern,vm_purgeable_queue_lock)
2d21ac55
A
86
87/* add a new token to queue. called by vm_object_purgeable_control */
88/* enter with page queue locked */
89kern_return_t vm_purgeable_token_add(purgeable_q_t queue);
90
91/* enter with page queue locked */
92void vm_purgeable_token_delete_first(purgeable_q_t queue);
316670eb 93void vm_purgeable_token_delete_last(purgeable_q_t queue);
2d21ac55
A
94
95/*
cf7d32b8
A
96 * decrement token counters.
97 * enter with page queue locked
2d21ac55 98 */
cf7d32b8 99void vm_purgeable_q_advance_all(void);
2d21ac55 100
cf7d32b8 101/* the object purger. purges the next eligible object from memory. */
b0d623f7 102/* returns TRUE if an object was purged, otherwise FALSE. */
fe8ab488 103boolean_t vm_purgeable_object_purge_one(int force_purge_below_group, int flags);
b0d623f7
A
104
105/* purge all volatile objects now */
106void vm_purgeable_object_purge_all(void);
2d21ac55
A
107
108/* insert purgeable object into queue */
109void vm_purgeable_object_add(vm_object_t object, purgeable_q_t queue, int group);
110
cf7d32b8 111/* look for object. If found, remove from purgeable queue. */
2d21ac55
A
112purgeable_q_t vm_purgeable_object_remove(vm_object_t object);
113
39236c6e
A
114/* statistics for purgable objects in all queues */
115void vm_purgeable_stats(vm_purgeable_info_t info, task_t target_task);
116
3e170ce0
A
117#if DEVELOPMENT || DEBUG
118/* statistics for purgeable object usage in all queues for a task */
119kern_return_t vm_purgeable_account(task_t task, pvm_account_info_t acnt_info);
120#endif /* DEVELOPMENT || DEBUG */
121
fe8ab488
A
122int vm_purgeable_purge_task_owned(task_t task);
123void vm_purgeable_nonvolatile_enqueue(vm_object_t object, task_t task);
124void vm_purgeable_nonvolatile_dequeue(vm_object_t object);
125void vm_purgeable_accounting(vm_object_t object,
126 vm_purgable_t old_state,
127 boolean_t disown);
128void vm_purgeable_compressed_update(vm_object_t object,
129 int delta);
39236c6e 130
4bd07ac2
A
131#define PURGEABLE_LOOP_MAX 64
132
133#define TOKEN_ADD 0x40 /* 0x100 */
134#define TOKEN_DELETE 0x41 /* 0x104 */
135#define TOKEN_RIPEN 0x42 /* 0x108 */
136#define OBJECT_ADD 0x48 /* 0x120 */
137#define OBJECT_REMOVE 0x49 /* 0x124 */
138#define OBJECT_PURGE 0x4a /* 0x128 */
139#define OBJECT_PURGE_ALL 0x4b /* 0x12c */
140#define OBJECT_PURGE_ONE 0x4c /* 0x12d */
141#define OBJECT_PURGE_LOOP 0x4e /* 0x12e */
142
2d21ac55 143#endif /* __VM_PURGEABLE_INTERNAL__ */