All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@tv-sign.ru>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: ebiederm@xmission.com, mingo@elte.hu,
	torvalds@linux-foundation.org, roland@redhat.com,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/3] introduce PF_KTHREAD flag
Date: Wed, 4 Jun 2008 21:44:47 +0400	[thread overview]
Message-ID: <20080604174447.GA10284@tv-sign.ru> (raw)
In-Reply-To: <20080603141416.43afaeba.akpm@linux-foundation.org>

On 06/03, Andrew Morton wrote:
>
> On Sun, 1 Jun 2008 19:30:42 +0400
> Oleg Nesterov <oleg@tv-sign.ru> wrote:
> 
> > Introduce the new PF_KTHREAD flag to mark the kernel threads. It is set by
> > INIT_TASK() and copied to the forked childs (we could set it in kthreadd()
> > along with PF_NOFREEZE instead).
> > 
> > daemonize() was changed as well. In that case testing of PF_KTHREAD is racy,
> > but daemonize() is hopeless anyway.
> > 
> > This flag is cleared in do_execve(), before search_binary_handler(). Probably
> > not the best place, we can do this in exec_mmap() or in start_thread(), or
> > clear it along with PF_FORKNOEXEC. But I think this doesn't matter in practice,
> > and if do_execve() fails kthread should die soon.
> 
> The changelog doesn't explain why this change is being made, and I
> wasn't able to work that out.

Currently it is not possible to see if the task is kthread or not.

In most cases we don't care, all we need to know is it has ->mm or not, but..

> Similarly, I can kinda see what benefit "[PATCH 2/3] kill
> PF_BORROWED_MM in favour of PF_KTHREAD" is bringing us, but it would be
> nice to see that spelled out please.

we can't use PF_BORROWED_MM for that without task_lock(), no matter how
many barriers we add/use.

The 3rd patch is just an example. We have a lot of "p->mm != NULL" checks
in (say) oom_kill.c, and they are not right. Without PF_KTHREAD which can
be checked lockless, we need something like

	int has_mm(struct task_struct *p)
	{
		task_lock(p);
		ret = p->mm && !(p->flags & PF_BORROWED_MM);
		task_unlock(p);

		return ret;
	}


In short, PF_KTHREAD is more flexible and doesn't need task_lock(). If
it it cleared after the check, the task has the new ->mm.

Oleg.


  reply	other threads:[~2008-06-04 17:43 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-01 15:30 [PATCH 1/3] introduce PF_KTHREAD flag Oleg Nesterov
2008-06-03 21:14 ` Andrew Morton
2008-06-04 17:44   ` Oleg Nesterov [this message]
2008-06-23 20:40 ` Andrew Morton
2008-06-23 20:47   ` Andrew Morton
2008-06-23 20:52     ` Andrew Morton
2008-06-23 21:36       ` Rafael J. Wysocki
2008-06-23 21:52         ` Andrew Morton
2008-06-24 13:42       ` Oleg Nesterov
2008-06-24 20:51         ` Rafael J. Wysocki

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=20080604174447.GA10284@tv-sign.ru \
    --to=oleg@tv-sign.ru \
    --cc=akpm@linux-foundation.org \
    --cc=ebiederm@xmission.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=roland@redhat.com \
    --cc=torvalds@linux-foundation.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 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.