Skip to contentSkip to conversation

generic/446: make sure all background processes are dead before umount

PATCH Superseded Eryu Guan 2 participants 8 messages Jul 24, 2017 – Jul 27, 2017

lore
Share & tools
lore

Eryu Guan

author
#0 lore raw

PATCH 1/1 generic/446: make sure all background processes are dead before umount

The $dread_pid refers to the while-true-do loop, wait for $dread_pid doesn't mean the xfs_io direct read process is already dead, sometimes xfs_io process is still running and blocking _scratch_unmount.

Fix it by making the direct read does a fixed number of loop and break out the second mmap-fpunch loop if the first loop exits. At this point we're sure that there's no unfinished background process blocking the umount.

---
 tests/generic/446 | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
tests/generic/446 +5 -3
index 62ae449de6b1..83ff4ac9edd3 100755
@@ -61,20 +61,22 @@ filesz=$((65536 * 2))
 $XFS_IO_PROG -f -c "truncate $((filesz * 2))" $SCRATCH_MNT/file >> $seqres.full
 
 # run a background dio read to a hole in a loop
-while true; do
+for i in `seq 0 999`; do
 	$XFS_IO_PROG -d -c "pread 0 $filesz" $SCRATCH_MNT/file > /dev/null 2>&1
 done &
 
 dread_pid=$!
 
 # run mapped write to the same hole as dio read
-for i in `seq 0 999`; do
+while true; do
 	$XFS_IO_PROG -c "mmap 0 $filesz" -c "mwrite 0 $filesz" $SCRATCH_MNT/file \
 		> /dev/null
 	$XFS_IO_PROG -c "fpunch 0 $filesz" $SCRATCH_MNT/file > /dev/null
+	if ! kill -s 0 $dread_pid >/dev/null 2>&1; then
+		break
+	fi
 done
 
-kill -9 $dread_pid > /dev/null 2>&1
 wait $dread_pid > /dev/null 2>&1
 
 echo "Silence is golden"
Signature · 1 line
2.13.3
#1 lore raw
Quoted 4 lines · Eryu Guan

The $dread_pid refers to the while-true-do loop, wait for $dread_pid doesn't mean the xfs_io direct read process is already dead, sometimes xfs_io process is still running and blocking _scratch_unmount.

Hi Eryu,

Could you tell me what can i do to trigger this block?

Quoted 2 lines

Fix it by making the direct read does a fixed number of loop and break out the second mmap-fpunch loop if the first loop exits. At

Does it break out the second mmap-fpunch loop if the first loop doesn't exit?

Quoted 2 lines

this point we're sure that there's no unfinished background process blocking the umount.

The others look fine.

Thanks,
Xiao Yang.

Quoted 35 lines
---
 tests/generic/446 | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
tests/generic/446 +5 -3
index 62ae449de6b1..83ff4ac9edd3 100755
@@ -61,20 +61,22 @@ filesz=$((65536 * 2))
 $XFS_IO_PROG -f -c "truncate $((filesz * 2))" $SCRATCH_MNT/file >> $seqres.full
 
 # run a background dio read to a hole in a loop
-while true; do
+for i in `seq 0 999`; do
 	$XFS_IO_PROG -d -c "pread 0 $filesz" $SCRATCH_MNT/file > /dev/null 2>&1
 done &
 
 dread_pid=$!
 
 # run mapped write to the same hole as dio read
-for i in `seq 0 999`; do
+while true; do
 	$XFS_IO_PROG -c "mmap 0 $filesz" -c "mwrite 0 $filesz" $SCRATCH_MNT/file \
 		> /dev/null
 	$XFS_IO_PROG -c "fpunch 0 $filesz" $SCRATCH_MNT/file > /dev/null
+	if ! kill -s 0 $dread_pid >/dev/null 2>&1; then
+		break
+	fi
 done
 
-kill -9 $dread_pid > /dev/null 2>&1
 wait $dread_pid > /dev/null 2>&1
 
 echo "Silence is golden"
author
#2 lore raw
Quoted 8 lines · Xiao Yang
Quoted 4 lines · Eryu Guan

The $dread_pid refers to the while-true-do loop, wait for $dread_pid doesn't mean the xfs_io direct read process is already dead, sometimes xfs_io process is still running and blocking _scratch_unmount.

Hi Eryu,

Could you tell me what can i do to trigger this block?

I don't have a reliable reproducer, I hit this in my automated tests, perhaps easier to hit with slow disks. You can try replace the fpunch operation with a pwrite, I can hit the block much easier this way.

Quoted 5 lines
Quoted 2 lines

Fix it by making the direct read does a fixed number of loop and break out the second mmap-fpunch loop if the first loop exits. At

Does it break out the second mmap-fpunch loop if the first loop doesn't exit?

The second mmap-fpunch loop won't break until it finds the first loop exits.

Quoted 5 lines
Quoted 3 lines

this point we're sure that there's no unfinished background process blocking the umount.

The others look fine.

Thanks!

Eryu

Quoted 41 lines

Thanks,
Xiao Yang.

Quoted 35 lines
---
 tests/generic/446 | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
tests/generic/446 +5 -3
index 62ae449de6b1..83ff4ac9edd3 100755
@@ -61,20 +61,22 @@ filesz=$((65536 * 2))
 $XFS_IO_PROG -f -c "truncate $((filesz * 2))" $SCRATCH_MNT/file >> $seqres.full
 
 # run a background dio read to a hole in a loop
-while true; do
+for i in `seq 0 999`; do
 	$XFS_IO_PROG -d -c "pread 0 $filesz" $SCRATCH_MNT/file > /dev/null 2>&1
 done &
 
 dread_pid=$!
 
 # run mapped write to the same hole as dio read
-for i in `seq 0 999`; do
+while true; do
 	$XFS_IO_PROG -c "mmap 0 $filesz" -c "mwrite 0 $filesz" $SCRATCH_MNT/file \
 		> /dev/null
 	$XFS_IO_PROG -c "fpunch 0 $filesz" $SCRATCH_MNT/file > /dev/null
+	if ! kill -s 0 $dread_pid >/dev/null 2>&1; then
+		break
+	fi
 done
 
-kill -9 $dread_pid > /dev/null 2>&1
 wait $dread_pid > /dev/null 2>&1
 
 echo "Silence is golden"
#3 lore raw
Quoted 6 lines · Eryu Guan
Quoted 5 lines · Xiao Yang
Quoted 4 lines · Eryu Guan

The $dread_pid refers to the while-true-do loop, wait for $dread_pid doesn't mean the xfs_io direct read process is already dead, sometimes xfs_io process is still running and blocking _scratch_unmount.

Quoted 6 lines
Quoted 3 lines

Hi Eryu,

Could you tell me what can i do to trigger this block?

I don't have a reliable reproducer, I hit this in my automated tests, perhaps easier to hit with slow disks. You can try replace the fpunch operation with a pwrite, I can hit the block much easier this way.

Hi Eryu,

Thanks for your explanation. I can hit this block easily when replacing the fpunch operation with a pwrite.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

Fix it by making the direct read does a fixed number of loop and break out the second mmap-fpunch loop if the first loop exits. At

Does it break out the second mmap-fpunch loop if the first loop doesn't exit?

The second mmap-fpunch loop won't break until it finds the first loop exits.

got it. :-)

Quoted 29 lines
Quoted 3 lines
Quoted 2 lines

this point we're sure that there's no unfinished background process blocking the umount.

The others look fine.

Thanks!

Eryu

Quoted 22 lines

Thanks,
Xiao Yang.

Quoted 20 lines
---
  tests/generic/446 | 8 +++++---
  1 file changed, 5 insertions(+), 3 deletions(-)
tests/generic/446 +1 -1
index 62ae449de6b1..83ff4ac9edd3 100755
@@ -61,20 +61,22 @@ filesz=$((65536 * 2))
  $XFS_IO_PROG -f -c "truncate $((filesz * 2))" $SCRATCH_MNT/file>>  $seqres.full
 
  # run a background dio read to a hole in a loop
-while true; do
+for i in `seq 0 999`; do
  	$XFS_IO_PROG -d -c "pread 0 $filesz" $SCRATCH_MNT/file>  /dev/null 2>&1
  done&
 
  dread_pid=$!
 
Quoted 10 lines
Quoted 10 lines

tests/generic/446 filesz=$((65536 * 2)) · line 78

Quoted 10 lines
tests/generic/446 +4 -1
  # run mapped write to the same hole as dio read
-for i in `seq 0 999`; do
+while true; do
  	$XFS_IO_PROG -c "mmap 0 $filesz" -c "mwrite 0 $filesz" $SCRATCH_MNT/file \
  		>  /dev/null
  	$XFS_IO_PROG -c "fpunch 0 $filesz" $SCRATCH_MNT/file>  /dev/null
+	if ! kill -s 0 $dread_pid>/dev/null 2>&1; then
+		break
+	fi
  done

Could we simplify this break, as below:
while kill -s 0 $dread_pid >/dev/null 2>&1; do
$XFS_IO_PROG -c "mmap 0 $filesz" -c "mwrite 0 $filesz"
$SCRATCH_MNT/file \

Quoted 1 line

/dev/null

$XFS_IO_PROG -c "fpunch 0 $filesz" $SCRATCH_MNT/file > /dev/null
done

Thanks,
Xiao Yang.

Quoted 10 lines
Quoted 7 lines

tests/generic/446 filesz=$((65536 * 2)) · line 82

Quoted 5 lines
tests/generic/446 +0 -1
-kill -9 $dread_pid>  /dev/null 2>&1
  wait $dread_pid>  /dev/null 2>&1
 
  echo "Silence is golden"

.

author
#4 lore raw
Quoted 14 lines · Xiao Yang
Quoted 10 lines
Quoted 10 lines

tests/generic/446 filesz=$((65536 * 2)) · line 78

Quoted 10 lines
  # run mapped write to the same hole as dio read
tests/generic/446 +4 -1
-for i in `seq 0 999`; do
+while true; do
  	$XFS_IO_PROG -c "mmap 0 $filesz" -c "mwrite 0 $filesz" $SCRATCH_MNT/file \
  		>  /dev/null
  	$XFS_IO_PROG -c "fpunch 0 $filesz" $SCRATCH_MNT/file>  /dev/null
+	if ! kill -s 0 $dread_pid>/dev/null 2>&1; then
+		break
+	fi
  done

Could we simplify this break, as below:
while kill -s 0 $dread_pid >/dev/null 2>&1; do
$XFS_IO_PROG -c "mmap 0 $filesz" -c "mwrite 0 $filesz" $SCRATCH_MNT/file
\

Quoted 3 lines
Quoted 1 line

/dev/null

$XFS_IO_PROG -c "fpunch 0 $filesz" $SCRATCH_MNT/file > /dev/null
done

This looks better, thanks! I'll send v2.

Eryu

author
#5 lore raw

PATCH v2 1/1 generic/446: make sure all background processes are dead before umount

In reply to Eryu Guan

The $dread_pid refers to the while-true-do loop, wait for $dread_pid doesn't mean the xfs_io direct read process is already dead, sometimes xfs_io process is still running and blocking _scratch_unmount.

Fix it by making the direct read does a fixed number of loop and break out the second mmap-fpunch loop if the first loop exits. At this point we're sure that there's no unfinished background process blocking the umount.

---
v2:
- move 'kill' to while loop condition to simplify the second loop
- add more comments about when to exit the loop

 tests/generic/446 | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tests/generic/446 +3 -3
index 62ae449de6b1..6a1b69aa2edc 100755
@@ -61,20 +61,20 @@ filesz=$((65536 * 2))
 $XFS_IO_PROG -f -c "truncate $((filesz * 2))" $SCRATCH_MNT/file >> $seqres.full
 
 # run a background dio read to a hole in a loop
-while true; do
+for i in `seq 0 999`; do
 	$XFS_IO_PROG -d -c "pread 0 $filesz" $SCRATCH_MNT/file > /dev/null 2>&1
 done &
 
 dread_pid=$!
 
 # run mapped write to the same hole as dio read
-for i in `seq 0 999`; do
+# loop until background dio read exits
+while kill -s 0 $dread_pid >/dev/null 2>&1; do
 	$XFS_IO_PROG -c "mmap 0 $filesz" -c "mwrite 0 $filesz" $SCRATCH_MNT/file \
 		> /dev/null
 	$XFS_IO_PROG -c "fpunch 0 $filesz" $SCRATCH_MNT/file > /dev/null
 done
 
-kill -9 $dread_pid > /dev/null 2>&1
 wait $dread_pid > /dev/null 2>&1
 
 echo "Silence is golden"
Signature · 1 line
2.13.3
author
#6 lore raw

Hi Xiao Yang,

Quoted 10 lines · Eryu Guan

The $dread_pid refers to the while-true-do loop, wait for $dread_pid doesn't mean the xfs_io direct read process is already dead, sometimes xfs_io process is still running and blocking _scratch_unmount.

Fix it by making the direct read does a fixed number of loop and break out the second mmap-fpunch loop if the first loop exits. At this point we're sure that there's no unfinished background process blocking the umount.

Quoted 5 lines

---
v2:
- move 'kill' to while loop condition to simplify the second loop
- add more comments about when to exit the loop

Would you please help test & review and provide reviewed-by tag if you think it's OK? Thanks a lot!

Eryu

Quoted 35 lines
 tests/generic/446 | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tests/generic/446 +3 -3
index 62ae449de6b1..6a1b69aa2edc 100755
@@ -61,20 +61,20 @@ filesz=$((65536 * 2))
 $XFS_IO_PROG -f -c "truncate $((filesz * 2))" $SCRATCH_MNT/file >> $seqres.full
 
 # run a background dio read to a hole in a loop
-while true; do
+for i in `seq 0 999`; do
 	$XFS_IO_PROG -d -c "pread 0 $filesz" $SCRATCH_MNT/file > /dev/null 2>&1
 done &
 
 dread_pid=$!
 
 # run mapped write to the same hole as dio read
-for i in `seq 0 999`; do
+# loop until background dio read exits
+while kill -s 0 $dread_pid >/dev/null 2>&1; do
 	$XFS_IO_PROG -c "mmap 0 $filesz" -c "mwrite 0 $filesz" $SCRATCH_MNT/file \
 		> /dev/null
 	$XFS_IO_PROG -c "fpunch 0 $filesz" $SCRATCH_MNT/file > /dev/null
 done
 
-kill -9 $dread_pid > /dev/null 2>&1
 wait $dread_pid > /dev/null 2>&1
 
 echo "Silence is golden"
Signature · 1 line
2.13.3
Reviewed-by
#7 lore raw
Quoted 13 lines · Eryu Guan

Hi Xiao Yang,

Quoted 10 lines · Eryu Guan

The $dread_pid refers to the while-true-do loop, wait for $dread_pid doesn't mean the xfs_io direct read process is already dead, sometimes xfs_io process is still running and blocking _scratch_unmount.

Fix it by making the direct read does a fixed number of loop and break out the second mmap-fpunch loop if the first loop exits. At this point we're sure that there's no unfinished background process blocking the umount.

Quoted 7 lines
Quoted 5 lines

---
v2:
- move 'kill' to while loop condition to simplify the second loop
- add more comments about when to exit the loop

Would you please help test& review and provide reviewed-by tag if you think it's OK? Thanks a lot!

Hi Eryu,

I have tested it on my host, so it's fine. :-)

Thanks,
Xiao Yang

Quoted 39 lines

Eryu

Quoted 34 lines
  tests/generic/446 | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
tests/generic/446 +3 -3
index 62ae449de6b1..6a1b69aa2edc 100755
@@ -61,20 +61,20 @@ filesz=$((65536 * 2))
  $XFS_IO_PROG -f -c "truncate $((filesz * 2))" $SCRATCH_MNT/file>>  $seqres.full
 
  # run a background dio read to a hole in a loop
-while true; do
+for i in `seq 0 999`; do
  	$XFS_IO_PROG -d -c "pread 0 $filesz" $SCRATCH_MNT/file>  /dev/null 2>&1
  done&
 
  dread_pid=$!
 
  # run mapped write to the same hole as dio read
-for i in `seq 0 999`; do
+# loop until background dio read exits
+while kill -s 0 $dread_pid>/dev/null 2>&1; do
  	$XFS_IO_PROG -c "mmap 0 $filesz" -c "mwrite 0 $filesz" $SCRATCH_MNT/file \
  		>  /dev/null
  	$XFS_IO_PROG -c "fpunch 0 $filesz" $SCRATCH_MNT/file>  /dev/null
  done
 
-kill -9 $dread_pid>  /dev/null 2>&1
  wait $dread_pid>  /dev/null 2>&1
 
  echo "Silence is golden"
Signature · 1 line
2.13.3

.