* [KJ] clear_page() and copy_page()
@ 2007-01-28 8:48 Robert P. J. Day
2007-01-28 15:51 ` Richard Knutsson
` (4 more replies)
0 siblings, 5 replies; 7+ messages in thread
From: Robert P. J. Day @ 2007-01-28 8:48 UTC (permalink / raw)
To: kernel-janitors
there are numerous instances of calls to memset() of the form
memset(<addr>, 0, PAGE_SIZE);
to clear a single page, as you can see sprinkled throughout the output
here (obviously, not every line of output represents one of those
cases, the grep pattern is overly general):
$ grep -r "memset.*PAGE_SIZE" .
however, most architectures define a more convenient clear_page()
macro in a "page.h" header file thusly:
$ grep -r "#define clear_page" include
include/asm-frv/page.h:#define clear_page(pgaddr) memset((pgaddr), 0, PAGE_SIZE)
include/asm-v850/page.h:#define clear_page(page) memset ((void *)(page), 0, PAGE_SIZE)
include/asm-parisc/page.h:#define clear_page(page) memset((void *)(page), 0, PAGE_SIZE)
...
and so on, which suggests the obvious cleanup that those calls to
memset() should be replaced by calls to clear_page(). is it really
that simple? well, maybe not.
from include/asm-i386/page.h:
=============================
#ifdef CONFIG_X86_USE_3DNOW
#include <asm/mmx.h>
#define clear_page(page) mmx_clear_page((void *)(page))
#define copy_page(to,from) mmx_copy_page(to,from)
#else
/*
* On older X86 processors it's not a win to use MMX here it seems.
* Maybe the K6-III ?
*/
#define clear_page(page) memset((void *)(page), 0, PAGE_SIZE)
#define copy_page(to,from) memcpy((void *)(to), (void *)(from),
PAGE_SIZE)
#endif
=============================
so what are the issues involved with that kind of cleanup?
similarly, there are a (smaller) number of calls of the form
memcpy(<src>, <dest>, PAGE_SIZE);
as you can see:
$ grep -r "memcpy.*PAGE_SIZE"
even though most arches also define the equivalent "copy_page" macro:
$ grep -r "#define copy_page" include
same questions here -- any issues with standardizing on calls to
copy_page()?
rday
p.s. obviously, rewriting to use those simpler macros would imply
that *every* architecture would need to define those macros, and i
don't think that's the case at the moment.
--
====================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry
Waterloo, Ontario, CANADA
http://www.fsdev.dreamhosters.com/wiki/index.php?title=Main_Page
====================================
_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [KJ] clear_page() and copy_page()
2007-01-28 8:48 [KJ] clear_page() and copy_page() Robert P. J. Day
@ 2007-01-28 15:51 ` Richard Knutsson
2007-01-28 16:09 ` Robert P. J. Day
` (3 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Richard Knutsson @ 2007-01-28 15:51 UTC (permalink / raw)
To: kernel-janitors
Robert P. J. Day wrote:
> there are numerous instances of calls to memset() of the form
>
> memset(<addr>, 0, PAGE_SIZE);
>
> to clear a single page, as you can see sprinkled throughout the output
> here (obviously, not every line of output represents one of those
> cases, the grep pattern is overly general):
>
[snip]
> same questions here -- any issues with standardizing on calls to
> copy_page()?
>
> rday
>
> p.s. obviously, rewriting to use those simpler macros would imply
> that *every* architecture would need to define those macros, and i
> don't think that's the case at the moment.
>
include]$ grep -L clear_page asm-*/page.h
asm-generic/page.h
asm-powerpc/page.h
include]$ grep -L copy_page asm-*/page.h
asm-generic/page.h
asm-powerpc/page.h
so it seems it only needs to be defined on PowerPC. But what confuses me is:
...
asm-x86_64/page.h:48:void clear_page(void *);
asm-x86_64/page.h:51:#define clear_user_page(page, vaddr, pg) clear_page(page)
...
Is x86_64 setting all its memory to zero before giving it to the caller, or what?
Well, just my 2 cents...
Richard Knutsson
_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [KJ] clear_page() and copy_page()
2007-01-28 8:48 [KJ] clear_page() and copy_page() Robert P. J. Day
2007-01-28 15:51 ` Richard Knutsson
@ 2007-01-28 16:09 ` Robert P. J. Day
2007-01-28 16:19 ` Robert P. J. Day
` (2 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Robert P. J. Day @ 2007-01-28 16:09 UTC (permalink / raw)
To: kernel-janitors
On Sun, 28 Jan 2007, Richard Knutsson wrote:
> Robert P. J. Day wrote:
> > there are numerous instances of calls to memset() of the form
> >
> > memset(<addr>, 0, PAGE_SIZE);
> >
> > to clear a single page, as you can see sprinkled throughout the output
> > here (obviously, not every line of output represents one of those
> > cases, the grep pattern is overly general):
> >
> [snip]
> > same questions here -- any issues with standardizing on calls to
> > copy_page()?
> > rday
> >
> > p.s. obviously, rewriting to use those simpler macros would imply
> > that *every* architecture would need to define those macros, and i
> > don't think that's the case at the moment.
> >
>
> include]$ grep -L clear_page asm-*/page.h
> asm-generic/page.h
> asm-powerpc/page.h
> include]$ grep -L copy_page asm-*/page.h
> asm-generic/page.h
> asm-powerpc/page.h
>
> so it seems it only needs to be defined on PowerPC. But what confuses me is:
> ...
> asm-x86_64/page.h:48:void clear_page(void *);
> asm-x86_64/page.h:51:#define clear_user_page(page, vaddr, pg)
> clear_page(page)
> ...
>
> Is x86_64 setting all its memory to zero before giving it to the caller, or
> what?
i can check with the appropriate people. i guess the major issue is
whether the semantics of clear_page() are *meant* to be identical to a
single page-sized call to memset(). technically, of course, they
don't *have* to be -- clear_page() could always be defined to do
something extra, but it doesn't seem like that's happening here, so a
simple substitution would appear to be a valid cleanup, yes?
rday
--
====================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry
Waterloo, Ontario, CANADA
http://www.fsdev.dreamhosters.com/wiki/index.php?title=Main_Page
====================================
_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [KJ] clear_page() and copy_page()
2007-01-28 8:48 [KJ] clear_page() and copy_page() Robert P. J. Day
2007-01-28 15:51 ` Richard Knutsson
2007-01-28 16:09 ` Robert P. J. Day
@ 2007-01-28 16:19 ` Robert P. J. Day
2007-01-28 17:41 ` Richard Knutsson
2007-01-29 11:42 ` Robert P. J. Day
4 siblings, 0 replies; 7+ messages in thread
From: Robert P. J. Day @ 2007-01-28 16:19 UTC (permalink / raw)
To: kernel-janitors
On Sun, 28 Jan 2007, Richard Knutsson wrote:
> include]$ grep -L clear_page asm-*/page.h
> asm-generic/page.h
> asm-powerpc/page.h
> include]$ grep -L copy_page asm-*/page.h
> asm-generic/page.h
> asm-powerpc/page.h
>
> so it seems it only needs to be defined on PowerPC.
powerpc should be OK since the files are named page_32.h and
page_64.h, not just page.h. so i think we're good there.
> But what confuses me is:
> ...
> asm-x86_64/page.h:48:void clear_page(void *);
> asm-x86_64/page.h:51:#define clear_user_page(page, vaddr, pg)
> clear_page(page)
> ...
>
> Is x86_64 setting all its memory to zero before giving it to the
> caller, or what?
i'm not sure what the problem is here. clear_page() still exists and
accepts a single page address. what exactly is your concern?
rday
--
====================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry
Waterloo, Ontario, CANADA
http://www.fsdev.dreamhosters.com/wiki/index.php?title=Main_Page
====================================
_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [KJ] clear_page() and copy_page()
2007-01-28 8:48 [KJ] clear_page() and copy_page() Robert P. J. Day
` (2 preceding siblings ...)
2007-01-28 16:19 ` Robert P. J. Day
@ 2007-01-28 17:41 ` Richard Knutsson
2007-01-29 11:42 ` Robert P. J. Day
4 siblings, 0 replies; 7+ messages in thread
From: Richard Knutsson @ 2007-01-28 17:41 UTC (permalink / raw)
To: kernel-janitors
Robert P. J. Day wrote:
> On Sun, 28 Jan 2007, Richard Knutsson wrote:
>
>
>> Robert P. J. Day wrote:
>>
>>> there are numerous instances of calls to memset() of the form
>>>
>>> memset(<addr>, 0, PAGE_SIZE);
>>>
>>> to clear a single page, as you can see sprinkled throughout the output
>>> here (obviously, not every line of output represents one of those
>>> cases, the grep pattern is overly general):
>>>
>>>
>> [snip]
>>
>>> same questions here -- any issues with standardizing on calls to
>>> copy_page()?
>>> rday
>>>
>>> p.s. obviously, rewriting to use those simpler macros would imply
>>> that *every* architecture would need to define those macros, and i
>>> don't think that's the case at the moment.
>>>
>>>
>> include]$ grep -L clear_page asm-*/page.h
>> asm-generic/page.h
>> asm-powerpc/page.h
>> include]$ grep -L copy_page asm-*/page.h
>> asm-generic/page.h
>> asm-powerpc/page.h
>>
>> so it seems it only needs to be defined on PowerPC. But what confuses me is:
>> ...
>> asm-x86_64/page.h:48:void clear_page(void *);
>> asm-x86_64/page.h:51:#define clear_user_page(page, vaddr, pg)
>> clear_page(page)
>> ...
>>
>> Is x86_64 setting all its memory to zero before giving it to the caller, or
>> what?
>>
>
> i can check with the appropriate people. i guess the major issue is
> whether the semantics of clear_page() are *meant* to be identical to a
> single page-sized call to memset(). technically, of course, they
>
The only reason against it, would be if it is meant the address has to
be a multiple of the PAGE_SIZE, but I find that unlikely.
> don't *have* to be -- clear_page() could always be defined to do
> something extra, but it doesn't seem like that's happening here, so a
> simple substitution would appear to be a valid cleanup, yes?
>
I would think so. Just a bit concerned that PowerPC does not have it
defined. I would rather see it defined in asm-generic and then if the
arch has a better solution, it just undef the generic one. But that is
just my opinion :)
Richard Knutsson
_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors
^ permalink raw reply [flat|nested] 7+ messages in thread* [KJ] clear_page() and copy_page()
2007-01-28 8:48 [KJ] clear_page() and copy_page() Robert P. J. Day
` (3 preceding siblings ...)
2007-01-28 17:41 ` Richard Knutsson
@ 2007-01-29 11:42 ` Robert P. J. Day
4 siblings, 0 replies; 7+ messages in thread
From: Robert P. J. Day @ 2007-01-29 11:42 UTC (permalink / raw)
To: kernel-janitors
i've updated the wiki page related to rewriting source in terms of
the above two macros.
http://www.fsdev.dreamhosters.com/wiki/index.php?title=Clear_page_copy_page
rday
--
====================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry
Waterloo, Ontario, CANADA
http://www.fsdev.dreamhosters.com/wiki/index.php?title=Main_Page
====================================
_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors
^ permalink raw reply [flat|nested] 7+ messages in thread
* [KJ] "clear_page" and "copy_page"?
@ 2007-03-08 20:39 Robert P. J. Day
0 siblings, 0 replies; 7+ messages in thread
From: Robert P. J. Day @ 2007-03-08 20:39 UTC (permalink / raw)
To: kernel-janitors
i asked about this once upon a time, but can anyone clarify whether
it's possible to effect the following replacements:
1) memset(addr, 0, PAGE_SIZE) --> clear_page(addr)
2) memcpy(to, from, PAGE_SIZE) --> copy_page(to, from)
the only issues i can see is if clear_page() and/or copy_page() have
some special semantics above and beyond simple memset and/or memcpy.
perhaps an alignment requirement or something.
it's fairly clear that every architecture *must* implement both
clear_page() and copy_page(). so is this a possible cleanup? if so,
i can add a page to the wiki.
rday
_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2007-03-08 20:39 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-01-28 8:48 [KJ] clear_page() and copy_page() Robert P. J. Day
2007-01-28 15:51 ` Richard Knutsson
2007-01-28 16:09 ` Robert P. J. Day
2007-01-28 16:19 ` Robert P. J. Day
2007-01-28 17:41 ` Richard Knutsson
2007-01-29 11:42 ` Robert P. J. Day
-- strict thread matches above, loose matches on Subject: below --
2007-03-08 20:39 [KJ] "clear_page" and "copy_page"? Robert P. J. Day
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.