summaryrefslogtreecommitdiff
path: root/debian/patches/ext2fs-two-pagers.patch
blob: 4f4087f5eff9d276bbd04437c539c363925c843a (plain)
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
commit f06e4557fed5d86a9eb4ab0a1fe54ba021dc53ed
Author: Justus Winter <4winter@informatik.uni-hamburg.de>
Date:   Sat Apr 26 19:48:18 2014 +0200

    ext2fs: use two distinct pager buckets for the disk and file pager
    
    ext2fs has two kinds of pagers.  One for the files, one for the disk.
    Previously, both were in the same port bucket.
    
    If a request for a file pager arrives, it most likely touches some
    metadata (like the superblock).  This is in turn backed by the disk
    pager, so another request is generated for the disk pager.
    
    Seperate all pagers clearly by using two port buckets.  This will
    enable us to use a single thread per port bucket in the future.
    
    * ext2fs/pager.c (pager_bucket): Rename to...
    (disk_pager_bucket): ... this to make the change explicit at every
    occurrence.
    (file_pager_bucket): New variable.
    (service_paging_requests): New function.
    (create_disk_pager): Also create the file pager.
    (diskfs_get_filemap): Handout pagers from the file_pager_bucket.
    (diskfs_shutdown_pager): This is only concerned with the file pager.
    Simplify code accordingly.
    (diskfs_sync_everything): Likewise.
    (diskfs_pager_users): Likewise.
    (diskfs_max_user_pager_prot): Likewise.
    (disable_caching): Iterate over both buckets.
    (enable_caching): Likewise.

diff --git a/ext2fs/pager.c b/ext2fs/pager.c
index 6e99c83..1753831 100644
--- a/ext2fs/pager.c
+++ b/ext2fs/pager.c
@@ -27,8 +27,11 @@
 /* XXX */
 #include "../libpager/priv.h"
 
-/* A ports bucket to hold pager ports.  */
-struct port_bucket *pager_bucket;
+/* A ports bucket to hold disk pager ports.  */
+struct port_bucket *disk_pager_bucket;
+
+/* A ports bucket to hold file pager ports.  */
+struct port_bucket *file_pager_bucket;
 
 pthread_spinlock_t node_to_page_lock = PTHREAD_SPINLOCK_INITIALIZER;
 
@@ -1188,21 +1191,56 @@ disk_cache_block_is_ref (block_t block)
   return ref;
 }
 
-/* Create the DISK pager.  */
+/* A top-level function for the paging thread that just services paging
+   requests.  */
+static void *
+service_paging_requests (void *arg)
+{
+  struct port_bucket *pager_bucket = arg;
+  ports_manage_port_operations_multithread (pager_bucket,
+					    pager_demuxer,
+					    1000,
+					    0,
+					    NULL);
+  /* Not reached.  */
+  return NULL;
+}
+
+/* Create the disk pager, and the file pager.  */
 void
 create_disk_pager (void)
 {
+  pthread_t thread;
+  pthread_attr_t attr;
+  error_t err;
+
+  /* The disk pager.  */
   struct user_pager_info *upi = malloc (sizeof (struct user_pager_info));
   if (!upi)
     ext2_panic ("can't create disk pager: %s", strerror (errno));
   upi->type = DISK;
-  pager_bucket = ports_create_bucket ();
+  disk_pager_bucket = ports_create_bucket ();
   get_hypermetadata ();
   disk_cache_blocks = DISK_CACHE_BLOCKS;
   disk_cache_size = disk_cache_blocks << log2_block_size;
-  diskfs_start_disk_pager (upi, pager_bucket, MAY_CACHE, 1,
+  diskfs_start_disk_pager (upi, disk_pager_bucket, MAY_CACHE, 1,
 			   disk_cache_size, &disk_cache);
   disk_cache_init ();
+
+  /* The file pager.  */
+  file_pager_bucket = ports_create_bucket ();
+
+#define STACK_SIZE (64 * 1024)
+  pthread_attr_init (&attr);
+  pthread_attr_setstacksize (&attr, STACK_SIZE);
+#undef STACK_SIZE
+
+  /* Make a thread to service file paging requests.  */
+  err = pthread_create (&thread, &attr,
+			service_paging_requests, file_pager_bucket);
+  if (err)
+    error (2, err, "pthread_create");
+  pthread_detach (thread);
 }
 
 /* Call this to create a FILE_DATA pager and return a send right.
@@ -1241,7 +1279,7 @@ diskfs_get_filemap (struct node *node, vm_prot_t prot)
 	  upi->max_prot = prot;
 	  diskfs_nref_light (node);
 	  node->dn->pager =
-	    pager_create (upi, pager_bucket, MAY_CACHE,
+	    pager_create (upi, file_pager_bucket, MAY_CACHE,
 			  MEMORY_OBJECT_COPY_DELAY, 0);
 	  if (node->dn->pager == 0)
 	    {
@@ -1324,14 +1362,13 @@ diskfs_shutdown_pager ()
   error_t shutdown_one (void *v_p)
     {
       struct pager *p = v_p;
-      if (p != diskfs_disk_pager)
-	pager_shutdown (p);
+      pager_shutdown (p);
       return 0;
     }
 
   write_all_disknodes ();
 
-  ports_bucket_iterate (pager_bucket, shutdown_one);
+  ports_bucket_iterate (file_pager_bucket, shutdown_one);
 
   /* Sync everything on the the disk pager.  */
   sync_global (1);
@@ -1347,13 +1384,12 @@ diskfs_sync_everything (int wait)
   error_t sync_one (void *v_p)
     {
       struct pager *p = v_p;
-      if (p != diskfs_disk_pager)
-	pager_sync (p, wait);
+      pager_sync (p, wait);
       return 0;
     }
 
   write_all_disknodes ();
-  ports_bucket_iterate (pager_bucket, sync_one);
+  ports_bucket_iterate (file_pager_bucket, sync_one);
 
   /* Do things on the the disk pager.  */
   sync_global (wait);
@@ -1372,7 +1408,8 @@ disable_caching ()
 
   /* Loop through the pagers and turn off caching one by one,
      synchronously.  That should cause termination of each pager. */
-  ports_bucket_iterate (pager_bucket, block_cache);
+  ports_bucket_iterate (disk_pager_bucket, block_cache);
+  ports_bucket_iterate (file_pager_bucket, block_cache);
 }
 
 static void
@@ -1400,7 +1437,8 @@ enable_caching ()
       return 0;
     }
 
-  ports_bucket_iterate (pager_bucket, enable_cache);
+  ports_bucket_iterate (disk_pager_bucket, enable_cache);
+  ports_bucket_iterate (file_pager_bucket, enable_cache);
 }
 
 /* Tell diskfs if there are pagers exported, and if none, then
@@ -1408,7 +1446,7 @@ enable_caching ()
 int
 diskfs_pager_users ()
 {
-  int npagers = ports_count_bucket (pager_bucket);
+  int npagers = ports_count_bucket (file_pager_bucket);
 
   if (npagers <= 1)
     return 0;
@@ -1421,8 +1459,8 @@ diskfs_pager_users ()
 	 immediately.  XXX */
       sleep (1);
 
-      npagers = ports_count_bucket (pager_bucket);
-      if (npagers <= 1)
+      npagers = ports_count_bucket (file_pager_bucket);
+      if (npagers == 0)
 	return 0;
 
       /* Darn, there are actual honest users.  Turn caching back on,
@@ -1430,7 +1468,7 @@ diskfs_pager_users ()
       enable_caching ();
     }
 
-  ports_enable_bucket (pager_bucket);
+  ports_enable_bucket (file_pager_bucket);
 
   return 1;
 }
@@ -1441,17 +1479,15 @@ vm_prot_t
 diskfs_max_user_pager_prot ()
 {
   vm_prot_t max_prot = 0;
-  int npagers = ports_count_bucket (pager_bucket);
+  int npagers = ports_count_bucket (file_pager_bucket);
 
-  if (npagers > 1)
-    /* More than just the disk pager.  */
+  if (npagers > 0)
     {
       error_t add_pager_max_prot (void *v_p)
 	{
 	  struct pager *p = v_p;
 	  struct user_pager_info *upi = pager_get_upi (p);
-	  if (upi->type == FILE_DATA)
-	    max_prot |= upi->max_prot;
+	  max_prot |= upi->max_prot;
 	  /* Stop iterating if MAX_PROT is as filled as it's going to get. */
 	  return
 	    (max_prot == (VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE)) ? 1 : 0;
@@ -1463,12 +1499,12 @@ diskfs_max_user_pager_prot ()
 	 immediately.  XXX */
       sleep (1);
 
-      ports_bucket_iterate (pager_bucket, add_pager_max_prot);
+      ports_bucket_iterate (file_pager_bucket, add_pager_max_prot);
 
       enable_caching ();
     }
 
-  ports_enable_bucket (pager_bucket);
+  ports_enable_bucket (file_pager_bucket);
 
   return max_prot;
 }