Skip to contentSkip to conversation

Provide accounting for dirty metadata

PATCH Superseded Josef Bacik 4 participants 13 messages Aug 22, 2016 – Sep 12, 2016

Subsystems (15)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover Provide accounting for dirty metadata

Here is my updated set of patches for providing a way for fs'es to do their own accounting for their dirty metadata pages. The changes since V1 include

-Split the accounting + ->write_metadata patches out into their own patches. -Added a few more account_metadata* helpers that I hadn't thought about previously.
-Changed the bdi->sb_list to bdi->dirty_sb_list. This is to avoid confusion about the purpose of the list. I do a splice of this list when processing it as we have to drop the list lock and I didn't want to worry about umounts screwing up the list while we were writing metadata.
-Added the dirty metadata counter to the various places we output those counters (meminfo, oom messages, etc).

I've also actually changed btrfs to use these interfaces and have been testing that code for almost a week now and have fixed up the various problems that happend with V1 of this code. 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 v2 1/3 remove mapping from balance_dirty_pages*()

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              |  4 ++--
 fs/btrfs/file.c                 |  3 ++-
 fs/btrfs/ioctl.c                |  3 ++-
 fs/btrfs/relocation.c           |  3 ++-
 fs/buffer.c                     |  3 ++-
 fs/iomap.c                      |  3 ++-
 fs/ntfs/attrib.c                | 10 +++++++---
 fs/ntfs/file.c                  |  4 ++--
 include/linux/backing-dev.h     | 29 +++++++++++++++++++++++------
 include/linux/writeback.h       |  3 ++-
 mm/filemap.c                    |  4 +++-
 mm/memory.c                     |  9 +++++++--
 mm/page-writeback.c             | 15 +++++++--------
 14 files changed, 71 insertions(+), 34 deletions(-)
drivers/mtd/devices/block2mtd.c +8 -4
index 7c887f1..7892d0b 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 -2
index 87dad55..4034ad6 100644
@@ -4024,8 +4024,8 @@ static void __btrfs_btree_balance_dirty(struct btrfs_root *root,
 	ret = percpu_counter_compare(&root->fs_info->dirty_metadata_bytes,
 				     BTRFS_DIRTY_METADATA_THRESH);
 	if (ret > 0) {
-		balance_dirty_pages_ratelimited(
-				   root->fs_info->btree_inode->i_mapping);
+		balance_dirty_pages_ratelimited(&root->fs_info->bdi,
+						root->fs_info->sb);
 	}
 }
 
fs/btrfs/file.c +2 -1
index 9404121..f060b08 100644
@@ -1686,7 +1686,8 @@ again:
 
 		cond_resched();
 
-		balance_dirty_pages_ratelimited(inode->i_mapping);
+		balance_dirty_pages_ratelimited(inode_to_bdi(inode),
+						inode->i_sb);
 		if (dirty_pages < (root->nodesize >> PAGE_SHIFT) + 1)
 			btrfs_btree_balance_dirty(root);
 
fs/btrfs/ioctl.c +2 -1
index 14ed1e9..a222bad 100644
@@ -1410,7 +1410,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 b26a5ae..6e194a5 100644
@@ -3202,7 +3202,8 @@ static int relocate_file_extent_cluster(struct inode *inode,
 		put_page(page);
 
 		index++;
-		balance_dirty_pages_ratelimited(inode->i_mapping);
+		balance_dirty_pages_ratelimited(inode_to_bdi(inode),
+						inode->i_sb);
 		btrfs_throttle(BTRFS_I(inode)->root);
 	}
 	WARN_ON(nr != cluster->nr);
fs/buffer.c +2 -1
index 9c8eb9b..9bbe30d 100644
@@ -2386,7 +2386,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 +2 -1
index 48141b8..937e266 100644
@@ -226,7 +226,8 @@ again:
 		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;
fs/ntfs/attrib.c +7 -3
index 44a39a0..0a8a39e 100644
@@ -2493,6 +2493,7 @@ conv_err_out:
 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 +2546,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 +2588,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 +2606,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 f548629..66082eb 100644
@@ -276,7 +276,7 @@ do_non_resident_extend:
 		 * 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);
@@ -1914,7 +1914,7 @@ again:
 		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 491a917..089acf6 100644
@@ -252,8 +252,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
@@ -262,15 +263,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);
 }
 
 /**
@@ -413,6 +424,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 +2 -1
index fc1e16c..256ffc3 100644
@@ -364,7 +364,8 @@ 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 page_writeback_init(void);
-void balance_dirty_pages_ratelimited(struct address_space *mapping);
+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 3083ded..abb0e98 100644
@@ -2667,6 +2667,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;
@@ -2746,7 +2747,8 @@ again:
 		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 +7 -2
index 83be99d..d43e73b 100644
@@ -64,6 +64,7 @@
 #include <linux/debugfs.h>
 #include <linux/userfaultfd_k.h>
 #include <linux/dax.h>
+#include <linux/backing-dev.h>
 
 #include <asm/io.h>
 #include <asm/mmu_context.h>
@@ -2105,11 +2106,13 @@ static inline int wp_page_reuse(struct fault_env *fe, pte_t orig_pte,
 		put_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)
@@ -3291,11 +3294,13 @@ static int do_shared_fault(struct fault_env *fe, pgoff_t pgoff)
 	mapping = page_rmapping(fault_page);
 	unlock_page(fault_page);
 	if ((dirtied || vma->vm_ops->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 (!vma->vm_ops->page_mkwrite)
mm/page-writeback.c +7 -8
index f4cd7d8..121a6e3 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) };
@@ -1849,7 +1848,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
@@ -1860,10 +1860,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;
@@ -1871,7 +1870,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;
@@ -1909,7 +1908,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
1.8.3.1

--
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

Re: [PATCH 1/3] remove mapping from balance_dirty_pages*()

url: https://github.com/0day-ci/linux/commits/Josef-Bacik/Provide-accounting-for-dirty-metadata/20160823-014222 config: sparc64-allyesconfig (attached as .config) compiler: sparc64-linux-gnu-gcc…

Hi Josef,

[auto build test ERROR on linus/master]
[also build test ERROR on v4.8-rc3 next-20160822]
[cannot apply to linux/master]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
[Suggest to use git(>=2.9.0) format-patch --base=<commit> (or --base=auto for convenience) to record what (public, well-known) commit your patch series was built on] [Check https://git-scm.com/docs/git-format-patch for more information]

url: https://github.com/0day-ci/linux/commits/Josef-Bacik/Provide-accounting-for-dirty-metadata/20160823-014222
config: sparc64-allyesconfig (attached as .config)
compiler: sparc64-linux-gnu-gcc (Debian 5.4.0-6) 5.4.0 20160609
reproduce:
wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=sparc64

All error/warnings (new ones prefixed by >>):

fs/ntfs/attrib.c: In function 'ntfs_attr_set':

>> fs/ntfs/attrib.c:2549:35: error: implicit declaration of function 'inode_to_bdi' [-Werror=implicit-function-declaration]
      balance_dirty_pages_ratelimited(inode_to_bdi(inode),
                                      ^
>> fs/ntfs/attrib.c:2549:35: warning: passing argument 1 of 'balance_dirty_pages_ratelimited' makes pointer from integer without a cast [-Wint-conversion]
   In file included from include/linux/memcontrol.h:30:0,
                    from include/linux/swap.h:8,
                    from fs/ntfs/attrib.c:26:
   include/linux/writeback.h:367:6: note: expected 'struct backing_dev_info *' but argument is of type 'int'
    void balance_dirty_pages_ratelimited(struct backing_dev_info *bdi,
         ^
   fs/ntfs/attrib.c:2591:35: warning: passing argument 1 of 'balance_dirty_pages_ratelimited' makes pointer from integer without a cast [-Wint-conversion]
      balance_dirty_pages_ratelimited(inode_to_bdi(inode),
                                      ^
   In file included from include/linux/memcontrol.h:30:0,
                    from include/linux/swap.h:8,
                    from fs/ntfs/attrib.c:26:
   include/linux/writeback.h:367:6: note: expected 'struct backing_dev_info *' but argument is of type 'int'
    void balance_dirty_pages_ratelimited(struct backing_dev_info *bdi,
         ^
   fs/ntfs/attrib.c:2609:35: warning: passing argument 1 of 'balance_dirty_pages_ratelimited' makes pointer from integer without a cast [-Wint-conversion]
      balance_dirty_pages_ratelimited(inode_to_bdi(inode),
                                      ^
   In file included from include/linux/memcontrol.h:30:0,
                    from include/linux/swap.h:8,
                    from fs/ntfs/attrib.c:26:

include/linux/writeback.h:367:6: note: expected 'struct backing_dev_info *' but argument is of type 'int'
void balance_dirty_pages_ratelimited(struct backing_dev_info *bdi,
^
cc1: some warnings being treated as errors

vim +/inode_to_bdi +2549 fs/ntfs/attrib.c

2543 kaddr = kmap_atomic(page);
2544 memset(kaddr + start_ofs, val, size - start_ofs);
2545 flush_dcache_page(page);
2546 kunmap_atomic(kaddr);
2547 set_page_dirty(page);
2548 put_page(page);

> 2549			balance_dirty_pages_ratelimited(inode_to_bdi(inode),

2550 inode->i_sb);
2551 cond_resched();
2552 if (idx == end)

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#3 lore raw

PATCH v2 2/3 writeback: allow for dirty metadata accounting

In reply to Josef Bacik

Provide a mechanism for file systems to indicate how much dirty metadata they are holding. This introduces a few things

1) Zone stats for dirty metadata, which is the same as the NR_FILE_DIRTY.
2) WB stat for dirty metadata. This way we know if we need to try and call into the file system to write out metadata. This could potentially be used in the future to make balancing of dirty pages smarter.

---
 arch/tile/mm/pgtable.c           |   3 +-
 drivers/base/node.c              |   2 +
 fs/fs-writeback.c                |   1 +
 fs/proc/meminfo.c                |   2 +
 include/linux/backing-dev-defs.h |   1 +
 include/linux/mm.h               |   7 +++
 include/linux/mmzone.h           |   1 +
 include/trace/events/writeback.h |   7 ++-
 mm/backing-dev.c                 |   2 +
 mm/page-writeback.c              | 100 +++++++++++++++++++++++++++++++++++++--
 mm/page_alloc.c                  |   7 ++-
 mm/vmscan.c                      |   3 +-
 12 files changed, 127 insertions(+), 9 deletions(-)
arch/tile/mm/pgtable.c +2 -1
index 7cc6ee7..9543468 100644
@@ -44,12 +44,13 @@ void show_mem(unsigned int filter)
 {
 	struct zone *zone;
 
-	pr_err("Active:%lu inactive:%lu dirty:%lu writeback:%lu unstable:%lu free:%lu\n slab:%lu mapped:%lu pagetables:%lu bounce:%lu pagecache:%lu swap:%lu\n",
+	pr_err("Active:%lu inactive:%lu dirty:%lu metadata_dirty:%lu writeback:%lu unstable:%lu free:%lu\n slab:%lu mapped:%lu pagetables:%lu bounce:%lu pagecache:%lu swap:%lu\n",
 	       (global_node_page_state(NR_ACTIVE_ANON) +
 		global_node_page_state(NR_ACTIVE_FILE)),
 	       (global_node_page_state(NR_INACTIVE_ANON) +
 		global_node_page_state(NR_INACTIVE_FILE)),
 	       global_node_page_state(NR_FILE_DIRTY),
+	       global_node_page_state(NR_METADATA_DIRTY),
 	       global_node_page_state(NR_WRITEBACK),
 	       global_node_page_state(NR_UNSTABLE_NFS),
 	       global_page_state(NR_FREE_PAGES),
drivers/base/node.c +2 -0
index 5548f96..efc867b2 100644
@@ -99,6 +99,7 @@ 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 FilePages:      %8lu kB\n"
 		       "Node %d Mapped:         %8lu kB\n"
@@ -119,6 +120,7 @@ static ssize_t node_read_meminfo(struct device *dev,
 #endif
 			,
 		       nid, K(node_page_state(pgdat, NR_FILE_DIRTY)),
+		       nid, K(node_page_state(pgdat, NR_METADATA_DIRTY)),
 		       nid, K(node_page_state(pgdat, NR_WRITEBACK)),
 		       nid, K(node_page_state(pgdat, NR_FILE_PAGES)),
 		       nid, K(node_page_state(pgdat, NR_FILE_MAPPED)),
fs/fs-writeback.c +1 -0
index 56c8fda..d329f89 100644
@@ -1809,6 +1809,7 @@ static unsigned long get_nr_dirty_pages(void)
 {
 	return global_node_page_state(NR_FILE_DIRTY) +
 		global_node_page_state(NR_UNSTABLE_NFS) +
+		global_node_page_state(NR_METADATA_DIRTY) +
 		get_nr_dirty_inodes();
 }
 
fs/proc/meminfo.c +2 -0
index 09e18fd..8ca094f 100644
@@ -80,6 +80,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
 		"SwapTotal:      %8lu kB\n"
 		"SwapFree:       %8lu kB\n"
 		"Dirty:          %8lu kB\n"
+		"MetadataDirty:  %8lu kB\n"
 		"Writeback:      %8lu kB\n"
 		"AnonPages:      %8lu kB\n"
 		"Mapped:         %8lu kB\n"
@@ -139,6 +140,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
 		K(i.totalswap),
 		K(i.freeswap),
 		K(global_node_page_state(NR_FILE_DIRTY)),
+		K(global_node_page_state(NR_METADATA_DIRTY)),
 		K(global_node_page_state(NR_WRITEBACK)),
 		K(global_node_page_state(NR_ANON_MAPPED)),
 		K(global_node_page_state(NR_FILE_MAPPED)),
include/linux/backing-dev-defs.h +1 -0
index 3f10307..1200aae 100644
@@ -34,6 +34,7 @@ typedef int (congested_fn)(void *, int);
 enum wb_stat_item {
 	WB_RECLAIMABLE,
 	WB_WRITEBACK,
+	WB_METADATA_DIRTY,
 	WB_DIRTIED,
 	WB_WRITTEN,
 	NR_WB_STAT_ITEMS
include/linux/mm.h +7 -0
index 08ed53e..5a3f626 100644
@@ -31,6 +31,7 @@ struct file_ra_state;
 struct user_struct;
 struct writeback_control;
 struct bdi_writeback;
+struct backing_dev_info;
 
 #ifndef CONFIG_NEED_MULTIPLE_NODES	/* Don't use mapnrs, do it properly */
 extern unsigned long max_mapnr;
@@ -1363,6 +1364,12 @@ 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);
+void account_metadata_cleaned(struct page *page, struct backing_dev_info *bdi);
+void account_metadata_writeback(struct page *page,
+				struct backing_dev_info *bdi);
+void account_metadata_end_writeback(struct page *page,
+				    struct backing_dev_info *bdi);
 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 +1 -0
index f2e4e90..c4177ef 100644
@@ -167,6 +167,7 @@ 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,	/* Metadata dirty pages */
 	NR_VM_NODE_STAT_ITEMS
 };
 
include/trace/events/writeback.h +5 -2
index 2ccd9cc..c9f6427 100644
@@ -402,6 +402,7 @@ 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_unstable)
 		__field(unsigned long,	background_thresh)
@@ -413,6 +414,7 @@ TRACE_EVENT(global_dirty_state,
 
 	TP_fast_assign(
 		__entry->nr_dirty	= global_node_page_state(NR_FILE_DIRTY);
+		__entry->nr_metadata_dirty = global_node_page_state(NR_METADATA_DIRTY);
 		__entry->nr_writeback	= global_node_page_state(NR_WRITEBACK);
 		__entry->nr_unstable	= global_node_page_state(NR_UNSTABLE_NFS);
 		__entry->nr_dirtied	= global_node_page_state(NR_DIRTIED);
@@ -424,7 +426,7 @@ 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",
 		  __entry->nr_dirty,
 		  __entry->nr_writeback,
 		  __entry->nr_unstable,
@@ -432,7 +434,8 @@ TRACE_EVENT(global_dirty_state,
 		  __entry->dirty_thresh,
 		  __entry->dirty_limit,
 		  __entry->nr_dirtied,
-		  __entry->nr_written
+		  __entry->nr_written,
+		  __entry->nr_metadata_dirty
 	)
 );
 
mm/backing-dev.c +2 -0
index efe2377..b48d4e4 100644
@@ -78,6 +78,7 @@ static int bdi_debug_stats_show(struct seq_file *m, void *v)
 		   "BackgroundThresh:   %10lu kB\n"
 		   "BdiDirtied:         %10lu kB\n"
 		   "BdiWritten:         %10lu kB\n"
+		   "BdiMetadataDirty:   %10lu kB\n"
 		   "BdiWriteBandwidth:  %10lu kBps\n"
 		   "b_dirty:            %10lu\n"
 		   "b_io:               %10lu\n"
@@ -92,6 +93,7 @@ static int bdi_debug_stats_show(struct seq_file *m, void *v)
 		   K(background_thresh),
 		   (unsigned long) K(wb_stat(wb, WB_DIRTIED)),
 		   (unsigned long) K(wb_stat(wb, WB_WRITTEN)),
+		   (unsigned long) K(wb_stat(wb, WB_METADATA_DIRTY)),
 		   (unsigned long) K(wb->write_bandwidth),
 		   nr_dirty,
 		   nr_io,
mm/page-writeback.c +97 -3

130 lines not on this page · raw message

mm/page_alloc.c +5 -2
index 39a372a..bc3523e 100644
@@ -4218,8 +4218,8 @@ void show_free_areas(unsigned int filter)
 
 	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"
+		" unevictable:%lu dirty:%lu metadata_dirty:%lu writeback:%lu\n"
+	        " unstable:%lu 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",
 		global_node_page_state(NR_ACTIVE_ANON),
@@ -4230,6 +4230,7 @@ void show_free_areas(unsigned int filter)
 		global_node_page_state(NR_ISOLATED_FILE),
 		global_node_page_state(NR_UNEVICTABLE),
 		global_node_page_state(NR_FILE_DIRTY),
+		global_node_page_state(NR_METADATA_DIRTY),
 		global_node_page_state(NR_WRITEBACK),
 		global_node_page_state(NR_UNSTABLE_NFS),
 		global_page_state(NR_SLAB_RECLAIMABLE),
@@ -4253,6 +4254,7 @@ void show_free_areas(unsigned int filter)
 			" isolated(file):%lukB"
 			" mapped:%lukB"
 			" dirty:%lukB"
+			" metadata_dirty:%lukB"
 			" writeback:%lukB"
 			" shmem:%lukB"
 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
@@ -4275,6 +4277,7 @@ void show_free_areas(unsigned int filter)
 			K(node_page_state(pgdat, NR_ISOLATED_FILE)),
 			K(node_page_state(pgdat, NR_FILE_MAPPED)),
 			K(node_page_state(pgdat, NR_FILE_DIRTY)),
+			K(node_page_state(pgdat, NR_METADATA_DIRTY)),
 			K(node_page_state(pgdat, NR_WRITEBACK)),
 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
 			K(node_page_state(pgdat, NR_SHMEM_THPS) * HPAGE_PMD_NR),
mm/vmscan.c +2 -1
index 374d95d..fb3eb62 100644
@@ -3714,7 +3714,8 @@ static unsigned long node_pagecache_reclaimable(struct pglist_data *pgdat)
 
 	/* If we can't clean pages, remove dirty pages from consideration */
 	if (!(node_reclaim_mode & RECLAIM_WRITE))
-		delta += node_page_state(pgdat, NR_FILE_DIRTY);
+		delta += node_page_state(pgdat, NR_FILE_DIRTY) +
+			node_page_state(pgdat, NR_METADATA_DIRTY);
 
 	/* Watch for any possible underflows due to delta */
 	if (unlikely(delta > nr_pagecache_reclaimable))
Signature · 7 lines
1.8.3.1

--
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
#4 lore raw

Re: [PATCH 2/3] writeback: allow for dirty metadata accounting

Quoted 7 lines · Josef Bacik

Provide a mechanism for file systems to indicate how much dirty metadata they are holding. This introduces a few things

1) Zone stats for dirty metadata, which is the same as the NR_FILE_DIRTY.
2) WB stat for dirty metadata. This way we know if we need to try and call into the file system to write out metadata. This could potentially be used in the future to make balancing of dirty pages smarter.

So I'm curious about one thing: In the previous posting you have mentioned that the main motivation for this work is to have a simple support for sub-pagesize dirty metadata blocks that need tracking in btrfs. However you do the dirty accounting at page granularity. What are your plans to handle this mismatch?

The thing is you actually shouldn't miscount by too much as that could upset some checks in mm checking how much dirty pages a node has directing how reclaim should be done... But it's a question whether NR_METADATA_DIRTY should be actually used in the checks in node_limits_ok() or in node_pagecache_reclaimable() at all because once you start accounting dirty slab objects, you are really on a thin ice...

fs/fs-writeback.c static unsigned long get_nr_dirty_pages(void) · line 1813

Quoted 10 lines
fs/fs-writeback.c +1 -0
index 56c8fda..d329f89 100644
@@ -1809,6 +1809,7 @@ static unsigned long get_nr_dirty_pages(void)
 {
 	return global_node_page_state(NR_FILE_DIRTY) +
 		global_node_page_state(NR_UNSTABLE_NFS) +
+		global_node_page_state(NR_METADATA_DIRTY) +
 		get_nr_dirty_inodes();

With my question is also connected this - when we have NR_METADATA_DIRTY, we could just account dirty inodes there and get rid of this get_nr_dirty_inodes() hack...

But actually getting this to work right to be able to track dirty inodes would be useful on its own - some throlling of creation of dirty inodes would be useful for several filesystems (ext4, xfs, ...).

Quoted 47 lines
mm/page-writeback.c +8 -3
index 121a6e3..6a52723 100644
@@ -506,6 +506,7 @@ bool node_dirty_ok(struct pglist_data *pgdat)
 	nr_pages += node_page_state(pgdat, NR_FILE_DIRTY);
 	nr_pages += node_page_state(pgdat, NR_UNSTABLE_NFS);
 	nr_pages += node_page_state(pgdat, NR_WRITEBACK);
+	nr_pages += node_page_state(pgdat, NR_METADATA_DIRTY);
 
 	return nr_pages <= limit;
 }
@@ -1595,7 +1596,8 @@ static void balance_dirty_pages(struct bdi_writeback *wb,
 		 * been flushed to permanent storage.
 		 */
 		nr_reclaimable = global_node_page_state(NR_FILE_DIRTY) +
-					global_node_page_state(NR_UNSTABLE_NFS);
+				global_node_page_state(NR_UNSTABLE_NFS) +
+				global_node_page_state(NR_METADATA_DIRTY);
 		gdtc->avail = global_dirtyable_memory();
 		gdtc->dirty = nr_reclaimable + global_node_page_state(NR_WRITEBACK);
 
@@ -1935,7 +1937,8 @@ bool wb_over_bg_thresh(struct bdi_writeback *wb)
 	 */
 	gdtc->avail = global_dirtyable_memory();
 	gdtc->dirty = global_node_page_state(NR_FILE_DIRTY) +
-		      global_node_page_state(NR_UNSTABLE_NFS);
+		      global_node_page_state(NR_UNSTABLE_NFS) +
+		      global_node_page_state(NR_METADATA_DIRTY);
 	domain_dirty_limits(gdtc);
 
 	if (gdtc->dirty > gdtc->bg_thresh)
@@ -2009,7 +2012,8 @@ void laptop_mode_timer_fn(unsigned long data)
 {
 	struct request_queue *q = (struct request_queue *)data;
 	int nr_pages = global_node_page_state(NR_FILE_DIRTY) +
-		global_node_page_state(NR_UNSTABLE_NFS);
+		global_node_page_state(NR_UNSTABLE_NFS) +
+		global_node_page_state(NR_METADATA_DIRTY);
 	struct bdi_writeback *wb;
 
 	/*
@@ -2473,6 +2477,96 @@ void account_page_dirtied(struct page *page, struct address_space *mapping)
 EXPORT_SYMBOL(account_page_dirtied);
 
 /*
+ * account_metadata_dirtied

mm/page-writeback.c void account_page_dirtied(struct page *page, struct address_space *mapping) · line 2490

Quoted 10 lines
mm/page-writeback.c +10 -0
+ * @page - the page being dirited
+ * @bdi - the bdi that owns this page
+ *
+ * Do the dirty page accounting for metadata pages that aren't backed by an
+ * address_space.
+ */
+void account_metadata_dirtied(struct page *page, struct backing_dev_info *bdi)
+{
+	unsigned long flags;
+

A bdi_cap_account_dirty() check here and in following functions?

Quoted 82 lines
mm/page-writeback.c +79 -0
+	local_irq_save(flags);
+	__inc_node_page_state(page, NR_METADATA_DIRTY);
+	__inc_zone_page_state(page, NR_ZONE_WRITE_PENDING);
+	__inc_node_page_state(page, NR_DIRTIED);
+	__inc_wb_stat(&bdi->wb, WB_RECLAIMABLE);
+	__inc_wb_stat(&bdi->wb, WB_DIRTIED);
+	__inc_wb_stat(&bdi->wb, WB_METADATA_DIRTY);
+	current->nr_dirtied++;
+	task_io_account_write(PAGE_SIZE);
+	this_cpu_inc(bdp_ratelimits);
+	local_irq_restore(flags);
+}
+EXPORT_SYMBOL(account_metadata_dirtied);
+
+/*
+ * account_metadata_cleaned
+ * @page - the page being cleaned
+ * @bdi - the bdi that owns this page
+ *
+ * Called on a no longer dirty metadata page.
+ */
+void account_metadata_cleaned(struct page *page, struct backing_dev_info *bdi)
+{
+	unsigned long flags;
+
+	local_irq_save(flags);
+	__dec_node_page_state(page, NR_METADATA_DIRTY);
+	__dec_zone_page_state(page, NR_ZONE_WRITE_PENDING);
+	__dec_wb_stat(&bdi->wb, WB_RECLAIMABLE);
+	__dec_wb_stat(&bdi->wb, WB_METADATA_DIRTY);
+	task_io_account_cancelled_write(PAGE_SIZE);
+	local_irq_restore(flags);
+}
+EXPORT_SYMBOL(account_metadata_cleaned);
+
+/*
+ * account_metadata_writeback
+ * @page - the page being marked as writeback
+ * @bdi - the bdi that owns this page
+ *
+ * Called on a metadata page that has been marked writeback.
+ */
+void account_metadata_writeback(struct page *page,
+				struct backing_dev_info *bdi)
+{
+	unsigned long flags;
+
+	local_irq_save(flags);
+	__inc_wb_stat(&bdi->wb, WB_WRITEBACK);
+	__inc_node_page_state(page, NR_WRITEBACK);
+	__dec_node_page_state(page, NR_METADATA_DIRTY);
+	__dec_wb_stat(&bdi->wb, WB_METADATA_DIRTY);
+	__dec_wb_stat(&bdi->wb, WB_RECLAIMABLE);
+	local_irq_restore(flags);
+}
+EXPORT_SYMBOL(account_metadata_writeback);
+
+/*
+ * account_metadata_end_writeback
+ * @page - the page we are ending writeback on
+ * @bdi - the bdi that owns this page
+ *
+ * Called on a metadata page that has completed writeback.
+ */
+void account_metadata_end_writeback(struct page *page,
+				    struct backing_dev_info *bdi)
+{
+	unsigned long flags;
+
+	local_irq_save(flags);
+	__dec_wb_stat(&bdi->wb, WB_WRITEBACK);
+	__dec_node_page_state(page, NR_WRITEBACK);
+	__dec_zone_page_state(page, NR_ZONE_WRITE_PENDING);
+	__inc_node_page_state(page, NR_WRITTEN);
+	local_irq_restore(flags);
+}
+EXPORT_SYMBOL(account_metadata_end_writeback);
+
+/*
  * Helper function for deaccounting dirty page without writeback.
  *
  * Caller must hold lock_page_memcg().

...

Quoted 5 lines
mm/vmscan.c +0 -0
index 374d95d..fb3eb62 100644

mm/vmscan.c static unsigned long node_pagecache_reclaimable(struct pglist_data *pgdat) · line 3721

Quoted 9 lines
mm/vmscan.c +2 -1
@@ -3714,7 +3714,8 @@ static unsigned long node_pagecache_reclaimable(struct pglist_data *pgdat)
 
 	/* If we can't clean pages, remove dirty pages from consideration */
 	if (!(node_reclaim_mode & RECLAIM_WRITE))
-		delta += node_page_state(pgdat, NR_FILE_DIRTY);
+		delta += node_page_state(pgdat, NR_FILE_DIRTY) +
+			node_page_state(pgdat, NR_METADATA_DIRTY);
 
 	/* Watch for any possible underflows due to delta */
 	if (unlikely(delta > nr_pagecache_reclaimable))

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>
#5 lore raw

Re: [PATCH 2/3] writeback: allow for dirty metadata accounting

Quoted 15 lines · Jan Kara
Quoted 7 lines · Josef Bacik

Provide a mechanism for file systems to indicate how much dirty metadata they are holding. This introduces a few things

1) Zone stats for dirty metadata, which is the same as the NR_FILE_DIRTY.
2) WB stat for dirty metadata. This way we know if we need to try and call into the file system to write out metadata. This could potentially be used in the future to make balancing of dirty pages smarter.

So I'm curious about one thing: In the previous posting you have mentioned that the main motivation for this work is to have a simple support for sub-pagesize dirty metadata blocks that need tracking in btrfs. However you do the dirty accounting at page granularity. What are your plans to handle this mismatch?

Quoted 6 lines

The thing is you actually shouldn't miscount by too much as that could upset some checks in mm checking how much dirty pages a node has directing how reclaim should be done... But it's a question whether NR_METADATA_DIRTY should be actually used in the checks in node_limits_ok() or in node_pagecache_reclaimable() at all because once you start accounting dirty slab objects, you are really on a thin ice...

The other thing I'm concerned about is that it's a btrfs-only thing, which means having dirty btrfs metadata on a system with different filesystems (e.g. btrfs root/home, XFS data) is going to affect how memory balance and throttling is run on other filesystems. i.e. it's going ot make a filesystem specific issue into a problem that affects global behaviour.

Quoted 15 lines

fs/fs-writeback.c static unsigned long get_nr_dirty_pages(void) · line 1813

Quoted 11 lines
fs/fs-writeback.c +1 -0
index 56c8fda..d329f89 100644
@@ -1809,6 +1809,7 @@ static unsigned long get_nr_dirty_pages(void)
 {
 	return global_node_page_state(NR_FILE_DIRTY) +
 		global_node_page_state(NR_UNSTABLE_NFS) +
+		global_node_page_state(NR_METADATA_DIRTY) +
 		get_nr_dirty_inodes();

With my question is also connected this - when we have NR_METADATA_DIRTY, we could just account dirty inodes there and get rid of this get_nr_dirty_inodes() hack...

Accounting of dirty inodes would have to applied to every filesystem before that could be done, but....

Quoted 3 lines

But actually getting this to work right to be able to track dirty inodes would be useful on its own - some throlling of creation of dirty inodes would be useful for several filesystems (ext4, xfs, ...).

... this relies on the VFS being able to track and control all dirtying of inodes and metadata.

Which, it should be noted, cannot be done unconditionally because some filesystems /explicitly avoid/ dirtying VFS inodes for anything other than dirty data and provide no mechanism to the VFS for writeback inodes or their related metadata. e.g. XFS, where all metadata changes are transactional and so all dirty inode tracking and writeback control is internal the to the XFS transaction subsystem.

Adding an external throttle to dirtying of metadata doesn't make any sense in this sort of architecture - in XFS we already have all the throttles and expedited writeback triggers integrated into the transaction subsystem (e.g transaction reservation limits, log space limits, periodic background writeback, memory reclaim triggers, etc). It's all so tightly integrated around the physical structure of the filesystem I can't see any way to sanely abstract it to work with a generic "dirty list" accounting and writeback engine at this point...

I can see how tracking of information such as the global amount of dirty metadata is useful for diagnostics, but I'm not convinced we should be using it for globally scoped external control of deeply integrated and highly specific internal filesystem functionality.

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
#6 lore raw

Re: [PATCH 2/3] writeback: allow for dirty metadata accounting

Quoted 23 lines · Dave Chinner
Quoted 15 lines · Jan Kara
Quoted 7 lines · Josef Bacik

Provide a mechanism for file systems to indicate how much dirty metadata they are holding. This introduces a few things

1) Zone stats for dirty metadata, which is the same as the NR_FILE_DIRTY.
2) WB stat for dirty metadata. This way we know if we need to try and call into the file system to write out metadata. This could potentially be used in the future to make balancing of dirty pages smarter.

So I'm curious about one thing: In the previous posting you have mentioned that the main motivation for this work is to have a simple support for sub-pagesize dirty metadata blocks that need tracking in btrfs. However you do the dirty accounting at page granularity. What are your plans to handle this mismatch?

Quoted 6 lines

The thing is you actually shouldn't miscount by too much as that could upset some checks in mm checking how much dirty pages a node has directing how reclaim should be done... But it's a question whether NR_METADATA_DIRTY should be actually used in the checks in node_limits_ok() or in node_pagecache_reclaimable() at all because once you start accounting dirty slab objects, you are really on a thin ice...

Quoted 6 lines

The other thing I'm concerned about is that it's a btrfs-only thing, which means having dirty btrfs metadata on a system with different filesystems (e.g. btrfs root/home, XFS data) is going to affect how memory balance and throttling is run on other filesystems. i.e. it's going ot make a filesystem specific issue into a problem that affects global behaviour.

Umm, I don't think it will be different than currently. Currently btrfs dirty metadata is accounted as dirty page cache because they have this virtual fs inode which owns all metadata pages. It is pretty similar to e.g. ext2 where you have bdev inode which effectively owns all metadata pages and these dirty pages account towards the dirty limits. For ext4 things are more complicated due to journaling and thus ext4 hides the fact that a metadata page is dirty until the corresponding transaction is committed. But from that moment on dirty metadata is again just a dirty pagecache page in the bdev inode.

So current Josef's patch just splits the counter in which btrfs metadata pages would be accounted but effectively there should be no change in the behavior. It is just a question whether this approach is workable in the future when they'd like to track different objects than just pages in the counter.

Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
fs/fs-writeback.c +0 -0
index 56c8fda..d329f89 100644
@@ -1809,6 +1809,7 @@ static unsigned long get_nr_dirty_pages(void)
 {
Quoted 8 lines

fs/fs-writeback.c static unsigned long get_nr_dirty_pages(void) · line 1813

Quoted 4 lines
fs/fs-writeback.c +1 -0
 	return global_node_page_state(NR_FILE_DIRTY) +
 		global_node_page_state(NR_UNSTABLE_NFS) +
+		global_node_page_state(NR_METADATA_DIRTY) +
 		get_nr_dirty_inodes();

With my question is also connected this - when we have NR_METADATA_DIRTY, we could just account dirty inodes there and get rid of this get_nr_dirty_inodes() hack...

Quoted 2 lines

Accounting of dirty inodes would have to applied to every filesystem before that could be done, but....

Well, this particular hack of adding get_nr_dirty_inodes() into the result of get_nr_dirty_pages() is there only so that we do writeback even if there are only dirty inodes without dirty pages. Since XFS doesn't care about writeback for dirty inodes, it would be fine regardless what we do here, won't it?

Quoted 15 lines
Quoted 3 lines

But actually getting this to work right to be able to track dirty inodes would be useful on its own - some throlling of creation of dirty inodes would be useful for several filesystems (ext4, xfs, ...).

... this relies on the VFS being able to track and control all dirtying of inodes and metadata.

Which, it should be noted, cannot be done unconditionally because some filesystems /explicitly avoid/ dirtying VFS inodes for anything other than dirty data and provide no mechanism to the VFS for writeback inodes or their related metadata. e.g. XFS, where all metadata changes are transactional and so all dirty inode tracking and writeback control is internal the to the XFS transaction subsystem.

Quoted 9 lines

Adding an external throttle to dirtying of metadata doesn't make any sense in this sort of architecture - in XFS we already have all the throttles and expedited writeback triggers integrated into the transaction subsystem (e.g transaction reservation limits, log space limits, periodic background writeback, memory reclaim triggers, etc). It's all so tightly integrated around the physical structure of the filesystem I can't see any way to sanely abstract it to work with a generic "dirty list" accounting and writeback engine at this point...

OK, thanks for providing the details about XFS. So my idea was (and Josef's patches seem to be working towards this), that filesystems that decide to use the generic throttling, would just account the dirty metadata in some counter. That counter would be included in the limits checked by balance_dirty_pages(). Filesystem that don't want to use generic throttling would have the counter 0 and thus for them there'd be no difference. And in appropriate points after metadata was dirtied, filesystems that care could call balance_dirty_pages() to throttle the process creating dirty metadata.

Quoted 4 lines

I can see how tracking of information such as the global amount of dirty metadata is useful for diagnostics, but I'm not convinced we should be using it for globally scoped external control of deeply integrated and highly specific internal filesystem functionality.

You are right that when journalling comes in, things get more complex. But btrfs already uses a scheme similar to the above and I believe ext4 could be made to use a similar scheme as well. If you have something better for XFS, then that's good for you and we should make sure we don't interfere with that. Currently I don't think we will.

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>
#7 lore raw

Re: [PATCH 2/3] writeback: allow for dirty metadata accounting

Dave your reply got eaten somewhere along the way for me, so all i have is this email. I'm going to respond to your stuff here.

Quoted 41 lines · Jan Kara
Quoted 23 lines · Dave Chinner
Quoted 15 lines · Jan Kara
Quoted 7 lines · Josef Bacik

Provide a mechanism for file systems to indicate how much dirty metadata they are holding. This introduces a few things

1) Zone stats for dirty metadata, which is the same as the NR_FILE_DIRTY.
2) WB stat for dirty metadata. This way we know if we need to try and call into the file system to write out metadata. This could potentially be used in the future to make balancing of dirty pages smarter.

So I'm curious about one thing: In the previous posting you have mentioned that the main motivation for this work is to have a simple support for sub-pagesize dirty metadata blocks that need tracking in btrfs. However you do the dirty accounting at page granularity. What are your plans to handle this mismatch?

Quoted 6 lines

The thing is you actually shouldn't miscount by too much as that could upset some checks in mm checking how much dirty pages a node has directing how reclaim should be done... But it's a question whether NR_METADATA_DIRTY should be actually used in the checks in node_limits_ok() or in node_pagecache_reclaimable() at all because once you start accounting dirty slab objects, you are really on a thin ice...

Quoted 6 lines

The other thing I'm concerned about is that it's a btrfs-only thing, which means having dirty btrfs metadata on a system with different filesystems (e.g. btrfs root/home, XFS data) is going to affect how memory balance and throttling is run on other filesystems. i.e. it's going ot make a filesystem specific issue into a problem that affects global behaviour.

Umm, I don't think it will be different than currently. Currently btrfs dirty metadata is accounted as dirty page cache because they have this virtual fs inode which owns all metadata pages. It is pretty similar to e.g. ext2 where you have bdev inode which effectively owns all metadata pages and these dirty pages account towards the dirty limits. For ext4 things are more complicated due to journaling and thus ext4 hides the fact that a metadata page is dirty until the corresponding transaction is committed. But from that moment on dirty metadata is again just a dirty pagecache page in the bdev inode.

Quoted 5 lines

So current Josef's patch just splits the counter in which btrfs metadata pages would be accounted but effectively there should be no change in the behavior. It is just a question whether this approach is workable in the future when they'd like to track different objects than just pages in the counter.

+1 to what Jan said. Btrfs's dirty metadata is always going to affect any other file systems in the system, no matter how we deal with it. In fact it's worse with our btree_inode approach as the dirtied_when thing will likely screw somebody and make us skip writing out dirty metadata when we want to. At least with this framework in place we can start to make the throttling smarter, so say make us flush metadata if that is the bigger % of the dirty pages in the system.
All I do now is move the status quo around, we are no worse, and arguably
better with these patches than we were without them.

Quoted 65 lines
Quoted 16 lines
Quoted 15 lines

fs/fs-writeback.c static unsigned long get_nr_dirty_pages(void) · line 1813

Quoted 11 lines
fs/fs-writeback.c +1 -0
index 56c8fda..d329f89 100644
@@ -1809,6 +1809,7 @@ static unsigned long get_nr_dirty_pages(void)
 {
 	return global_node_page_state(NR_FILE_DIRTY) +
 		global_node_page_state(NR_UNSTABLE_NFS) +
+		global_node_page_state(NR_METADATA_DIRTY) +
 		get_nr_dirty_inodes();

With my question is also connected this - when we have NR_METADATA_DIRTY, we could just account dirty inodes there and get rid of this get_nr_dirty_inodes() hack...

Quoted 2 lines

Accounting of dirty inodes would have to applied to every filesystem before that could be done, but....

Well, this particular hack of adding get_nr_dirty_inodes() into the result of get_nr_dirty_pages() is there only so that we do writeback even if there are only dirty inodes without dirty pages. Since XFS doesn't care about writeback for dirty inodes, it would be fine regardless what we do here, won't it?

Quoted 15 lines
Quoted 3 lines

But actually getting this to work right to be able to track dirty inodes would be useful on its own - some throlling of creation of dirty inodes would be useful for several filesystems (ext4, xfs, ...).

... this relies on the VFS being able to track and control all dirtying of inodes and metadata.

Which, it should be noted, cannot be done unconditionally because some filesystems /explicitly avoid/ dirtying VFS inodes for anything other than dirty data and provide no mechanism to the VFS for writeback inodes or their related metadata. e.g. XFS, where all metadata changes are transactional and so all dirty inode tracking and writeback control is internal the to the XFS transaction subsystem.

Quoted 9 lines

Adding an external throttle to dirtying of metadata doesn't make any sense in this sort of architecture - in XFS we already have all the throttles and expedited writeback triggers integrated into the transaction subsystem (e.g transaction reservation limits, log space limits, periodic background writeback, memory reclaim triggers, etc). It's all so tightly integrated around the physical structure of the filesystem I can't see any way to sanely abstract it to work with a generic "dirty list" accounting and writeback engine at this point...

OK, thanks for providing the details about XFS. So my idea was (and Josef's patches seem to be working towards this), that filesystems that decide to use the generic throttling, would just account the dirty metadata in some counter. That counter would be included in the limits checked by balance_dirty_pages(). Filesystem that don't want to use generic throttling would have the counter 0 and thus for them there'd be no difference. And in appropriate points after metadata was dirtied, filesystems that care could call balance_dirty_pages() to throttle the process creating dirty metadata.

Quoted 4 lines

I can see how tracking of information such as the global amount of dirty metadata is useful for diagnostics, but I'm not convinced we should be using it for globally scoped external control of deeply integrated and highly specific internal filesystem functionality.

Quoted 5 lines

You are right that when journalling comes in, things get more complex. But btrfs already uses a scheme similar to the above and I believe ext4 could be made to use a similar scheme as well. If you have something better for XFS, then that's good for you and we should make sure we don't interfere with that. Currently I don't think we will.

XFS doesn't have the problem that btrfs has, so I don't expect it to take advantage of this. Your writeback throttling is tied to your journal transactions, which are already limited in size. Btrfs on the other hand is only limited by the amount of memory in the system, which is why I want to leverage the global throttling code. I went down this path years ago and tried to build the throttling intelligence into btrfs itself and that way lies dragons. I cycled between OOM'ing the box and duplicating a bunch of the global counters inside btrfs.

Btrfs doesn't have the benefit of a arbitrary journal size constraint on it's dirty metadata, so we have to rely on the global limits to make sure we're kept in check. The only thing my patches do is allow us to account for this separately and trigger writeback specifically. 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>

#8 lore raw

Re: [PATCH 2/3] writeback: allow for dirty metadata accounting

Quoted 2 lines · Josef Bacik

Dave your reply got eaten somewhere along the way for me, so all i have is this email. I'm going to respond to your stuff here.

No worries, I'll do a 2-in-1 reply :P

Quoted 32 lines · Jan Kara
Quoted 31 lines · Dave Chinner
Quoted 29 lines · Jan Kara
Quoted 15 lines · Josef Bacik
Quoted 7 lines

Provide a mechanism for file systems to indicate how much dirty metadata they are holding. This introduces a few things

1) Zone stats for dirty metadata, which is the same as the NR_FILE_DIRTY.
2) WB stat for dirty metadata. This way we know if we need to try and call into the file system to write out metadata. This could potentially be used in the future to make balancing of dirty pages smarter.

So I'm curious about one thing: In the previous posting you have mentioned that the main motivation for this work is to have a simple support for sub-pagesize dirty metadata blocks that need tracking in btrfs. However you do the dirty accounting at page granularity. What are your plans to handle this mismatch?

Quoted 6 lines

The thing is you actually shouldn't miscount by too much as that could upset some checks in mm checking how much dirty pages a node has directing how reclaim should be done... But it's a question whether NR_METADATA_DIRTY should be actually used in the checks in node_limits_ok() or in node_pagecache_reclaimable() at all because once you start accounting dirty slab objects, you are really on a thin ice...

The other thing I'm concerned about is that it's a btrfs-only thing, which means having dirty btrfs metadata on a system with different filesystems (e.g. btrfs root/home, XFS data) is going to affect how memory balance and throttling is run on other filesystems. i.e. it's going ot make a filesystem specific issue into a problem that affects global behaviour.

Quoted 3 lines
Quoted 3 lines

Umm, I don't think it will be different than currently. Currently btrfs dirty metadata is accounted as dirty page cache because they have this virtual fs inode which owns all metadata pages.

Yes, so effectively they are treated the same as file data pages w.r.t. throttling, writeback and reclaim....

Quoted 7 lines
Quoted 7 lines

It is pretty similar to
e.g. ext2 where you have bdev inode which effectively owns all metadata pages and these dirty pages account towards the dirty limits. For ext4 things are more complicated due to journaling and thus ext4 hides the fact that a metadata page is dirty until the corresponding transaction is committed. But from that moment on dirty metadata is again just a dirty pagecache page in the bdev inode.

Yeah, though those filesystems don't suffer from the uncontrolled explosion of metadata that btrfs is suffering from, so simply treating them as another dirty inode that needs flushing works just fine.

Quoted 3 lines
Quoted 3 lines

So current Josef's patch just splits the counter in which btrfs metadata pages would be accounted but effectively there should be no change in the behavior.

Yup, I missed the addition to the node_pagecache_reclaimable() that ensures reclaim sees the same number or dirty pages...

Quoted 3 lines
Quoted 3 lines

It is just a question whether this approach is workable in the future when they'd like to track different objects than just pages in the counter.

I don't think it can. Because the counters directly influences the page lru reclaim scanning algorithms, it can only be used to account for pages that are in the LRUs. Other objects like slab objects need to be accounted for and reclaimed by the shrinker infrastructure.

Accounting for metadata writeback is a different issue - it could track slab objects if we wanted to, but the issue is that these are often difficult to determine the amount of IO needed to clean them so generic balancing is hard. (e.g. effect of inode write clustering).

Quoted 5 lines

+1 to what Jan said. Btrfs's dirty metadata is always going to affect any other file systems in the system, no matter how we deal with it. In fact it's worse with our btree_inode approach as the dirtied_when thing will likely screw somebody and make us skip writing out dirty metadata when we want to.

XFS takes care of metadata flushing with a periodic background work controlled by /proc/sys/fs/xfs/xfssyncd_centisecs. We trigger both background async inode reclaim and background dirty metadata flushing from this (run on workqueues) if the system is idle or hasn't had some other trigger fire to run these sooner. It works well enough that I can't remember the last time someone asked a question about needing to tune this parameter, or had a problem that required tuning it to fix....

Quoted 6 lines

At least with this
framework in place we can start to make the throttling smarter, so say make us flush metadata if that is the bigger % of the dirty pages in the system. All I do now is move the status quo around, we are no worse, and arguably better with these patches than we were without them.

Agreed - I misread part of the patch, so I was a little off-target.

Quoted 21 lines
Quoted 15 lines

OK, thanks for providing the details about XFS. So my idea was (and Josef's patches seem to be working towards this), that filesystems that decide to use the generic throttling, would just account the dirty metadata in some counter. That counter would be included in the limits checked by balance_dirty_pages(). Filesystem that don't want to use generic throttling would have the counter 0 and thus for them there'd be no difference. And in appropriate points after metadata was dirtied, filesystems that care could call balance_dirty_pages() to throttle the process creating dirty metadata.

Quoted 4 lines

I can see how tracking of information such as the global amount of dirty metadata is useful for diagnostics, but I'm not convinced we should be using it for globally scoped external control of deeply integrated and highly specific internal filesystem functionality.

Quoted 5 lines

You are right that when journalling comes in, things get more complex. But btrfs already uses a scheme similar to the above and I believe ext4 could be made to use a similar scheme as well. If you have something better for XFS, then that's good for you and we should make sure we don't interfere with that. Currently I don't think we will.

Quoted 8 lines

XFS doesn't have the problem that btrfs has, so I don't expect it to take advantage of this. Your writeback throttling is tied to your journal transactions, which are already limited in size. Btrfs on the other hand is only limited by the amount of memory in the system, which is why I want to leverage the global throttling code. Btrfs doesn't have the benefit of a arbitrary journal size constraint on it's dirty metadata, so we have to rely on the global limits to make sure we're kept in check.

Though you do have a transaction reservation system, so I would expect that be the place where a dirty metadata throttling could be applied sanely. i.e. if there's too much dirty metadata in the system, then you can't get a reservation to dirty more until some of the metadata has been cleaned.

Quoted 3 lines

The only thing my patches
do is allow us to account for this separately and trigger writeback specifically. Thanks,

I'm not sure that global metadata accounting makes sense if there is no mechanism provided for per-sb throttling based purely on metadata demand. Sure, global dirty metadata might be a way of measuring how much metadata all the active filesystems have created, but then you're going to throttle filesystems with no dirty metadata because some other filesystem is being a massive hog.

I suspect that for a well balanced system we are going to need some kind of "in-between" solution that shares the dirty metadata limits across all bdis somewhat fairly similar to file data. How that ties into the bdi writeback rate estimates and other IO/dirty page throttling feedback loops is an interesting question - to me this isn't as obviously simple as it simply separating out metadata accounting...

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>
#9 lore raw

Re: [PATCH 2/3] writeback: allow for dirty metadata accounting

In reply to Jan Kara
Quoted 9 lines · Jan Kara
Quoted 7 lines · Josef Bacik

Provide a mechanism for file systems to indicate how much dirty metadata they are holding. This introduces a few things

1) Zone stats for dirty metadata, which is the same as the NR_FILE_DIRTY.
2) WB stat for dirty metadata. This way we know if we need to try and call into the file system to write out metadata. This could potentially be used in the future to make balancing of dirty pages smarter.

Quoted 5 lines

So I'm curious about one thing: In the previous posting you have mentioned that the main motivation for this work is to have a simple support for sub-pagesize dirty metadata blocks that need tracking in btrfs. However you do the dirty accounting at page granularity. What are your plans to handle this mismatch?

We already track how much dirty metadata we have internally in btrfs, I envisioned the subpage blocksize guys just calling the accounting ever N objects that were dirited in order to keep the accounting correct. This is not great, but it was better than the hoops we needed to jump through to deal with the btree_inode and subpagesize blocksizes.

Quoted 7 lines

The thing is you actually shouldn't miscount by too much as that could upset some checks in mm checking how much dirty pages a node has directing how reclaim should be done... But it's a question whether NR_METADATA_DIRTY should be actually used in the checks in node_limits_ok() or in node_pagecache_reclaimable() at all because once you start accounting dirty slab objects, you are really on a thin ice...

Agreed, this does get a bit ugly.

Quoted 16 lines

fs/fs-writeback.c static unsigned long get_nr_dirty_pages(void) · line 1813

Quoted 11 lines
fs/fs-writeback.c +1 -0
index 56c8fda..d329f89 100644
@@ -1809,6 +1809,7 @@ static unsigned long get_nr_dirty_pages(void)
 {
 	return global_node_page_state(NR_FILE_DIRTY) +
 		global_node_page_state(NR_UNSTABLE_NFS) +
+		global_node_page_state(NR_METADATA_DIRTY) +
 		get_nr_dirty_inodes();

With my question is also connected this - when we have NR_METADATA_DIRTY, we could just account dirty inodes there and get rid of this get_nr_dirty_inodes() hack...

Quoted 3 lines

But actually getting this to work right to be able to track dirty inodes would be useful on its own - some throlling of creation of dirty inodes would be useful for several filesystems (ext4, xfs, ...).

So I suppose what I could do is instead provide a callback for the vm to ask how many dirty objects we have in the file system, instead of adding another page counter. That way the actual accounting is kept internal to the file system, and it gets rid of the weird mismatch when blocksize < pagesize. Does that sound like a more acceptable approach? Unfortunately I decided to do this work to make the blocksize < pagesize work easier, but then didn't actually think about how the accounting would interact with that case, because I'm an idiot.

I think that looping through all the sb's in the system would be kinda shitty for this tho, we want the "get number of dirty pages" part to be relatively fast. What if I do something like the shrinker_control only for dirty objects. So the fs registers some dirty_objects_control, we call into each of those and get the counts from that. Does that sound less crappy? 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>

#10 lore raw

Re: [PATCH 2/3] writeback: allow for dirty metadata accounting

Quoted 6 lines · Josef Bacik

I think that looping through all the sb's in the system would be kinda shitty for this tho, we want the "get number of dirty pages" part to be relatively fast. What if I do something like the shrinker_control only for dirty objects. So the fs registers some dirty_objects_control, we call into each of those and get the counts from that. Does that sound less crappy? Thanks,

Hmmm - just an off-the-wall thought on this....

If you're going to do that, then why wouldn't you simply use a "shrinker" to do the metadata writeback rather than having a hook to count dirty objects to pass to some other writeback code that calls a hook to write the metadata?

That way filesystems can also implement dirty accounting and "writers" for each cache of objects they currently implement shrinkers for. i.e. just expanding shrinkers to be able to "count dirty objects" and "write dirty objects" so that we can tell filesystems to write back all their different metadata caches proportionally to the size of the page cache and it's dirty state. The existing file data and inode writeback could then just be new generic "superblock shrinker" operations, and the fs could have it's own private metadata writeback similar to the private sb shrinker callout we currently have...

And, in doing so, we might be able to completely hide memcg from the writeback implementations similar to the way memcg is completely hidden from the shrinker reclaim implementations...

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>
#11 lore raw

PATCH v2 3/3 writeback: introduce super_operations->write_metadata

In reply to Josef Bacik

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                | 58 +++++++++++++++++++++++++++++++++++++---
 fs/super.c                       |  7 +++++
 include/linux/backing-dev-defs.h |  2 ++
 include/linux/fs.h               |  4 +++
 mm/backing-dev.c                 |  1 +
 5 files changed, 69 insertions(+), 3 deletions(-)
fs/fs-writeback.c +55 -3
index d329f89..b7d8946 100644
@@ -1615,11 +1615,36 @@ static long writeback_sb_inodes(struct super_block *sb,
 	return wrote;
 }
 
+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;
+}
+
 static long __writeback_inodes_wb(struct bdi_writeback *wb,
 				  struct wb_writeback_work *work)
 {
 	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);
@@ -1639,11 +1664,38 @@ 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)) {
+		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_list);
+			list_move_tail(&sb->s_bdi_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 +7 -0
index c2ff475..c1b1028 100644
@@ -215,6 +215,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_list);
 
 	if (list_lru_init_memcg(&s->s_dentry_lru))
 		goto fail;
@@ -305,6 +306,8 @@ void deactivate_locked_super(struct super_block *s)
 {
 	struct file_system_type *fs = s->s_type;
 	if (atomic_dec_and_test(&s->s_active)) {
+		struct backing_dev_info *bdi = s->s_bdi;
+
 		cleancache_invalidate_fs(s);
 		unregister_shrinker(&s->s_shrink);
 		fs->kill_sb(s);
@@ -317,6 +320,10 @@ void deactivate_locked_super(struct super_block *s)
 		list_lru_destroy(&s->s_dentry_lru);
 		list_lru_destroy(&s->s_inode_lru);
 
+		spin_lock(&bdi->sb_list_lock);
+		list_del_init(&s->s_bdi_list);
+		spin_unlock(&bdi->sb_list_lock);
+
 		put_filesystem(fs);
 		put_super(s);
 	} else {
include/linux/backing-dev-defs.h +2 -0
index 1200aae..ee6f27f 100644
@@ -167,6 +167,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 f3f0b4c8..c063ac6 100644
@@ -1430,6 +1430,8 @@ struct super_block {
 
 	spinlock_t		s_inode_wblist_lock;
 	struct list_head	s_inodes_wb;	/* writeback inodes */
+
+	struct list_head	s_bdi_list;
 };
 
 /* Helper functions so that in most cases filesystems will
@@ -1805,6 +1807,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 +1 -0
index b48d4e4..80ba94a 100644
@@ -782,6 +782,7 @@ 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);
 	init_waitqueue_head(&bdi->wb_waitq);
 
 	ret = cgwb_bdi_init(bdi);
Signature · 7 lines
1.8.3.1

--
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
#12 lore raw

Re: [PATCH 3/3] writeback: introduce super_operations->write_metadata

Quoted 9 lines · Josef Bacik

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.

...

Quoted 32 lines
fs/fs-writeback.c +24 -3
@@ -1639,11 +1664,38 @@ 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)) {
+		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_list);
+			list_move_tail(&sb->s_bdi_list,
+				       &wb->bdi->dirty_sb_list);
+			if (!sb->s_op->write_metadata)
+				continue;
+			if (!trylock_super(sb))
+				continue;

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

Quoted 10 lines
fs/fs-writeback.c +6 -0
+			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;

So this will hook metadata writeback into the periodic writeback but when work->sb is set, metadata won't be written because in that case we call writeback_sb_inodes() directly. So you need to call writeback_sb_metadata() from wb_writeback() in that case as well.

...

include/linux/fs.h struct super_block { · line 1434

Quoted 10 lines
include/linux/fs.h +2 -0
index f3f0b4c8..c063ac6 100644
@@ -1430,6 +1430,8 @@ struct super_block {
 
 	spinlock_t		s_inode_wblist_lock;
 	struct list_head	s_inodes_wb;	/* writeback inodes */
+
+	struct list_head	s_bdi_list;

Maybe call this s_bdi_dirty_list?

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>