Skip to contentSkip to conversation

xfs: Allow user to kill fstrim process

PATCH In review Lukas Czerner 3 participants 8 messages Apr 27, 2017 – Apr 28, 2017 XFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs: Allow user to kill fstrim process

fstrim can take really long time on big, slow device or on file system with a lots of allocation groups. Currently there is no way for the user to cancell the operation. This patch makes it possible for the user to kill fstrim pocess by adding the check for fatal_signal_pending() in xfs_trim_extents().

---
 fs/xfs/xfs_discard.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
fs/xfs/xfs_discard.c +9 -1
index d796ffa..6a05d27 100644
@@ -132,6 +132,11 @@ xfs_trim_extents(
 		error = xfs_btree_decrement(cur, 0, &i);
 		if (error)
 			goto out_del_cursor;
+
+		if (fatal_signal_pending(current)) {
+			error = -ERESTARTSYS;
+			goto out_del_cursor;
+		}
 	}
 
 out_del_cursor:
@@ -196,8 +201,11 @@ xfs_ioc_trim(
 	for (agno = start_agno; agno <= end_agno; agno++) {
 		error = xfs_trim_extents(mp, agno, start, end, minlen,
 					  &blocks_trimmed);
-		if (error)
+		if (error) {
 			last_error = error;
+			if (error == -ERESTARTSYS)
+				break;
+		}
 	}
 
 	if (last_error)
Signature · 1 line
2.7.4
#1 lore raw
Quoted 5 lines · Lukas Czerner

fstrim can take really long time on big, slow device or on file system with a lots of allocation groups. Currently there is no way for the user to cancell the operation. This patch makes it possible for the user to kill fstrim pocess by adding the check for fatal_signal_pending() in xfs_trim_extents().

With this patch, it seems that if it is killed, then nothing is copied back to the user about the number of blocks trimmed before the kill.

Is that intentional?

I think it could be done in a way that the progress until the kill does get reported, and that might be more useful?

Thanks,
-Eric

Quoted 36 lines
---
 fs/xfs/xfs_discard.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
fs/xfs/xfs_discard.c +9 -1
index d796ffa..6a05d27 100644
@@ -132,6 +132,11 @@ xfs_trim_extents(
 		error = xfs_btree_decrement(cur, 0, &i);
 		if (error)
 			goto out_del_cursor;
+
+		if (fatal_signal_pending(current)) {
+			error = -ERESTARTSYS;
+			goto out_del_cursor;
+		}
 	}
 
 out_del_cursor:
@@ -196,8 +201,11 @@ xfs_ioc_trim(
 	for (agno = start_agno; agno <= end_agno; agno++) {
 		error = xfs_trim_extents(mp, agno, start, end, minlen,
 					  &blocks_trimmed);
-		if (error)
+		if (error) {
 			last_error = error;
+			if (error == -ERESTARTSYS)
+				break;
+		}
 	}
 
 	if (last_error)
#2 lore raw
Quoted 7 lines · Eric Sandeen
Quoted 5 lines · Lukas Czerner

fstrim can take really long time on big, slow device or on file system with a lots of allocation groups. Currently there is no way for the user to cancell the operation. This patch makes it possible for the user to kill fstrim pocess by adding the check for fatal_signal_pending() in xfs_trim_extents().

Quoted 7 lines

With this patch, it seems that if it is killed, then nothing is copied back to the user about the number of blocks trimmed before the kill.

Is that intentional?

I think it could be done in a way that the progress until the kill does get reported, and that might be more useful?

AFAICT ext4 doesn't report anything if somoene ERESTARTSYS's it...

Quoted 10 lines

Thanks,
-Eric

Quoted 6 lines
---
 fs/xfs/xfs_discard.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
Quoted 10 lines

fs/xfs/xfs_discard.c xfs_trim_extents( · line 136

Quoted 10 lines
fs/xfs/xfs_discard.c +2 -0
index d796ffa..6a05d27 100644
@@ -132,6 +132,11 @@ xfs_trim_extents(
 		error = xfs_btree_decrement(cur, 0, &i);
 		if (error)
 			goto out_del_cursor;
+
+		if (fatal_signal_pending(current)) {

...but the process isn't going to be around to care anyway, right?

--D

Quoted 24 lines
Quoted 10 lines
fs/xfs/xfs_discard.c +3 -0
+			error = -ERESTARTSYS;
+			goto out_del_cursor;
+		}
 	}
 
 out_del_cursor:
@@ -196,8 +201,11 @@ xfs_ioc_trim(
 	for (agno = start_agno; agno <= end_agno; agno++) {
 		error = xfs_trim_extents(mp, agno, start, end, minlen,

fs/xfs/xfs_discard.c xfs_ioc_trim( · line 211

Quoted 10 lines
fs/xfs/xfs_discard.c +4 -1
 					  &blocks_trimmed);
-		if (error)
+		if (error) {
 			last_error = error;
+			if (error == -ERESTARTSYS)
+				break;
+		}
 	}
 
 	if (last_error)

--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw
Quoted 11 lines · Darrick J. Wong
Quoted 10 lines · Eric Sandeen
Quoted 5 lines · Lukas Czerner

fstrim can take really long time on big, slow device or on file system with a lots of allocation groups. Currently there is no way for the user to cancell the operation. This patch makes it possible for the user to kill fstrim pocess by adding the check for fatal_signal_pending() in xfs_trim_extents().

With this patch, it seems that if it is killed, then nothing is copied back to the user about the number of blocks trimmed before the kill.

Quoted 6 lines
Quoted 4 lines

Is that intentional?

I think it could be done in a way that the progress until the kill does get reported, and that might be more useful?

AFAICT ext4 doesn't report anything if somoene ERESTARTSYS's it...

Well we aren't ext4, are we? ;)

actually, it seems that it may report "count" as ERESTARTSYS in:

ext4_debug("trimmed %d blocks in the group %d\n",
count, group);

But yeah, although it does update the &range values, they don't get copied out on any error.

Anyway, ok, ext4 doesn't. Is there a reason that we shouldn't?

Thanks,
-Eric

Quoted 50 lines
Quoted 10 lines

Thanks,
-Eric

Quoted 6 lines
---
 fs/xfs/xfs_discard.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
Quoted 10 lines

fs/xfs/xfs_discard.c xfs_trim_extents( · line 136

Quoted 10 lines
fs/xfs/xfs_discard.c +2 -0
index d796ffa..6a05d27 100644
@@ -132,6 +132,11 @@ xfs_trim_extents(
 		error = xfs_btree_decrement(cur, 0, &i);
 		if (error)
 			goto out_del_cursor;
+
+		if (fatal_signal_pending(current)) {

...but the process isn't going to be around to care anyway, right?

--D

Quoted 24 lines
Quoted 10 lines
fs/xfs/xfs_discard.c +3 -0
+			error = -ERESTARTSYS;
+			goto out_del_cursor;
+		}
 	}
 
 out_del_cursor:
@@ -196,8 +201,11 @@ xfs_ioc_trim(
 	for (agno = start_agno; agno <= end_agno; agno++) {
 		error = xfs_trim_extents(mp, agno, start, end, minlen,

fs/xfs/xfs_discard.c xfs_ioc_trim( · line 211

Quoted 10 lines
fs/xfs/xfs_discard.c +4 -1
 					  &blocks_trimmed);
-		if (error)
+		if (error) {
 			last_error = error;
+			if (error == -ERESTARTSYS)
+				break;
+		}
 	}
 
 	if (last_error)

--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw
Quoted 23 lines · Eric Sandeen
Quoted 11 lines · Darrick J. Wong
Quoted 10 lines · Eric Sandeen
Quoted 5 lines · Lukas Czerner

fstrim can take really long time on big, slow device or on file system with a lots of allocation groups. Currently there is no way for the user to cancell the operation. This patch makes it possible for the user to kill fstrim pocess by adding the check for fatal_signal_pending() in xfs_trim_extents().

With this patch, it seems that if it is killed, then nothing is copied back to the user about the number of blocks trimmed before the kill.

Quoted 6 lines
Quoted 4 lines

Is that intentional?

I think it could be done in a way that the progress until the kill does get reported, and that might be more useful?

AFAICT ext4 doesn't report anything if somoene ERESTARTSYS's it...

Well we aren't ext4, are we? ;)

actually, it seems that it may report "count" as ERESTARTSYS in:

Quoted 7 lines

ext4_debug("trimmed %d blocks in the group %d\n",
count, group);

But yeah, although it does update the &range values, they don't get copied out on any error.

Anyway, ok, ext4 doesn't. Is there a reason that we shouldn't?

Ok I am probably misunderstanding how things work, maybe it's not actually possible (he says after a little experimentation.) Feel free to ignore me on this one. :)

-Eric

#5 lore raw
Quoted 30 lines · Eric Sandeen
Quoted 29 lines · Eric Sandeen
Quoted 11 lines · Darrick J. Wong
Quoted 10 lines · Eric Sandeen
Quoted 5 lines · Lukas Czerner

fstrim can take really long time on big, slow device or on file system with a lots of allocation groups. Currently there is no way for the user to cancell the operation. This patch makes it possible for the user to kill fstrim pocess by adding the check for fatal_signal_pending() in xfs_trim_extents().

With this patch, it seems that if it is killed, then nothing is copied back to the user about the number of blocks trimmed before the kill.

Quoted 6 lines
Quoted 4 lines

Is that intentional?

I think it could be done in a way that the progress until the kill does get reported, and that might be more useful?

AFAICT ext4 doesn't report anything if somoene ERESTARTSYS's it...

Well we aren't ext4, are we? ;)

actually, it seems that it may report "count" as ERESTARTSYS in:

ext4_debug("trimmed %d blocks in the group %d\n",
count, group);

But yeah, although it does update the &range values, they don't get copied out on any error.

Quoted 7 lines
Quoted 1 line

Anyway, ok, ext4 doesn't. Is there a reason that we shouldn't?

Ok I am probably misunderstanding how things work, maybe it's not actually possible (he says after a little experimentation.) Feel free to ignore me on this one. :)

-Eric

Hi Eric,

I agree with Darrick, at the moment fstrim is not sticikng around to care, I am not even sure if it can stick around to care.

Thanks!
-Lukas

Reviewed-by on v1 1/1
#6 lore raw
In reply to Lukas Czerner
Quoted 8 lines · Lukas Czerner

fstrim can take really long time on big, slow device or on file system with a lots of allocation groups. Currently there is no way for the user to cancell the operation. This patch makes it possible for the user to kill fstrim pocess by adding the check for fatal_signal_pending() in xfs_trim_extents().

Sorry for the detour while I got confused about signals. ;)

This looks ok to me. Thanks!

Quoted 34 lines
---
 fs/xfs/xfs_discard.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
fs/xfs/xfs_discard.c +9 -1
index d796ffa..6a05d27 100644
@@ -132,6 +132,11 @@ xfs_trim_extents(
 		error = xfs_btree_decrement(cur, 0, &i);
 		if (error)
 			goto out_del_cursor;
+
+		if (fatal_signal_pending(current)) {
+			error = -ERESTARTSYS;
+			goto out_del_cursor;
+		}
 	}
 
 out_del_cursor:
@@ -196,8 +201,11 @@ xfs_ioc_trim(
 	for (agno = start_agno; agno <= end_agno; agno++) {
 		error = xfs_trim_extents(mp, agno, start, end, minlen,
 					  &blocks_trimmed);
-		if (error)
+		if (error) {
 			last_error = error;
+			if (error == -ERESTARTSYS)
+				break;
+		}
 	}
 
 	if (last_error)
Reviewed-by on v1 1/1
#7 lore raw
In reply to Lukas Czerner
Quoted 8 lines · Lukas Czerner

fstrim can take really long time on big, slow device or on file system with a lots of allocation groups. Currently there is no way for the user to cancell the operation. This patch makes it possible for the user to kill fstrim pocess by adding the check for fatal_signal_pending() in xfs_trim_extents().

Looks ok,

--D

Quoted 40 lines
---
 fs/xfs/xfs_discard.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
fs/xfs/xfs_discard.c +9 -1
index d796ffa..6a05d27 100644
@@ -132,6 +132,11 @@ xfs_trim_extents(
 		error = xfs_btree_decrement(cur, 0, &i);
 		if (error)
 			goto out_del_cursor;
+
+		if (fatal_signal_pending(current)) {
+			error = -ERESTARTSYS;
+			goto out_del_cursor;
+		}
 	}
 
 out_del_cursor:
@@ -196,8 +201,11 @@ xfs_ioc_trim(
 	for (agno = start_agno; agno <= end_agno; agno++) {
 		error = xfs_trim_extents(mp, agno, start, end, minlen,
 					  &blocks_trimmed);
-		if (error)
+		if (error) {
 			last_error = error;
+			if (error == -ERESTARTSYS)
+				break;
+		}
 	}
 
 	if (last_error)
Signature · 6 lines
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html