mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Robert P. J. Day" <rpjday@mindspring.com>
To: Folkert van Heusden <folkert@vanheusden.com>
Cc: Paul Mundt <lethal@linux-sh.org>,
	Arjan van de Ven <arjan@infradead.org>,
	Denis Vlasenko <vda.linux@googlemail.com>,
	Linux kernel mailing list <linux-kernel@vger.kernel.org>
Subject: Re: replace "memset(...,0,PAGE_SIZE)" calls with "clear_page()"?
Date: Mon, 1 Jan 2007 03:33:47 -0500 (EST)	[thread overview]
Message-ID: <Pine.LNX.4.64.0701010332130.3084@localhost.localdomain> (raw)
In-Reply-To: <20070101015932.GP13521@vanheusden.com>

On Mon, 1 Jan 2007, Folkert van Heusden wrote:

> > > regarding alignment that don't allow clear_page() to be used
> > > copy_page() in the memcpy() case), but it's going to need a lot of
>
> Maybe these optimalisations should be in the coding style docs?

i was thinking of submitting the following as a new "chapter" for the
doc -- it would address *some* of these issues:


Chapter XX:  Page-related memory management

  The following functions and macro definitions are available via
include/linux/gfp.h for page-based memory management:

  struct page *alloc_pages(gfp_mask, order);
  unsigned long __get_free_pages(gfp_mask, order);
  unsigned long get_zeroed_page(gfp_mask);
  void __free_pages(struct page *page, order);
  void free_pages(unsigned long addr, order);

  #define alloc_page(gfp_mask) alloc_pages(gfp_mask, 0)
  #define __get_free_page(gfp_mask) __get_free_pages((gfp_mask),0)
  #define __free_page(page) __free_pages((page), 0)
  #define free_page(addr) free_pages((addr),0)

  #define __get_dma_pages(gfp_mask, order) \
                __get_free_pages((gfp_mask) | GFP_DMA,(order))

  Given the above, some basic suggestions for page-based memory management:

 (a) If you need to allocate or free a single page, use the single page
     version of the routine/macro, rather than calling the multi-page
     version with an order value of zero, such as:

	alloc_pages(gfp_mask, 0);	/* no */
	alloc_page(gfp_mask);		/* better */

 (b) If you need to allocate a single zeroed page by logical address,
     use get_zeroed_page(), rather than __get_free_page() followed
     by a call to memset() to clear that page.

 (c) If you need to specifically allocate some DMA pages, use the
     __get_dma_pages() macro, as in:

	__get_free_pages(GFP_KERNEL|GFP_DMA, order)	/* no */
	__get_dma_pages(GFP_KERNEL, order)		/* better */

 (d) If you need to clear (zero) a page, be aware that every
     architecture defines a clear_page() routine, either as a macro
     in include/<arch>/page.h or as an assembler routine.

     You should check if it's appropriate to use that routine/macro,
     rather than making an explicit call to memset(...,0, PAGE_SIZE).

  reply	other threads:[~2007-01-01  8:38 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-29  6:16 Robert P. J. Day
2006-12-30 20:49 ` Denis Vlasenko
2006-12-30 22:08   ` Robert P. J. Day
2006-12-30 22:40     ` Denis Vlasenko
2007-01-03  6:23       ` dean gaudet
2006-12-30 22:45     ` Arjan van de Ven
2006-12-30 23:04       ` Robert P. J. Day
2006-12-31 18:39         ` Paul Mundt
2006-12-31 19:04           ` Robert P. J. Day
2007-01-01  1:59             ` Folkert van Heusden
2007-01-01  8:33               ` Robert P. J. Day [this message]
2007-01-01 10:14                 ` Arjan van de Ven
2007-01-01 10:27                   ` Robert P. J. Day
2007-01-01 19:05                     ` Dave Jones
2007-01-01  8:42               ` Paul Mundt
2007-01-01 17:09                 ` Randy Dunlap
2006-12-31 13:39       ` Folkert van Heusden
2006-12-31 13:45         ` Arjan van de Ven
2006-12-31 16:39           ` Robert P. J. Day
2006-12-31 17:43             ` Arjan van de Ven
2007-01-03 13:20               ` Robert P. J. Day

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=Pine.LNX.4.64.0701010332130.3084@localhost.localdomain \
    --to=rpjday@mindspring.com \
    --cc=arjan@infradead.org \
    --cc=folkert@vanheusden.com \
    --cc=lethal@linux-sh.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=vda.linux@googlemail.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

all inboxes | Powered by JetHome®