public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] erofs: avoid unnecessary loops in z_erofs_pcluster_readmore() when read page beyond EOF
@ 2023-07-10  4:25 Chunhai Guo
  2023-07-10  4:40 ` Gao Xiang
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Chunhai Guo @ 2023-07-10  4:25 UTC (permalink / raw)
  To: xiang, chao; +Cc: huyue2, jefflexu, linux-erofs, linux-kernel, Chunhai Guo

z_erofs_pcluster_readmore() may take a long time to loop when the page
offset is large enough, which is unnecessary should be prevented.
For example, when the following case is encountered, it will loop 4691368
times, taking about 27 seconds.
    - offset = 19217289215
    - inode_size = 1442672

Signed-off-by: Chunhai Guo <guochunhai@vivo.com>
---
 fs/erofs/zdata.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c
index 5f1890e309c6..d9a0763f4595 100644
--- a/fs/erofs/zdata.c
+++ b/fs/erofs/zdata.c
@@ -1841,7 +1841,7 @@ static void z_erofs_pcluster_readmore(struct z_erofs_decompress_frontend *f,
 	}
 
 	cur = map->m_la + map->m_llen - 1;
-	while (cur >= end) {
+	while ((cur >= end) && (cur < i_size_read(inode))) {
 		pgoff_t index = cur >> PAGE_SHIFT;
 		struct page *page;
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] erofs: avoid unnecessary loops in z_erofs_pcluster_readmore() when read page beyond EOF
  2023-07-10  4:25 [PATCH] erofs: avoid unnecessary loops in z_erofs_pcluster_readmore() when read page beyond EOF Chunhai Guo
@ 2023-07-10  4:40 ` Gao Xiang
  2023-07-10  7:48 ` Yue Hu
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Gao Xiang @ 2023-07-10  4:40 UTC (permalink / raw)
  To: Chunhai Guo, xiang, chao; +Cc: huyue2, jefflexu, linux-erofs, linux-kernel



On 2023/7/10 12:25, Chunhai Guo wrote:
> z_erofs_pcluster_readmore() may take a long time to loop when the page
> offset is large enough, which is unnecessary should be prevented.
> For example, when the following case is encountered, it will loop 4691368
> times, taking about 27 seconds.
>      - offset = 19217289215
>      - inode_size = 1442672
> 
> Signed-off-by: Chunhai Guo <guochunhai@vivo.com>

It looks good to me,

Fixes: 386292919c25 ("erofs: introduce readmore decompression strategy")
Reviewed-by: Gao Xiang <hsiangkao@linux.alibaba.com>

Thanks,
Gao Xiang

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] erofs: avoid unnecessary loops in z_erofs_pcluster_readmore() when read page beyond EOF
  2023-07-10  4:25 [PATCH] erofs: avoid unnecessary loops in z_erofs_pcluster_readmore() when read page beyond EOF Chunhai Guo
  2023-07-10  4:40 ` Gao Xiang
@ 2023-07-10  7:48 ` Yue Hu
  2023-07-10 10:41 ` Gao Xiang
  2023-07-11 13:56 ` Chao Yu
  3 siblings, 0 replies; 5+ messages in thread
From: Yue Hu @ 2023-07-10  7:48 UTC (permalink / raw)
  To: Chunhai Guo; +Cc: xiang, chao, linux-erofs, linux-kernel, huyue2

On Mon, 10 Jul 2023 12:25:31 +0800
Chunhai Guo <guochunhai@vivo.com> wrote:

> z_erofs_pcluster_readmore() may take a long time to loop when the page
> offset is large enough, which is unnecessary should be prevented.
> For example, when the following case is encountered, it will loop 4691368
> times, taking about 27 seconds.
>     - offset = 19217289215
>     - inode_size = 1442672
> 
> Signed-off-by: Chunhai Guo <guochunhai@vivo.com>
> ---
>  fs/erofs/zdata.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c
> index 5f1890e309c6..d9a0763f4595 100644
> --- a/fs/erofs/zdata.c
> +++ b/fs/erofs/zdata.c
> @@ -1841,7 +1841,7 @@ static void z_erofs_pcluster_readmore(struct z_erofs_decompress_frontend *f,
>  	}
>  
>  	cur = map->m_la + map->m_llen - 1;
> -	while (cur >= end) {
> +	while ((cur >= end) && (cur < i_size_read(inode))) {
>  		pgoff_t index = cur >> PAGE_SHIFT;
>  		struct page *page;
>  

Reviewed-by: Yue Hu <huyue2@coolpad.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] erofs: avoid unnecessary loops in z_erofs_pcluster_readmore() when read page beyond EOF
  2023-07-10  4:25 [PATCH] erofs: avoid unnecessary loops in z_erofs_pcluster_readmore() when read page beyond EOF Chunhai Guo
  2023-07-10  4:40 ` Gao Xiang
  2023-07-10  7:48 ` Yue Hu
@ 2023-07-10 10:41 ` Gao Xiang
  2023-07-11 13:56 ` Chao Yu
  3 siblings, 0 replies; 5+ messages in thread
From: Gao Xiang @ 2023-07-10 10:41 UTC (permalink / raw)
  To: Chunhai Guo, xiang, chao; +Cc: huyue2, jefflexu, linux-erofs, linux-kernel



On 2023/7/10 12:25, Chunhai Guo wrote:
> z_erofs_pcluster_readmore() may take a long time to loop when the page
> offset is large enough, which is unnecessary should be prevented.
> For example, when the following case is encountered, it will loop 4691368
> times, taking about 27 seconds.
>      - offset = 19217289215
>      - inode_size = 1442672
> 
> Signed-off-by: Chunhai Guo <guochunhai@vivo.com>

I will update the subject manually to:
"erofs: avoid useless loops in z_erofs_pcluster_readmore() when reading beyond EOF"

to avoid overly long subject as well...

Thanks,
Gao Xiang

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] erofs: avoid unnecessary loops in z_erofs_pcluster_readmore() when read page beyond EOF
  2023-07-10  4:25 [PATCH] erofs: avoid unnecessary loops in z_erofs_pcluster_readmore() when read page beyond EOF Chunhai Guo
                   ` (2 preceding siblings ...)
  2023-07-10 10:41 ` Gao Xiang
@ 2023-07-11 13:56 ` Chao Yu
  3 siblings, 0 replies; 5+ messages in thread
From: Chao Yu @ 2023-07-11 13:56 UTC (permalink / raw)
  To: Chunhai Guo, xiang; +Cc: huyue2, jefflexu, linux-erofs, linux-kernel

On 2023/7/10 12:25, Chunhai Guo wrote:
> z_erofs_pcluster_readmore() may take a long time to loop when the page
> offset is large enough, which is unnecessary should be prevented.
> For example, when the following case is encountered, it will loop 4691368
> times, taking about 27 seconds.
>      - offset = 19217289215
>      - inode_size = 1442672
> 
> Signed-off-by: Chunhai Guo <guochunhai@vivo.com>

Reviewed-by: Chao Yu <chao@kernel.org>

Thanks,

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-07-11 13:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-10  4:25 [PATCH] erofs: avoid unnecessary loops in z_erofs_pcluster_readmore() when read page beyond EOF Chunhai Guo
2023-07-10  4:40 ` Gao Xiang
2023-07-10  7:48 ` Yue Hu
2023-07-10 10:41 ` Gao Xiang
2023-07-11 13:56 ` Chao Yu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox