bdi: replace BDI_CAP_NO_{WRITEBACK,ACCT_DIRTY} with a single flag
authorChristoph Hellwig <hch@lst.de>
Thu, 24 Sep 2020 06:51:40 +0000 (08:51 +0200)
committerJens Axboe <axboe@kernel.dk>
Thu, 24 Sep 2020 19:43:39 +0000 (13:43 -0600)
Replace the two negative flags that are always used together with a
single positive flag that indicates the writeback capability instead
of two related non-capabilities.  Also remove the pointless wrappers
to just check the flag.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Jan Kara <jack@suse.cz>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
fs/9p/vfs_file.c
fs/fs-writeback.c
include/linux/backing-dev.h
mm/backing-dev.c
mm/filemap.c
mm/memcontrol.c
mm/memory-failure.c
mm/migrate.c
mm/mmap.c
mm/page-writeback.c

index 3576123d82990e61dca4b3bbc8dabb1ebd0cea6a..6ecf863bfa2f4b57db975b88f14fe7d80ad36afa 100644 (file)
@@ -625,7 +625,7 @@ static void v9fs_mmap_vm_close(struct vm_area_struct *vma)
 
        inode = file_inode(vma->vm_file);
 
-       if (!mapping_cap_writeback_dirty(inode->i_mapping))
+       if (!mapping_can_writeback(inode->i_mapping))
                wbc.nr_to_write = 0;
 
        might_sleep();
index 149227160ff0b07f7b14594926178a5e8fb8215f..d4f84a2fe0878ebdd8c8f6d82de4a91cb484241d 100644 (file)
@@ -2321,7 +2321,7 @@ void __mark_inode_dirty(struct inode *inode, int flags)
 
                        wb = locked_inode_to_wb_and_lock_list(inode);
 
-                       WARN(bdi_cap_writeback_dirty(wb->bdi) &&
+                       WARN((wb->bdi->capabilities & BDI_CAP_WRITEBACK) &&
                             !test_bit(WB_registered, &wb->state),
                             "bdi-%s not registered\n", bdi_dev_name(wb->bdi));
 
@@ -2346,7 +2346,8 @@ void __mark_inode_dirty(struct inode *inode, int flags)
                         * to make sure background write-back happens
                         * later.
                         */
-                       if (bdi_cap_writeback_dirty(wb->bdi) && wakeup_bdi)
+                       if (wakeup_bdi &&
+                           (wb->bdi->capabilities & BDI_CAP_WRITEBACK))
                                wb_wakeup_delayed(wb);
                        return;
                }
@@ -2581,7 +2582,7 @@ int write_inode_now(struct inode *inode, int sync)
                .range_end = LLONG_MAX,
        };
 
-       if (!mapping_cap_writeback_dirty(inode->i_mapping))
+       if (!mapping_can_writeback(inode->i_mapping))
                wbc.nr_to_write = 0;
 
        might_sleep();
index b217344a2c63be4950baa0ae9c021d1f95149cc0..44df4fcef65c1ebaa2610ddec2fc93c03750c21a 100644 (file)
@@ -110,27 +110,14 @@ int bdi_set_max_ratio(struct backing_dev_info *bdi, unsigned int max_ratio);
 /*
  * Flags in backing_dev_info::capability
  *
- * The first three flags control whether dirty pages will contribute to the
- * VM's accounting and whether writepages() should be called for dirty pages
- * (something that would not, for example, be appropriate for ramfs)
- *
- * WARNING: these flags are closely related and should not normally be
- * used separately.  The BDI_CAP_NO_ACCT_AND_WRITEBACK combines these
- * three flags into a single convenience macro.
- *
- * BDI_CAP_NO_ACCT_DIRTY:  Dirty pages shouldn't contribute to accounting
- * BDI_CAP_NO_WRITEBACK:   Don't write pages back
- * BDI_CAP_WRITEBACK_ACCT: Automatically account writeback pages
- * BDI_CAP_STRICTLIMIT:    Keep number of dirty pages below bdi threshold.
+ * BDI_CAP_WRITEBACK:          Supports dirty page writeback, and dirty pages
+ *                             should contribute to accounting
+ * BDI_CAP_WRITEBACK_ACCT:     Automatically account writeback pages
+ * BDI_CAP_STRICTLIMIT:                Keep number of dirty pages below bdi threshold
  */
-#define BDI_CAP_NO_ACCT_DIRTY  0x00000001
-#define BDI_CAP_NO_WRITEBACK   0x00000002
-#define BDI_CAP_WRITEBACK_ACCT 0x00000004
-#define BDI_CAP_STRICTLIMIT    0x00000010
-#define BDI_CAP_CGROUP_WRITEBACK 0x00000020
-
-#define BDI_CAP_NO_ACCT_AND_WRITEBACK \
-       (BDI_CAP_NO_WRITEBACK | BDI_CAP_NO_ACCT_DIRTY)
+#define BDI_CAP_WRITEBACK              (1 << 0)
+#define BDI_CAP_WRITEBACK_ACCT         (1 << 1)
+#define BDI_CAP_STRICTLIMIT            (1 << 2)
 
 extern struct backing_dev_info noop_backing_dev_info;
 
@@ -169,24 +156,9 @@ static inline int wb_congested(struct bdi_writeback *wb, int cong_bits)
 long congestion_wait(int sync, long timeout);
 long wait_iff_congested(int sync, long timeout);
 
-static inline bool bdi_cap_writeback_dirty(struct backing_dev_info *bdi)
-{
-       return !(bdi->capabilities & BDI_CAP_NO_WRITEBACK);
-}
-
-static inline bool bdi_cap_account_dirty(struct backing_dev_info *bdi)
-{
-       return !(bdi->capabilities & BDI_CAP_NO_ACCT_DIRTY);
-}
-
-static inline bool mapping_cap_writeback_dirty(struct address_space *mapping)
-{
-       return bdi_cap_writeback_dirty(inode_to_bdi(mapping->host));
-}
-
-static inline bool mapping_cap_account_dirty(struct address_space *mapping)
+static inline bool mapping_can_writeback(struct address_space *mapping)
 {
-       return bdi_cap_account_dirty(inode_to_bdi(mapping->host));
+       return inode_to_bdi(mapping->host)->capabilities & BDI_CAP_WRITEBACK;
 }
 
 static inline int bdi_sched_wait(void *word)
@@ -223,7 +195,7 @@ static inline bool inode_cgwb_enabled(struct inode *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_WRITEBACK) &&
                (inode->i_sb->s_iflags & SB_I_CGROUPWB);
 }
 
index df18f0088dd3f5afbc1c9dd13c8657510fba697b..408d5051d05b3d281d4e539b961a16248bd30e4f 100644 (file)
@@ -14,9 +14,7 @@
 #include <linux/device.h>
 #include <trace/events/writeback.h>
 
-struct backing_dev_info noop_backing_dev_info = {
-       .capabilities   = BDI_CAP_NO_ACCT_AND_WRITEBACK,
-};
+struct backing_dev_info noop_backing_dev_info;
 EXPORT_SYMBOL_GPL(noop_backing_dev_info);
 
 static struct class *bdi_class;
@@ -745,7 +743,7 @@ struct backing_dev_info *bdi_alloc(int node_id)
                kfree(bdi);
                return NULL;
        }
-       bdi->capabilities = BDI_CAP_WRITEBACK_ACCT;
+       bdi->capabilities = BDI_CAP_WRITEBACK | BDI_CAP_WRITEBACK_ACCT;
        bdi->ra_pages = VM_READAHEAD_PAGES;
        bdi->io_pages = VM_READAHEAD_PAGES;
        return bdi;
index 1aaea26556cc7e4ab702af1e96262d67a0607cf0..6c2a0139e22fa346e2eae24e02f3d838347f4cbb 100644 (file)
@@ -414,7 +414,7 @@ int __filemap_fdatawrite_range(struct address_space *mapping, loff_t start,
                .range_end = end,
        };
 
-       if (!mapping_cap_writeback_dirty(mapping) ||
+       if (!mapping_can_writeback(mapping) ||
            !mapping_tagged(mapping, PAGECACHE_TAG_DIRTY))
                return 0;
 
@@ -1702,7 +1702,7 @@ repeat:
 no_page:
        if (!page && (fgp_flags & FGP_CREAT)) {
                int err;
-               if ((fgp_flags & FGP_WRITE) && mapping_cap_account_dirty(mapping))
+               if ((fgp_flags & FGP_WRITE) && mapping_can_writeback(mapping))
                        gfp_mask |= __GFP_WRITE;
                if (fgp_flags & FGP_NOFS)
                        gfp_mask &= ~__GFP_FS;
index b807952b4d431b60c52e2fef59a093ed6cc6f373..d2352f76d6519f28a11a0432c14d68d9bbfc5a3f 100644 (file)
@@ -5643,7 +5643,7 @@ static int mem_cgroup_move_account(struct page *page,
                if (PageDirty(page)) {
                        struct address_space *mapping = page_mapping(page);
 
-                       if (mapping_cap_account_dirty(mapping)) {
+                       if (mapping_can_writeback(mapping)) {
                                __mod_lruvec_state(from_vec, NR_FILE_DIRTY,
                                                   -nr_pages);
                                __mod_lruvec_state(to_vec, NR_FILE_DIRTY,
index f1aa6433f4041666ee94e2b586768a04cb9eca68..a1e73943445e77525a1fc22626552705a6f95487 100644 (file)
@@ -1006,7 +1006,7 @@ static bool hwpoison_user_mappings(struct page *p, unsigned long pfn,
         */
        mapping = page_mapping(hpage);
        if (!(flags & MF_MUST_KILL) && !PageDirty(hpage) && mapping &&
-           mapping_cap_writeback_dirty(mapping)) {
+           mapping_can_writeback(mapping)) {
                if (page_mkclean(hpage)) {
                        SetPageDirty(hpage);
                } else {
index 34a842a8eb6a7b85b191e58adca66002a1a5072c..9d2f42a3a162940802012653933c09ab4ec0f3f8 100644 (file)
@@ -503,7 +503,7 @@ int migrate_page_move_mapping(struct address_space *mapping,
                        __dec_lruvec_state(old_lruvec, NR_SHMEM);
                        __inc_lruvec_state(new_lruvec, NR_SHMEM);
                }
-               if (dirty && mapping_cap_account_dirty(mapping)) {
+               if (dirty && mapping_can_writeback(mapping)) {
                        __dec_node_state(oldzone->zone_pgdat, NR_FILE_DIRTY);
                        __dec_zone_state(oldzone, NR_ZONE_WRITE_PENDING);
                        __inc_node_state(newzone->zone_pgdat, NR_FILE_DIRTY);
index 40248d84ad5fbd486a65a6c45bdf4413e8e6789c..1fc0e92be4ba9ba0e4b6752350747e7a42bbc162 100644 (file)
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -1666,7 +1666,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma, pgprot_t vm_page_prot)
 
        /* Can the mapping track the dirty pages? */
        return vma->vm_file && vma->vm_file->f_mapping &&
-               mapping_cap_account_dirty(vma->vm_file->f_mapping);
+               mapping_can_writeback(vma->vm_file->f_mapping);
 }
 
 /*
index 0139f9622a92da52cb202f870cdb20dc30fd84a8..358d6f28c627b737417a9ad6ccdd424bbab1d3c1 100644 (file)
@@ -1882,7 +1882,7 @@ void balance_dirty_pages_ratelimited(struct address_space *mapping)
        int ratelimit;
        int *p;
 
-       if (!bdi_cap_account_dirty(bdi))
+       if (!(bdi->capabilities & BDI_CAP_WRITEBACK))
                return;
 
        if (inode_cgwb_enabled(inode))
@@ -2423,7 +2423,7 @@ void account_page_dirtied(struct page *page, struct address_space *mapping)
 
        trace_writeback_dirty_page(page, mapping);
 
-       if (mapping_cap_account_dirty(mapping)) {
+       if (mapping_can_writeback(mapping)) {
                struct bdi_writeback *wb;
 
                inode_attach_wb(inode, page);
@@ -2450,7 +2450,7 @@ 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)
 {
-       if (mapping_cap_account_dirty(mapping)) {
+       if (mapping_can_writeback(mapping)) {
                dec_lruvec_page_state(page, NR_FILE_DIRTY);
                dec_zone_page_state(page, NR_ZONE_WRITE_PENDING);
                dec_wb_stat(wb, WB_RECLAIMABLE);
@@ -2513,7 +2513,7 @@ void account_page_redirty(struct page *page)
 {
        struct address_space *mapping = page->mapping;
 
-       if (mapping && mapping_cap_account_dirty(mapping)) {
+       if (mapping && mapping_can_writeback(mapping)) {
                struct inode *inode = mapping->host;
                struct bdi_writeback *wb;
                struct wb_lock_cookie cookie = {};
@@ -2625,7 +2625,7 @@ void __cancel_dirty_page(struct page *page)
 {
        struct address_space *mapping = page_mapping(page);
 
-       if (mapping_cap_account_dirty(mapping)) {
+       if (mapping_can_writeback(mapping)) {
                struct inode *inode = mapping->host;
                struct bdi_writeback *wb;
                struct wb_lock_cookie cookie = {};
@@ -2665,7 +2665,7 @@ int clear_page_dirty_for_io(struct page *page)
 
        VM_BUG_ON_PAGE(!PageLocked(page), page);
 
-       if (mapping && mapping_cap_account_dirty(mapping)) {
+       if (mapping && mapping_can_writeback(mapping)) {
                struct inode *inode = mapping->host;
                struct bdi_writeback *wb;
                struct wb_lock_cookie cookie = {};