Usenet comp.os.linux.alpha (1997-2013)
 help / color / mirror / Atom feed
From: Jason Stratos Papadopoulos <jasonp@y.glue.umd.edu>
Subject: The case for page coloring
Date: 18 Mar 2001 05:42:10 GMT	[thread overview]
Message-ID: <991hri$udm$1@hecate.umd.edu> (raw)

I recently ran some memory bandwidth tests on a 466MHz DS10 running Redhat
6.2 with kernel 2.4.2, and I don't like the results. 

The figures below seem to imply that even though the L2 cache on the
machine is 2MB, you only get drastically higher bandwidth than main memory
for working sets of size 256k or less. Also, the measured numbers can vary
drastically! Often, recompiling the same program and rerunning produced
numbers 25% smaller.

Is this due to bad page coloring, like the comments below postulate?
If so, how nasty is the hacking required to make the linux kernel do
a better job?

jasonp

/*-------------------------------------------------------------------
 
        uint64 read_array( uint64 *x, int32 size );
 
        reads "size" contiguous bytes from x[]. Returns the number
        of clocks taken.
 
        Measured bandwidth on a 466 MHz Alpha 21264:
 
        size of x[]     clks/iter       MB/s    peak
        32k             5               5932    7456
        64k             5               5932    7456
        128k            11.4            2611    3200
        256k            13.6            2185    3200
        512k            18.6            1598    3200
        1M              24.2            1296    3200
        16M             40.7            732     1300
        
        No difference in loads to the FPU registers.
 
-------------------------------------------------------------------*/
 
 
/*-------------------------------------------------------------------
 
        uint64 read_array_p( uint64 *x, int32 size );
 
        reads "size" contiguous bytes from x[], prefetching
        8 cache lines ahead. Returns the number of clocks taken.
 
        The first version here used a normal prefetch, the ldl
        instruction. Measured bandwidth on a 466 MHz Alpha 21264:
 
        size of x[]     clks/iter       MB/s    peak
        32k             5               5932    7456
        64k             5.1             5839    7456
        128k            ?               ?       3200
        256k            ?               ?       3200
        512k            ?               ?       3200
        1M              ?               ?       3200
        16M             32.0            930     1300
        
        Prefetching evidently allows drastically better memory
        bandwidth out of main memory; it essentially means 25% 
        more read bandwidth for free.
 
        The bandwidth out of L2 varies crazily; on average it 
        looks like the no-prefetching code, but can also be 
        drastically lower or higher. The 128k size varies from
        2000 to 2700 MB/s, and the 1M case varies from 1000 to
        1350 MB/s. This is really disturbing; not only is the real
        bandwidth out of L2 miserably low, but it varies over a
        large range and the access pattern precludes any culprits
        like bad page coloring.
 
        Next, try prefetching using the "load, evict next" instruction,
        ldq. The bandwidth now looks like
 
        size of x[]     clks/iter       MB/s    peak
        32k               same
        64k               same
        128k            9.6             3100    3200
        256k            10.1            2920    3200
        512k            12.1            2455    3200
        1M              17              1755    3200
        16M               same
 
        The measured bandwidth seems more consistent now, and is
        higher than the non-prefetching case by quite a bit. What is it
        about the "evict next" that improves things? There are no dirty
        cache lines to be evicted in this code, so it shouldn't matter
        which of the two 32kB Dcache halves a given line lands in.
 
        Maybe it's the fact that ldq is a 64-bit load and ldl is a 32-bit
        load? Well, ldt is a 64-bit load too (a normal prefetch), and it
        doesn't do much different from the non-prefetched case.
 
        On second thought, it could be bad page coloring that's the culprit.
        There are no dirty cache lines, but if you're measuring L2 latency
        and bad coloring keeps replacing the pages in L2 with other pages,
        then eventually the latency to main memory will start creeping into
        the timings for L2. In any case, it looks like if you keep the 
        working set to 256kB or less you get enormously more bandwidth
        out of L2, at least for memory-limited code. It still varies by
        more than I'd like, though (the figures above occur commonly but
        so do figures that are 20% lower).
 
-------------------------------------------------------------------*/
 
 
/*-------------------------------------------------------------------
 
        uint64 write_array( uint64 *x, int32 size );
 
        writes "size" contiguous bytes to x[]. Returns the number
        of clocks taken.
 
        Measured bandwidth on a 466 MHz Alpha 21264:
 
        size of x[]     clks/iter       MB/s    peak
        32k             6               4965    7456
        64k             6.1             4890    7456
        128k            21.2            1400    3200
        256k            24.5            1213    3200
        512k            34              870     3200
        1M              44.2            674     3200
        16M             73              408     1300
        
        As expected, write bandwidth is a lot lower than read bandwidth
        (now bad page coloring means a writeback *and* a cache reload).
        These figures are a bit pessimistic; other runs yield results up
        to 10% better.
 
-------------------------------------------------------------------*/
 
 
/*-------------------------------------------------------------------
 
        uint64 write_array_p( uint64 *x, int32 size );
 
        writes "size" contiguous bytes to x[], write-hinting 8 lines
        ahead. Returns the number of clocks taken.
 
        Measured bandwidth on a 466 MHz Alpha 21264:
 
        size of x[]     clks/iter       MB/s    peak
        32k             6.75            4418    7456
        64k             6.83            4366    7456
        128k            21.2            1400    3200
        256k            22.3            1330    3200
        512k            23              1293    3200
        1M              25              1133    3200
        16M             31.7            940     1300
        
        The prefetching increases write bandwidth to main memory
        even more than it increases read bandwidth (more than double!).
        It also makes the write bandwidth to L2 much more consistent;
        for a 256kB working set, though, write bandwidth seems to be
        only half of read bandwidth.
 
-------------------------------------------------------------------*/
 
 
/*-------------------------------------------------------------------
 
        uint64 readwrite_array( uint64 *x, int32 size );
 
        writes "size" contiguous bytes to x[], does a simple 
        operation on them and writes them back. Returns the number
        of clocks taken.
 
        Measured bandwidth on a 466 MHz Alpha 21264:
 
        size of x[]     clks/iter       MB/s    peak
        32k             12              4964    7456
        64k             12              4964    7456
        128k            25              2384    3200
        256k            25              2384    3200
        512k            31.3            1906    3200
        1M              49              1212    3200
        16M             91              654     1300
        
        Here are the corresponding figures with prefetching
        8 lines ahead:
        
        size of x[]     clks/iter       MB/s    peak
        32k             11.2            5294    7456
        64k             11.7            5084    7456
        128k            21.8            2740    3200
        256k            27.4            2170    3200
        512k            30.3            1964    3200
        1M              37.8            1574    3200
        16M             70              852     1300
        
        Prefetching only seems to help main memory here (22% better
        is nothing to sneeze at, though)
 
        Always process data in-place! Reading from one array and
        writing to another will drop the achievable memory bandwidth
        by 20-30% at all array sizes.
 
-------------------------------------------------------------------*/
 


             reply	other threads:[~2001-03-18  5:42 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-03-18  5:42 Jason Stratos Papadopoulos [this message]
2001-03-18 21:55 ` The case for page coloring Greg Lindahl
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox