linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@elte.hu>
To: Linus Torvalds <torvalds@osdl.org>
Cc: Andy Nelson <andy@thermo.lanl.gov>,
	akpm@osdl.org, arjan@infradead.org, arjanv@infradead.org,
	haveblue@us.ibm.com, kravetz@us.ibm.com,
	lhms-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org,
	linux-mm@kvack.org, mbligh@mbligh.org, mel@csn.ul.ie,
	nickpiggin@yahoo.com.au, pj@sgi.com
Subject: Re: [Lhms-devel] [PATCH 0/7] Fragmentation Avoidance V19
Date: Fri, 4 Nov 2005 17:40:20 +0100	[thread overview]
Message-ID: <20051104164020.GA9028@elte.hu> (raw)
In-Reply-To: <Pine.LNX.4.64.0511040801450.27915@g5.osdl.org>

* Linus Torvalds <torvalds@osdl.org> wrote:

> Time it on a real machine some day. On a modern x86, you will fill a 
> TLB entry in anything from 1-8 cycles if it's in L1, and add a couple 
> of dozen cycles for L2.

below is my (x86-only) testcode that accurately measures TLB miss costs 
in cycles. (Has to be run as root, because it uses 'cli' as the 
serializing instruction.)

here's the output from the default 128MB (32768 4K pages) random access 
pattern workload, on a 2 GHz P4 (which has 64 dTLBs):

  0 24 24 24 12 12 0 0 16 0 24 24 24 12 0 12 0 12

  32768 randomly accessed pages, 13 cycles avg, 73.751831% TLB misses.

i.e. really cheap TLB misses even in this very bad and TLB-trashing 
scenario: there are only 64 dTLBs and we have 32768 pages - so they are 
outnumbered by a factor of 1:512! Still the CPU gets it right.

setting LINEAR to 1 gives an embarrasing:

 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 

 32768 linearly accessed pages, 0 cycles avg, 0.259399% TLB misses.

showing that the pagetable got fully cached (probably in L1) and that 
has _zero_ overhead. Truly remarkable.

lowering the size to 16 MB (still 1:64 TLB-to-working-set-size ratio!) 
gives:

 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 

 4096 randomly accessed pages, 0 cycles avg, 5.859375% TLB misses.

so near-zero TLB overhead.

increasing BYTES to half a gigabyte gives:

 2 0 12 12 24 12 24 264 24 12 24 24 0 0 24 12 24 24 24 24 24 24 24 24 12 
 12 24 24 24 36 24 24 0 24 24 0 24 24 288 24 24 0 228 24 24 0 0 

 131072 randomly accessed pages, 75 cycles avg, 94.162750% TLB misses.

so an occasional ~220 cycles (~== 100 nsec - DRAM latency) cachemiss, 
but still the average is 75 cycles, or 37 nsecs - which is still only 
~37% of the DRAM latency.

(NOTE: the test eliminates most data cachemisses, by using zero-mapped 
anonymous memory, so only a single data page exists. So the costs seen 
here are mostly TLB misses.)

	Ingo

---------------
/*
 * TLB miss measurement on PII CPUs.
 *
 * Copyright (C) 1999, Ingo Molnar <mingo@redhat.com>
 */
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/wait.h>
#include <sys/mman.h>

#define BYTES (128*1024*1024)
#define PAGES (BYTES/4096)

/* This define turns on the linear mode.. */
#define LINEAR 0

#if 1
# define BARRIER "cli"
#else
# define BARRIER "lock ; addl $0,0(%%esp)"
#endif

int do_test (char * addr)
{
	unsigned long start, end;
	/*
	 * 'cli' is used as a serializing instruction to
	 * isolate the benchmarked instruction from rdtsc.
	 */
	__asm__ (
		"jmp 1f; 1: .align 128;\
"BARRIER";				\
		rdtsc;			\
		movl %0, %1;		\
"BARRIER";				\
		movl (%%esi), %%eax;	\
"BARRIER";				\
		rdtsc;			\
"BARRIER";				\
		"

		:"=a" (end), "=c" (start)
		:"S" (addr)
		:"dx","memory");
	return end - start;
}

extern int iopl(int);

int main (void)
{
	unsigned long overhead, sum;
	int j, k, c, hit;
	int matrix [PAGES];
	int delta [PAGES];
	char *buffer = mmap(NULL, BYTES, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);

	iopl(3);
	/*
	 * first generate a random access pattern.
	 */
	for (j = 0; j < PAGES; j++) {
		unsigned long val;
#if LINEAR
		val = ((j*8) % PAGES) * 4096;
		val = j*2048;
#else
		val = (random() % PAGES) * 4096;
#endif
		matrix[j] = val;
	}

	/*
	 * Calculate the overhead
	 */
	overhead = ~0UL;
	for (j = 0; j < 100; j++) {
		unsigned int diff = do_test(buffer);
		if (diff < overhead)
			overhead = diff;
	}
	printf("Overhead = %ld cycles\n", overhead);

	/*
	 * 10 warmup loops, the last one is printed.
	 */
	for (k = 0; k < 10; k++) {
		c = 0;
		for (j = 0; j < PAGES; j++) {
			char * addr;
			addr = buffer + matrix[j];
			delta[c++] = do_test(addr);
		}
	}
	hit = 0;
	sum = 0;
	for (j = 0; j < PAGES; j++) {
		unsigned long d = delta[j] - overhead;
		printf("%ld ", d);
		if (d <= 1)
			hit++;
		sum += d;
	}
	printf("\n");
	printf("%d %s accessed pages, %d cycles avg, %f%% TLB misses.\n",
		PAGES,
#if LINEAR
		"linearly",
#else
		"randomly",
#endif
		sum/PAGES,
		100.0*((double)PAGES-(double)hit)/(double)PAGES);

	return 0;
}

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2005-11-04 16:40 UTC|newest]

Thread overview: 225+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-04  1:00 Andy Nelson
2005-11-04  1:16 ` Martin J. Bligh
2005-11-04  1:27   ` Nick Piggin
2005-11-04  5:14 ` Linus Torvalds
2005-11-04  6:10   ` Paul Jackson
2005-11-04  6:38     ` Ingo Molnar
2005-11-04  7:26       ` Paul Jackson
2005-11-04  7:37         ` Ingo Molnar
2005-11-04 15:31       ` Linus Torvalds
2005-11-04 15:39         ` Martin J. Bligh
2005-11-04 15:53         ` Ingo Molnar
2005-11-06  7:34           ` Paul Jackson
2005-11-06 15:55             ` Linus Torvalds
2005-11-06 18:18               ` Paul Jackson
2005-11-06  8:44         ` Kyle Moffett
2005-11-06 16:12           ` Linus Torvalds
2005-11-06 17:00             ` Linus Torvalds
2005-11-07  8:00               ` Ingo Molnar
2005-11-07 11:00                 ` Dave Hansen
2005-11-07 12:20                   ` Ingo Molnar
2005-11-07 19:34                     ` Steven Rostedt
2005-11-07 23:38                       ` Joel Schopp
2005-11-04  7:44     ` Eric Dumazet
2005-11-07 16:42       ` Adam Litke
2005-11-04 14:56   ` Andy Nelson
2005-11-04 15:18     ` Ingo Molnar
2005-11-04 15:39       ` Andy Nelson
2005-11-04 16:05         ` Ingo Molnar
2005-11-04 16:07         ` Linus Torvalds
2005-11-04 16:40           ` Ingo Molnar [this message]
2005-11-04 17:22             ` Linus Torvalds
2005-11-04 17:43               ` Andy Nelson
2005-11-04 16:00     ` Linus Torvalds
2005-11-04 16:13       ` Martin J. Bligh
2005-11-04 16:40         ` Linus Torvalds
2005-11-04 17:10           ` Martin J. Bligh
2005-11-04 16:14       ` Andy Nelson
2005-11-04 16:49         ` Linus Torvalds
  -- strict thread matches above, loose matches on Subject: below --
2005-11-05  1:52 Seth, Rohit, Friday, November
2005-11-05  1:37 Seth, Rohit, Nick
2005-11-07  0:34 ` Andy Nelson
2005-11-07 18:58   ` Adam Litke
2005-11-07 20:51     ` Rohit Seth
2005-11-07 20:55       ` Andy Nelson
2005-11-07 20:58         ` Martin J. Bligh
2005-11-07 21:20           ` Rohit Seth
2005-11-07 21:33             ` Adam Litke
2005-11-08  2:12         ` David Gibson
2005-11-07 21:11       ` Adam Litke
2005-11-07 21:31         ` Rohit Seth
2005-11-04 21:51 Andy Nelson
2005-11-04 17:56 Andy Nelson
2005-11-04 17:03 Andy Nelson
2005-11-04 17:49 ` Linus Torvalds
2005-11-04 17:51   ` Andy Nelson
2005-11-04 20:12 ` Ingo Molnar
2005-11-04 21:04   ` Andy Nelson
2005-11-04 21:14     ` Ingo Molnar
2005-11-04 21:22     ` Linus Torvalds
2005-11-04 21:39       ` Linus Torvalds
2005-11-05  2:48       ` Rob Landley
2005-11-06 10:59       ` Paul Jackson
2005-11-04 21:31     ` Gregory Maxwell
2005-11-04 22:43       ` Andi Kleen
2005-11-05  0:07         ` Nick Piggin
2005-11-06  1:30         ` Zan Lynx
2005-11-06  2:25           ` Rob Landley
2005-11-04 15:19 Andy Nelson
2005-10-30 18:33 Mel Gorman
2005-10-31  5:57 ` [Lhms-devel] " Mike Kravetz
2005-10-31  6:37   ` Nick Piggin
2005-10-31  7:54     ` Andrew Morton
2005-10-31  7:11       ` Nick Piggin
2005-10-31 16:19         ` Mel Gorman
2005-10-31 23:54           ` Nick Piggin
2005-11-01  1:28             ` Mel Gorman
2005-11-01  1:42               ` Nick Piggin
2005-10-31 14:34       ` Martin J. Bligh
2005-10-31 19:24         ` Andrew Morton
2005-10-31 19:40           ` Martin J. Bligh
2005-10-31 23:59             ` Nick Piggin
2005-11-01  1:36               ` Mel Gorman
2005-10-31 23:29         ` Nick Piggin
2005-11-01  0:59           ` Mel Gorman
2005-11-01  1:31             ` Nick Piggin
2005-11-01  2:07               ` Mel Gorman
2005-11-01  2:35                 ` Nick Piggin
2005-11-01 11:57                   ` Mel Gorman
2005-11-01 13:56                     ` Ingo Molnar
2005-11-01 14:10                       ` Dave Hansen
2005-11-01 14:29                         ` Ingo Molnar
2005-11-01 14:49                           ` Dave Hansen
2005-11-01 15:01                             ` Ingo Molnar
2005-11-01 15:22                               ` Dave Hansen
2005-11-02  8:49                                 ` Ingo Molnar
2005-11-02  9:02                                   ` Nick Piggin
2005-11-02  9:17                                     ` Ingo Molnar
2005-11-02  9:32                                     ` Dave Hansen
2005-11-02  9:48                                       ` Nick Piggin
2005-11-02 10:54                                         ` Dave Hansen
2005-11-02 15:02                                         ` Martin J. Bligh
2005-11-03  3:21                                           ` Nick Piggin
2005-11-03 15:36                                             ` Martin J. Bligh
2005-11-03 15:40                                               ` Arjan van de Ven
2005-11-03 15:51                                                 ` Linus Torvalds
2005-11-03 15:57                                                   ` Martin J. Bligh
2005-11-03 16:20                                                   ` Arjan van de Ven
2005-11-03 16:27                                                   ` Mel Gorman
2005-11-03 16:46                                                     ` Linus Torvalds
2005-11-03 16:52                                                       ` Martin J. Bligh
2005-11-03 17:19                                                         ` Linus Torvalds
2005-11-03 17:48                                                           ` Dave Hansen
2005-11-03 17:51                                                           ` Martin J. Bligh
2005-11-03 17:59                                                             ` Arjan van de Ven
2005-11-03 18:08                                                               ` Linus Torvalds
2005-11-03 18:17                                                                 ` Martin J. Bligh
2005-11-03 18:44                                                                   ` Linus Torvalds
2005-11-03 18:51                                                                     ` Martin J. Bligh
2005-11-03 19:35                                                                       ` Linus Torvalds
2005-11-03 22:40                                                                         ` Martin J. Bligh
2005-11-03 22:56                                                                           ` Linus Torvalds
2005-11-03 23:01                                                                             ` Martin J. Bligh
2005-11-04  0:58                                                                   ` Nick Piggin
2005-11-04  1:06                                                                     ` Linus Torvalds
2005-11-04  1:20                                                                       ` Paul Mackerras
2005-11-04  1:22                                                                       ` Nick Piggin
2005-11-04  1:48                                                                         ` Mel Gorman
2005-11-04  1:59                                                                           ` Nick Piggin
2005-11-04  2:35                                                                             ` Mel Gorman
2005-11-04  1:26                                                                       ` Mel Gorman
2005-11-03 21:11                                                                 ` Mel Gorman
2005-11-03 18:03                                                             ` Linus Torvalds
2005-11-03 20:00                                                               ` Paul Jackson
2005-11-03 20:46                                                               ` Mel Gorman
2005-11-03 18:48                                                             ` Martin J. Bligh
2005-11-03 19:08                                                               ` Linus Torvalds
2005-11-03 22:37                                                                 ` Martin J. Bligh
2005-11-03 23:16                                                                   ` Linus Torvalds
2005-11-03 23:39                                                                     ` Martin J. Bligh
2005-11-04  0:42                                                                       ` Nick Piggin
2005-11-04  4:39                                                                     ` Andrew Morton
2005-11-04 16:22                                                                 ` Mel Gorman
2005-11-03 15:53                                                 ` Martin J. Bligh
2005-11-02 14:57                                   ` Martin J. Bligh
2005-11-01 16:48                               ` Kamezawa Hiroyuki
2005-11-01 16:59                                 ` Kamezawa Hiroyuki
2005-11-01 17:19                                 ` Mel Gorman
2005-11-02  0:32                                   ` KAMEZAWA Hiroyuki
2005-11-02 11:22                                     ` Mel Gorman
2005-11-01 18:06                                 ` linux-os (Dick Johnson)
2005-11-02  7:19                                 ` Ingo Molnar
2005-11-02  7:46                                   ` Gerrit Huizenga
2005-11-02  8:50                                     ` Nick Piggin
2005-11-02  9:12                                       ` Gerrit Huizenga
2005-11-02  9:37                                         ` Nick Piggin
2005-11-02 10:17                                           ` Gerrit Huizenga
2005-11-02 23:47                                           ` Rob Landley
2005-11-03  4:43                                             ` Nick Piggin
2005-11-03  6:07                                               ` Rob Landley
2005-11-03  7:34                                                 ` Nick Piggin
2005-11-03 17:54                                                   ` Rob Landley
2005-11-03 20:13                                                     ` Jeff Dike
2005-11-03 16:35                                                 ` Jeff Dike
2005-11-03 16:23                                                   ` Badari Pulavarty
2005-11-03 18:27                                                     ` Jeff Dike
2005-11-03 18:49                                                     ` Rob Landley
2005-11-04  4:52                                                     ` Andrew Morton
2005-11-04  5:35                                                       ` Paul Jackson
2005-11-04  5:48                                                         ` Andrew Morton
2005-11-04  6:42                                                           ` Paul Jackson
2005-11-04  7:10                                                             ` Andrew Morton
2005-11-04  7:45                                                               ` Paul Jackson
2005-11-04  8:02                                                                 ` Andrew Morton
2005-11-04  9:52                                                                   ` Paul Jackson
2005-11-04 15:27                                                                     ` Martin J. Bligh
2005-11-04 15:19                                                               ` Martin J. Bligh
2005-11-04 17:38                                                                 ` Andrew Morton
2005-11-04  6:16                                                         ` Bron Nelson
2005-11-02 10:41                                     ` Ingo Molnar
2005-11-02 11:04                                       ` Gerrit Huizenga
2005-11-02 12:00                                         ` Ingo Molnar
2005-11-02 12:42                                           ` Dave Hansen
2005-11-02 15:02                                           ` Gerrit Huizenga
2005-11-03  0:10                                             ` Rob Landley
2005-11-02  7:57                                   ` Nick Piggin
2005-11-02  0:51                             ` Nick Piggin
2005-11-02  7:42                               ` Dave Hansen
2005-11-02  8:24                                 ` Nick Piggin
2005-11-02  8:33                                   ` Yasunori Goto
2005-11-02  8:43                                     ` Nick Piggin
2005-11-02 14:51                                       ` Martin J. Bligh
2005-11-02 23:28                                       ` Rob Landley
2005-11-03  5:26                                         ` Jeff Dike
2005-11-03  5:41                                           ` Rob Landley
2005-11-01 14:41                       ` Mel Gorman
2005-11-01 14:46                         ` Ingo Molnar
2005-11-01 15:23                           ` Mel Gorman
2005-11-01 18:33                           ` Rob Landley
2005-11-01 19:02                             ` Ingo Molnar
2005-11-01 14:50                         ` Dave Hansen
2005-11-01 15:24                           ` Mel Gorman
2005-11-02  5:11                         ` Andrew Morton
2005-11-01 18:23                       ` Rob Landley
2005-11-01 20:31                         ` Joel Schopp
2005-11-01 20:59                   ` Joel Schopp
2005-11-02  1:06                     ` Nick Piggin
2005-11-02  1:41                       ` Martin J. Bligh
2005-11-02  2:03                         ` Nick Piggin
2005-11-02  2:24                           ` Martin J. Bligh
2005-11-02  2:49                             ` Nick Piggin
2005-11-02  4:39                               ` Martin J. Bligh
2005-11-02  5:09                                 ` Nick Piggin
2005-11-02  5:14                                   ` Martin J. Bligh
2005-11-02  6:23                                     ` KAMEZAWA Hiroyuki
2005-11-02 10:15                                       ` Nick Piggin
2005-11-02  7:19                               ` Yasunori Goto
2005-11-02 11:48                               ` Mel Gorman
2005-11-02 11:41                           ` Mel Gorman
2005-11-02 11:37                       ` Mel Gorman
2005-11-02 15:11                       ` Mel Gorman
2005-11-01 15:25               ` Martin J. Bligh
2005-11-01 15:33                 ` Dave Hansen
2005-11-01 16:57                   ` Mel Gorman
2005-11-01 17:00                     ` Mel Gorman
2005-11-01 18:58                   ` Rob Landley
2005-11-01 14:40         ` Avi Kivity

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=20051104164020.GA9028@elte.hu \
    --to=mingo@elte.hu \
    --cc=akpm@osdl.org \
    --cc=andy@thermo.lanl.gov \
    --cc=arjan@infradead.org \
    --cc=arjanv@infradead.org \
    --cc=haveblue@us.ibm.com \
    --cc=kravetz@us.ibm.com \
    --cc=lhms-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mbligh@mbligh.org \
    --cc=mel@csn.ul.ie \
    --cc=nickpiggin@yahoo.com.au \
    --cc=pj@sgi.com \
    --cc=torvalds@osdl.org \
    /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