]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/journal_reclaim.c
Update bcachefs sources to 9b3aa5ec6c bcachefs: Add tabstops to printbufs
[bcachefs-tools-debian] / libbcachefs / journal_reclaim.c
index 7a0ae5d3431c0aa29e7e075e6628b64365a4916f..9467191e182e6ff2e09625b54a2be11d8251630f 100644 (file)
@@ -34,8 +34,10 @@ unsigned bch2_journal_dev_buckets_available(struct journal *j,
                                            struct journal_device *ja,
                                            enum journal_space_from from)
 {
-       unsigned available = (journal_space_from(ja, from) -
-                             ja->cur_idx - 1 + ja->nr) % ja->nr;
+       unsigned available = !test_bit(JOURNAL_NOCHANGES, &j->flags)
+               ? ((journal_space_from(ja, from) -
+                   ja->cur_idx - 1 + ja->nr) % ja->nr)
+               : ja->nr;
 
        /*
         * Don't use the last bucket unless writing the new last_seq
@@ -284,7 +286,8 @@ void bch2_journal_do_discards(struct journal *j)
                struct journal_device *ja = &ca->journal;
 
                while (should_discard_bucket(j, ja)) {
-                       if (ca->mi.discard &&
+                       if (!c->opts.nochanges &&
+                           ca->mi.discard &&
                            blk_queue_discard(bdev_get_queue(ca->disk_sb.bdev)))
                                blkdev_issue_discard(ca->disk_sb.bdev,
                                        bucket_to_sector(ca,
@@ -487,9 +490,6 @@ static size_t journal_flush_pins(struct journal *j, u64 seq_to_flush,
        u64 seq;
        int err;
 
-       if (!test_bit(JOURNAL_RECLAIM_STARTED, &j->flags))
-               return 0;
-
        lockdep_assert_held(&j->reclaim_lock);
 
        while (1) {
@@ -635,7 +635,7 @@ static int __bch2_journal_reclaim(struct journal *j, bool direct)
                 * make sure to flush at least one journal pin:
                 */
                if (time_after(jiffies, j->last_flushed +
-                              msecs_to_jiffies(j->reclaim_delay_ms)))
+                              msecs_to_jiffies(c->opts.journal_reclaim_delay)))
                        min_nr = 1;
 
                if (j->prereserved.reserved * 4 > j->prereserved.remaining)
@@ -644,6 +644,9 @@ static int __bch2_journal_reclaim(struct journal *j, bool direct)
                if (fifo_free(&j->pin) <= 32)
                        min_nr = 1;
 
+               if (atomic_read(&c->btree_cache.dirty) * 2 > c->btree_cache.used)
+                       min_nr = 1;
+
                trace_journal_reclaim_start(c,
                                min_nr,
                                j->prereserved.reserved,
@@ -653,7 +656,7 @@ static int __bch2_journal_reclaim(struct journal *j, bool direct)
                                atomic_long_read(&c->btree_key_cache.nr_dirty),
                                atomic_long_read(&c->btree_key_cache.nr_keys));
 
-               min_key_cache = min(bch2_nr_btree_keys_need_flush(c), 128UL);
+               min_key_cache = min(bch2_nr_btree_keys_need_flush(c), (size_t) 128);
 
                nr_flushed = journal_flush_pins(j, seq_to_flush,
                                                min_nr, min_key_cache);
@@ -681,13 +684,12 @@ int bch2_journal_reclaim(struct journal *j)
 static int bch2_journal_reclaim_thread(void *arg)
 {
        struct journal *j = arg;
+       struct bch_fs *c = container_of(j, struct bch_fs, journal);
        unsigned long delay, now;
        int ret = 0;
 
        set_freezable();
 
-       kthread_wait_freezable(test_bit(JOURNAL_RECLAIM_STARTED, &j->flags));
-
        j->last_flushed = jiffies;
 
        while (!ret && !kthread_should_stop()) {
@@ -698,7 +700,7 @@ static int bch2_journal_reclaim_thread(void *arg)
                mutex_unlock(&j->reclaim_lock);
 
                now = jiffies;
-               delay = msecs_to_jiffies(j->reclaim_delay_ms);
+               delay = msecs_to_jiffies(c->opts.journal_reclaim_delay);
                j->next_reclaim = j->last_flushed + delay;
 
                if (!time_in_range(j->next_reclaim, now, now + delay))