Whamcloud - gitweb
LU-12518 llite: fix stride window increase 93/35893/5
authorWang Shilong <wshilong@ddn.com>
Fri, 23 Aug 2019 06:17:41 +0000 (14:17 +0800)
committerOleg Drokin <green@whamcloud.com>
Fri, 14 Feb 2020 05:50:13 +0000 (05:50 +0000)
Fix following problems:

1. stride_byte_count() argument @off should be @windows_start
rather than @stride_offset to calculate stride bytes.

2. In a limited memory client(for testing etc), we could possibly
have ra_rpc_size(64M) initially > ra_max_pages_per_file, this will
make possibly @window_len 0 after ras_increase_window()

3. @window_len in ras_stride_increase_window() could be negative,
be carefully to avoid overflow.

Change-Id: Ied00bec834d4bb0ad04b688c10a03bbcd667f39b
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-on: https://review.whamcloud.com/35893
Tested-by: jenkins <devops@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Bobi Jam <bobijam@hotmail.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/llite/rw.c

index 23093e1..7d5453f 100644 (file)
@@ -843,7 +843,7 @@ stride_page_count(struct ll_readahead_state *ras, loff_t len)
        loff_t bytes_count =
                stride_byte_count(ras->ras_stride_offset,
                                  ras->ras_stride_length, ras->ras_stride_bytes,
        loff_t bytes_count =
                stride_byte_count(ras->ras_stride_offset,
                                  ras->ras_stride_length, ras->ras_stride_bytes,
-                                 ras->ras_stride_offset, len);
+                                 ras->ras_window_start_idx << PAGE_SHIFT, len);
 
        return (bytes_count + PAGE_SIZE - 1) >> PAGE_SHIFT;
 }
 
        return (bytes_count + PAGE_SIZE - 1) >> PAGE_SHIFT;
 }
@@ -874,23 +874,33 @@ static void ras_stride_increase_window(struct ll_readahead_state *ras,
                stride_bytes = end - ras->ras_stride_offset;
 
        div64_u64_rem(stride_bytes, ras->ras_stride_length, &left_bytes);
                stride_bytes = end - ras->ras_stride_offset;
 
        div64_u64_rem(stride_bytes, ras->ras_stride_length, &left_bytes);
-       window_bytes = ((loff_t)ras->ras_window_pages << PAGE_SHIFT) -
-               left_bytes;
-
-       if (left_bytes < ras->ras_stride_bytes)
-               left_bytes += inc_bytes;
-       else
-               left_bytes = ras->ras_stride_bytes + inc_bytes;
+       window_bytes = (ras->ras_window_pages << PAGE_SHIFT);
+       if (left_bytes < ras->ras_stride_bytes) {
+               if (ras->ras_stride_bytes - left_bytes >= inc_bytes) {
+                       window_bytes += inc_bytes;
+                       goto out;
+               } else {
+                       window_bytes += (ras->ras_stride_bytes - left_bytes);
+                       inc_bytes -= (ras->ras_stride_bytes - left_bytes);
+               }
+       } else {
+               window_bytes += (ras->ras_stride_length - left_bytes);
+       }
 
        LASSERT(ras->ras_stride_bytes != 0);
 
 
        LASSERT(ras->ras_stride_bytes != 0);
 
-       step = div64_u64_rem(left_bytes, ras->ras_stride_bytes, &left_bytes);
+       step = div64_u64_rem(inc_bytes, ras->ras_stride_bytes, &left_bytes);
 
        window_bytes += step * ras->ras_stride_length + left_bytes;
 
        window_bytes += step * ras->ras_stride_length + left_bytes;
+       LASSERT(window_bytes > 0);
 
 
-       if (stride_page_count(ras, window_bytes) <= ra->ra_max_pages_per_file)
+out:
+       if (stride_page_count(ras, window_bytes) <=
+           ra->ra_max_pages_per_file || ras->ras_window_pages == 0)
                ras->ras_window_pages = (window_bytes >> PAGE_SHIFT);
 
                ras->ras_window_pages = (window_bytes >> PAGE_SHIFT);
 
+       LASSERT(ras->ras_window_pages > 0);
+
        RAS_CDEBUG(ras);
 }
 
        RAS_CDEBUG(ras);
 }