aboutsummaryrefslogtreecommitdiffstats
path: root/fs/jbd2/journal.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/jbd2/journal.c')
-rw-r--r--fs/jbd2/journal.c128
1 files changed, 15 insertions, 113 deletions
diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
index f37324aee817..6ddc5531587c 100644
--- a/fs/jbd2/journal.c
+++ b/fs/jbd2/journal.c
@@ -84,7 +84,6 @@ EXPORT_SYMBOL(jbd2_journal_force_commit);
84 84
85static int journal_convert_superblock_v1(journal_t *, journal_superblock_t *); 85static int journal_convert_superblock_v1(journal_t *, journal_superblock_t *);
86static void __journal_abort_soft (journal_t *journal, int errno); 86static void __journal_abort_soft (journal_t *journal, int errno);
87static int jbd2_journal_create_jbd_slab(size_t slab_size);
88 87
89/* 88/*
90 * Helper function used to manage commit timeouts 89 * Helper function used to manage commit timeouts
@@ -335,10 +334,10 @@ repeat:
335 char *tmp; 334 char *tmp;
336 335
337 jbd_unlock_bh_state(bh_in); 336 jbd_unlock_bh_state(bh_in);
338 tmp = jbd2_slab_alloc(bh_in->b_size, GFP_NOFS); 337 tmp = jbd2_alloc(bh_in->b_size, GFP_NOFS);
339 jbd_lock_bh_state(bh_in); 338 jbd_lock_bh_state(bh_in);
340 if (jh_in->b_frozen_data) { 339 if (jh_in->b_frozen_data) {
341 jbd2_slab_free(tmp, bh_in->b_size); 340 jbd2_free(tmp, bh_in->b_size);
342 goto repeat; 341 goto repeat;
343 } 342 }
344 343
@@ -655,10 +654,9 @@ static journal_t * journal_init_common (void)
655 journal_t *journal; 654 journal_t *journal;
656 int err; 655 int err;
657 656
658 journal = jbd_kmalloc(sizeof(*journal), GFP_KERNEL); 657 journal = kzalloc(sizeof(*journal), GFP_KERNEL|__GFP_NOFAIL);
659 if (!journal) 658 if (!journal)
660 goto fail; 659 goto fail;
661 memset(journal, 0, sizeof(*journal));
662 660
663 init_waitqueue_head(&journal->j_wait_transaction_locked); 661 init_waitqueue_head(&journal->j_wait_transaction_locked);
664 init_waitqueue_head(&journal->j_wait_logspace); 662 init_waitqueue_head(&journal->j_wait_logspace);
@@ -672,7 +670,7 @@ static journal_t * journal_init_common (void)
672 spin_lock_init(&journal->j_list_lock); 670 spin_lock_init(&journal->j_list_lock);
673 spin_lock_init(&journal->j_state_lock); 671 spin_lock_init(&journal->j_state_lock);
674 672
675 journal->j_commit_interval = (HZ * JBD_DEFAULT_MAX_COMMIT_AGE); 673 journal->j_commit_interval = (HZ * JBD2_DEFAULT_MAX_COMMIT_AGE);
676 674
677 /* The journal is marked for error until we succeed with recovery! */ 675 /* The journal is marked for error until we succeed with recovery! */
678 journal->j_flags = JBD2_ABORT; 676 journal->j_flags = JBD2_ABORT;
@@ -1096,13 +1094,6 @@ int jbd2_journal_load(journal_t *journal)
1096 } 1094 }
1097 } 1095 }
1098 1096
1099 /*
1100 * Create a slab for this blocksize
1101 */
1102 err = jbd2_journal_create_jbd_slab(be32_to_cpu(sb->s_blocksize));
1103 if (err)
1104 return err;
1105
1106 /* Let the recovery code check whether it needs to recover any 1097 /* Let the recovery code check whether it needs to recover any
1107 * data from the journal. */ 1098 * data from the journal. */
1108 if (jbd2_journal_recover(journal)) 1099 if (jbd2_journal_recover(journal))
@@ -1621,89 +1612,9 @@ int jbd2_journal_blocks_per_page(struct inode *inode)
1621size_t journal_tag_bytes(journal_t *journal) 1612size_t journal_tag_bytes(journal_t *journal)
1622{ 1613{
1623 if (JBD2_HAS_INCOMPAT_FEATURE(journal, JBD2_FEATURE_INCOMPAT_64BIT)) 1614 if (JBD2_HAS_INCOMPAT_FEATURE(journal, JBD2_FEATURE_INCOMPAT_64BIT))
1624 return JBD_TAG_SIZE64; 1615 return JBD2_TAG_SIZE64;
1625 else 1616 else
1626 return JBD_TAG_SIZE32; 1617 return JBD2_TAG_SIZE32;
1627}
1628
1629/*
1630 * Simple support for retrying memory allocations. Introduced to help to
1631 * debug different VM deadlock avoidance strategies.
1632 */
1633void * __jbd2_kmalloc (const char *where, size_t size, gfp_t flags, int retry)
1634{
1635 return kmalloc(size, flags | (retry ? __GFP_NOFAIL : 0));
1636}
1637
1638/*
1639 * jbd slab management: create 1k, 2k, 4k, 8k slabs as needed
1640 * and allocate frozen and commit buffers from these slabs.
1641 *
1642 * Reason for doing this is to avoid, SLAB_DEBUG - since it could
1643 * cause bh to cross page boundary.
1644 */
1645
1646#define JBD_MAX_SLABS 5
1647#define JBD_SLAB_INDEX(size) (size >> 11)
1648
1649static struct kmem_cache *jbd_slab[JBD_MAX_SLABS];
1650static const char *jbd_slab_names[JBD_MAX_SLABS] = {
1651 "jbd2_1k", "jbd2_2k", "jbd2_4k", NULL, "jbd2_8k"
1652};
1653
1654static void jbd2_journal_destroy_jbd_slabs(void)
1655{
1656 int i;
1657
1658 for (i = 0; i < JBD_MAX_SLABS; i++) {
1659 if (jbd_slab[i])
1660 kmem_cache_destroy(jbd_slab[i]);
1661 jbd_slab[i] = NULL;
1662 }
1663}
1664
1665static int jbd2_journal_create_jbd_slab(size_t slab_size)
1666{
1667 int i = JBD_SLAB_INDEX(slab_size);
1668
1669 BUG_ON(i >= JBD_MAX_SLABS);
1670
1671 /*
1672 * Check if we already have a slab created for this size
1673 */
1674 if (jbd_slab[i])
1675 return 0;
1676
1677 /*
1678 * Create a slab and force alignment to be same as slabsize -
1679 * this will make sure that allocations won't cross the page
1680 * boundary.
1681 */
1682 jbd_slab[i] = kmem_cache_create(jbd_slab_names[i],
1683 slab_size, slab_size, 0, NULL);
1684 if (!jbd_slab[i]) {
1685 printk(KERN_EMERG "JBD: no memory for jbd_slab cache\n");
1686 return -ENOMEM;
1687 }
1688 return 0;
1689}
1690
1691void * jbd2_slab_alloc(size_t size, gfp_t flags)
1692{
1693 int idx;
1694
1695 idx = JBD_SLAB_INDEX(size);
1696 BUG_ON(jbd_slab[idx] == NULL);
1697 return kmem_cache_alloc(jbd_slab[idx], flags | __GFP_NOFAIL);
1698}
1699
1700void jbd2_slab_free(void *ptr, size_t size)
1701{
1702 int idx;
1703
1704 idx = JBD_SLAB_INDEX(size);
1705 BUG_ON(jbd_slab[idx] == NULL);
1706 kmem_cache_free(jbd_slab[idx], ptr);
1707} 1618}
1708 1619
1709/* 1620/*
@@ -1770,7 +1681,7 @@ static void journal_free_journal_head(struct journal_head *jh)
1770{ 1681{
1771#ifdef CONFIG_JBD2_DEBUG 1682#ifdef CONFIG_JBD2_DEBUG
1772 atomic_dec(&nr_journal_heads); 1683 atomic_dec(&nr_journal_heads);
1773 memset(jh, JBD_POISON_FREE, sizeof(*jh)); 1684 memset(jh, JBD2_POISON_FREE, sizeof(*jh));
1774#endif 1685#endif
1775 kmem_cache_free(jbd2_journal_head_cache, jh); 1686 kmem_cache_free(jbd2_journal_head_cache, jh);
1776} 1687}
@@ -1893,13 +1804,13 @@ static void __journal_remove_journal_head(struct buffer_head *bh)
1893 printk(KERN_WARNING "%s: freeing " 1804 printk(KERN_WARNING "%s: freeing "
1894 "b_frozen_data\n", 1805 "b_frozen_data\n",
1895 __FUNCTION__); 1806 __FUNCTION__);
1896 jbd2_slab_free(jh->b_frozen_data, bh->b_size); 1807 jbd2_free(jh->b_frozen_data, bh->b_size);
1897 } 1808 }
1898 if (jh->b_committed_data) { 1809 if (jh->b_committed_data) {
1899 printk(KERN_WARNING "%s: freeing " 1810 printk(KERN_WARNING "%s: freeing "
1900 "b_committed_data\n", 1811 "b_committed_data\n",
1901 __FUNCTION__); 1812 __FUNCTION__);
1902 jbd2_slab_free(jh->b_committed_data, bh->b_size); 1813 jbd2_free(jh->b_committed_data, bh->b_size);
1903 } 1814 }
1904 bh->b_private = NULL; 1815 bh->b_private = NULL;
1905 jh->b_bh = NULL; /* debug, really */ 1816 jh->b_bh = NULL; /* debug, really */
@@ -1953,16 +1864,14 @@ void jbd2_journal_put_journal_head(struct journal_head *jh)
1953/* 1864/*
1954 * debugfs tunables 1865 * debugfs tunables
1955 */ 1866 */
1956#if defined(CONFIG_JBD2_DEBUG) 1867#ifdef CONFIG_JBD2_DEBUG
1957u8 jbd2_journal_enable_debug; 1868u8 jbd2_journal_enable_debug __read_mostly;
1958EXPORT_SYMBOL(jbd2_journal_enable_debug); 1869EXPORT_SYMBOL(jbd2_journal_enable_debug);
1959#endif
1960
1961#if defined(CONFIG_JBD2_DEBUG) && defined(CONFIG_DEBUG_FS)
1962 1870
1963#define JBD2_DEBUG_NAME "jbd2-debug" 1871#define JBD2_DEBUG_NAME "jbd2-debug"
1964 1872
1965struct dentry *jbd2_debugfs_dir, *jbd2_debug; 1873static struct dentry *jbd2_debugfs_dir;
1874static struct dentry *jbd2_debug;
1966 1875
1967static void __init jbd2_create_debugfs_entry(void) 1876static void __init jbd2_create_debugfs_entry(void)
1968{ 1877{
@@ -1975,24 +1884,18 @@ static void __init jbd2_create_debugfs_entry(void)
1975 1884
1976static void __exit jbd2_remove_debugfs_entry(void) 1885static void __exit jbd2_remove_debugfs_entry(void)
1977{ 1886{
1978 if (jbd2_debug) 1887 debugfs_remove(jbd2_debug);
1979 debugfs_remove(jbd2_debug); 1888 debugfs_remove(jbd2_debugfs_dir);
1980 if (jbd2_debugfs_dir)
1981 debugfs_remove(jbd2_debugfs_dir);
1982} 1889}
1983 1890
1984#else 1891#else
1985 1892
1986static void __init jbd2_create_debugfs_entry(void) 1893static void __init jbd2_create_debugfs_entry(void)
1987{ 1894{
1988 do {
1989 } while (0);
1990} 1895}
1991 1896
1992static void __exit jbd2_remove_debugfs_entry(void) 1897static void __exit jbd2_remove_debugfs_entry(void)
1993{ 1898{
1994 do {
1995 } while (0);
1996} 1899}
1997 1900
1998#endif 1901#endif
@@ -2040,7 +1943,6 @@ static void jbd2_journal_destroy_caches(void)
2040 jbd2_journal_destroy_revoke_caches(); 1943 jbd2_journal_destroy_revoke_caches();
2041 jbd2_journal_destroy_jbd2_journal_head_cache(); 1944 jbd2_journal_destroy_jbd2_journal_head_cache();
2042 jbd2_journal_destroy_handle_cache(); 1945 jbd2_journal_destroy_handle_cache();
2043 jbd2_journal_destroy_jbd_slabs();
2044} 1946}
2045 1947
2046static int __init journal_init(void) 1948static int __init journal_init(void)