jbd: Make jbd transactions come from its own cache.
PATCH 1/1 jbd: Make jbd transactions come from its own cache.
Allocate a slab cache for jbd transaction allocations. It may help to test various memory failure scenarios.
--- fs/jbd/checkpoint.c | 2 +- fs/jbd/journal.c | 25 +++++++++++++++++++++++++ fs/jbd/transaction.c | 6 ++---- include/linux/jbd.h | 16 ++++++++++++++++ 4 files changed, 44 insertions(+), 5 deletions(-)
fs/jbd/checkpoint.c +1 -1
@@ -753,5 +753,5 @@ void __journal_drop_transaction(journal_t *journal, transaction_t *transaction)J_ASSERT (journal->j_running_transaction != transaction);jbd_debug (1 ,"Dropping transaction %d, all done\n" , transaction->t_tid); -kfree (transaction); +jbd_free_transaction (transaction); }
fs/jbd/journal.c +25 -0
@@ -82,6 +82,7 @@ EXPORT_SYMBOL(journal_blocks_per_page);EXPORT_SYMBOL (journal_invalidatepage);EXPORT_SYMBOL (journal_try_to_free_buffers);EXPORT_SYMBOL (journal_force_commit); +EXPORT_SYMBOL (jbd_transaction_cache);static int journal_convert_superblock_v1 (journal_t *,journal_superblock_t *);static void __journal_abort_soft (journal_t *journal,int errno);
@@ -1752,6 +1753,27 @@ static void journal_destroy_journal_head_cache(void) } } +struct kmem_cache *jbd_transaction_cache; + +static int journal_init_transaction_cache (void ) +{ +J_ASSERT (jbd_transaction_cache ==NULL ); + jbd_transaction_cache =kmem_cache_create ("jbd_transaction" , +sizeof (transaction_t), +0 ,0 ,NULL ); +if (jbd_transaction_cache ==NULL ) { +printk (KERN_EMERG "JBD: failed to create transaction cache\n" ); +return -ENOMEM ; + } +return 0 ; +} + +static void journal_destroy_transaction_cache (void ) +{ +if (jbd_transaction_cache) +kmem_cache_destroy (jbd_transaction_cache); +} +/* * journal_head splicing and dicing */
@@ -2033,6 +2055,8 @@ static int __init journal_init_caches(void) ret =journal_init_journal_head_cache ();if (ret ==0 ) ret =journal_init_handle_cache (); +if (ret ==0 ) + ret =journal_init_transaction_cache ();return ret; }
@@ -2041,6 +2065,7 @@ static void journal_destroy_caches(void)journal_destroy_revoke_caches ();journal_destroy_journal_head_cache ();journal_destroy_handle_cache (); +journal_destroy_transaction_cache (); }static int __init journal_init (void )
fs/jbd/transaction.c +2 -4
@@ -99,8 +99,7 @@ static int start_this_handle(journal_t *journal, handle_t *handle) alloc_transaction:if (!journal->j_running_transaction) { - new_transaction =kzalloc (sizeof (*new_transaction), -GFP_NOFS |__GFP_NOFAIL); + new_transaction =jbd_alloc_transaction (GFP_NOFS |__GFP_NOFAIL);if (!new_transaction) { ret = -ENOMEM ; goto out;
@@ -232,8 +231,7 @@ repeat_locked:lock_map_acquire (&handle->h_lockdep_map); out: -if (unlikely (new_transaction))/* It's usually NULL */ -kfree (new_transaction); +jbd_free_transaction (new_transaction);return ret; }
include/linux/jbd.h +16 -0
@@ -958,6 +958,22 @@ static inline void jbd_free_handle(handle_t *handle)kmem_cache_free (jbd_handle_cache, handle); } +/* +* transaction management +*/ +extern struct kmem_cache *jbd_transaction_cache; + +static inline transaction_t *jbd_alloc_transaction (gfp_t gfp_flags) +{ +return kmem_cache_zalloc (jbd_transaction_cache, gfp_flags); +} + +static inline void jbd_free_transaction (transaction_t *transaction) +{ +if (transaction) +kmem_cache_free (jbd_transaction_cache, transaction); +} +/* Primary revoke support */ #define JOURNAL_REVOKE_DEFAULT_HASH 256extern int journal_init_revoke (journal_t *,int );
Signature · 1 line
1.7.4.1
Quoted 2 lines · On Sat, 11 Jun 2011 02:36:01 -0700 Manish Katiyar <[email protected]> wrote:
Allocate a slab cache for jbd transaction allocations. It may help to test various memory failure scenarios.
This doesn't seem terribly useful to me. That's truly ancient code and the change rate is really low. If there were problem in there then we'd already know about them. And the allocation frequency for these objects is very low.
If you had some deeper reason for making this change, please describe it. For example, were you chasing some bug?
fs/jbd/journal.c static void journal_destroy_journal_head_cache(void) · line 1763
Quoted 6 lines
fs/jbd/journal.c +6
-0+static int journal_init_transaction_cache (void ) +{ +J_ASSERT (jbd_transaction_cache ==NULL ); + jbd_transaction_cache =kmem_cache_create ("jbd_transaction" , +sizeof (transaction_t), +0 ,0 ,NULL );
We have a KMEM_CACHE helper macro for this. It proved useful at the time, when we were changing the kmem_cache_create() arguments fairly often. It's less useful now.
Quoted 6 lines · Andrew Morton
Quoted 2 lines · On Sat, 11 Jun 2011 02:36:01 -0700 Manish Katiyar <[email protected]> wrote:
Allocate a slab cache for jbd transaction allocations. It may help to test various memory failure scenarios.
Quoted 7 lines
This doesn't seem terribly useful to me. That's truly ancient code and the change rate is really low. If there were problem in there then we'd already know about them. And the allocation frequency for these objects is very low.
If you had some deeper reason for making this change, please describe it. For example, were you chasing some bug?
Hi Andrew,
I was doing similar changes for jbd2, hence did it for jbd too. The
changes for jbd2 were done so that we can use the
fault injection framework to introduce/test ENOMEM situations from the journal transaction allocation layer and test
how well the callers (ext4 code in particular) deal with such situations and fix them if required.
Signature · 6 lines
Thanks - Manish -- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html