From: Akinobu Mita <mita@miraclelinux.com>
To: linux-kernel@vger.kernel.org
Cc: sct@redhat.com, akpm@osdl.org, adilger@clusterfs.com,
ext3-users@redhat.com
Subject: [PATCH 3/6] jbd: cleanup for initializing/destroying the revoke tables
Date: Fri, 9 Sep 2005 17:46:00 +0900 [thread overview]
Message-ID: <20050909084600.GE14205@miraclelinux.com> (raw)
In-Reply-To: <20050909084214.GB14205@miraclelinux.com>
use loop counter for initializing/destroying a pair of the revoke tables.
Signed-off-by: Akinobu Mita <mita@miraclelinux.com>
---
revoke.c | 116 ++++++++++++++++++++++-----------------------------------------
1 files changed, 42 insertions(+), 74 deletions(-)
diff -X 2.6.13-mm1/Documentation/dontdiff -Nurp 2.6.13-mm1.old/fs/jbd/revoke.c 2.6.13-mm1/fs/jbd/revoke.c
--- 2.6.13-mm1.old/fs/jbd/revoke.c 2005-09-05 03:21:00.000000000 +0900
+++ 2.6.13-mm1/fs/jbd/revoke.c 2005-09-05 11:16:04.000000000 +0900
@@ -193,108 +193,76 @@ void journal_destroy_revoke_caches(void)
int journal_init_revoke(journal_t *journal, int hash_size)
{
- int shift, tmp;
+ int shift = 0;
+ int tmp = hash_size;
+ int i;
+ /* Check that the hash_size is a power of two */
+ J_ASSERT ((hash_size & (hash_size-1)) == 0);
J_ASSERT (journal->j_revoke_table[0] == NULL);
- shift = 0;
- tmp = hash_size;
- while((tmp >>= 1UL) != 0UL)
+ while ((tmp >>= 1UL) != 0UL)
shift++;
- journal->j_revoke_table[0] = kmem_cache_alloc(revoke_table_cache, GFP_KERNEL);
- if (!journal->j_revoke_table[0])
- return -ENOMEM;
- journal->j_revoke = journal->j_revoke_table[0];
-
- /* Check that the hash_size is a power of two */
- J_ASSERT ((hash_size & (hash_size-1)) == 0);
+ for (i = 0; i < 2; i++) {
+ struct jbd_revoke_table_s *table;
- journal->j_revoke->hash_size = hash_size;
+ table = kmem_cache_alloc(revoke_table_cache, GFP_KERNEL);
+ if (!table)
+ goto nomem;
+
+ table->hash_size = hash_size;
+ table->hash_shift = shift;
+ table->hash_table = kmalloc(hash_size * sizeof(struct hlist_head), GFP_KERNEL);
+ if (!table->hash_table) {
+ kmem_cache_free(revoke_table_cache, table);
+ goto nomem;
+ }
- journal->j_revoke->hash_shift = shift;
+ for (tmp = 0; tmp < hash_size; tmp++)
+ INIT_HLIST_HEAD(&table->hash_table[tmp]);
- journal->j_revoke->hash_table =
- kmalloc(hash_size * sizeof(struct hlist_head), GFP_KERNEL);
- if (!journal->j_revoke->hash_table) {
- kmem_cache_free(revoke_table_cache, journal->j_revoke_table[0]);
- journal->j_revoke = NULL;
- return -ENOMEM;
- }
-
- for (tmp = 0; tmp < hash_size; tmp++)
- INIT_HLIST_HEAD(&journal->j_revoke->hash_table[tmp]);
-
- journal->j_revoke_table[1] = kmem_cache_alloc(revoke_table_cache, GFP_KERNEL);
- if (!journal->j_revoke_table[1]) {
- kfree(journal->j_revoke_table[0]->hash_table);
- kmem_cache_free(revoke_table_cache, journal->j_revoke_table[0]);
- return -ENOMEM;
+ journal->j_revoke_table[i] = table;
}
-
journal->j_revoke = journal->j_revoke_table[1];
+ spin_lock_init(&journal->j_revoke_lock);
- /* Check that the hash_size is a power of two */
- J_ASSERT ((hash_size & (hash_size-1)) == 0);
-
- journal->j_revoke->hash_size = hash_size;
-
- journal->j_revoke->hash_shift = shift;
+ return 0;
- journal->j_revoke->hash_table =
- kmalloc(hash_size * sizeof(struct hlist_head), GFP_KERNEL);
- if (!journal->j_revoke->hash_table) {
- kfree(journal->j_revoke_table[0]->hash_table);
- kmem_cache_free(revoke_table_cache, journal->j_revoke_table[0]);
- kmem_cache_free(revoke_table_cache, journal->j_revoke_table[1]);
- journal->j_revoke = NULL;
- return -ENOMEM;
+nomem:
+ while (i--) {
+ kfree(journal->j_revoke_table[i]->hash_table);
+ kmem_cache_free(revoke_table_cache, journal->j_revoke_table[i]);
}
- for (tmp = 0; tmp < hash_size; tmp++)
- INIT_HLIST_HEAD(&journal->j_revoke->hash_table[tmp]);
-
- spin_lock_init(&journal->j_revoke_lock);
-
- return 0;
+ return -ENOMEM;
}
/* Destoy a journal's revoke table. The table must already be empty! */
void journal_destroy_revoke(journal_t *journal)
{
- struct jbd_revoke_table_s *table;
- struct hlist_head *hash_list;
- int i;
+ int j;
- table = journal->j_revoke_table[0];
- if (!table)
- return;
+ journal->j_revoke = NULL;
- for (i=0; i<table->hash_size; i++) {
- hash_list = &table->hash_table[i];
- J_ASSERT (hlist_empty(hash_list));
- }
+ for (j = 0; j < 2; j++) {
+ int i;
+ struct jbd_revoke_table_s *table = journal->j_revoke_table[j];
- kfree(table->hash_table);
- kmem_cache_free(revoke_table_cache, table);
- journal->j_revoke = NULL;
+ if (!table)
+ return;
- table = journal->j_revoke_table[1];
- if (!table)
- return;
+ for (i = 0; i < table->hash_size; i++) {
+ struct hlist_head *hash_list = &table->hash_table[i];
+ J_ASSERT (hlist_empty(hash_list));
+ }
- for (i=0; i<table->hash_size; i++) {
- hash_list = &table->hash_table[i];
- J_ASSERT (hlist_empty(hash_list));
+ kfree(table->hash_table);
+ kmem_cache_free(revoke_table_cache, table);
}
-
- kfree(table->hash_table);
- kmem_cache_free(revoke_table_cache, table);
- journal->j_revoke = NULL;
}
-
#ifdef __KERNEL__
/*
next prev parent reply other threads:[~2005-09-09 8:49 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-09-09 8:42 [PATCH 0/6] jbd cleanup Akinobu Mita
2005-09-09 8:43 ` [PATCH 1/6] jbd: remove duplicated debug print Akinobu Mita
2005-09-09 18:16 ` Theodore Ts'o
2005-09-10 14:36 ` Akinobu Mita
2005-09-09 8:44 ` [PATCH 2/6] jbd: use hlist for the revoke tables Akinobu Mita
2005-09-09 8:46 ` Akinobu Mita [this message]
2005-09-09 8:47 ` [PATCH 4/6] jbd: use list_head for the list of buffers on a transaction's data Akinobu Mita
2005-09-09 8:48 ` [-mm PATCH 5/6] jbd: use list_head for the list of all transactions waiting for Akinobu Mita
2005-09-09 8:50 ` [-mm PATCH 6/6] jbd: use list_head for a transaction checkpoint list Akinobu Mita
2005-09-09 9:15 ` [PATCH 0/6] jbd cleanup Andrew Morton
2005-09-10 14:55 ` Akinobu Mita
2005-09-10 21:58 ` Andrew Morton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20050909084600.GE14205@miraclelinux.com \
--to=mita@miraclelinux.com \
--cc=adilger@clusterfs.com \
--cc=akpm@osdl.org \
--cc=ext3-users@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=sct@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.