All of lore.kernel.org
 help / color / mirror / Atom feed
* [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
* [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.