Make get_user_pages interruptible
Subsystems (3)
PATCH v4 1/1 Make get_user_pages interruptible
From: Ying Han <[email protected]>
make get_user_pages interruptible
The initial implementation of checking TIF_MEMDIE covers the cases of OOM killing. If the process has been OOM killed, the TIF_MEMDIE is set and it return immediately. This patch includes:
1. add the case that the SIGKILL is sent by user processes. The process can try to get_user_pages() unlimited memory even if a user process has sent a SIGKILL to it(maybe a monitor find the process exceed its memory limit and try to kill it). In the old implementation, the SIGKILL won't be handled until the get_user_pages() returns.
2. change the return value to be ERESTARTSYS. It makes no sense to return ENOMEM if the get_user_pages returned by getting a SIGKILL signal. Considering the general convention for a system call interrupted by a signal is ERESTARTNOSYS, so the current return value is consistant to that.
include/linux/sched.h | 1 + kernel/signal.c | 2 +- mm/memory.c | 9 +-
include/linux/sched.h +1 -0
@@ -1790,6 +1790,7 @@ extern void sched_dead(struct task_struct *p);extern int in_group_p (gid_t );extern int in_egroup_p (gid_t ); +extern int sigkill_pending (struct task_struct *tsk);extern void proc_caches_init (void );extern void flush_signals (struct task_struct *);extern void ignore_signals (struct task_struct *);
kernel/signal.c +1 -1
@@ -1497,7 +1497,7 @@ static inline int may_ptrace_stop(void)* Return nonzero if there is a SIGKILL that should be waking us up. * Called with the siglock held. */ -static int sigkill_pending (struct task_struct *tsk) +int sigkill_pending (struct task_struct *tsk) {return sigismember (&tsk->pending.signal,SIGKILL ) ||sigismember (&tsk->signal->shared_pending.signal,SIGKILL );
mm/memory.c +5 -5
@@ -1218,12 +1218,12 @@ int __get_user_pages(struct task_struct *tsk, struct mstruct page *page;/* -* If tsk is ooming, cut off its access to large memory -* allocations. It has a pending SIGKILL, but it can't -* be processed until returning to user space. +* If we have a pending SIGKILL, don't keep +* allocating memory. */ -if (unlikely (test_tsk_thread_flag (tsk,TIF_MEMDIE ))) -return i ? i : -ENOMEM ; +if (unlikely (sigkill_pending (current) || +sigkill_pending (tsk))) +return i ? i : -ERESTARTSYS ;if (write) foll_flags |=FOLL_WRITE ;
--
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>
Quoted 13 lines · Ying Han
From: Ying Han <[email protected]>
make
get_user_pagesinterruptible
The initial implementation of checkingTIF_MEMDIEcovers the cases of OOM killing. If the process has been OOM killed, theTIF_MEMDIEis set and it return immediately. This patch includes:1. add the case that the SIGKILL is sent by user processes. The process can try to
get_user_pages()unlimited memory even if a user process has sent a SIGKILL to it(maybe a monitor find the process exceed its memory limit and try to kill it). In the old implementation, the SIGKILL won't be handled until theget_user_pages()returns.
Quoted 4 lines
2. change the return value to be ERESTARTSYS. It makes no sense to return ENOMEM if the
get_user_pagesreturned by getting a SIGKILL signal. Considering the general convention for a system call interrupted by a signal is ERESTARTNOSYS, so the current return value is consistant to that.
Looks good to me (but I'm not the maintainer of this particular piece of code).
You might want to add an explanation why we check both 'tsk' and 'current' in either in the patch description or as a comment, though. Or just add a link to the mailing list archives in the description or something.
Quoted 2 lines
Signed-off-by Paul Menage <[email protected]>Singed-off-by Ying Han <[email protected]>
^^^^^^
I'm sure you have a beautiful singing voice but from legal point of view, it's probably better to just sign it off. ;-)
Pekka
Andrew Morton
maintainerQuoted 4 lines · On Tue, 25 Nov 2008 11:28:20 +0200 Pekka Enberg <[email protected]> wrote:
___Youmight want to add an explanation why we check both 'tsk' and 'current' in either in the patch description or as a comment, though. Or just add a link to the mailing list archives in the description or something.
As a code comment, I'd suggest.
Quoted 6 lines
Quoted 2 lines
Signed-off-by Paul Menage <[email protected]>Singed-off-by Ying Han <[email protected]>^^^^^^
I'm sure you have a beautiful singing voice but from legal point of view, it's probably better to just sign it off. ;-)
That's my favorite typo.
--
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>