linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][RESEND] nommu: yield CPU periodically while disposing large VM
@ 2010-11-11 20:33 Steven J. Magnani
  2010-11-12  2:40 ` Andrew Morton
  2010-11-14  5:07 ` KOSAKI Motohiro
  0 siblings, 2 replies; 6+ messages in thread
From: Steven J. Magnani @ 2010-11-11 20:33 UTC (permalink / raw)
  To: linux-mm; +Cc: linux-kernel, Steven J. Magnani

Depending on processor speed, page size, and the amount of memory a process
is allowed to amass, cleanup of a large VM may freeze the system for many
seconds. This can result in a watchdog timeout.

Make sure other tasks receive some service when cleaning up large VMs.

Signed-off-by: Steven J. Magnani <steve@digidescorp.com>
---
diff -uprN a/mm/nommu.c b/mm/nommu.c
--- a/mm/nommu.c	2010-10-21 07:42:23.000000000 -0500
+++ b/mm/nommu.c	2010-10-21 07:46:50.000000000 -0500
@@ -1656,6 +1656,7 @@ SYSCALL_DEFINE2(munmap, unsigned long, a
 void exit_mmap(struct mm_struct *mm)
 {
 	struct vm_area_struct *vma;
+	unsigned long next_yield = jiffies + HZ;
 
 	if (!mm)
 		return;
@@ -1668,6 +1669,11 @@ void exit_mmap(struct mm_struct *mm)
 		mm->mmap = vma->vm_next;
 		delete_vma_from_mm(vma);
 		delete_vma(mm, vma);
+		/* Yield periodically to prevent watchdog timeout */
+		if (time_after(jiffies, next_yield)) {
+			cond_resched();
+			next_yield = jiffies + HZ;
+		}
 	}
 
 	kleave("");


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH][RESEND] nommu: yield CPU periodically while disposing large VM
  2010-11-11 20:33 [PATCH][RESEND] nommu: yield CPU periodically while disposing large VM Steven J. Magnani
@ 2010-11-12  2:40 ` Andrew Morton
  2010-11-15 14:29   ` Steven J. Magnani
  2010-11-14  5:07 ` KOSAKI Motohiro
  1 sibling, 1 reply; 6+ messages in thread
From: Andrew Morton @ 2010-11-12  2:40 UTC (permalink / raw)
  To: Steven J. Magnani; +Cc: linux-mm, linux-kernel, Greg Ungerer

On Thu, 11 Nov 2010 14:33:16 -0600 "Steven J. Magnani" <steve@digidescorp.com> wrote:

> Depending on processor speed, page size, and the amount of memory a process
> is allowed to amass, cleanup of a large VM may freeze the system for many
> seconds. This can result in a watchdog timeout.

hm, that's no good.

> Make sure other tasks receive some service when cleaning up large VMs.
> 
> Signed-off-by: Steven J. Magnani <steve@digidescorp.com>
> ---
> diff -uprN a/mm/nommu.c b/mm/nommu.c
> --- a/mm/nommu.c	2010-10-21 07:42:23.000000000 -0500
> +++ b/mm/nommu.c	2010-10-21 07:46:50.000000000 -0500
> @@ -1656,6 +1656,7 @@ SYSCALL_DEFINE2(munmap, unsigned long, a
>  void exit_mmap(struct mm_struct *mm)
>  {
>  	struct vm_area_struct *vma;
> +	unsigned long next_yield = jiffies + HZ;
>  
>  	if (!mm)
>  		return;
> @@ -1668,6 +1669,11 @@ void exit_mmap(struct mm_struct *mm)
>  		mm->mmap = vma->vm_next;
>  		delete_vma_from_mm(vma);
>  		delete_vma(mm, vma);
> +		/* Yield periodically to prevent watchdog timeout */
> +		if (time_after(jiffies, next_yield)) {
> +			cond_resched();
> +			next_yield = jiffies + HZ;
> +		}
>  	}
>  
>  	kleave("");

You might be able to do this a bit more neatly with __ratelimit:

	DEFINE_RATELIMIT_STATE(rl, HZ, 1);

	...

	if (___ratelimit(&rl, NULL))
		cond_resched();

but ___ratelimit() isn't really ready for that - it still has (easily
fixed) assumptions that it's being used for printk ratelimiting.


But anyway.  cond_resched() is pretty efficient and one second is still
a very long time.  I suspect you don't need the ratelimiting at all?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH][RESEND] nommu: yield CPU periodically while disposing large VM
  2010-11-11 20:33 [PATCH][RESEND] nommu: yield CPU periodically while disposing large VM Steven J. Magnani
  2010-11-12  2:40 ` Andrew Morton
@ 2010-11-14  5:07 ` KOSAKI Motohiro
  1 sibling, 0 replies; 6+ messages in thread
From: KOSAKI Motohiro @ 2010-11-14  5:07 UTC (permalink / raw)
  To: Steven J. Magnani; +Cc: kosaki.motohiro, linux-mm, linux-kernel

> Depending on processor speed, page size, and the amount of memory a process
> is allowed to amass, cleanup of a large VM may freeze the system for many
> seconds. This can result in a watchdog timeout.
> 
> Make sure other tasks receive some service when cleaning up large VMs.
> 
> Signed-off-by: Steven J. Magnani <steve@digidescorp.com>
> ---
> diff -uprN a/mm/nommu.c b/mm/nommu.c
> --- a/mm/nommu.c	2010-10-21 07:42:23.000000000 -0500
> +++ b/mm/nommu.c	2010-10-21 07:46:50.000000000 -0500
> @@ -1656,6 +1656,7 @@ SYSCALL_DEFINE2(munmap, unsigned long, a
>  void exit_mmap(struct mm_struct *mm)
>  {
>  	struct vm_area_struct *vma;
> +	unsigned long next_yield = jiffies + HZ;
>  
>  	if (!mm)
>  		return;
> @@ -1668,6 +1669,11 @@ void exit_mmap(struct mm_struct *mm)
>  		mm->mmap = vma->vm_next;
>  		delete_vma_from_mm(vma);
>  		delete_vma(mm, vma);
> +		/* Yield periodically to prevent watchdog timeout */
> +		if (time_after(jiffies, next_yield)) {
> +			cond_resched();
> +			next_yield = jiffies + HZ;
> +		}

If watchdog tiemr interval is less than HZ, this logic doesn't work. right?
If so, I would suggest just remove time_after() and call cond_resched() every time
because cond_resched is no-op if TIF_NEED_RESCHED is not setted.




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH][RESEND] nommu: yield CPU periodically while disposing large VM
  2010-11-12  2:40 ` Andrew Morton
@ 2010-11-15 14:29   ` Steven J. Magnani
  2010-11-16  4:47     ` Andrew Morton
  0 siblings, 1 reply; 6+ messages in thread
From: Steven J. Magnani @ 2010-11-15 14:29 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-mm, linux-kernel, Greg Ungerer, KOSAKI Motohiro

On Thu, 2010-11-11 at 18:40 -0800, Andrew Morton wrote:
> On Thu, 11 Nov 2010 14:33:16 -0600 "Steven J. Magnani" <steve@digidescorp.com> wrote:
> 
> > --- a/mm/nommu.c	2010-10-21 07:42:23.000000000 -0500
> > +++ b/mm/nommu.c	2010-10-21 07:46:50.000000000 -0500
> > @@ -1656,6 +1656,7 @@ SYSCALL_DEFINE2(munmap, unsigned long, a
> >  void exit_mmap(struct mm_struct *mm)
> >  {
> >  	struct vm_area_struct *vma;
> > +	unsigned long next_yield = jiffies + HZ;
> >  
> >  	if (!mm)
> >  		return;
> > @@ -1668,6 +1669,11 @@ void exit_mmap(struct mm_struct *mm)
> >  		mm->mmap = vma->vm_next;
> >  		delete_vma_from_mm(vma);
> >  		delete_vma(mm, vma);
> > +		/* Yield periodically to prevent watchdog timeout */
> > +		if (time_after(jiffies, next_yield)) {
> > +			cond_resched();
> > +			next_yield = jiffies + HZ;
> > +		}
> >  	}
> >  
> >  	kleave("");
> 
[snip]
> cond_resched() is pretty efficient and one second is still
> a very long time.  I suspect you don't need the ratelimiting at all?

Probably not, but the issue was that disposal of "large" VMs can starve
the system. Since these are not the norm (otherwise this would have been
fixed long ago) I was attempting to limit the impact on more
"normal"-sized VMs. Responsiveness is not great with a one-second
ratelimit, and as KOSAKI Motohiro points out this fix won't work on
systems with short watchdog intervals. I assumed that these were not
common.

As efficient as schedule() may be, it still scares me to call it on
reclaim of every block of memory allocated by a terminating process,
particularly on the relatively slow processors that inhabit NOMMU land.
It wasn't obvious to me that it has a quick exit. But since we are
talking about sharing the CPU with other processes perhaps this is only
an issue in an OOM scenario, when fast reclaim might be more important.

I can certainly respin the patch to call cond_resched() unconditionally
if that's the consensus.

Regards,
------------------------------------------------------------------------
 Steven J. Magnani               "I claim this network for MARS!
 www.digidescorp.com              Earthling, return my space modulator!"

 #include <standard.disclaimer>



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH][RESEND] nommu: yield CPU periodically while disposing large VM
  2010-11-15 14:29   ` Steven J. Magnani
@ 2010-11-16  4:47     ` Andrew Morton
  2010-11-16 13:03       ` Steven J. Magnani
  0 siblings, 1 reply; 6+ messages in thread
From: Andrew Morton @ 2010-11-16  4:47 UTC (permalink / raw)
  To: steve; +Cc: linux-mm, linux-kernel, Greg Ungerer, KOSAKI Motohiro

On Mon, 15 Nov 2010 08:29:11 -0600 "Steven J. Magnani" <steve@digidescorp.com> wrote:

> On Thu, 2010-11-11 at 18:40 -0800, Andrew Morton wrote:
> > On Thu, 11 Nov 2010 14:33:16 -0600 "Steven J. Magnani" <steve@digidescorp.com> wrote:
> > 
> > > --- a/mm/nommu.c	2010-10-21 07:42:23.000000000 -0500
> > > +++ b/mm/nommu.c	2010-10-21 07:46:50.000000000 -0500
> > > @@ -1656,6 +1656,7 @@ SYSCALL_DEFINE2(munmap, unsigned long, a
> > >  void exit_mmap(struct mm_struct *mm)
> > >  {
> > >  	struct vm_area_struct *vma;
> > > +	unsigned long next_yield = jiffies + HZ;
> > >  
> > >  	if (!mm)
> > >  		return;
> > > @@ -1668,6 +1669,11 @@ void exit_mmap(struct mm_struct *mm)
> > >  		mm->mmap = vma->vm_next;
> > >  		delete_vma_from_mm(vma);
> > >  		delete_vma(mm, vma);
> > > +		/* Yield periodically to prevent watchdog timeout */
> > > +		if (time_after(jiffies, next_yield)) {
> > > +			cond_resched();
> > > +			next_yield = jiffies + HZ;
> > > +		}
> > >  	}
> > >  
> > >  	kleave("");
> > 
> [snip]
> > cond_resched() is pretty efficient and one second is still
> > a very long time.  I suspect you don't need the ratelimiting at all?
> 
> Probably not, but the issue was that disposal of "large" VMs can starve
> the system. Since these are not the norm (otherwise this would have been
> fixed long ago) I was attempting to limit the impact on more
> "normal"-sized VMs. Responsiveness is not great with a one-second
> ratelimit, and as KOSAKI Motohiro points out this fix won't work on
> systems with short watchdog intervals. I assumed that these were not
> common.
> 
> As efficient as schedule() may be, it still scares me to call it on
> reclaim of every block of memory allocated by a terminating process,
> particularly on the relatively slow processors that inhabit NOMMU land.

This is cond_resched(), not schedule()!  cond_resched() is just a few
instructions, except for the super-rare case where it calls schedule().

> It wasn't obvious to me that it has a quick exit. But since we are
> talking about sharing the CPU with other processes perhaps this is only
> an issue in an OOM scenario, when fast reclaim might be more important.
> 
> I can certainly respin the patch to call cond_resched() unconditionally
> if that's the consensus.

You have a consensus of 1 so far :)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH][RESEND] nommu: yield CPU periodically while disposing large VM
  2010-11-16  4:47     ` Andrew Morton
@ 2010-11-16 13:03       ` Steven J. Magnani
  0 siblings, 0 replies; 6+ messages in thread
From: Steven J. Magnani @ 2010-11-16 13:03 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-mm, linux-kernel, Greg Ungerer, KOSAKI Motohiro

On Mon, 2010-11-15 at 20:47 -0800, Andrew Morton wrote:
> On Mon, 15 Nov 2010 08:29:11 -0600 "Steven J. Magnani" <steve@digidescorp.com> wrote:
> 
> > As efficient as schedule() may be, it still scares me to call it on
> > reclaim of every block of memory allocated by a terminating process,
> > particularly on the relatively slow processors that inhabit NOMMU land.
> 
> This is cond_resched(), not schedule()!  cond_resched() is just a few
> instructions, except for the super-rare case where it calls schedule().

The light comes on..._cond_resched() is overloaded. I was looking at the
static version, which calls schedule(). The extern version is much more
lightweight.

I'll respin the patch.

Thanks,
------------------------------------------------------------------------
 Steven J. Magnani               "I claim this network for MARS!
 www.digidescorp.com              Earthling, return my space modulator!"

 #include <standard.disclaimer>




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2010-11-16 13:04 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-11 20:33 [PATCH][RESEND] nommu: yield CPU periodically while disposing large VM Steven J. Magnani
2010-11-12  2:40 ` Andrew Morton
2010-11-15 14:29   ` Steven J. Magnani
2010-11-16  4:47     ` Andrew Morton
2010-11-16 13:03       ` Steven J. Magnani
2010-11-14  5:07 ` KOSAKI Motohiro

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).