Skip to contentSkip to conversation

mm: Make truncate_inode_pages_range() killable

PATCH In review Bart Van Assche 4 participants 7 messages Apr 14, 2017 – Apr 18, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm: Make truncate_inode_pages_range() killable

The default behavior of multipathd is to run kpartx against newly discovered paths. Avoid that these kpartx processes become unkillable if there are no paths left and when using queue_if_no_path. This patch avoids that kpartx sporadically hangs as follows:

Call Trace:
 __schedule+0x3df/0xc10
 schedule+0x3d/0x90
 io_schedule+0x16/0x40
 __lock_page+0x111/0x140
 truncate_inode_pages_range+0x462/0x790
 truncate_inode_pages+0x15/0x20
 kill_bdev+0x35/0x40
 __blkdev_put+0x76/0x220
 blkdev_put+0x4e/0x170
 blkdev_close+0x25/0x30
 __fput+0xed/0x1f0
 ____fput+0xe/0x10
 task_work_run+0x85/0xc0
 do_exit+0x311/0xc70
 do_group_exit+0x50/0xd0
 get_signal+0x2c7/0x930
 do_signal+0x28/0x6b0
 exit_to_usermode_loop+0x62/0xa0
 do_syscall_64+0xda/0x140
 entry_SYSCALL64_slow_path+0x25/0x25
Cc Oleg Nesterov <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Mel Gorman <[email protected]>
Cc Hugh Dickins <[email protected]>
Cc Mike Snitzer <[email protected]>
Cc Jan Kara <[email protected]>
Cc Hannes Reinecke <[email protected]>
---
 mm/truncate.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
mm/truncate.c +4 -2
index 6263affdef88..91abd16d74f8 100644
@@ -20,6 +20,7 @@
 #include <linux/task_io_accounting_ops.h>
 #include <linux/buffer_head.h>	/* grr. try_to_release_page,
 				   do_invalidatepage */
+#include <linux/sched/signal.h>
 #include <linux/shmem_fs.h>
 #include <linux/cleancache.h>
 #include <linux/rmap.h>
@@ -366,7 +367,7 @@ void truncate_inode_pages_range(struct address_space *mapping,
 		return;
 
 	index = start;
-	for ( ; ; ) {
+	for ( ; !signal_pending_state(TASK_WAKEKILL, current); ) {
 		cond_resched();
 		if (!pagevec_lookup_entries(&pvec, mapping, index,
 			min(end - index, (pgoff_t)PAGEVEC_SIZE), indices)) {
@@ -400,7 +401,8 @@ void truncate_inode_pages_range(struct address_space *mapping,
 				continue;
 			}
 
-			lock_page(page);
+			if (lock_page_killable(page))
+				break;
 			WARN_ON(page_to_index(page) != index);
 			wait_on_page_writeback(page);
 			truncate_inode_page(mapping, page);
Signature · 7 lines
2.12.2

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#1 lore raw
Quoted 22 lines · Bart Van Assche
mm/truncate.c +2 -1
index 6263affdef88..91abd16d74f8 100644
@@ -20,6 +20,7 @@
 #include <linux/task_io_accounting_ops.h>
 #include <linux/buffer_head.h>	/* grr. try_to_release_page,
 				   do_invalidatepage */
+#include <linux/sched/signal.h>
 #include <linux/shmem_fs.h>
 #include <linux/cleancache.h>
 #include <linux/rmap.h>
@@ -366,7 +367,7 @@ void truncate_inode_pages_range(struct address_space *mapping,
 		return;
 
 	index = start;
-	for ( ; ; ) {
+	for ( ; !signal_pending_state(TASK_WAKEKILL, current); ) {
 		cond_resched();
 		if (!pagevec_lookup_entries(&pvec, mapping, index,
 			min(end - index, (pgoff_t)PAGEVEC_SIZE), indices)) {

mm/truncate.c void truncate_inode_pages_range(struct address_space *mapping, · line 408

Quoted 9 lines
mm/truncate.c +2 -1
@@ -400,7 +401,8 @@ void truncate_inode_pages_range(struct address_space *mapping,
 				continue;
 			}
 
-			lock_page(page);
+			if (lock_page_killable(page))
+				break;
 			WARN_ON(page_to_index(page) != index);
 			wait_on_page_writeback(page);
 			truncate_inode_page(mapping, page);

Sorry but a small part of this patch got left out accidentally:

kernel/signal.c +0 -0
index 7e59ebc2c25e..a02b273a4a1c 100644
@@ -869,10 +869,10 @@ static inline int wants_signal(int sig, struct task_struct *p)

 {
  if (sigismember(&p->blocked, sig)) return 0;
- if (p->flags & PF_EXITING)
- return 0;
  if (sig == SIGKILL)
  return 1;
+ if (p->flags & PF_EXITING)
+ return 0;
  if (task_is_stopped_or_traced(p)) return 0;
  return task_curr(p) || !signal_pending(p);

Does anyone who is on the CC-list of this e-mail know whether this change is acceptable? As far as I can see the most recent change to that function was made through the following commit:

commit 188a1eafa03aaa5e5fe6f53e637e704cd2c31c7c
Author: Linus Torvalds <[email protected]>
Date:   Fri Sep 23 13:22:21 2005 -0700

    Make sure SIGKILL gets proper respect

Thanks,

Bart.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#2 lore raw
In reply to Bart Van Assche
Quoted 27 lines · Bart Van Assche

The default behavior of multipathd is to run kpartx against newly discovered paths. Avoid that these kpartx processes become unkillable if there are no paths left and when using queue_if_no_path. This patch avoids that kpartx sporadically hangs as follows:

Call Trace:
 __schedule+0x3df/0xc10
 schedule+0x3d/0x90
 io_schedule+0x16/0x40
 __lock_page+0x111/0x140
 truncate_inode_pages_range+0x462/0x790
 truncate_inode_pages+0x15/0x20
 kill_bdev+0x35/0x40
 __blkdev_put+0x76/0x220
 blkdev_put+0x4e/0x170
 blkdev_close+0x25/0x30
 __fput+0xed/0x1f0
 ____fput+0xe/0x10
 task_work_run+0x85/0xc0
 do_exit+0x311/0xc70
 do_group_exit+0x50/0xd0
 get_signal+0x2c7/0x930
 do_signal+0x28/0x6b0
 exit_to_usermode_loop+0x62/0xa0
 do_syscall_64+0xda/0x140
 entry_SYSCALL64_slow_path+0x25/0x25
Quoted 9 lines
Cc Oleg Nesterov <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Mel Gorman <[email protected]>
Cc Hugh Dickins <[email protected]>
Cc Mike Snitzer <[email protected]>
Cc Jan Kara <[email protected]>
Cc Hannes Reinecke <[email protected]>

Changing a fundamental function, silently not to do its essential job, when something in the kernel has forgotten (or is slow to) unlock_page():
that seems very wrong to me in many ways. But linux-fsdevel, Cc'ed, will be a better forum to advise on how to solve the problem you're seeing.

Hugh

Quoted 37 lines
---
 mm/truncate.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
mm/truncate.c +4 -2
index 6263affdef88..91abd16d74f8 100644
@@ -20,6 +20,7 @@
 #include <linux/task_io_accounting_ops.h>
 #include <linux/buffer_head.h>	/* grr. try_to_release_page,
 				   do_invalidatepage */
+#include <linux/sched/signal.h>
 #include <linux/shmem_fs.h>
 #include <linux/cleancache.h>
 #include <linux/rmap.h>
@@ -366,7 +367,7 @@ void truncate_inode_pages_range(struct address_space *mapping,
 		return;
 
 	index = start;
-	for ( ; ; ) {
+	for ( ; !signal_pending_state(TASK_WAKEKILL, current); ) {
 		cond_resched();
 		if (!pagevec_lookup_entries(&pvec, mapping, index,
 			min(end - index, (pgoff_t)PAGEVEC_SIZE), indices)) {
@@ -400,7 +401,8 @@ void truncate_inode_pages_range(struct address_space *mapping,
 				continue;
 			}
 
-			lock_page(page);
+			if (lock_page_killable(page))
+				break;
 			WARN_ON(page_to_index(page) != index);
 			wait_on_page_writeback(page);
 			truncate_inode_page(mapping, page);
Signature · 1 line
2.12.2

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#3 lore raw

T24gRnJpLCAyMDE3LTA0LTE0IGF0IDE3OjQwIC0wNzAwLCBIdWdoIERpY2tpbnMgd3JvdGU6DQo+ IENoYW5naW5nIGEgZnVuZGFtZW50YWwgZnVuY3Rpb24sIHNpbGVudGx5IG5vdCB0byBkbyBpdHMg ZXNzZW50aWFsIGpvYiwNCj4gd2hlbiBzb21ldGhpbmcgaW4gdGhlIGtlcm5lbCBoYXMgZm9yZ290 dGVuIChvciBpcyBzbG93IHRvKSB1bmxvY2tfcGFnZSgpOg0KPiB0aGF0IHNlZW1zIHZlcnkgd3Jv bmcgdG8gbWUgaW4gbWFueSB3YXlzLiAgQnV0IGxpbnV4LWZzZGV2ZWwsIENjJ2VkLCB3aWxsDQo+ IGJlIGEgYmV0dGVyIGZvcnVtIHRvIGFkdmlzZSBvbiBob3cgdG8gc29sdmUgdGhlIHByb2JsZW0g eW91J3JlIHNlZWluZy4NCg0KSGVsbG8gSHVnaCwNCg0KSXQgc2VlbXMgbGlrZSB5b3UgaGF2ZSBt aXN1bmRlcnN0b29kIHRoZSBwdXJwb3NlIG9mIHRoZSBwYXRjaCBJIHBvc3RlZC4gSXQncw0KbmVp dGhlciBhIG1pc3NpbmcgdW5sb2NrX3BhZ2UoKSBub3Igc2xvdyBJL08gdGhhdCBJIHdhbnQgdG8g YWRkcmVzcyBidXQgYQ0KZ2VudWluZSBkZWFkbG9jay4gSW4gY2FzZSB5b3Ugd291bGQgbm90IGJl IGZhbWlsaWFyIHdpdGggdGhlIHF1ZXVlX2lmX25vX3BhdGgNCm11bHRpcGF0aCBjb25maWd1cmF0 aW9uIG9wdGlvbiwgdGhlIG11bHRpcGF0aC5jb25mIG1hbiBwYWdlIGlzIGF2YWlsYWJsZSBhdA0K ZS5nLiBodHRwczovL2xpbnV4LmRpZS5uZXQvbWFuLzUvbXVsdGlwYXRoLmNvbmYuDQoNCkJhcnQu DQo=

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#4 lore raw
Quoted 6 lines · Bart Van Assche
Quoted 4 lines · Hugh Dickins

Changing a fundamental function, silently not to do its essential job, when something in the kernel has forgotten (or is slow to) unlock_page():
that seems very wrong to me in many ways. But linux-fsdevel, Cc'ed, will be a better forum to advise on how to solve the problem you're seeing.

Quoted 7 lines

Hello Hugh,

It seems like you have misunderstood the purpose of the patch I posted. It's neither a missing unlock_page() nor slow I/O that I want to address but a genuine deadlock. In case you would not be familiar with the queue_if_no_path multipath configuration option, the multipath.conf man page is available at e.g. https://linux.die.net/man/5/multipath.conf.

So, whole is holding the page lock and why it cannot make forward progress? Is the storage gone so that the ongoing IO will never terminate? Btw. we have many other places which wait for the page lock !killable way. Why they are any different from this case?

Signature · 8 lines
Michal Hocko
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#6 lore raw
In reply to Bart Van Assche
Quoted 17 lines · Bart Van Assche
Quoted 15 lines · Bart Van Assche
mm/truncate.c +1 -0
index 6263affdef88..91abd16d74f8 100644
@@ -20,6 +20,7 @@
 #include <linux/task_io_accounting_ops.h>
 #include <linux/buffer_head.h>	/* grr. try_to_release_page,
 				   do_invalidatepage */
+#include <linux/sched/signal.h>
 #include <linux/shmem_fs.h>
 #include <linux/cleancache.h>
 #include <linux/rmap.h>
@@ -366,7 +367,7 @@ void truncate_inode_pages_range(struct address_space *mapping,
 		return;
 
Quoted 3 lines

mm/truncate.c void truncate_inode_pages_range(struct address_space *mapping, · line 370

Quoted 3 lines
mm/truncate.c +1 -1
 	index = start;
-	for ( ; ; ) {
+	for ( ; !signal_pending_state(TASK_WAKEKILL, current); ) {

you could just use fatal_signal_pending(current)

Quoted 7 lines

Sorry but a small part of this patch got left out accidentally:

kernel/signal.c +0 -0
index 7e59ebc2c25e..a02b273a4a1c 100644

kernel/signal.c static inline int wants_signal(int sig, struct task_struct *p) · line 875

Quoted 9 lines
kernel/signal.c +2 -2
@@ -869,10 +869,10 @@ static inline int wants_signal(int sig, struct task_struct *p)
 {
 	if (sigismember(&p->blocked, sig))
 		return 0;
-	if (p->flags & PF_EXITING)
-		return 0;
 	if (sig == SIGKILL)
 		return 1;
+	if (p->flags & PF_EXITING)
+		return 0;

Oh. This is the user-visible change. With this change you send a private signal to a zombie thread and it will kill the process. Perhaps this is even good, and in fact I was thinking about this change too many times, but I am not sure.

And afaics it won't really help. If the exiting task is multithreaded then another kill(SIGKILL) won't wake other threads up, you will need tkill(tid_of_bloked_thread).

OTOH. Please note that fatal_signal_pending(exiting_thread) can be true even if you do not send another SIGKILL.

But the main problem is that the behaviour of signal sent to PF_EXITING task is not defined, it is not clear to me what do we actually want to do.

Oleg.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#5 lore raw
In reply to Michal Hocko
Quoted 13 lines · Michal Hocko
Quoted 11 lines · Bart Van Assche
Quoted 4 lines · Hugh Dickins

Changing a fundamental function, silently not to do its essential job, when something in the kernel has forgotten (or is slow to) unlock_page():
that seems very wrong to me in many ways. But linux-fsdevel, Cc'ed, will be a better forum to advise on how to solve the problem you're seeing.

It seems like you have misunderstood the purpose of the patch I posted. It's neither a missing unlock_page() nor slow I/O that I want to address but a genuine deadlock. In case you would not be familiar with the queue_if_no_path multipath configuration option, the multipath.conf man page is available at e.g. https://linux.die.net/man/5/multipath.conf.

Quoted 4 lines

So, who is holding the page lock and why it cannot make forward progress? Is the storage gone so that the ongoing IO will never terminate? Btw. we have many other places which wait for the page lock !killable way. Why they are any different from this case?

Hello Michal,

queue_if_no_path means that if no paths are available that the dm-mpath driver does not complete an I/O request until a path becomes available. A standard test for multipathed storage is to alternatingly remove and restore all paths.

If the reported lockup happens at the end of a test I can break the cycle by running "dmsetup message ${mpath} 0 fail_if_no_path". That command causes pending I/O requests to fail if no paths are available.

I think it is rather unintuitive that kill -9 does not work for a process that uses a dm-mpath device for I/O as long as no paths are available.

The call stack I reported in the first e-mail in this thread is what I ran into while running multipath tests. I'm not sure why I have not yet hit any other code paths that perform an unkillable wait on a page lock.

Bart.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>