Skip to contentSkip to conversation

fs: don't write pages when receiving a pending SIGKILL in __get_user_pages()

PATCH In review Xishi Qiu 2 participants 2 messages Jan 18, 2014 – Jan 21, 2014 VFS

lore
Share & tools
lore

Xishi Qiu

author
#0 lore raw

PATCH v2 1/1 fs: don't write pages when receiving a pending SIGKILL in __get_user_pages()

In the process IO direction, dio_refill_pages will call get_user_pages_fast to map the page from user space. If ret is less than 0 and IO is write, the function will create a zero page to fill data. This may work for some file system, but in some device operate we prefer whole write or fail, not half data half zero, e.g. fs metadata, like inode, identy.
This happens often when kill a process which is doing direct IO. Consider the following cases, the process A is doing IO process, may enter __get_user_pages function, if other processes send process A SIG_KILL, A will enter the following branches

		/*
		 * If we have a pending SIGKILL, don't keep faulting
		 * pages and potentially allocating memory.
		 */
		if (unlikely(fatal_signal_pending(current)))
			return i ? i : -ERESTARTSYS;

Return current pages. direct IO will write the pages, the subsequent pages which can’t get will use zero page instead.

---
 fs/direct-io.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
fs/direct-io.c +3 -0
index 0e04142..b74d565 100644
@@ -174,6 +174,9 @@ static inline int dio_refill_pages(struct dio *dio, struct dio_submit *sdio)
 		&dio->pages[0]);		/* Put results here */
 
 	if (ret < 0 && sdio->blocks_available && (dio->rw & WRITE)) {
+		/* If task is killed, do not write anymore */
+		if (ret == -ERESTARTSYS)
+			goto out;
 		struct page *page = ZERO_PAGE(0);
 		/*
 		 * A memory fault, but the filesystem has some outstanding
Signature · 1 line
1.7.1
#1 lore raw
Quoted 5 lines · Xishi Qiu

In the process IO direction, dio_refill_pages will call get_user_pages_fast to map the page from user space. If ret is less than 0 and IO is write, the function will create a zero page to fill data. This may work for some file system, but in some device operate we prefer whole write or fail, not half data half zero, e.g. fs metadata, like inode, identy.

So you're attemping to define a behavior for all users of direct IO for a problem that is filesystem or backing device dependent? Perhaps if you elaborated on the problem that you're seeing then we could address it.

Quoted 24 lines

This happens often when kill a process which is doing direct IO. Consider the following cases, the process A is doing IO process, may enter __get_user_pages function, if other processes send process A SIG_KILL, A will enter the following branches

		/*
		 * If we have a pending SIGKILL, don't keep faulting
		 * pages and potentially allocating memory.
		 */
		if (unlikely(fatal_signal_pending(current)))
			return i ? i : -ERESTARTSYS;

Return current pages. direct IO will write the pages, the subsequent pages which can’t get will use zero page instead.

---
 fs/direct-io.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
fs/direct-io.c +0 -0
index 0e04142..b74d565 100644

fs/direct-io.c static inline int dio_refill_pages(struct dio *dio, struct dio_submit *sdio) · line 182

Quoted 9 lines
fs/direct-io.c +3 -0
@@ -174,6 +174,9 @@ static inline int dio_refill_pages(struct dio *dio, struct dio_submit *sdio)
 		&dio->pages[0]);		/* Put results here */
 
 	if (ret < 0 && sdio->blocks_available && (dio->rw & WRITE)) {
+		/* If task is killed, do not write anymore */
+		if (ret == -ERESTARTSYS)
+			goto out;
 		struct page *page = ZERO_PAGE(0);
 		/*
 		 * A memory fault, but the filesystem has some outstanding

We don't mix declarations and text, please try to compile your patches before proposing them.