journal.c (fcf37549ae19e904bc6a5eadf5c25eca36100c5e) journal.c (4ba3fcdde7e36af93610ceb3cc38365b14539865)
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * linux/fs/jbd2/journal.c
4 *
5 * Written by Stephen C. Tweedie <sct@redhat.com>, 1998
6 *
7 * Copyright 1998 Red Hat corp --- All Rights Reserved
8 *

--- 2037 unchanged lines hidden (view full) ---

2046 return 0;
2047
2048recovery_error:
2049 printk(KERN_WARNING "JBD2: recovery failed\n");
2050 return -EIO;
2051}
2052
2053/**
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * linux/fs/jbd2/journal.c
4 *
5 * Written by Stephen C. Tweedie <sct@redhat.com>, 1998
6 *
7 * Copyright 1998 Red Hat corp --- All Rights Reserved
8 *

--- 2037 unchanged lines hidden (view full) ---

2046 return 0;
2047
2048recovery_error:
2049 printk(KERN_WARNING "JBD2: recovery failed\n");
2050 return -EIO;
2051}
2052
2053/**
2054 * jbd2_journal_shrink_scan()
2055 *
2056 * Scan the checkpointed buffer on the checkpoint list and release the
2057 * journal_head.
2058 */
2059static unsigned long jbd2_journal_shrink_scan(struct shrinker *shrink,
2060 struct shrink_control *sc)
2061{
2062 journal_t *journal = container_of(shrink, journal_t, j_shrinker);
2063 unsigned long nr_to_scan = sc->nr_to_scan;
2064 unsigned long nr_shrunk;
2065 unsigned long count;
2066
2067 count = percpu_counter_read_positive(&journal->j_jh_shrink_count);
2068 trace_jbd2_shrink_scan_enter(journal, sc->nr_to_scan, count);
2069
2070 nr_shrunk = jbd2_journal_shrink_checkpoint_list(journal, &nr_to_scan);
2071
2072 count = percpu_counter_read_positive(&journal->j_jh_shrink_count);
2073 trace_jbd2_shrink_scan_exit(journal, nr_to_scan, nr_shrunk, count);
2074
2075 return nr_shrunk;
2076}
2077
2078/**
2079 * jbd2_journal_shrink_count()
2080 *
2081 * Count the number of checkpoint buffers on the checkpoint list.
2082 */
2083static unsigned long jbd2_journal_shrink_count(struct shrinker *shrink,
2084 struct shrink_control *sc)
2085{
2086 journal_t *journal = container_of(shrink, journal_t, j_shrinker);
2087 unsigned long count;
2088
2089 count = percpu_counter_read_positive(&journal->j_jh_shrink_count);
2090 trace_jbd2_shrink_count(journal, sc->nr_to_scan, count);
2091
2092 return count;
2093}
2094
2095/**
2096 * jbd2_journal_register_shrinker()
2097 * @journal: Journal to act on.
2098 *
2099 * Init a percpu counter to record the checkpointed buffers on the checkpoint
2100 * list and register a shrinker to release their journal_head.
2101 */
2102int jbd2_journal_register_shrinker(journal_t *journal)
2103{
2104 int err;
2105
2106 journal->j_shrink_transaction = NULL;
2107
2108 err = percpu_counter_init(&journal->j_jh_shrink_count, 0, GFP_KERNEL);
2109 if (err)
2110 return err;
2111
2112 journal->j_shrinker.scan_objects = jbd2_journal_shrink_scan;
2113 journal->j_shrinker.count_objects = jbd2_journal_shrink_count;
2114 journal->j_shrinker.seeks = DEFAULT_SEEKS;
2115 journal->j_shrinker.batch = journal->j_max_transaction_buffers;
2116
2117 err = register_shrinker(&journal->j_shrinker);
2118 if (err) {
2119 percpu_counter_destroy(&journal->j_jh_shrink_count);
2120 return err;
2121 }
2122
2123 return 0;
2124}
2125
2126/**
2127 * jbd2_journal_unregister_shrinker()
2128 * @journal: Journal to act on.
2129 *
2130 * Unregister the checkpointed buffer shrinker and destroy the percpu counter.
2131 */
2132void jbd2_journal_unregister_shrinker(journal_t *journal)
2133{
2134 percpu_counter_destroy(&journal->j_jh_shrink_count);
2135 unregister_shrinker(&journal->j_shrinker);
2136}
2137
2138/**
2054 * jbd2_journal_destroy() - Release a journal_t structure.
2055 * @journal: Journal to act on.
2056 *
2057 * Release a journal_t structure once it is no longer in use by the
2058 * journaled object.
2059 * Return <0 if we couldn't clean up the journal.
2060 */
2061int jbd2_journal_destroy(journal_t *journal)

--- 55 unchanged lines hidden (view full) ---

2117 jbd2_mark_journal_empty(journal,
2118 REQ_SYNC | REQ_PREFLUSH | REQ_FUA);
2119 mutex_unlock(&journal->j_checkpoint_mutex);
2120 } else
2121 err = -EIO;
2122 brelse(journal->j_sb_buffer);
2123 }
2124
2139 * jbd2_journal_destroy() - Release a journal_t structure.
2140 * @journal: Journal to act on.
2141 *
2142 * Release a journal_t structure once it is no longer in use by the
2143 * journaled object.
2144 * Return <0 if we couldn't clean up the journal.
2145 */
2146int jbd2_journal_destroy(journal_t *journal)

--- 55 unchanged lines hidden (view full) ---

2202 jbd2_mark_journal_empty(journal,
2203 REQ_SYNC | REQ_PREFLUSH | REQ_FUA);
2204 mutex_unlock(&journal->j_checkpoint_mutex);
2205 } else
2206 err = -EIO;
2207 brelse(journal->j_sb_buffer);
2208 }
2209
2210 jbd2_journal_unregister_shrinker(journal);
2211
2125 if (journal->j_proc_entry)
2126 jbd2_stats_proc_exit(journal);
2127 iput(journal->j_inode);
2128 if (journal->j_revoke)
2129 jbd2_journal_destroy_revoke(journal);
2130 if (journal->j_chksum_driver)
2131 crypto_free_shash(journal->j_chksum_driver);
2132 kfree(journal->j_fc_wbuf);

--- 1000 unchanged lines hidden ---
2212 if (journal->j_proc_entry)
2213 jbd2_stats_proc_exit(journal);
2214 iput(journal->j_inode);
2215 if (journal->j_revoke)
2216 jbd2_journal_destroy_revoke(journal);
2217 if (journal->j_chksum_driver)
2218 crypto_free_shash(journal->j_chksum_driver);
2219 kfree(journal->j_fc_wbuf);

--- 1000 unchanged lines hidden ---