1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
From 10c45d92cba6858f1bc3fd4ff94363fe2bf85074 Mon Sep 17 00:00:00 2001
From: Richard Braun <rbraun@sceen.net>
Date: Sun, 7 Feb 2016 14:08:24 +0100
Subject: [PATCH gnumach 2/2] Fix page cache accounting
* vm/vm_object.c (vm_object_bootstrap): Set template object `cached'
member to FALSE.
(vm_object_cache_add, vm_object_cache_remove): New functions.
(vm_object_collect, vm_object_deallocate, vm_object_lookup,
vm_object_lookup_name, vm_object_destroy): Use new cache management functions.
(vm_object_terminate, vm_object_collapse): Make sure object isn't cached.
* vm/vm_object.h (struct vm_object): New `cached' member.
---
vm/vm_object.c | 70 +++++++++++++++++++++++++++++++++-------------------------
vm/vm_object.h | 3 ++-
2 files changed, 42 insertions(+), 31 deletions(-)
diff --git a/vm/vm_object.c b/vm/vm_object.c
index 449af16..bc30128 100644
--- a/vm/vm_object.c
+++ b/vm/vm_object.c
@@ -303,6 +303,7 @@ void vm_object_bootstrap(void)
vm_object_template.paging_in_progress = 0;
vm_object_template.can_persist = FALSE;
+ vm_object_template.cached = FALSE;
vm_object_template.internal = TRUE;
vm_object_template.temporary = TRUE;
vm_object_template.alive = TRUE;
@@ -348,6 +349,33 @@ void vm_object_init(void)
IKOT_PAGING_NAME);
}
+/*
+ * Object cache management functions.
+ *
+ * Both the cache and the object must be locked
+ * before calling these functions.
+ */
+
+static void vm_object_cache_add(
+ vm_object_t object)
+{
+ assert(!object->cached);
+ queue_enter(&vm_object_cached_list, object, vm_object_t, cached_list);
+ vm_object_cached_count++;
+ vm_object_cached_pages_update(object->resident_page_count);
+ object->cached = TRUE;
+}
+
+static void vm_object_cache_remove(
+ vm_object_t object)
+{
+ assert(object->cached);
+ queue_remove(&vm_object_cached_list, object, vm_object_t, cached_list);
+ vm_object_cached_count--;
+ vm_object_cached_pages_update(-object->resident_page_count);
+ object->cached = FALSE;
+}
+
void vm_object_collect(
register vm_object_t object)
{
@@ -371,7 +399,7 @@ void vm_object_collect(
return;
}
- queue_remove(&vm_object_cached_list, object, vm_object_t, cached_list);
+ vm_object_cache_remove(object);
vm_object_terminate(object);
}
@@ -438,12 +466,8 @@ void vm_object_deallocate(
* it in the cache.
*/
if (object->can_persist && (object->resident_page_count > 0)) {
- queue_enter(&vm_object_cached_list, object,
- vm_object_t, cached_list);
- vm_object_cached_count++;
- vm_object_cached_pages_update(object->resident_page_count);
+ vm_object_cache_add(object);
vm_object_cache_unlock();
-
vm_object_unlock(object);
return;
}
@@ -594,6 +618,7 @@ void vm_object_terminate(
assert(object->ref_count == 0);
assert(object->paging_in_progress == 0);
+ assert(!object->cached);
/*
* Throw away port rights... note that they may
@@ -1779,12 +1804,8 @@ vm_object_t vm_object_lookup(
assert(object->alive);
- if (object->ref_count == 0) {
- queue_remove(&vm_object_cached_list, object,
- vm_object_t, cached_list);
- vm_object_cached_count--;
- vm_object_cached_pages_update(-object->resident_page_count);
- }
+ if (object->ref_count == 0)
+ vm_object_cache_remove(object);
object->ref_count++;
vm_object_unlock(object);
@@ -1811,12 +1832,8 @@ vm_object_t vm_object_lookup_name(
assert(object->alive);
- if (object->ref_count == 0) {
- queue_remove(&vm_object_cached_list, object,
- vm_object_t, cached_list);
- vm_object_cached_count--;
- vm_object_cached_pages_update(-object->resident_page_count);
- }
+ if (object->ref_count == 0)
+ vm_object_cache_remove(object);
object->ref_count++;
vm_object_unlock(object);
@@ -1848,12 +1865,8 @@ void vm_object_destroy(
object = (vm_object_t) pager->ip_kobject;
vm_object_lock(object);
- if (object->ref_count == 0) {
- queue_remove(&vm_object_cached_list, object,
- vm_object_t, cached_list);
- vm_object_cached_count--;
- vm_object_cached_pages_update(-object->resident_page_count);
- }
+ if (object->ref_count == 0)
+ vm_object_cache_remove(object);
object->ref_count++;
object->can_persist = FALSE;
@@ -2001,12 +2014,8 @@ restart:
if ((object != VM_OBJECT_NULL) && !must_init) {
vm_object_lock(object);
- if (object->ref_count == 0) {
- queue_remove(&vm_object_cached_list, object,
- vm_object_t, cached_list);
- vm_object_cached_count--;
- vm_object_cached_pages_update(-object->resident_page_count);
- }
+ if (object->ref_count == 0)
+ vm_object_cache_remove(object);
object->ref_count++;
vm_object_unlock(object);
@@ -2515,6 +2524,7 @@ void vm_object_collapse(
);
assert(backing_object->alive);
+ assert(!backing_object->cached);
backing_object->alive = FALSE;
vm_object_unlock(backing_object);
diff --git a/vm/vm_object.h b/vm/vm_object.h
index 96bfbac..eb8a0c2 100644
--- a/vm/vm_object.h
+++ b/vm/vm_object.h
@@ -148,8 +148,9 @@ struct vm_object {
*/
/* boolean_t */ use_shared_copy : 1,/* Use shared (i.e.,
* delayed) copy on write */
- /* boolean_t */ shadowed: 1; /* Shadow may exist */
+ /* boolean_t */ shadowed: 1, /* Shadow may exist */
+ /* boolean_t */ cached: 1; /* Object is cached */
queue_chain_t cached_list; /* Attachment point for the list
* of objects cached as a result
* of their can_persist value
--
2.1.4
|