mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@osdl.org>
To: davidm@hpl.hp.com
Cc: davidm@napali.hpl.hp.com, davej@redhat.com, mpm@selenic.com,
	linux-kernel@vger.kernel.org
Subject: Re: Fw: potential /dev/urandom scalability improvement
Date: Fri, 26 Mar 2004 10:49:04 -0800	[thread overview]
Message-ID: <20040326104904.59f7a156.akpm@osdl.org> (raw)
In-Reply-To: <16484.29095.842735.102236@napali.hpl.hp.com>

David Mosberger <davidm@napali.hpl.hp.com> wrote:
>
> >>>>> On Fri, 26 Mar 2004 11:06:19 +0000, Dave Jones <davej@redhat.com> said:
> 
>   Dave> On Thu, Mar 25, 2004 at 06:00:14PM -0800, Andrew Morton wrote:
>   >> +static inline void prefetch_range(void *addr, size_t len) +{
>   >> +#ifdef ARCH_HAS_PREFETCH + char *cp; + char *end = addr + len; +
>   >> + for (cp = addr; cp < end; cp += PREFETCH_STRIDE) +
>   >> prefetch(cp); +#endif +} + #endif
> 
>   Dave> I think this may be dangerous on some CPUs, if may prefetch
>   Dave> past the end of the buffer. Ie, if PREFETCH_STRIDE was 32, and
>   Dave> len was 65, we'd end up prefetching 65->97. As well as being
>   Dave> wasteful to cachelines, this can crash if theres for eg
>   Dave> nothing mapped after the next page boundary.
> 
> Huh?  It only ever prefetches addresses that are _within_ the
> specified buffer.  Of course it will prefetch entire cachelines, but I
> hope you're not worried about cachlines crossing page-boundaries! ;-))
> 

But the start address which is fed into prefetch_range() may not be
cacheline-aligned.  So if appropriately abused, a prefetch_range() could
wander off the end of the user's buffer and into a new page.

I think this gets it right, but I probably screwed something up.

static inline void prefetch_range(void *addr, size_t len)
{
#ifdef ARCH_HAS_PREFETCH
	char *cp;
	unsigned long end;

	end = ((unsigned long)addr + len + PREFETCH_STRIDE - 1);
	end &= ~(PREFETCH_STRIDE - 1);

	for (cp = addr; cp < (char *)end; cp += PREFETCH_STRIDE)
		prefetch(cp);
#endif
}


  parent reply	other threads:[~2004-03-26 18:50 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20040325141923.7080c6f0.akpm@osdl.org>
2004-03-25 22:47 ` Matt Mackall
2004-03-26  1:45   ` David Mosberger
2004-03-26  2:00     ` Andrew Morton
2004-03-26  2:10       ` David Mosberger
2004-03-26  4:07       ` Matt Mackall
2004-03-26  4:19       ` Matt Mackall
2004-03-26  4:51         ` David Mosberger
2004-03-26  5:15           ` Matt Mackall
2004-03-26  5:24             ` David Mosberger
2004-03-26 11:06       ` Dave Jones
2004-03-26 18:08         ` David Mosberger
2004-03-26 18:23           ` Dave Jones
2004-03-26 21:31             ` David Mosberger
2004-03-26 18:49           ` Andrew Morton [this message]
2004-03-26 20:25             ` David Mosberger
2004-03-26 20:33               ` Andrew Morton
2004-03-26 20:45                 ` Arjan van de Ven
2004-03-26 21:17                   ` Andrew Morton
2004-03-27  7:44                     ` Arjan van de Ven
2004-03-26 21:12                 ` David Mosberger
     [not found] <1DLZM-8aK-67@gated-at.bofh.it>
     [not found] ` <1DLZM-8aK-65@gated-at.bofh.it>
     [not found]   ` <1DOE1-20o-17@gated-at.bofh.it>
     [not found]     ` <1DOXn-2k7-5@gated-at.bofh.it>
     [not found]       ` <1DXxI-Z7-39@gated-at.bofh.it>
     [not found]         ` <1E467-6KK-17@gated-at.bofh.it>
     [not found]           ` <1E4IT-7f3-21@gated-at.bofh.it>
2004-03-27  1:29             ` Andi Kleen
2004-03-27 15:48               ` Matt Mackall

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=20040326104904.59f7a156.akpm@osdl.org \
    --to=akpm@osdl.org \
    --cc=davej@redhat.com \
    --cc=davidm@hpl.hp.com \
    --cc=davidm@napali.hpl.hp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mpm@selenic.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®