Skip to contentSkip to conversation

Remove remaining parts of congestion tracking code.

PATCH In review NeilBrown 3 participants 21 messages Feb 22, 2022 – Mar 4, 2022

Subsystems (21)
lore
Share & tools
lore

NeilBrown

author
#0 lore raw

cover Remove remaining parts of congestion tracking code.

Here is another refresh of my "remove congestion tracking" series.

I removed the small tweaks to read-ahead code because they raised questions and are actually required for this series.

Everything else is the same.

Andrew: please drop the version of this that is currently in your tree even if you don't take this. The changes to fuse/nfs/ceph are not appropriate and I wouldn't want them to land by mistake.

Thanks,
NeilBrown

---

NeilBrown (11):
DOC: convert 'subsection' to 'section' in gfp.h
MM: document and polish read-ahead code.
MM: improve cleanup when ->readpages doesn't process all pages.
fuse: remove reliance on bdi congestion
nfs: remove reliance on bdi congestion
ceph: remove reliance on bdi congestion
Remove inode_congested()
Remove bdi_congested() and wb_congested() and related functions
f2fs: replace congestion_wait() calls with io_schedule_timeout() block/bfq-iosched.c: use "false" rather than "BLK_RW_ASYNC" Remove congestion tracking framework.

 Documentation/core-api/mm-api.rst |  19 ++++-
 Documentation/filesystems/vfs.rst |  16 ++--
 block/bfq-iosched.c               |   2 +-
 drivers/block/drbd/drbd_int.h     |   3 -
 drivers/block/drbd/drbd_req.c     |   3 +-
 fs/ceph/addr.c                    |  22 +++---
 fs/ceph/super.c                   |   1 +
 fs/ceph/super.h                   |   1 +
 fs/ext2/ialloc.c                  |   5 --
 fs/f2fs/compress.c                |   4 +-
 fs/f2fs/data.c                    |   3 +-
 fs/f2fs/f2fs.h                    |   6 ++
 fs/f2fs/segment.c                 |   8 +-
 fs/f2fs/super.c                   |   6 +-
 fs/fs-writeback.c                 |  37 ---------
 fs/fuse/control.c                 |  17 -----
 fs/fuse/dev.c                     |   8 --
 fs/fuse/file.c                    |  17 +++++
 fs/nfs/write.c                    |  14 +++-
 fs/nilfs2/segbuf.c                |  15 ----
 fs/xfs/xfs_buf.c                  |   3 -
 include/linux/backing-dev-defs.h  |   8 --
 include/linux/backing-dev.h       |  50 ------------
 include/linux/fs.h                |   9 ++-
 include/linux/nfs_fs_sb.h         |   1 +
 include/trace/events/writeback.h  |  28 -------
 mm/backing-dev.c                  |  57 --------------
 mm/fadvise.c                      |   5 +-
 mm/readahead.c                    | 122 ++++++++++++++++++++++++++++--
 mm/vmscan.c                       |  21 +----
 30 files changed, 212 insertions(+), 299 deletions(-)

--
Signature

author
#1 lore raw

PATCH 1/11 DOC: convert 'subsection' to 'section' in gfp.h

Various DOC: sections in gfp.h have subsection headers (~~~) but the place where they are included in mm-api.rst does not have section, only chapters.
So convert to section headers (---) to avoid confusion. Specifically if section are added later in mm-api.rst, an error results.

---
 include/linux/gfp.h |   10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
include/linux/gfp.h +5 -5
index 80f63c862be5..20f6fbe12993 100644
@@ -79,7 +79,7 @@ struct vm_area_struct;
  * DOC: Page mobility and placement hints
  *
  * Page mobility and placement hints
- * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ * ---------------------------------
  *
  * These flags provide hints about how mobile the page is. Pages with similar
  * mobility are placed within the same pageblocks to minimise problems due
@@ -112,7 +112,7 @@ struct vm_area_struct;
  * DOC: Watermark modifiers
  *
  * Watermark modifiers -- controls access to emergency reserves
- * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ * ------------------------------------------------------------
  *
  * %__GFP_HIGH indicates that the caller is high-priority and that granting
  * the request is necessary before the system can make forward progress.
@@ -144,7 +144,7 @@ struct vm_area_struct;
  * DOC: Reclaim modifiers
  *
  * Reclaim modifiers
- * ~~~~~~~~~~~~~~~~~
+ * -----------------
  * Please note that all the following flags are only applicable to sleepable
  * allocations (e.g. %GFP_NOWAIT and %GFP_ATOMIC will ignore them).
  *
@@ -224,7 +224,7 @@ struct vm_area_struct;
  * DOC: Action modifiers
  *
  * Action modifiers
- * ~~~~~~~~~~~~~~~~
+ * ----------------
  *
  * %__GFP_NOWARN suppresses allocation failure reports.
  *
@@ -256,7 +256,7 @@ struct vm_area_struct;
  * DOC: Useful GFP flag combinations
  *
  * Useful GFP flag combinations
- * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ * ----------------------------
  *
  * Useful GFP flag combinations that are commonly used. It is recommended
  * that subsystems start with one of these combinations and then set/clear
author
#2 lore raw

PATCH 2/11 MM: document and polish read-ahead code.

In reply to NeilBrown

Add some "big-picture" documentation for read-ahead and polish the code to make it fit this documentation.

The meaning of ->async_size is clarified to match its name. i.e. Any request to ->readahead() has a sync part and an async part. The caller will wait for the sync pages to complete, but will not wait for the async pages. The first async page is still marked PG_readahead

Note that the current function names page_cache_sync_ra() and page_cache_async_ra() are misleading. All ra request are partly sync and partly async, so either part can be empty.
A page_cache_sync_ra() request will usually set ->async_size non-zero, implying it is not all synchronous.
When a non-zero req_count is passed to page_cache_async_ra(), the implication is that some prefix of the request is synchronous, though the calculation made there is incorrect - I haven't tried to fix it.

---
 Documentation/core-api/mm-api.rst |   19 ++++++-
 Documentation/filesystems/vfs.rst |   16 ++++--
 include/linux/fs.h                |    9 +++
 mm/readahead.c                    |   99 +++++++++++++++++++++++++++++++++++++
 4 files changed, 133 insertions(+), 10 deletions(-)
Documentation/core-api/mm-api.rst +17 -2
index 395835f9289f..f5b2f92822c8 100644
@@ -58,15 +58,30 @@ Virtually Contiguous Mappings
 File Mapping and Page Cache
 ===========================
 
-.. kernel-doc:: mm/readahead.c
-   :export:
+Filemap
+-------
 
 .. kernel-doc:: mm/filemap.c
    :export:
 
+Readahead
+---------
+
+.. kernel-doc:: mm/readahead.c
+   :doc: Readahead Overview
+
+.. kernel-doc:: mm/readahead.c
+   :export:
+
+Writeback
+---------
+
 .. kernel-doc:: mm/page-writeback.c
    :export:
 
+Truncate
+--------
+
 .. kernel-doc:: mm/truncate.c
    :export:
 
Documentation/filesystems/vfs.rst +10 -6
index bf5c48066fac..b4a0baa46dcc 100644
@@ -806,12 +806,16 @@ cache in your filesystem.  The following members are defined:
 	object.  The pages are consecutive in the page cache and are
 	locked.  The implementation should decrement the page refcount
 	after starting I/O on each page.  Usually the page will be
-	unlocked by the I/O completion handler.  If the filesystem decides
-	to stop attempting I/O before reaching the end of the readahead
-	window, it can simply return.  The caller will decrement the page
-	refcount and unlock the remaining pages for you.  Set PageUptodate
-	if the I/O completes successfully.  Setting PageError on any page
-	will be ignored; simply unlock the page if an I/O error occurs.
+	unlocked by the I/O completion handler.  The set of pages are
+	divided into some sync pages followed by some async pages,
+	rac->ra->async_size gives the number of async pages.  The
+	filesystem should attempt to read all sync pages but may decide
+	to stop once it reaches the async pages.  If it does decide to
+	stop attempting I/O, it can simply return.  The caller will
+	remove the remaining pages from the address space, unlock them
+	and decrement the page refcount.  Set PageUptodate if the I/O
+	completes successfully.  Setting PageError on any page will be
+	ignored; simply unlock the page if an I/O error occurs.
 
 ``readpages``
 	called by the VM to read pages associated with the address_space
include/linux/fs.h +7 -2
index e2d892b201b0..8b5c486bd4a2 100644
@@ -930,10 +930,15 @@ struct fown_struct {
  * struct file_ra_state - Track a file's readahead state.
  * @start: Where the most recent readahead started.
  * @size: Number of pages read in the most recent readahead.
- * @async_size: Start next readahead when this many pages are left.
- * @ra_pages: Maximum size of a readahead request.
+ * @async_size: Numer of pages that were/are not needed immediately
+ *      and so were/are genuinely "ahead".  Start next readahead when
+ *      the first of these pages is accessed.
+ * @ra_pages: Maximum size of a readahead request, copied from the bdi.
  * @mmap_miss: How many mmap accesses missed in the page cache.
  * @prev_pos: The last byte in the most recent read request.
+ *
+ * When this structure is passed to ->readahead(), the "most recent"
+ * readahead means the current readahead.
  */
 struct file_ra_state {
 	pgoff_t start;
mm/readahead.c +99 -0

105 lines not on this page · raw message

author
#3 lore raw

PATCH 3/11 MM: improve cleanup when ->readpages doesn't process all pages.

In reply to NeilBrown

If ->readpages doesn't process all the pages, then it is best to act as though they weren't requested so that a subsequent readahead can try again.
So:
- remove any 'ahead' pages from the page cache so they can be loaded

    with ->readahead() rather then multiple ->read()s

- update the file_ra_state to reflect the reads that were actually submitted.

This allows ->readpages() to abort early due e.g. to congestion, which will then allow us to remove the inode_read_congested() test from page_Cache_async_ra().

---
 mm/readahead.c |   19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)
mm/readahead.c +17 -2
index 73b2bc5302e0..8a97bd408cf6 100644
@@ -104,7 +104,13 @@
  * for necessary resources (e.g.  memory or indexing information) to
  * become available.  Pages in the final ``async_size`` may be
  * considered less urgent and failure to read them is more acceptable.
- * They will eventually be read individually using ->readpage().
+ * In this case it is best to use delete_from_page_cache() to remove the
+ * pages from the page cache as is automatically done for pages that
+ * were not fetched with readahead_page().  This will allow a
+ * subsequent synchronous read ahead request to try them again.  If they
+ * are left in the page cache, then they will be read individually using
+ * ->readpage().
+ *
  */
 
 #include <linux/kernel.h>
@@ -226,8 +232,17 @@ static void read_pages(struct readahead_control *rac, struct list_head *pages,
 
 	if (aops->readahead) {
 		aops->readahead(rac);
-		/* Clean up the remaining pages */
+		/*
+		 * Clean up the remaining pages.  The sizes in ->ra
+		 * maybe be used to size next read-ahead, so make sure
+		 * they accurately reflect what happened.
+		 */
 		while ((page = readahead_page(rac))) {
+			rac->ra->size -= 1;
+			if (rac->ra->async_size > 0) {
+				rac->ra->async_size -= 1;
+				delete_from_page_cache(page);
+			}
 			unlock_page(page);
 			put_page(page);
 		}
maintainer
#4 lore raw

Re: [PATCH 03/11] MM: improve cleanup when ->readpages doesn't process all pages.

Quoted 44 lines · NeilBrown

If ->readpages doesn't process all the pages, then it is best to act as though they weren't requested so that a subsequent readahead can try again.
So:
- remove any 'ahead' pages from the page cache so they can be loaded

    with ->readahead() rather then multiple ->read()s

- update the file_ra_state to reflect the reads that were actually submitted.

This allows ->readpages() to abort early due e.g. to congestion, which will then allow us to remove the inode_read_congested() test from page_Cache_async_ra().

---
 mm/readahead.c |   19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)
mm/readahead.c +8 -2
index 73b2bc5302e0..8a97bd408cf6 100644
@@ -104,7 +104,13 @@
  * for necessary resources (e.g.  memory or indexing information) to
  * become available.  Pages in the final ``async_size`` may be
  * considered less urgent and failure to read them is more acceptable.
- * They will eventually be read individually using ->readpage().
+ * In this case it is best to use delete_from_page_cache() to remove the
+ * pages from the page cache as is automatically done for pages that
+ * were not fetched with readahead_page().  This will allow a
+ * subsequent synchronous read ahead request to try them again.  If they
+ * are left in the page cache, then they will be read individually using
+ * ->readpage().
+ *
  */
 
 #include <linux/kernel.h>
@@ -226,8 +232,17 @@ static void read_pages(struct readahead_control *rac, struct list_head *pages,
 
        if (aops->readahead) {
                aops->readahead(rac);
-               /* Clean up the remaining pages */
+               /*

mm/readahead.c static void read_pages(struct readahead_control *rac, struct list_head *pages, · line 245

Quoted 10 lines
mm/readahead.c +9 -0
+                * Clean up the remaining pages.  The sizes in ->ra
+                * maybe be used to size next read-ahead, so make sure
+                * they accurately reflect what happened.
+                */
                while ((page = readahead_page(rac))) {
+                       rac->ra->size -= 1;
+                       if (rac->ra->async_size > 0) {
+                               rac->ra->async_size -= 1;
+                               delete_from_page_cache(page);
+                       }

Does the above imply that filesystem should submit at least ra->size pages, regardless of congestion?

Thanks,
Miklos

author
#5 lore raw

Re: [PATCH 03/11] MM: improve cleanup when ->readpages doesn't process all pages.

Quoted 50 lines · Miklos Szeredi
Quoted 49 lines · NeilBrown

If ->readpages doesn't process all the pages, then it is best to act as though they weren't requested so that a subsequent readahead can try again.
So:
- remove any 'ahead' pages from the page cache so they can be loaded

    with ->readahead() rather then multiple ->read()s

- update the file_ra_state to reflect the reads that were actually submitted.

This allows ->readpages() to abort early due e.g. to congestion, which will then allow us to remove the inode_read_congested() test from page_Cache_async_ra().

---
 mm/readahead.c |   19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)
mm/readahead.c +12 -2
index 73b2bc5302e0..8a97bd408cf6 100644
@@ -104,7 +104,13 @@
  * for necessary resources (e.g.  memory or indexing information) to
  * become available.  Pages in the final ``async_size`` may be
  * considered less urgent and failure to read them is more acceptable.
- * They will eventually be read individually using ->readpage().
+ * In this case it is best to use delete_from_page_cache() to remove the
+ * pages from the page cache as is automatically done for pages that
+ * were not fetched with readahead_page().  This will allow a
+ * subsequent synchronous read ahead request to try them again.  If they
+ * are left in the page cache, then they will be read individually using
+ * ->readpage().
+ *
  */
 
 #include <linux/kernel.h>
@@ -226,8 +232,17 @@ static void read_pages(struct readahead_control *rac, struct list_head *pages,
 
        if (aops->readahead) {
                aops->readahead(rac);
-               /* Clean up the remaining pages */
+               /*
+                * Clean up the remaining pages.  The sizes in ->ra
+                * maybe be used to size next read-ahead, so make sure
+                * they accurately reflect what happened.
+                */
                while ((page = readahead_page(rac))) {
Quoted 8 lines

mm/readahead.c static void read_pages(struct readahead_control *rac, struct list_head *pages, · line 245

Quoted 5 lines
mm/readahead.c +5 -0
+                       rac->ra->size -= 1;
+                       if (rac->ra->async_size > 0) {
+                               rac->ra->async_size -= 1;
+                               delete_from_page_cache(page);
+                       }

Does the above imply that filesystem should submit at least ra->size pages, regardless of congestion?

ra->size - ra_async_size
pages should be submitted reguardless of congestion.

NeilBrown

author
#6 lore raw

PATCH 4/11 fuse: remove reliance on bdi congestion

In reply to NeilBrown

The bdi congestion tracking in not widely used and will be removed.

Fuse is one of a small number of filesystems that uses it, setting both the sync (read) and async (write) congestion flags at what it determines are appropriate times.

The only remaining effect of the sync flag is to cause read-ahead to be skipped.
The only remaining effect of the async flag is to cause (some) WB_SYNC_NONE writes to be skipped.

So instead of setting the flags, change:
- .readahead to stop when it has submitted all non-async pages for read.
- .writepages to do nothing if WB_SYNC_NONE and the flag would be set
- .writepage to return AOP_WRITEPAGE_ACTIVATE if WB_SYNC_NONE and the flag would be set.

The writepages change causes a behavioural change in that pageout() can now return PAGE_ACTIVATE instead of PAGE_KEEP, so SetPageActive() will be called on the page which (I think) will further delay the next attempt at writeout. This might be a good thing.

---
 fs/fuse/control.c |   17 -----------------
 fs/fuse/dev.c     |    8 --------
 fs/fuse/file.c    |   17 +++++++++++++++++
 3 files changed, 17 insertions(+), 25 deletions(-)
fs/fuse/control.c +0 -17
index 000d2e5627e9..7cede9a3bc96 100644
@@ -164,7 +164,6 @@ static ssize_t fuse_conn_congestion_threshold_write(struct file *file,
 {
 	unsigned val;
 	struct fuse_conn *fc;
-	struct fuse_mount *fm;
 	ssize_t ret;
 
 	ret = fuse_conn_limit_write(file, buf, count, ppos, &val,
@@ -178,22 +177,6 @@ static ssize_t fuse_conn_congestion_threshold_write(struct file *file,
 	down_read(&fc->killsb);
 	spin_lock(&fc->bg_lock);
 	fc->congestion_threshold = val;
-
-	/*
-	 * Get any fuse_mount belonging to this fuse_conn; s_bdi is
-	 * shared between all of them
-	 */
-
-	if (!list_empty(&fc->mounts)) {
-		fm = list_first_entry(&fc->mounts, struct fuse_mount, fc_entry);
-		if (fc->num_background < fc->congestion_threshold) {
-			clear_bdi_congested(fm->sb->s_bdi, BLK_RW_SYNC);
-			clear_bdi_congested(fm->sb->s_bdi, BLK_RW_ASYNC);
-		} else {
-			set_bdi_congested(fm->sb->s_bdi, BLK_RW_SYNC);
-			set_bdi_congested(fm->sb->s_bdi, BLK_RW_ASYNC);
-		}
-	}
 	spin_unlock(&fc->bg_lock);
 	up_read(&fc->killsb);
 	fuse_conn_put(fc);
fs/fuse/dev.c +0 -8
index cd54a529460d..e1b4a846c90d 100644
@@ -315,10 +315,6 @@ void fuse_request_end(struct fuse_req *req)
 				wake_up(&fc->blocked_waitq);
 		}
 
-		if (fc->num_background == fc->congestion_threshold && fm->sb) {
-			clear_bdi_congested(fm->sb->s_bdi, BLK_RW_SYNC);
-			clear_bdi_congested(fm->sb->s_bdi, BLK_RW_ASYNC);
-		}
 		fc->num_background--;
 		fc->active_background--;
 		flush_bg_queue(fc);
@@ -540,10 +536,6 @@ static bool fuse_request_queue_background(struct fuse_req *req)
 		fc->num_background++;
 		if (fc->num_background == fc->max_background)
 			fc->blocked = 1;
-		if (fc->num_background == fc->congestion_threshold && fm->sb) {
-			set_bdi_congested(fm->sb->s_bdi, BLK_RW_SYNC);
-			set_bdi_congested(fm->sb->s_bdi, BLK_RW_ASYNC);
-		}
 		list_add_tail(&req->list, &fc->bg_queue);
 		flush_bg_queue(fc);
 		queued = true;
fs/fuse/file.c +17 -0
index 829094451774..94747bac3489 100644
@@ -966,6 +966,14 @@ static void fuse_readahead(struct readahead_control *rac)
 		struct fuse_io_args *ia;
 		struct fuse_args_pages *ap;
 
+		if (fc->num_background >= fc->congestion_threshold &&
+		    rac->ra->async_size >= readahead_count(rac))
+			/*
+			 * Congested and only async pages left, so skip the
+			 * rest.
+			 */
+			break;
+
 		nr_pages = readahead_count(rac) - nr_pages;
 		if (nr_pages > max_pages)
 			nr_pages = max_pages;
@@ -1958,6 +1966,7 @@ static int fuse_writepage_locked(struct page *page)
 
 static int fuse_writepage(struct page *page, struct writeback_control *wbc)
 {
+	struct fuse_conn *fc = get_fuse_conn(page->mapping->host);
 	int err;
 
 	if (fuse_page_is_writeback(page->mapping->host, page->index)) {
@@ -1973,6 +1982,10 @@ static int fuse_writepage(struct page *page, struct writeback_control *wbc)
 		return 0;
 	}
 
+	if (wbc->sync_mode == WB_SYNC_NONE &&
+	    fc->num_background >= fc->congestion_threshold)
+		return AOP_WRITEPAGE_ACTIVATE;
+
 	err = fuse_writepage_locked(page);
 	unlock_page(page);
 
@@ -2226,6 +2239,10 @@ static int fuse_writepages(struct address_space *mapping,
 	if (fuse_is_bad(inode))
 		goto out;
 
+	if (wbc->sync_mode == WB_SYNC_NONE &&
+	    fc->num_background >= fc->congestion_threshold)
+		return 0;
+
 	data.inode = inode;
 	data.wpa = NULL;
 	data.ff = NULL;
maintainer
#7 lore raw

Re: [PATCH 04/11] fuse: remove reliance on bdi congestion

Quoted 97 lines · NeilBrown

The bdi congestion tracking in not widely used and will be removed.

Fuse is one of a small number of filesystems that uses it, setting both the sync (read) and async (write) congestion flags at what it determines are appropriate times.

The only remaining effect of the sync flag is to cause read-ahead to be skipped.
The only remaining effect of the async flag is to cause (some) WB_SYNC_NONE writes to be skipped.

So instead of setting the flags, change:
- .readahead to stop when it has submitted all non-async pages for read.
- .writepages to do nothing if WB_SYNC_NONE and the flag would be set
- .writepage to return AOP_WRITEPAGE_ACTIVATE if WB_SYNC_NONE and the flag would be set.

The writepages change causes a behavioural change in that pageout() can now return PAGE_ACTIVATE instead of PAGE_KEEP, so SetPageActive() will be called on the page which (I think) will further delay the next attempt at writeout. This might be a good thing.

---
 fs/fuse/control.c |   17 -----------------
 fs/fuse/dev.c     |    8 --------
 fs/fuse/file.c    |   17 +++++++++++++++++
 3 files changed, 17 insertions(+), 25 deletions(-)
fs/fuse/control.c +0 -17
index 000d2e5627e9..7cede9a3bc96 100644
@@ -164,7 +164,6 @@ static ssize_t fuse_conn_congestion_threshold_write(struct file *file,
 {
        unsigned val;
        struct fuse_conn *fc;
-       struct fuse_mount *fm;
        ssize_t ret;
 
        ret = fuse_conn_limit_write(file, buf, count, ppos, &val,
@@ -178,22 +177,6 @@ static ssize_t fuse_conn_congestion_threshold_write(struct file *file,
        down_read(&fc->killsb);
        spin_lock(&fc->bg_lock);
        fc->congestion_threshold = val;
-
-       /*
-        * Get any fuse_mount belonging to this fuse_conn; s_bdi is
-        * shared between all of them
-        */
-
-       if (!list_empty(&fc->mounts)) {
-               fm = list_first_entry(&fc->mounts, struct fuse_mount, fc_entry);
-               if (fc->num_background < fc->congestion_threshold) {
-                       clear_bdi_congested(fm->sb->s_bdi, BLK_RW_SYNC);
-                       clear_bdi_congested(fm->sb->s_bdi, BLK_RW_ASYNC);
-               } else {
-                       set_bdi_congested(fm->sb->s_bdi, BLK_RW_SYNC);
-                       set_bdi_congested(fm->sb->s_bdi, BLK_RW_ASYNC);
-               }
-       }
        spin_unlock(&fc->bg_lock);
        up_read(&fc->killsb);
        fuse_conn_put(fc);
fs/fuse/dev.c +0 -8
index cd54a529460d..e1b4a846c90d 100644
@@ -315,10 +315,6 @@ void fuse_request_end(struct fuse_req *req)
                                wake_up(&fc->blocked_waitq);
                }
 
-               if (fc->num_background == fc->congestion_threshold && fm->sb) {
-                       clear_bdi_congested(fm->sb->s_bdi, BLK_RW_SYNC);
-                       clear_bdi_congested(fm->sb->s_bdi, BLK_RW_ASYNC);
-               }
                fc->num_background--;
                fc->active_background--;
                flush_bg_queue(fc);
@@ -540,10 +536,6 @@ static bool fuse_request_queue_background(struct fuse_req *req)
                fc->num_background++;
                if (fc->num_background == fc->max_background)
                        fc->blocked = 1;
-               if (fc->num_background == fc->congestion_threshold && fm->sb) {
-                       set_bdi_congested(fm->sb->s_bdi, BLK_RW_SYNC);
-                       set_bdi_congested(fm->sb->s_bdi, BLK_RW_ASYNC);
-               }
                list_add_tail(&req->list, &fc->bg_queue);
                flush_bg_queue(fc);
                queued = true;
fs/fuse/file.c +0 -0
index 829094451774..94747bac3489 100644

fs/fuse/file.c static void fuse_readahead(struct readahead_control *rac) · line 975

Quoted 10 lines
fs/fuse/file.c +7 -0
@@ -966,6 +966,14 @@ static void fuse_readahead(struct readahead_control *rac)
                struct fuse_io_args *ia;
                struct fuse_args_pages *ap;
 
+               if (fc->num_background >= fc->congestion_threshold &&
+                   rac->ra->async_size >= readahead_count(rac))
+                       /*
+                        * Congested and only async pages left, so skip the
+                        * rest.
+                        */
+                       break;

Ah, you are taking care of it here...

Regarding the async part: a potential (corner?) case is if task A is reading region X and triggering readahead for region Y and at the same time task B is reading region Y. In the congestion case it can happen that non-uptodate pages in Y are truncated off the pagecache while B is waiting for them to become uptodate.

This shouldn't be too hard to trigger, just need two sequential readers of the same file, where one is just ahead of the other. I'll try to do a test program for this case specifically.

Thanks,
Miklos

author
#8 lore raw

Re: [PATCH 04/11] fuse: remove reliance on bdi congestion

Quoted 111 lines · Miklos Szeredi
Quoted 97 lines · NeilBrown

The bdi congestion tracking in not widely used and will be removed.

Fuse is one of a small number of filesystems that uses it, setting both the sync (read) and async (write) congestion flags at what it determines are appropriate times.

The only remaining effect of the sync flag is to cause read-ahead to be skipped.
The only remaining effect of the async flag is to cause (some) WB_SYNC_NONE writes to be skipped.

So instead of setting the flags, change:
- .readahead to stop when it has submitted all non-async pages for read.
- .writepages to do nothing if WB_SYNC_NONE and the flag would be set
- .writepage to return AOP_WRITEPAGE_ACTIVATE if WB_SYNC_NONE and the flag would be set.

The writepages change causes a behavioural change in that pageout() can now return PAGE_ACTIVATE instead of PAGE_KEEP, so SetPageActive() will be called on the page which (I think) will further delay the next attempt at writeout. This might be a good thing.

---
 fs/fuse/control.c |   17 -----------------
 fs/fuse/dev.c     |    8 --------
 fs/fuse/file.c    |   17 +++++++++++++++++
 3 files changed, 17 insertions(+), 25 deletions(-)
fs/fuse/control.c +0 -17
index 000d2e5627e9..7cede9a3bc96 100644
@@ -164,7 +164,6 @@ static ssize_t fuse_conn_congestion_threshold_write(struct file *file,
 {
        unsigned val;
        struct fuse_conn *fc;
-       struct fuse_mount *fm;
        ssize_t ret;
 
        ret = fuse_conn_limit_write(file, buf, count, ppos, &val,
@@ -178,22 +177,6 @@ static ssize_t fuse_conn_congestion_threshold_write(struct file *file,
        down_read(&fc->killsb);
        spin_lock(&fc->bg_lock);
        fc->congestion_threshold = val;
-
-       /*
-        * Get any fuse_mount belonging to this fuse_conn; s_bdi is
-        * shared between all of them
-        */
-
-       if (!list_empty(&fc->mounts)) {
-               fm = list_first_entry(&fc->mounts, struct fuse_mount, fc_entry);
-               if (fc->num_background < fc->congestion_threshold) {
-                       clear_bdi_congested(fm->sb->s_bdi, BLK_RW_SYNC);
-                       clear_bdi_congested(fm->sb->s_bdi, BLK_RW_ASYNC);
-               } else {
-                       set_bdi_congested(fm->sb->s_bdi, BLK_RW_SYNC);
-                       set_bdi_congested(fm->sb->s_bdi, BLK_RW_ASYNC);
-               }
-       }
        spin_unlock(&fc->bg_lock);
        up_read(&fc->killsb);
        fuse_conn_put(fc);
fs/fuse/dev.c +0 -8
index cd54a529460d..e1b4a846c90d 100644
@@ -315,10 +315,6 @@ void fuse_request_end(struct fuse_req *req)
                                wake_up(&fc->blocked_waitq);
                }
 
-               if (fc->num_background == fc->congestion_threshold && fm->sb) {
-                       clear_bdi_congested(fm->sb->s_bdi, BLK_RW_SYNC);
-                       clear_bdi_congested(fm->sb->s_bdi, BLK_RW_ASYNC);
-               }
                fc->num_background--;
                fc->active_background--;
                flush_bg_queue(fc);
@@ -540,10 +536,6 @@ static bool fuse_request_queue_background(struct fuse_req *req)
                fc->num_background++;
                if (fc->num_background == fc->max_background)
                        fc->blocked = 1;
-               if (fc->num_background == fc->congestion_threshold && fm->sb) {
-                       set_bdi_congested(fm->sb->s_bdi, BLK_RW_SYNC);
-                       set_bdi_congested(fm->sb->s_bdi, BLK_RW_ASYNC);
-               }
                list_add_tail(&req->list, &fc->bg_queue);
                flush_bg_queue(fc);
                queued = true;
fs/fuse/file.c +0 -0
index 829094451774..94747bac3489 100644

fs/fuse/file.c static void fuse_readahead(struct readahead_control *rac) · line 975

Quoted 10 lines
fs/fuse/file.c +7 -0
@@ -966,6 +966,14 @@ static void fuse_readahead(struct readahead_control *rac)
                struct fuse_io_args *ia;
                struct fuse_args_pages *ap;
 
+               if (fc->num_background >= fc->congestion_threshold &&
+                   rac->ra->async_size >= readahead_count(rac))
+                       /*
+                        * Congested and only async pages left, so skip the
+                        * rest.
+                        */
+                       break;

Ah, you are taking care of it here...

Quoted 5 lines

Regarding the async part: a potential (corner?) case is if task A is reading region X and triggering readahead for region Y and at the same time task B is reading region Y. In the congestion case it can happen that non-uptodate pages in Y are truncated off the pagecache while B is waiting for them to become uptodate.

I don't think that is a problem.
If the second reader finds the non-uptodate page that is waiting for attention from the readahead of the first reader, then it will wait until the page is unlocked. Once it gets the lock, it will find that ->mapping is NULL (in the middle of filemap_update_page() for example) and so will drop the page and try again.
Second time around (in e.g. filemap_get_pages()) it will find that there is no page, and so will call pagE_cache_sync_readahead() which allocates some pages as appropriate and calls ->readahead() on them.

It might be best for the discarding of pages to having in reverse index order so that there is no risk of waiting and retrying a series of times, but I suspect that wouldn't happen very often.

Quoted 4 lines

This shouldn't be too hard to trigger, just need two sequential readers of the same file, where one is just ahead of the other. I'll try to do a test program for this case specifically.

Thanks - I'd love to hear of any test results you can produce.

Thanks,
NeilBrown

author
#9 lore raw

PATCH 5/11 nfs: remove reliance on bdi congestion

In reply to NeilBrown

The bdi congestion tracking in not widely used and will be removed.

NFS is one of a small number of filesystems that uses it, setting just the async (write) congestion flag at what it determines are appropriate times.

The only remaining effect of the async flag is to cause (some) WB_SYNC_NONE writes to be skipped.

So instead of setting the flag, set an internal flag and change:
- .writepages to do nothing if WB_SYNC_NONE and the flag is set
- .writepage to return AOP_WRITEPAGE_ACTIVATE if WB_SYNC_NONE and the flag is set.

The writepages change causes a behavioural change in that pageout() can now return PAGE_ACTIVATE instead of PAGE_KEEP, so SetPageActive() will be called on the page which (I think) wil further delay the next attempt at writeout. This might be a good thing.

---
 fs/nfs/write.c            |   14 +++++++++++---
 include/linux/nfs_fs_sb.h |    1 +
 2 files changed, 12 insertions(+), 3 deletions(-)
fs/nfs/write.c +11 -3
index 987a187bd39a..7c986164018e 100644
@@ -417,7 +417,7 @@ static void nfs_set_page_writeback(struct page *page)
 
 	if (atomic_long_inc_return(&nfss->writeback) >
 			NFS_CONGESTION_ON_THRESH)
-		set_bdi_congested(inode_to_bdi(inode), BLK_RW_ASYNC);
+		nfss->write_congested = 1;
 }
 
 static void nfs_end_page_writeback(struct nfs_page *req)
@@ -433,7 +433,7 @@ static void nfs_end_page_writeback(struct nfs_page *req)
 
 	end_page_writeback(req->wb_page);
 	if (atomic_long_dec_return(&nfss->writeback) < NFS_CONGESTION_OFF_THRESH)
-		clear_bdi_congested(inode_to_bdi(inode), BLK_RW_ASYNC);
+		nfss->write_congested = 0;
 }
 
 /*
@@ -672,6 +672,10 @@ static int nfs_writepage_locked(struct page *page,
 	struct inode *inode = page_file_mapping(page)->host;
 	int err;
 
+	if (wbc->sync_mode == WB_SYNC_NONE &&
+	    NFS_SERVER(inode)->write_congested)
+		return AOP_WRITEPAGE_ACTIVATE;
+
 	nfs_inc_stats(inode, NFSIOS_VFSWRITEPAGE);
 	nfs_pageio_init_write(&pgio, inode, 0,
 				false, &nfs_async_write_completion_ops);
@@ -719,6 +723,10 @@ int nfs_writepages(struct address_space *mapping, struct writeback_control *wbc)
 	int priority = 0;
 	int err;
 
+	if (wbc->sync_mode == WB_SYNC_NONE &&
+	    NFS_SERVER(inode)->write_congested)
+		return 0;
+
 	nfs_inc_stats(inode, NFSIOS_VFSWRITEPAGES);
 
 	if (!(mntflags & NFS_MOUNT_WRITE_EAGER) || wbc->for_kupdate ||
@@ -1893,7 +1901,7 @@ static void nfs_commit_release_pages(struct nfs_commit_data *data)
 	}
 	nfss = NFS_SERVER(data->inode);
 	if (atomic_long_read(&nfss->writeback) < NFS_CONGESTION_OFF_THRESH)
-		clear_bdi_congested(inode_to_bdi(data->inode), BLK_RW_ASYNC);
+		nfss->write_congested = 0;
 
 	nfs_init_cinfo(&cinfo, data->inode, data->dreq);
 	nfs_commit_end(cinfo.mds);
include/linux/nfs_fs_sb.h +1 -0
index ca0959e51e81..6aa2a200676a 100644
@@ -138,6 +138,7 @@ struct nfs_server {
 	struct nlm_host		*nlm_host;	/* NLM client handle */
 	struct nfs_iostats __percpu *io_stats;	/* I/O statistics */
 	atomic_long_t		writeback;	/* number of writeback pages */
+	unsigned int		write_congested;/* flag set when writeback gets too high */
 	unsigned int		flags;		/* various flags */
 
 /* The following are for internal use only. Also see uapi/linux/nfs_mount.h */
author
#10 lore raw

PATCH 6/11 ceph: remove reliance on bdi congestion

In reply to NeilBrown

The bdi congestion tracking in not widely used and will be removed.

CEPHfs is one of a small number of filesystems that uses it, setting just the async (write) congestion flags at what it determines are appropriate times.

The only remaining effect of the async flag is to cause (some) WB_SYNC_NONE writes to be skipped.

So instead of setting the flag, set an internal flag and change:
- .writepages to do nothing if WB_SYNC_NONE and the flag is set
- .writepage to return AOP_WRITEPAGE_ACTIVATE if WB_SYNC_NONE and the flag is set.

The writepages change causes a behavioural change in that pageout() can now return PAGE_ACTIVATE instead of PAGE_KEEP, so SetPageActive() will be called on the page which (I think) wil further delay the next attempt at writeout. This might be a good thing.

---
 fs/ceph/addr.c  |   22 +++++++++++++---------
 fs/ceph/super.c |    1 +
 fs/ceph/super.h |    1 +
 3 files changed, 15 insertions(+), 9 deletions(-)
fs/ceph/addr.c +13 -9
index c98e5238a1b6..dc7af34640dd 100644
@@ -563,7 +563,7 @@ static int writepage_nounlock(struct page *page, struct writeback_control *wbc)
 
 	if (atomic_long_inc_return(&fsc->writeback_count) >
 	    CONGESTION_ON_THRESH(fsc->mount_options->congestion_kb))
-		set_bdi_congested(inode_to_bdi(inode), BLK_RW_ASYNC);
+		fsc->write_congested = true;
 
 	req = ceph_osdc_new_request(osdc, &ci->i_layout, ceph_vino(inode), page_off, &len, 0, 1,
 				    CEPH_OSD_OP_WRITE, CEPH_OSD_FLAG_WRITE, snapc,
@@ -623,7 +623,7 @@ static int writepage_nounlock(struct page *page, struct writeback_control *wbc)
 
 	if (atomic_long_dec_return(&fsc->writeback_count) <
 	    CONGESTION_OFF_THRESH(fsc->mount_options->congestion_kb))
-		clear_bdi_congested(inode_to_bdi(inode), BLK_RW_ASYNC);
+		fsc->write_congested = false;
 
 	return err;
 }
@@ -635,6 +635,10 @@ static int ceph_writepage(struct page *page, struct writeback_control *wbc)
 	BUG_ON(!inode);
 	ihold(inode);
 
+	if (wbc->sync_mode == WB_SYNC_NONE &&
+	    ceph_inode_to_client(inode)->write_congested)
+		return AOP_WRITEPAGE_ACTIVATE;
+
 	wait_on_page_fscache(page);
 
 	err = writepage_nounlock(page, wbc);
@@ -707,8 +711,7 @@ static void writepages_finish(struct ceph_osd_request *req)
 			if (atomic_long_dec_return(&fsc->writeback_count) <
 			     CONGESTION_OFF_THRESH(
 					fsc->mount_options->congestion_kb))
-				clear_bdi_congested(inode_to_bdi(inode),
-						    BLK_RW_ASYNC);
+				fsc->write_congested = false;
 
 			ceph_put_snap_context(detach_page_private(page));
 			end_page_writeback(page);
@@ -760,6 +763,10 @@ static int ceph_writepages_start(struct address_space *mapping,
 	bool done = false;
 	bool caching = ceph_is_cache_enabled(inode);
 
+	if (wbc->sync_mode == WB_SYNC_NONE &&
+	    fsc->write_congested)
+		return 0;
+
 	dout("writepages_start %p (mode=%s)\n", inode,
 	     wbc->sync_mode == WB_SYNC_NONE ? "NONE" :
 	     (wbc->sync_mode == WB_SYNC_ALL ? "ALL" : "HOLD"));
@@ -954,11 +961,8 @@ static int ceph_writepages_start(struct address_space *mapping,
 
 			if (atomic_long_inc_return(&fsc->writeback_count) >
 			    CONGESTION_ON_THRESH(
-				    fsc->mount_options->congestion_kb)) {
-				set_bdi_congested(inode_to_bdi(inode),
-						  BLK_RW_ASYNC);
-			}
-
+				    fsc->mount_options->congestion_kb))
+				fsc->write_congested = true;
 
 			pages[locked_pages++] = page;
 			pvec.pages[i] = NULL;
fs/ceph/super.c +1 -0
index bf79f369aec6..4a3b77d049c7 100644
@@ -802,6 +802,7 @@ static struct ceph_fs_client *create_fs_client(struct ceph_mount_options *fsopt,
 	fsc->have_copy_from2 = true;
 
 	atomic_long_set(&fsc->writeback_count, 0);
+	fsc->write_congested = false;
 
 	err = -ENOMEM;
 	/*
fs/ceph/super.h +1 -0
index 67f145e1ae7a..0bd97aea2319 100644
@@ -121,6 +121,7 @@ struct ceph_fs_client {
 	struct ceph_mds_client *mdsc;
 
 	atomic_long_t writeback_count;
+	bool write_congested;
 
 	struct workqueue_struct *inode_wq;
 	struct workqueue_struct *cap_wq;
maintainer
#11 lore raw

Re: [PATCH 06/11] ceph: remove reliance on bdi congestion

Quoted 14 lines · NeilBrown

The bdi congestion tracking in not widely used and will be removed.

CEPHfs is one of a small number of filesystems that uses it, setting just the async (write) congestion flags at what it determines are appropriate times.

The only remaining effect of the async flag is to cause (some) WB_SYNC_NONE writes to be skipped.

So instead of setting the flag, set an internal flag and change:
- .writepages to do nothing if WB_SYNC_NONE and the flag is set
- .writepage to return AOP_WRITEPAGE_ACTIVATE if WB_SYNC_NONE and the flag is set.

Quoted 6 lines

The writepages change causes a behavioural change in that pageout() can now return PAGE_ACTIVATE instead of PAGE_KEEP, so SetPageActive() will be called on the page which (I think) wil further delay the next attempt at writeout. This might be a good thing.

Maybe. I have to wonder whether all of this is really useful.

When things are congested we'll avoid trying to issue new writeback requests. Note that we don't prevent new pages from being dirtied here -
- only their being written back.

This also doesn't do anything in the DIO or sync_write cases, so if we lose caps or are doing DIO, we'll just keep churning out "unlimited" writes in those cases anyway.

With ceph too, we're not likely to be dealing with a single server as well. One OSD could be struggling to keep up but others are OK. Do we really want to throttle writeback to the ones that are fine?

FWIW, the original patch that added this stuff was this:

commit 2baba25019ec564cd247af74013873d69a0b8190

Author: Yehuda Sadeh <[email protected]>
Date:   Fri Dec 18 13:51:57 2009 -0800

ceph: writeback congestion control

Set bdi congestion bit when amount of write data in flight exceeds adjustable threshold.

...but it's pretty scant on details.

The only reason I can see to throttle writeback like this is to prevent you from having too much memory tied up in writeback requests, but we aren't limiting other requests in the same way.

Maybe we would do better to just rip this stuff out?

Quoted 100 lines
---
 fs/ceph/addr.c  |   22 +++++++++++++---------
 fs/ceph/super.c |    1 +
 fs/ceph/super.h |    1 +
 3 files changed, 15 insertions(+), 9 deletions(-)
fs/ceph/addr.c +13 -9
index c98e5238a1b6..dc7af34640dd 100644
@@ -563,7 +563,7 @@ static int writepage_nounlock(struct page *page, struct writeback_control *wbc)
 
 	if (atomic_long_inc_return(&fsc->writeback_count) >
 	    CONGESTION_ON_THRESH(fsc->mount_options->congestion_kb))
-		set_bdi_congested(inode_to_bdi(inode), BLK_RW_ASYNC);
+		fsc->write_congested = true;
 
 	req = ceph_osdc_new_request(osdc, &ci->i_layout, ceph_vino(inode), page_off, &len, 0, 1,
 				    CEPH_OSD_OP_WRITE, CEPH_OSD_FLAG_WRITE, snapc,
@@ -623,7 +623,7 @@ static int writepage_nounlock(struct page *page, struct writeback_control *wbc)
 
 	if (atomic_long_dec_return(&fsc->writeback_count) <
 	    CONGESTION_OFF_THRESH(fsc->mount_options->congestion_kb))
-		clear_bdi_congested(inode_to_bdi(inode), BLK_RW_ASYNC);
+		fsc->write_congested = false;
 
 	return err;
 }
@@ -635,6 +635,10 @@ static int ceph_writepage(struct page *page, struct writeback_control *wbc)
 	BUG_ON(!inode);
 	ihold(inode);
 
+	if (wbc->sync_mode == WB_SYNC_NONE &&
+	    ceph_inode_to_client(inode)->write_congested)
+		return AOP_WRITEPAGE_ACTIVATE;
+
 	wait_on_page_fscache(page);
 
 	err = writepage_nounlock(page, wbc);
@@ -707,8 +711,7 @@ static void writepages_finish(struct ceph_osd_request *req)
 			if (atomic_long_dec_return(&fsc->writeback_count) <
 			     CONGESTION_OFF_THRESH(
 					fsc->mount_options->congestion_kb))
-				clear_bdi_congested(inode_to_bdi(inode),
-						    BLK_RW_ASYNC);
+				fsc->write_congested = false;
 
 			ceph_put_snap_context(detach_page_private(page));
 			end_page_writeback(page);
@@ -760,6 +763,10 @@ static int ceph_writepages_start(struct address_space *mapping,
 	bool done = false;
 	bool caching = ceph_is_cache_enabled(inode);
 
+	if (wbc->sync_mode == WB_SYNC_NONE &&
+	    fsc->write_congested)
+		return 0;
+
 	dout("writepages_start %p (mode=%s)\n", inode,
 	     wbc->sync_mode == WB_SYNC_NONE ? "NONE" :
 	     (wbc->sync_mode == WB_SYNC_ALL ? "ALL" : "HOLD"));
@@ -954,11 +961,8 @@ static int ceph_writepages_start(struct address_space *mapping,
 
 			if (atomic_long_inc_return(&fsc->writeback_count) >
 			    CONGESTION_ON_THRESH(
-				    fsc->mount_options->congestion_kb)) {
-				set_bdi_congested(inode_to_bdi(inode),
-						  BLK_RW_ASYNC);
-			}
-
+				    fsc->mount_options->congestion_kb))
+				fsc->write_congested = true;
 
 			pages[locked_pages++] = page;
 			pvec.pages[i] = NULL;
fs/ceph/super.c +1 -0
index bf79f369aec6..4a3b77d049c7 100644
@@ -802,6 +802,7 @@ static struct ceph_fs_client *create_fs_client(struct ceph_mount_options *fsopt,
 	fsc->have_copy_from2 = true;
 
 	atomic_long_set(&fsc->writeback_count, 0);
+	fsc->write_congested = false;
 
 	err = -ENOMEM;
 	/*
fs/ceph/super.h +1 -0
index 67f145e1ae7a..0bd97aea2319 100644
@@ -121,6 +121,7 @@ struct ceph_fs_client {
 	struct ceph_mds_client *mdsc;
 
 	atomic_long_t writeback_count;
+	bool write_congested;
 
 	struct workqueue_struct *inode_wq;
 	struct workqueue_struct *cap_wq;
Signature · 1 line
Jeff Layton <[email protected]>
author
#12 lore raw

Re: [PATCH 06/11] ceph: remove reliance on bdi congestion

Quoted 24 lines · Jeff Layton
Quoted 14 lines · NeilBrown

The bdi congestion tracking in not widely used and will be removed.

CEPHfs is one of a small number of filesystems that uses it, setting just the async (write) congestion flags at what it determines are appropriate times.

The only remaining effect of the async flag is to cause (some) WB_SYNC_NONE writes to be skipped.

So instead of setting the flag, set an internal flag and change:
- .writepages to do nothing if WB_SYNC_NONE and the flag is set
- .writepage to return AOP_WRITEPAGE_ACTIVATE if WB_SYNC_NONE and the flag is set.

Quoted 6 lines

The writepages change causes a behavioural change in that pageout() can now return PAGE_ACTIVATE instead of PAGE_KEEP, so SetPageActive() will be called on the page which (I think) wil further delay the next attempt at writeout. This might be a good thing.

Maybe. I have to wonder whether all of this is really useful.

Quoted 7 lines

When things are congested we'll avoid trying to issue new writeback requests. Note that we don't prevent new pages from being dirtied here -
- only their being written back.

This also doesn't do anything in the DIO or sync_write cases, so if we lose caps or are doing DIO, we'll just keep churning out "unlimited" writes in those cases anyway.

I think the point of congestion tracking is to differentiate between sync and async IO. Or maybe "required" and "optional". Eventually the "optional" IO will become required, but if we can delay it until a time when there is less "required" io, then maybe we can improve perceived latency.

"optional" IO here is write-back and read-ahead. If the load of "required" IO is bursty, and if we can shuffle that optional stuff into the quiet periods, we might win.

Whether this is a real need is an important question that I don't have an answer for. And whether it is better to leave delayed requests in the page cache, or in the low-level queue with sync requests able to over-take them - I don't know. If you have multiple low-level queue as you say you can with ceph, then lower might be better.

The block layer has REQ_RAHEAD .. maybe those request get should get a lower priority ... though I don't think they do.
NFS has a 3 level priority queue, with write-back going at a lower priority ... I think... for NFSv3 at least.

Sometimes I suspect that as all our transports have become faster, we have been able to ignore the extra latency caused by poor scheduling of optional requests. But at other times when my recently upgraded desktop is struggling to view a web page while compiling a kernel ... I wonder if maybe we don't have the balance right any more.

So maybe you are right - maybe we can rip all this stuff out.

Or maybe not.

Thanks,
NeilBrown

maintainer
#13 lore raw

Re: [PATCH 06/11] ceph: remove reliance on bdi congestion

Quoted 39 lines · NeilBrown
Quoted 24 lines · Jeff Layton
Quoted 14 lines · NeilBrown

The bdi congestion tracking in not widely used and will be removed.

CEPHfs is one of a small number of filesystems that uses it, setting just the async (write) congestion flags at what it determines are appropriate times.

The only remaining effect of the async flag is to cause (some) WB_SYNC_NONE writes to be skipped.

So instead of setting the flag, set an internal flag and change:
- .writepages to do nothing if WB_SYNC_NONE and the flag is set
- .writepage to return AOP_WRITEPAGE_ACTIVATE if WB_SYNC_NONE and the flag is set.

Quoted 6 lines

The writepages change causes a behavioural change in that pageout() can now return PAGE_ACTIVATE instead of PAGE_KEEP, so SetPageActive() will be called on the page which (I think) wil further delay the next attempt at writeout. This might be a good thing.

Maybe. I have to wonder whether all of this is really useful.

Quoted 7 lines

When things are congested we'll avoid trying to issue new writeback requests. Note that we don't prevent new pages from being dirtied here -
- only their being written back.

This also doesn't do anything in the DIO or sync_write cases, so if we lose caps or are doing DIO, we'll just keep churning out "unlimited" writes in those cases anyway.

I think the point of congestion tracking is to differentiate between sync and async IO. Or maybe "required" and "optional". Eventually the "optional" IO will become required, but if we can delay it until a time when there is less "required" io, then maybe we can improve perceived latency.

Quoted 4 lines

"optional" IO here is write-back and read-ahead. If the load of "required" IO is bursty, and if we can shuffle that optional stuff into the quiet periods, we might win.

In that case, maybe we should be counting in-flight reads too and deny readahead when the count crosses some threshold? It seems a bit silly to only look at writes when it comes to "congestion".

Quoted 11 lines

Whether this is a real need is an important question that I don't have an answer for. And whether it is better to leave delayed requests in the page cache, or in the low-level queue with sync requests able to over-take them - I don't know. If you have multiple low-level queue as you say you can with ceph, then lower might be better.

The block layer has REQ_RAHEAD .. maybe those request get should get a lower priority ... though I don't think they do.
NFS has a 3 level priority queue, with write-back going at a lower priority ... I think... for NFSv3 at least.

Quoted 8 lines

Sometimes I suspect that as all our transports have become faster, we have been able to ignore the extra latency caused by poor scheduling of optional requests. But at other times when my recently upgraded desktop is struggling to view a web page while compiling a kernel ... I wonder if maybe we don't have the balance right any more.

So maybe you are right - maybe we can rip all this stuff out.

I lean more toward just removing it. The existing implementation seems a bit half-baked with the gaps in what's being counted. Granted, the default congestion threshold is pretty high with modern memory sizes, so it probably doesn't come into play much in practice, but removing it would reduce some complexity in the client.

Signature · 1 line
Jeff Layton <[email protected]>
author
#14 lore raw

Re: [PATCH 06/11] ceph: remove reliance on bdi congestion

Quoted 40 lines · Jeff Layton
Quoted 39 lines · NeilBrown
Quoted 24 lines · Jeff Layton
Quoted 14 lines · NeilBrown

The bdi congestion tracking in not widely used and will be removed.

CEPHfs is one of a small number of filesystems that uses it, setting just the async (write) congestion flags at what it determines are appropriate times.

The only remaining effect of the async flag is to cause (some) WB_SYNC_NONE writes to be skipped.

So instead of setting the flag, set an internal flag and change:
- .writepages to do nothing if WB_SYNC_NONE and the flag is set
- .writepage to return AOP_WRITEPAGE_ACTIVATE if WB_SYNC_NONE and the flag is set.

Quoted 6 lines

The writepages change causes a behavioural change in that pageout() can now return PAGE_ACTIVATE instead of PAGE_KEEP, so SetPageActive() will be called on the page which (I think) wil further delay the next attempt at writeout. This might be a good thing.

Maybe. I have to wonder whether all of this is really useful.

Quoted 7 lines

When things are congested we'll avoid trying to issue new writeback requests. Note that we don't prevent new pages from being dirtied here -
- only their being written back.

This also doesn't do anything in the DIO or sync_write cases, so if we lose caps or are doing DIO, we'll just keep churning out "unlimited" writes in those cases anyway.

I think the point of congestion tracking is to differentiate between sync and async IO. Or maybe "required" and "optional". Eventually the "optional" IO will become required, but if we can delay it until a time when there is less "required" io, then maybe we can improve perceived latency.

Quoted 8 lines
Quoted 4 lines

"optional" IO here is write-back and read-ahead. If the load of "required" IO is bursty, and if we can shuffle that optional stuff into the quiet periods, we might win.

In that case, maybe we should be counting in-flight reads too and deny readahead when the count crosses some threshold? It seems a bit silly to only look at writes when it comes to "congestion".

I agree that seems a bit silly.

Quoted 18 lines
Quoted 18 lines

Whether this is a real need is an important question that I don't have an answer for. And whether it is better to leave delayed requests in the page cache, or in the low-level queue with sync requests able to over-take them - I don't know. If you have multiple low-level queue as you say you can with ceph, then lower might be better.

The block layer has REQ_RAHEAD .. maybe those request get should get a lower priority ... though I don't think they do.
NFS has a 3 level priority queue, with write-back going at a lower priority ... I think... for NFSv3 at least.

Sometimes I suspect that as all our transports have become faster, we have been able to ignore the extra latency caused by poor scheduling of optional requests. But at other times when my recently upgraded desktop is struggling to view a web page while compiling a kernel ... I wonder if maybe we don't have the balance right any more.

Quoted 8 lines
Quoted 2 lines

So maybe you are right - maybe we can rip all this stuff out.

I lean more toward just removing it. The existing implementation seems a bit half-baked with the gaps in what's being counted. Granted, the default congestion threshold is pretty high with modern memory sizes, so it probably doesn't come into play much in practice, but removing it would reduce some complexity in the client.

I'd love to have some test that could reliably generate congestion and measure latencies for other IO. Without that, it is mostly guess work. So I cannot argue against your proposal, and do agree that removing the code would reduce complexity. I have no idea what the costs might be - if any. Hence my focus was on not changing behaviour.

Thanks,
NeilBrown

maintainer
#15 lore raw

Re: [PATCH 06/11] ceph: remove reliance on bdi congestion

Quoted 79 lines · NeilBrown
Quoted 40 lines · Jeff Layton
Quoted 39 lines · NeilBrown
Quoted 24 lines · Jeff Layton
Quoted 14 lines · NeilBrown

The bdi congestion tracking in not widely used and will be removed.

CEPHfs is one of a small number of filesystems that uses it, setting just the async (write) congestion flags at what it determines are appropriate times.

The only remaining effect of the async flag is to cause (some) WB_SYNC_NONE writes to be skipped.

So instead of setting the flag, set an internal flag and change:
- .writepages to do nothing if WB_SYNC_NONE and the flag is set
- .writepage to return AOP_WRITEPAGE_ACTIVATE if WB_SYNC_NONE and the flag is set.

Quoted 6 lines

The writepages change causes a behavioural change in that pageout() can now return PAGE_ACTIVATE instead of PAGE_KEEP, so SetPageActive() will be called on the page which (I think) wil further delay the next attempt at writeout. This might be a good thing.

Maybe. I have to wonder whether all of this is really useful.

Quoted 7 lines

When things are congested we'll avoid trying to issue new writeback requests. Note that we don't prevent new pages from being dirtied here -
- only their being written back.

This also doesn't do anything in the DIO or sync_write cases, so if we lose caps or are doing DIO, we'll just keep churning out "unlimited" writes in those cases anyway.

I think the point of congestion tracking is to differentiate between sync and async IO. Or maybe "required" and "optional". Eventually the "optional" IO will become required, but if we can delay it until a time when there is less "required" io, then maybe we can improve perceived latency.

Quoted 8 lines
Quoted 4 lines

"optional" IO here is write-back and read-ahead. If the load of "required" IO is bursty, and if we can shuffle that optional stuff into the quiet periods, we might win.

In that case, maybe we should be counting in-flight reads too and deny readahead when the count crosses some threshold? It seems a bit silly to only look at writes when it comes to "congestion".

I agree that seems a bit silly.

Quoted 18 lines
Quoted 18 lines

Whether this is a real need is an important question that I don't have an answer for. And whether it is better to leave delayed requests in the page cache, or in the low-level queue with sync requests able to over-take them - I don't know. If you have multiple low-level queue as you say you can with ceph, then lower might be better.

The block layer has REQ_RAHEAD .. maybe those request get should get a lower priority ... though I don't think they do.
NFS has a 3 level priority queue, with write-back going at a lower priority ... I think... for NFSv3 at least.

Sometimes I suspect that as all our transports have become faster, we have been able to ignore the extra latency caused by poor scheduling of optional requests. But at other times when my recently upgraded desktop is struggling to view a web page while compiling a kernel ... I wonder if maybe we don't have the balance right any more.

Quoted 8 lines
Quoted 2 lines

So maybe you are right - maybe we can rip all this stuff out.

I lean more toward just removing it. The existing implementation seems a bit half-baked with the gaps in what's being counted. Granted, the default congestion threshold is pretty high with modern memory sizes, so it probably doesn't come into play much in practice, but removing it would reduce some complexity in the client.

Quoted 6 lines

I'd love to have some test that could reliably generate congestion and measure latencies for other IO. Without that, it is mostly guess work. So I cannot argue against your proposal, and do agree that removing the code would reduce complexity. I have no idea what the costs might be - if any. Hence my focus was on not changing behaviour.

Fair enough -- caution is warranted.

I think the thing to do here is to take your patch for now, and then we can look at just removing all of this stuff at some point in the future. That would also give us a fallback that doesn't require the old congestion infrastructure if it turns out that it is needed.

I'm assuming this is going in via Andrew's tree, but let us know if you'd like us to take any of these in via the ceph tree.

Thanks,

Signature · 1 line
Jeff Layton <[email protected]>
author
#16 lore raw

PATCH 7/11 Remove inode_congested()

In reply to NeilBrown

inode_congested() reports if the backing-device for the inode is congested. No bdi reports congestion any more, so this always returns 'false'.

So remove inode_congested() and related functions, and remove the call sites, assuming that inode_congested() always returns 'false'.

---
 fs/fs-writeback.c           |   37 -------------------------------------
 include/linux/backing-dev.h |   22 ----------------------
 mm/fadvise.c                |    5 ++---
 mm/readahead.c              |    6 ------
 mm/vmscan.c                 |   17 +----------------
 5 files changed, 3 insertions(+), 84 deletions(-)
fs/fs-writeback.c +0 -37
index f8d7fe6db989..42a3dfad40b8 100644
@@ -893,43 +893,6 @@ void wbc_account_cgroup_owner(struct writeback_control *wbc, struct page *page,
 }
 EXPORT_SYMBOL_GPL(wbc_account_cgroup_owner);
 
-/**
- * inode_congested - test whether an inode is congested
- * @inode: inode to test for congestion (may be NULL)
- * @cong_bits: mask of WB_[a]sync_congested bits to test
- *
- * Tests whether @inode is congested.  @cong_bits is the mask of congestion
- * bits to test and the return value is the mask of set bits.
- *
- * If cgroup writeback is enabled for @inode, the congestion state is
- * determined by whether the cgwb (cgroup bdi_writeback) for the blkcg
- * associated with @inode is congested; otherwise, the root wb's congestion
- * state is used.
- *
- * @inode is allowed to be NULL as this function is often called on
- * mapping->host which is NULL for the swapper space.
- */
-int inode_congested(struct inode *inode, int cong_bits)
-{
-	/*
-	 * Once set, ->i_wb never becomes NULL while the inode is alive.
-	 * Start transaction iff ->i_wb is visible.
-	 */
-	if (inode && inode_to_wb_is_valid(inode)) {
-		struct bdi_writeback *wb;
-		struct wb_lock_cookie lock_cookie = {};
-		bool congested;
-
-		wb = unlocked_inode_to_wb_begin(inode, &lock_cookie);
-		congested = wb_congested(wb, cong_bits);
-		unlocked_inode_to_wb_end(inode, &lock_cookie);
-		return congested;
-	}
-
-	return wb_congested(&inode_to_bdi(inode)->wb, cong_bits);
-}
-EXPORT_SYMBOL_GPL(inode_congested);
-
 /**
  * wb_split_bdi_pages - split nr_pages to write according to bandwidth
  * @wb: target bdi_writeback to split @nr_pages to
include/linux/backing-dev.h +0 -22
index 483979c1b9f4..860b675c2929 100644
@@ -162,7 +162,6 @@ struct bdi_writeback *wb_get_create(struct backing_dev_info *bdi,
 				    gfp_t gfp);
 void wb_memcg_offline(struct mem_cgroup *memcg);
 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
@@ -390,29 +389,8 @@ static inline void wb_blkcg_offline(struct blkcg *blkcg)
 {
 }
 
-static inline int inode_congested(struct inode *inode, int cong_bits)
-{
-	return wb_congested(&inode_to_bdi(inode)->wb, cong_bits);
-}
-
 #endif	/* CONFIG_CGROUP_WRITEBACK */
 
-static inline int inode_read_congested(struct inode *inode)
-{
-	return inode_congested(inode, 1 << WB_sync_congested);
-}
-
-static inline int inode_write_congested(struct inode *inode)
-{
-	return inode_congested(inode, 1 << WB_async_congested);
-}
-
-static inline int inode_rw_congested(struct inode *inode)
-{
-	return inode_congested(inode, (1 << WB_sync_congested) |
-				      (1 << WB_async_congested));
-}
-
 static inline int bdi_congested(struct backing_dev_info *bdi, int cong_bits)
 {
 	return wb_congested(&bdi->wb, cong_bits);
mm/fadvise.c +2 -3
index d6baa4f451c5..338f16022012 100644
@@ -109,9 +109,8 @@ int generic_fadvise(struct file *file, loff_t offset, loff_t len, int advice)
 	case POSIX_FADV_NOREUSE:
 		break;
 	case POSIX_FADV_DONTNEED:
-		if (!inode_write_congested(mapping->host))
-			__filemap_fdatawrite_range(mapping, offset, endbyte,
-						   WB_SYNC_NONE);
+		__filemap_fdatawrite_range(mapping, offset, endbyte,
+					   WB_SYNC_NONE);
 
 		/*
 		 * First and last FULL page! Partial pages are deliberately
mm/readahead.c +0 -6
index 8a97bd408cf6..f61943fd1741 100644
@@ -709,12 +709,6 @@ void page_cache_async_ra(struct readahead_control *ractl,
 
 	folio_clear_readahead(folio);
 
-	/*
-	 * Defer asynchronous read-ahead on IO congestion.
-	 */
-	if (inode_read_congested(ractl->mapping->host))
-		return;
-
 	if (blk_cgroup_congested())
 		return;
 
mm/vmscan.c +1 -16
index 59b14e0d696c..e38de6456cdc 100644
@@ -989,17 +989,6 @@ static inline int is_page_cache_freeable(struct page *page)
 	return page_count(page) - page_has_private(page) == 1 + page_cache_pins;
 }
 
-static int may_write_to_inode(struct inode *inode)
-{
-	if (current->flags & PF_SWAPWRITE)
-		return 1;
-	if (!inode_write_congested(inode))
-		return 1;
-	if (inode_to_bdi(inode) == current->backing_dev_info)
-		return 1;
-	return 0;
-}
-
 /*
  * We detected a synchronous write error writing a page out.  Probably
  * -ENOSPC.  We need to propagate that into the address_space for a subsequent
@@ -1201,8 +1190,6 @@ static pageout_t pageout(struct page *page, struct address_space *mapping)
 	}
 	if (mapping->a_ops->writepage == NULL)
 		return PAGE_ACTIVATE;
-	if (!may_write_to_inode(mapping->host))
-		return PAGE_KEEP;
 
 	if (clear_page_dirty_for_io(page)) {
 		int res;
@@ -1578,9 +1565,7 @@ static unsigned int shrink_page_list(struct list_head *page_list,
 		 * end of the LRU a second time.
 		 */
 		mapping = page_mapping(page);
-		if (((dirty || writeback) && mapping &&
-		     inode_write_congested(mapping->host)) ||
-		    (writeback && PageReclaim(page)))
+		if (writeback && PageReclaim(page))
 			stat->nr_congested++;
 
 		/*
author
#17 lore raw

PATCH 8/11 Remove bdi_congested() and wb_congested() and related functions

In reply to NeilBrown

These functions are no longer useful as no BDIs report congestions any more.

Removing the test on bdi_write_contested() in current_may_throttle() could cause a small change in behaviour, but only when PF_LOCAL_THROTTLE is set.

So replace the calls by 'false' and simplify the code - and remove the functions.

---
 drivers/block/drbd/drbd_int.h |    3 ---
 drivers/block/drbd/drbd_req.c |    3 +--
 fs/ext2/ialloc.c              |    5 -----
 fs/nilfs2/segbuf.c            |   15 ---------------
 fs/xfs/xfs_buf.c              |    3 ---
 include/linux/backing-dev.h   |   26 --------------------------
 mm/vmscan.c                   |    4 +---
 7 files changed, 2 insertions(+), 57 deletions(-)
drivers/block/drbd/drbd_int.h +0 -3
index f27d5b0f9a0b..f804b1bfb3e6 100644
@@ -638,9 +638,6 @@ enum {
 	STATE_SENT,		/* Do not change state/UUIDs while this is set */
 	CALLBACK_PENDING,	/* Whether we have a call_usermodehelper(, UMH_WAIT_PROC)
 				 * pending, from drbd worker context.
-				 * If set, bdi_write_congested() returns true,
-				 * so shrink_page_list() would not recurse into,
-				 * and potentially deadlock on, this drbd worker.
 				 */
 	DISCONNECT_SENT,
 
drivers/block/drbd/drbd_req.c +1 -2
index 3235532ae077..2e5fb7e442e3 100644
@@ -909,8 +909,7 @@ static bool remote_due_to_read_balancing(struct drbd_device *device, sector_t se
 
 	switch (rbm) {
 	case RB_CONGESTED_REMOTE:
-		return bdi_read_congested(
-			device->ldev->backing_bdev->bd_disk->bdi);
+		return 0;
 	case RB_LEAST_PENDING:
 		return atomic_read(&device->local_cnt) >
 			atomic_read(&device->ap_pending_cnt) + atomic_read(&device->rs_pending_cnt);
fs/ext2/ialloc.c +0 -5
index df14e750e9fe..998dd2ac8008 100644
@@ -170,11 +170,6 @@ static void ext2_preread_inode(struct inode *inode)
 	unsigned long offset;
 	unsigned long block;
 	struct ext2_group_desc * gdp;
-	struct backing_dev_info *bdi;
-
-	bdi = inode_to_bdi(inode);
-	if (bdi_rw_congested(bdi))
-		return;
 
 	block_group = (inode->i_ino - 1) / EXT2_INODES_PER_GROUP(inode->i_sb);
 	gdp = ext2_get_group_desc(inode->i_sb, block_group, NULL);
fs/nilfs2/segbuf.c +0 -15
index 43287b0d3e9b..c4510f79037f 100644
@@ -343,17 +343,6 @@ static int nilfs_segbuf_submit_bio(struct nilfs_segment_buffer *segbuf,
 	struct bio *bio = wi->bio;
 	int err;
 
-	if (segbuf->sb_nbio > 0 &&
-	    bdi_write_congested(segbuf->sb_super->s_bdi)) {
-		wait_for_completion(&segbuf->sb_bio_event);
-		segbuf->sb_nbio--;
-		if (unlikely(atomic_read(&segbuf->sb_err))) {
-			bio_put(bio);
-			err = -EIO;
-			goto failed;
-		}
-	}
-
 	bio->bi_end_io = nilfs_end_bio_write;
 	bio->bi_private = segbuf;
 	bio_set_op_attrs(bio, mode, mode_flags);
@@ -365,10 +354,6 @@ static int nilfs_segbuf_submit_bio(struct nilfs_segment_buffer *segbuf,
 	wi->nr_vecs = min(wi->max_pages, wi->rest_blocks);
 	wi->start = wi->end;
 	return 0;
-
- failed:
-	wi->bio = NULL;
-	return err;
 }
 
 /**
fs/xfs/xfs_buf.c +0 -3
index b45e0d50a405..b7ebcfe6b8d3 100644
@@ -843,9 +843,6 @@ xfs_buf_readahead_map(
 {
 	struct xfs_buf		*bp;
 
-	if (bdi_read_congested(target->bt_bdev->bd_disk->bdi))
-		return;
-
 	xfs_buf_read_map(target, map, nmaps,
 		     XBF_TRYLOCK | XBF_ASYNC | XBF_READ_AHEAD, &bp, ops,
 		     __this_address);
include/linux/backing-dev.h +0 -26
index 860b675c2929..2d764566280c 100644
@@ -135,11 +135,6 @@ static inline bool writeback_in_progress(struct bdi_writeback *wb)
 
 struct backing_dev_info *inode_to_bdi(struct inode *inode);
 
-static inline int wb_congested(struct bdi_writeback *wb, int cong_bits)
-{
-	return wb->congested & cong_bits;
-}
-
 long congestion_wait(int sync, long timeout);
 
 static inline bool mapping_can_writeback(struct address_space *mapping)
@@ -391,27 +386,6 @@ static inline void wb_blkcg_offline(struct blkcg *blkcg)
 
 #endif	/* CONFIG_CGROUP_WRITEBACK */
 
-static inline int bdi_congested(struct backing_dev_info *bdi, int cong_bits)
-{
-	return wb_congested(&bdi->wb, cong_bits);
-}
-
-static inline int bdi_read_congested(struct backing_dev_info *bdi)
-{
-	return bdi_congested(bdi, 1 << WB_sync_congested);
-}
-
-static inline int bdi_write_congested(struct backing_dev_info *bdi)
-{
-	return bdi_congested(bdi, 1 << WB_async_congested);
-}
-
-static inline int bdi_rw_congested(struct backing_dev_info *bdi)
-{
-	return bdi_congested(bdi, (1 << WB_sync_congested) |
-				  (1 << WB_async_congested));
-}
-
 const char *bdi_dev_name(struct backing_dev_info *bdi);
 
 #endif	/* _LINUX_BACKING_DEV_H */
mm/vmscan.c +1 -3
index e38de6456cdc..5e1469887afa 100644
@@ -2364,9 +2364,7 @@ static unsigned int move_pages_to_lru(struct lruvec *lruvec,
  */
 static int current_may_throttle(void)
 {
-	return !(current->flags & PF_LOCAL_THROTTLE) ||
-		current->backing_dev_info == NULL ||
-		bdi_write_congested(current->backing_dev_info);
+	return !(current->flags & PF_LOCAL_THROTTLE);
 }
 
 /*
author
#18 lore raw

PATCH 9/11 f2fs: replace congestion_wait() calls with io_schedule_timeout()

In reply to NeilBrown

As congestion is no longer tracked, congestion_wait() is effectively equivalent to io_schedule_timeout().
So introduce f2fs_io_schedule_timeout() which sets TASK_UNINTERRUPTIBLE and call that instead.

---
 fs/f2fs/compress.c |    4 +---
 fs/f2fs/data.c     |    3 +--
 fs/f2fs/f2fs.h     |    6 ++++++
 fs/f2fs/segment.c  |    8 +++-----
 fs/f2fs/super.c    |    6 ++----
 5 files changed, 13 insertions(+), 14 deletions(-)
fs/f2fs/compress.c +1 -3
index d0c3aeba5945..2f95559025ad 100644
@@ -1505,9 +1505,7 @@ static int f2fs_write_raw_pages(struct compress_ctx *cc,
 				if (IS_NOQUOTA(cc->inode))
 					return 0;
 				ret = 0;
-				cond_resched();
-				congestion_wait(BLK_RW_ASYNC,
-						DEFAULT_IO_TIMEOUT);
+				f2fs_io_schedule_timeout(DEFAULT_IO_TIMEOUT);
 				goto retry_write;
 			}
 			return ret;
fs/f2fs/data.c +1 -2
index 8c417864c66a..d428ddfd42ee 100644
@@ -3047,8 +3047,7 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
 				} else if (ret == -EAGAIN) {
 					ret = 0;
 					if (wbc->sync_mode == WB_SYNC_ALL) {
-						cond_resched();
-						congestion_wait(BLK_RW_ASYNC,
+						f2fs_io_schedule_timeout(
 							DEFAULT_IO_TIMEOUT);
 						goto retry_write;
 					}
fs/f2fs/f2fs.h +6 -0
index 68b44015514f..467f5dbdc7d1 100644
@@ -4426,6 +4426,12 @@ static inline bool f2fs_block_unit_discard(struct f2fs_sb_info *sbi)
 	return F2FS_OPTION(sbi).discard_unit == DISCARD_UNIT_BLOCK;
 }
 
+static inline void f2fs_io_schedule_timeout(long timeout)
+{
+	set_current_state(TASK_UNINTERRUPTIBLE);
+	io_schedule_timeout(timeout);
+}
+
 #define EFSBADCRC	EBADMSG		/* Bad CRC detected */
 #define EFSCORRUPTED	EUCLEAN		/* Filesystem is corrupted */
 
fs/f2fs/segment.c +3 -5
index 1dabc8244083..6ff20da44ad7 100644
@@ -313,8 +313,7 @@ void f2fs_drop_inmem_pages_all(struct f2fs_sb_info *sbi, bool gc_failure)
 skip:
 		iput(inode);
 	}
-	congestion_wait(BLK_RW_ASYNC, DEFAULT_IO_TIMEOUT);
-	cond_resched();
+	f2fs_io_schedule_timeout(DEFAULT_IO_TIMEOUT);
 	if (gc_failure) {
 		if (++looped >= count)
 			return;
@@ -803,8 +802,7 @@ int f2fs_flush_device_cache(struct f2fs_sb_info *sbi)
 		do {
 			ret = __submit_flush_wait(sbi, FDEV(i).bdev);
 			if (ret)
-				congestion_wait(BLK_RW_ASYNC,
-						DEFAULT_IO_TIMEOUT);
+				f2fs_io_schedule_timeout(DEFAULT_IO_TIMEOUT);
 		} while (ret && --count);
 
 		if (ret) {
@@ -3133,7 +3131,7 @@ static unsigned int __issue_discard_cmd_range(struct f2fs_sb_info *sbi,
 			blk_finish_plug(&plug);
 			mutex_unlock(&dcc->cmd_lock);
 			trimmed += __wait_all_discard_cmd(sbi, NULL);
-			congestion_wait(BLK_RW_ASYNC, DEFAULT_IO_TIMEOUT);
+			f2fs_io_schedule_timeout(DEFAULT_IO_TIMEOUT);
 			goto next;
 		}
 skip:
fs/f2fs/super.c +2 -4
index baefd398ec1a..ebd32daf052c 100644
@@ -2135,8 +2135,7 @@ static void f2fs_enable_checkpoint(struct f2fs_sb_info *sbi)
 	/* we should flush all the data to keep data consistency */
 	do {
 		sync_inodes_sb(sbi->sb);
-		cond_resched();
-		congestion_wait(BLK_RW_ASYNC, DEFAULT_IO_TIMEOUT);
+		f2fs_io_schedule_timeout(DEFAULT_IO_TIMEOUT);
 	} while (get_pages(sbi, F2FS_DIRTY_DATA) && retry--);
 
 	if (unlikely(retry < 0))
@@ -2504,8 +2503,7 @@ static ssize_t f2fs_quota_write(struct super_block *sb, int type,
 							&page, &fsdata);
 		if (unlikely(err)) {
 			if (err == -ENOMEM) {
-				congestion_wait(BLK_RW_ASYNC,
-						DEFAULT_IO_TIMEOUT);
+				f2fs_io_schedule_timeout(DEFAULT_IO_TIMEOUT);
 				goto retry;
 			}
 			set_sbi_flag(F2FS_SB(sb), SBI_QUOTA_NEED_REPAIR);
author
#19 lore raw

PATCH 10/11 block/bfq-iosched.c: use "false" rather than "BLK_RW_ASYNC"

In reply to NeilBrown

bfq_get_queue() expects a "bool" for the third arg, so pass "false" rather than "BLK_RW_ASYNC" which will soon be removed.

---
 block/bfq-iosched.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/bfq-iosched.c +1 -1
index 36a66e97e3c2..ed9bb1054bf2 100644
@@ -5448,7 +5448,7 @@ static void bfq_check_ioprio_change(struct bfq_io_cq *bic, struct bio *bio)
 	bfqq = bic_to_bfqq(bic, false);
 	if (bfqq) {
 		bfq_release_process_ref(bfqd, bfqq);
-		bfqq = bfq_get_queue(bfqd, bio, BLK_RW_ASYNC, bic, true);
+		bfqq = bfq_get_queue(bfqd, bio, false, bic, true);
 		bic_set_bfqq(bic, bfqq, false);
 	}
author
#20 lore raw

PATCH 11/11 Remove congestion tracking framework.

In reply to NeilBrown

This framework is no longer used - so discard it.

---
 include/linux/backing-dev-defs.h |    8 -----
 include/linux/backing-dev.h      |    2 -
 include/trace/events/writeback.h |   28 -------------------
 mm/backing-dev.c                 |   57 --------------------------------------
 4 files changed, 95 deletions(-)
include/linux/backing-dev-defs.h +0 -8
index 993c5628a726..e863c88df95f 100644
@@ -207,14 +207,6 @@ struct backing_dev_info {
 #endif
 };
 
-enum {
-	BLK_RW_ASYNC	= 0,
-	BLK_RW_SYNC	= 1,
-};
-
-void clear_bdi_congested(struct backing_dev_info *bdi, int sync);
-void set_bdi_congested(struct backing_dev_info *bdi, int sync);
-
 struct wb_lock_cookie {
 	bool locked;
 	unsigned long flags;
include/linux/backing-dev.h +0 -2
index 2d764566280c..87ce24d238f3 100644
@@ -135,8 +135,6 @@ static inline bool writeback_in_progress(struct bdi_writeback *wb)
 
 struct backing_dev_info *inode_to_bdi(struct inode *inode);
 
-long congestion_wait(int sync, long timeout);
-
 static inline bool mapping_can_writeback(struct address_space *mapping)
 {
 	return inode_to_bdi(mapping->host)->capabilities & BDI_CAP_WRITEBACK;
include/trace/events/writeback.h +0 -28
index a345b1e12daf..86b2a82da546 100644
@@ -735,34 +735,6 @@ TRACE_EVENT(writeback_sb_inodes_requeue,
 	)
 );
 
-DECLARE_EVENT_CLASS(writeback_congest_waited_template,
-
-	TP_PROTO(unsigned int usec_timeout, unsigned int usec_delayed),
-
-	TP_ARGS(usec_timeout, usec_delayed),
-
-	TP_STRUCT__entry(
-		__field(	unsigned int,	usec_timeout	)
-		__field(	unsigned int,	usec_delayed	)
-	),
-
-	TP_fast_assign(
-		__entry->usec_timeout	= usec_timeout;
-		__entry->usec_delayed	= usec_delayed;
-	),
-
-	TP_printk("usec_timeout=%u usec_delayed=%u",
-			__entry->usec_timeout,
-			__entry->usec_delayed)
-);
-
-DEFINE_EVENT(writeback_congest_waited_template, writeback_congestion_wait,
-
-	TP_PROTO(unsigned int usec_timeout, unsigned int usec_delayed),
-
-	TP_ARGS(usec_timeout, usec_delayed)
-);
-
 DECLARE_EVENT_CLASS(writeback_single_inode_template,
 
 	TP_PROTO(struct inode *inode,
mm/backing-dev.c +0 -57

60 lines not on this page · raw message