public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Maxim Kuvyrkov <maxim.kuvyrkov@linaro.org>
To: Andrew Pinski <pinskia@gmail.com>
Cc: Adhemerval Zanella <adhemerval.zanella@linaro.org>,
	GNU C Library <libc-alpha@sourceware.org>
Subject: Re: [libc/string] State of PAGE_COPY_FWD / PAGE_COPY_THRESHOLD
Date: Thu, 10 Nov 2016 07:52:00 -0000	[thread overview]
Message-ID: <FAC7553E-A7FA-4A00-A984-0F2C1D3A2D36@linaro.org> (raw)
In-Reply-To: <CA+=Sn1nEq4mjH0T1+vcdA9N1Vzo8n5DAvaDkzhzNQB-akJVfjw@mail.gmail.com>

> On Nov 10, 2016, at 11:48 AM, Andrew Pinski <pinskia@gmail.com> wrote:
> 
> On Wed, Nov 9, 2016 at 11:39 PM, Maxim Kuvyrkov
> <maxim.kuvyrkov@linaro.org> wrote:
>>> On Nov 1, 2016, at 5:59 PM, Adhemerval Zanella <adhemerval.zanella@linaro.org> wrote:
>>> 
>> ...
>>> $ cat sysdeps/x86/pagecopy.h
>>> 
>>> #define PAGE_SIZE           4096
>>> #define PAGE_COPY_THRESHOLD PAGE_SIZE
>>> 
>>> #define PAGE_COPY_FWD(dstp, srcp, nbytes_left, nbytes)  /* Implement it */
>>> 
>>> It should work on any other architecture as well.  Now the question
>>> is whether this actually does make sense for Linux.  Hurd/mach provided
>>> a syscall (?) to actually copy the pages (vm_copy) which seems to apply
>>> some tricks to avoid full copy pages. By 'linux zero page sharing' are
>>> you referring to KSM (Kernel Samepage Merging)?
>>> 
>>> If so, on a system without a provided kernel interface to work directed
>>> with underlying memory mapping (such as for mach), mem{cpy,set} will
>>> actually need to touch the pages and it will be up to kernel page fault
>>> mechanism to actually handle it (by identifying common pages and adjusting
>>> vma mapping accordingly). And AFAIK this are only enabled on KSM if you
>>> actually madavise the page explicit. So I am not grasping the need to
>>> actually implement page copying on Linux.
>> 
>> Linux kernel has a reserved page filled with zeroes, so it there /were/ a syscall to tell kernel to map N consecutive pages starting at address PTR to that zero page, we could use that in GLIBC for really big memset(0).
>> 
>> A quick investigation shows that there is no such syscall provided by the Linux kernel.  Doesn't mean we can't ask for / implement one.
> 
> And then there would be a COW interrupt on the first write.  Not a
> good idea.  Since most likely you are writing zeros to a big page for
> security reasons before filling it again with other data.

I'm looking at this as a possible performance optimization for a well-known benchmark.  

>   That mean
> each page would need to be copied which is normally slower than
> zeroing in the first place.

It may be like you say, or it may be a significant performance improvement.  I want to see numbers before deciding on how useful this may be.

> 
> COW is only useful when most of the pages will not be written to; it
> is not useful when doing memcpy or memset.  Mainly because you don't
> need to take the overhead of taking an interrupt twice (a system call
> is still an interrupt).


--
Maxim Kuvyrkov
www.linaro.org

  reply	other threads:[~2016-11-10  7:52 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-01  9:28 Maxim Kuvyrkov
2016-11-01 13:59 ` Adhemerval Zanella
2016-11-10  7:39   ` Maxim Kuvyrkov
2016-11-10  7:48     ` Andrew Pinski
2016-11-10  7:52       ` Maxim Kuvyrkov [this message]
2016-11-10  8:01         ` Andrew Pinski
2016-11-10  8:05           ` Andrew Pinski
2016-11-10  8:25             ` Florian Weimer
2016-11-10  8:34               ` Andrew Pinski
2016-11-10  8:55                 ` Andrew Pinski
2016-11-10  9:25                   ` Siddhesh Poyarekar
2016-11-10  9:29                     ` Florian Weimer
2016-11-10  9:34                       ` Siddhesh Poyarekar
2016-11-30 11:18                   ` Siddhesh Poyarekar
2016-11-10  8:26     ` Florian Weimer
2016-11-10  8:27 ` Florian Weimer

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=FAC7553E-A7FA-4A00-A984-0F2C1D3A2D36@linaro.org \
    --to=maxim.kuvyrkov@linaro.org \
    --cc=adhemerval.zanella@linaro.org \
    --cc=libc-alpha@sourceware.org \
    --cc=pinskia@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).