Skip to contentSkip to conversation

Metadata specific accouting and dirty writeout

PATCH Superseded Josef Bacik 4 participants 31 messages Dec 11, 2017 – Sep 28, 2018

Subsystems (17)
lore
Share & tools
lore
#0 lore raw

v3 cover Metadata specific accouting and dirty writeout

FYI patches 8-10 are purely there so people can see how I intend to use this. These are large changes that need to go through the btrfs tree and will undoubtedly change a lot. My goal is for patches 1-7 to go through Andrew via the mm tree and then once they have landed to go ahead and work out the details of the btrfs patches with the other btrfs developers and merge via that tree. I'm not asking for reviews on those, Jan just mentioned that it would be easier to tell what I was trying to do if he could see how I intended to use it.

v2->v3:
- addressed issues brought up by Jan in the actual node metadata bytes accounting patch.
- collapsed the fprop patch that converted everything to bytes into the patch that converted the wb usage of fprop stuff to bytes.

-- Original message --
These patches are to support having metadata accounting and dirty handling in a generic way. For dirty metadata ext4 and xfs currently are limited by their journal size, which allows them to handle dirty metadata flushing in a relatively easy way. Btrfs does not have this limiting factor, we can have as much dirty metadata on the system as we have memory, so we have a dummy inode that all of our metadat pages are allocated from so we can call balance_dirty_pages() on it and make sure we don't overwhelm the system with dirty metadata pages.

The problem with this is it severely limits our ability to do things like support sub-pagesize blocksizes. Btrfs also supports metadata blocksizes > page size, which makes keeping track of our metadata and it's pages particularly tricky. We have the inode mapping with our pages, and we have another radix tree for our actual metadata buffers. This double accounting leads to some fun shenanigans around reclaim and evicting pages we know we are done using.

To solve this we would like to switch to a scheme like xfs has, where we simply have our metadata structures tied into the slab shrinking code, and we just use alloc_page() for our pages, or kmalloc() when we add sub-pagesize blocksizes. In order to do this we need infrastructure in place to make sure we still don't overwhelm the system with dirty metadata pages.

Enter these patches. Because metadata is tracked on a non-pagesize amount we need to convert a bunch of our existing counters to bytes. From there I've added various counters for metadata, to keep track of overall metadata bytes, how many are dirty and how many are under writeback. I've added a super operation to handle the dirty writeback, which is going to be handled mostly inside the fs since we will need a little more smarts around what we writeback.

The last three patches are just there to show how we use the infrastructure in the first 8 patches. The actuall kill btree_inode patch is pretty big, unfortunately ripping out all of the pagecache based handling and replacing it with the new infrastructure has to be done whole-hog and can't be broken up anymore than it already has been without making it un-bisectable.

Thanks,

Josef

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#1 lore raw

PATCH v3 1/10 remove mapping from balance_dirty_pages*()

From: Josef Bacik <[email protected]>

The only reason we pass in the mapping is to get the inode in order to see if writeback cgroups is enabled, and even then it only checks the bdi and a super block flag. balance_dirty_pages() doesn't even use the mapping. Since balance_dirty_pages*() works on a bdi level, just pass in the bdi and super block directly so we can avoid using mapping. This will allow us to still use balance_dirty_pages for dirty metadata pages that are not backed by an address_mapping.

---
 drivers/mtd/devices/block2mtd.c | 12 ++++++++----
 fs/btrfs/disk-io.c              |  3 ++-
 fs/btrfs/file.c                 |  3 ++-
 fs/btrfs/ioctl.c                |  3 ++-
 fs/btrfs/relocation.c           |  3 ++-
 fs/buffer.c                     |  3 ++-
 fs/iomap.c                      |  6 ++++--
 fs/ntfs/attrib.c                | 11 ++++++++---
 fs/ntfs/file.c                  |  4 ++--
 include/linux/backing-dev.h     | 29 +++++++++++++++++++++++------
 include/linux/writeback.h       |  4 +++-
 mm/filemap.c                    |  4 +++-
 mm/memory.c                     |  5 ++++-
 mm/page-writeback.c             | 15 +++++++--------
 14 files changed, 72 insertions(+), 33 deletions(-)
drivers/mtd/devices/block2mtd.c +8 -4
index 7c887f111a7d..7892d0b9fcb0 100644
@@ -52,7 +52,8 @@ static struct page *page_read(struct address_space *mapping, int index)
 /* erase a specified part of the device */
 static int _block2mtd_erase(struct block2mtd_dev *dev, loff_t to, size_t len)
 {
-	struct address_space *mapping = dev->blkdev->bd_inode->i_mapping;
+	struct inode *inode = dev->blkdev->bd_inode;
+	struct address_space *mapping = inode->i_mapping;
 	struct page *page;
 	int index = to >> PAGE_SHIFT;	// page index
 	int pages = len >> PAGE_SHIFT;
@@ -71,7 +72,8 @@ static int _block2mtd_erase(struct block2mtd_dev *dev, loff_t to, size_t len)
 				memset(page_address(page), 0xff, PAGE_SIZE);
 				set_page_dirty(page);
 				unlock_page(page);
-				balance_dirty_pages_ratelimited(mapping);
+				balance_dirty_pages_ratelimited(inode_to_bdi(inode),
+								inode->i_sb);
 				break;
 			}
 
@@ -141,7 +143,8 @@ static int _block2mtd_write(struct block2mtd_dev *dev, const u_char *buf,
 		loff_t to, size_t len, size_t *retlen)
 {
 	struct page *page;
-	struct address_space *mapping = dev->blkdev->bd_inode->i_mapping;
+	struct inode *inode = dev->blkdev->bd_inode;
+	struct address_space *mapping = inode->i_mapping;
 	int index = to >> PAGE_SHIFT;	// page index
 	int offset = to & ~PAGE_MASK;	// page offset
 	int cpylen;
@@ -162,7 +165,8 @@ static int _block2mtd_write(struct block2mtd_dev *dev, const u_char *buf,
 			memcpy(page_address(page) + offset, buf, cpylen);
 			set_page_dirty(page);
 			unlock_page(page);
-			balance_dirty_pages_ratelimited(mapping);
+			balance_dirty_pages_ratelimited(inode_to_bdi(inode),
+							inode->i_sb);
 		}
 		put_page(page);
 
fs/btrfs/disk-io.c +2 -1
index 689b9913ccb5..8b6df7688d52 100644
@@ -4150,7 +4150,8 @@ static void __btrfs_btree_balance_dirty(struct btrfs_fs_info *fs_info,
 	ret = percpu_counter_compare(&fs_info->dirty_metadata_bytes,
 				     BTRFS_DIRTY_METADATA_THRESH);
 	if (ret > 0) {
-		balance_dirty_pages_ratelimited(fs_info->btree_inode->i_mapping);
+		balance_dirty_pages_ratelimited(fs_info->sb->s_bdi,
+						fs_info->sb);
 	}
 }
 
fs/btrfs/file.c +2 -1
index ab1c38f2dd8c..4bc6cd6509be 100644
@@ -1779,7 +1779,8 @@ static noinline ssize_t __btrfs_buffered_write(struct file *file,
 
 		cond_resched();
 
-		balance_dirty_pages_ratelimited(inode->i_mapping);
+		balance_dirty_pages_ratelimited(inode_to_bdi(inode),
+						inode->i_sb);
 		if (dirty_pages < (fs_info->nodesize >> PAGE_SHIFT) + 1)
 			btrfs_btree_balance_dirty(fs_info);
 
fs/btrfs/ioctl.c +2 -1
index 6a07d4e12fd2..ec92fb5e2b51 100644
@@ -1368,7 +1368,8 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
 		}
 
 		defrag_count += ret;
-		balance_dirty_pages_ratelimited(inode->i_mapping);
+		balance_dirty_pages_ratelimited(inode_to_bdi(inode),
+						inode->i_sb);
 		inode_unlock(inode);
 
 		if (newer_than) {
fs/btrfs/relocation.c +2 -1
index 4cf2eb67eba6..9f31c5e6c0e5 100644
@@ -3278,7 +3278,8 @@ static int relocate_file_extent_cluster(struct inode *inode,
 
 		index++;
 		btrfs_delalloc_release_extents(BTRFS_I(inode), PAGE_SIZE);
-		balance_dirty_pages_ratelimited(inode->i_mapping);
+		balance_dirty_pages_ratelimited(inode_to_bdi(inode),
+						inode->i_sb);
 		btrfs_throttle(fs_info);
 	}
 	WARN_ON(nr != cluster->nr);
fs/buffer.c +2 -1
index 170df856bdb9..36be326a316c 100644
@@ -2421,7 +2421,8 @@ static int cont_expand_zero(struct file *file, struct address_space *mapping,
 		BUG_ON(err != len);
 		err = 0;
 
-		balance_dirty_pages_ratelimited(mapping);
+		balance_dirty_pages_ratelimited(inode_to_bdi(inode),
+						inode->i_sb);
 
 		if (unlikely(fatal_signal_pending(current))) {
 			err = -EINTR;
fs/iomap.c +4 -2
index 269b24a01f32..0eb1ec680f87 100644
@@ -223,7 +223,8 @@ iomap_write_actor(struct inode *inode, loff_t pos, loff_t length, void *data,
 		written += copied;
 		length -= copied;
 
-		balance_dirty_pages_ratelimited(inode->i_mapping);
+		balance_dirty_pages_ratelimited(inode_to_bdi(inode),
+						inode->i_sb);
 	} while (iov_iter_count(i) && length);
 
 	return written ? written : status;
@@ -305,7 +306,8 @@ iomap_dirty_actor(struct inode *inode, loff_t pos, loff_t length, void *data,
 		written += status;
 		length -= status;
 
-		balance_dirty_pages_ratelimited(inode->i_mapping);
+		balance_dirty_pages_ratelimited(inode_to_bdi(inode),
+						inode->i_sb);
 	} while (length);
 
 	return written;
fs/ntfs/attrib.c +8 -3
index 44a39a099b54..d85368dd82e7 100644
@@ -25,6 +25,7 @@
 #include <linux/slab.h>
 #include <linux/swap.h>
 #include <linux/writeback.h>
+#include <linux/backing-dev.h>
 
 #include "attrib.h"
 #include "debug.h"
@@ -2493,6 +2494,7 @@ s64 ntfs_attr_extend_allocation(ntfs_inode *ni, s64 new_alloc_size,
 int ntfs_attr_set(ntfs_inode *ni, const s64 ofs, const s64 cnt, const u8 val)
 {
 	ntfs_volume *vol = ni->vol;
+	struct inode *inode = VFS_I(ni);
 	struct address_space *mapping;
 	struct page *page;
 	u8 *kaddr;
@@ -2545,7 +2547,8 @@ int ntfs_attr_set(ntfs_inode *ni, const s64 ofs, const s64 cnt, const u8 val)
 		kunmap_atomic(kaddr);
 		set_page_dirty(page);
 		put_page(page);
-		balance_dirty_pages_ratelimited(mapping);
+		balance_dirty_pages_ratelimited(inode_to_bdi(inode),
+						inode->i_sb);
 		cond_resched();
 		if (idx == end)
 			goto done;
@@ -2586,7 +2589,8 @@ int ntfs_attr_set(ntfs_inode *ni, const s64 ofs, const s64 cnt, const u8 val)
 		/* Finally unlock and release the page. */
 		unlock_page(page);
 		put_page(page);
-		balance_dirty_pages_ratelimited(mapping);
+		balance_dirty_pages_ratelimited(inode_to_bdi(inode),
+						inode->i_sb);
 		cond_resched();
 	}
 	/* If there is a last partial page, need to do it the slow way. */
@@ -2603,7 +2607,8 @@ int ntfs_attr_set(ntfs_inode *ni, const s64 ofs, const s64 cnt, const u8 val)
 		kunmap_atomic(kaddr);
 		set_page_dirty(page);
 		put_page(page);
-		balance_dirty_pages_ratelimited(mapping);
+		balance_dirty_pages_ratelimited(inode_to_bdi(inode),
+						inode->i_sb);
 		cond_resched();
 	}
 done:
fs/ntfs/file.c +2 -2
index 331910fa8442..77b04be4a157 100644
@@ -276,7 +276,7 @@ static int ntfs_attr_extend_initialized(ntfs_inode *ni, const s64 new_init_size)
 		 * number of pages we read and make dirty in the case of sparse
 		 * files.
 		 */
-		balance_dirty_pages_ratelimited(mapping);
+		balance_dirty_pages_ratelimited(inode_to_bdi(vi), vi->i_sb);
 		cond_resched();
 	} while (++index < end_index);
 	read_lock_irqsave(&ni->size_lock, flags);
@@ -1913,7 +1913,7 @@ static ssize_t ntfs_perform_write(struct file *file, struct iov_iter *i,
 		iov_iter_advance(i, copied);
 		pos += copied;
 		written += copied;
-		balance_dirty_pages_ratelimited(mapping);
+		balance_dirty_pages_ratelimited(inode_to_bdi(vi), vi->i_sb);
 		if (fatal_signal_pending(current)) {
 			status = -EINTR;
 			break;
include/linux/backing-dev.h +23 -6
index 854e1bdd0b2a..14e266d12620 100644
@@ -228,8 +228,9 @@ void wb_blkcg_offline(struct blkcg *blkcg);
 int inode_congested(struct inode *inode, int cong_bits);
 
 /**
- * inode_cgwb_enabled - test whether cgroup writeback is enabled on an inode
- * @inode: inode of interest
+ * bdi_cgwb_enabled - test wether cgroup writeback is enabled on a filesystem
+ * @bdi: the bdi we care about
+ * @sb: the super for the bdi
  *
  * cgroup writeback requires support from both the bdi and filesystem.
  * Also, both memcg and iocg have to be on the default hierarchy.  Test
@@ -238,15 +239,25 @@ int inode_congested(struct inode *inode, int cong_bits);
  * Note that the test result may change dynamically on the same inode
  * depending on how memcg and iocg are configured.
  */
-static inline bool inode_cgwb_enabled(struct inode *inode)
+static inline bool bdi_cgwb_enabled(struct backing_dev_info *bdi,
+				    struct super_block *sb)
 {
-	struct backing_dev_info *bdi = inode_to_bdi(inode);
-
 	return cgroup_subsys_on_dfl(memory_cgrp_subsys) &&
 		cgroup_subsys_on_dfl(io_cgrp_subsys) &&
 		bdi_cap_account_dirty(bdi) &&
 		(bdi->capabilities & BDI_CAP_CGROUP_WRITEBACK) &&
-		(inode->i_sb->s_iflags & SB_I_CGROUPWB);
+		(sb->s_iflags & SB_I_CGROUPWB);
+}
+
+/**
+ * inode_cgwb_enabled - test whether cgroup writeback is enabled on an inode
+ * @inode: inode of interest
+ *
+ * Does the inode have cgroup writeback support.
+ */
+static inline bool inode_cgwb_enabled(struct inode *inode)
+{
+	return bdi_cgwb_enabled(inode_to_bdi(inode), inode->i_sb);
 }
 
 /**
@@ -389,6 +400,12 @@ static inline void unlocked_inode_to_wb_end(struct inode *inode, bool locked)
 
 #else	/* CONFIG_CGROUP_WRITEBACK */
 
+static inline bool bdi_cgwb_enabled(struct backing_dev_info *bdi,
+				    struct super_block *sb)
+{
+	return false;
+}
+
 static inline bool inode_cgwb_enabled(struct inode *inode)
 {
 	return false;
include/linux/writeback.h +3 -1
index d5815794416c..fa799a4a7755 100644
@@ -376,7 +376,9 @@ void global_dirty_limits(unsigned long *pbackground, unsigned long *pdirty);
 unsigned long wb_calc_thresh(struct bdi_writeback *wb, unsigned long thresh);
 
 void wb_update_bandwidth(struct bdi_writeback *wb, unsigned long start_time);
-void balance_dirty_pages_ratelimited(struct address_space *mapping);
+void page_writeback_init(void);
+void balance_dirty_pages_ratelimited(struct backing_dev_info *bdi,
+				     struct super_block *sb);
 bool wb_over_bg_thresh(struct bdi_writeback *wb);
 
 typedef int (*writepage_t)(struct page *page, struct writeback_control *wbc,
mm/filemap.c +3 -1
index 870971e20967..5ea4878e9c78 100644
@@ -2971,6 +2971,7 @@ ssize_t generic_perform_write(struct file *file,
 				struct iov_iter *i, loff_t pos)
 {
 	struct address_space *mapping = file->f_mapping;
+	struct inode *inode = mapping->host;
 	const struct address_space_operations *a_ops = mapping->a_ops;
 	long status = 0;
 	ssize_t written = 0;
@@ -3044,7 +3045,8 @@ ssize_t generic_perform_write(struct file *file,
 		pos += copied;
 		written += copied;
 
-		balance_dirty_pages_ratelimited(mapping);
+		balance_dirty_pages_ratelimited(inode_to_bdi(inode),
+						inode->i_sb);
 	} while (iov_iter_count(i));
 
 	return written ? written : status;
mm/memory.c +4 -1
index ec4e15494901..86f31b3d54c6 100644
@@ -70,6 +70,7 @@
 #include <linux/userfaultfd_k.h>
 #include <linux/dax.h>
 #include <linux/oom.h>
+#include <linux/backing-dev.h>
 
 #include <asm/io.h>
 #include <asm/mmu_context.h>
@@ -2391,11 +2392,13 @@ static void fault_dirty_shared_page(struct vm_area_struct *vma,
 	unlock_page(page);
 
 	if ((dirtied || page_mkwrite) && mapping) {
+		struct inode *inode = mapping->host;
 		/*
 		 * Some device drivers do not set page.mapping
 		 * but still dirty their pages
 		 */
-		balance_dirty_pages_ratelimited(mapping);
+		balance_dirty_pages_ratelimited(inode_to_bdi(inode),
+						inode->i_sb);
 	}
 
 	if (!page_mkwrite)
mm/page-writeback.c +7 -8
index 0b9c5cbe8eba..1a47d4296750 100644
@@ -1559,8 +1559,7 @@ static inline void wb_dirty_limits(struct dirty_throttle_control *dtc)
  * If we're over `background_thresh' then the writeback threads are woken to
  * perform some writeout.
  */
-static void balance_dirty_pages(struct address_space *mapping,
-				struct bdi_writeback *wb,
+static void balance_dirty_pages(struct bdi_writeback *wb,
 				unsigned long pages_dirtied)
 {
 	struct dirty_throttle_control gdtc_stor = { GDTC_INIT(wb) };
@@ -1850,7 +1849,8 @@ DEFINE_PER_CPU(int, dirty_throttle_leaks) = 0;
 
 /**
  * balance_dirty_pages_ratelimited - balance dirty memory state
- * @mapping: address_space which was dirtied
+ * @bdi: the bdi that was dirtied
+ * @sb: the super block that was dirtied
  *
  * Processes which are dirtying memory should call in here once for each page
  * which was newly dirtied.  The function will periodically check the system's
@@ -1861,10 +1861,9 @@ DEFINE_PER_CPU(int, dirty_throttle_leaks) = 0;
  * limit we decrease the ratelimiting by a lot, to prevent individual processes
  * from overshooting the limit by (ratelimit_pages) each.
  */
-void balance_dirty_pages_ratelimited(struct address_space *mapping)
+void balance_dirty_pages_ratelimited(struct backing_dev_info *bdi,
+				     struct super_block *sb)
 {
-	struct inode *inode = mapping->host;
-	struct backing_dev_info *bdi = inode_to_bdi(inode);
 	struct bdi_writeback *wb = NULL;
 	int ratelimit;
 	int *p;
@@ -1872,7 +1871,7 @@ void balance_dirty_pages_ratelimited(struct address_space *mapping)
 	if (!bdi_cap_account_dirty(bdi))
 		return;
 
-	if (inode_cgwb_enabled(inode))
+	if (bdi_cgwb_enabled(bdi, sb))
 		wb = wb_get_create_current(bdi, GFP_KERNEL);
 	if (!wb)
 		wb = &bdi->wb;
@@ -1910,7 +1909,7 @@ void balance_dirty_pages_ratelimited(struct address_space *mapping)
 	preempt_enable();
 
 	if (unlikely(current->nr_dirtied >= ratelimit))
-		balance_dirty_pages(mapping, wb, current->nr_dirtied);
+		balance_dirty_pages(wb, current->nr_dirtied);
 
 	wb_put(wb);
 }
Signature · 7 lines
2.7.5

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#2 lore raw

PATCH v3 2/10 writeback: convert WB_WRITTEN/WB_DIRITED counters to bytes

In reply to Josef Bacik

From: Josef Bacik <[email protected]>

These are counters that constantly go up in order to do bandwidth calculations. It isn't important what the units are in, as long as they are consistent between the two of them, so convert them to count bytes written/dirtied, and allow the metadata accounting stuff to change the counters as well.

---
 fs/fuse/file.c                   |  4 ++--
 include/linux/backing-dev-defs.h |  4 ++--
 include/linux/backing-dev.h      |  2 +-
 mm/backing-dev.c                 |  9 +++++----
 mm/page-writeback.c              | 20 ++++++++++----------
 5 files changed, 20 insertions(+), 19 deletions(-)
fs/fuse/file.c +2 -2
index cb7dff5c45d7..67e7c4fac28d 100644
@@ -1471,7 +1471,7 @@ static void fuse_writepage_finish(struct fuse_conn *fc, struct fuse_req *req)
 	for (i = 0; i < req->num_pages; i++) {
 		dec_wb_stat(&bdi->wb, WB_WRITEBACK);
 		dec_node_page_state(req->pages[i], NR_WRITEBACK_TEMP);
-		wb_writeout_inc(&bdi->wb);
+		wb_writeout_add(&bdi->wb, PAGE_SIZE);
 	}
 	wake_up(&fi->page_waitq);
 }
@@ -1776,7 +1776,7 @@ static bool fuse_writepage_in_flight(struct fuse_req *new_req,
 
 		dec_wb_stat(&bdi->wb, WB_WRITEBACK);
 		dec_node_page_state(page, NR_WRITEBACK_TEMP);
-		wb_writeout_inc(&bdi->wb);
+		wb_writeout_add(&bdi->wb, PAGE_SIZE);
 		fuse_writepage_free(fc, new_req);
 		fuse_request_free(new_req);
 		goto out;
include/linux/backing-dev-defs.h +2 -2
index 866c433e7d32..ded45ac2cec7 100644
@@ -36,8 +36,8 @@ typedef int (congested_fn)(void *, int);
 enum wb_stat_item {
 	WB_RECLAIMABLE,
 	WB_WRITEBACK,
-	WB_DIRTIED,
-	WB_WRITTEN,
+	WB_DIRTIED_BYTES,
+	WB_WRITTEN_BYTES,
 	NR_WB_STAT_ITEMS
 };
 
include/linux/backing-dev.h +1 -1
index 14e266d12620..39b8dc486ea7 100644
@@ -89,7 +89,7 @@ static inline s64 wb_stat_sum(struct bdi_writeback *wb, enum wb_stat_item item)
 	return percpu_counter_sum_positive(&wb->stat[item]);
 }
 
-extern void wb_writeout_inc(struct bdi_writeback *wb);
+extern void wb_writeout_add(struct bdi_writeback *wb, long bytes);
 
 /*
  * maximal error of a stat counter.
mm/backing-dev.c +5 -4
index e19606bb41a0..62a332a91b38 100644
@@ -68,14 +68,15 @@ static int bdi_debug_stats_show(struct seq_file *m, void *v)
 	wb_thresh = wb_calc_thresh(wb, dirty_thresh);
 
 #define K(x) ((x) << (PAGE_SHIFT - 10))
+#define BtoK(x) ((x) >> 10)
 	seq_printf(m,
 		   "BdiWriteback:       %10lu kB\n"
 		   "BdiReclaimable:     %10lu kB\n"
 		   "BdiDirtyThresh:     %10lu kB\n"
 		   "DirtyThresh:        %10lu kB\n"
 		   "BackgroundThresh:   %10lu kB\n"
-		   "BdiDirtied:         %10lu kB\n"
-		   "BdiWritten:         %10lu kB\n"
+		   "BdiDirtiedBytes:    %10lu kB\n"
+		   "BdiWrittenBytes:    %10lu kB\n"
 		   "BdiWriteBandwidth:  %10lu kBps\n"
 		   "b_dirty:            %10lu\n"
 		   "b_io:               %10lu\n"
@@ -88,8 +89,8 @@ static int bdi_debug_stats_show(struct seq_file *m, void *v)
 		   K(wb_thresh),
 		   K(dirty_thresh),
 		   K(background_thresh),
-		   (unsigned long) K(wb_stat(wb, WB_DIRTIED)),
-		   (unsigned long) K(wb_stat(wb, WB_WRITTEN)),
+		   (unsigned long) BtoK(wb_stat(wb, WB_DIRTIED_BYTES)),
+		   (unsigned long) BtoK(wb_stat(wb, WB_WRITTEN_BYTES)),
 		   (unsigned long) K(wb->write_bandwidth),
 		   nr_dirty,
 		   nr_io,
mm/page-writeback.c +10 -10
index 1a47d4296750..e4563645749a 100644
@@ -597,11 +597,11 @@ static void wb_domain_writeout_inc(struct wb_domain *dom,
  * Increment @wb's writeout completion count and the global writeout
  * completion count. Called from test_clear_page_writeback().
  */
-static inline void __wb_writeout_inc(struct bdi_writeback *wb)
+static inline void __wb_writeout_add(struct bdi_writeback *wb, long bytes)
 {
 	struct wb_domain *cgdom;
 
-	inc_wb_stat(wb, WB_WRITTEN);
+	__add_wb_stat(wb, WB_WRITTEN_BYTES, bytes);
 	wb_domain_writeout_inc(&global_wb_domain, &wb->completions,
 			       wb->bdi->max_prop_frac);
 
@@ -611,15 +611,15 @@ static inline void __wb_writeout_inc(struct bdi_writeback *wb)
 				       wb->bdi->max_prop_frac);
 }
 
-void wb_writeout_inc(struct bdi_writeback *wb)
+void wb_writeout_add(struct bdi_writeback *wb, long bytes)
 {
 	unsigned long flags;
 
 	local_irq_save(flags);
-	__wb_writeout_inc(wb);
+	__wb_writeout_add(wb, bytes);
 	local_irq_restore(flags);
 }
-EXPORT_SYMBOL_GPL(wb_writeout_inc);
+EXPORT_SYMBOL_GPL(wb_writeout_add);
 
 /*
  * On idle system, we can be called long after we scheduled because we use
@@ -1362,8 +1362,8 @@ static void __wb_update_bandwidth(struct dirty_throttle_control *gdtc,
 	if (elapsed < BANDWIDTH_INTERVAL)
 		return;
 
-	dirtied = percpu_counter_read(&wb->stat[WB_DIRTIED]);
-	written = percpu_counter_read(&wb->stat[WB_WRITTEN]);
+	dirtied = percpu_counter_read(&wb->stat[WB_DIRTIED_BYTES]) >> PAGE_SHIFT;
+	written = percpu_counter_read(&wb->stat[WB_WRITTEN_BYTES]) >> PAGE_SHIFT;
 
 	/*
 	 * Skip quiet periods when disk bandwidth is under-utilized.
@@ -2435,7 +2435,7 @@ void account_page_dirtied(struct page *page, struct address_space *mapping)
 		__inc_zone_page_state(page, NR_ZONE_WRITE_PENDING);
 		__inc_node_page_state(page, NR_DIRTIED);
 		inc_wb_stat(wb, WB_RECLAIMABLE);
-		inc_wb_stat(wb, WB_DIRTIED);
+		__add_wb_stat(wb, WB_DIRTIED_BYTES, PAGE_SIZE);
 		task_io_account_write(PAGE_SIZE);
 		current->nr_dirtied++;
 		this_cpu_inc(bdp_ratelimits);
@@ -2522,7 +2522,7 @@ void account_page_redirty(struct page *page)
 		wb = unlocked_inode_to_wb_begin(inode, &locked);
 		current->nr_dirtied--;
 		dec_node_page_state(page, NR_DIRTIED);
-		dec_wb_stat(wb, WB_DIRTIED);
+		__add_wb_stat(wb, WB_DIRTIED_BYTES, -(long)PAGE_SIZE);
 		unlocked_inode_to_wb_end(inode, locked);
 	}
 }
@@ -2744,7 +2744,7 @@ int test_clear_page_writeback(struct page *page)
 				struct bdi_writeback *wb = inode_to_wb(inode);
 
 				dec_wb_stat(wb, WB_WRITEBACK);
-				__wb_writeout_inc(wb);
+				__wb_writeout_add(wb, PAGE_SIZE);
 			}
 		}
 
Signature · 7 lines
2.7.5

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#3 lore raw

PATCH v3 3/10 lib: add a __fprop_add_percpu_max

In reply to Josef Bacik

From: Josef Bacik <[email protected]>

This helper allows us to add an arbitrary amount to the fprop structures.

---
 include/linux/flex_proportions.h | 11 +++++++++--
 lib/flex_proportions.c           |  9 +++++----
 2 files changed, 14 insertions(+), 6 deletions(-)
include/linux/flex_proportions.h +9 -2
index 0d348e011a6e..9f88684bf0a0 100644
@@ -83,8 +83,8 @@ struct fprop_local_percpu {
 int fprop_local_init_percpu(struct fprop_local_percpu *pl, gfp_t gfp);
 void fprop_local_destroy_percpu(struct fprop_local_percpu *pl);
 void __fprop_inc_percpu(struct fprop_global *p, struct fprop_local_percpu *pl);
-void __fprop_inc_percpu_max(struct fprop_global *p, struct fprop_local_percpu *pl,
-			    int max_frac);
+void __fprop_add_percpu_max(struct fprop_global *p, struct fprop_local_percpu *pl,
+			    unsigned long nr, int max_frac);
 void fprop_fraction_percpu(struct fprop_global *p,
 	struct fprop_local_percpu *pl, unsigned long *numerator,
 	unsigned long *denominator);
@@ -99,4 +99,11 @@ void fprop_inc_percpu(struct fprop_global *p, struct fprop_local_percpu *pl)
 	local_irq_restore(flags);
 }
 
+static inline
+void __fprop_inc_percpu_max(struct fprop_global *p,
+			    struct fprop_local_percpu *pl, int max_frac)
+{
+	__fprop_add_percpu_max(p, pl, 1, max_frac);
+}
+
 #endif
lib/flex_proportions.c +5 -4
index 2cc1f94e03a1..31003989d34a 100644
@@ -255,8 +255,9 @@ void fprop_fraction_percpu(struct fprop_global *p,
  * Like __fprop_inc_percpu() except that event is counted only if the given
  * type has fraction smaller than @max_frac/FPROP_FRAC_BASE
  */
-void __fprop_inc_percpu_max(struct fprop_global *p,
-			    struct fprop_local_percpu *pl, int max_frac)
+void __fprop_add_percpu_max(struct fprop_global *p,
+			    struct fprop_local_percpu *pl, unsigned long nr,
+			    int max_frac)
 {
 	if (unlikely(max_frac < FPROP_FRAC_BASE)) {
 		unsigned long numerator, denominator;
@@ -267,6 +268,6 @@ void __fprop_inc_percpu_max(struct fprop_global *p,
 			return;
 	} else
 		fprop_reflect_period_percpu(p, pl);
-	percpu_counter_add_batch(&pl->events, 1, PROP_BATCH);
-	percpu_counter_add(&p->events, 1);
+	percpu_counter_add_batch(&pl->events, nr, PROP_BATCH);
+	percpu_counter_add(&p->events, nr);
 }
Signature · 7 lines
2.7.5

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
maintainer Reviewed-by on v3 3/10
#4 lore raw

Re: [PATCH v3 03/10] lib: add a __fprop_add_percpu_max

Quoted 6 lines · Josef Bacik

From: Josef Bacik <[email protected]>

This helper allows us to add an arbitrary amount to the fprop structures.

Looks good. You can add:

Honza

Quoted 60 lines
---
 include/linux/flex_proportions.h | 11 +++++++++--
 lib/flex_proportions.c           |  9 +++++----
 2 files changed, 14 insertions(+), 6 deletions(-)
include/linux/flex_proportions.h +9 -2
index 0d348e011a6e..9f88684bf0a0 100644
@@ -83,8 +83,8 @@ struct fprop_local_percpu {
 int fprop_local_init_percpu(struct fprop_local_percpu *pl, gfp_t gfp);
 void fprop_local_destroy_percpu(struct fprop_local_percpu *pl);
 void __fprop_inc_percpu(struct fprop_global *p, struct fprop_local_percpu *pl);
-void __fprop_inc_percpu_max(struct fprop_global *p, struct fprop_local_percpu *pl,
-			    int max_frac);
+void __fprop_add_percpu_max(struct fprop_global *p, struct fprop_local_percpu *pl,
+			    unsigned long nr, int max_frac);
 void fprop_fraction_percpu(struct fprop_global *p,
 	struct fprop_local_percpu *pl, unsigned long *numerator,
 	unsigned long *denominator);
@@ -99,4 +99,11 @@ void fprop_inc_percpu(struct fprop_global *p, struct fprop_local_percpu *pl)
 	local_irq_restore(flags);
 }
 
+static inline
+void __fprop_inc_percpu_max(struct fprop_global *p,
+			    struct fprop_local_percpu *pl, int max_frac)
+{
+	__fprop_add_percpu_max(p, pl, 1, max_frac);
+}
+
 #endif
lib/flex_proportions.c +5 -4
index 2cc1f94e03a1..31003989d34a 100644
@@ -255,8 +255,9 @@ void fprop_fraction_percpu(struct fprop_global *p,
  * Like __fprop_inc_percpu() except that event is counted only if the given
  * type has fraction smaller than @max_frac/FPROP_FRAC_BASE
  */
-void __fprop_inc_percpu_max(struct fprop_global *p,
-			    struct fprop_local_percpu *pl, int max_frac)
+void __fprop_add_percpu_max(struct fprop_global *p,
+			    struct fprop_local_percpu *pl, unsigned long nr,
+			    int max_frac)
 {
 	if (unlikely(max_frac < FPROP_FRAC_BASE)) {
 		unsigned long numerator, denominator;
@@ -267,6 +268,6 @@ void __fprop_inc_percpu_max(struct fprop_global *p,
 			return;
 	} else
 		fprop_reflect_period_percpu(p, pl);
-	percpu_counter_add_batch(&pl->events, 1, PROP_BATCH);
-	percpu_counter_add(&p->events, 1);
+	percpu_counter_add_batch(&pl->events, nr, PROP_BATCH);
+	percpu_counter_add(&p->events, nr);
 }
Signature · 1 line
2.7.5
Signature · 8 lines
Jan Kara <[email protected]>
SUSE Labs, CR

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#5 lore raw

PATCH v3 4/10 writeback: convert the flexible prop stuff to bytes

In reply to Josef Bacik

From: Josef Bacik <[email protected]>

The flexible proportions were all page based, but now that we are doing metadata writeout that can be smaller or larger than page size we need to account for this in bytes instead of number of pages.

---
 lib/flex_proportions.c |  2 +-
 mm/page-writeback.c    | 10 +++++-----
 2 files changed, 6 insertions(+), 6 deletions(-)
lib/flex_proportions.c +1 -1
index 31003989d34a..fd95791a2c93 100644
@@ -166,7 +166,7 @@ void fprop_fraction_single(struct fprop_global *p,
 /*
  * ---- PERCPU ----
  */
-#define PROP_BATCH (8*(1+ilog2(nr_cpu_ids)))
+#define PROP_BATCH (8*PAGE_SIZE*(1+ilog2(nr_cpu_ids)))
 
 int fprop_local_init_percpu(struct fprop_local_percpu *pl, gfp_t gfp)
 {
mm/page-writeback.c +5 -5
index e4563645749a..2a1994194cc1 100644
@@ -574,11 +574,11 @@ static unsigned long wp_next_time(unsigned long cur_time)
 	return cur_time;
 }
 
-static void wb_domain_writeout_inc(struct wb_domain *dom,
+static void wb_domain_writeout_add(struct wb_domain *dom,
 				   struct fprop_local_percpu *completions,
-				   unsigned int max_prop_frac)
+				   long bytes, unsigned int max_prop_frac)
 {
-	__fprop_inc_percpu_max(&dom->completions, completions,
+	__fprop_add_percpu_max(&dom->completions, completions, bytes,
 			       max_prop_frac);
 	/* First event after period switching was turned off? */
 	if (unlikely(!dom->period_time)) {
@@ -602,12 +602,12 @@ static inline void __wb_writeout_add(struct bdi_writeback *wb, long bytes)
 	struct wb_domain *cgdom;
 
 	__add_wb_stat(wb, WB_WRITTEN_BYTES, bytes);
-	wb_domain_writeout_inc(&global_wb_domain, &wb->completions,
+	wb_domain_writeout_add(&global_wb_domain, &wb->completions, bytes,
 			       wb->bdi->max_prop_frac);
 
 	cgdom = mem_cgroup_wb_domain(wb);
 	if (cgdom)
-		wb_domain_writeout_inc(cgdom, wb_memcg_completions(wb),
+		wb_domain_writeout_add(cgdom, wb_memcg_completions(wb), bytes,
 				       wb->bdi->max_prop_frac);
 }
 
Signature · 7 lines
2.7.5

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#6 lore raw

PATCH v3 5/10 writeback: add counters for metadata usage

In reply to Josef Bacik

From: Josef Bacik <[email protected]>

Btrfs has no bounds except memory on the amount of dirty memory that we have in use for metadata. Historically we have used a special inode so we could take advantage of the balance_dirty_pages throttling that comes with using pagecache. However as we'd like to support different blocksizes it would be nice to not have to rely on pagecache, but still get the balance_dirty_pages throttling without having to do it ourselves.

So introduce *METADATA_DIRTY_BYTES and *METADATA_WRITEBACK_BYTES. These are zone and bdi_writeback counters to keep track of how many bytes we have in flight for METADATA. We need to count in bytes as blocksizes could be percentages of pagesize. We simply convert the bytes to number of pages where it is needed for the throttling.

Also introduce NR_METADATA_BYTES so we can keep track of the total amount of pages used for metadata on the system. This is also needed so things like dirty throttling know that this is dirtyable memory as well and easily reclaimed.

---
 drivers/base/node.c              |   8 +++
 fs/fs-writeback.c                |   2 +
 fs/proc/meminfo.c                |   8 +++
 include/linux/backing-dev-defs.h |   2 +
 include/linux/mm.h               |   9 +++
 include/linux/mmzone.h           |  10 +++
 include/trace/events/writeback.h |  13 +++-
 mm/backing-dev.c                 |   4 ++
 mm/page-writeback.c              | 142 +++++++++++++++++++++++++++++++++++----
 mm/page_alloc.c                  |  20 ++++--
 mm/util.c                        |   1 +
 mm/vmscan.c                      |   3 +-
 mm/vmstat.c                      |  10 +++
 13 files changed, 211 insertions(+), 21 deletions(-)
drivers/base/node.c +8 -0
index 3855902f2c5b..a39cecc8957a 100644
@@ -51,6 +51,8 @@ static DEVICE_ATTR(cpumap,  S_IRUGO, node_read_cpumask, NULL);
 static DEVICE_ATTR(cpulist, S_IRUGO, node_read_cpulist, NULL);
 
 #define K(x) ((x) << (PAGE_SHIFT - 10))
+#define BtoK(x) ((x) >> 10)
+
 static ssize_t node_read_meminfo(struct device *dev,
 			struct device_attribute *attr, char *buf)
 {
@@ -99,7 +101,10 @@ static ssize_t node_read_meminfo(struct device *dev,
 #endif
 	n += sprintf(buf + n,
 		       "Node %d Dirty:          %8lu kB\n"
+		       "Node %d MetadataDirty:	%8lu kB\n"
 		       "Node %d Writeback:      %8lu kB\n"
+		       "Node %d MetaWriteback:  %8lu kB\n"
+		       "Node %d Metadata:       %8lu kB\n"
 		       "Node %d FilePages:      %8lu kB\n"
 		       "Node %d Mapped:         %8lu kB\n"
 		       "Node %d AnonPages:      %8lu kB\n"
@@ -119,8 +124,11 @@ static ssize_t node_read_meminfo(struct device *dev,
 #endif
 			,
 		       nid, K(node_page_state(pgdat, NR_FILE_DIRTY)),
+		       nid, BtoK(node_page_state(pgdat, NR_METADATA_DIRTY_BYTES)),
 		       nid, K(node_page_state(pgdat, NR_WRITEBACK)),
+		       nid, BtoK(node_page_state(pgdat, NR_METADATA_WRITEBACK_BYTES)),
 		       nid, K(node_page_state(pgdat, NR_FILE_PAGES)),
+		       nid, BtoK(node_page_state(pgdat, NR_METADATA_BYTES)),
 		       nid, K(node_page_state(pgdat, NR_FILE_MAPPED)),
 		       nid, K(node_page_state(pgdat, NR_ANON_MAPPED)),
 		       nid, K(i.sharedram),
fs/fs-writeback.c +2 -0
index 245c430a2e41..987448ed7698 100644
@@ -1814,6 +1814,7 @@ static struct wb_writeback_work *get_next_work_item(struct bdi_writeback *wb)
 	return work;
 }
 
+#define BtoP(x) ((x) >> PAGE_SHIFT)
 /*
  * Add in the number of potentially dirty inodes, because each inode
  * write can dirty pagecache in the underlying blockdev.
@@ -1822,6 +1823,7 @@ static unsigned long get_nr_dirty_pages(void)
 {
 	return global_node_page_state(NR_FILE_DIRTY) +
 		global_node_page_state(NR_UNSTABLE_NFS) +
+		BtoP(global_node_page_state(NR_METADATA_DIRTY_BYTES)) +
 		get_nr_dirty_inodes();
 }
 
fs/proc/meminfo.c +8 -0
index cdd979724c74..fa1fd24a4d99 100644
@@ -42,6 +42,8 @@ static void show_val_kb(struct seq_file *m, const char *s, unsigned long num)
 	seq_write(m, " kB\n", 4);
 }
 
+#define BtoP(x) ((x) >> PAGE_SHIFT)
+
 static int meminfo_proc_show(struct seq_file *m, void *v)
 {
 	struct sysinfo i;
@@ -71,6 +73,8 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
 	show_val_kb(m, "Buffers:        ", i.bufferram);
 	show_val_kb(m, "Cached:         ", cached);
 	show_val_kb(m, "SwapCached:     ", total_swapcache_pages());
+	show_val_kb(m, "Metadata:       ",
+		    BtoP(global_node_page_state(NR_METADATA_BYTES)));
 	show_val_kb(m, "Active:         ", pages[LRU_ACTIVE_ANON] +
 					   pages[LRU_ACTIVE_FILE]);
 	show_val_kb(m, "Inactive:       ", pages[LRU_INACTIVE_ANON] +
@@ -98,8 +102,12 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
 	show_val_kb(m, "SwapFree:       ", i.freeswap);
 	show_val_kb(m, "Dirty:          ",
 		    global_node_page_state(NR_FILE_DIRTY));
+	show_val_kb(m, "MetadataDirty:  ",
+		    BtoP(global_node_page_state(NR_METADATA_DIRTY_BYTES)));
 	show_val_kb(m, "Writeback:      ",
 		    global_node_page_state(NR_WRITEBACK));
+	show_val_kb(m, "MetaWriteback:  ",
+		    BtoP(global_node_page_state(NR_METADATA_WRITEBACK_BYTES)));
 	show_val_kb(m, "AnonPages:      ",
 		    global_node_page_state(NR_ANON_MAPPED));
 	show_val_kb(m, "Mapped:         ",
include/linux/backing-dev-defs.h +2 -0
index ded45ac2cec7..78c65e2910dc 100644
@@ -38,6 +38,8 @@ enum wb_stat_item {
 	WB_WRITEBACK,
 	WB_DIRTIED_BYTES,
 	WB_WRITTEN_BYTES,
+	WB_METADATA_DIRTY_BYTES,
+	WB_METADATA_WRITEBACK_BYTES,
 	NR_WB_STAT_ITEMS
 };
 
include/linux/mm.h +9 -0
index f8c10d336e42..e14ada96af25 100644
@@ -32,6 +32,7 @@ struct file_ra_state;
 struct user_struct;
 struct writeback_control;
 struct bdi_writeback;
+struct backing_dev_info;
 
 void init_mm_internals(void);
 
@@ -1428,6 +1429,14 @@ int redirty_page_for_writepage(struct writeback_control *wbc,
 void account_page_dirtied(struct page *page, struct address_space *mapping);
 void account_page_cleaned(struct page *page, struct address_space *mapping,
 			  struct bdi_writeback *wb);
+void account_metadata_dirtied(struct page *page, struct backing_dev_info *bdi,
+			      long bytes);
+void account_metadata_cleaned(struct page *page, struct backing_dev_info *bdi,
+			      long bytes);
+void account_metadata_writeback(struct page *page,
+				struct backing_dev_info *bdi, long bytes);
+void account_metadata_end_writeback(struct page *page,
+				    struct backing_dev_info *bdi, long bytes);
 int set_page_dirty(struct page *page);
 int set_page_dirty_lock(struct page *page);
 void cancel_dirty_page(struct page *page);
include/linux/mmzone.h +10 -0
index 356a814e7c8e..48de090f5a07 100644
@@ -179,9 +179,19 @@ enum node_stat_item {
 	NR_VMSCAN_IMMEDIATE,	/* Prioritise for reclaim when writeback ends */
 	NR_DIRTIED,		/* page dirtyings since bootup */
 	NR_WRITTEN,		/* page writings since bootup */
+	NR_METADATA_DIRTY_BYTES,	/* Metadata dirty bytes */
+	NR_METADATA_WRITEBACK_BYTES,	/* Metadata writeback bytes */
+	NR_METADATA_BYTES,	/* total metadata bytes in use. */
 	NR_VM_NODE_STAT_ITEMS
 };
 
+static inline int is_bytes_node_stat(enum node_stat_item item)
+{
+	return (item == NR_METADATA_DIRTY_BYTES ||
+		item == NR_METADATA_WRITEBACK_BYTES ||
+		item == NR_METADATA_BYTES);
+}
+
 /*
  * We do arithmetic on the LRU lists in various places in the code,
  * so it is important to keep the active lists LRU_ACTIVE higher in
include/trace/events/writeback.h +11 -2
index 9b57f014d79d..989cdae363db 100644
@@ -390,6 +390,8 @@ TRACE_EVENT(writeback_queue_io,
 	)
 );
 
+#define BtoP(x) ((x) >> PAGE_SHIFT)
+
 TRACE_EVENT(global_dirty_state,
 
 	TP_PROTO(unsigned long background_thresh,
@@ -402,7 +404,9 @@ TRACE_EVENT(global_dirty_state,
 
 	TP_STRUCT__entry(
 		__field(unsigned long,	nr_dirty)
+		__field(unsigned long,	nr_metadata_dirty)
 		__field(unsigned long,	nr_writeback)
+		__field(unsigned long,	nr_metadata_writeback)
 		__field(unsigned long,	nr_unstable)
 		__field(unsigned long,	background_thresh)
 		__field(unsigned long,	dirty_thresh)
@@ -413,7 +417,9 @@ TRACE_EVENT(global_dirty_state,
 
 	TP_fast_assign(
 		__entry->nr_dirty	= global_node_page_state(NR_FILE_DIRTY);
+		__entry->nr_metadata_dirty = BtoP(global_node_page_state(NR_METADATA_DIRTY_BYTES));
 		__entry->nr_writeback	= global_node_page_state(NR_WRITEBACK);
+		__entry->nr_metadata_dirty = BtoP(global_node_page_state(NR_METADATA_WRITEBACK_BYTES));
 		__entry->nr_unstable	= global_node_page_state(NR_UNSTABLE_NFS);
 		__entry->nr_dirtied	= global_node_page_state(NR_DIRTIED);
 		__entry->nr_written	= global_node_page_state(NR_WRITTEN);
@@ -424,7 +430,8 @@ TRACE_EVENT(global_dirty_state,
 
 	TP_printk("dirty=%lu writeback=%lu unstable=%lu "
 		  "bg_thresh=%lu thresh=%lu limit=%lu "
-		  "dirtied=%lu written=%lu",
+		  "dirtied=%lu written=%lu metadata_dirty=%lu "
+		  "metadata_writeback=%lu",
 		  __entry->nr_dirty,
 		  __entry->nr_writeback,
 		  __entry->nr_unstable,
@@ -432,7 +439,9 @@ TRACE_EVENT(global_dirty_state,
 		  __entry->dirty_thresh,
 		  __entry->dirty_limit,
 		  __entry->nr_dirtied,
-		  __entry->nr_written
+		  __entry->nr_written,
+		  __entry->nr_metadata_dirty,
+		  __entry->nr_metadata_writeback
 	)
 );
 
mm/backing-dev.c +4 -0
index 62a332a91b38..0aad67bc0898 100644
@@ -77,6 +77,8 @@ static int bdi_debug_stats_show(struct seq_file *m, void *v)
 		   "BackgroundThresh:   %10lu kB\n"
 		   "BdiDirtiedBytes:    %10lu kB\n"
 		   "BdiWrittenBytes:    %10lu kB\n"
+		   "BdiMetadataDirty:   %10lu kB\n"
+		   "BdiMetaWriteback:	%10lu kB\n"
 		   "BdiWriteBandwidth:  %10lu kBps\n"
 		   "b_dirty:            %10lu\n"
 		   "b_io:               %10lu\n"
@@ -91,6 +93,8 @@ static int bdi_debug_stats_show(struct seq_file *m, void *v)
 		   K(background_thresh),
 		   (unsigned long) BtoK(wb_stat(wb, WB_DIRTIED_BYTES)),
 		   (unsigned long) BtoK(wb_stat(wb, WB_WRITTEN_BYTES)),
+		   (unsigned long) BtoK(wb_stat(wb, WB_METADATA_DIRTY_BYTES)),
+		   (unsigned long) BtoK(wb_stat(wb, WB_METADATA_WRITEBACK_BYTES)),
 		   (unsigned long) K(wb->write_bandwidth),
 		   nr_dirty,
 		   nr_io,
mm/page-writeback.c +128 -14

234 lines not on this page · raw message

mm/page_alloc.c +16 -4
index c841af88836a..aab0dd6aa8d7 100644
@@ -4640,6 +4640,8 @@ static bool show_mem_node_skip(unsigned int flags, int nid, nodemask_t *nodemask
 }
 
 #define K(x) ((x) << (PAGE_SHIFT-10))
+#define BtoK(x) ((x) >> 10)
+#define BtoP(x) ((x) >> PAGE_SHIFT)
 
 static void show_migration_types(unsigned char type)
 {
@@ -4694,10 +4696,11 @@ void show_free_areas(unsigned int filter, nodemask_t *nodemask)
 
 	printk("active_anon:%lu inactive_anon:%lu isolated_anon:%lu\n"
 		" active_file:%lu inactive_file:%lu isolated_file:%lu\n"
-		" unevictable:%lu dirty:%lu writeback:%lu unstable:%lu\n"
-		" slab_reclaimable:%lu slab_unreclaimable:%lu\n"
-		" mapped:%lu shmem:%lu pagetables:%lu bounce:%lu\n"
-		" free:%lu free_pcp:%lu free_cma:%lu\n",
+		" unevictable:%lu metadata:%lu dirty:%lu metadata_dirty:%lu\n"
+		" writeback:%lu unstable:%lu metadata_writeback:%lu\n"
+		" slab_reclaimable:%lu slab_unreclaimable:%lu mapped:%lu\n"
+		" shmem:%lu pagetables:%lu bounce:%lu free:%lu free_pcp:%lu\n"
+	        " free_cma:%lu\n",
 		global_node_page_state(NR_ACTIVE_ANON),
 		global_node_page_state(NR_INACTIVE_ANON),
 		global_node_page_state(NR_ISOLATED_ANON),
@@ -4705,9 +4708,12 @@ void show_free_areas(unsigned int filter, nodemask_t *nodemask)
 		global_node_page_state(NR_INACTIVE_FILE),
 		global_node_page_state(NR_ISOLATED_FILE),
 		global_node_page_state(NR_UNEVICTABLE),
+		BtoP(global_node_page_state(NR_METADATA_BYTES)),
 		global_node_page_state(NR_FILE_DIRTY),
+		BtoP(global_node_page_state(NR_METADATA_DIRTY_BYTES)),
 		global_node_page_state(NR_WRITEBACK),
 		global_node_page_state(NR_UNSTABLE_NFS),
+		BtoP(global_node_page_state(NR_METADATA_WRITEBACK_BYTES)),
 		global_node_page_state(NR_SLAB_RECLAIMABLE),
 		global_node_page_state(NR_SLAB_UNRECLAIMABLE),
 		global_node_page_state(NR_FILE_MAPPED),
@@ -4730,9 +4736,12 @@ void show_free_areas(unsigned int filter, nodemask_t *nodemask)
 			" unevictable:%lukB"
 			" isolated(anon):%lukB"
 			" isolated(file):%lukB"
+			" metadata:%lukB"
 			" mapped:%lukB"
 			" dirty:%lukB"
+			" metadata_dirty:%lukB"
 			" writeback:%lukB"
+			" metadata_writeback:%lukB"
 			" shmem:%lukB"
 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
 			" shmem_thp: %lukB"
@@ -4751,9 +4760,12 @@ void show_free_areas(unsigned int filter, nodemask_t *nodemask)
 			K(node_page_state(pgdat, NR_UNEVICTABLE)),
 			K(node_page_state(pgdat, NR_ISOLATED_ANON)),
 			K(node_page_state(pgdat, NR_ISOLATED_FILE)),
+			BtoK(node_page_state(pgdat, NR_METADATA_BYTES)),
 			K(node_page_state(pgdat, NR_FILE_MAPPED)),
 			K(node_page_state(pgdat, NR_FILE_DIRTY)),
+			BtoK(node_page_state(pgdat, NR_METADATA_DIRTY_BYTES)),
 			K(node_page_state(pgdat, NR_WRITEBACK)),
+			BtoK(node_page_state(pgdat, NR_METADATA_WRITEBACK_BYTES)),
 			K(node_page_state(pgdat, NR_SHMEM)),
 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
 			K(node_page_state(pgdat, NR_SHMEM_THPS) * HPAGE_PMD_NR),
mm/util.c +1 -0
index 34e57fae959d..681d62631ee0 100644
@@ -616,6 +616,7 @@ int __vm_enough_memory(struct mm_struct *mm, long pages, int cap_sys_admin)
 	if (sysctl_overcommit_memory == OVERCOMMIT_GUESS) {
 		free = global_zone_page_state(NR_FREE_PAGES);
 		free += global_node_page_state(NR_FILE_PAGES);
+		free += global_node_page_state(NR_METADATA_BYTES) >> PAGE_SHIFT;
 
 		/*
 		 * shmem pages shouldn't be counted as free in this
mm/vmscan.c +2 -1
index 13d711dd8776..8589a718a9c2 100644
@@ -225,7 +225,8 @@ unsigned long pgdat_reclaimable_pages(struct pglist_data *pgdat)
 
 	nr = node_page_state_snapshot(pgdat, NR_ACTIVE_FILE) +
 	     node_page_state_snapshot(pgdat, NR_INACTIVE_FILE) +
-	     node_page_state_snapshot(pgdat, NR_ISOLATED_FILE);
+	     node_page_state_snapshot(pgdat, NR_ISOLATED_FILE) +
+	     (node_page_state_snapshot(pgdat, NR_METADATA_BYTES) >> PAGE_SHIFT);
 
 	if (get_nr_swap_pages() > 0)
 		nr += node_page_state_snapshot(pgdat, NR_ACTIVE_ANON) +
mm/vmstat.c +10 -0
index 4bb13e72ac97..0b32e6381590 100644
@@ -273,6 +273,13 @@ void __mod_node_page_state(struct pglist_data *pgdat, enum node_stat_item item,
 
 	t = __this_cpu_read(pcp->stat_threshold);
 
+	/*
+	 * If this item is counted in bytes and not pages adjust the threshold
+	 * accordingly.
+	 */
+	if (is_bytes_node_stat(item))
+		t <<= PAGE_SHIFT;
+
 	if (unlikely(x > t || x < -t)) {
 		node_page_state_add(x, pgdat, item);
 		x = 0;
@@ -1090,6 +1097,9 @@ const char * const vmstat_text[] = {
 	"nr_vmscan_immediate_reclaim",
 	"nr_dirtied",
 	"nr_written",
+	"nr_metadata_dirty_bytes",
+	"nr_metadata_writeback_bytes",
+	"nr_metadata_bytes",
 
 	/* enum writeback_stat_item counters */
 	"nr_dirty_threshold",
Signature · 7 lines
2.7.5

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
maintainer
#7 lore raw

Re: [PATCH v3 05/10] writeback: add counters for metadata usage

include/linux/mmzone.h enum node_stat_item { · line 186

Quoted 13 lines · Josef Bacik
include/linux/mmzone.h +3 -0
index 356a814e7c8e..48de090f5a07 100644
@@ -179,9 +179,19 @@ enum node_stat_item {
 	NR_VMSCAN_IMMEDIATE,	/* Prioritise for reclaim when writeback ends */
 	NR_DIRTIED,		/* page dirtyings since bootup */
 	NR_WRITTEN,		/* page writings since bootup */
+	NR_METADATA_DIRTY_BYTES,	/* Metadata dirty bytes */
+	NR_METADATA_WRITEBACK_BYTES,	/* Metadata writeback bytes */
+	NR_METADATA_BYTES,	/* total metadata bytes in use. */
 	NR_VM_NODE_STAT_ITEMS
 };

Please add here something like: "Warning: These counters will overflow on 32-bit machines if we ever have more than 2G of metadata on such machine! But kernel won't be able to address that easily either so it should not be a real issue."

Quoted 8 lines
mm/vmstat.c +0 -0
index 4bb13e72ac97..0b32e6381590 100644
@@ -273,6 +273,13 @@ void __mod_node_page_state(struct pglist_data *pgdat, enum node_stat_item item,
 
 	t = __this_cpu_read(pcp->stat_threshold);
 

mm/vmstat.c void __mod_node_page_state(struct pglist_data *pgdat, enum node_stat_item item, · line 285

Quoted 10 lines
mm/vmstat.c +7 -0
+	/*
+	 * If this item is counted in bytes and not pages adjust the threshold
+	 * accordingly.
+	 */
+	if (is_bytes_node_stat(item))
+		t <<= PAGE_SHIFT;
+
 	if (unlikely(x > t || x < -t)) {
 		node_page_state_add(x, pgdat, item);
 		x = 0;

This is wrong. The per-cpu counters are stored in s8 so you cannot just bump the threshold. I would just ignore the PCP counters for metadata (I don't think they are that critical for performance for metadata tracking) and add to the comment I've suggested above: "Also note that updates to these counters won't be batched using per-cpu counters since the updates are generally larger than the counter threshold."

Honza

Signature · 8 lines
Jan Kara <[email protected]>
SUSE Labs, CR

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#8 lore raw

PATCH v3 6/10 writeback: introduce super_operations->write_metadata

In reply to Josef Bacik

From: Josef Bacik <[email protected]>

Now that we have metadata counters in the VM, we need to provide a way to kick writeback on dirty metadata. Introduce super_operations->write_metadata. This allows file systems to deal with writing back any dirty metadata we need based on the writeback needs of the system. Since there is no inode to key off of we need a list in the bdi for dirty super blocks to be added. From there we can find any dirty sb's on the bdi we are currently doing writeback on and call into their ->write_metadata callback.

---
 fs/fs-writeback.c                | 72 ++++++++++++++++++++++++++++++++++++----
 fs/super.c                       |  6 ++++
 include/linux/backing-dev-defs.h |  2 ++
 include/linux/fs.h               |  4 +++
 mm/backing-dev.c                 |  2 ++
 5 files changed, 80 insertions(+), 6 deletions(-)
fs/fs-writeback.c +66 -6
index 987448ed7698..fba703dff678 100644
@@ -1479,6 +1479,31 @@ static long writeback_chunk_size(struct bdi_writeback *wb,
 	return pages;
 }
 
+static long writeback_sb_metadata(struct super_block *sb,
+				  struct bdi_writeback *wb,
+				  struct wb_writeback_work *work)
+{
+	struct writeback_control wbc = {
+		.sync_mode		= work->sync_mode,
+		.tagged_writepages	= work->tagged_writepages,
+		.for_kupdate		= work->for_kupdate,
+		.for_background		= work->for_background,
+		.for_sync		= work->for_sync,
+		.range_cyclic		= work->range_cyclic,
+		.range_start		= 0,
+		.range_end		= LLONG_MAX,
+	};
+	long write_chunk;
+
+	write_chunk = writeback_chunk_size(wb, work);
+	wbc.nr_to_write = write_chunk;
+	sb->s_op->write_metadata(sb, &wbc);
+	work->nr_pages -= write_chunk - wbc.nr_to_write;
+
+	return write_chunk - wbc.nr_to_write;
+}
+
+
 /*
  * Write a portion of b_io inodes which belong to @sb.
  *
@@ -1505,6 +1530,7 @@ static long writeback_sb_inodes(struct super_block *sb,
 	unsigned long start_time = jiffies;
 	long write_chunk;
 	long wrote = 0;  /* count both pages and inodes */
+	bool done = false;
 
 	while (!list_empty(&wb->b_io)) {
 		struct inode *inode = wb_inode(wb->b_io.prev);
@@ -1621,12 +1647,18 @@ static long writeback_sb_inodes(struct super_block *sb,
 		 * background threshold and other termination conditions.
 		 */
 		if (wrote) {
-			if (time_is_before_jiffies(start_time + HZ / 10UL))
-				break;
-			if (work->nr_pages <= 0)
+			if (time_is_before_jiffies(start_time + HZ / 10UL) ||
+			    work->nr_pages <= 0) {
+				done = true;
 				break;
+			}
 		}
 	}
+	if (!done && sb->s_op->write_metadata) {
+		spin_unlock(&wb->list_lock);
+		wrote += writeback_sb_metadata(sb, wb, work);
+		spin_lock(&wb->list_lock);
+	}
 	return wrote;
 }
 
@@ -1635,6 +1667,7 @@ static long __writeback_inodes_wb(struct bdi_writeback *wb,
 {
 	unsigned long start_time = jiffies;
 	long wrote = 0;
+	bool done = false;
 
 	while (!list_empty(&wb->b_io)) {
 		struct inode *inode = wb_inode(wb->b_io.prev);
@@ -1654,12 +1687,39 @@ static long __writeback_inodes_wb(struct bdi_writeback *wb,
 
 		/* refer to the same tests at the end of writeback_sb_inodes */
 		if (wrote) {
-			if (time_is_before_jiffies(start_time + HZ / 10UL))
-				break;
-			if (work->nr_pages <= 0)
+			if (time_is_before_jiffies(start_time + HZ / 10UL) ||
+			    work->nr_pages <= 0) {
+				done = true;
 				break;
+			}
 		}
 	}
+
+	if (!done && wb_stat(wb, WB_METADATA_DIRTY_BYTES)) {
+		LIST_HEAD(list);
+
+		spin_unlock(&wb->list_lock);
+		spin_lock(&wb->bdi->sb_list_lock);
+		list_splice_init(&wb->bdi->dirty_sb_list, &list);
+		while (!list_empty(&list)) {
+			struct super_block *sb;
+
+			sb = list_first_entry(&list, struct super_block,
+					      s_bdi_dirty_list);
+			list_move_tail(&sb->s_bdi_dirty_list,
+				       &wb->bdi->dirty_sb_list);
+			if (!sb->s_op->write_metadata)
+				continue;
+			if (!trylock_super(sb))
+				continue;
+			spin_unlock(&wb->bdi->sb_list_lock);
+			wrote += writeback_sb_metadata(sb, wb, work);
+			spin_lock(&wb->bdi->sb_list_lock);
+			up_read(&sb->s_umount);
+		}
+		spin_unlock(&wb->bdi->sb_list_lock);
+		spin_lock(&wb->list_lock);
+	}
 	/* Leave any unwritten inodes on b_io */
 	return wrote;
 }
fs/super.c +6 -0
index 166c4ee0d0ed..2290bef486a3 100644
@@ -214,6 +214,7 @@ static struct super_block *alloc_super(struct file_system_type *type, int flags,
 	spin_lock_init(&s->s_inode_list_lock);
 	INIT_LIST_HEAD(&s->s_inodes_wb);
 	spin_lock_init(&s->s_inode_wblist_lock);
+	INIT_LIST_HEAD(&s->s_bdi_dirty_list);
 
 	if (list_lru_init_memcg(&s->s_dentry_lru))
 		goto fail;
@@ -446,6 +447,11 @@ void generic_shutdown_super(struct super_block *sb)
 	spin_unlock(&sb_lock);
 	up_write(&sb->s_umount);
 	if (sb->s_bdi != &noop_backing_dev_info) {
+		if (!list_empty(&sb->s_bdi_dirty_list)) {
+			spin_lock(&sb->s_bdi->sb_list_lock);
+			list_del_init(&sb->s_bdi_dirty_list);
+			spin_unlock(&sb->s_bdi->sb_list_lock);
+		}
 		bdi_put(sb->s_bdi);
 		sb->s_bdi = &noop_backing_dev_info;
 	}
include/linux/backing-dev-defs.h +2 -0
index 78c65e2910dc..a961f9a51a38 100644
@@ -176,6 +176,8 @@ struct backing_dev_info {
 
 	struct timer_list laptop_mode_wb_timer;
 
+	spinlock_t sb_list_lock;
+	struct list_head dirty_sb_list;
 #ifdef CONFIG_DEBUG_FS
 	struct dentry *debug_dir;
 	struct dentry *debug_stats;
include/linux/fs.h +4 -0
index 339e73742e73..298a28eaed2b 100644
@@ -1440,6 +1440,8 @@ struct super_block {
 
 	spinlock_t		s_inode_wblist_lock;
 	struct list_head	s_inodes_wb;	/* writeback inodes */
+
+	struct list_head        s_bdi_dirty_list;
 } __randomize_layout;
 
 /* Helper functions so that in most cases filesystems will
@@ -1830,6 +1832,8 @@ struct super_operations {
 				  struct shrink_control *);
 	long (*free_cached_objects)(struct super_block *,
 				    struct shrink_control *);
+	void (*write_metadata)(struct super_block *sb,
+			       struct writeback_control *wbc);
 };
 
 /*
mm/backing-dev.c +2 -0
index 0aad67bc0898..e3aa4e0dd15e 100644
@@ -839,6 +839,8 @@ static int bdi_init(struct backing_dev_info *bdi)
 	bdi->max_prop_frac = FPROP_FRAC_BASE;
 	INIT_LIST_HEAD(&bdi->bdi_list);
 	INIT_LIST_HEAD(&bdi->wb_list);
+	INIT_LIST_HEAD(&bdi->dirty_sb_list);
+	spin_lock_init(&bdi->sb_list_lock);
 	init_waitqueue_head(&bdi->wb_waitq);
 
 	ret = cgwb_bdi_init(bdi);
Signature · 7 lines
2.7.5

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#9 lore raw

Re: [PATCH v3 06/10] writeback: introduce super_operations->write_metadata

Quoted 41 lines · Josef Bacik

From: Josef Bacik <[email protected]>

Now that we have metadata counters in the VM, we need to provide a way to kick writeback on dirty metadata. Introduce super_operations->write_metadata. This allows file systems to deal with writing back any dirty metadata we need based on the writeback needs of the system. Since there is no inode to key off of we need a list in the bdi for dirty super blocks to be added. From there we can find any dirty sb's on the bdi we are currently doing writeback on and call into their ->write_metadata callback.

---
 fs/fs-writeback.c                | 72 ++++++++++++++++++++++++++++++++++++----
 fs/super.c                       |  6 ++++
 include/linux/backing-dev-defs.h |  2 ++
 include/linux/fs.h               |  4 +++
 mm/backing-dev.c                 |  2 ++
 5 files changed, 80 insertions(+), 6 deletions(-)
fs/fs-writeback.c +12 -0
index 987448ed7698..fba703dff678 100644
@@ -1479,6 +1479,31 @@ static long writeback_chunk_size(struct bdi_writeback *wb,
 	return pages;
 }
 
+static long writeback_sb_metadata(struct super_block *sb,
+				  struct bdi_writeback *wb,
+				  struct wb_writeback_work *work)
+{
+	struct writeback_control wbc = {
+		.sync_mode		= work->sync_mode,
+		.tagged_writepages	= work->tagged_writepages,
+		.for_kupdate		= work->for_kupdate,
+		.for_background		= work->for_background,
+		.for_sync		= work->for_sync,
+		.range_cyclic		= work->range_cyclic,
+		.range_start		= 0,

fs/fs-writeback.c static long writeback_chunk_size(struct bdi_writeback *wb, · line 1503

Quoted 10 lines
fs/fs-writeback.c +10 -0
+		.range_end		= LLONG_MAX,
+	};
+	long write_chunk;
+
+	write_chunk = writeback_chunk_size(wb, work);
+	wbc.nr_to_write = write_chunk;
+	sb->s_op->write_metadata(sb, &wbc);
+	work->nr_pages -= write_chunk - wbc.nr_to_write;
+
+	return write_chunk - wbc.nr_to_write;

Ok, writeback_chunk_size() returns a page count. We've already gone through the "metadata is not page sized" dance on the dirty accounting side, so how are we supposed to use pages to account for metadata writeback?

And, from what I can tell, if work->sync_mode = WB_SYNC_ALL or work->tagged_writepages is set, this will basically tell us to flush the entire dirty metadata cache because write_chunk will get set to LONG_MAX.

IOWs, this would appear to me to change sync() behaviour quite dramatically on filesystems where ->write_metadata is implemented. That is, instead of leaving all the metadata dirty in memory and just forcing the journal to stable storage, filesystems will be told to also write back all their dirty metadata before sync() returns, even though it is not necessary to provide correct sync() semantics....

Mind you, writeback invocation is so convoluted now I could easily be mis-interpretting this code, but it does seem to me like this code is going to have some unintended behaviours....

Cheers,

Dave.

Signature · 8 lines
Dave Chinner
[email protected]

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#10 lore raw

Re: [PATCH v3 06/10] writeback: introduce super_operations->write_metadata

Quoted 49 lines · Dave Chinner
Quoted 48 lines · Josef Bacik

From: Josef Bacik <[email protected]>

Now that we have metadata counters in the VM, we need to provide a way to kick writeback on dirty metadata. Introduce super_operations->write_metadata. This allows file systems to deal with writing back any dirty metadata we need based on the writeback needs of the system. Since there is no inode to key off of we need a list in the bdi for dirty super blocks to be added. From there we can find any dirty sb's on the bdi we are currently doing writeback on and call into their ->write_metadata callback.

---
 fs/fs-writeback.c                | 72 ++++++++++++++++++++++++++++++++++++----
 fs/super.c                       |  6 ++++
 include/linux/backing-dev-defs.h |  2 ++
 include/linux/fs.h               |  4 +++
 mm/backing-dev.c                 |  2 ++
 5 files changed, 80 insertions(+), 6 deletions(-)
fs/fs-writeback.c +19 -0
index 987448ed7698..fba703dff678 100644
@@ -1479,6 +1479,31 @@ static long writeback_chunk_size(struct bdi_writeback *wb,
 	return pages;
 }
 
+static long writeback_sb_metadata(struct super_block *sb,
+				  struct bdi_writeback *wb,
+				  struct wb_writeback_work *work)
+{
+	struct writeback_control wbc = {
+		.sync_mode		= work->sync_mode,
+		.tagged_writepages	= work->tagged_writepages,
+		.for_kupdate		= work->for_kupdate,
+		.for_background		= work->for_background,
+		.for_sync		= work->for_sync,
+		.range_cyclic		= work->range_cyclic,
+		.range_start		= 0,
+		.range_end		= LLONG_MAX,
+	};
+	long write_chunk;
+
+	write_chunk = writeback_chunk_size(wb, work);
+	wbc.nr_to_write = write_chunk;
+	sb->s_op->write_metadata(sb, &wbc);
Quoted 9 lines

fs/fs-writeback.c static long writeback_chunk_size(struct bdi_writeback *wb, · line 1503

Quoted 3 lines
fs/fs-writeback.c +3 -0
+	work->nr_pages -= write_chunk - wbc.nr_to_write;
+
+	return write_chunk - wbc.nr_to_write;

Ok, writeback_chunk_size() returns a page count. We've already gone through the "metadata is not page sized" dance on the dirty accounting side, so how are we supposed to use pages to account for metadata writeback?

This is just one of those things that's going to be slightly shitty. It's the same for memory reclaim, all of those places use pages so we just take METADATA_*_BYTES >> PAGE_SHIFT to get pages and figure it's close enough.

Quoted 5 lines

And, from what I can tell, if work->sync_mode = WB_SYNC_ALL or work->tagged_writepages is set, this will basically tell us to flush the entire dirty metadata cache because write_chunk will get set to LONG_MAX.

Quoted 7 lines

IOWs, this would appear to me to change sync() behaviour quite dramatically on filesystems where ->write_metadata is implemented. That is, instead of leaving all the metadata dirty in memory and just forcing the journal to stable storage, filesystems will be told to also write back all their dirty metadata before sync() returns, even though it is not necessary to provide correct sync() semantics....

Well for btrfs that's exactly what we have currently since it's just backed by an inode. Obviously this is different for journaled fs'es, but I assumed that in your case you would either not use this part of the infrastructure or simply ignore WB_SYNC_ALL and use WB_SYNC_NONE as a way to be nice under memory pressure or whatever.

Quoted 5 lines

Mind you, writeback invocation is so convoluted now I could easily be mis-interpretting this code, but it does seem to me like this code is going to have some unintended behaviours....

I don't think so, because right now this behavior is exactly what btrfs has currently with it's inode setup. I didn't really think the journaled use case out since you guys are already rate limited by the journal. If you would want to start using this stuff what would you like to see done instead? Thanks,

Josef

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#11 lore raw

Re: [PATCH v3 06/10] writeback: introduce super_operations->write_metadata

Quoted 60 lines · Josef Bacik
Quoted 49 lines · Dave Chinner
Quoted 48 lines · Josef Bacik

From: Josef Bacik <[email protected]>

Now that we have metadata counters in the VM, we need to provide a way to kick writeback on dirty metadata. Introduce super_operations->write_metadata. This allows file systems to deal with writing back any dirty metadata we need based on the writeback needs of the system. Since there is no inode to key off of we need a list in the bdi for dirty super blocks to be added. From there we can find any dirty sb's on the bdi we are currently doing writeback on and call into their ->write_metadata callback.

---
 fs/fs-writeback.c                | 72 ++++++++++++++++++++++++++++++++++++----
 fs/super.c                       |  6 ++++
 include/linux/backing-dev-defs.h |  2 ++
 include/linux/fs.h               |  4 +++
 mm/backing-dev.c                 |  2 ++
 5 files changed, 80 insertions(+), 6 deletions(-)
fs/fs-writeback.c +19 -0
index 987448ed7698..fba703dff678 100644
@@ -1479,6 +1479,31 @@ static long writeback_chunk_size(struct bdi_writeback *wb,
 	return pages;
 }
 
+static long writeback_sb_metadata(struct super_block *sb,
+				  struct bdi_writeback *wb,
+				  struct wb_writeback_work *work)
+{
+	struct writeback_control wbc = {
+		.sync_mode		= work->sync_mode,
+		.tagged_writepages	= work->tagged_writepages,
+		.for_kupdate		= work->for_kupdate,
+		.for_background		= work->for_background,
+		.for_sync		= work->for_sync,
+		.range_cyclic		= work->range_cyclic,
+		.range_start		= 0,
+		.range_end		= LLONG_MAX,
+	};
+	long write_chunk;
+
+	write_chunk = writeback_chunk_size(wb, work);
+	wbc.nr_to_write = write_chunk;
+	sb->s_op->write_metadata(sb, &wbc);
Quoted 9 lines

fs/fs-writeback.c static long writeback_chunk_size(struct bdi_writeback *wb, · line 1503

Quoted 3 lines
fs/fs-writeback.c +3 -0
+	work->nr_pages -= write_chunk - wbc.nr_to_write;
+
+	return write_chunk - wbc.nr_to_write;

Ok, writeback_chunk_size() returns a page count. We've already gone through the "metadata is not page sized" dance on the dirty accounting side, so how are we supposed to use pages to account for metadata writeback?

Quoted 3 lines

This is just one of those things that's going to be slightly shitty. It's the same for memory reclaim, all of those places use pages so we just take METADATA_*_BYTES >> PAGE_SHIFT to get pages and figure it's close enough.

Ok, so that isn't exactly easy to deal with, because all our metadata writeback is based on log sequence number targets (i.e. how far to push the tail of the log towards the current head). We've actually got no idea how pages/bytes actually map to a LSN target because while we might account a full buffer as dirty for memory reclaim purposes (up to 64k in size), we might have only logged 128 bytes of it.

i.e. if we are asked to push 2MB of metadata and we treat that as 2MB of log space (i.e. push target of tail LSN + 2MB) we could have logged several tens of megabytes of dirty metadata in that LSN range and have to flush it all. OTOH, if the buffers are fully logged, then that same target might only flush 1.5MB of metadata once all the log overhead is taken into account.

So there's a fairly large disconnect between the "flush N bytes of metadata" API and the "push to a target LSN" that XFS uses for flushing metadata in aged order. I'm betting that extN and otehr filesystems might have similar mismatches with their journal flushing...

Quoted 13 lines
Quoted 5 lines

And, from what I can tell, if work->sync_mode = WB_SYNC_ALL or work->tagged_writepages is set, this will basically tell us to flush the entire dirty metadata cache because write_chunk will get set to LONG_MAX.

Quoted 7 lines

IOWs, this would appear to me to change sync() behaviour quite dramatically on filesystems where ->write_metadata is implemented. That is, instead of leaving all the metadata dirty in memory and just forcing the journal to stable storage, filesystems will be told to also write back all their dirty metadata before sync() returns, even though it is not necessary to provide correct sync() semantics....

Quoted 2 lines

Well for btrfs that's exactly what we have currently since it's just backed by an inode.

Hmmmm. That explains a lot.

Seems to me that btrfs is the odd one out here, so I'm not sure a mechanism primarily designed for btrfs is going to work generically....

Quoted 4 lines

Obviously this is different for journaled fs'es, but I assumed that in your case you would either not use this part of the infrastructure or simply ignore WB_SYNC_ALL and use WB_SYNC_NONE as a way to be nice under memory pressure or whatever.

I don't think that designing an interface with the assumption other filesystems will abuse it until it works for them is a great process to follow...

Quoted 8 lines
Quoted 4 lines

Mind you, writeback invocation is so convoluted now I could easily be mis-interpretting this code, but it does seem to me like this code is going to have some unintended behaviours....

I don't think so, because right now this behavior is exactly what btrfs has currently with it's inode setup. I didn't really think the journaled use case out since you guys are already rate limited by the journal.

We are?

XFS is rate limited by metadata writeback, not journal throughput. Yes, journal space is limited by the metadata writeback rate, but journalling itself is not the bottleneck.

Quoted 2 lines

If you would want
to start using this stuff what would you like to see done instead? Thanks,

If this is all about reacting to memory pressure, then writeback is not the mechanism that should drive this writeback. Reacting to memory pressure is what shrinkers are for, and XFS already triggers metadata writeback on memory pressure. Hence I don't see how this writeback mechanism would help us if we have to abuse it to infer "memory pressure occurring"

What I was hoping for was this interface to be a mechanism to drive periodic background metadata writeback from the VFS so that when we start to run out of memory the VFS has already started to ramp up the rate of metadata writeback so we don't have huge amounts of dirty metadata to write back during superblock shrinker based reclaim.

i.e. it works more like dirty background data writeback, get's the amount of work to do from the amount of dirty metadata associated with the bdi and doesn't actually do anything when operations like sync() are run because there isn't a need to writeback metadata in those operations.

IOWs, treating metadata like it's one great big data inode doesn't seem to me to be the right abstraction to use for this - in most fileystems it's a bunch of objects with a complex dependency tree and unknown write ordering, not an inode full of data that can be sequentially written.

Maybe we need multiple ops with well defined behaviours. e.g. ->writeback_metadata() for background writeback, ->sync_metadata() for sync based operations. That way different filesystems can ignore the parts they don't need simply by not implementing those operations, and the writeback code doesn't need to try to cater for all operations through the one op. The writeback code should be cleaner, the filesystem code should be cleaner, and we can tailor the work guidelines for each operation separately so there's less mismatch between what writeback is asking and how filesystems track dirty metadata...

Cheers,

Dave.

Signature · 8 lines
Dave Chinner
[email protected]

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#12 lore raw

Re: [PATCH v3 06/10] writeback: introduce super_operations->write_metadata

Quoted 80 lines · Dave Chinner
Quoted 60 lines · Josef Bacik
Quoted 49 lines · Dave Chinner
Quoted 48 lines · Josef Bacik

From: Josef Bacik <[email protected]>

Now that we have metadata counters in the VM, we need to provide a way to kick writeback on dirty metadata. Introduce super_operations->write_metadata. This allows file systems to deal with writing back any dirty metadata we need based on the writeback needs of the system. Since there is no inode to key off of we need a list in the bdi for dirty super blocks to be added. From there we can find any dirty sb's on the bdi we are currently doing writeback on and call into their ->write_metadata callback.

---
 fs/fs-writeback.c                | 72 ++++++++++++++++++++++++++++++++++++----
 fs/super.c                       |  6 ++++
 include/linux/backing-dev-defs.h |  2 ++
 include/linux/fs.h               |  4 +++
 mm/backing-dev.c                 |  2 ++
 5 files changed, 80 insertions(+), 6 deletions(-)
fs/fs-writeback.c +19 -0
index 987448ed7698..fba703dff678 100644
@@ -1479,6 +1479,31 @@ static long writeback_chunk_size(struct bdi_writeback *wb,
 	return pages;
 }
 
+static long writeback_sb_metadata(struct super_block *sb,
+				  struct bdi_writeback *wb,
+				  struct wb_writeback_work *work)
+{
+	struct writeback_control wbc = {
+		.sync_mode		= work->sync_mode,
+		.tagged_writepages	= work->tagged_writepages,
+		.for_kupdate		= work->for_kupdate,
+		.for_background		= work->for_background,
+		.for_sync		= work->for_sync,
+		.range_cyclic		= work->range_cyclic,
+		.range_start		= 0,
+		.range_end		= LLONG_MAX,
+	};
+	long write_chunk;
+
+	write_chunk = writeback_chunk_size(wb, work);
+	wbc.nr_to_write = write_chunk;
+	sb->s_op->write_metadata(sb, &wbc);
Quoted 9 lines

fs/fs-writeback.c static long writeback_chunk_size(struct bdi_writeback *wb, · line 1503

Quoted 3 lines
fs/fs-writeback.c +3 -0
+	work->nr_pages -= write_chunk - wbc.nr_to_write;
+
+	return write_chunk - wbc.nr_to_write;

Ok, writeback_chunk_size() returns a page count. We've already gone through the "metadata is not page sized" dance on the dirty accounting side, so how are we supposed to use pages to account for metadata writeback?

Quoted 3 lines

This is just one of those things that's going to be slightly shitty. It's the same for memory reclaim, all of those places use pages so we just take METADATA_*_BYTES >> PAGE_SHIFT to get pages and figure it's close enough.

Ok, so that isn't exactly easy to deal with, because all our metadata writeback is based on log sequence number targets (i.e. how far to push the tail of the log towards the current head). We've actually got no idea how pages/bytes actually map to a LSN target because while we might account a full buffer as dirty for memory reclaim purposes (up to 64k in size), we might have only logged 128 bytes of it.

i.e. if we are asked to push 2MB of metadata and we treat that as 2MB of log space (i.e. push target of tail LSN + 2MB) we could have logged several tens of megabytes of dirty metadata in that LSN range and have to flush it all. OTOH, if the buffers are fully logged, then that same target might only flush 1.5MB of metadata once all the log overhead is taken into account.

Quoted 6 lines

So there's a fairly large disconnect between the "flush N bytes of metadata" API and the "push to a target LSN" that XFS uses for flushing metadata in aged order. I'm betting that extN and otehr filesystems might have similar mismatches with their journal flushing...

If there's not a correlation then there's no sense in xfs using this. If btrfs has 16gib of dirty metadata then that's exactly how much we have to write out, which is what this is designed for.

Quoted 13 lines
Quoted 13 lines
Quoted 12 lines

And, from what I can tell, if work->sync_mode = WB_SYNC_ALL or work->tagged_writepages is set, this will basically tell us to flush the entire dirty metadata cache because write_chunk will get set to LONG_MAX.

IOWs, this would appear to me to change sync() behaviour quite dramatically on filesystems where ->write_metadata is implemented. That is, instead of leaving all the metadata dirty in memory and just forcing the journal to stable storage, filesystems will be told to also write back all their dirty metadata before sync() returns, even though it is not necessary to provide correct sync() semantics....

Quoted 9 lines
Quoted 2 lines

Well for btrfs that's exactly what we have currently since it's just backed by an inode.

Hmmmm. That explains a lot.

Seems to me that btrfs is the odd one out here, so I'm not sure a mechanism primarily designed for btrfs is going to work generically....

The generic stuff is very lightweight specifically because we don't need a whole lot, just a way to get all of the balance dirty pages logic without duplicating it internally in btrfs.

Quoted 9 lines
Quoted 4 lines

Obviously this is different for journaled fs'es, but I assumed that in your case you would either not use this part of the infrastructure or simply ignore WB_SYNC_ALL and use WB_SYNC_NONE as a way to be nice under memory pressure or whatever.

I don't think that designing an interface with the assumption other filesystems will abuse it until it works for them is a great process to follow...

Again not really designing it with your stuff in mind. ext* and xfs already handle dirty metadata fine, btrfs is the odd man out so we need a little extra. It would be cool to at least use the accounting part of it in xfs and ext* so we could see how much of the system memory is in use by metadata, but I imagine the dirty metadata tracking is going to be mostly useless for you guys.

Quoted 9 lines
Quoted 8 lines
Quoted 4 lines

Mind you, writeback invocation is so convoluted now I could easily be mis-interpretting this code, but it does seem to me like this code is going to have some unintended behaviours....

I don't think so, because right now this behavior is exactly what btrfs has currently with it's inode setup. I didn't really think the journaled use case out since you guys are already rate limited by the journal.

Quoted 6 lines

We are?

XFS is rate limited by metadata writeback, not journal throughput. Yes, journal space is limited by the metadata writeback rate, but journalling itself is not the bottleneck.

I'm not saying "rate limited" as in xfs sucks because journal. I'm saying your dirty metadata foot print is limited by your journal size, so you aren't going to have gigabytes of dirty metadata sitting around needing to be flushed (I assume, I'm going on previous discussions with you about this.)

Quoted 10 lines
Quoted 2 lines

If you would want
to start using this stuff what would you like to see done instead? Thanks,

If this is all about reacting to memory pressure, then writeback is not the mechanism that should drive this writeback. Reacting to memory pressure is what shrinkers are for, and XFS already triggers metadata writeback on memory pressure. Hence I don't see how this writeback mechanism would help us if we have to abuse it to infer "memory pressure occurring"

This isn't reacting to memory pressure, it's reacting to dirty pressure. Btrfs is only limited by system memory for its metadata, so I want all the benefits of years of work on balance_dirty_pages() without having to duplicate the effort internally in btrfs. This is how I'm going about doing it.

Quoted 12 lines

What I was hoping for was this interface to be a mechanism to drive periodic background metadata writeback from the VFS so that when we start to run out of memory the VFS has already started to ramp up the rate of metadata writeback so we don't have huge amounts of dirty metadata to write back during superblock shrinker based reclaim.

i.e. it works more like dirty background data writeback, get's the amount of work to do from the amount of dirty metadata associated with the bdi and doesn't actually do anything when operations like sync() are run because there isn't a need to writeback metadata in those operations.

Quoted 5 lines

IOWs, treating metadata like it's one great big data inode doesn't seem to me to be the right abstraction to use for this - in most fileystems it's a bunch of objects with a complex dependency tree and unknown write ordering, not an inode full of data that can be sequentially written.

But this isn't dictating what to write out, just how much we need to undirty. How the fs wants to write stuff out is completely up to the file system, I specifically made it as generic as possible so we could do whatever we felt like with the numbers we got. This work gives you exactly what you want, a callback when balance dirty pages is telling us that hey we have too much dirty memory in use on the system.

Quoted 12 lines

Maybe we need multiple ops with well defined behaviours. e.g. ->writeback_metadata() for background writeback, ->sync_metadata() for sync based operations. That way different filesystems can ignore the parts they don't need simply by not implementing those operations, and the writeback code doesn't need to try to cater for all operations through the one op. The writeback code should be cleaner, the filesystem code should be cleaner, and we can tailor the work guidelines for each operation separately so there's less mismatch between what writeback is asking and how filesystems track dirty metadata...

So I don't mind adding new things or changing around, but this is just getting us the same behavior that I mentioned before, only at a higher level. We want the balance_dirty_pages() stuff to be able to dip into metadata writeback via the method that I've implemented here. Basically do data writeback, and if we didn't do enough do some metadata writeback. With what you've proposed we would keep that and instead of doing ->write_metadata() when we have SYNC_ALL we'd just do ->sync_metadata() and let the fs figure out what to do, which is what I was suggesting fs'es do.

The problem is there's a disconnect between what btrfs and ext4 do with their dirty metadata and what xfs does. Ext4 is going to log entire blocks into the journal, so there's a 1:1 mapping of dirty metadata to what's going to be written out. So telling it "write x pages" worth of metadata is going to be somewhat useful. That's not the case for xfs, and I'm not sure what a good way to accommodate you would look like. My first thought is a ratio, but man trying to change how we dealt with slab ratios made me want to suck start a shotgun so I don't really want to do something like that again.

How would you prefer to get information to act on from upper layers? Personally I feel like the generic writeback stuff already gives us enough info and we can figure out what we want to do from there. Thanks,

Josef

ps: I'm going to try and stay up for a while so we can hash this out now instead of switching back and forth through our timezones.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

maintainer
#13 lore raw

Re: [PATCH v3 06/10] writeback: introduce super_operations->write_metadata

In reply to Dave Chinner
Quoted 80 lines · Dave Chinner
Quoted 60 lines · Josef Bacik
Quoted 49 lines · Dave Chinner
Quoted 48 lines · Josef Bacik

From: Josef Bacik <[email protected]>

Now that we have metadata counters in the VM, we need to provide a way to kick writeback on dirty metadata. Introduce super_operations->write_metadata. This allows file systems to deal with writing back any dirty metadata we need based on the writeback needs of the system. Since there is no inode to key off of we need a list in the bdi for dirty super blocks to be added. From there we can find any dirty sb's on the bdi we are currently doing writeback on and call into their ->write_metadata callback.

---
 fs/fs-writeback.c                | 72 ++++++++++++++++++++++++++++++++++++----
 fs/super.c                       |  6 ++++
 include/linux/backing-dev-defs.h |  2 ++
 include/linux/fs.h               |  4 +++
 mm/backing-dev.c                 |  2 ++
 5 files changed, 80 insertions(+), 6 deletions(-)
fs/fs-writeback.c +19 -0
index 987448ed7698..fba703dff678 100644
@@ -1479,6 +1479,31 @@ static long writeback_chunk_size(struct bdi_writeback *wb,
 	return pages;
 }
 
+static long writeback_sb_metadata(struct super_block *sb,
+				  struct bdi_writeback *wb,
+				  struct wb_writeback_work *work)
+{
+	struct writeback_control wbc = {
+		.sync_mode		= work->sync_mode,
+		.tagged_writepages	= work->tagged_writepages,
+		.for_kupdate		= work->for_kupdate,
+		.for_background		= work->for_background,
+		.for_sync		= work->for_sync,
+		.range_cyclic		= work->range_cyclic,
+		.range_start		= 0,
+		.range_end		= LLONG_MAX,
+	};
+	long write_chunk;
+
+	write_chunk = writeback_chunk_size(wb, work);
+	wbc.nr_to_write = write_chunk;
+	sb->s_op->write_metadata(sb, &wbc);
Quoted 9 lines

fs/fs-writeback.c static long writeback_chunk_size(struct bdi_writeback *wb, · line 1503

Quoted 3 lines
fs/fs-writeback.c +3 -0
+	work->nr_pages -= write_chunk - wbc.nr_to_write;
+
+	return write_chunk - wbc.nr_to_write;

Ok, writeback_chunk_size() returns a page count. We've already gone through the "metadata is not page sized" dance on the dirty accounting side, so how are we supposed to use pages to account for metadata writeback?

Quoted 3 lines

This is just one of those things that's going to be slightly shitty. It's the same for memory reclaim, all of those places use pages so we just take METADATA_*_BYTES >> PAGE_SHIFT to get pages and figure it's close enough.

Ok, so that isn't exactly easy to deal with, because all our metadata writeback is based on log sequence number targets (i.e. how far to push the tail of the log towards the current head). We've actually got no idea how pages/bytes actually map to a LSN target because while we might account a full buffer as dirty for memory reclaim purposes (up to 64k in size), we might have only logged 128 bytes of it.

i.e. if we are asked to push 2MB of metadata and we treat that as 2MB of log space (i.e. push target of tail LSN + 2MB) we could have logged several tens of megabytes of dirty metadata in that LSN range and have to flush it all. OTOH, if the buffers are fully logged, then that same target might only flush 1.5MB of metadata once all the log overhead is taken into account.

Quoted 5 lines

So there's a fairly large disconnect between the "flush N bytes of metadata" API and the "push to a target LSN" that XFS uses for flushing metadata in aged order. I'm betting that extN and otehr filesystems might have similar mismatches with their journal flushing...

Well, for ext4 it isn't as bad since we do full block logging only. So if we are asked to flush N pages, we can easily translate that to number of fs blocks and flush that many from the oldest transaction.

Couldn't XFS just track how much it has cleaned (from reclaim perspective) when pushing items from AIL (which is what I suppose XFS would do in response to metadata writeback request) and just stop pushing when it has cleaned as much as it was asked to?

Quoted 13 lines
Quoted 13 lines
Quoted 12 lines

And, from what I can tell, if work->sync_mode = WB_SYNC_ALL or work->tagged_writepages is set, this will basically tell us to flush the entire dirty metadata cache because write_chunk will get set to LONG_MAX.

IOWs, this would appear to me to change sync() behaviour quite dramatically on filesystems where ->write_metadata is implemented. That is, instead of leaving all the metadata dirty in memory and just forcing the journal to stable storage, filesystems will be told to also write back all their dirty metadata before sync() returns, even though it is not necessary to provide correct sync() semantics....

Quoted 8 lines
Quoted 2 lines

Well for btrfs that's exactly what we have currently since it's just backed by an inode.

Hmmmm. That explains a lot.

Seems to me that btrfs is the odd one out here, so I'm not sure a mechanism primarily designed for btrfs is going to work generically....

For record ext4 is currently behaving the way btrfs is as well (at least in practice). We expose committed but not yet checkpointed transaction data (equivalent of XFS's AIL AFAICT) in block device's page cache as dirty buffers. Thus calls like sync_blockdev() which are called as part of sync(2) will result in flushing all of those metadata buffers to disk (although as you properly point out it is not strictly necessary for correctness of sync(2)).

Quoted 34 lines
Quoted 4 lines

Obviously this is different for journaled fs'es, but I assumed that in your case you would either not use this part of the infrastructure or simply ignore WB_SYNC_ALL and use WB_SYNC_NONE as a way to be nice under memory pressure or whatever.

I don't think that designing an interface with the assumption other filesystems will abuse it until it works for them is a great process to follow...

Quoted 8 lines
Quoted 4 lines

Mind you, writeback invocation is so convoluted now I could easily be mis-interpretting this code, but it does seem to me like this code is going to have some unintended behaviours....

I don't think so, because right now this behavior is exactly what btrfs has currently with it's inode setup. I didn't really think the journaled use case out since you guys are already rate limited by the journal.

We are?

XFS is rate limited by metadata writeback, not journal throughput. Yes, journal space is limited by the metadata writeback rate, but journalling itself is not the bottleneck.

Quoted 2 lines

If you would want
to start using this stuff what would you like to see done instead? Thanks,

If this is all about reacting to memory pressure, then writeback is not the mechanism that should drive this writeback. Reacting to memory pressure is what shrinkers are for, and XFS already triggers metadata writeback on memory pressure. Hence I don't see how this writeback mechanism would help us if we have to abuse it to infer "memory pressure occurring"

Quoted 5 lines

What I was hoping for was this interface to be a mechanism to drive periodic background metadata writeback from the VFS so that when we start to run out of memory the VFS has already started to ramp up the rate of metadata writeback so we don't have huge amounts of dirty metadata to write back during superblock shrinker based reclaim.

Yeah, that's where I'd like this patch set to end up as well and I believe Josef is as well - he wants to prevent too much dirty metadata to get accumulated after all and background writeback of metadata is a part of that.

Quoted 12 lines

i.e. it works more like dirty background data writeback, get's the amount of work to do from the amount of dirty metadata associated with the bdi and doesn't actually do anything when operations like sync() are run because there isn't a need to writeback metadata in those operations.

IOWs, treating metadata like it's one great big data inode doesn't seem to me to be the right abstraction to use for this - in most fileystems it's a bunch of objects with a complex dependency tree and unknown write ordering, not an inode full of data that can be sequentially written.

Quoted 10 lines

Maybe we need multiple ops with well defined behaviours. e.g. ->writeback_metadata() for background writeback, ->sync_metadata() for sync based operations. That way different filesystems can ignore the parts they don't need simply by not implementing those operations, and the writeback code doesn't need to try to cater for all operations through the one op. The writeback code should be cleaner, the filesystem code should be cleaner, and we can tailor the work guidelines for each operation separately so there's less mismatch between what writeback is asking and how filesystems track dirty metadata...

I agree that writeback for memory cleaning and writeback for data integrity are two very different things especially for metadata. In fact for data integrity writeback we already have ->sync_fs operation so there the functionality gets duplicated. What we could do is that in writeback_sb_inodes() we'd call ->write_metadata only when work->for_kupdate or work->for_background is set. That way ->write_metadata would be called only for memory cleaning purposes.

Honza

Signature · 8 lines
Jan Kara <[email protected]>
SUSE Labs, CR

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#14 lore raw

Re: [PATCH v3 06/10] writeback: introduce super_operations->write_metadata

Quoted 29 lines · Jan Kara
Quoted 22 lines · Dave Chinner
Quoted 5 lines · Josef Bacik
Quoted 1 line · Dave Chinner

On Mon, Dec 11, 2017 at 04:55:31PM -0500, Josef Bacik wrote:

This is just one of those things that's going to be slightly shitty. It's the same for memory reclaim, all of those places use pages so we just take METADATA_*_BYTES >> PAGE_SHIFT to get pages and figure it's close enough.

Ok, so that isn't exactly easy to deal with, because all our metadata writeback is based on log sequence number targets (i.e. how far to push the tail of the log towards the current head). We've actually got no idea how pages/bytes actually map to a LSN target because while we might account a full buffer as dirty for memory reclaim purposes (up to 64k in size), we might have only logged 128 bytes of it.

i.e. if we are asked to push 2MB of metadata and we treat that as 2MB of log space (i.e. push target of tail LSN + 2MB) we could have logged several tens of megabytes of dirty metadata in that LSN range and have to flush it all. OTOH, if the buffers are fully logged, then that same target might only flush 1.5MB of metadata once all the log overhead is taken into account.

Quoted 5 lines

So there's a fairly large disconnect between the "flush N bytes of metadata" API and the "push to a target LSN" that XFS uses for flushing metadata in aged order. I'm betting that extN and otehr filesystems might have similar mismatches with their journal flushing...

Quoted 8 lines

Well, for ext4 it isn't as bad since we do full block logging only. So if we are asked to flush N pages, we can easily translate that to number of fs blocks and flush that many from the oldest transaction.

Couldn't XFS just track how much it has cleaned (from reclaim perspective) when pushing items from AIL (which is what I suppose XFS would do in response to metadata writeback request) and just stop pushing when it has cleaned as much as it was asked to?

If only it were that simple :/

To start with, flushing the dirty objects (such as inodes) to their backing buffers do not mean the the object is clean once the writeback completes. XFS has decoupled in-memory objects with logical object logging rather than logging physical buffers, and so can be modified and dirtied while the inode buffer
is being written back. Hence if we just count things like "buffer size written" it's not actually a correct account of the amount of dirty metadata we've cleaned. If we don't get that right, it'll result in accounting errors and incorrect behaviour.

The bigger problem, however, is that we have no channel to return flush information from the AIL pushing to whatever caller asked for the push. Pushing metadata is completely decoupled from every other subsystem. i.e. the caller asked the xfsaild to push to a specific LSN (e.g. to free up a certain amount of log space for new transactions), and *nothing* has any idea of how much metadata we'll need to write to push the tail of the log to that LSN.

It's also completely asynchronous - there's no mechanism for waiting on a push to a specific LSN. Anything that needs a specific amount of log space to be available waits in ordered ticket queues on the log tail moving forwards. The only interfaces that have access to the log tail ticket waiting is the transaction reservation subsystem, which cannot be used during metadata writeback because that's a guaranteed deadlock vector....

Saying "just account for bytes written" assumes directly connected, synchronous dispatch metadata writeback infrastructure which we simply don't have in XFS. "just clean this many bytes" doesn't really fit at all because we have no way of referencing that to the distance we need to push the tail of the log. An interface that tells us "clean this percentage of dirty metadata" is much more useful because we can map that easily to a log sequence number based push target....

Quoted 17 lines
Quoted 6 lines

IOWs, treating metadata like it's one great big data inode doesn't seem to me to be the right abstraction to use for this - in most fileystems it's a bunch of objects with a complex dependency tree and unknown write ordering, not an inode full of data that can be sequentially written.

Quoted 10 lines

Maybe we need multiple ops with well defined behaviours. e.g. ->writeback_metadata() for background writeback, ->sync_metadata() for sync based operations. That way different filesystems can ignore the parts they don't need simply by not implementing those operations, and the writeback code doesn't need to try to cater for all operations through the one op. The writeback code should be cleaner, the filesystem code should be cleaner, and we can tailor the work guidelines for each operation separately so there's less mismatch between what writeback is asking and how filesystems track dirty metadata...

Quoted 7 lines

I agree that writeback for memory cleaning and writeback for data integrity are two very different things especially for metadata. In fact for data integrity writeback we already have ->sync_fs operation so there the functionality gets duplicated. What we could do is that in writeback_sb_inodes() we'd call ->write_metadata only when work->for_kupdate or work->for_background is set. That way ->write_metadata would be called only for memory cleaning purposes.

That makes sense, but I still think we need a better indication of how much writeback we need to do than just "writeback this chunk of pages". That "writeback a chunk" interface is necessary to share writeback bandwidth across numerous data inodes so that we don't starve any one inode of writeback bandwidth. That's unnecessary for metadata writeback on a superblock - we don't need to share that bandwidth around hundreds or thousands of inodes. What we actually need to know is how much writeback we need to do as a total of all the dirty metadata on the superblock.

Sure, that's not ideal for btrfs and mayext4, but we can write a simple generic helper that converts "flush X percent of dirty metadata" to a page/byte chunk as the current code does. DOing it this way allows filesystems to completely internalise the accounting that needs to be done, rather than trying to hack around a writeback accounting interface with large impedance mismatches to how the filesystem accounts for dirty metadata and/or tracks writeback progress.

Cheers,

Dave.

Signature · 8 lines
Dave Chinner
[email protected]

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
maintainer
#15 lore raw

Re: [PATCH v3 06/10] writeback: introduce super_operations->write_metadata

Quoted 67 lines · Dave Chinner
Quoted 29 lines · Jan Kara
Quoted 22 lines · Dave Chinner
Quoted 5 lines · Josef Bacik
Quoted 1 line · Dave Chinner

On Mon, Dec 11, 2017 at 04:55:31PM -0500, Josef Bacik wrote:

This is just one of those things that's going to be slightly shitty. It's the same for memory reclaim, all of those places use pages so we just take METADATA_*_BYTES >> PAGE_SHIFT to get pages and figure it's close enough.

Ok, so that isn't exactly easy to deal with, because all our metadata writeback is based on log sequence number targets (i.e. how far to push the tail of the log towards the current head). We've actually got no idea how pages/bytes actually map to a LSN target because while we might account a full buffer as dirty for memory reclaim purposes (up to 64k in size), we might have only logged 128 bytes of it.

i.e. if we are asked to push 2MB of metadata and we treat that as 2MB of log space (i.e. push target of tail LSN + 2MB) we could have logged several tens of megabytes of dirty metadata in that LSN range and have to flush it all. OTOH, if the buffers are fully logged, then that same target might only flush 1.5MB of metadata once all the log overhead is taken into account.

Quoted 5 lines

So there's a fairly large disconnect between the "flush N bytes of metadata" API and the "push to a target LSN" that XFS uses for flushing metadata in aged order. I'm betting that extN and otehr filesystems might have similar mismatches with their journal flushing...

Quoted 8 lines

Well, for ext4 it isn't as bad since we do full block logging only. So if we are asked to flush N pages, we can easily translate that to number of fs blocks and flush that many from the oldest transaction.

Couldn't XFS just track how much it has cleaned (from reclaim perspective) when pushing items from AIL (which is what I suppose XFS would do in response to metadata writeback request) and just stop pushing when it has cleaned as much as it was asked to?

If only it were that simple :/

To start with, flushing the dirty objects (such as inodes) to their backing buffers do not mean the the object is clean once the writeback completes. XFS has decoupled in-memory objects with logical object logging rather than logging physical buffers, and so can be modified and dirtied while the inode buffer
is being written back. Hence if we just count things like "buffer size written" it's not actually a correct account of the amount of dirty metadata we've cleaned. If we don't get that right, it'll result in accounting errors and incorrect behaviour.

The bigger problem, however, is that we have no channel to return flush information from the AIL pushing to whatever caller asked for the push. Pushing metadata is completely decoupled from every other subsystem. i.e. the caller asked the xfsaild to push to a specific LSN (e.g. to free up a certain amount of log space for new transactions), and *nothing* has any idea of how much metadata we'll need to write to push the tail of the log to that LSN.

It's also completely asynchronous - there's no mechanism for waiting on a push to a specific LSN. Anything that needs a specific amount of log space to be available waits in ordered ticket queues on the log tail moving forwards. The only interfaces that have access to the log tail ticket waiting is the transaction reservation subsystem, which cannot be used during metadata writeback because that's a guaranteed deadlock vector....

Quoted 8 lines

Saying "just account for bytes written" assumes directly connected, synchronous dispatch metadata writeback infrastructure which we simply don't have in XFS. "just clean this many bytes" doesn't really fit at all because we have no way of referencing that to the distance we need to push the tail of the log. An interface that tells us "clean this percentage of dirty metadata" is much more useful because we can map that easily to a log sequence number based push target....

OK, understood.

Quoted 35 lines
Quoted 17 lines
Quoted 6 lines

IOWs, treating metadata like it's one great big data inode doesn't seem to me to be the right abstraction to use for this - in most fileystems it's a bunch of objects with a complex dependency tree and unknown write ordering, not an inode full of data that can be sequentially written.

Quoted 10 lines

Maybe we need multiple ops with well defined behaviours. e.g. ->writeback_metadata() for background writeback, ->sync_metadata() for sync based operations. That way different filesystems can ignore the parts they don't need simply by not implementing those operations, and the writeback code doesn't need to try to cater for all operations through the one op. The writeback code should be cleaner, the filesystem code should be cleaner, and we can tailor the work guidelines for each operation separately so there's less mismatch between what writeback is asking and how filesystems track dirty metadata...

Quoted 7 lines

I agree that writeback for memory cleaning and writeback for data integrity are two very different things especially for metadata. In fact for data integrity writeback we already have ->sync_fs operation so there the functionality gets duplicated. What we could do is that in writeback_sb_inodes() we'd call ->write_metadata only when work->for_kupdate or work->for_background is set. That way ->write_metadata would be called only for memory cleaning purposes.

That makes sense, but I still think we need a better indication of how much writeback we need to do than just "writeback this chunk of pages". That "writeback a chunk" interface is necessary to share writeback bandwidth across numerous data inodes so that we don't starve any one inode of writeback bandwidth. That's unnecessary for metadata writeback on a superblock - we don't need to share that bandwidth around hundreds or thousands of inodes. What we actually need to know is how much writeback we need to do as a total of all the dirty metadata on the superblock.

Quoted 8 lines

Sure, that's not ideal for btrfs and mayext4, but we can write a simple generic helper that converts "flush X percent of dirty metadata" to a page/byte chunk as the current code does. DOing it this way allows filesystems to completely internalise the accounting that needs to be done, rather than trying to hack around a writeback accounting interface with large impedance mismatches to how the filesystem accounts for dirty metadata and/or tracks writeback progress.

Let me think loud on how we could tie this into how memory cleaning writeback currently works - the one with for_background == 1 which is generally used to get amount of dirty pages in the system under control. We have a queue of inodes to write, we iterate over this queue and ask each inode to write some amount (e.g. 64 M - exact amount depends on measured writeback bandwidth etc.). Some amount from that inode gets written and we continue with the next inode in the queue (put this one at the end of the queue if it still has dirty pages). We do this until:

a) the number of dirty pages in the system is below background dirty limit and the number dirty pages for this device is below background dirty limit for this device.
b) run out of dirty inodes on this device
c) someone queues different type of writeback

And we need to somehow incorporate metadata writeback into this loop. I see two questions here:

1) When / how often should we ask for metadata writeback?
2) How much to ask to write in one go?

The second question is especially tricky in the presence of completely async metadata flushing in XFS - we can ask to write say half of dirty metadata but then we have no idea whether the next observation of dirty metadata counters is with that part of metadata already under writeback / cleaned or whether xfsaild didn't even start working and pushing more has no sense. Partly, this could be dealt with by telling the filesystem "metadata dirty target" - i.e. "get your dirty metadata counters below X"
- and whether we communicate that in bytes, pages, or a fraction of current dirty metadata counter value is a detail I don't have a strong opinion on now. And the fact is the amount written by the filesystem doesn't have to be very accurate anyway - we basically just want to make some forward progress with writing metadata, don't want that to take too long (so that other writeback from the thread isn't stalled), and if writeback code is unhappy about the state of counters next time it looks, it will ask the filesystem again...

This gets me directly to another problem with async nature of XFS metadata writeback. That is that it could get writeback thread into busyloop - we are supposed to terminate memory cleaning writeback only once dirty counters are below limit and in case dirty metadata is causing counters to be over limit, we would just ask in a loop XFS to get metadata below the target. I suppose XFS could just return "nothing written" from its ->write_metadata operation and in such case we could sleep a bit before going for another writeback loop (the same thing happens when filesystem reports all inodes are locked / busy and it cannot writeback anything). But it's getting a bit ugly and is it really better than somehow waiting inside XFS for metadata writeback to occur? Any idea Dave?

Regarding question 1). What Josef does is that once we went through all queued inodes and wrote some amount from each one, we'd go and ask fs to write some metadata. And then we'll again go to write inodes that are still dirty. That is somewhat rough but I guess it is fine for now.

Honza

Signature · 8 lines
Jan Kara <[email protected]>
SUSE Labs, CR

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#16 lore raw

Re: [PATCH v3 06/10] writeback: introduce super_operations->write_metadata

Quoted 172 lines · Jan Kara
Quoted 67 lines · Dave Chinner
Quoted 29 lines · Jan Kara
Quoted 22 lines · Dave Chinner
Quoted 5 lines · Josef Bacik
Quoted 1 line · Dave Chinner

On Mon, Dec 11, 2017 at 04:55:31PM -0500, Josef Bacik wrote:

This is just one of those things that's going to be slightly shitty. It's the same for memory reclaim, all of those places use pages so we just take METADATA_*_BYTES >> PAGE_SHIFT to get pages and figure it's close enough.

Ok, so that isn't exactly easy to deal with, because all our metadata writeback is based on log sequence number targets (i.e. how far to push the tail of the log towards the current head). We've actually got no idea how pages/bytes actually map to a LSN target because while we might account a full buffer as dirty for memory reclaim purposes (up to 64k in size), we might have only logged 128 bytes of it.

i.e. if we are asked to push 2MB of metadata and we treat that as 2MB of log space (i.e. push target of tail LSN + 2MB) we could have logged several tens of megabytes of dirty metadata in that LSN range and have to flush it all. OTOH, if the buffers are fully logged, then that same target might only flush 1.5MB of metadata once all the log overhead is taken into account.

Quoted 5 lines

So there's a fairly large disconnect between the "flush N bytes of metadata" API and the "push to a target LSN" that XFS uses for flushing metadata in aged order. I'm betting that extN and otehr filesystems might have similar mismatches with their journal flushing...

Quoted 8 lines

Well, for ext4 it isn't as bad since we do full block logging only. So if we are asked to flush N pages, we can easily translate that to number of fs blocks and flush that many from the oldest transaction.

Couldn't XFS just track how much it has cleaned (from reclaim perspective) when pushing items from AIL (which is what I suppose XFS would do in response to metadata writeback request) and just stop pushing when it has cleaned as much as it was asked to?

If only it were that simple :/

To start with, flushing the dirty objects (such as inodes) to their backing buffers do not mean the the object is clean once the writeback completes. XFS has decoupled in-memory objects with logical object logging rather than logging physical buffers, and so can be modified and dirtied while the inode buffer
is being written back. Hence if we just count things like "buffer size written" it's not actually a correct account of the amount of dirty metadata we've cleaned. If we don't get that right, it'll result in accounting errors and incorrect behaviour.

The bigger problem, however, is that we have no channel to return flush information from the AIL pushing to whatever caller asked for the push. Pushing metadata is completely decoupled from every other subsystem. i.e. the caller asked the xfsaild to push to a specific LSN (e.g. to free up a certain amount of log space for new transactions), and *nothing* has any idea of how much metadata we'll need to write to push the tail of the log to that LSN.

It's also completely asynchronous - there's no mechanism for waiting on a push to a specific LSN. Anything that needs a specific amount of log space to be available waits in ordered ticket queues on the log tail moving forwards. The only interfaces that have access to the log tail ticket waiting is the transaction reservation subsystem, which cannot be used during metadata writeback because that's a guaranteed deadlock vector....

Quoted 8 lines

Saying "just account for bytes written" assumes directly connected, synchronous dispatch metadata writeback infrastructure which we simply don't have in XFS. "just clean this many bytes" doesn't really fit at all because we have no way of referencing that to the distance we need to push the tail of the log. An interface that tells us "clean this percentage of dirty metadata" is much more useful because we can map that easily to a log sequence number based push target....

OK, understood.

Quoted 35 lines
Quoted 17 lines
Quoted 6 lines

IOWs, treating metadata like it's one great big data inode doesn't seem to me to be the right abstraction to use for this - in most fileystems it's a bunch of objects with a complex dependency tree and unknown write ordering, not an inode full of data that can be sequentially written.

Quoted 10 lines

Maybe we need multiple ops with well defined behaviours. e.g. ->writeback_metadata() for background writeback, ->sync_metadata() for sync based operations. That way different filesystems can ignore the parts they don't need simply by not implementing those operations, and the writeback code doesn't need to try to cater for all operations through the one op. The writeback code should be cleaner, the filesystem code should be cleaner, and we can tailor the work guidelines for each operation separately so there's less mismatch between what writeback is asking and how filesystems track dirty metadata...

Quoted 7 lines

I agree that writeback for memory cleaning and writeback for data integrity are two very different things especially for metadata. In fact for data integrity writeback we already have ->sync_fs operation so there the functionality gets duplicated. What we could do is that in writeback_sb_inodes() we'd call ->write_metadata only when work->for_kupdate or work->for_background is set. That way ->write_metadata would be called only for memory cleaning purposes.

That makes sense, but I still think we need a better indication of how much writeback we need to do than just "writeback this chunk of pages". That "writeback a chunk" interface is necessary to share writeback bandwidth across numerous data inodes so that we don't starve any one inode of writeback bandwidth. That's unnecessary for metadata writeback on a superblock - we don't need to share that bandwidth around hundreds or thousands of inodes. What we actually need to know is how much writeback we need to do as a total of all the dirty metadata on the superblock.

Quoted 8 lines

Sure, that's not ideal for btrfs and mayext4, but we can write a simple generic helper that converts "flush X percent of dirty metadata" to a page/byte chunk as the current code does. DOing it this way allows filesystems to completely internalise the accounting that needs to be done, rather than trying to hack around a writeback accounting interface with large impedance mismatches to how the filesystem accounts for dirty metadata and/or tracks writeback progress.

Let me think loud on how we could tie this into how memory cleaning writeback currently works - the one with for_background == 1 which is generally used to get amount of dirty pages in the system under control. We have a queue of inodes to write, we iterate over this queue and ask each inode to write some amount (e.g. 64 M - exact amount depends on measured writeback bandwidth etc.). Some amount from that inode gets written and we continue with the next inode in the queue (put this one at the end of the queue if it still has dirty pages). We do this until:

a) the number of dirty pages in the system is below background dirty limit and the number dirty pages for this device is below background dirty limit for this device.
b) run out of dirty inodes on this device
c) someone queues different type of writeback

And we need to somehow incorporate metadata writeback into this loop. I see two questions here:

1) When / how often should we ask for metadata writeback?
2) How much to ask to write in one go?

The second question is especially tricky in the presence of completely async metadata flushing in XFS - we can ask to write say half of dirty metadata but then we have no idea whether the next observation of dirty metadata counters is with that part of metadata already under writeback / cleaned or whether xfsaild didn't even start working and pushing more has no sense. Partly, this could be dealt with by telling the filesystem "metadata dirty target" - i.e. "get your dirty metadata counters below X"
- and whether we communicate that in bytes, pages, or a fraction of current dirty metadata counter value is a detail I don't have a strong opinion on now. And the fact is the amount written by the filesystem doesn't have to be very accurate anyway - we basically just want to make some forward progress with writing metadata, don't want that to take too long (so that other writeback from the thread isn't stalled), and if writeback code is unhappy about the state of counters next time it looks, it will ask the filesystem again...

This gets me directly to another problem with async nature of XFS metadata writeback. That is that it could get writeback thread into busyloop - we are supposed to terminate memory cleaning writeback only once dirty counters are below limit and in case dirty metadata is causing counters to be over limit, we would just ask in a loop XFS to get metadata below the target. I suppose XFS could just return "nothing written" from its ->write_metadata operation and in such case we could sleep a bit before going for another writeback loop (the same thing happens when filesystem reports all inodes are locked / busy and it cannot writeback anything). But it's getting a bit ugly and is it really better than somehow waiting inside XFS for metadata writeback to occur? Any idea Dave?

Quoted 5 lines

Regarding question 1). What Josef does is that once we went through all queued inodes and wrote some amount from each one, we'd go and ask fs to write some metadata. And then we'll again go to write inodes that are still dirty. That is somewhat rough but I guess it is fine for now.

Alright I'm back from vacation so am sufficiently hungover to try and figure this out. Btrfs and ext4 account their dirty metadata directly and reclaim it like inodes, xfs doesn't. Btrfs does do something similar to what xfs does with delayed updates, but we just use the enospc logic to trigger when to update the metadata blocks, and then those just get written out via the dirty balancing stuff. Since xfs doesn't have a direct way to tie that together, you'd rather we'd have some sort of ratio so you know you need to flush dirty inodes, correct Dave?

I don't think this is solvable for xfs. The whole vm is around pages/bytes. The only place we have this ratio thing is in slab reclaim, and we only have to worry about actual memory pressure there because we have a nice external trigger, we're out of pages.

For dirty throttling we have to know how much we're pushing and how much we need to push, and that _requires_ bytes/pages. And not like "we can only send you bytes/pages to reclaim" but like the throttling stuff has all of it's accounting in bytes/pages, so putting in arbitrary object counts into this logic is not going to be straightforward. The system administrator sets their dirty limits to absolute numbers or % of total memory. If xfs can't account for its metadata this way then I don't think it can use any sort of infrastructure we provide in the current framework. We'd have to completely overhaul the dirty throttling stuff for it to work, and even then we still need bandwidth of the device which means how many bytes we're writing out.

I have an alternative proposal. We keep these patches the way they are and use it for btrfs and ext4 since our actual metadata pool is tracked similarly to inodes.

Then to accomodate xfs (and btrfs and ext4) we have a separate throttling system that is fs object based. I know xfs and btrfs bypass the mark_inode_dirty() stuff, but there's no reason we couldn't strap some logic in there to account for how many dirty objects we have lying around. Then we need to come up with a way we want to limit the objects. I feel like this part is going to be very fs specific, btrfs will have it's enospc checks, ext4 and xfs will have log space checks. We add this into balance_dirty_pages(), so we benefit from the per-process rate limiting, and we just have super->balance_metadata() and inside balance_metadata() the fs takes into account the current dirty objects usage and how much space we have left and then does it's job for throttling stuff. If there's plenty of space or whatever it's just a no-op and returns.

This would couple nicely with what I've done in these patches, as the balance_metadata() would simply move our in-memory updates into the buffers themselves, making them dirty. Then the actualy dirty metadata block stuff could see if it's time to do writeout.

And this would make xfs so it doesn't do writeout from the slab reclamation path, which Facebook constantly has to patch out because it just make xfs unusable in our environments.

Quoted 1 line

From here we could then extend the fs object dirty balancing to have more

generic logic for when we need to flush, but I feel like that's going to be a much larger project than just providing a callback. This doesn't get us anything super new or fancy, but could even be used in the memory reclaim path in a less critical area to flush dirty metadata rather than the slab reclaim path that xfs currently uses. And then we can build more complicated things from there. What do you think of this?

Josef

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#17 lore raw

Re: [PATCH v3 06/10] writeback: introduce super_operations->write_metadata

Quoted 48 lines · Josef Bacik
Quoted 47 lines · Jan Kara
Quoted 45 lines · Dave Chinner
Quoted 18 lines · Jan Kara
Quoted 6 lines · Dave Chinner

IOWs, treating metadata like it's one great big data inode doesn't seem to me to be the right abstraction to use for this - in most fileystems it's a bunch of objects with a complex dependency tree and unknown write ordering, not an inode full of data that can be sequentially written.

Quoted 10 lines

Maybe we need multiple ops with well defined behaviours. e.g. ->writeback_metadata() for background writeback, ->sync_metadata() for sync based operations. That way different filesystems can ignore the parts they don't need simply by not implementing those operations, and the writeback code doesn't need to try to cater for all operations through the one op. The writeback code should be cleaner, the filesystem code should be cleaner, and we can tailor the work guidelines for each operation separately so there's less mismatch between what writeback is asking and how filesystems track dirty metadata...

Quoted 7 lines

I agree that writeback for memory cleaning and writeback for data integrity are two very different things especially for metadata. In fact for data integrity writeback we already have ->sync_fs operation so there the functionality gets duplicated. What we could do is that in writeback_sb_inodes() we'd call ->write_metadata only when work->for_kupdate or work->for_background is set. That way ->write_metadata would be called only for memory cleaning purposes.

That makes sense, but I still think we need a better indication of how much writeback we need to do than just "writeback this chunk of pages". That "writeback a chunk" interface is necessary to share writeback bandwidth across numerous data inodes so that we don't starve any one inode of writeback bandwidth. That's unnecessary for metadata writeback on a superblock - we don't need to share that bandwidth around hundreds or thousands of inodes. What we actually need to know is how much writeback we need to do as a total of all the dirty metadata on the superblock.

Sure, that's not ideal for btrfs and mayext4, but we can write a simple generic helper that converts "flush X percent of dirty metadata" to a page/byte chunk as the current code does. DOing it this way allows filesystems to completely internalise the accounting that needs to be done, rather than trying to hack around a writeback accounting interface with large impedance mismatches to how the filesystem accounts for dirty metadata and/or tracks writeback progress.

Quoted 5 lines
Quoted 5 lines

Let me think loud on how we could tie this into how memory cleaning writeback currently works - the one with for_background == 1 which is generally used to get amount of dirty pages in the system under control. We have a queue of inodes to write, we iterate over this queue and ask each inode to write some amount (e.g. 64 M - exact amount depends on measured

It's a maximum of 1024 pages per inode.

Quoted 16 lines
Quoted 16 lines

writeback bandwidth etc.). Some amount from that inode gets written and we continue with the next inode in the queue (put this one at the end of the queue if it still has dirty pages). We do this until:

a) the number of dirty pages in the system is below background dirty limit and the number dirty pages for this device is below background dirty limit for this device.
b) run out of dirty inodes on this device
c) someone queues different type of writeback

And we need to somehow incorporate metadata writeback into this loop. I see two questions here:

1) When / how often should we ask for metadata writeback?
2) How much to ask to write in one go?

Quoted 6 lines
Quoted 6 lines

The second question is especially tricky in the presence of completely async metadata flushing in XFS - we can ask to write say half of dirty metadata but then we have no idea whether the next observation of dirty metadata counters is with that part of metadata already under writeback / cleaned or whether xfsaild didn't even start working and pushing more has no sense.

Well, like with ext4, we've also got to consider that a bunch of the recently dirtied metadata (e.g. from delalloc, EOF updates on IO completion, etc) is still pinned in memory because the journal has not been flushed/checkpointed. Hence we should not be attempting to write back metadata we've dirtied as a result of writing data in the background writeback loop.

That greatly simplifies what we need to consider here. That is, we just need to sample the ratio of dirty metadata to clean metadata before we start data writeback, and we calculate the amount of metadata writeback we should trigger from there. We only need to do this *once* per background writeback scan for a superblock as there is no need for sharing bandwidth between lots of data inodes - there's only one metadata inode for ext4/btrfs, and XFS is completely async....

Quoted 10 lines
Quoted 10 lines

Partly, this could be dealt with by telling the filesystem "metadata dirty target" - i.e. "get your dirty metadata counters below X"
- and whether we communicate that in bytes, pages, or a fraction of current dirty metadata counter value is a detail I don't have a strong opinion on now. And the fact is the amount written by the filesystem doesn't have to be very accurate anyway - we basically just want to make some forward progress with writing metadata, don't want that to take too long (so that other writeback from the thread isn't stalled), and if writeback code is unhappy about the state of counters next time it looks, it will ask the filesystem again...

Right. The problem is communicating "how much" to the filesystem in a useful manner....

Quoted 11 lines
Quoted 11 lines

This gets me directly to another problem with async nature of XFS metadata writeback. That is that it could get writeback thread into busyloop - we are supposed to terminate memory cleaning writeback only once dirty counters are below limit and in case dirty metadata is causing counters to be over limit, we would just ask in a loop XFS to get metadata below the target. I suppose XFS could just return "nothing written" from its ->write_metadata operation and in such case we could sleep a bit before going for another writeback loop (the same thing happens when filesystem reports all inodes are locked / busy and it cannot writeback anything). But it's getting a bit ugly and is it really better than somehow waiting inside XFS for metadata writeback to occur? Any idea Dave?

I tend to think that the whole point of background writeback is to do it asynchronously and keep the IO pipe full by avoiding blocking on any specific object. i.e. if we can't do writeback from this object, then skip it and do it from the next....

I think we could probably block ->write_metadata if necessary via a completion/wakeup style notification when a specific LSN is reached by the log tail, but realistically if there's any amount of data needing to be written it'll throttle data writes because the IO pipeline is being kept full by background metadata writes....

Quoted 9 lines
Quoted 5 lines

Regarding question 1). What Josef does is that once we went through all queued inodes and wrote some amount from each one, we'd go and ask fs to write some metadata. And then we'll again go to write inodes that are still dirty. That is somewhat rough but I guess it is fine for now.

Alright I'm back from vacation so am sufficiently hungover to try and figure this out. Btrfs and ext4 account their dirty metadata directly and reclaim it like inodes, xfs doesn't.

Terminology: "reclaim" is not what we do when accounting for writeback IO completion.

And we've already been through the accounting side of things - we can add that to XFS once it's converted to byte-based accounting.

Quoted 6 lines

Btrfs does do something similar to what xfs does with
delayed updates, but we just use the enospc logic to trigger when to update the metadata blocks, and then those just get written out via the dirty balancing stuff. Since xfs doesn't have a direct way to tie that together, you'd rather we'd have some sort of ratio so you know you need to flush dirty inodes, correct Dave?

Again, terminology: We don't "need to flush dirty inodes" in XFS, we need to flush /metadata objects/.

Quoted 4 lines

I don't think this is solvable for xfs. The whole vm is around pages/bytes. The only place we have this ratio thing is in slab reclaim, and we only have to worry about actual memory pressure there because we have a nice external trigger, we're out of pages.

WE don't need all of the complexity of slab reclaim, though. That's a complete red herring.

All that is needed is for the writeback API to tell us "flush X% of your dirty metadata". We will have cached data and metadata in bytes and dirty cached data and metadata in bytes at the generic writeback level - it's not at all difficult to turn that into a flush ratio. e.g. take the amount we are over the dirty metadata background threshold, request writeback for that amount of metadata as a percentage of the overall dirty metadata.

Quoted 2 lines

For dirty throttling we have to know how much we're pushing and how much we need to push, and that _requires_ bytes/pages.

Dirty throttling does not need to know how much work you've asked the filesystem to do. It does it's own accounting of bytes/pages being cleaned based on the accounting updates from the filesystem metadata object IO completion routines. That is what needs to be in bytes/pages for dirty throttling to work.

Quoted 7 lines

And not like "we can only send you
bytes/pages to reclaim" but like the throttling stuff has all of it's accounting in bytes/pages, so putting in arbitrary object counts into this logic is not going to be straightforward. The system administrator sets their dirty limits to absolute numbers or % of total memory. If xfs can't account for its metadata this way then I don't think it can use any sort of infrastructure we provide in the current framework.

XFS will account for clean/dirty metadata in bytes, just like btrfs and ext4 will do. We've already been over this and *solved that problem*.

But really, though, I'm fed up with having to fight time and time again over simple changes to core infrastructure that make it generic rather than specifically tailored to the filesystem that wants it first. Merge whatever crap you need for btrfs and I'll make it work for XFS later and leave what gets fed to btrfs completely unchanged.

-Dave.

Signature · 8 lines
Dave Chinner
[email protected]

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
maintainer
#18 lore raw

Re: [PATCH v3 06/10] writeback: introduce super_operations->write_metadata

Quoted 49 lines · Dave Chinner
Quoted 48 lines · Josef Bacik
Quoted 47 lines · Jan Kara
Quoted 45 lines · Dave Chinner
Quoted 18 lines · Jan Kara
Quoted 6 lines · Dave Chinner

IOWs, treating metadata like it's one great big data inode doesn't seem to me to be the right abstraction to use for this - in most fileystems it's a bunch of objects with a complex dependency tree and unknown write ordering, not an inode full of data that can be sequentially written.

Quoted 10 lines

Maybe we need multiple ops with well defined behaviours. e.g. ->writeback_metadata() for background writeback, ->sync_metadata() for sync based operations. That way different filesystems can ignore the parts they don't need simply by not implementing those operations, and the writeback code doesn't need to try to cater for all operations through the one op. The writeback code should be cleaner, the filesystem code should be cleaner, and we can tailor the work guidelines for each operation separately so there's less mismatch between what writeback is asking and how filesystems track dirty metadata...

Quoted 7 lines

I agree that writeback for memory cleaning and writeback for data integrity are two very different things especially for metadata. In fact for data integrity writeback we already have ->sync_fs operation so there the functionality gets duplicated. What we could do is that in writeback_sb_inodes() we'd call ->write_metadata only when work->for_kupdate or work->for_background is set. That way ->write_metadata would be called only for memory cleaning purposes.

That makes sense, but I still think we need a better indication of how much writeback we need to do than just "writeback this chunk of pages". That "writeback a chunk" interface is necessary to share writeback bandwidth across numerous data inodes so that we don't starve any one inode of writeback bandwidth. That's unnecessary for metadata writeback on a superblock - we don't need to share that bandwidth around hundreds or thousands of inodes. What we actually need to know is how much writeback we need to do as a total of all the dirty metadata on the superblock.

Sure, that's not ideal for btrfs and mayext4, but we can write a simple generic helper that converts "flush X percent of dirty metadata" to a page/byte chunk as the current code does. DOing it this way allows filesystems to completely internalise the accounting that needs to be done, rather than trying to hack around a writeback accounting interface with large impedance mismatches to how the filesystem accounts for dirty metadata and/or tracks writeback progress.

Quoted 7 lines
Quoted 5 lines
Quoted 5 lines

Let me think loud on how we could tie this into how memory cleaning writeback currently works - the one with for_background == 1 which is generally used to get amount of dirty pages in the system under control. We have a queue of inodes to write, we iterate over this queue and ask each inode to write some amount (e.g. 64 M - exact amount depends on measured

It's a maximum of 1024 pages per inode.

That's actually a minimum, not maximum, if I read the code in writeback_chunk_size() right.

Quoted 23 lines
Quoted 16 lines
Quoted 16 lines

writeback bandwidth etc.). Some amount from that inode gets written and we continue with the next inode in the queue (put this one at the end of the queue if it still has dirty pages). We do this until:

a) the number of dirty pages in the system is below background dirty limit and the number dirty pages for this device is below background dirty limit for this device.
b) run out of dirty inodes on this device
c) someone queues different type of writeback

And we need to somehow incorporate metadata writeback into this loop. I see two questions here:

1) When / how often should we ask for metadata writeback?
2) How much to ask to write in one go?

Quoted 6 lines
Quoted 6 lines

The second question is especially tricky in the presence of completely async metadata flushing in XFS - we can ask to write say half of dirty metadata but then we have no idea whether the next observation of dirty metadata counters is with that part of metadata already under writeback / cleaned or whether xfsaild didn't even start working and pushing more has no sense.

Quoted 6 lines

Well, like with ext4, we've also got to consider that a bunch of the recently dirtied metadata (e.g. from delalloc, EOF updates on IO completion, etc) is still pinned in memory because the journal has not been flushed/checkpointed. Hence we should not be attempting to write back metadata we've dirtied as a result of writing data in the background writeback loop.

Agreed. Actually for ext4 I would not expose 'pinned' buffers as dirty to VM - the journalling layer currently already works that way and it works well for us. But that's just a small technical detail and different filesystems can decide differently.

Quoted 8 lines

That greatly simplifies what we need to consider here. That is, we just need to sample the ratio of dirty metadata to clean metadata before we start data writeback, and we calculate the amount of metadata writeback we should trigger from there. We only need to do this *once* per background writeback scan for a superblock as there is no need for sharing bandwidth between lots of data inodes - there's only one metadata inode for ext4/btrfs, and XFS is completely async....

OK, agreed again.

Quoted 11 lines
Quoted 10 lines
Quoted 10 lines

Partly, this could be dealt with by telling the filesystem "metadata dirty target" - i.e. "get your dirty metadata counters below X"
- and whether we communicate that in bytes, pages, or a fraction of current dirty metadata counter value is a detail I don't have a strong opinion on now. And the fact is the amount written by the filesystem doesn't have to be very accurate anyway - we basically just want to make some forward progress with writing metadata, don't want that to take too long (so that other writeback from the thread isn't stalled), and if writeback code is unhappy about the state of counters next time it looks, it will ask the filesystem again...

Quoted 2 lines

Right. The problem is communicating "how much" to the filesystem in a useful manner....

Yep. I'm fine with communication in the form of 'write X% of your dirty metadata'. That should be useful for XFS and as you mentioned in some previous email, we can provide a helper function to compute number of pages to write (including some reasonable upper limit to bound time spent in one ->write_metadata invocation) for ext4 and btrfs.

Quoted 12 lines
Quoted 11 lines
Quoted 11 lines

This gets me directly to another problem with async nature of XFS metadata writeback. That is that it could get writeback thread into busyloop - we are supposed to terminate memory cleaning writeback only once dirty counters are below limit and in case dirty metadata is causing counters to be over limit, we would just ask in a loop XFS to get metadata below the target. I suppose XFS could just return "nothing written" from its ->write_metadata operation and in such case we could sleep a bit before going for another writeback loop (the same thing happens when filesystem reports all inodes are locked / busy and it cannot writeback anything). But it's getting a bit ugly and is it really better than somehow waiting inside XFS for metadata writeback to occur? Any idea Dave?

Quoted 4 lines

I tend to think that the whole point of background writeback is to do it asynchronously and keep the IO pipe full by avoiding blocking on any specific object. i.e. if we can't do writeback from this object, then skip it and do it from the next....

Agreed.

Quoted 5 lines

I think we could probably block ->write_metadata if necessary via a completion/wakeup style notification when a specific LSN is reached by the log tail, but realistically if there's any amount of data needing to be written it'll throttle data writes because the IO pipeline is being kept full by background metadata writes....

So the problem I'm concerned about is a corner case. Consider a situation when you have no dirty data, only dirty metadata but enough of them to trigger background writeback. How should metadata writeback behave for XFS in this case? Who should be responsible that wb_writeback() just does not loop invoking ->write_metadata() as fast as CPU allows until xfsaild makes enough progress?

Thinking about this today, I think this looping prevention belongs to wb_writeback(). Sadly we don't have much info to decide how long to sleep before trying more writeback so we'd have to just sleep for <some_magic_amount> if we found no writeback happened in the last writeback round before going through the whole writeback loop again. And ->write_metadata() for XFS would need to always return 0 (as in "no progress made") to make sure this busyloop avoidance logic in wb_writeback() triggers. ext4 and btrfs would return number of bytes written from ->write_metadata (or just 1 would be enough to indicate some progress in metadata writeback was made and busyloop avoidance is not needed).

So overall I think I have pretty clear idea on how this all should work to make ->write_metadata useful for btrfs, XFS, and ext4 and we agree on the plan.

Honza

Signature · 8 lines
Jan Kara <[email protected]>
SUSE Labs, CR

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#19 lore raw

Re: [PATCH v3 06/10] writeback: introduce super_operations->write_metadata

Quoted 170 lines · Jan Kara
Quoted 49 lines · Dave Chinner
Quoted 48 lines · Josef Bacik
Quoted 47 lines · Jan Kara
Quoted 45 lines · Dave Chinner
Quoted 18 lines · Jan Kara
Quoted 6 lines · Dave Chinner

IOWs, treating metadata like it's one great big data inode doesn't seem to me to be the right abstraction to use for this - in most fileystems it's a bunch of objects with a complex dependency tree and unknown write ordering, not an inode full of data that can be sequentially written.

Quoted 10 lines

Maybe we need multiple ops with well defined behaviours. e.g. ->writeback_metadata() for background writeback, ->sync_metadata() for sync based operations. That way different filesystems can ignore the parts they don't need simply by not implementing those operations, and the writeback code doesn't need to try to cater for all operations through the one op. The writeback code should be cleaner, the filesystem code should be cleaner, and we can tailor the work guidelines for each operation separately so there's less mismatch between what writeback is asking and how filesystems track dirty metadata...

Quoted 7 lines

I agree that writeback for memory cleaning and writeback for data integrity are two very different things especially for metadata. In fact for data integrity writeback we already have ->sync_fs operation so there the functionality gets duplicated. What we could do is that in writeback_sb_inodes() we'd call ->write_metadata only when work->for_kupdate or work->for_background is set. That way ->write_metadata would be called only for memory cleaning purposes.

That makes sense, but I still think we need a better indication of how much writeback we need to do than just "writeback this chunk of pages". That "writeback a chunk" interface is necessary to share writeback bandwidth across numerous data inodes so that we don't starve any one inode of writeback bandwidth. That's unnecessary for metadata writeback on a superblock - we don't need to share that bandwidth around hundreds or thousands of inodes. What we actually need to know is how much writeback we need to do as a total of all the dirty metadata on the superblock.

Sure, that's not ideal for btrfs and mayext4, but we can write a simple generic helper that converts "flush X percent of dirty metadata" to a page/byte chunk as the current code does. DOing it this way allows filesystems to completely internalise the accounting that needs to be done, rather than trying to hack around a writeback accounting interface with large impedance mismatches to how the filesystem accounts for dirty metadata and/or tracks writeback progress.

Quoted 7 lines
Quoted 5 lines
Quoted 5 lines

Let me think loud on how we could tie this into how memory cleaning writeback currently works - the one with for_background == 1 which is generally used to get amount of dirty pages in the system under control. We have a queue of inodes to write, we iterate over this queue and ask each inode to write some amount (e.g. 64 M - exact amount depends on measured

It's a maximum of 1024 pages per inode.

That's actually a minimum, not maximum, if I read the code in writeback_chunk_size() right.

Quoted 23 lines
Quoted 16 lines
Quoted 16 lines

writeback bandwidth etc.). Some amount from that inode gets written and we continue with the next inode in the queue (put this one at the end of the queue if it still has dirty pages). We do this until:

a) the number of dirty pages in the system is below background dirty limit and the number dirty pages for this device is below background dirty limit for this device.
b) run out of dirty inodes on this device
c) someone queues different type of writeback

And we need to somehow incorporate metadata writeback into this loop. I see two questions here:

1) When / how often should we ask for metadata writeback?
2) How much to ask to write in one go?

Quoted 6 lines
Quoted 6 lines

The second question is especially tricky in the presence of completely async metadata flushing in XFS - we can ask to write say half of dirty metadata but then we have no idea whether the next observation of dirty metadata counters is with that part of metadata already under writeback / cleaned or whether xfsaild didn't even start working and pushing more has no sense.

Quoted 6 lines

Well, like with ext4, we've also got to consider that a bunch of the recently dirtied metadata (e.g. from delalloc, EOF updates on IO completion, etc) is still pinned in memory because the journal has not been flushed/checkpointed. Hence we should not be attempting to write back metadata we've dirtied as a result of writing data in the background writeback loop.

Agreed. Actually for ext4 I would not expose 'pinned' buffers as dirty to VM - the journalling layer currently already works that way and it works well for us. But that's just a small technical detail and different filesystems can decide differently.

Quoted 8 lines

That greatly simplifies what we need to consider here. That is, we just need to sample the ratio of dirty metadata to clean metadata before we start data writeback, and we calculate the amount of metadata writeback we should trigger from there. We only need to do this *once* per background writeback scan for a superblock as there is no need for sharing bandwidth between lots of data inodes - there's only one metadata inode for ext4/btrfs, and XFS is completely async....

OK, agreed again.

Quoted 11 lines
Quoted 10 lines
Quoted 10 lines

Partly, this could be dealt with by telling the filesystem "metadata dirty target" - i.e. "get your dirty metadata counters below X"
- and whether we communicate that in bytes, pages, or a fraction of current dirty metadata counter value is a detail I don't have a strong opinion on now. And the fact is the amount written by the filesystem doesn't have to be very accurate anyway - we basically just want to make some forward progress with writing metadata, don't want that to take too long (so that other writeback from the thread isn't stalled), and if writeback code is unhappy about the state of counters next time it looks, it will ask the filesystem again...

Quoted 2 lines

Right. The problem is communicating "how much" to the filesystem in a useful manner....

Yep. I'm fine with communication in the form of 'write X% of your dirty metadata'. That should be useful for XFS and as you mentioned in some previous email, we can provide a helper function to compute number of pages to write (including some reasonable upper limit to bound time spent in one ->write_metadata invocation) for ext4 and btrfs.

Quoted 12 lines
Quoted 11 lines
Quoted 11 lines

This gets me directly to another problem with async nature of XFS metadata writeback. That is that it could get writeback thread into busyloop - we are supposed to terminate memory cleaning writeback only once dirty counters are below limit and in case dirty metadata is causing counters to be over limit, we would just ask in a loop XFS to get metadata below the target. I suppose XFS could just return "nothing written" from its ->write_metadata operation and in such case we could sleep a bit before going for another writeback loop (the same thing happens when filesystem reports all inodes are locked / busy and it cannot writeback anything). But it's getting a bit ugly and is it really better than somehow waiting inside XFS for metadata writeback to occur? Any idea Dave?

Quoted 4 lines

I tend to think that the whole point of background writeback is to do it asynchronously and keep the IO pipe full by avoiding blocking on any specific object. i.e. if we can't do writeback from this object, then skip it and do it from the next....

Agreed.

Quoted 5 lines

I think we could probably block ->write_metadata if necessary via a completion/wakeup style notification when a specific LSN is reached by the log tail, but realistically if there's any amount of data needing to be written it'll throttle data writes because the IO pipeline is being kept full by background metadata writes....

So the problem I'm concerned about is a corner case. Consider a situation when you have no dirty data, only dirty metadata but enough of them to trigger background writeback. How should metadata writeback behave for XFS in this case? Who should be responsible that wb_writeback() just does not loop invoking ->write_metadata() as fast as CPU allows until xfsaild makes enough progress?

Thinking about this today, I think this looping prevention belongs to wb_writeback(). Sadly we don't have much info to decide how long to sleep before trying more writeback so we'd have to just sleep for <some_magic_amount> if we found no writeback happened in the last writeback round before going through the whole writeback loop again. And ->write_metadata() for XFS would need to always return 0 (as in "no progress made") to make sure this busyloop avoidance logic in wb_writeback() triggers. ext4 and btrfs would return number of bytes written from ->write_metadata (or just 1 would be enough to indicate some progress in metadata writeback was made and busyloop avoidance is not needed).

Quoted 4 lines

So overall I think I have pretty clear idea on how this all should work to make ->write_metadata useful for btrfs, XFS, and ext4 and we agree on the plan.

I'm glad you do, I'm still confused. I'm totally fine with sending a % to the fs to figure out what it wants, what I'm confused about is how to get that % for xfs? Since xfs doesn't mark its actual buffers dirty, so wouldn't use account_metadata_dirtied and it's family, how do we generate this % for xfs? Or am I misunderstanding and you do plan to use those helpers? If you do plan to use them, then we just need to figure out what we want the ratio to be of, and then you'll be happy Dave? I'm not trying to argue with you Dave, we're just in that "talking past each other" stage of every email conversation we've ever had, I'm trying to get to the "we both understand what we're both saying and are happy again" stage. Thanks,

Josef

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

maintainer
#20 lore raw

Re: [PATCH v3 06/10] writeback: introduce super_operations->write_metadata

Quoted 176 lines · Josef Bacik
Quoted 170 lines · Jan Kara
Quoted 49 lines · Dave Chinner
Quoted 48 lines · Josef Bacik
Quoted 47 lines · Jan Kara
Quoted 45 lines · Dave Chinner
Quoted 18 lines · Jan Kara
Quoted 6 lines · Dave Chinner

IOWs, treating metadata like it's one great big data inode doesn't seem to me to be the right abstraction to use for this - in most fileystems it's a bunch of objects with a complex dependency tree and unknown write ordering, not an inode full of data that can be sequentially written.

Quoted 10 lines

Maybe we need multiple ops with well defined behaviours. e.g. ->writeback_metadata() for background writeback, ->sync_metadata() for sync based operations. That way different filesystems can ignore the parts they don't need simply by not implementing those operations, and the writeback code doesn't need to try to cater for all operations through the one op. The writeback code should be cleaner, the filesystem code should be cleaner, and we can tailor the work guidelines for each operation separately so there's less mismatch between what writeback is asking and how filesystems track dirty metadata...

Quoted 7 lines

I agree that writeback for memory cleaning and writeback for data integrity are two very different things especially for metadata. In fact for data integrity writeback we already have ->sync_fs operation so there the functionality gets duplicated. What we could do is that in writeback_sb_inodes() we'd call ->write_metadata only when work->for_kupdate or work->for_background is set. That way ->write_metadata would be called only for memory cleaning purposes.

That makes sense, but I still think we need a better indication of how much writeback we need to do than just "writeback this chunk of pages". That "writeback a chunk" interface is necessary to share writeback bandwidth across numerous data inodes so that we don't starve any one inode of writeback bandwidth. That's unnecessary for metadata writeback on a superblock - we don't need to share that bandwidth around hundreds or thousands of inodes. What we actually need to know is how much writeback we need to do as a total of all the dirty metadata on the superblock.

Sure, that's not ideal for btrfs and mayext4, but we can write a simple generic helper that converts "flush X percent of dirty metadata" to a page/byte chunk as the current code does. DOing it this way allows filesystems to completely internalise the accounting that needs to be done, rather than trying to hack around a writeback accounting interface with large impedance mismatches to how the filesystem accounts for dirty metadata and/or tracks writeback progress.

Quoted 7 lines
Quoted 5 lines
Quoted 5 lines

Let me think loud on how we could tie this into how memory cleaning writeback currently works - the one with for_background == 1 which is generally used to get amount of dirty pages in the system under control. We have a queue of inodes to write, we iterate over this queue and ask each inode to write some amount (e.g. 64 M - exact amount depends on measured

It's a maximum of 1024 pages per inode.

That's actually a minimum, not maximum, if I read the code in writeback_chunk_size() right.

Quoted 23 lines
Quoted 16 lines
Quoted 16 lines

writeback bandwidth etc.). Some amount from that inode gets written and we continue with the next inode in the queue (put this one at the end of the queue if it still has dirty pages). We do this until:

a) the number of dirty pages in the system is below background dirty limit and the number dirty pages for this device is below background dirty limit for this device.
b) run out of dirty inodes on this device
c) someone queues different type of writeback

And we need to somehow incorporate metadata writeback into this loop. I see two questions here:

1) When / how often should we ask for metadata writeback?
2) How much to ask to write in one go?

Quoted 6 lines
Quoted 6 lines

The second question is especially tricky in the presence of completely async metadata flushing in XFS - we can ask to write say half of dirty metadata but then we have no idea whether the next observation of dirty metadata counters is with that part of metadata already under writeback / cleaned or whether xfsaild didn't even start working and pushing more has no sense.

Quoted 6 lines

Well, like with ext4, we've also got to consider that a bunch of the recently dirtied metadata (e.g. from delalloc, EOF updates on IO completion, etc) is still pinned in memory because the journal has not been flushed/checkpointed. Hence we should not be attempting to write back metadata we've dirtied as a result of writing data in the background writeback loop.

Agreed. Actually for ext4 I would not expose 'pinned' buffers as dirty to VM - the journalling layer currently already works that way and it works well for us. But that's just a small technical detail and different filesystems can decide differently.

Quoted 8 lines

That greatly simplifies what we need to consider here. That is, we just need to sample the ratio of dirty metadata to clean metadata before we start data writeback, and we calculate the amount of metadata writeback we should trigger from there. We only need to do this *once* per background writeback scan for a superblock as there is no need for sharing bandwidth between lots of data inodes - there's only one metadata inode for ext4/btrfs, and XFS is completely async....

OK, agreed again.

Quoted 11 lines
Quoted 10 lines
Quoted 10 lines

Partly, this could be dealt with by telling the filesystem "metadata dirty target" - i.e. "get your dirty metadata counters below X"
- and whether we communicate that in bytes, pages, or a fraction of current dirty metadata counter value is a detail I don't have a strong opinion on now. And the fact is the amount written by the filesystem doesn't have to be very accurate anyway - we basically just want to make some forward progress with writing metadata, don't want that to take too long (so that other writeback from the thread isn't stalled), and if writeback code is unhappy about the state of counters next time it looks, it will ask the filesystem again...

Quoted 2 lines

Right. The problem is communicating "how much" to the filesystem in a useful manner....

Yep. I'm fine with communication in the form of 'write X% of your dirty metadata'. That should be useful for XFS and as you mentioned in some previous email, we can provide a helper function to compute number of pages to write (including some reasonable upper limit to bound time spent in one ->write_metadata invocation) for ext4 and btrfs.

Quoted 12 lines
Quoted 11 lines
Quoted 11 lines

This gets me directly to another problem with async nature of XFS metadata writeback. That is that it could get writeback thread into busyloop - we are supposed to terminate memory cleaning writeback only once dirty counters are below limit and in case dirty metadata is causing counters to be over limit, we would just ask in a loop XFS to get metadata below the target. I suppose XFS could just return "nothing written" from its ->write_metadata operation and in such case we could sleep a bit before going for another writeback loop (the same thing happens when filesystem reports all inodes are locked / busy and it cannot writeback anything). But it's getting a bit ugly and is it really better than somehow waiting inside XFS for metadata writeback to occur? Any idea Dave?

Quoted 4 lines

I tend to think that the whole point of background writeback is to do it asynchronously and keep the IO pipe full by avoiding blocking on any specific object. i.e. if we can't do writeback from this object, then skip it and do it from the next....

Agreed.

Quoted 5 lines

I think we could probably block ->write_metadata if necessary via a completion/wakeup style notification when a specific LSN is reached by the log tail, but realistically if there's any amount of data needing to be written it'll throttle data writes because the IO pipeline is being kept full by background metadata writes....

So the problem I'm concerned about is a corner case. Consider a situation when you have no dirty data, only dirty metadata but enough of them to trigger background writeback. How should metadata writeback behave for XFS in this case? Who should be responsible that wb_writeback() just does not loop invoking ->write_metadata() as fast as CPU allows until xfsaild makes enough progress?

Thinking about this today, I think this looping prevention belongs to wb_writeback(). Sadly we don't have much info to decide how long to sleep before trying more writeback so we'd have to just sleep for <some_magic_amount> if we found no writeback happened in the last writeback round before going through the whole writeback loop again. And ->write_metadata() for XFS would need to always return 0 (as in "no progress made") to make sure this busyloop avoidance logic in wb_writeback() triggers. ext4 and btrfs would return number of bytes written from ->write_metadata (or just 1 would be enough to indicate some progress in metadata writeback was made and busyloop avoidance is not needed).

Quoted 4 lines

So overall I think I have pretty clear idea on how this all should work to make ->write_metadata useful for btrfs, XFS, and ext4 and we agree on the plan.

Quoted 5 lines

I'm glad you do, I'm still confused. I'm totally fine with sending a % to the fs to figure out what it wants, what I'm confused about is how to get that % for xfs? Since xfs doesn't mark its actual buffers dirty, so wouldn't use account_metadata_dirtied and it's family, how do we generate this % for xfs? Or am I misunderstanding and you do plan to use those helpers?

AFAIU he plans to use account_metadata_dirtied() & co. in XFS.

Quoted 2 lines

If you do plan to use them, then we just need to figure out what we want the ratio to be of, and then you'll be happy Dave?

Reasonably natural dirty target would be dirty_background_ratio of total metadata amount to be dirty. We would have to be somewhat creative if dirty_background_bytes is actually set instead of dirty_background_ratio and use ratio like dirty_background_bytes / (data + metadata amount) but it's doable...

Honza

Signature · 8 lines
Jan Kara <[email protected]>
SUSE Labs, CR

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#21 lore raw

Re: [PATCH v3 06/10] writeback: introduce super_operations->write_metadata

Quoted 185 lines · Jan Kara
Quoted 176 lines · Josef Bacik
Quoted 170 lines · Jan Kara
Quoted 49 lines · Dave Chinner
Quoted 48 lines · Josef Bacik
Quoted 47 lines · Jan Kara
Quoted 45 lines · Dave Chinner
Quoted 18 lines · Jan Kara
Quoted 6 lines · Dave Chinner

IOWs, treating metadata like it's one great big data inode doesn't seem to me to be the right abstraction to use for this - in most fileystems it's a bunch of objects with a complex dependency tree and unknown write ordering, not an inode full of data that can be sequentially written.

Quoted 10 lines

Maybe we need multiple ops with well defined behaviours. e.g. ->writeback_metadata() for background writeback, ->sync_metadata() for sync based operations. That way different filesystems can ignore the parts they don't need simply by not implementing those operations, and the writeback code doesn't need to try to cater for all operations through the one op. The writeback code should be cleaner, the filesystem code should be cleaner, and we can tailor the work guidelines for each operation separately so there's less mismatch between what writeback is asking and how filesystems track dirty metadata...

Quoted 7 lines

I agree that writeback for memory cleaning and writeback for data integrity are two very different things especially for metadata. In fact for data integrity writeback we already have ->sync_fs operation so there the functionality gets duplicated. What we could do is that in writeback_sb_inodes() we'd call ->write_metadata only when work->for_kupdate or work->for_background is set. That way ->write_metadata would be called only for memory cleaning purposes.

That makes sense, but I still think we need a better indication of how much writeback we need to do than just "writeback this chunk of pages". That "writeback a chunk" interface is necessary to share writeback bandwidth across numerous data inodes so that we don't starve any one inode of writeback bandwidth. That's unnecessary for metadata writeback on a superblock - we don't need to share that bandwidth around hundreds or thousands of inodes. What we actually need to know is how much writeback we need to do as a total of all the dirty metadata on the superblock.

Sure, that's not ideal for btrfs and mayext4, but we can write a simple generic helper that converts "flush X percent of dirty metadata" to a page/byte chunk as the current code does. DOing it this way allows filesystems to completely internalise the accounting that needs to be done, rather than trying to hack around a writeback accounting interface with large impedance mismatches to how the filesystem accounts for dirty metadata and/or tracks writeback progress.

Quoted 7 lines
Quoted 5 lines
Quoted 5 lines

Let me think loud on how we could tie this into how memory cleaning writeback currently works - the one with for_background == 1 which is generally used to get amount of dirty pages in the system under control. We have a queue of inodes to write, we iterate over this queue and ask each inode to write some amount (e.g. 64 M - exact amount depends on measured

It's a maximum of 1024 pages per inode.

That's actually a minimum, not maximum, if I read the code in writeback_chunk_size() right.

Quoted 23 lines
Quoted 16 lines
Quoted 16 lines

writeback bandwidth etc.). Some amount from that inode gets written and we continue with the next inode in the queue (put this one at the end of the queue if it still has dirty pages). We do this until:

a) the number of dirty pages in the system is below background dirty limit and the number dirty pages for this device is below background dirty limit for this device.
b) run out of dirty inodes on this device
c) someone queues different type of writeback

And we need to somehow incorporate metadata writeback into this loop. I see two questions here:

1) When / how often should we ask for metadata writeback?
2) How much to ask to write in one go?

Quoted 6 lines
Quoted 6 lines

The second question is especially tricky in the presence of completely async metadata flushing in XFS - we can ask to write say half of dirty metadata but then we have no idea whether the next observation of dirty metadata counters is with that part of metadata already under writeback / cleaned or whether xfsaild didn't even start working and pushing more has no sense.

Quoted 6 lines

Well, like with ext4, we've also got to consider that a bunch of the recently dirtied metadata (e.g. from delalloc, EOF updates on IO completion, etc) is still pinned in memory because the journal has not been flushed/checkpointed. Hence we should not be attempting to write back metadata we've dirtied as a result of writing data in the background writeback loop.

Agreed. Actually for ext4 I would not expose 'pinned' buffers as dirty to VM - the journalling layer currently already works that way and it works well for us. But that's just a small technical detail and different filesystems can decide differently.

Quoted 8 lines

That greatly simplifies what we need to consider here. That is, we just need to sample the ratio of dirty metadata to clean metadata before we start data writeback, and we calculate the amount of metadata writeback we should trigger from there. We only need to do this *once* per background writeback scan for a superblock as there is no need for sharing bandwidth between lots of data inodes - there's only one metadata inode for ext4/btrfs, and XFS is completely async....

OK, agreed again.

Quoted 11 lines
Quoted 10 lines
Quoted 10 lines

Partly, this could be dealt with by telling the filesystem "metadata dirty target" - i.e. "get your dirty metadata counters below X"
- and whether we communicate that in bytes, pages, or a fraction of current dirty metadata counter value is a detail I don't have a strong opinion on now. And the fact is the amount written by the filesystem doesn't have to be very accurate anyway - we basically just want to make some forward progress with writing metadata, don't want that to take too long (so that other writeback from the thread isn't stalled), and if writeback code is unhappy about the state of counters next time it looks, it will ask the filesystem again...

Quoted 2 lines

Right. The problem is communicating "how much" to the filesystem in a useful manner....

Yep. I'm fine with communication in the form of 'write X% of your dirty metadata'. That should be useful for XFS and as you mentioned in some previous email, we can provide a helper function to compute number of pages to write (including some reasonable upper limit to bound time spent in one ->write_metadata invocation) for ext4 and btrfs.

Quoted 12 lines
Quoted 11 lines
Quoted 11 lines

This gets me directly to another problem with async nature of XFS metadata writeback. That is that it could get writeback thread into busyloop - we are supposed to terminate memory cleaning writeback only once dirty counters are below limit and in case dirty metadata is causing counters to be over limit, we would just ask in a loop XFS to get metadata below the target. I suppose XFS could just return "nothing written" from its ->write_metadata operation and in such case we could sleep a bit before going for another writeback loop (the same thing happens when filesystem reports all inodes are locked / busy and it cannot writeback anything). But it's getting a bit ugly and is it really better than somehow waiting inside XFS for metadata writeback to occur? Any idea Dave?

Quoted 4 lines

I tend to think that the whole point of background writeback is to do it asynchronously and keep the IO pipe full by avoiding blocking on any specific object. i.e. if we can't do writeback from this object, then skip it and do it from the next....

Agreed.

Quoted 5 lines

I think we could probably block ->write_metadata if necessary via a completion/wakeup style notification when a specific LSN is reached by the log tail, but realistically if there's any amount of data needing to be written it'll throttle data writes because the IO pipeline is being kept full by background metadata writes....

So the problem I'm concerned about is a corner case. Consider a situation when you have no dirty data, only dirty metadata but enough of them to trigger background writeback. How should metadata writeback behave for XFS in this case? Who should be responsible that wb_writeback() just does not loop invoking ->write_metadata() as fast as CPU allows until xfsaild makes enough progress?

Thinking about this today, I think this looping prevention belongs to wb_writeback(). Sadly we don't have much info to decide how long to sleep before trying more writeback so we'd have to just sleep for <some_magic_amount> if we found no writeback happened in the last writeback round before going through the whole writeback loop again. And ->write_metadata() for XFS would need to always return 0 (as in "no progress made") to make sure this busyloop avoidance logic in wb_writeback() triggers. ext4 and btrfs would return number of bytes written from ->write_metadata (or just 1 would be enough to indicate some progress in metadata writeback was made and busyloop avoidance is not needed).

Quoted 4 lines

So overall I think I have pretty clear idea on how this all should work to make ->write_metadata useful for btrfs, XFS, and ext4 and we agree on the plan.

Quoted 5 lines

I'm glad you do, I'm still confused. I'm totally fine with sending a % to the fs to figure out what it wants, what I'm confused about is how to get that % for xfs? Since xfs doesn't mark its actual buffers dirty, so wouldn't use account_metadata_dirtied and it's family, how do we generate this % for xfs? Or am I misunderstanding and you do plan to use those helpers?

AFAIU he plans to use account_metadata_dirtied() & co. in XFS.

Quoted 9 lines
Quoted 2 lines

If you do plan to use them, then we just need to figure out what we want the ratio to be of, and then you'll be happy Dave?

Reasonably natural dirty target would be dirty_background_ratio of total metadata amount to be dirty. We would have to be somewhat creative if dirty_background_bytes is actually set instead of dirty_background_ratio and use ratio like dirty_background_bytes / (data + metadata amount) but it's doable...

Oh ok well if that's the case then I'll fix this up to be a ratio, test everything, and send it along probably early next week. Thanks,

Josef

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#22 lore raw

Re: [PATCH v3 06/10] writeback: introduce super_operations->write_metadata

Quoted 6 lines · IST Josef Bacik

On Wed, Jan 03, 2018 at 05:26:03PM +0100, Jan Kara wrote:

Oh ok well if that's the case then I'll fix this up to be a ratio, test everything, and send it along probably early next week. Thanks,

Hi Josef,

Did you get a chance to work on the next version of this patchset?

Signature · 1 line
chandan
#23 lore raw

Re: [PATCH v3 06/10] writeback: introduce super_operations->write_metadata

Quoted 4 lines · IST Chandan Rajendra
Quoted 3 lines · IST Josef Bacik

On Wed, Jan 03, 2018 at 05:26:03PM +0100, Jan Kara wrote:

Quoted 10 lines
Quoted 3 lines

Oh ok well if that's the case then I'll fix this up to be a ratio, test everything, and send it along probably early next week. Thanks,

Hi Josef,

Did you get a chance to work on the next version of this patchset?

Josef, Any updates on this and the "Kill Btree inode" patchset?

Signature · 1 line
chandan
#24 lore raw

Re: [PATCH v3 06/10] writeback: introduce super_operations->write_metadata

In reply to Jan Kara
Quoted 14 lines · Jan Kara
Quoted 5 lines · Dave Chinner

I think we could probably block ->write_metadata if necessary via a completion/wakeup style notification when a specific LSN is reached by the log tail, but realistically if there's any amount of data needing to be written it'll throttle data writes because the IO pipeline is being kept full by background metadata writes....

So the problem I'm concerned about is a corner case. Consider a situation when you have no dirty data, only dirty metadata but enough of them to trigger background writeback. How should metadata writeback behave for XFS in this case? Who should be responsible that wb_writeback() just does not loop invoking ->write_metadata() as fast as CPU allows until xfsaild makes enough progress?

Quoted 2 lines

Thinking about this today, I think this looping prevention belongs to wb_writeback().

Well, backgroudn data writeback can block in two ways. One is during IO submission when the request queue is full, the other is when all dirty inodes have had some work done on them and have all been moved to b_more_io - wb_writeback waits for the __I_SYNC bit to be cleared on the last(?) inode on that list, hence backing off before submitting more IO.

IOws, there's a "during writeback" blocking mechanism as well as a "between cycles" block mechanism.

Quoted 4 lines

Sadly we don't have much info to decide how long to sleep before trying more writeback so we'd have to just sleep for <some_magic_amount> if we found no writeback happened in the last writeback round before going through the whole writeback loop again.

Right - I don't think we can provide a generic "between cycles" blocking mechanism for XFS, but I'm pretty sure we can emulate a "during writeback" blocking mechanism to avoid busy looping inside the XFS code.

e.g. if we get a writeback call that asks for 5% to be written, and we already have a metadata writeback target of 5% in place, that means we should block for a while. That would emulate request queue blocking and prevent busy looping in this case....

Quoted 6 lines

And
->write_metadata() for XFS would need to always return 0 (as in "no progress made") to make sure this busyloop avoidance logic in wb_writeback() triggers. ext4 and btrfs would return number of bytes written from ->write_metadata (or just 1 would be enough to indicate some progress in metadata writeback was made and busyloop avoidance is not needed).

Well, if we block for a little while, we can indicate that progress has been made and this whole mess would go away, right?

Cheers,

Dave.

Signature · 8 lines
Dave Chinner
[email protected]

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
maintainer
#25 lore raw

Re: [PATCH v3 06/10] writeback: introduce super_operations->write_metadata

Quoted 38 lines · Dave Chinner
Quoted 14 lines · Jan Kara
Quoted 5 lines · Dave Chinner

I think we could probably block ->write_metadata if necessary via a completion/wakeup style notification when a specific LSN is reached by the log tail, but realistically if there's any amount of data needing to be written it'll throttle data writes because the IO pipeline is being kept full by background metadata writes....

So the problem I'm concerned about is a corner case. Consider a situation when you have no dirty data, only dirty metadata but enough of them to trigger background writeback. How should metadata writeback behave for XFS in this case? Who should be responsible that wb_writeback() just does not loop invoking ->write_metadata() as fast as CPU allows until xfsaild makes enough progress?

Quoted 2 lines

Thinking about this today, I think this looping prevention belongs to wb_writeback().

Well, backgroudn data writeback can block in two ways. One is during IO submission when the request queue is full, the other is when all dirty inodes have had some work done on them and have all been moved to b_more_io - wb_writeback waits for the __I_SYNC bit to be cleared on the last(?) inode on that list, hence backing off before submitting more IO.

IOws, there's a "during writeback" blocking mechanism as well as a "between cycles" block mechanism.

Quoted 4 lines

Sadly we don't have much info to decide how long to sleep before trying more writeback so we'd have to just sleep for <some_magic_amount> if we found no writeback happened in the last writeback round before going through the whole writeback loop again.

Right - I don't think we can provide a generic "between cycles" blocking mechanism for XFS, but I'm pretty sure we can emulate a "during writeback" blocking mechanism to avoid busy looping inside the XFS code.

Quoted 4 lines

e.g. if we get a writeback call that asks for 5% to be written, and we already have a metadata writeback target of 5% in place, that means we should block for a while. That would emulate request queue blocking and prevent busy looping in this case....

If you can do this in XFS then fine, it saves some mess in the generic code.

Quoted 9 lines
Quoted 6 lines

And
->write_metadata() for XFS would need to always return 0 (as in "no progress made") to make sure this busyloop avoidance logic in wb_writeback() triggers. ext4 and btrfs would return number of bytes written from ->write_metadata (or just 1 would be enough to indicate some progress in metadata writeback was made and busyloop avoidance is not needed).

Well, if we block for a little while, we can indicate that progress has been made and this whole mess would go away, right?

Right. So let's just ignore the problem for the sake of Josef's patch set. Once the patches land and when XFS starts using the infrastructure, we will make sure this is handled properly.

Honza

Signature · 8 lines
Jan Kara <[email protected]>
SUSE Labs, CR

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
maintainer
#26 lore raw

Re: [PATCH v3 06/10] writeback: introduce super_operations->write_metadata

In reply to Josef Bacik
Quoted 11 lines · Josef Bacik
fs/fs-writeback.c +3 -3
@@ -1621,12 +1647,18 @@ static long writeback_sb_inodes(struct super_block *sb,
 		 * background threshold and other termination conditions.
 		 */
 		if (wrote) {
-			if (time_is_before_jiffies(start_time + HZ / 10UL))
-				break;
-			if (work->nr_pages <= 0)
+			if (time_is_before_jiffies(start_time + HZ / 10UL) ||
+			    work->nr_pages <= 0) {
+				done = true;
 				break;

fs/fs-writeback.c static long writeback_sb_inodes(struct super_block *sb, · line 1663

Quoted 10 lines
fs/fs-writeback.c +6 -0
+			}
 		}
 	}
+	if (!done && sb->s_op->write_metadata) {
+		spin_unlock(&wb->list_lock);
+		wrote += writeback_sb_metadata(sb, wb, work);
+		spin_lock(&wb->list_lock);
+	}
 	return wrote;
 }

One thing I've notice when looking at this patch again: This duplicates the metadata writeback done in __writeback_inodes_wb(). So you probably need a new helper function like writeback_sb() that will call writeback_sb_inodes() and handle metadata writeback and call that from wb_writeback() instead of writeback_sb_inodes() directly.

Honza

Quoted 51 lines
fs/fs-writeback.c +31 -3
@@ -1635,6 +1667,7 @@ static long __writeback_inodes_wb(struct bdi_writeback *wb,
 {
 	unsigned long start_time = jiffies;
 	long wrote = 0;
+	bool done = false;
 
 	while (!list_empty(&wb->b_io)) {
 		struct inode *inode = wb_inode(wb->b_io.prev);
@@ -1654,12 +1687,39 @@ static long __writeback_inodes_wb(struct bdi_writeback *wb,
 
 		/* refer to the same tests at the end of writeback_sb_inodes */
 		if (wrote) {
-			if (time_is_before_jiffies(start_time + HZ / 10UL))
-				break;
-			if (work->nr_pages <= 0)
+			if (time_is_before_jiffies(start_time + HZ / 10UL) ||
+			    work->nr_pages <= 0) {
+				done = true;
 				break;
+			}
 		}
 	}
+
+	if (!done && wb_stat(wb, WB_METADATA_DIRTY_BYTES)) {
+		LIST_HEAD(list);
+
+		spin_unlock(&wb->list_lock);
+		spin_lock(&wb->bdi->sb_list_lock);
+		list_splice_init(&wb->bdi->dirty_sb_list, &list);
+		while (!list_empty(&list)) {
+			struct super_block *sb;
+
+			sb = list_first_entry(&list, struct super_block,
+					      s_bdi_dirty_list);
+			list_move_tail(&sb->s_bdi_dirty_list,
+				       &wb->bdi->dirty_sb_list);
+			if (!sb->s_op->write_metadata)
+				continue;
+			if (!trylock_super(sb))
+				continue;
+			spin_unlock(&wb->bdi->sb_list_lock);
+			wrote += writeback_sb_metadata(sb, wb, work);
+			spin_lock(&wb->bdi->sb_list_lock);
+			up_read(&sb->s_umount);
+		}
+		spin_unlock(&wb->bdi->sb_list_lock);
+		spin_lock(&wb->list_lock);
+	}
 	/* Leave any unwritten inodes on b_io */
 	return wrote;
 }
Signature · 8 lines
Jan Kara <[email protected]>
SUSE Labs, CR

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#27 lore raw

PATCH v3 7/10 export radix_tree_iter_tag_set

In reply to Josef Bacik

From: Josef Bacik <[email protected]>

We use this in btrfs for metadata writeback.

---
 lib/radix-tree.c | 1 +
 1 file changed, 1 insertion(+)
lib/radix-tree.c +1 -0
index 8b1feca1230a..0c1cde9fcb69 100644
@@ -1459,6 +1459,7 @@ void radix_tree_iter_tag_set(struct radix_tree_root *root,
 {
 	node_tag_set(root, iter->node, tag, iter_offset(iter));
 }
+EXPORT_SYMBOL(radix_tree_iter_tag_set);
 
 static void node_tag_clear(struct radix_tree_root *root,
 				struct radix_tree_node *node,
Signature · 7 lines
2.7.5

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#28 lore raw

PATCH v3 8/10 Btrfs: kill the btree_inode

In reply to Josef Bacik

From: Josef Bacik <[email protected]>

In order to more efficiently support sub-page blocksizes we need to stop allocating pages from pagecache for our metadata. Instead switch to using the account_metadata* counters for making sure we are keeping the system aware of how much dirty metadata we have, and use the ->free_cached_objects super operation in order to handle freeing up extent buffers. This greatly simplifies how we deal with extent buffers as now we no longer have to tie the page cache reclaimation stuff to the extent buffer stuff. This will also allow us to simply kmalloc() our data for sub-page blocksizes.

---
 fs/btrfs/btrfs_inode.h                 |   1 -
 fs/btrfs/ctree.c                       |  18 +-
 fs/btrfs/ctree.h                       |  17 +-
 fs/btrfs/dir-item.c                    |   2 +-
 fs/btrfs/disk-io.c                     | 386 ++++----------
 fs/btrfs/extent-tree.c                 |  14 +-
 fs/btrfs/extent_io.c                   | 906 ++++++++++++++++++---------------
 fs/btrfs/extent_io.h                   |  51 +-
 fs/btrfs/inode.c                       |   6 +-
 fs/btrfs/print-tree.c                  |  13 +-
 fs/btrfs/reada.c                       |   2 +-
 fs/btrfs/root-tree.c                   |   2 +-
 fs/btrfs/super.c                       |  31 +-
 fs/btrfs/tests/btrfs-tests.c           |  36 +-
 fs/btrfs/tests/extent-buffer-tests.c   |   3 +-
 fs/btrfs/tests/extent-io-tests.c       |   4 +-
 fs/btrfs/tests/free-space-tree-tests.c |   3 +-
 fs/btrfs/tests/inode-tests.c           |   4 +-
 fs/btrfs/tests/qgroup-tests.c          |   3 +-
 fs/btrfs/transaction.c                 |  13 +-
 20 files changed, 744 insertions(+), 771 deletions(-)
fs/btrfs/btrfs_inode.h +0 -1
index f9c6887a8b6c..24582650622d 100644
@@ -241,7 +241,6 @@ static inline u64 btrfs_ino(const struct btrfs_inode *inode)
 	u64 ino = inode->location.objectid;
 
 	/*
-	 * !ino: btree_inode
 	 * type == BTRFS_ROOT_ITEM_KEY: subvol dir
 	 */
 	if (!ino || inode->location.type == BTRFS_ROOT_ITEM_KEY)
fs/btrfs/ctree.c +10 -8
index 531e0a8645b0..3c6610b5d0d3 100644
@@ -1361,7 +1361,8 @@ tree_mod_log_rewind(struct btrfs_fs_info *fs_info, struct btrfs_path *path,
 
 	if (tm->op == MOD_LOG_KEY_REMOVE_WHILE_FREEING) {
 		BUG_ON(tm->slot != 0);
-		eb_rewin = alloc_dummy_extent_buffer(fs_info, eb->start);
+		eb_rewin = alloc_dummy_extent_buffer(fs_info->eb_info,
+						     eb->start, eb->len);
 		if (!eb_rewin) {
 			btrfs_tree_read_unlock_blocking(eb);
 			free_extent_buffer(eb);
@@ -1444,7 +1445,8 @@ get_old_root(struct btrfs_root *root, u64 time_seq)
 	} else if (old_root) {
 		btrfs_tree_read_unlock(eb_root);
 		free_extent_buffer(eb_root);
-		eb = alloc_dummy_extent_buffer(fs_info, logical);
+		eb = alloc_dummy_extent_buffer(root->fs_info->eb_info, logical,
+					       root->fs_info->nodesize);
 	} else {
 		btrfs_set_lock_blocking_rw(eb_root, BTRFS_READ_LOCK);
 		eb = btrfs_clone_extent_buffer(eb_root);
@@ -1675,7 +1677,7 @@ int btrfs_realloc_node(struct btrfs_trans_handle *trans,
 			continue;
 		}
 
-		cur = find_extent_buffer(fs_info, blocknr);
+		cur = find_extent_buffer(fs_info->eb_info, blocknr);
 		if (cur)
 			uptodate = btrfs_buffer_uptodate(cur, gen, 0);
 		else
@@ -1748,7 +1750,7 @@ static noinline int generic_bin_search(struct extent_buffer *eb,
 	int err;
 
 	if (low > high) {
-		btrfs_err(eb->fs_info,
+		btrfs_err(eb->eb_info->fs_info,
 		 "%s: low (%d) > high (%d) eb %llu owner %llu level %d",
 			  __func__, low, high, eb->start,
 			  btrfs_header_owner(eb), btrfs_header_level(eb));
@@ -2260,7 +2262,7 @@ static void reada_for_search(struct btrfs_fs_info *fs_info,
 
 	search = btrfs_node_blockptr(node, slot);
 	blocksize = fs_info->nodesize;
-	eb = find_extent_buffer(fs_info, search);
+	eb = find_extent_buffer(fs_info->eb_info, search);
 	if (eb) {
 		free_extent_buffer(eb);
 		return;
@@ -2319,7 +2321,7 @@ static noinline void reada_for_balance(struct btrfs_fs_info *fs_info,
 	if (slot > 0) {
 		block1 = btrfs_node_blockptr(parent, slot - 1);
 		gen = btrfs_node_ptr_generation(parent, slot - 1);
-		eb = find_extent_buffer(fs_info, block1);
+		eb = find_extent_buffer(fs_info->eb_info, block1);
 		/*
 		 * if we get -eagain from btrfs_buffer_uptodate, we
 		 * don't want to return eagain here.  That will loop
@@ -2332,7 +2334,7 @@ static noinline void reada_for_balance(struct btrfs_fs_info *fs_info,
 	if (slot + 1 < nritems) {
 		block2 = btrfs_node_blockptr(parent, slot + 1);
 		gen = btrfs_node_ptr_generation(parent, slot + 1);
-		eb = find_extent_buffer(fs_info, block2);
+		eb = find_extent_buffer(fs_info->eb_info, block2);
 		if (eb && btrfs_buffer_uptodate(eb, gen, 1) != 0)
 			block2 = 0;
 		free_extent_buffer(eb);
@@ -2450,7 +2452,7 @@ read_block_for_search(struct btrfs_root *root, struct btrfs_path *p,
 	blocknr = btrfs_node_blockptr(b, slot);
 	gen = btrfs_node_ptr_generation(b, slot);
 
-	tmp = find_extent_buffer(fs_info, blocknr);
+	tmp = find_extent_buffer(fs_info->eb_info, blocknr);
 	if (tmp) {
 		/* first we do an atomic uptodate check */
 		if (btrfs_buffer_uptodate(tmp, gen, 1) > 0) {
fs/btrfs/ctree.h +8 -9
index 4ffbe9f07cf7..a7c764a1ee48 100644
@@ -40,6 +40,7 @@
 #include <linux/sizes.h>
 #include <linux/dynamic_debug.h>
 #include <linux/refcount.h>
+#include <linux/list_lru.h>
 #include "extent_io.h"
 #include "extent_map.h"
 #include "async-thread.h"
@@ -701,6 +702,7 @@ struct btrfs_device;
 struct btrfs_fs_devices;
 struct btrfs_balance_control;
 struct btrfs_delayed_root;
+struct btrfs_eb_info;
 
 #define BTRFS_FS_BARRIER			1
 #define BTRFS_FS_CLOSING_START			2
@@ -818,7 +820,7 @@ struct btrfs_fs_info {
 	struct btrfs_super_block *super_copy;
 	struct btrfs_super_block *super_for_commit;
 	struct super_block *sb;
-	struct inode *btree_inode;
+	struct btrfs_eb_info *eb_info;
 	struct mutex tree_log_mutex;
 	struct mutex transaction_kthread_mutex;
 	struct mutex cleaner_mutex;
@@ -1060,10 +1062,6 @@ struct btrfs_fs_info {
 	/* readahead works cnt */
 	atomic_t reada_works_cnt;
 
-	/* Extent buffer radix tree */
-	spinlock_t buffer_lock;
-	struct radix_tree_root buffer_radix;
-
 	/* next backup root to be overwritten */
 	int backup_root_index;
 
@@ -1563,7 +1561,7 @@ static inline void btrfs_set_device_total_bytes(struct extent_buffer *eb,
 {
 	BUILD_BUG_ON(sizeof(u64) !=
 		     sizeof(((struct btrfs_dev_item *)0))->total_bytes);
-	WARN_ON(!IS_ALIGNED(val, eb->fs_info->sectorsize));
+	WARN_ON(!IS_ALIGNED(val, eb->eb_info->fs_info->sectorsize));
 	btrfs_set_64(eb, s, offsetof(struct btrfs_dev_item, total_bytes), val);
 }
 
@@ -2962,6 +2960,10 @@ static inline int btrfs_need_cleaner_sleep(struct btrfs_fs_info *fs_info)
 
 static inline void free_fs_info(struct btrfs_fs_info *fs_info)
 {
+	if (fs_info->eb_info) {
+		list_lru_destroy(&fs_info->eb_info->lru_list);
+		kfree(fs_info->eb_info);
+	}
 	kfree(fs_info->balance_ctl);
 	kfree(fs_info->delayed_root);
 	kfree(fs_info->extent_root);
@@ -3185,9 +3187,6 @@ int btrfs_create_subvol_root(struct btrfs_trans_handle *trans,
 			     struct btrfs_root *new_root,
 			     struct btrfs_root *parent_root,
 			     u64 new_dirid);
-int btrfs_merge_bio_hook(struct page *page, unsigned long offset,
-			 size_t size, struct bio *bio,
-			 unsigned long bio_flags);
 void btrfs_set_range_writeback(void *private_data, u64 start, u64 end);
 int btrfs_page_mkwrite(struct vm_fault *vmf);
 int btrfs_readpage(struct file *file, struct page *page);
fs/btrfs/dir-item.c +1 -1
index 41cb9196eaa8..f5782523e723 100644
@@ -496,7 +496,7 @@ int verify_dir_item(struct btrfs_fs_info *fs_info,
 bool btrfs_is_name_len_valid(struct extent_buffer *leaf, int slot,
 			     unsigned long start, u16 name_len)
 {
-	struct btrfs_fs_info *fs_info = leaf->fs_info;
+	struct btrfs_fs_info *fs_info = leaf->eb_info->fs_info;
 	struct btrfs_key key;
 	u32 read_start;
 	u32 read_end;
fs/btrfs/disk-io.c +111 -275

689 lines not on this page · raw message

fs/btrfs/extent-tree.c +8 -6
index 0bdc10b453b9..a48fb3abed0c 100644
@@ -1158,28 +1158,30 @@ int btrfs_get_extent_inline_ref_type(const struct extent_buffer *eb,
 			if (type == BTRFS_TREE_BLOCK_REF_KEY)
 				return type;
 			if (type == BTRFS_SHARED_BLOCK_REF_KEY) {
-				ASSERT(eb->fs_info);
+				ASSERT(eb->eb_info);
 				/*
 				 * Every shared one has parent tree
 				 * block, which must be aligned to
 				 * nodesize.
 				 */
 				if (offset &&
-				    IS_ALIGNED(offset, eb->fs_info->nodesize))
+				    IS_ALIGNED(offset,
+					       eb->eb_info->fs_info->nodesize))
 					return type;
 			}
 		} else if (is_data == BTRFS_REF_TYPE_DATA) {
 			if (type == BTRFS_EXTENT_DATA_REF_KEY)
 				return type;
 			if (type == BTRFS_SHARED_DATA_REF_KEY) {
-				ASSERT(eb->fs_info);
+				ASSERT(eb->eb_info->fs_info);
 				/*
 				 * Every shared one has parent tree
 				 * block, which must be aligned to
 				 * nodesize.
 				 */
 				if (offset &&
-				    IS_ALIGNED(offset, eb->fs_info->nodesize))
+				    IS_ALIGNED(offset,
+					       eb->eb_info->fs_info->nodesize))
 					return type;
 			}
 		} else {
@@ -1189,7 +1191,7 @@ int btrfs_get_extent_inline_ref_type(const struct extent_buffer *eb,
 	}
 
 	btrfs_print_leaf((struct extent_buffer *)eb);
-	btrfs_err(eb->fs_info, "eb %llu invalid extent inline ref type %d",
+	btrfs_err(eb->eb_info->fs_info, "eb %llu invalid extent inline ref type %d",
 		  eb->start, type);
 	WARN_ON(1);
 
@@ -8731,7 +8733,7 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans,
 	bytenr = btrfs_node_blockptr(path->nodes[level], path->slots[level]);
 	blocksize = fs_info->nodesize;
 
-	next = find_extent_buffer(fs_info, bytenr);
+	next = find_extent_buffer(fs_info->eb_info, bytenr);
 	if (!next) {
 		next = btrfs_find_create_tree_block(fs_info, bytenr);
 		if (IS_ERR(next))
fs/btrfs/extent_io.c +498 -408

1,404 lines not on this page · raw message

fs/btrfs/extent_io.h +37 -14

116 lines not on this page · raw message

fs/btrfs/inode.c +3 -3
index 46b5632a7c6d..27bc64fb6d3e 100644
@@ -1877,9 +1877,9 @@ static void btrfs_clear_bit_hook(void *private_data,
  * return 0 if page can be merged to bio
  * return error otherwise
  */
-int btrfs_merge_bio_hook(struct page *page, unsigned long offset,
-			 size_t size, struct bio *bio,
-			 unsigned long bio_flags)
+static int btrfs_merge_bio_hook(struct page *page, unsigned long offset,
+				size_t size, struct bio *bio,
+				unsigned long bio_flags)
 {
 	struct inode *inode = page->mapping->host;
 	struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
fs/btrfs/print-tree.c +7 -6
index 569205e651c7..f912c8166d94 100644
@@ -102,6 +102,7 @@ static void print_extent_item(struct extent_buffer *eb, int slot, int type)
 	ptr = (unsigned long)iref;
 	end = (unsigned long)ei + item_size;
 	while (ptr < end) {
+		struct btrfs_fs_info *fs_info = eb->eb_info->fs_info;
 		iref = (struct btrfs_extent_inline_ref *)ptr;
 		type = btrfs_extent_inline_ref_type(eb, iref);
 		offset = btrfs_extent_inline_ref_offset(eb, iref);
@@ -116,9 +117,9 @@ static void print_extent_item(struct extent_buffer *eb, int slot, int type)
 			 * offset is supposed to be a tree block which
 			 * must be aligned to nodesize.
 			 */
-			if (!IS_ALIGNED(offset, eb->fs_info->nodesize))
+			if (!IS_ALIGNED(offset, fs_info->nodesize))
 				pr_info("\t\t\t(parent %llu is NOT ALIGNED to nodesize %llu)\n",
-					offset, (unsigned long long)eb->fs_info->nodesize);
+					offset, (unsigned long long)fs_info->nodesize);
 			break;
 		case BTRFS_EXTENT_DATA_REF_KEY:
 			dref = (struct btrfs_extent_data_ref *)(&iref->offset);
@@ -132,9 +133,9 @@ static void print_extent_item(struct extent_buffer *eb, int slot, int type)
 			 * offset is supposed to be a tree block which
 			 * must be aligned to nodesize.
 			 */
-			if (!IS_ALIGNED(offset, eb->fs_info->nodesize))
+			if (!IS_ALIGNED(offset, fs_info->nodesize))
 				pr_info("\t\t\t(parent %llu is NOT ALIGNED to nodesize %llu)\n",
-				     offset, (unsigned long long)eb->fs_info->nodesize);
+				     offset, (unsigned long long)fs_info->nodesize);
 			break;
 		default:
 			pr_cont("(extent %llu has INVALID ref type %d)\n",
@@ -199,7 +200,7 @@ void btrfs_print_leaf(struct extent_buffer *l)
 	if (!l)
 		return;
 
-	fs_info = l->fs_info;
+	fs_info = l->eb_info->fs_info;
 	nr = btrfs_header_nritems(l);
 
 	btrfs_info(fs_info, "leaf %llu total ptrs %d free space %d",
@@ -347,7 +348,7 @@ void btrfs_print_tree(struct extent_buffer *c)
 
 	if (!c)
 		return;
-	fs_info = c->fs_info;
+	fs_info = c->eb_info->fs_info;
 	nr = btrfs_header_nritems(c);
 	level = btrfs_header_level(c);
 	if (level == 0) {
fs/btrfs/reada.c +1 -1
index ab852b8e3e37..c6244890085f 100644
@@ -210,7 +210,7 @@ static void __readahead_hook(struct btrfs_fs_info *fs_info,
 
 int btree_readahead_hook(struct extent_buffer *eb, int err)
 {
-	struct btrfs_fs_info *fs_info = eb->fs_info;
+	struct btrfs_fs_info *fs_info = eb->eb_info->fs_info;
 	int ret = 0;
 	struct reada_extent *re;
 
fs/btrfs/root-tree.c +1 -1
index 3338407ef0f0..e40bd9a910dd 100644
@@ -45,7 +45,7 @@ static void btrfs_read_root_item(struct extent_buffer *eb, int slot,
 	if (!need_reset && btrfs_root_generation(item)
 		!= btrfs_root_generation_v2(item)) {
 		if (btrfs_root_generation_v2(item) != 0) {
-			btrfs_warn(eb->fs_info,
+			btrfs_warn(eb->eb_info->fs_info,
 					"mismatching generation and generation_v2 found in root item. This root was probably mounted with an older kernel. Resetting all new fields.");
 		}
 		need_reset = 1;
fs/btrfs/super.c +17 -14
index 8e74f7029e12..3b5fe791639d 100644
@@ -1198,7 +1198,7 @@ int btrfs_sync_fs(struct super_block *sb, int wait)
 	trace_btrfs_sync_fs(fs_info, wait);
 
 	if (!wait) {
-		filemap_flush(fs_info->btree_inode->i_mapping);
+		btree_flush(fs_info);
 		return 0;
 	}
 
@@ -2284,19 +2284,22 @@ static int btrfs_show_devname(struct seq_file *m, struct dentry *root)
 }
 
 static const struct super_operations btrfs_super_ops = {
-	.drop_inode	= btrfs_drop_inode,
-	.evict_inode	= btrfs_evict_inode,
-	.put_super	= btrfs_put_super,
-	.sync_fs	= btrfs_sync_fs,
-	.show_options	= btrfs_show_options,
-	.show_devname	= btrfs_show_devname,
-	.write_inode	= btrfs_write_inode,
-	.alloc_inode	= btrfs_alloc_inode,
-	.destroy_inode	= btrfs_destroy_inode,
-	.statfs		= btrfs_statfs,
-	.remount_fs	= btrfs_remount,
-	.freeze_fs	= btrfs_freeze,
-	.unfreeze_fs	= btrfs_unfreeze,
+	.drop_inode		= btrfs_drop_inode,
+	.evict_inode		= btrfs_evict_inode,
+	.put_super		= btrfs_put_super,
+	.sync_fs		= btrfs_sync_fs,
+	.show_options		= btrfs_show_options,
+	.show_devname		= btrfs_show_devname,
+	.write_inode		= btrfs_write_inode,
+	.alloc_inode		= btrfs_alloc_inode,
+	.destroy_inode		= btrfs_destroy_inode,
+	.statfs			= btrfs_statfs,
+	.remount_fs		= btrfs_remount,
+	.freeze_fs		= btrfs_freeze,
+	.unfreeze_fs		= btrfs_unfreeze,
+	.nr_cached_objects	= btrfs_nr_ebs,
+	.free_cached_objects	= btrfs_free_ebs,
+	.write_metadata		= btrfs_write_ebs,
 };
 
 static const struct file_operations btrfs_ctl_fops = {
fs/btrfs/tests/btrfs-tests.c +28 -8
index d3f25376a0f8..dbf05b2ab9ee 100644
@@ -102,15 +102,32 @@ struct btrfs_fs_info *btrfs_alloc_dummy_fs_info(u32 nodesize, u32 sectorsize)
 
 	fs_info->nodesize = nodesize;
 	fs_info->sectorsize = sectorsize;
+	fs_info->eb_info = kzalloc(sizeof(struct btrfs_eb_info),
+				   GFP_KERNEL);
+	if (!fs_info->eb_info) {
+		kfree(fs_info->fs_devices);
+		kfree(fs_info->super_copy);
+		kfree(fs_info);
+		return NULL;
+	}
+
+	if (btrfs_init_eb_info(fs_info)) {
+		kfree(fs_info->eb_info);
+		kfree(fs_info->fs_devices);
+		kfree(fs_info->super_copy);
+		kfree(fs_info);
+		return NULL;
+	}
 
 	if (init_srcu_struct(&fs_info->subvol_srcu)) {
+		list_lru_destroy(&fs_info->eb_info->lru_list);
+		kfree(fs_info->eb_info);
 		kfree(fs_info->fs_devices);
 		kfree(fs_info->super_copy);
 		kfree(fs_info);
 		return NULL;
 	}
 
-	spin_lock_init(&fs_info->buffer_lock);
 	spin_lock_init(&fs_info->qgroup_lock);
 	spin_lock_init(&fs_info->qgroup_op_lock);
 	spin_lock_init(&fs_info->super_lock);
@@ -126,7 +143,6 @@ struct btrfs_fs_info *btrfs_alloc_dummy_fs_info(u32 nodesize, u32 sectorsize)
 	INIT_LIST_HEAD(&fs_info->dirty_qgroups);
 	INIT_LIST_HEAD(&fs_info->dead_roots);
 	INIT_LIST_HEAD(&fs_info->tree_mod_seq_list);
-	INIT_RADIX_TREE(&fs_info->buffer_radix, GFP_ATOMIC);
 	INIT_RADIX_TREE(&fs_info->fs_roots_radix, GFP_ATOMIC);
 	extent_io_tree_init(&fs_info->freed_extents[0], NULL);
 	extent_io_tree_init(&fs_info->freed_extents[1], NULL);
@@ -140,6 +156,7 @@ struct btrfs_fs_info *btrfs_alloc_dummy_fs_info(u32 nodesize, u32 sectorsize)
 
 void btrfs_free_dummy_fs_info(struct btrfs_fs_info *fs_info)
 {
+	struct btrfs_eb_info *eb_info;
 	struct radix_tree_iter iter;
 	void **slot;
 
@@ -150,13 +167,14 @@ void btrfs_free_dummy_fs_info(struct btrfs_fs_info *fs_info)
 			      &fs_info->fs_state)))
 		return;
 
+	eb_info = fs_info->eb_info;
 	test_mnt->mnt_sb->s_fs_info = NULL;
 
-	spin_lock(&fs_info->buffer_lock);
-	radix_tree_for_each_slot(slot, &fs_info->buffer_radix, &iter, 0) {
+	spin_lock_irq(&eb_info->buffer_lock);
+	radix_tree_for_each_slot(slot, &eb_info->buffer_radix, &iter, 0) {
 		struct extent_buffer *eb;
 
-		eb = radix_tree_deref_slot_protected(slot, &fs_info->buffer_lock);
+		eb = radix_tree_deref_slot_protected(slot, &eb_info->buffer_lock);
 		if (!eb)
 			continue;
 		/* Shouldn't happen but that kind of thinking creates CVE's */
@@ -166,15 +184,17 @@ void btrfs_free_dummy_fs_info(struct btrfs_fs_info *fs_info)
 			continue;
 		}
 		slot = radix_tree_iter_resume(slot, &iter);
-		spin_unlock(&fs_info->buffer_lock);
+		spin_unlock_irq(&eb_info->buffer_lock);
 		free_extent_buffer_stale(eb);
-		spin_lock(&fs_info->buffer_lock);
+		spin_lock_irq(&eb_info->buffer_lock);
 	}
-	spin_unlock(&fs_info->buffer_lock);
+	spin_unlock_irq(&eb_info->buffer_lock);
 
 	btrfs_free_qgroup_config(fs_info);
 	btrfs_free_fs_roots(fs_info);
 	cleanup_srcu_struct(&fs_info->subvol_srcu);
+	list_lru_destroy(&eb_info->lru_list);
+	kfree(fs_info->eb_info);
 	kfree(fs_info->super_copy);
 	kfree(fs_info->fs_devices);
 	kfree(fs_info);
fs/btrfs/tests/extent-buffer-tests.c +2 -1
index b9142c614114..9a264b81a7b4 100644
@@ -61,7 +61,8 @@ static int test_btrfs_split_item(u32 sectorsize, u32 nodesize)
 		goto out;
 	}
 
-	path->nodes[0] = eb = alloc_dummy_extent_buffer(fs_info, nodesize);
+	path->nodes[0] = eb = alloc_dummy_extent_buffer(fs_info->eb_info, 0,
+							nodesize);
 	if (!eb) {
 		test_msg("Could not allocate dummy buffer\n");
 		ret = -ENOMEM;
fs/btrfs/tests/extent-io-tests.c +2 -2
index d06b1c931d05..600c01ddf0d0 100644
@@ -406,7 +406,7 @@ static int test_eb_bitmaps(u32 sectorsize, u32 nodesize)
 		return -ENOMEM;
 	}
 
-	eb = __alloc_dummy_extent_buffer(fs_info, 0, len);
+	eb = alloc_dummy_extent_buffer(NULL, 0, len);
 	if (!eb) {
 		test_msg("Couldn't allocate test extent buffer\n");
 		kfree(bitmap);
@@ -419,7 +419,7 @@ static int test_eb_bitmaps(u32 sectorsize, u32 nodesize)
 
 	/* Do it over again with an extent buffer which isn't page-aligned. */
 	free_extent_buffer(eb);
-	eb = __alloc_dummy_extent_buffer(NULL, nodesize / 2, len);
+	eb = alloc_dummy_extent_buffer(NULL, nodesize / 2, len);
 	if (!eb) {
 		test_msg("Couldn't allocate test extent buffer\n");
 		kfree(bitmap);
fs/btrfs/tests/free-space-tree-tests.c +2 -1
index 8444a018cca2..afba937f4365 100644
@@ -474,7 +474,8 @@ static int run_test(test_func_t test_func, int bitmaps, u32 sectorsize,
 	root->fs_info->free_space_root = root;
 	root->fs_info->tree_root = root;
 
-	root->node = alloc_test_extent_buffer(root->fs_info, nodesize);
+	root->node = alloc_test_extent_buffer(fs_info->eb_info, nodesize,
+					      nodesize);
 	if (!root->node) {
 		test_msg("Couldn't allocate dummy buffer\n");
 		ret = -ENOMEM;
fs/btrfs/tests/inode-tests.c +2 -2
index 11c77eafde00..486aa7fbfce2 100644
@@ -261,7 +261,7 @@ static noinline int test_btrfs_get_extent(u32 sectorsize, u32 nodesize)
 		goto out;
 	}
 
-	root->node = alloc_dummy_extent_buffer(fs_info, nodesize);
+	root->node = alloc_dummy_extent_buffer(fs_info->eb_info, 0, nodesize);
 	if (!root->node) {
 		test_msg("Couldn't allocate dummy buffer\n");
 		goto out;
@@ -867,7 +867,7 @@ static int test_hole_first(u32 sectorsize, u32 nodesize)
 		goto out;
 	}
 
-	root->node = alloc_dummy_extent_buffer(fs_info, nodesize);
+	root->node = alloc_dummy_extent_buffer(fs_info->eb_info, 0, nodesize);
 	if (!root->node) {
 		test_msg("Couldn't allocate dummy buffer\n");
 		goto out;
fs/btrfs/tests/qgroup-tests.c +2 -1
index 0f4ce970d195..0ba27cd9ae4c 100644
@@ -486,7 +486,8 @@ int btrfs_test_qgroups(u32 sectorsize, u32 nodesize)
 	 * Can't use bytenr 0, some things freak out
 	 * *cough*backref walking code*cough*
 	 */
-	root->node = alloc_test_extent_buffer(root->fs_info, nodesize);
+	root->node = alloc_test_extent_buffer(fs_info->eb_info, nodesize,
+					      nodesize);
 	if (!root->node) {
 		test_msg("Couldn't allocate dummy buffer\n");
 		ret = -ENOMEM;
fs/btrfs/transaction.c +4 -9
index 9fed8c67b6e8..5df3963c413e 100644
@@ -293,8 +293,7 @@ static noinline int join_transaction(struct btrfs_fs_info *fs_info,
 	INIT_LIST_HEAD(&cur_trans->deleted_bgs);
 	spin_lock_init(&cur_trans->dropped_roots_lock);
 	list_add_tail(&cur_trans->list, &fs_info->trans_list);
-	extent_io_tree_init(&cur_trans->dirty_pages,
-			     fs_info->btree_inode);
+	extent_io_tree_init(&cur_trans->dirty_pages, NULL);
 	fs_info->generation++;
 	cur_trans->transid = fs_info->generation;
 	fs_info->running_transaction = cur_trans;
@@ -944,12 +943,10 @@ int btrfs_write_marked_extents(struct btrfs_fs_info *fs_info,
 {
 	int err = 0;
 	int werr = 0;
-	struct address_space *mapping = fs_info->btree_inode->i_mapping;
 	struct extent_state *cached_state = NULL;
 	u64 start = 0;
 	u64 end;
 
-	atomic_inc(&BTRFS_I(fs_info->btree_inode)->sync_writers);
 	while (!find_first_extent_bit(dirty_pages, start, &start, &end,
 				      mark, &cached_state)) {
 		bool wait_writeback = false;
@@ -975,17 +972,16 @@ int btrfs_write_marked_extents(struct btrfs_fs_info *fs_info,
 			wait_writeback = true;
 		}
 		if (!err)
-			err = filemap_fdatawrite_range(mapping, start, end);
+			err = btree_write_range(fs_info, start, end);
 		if (err)
 			werr = err;
 		else if (wait_writeback)
-			werr = filemap_fdatawait_range(mapping, start, end);
+			werr = btree_wait_range(fs_info, start, end);
 		free_extent_state(cached_state);
 		cached_state = NULL;
 		cond_resched();
 		start = end + 1;
 	}
-	atomic_dec(&BTRFS_I(fs_info->btree_inode)->sync_writers);
 	return werr;
 }
 
@@ -1000,7 +996,6 @@ static int __btrfs_wait_marked_extents(struct btrfs_fs_info *fs_info,
 {
 	int err = 0;
 	int werr = 0;
-	struct address_space *mapping = fs_info->btree_inode->i_mapping;
 	struct extent_state *cached_state = NULL;
 	u64 start = 0;
 	u64 end;
@@ -1021,7 +1016,7 @@ static int __btrfs_wait_marked_extents(struct btrfs_fs_info *fs_info,
 		if (err == -ENOMEM)
 			err = 0;
 		if (!err)
-			err = filemap_fdatawait_range(mapping, start, end);
+			err = btree_wait_range(fs_info, start, end);
 		if (err)
 			werr = err;
 		free_extent_state(cached_state);
Signature · 7 lines
2.7.5

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#29 lore raw

PATCH v3 9/10 btrfs: rework end io for extent buffer reads

In reply to Josef Bacik

From: Josef Bacik <[email protected]>

Now that the only thing that keeps eb's alive is io_pages and it's refcount we need to hold the eb ref for the entire end io call so we don't get it removed out from underneath us. Also the hooks make no sense for us now, so rework this to be cleaner.

---
 fs/btrfs/disk-io.c   | 63 ++++---------------------------------------------
 fs/btrfs/disk-io.h   |  1 +
 fs/btrfs/extent_io.c | 66 +++++++++++++++++++++++++++-------------------------
 3 files changed, 40 insertions(+), 90 deletions(-)
fs/btrfs/disk-io.c +5 -58
index d9d69e181942..1a890f8c78c8 100644
@@ -755,33 +755,13 @@ static int check_node(struct btrfs_root *root, struct extent_buffer *node)
 	return ret;
 }
 
-static int btree_readpage_end_io_hook(struct btrfs_io_bio *io_bio,
-				      u64 phy_offset, struct page *page,
-				      u64 start, u64 end, int mirror)
+int btrfs_extent_buffer_end_read(struct extent_buffer *eb, int mirror)
 {
+	struct btrfs_fs_info *fs_info = eb->eb_info->fs_info;
+	struct btrfs_root *root = fs_info->tree_root;
 	u64 found_start;
 	int found_level;
-	struct extent_buffer *eb;
-	struct btrfs_root *root;
-	struct btrfs_fs_info *fs_info;
 	int ret = 0;
-	int reads_done;
-
-	if (!page->private)
-		goto out;
-
-	eb = (struct extent_buffer *)page->private;
-
-	/* the pending IO might have been the only thing that kept this buffer
-	 * in memory.  Make sure we have a ref for all this other checks
-	 */
-	extent_buffer_get(eb);
-	fs_info = eb->eb_info->fs_info;
-	root = fs_info->tree_root;
-
-	reads_done = atomic_dec_and_test(&eb->io_pages);
-	if (!reads_done)
-		goto err;
 
 	eb->read_mirror = mirror;
 	if (test_bit(EXTENT_BUFFER_READ_ERR, &eb->bflags)) {
@@ -833,45 +813,14 @@ static int btree_readpage_end_io_hook(struct btrfs_io_bio *io_bio,
 	if (!ret)
 		set_extent_buffer_uptodate(eb);
 err:
-	if (reads_done &&
-	    test_and_clear_bit(EXTENT_BUFFER_READAHEAD, &eb->bflags))
+	if (test_and_clear_bit(EXTENT_BUFFER_READAHEAD, &eb->bflags))
 		btree_readahead_hook(eb, ret);
 
-	if (ret) {
-		/*
-		 * our io error hook is going to dec the io pages
-		 * again, we have to make sure it has something
-		 * to decrement.
-		 *
-		 * TODO: Kill this, we've re-arranged how this works now so we
-		 * don't need to do this io_pages dance.
-		 */
-		atomic_inc(&eb->io_pages);
+	if (ret)
 		clear_extent_buffer_uptodate(eb);
-	}
-	if (reads_done) {
-		clear_bit(EXTENT_BUFFER_READING, &eb->bflags);
-		smp_mb__after_atomic();
-		wake_up_bit(&eb->bflags, EXTENT_BUFFER_READING);
-	}
-	free_extent_buffer(eb);
-out:
 	return ret;
 }
 
-static int btree_io_failed_hook(struct page *page, int failed_mirror)
-{
-	struct extent_buffer *eb;
-
-	eb = (struct extent_buffer *)page->private;
-	set_bit(EXTENT_BUFFER_READ_ERR, &eb->bflags);
-	eb->read_mirror = failed_mirror;
-	atomic_dec(&eb->io_pages);
-	if (test_and_clear_bit(EXTENT_BUFFER_READAHEAD, &eb->bflags))
-		btree_readahead_hook(eb, -EIO);
-	return -EIO;	/* we fixed nothing */
-}
-
 static void end_workqueue_bio(struct bio *bio)
 {
 	struct btrfs_end_io_wq *end_io_wq = bio->bi_private;
@@ -4554,9 +4503,7 @@ static int btree_merge_bio_hook(struct page *page, unsigned long offset,
 static const struct extent_io_ops btree_extent_io_ops = {
 	/* mandatory callbacks */
 	.submit_bio_hook = btree_submit_bio_hook,
-	.readpage_end_io_hook = btree_readpage_end_io_hook,
 	.merge_bio_hook = btree_merge_bio_hook,
-	.readpage_io_failed_hook = btree_io_failed_hook,
 	.set_range_writeback = btrfs_set_range_writeback,
 	.tree_fs_info = btree_fs_info,
 
fs/btrfs/disk-io.h +1 -0
index 7f7c35d6347a..e1f4fef91547 100644
@@ -152,6 +152,7 @@ int btree_lock_page_hook(struct page *page, void *data,
 int btrfs_get_num_tolerated_disk_barrier_failures(u64 flags);
 int __init btrfs_end_io_wq_init(void);
 void btrfs_end_io_wq_exit(void);
+int btrfs_extent_buffer_end_read(struct extent_buffer *eb, int mirror);
 
 #ifdef CONFIG_DEBUG_LOCK_ALLOC
 void btrfs_init_lockdep(void);
fs/btrfs/extent_io.c +34 -32

99 lines not on this page · raw message

Signature · 7 lines
2.7.5

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#30 lore raw

PATCH v3 10/10 btrfs: add NR_METADATA_BYTES accounting

In reply to Josef Bacik

From: Josef Bacik <[email protected]>

Now that we have these counters, account for the private pages we allocate in NR_METADATA_BYTES.

---
 fs/btrfs/extent_io.c | 4 ++++
 1 file changed, 4 insertions(+)
fs/btrfs/extent_io.c +4 -0
index e11372455fb0..7536352f424d 100644
@@ -4802,6 +4802,8 @@ static void btrfs_release_extent_buffer_page(struct extent_buffer *eb)
 		ClearPagePrivate(page);
 		set_page_private(page, 0);
 
+		mod_node_page_state(page_pgdat(page), NR_METADATA_BYTES,
+				    -(long)PAGE_SIZE);
 		/* Once for the page private. */
 		put_page(page);
 
@@ -5081,6 +5083,8 @@ struct extent_buffer *alloc_extent_buffer(struct btrfs_fs_info *fs_info,
 			goto free_eb;
 		}
 		attach_extent_buffer_page(eb, p);
+		mod_node_page_state(page_pgdat(p), NR_METADATA_BYTES,
+				    PAGE_SIZE);
 		eb->pages[i] = p;
 	}
 again:
Signature · 7 lines
2.7.5

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>