All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/4] fsx: fix infinite/too long loops when generating ranges for clone operations
@ 2020-04-20 17:09 fdmanana
  0 siblings, 0 replies; 3+ messages in thread
From: fdmanana @ 2020-04-20 17:09 UTC (permalink / raw)
  To: fstests; +Cc: linux-btrfs, Filipe Manana

From: Filipe Manana <fdmanana@suse.com>

While running generic/457 I've had fsx taking a lot of CPU time and not
making any progress for over an hour. Attaching gdb to the fsx process
revealed that fsx was in the loop that generates the ranges for a clone
operation, in particular the loop seemed to never end because the range
defined by 'offset2' kept overlapping with the range defined by 'offset'.
So far this happened two times in one of my test VMs with generic/457.

Fix this by breaking out of the loop after trying 30 times, like we
currently do for dedupe operations, which results in logging the operation
as skipped.

Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
---
 ltp/fsx.c | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/ltp/fsx.c b/ltp/fsx.c
index 56479eda..ab64b50a 100644
--- a/ltp/fsx.c
+++ b/ltp/fsx.c
@@ -2013,16 +2013,24 @@ test(void)
 			keep_size = random() % 2;
 		break;
 	case OP_CLONE_RANGE:
-		TRIM_OFF_LEN(offset, size, file_size);
-		offset = offset & ~(block_size - 1);
-		size = size & ~(block_size - 1);
-		do {
-			offset2 = random();
-			TRIM_OFF(offset2, maxfilelen);
-			offset2 = offset2 & ~(block_size - 1);
-		} while (range_overlaps(offset, offset2, size) ||
-			 offset2 + size > maxfilelen);
-		break;
+		{
+			int tries = 0;
+
+			TRIM_OFF_LEN(offset, size, file_size);
+			offset = offset & ~(block_size - 1);
+			size = size & ~(block_size - 1);
+			do {
+				if (tries++ >= 30) {
+					size = 0;
+					break;
+				}
+				offset2 = random();
+				TRIM_OFF(offset2, maxfilelen);
+				offset2 = offset2 & ~(block_size - 1);
+			} while (range_overlaps(offset, offset2, size) ||
+				 offset2 + size > maxfilelen);
+			break;
+		}
 	case OP_DEDUPE_RANGE:
 		{
 			int tries = 0;
-- 
2.11.0


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

* Re: [PATCH 2/4] fsx: fix infinite/too long loops when generating ranges for clone operations
  2020-04-08 10:36 fdmanana
@ 2020-04-17 17:10 ` Brian Foster
  0 siblings, 0 replies; 3+ messages in thread
From: Brian Foster @ 2020-04-17 17:10 UTC (permalink / raw)
  To: fdmanana; +Cc: fstests, linux-btrfs, Filipe Manana

On Wed, Apr 08, 2020 at 11:36:04AM +0100, fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
> 
> While running generic/457 I've had fsx taking a lot of CPU time and not
> making any progress for over an hour. Attaching gdb to the fsx process
> revealed that fsx was in the loop that generates the ranges for a clone
> operation, in particular the loop seemed to never end because the range
> defined by 'offset2' kept overlapping with the range defined by 'offset'.
> So far this happened two times in one of my test VMs with generic/457.
> 
> Fix this by breaking out of the loop after trying 30 times, like we
> currently do for dedupe operations, which results in logging the operation
> as skipped.
> 
> Signed-off-by: Filipe Manana <fdmanana@suse.com>
> ---

Reviewed-by: Brian Foster <bfoster@redhat.com>

>  ltp/fsx.c | 28 ++++++++++++++++++----------
>  1 file changed, 18 insertions(+), 10 deletions(-)
> 
> diff --git a/ltp/fsx.c b/ltp/fsx.c
> index fa383c94..5949ebf0 100644
> --- a/ltp/fsx.c
> +++ b/ltp/fsx.c
> @@ -2004,16 +2004,24 @@ test(void)
>  			keep_size = random() % 2;
>  		break;
>  	case OP_CLONE_RANGE:
> -		TRIM_OFF_LEN(offset, size, file_size);
> -		offset = offset & ~(block_size - 1);
> -		size = size & ~(block_size - 1);
> -		do {
> -			offset2 = random();
> -			TRIM_OFF(offset2, maxfilelen);
> -			offset2 = offset2 & ~(block_size - 1);
> -		} while (range_overlaps(offset, offset2, size) ||
> -			 offset2 + size > maxfilelen);
> -		break;
> +		{
> +			int tries = 0;
> +
> +			TRIM_OFF_LEN(offset, size, file_size);
> +			offset = offset & ~(block_size - 1);
> +			size = size & ~(block_size - 1);
> +			do {
> +				if (tries++ >= 30) {
> +					size = 0;
> +					break;
> +				}
> +				offset2 = random();
> +				TRIM_OFF(offset2, maxfilelen);
> +				offset2 = offset2 & ~(block_size - 1);
> +			} while (range_overlaps(offset, offset2, size) ||
> +				 offset2 + size > maxfilelen);
> +			break;
> +		}
>  	case OP_DEDUPE_RANGE:
>  		{
>  			int tries = 0;
> -- 
> 2.11.0
> 


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

* [PATCH 2/4] fsx: fix infinite/too long loops when generating ranges for clone operations
@ 2020-04-08 10:36 fdmanana
  2020-04-17 17:10 ` Brian Foster
  0 siblings, 1 reply; 3+ messages in thread
From: fdmanana @ 2020-04-08 10:36 UTC (permalink / raw)
  To: fstests; +Cc: linux-btrfs, Filipe Manana

From: Filipe Manana <fdmanana@suse.com>

While running generic/457 I've had fsx taking a lot of CPU time and not
making any progress for over an hour. Attaching gdb to the fsx process
revealed that fsx was in the loop that generates the ranges for a clone
operation, in particular the loop seemed to never end because the range
defined by 'offset2' kept overlapping with the range defined by 'offset'.
So far this happened two times in one of my test VMs with generic/457.

Fix this by breaking out of the loop after trying 30 times, like we
currently do for dedupe operations, which results in logging the operation
as skipped.

Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
 ltp/fsx.c | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/ltp/fsx.c b/ltp/fsx.c
index fa383c94..5949ebf0 100644
--- a/ltp/fsx.c
+++ b/ltp/fsx.c
@@ -2004,16 +2004,24 @@ test(void)
 			keep_size = random() % 2;
 		break;
 	case OP_CLONE_RANGE:
-		TRIM_OFF_LEN(offset, size, file_size);
-		offset = offset & ~(block_size - 1);
-		size = size & ~(block_size - 1);
-		do {
-			offset2 = random();
-			TRIM_OFF(offset2, maxfilelen);
-			offset2 = offset2 & ~(block_size - 1);
-		} while (range_overlaps(offset, offset2, size) ||
-			 offset2 + size > maxfilelen);
-		break;
+		{
+			int tries = 0;
+
+			TRIM_OFF_LEN(offset, size, file_size);
+			offset = offset & ~(block_size - 1);
+			size = size & ~(block_size - 1);
+			do {
+				if (tries++ >= 30) {
+					size = 0;
+					break;
+				}
+				offset2 = random();
+				TRIM_OFF(offset2, maxfilelen);
+				offset2 = offset2 & ~(block_size - 1);
+			} while (range_overlaps(offset, offset2, size) ||
+				 offset2 + size > maxfilelen);
+			break;
+		}
 	case OP_DEDUPE_RANGE:
 		{
 			int tries = 0;
-- 
2.11.0


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

end of thread, other threads:[~2020-04-20 17:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-20 17:09 [PATCH 2/4] fsx: fix infinite/too long loops when generating ranges for clone operations fdmanana
  -- strict thread matches above, loose matches on Subject: below --
2020-04-08 10:36 fdmanana
2020-04-17 17:10 ` Brian Foster

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.