1059 lines
34 KiB
Diff
1059 lines
34 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Tyler Smith <74526874+tylertms@users.noreply.github.com>
|
|
Date: Wed, 4 Nov 2026 04:11:56 +0000
|
|
Subject: [PATCH] refactor(vfs): link original single-inode writeback
|
|
|
|
---
|
|
fs/fs-writeback.c | 299 +-----------------------------------------
|
|
fs/inode_evict.c | 276 ++++++++++++++++++++++++++++++++++++++
|
|
fs/writeback_inode.h | 28 ++++
|
|
mm/page-writeback.c | 124 +-----------------
|
|
mm/writeback_domain.c | 133 +++++++++++++++++++
|
|
mm/writeback_domain.h | 10 ++
|
|
6 files changed, 450 insertions(+), 420 deletions(-)
|
|
|
|
diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c
|
|
index a46f4572d1f552ef824b6d9373c22bcb1a51ccc9..219d5379655a793ea1397beaab5a854982f84173 100644
|
|
--- a/fs/fs-writeback.c
|
|
+++ b/fs/fs-writeback.c
|
|
@@ -52,18 +52,6 @@ struct wb_writeback_work {
|
|
struct wb_completion *done; /* set if the caller waits */
|
|
};
|
|
|
|
-/*
|
|
- * If an inode is constantly having its pages dirtied, but then the
|
|
- * updates stop dirtytime_expire_interval seconds in the past, it's
|
|
- * possible for the worst case time between when an inode has its
|
|
- * timestamps updated and when they finally get written out to be two
|
|
- * dirtytime_expire_intervals. We set the default to 12 hours (in
|
|
- * seconds), which means most of the time inodes will have their
|
|
- * timestamps written to disk after 12 hours, but in the worst case a
|
|
- * few inodes might not their timestamps updated for 24 hours.
|
|
- */
|
|
-static unsigned int dirtytime_expire_interval = 12 * 60 * 60;
|
|
-
|
|
static inline struct inode *wb_inode(struct list_head *head)
|
|
{
|
|
return list_entry(head, struct inode, i_io_list);
|
|
@@ -233,7 +221,7 @@ void __inode_attach_wb(struct inode *inode, struct folio *folio)
|
|
* Remove the inode from wb's io lists and if necessarily put onto b_attached
|
|
* list. Only inodes attached to cgwb's are kept on this list.
|
|
*/
|
|
-static void inode_cgwb_move_to_attached(struct inode *inode,
|
|
+void inode_cgwb_move_to_attached(struct inode *inode,
|
|
struct bdi_writeback *wb)
|
|
{
|
|
assert_spin_locked(&wb->list_lock);
|
|
@@ -699,7 +687,7 @@ bool cleanup_offline_cgwb(struct bdi_writeback *wb)
|
|
* writeback completion, wbc_detach_inode() should be called. This is used
|
|
* to track the cgroup writeback context.
|
|
*/
|
|
-static void wbc_attach_and_unlock_inode(struct writeback_control *wbc,
|
|
+void wbc_attach_and_unlock_inode(struct writeback_control *wbc,
|
|
struct inode *inode)
|
|
__releases(&inode->i_lock)
|
|
{
|
|
@@ -1154,18 +1142,6 @@ fs_initcall(cgroup_writeback_init);
|
|
static void bdi_down_write_wb_switch_rwsem(struct backing_dev_info *bdi) { }
|
|
static void bdi_up_write_wb_switch_rwsem(struct backing_dev_info *bdi) { }
|
|
|
|
-static void inode_cgwb_move_to_attached(struct inode *inode,
|
|
- struct bdi_writeback *wb)
|
|
-{
|
|
- assert_spin_locked(&wb->list_lock);
|
|
- assert_spin_locked(&inode->i_lock);
|
|
- WARN_ON_ONCE(inode_state_read(inode) & I_FREEING);
|
|
-
|
|
- inode_state_clear(inode, I_SYNC_QUEUED);
|
|
- list_del_init(&inode->i_io_list);
|
|
- wb_io_lists_depopulated(wb);
|
|
-}
|
|
-
|
|
static long wb_split_bdi_pages(struct bdi_writeback *wb, long nr_pages)
|
|
{
|
|
return nr_pages;
|
|
@@ -1183,13 +1159,6 @@ static void bdi_split_work_to_wbs(struct backing_dev_info *bdi,
|
|
}
|
|
}
|
|
|
|
-static inline void wbc_attach_and_unlock_inode(struct writeback_control *wbc,
|
|
- struct inode *inode)
|
|
- __releases(&inode->i_lock)
|
|
-{
|
|
- spin_unlock(&inode->i_lock);
|
|
-}
|
|
-
|
|
#endif /* CONFIG_CGROUP_WRITEBACK */
|
|
|
|
/*
|
|
@@ -1279,40 +1248,6 @@ void sb_clear_inode_writeback(struct inode *inode)
|
|
}
|
|
}
|
|
|
|
-/*
|
|
- * Redirty an inode: set its when-it-was dirtied timestamp and move it to the
|
|
- * furthest end of its superblock's dirty-inode list.
|
|
- *
|
|
- * Before stamping the inode's ->dirtied_when, we check to see whether it is
|
|
- * already the most-recently-dirtied inode on the b_dirty list. If that is
|
|
- * the case then the inode must have been redirtied while it was being written
|
|
- * out and we don't reset its dirtied_when.
|
|
- */
|
|
-static void redirty_tail_locked(struct inode *inode, struct bdi_writeback *wb)
|
|
-{
|
|
- assert_spin_locked(&inode->i_lock);
|
|
-
|
|
- inode_state_clear(inode, I_SYNC_QUEUED);
|
|
- /*
|
|
- * When the inode is being freed just don't bother with dirty list
|
|
- * tracking. Flush worker will ignore this inode anyway and it will
|
|
- * trigger assertions in inode_io_list_move_locked().
|
|
- */
|
|
- if (inode_state_read(inode) & I_FREEING) {
|
|
- list_del_init(&inode->i_io_list);
|
|
- wb_io_lists_depopulated(wb);
|
|
- return;
|
|
- }
|
|
- if (!list_empty(&wb->b_dirty)) {
|
|
- struct inode *tail;
|
|
-
|
|
- tail = wb_inode(wb->b_dirty.next);
|
|
- if (time_before(inode->dirtied_when, tail->dirtied_when))
|
|
- inode->dirtied_when = jiffies;
|
|
- }
|
|
- inode_io_list_move_locked(inode, wb, &wb->b_dirty);
|
|
-}
|
|
-
|
|
static void redirty_tail(struct inode *inode, struct bdi_writeback *wb)
|
|
{
|
|
spin_lock(&inode->i_lock);
|
|
@@ -1328,17 +1263,6 @@ static void requeue_io(struct inode *inode, struct bdi_writeback *wb)
|
|
inode_io_list_move_locked(inode, wb, &wb->b_more_io);
|
|
}
|
|
|
|
-static void inode_sync_complete(struct inode *inode)
|
|
-{
|
|
- assert_spin_locked(&inode->i_lock);
|
|
-
|
|
- inode_state_clear(inode, I_SYNC);
|
|
- /* If inode is clean an unused, put it into LRU now... */
|
|
- inode_lru_list_add(inode);
|
|
- /* Called with inode->i_lock which ensures memory ordering. */
|
|
- inode_wake_up_bit(inode, __I_SYNC);
|
|
-}
|
|
-
|
|
static bool inode_dirtied_after(struct inode *inode, unsigned long t)
|
|
{
|
|
bool ret = time_after(inode->dirtied_when, t);
|
|
@@ -1438,19 +1362,6 @@ static void queue_io(struct bdi_writeback *wb, struct wb_writeback_work *work,
|
|
trace_writeback_queue_io(wb, work, dirtied_before, moved);
|
|
}
|
|
|
|
-static int write_inode(struct inode *inode, struct writeback_control *wbc)
|
|
-{
|
|
- int ret;
|
|
-
|
|
- if (inode->i_sb->s_op->write_inode && !is_bad_inode(inode)) {
|
|
- trace_writeback_write_inode_start(inode, wbc);
|
|
- ret = inode->i_sb->s_op->write_inode(inode, wbc);
|
|
- trace_writeback_write_inode(inode, wbc);
|
|
- return ret;
|
|
- }
|
|
- return 0;
|
|
-}
|
|
-
|
|
/*
|
|
* Sleep until I_SYNC is cleared. This function must be called with i_lock
|
|
* held and drops it. It is aimed for callers not holding any inode reference
|
|
@@ -1549,185 +1460,6 @@ static void requeue_inode(struct inode *inode, struct bdi_writeback *wb,
|
|
}
|
|
}
|
|
|
|
-/*
|
|
- * Write out an inode and its dirty pages (or some of its dirty pages, depending
|
|
- * on @wbc->nr_to_write), and clear the relevant dirty flags from i_state.
|
|
- *
|
|
- * This doesn't remove the inode from the writeback list it is on, except
|
|
- * potentially to move it from b_dirty_time to b_dirty due to timestamp
|
|
- * expiration. The caller is otherwise responsible for writeback list handling.
|
|
- *
|
|
- * The caller is also responsible for setting the I_SYNC flag beforehand and
|
|
- * calling inode_sync_complete() to clear it afterwards.
|
|
- */
|
|
-static int
|
|
-__writeback_single_inode(struct inode *inode, struct writeback_control *wbc)
|
|
-{
|
|
- struct address_space *mapping = inode->i_mapping;
|
|
- long nr_to_write = wbc->nr_to_write;
|
|
- unsigned dirty;
|
|
- int ret;
|
|
-
|
|
- WARN_ON(!(inode_state_read_once(inode) & I_SYNC));
|
|
-
|
|
- trace_writeback_single_inode_start(inode, wbc, nr_to_write);
|
|
-
|
|
- ret = do_writepages(mapping, wbc);
|
|
-
|
|
- /*
|
|
- * Make sure to wait on the data before writing out the metadata.
|
|
- * This is important for filesystems that modify metadata on data
|
|
- * I/O completion. We don't do it for sync(2) writeback because it has a
|
|
- * separate, external IO completion path and ->sync_fs for guaranteeing
|
|
- * inode metadata is written back correctly.
|
|
- */
|
|
- if (wbc->sync_mode == WB_SYNC_ALL && !wbc->for_sync) {
|
|
- int err = filemap_fdatawait(mapping);
|
|
- if (ret == 0)
|
|
- ret = err;
|
|
- }
|
|
-
|
|
- /*
|
|
- * For data integrity writeback, or when the dirty interval expired,
|
|
- * ask the file system to propagata lazy timestamp updates into real
|
|
- * dirty state.
|
|
- */
|
|
- if ((inode_state_read_once(inode) & I_DIRTY_TIME) &&
|
|
- (wbc->sync_mode == WB_SYNC_ALL ||
|
|
- time_after(jiffies, inode->dirtied_time_when +
|
|
- dirtytime_expire_interval * HZ)))
|
|
- sync_lazytime(inode);
|
|
-
|
|
- /*
|
|
- * Get and clear the dirty flags from i_state. This needs to be done
|
|
- * after calling writepages because some filesystems may redirty the
|
|
- * inode during writepages due to delalloc. It also needs to be done
|
|
- * after handling timestamp expiration, as that may dirty the inode too.
|
|
- */
|
|
- spin_lock(&inode->i_lock);
|
|
- dirty = inode_state_read(inode) & I_DIRTY;
|
|
- inode_state_clear(inode, dirty);
|
|
-
|
|
- /*
|
|
- * Paired with smp_mb() in __mark_inode_dirty(). This allows
|
|
- * __mark_inode_dirty() to test i_state without grabbing i_lock -
|
|
- * either they see the I_DIRTY bits cleared or we see the dirtied
|
|
- * inode.
|
|
- *
|
|
- * I_DIRTY_PAGES is always cleared together above even if @mapping
|
|
- * still has dirty pages. The flag is reinstated after smp_mb() if
|
|
- * necessary. This guarantees that either __mark_inode_dirty()
|
|
- * sees clear I_DIRTY_PAGES or we see PAGECACHE_TAG_DIRTY.
|
|
- */
|
|
- smp_mb();
|
|
-
|
|
- if (mapping_tagged(mapping, PAGECACHE_TAG_DIRTY))
|
|
- inode_state_set(inode, I_DIRTY_PAGES);
|
|
- else if (unlikely(inode_state_read(inode) & I_PINNING_NETFS_WB)) {
|
|
- if (!(inode_state_read(inode) & I_DIRTY_PAGES)) {
|
|
- inode_state_clear(inode, I_PINNING_NETFS_WB);
|
|
- wbc->unpinned_netfs_wb = true;
|
|
- dirty |= I_PINNING_NETFS_WB; /* Cause write_inode */
|
|
- }
|
|
- }
|
|
-
|
|
- spin_unlock(&inode->i_lock);
|
|
-
|
|
- /* Don't write the inode if only I_DIRTY_PAGES was set */
|
|
- if (dirty & ~I_DIRTY_PAGES) {
|
|
- int err = write_inode(inode, wbc);
|
|
- if (ret == 0)
|
|
- ret = err;
|
|
- }
|
|
- wbc->unpinned_netfs_wb = false;
|
|
- trace_writeback_single_inode(inode, wbc, nr_to_write);
|
|
- return ret;
|
|
-}
|
|
-
|
|
-/*
|
|
- * Write out an inode's dirty data and metadata on-demand, i.e. separately from
|
|
- * the regular batched writeback done by the flusher threads in
|
|
- * writeback_sb_inodes(). @wbc controls various aspects of the write, such as
|
|
- * whether it is a data-integrity sync (%WB_SYNC_ALL) or not (%WB_SYNC_NONE).
|
|
- *
|
|
- * To prevent the inode from going away, either the caller must have a reference
|
|
- * to the inode, or the inode must have I_WILL_FREE or I_FREEING set.
|
|
- */
|
|
-static int writeback_single_inode(struct inode *inode,
|
|
- struct writeback_control *wbc)
|
|
-{
|
|
- struct bdi_writeback *wb;
|
|
- int ret = 0;
|
|
-
|
|
- spin_lock(&inode->i_lock);
|
|
- if (!icount_read(inode))
|
|
- WARN_ON(!(inode_state_read(inode) & (I_WILL_FREE | I_FREEING)));
|
|
- else
|
|
- WARN_ON(inode_state_read(inode) & I_WILL_FREE);
|
|
-
|
|
- if (inode_state_read(inode) & I_SYNC) {
|
|
- /*
|
|
- * Writeback is already running on the inode. For WB_SYNC_NONE,
|
|
- * that's enough and we can just return. For WB_SYNC_ALL, we
|
|
- * must wait for the existing writeback to complete, then do
|
|
- * writeback again if there's anything left.
|
|
- */
|
|
- if (wbc->sync_mode != WB_SYNC_ALL)
|
|
- goto out;
|
|
- inode_wait_for_writeback(inode);
|
|
- }
|
|
- WARN_ON(inode_state_read(inode) & I_SYNC);
|
|
- /*
|
|
- * If the inode is already fully clean, then there's nothing to do.
|
|
- *
|
|
- * For data-integrity syncs we also need to check whether any pages are
|
|
- * still under writeback, e.g. due to prior WB_SYNC_NONE writeback. If
|
|
- * there are any such pages, we'll need to wait for them.
|
|
- */
|
|
- if (!(inode_state_read(inode) & I_DIRTY_ALL) &&
|
|
- (wbc->sync_mode != WB_SYNC_ALL ||
|
|
- !mapping_tagged(inode->i_mapping, PAGECACHE_TAG_WRITEBACK)))
|
|
- goto out;
|
|
- inode_state_set(inode, I_SYNC);
|
|
- wbc_attach_and_unlock_inode(wbc, inode);
|
|
-
|
|
- ret = __writeback_single_inode(inode, wbc);
|
|
-
|
|
- wbc_detach_inode(wbc);
|
|
-
|
|
- wb = inode_to_wb_and_lock_list(inode);
|
|
- spin_lock(&inode->i_lock);
|
|
- /*
|
|
- * If the inode is freeing, its i_io_list shoudn't be updated
|
|
- * as it can be finally deleted at this moment.
|
|
- */
|
|
- if (!(inode_state_read(inode) & I_FREEING)) {
|
|
- /*
|
|
- * If the inode is now fully clean, then it can be safely
|
|
- * removed from its writeback list (if any). Otherwise the
|
|
- * flusher threads are responsible for the writeback lists.
|
|
- */
|
|
- if (!(inode_state_read(inode) & I_DIRTY_ALL))
|
|
- inode_cgwb_move_to_attached(inode, wb);
|
|
- else if (!(inode_state_read(inode) & I_SYNC_QUEUED)) {
|
|
- if ((inode_state_read(inode) & I_DIRTY))
|
|
- redirty_tail_locked(inode, wb);
|
|
- else if (inode_state_read(inode) & I_DIRTY_TIME) {
|
|
- inode->dirtied_when = jiffies;
|
|
- inode_io_list_move_locked(inode,
|
|
- wb,
|
|
- &wb->b_dirty_time);
|
|
- }
|
|
- }
|
|
- }
|
|
-
|
|
- spin_unlock(&wb->list_lock);
|
|
- inode_sync_complete(inode);
|
|
-out:
|
|
- spin_unlock(&inode->i_lock);
|
|
- return ret;
|
|
-}
|
|
-
|
|
static long writeback_chunk_size(struct super_block *sb,
|
|
struct bdi_writeback *wb, struct wb_writeback_work *work)
|
|
{
|
|
@@ -2649,33 +2381,6 @@ void sync_inodes_sb(struct super_block *sb)
|
|
}
|
|
EXPORT_SYMBOL(sync_inodes_sb);
|
|
|
|
-/**
|
|
- * write_inode_now - write an inode to disk
|
|
- * @inode: inode to write to disk
|
|
- * @sync: whether the write should be synchronous or not
|
|
- *
|
|
- * This function commits an inode to disk immediately if it is dirty. This is
|
|
- * primarily needed by knfsd.
|
|
- *
|
|
- * The caller must either have a ref on the inode or must have set I_WILL_FREE.
|
|
- */
|
|
-int write_inode_now(struct inode *inode, int sync)
|
|
-{
|
|
- struct writeback_control wbc = {
|
|
- .nr_to_write = LONG_MAX,
|
|
- .sync_mode = sync ? WB_SYNC_ALL : WB_SYNC_NONE,
|
|
- .range_start = 0,
|
|
- .range_end = LLONG_MAX,
|
|
- };
|
|
-
|
|
- if (!mapping_can_writeback(inode->i_mapping))
|
|
- wbc.nr_to_write = 0;
|
|
-
|
|
- might_sleep();
|
|
- return writeback_single_inode(inode, &wbc);
|
|
-}
|
|
-EXPORT_SYMBOL(write_inode_now);
|
|
-
|
|
/**
|
|
* sync_inode_metadata - write an inode to disk
|
|
* @inode: the inode to sync
|
|
diff --git a/fs/inode_evict.c b/fs/inode_evict.c
|
|
index 746c23590f23b56bb0050b0ce5836e92dd537e08..ffc3f05da35aad82069ed7fdb8f61177f1362180 100644
|
|
--- a/fs/inode_evict.c
|
|
+++ b/fs/inode_evict.c
|
|
@@ -7,6 +7,7 @@
|
|
#include <linux/export.h>
|
|
#include <linux/fs.h>
|
|
#include <linux/fsverity.h>
|
|
+#include <linux/jiffies.h>
|
|
#include <linux/pagemap.h>
|
|
#include <linux/percpu.h>
|
|
#include <linux/sched.h>
|
|
@@ -557,3 +558,278 @@ bool sync_lazytime(struct inode *inode)
|
|
mark_inode_dirty_sync(inode);
|
|
return true;
|
|
}
|
|
+
|
|
+/*
|
|
+ * If an inode is constantly having its pages dirtied, but then the
|
|
+ * updates stop dirtytime_expire_interval seconds in the past, it's
|
|
+ * possible for the worst case time between when an inode has its
|
|
+ * timestamps updated and when they finally get written out to be two
|
|
+ * dirtytime_expire_intervals. We set the default to 12 hours (in
|
|
+ * seconds), which means most of the time inodes will have their
|
|
+ * timestamps written to disk after 12 hours, but in the worst case a
|
|
+ * few inodes might not their timestamps updated for 24 hours.
|
|
+ */
|
|
+unsigned int dirtytime_expire_interval = 12 * 60 * 60;
|
|
+
|
|
+/*
|
|
+ * Redirty an inode: set its when-it-was dirtied timestamp and move it to the
|
|
+ * furthest end of its superblock's dirty-inode list.
|
|
+ *
|
|
+ * Before stamping the inode's ->dirtied_when, we check to see whether it is
|
|
+ * already the most-recently-dirtied inode on the b_dirty list. If that is
|
|
+ * the case then the inode must have been redirtied while it was being written
|
|
+ * out and we don't reset its dirtied_when.
|
|
+ */
|
|
+void redirty_tail_locked(struct inode *inode, struct bdi_writeback *wb)
|
|
+{
|
|
+ assert_spin_locked(&inode->i_lock);
|
|
+
|
|
+ inode_state_clear(inode, I_SYNC_QUEUED);
|
|
+ /*
|
|
+ * When the inode is being freed just don't bother with dirty list
|
|
+ * tracking. Flush worker will ignore this inode anyway and it will
|
|
+ * trigger assertions in inode_io_list_move_locked().
|
|
+ */
|
|
+ if (inode_state_read(inode) & I_FREEING) {
|
|
+ list_del_init(&inode->i_io_list);
|
|
+ wb_io_lists_depopulated(wb);
|
|
+ return;
|
|
+ }
|
|
+ if (!list_empty(&wb->b_dirty)) {
|
|
+ struct inode *tail;
|
|
+
|
|
+ tail = list_first_entry(&wb->b_dirty, struct inode, i_io_list);
|
|
+ if (time_before(inode->dirtied_when, tail->dirtied_when))
|
|
+ inode->dirtied_when = jiffies;
|
|
+ }
|
|
+ inode_io_list_move_locked(inode, wb, &wb->b_dirty);
|
|
+}
|
|
+
|
|
+void inode_sync_complete(struct inode *inode)
|
|
+{
|
|
+ assert_spin_locked(&inode->i_lock);
|
|
+
|
|
+ inode_state_clear(inode, I_SYNC);
|
|
+ /* If inode is clean an unused, put it into LRU now... */
|
|
+ inode_lru_list_add(inode);
|
|
+ /* Called with inode->i_lock which ensures memory ordering. */
|
|
+ inode_wake_up_bit(inode, __I_SYNC);
|
|
+}
|
|
+
|
|
+static int write_inode(struct inode *inode, struct writeback_control *wbc)
|
|
+{
|
|
+ int ret;
|
|
+
|
|
+ if (inode->i_sb->s_op->write_inode && !is_bad_inode(inode)) {
|
|
+ trace_writeback_write_inode_start(inode, wbc);
|
|
+ ret = inode->i_sb->s_op->write_inode(inode, wbc);
|
|
+ trace_writeback_write_inode(inode, wbc);
|
|
+ return ret;
|
|
+ }
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+/*
|
|
+ * Write out an inode and its dirty pages (or some of its dirty pages, depending
|
|
+ * on @wbc->nr_to_write), and clear the relevant dirty flags from i_state.
|
|
+ *
|
|
+ * This doesn't remove the inode from the writeback list it is on, except
|
|
+ * potentially to move it from b_dirty_time to b_dirty due to timestamp
|
|
+ * expiration. The caller is otherwise responsible for writeback list handling.
|
|
+ *
|
|
+ * The caller is also responsible for setting the I_SYNC flag beforehand and
|
|
+ * calling inode_sync_complete() to clear it afterwards.
|
|
+ */
|
|
+int __writeback_single_inode(struct inode *inode, struct writeback_control *wbc)
|
|
+{
|
|
+ struct address_space *mapping = inode->i_mapping;
|
|
+ long nr_to_write = wbc->nr_to_write;
|
|
+ unsigned dirty;
|
|
+ int ret;
|
|
+
|
|
+ WARN_ON(!(inode_state_read_once(inode) & I_SYNC));
|
|
+
|
|
+ trace_writeback_single_inode_start(inode, wbc, nr_to_write);
|
|
+
|
|
+ ret = do_writepages(mapping, wbc);
|
|
+
|
|
+ /*
|
|
+ * Make sure to wait on the data before writing out the metadata.
|
|
+ * This is important for filesystems that modify metadata on data
|
|
+ * I/O completion. We don't do it for sync(2) writeback because it has a
|
|
+ * separate, external IO completion path and ->sync_fs for guaranteeing
|
|
+ * inode metadata is written back correctly.
|
|
+ */
|
|
+ if (wbc->sync_mode == WB_SYNC_ALL && !wbc->for_sync) {
|
|
+ int err = filemap_fdatawait(mapping);
|
|
+ if (ret == 0)
|
|
+ ret = err;
|
|
+ }
|
|
+
|
|
+ /*
|
|
+ * For data integrity writeback, or when the dirty interval expired,
|
|
+ * ask the file system to propagata lazy timestamp updates into real
|
|
+ * dirty state.
|
|
+ */
|
|
+ if ((inode_state_read_once(inode) & I_DIRTY_TIME) &&
|
|
+ (wbc->sync_mode == WB_SYNC_ALL ||
|
|
+ time_after(jiffies, inode->dirtied_time_when +
|
|
+ dirtytime_expire_interval * HZ)))
|
|
+ sync_lazytime(inode);
|
|
+
|
|
+ /*
|
|
+ * Get and clear the dirty flags from i_state. This needs to be done
|
|
+ * after calling writepages because some filesystems may redirty the
|
|
+ * inode during writepages due to delalloc. It also needs to be done
|
|
+ * after handling timestamp expiration, as that may dirty the inode too.
|
|
+ */
|
|
+ spin_lock(&inode->i_lock);
|
|
+ dirty = inode_state_read(inode) & I_DIRTY;
|
|
+ inode_state_clear(inode, dirty);
|
|
+
|
|
+ /*
|
|
+ * Paired with smp_mb() in __mark_inode_dirty(). This allows
|
|
+ * __mark_inode_dirty() to test i_state without grabbing i_lock -
|
|
+ * either they see the I_DIRTY bits cleared or we see the dirtied
|
|
+ * inode.
|
|
+ *
|
|
+ * I_DIRTY_PAGES is always cleared together above even if @mapping
|
|
+ * still has dirty pages. The flag is reinstated after smp_mb() if
|
|
+ * necessary. This guarantees that either __mark_inode_dirty()
|
|
+ * sees clear I_DIRTY_PAGES or we see PAGECACHE_TAG_DIRTY.
|
|
+ */
|
|
+ smp_mb();
|
|
+
|
|
+ if (mapping_tagged(mapping, PAGECACHE_TAG_DIRTY))
|
|
+ inode_state_set(inode, I_DIRTY_PAGES);
|
|
+ else if (unlikely(inode_state_read(inode) & I_PINNING_NETFS_WB)) {
|
|
+ if (!(inode_state_read(inode) & I_DIRTY_PAGES)) {
|
|
+ inode_state_clear(inode, I_PINNING_NETFS_WB);
|
|
+ wbc->unpinned_netfs_wb = true;
|
|
+ dirty |= I_PINNING_NETFS_WB; /* Cause write_inode */
|
|
+ }
|
|
+ }
|
|
+
|
|
+ spin_unlock(&inode->i_lock);
|
|
+
|
|
+ /* Don't write the inode if only I_DIRTY_PAGES was set */
|
|
+ if (dirty & ~I_DIRTY_PAGES) {
|
|
+ int err = write_inode(inode, wbc);
|
|
+ if (ret == 0)
|
|
+ ret = err;
|
|
+ }
|
|
+ wbc->unpinned_netfs_wb = false;
|
|
+ trace_writeback_single_inode(inode, wbc, nr_to_write);
|
|
+ return ret;
|
|
+}
|
|
+
|
|
+/*
|
|
+ * Write out an inode's dirty data and metadata on-demand, i.e. separately from
|
|
+ * the regular batched writeback done by the flusher threads in
|
|
+ * writeback_sb_inodes(). @wbc controls various aspects of the write, such as
|
|
+ * whether it is a data-integrity sync (%WB_SYNC_ALL) or not (%WB_SYNC_NONE).
|
|
+ *
|
|
+ * To prevent the inode from going away, either the caller must have a reference
|
|
+ * to the inode, or the inode must have I_WILL_FREE or I_FREEING set.
|
|
+ */
|
|
+int writeback_single_inode(struct inode *inode,
|
|
+ struct writeback_control *wbc)
|
|
+{
|
|
+ struct bdi_writeback *wb;
|
|
+ int ret = 0;
|
|
+
|
|
+ spin_lock(&inode->i_lock);
|
|
+ if (!icount_read(inode))
|
|
+ WARN_ON(!(inode_state_read(inode) & (I_WILL_FREE | I_FREEING)));
|
|
+ else
|
|
+ WARN_ON(inode_state_read(inode) & I_WILL_FREE);
|
|
+
|
|
+ if (inode_state_read(inode) & I_SYNC) {
|
|
+ /*
|
|
+ * Writeback is already running on the inode. For WB_SYNC_NONE,
|
|
+ * that's enough and we can just return. For WB_SYNC_ALL, we
|
|
+ * must wait for the existing writeback to complete, then do
|
|
+ * writeback again if there's anything left.
|
|
+ */
|
|
+ if (wbc->sync_mode != WB_SYNC_ALL)
|
|
+ goto out;
|
|
+ inode_wait_for_writeback(inode);
|
|
+ }
|
|
+ WARN_ON(inode_state_read(inode) & I_SYNC);
|
|
+ /*
|
|
+ * If the inode is already fully clean, then there's nothing to do.
|
|
+ *
|
|
+ * For data-integrity syncs we also need to check whether any pages are
|
|
+ * still under writeback, e.g. due to prior WB_SYNC_NONE writeback. If
|
|
+ * there are any such pages, we'll need to wait for them.
|
|
+ */
|
|
+ if (!(inode_state_read(inode) & I_DIRTY_ALL) &&
|
|
+ (wbc->sync_mode != WB_SYNC_ALL ||
|
|
+ !mapping_tagged(inode->i_mapping, PAGECACHE_TAG_WRITEBACK)))
|
|
+ goto out;
|
|
+ inode_state_set(inode, I_SYNC);
|
|
+ wbc_attach_and_unlock_inode(wbc, inode);
|
|
+
|
|
+ ret = __writeback_single_inode(inode, wbc);
|
|
+
|
|
+ wbc_detach_inode(wbc);
|
|
+
|
|
+ wb = inode_to_wb_and_lock_list(inode);
|
|
+ spin_lock(&inode->i_lock);
|
|
+ /*
|
|
+ * If the inode is freeing, its i_io_list shoudn't be updated
|
|
+ * as it can be finally deleted at this moment.
|
|
+ */
|
|
+ if (!(inode_state_read(inode) & I_FREEING)) {
|
|
+ /*
|
|
+ * If the inode is now fully clean, then it can be safely
|
|
+ * removed from its writeback list (if any). Otherwise the
|
|
+ * flusher threads are responsible for the writeback lists.
|
|
+ */
|
|
+ if (!(inode_state_read(inode) & I_DIRTY_ALL))
|
|
+ inode_cgwb_move_to_attached(inode, wb);
|
|
+ else if (!(inode_state_read(inode) & I_SYNC_QUEUED)) {
|
|
+ if ((inode_state_read(inode) & I_DIRTY))
|
|
+ redirty_tail_locked(inode, wb);
|
|
+ else if (inode_state_read(inode) & I_DIRTY_TIME) {
|
|
+ inode->dirtied_when = jiffies;
|
|
+ inode_io_list_move_locked(inode,
|
|
+ wb,
|
|
+ &wb->b_dirty_time);
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+
|
|
+ spin_unlock(&wb->list_lock);
|
|
+ inode_sync_complete(inode);
|
|
+out:
|
|
+ spin_unlock(&inode->i_lock);
|
|
+ return ret;
|
|
+}
|
|
+
|
|
+/**
|
|
+ * write_inode_now - write an inode to disk
|
|
+ * @inode: inode to write to disk
|
|
+ * @sync: whether the write should be synchronous or not
|
|
+ *
|
|
+ * This function commits an inode to disk immediately if it is dirty. This is
|
|
+ * primarily needed by knfsd.
|
|
+ *
|
|
+ * The caller must either have a ref on the inode or must have set I_WILL_FREE.
|
|
+ */
|
|
+int write_inode_now(struct inode *inode, int sync)
|
|
+{
|
|
+ struct writeback_control wbc = {
|
|
+ .nr_to_write = LONG_MAX,
|
|
+ .sync_mode = sync ? WB_SYNC_ALL : WB_SYNC_NONE,
|
|
+ .range_start = 0,
|
|
+ .range_end = LLONG_MAX,
|
|
+ };
|
|
+
|
|
+ if (!mapping_can_writeback(inode->i_mapping))
|
|
+ wbc.nr_to_write = 0;
|
|
+
|
|
+ might_sleep();
|
|
+ return writeback_single_inode(inode, &wbc);
|
|
+}
|
|
+EXPORT_SYMBOL(write_inode_now);
|
|
diff --git a/fs/writeback_inode.h b/fs/writeback_inode.h
|
|
index d3d355adc9fe98fcd042ab74aa1bf13e96a2153c..8bb33017328b09e823797ba64e88a30847a8a049 100644
|
|
--- a/fs/writeback_inode.h
|
|
+++ b/fs/writeback_inode.h
|
|
@@ -19,7 +19,16 @@ static inline void wb_io_lists_depopulated(struct bdi_writeback *wb)
|
|
}
|
|
}
|
|
|
|
+extern unsigned int dirtytime_expire_interval;
|
|
+void redirty_tail_locked(struct inode *inode, struct bdi_writeback *wb);
|
|
+void inode_sync_complete(struct inode *inode);
|
|
+int __writeback_single_inode(struct inode *inode, struct writeback_control *wbc);
|
|
+int writeback_single_inode(struct inode *inode, struct writeback_control *wbc);
|
|
+
|
|
#ifdef CONFIG_CGROUP_WRITEBACK
|
|
+void inode_cgwb_move_to_attached(struct inode *inode, struct bdi_writeback *wb);
|
|
+void wbc_attach_and_unlock_inode(struct writeback_control *wbc, struct inode *inode);
|
|
+
|
|
/**
|
|
* locked_inode_to_wb_and_lock_list - determine a locked inode's wb and lock it
|
|
* @inode: inode of interest with i_lock held
|
|
@@ -74,6 +83,25 @@ static inline struct bdi_writeback *inode_to_wb_and_lock_list(struct inode *inod
|
|
}
|
|
|
|
#else
|
|
+static inline void inode_cgwb_move_to_attached(struct inode *inode,
|
|
+ struct bdi_writeback *wb)
|
|
+{
|
|
+ assert_spin_locked(&wb->list_lock);
|
|
+ assert_spin_locked(&inode->i_lock);
|
|
+ WARN_ON_ONCE(inode_state_read(inode) & I_FREEING);
|
|
+
|
|
+ inode_state_clear(inode, I_SYNC_QUEUED);
|
|
+ list_del_init(&inode->i_io_list);
|
|
+ wb_io_lists_depopulated(wb);
|
|
+}
|
|
+
|
|
+static inline void wbc_attach_and_unlock_inode(struct writeback_control *wbc,
|
|
+ struct inode *inode)
|
|
+ __releases(&inode->i_lock)
|
|
+{
|
|
+ spin_unlock(&inode->i_lock);
|
|
+}
|
|
+
|
|
static inline struct bdi_writeback *
|
|
locked_inode_to_wb_and_lock_list(struct inode *inode)
|
|
__releases(&inode->i_lock)
|
|
diff --git a/mm/page-writeback.c b/mm/page-writeback.c
|
|
index a9b2680a3d120b306675f40ce74ab3e3b564fed6..26ce52aed13e110585954f164e57181e12f74c9f 100644
|
|
--- a/mm/page-writeback.c
|
|
+++ b/mm/page-writeback.c
|
|
@@ -55,11 +55,6 @@
|
|
*/
|
|
#define DIRTY_POLL_THRESH (128 >> (PAGE_SHIFT - 10))
|
|
|
|
-/*
|
|
- * Estimate write bandwidth or update dirty limit at 200ms intervals.
|
|
- */
|
|
-#define BANDWIDTH_INTERVAL max(HZ/5, 1)
|
|
-
|
|
#define RATELIMIT_CALC_SHIFT 10
|
|
|
|
/*
|
|
@@ -1157,56 +1152,6 @@ static void wb_position_ratio(struct dirty_throttle_control *dtc)
|
|
dtc->pos_ratio = pos_ratio;
|
|
}
|
|
|
|
-static void wb_update_write_bandwidth(struct bdi_writeback *wb,
|
|
- unsigned long elapsed,
|
|
- unsigned long written)
|
|
-{
|
|
- const unsigned long period = roundup_pow_of_two(3 * HZ);
|
|
- unsigned long avg = wb->avg_write_bandwidth;
|
|
- unsigned long old = wb->write_bandwidth;
|
|
- u64 bw;
|
|
-
|
|
- /*
|
|
- * bw = written * HZ / elapsed
|
|
- *
|
|
- * bw * elapsed + write_bandwidth * (period - elapsed)
|
|
- * write_bandwidth = ---------------------------------------------------
|
|
- * period
|
|
- *
|
|
- * @written may have decreased due to folio_redirty_for_writepage().
|
|
- * Avoid underflowing @bw calculation.
|
|
- */
|
|
- bw = written - min(written, wb->written_stamp);
|
|
- bw *= HZ;
|
|
- if (unlikely(elapsed > period)) {
|
|
- bw = div64_ul(bw, elapsed);
|
|
- avg = bw;
|
|
- goto out;
|
|
- }
|
|
- bw += (u64)wb->write_bandwidth * (period - elapsed);
|
|
- bw >>= ilog2(period);
|
|
-
|
|
- /*
|
|
- * one more level of smoothing, for filtering out sudden spikes
|
|
- */
|
|
- if (avg > old && old >= (unsigned long)bw)
|
|
- avg -= (avg - old) >> 3;
|
|
-
|
|
- if (avg < old && old <= (unsigned long)bw)
|
|
- avg += (old - avg) >> 3;
|
|
-
|
|
-out:
|
|
- /* keep avg > 0 to guarantee that tot > 0 if there are dirty wbs */
|
|
- avg = max(avg, 1LU);
|
|
- if (wb_has_dirty_io(wb)) {
|
|
- long delta = avg - wb->avg_write_bandwidth;
|
|
- WARN_ON_ONCE(atomic_long_add_return(delta,
|
|
- &wb->bdi->tot_write_bandwidth) <= 0);
|
|
- }
|
|
- wb->write_bandwidth = bw;
|
|
- WRITE_ONCE(wb->avg_write_bandwidth, avg);
|
|
-}
|
|
-
|
|
static void update_dirty_limit(struct dirty_throttle_control *dtc)
|
|
{
|
|
struct wb_domain *dom = dtc_dom(dtc);
|
|
@@ -1447,39 +1392,10 @@ static void __wb_update_bandwidth(struct dirty_throttle_control *gdtc,
|
|
wb_update_dirty_ratelimit(mdtc, dirtied, elapsed);
|
|
}
|
|
}
|
|
- wb_update_write_bandwidth(wb, elapsed, written);
|
|
-
|
|
- wb->dirtied_stamp = dirtied;
|
|
- wb->written_stamp = written;
|
|
- WRITE_ONCE(wb->bw_time_stamp, now);
|
|
+ wb_update_bandwidth_sample(wb, now, elapsed, dirtied, written);
|
|
spin_unlock(&wb->list_lock);
|
|
}
|
|
|
|
-void wb_update_bandwidth(struct bdi_writeback *wb)
|
|
-{
|
|
- struct dirty_throttle_control gdtc = { GDTC_INIT(wb) };
|
|
-
|
|
- __wb_update_bandwidth(&gdtc, NULL, false);
|
|
-}
|
|
-
|
|
-/* Interval after which we consider wb idle and don't estimate bandwidth */
|
|
-#define WB_BANDWIDTH_IDLE_JIF (HZ)
|
|
-
|
|
-static void wb_bandwidth_estimate_start(struct bdi_writeback *wb)
|
|
-{
|
|
- unsigned long now = jiffies;
|
|
- unsigned long elapsed = now - READ_ONCE(wb->bw_time_stamp);
|
|
-
|
|
- if (elapsed > WB_BANDWIDTH_IDLE_JIF &&
|
|
- !atomic_read(&wb->writeback_inodes)) {
|
|
- spin_lock(&wb->list_lock);
|
|
- wb->dirtied_stamp = wb_stat(wb, WB_DIRTIED);
|
|
- wb->written_stamp = wb_stat(wb, WB_WRITTEN);
|
|
- WRITE_ONCE(wb->bw_time_stamp, now);
|
|
- spin_unlock(&wb->list_lock);
|
|
- }
|
|
-}
|
|
-
|
|
/*
|
|
* After a task dirtied this many pages, balance_dirty_pages_ratelimited()
|
|
* will look to see if it needs to start dirty throttling.
|
|
@@ -2491,44 +2407,6 @@ done:
|
|
}
|
|
EXPORT_SYMBOL_GPL(writeback_iter);
|
|
|
|
-int do_writepages(struct address_space *mapping, struct writeback_control *wbc)
|
|
-{
|
|
- int ret;
|
|
- struct bdi_writeback *wb;
|
|
-
|
|
- if (wbc->nr_to_write <= 0)
|
|
- return 0;
|
|
- wb = inode_to_wb_wbc(mapping->host, wbc);
|
|
- wb_bandwidth_estimate_start(wb);
|
|
- while (1) {
|
|
- if (mapping->a_ops->writepages)
|
|
- ret = mapping->a_ops->writepages(mapping, wbc);
|
|
- else
|
|
- /* deal with chardevs and other special files */
|
|
- ret = 0;
|
|
- if (ret != -ENOMEM || wbc->sync_mode != WB_SYNC_ALL)
|
|
- break;
|
|
-
|
|
- /*
|
|
- * Lacking an allocation context or the locality or writeback
|
|
- * state of any of the inode's pages, throttle based on
|
|
- * writeback activity on the local node. It's as good a
|
|
- * guess as any.
|
|
- */
|
|
- reclaim_throttle(NODE_DATA(numa_node_id()),
|
|
- VMSCAN_THROTTLE_WRITEBACK);
|
|
- }
|
|
- /*
|
|
- * Usually few pages are written by now from those we've just submitted
|
|
- * but if there's constant writeback being submitted, this makes sure
|
|
- * writeback bandwidth is updated once in a while.
|
|
- */
|
|
- if (time_is_before_jiffies(READ_ONCE(wb->bw_time_stamp) +
|
|
- BANDWIDTH_INTERVAL))
|
|
- wb_update_bandwidth(wb);
|
|
- return ret;
|
|
-}
|
|
-
|
|
/*
|
|
* Helper function for set_page_dirty family.
|
|
*
|
|
diff --git a/mm/writeback_domain.c b/mm/writeback_domain.c
|
|
index 91856bfe6075e45136f2939654f8b9545fb81852..944b2c63dc3a571d6ce3e6f382846aa9f72099d8 100644
|
|
--- a/mm/writeback_domain.c
|
|
+++ b/mm/writeback_domain.c
|
|
@@ -12,11 +12,13 @@
|
|
* Initial version
|
|
*/
|
|
|
|
+#include <linux/backing-dev.h>
|
|
#include <linux/export.h>
|
|
#include <linux/string.h>
|
|
#include <linux/timer.h>
|
|
#include <linux/writeback.h>
|
|
|
|
+#include "internal.h"
|
|
#include "writeback_domain.h"
|
|
|
|
/*
|
|
@@ -76,3 +78,134 @@ void wb_domain_exit(struct wb_domain *dom)
|
|
fprop_global_destroy(&dom->completions);
|
|
}
|
|
#endif
|
|
+
|
|
+static void wb_update_write_bandwidth(struct bdi_writeback *wb,
|
|
+ unsigned long elapsed,
|
|
+ unsigned long written)
|
|
+{
|
|
+ const unsigned long period = roundup_pow_of_two(3 * HZ);
|
|
+ unsigned long avg = wb->avg_write_bandwidth;
|
|
+ unsigned long old = wb->write_bandwidth;
|
|
+ u64 bw;
|
|
+
|
|
+ /*
|
|
+ * bw = written * HZ / elapsed
|
|
+ *
|
|
+ * bw * elapsed + write_bandwidth * (period - elapsed)
|
|
+ * write_bandwidth = ---------------------------------------------------
|
|
+ * period
|
|
+ *
|
|
+ * @written may have decreased due to folio_redirty_for_writepage().
|
|
+ * Avoid underflowing @bw calculation.
|
|
+ */
|
|
+ bw = written - min(written, wb->written_stamp);
|
|
+ bw *= HZ;
|
|
+ if (unlikely(elapsed > period)) {
|
|
+ bw = div64_ul(bw, elapsed);
|
|
+ avg = bw;
|
|
+ goto out;
|
|
+ }
|
|
+ bw += (u64)wb->write_bandwidth * (period - elapsed);
|
|
+ bw >>= ilog2(period);
|
|
+
|
|
+ /*
|
|
+ * one more level of smoothing, for filtering out sudden spikes
|
|
+ */
|
|
+ if (avg > old && old >= (unsigned long)bw)
|
|
+ avg -= (avg - old) >> 3;
|
|
+
|
|
+ if (avg < old && old <= (unsigned long)bw)
|
|
+ avg += (old - avg) >> 3;
|
|
+
|
|
+out:
|
|
+ /* keep avg > 0 to guarantee that tot > 0 if there are dirty wbs */
|
|
+ avg = max(avg, 1LU);
|
|
+ if (wb_has_dirty_io(wb)) {
|
|
+ long delta = avg - wb->avg_write_bandwidth;
|
|
+ WARN_ON_ONCE(atomic_long_add_return(delta,
|
|
+ &wb->bdi->tot_write_bandwidth) <= 0);
|
|
+ }
|
|
+ wb->write_bandwidth = bw;
|
|
+ WRITE_ONCE(wb->avg_write_bandwidth, avg);
|
|
+}
|
|
+
|
|
+void wb_update_bandwidth_sample(struct bdi_writeback *wb, unsigned long now,
|
|
+ unsigned long elapsed, unsigned long dirtied,
|
|
+ unsigned long written)
|
|
+{
|
|
+ assert_spin_locked(&wb->list_lock);
|
|
+ wb_update_write_bandwidth(wb, elapsed, written);
|
|
+
|
|
+ wb->dirtied_stamp = dirtied;
|
|
+ wb->written_stamp = written;
|
|
+ WRITE_ONCE(wb->bw_time_stamp, now);
|
|
+}
|
|
+
|
|
+void wb_update_bandwidth(struct bdi_writeback *wb)
|
|
+{
|
|
+ unsigned long now = jiffies;
|
|
+ unsigned long elapsed, dirtied, written;
|
|
+
|
|
+ spin_lock(&wb->list_lock);
|
|
+ elapsed = max(now - wb->bw_time_stamp, 1UL);
|
|
+ dirtied = percpu_counter_read(&wb->stat[WB_DIRTIED]);
|
|
+ written = percpu_counter_read(&wb->stat[WB_WRITTEN]);
|
|
+ wb_update_bandwidth_sample(wb, now, elapsed, dirtied, written);
|
|
+ spin_unlock(&wb->list_lock);
|
|
+}
|
|
+
|
|
+/* Interval after which we consider wb idle and don't estimate bandwidth */
|
|
+#define WB_BANDWIDTH_IDLE_JIF (HZ)
|
|
+
|
|
+static void wb_bandwidth_estimate_start(struct bdi_writeback *wb)
|
|
+{
|
|
+ unsigned long now = jiffies;
|
|
+ unsigned long elapsed = now - READ_ONCE(wb->bw_time_stamp);
|
|
+
|
|
+ if (elapsed > WB_BANDWIDTH_IDLE_JIF &&
|
|
+ !atomic_read(&wb->writeback_inodes)) {
|
|
+ spin_lock(&wb->list_lock);
|
|
+ wb->dirtied_stamp = wb_stat(wb, WB_DIRTIED);
|
|
+ wb->written_stamp = wb_stat(wb, WB_WRITTEN);
|
|
+ WRITE_ONCE(wb->bw_time_stamp, now);
|
|
+ spin_unlock(&wb->list_lock);
|
|
+ }
|
|
+}
|
|
+
|
|
+int do_writepages(struct address_space *mapping, struct writeback_control *wbc)
|
|
+{
|
|
+ int ret;
|
|
+ struct bdi_writeback *wb;
|
|
+
|
|
+ if (wbc->nr_to_write <= 0)
|
|
+ return 0;
|
|
+ wb = inode_to_wb_wbc(mapping->host, wbc);
|
|
+ wb_bandwidth_estimate_start(wb);
|
|
+ while (1) {
|
|
+ if (mapping->a_ops->writepages)
|
|
+ ret = mapping->a_ops->writepages(mapping, wbc);
|
|
+ else
|
|
+ /* deal with chardevs and other special files */
|
|
+ ret = 0;
|
|
+ if (ret != -ENOMEM || wbc->sync_mode != WB_SYNC_ALL)
|
|
+ break;
|
|
+
|
|
+ /*
|
|
+ * Lacking an allocation context or the locality or writeback
|
|
+ * state of any of the inode's pages, throttle based on
|
|
+ * writeback activity on the local node. It's as good a
|
|
+ * guess as any.
|
|
+ */
|
|
+ reclaim_throttle(NODE_DATA(numa_node_id()),
|
|
+ VMSCAN_THROTTLE_WRITEBACK);
|
|
+ }
|
|
+ /*
|
|
+ * Usually few pages are written by now from those we've just submitted
|
|
+ * but if there's constant writeback being submitted, this makes sure
|
|
+ * writeback bandwidth is updated once in a while.
|
|
+ */
|
|
+ if (time_is_before_jiffies(READ_ONCE(wb->bw_time_stamp) +
|
|
+ BANDWIDTH_INTERVAL))
|
|
+ wb_update_bandwidth(wb);
|
|
+ return ret;
|
|
+}
|
|
diff --git a/mm/writeback_domain.h b/mm/writeback_domain.h
|
|
index 3057ecc372414f833879e607711f0bfc27c85dcf..228c94f95e0f6ad1f89c0b216fbc6743e1dff3a3 100644
|
|
--- a/mm/writeback_domain.h
|
|
+++ b/mm/writeback_domain.h
|
|
@@ -4,6 +4,16 @@
|
|
|
|
#include <linux/jiffies.h>
|
|
|
|
+/*
|
|
+ * Estimate write bandwidth or update dirty limit at 200ms intervals.
|
|
+ */
|
|
+#define BANDWIDTH_INTERVAL max(HZ/5, 1)
|
|
+
|
|
+struct bdi_writeback;
|
|
+void wb_update_bandwidth_sample(struct bdi_writeback *wb, unsigned long now,
|
|
+ unsigned long elapsed, unsigned long dirtied,
|
|
+ unsigned long written);
|
|
+
|
|
#define VM_COMPLETIONS_PERIOD_LEN (3*HZ)
|
|
|
|
static inline unsigned long wp_next_time(unsigned long cur_time)
|