f2fs: introduce DEFAULT_IO_TIMEOUT
authorChao Yu <yuchao0@huawei.com>
Mon, 17 Feb 2020 09:45:44 +0000 (17:45 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Thu, 19 Mar 2020 18:41:26 +0000 (11:41 -0700)
As Geert Uytterhoeven reported:

for parameter HZ/50 in congestion_wait(BLK_RW_ASYNC, HZ/50);

On some platforms, HZ can be less than 50, then unexpected 0 timeout
jiffies will be set in congestion_wait().

This patch introduces a macro DEFAULT_IO_TIMEOUT to wrap a determinate
value with msecs_to_jiffies(20) to instead HZ/50 to avoid such issue.

Quoted from Geert Uytterhoeven:

"A timeout of HZ means 1 second.
HZ/50 means 20 ms, but has the risk of being zero, if HZ < 50.

If you want to use a timeout of 20 ms, you best use msecs_to_jiffies(20),
as that takes care of the special cases, and never returns 0."

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/checkpoint.c
fs/f2fs/compress.c
fs/f2fs/data.c
fs/f2fs/f2fs.h
fs/f2fs/gc.c
fs/f2fs/inode.c
fs/f2fs/node.c
fs/f2fs/recovery.c
fs/f2fs/segment.c
fs/f2fs/super.c

index 0dea31f1ddadffcfa3f36dae3234be6faad934a4..46fc9c1542fed87a1c9b039225710aadfb0ffec6 100644 (file)
@@ -1260,7 +1260,7 @@ void f2fs_wait_on_all_pages(struct f2fs_sb_info *sbi, int type)
                if (unlikely(f2fs_cp_error(sbi)))
                        break;
 
-               io_schedule_timeout(HZ/50);
+               io_schedule_timeout(DEFAULT_IO_TIMEOUT);
        }
        finish_wait(&sbi->cp_wait, &wait);
 }
index 5ef7d7cfc0e7e06fc8cc505d2475bc0db4d701cd..748933813cd1fa25d5307278d404d447af9b7f2b 100644 (file)
@@ -988,7 +988,8 @@ retry_write:
                        } else if (ret == -EAGAIN) {
                                ret = 0;
                                cond_resched();
-                               congestion_wait(BLK_RW_ASYNC, HZ/50);
+                               congestion_wait(BLK_RW_ASYNC,
+                                               DEFAULT_IO_TIMEOUT);
                                lock_page(cc->rpages[i]);
                                clear_page_dirty_for_io(cc->rpages[i]);
                                goto retry_write;
index 9fba196bd808c161fd0ed3743c2379251ffb1342..43d705727aa52c7991c64c92f2afd4ef30aa8a25 100644 (file)
@@ -2317,7 +2317,7 @@ retry_encrypt:
                /* flush pending IOs and wait for a while in the ENOMEM case */
                if (PTR_ERR(fio->encrypted_page) == -ENOMEM) {
                        f2fs_flush_merged_writes(fio->sbi);
-                       congestion_wait(BLK_RW_ASYNC, HZ/50);
+                       congestion_wait(BLK_RW_ASYNC, DEFAULT_IO_TIMEOUT);
                        gfp_flags |= __GFP_NOFAIL;
                        goto retry_encrypt;
                }
@@ -2908,7 +2908,7 @@ result:
                                        if (wbc->sync_mode == WB_SYNC_ALL) {
                                                cond_resched();
                                                congestion_wait(BLK_RW_ASYNC,
-                                                               HZ/50);
+                                                       DEFAULT_IO_TIMEOUT);
                                                goto retry_write;
                                        }
                                        goto next;
index ef3ec654862976e99f6aac2ff657f0b0c9a72804..241a87d0d71c1a871ae3a25217074490e9c81f5c 100644 (file)
@@ -558,6 +558,9 @@ enum {
 
 #define DEFAULT_RETRY_IO_COUNT 8       /* maximum retry read IO count */
 
+/* congestion wait timeout value, default: 20ms */
+#define        DEFAULT_IO_TIMEOUT      (msecs_to_jiffies(20))
+
 /* maximum retry quota flush count */
 #define DEFAULT_RETRY_QUOTA_FLUSH_COUNT                8
 
index 0dfdec4926e45fa5e111b306b2d59767c7dc74e6..f6958ae8c157ca1900b0b35276b405881d479602 100644 (file)
@@ -977,7 +977,8 @@ retry:
                if (err) {
                        clear_cold_data(page);
                        if (err == -ENOMEM) {
-                               congestion_wait(BLK_RW_ASYNC, HZ/50);
+                               congestion_wait(BLK_RW_ASYNC,
+                                               DEFAULT_IO_TIMEOUT);
                                goto retry;
                        }
                        if (is_dirty)
index 45aff90af5c51390ed09f2d794bc55943e150b72..44e08bf2e2b436802f0c17bab8651bf9f10a790d 100644 (file)
@@ -535,7 +535,7 @@ retry:
        inode = f2fs_iget(sb, ino);
        if (IS_ERR(inode)) {
                if (PTR_ERR(inode) == -ENOMEM) {
-                       congestion_wait(BLK_RW_ASYNC, HZ/50);
+                       congestion_wait(BLK_RW_ASYNC, DEFAULT_IO_TIMEOUT);
                        goto retry;
                }
        }
index cc2646794130414b77a00c0b62438f682566b40d..aea9915a789753d3b488bf09ac5b253f03b2cd90 100644 (file)
@@ -2599,7 +2599,7 @@ int f2fs_recover_inode_page(struct f2fs_sb_info *sbi, struct page *page)
 retry:
        ipage = f2fs_grab_cache_page(NODE_MAPPING(sbi), ino, false);
        if (!ipage) {
-               congestion_wait(BLK_RW_ASYNC, HZ/50);
+               congestion_wait(BLK_RW_ASYNC, DEFAULT_IO_TIMEOUT);
                goto retry;
        }
 
index 348e8d463b3ec926e059d75f3519d364346c3b21..dd804c07eeb05932825b5c8a6f2939dc962be16e 100644 (file)
@@ -534,7 +534,7 @@ retry_dn:
        err = f2fs_get_dnode_of_data(&dn, start, ALLOC_NODE);
        if (err) {
                if (err == -ENOMEM) {
-                       congestion_wait(BLK_RW_ASYNC, HZ/50);
+                       congestion_wait(BLK_RW_ASYNC, DEFAULT_IO_TIMEOUT);
                        goto retry_dn;
                }
                goto out;
@@ -617,7 +617,8 @@ retry_prev:
                        err = check_index_in_prev_nodes(sbi, dest, &dn);
                        if (err) {
                                if (err == -ENOMEM) {
-                                       congestion_wait(BLK_RW_ASYNC, HZ/50);
+                                       congestion_wait(BLK_RW_ASYNC,
+                                                       DEFAULT_IO_TIMEOUT);
                                        goto retry_prev;
                                }
                                goto err;
index 04156df83e7a01c7979b5549a2f514f9e3e3300a..a2beb0e8144022b435031176fa983370916c46d4 100644 (file)
@@ -245,7 +245,8 @@ retry:
                                                                LOOKUP_NODE);
                        if (err) {
                                if (err == -ENOMEM) {
-                                       congestion_wait(BLK_RW_ASYNC, HZ/50);
+                                       congestion_wait(BLK_RW_ASYNC,
+                                                       DEFAULT_IO_TIMEOUT);
                                        cond_resched();
                                        goto retry;
                                }
@@ -312,7 +313,7 @@ next:
 skip:
                iput(inode);
        }
-       congestion_wait(BLK_RW_ASYNC, HZ/50);
+       congestion_wait(BLK_RW_ASYNC, DEFAULT_IO_TIMEOUT);
        cond_resched();
        if (gc_failure) {
                if (++looped >= count)
@@ -415,7 +416,8 @@ retry:
                        err = f2fs_do_write_data_page(&fio);
                        if (err) {
                                if (err == -ENOMEM) {
-                                       congestion_wait(BLK_RW_ASYNC, HZ/50);
+                                       congestion_wait(BLK_RW_ASYNC,
+                                                       DEFAULT_IO_TIMEOUT);
                                        cond_resched();
                                        goto retry;
                                }
@@ -2801,7 +2803,7 @@ next:
                        blk_finish_plug(&plug);
                        mutex_unlock(&dcc->cmd_lock);
                        trimmed += __wait_all_discard_cmd(sbi, NULL);
-                       congestion_wait(BLK_RW_ASYNC, HZ/50);
+                       congestion_wait(BLK_RW_ASYNC, DEFAULT_IO_TIMEOUT);
                        goto next;
                }
 skip:
index cdcb80f9b3d0c0359146465544bc83632754f7c7..36539afae1e51aefa35abb0d2016164a3fed4114 100644 (file)
@@ -1885,7 +1885,8 @@ repeat:
                page = read_cache_page_gfp(mapping, blkidx, GFP_NOFS);
                if (IS_ERR(page)) {
                        if (PTR_ERR(page) == -ENOMEM) {
-                               congestion_wait(BLK_RW_ASYNC, HZ/50);
+                               congestion_wait(BLK_RW_ASYNC,
+                                               DEFAULT_IO_TIMEOUT);
                                goto repeat;
                        }
                        set_sbi_flag(F2FS_SB(sb), SBI_QUOTA_NEED_REPAIR);
@@ -1939,7 +1940,8 @@ retry:
                                                        &page, NULL);
                if (unlikely(err)) {
                        if (err == -ENOMEM) {
-                               congestion_wait(BLK_RW_ASYNC, HZ/50);
+                               congestion_wait(BLK_RW_ASYNC,
+                                               DEFAULT_IO_TIMEOUT);
                                goto retry;
                        }
                        set_sbi_flag(F2FS_SB(sb), SBI_QUOTA_NEED_REPAIR);