public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Copy on write and page initialization
@ 2009-02-24  4:50 sidc7
  2009-02-24  9:17 ` Nick Piggin
  0 siblings, 1 reply; 4+ messages in thread
From: sidc7 @ 2009-02-24  4:50 UTC (permalink / raw)
  To: linux-kernel


Hi,

As far as I understand, Linux uses the COW optimization so parent and child
process share the same address space, till one of them writes to it, at
which point the kernel creates a copy of the page written to. This is done
through the function do_wp_page which in turn calls cow_user_page. 

I created a simple program, where the child and parent process write to a
variable differently. I have instrumented the kernel at cow_user_page. On
inserting the kprobe module and running the fork program, I do not get a
call to cow_user_page. I had several questions:
1. Does this mean that the kernel is not doing COW optimization? 
2. Is COW enabled by default, if not, how do we turn it on? 
3. Any other point in the kernel, where cow is done, other than
cow_user_page?

Regarding page initialization, if I understand it correctly, the kernel
calls get_zeroed_page when it has to allocated a zeroed page, once again in
my kernel module, I have probes the kernel at get_zeroed_page, but get no
calls, even on running the system for a long time, any other place where the
kernel gets zeroed pages to return the applications ?



Any help would be appreciated, thanks in advance
SC
-- 
View this message in context: http://www.nabble.com/Copy-on-write-and-page-initialization-tp22175803p22175803.html
Sent from the linux-kernel mailing list archive at Nabble.com.


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

* Re: Copy on write and page initialization
  2009-02-24  4:50 Copy on write and page initialization sidc7
@ 2009-02-24  9:17 ` Nick Piggin
  2009-02-24  9:47   ` sidc7
  0 siblings, 1 reply; 4+ messages in thread
From: Nick Piggin @ 2009-02-24  9:17 UTC (permalink / raw)
  To: sidc7; +Cc: linux-kernel

On Tuesday 24 February 2009 15:50:05 sidc7 wrote:
> Hi,
>
> As far as I understand, Linux uses the COW optimization so parent and child
> process share the same address space, till one of them writes to it, at

The "address space" is not shared. Ie. the logical memory space is
separate, but it happens that the actual virtual->physical mappings
can be shared due to COW, yes.


> which point the kernel creates a copy of the page written to. This is done
> through the function do_wp_page which in turn calls cow_user_page.

Yes.


> I created a simple program, where the child and parent process write to a
> variable differently. I have instrumented the kernel at cow_user_page. On
> inserting the kprobe module and running the fork program, I do not get a
> call to cow_user_page. I had several questions:
> 1. Does this mean that the kernel is not doing COW optimization?

It means it is not breaking COW where you expect.


> 2. Is COW enabled by default, if not, how do we turn it on?

It is.


> 3. Any other point in the kernel, where cow is done, other than
> cow_user_page?

If one process exits before the other writes to it, that condition
will be noticed in do_wp_fault and a copy can be avoided. The kernel
would still be doing the COW optimisation without ever actually
making a copy.


> Regarding page initialization, if I understand it correctly, the kernel
> calls get_zeroed_page when it has to allocated a zeroed page, once again in
> my kernel module, I have probes the kernel at get_zeroed_page, but get no
> calls, even on running the system for a long time, any other place where
> the kernel gets zeroed pages to return the applications ?

No, it doesn't look like it calls get_zeroed_page for userspace memory
allocation. Try alloc_zeroed_user_highpage_movable, alloc_page_vma etc.


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

* Re: Copy on write and page initialization
  2009-02-24  9:17 ` Nick Piggin
@ 2009-02-24  9:47   ` sidc7
  2009-02-26 21:26     ` Frank Ch. Eigler
  0 siblings, 1 reply; 4+ messages in thread
From: sidc7 @ 2009-02-24  9:47 UTC (permalink / raw)
  To: linux-kernel


I figured why it was not breaking, cow_user_page is inlined hence it wont
break there

For the initialization, do you think, instrumenting at __alloc_pages using
jprobes and checking the gfp_flags to have GFP_ZERO will work? I did this,
and I could see a bunch of page initializations

Thanks once again
SC



Nick Piggin wrote:
> 
> On Tuesday 24 February 2009 15:50:05 sidc7 wrote:
>> Hi,
>>
>> As far as I understand, Linux uses the COW optimization so parent and
>> child
>> process share the same address space, till one of them writes to it, at
> 
> The "address space" is not shared. Ie. the logical memory space is
> separate, but it happens that the actual virtual->physical mappings
> can be shared due to COW, yes.
> 
> 
>> which point the kernel creates a copy of the page written to. This is
>> done
>> through the function do_wp_page which in turn calls cow_user_page.
> 
> Yes.
> 
> 
>> I created a simple program, where the child and parent process write to a
>> variable differently. I have instrumented the kernel at cow_user_page. On
>> inserting the kprobe module and running the fork program, I do not get a
>> call to cow_user_page. I had several questions:
>> 1. Does this mean that the kernel is not doing COW optimization?
> 
> It means it is not breaking COW where you expect.
> 
> 
>> 2. Is COW enabled by default, if not, how do we turn it on?
> 
> It is.
> 
> 
>> 3. Any other point in the kernel, where cow is done, other than
>> cow_user_page?
> 
> If one process exits before the other writes to it, that condition
> will be noticed in do_wp_fault and a copy can be avoided. The kernel
> would still be doing the COW optimisation without ever actually
> making a copy.
> 
> 
>> Regarding page initialization, if I understand it correctly, the kernel
>> calls get_zeroed_page when it has to allocated a zeroed page, once again
>> in
>> my kernel module, I have probes the kernel at get_zeroed_page, but get no
>> calls, even on running the system for a long time, any other place where
>> the kernel gets zeroed pages to return the applications ?
> 
> No, it doesn't look like it calls get_zeroed_page for userspace memory
> allocation. Try alloc_zeroed_user_highpage_movable, alloc_page_vma etc.
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" 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.tux.org/lkml/
> 
> 

-- 
View this message in context: http://www.nabble.com/Copy-on-write-and-page-initialization-tp22175803p22178976.html
Sent from the linux-kernel mailing list archive at Nabble.com.


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

* Re: Copy on write and page initialization
  2009-02-24  9:47   ` sidc7
@ 2009-02-26 21:26     ` Frank Ch. Eigler
  0 siblings, 0 replies; 4+ messages in thread
From: Frank Ch. Eigler @ 2009-02-26 21:26 UTC (permalink / raw)
  To: sidc7; +Cc: linux-kernel

sidc7 <siddhartha.chhabra@gmail.com> writes:

> I figured why it was not breaking, cow_user_page is inlined hence it wont
> break there [...]

There is good chance a systemtap can find it for you despite inlining:

# stap -e 'probe kernel.function("cow_user_page") { print_backtrace() }'


- FChE

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

end of thread, other threads:[~2009-02-26 21:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-24  4:50 Copy on write and page initialization sidc7
2009-02-24  9:17 ` Nick Piggin
2009-02-24  9:47   ` sidc7
2009-02-26 21:26     ` Frank Ch. Eigler

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