linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Kirill Korotaev <dev@sw.ru>
To: Christoph Lameter <christoph@lameter.com>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	raybry@engr.sgi.com, pavel@suse.cz, torvalds@osdl.org
Subject: Re: [RFC] Fix SMP brokenness for PF_FREEZE and make freezing usable for other purposes
Date: Sat, 25 Jun 2005 11:35:34 +0400	[thread overview]
Message-ID: <1104805430.20050625113534@sw.ru> (raw)
In-Reply-To: <Pine.LNX.4.62.0506241316370.30503@graphe.net>

CL> The process freezing used by software suspend currently relies on modifying
current->>flags from outside of the processes context. This makes freezing and
CL> unfreezing SMP unsafe since a process may change the flags at any time without
CL> locking. The following patch introduces a new atomic_t field in task_struct
CL> to allow SMP safe freezing and unfreezing.

CL> It provides a simple API for process freezing:

CL> frozen(process)             Check for frozen process
CL> freezing(process)   Check if a process is being frozen
CL> freeze(process)             Tell a process to freeze (go to refrigerator)
CL> thaw_process(process)       Restart process

CL> I only know that this boots correctly since I have no system that can do
CL> suspend. But Ray needs an effective means of process suspension for
CL> his process migration patches.
Just out of curiosity what patches are you talking about?
Is it possible to take a glance at it if it is what I think of?

comments below...

[skip]
CL>  /* Refrigerator is place where frozen processes are stored :-). */
CL> -void refrigerator(unsigned long flag)
CL> +void refrigerator(void)
CL>  {
CL>  	/* Hmm, should we be allowed to suspend when there are realtime
CL>  	   processes around? */
CL> @@ -40,15 +40,13 @@ void refrigerator(unsigned long flag)
CL>  	save = current->state;
CL>  	current->state = TASK_UNINTERRUPTIBLE;
CL>  	pr_debug("%s entered refrigerator\n", current->comm);
CL> -	printk("=");
-	current->>flags &= ~PF_FREEZE;
 
CL>  	spin_lock_irq(&current->sighand->siglock);
CL>  	recalc_sigpending(); /* We sent fake signal, clean it up */
CL>  	spin_unlock_irq(&current->sighand->siglock);
 
-	current->>flags |= PF_FROZEN;
-	while (current->>flags & PF_FROZEN)
CL> +	atomic_set(&current->freeze_status, FROZEN);
<<<< this looks unsafe... what if thaw_process() was called exactly
before this atomic_set()? then you won't wake up anymore...
CL> +	while (frozen(current))
CL>  		schedule();
CL>  	pr_debug("%s left refrigerator\n", current->comm);
CL>  	current->state = save;
CL> @@ -57,10 +55,10 @@ void refrigerator(unsigned long flag)
CL>  /* 0 = success, else # of processes that we failed to stop */
CL>  int freeze_processes(void)
CL>  {
CL> -       int todo;
CL> -       unsigned long start_time;
CL> +	int todo;
CL> +	unsigned long start_time;
CL>  	struct task_struct *g, *p;
CL> -	
CL> +
CL>  	printk( "Stopping tasks: " );
CL>  	start_time = jiffies;
CL>  	do {
CL> @@ -70,14 +68,12 @@ int freeze_processes(void)
CL>  			unsigned long flags;
CL>  			if (!freezeable(p))
CL>  				continue;
-			if ((p->>flags & PF_FROZEN) ||
CL> +			if ((frozen(p)) ||
<<<< this looks unsafe also... i think you have to check freezing()
instead of frozen(). otherwise you will be constantly incrementing
freezing counter and it can potentially overflow... Though this is
unlikely I see no reason to call freeze() if we are freezing
already... But we can call signal_wake_up() to speed up the process...
CL>  			    (p->state == TASK_TRACED) ||
CL>  			    (p->state == TASK_STOPPED))
CL>  				continue;
 
CL> -			/* FIXME: smp problem here: we may not access other process' flags
CL> -			   without locking */
-			p->>flags |= PF_FREEZE;
CL> +			freeze(p);
CL>  			spin_lock_irqsave(&p->sighand->siglock, flags);
CL>  			signal_wake_up(p, 0);
CL>  			spin_unlock_irqrestore(&p->sighand->siglock, flags);
CL> @@ -91,7 +87,7 @@ int freeze_processes(void)
CL>  			return todo;
CL>  		}
CL>  	} while(todo);
CL> -	
CL> +
CL>  	printk( "|\n" );
CL>  	BUG_ON(in_atomic());
CL>  	return 0;
CL> @@ -106,10 +102,7 @@ void thaw_processes(void)
CL>  	do_each_thread(g, p) {
CL>  		if (!freezeable(p))
CL>  			continue;
-		if (p->>flags & PF_FROZEN) {
-			p->>flags &= ~PF_FROZEN;
CL> -			wake_up_process(p);
CL> -		} else
CL> +		if (!thaw_process(p))
CL>  			printk(KERN_INFO " Strange, %s not stopped\n", p->comm );
CL>  	} while_each_thread(g, p);
 
[skip]

CL> Index: linux-2.6.12/arch/i386/kernel/signal.c
CL> ===================================================================
CL> --- linux-2.6.12.orig/arch/i386/kernel/signal.c	2005-06-24 20:03:23.000000000 +0000
CL> +++ linux-2.6.12/arch/i386/kernel/signal.c	2005-06-24 20:03:25.000000000 +0000
CL> @@ -608,10 +608,8 @@ int fastcall do_signal(struct pt_regs *r
CL>  	if (!user_mode(regs))
CL>  		return 1;
 
-	if (current->>flags & PF_FREEZE) {
CL> -		refrigerator(0);
CL> +	if (try_to_freeze)
<<<< missed ()?
CL>  		goto no_signal;

Kirill
--
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/ .
Don't email: <a href=mailto:"aart@kvack.org"> aart@kvack.org </a>

  parent reply	other threads:[~2005-06-25  7:35 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-24 20:20 Christoph Lameter
2005-06-24 22:25 ` Nigel Cunningham
2005-06-25  2:51 ` Pavel Machek
2005-06-25  4:31   ` Christoph Lameter
2005-06-25  4:46     ` Nigel Cunningham
2005-06-25 22:37     ` Pavel Machek
2005-06-25  6:13   ` Christoph Lameter
2005-06-26  2:30     ` Pavel Machek
2005-06-26  2:55       ` Christoph Lameter
2005-06-26  3:09         ` Pavel Machek
2005-06-27  3:51           ` Christoph Lameter
2005-06-27  4:21             ` Pavel Machek
2005-06-27  4:24             ` Linus Torvalds
2005-06-27  5:53               ` Christoph Lameter
2005-06-27 14:13                 ` Pavel Machek
2005-06-27 15:13                   ` Christoph Lameter
2005-06-28  6:18                     ` Kirill Korotaev
2005-06-28  7:01                       ` Christoph Lameter
2005-06-28  7:30                         ` Kirill Korotaev
2005-06-28  8:13                           ` Kirill Korotaev
2005-06-28 14:02                             ` Christoph Lameter
2005-06-28 14:01                           ` Christoph Lameter
2005-06-28 12:47                       ` Pavel Machek
2005-07-01 17:06                         ` [SUSPEND 1/2]Replace PF_FREEZE with TIF_FREEZE Christoph Lameter
2005-07-01 17:14                           ` [SUSPEND 2/2] Replace PF_FROZEN with TASK_FROZEN Christoph Lameter
2005-06-28 21:50                 ` [RFC] Fix SMP brokenness for PF_FREEZE and make freezing usable for other purposes Ray Bryant
2005-06-28 21:54                   ` Christoph Lameter
2005-07-03 11:06                     ` Pavel Machek
2005-06-26 10:54       ` Nigel Cunningham
2005-06-25  6:18   ` Christoph Lameter
2005-06-25  7:35 ` Kirill Korotaev [this message]
2005-06-27  7:06   ` Ray Bryant
2005-06-27 13:17     ` Pavel Machek
2005-06-27 14:59       ` Ray Bryant
2005-06-27 18:05         ` Pavel Machek

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=1104805430.20050625113534@sw.ru \
    --to=dev@sw.ru \
    --cc=christoph@lameter.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=pavel@suse.cz \
    --cc=raybry@engr.sgi.com \
    --cc=torvalds@osdl.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox