Fix mballoc-core.patch so it will compile w/o CONFIG_PROC_FS
[ext4-patch-queue.git] / jbd2_slab_cleanup.patch
blob33d091eb02ef558c3b9ca23080df4c1302f40857
1 JBD2: jbd2 slab allocation cleanups
3 From: Mingming Cao <cmm@us.ibm.com>
5 JBD2: Replace slab allocations with page allocations
7 JBD2 allocate memory for committed_data and frozen_data from slab. However
8 JBD2 should not pass slab pages down to the block layer. Use page allocator
9 pages instead. This will also prepare JBD for the large blocksize patchset.
11 Signed-off-by: Christoph Lameter <clameter@sgi.com>
12 Signed-off-by: Mingming Cao <cmm@us.ibm.com>
13 ---
15 fs/jbd2/commit.c | 6 +--
16 fs/jbd2/journal.c | 88 ++------------------------------------------------
17 fs/jbd2/transaction.c | 14 +++----
18 include/linux/jbd2.h | 18 +++++++---
19 4 files changed, 27 insertions(+), 99 deletions(-)
22 Index: linux-2.6.23-rc9/fs/jbd2/commit.c
23 ===================================================================
24 --- linux-2.6.23-rc9.orig/fs/jbd2/commit.c 2007-10-05 12:03:43.000000000 -0700
25 +++ linux-2.6.23-rc9/fs/jbd2/commit.c 2007-10-05 12:08:26.000000000 -0700
26 @@ -384,7 +384,7 @@ void jbd2_journal_commit_transaction(jou
27 struct buffer_head *bh = jh2bh(jh);
29 jbd_lock_bh_state(bh);
30 - jbd2_slab_free(jh->b_committed_data, bh->b_size);
31 + jbd2_free(jh->b_committed_data, bh->b_size);
32 jh->b_committed_data = NULL;
33 jbd_unlock_bh_state(bh);
35 @@ -801,14 +801,14 @@ restart_loop:
36 * Otherwise, we can just throw away the frozen data now.
38 if (jh->b_committed_data) {
39 - jbd2_slab_free(jh->b_committed_data, bh->b_size);
40 + jbd2_free(jh->b_committed_data, bh->b_size);
41 jh->b_committed_data = NULL;
42 if (jh->b_frozen_data) {
43 jh->b_committed_data = jh->b_frozen_data;
44 jh->b_frozen_data = NULL;
46 } else if (jh->b_frozen_data) {
47 - jbd2_slab_free(jh->b_frozen_data, bh->b_size);
48 + jbd2_free(jh->b_frozen_data, bh->b_size);
49 jh->b_frozen_data = NULL;
52 Index: linux-2.6.23-rc9/fs/jbd2/journal.c
53 ===================================================================
54 --- linux-2.6.23-rc9.orig/fs/jbd2/journal.c 2007-10-05 12:03:43.000000000 -0700
55 +++ linux-2.6.23-rc9/fs/jbd2/journal.c 2007-10-05 12:08:26.000000000 -0700
56 @@ -84,7 +84,6 @@ EXPORT_SYMBOL(jbd2_journal_force_commit)
58 static int journal_convert_superblock_v1(journal_t *, journal_superblock_t *);
59 static void __journal_abort_soft (journal_t *journal, int errno);
60 -static int jbd2_journal_create_jbd_slab(size_t slab_size);
63 * Helper function used to manage commit timeouts
64 @@ -335,10 +334,10 @@ repeat:
65 char *tmp;
67 jbd_unlock_bh_state(bh_in);
68 - tmp = jbd2_slab_alloc(bh_in->b_size, GFP_NOFS);
69 + tmp = jbd2_alloc(bh_in->b_size, GFP_NOFS);
70 jbd_lock_bh_state(bh_in);
71 if (jh_in->b_frozen_data) {
72 - jbd2_slab_free(tmp, bh_in->b_size);
73 + jbd2_free(tmp, bh_in->b_size);
74 goto repeat;
77 @@ -1096,13 +1095,6 @@ int jbd2_journal_load(journal_t *journal
81 - /*
82 - * Create a slab for this blocksize
83 - */
84 - err = jbd2_journal_create_jbd_slab(be32_to_cpu(sb->s_blocksize));
85 - if (err)
86 - return err;
88 /* Let the recovery code check whether it needs to recover any
89 * data from the journal. */
90 if (jbd2_journal_recover(journal))
91 @@ -1636,77 +1628,6 @@ void * __jbd2_kmalloc (const char *where
95 - * jbd slab management: create 1k, 2k, 4k, 8k slabs as needed
96 - * and allocate frozen and commit buffers from these slabs.
97 - *
98 - * Reason for doing this is to avoid, SLAB_DEBUG - since it could
99 - * cause bh to cross page boundary.
100 - */
102 -#define JBD_MAX_SLABS 5
103 -#define JBD_SLAB_INDEX(size) (size >> 11)
105 -static struct kmem_cache *jbd_slab[JBD_MAX_SLABS];
106 -static const char *jbd_slab_names[JBD_MAX_SLABS] = {
107 - "jbd2_1k", "jbd2_2k", "jbd2_4k", NULL, "jbd2_8k"
110 -static void jbd2_journal_destroy_jbd_slabs(void)
112 - int i;
114 - for (i = 0; i < JBD_MAX_SLABS; i++) {
115 - if (jbd_slab[i])
116 - kmem_cache_destroy(jbd_slab[i]);
117 - jbd_slab[i] = NULL;
121 -static int jbd2_journal_create_jbd_slab(size_t slab_size)
123 - int i = JBD_SLAB_INDEX(slab_size);
125 - BUG_ON(i >= JBD_MAX_SLABS);
127 - /*
128 - * Check if we already have a slab created for this size
129 - */
130 - if (jbd_slab[i])
131 - return 0;
133 - /*
134 - * Create a slab and force alignment to be same as slabsize -
135 - * this will make sure that allocations won't cross the page
136 - * boundary.
137 - */
138 - jbd_slab[i] = kmem_cache_create(jbd_slab_names[i],
139 - slab_size, slab_size, 0, NULL);
140 - if (!jbd_slab[i]) {
141 - printk(KERN_EMERG "JBD: no memory for jbd_slab cache\n");
142 - return -ENOMEM;
144 - return 0;
147 -void * jbd2_slab_alloc(size_t size, gfp_t flags)
149 - int idx;
151 - idx = JBD_SLAB_INDEX(size);
152 - BUG_ON(jbd_slab[idx] == NULL);
153 - return kmem_cache_alloc(jbd_slab[idx], flags | __GFP_NOFAIL);
156 -void jbd2_slab_free(void *ptr, size_t size)
158 - int idx;
160 - idx = JBD_SLAB_INDEX(size);
161 - BUG_ON(jbd_slab[idx] == NULL);
162 - kmem_cache_free(jbd_slab[idx], ptr);
166 * Journal_head storage management
168 static struct kmem_cache *jbd2_journal_head_cache;
169 @@ -1893,13 +1814,13 @@ static void __journal_remove_journal_hea
170 printk(KERN_WARNING "%s: freeing "
171 "b_frozen_data\n",
172 __FUNCTION__);
173 - jbd2_slab_free(jh->b_frozen_data, bh->b_size);
174 + jbd2_free(jh->b_frozen_data, bh->b_size);
176 if (jh->b_committed_data) {
177 printk(KERN_WARNING "%s: freeing "
178 "b_committed_data\n",
179 __FUNCTION__);
180 - jbd2_slab_free(jh->b_committed_data, bh->b_size);
181 + jbd2_free(jh->b_committed_data, bh->b_size);
183 bh->b_private = NULL;
184 jh->b_bh = NULL; /* debug, really */
185 @@ -2040,7 +1961,6 @@ static void jbd2_journal_destroy_caches(
186 jbd2_journal_destroy_revoke_caches();
187 jbd2_journal_destroy_jbd2_journal_head_cache();
188 jbd2_journal_destroy_handle_cache();
189 - jbd2_journal_destroy_jbd_slabs();
192 static int __init journal_init(void)
193 Index: linux-2.6.23-rc9/fs/jbd2/transaction.c
194 ===================================================================
195 --- linux-2.6.23-rc9.orig/fs/jbd2/transaction.c 2007-10-05 12:03:43.000000000 -0700
196 +++ linux-2.6.23-rc9/fs/jbd2/transaction.c 2007-10-05 12:08:26.000000000 -0700
197 @@ -236,7 +236,7 @@ out:
198 /* Allocate a new handle. This should probably be in a slab... */
199 static handle_t *new_handle(int nblocks)
201 - handle_t *handle = jbd_alloc_handle(GFP_NOFS);
202 + handle_t *handle = jbd2_alloc_handle(GFP_NOFS);
203 if (!handle)
204 return NULL;
205 memset(handle, 0, sizeof(*handle));
206 @@ -282,7 +282,7 @@ handle_t *jbd2_journal_start(journal_t *
208 err = start_this_handle(journal, handle);
209 if (err < 0) {
210 - jbd_free_handle(handle);
211 + jbd2_free_handle(handle);
212 current->journal_info = NULL;
213 handle = ERR_PTR(err);
215 @@ -668,7 +668,7 @@ repeat:
216 JBUFFER_TRACE(jh, "allocate memory for buffer");
217 jbd_unlock_bh_state(bh);
218 frozen_buffer =
219 - jbd2_slab_alloc(jh2bh(jh)->b_size,
220 + jbd2_alloc(jh2bh(jh)->b_size,
221 GFP_NOFS);
222 if (!frozen_buffer) {
223 printk(KERN_EMERG
224 @@ -728,7 +728,7 @@ done:
226 out:
227 if (unlikely(frozen_buffer)) /* It's usually NULL */
228 - jbd2_slab_free(frozen_buffer, bh->b_size);
229 + jbd2_free(frozen_buffer, bh->b_size);
231 JBUFFER_TRACE(jh, "exit");
232 return error;
233 @@ -881,7 +881,7 @@ int jbd2_journal_get_undo_access(handle_
235 repeat:
236 if (!jh->b_committed_data) {
237 - committed_data = jbd2_slab_alloc(jh2bh(jh)->b_size, GFP_NOFS);
238 + committed_data = jbd2_alloc(jh2bh(jh)->b_size, GFP_NOFS);
239 if (!committed_data) {
240 printk(KERN_EMERG "%s: No memory for committed data\n",
241 __FUNCTION__);
242 @@ -908,7 +908,7 @@ repeat:
243 out:
244 jbd2_journal_put_journal_head(jh);
245 if (unlikely(committed_data))
246 - jbd2_slab_free(committed_data, bh->b_size);
247 + jbd2_free(committed_data, bh->b_size);
248 return err;
251 @@ -1411,7 +1411,7 @@ int jbd2_journal_stop(handle_t *handle)
252 spin_unlock(&journal->j_state_lock);
255 - jbd_free_handle(handle);
256 + jbd2_free_handle(handle);
257 return err;
260 Index: linux-2.6.23-rc9/include/linux/jbd2.h
261 ===================================================================
262 --- linux-2.6.23-rc9.orig/include/linux/jbd2.h 2007-10-05 12:03:43.000000000 -0700
263 +++ linux-2.6.23-rc9/include/linux/jbd2.h 2007-10-05 12:08:26.000000000 -0700
264 @@ -72,14 +72,22 @@ extern u8 jbd2_journal_enable_debug;
265 #endif
267 extern void * __jbd2_kmalloc (const char *where, size_t size, gfp_t flags, int retry);
268 -extern void * jbd2_slab_alloc(size_t size, gfp_t flags);
269 -extern void jbd2_slab_free(void *ptr, size_t size);
271 #define jbd_kmalloc(size, flags) \
272 __jbd2_kmalloc(__FUNCTION__, (size), (flags), journal_oom_retry)
273 #define jbd_rep_kmalloc(size, flags) \
274 __jbd2_kmalloc(__FUNCTION__, (size), (flags), 1)
277 +static inline void *jbd2_alloc(size_t size, gfp_t flags)
279 + return (void *)__get_free_pages(flags, get_order(size));
282 +static inline void jbd2_free(void *ptr, size_t size)
284 + free_pages((unsigned long)ptr, get_order(size));
287 #define JBD2_MIN_JOURNAL_BLOCKS 1024
289 #ifdef __KERNEL__
290 @@ -959,12 +967,12 @@ void jbd2_journal_put_journal_head(struc
292 extern struct kmem_cache *jbd2_handle_cache;
294 -static inline handle_t *jbd_alloc_handle(gfp_t gfp_flags)
295 +static inline handle_t *jbd2_alloc_handle(gfp_t gfp_flags)
297 return kmem_cache_alloc(jbd2_handle_cache, gfp_flags);
300 -static inline void jbd_free_handle(handle_t *handle)
301 +static inline void jbd2_free_handle(handle_t *handle)
303 kmem_cache_free(jbd2_handle_cache, handle);