public inbox for linux-newbie@vger.kernel.org
 help / color / mirror / Atom feed
* Copy-on-Write
@ 2008-02-06  5:49 Rick Brown
  2008-02-06 11:00 ` Copy-on-Write Manish Katiyar
  2008-02-07 15:30 ` Copy-on-Write Mulyadi Santosa
  0 siblings, 2 replies; 9+ messages in thread
From: Rick Brown @ 2008-02-06  5:49 UTC (permalink / raw)
  To: kernelnewbies, linux-newbie

Hi,

I had read that the operating systems that use copy-on-write mechanism
for fork(), it is better if they deliberately allow the CHILD to run
first.

This would be better because in 99% of the cases child will call
exec() and the new address space will be allocated. Instead if the
parent is executes first, an unnecessary copy of the pages is made (if
parents writes) and later on when child executes, a fresh address
space is executed.

So in linux, is a child run first or the parent? Can we rely on this
information?

TIA

Rick
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

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

* Re: Copy-on-Write
  2008-02-06  5:49 Copy-on-Write Rick Brown
@ 2008-02-06 11:00 ` Manish Katiyar
  2008-02-06 12:33   ` Copy-on-Write Rajat Jain
  2008-02-07 15:30 ` Copy-on-Write Mulyadi Santosa
  1 sibling, 1 reply; 9+ messages in thread
From: Manish Katiyar @ 2008-02-06 11:00 UTC (permalink / raw)
  To: Rick Brown; +Cc: kernelnewbies, linux-newbie

On Feb 6, 2008 11:19 AM, Rick Brown <rick.brown.3@gmail.com> wrote:
> Hi,
>
> I had read that the operating systems that use copy-on-write mechanism
> for fork(), it is better if they deliberately allow the CHILD to run
> first.
>
> This would be better because in 99% of the cases child will call
> exec() and the new address space will be allocated. Instead if the
> parent is executes first, an unnecessary copy of the pages is made (if
> parents writes) and later on when child executes, a fresh address
> space is executed.
>
> So in linux, is a child run first or the parent? Can we rely on this
> information?

No with fork() it is not guaranteed.......however if you use vfork()
child is guaranteed to run first......

>
> TIA
>
> Rick
>
> --
> To unsubscribe from this list: send an email with
> "unsubscribe kernelnewbies" to ecartis@nl.linux.org
> Please read the FAQ at http://kernelnewbies.org/FAQ
>
>



-- 
Thanks & Regards,
********************************************
Manish Katiyar  ( http://mkatiyar.googlepages.com )
3rd Floor, Fair Winds Block
EGL Software Park
Off Intermediate Ring Road
Bangalore 560071, India
***********************************************
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

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

* RE: Copy-on-Write
  2008-02-06 11:00 ` Copy-on-Write Manish Katiyar
@ 2008-02-06 12:33   ` Rajat Jain
  2008-02-06 12:41     ` Copy-on-Write Manish Katiyar
  2008-02-06 13:17     ` Copy-on-Write Daniel Cheng
  0 siblings, 2 replies; 9+ messages in thread
From: Rajat Jain @ 2008-02-06 12:33 UTC (permalink / raw)
  To: Manish Katiyar, Rick Brown; +Cc: kernelnewbies, linux-newbie


Hi,

>> 
>> I had read that the operating systems that use copy-on-write
>> mechanism for fork(), it is better if they deliberately allow the
>> CHILD to run first. 
>> 
>> This would be better because in 99% of the cases child will call
>> exec() and the new address space will be allocated. Instead if the
>> parent is executes first, an unnecessary copy of the pages is made
>> (if parents writes) and later on when child executes, a fresh
>> address space is executed. 
>> 
>> So in linux, is a child run first or the parent? Can we rely on this
>> information?
> 
> No with fork() it is not guaranteed.......however if you use vfork()
> child is guaranteed to run first......
> 

So as the author says, isn't running child first a good idea that needs to be implemented?

Thanks,

Rajat
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

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

* Re: Copy-on-Write
  2008-02-06 12:33   ` Copy-on-Write Rajat Jain
@ 2008-02-06 12:41     ` Manish Katiyar
  2008-02-06 13:17     ` Copy-on-Write Daniel Cheng
  1 sibling, 0 replies; 9+ messages in thread
From: Manish Katiyar @ 2008-02-06 12:41 UTC (permalink / raw)
  To: Rajat Jain; +Cc: Rick Brown, kernelnewbies, linux-newbie

On Feb 6, 2008 6:03 PM, Rajat Jain <Rajat.Jain@infogain.com> wrote:
>
> Hi,
>
> >>
> >> I had read that the operating systems that use copy-on-write
> >> mechanism for fork(), it is better if they deliberately allow the
> >> CHILD to run first.
> >>
> >> This would be better because in 99% of the cases child will call
> >> exec() and the new address space will be allocated. Instead if the
> >> parent is executes first, an unnecessary copy of the pages is made
> >> (if parents writes) and later on when child executes, a fresh
> >> address space is executed.
> >>
> >> So in linux, is a child run first or the parent? Can we rely on this
> >> information?
> >
> > No with fork() it is not guaranteed.......however if you use vfork()
> > child is guaranteed to run first......
> >
>
> So as the author says, isn't running child first a good idea that needs to be implemented?
>

Not sure......I am getting a bit confused.....If implemented will
there be any issues in case of backward compatibility ?? ... For
example what will happen to daemon programs where typically parent
process exits after a fork() and rest of the code is taken care by the
child . In that case will there be an issue ???


> Thanks,
>
> Rajat
>



-- 
Thanks & Regards,
********************************************
Manish Katiyar  ( http://mkatiyar.googlepages.com )
3rd Floor, Fair Winds Block
EGL Software Park
Off Intermediate Ring Road
Bangalore 560071, India
***********************************************
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

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

* Re: Copy-on-Write
  2008-02-06 12:33   ` Copy-on-Write Rajat Jain
  2008-02-06 12:41     ` Copy-on-Write Manish Katiyar
@ 2008-02-06 13:17     ` Daniel Cheng
  1 sibling, 0 replies; 9+ messages in thread
From: Daniel Cheng @ 2008-02-06 13:17 UTC (permalink / raw)
  To: linux-newbie; +Cc: kernelnewbies

Rajat Jain wrote:
[...]
> 
> So as the author says, isn't running child first a good idea that needs to be implemented?

This have been discussed for a few times in lkml. The actual behavior
have been change back and fore for a few times.

You should never depend on this implementation detail for not doing
process synchronization.

> 
> Thanks,
> 
> Rajat
> -

-- 

-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

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

* Re: Copy-on-Write
  2008-02-06  5:49 Copy-on-Write Rick Brown
  2008-02-06 11:00 ` Copy-on-Write Manish Katiyar
@ 2008-02-07 15:30 ` Mulyadi Santosa
  2008-02-07 23:46   ` Copy-on-Write Brandon Philips
  1 sibling, 1 reply; 9+ messages in thread
From: Mulyadi Santosa @ 2008-02-07 15:30 UTC (permalink / raw)
  To: Rick Brown; +Cc: kernelnewbies, linux-newbie

Hi....

On Feb 6, 2008 12:49 PM, Rick Brown <rick.brown.3@gmail.com> wrote:
> So in linux, is a child run first or the parent? Can we rely on this
> information?

Hm, this might be the answer:
http://lxr.linux.no/linux/kernel/sched.c#L1663

it says:
unsigned int __read_mostly sysctl_sched_child_runs_first = 1;

and I guess it has relationship with certain /proc or /sys entry.

regards,

Mulyadi.
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

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

* Re: Copy-on-Write
  2008-02-07 15:30 ` Copy-on-Write Mulyadi Santosa
@ 2008-02-07 23:46   ` Brandon Philips
  2008-02-08  2:11     ` Copy-on-Write Renê
       [not found]     ` <5f9618380802071809v24f2be47xc9aea8664a8f8488@mail.gmail.com>
  0 siblings, 2 replies; 9+ messages in thread
From: Brandon Philips @ 2008-02-07 23:46 UTC (permalink / raw)
  To: Mulyadi Santosa; +Cc: Rick Brown, kernelnewbies, linux-newbie

On 22:30 Thu 07 Feb 2008, Mulyadi Santosa wrote:
> On Feb 6, 2008 12:49 PM, Rick Brown <rick.brown.3@gmail.com> wrote:
> > So in linux, is a child run first or the parent? Can we rely on this
> > information?
> 
> Hm, this might be the answer:
> http://lxr.linux.no/linux/kernel/sched.c#L1663
> 
> it says:
> unsigned int __read_mostly sysctl_sched_child_runs_first = 1;
> 
> and I guess it has relationship with certain /proc or /sys entry.

 $ sysctl -w kernel.sched_child_runs_first=0

Also available here: /proc/sys/kernel/sched_child_runs_first
  
Cheers,

	Brandon
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

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

* Re: Copy-on-Write
  2008-02-07 23:46   ` Copy-on-Write Brandon Philips
@ 2008-02-08  2:11     ` Renê
       [not found]     ` <5f9618380802071809v24f2be47xc9aea8664a8f8488@mail.gmail.com>
  1 sibling, 0 replies; 9+ messages in thread
From: Renê @ 2008-02-08  2:11 UTC (permalink / raw)
  To: Linux Kernel Newbie

What kernel version did you get this code?

I looked at 2.6.22.1 (my kernel version) and found this piece of code:

/*
 * wake_up_new_task - wake up a newly created task for the first time.
  *
 * This function will do some initial scheduler statistics housekeeping
 * that must be done for every newly created context, then puts the task
 * on the runqueue and wakes it.
 */
void fastcall wake_up_new_task(struct task_struct *p, unsigned long clone_flags)
 {
       ......
       if (likely(cpu == this_cpu)) {
                if (!(clone_flags & CLONE_VM)) {
                        /*
                         * The VM isn't cloned, so we're in a good position to
                          * do child-runs-first in anticipation of an exec. This
                         * usually avoids a lot of COW overhead.
                         */
                        if (unlikely(!current->array))
                                 __activate_task(p, rq);
                        else {
                                ....
                        }
                        set_need_resched();
                } else
                         /* Run child last */
                        __activate_task(p, rq);

The variable ...sysctl_sched_child_runs
_first it's not present, such as /sys relationship..... Perhaps was
removed from oldest version, anybody know about that?

Cheers;

Renê
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

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

* Re: Copy-on-Write
       [not found]     ` <5f9618380802071809v24f2be47xc9aea8664a8f8488@mail.gmail.com>
@ 2008-02-13  5:44       ` Brandon Philips
  0 siblings, 0 replies; 9+ messages in thread
From: Brandon Philips @ 2008-02-13  5:44 UTC (permalink / raw)
  To: Renê; +Cc: linux-newbie

On 00:09 Fri 08 Feb 2008, Renê wrote:
> What kernel version did you get this code?

It exists in 2.6.23+ IIRC.  Poke around at the git-log for
kernel/sched.c

Cheers,

	Brandon

> On Feb 7, 2008 9:46 PM, Brandon Philips <brandon@ifup.org> wrote:
> > On 22:30 Thu 07 Feb 2008, Mulyadi Santosa wrote:
> > > On Feb 6, 2008 12:49 PM, Rick Brown <rick.brown.3@gmail.com> wrote:
> > > > So in linux, is a child run first or the parent? Can we rely on this
> > > > information?
> > >
> > > Hm, this might be the answer:
> > > http://lxr.linux.no/linux/kernel/sched.c#L1663
> > >
> > > it says:
> > > unsigned int __read_mostly sysctl_sched_child_runs_first = 1;
> > >
> > > and I guess it has relationship with certain /proc or /sys entry.
> >
> >  $ sysctl -w kernel.sched_child_runs_first=0
> >
> > Also available here: /proc/sys/kernel/sched_child_runs_first
> >
> > Cheers,
> >
> >        Brandon
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

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

end of thread, other threads:[~2008-02-13  5:44 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-02-06  5:49 Copy-on-Write Rick Brown
2008-02-06 11:00 ` Copy-on-Write Manish Katiyar
2008-02-06 12:33   ` Copy-on-Write Rajat Jain
2008-02-06 12:41     ` Copy-on-Write Manish Katiyar
2008-02-06 13:17     ` Copy-on-Write Daniel Cheng
2008-02-07 15:30 ` Copy-on-Write Mulyadi Santosa
2008-02-07 23:46   ` Copy-on-Write Brandon Philips
2008-02-08  2:11     ` Copy-on-Write Renê
     [not found]     ` <5f9618380802071809v24f2be47xc9aea8664a8f8488@mail.gmail.com>
2008-02-13  5:44       ` Copy-on-Write Brandon Philips

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox