All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: "Steven J. Magnani" <steve@digidescorp.com>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	Greg Ungerer <gerg@snapgear.com>
Subject: Re: [PATCH][RESEND] nommu: yield CPU periodically while disposing large VM
Date: Thu, 11 Nov 2010 18:40:59 -0800	[thread overview]
Message-ID: <20101111184059.5744a42f.akpm@linux-foundation.org> (raw)
In-Reply-To: <1289507596-17613-1-git-send-email-steve@digidescorp.com>

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?

WARNING: multiple messages have this Message-ID (diff)
From: Andrew Morton <akpm@linux-foundation.org>
To: "Steven J. Magnani" <steve@digidescorp.com>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	Greg Ungerer <gerg@snapgear.com>
Subject: Re: [PATCH][RESEND] nommu: yield CPU periodically while disposing large VM
Date: Thu, 11 Nov 2010 18:40:59 -0800	[thread overview]
Message-ID: <20101111184059.5744a42f.akpm@linux-foundation.org> (raw)
In-Reply-To: <1289507596-17613-1-git-send-email-steve@digidescorp.com>

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?

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2010-11-12  2:44 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-11 20:33 [PATCH][RESEND] nommu: yield CPU periodically while disposing large VM Steven J. Magnani
2010-11-11 20:33 ` Steven J. Magnani
2010-11-12  2:40 ` Andrew Morton [this message]
2010-11-12  2:40   ` Andrew Morton
2010-11-15 14:29   ` Steven J. Magnani
2010-11-15 14:29     ` Steven J. Magnani
2010-11-16  4:47     ` Andrew Morton
2010-11-16  4:47       ` Andrew Morton
2010-11-16 13:03       ` Steven J. Magnani
2010-11-16 13:03         ` Steven J. Magnani
2010-11-14  5:07 ` KOSAKI Motohiro
2010-11-14  5:07   ` KOSAKI Motohiro

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20101111184059.5744a42f.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=gerg@snapgear.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=steve@digidescorp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.