summaryrefslogtreecommitdiff
path: root/debian/patches/pager-alloc0001-libpager-provide-pager_create_alloc.patch
blob: b56aaa917408a4212913c453c2683ac8394af87d (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
From 0994ce18f6c09b7c5c6e47e0d0468109aef0e2c4 Mon Sep 17 00:00:00 2001
From: Justus Winter <justus@gnupg.org>
Date: Sun, 22 May 2016 19:35:10 +0200
Subject: [PATCH hurd 1/2] libpager: provide 'pager_create_alloc'

Add a variant to 'pager_create' that allocates memory for the user
hook next to the pager data increasing locality.

* doc/hurd.texi: Document new function.
* ext2fs/pager.c (pager_clear_user_data): Don't free 'upi'.
(diskfs_get_filemap): Use the new function.
* libpager/pager-create.c (_pager_create): New generic allocation
function.
(pager_create): Use the new generic function.
(pager_create_alloc): New function.
* libpager/pager.h (pager_create_alloc): New prototype.
---
 doc/hurd.texi           |  5 +++++
 ext2fs/pager.c          | 25 +++++++++++--------------
 libpager/pager-create.c | 50 ++++++++++++++++++++++++++++++++++++++++---------
 libpager/pager.h        |  8 ++++++++
 4 files changed, 65 insertions(+), 23 deletions(-)

diff --git a/doc/hurd.texi b/doc/hurd.texi
index 2bcf561..8428a77 100644
--- a/doc/hurd.texi
+++ b/doc/hurd.texi
@@ -1410,6 +1410,11 @@ create references to pagers by use of the relevant ports library
 functions.  On errors, return null and set @code{errno}.
 @end deftypefun
 
+@deftypefun {struct pager *} pager_create_alloc (@w{size_t @var{u_pager_size}}, @w{struct port_bucket *@var{bucket}}, @w{boolean_t @var{may_cache}}, @w{memory_object_copy_strategy_t @var{copy_strategy}})
+Likewise, but allocate space for the user hook adjacent to the pager
+data.
+@end deftypefun
+
 Once you are ready to turn over control to the pager library, you should
 call @code{ports_manage_port_operations_multithread} on the
 @var{bucket}, using @code{pager_demuxer} as the ports @var{demuxer}.
diff --git a/ext2fs/pager.c b/ext2fs/pager.c
index 485f69c..2ddce68 100644
--- a/ext2fs/pager.c
+++ b/ext2fs/pager.c
@@ -822,8 +822,6 @@ pager_clear_user_data (struct user_pager_info *upi)
 
       diskfs_nrele_light (upi->node);
     }
-
-  free (upi);
 }
 
 /* This will be called when the ports library wants to drop weak references.
@@ -1316,23 +1314,22 @@ diskfs_get_filemap (struct node *node, vm_prot_t prot)
 	}
       else
 	{
-	  struct user_pager_info *upi =
-	    malloc (sizeof (struct user_pager_info));
-	  upi->type = FILE_DATA;
-	  upi->node = node;
-	  upi->max_prot = prot;
-	  diskfs_nref_light (node);
-	  diskfs_node_disknode (node)->pager =
-		    pager_create (upi, file_pager_bucket, MAY_CACHE,
-				  MEMORY_OBJECT_COPY_DELAY, 0);
-	  if (diskfs_node_disknode (node)->pager == 0)
+	  struct user_pager_info *upi;
+	  pager = pager_create_alloc (sizeof *upi, file_pager_bucket,
+				      MAY_CACHE, MEMORY_OBJECT_COPY_DELAY, 0);
+	  if (pager == NULL)
 	    {
-	      diskfs_nrele_light (node);
-	      free (upi);
 	      pthread_spin_unlock (&node_to_page_lock);
 	      return MACH_PORT_NULL;
 	    }
 
+	  upi = pager->upi;
+	  upi->type = FILE_DATA;
+	  upi->node = node;
+	  upi->max_prot = prot;
+	  diskfs_nref_light (node);
+	  diskfs_node_disknode (node)->pager = pager;
+
 	  /* A weak reference for being part of the node.  */
 	  ports_port_ref_weak (diskfs_node_disknode (node)->pager);
 
diff --git a/libpager/pager-create.c b/libpager/pager-create.c
index b583f02..b3b7c8f 100644
--- a/libpager/pager-create.c
+++ b/libpager/pager-create.c
@@ -17,21 +17,19 @@
 
 #include "priv.h"
 
-/* Create and return a new pager with user info UPI.  */
-struct pager *
-pager_create (struct user_pager_info *upi,
-	      struct port_bucket *bucket,
-	      boolean_t may_cache,
-	      memory_object_copy_strategy_t copy_strategy,
-	      boolean_t notify_on_evict)
+static struct pager *
+_pager_create (size_t size,
+	       struct port_bucket *bucket,
+	       boolean_t may_cache,
+	       memory_object_copy_strategy_t copy_strategy,
+	       boolean_t notify_on_evict)
 {
   struct pager *p;
 
-  errno = ports_create_port (_pager_class, bucket, sizeof (struct pager), &p);
+  errno = ports_create_port (_pager_class, bucket, sizeof *p + size, &p);
   if (errno)
     return 0;
 
-  p->upi = upi;
   p->pager_state = NOTINIT;
   pthread_mutex_init (&p->interlock, NULL);
   pthread_cond_init (&p->wakeup, NULL);
@@ -50,6 +48,40 @@ pager_create (struct user_pager_info *upi,
   return p;
 }
 
+/* Create and return a new pager with user info UPI.  */
+struct pager *
+pager_create (struct user_pager_info *upi,
+	      struct port_bucket *bucket,
+	      boolean_t may_cache,
+	      memory_object_copy_strategy_t copy_strategy,
+	      boolean_t notify_on_evict)
+{
+  struct pager *p;
+
+  p = _pager_create (0, bucket, may_cache, copy_strategy, notify_on_evict);
+  if (p)
+    p->upi = upi;
+
+  return p;
+}
+
+struct pager *
+pager_create_alloc (size_t u_pager_size,
+		    struct port_bucket *bucket,
+		    boolean_t may_cache,
+		    memory_object_copy_strategy_t copy_strategy,
+		    boolean_t notify_on_evict)
+{
+  struct pager *p;
+
+  p = _pager_create (u_pager_size, bucket, may_cache, copy_strategy,
+		     notify_on_evict);
+  if (p)
+    p->upi = (struct user_pager_info *) ((char *) p + sizeof *p);
+
+  return p;
+}
+
 
 /* This causes the function to be run at startup by compiler magic. */
 static void create_class (void) __attribute__ ((constructor));
diff --git a/libpager/pager.h b/libpager/pager.h
index df4db68..d2a8d39 100644
--- a/libpager/pager.h
+++ b/libpager/pager.h
@@ -69,6 +69,14 @@ pager_create (struct user_pager_info *u_pager,
 	      memory_object_copy_strategy_t copy_strategy,
 	      boolean_t notify_on_evict);
 
+/* Likewise, but also allocate space for the user hook.  */
+struct pager *
+pager_create_alloc (size_t u_pager_size,
+		    struct port_bucket *bucket,
+		    boolean_t may_cache,
+		    memory_object_copy_strategy_t copy_strategy,
+		    boolean_t notify_on_evict);
+
 /* Return the user_pager_info struct associated with a pager. */
 struct user_pager_info *
 pager_get_upi (struct pager *p);
-- 
2.8.1