linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] jbd2: allocate transaction from special cache
@ 2011-11-13 11:21 Yongqiang Yang
  2011-11-13 11:21 ` [PATCH 2/3] jbd2: rename functions initializing caches Yongqiang Yang
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Yongqiang Yang @ 2011-11-13 11:21 UTC (permalink / raw)
  To: tytso; +Cc: linux-ext4, Yongqiang Yang

transaction_t is 136 byes under 32-bit systems. If we allocate
it from general cache, it comsumes 256 bytes.  So let jbd2 allocate
it from special cache to reduce memory consumption.

Signed-off-by: Yongqiang Yang <xiaoqiangnk@gmail.com>
---
 fs/jbd2/checkpoint.c  |    2 +-
 fs/jbd2/commit.c      |    2 +-
 fs/jbd2/journal.c     |    3 +++
 fs/jbd2/transaction.c |   36 +++++++++++++++++++++++++++++++++---
 include/linux/jbd2.h  |    5 +++++
 5 files changed, 43 insertions(+), 5 deletions(-)

diff --git a/fs/jbd2/checkpoint.c b/fs/jbd2/checkpoint.c
index 16a698b..7fcffbb 100644
--- a/fs/jbd2/checkpoint.c
+++ b/fs/jbd2/checkpoint.c
@@ -722,7 +722,7 @@ int __jbd2_journal_remove_checkpoint(struct journal_head *jh)
 				    transaction->t_tid, stats);
 
 	__jbd2_journal_drop_transaction(journal, transaction);
-	kfree(transaction);
+	jbd2_journal_free_transaction(transaction);
 
 	/* Just in case anybody was waiting for more transactions to be
            checkpointed... */
diff --git a/fs/jbd2/commit.c b/fs/jbd2/commit.c
index eef6979..264f0bb 100644
--- a/fs/jbd2/commit.c
+++ b/fs/jbd2/commit.c
@@ -1042,7 +1042,7 @@ restart_loop:
 	jbd_debug(1, "JBD: commit %d complete, head %d\n",
 		  journal->j_commit_sequence, journal->j_tail_sequence);
 	if (to_free)
-		kfree(commit_transaction);
+		jbd2_journal_free_transaction(commit_transaction);
 
 	wake_up(&journal->j_wait_done_commit);
 }
diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
index f24df13..56b8a1a 100644
--- a/fs/jbd2/journal.c
+++ b/fs/jbd2/journal.c
@@ -2351,6 +2351,8 @@ static int __init journal_init_caches(void)
 		ret = journal_init_jbd2_journal_head_cache();
 	if (ret == 0)
 		ret = journal_init_handle_cache();
+	if (ret == 0)
+		ret = jbd2_journal_init_transaction_cache();
 	return ret;
 }
 
@@ -2359,6 +2361,7 @@ static void jbd2_journal_destroy_caches(void)
 	jbd2_journal_destroy_revoke_caches();
 	jbd2_journal_destroy_jbd2_journal_head_cache();
 	jbd2_journal_destroy_handle_cache();
+	jbd2_journal_destroy_transaction_cache();
 	jbd2_journal_destroy_slabs();
 }
 
diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c
index 1e5c5ea..f394a13 100644
--- a/fs/jbd2/transaction.c
+++ b/fs/jbd2/transaction.c
@@ -33,6 +33,35 @@
 static void __jbd2_journal_temp_unlink_buffer(struct journal_head *jh);
 static void __jbd2_journal_unfile_buffer(struct journal_head *jh);
 
+static struct kmem_cache *transaction_cache;
+int __init jbd2_journal_init_transaction_cache(void)
+{
+	J_ASSERT(!transaction_cache);
+	transaction_cache = kmem_cache_create("jbd2_transaction_s",
+					sizeof(transaction_t),
+					0,
+					SLAB_HWCACHE_ALIGN|SLAB_TEMPORARY,
+					NULL);
+	if (transaction_cache)
+		return 0;
+	return -ENOMEM;
+}
+
+void jbd2_journal_destroy_transaction_cache(void)
+{
+	if (transaction_cache) {
+		kmem_cache_destroy(transaction_cache);
+		transaction_cache = NULL;
+	}
+}
+
+void jbd2_journal_free_transaction(transaction_t *transaction)
+{
+	if (unlikely(ZERO_OR_NULL_PTR(transaction)))
+		return;
+	kmem_cache_free(transaction_cache, transaction);
+}
+
 /*
  * jbd2_get_transaction: obtain a new transaction_t object.
  *
@@ -133,7 +162,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_mask);
+		new_transaction = kmem_cache_alloc(transaction_cache, gfp_mask);
 		if (!new_transaction) {
 			/*
 			 * If __GFP_FS is not present, then we may be
@@ -148,6 +177,7 @@ alloc_transaction:
 			}
 			return -ENOMEM;
 		}
+		memset(new_transaction, 0, sizeof(*new_transaction));
 	}
 
 	jbd_debug(3, "New handle %p going live.\n", handle);
@@ -162,7 +192,7 @@ repeat:
 	if (is_journal_aborted(journal) ||
 	    (journal->j_errno != 0 && !(journal->j_flags & JBD2_ACK_ERR))) {
 		read_unlock(&journal->j_state_lock);
-		kfree(new_transaction);
+		jbd2_journal_free_transaction(new_transaction);
 		return -EROFS;
 	}
 
@@ -284,7 +314,7 @@ repeat:
 	read_unlock(&journal->j_state_lock);
 
 	lock_map_acquire(&handle->h_lockdep_map);
-	kfree(new_transaction);
+	jbd2_journal_free_transaction(new_transaction);
 	return 0;
 }
 
diff --git a/include/linux/jbd2.h b/include/linux/jbd2.h
index 2092ea2..e44d114 100644
--- a/include/linux/jbd2.h
+++ b/include/linux/jbd2.h
@@ -1020,6 +1020,11 @@ jbd2_journal_write_metadata_buffer(transaction_t	  *transaction,
 /* Transaction locking */
 extern void		__wait_on_journal (journal_t *);
 
+/* Transaction cache support */
+extern void jbd2_journal_destroy_transaction_cache(void);
+extern int  jbd2_journal_init_transaction_cache(void);
+extern void jbd2_journal_free_transaction(transaction_t *);
+
 /*
  * Journal locking.
  *
-- 
1.7.5.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/3] jbd2: rename functions initializing caches
  2011-11-13 11:21 [PATCH 1/3] jbd2: allocate transaction from special cache Yongqiang Yang
@ 2011-11-13 11:21 ` Yongqiang Yang
  2012-02-13 22:10   ` Ted Ts'o
  2011-11-13 11:21 ` [PATCH 3/3] jbd2: use KMEM_CACHE instead of kmem_cache_create Yongqiang Yang
  2012-02-13 22:10 ` [PATCH 1/3] jbd2: allocate transaction from special cache Ted Ts'o
  2 siblings, 1 reply; 6+ messages in thread
From: Yongqiang Yang @ 2011-11-13 11:21 UTC (permalink / raw)
  To: tytso; +Cc: linux-ext4, Yongqiang Yang

This patch renames functions initializing caches to let them
be in accord with functions destroying caches.

Signed-off-by: Yongqiang Yang <xiaoqiangnk@gmail.com>
---
 fs/jbd2/journal.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
index 56b8a1a..a5e99c4 100644
--- a/fs/jbd2/journal.c
+++ b/fs/jbd2/journal.c
@@ -2007,7 +2007,7 @@ static struct kmem_cache *jbd2_journal_head_cache;
 static atomic_t nr_journal_heads = ATOMIC_INIT(0);
 #endif
 
-static int journal_init_jbd2_journal_head_cache(void)
+static int jbd2_journal_init_journal_head_cache(void)
 {
 	int retval;
 
@@ -2025,7 +2025,7 @@ static int journal_init_jbd2_journal_head_cache(void)
 	return retval;
 }
 
-static void jbd2_journal_destroy_jbd2_journal_head_cache(void)
+static void jbd2_journal_destroy_journal_head_cache(void)
 {
 	if (jbd2_journal_head_cache) {
 		kmem_cache_destroy(jbd2_journal_head_cache);
@@ -2313,7 +2313,7 @@ static void __exit jbd2_remove_jbd_stats_proc_entry(void)
 
 struct kmem_cache *jbd2_handle_cache, *jbd2_inode_cache;
 
-static int __init journal_init_handle_cache(void)
+static int __init jbd2_journal_init_handle_cache(void)
 {
 	jbd2_handle_cache = KMEM_CACHE(jbd2_journal_handle, SLAB_TEMPORARY);
 	if (jbd2_handle_cache == NULL) {
@@ -2348,9 +2348,9 @@ static int __init journal_init_caches(void)
 
 	ret = jbd2_journal_init_revoke_caches();
 	if (ret == 0)
-		ret = journal_init_jbd2_journal_head_cache();
+		ret = jbd2_journal_init_journal_head_cache();
 	if (ret == 0)
-		ret = journal_init_handle_cache();
+		ret = jbd2_journal_init_handle_cache();
 	if (ret == 0)
 		ret = jbd2_journal_init_transaction_cache();
 	return ret;
@@ -2359,7 +2359,7 @@ static int __init journal_init_caches(void)
 static void jbd2_journal_destroy_caches(void)
 {
 	jbd2_journal_destroy_revoke_caches();
-	jbd2_journal_destroy_jbd2_journal_head_cache();
+	jbd2_journal_destroy_journal_head_cache();
 	jbd2_journal_destroy_handle_cache();
 	jbd2_journal_destroy_transaction_cache();
 	jbd2_journal_destroy_slabs();
-- 
1.7.5.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/3] jbd2: use KMEM_CACHE instead of kmem_cache_create
  2011-11-13 11:21 [PATCH 1/3] jbd2: allocate transaction from special cache Yongqiang Yang
  2011-11-13 11:21 ` [PATCH 2/3] jbd2: rename functions initializing caches Yongqiang Yang
@ 2011-11-13 11:21 ` Yongqiang Yang
  2012-02-13 22:10   ` Ted Ts'o
  2012-02-13 22:10 ` [PATCH 1/3] jbd2: allocate transaction from special cache Ted Ts'o
  2 siblings, 1 reply; 6+ messages in thread
From: Yongqiang Yang @ 2011-11-13 11:21 UTC (permalink / raw)
  To: tytso; +Cc: linux-ext4, Yongqiang Yang

This patch lets jbd2 use KMEM_CACHE instead of kmem_cache_create.

Signed-off-by: Yongqiang Yang <xiaoqiangnk@gmail.com>
---
 fs/jbd2/revoke.c |   12 ++++--------
 1 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/fs/jbd2/revoke.c b/fs/jbd2/revoke.c
index 69fd935..1b67105 100644
--- a/fs/jbd2/revoke.c
+++ b/fs/jbd2/revoke.c
@@ -204,17 +204,13 @@ int __init jbd2_journal_init_revoke_caches(void)
 	J_ASSERT(!jbd2_revoke_record_cache);
 	J_ASSERT(!jbd2_revoke_table_cache);
 
-	jbd2_revoke_record_cache = kmem_cache_create("jbd2_revoke_record",
-					   sizeof(struct jbd2_revoke_record_s),
-					   0,
-					   SLAB_HWCACHE_ALIGN|SLAB_TEMPORARY,
-					   NULL);
+	jbd2_revoke_record_cache = KMEM_CACHE(jbd2_revoke_record_s,
+					SLAB_HWCACHE_ALIGN|SLAB_TEMPORARY);
 	if (!jbd2_revoke_record_cache)
 		goto record_cache_failure;
 
-	jbd2_revoke_table_cache = kmem_cache_create("jbd2_revoke_table",
-					   sizeof(struct jbd2_revoke_table_s),
-					   0, SLAB_TEMPORARY, NULL);
+	jbd2_revoke_table_cache = KMEM_CACHE(jbd2_revoke_table_s,
+					     SLAB_TEMPORARY);
 	if (!jbd2_revoke_table_cache)
 		goto table_cache_failure;
 	return 0;
-- 
1.7.5.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/3] jbd2: allocate transaction from special cache
  2011-11-13 11:21 [PATCH 1/3] jbd2: allocate transaction from special cache Yongqiang Yang
  2011-11-13 11:21 ` [PATCH 2/3] jbd2: rename functions initializing caches Yongqiang Yang
  2011-11-13 11:21 ` [PATCH 3/3] jbd2: use KMEM_CACHE instead of kmem_cache_create Yongqiang Yang
@ 2012-02-13 22:10 ` Ted Ts'o
  2 siblings, 0 replies; 6+ messages in thread
From: Ted Ts'o @ 2012-02-13 22:10 UTC (permalink / raw)
  To: Yongqiang Yang; +Cc: linux-ext4, Manish Katiyar

On Sun, Nov 13, 2011 at 07:21:29PM +0800, Yongqiang Yang wrote:
> transaction_t is 136 byes under 32-bit systems. If we allocate
> it from general cache, it comsumes 256 bytes.  So let jbd2 allocate
> it from special cache to reduce memory consumption.
> 
> Signed-off-by: Yongqiang Yang <xiaoqiangnk@gmail.com>

Thanks, applied with a modified description:

    jbd2: allocate transaction from separate slab cache
    
    There is normally only a handful of these active at any one time, but
    putting them in a separate slab cache makes debugging memory
    corruption problems easier.  Manish Katiyar also wanted this make it
    easier to test memory failure scenarios in the jbd2 layer.

    	      	   	  	  	       - Ted

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/3] jbd2: rename functions initializing caches
  2011-11-13 11:21 ` [PATCH 2/3] jbd2: rename functions initializing caches Yongqiang Yang
@ 2012-02-13 22:10   ` Ted Ts'o
  0 siblings, 0 replies; 6+ messages in thread
From: Ted Ts'o @ 2012-02-13 22:10 UTC (permalink / raw)
  To: Yongqiang Yang; +Cc: linux-ext4

On Sun, Nov 13, 2011 at 07:21:30PM +0800, Yongqiang Yang wrote:
> This patch renames functions initializing caches to let them
> be in accord with functions destroying caches.
> 
> Signed-off-by: Yongqiang Yang <xiaoqiangnk@gmail.com>

Thanks, applied.

					- Ted

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 3/3] jbd2: use KMEM_CACHE instead of kmem_cache_create
  2011-11-13 11:21 ` [PATCH 3/3] jbd2: use KMEM_CACHE instead of kmem_cache_create Yongqiang Yang
@ 2012-02-13 22:10   ` Ted Ts'o
  0 siblings, 0 replies; 6+ messages in thread
From: Ted Ts'o @ 2012-02-13 22:10 UTC (permalink / raw)
  To: Yongqiang Yang; +Cc: linux-ext4

On Sun, Nov 13, 2011 at 07:21:31PM +0800, Yongqiang Yang wrote:
> This patch lets jbd2 use KMEM_CACHE instead of kmem_cache_create.
> 
> Signed-off-by: Yongqiang Yang <xiaoqiangnk@gmail.com>

Thanks, applied.

					- Ted

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-02-13 22:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-13 11:21 [PATCH 1/3] jbd2: allocate transaction from special cache Yongqiang Yang
2011-11-13 11:21 ` [PATCH 2/3] jbd2: rename functions initializing caches Yongqiang Yang
2012-02-13 22:10   ` Ted Ts'o
2011-11-13 11:21 ` [PATCH 3/3] jbd2: use KMEM_CACHE instead of kmem_cache_create Yongqiang Yang
2012-02-13 22:10   ` Ted Ts'o
2012-02-13 22:10 ` [PATCH 1/3] jbd2: allocate transaction from special cache Ted Ts'o

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).