linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@elte.hu>
To: Martin Bligh <mbligh@mbligh.org>
Cc: Linus Torvalds <torvalds@osdl.org>,
	Matt Mackall <mpm@selenic.com>,
	Arjan van de Ven <arjan@infradead.org>,
	Chuck Ebbert <76306.1226@compuserve.com>,
	Adrian Bunk <bunk@stusta.de>, Andrew Morton <akpm@osdl.org>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	Dave Jones <davej@redhat.com>,
	Tim Schmielau <tim@physik3.uni-rostock.de>
Subject: Re: [patch 00/2] improve .text size on gcc 4.0 and newer  compilers
Date: Fri, 6 Jan 2006 01:40:50 +0100	[thread overview]
Message-ID: <20060106004050.GA18727@elte.hu> (raw)
In-Reply-To: <43BDB381.6020701@mbligh.org>


* Martin Bligh <mbligh@mbligh.org> wrote:

> >I think the only sane solution [that would be endorsed by distributions] 
> >is to allow users to reorder function sections runtime (per boot). That 
> >is alot faster and more robust (from a production POV) than a full 
> >recompilation of the kernel. Recompilation is always risky, it needs too 
> >much context, and has too many tool dependencies - and is thus currently 
> >untestable. 
> 
> <smhuch> - the sound of my eyeballs popping out and splatting against 
> the opposite wall.
> 
> So ... recompilation is not testable, but boot time reordering of the 
> code somehow is? ;-) Yes, I understand the distro toolchain issues, 
> but it's still a scary solution ...

'testable' in the sense that the stability and reliability of the system 
is alot less dependent on function ordering, than it is dependent on 
compilation. It's not 'testable' in the sense of being able to cycle 
through all the 60000-factorial function combinations - but that's not 
really a problem, as long as the risk of the worst-case effect of 
function reordering can be judged and covered. The kernel stopped being 
'fully testable' sometime around version 0.2 already ;-)

> Personally, I'd think the sane thing is not to try to optimise by 
> workload, but get 80% of the benefit by just reordering on a more 
> generalized workload. Doing boot-time reordering for this on 
> non-custom kernels just seems terrifying .. it's not that huge a 
> benefit, surely?

i'm not so sure, see the ballpark figures below.

> >one problem are modules though - they could only be reordered within 
> >themselves. On an average system which has ~100 modules loaded, the 
> >average icache fragmentation is +100*128/2 == 6.4K [with 128 byte L1 
> >cachelines], which can be significant (depending on the workload). OTOH, 
> >modules do have strong internal cohesion - they contain functions that 
> >belong together conceptually. So by reordering functions within modules 
> >we'll likely be able to realize most of the icache savings possible. The 
> >only exception would be workloads that utilize many modules at a high 
> >frequency. Such workloads will likely trash the icache anyway.
> 
> I was thinking about that with modules earlier, and whether modular 
> kernels would actually be faster because of that than a statically 
> compiled one. But don't you get similar effects from the .o groupings 
> by file we get? or does the linker not preserve those groupings?

they are mostly preserved (except for things like __sched which move 
functions out of .o), but look at a call-chain like this:

| new stack-footprint maximum: khelper/1125, 2412 bytes (out of 8140 bytes).
------------|
{   40} [<c0144a31>] debug_stackoverflow+0xb6/0xc4
{   60} [<c0144f66>] __mcount+0x47/0xe0
{   20} [<c0110b24>] mcount+0x14/0x18
{  116} [<c05fec5e>] __down_mutex+0xe/0x87b
{   28} [<c0601544>] _spin_lock+0x24/0x49
{   36} [<c015aa7e>] kmem_cache_alloc+0x40/0xe9
{   16} [<c0154ddd>] mempool_alloc_slab+0x1d/0x1f
{   56} [<c0154c82>] mempool_alloc+0x39/0xf1
{   44} [<c02f3519>] get_request+0xf7/0x2dc
{   60} [<c02f372d>] get_request_wait+0x2f/0x10f
{   88} [<c02f43bc>] __make_request+0xae/0x552
{   88} [<c02f4b9b>] generic_make_request+0xaf/0x24c
{   84} [<c02f4d90>] submit_bio+0x58/0x127
{   20} [<c0196912>] mpage_bio_submit+0x31/0x39
{  292} [<c0196d4e>] do_mpage_readpage+0x2f5/0x451
{   88} [<c0196f99>] mpage_readpages+0xef/0x19e
{   24} [<c01dfeb4>] ext3_readpages+0x2c/0x2e
{   80} [<c0158b4b>] read_pages+0x38/0x14d
{   60} [<c0158de1>] __do_page_cache_readahead+0x181/0x186
{   36} [<c0158f40>] blockable_page_cache_readahead+0x69/0xd0
{   44} [<c015918e>] page_cache_readahead+0x13c/0x185
{  120} [<c0151abf>] do_generic_mapping_read+0x436/0x6c3
{   80} [<c0151fc8>] __generic_file_aio_read+0x17f/0x22e
{   44} [<c01520c8>] generic_file_aio_read+0x51/0x7f
{  160} [<c0171091>] do_sync_read+0xba/0x109
{   40} [<c017119e>] vfs_read+0xbe/0x1a0
{   40} [<c017c5fa>] kernel_read+0x4b/0x55
{  192} [<c019f844>] load_elf_binary+0x5e9/0xd2d
{   32} [<c017d4d1>] search_binary_handler+0x80/0x136
{  176} [<c019e87e>] load_script+0x246/0x258
{   32} [<c017d4d1>] search_binary_handler+0x80/0x136
{   36} [<c017d7c2>] do_execve+0x23b/0x268
{   36} [<c0101c4e>] sys_execve+0x41/0x8f
{=2368} [<c01030ca>] syscall_call+0x7/0xb
<---------------------------

[readers beware, quick & dirty and possibly wrong guesstimations: ]

these 30 functions involve roughly 10-15 .o files, so we've got 2-3 
functions per .o file only. And that's typical for VFS, IO, networking 
and lots of other syscall types. So if the full kernel image is 3MB, and 
we've got 30 functions totalling to 3000 bytes, they are spread out in 
10-15 groups right now - creating 10-15 split icache lines. (in reality 
we have in excess of 20 split icache-lines, due to weak cohesion even 
within .o files) With 64-byte lines that's 320-480 bytes 'lost' due to 
fragmentation alone, with 128-byte lines it's 640-960 bytes - which is 
10%-21% in the 64-byte case, and 21%-42% in the 128-byte case. I.e. the 
icache bloat just due to the placement is quite significant. Adding 
.o-level fragmentation plus inter-function inactive code to the mix can 
easily baloon this even higher. Plus the current method of doing 
unlikely() means the unlikely instructions are near the end of the 
function - so they still 'spread apart' the footprint and thus have a 
nontrivial icache cost.

[ now the above one is a random example out of my logs that is also a 
  really bad example: in reality would win little from better icache 
  footprint: an execve() takes 100,000-200,000 cycles even when
  everything comes from the pagecache, and most of those cycles are
  spent in very tight codepaths. ]

	Ingo


  reply	other threads:[~2006-01-06  0:44 UTC|newest]

Thread overview: 167+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-01-05  0:55 [patch 00/2] improve .text size on gcc 4.0 and newer compilers Chuck Ebbert
2006-01-05  1:07 ` Martin Bligh
2006-01-05 12:19   ` Arjan van de Ven
2006-01-05 14:30     ` Jakub Jelinek
2006-01-05 16:55       ` Linus Torvalds
2006-01-05 18:42         ` Daniel Jacobowitz
2006-01-05 17:02     ` Matt Mackall
2006-01-05 17:59       ` Martin Bligh
2006-01-05 18:09         ` Arjan van de Ven
2006-01-05 18:43           ` Daniel Jacobowitz
2006-01-05 19:17         ` Linus Torvalds
2006-01-05 19:40           ` Linus Torvalds
2006-01-05 19:49             ` Martin Bligh
2006-01-05 20:13               ` Linus Torvalds
2006-01-05 20:15                 ` Linus Torvalds
2006-01-05 23:30                   ` Ingo Molnar
2006-01-05 23:54                     ` Linus Torvalds
2006-01-06  0:15                       ` Ingo Molnar
2006-01-06  0:27                         ` Linus Torvalds
2006-01-06  0:54                           ` Ingo Molnar
2006-01-06  0:02                     ` Martin Bligh
2006-01-06  0:40                       ` Ingo Molnar [this message]
2006-01-06  0:55                         ` Martin Bligh
2006-01-06  1:48                           ` Mitchell Blank Jr
2006-01-06  0:50                   ` Mitchell Blank Jr
2006-01-06  0:58                     ` Ingo Molnar
2006-01-06  1:22                       ` Mitchell Blank Jr
2006-01-05 21:34             ` Matt Mackall
2006-01-05 22:08               ` Linus Torvalds
2006-01-05 22:36                 ` Matt Mackall
2006-01-05 22:49                   ` Martin Bligh
2006-01-05 23:02                     ` Matt Mackall
2006-01-05 22:55                   ` Ingo Molnar
2006-01-05 23:11                     ` Matt Mackall
2006-01-05 23:27                       ` Jesse Barnes
2006-01-05 23:58                       ` Ingo Molnar
2006-01-05 21:32           ` Grzegorz Kulewski
  -- strict thread matches above, loose matches on Subject: below --
2005-12-28 11:46 Ingo Molnar
2005-12-28 19:17 ` Linus Torvalds
2005-12-28 19:34   ` Arjan van de Ven
2005-12-28 21:02     ` Linus Torvalds
2005-12-28 21:17       ` Arjan van de Ven
2005-12-28 21:23       ` Ingo Molnar
2005-12-28 21:48         ` Ingo Molnar
2005-12-28 23:56           ` Krzysztof Halasa
2005-12-29  7:41             ` Ingo Molnar
2005-12-29  8:02               ` Dave Jones
2005-12-29 19:44               ` Krzysztof Halasa
2005-12-29  4:11           ` Andrew Morton
2005-12-29  7:32             ` Ingo Molnar
2005-12-29 14:58               ` Horst von Brand
2005-12-29 15:40               ` Adrian Bunk
2005-12-29 17:41               ` Linus Torvalds
2005-12-29 18:42                 ` Arjan van de Ven
2005-12-29 18:45                   ` Arjan van de Ven
2005-12-29 20:19                 ` Ingo Molnar
2005-12-29 22:20                   ` Matt Mackall
2005-12-29 20:28                 ` Dave Jones
2005-12-29 20:49                   ` Linus Torvalds
2005-12-29 21:25                     ` Linus Torvalds
     [not found]                       ` <20051229224839.GA12247@elte.hu>
2005-12-29 22:58                         ` Arjan van de Ven
2005-12-30  2:03                           ` Tim Schmielau
2005-12-30  2:15                             ` Tim Schmielau
2005-12-30  7:49                             ` Ingo Molnar
2005-12-31 14:38                               ` Adrian Bunk
2005-12-31 14:45                                 ` Ingo Molnar
2005-12-31 15:08                                   ` Adrian Bunk
2006-01-02 10:37                                     ` Ingo Molnar
2006-01-02 10:48                                       ` Arjan van de Ven
2006-01-02 13:43                                         ` Adrian Bunk
2006-01-02 14:05                                           ` Ingo Molnar
2006-01-02 15:01                                             ` Adrian Bunk
2006-01-02 18:44                                             ` Krzysztof Halasa
2006-01-02 18:51                                               ` Arjan van de Ven
2006-01-02 19:49                                                 ` Krzysztof Halasa
2006-01-02 19:54                                                   ` Arjan van de Ven
2006-01-02 20:05                                                     ` Krzysztof Halasa
2006-01-02 20:18                                                       ` Jörn Engel
2006-01-02 22:23                                                 ` Russell King
2006-01-02 23:55                                                   ` Alan Cox
2006-01-03  3:59                                                   ` Daniel Jacobowitz
2006-01-03  8:53                                                     ` Russell King
2006-01-03  8:56                                                       ` Arjan van de Ven
2006-01-03  9:00                                                         ` Russell King
2006-01-03  9:10                                                           ` Arjan van de Ven
2006-01-03  9:14                                                         ` Vitaly Wool
2006-01-02 19:03                                               ` Andrew Morton
2006-01-02 19:17                                                 ` Jakub Jelinek
2006-01-02 19:30                                                   ` Andrew Morton
2006-01-02 19:41                                                   ` Linus Torvalds
2006-01-02 19:53                                                     ` Ingo Molnar
2006-01-02 20:28                                                     ` Jakub Jelinek
2006-01-02 20:09                                                 ` Ingo Molnar
2006-01-02 20:24                                                   ` Andrew Morton
2006-01-02 20:40                                                     ` Ingo Molnar
2006-01-02 20:30                                                 ` Ingo Molnar
2006-01-02 19:12                                               ` Linus Torvalds
2006-01-02 19:59                                                 ` Krzysztof Halasa
2006-01-02 20:13                                                 ` Ingo Molnar
2006-01-02 21:00                                                   ` Jan Engelhardt
2006-01-02 22:43                                                     ` Linus Torvalds
2006-01-02 13:42                                       ` Adrian Bunk
2006-01-02 18:28                                         ` Andrew Morton
2006-01-02 18:49                                           ` Arjan van de Ven
2006-01-02 19:26                                             ` Jörn Engel
2006-01-02 21:51                                             ` Grant Coady
2006-01-02 22:03                                               ` Antonio Vargas
2006-01-02 22:56                                                 ` Arjan van de Ven
2006-01-02 23:10                                                   ` Grant Coady
2006-01-02 23:57                                                     ` Alan Cox
2006-01-02 23:58                                                       ` Grant Coady
2006-01-03  5:31                                           ` Nick Piggin
2006-01-03 23:40                                           ` Martin J. Bligh
2006-01-04  4:28                                             ` Matt Mackall
2006-01-04  5:51                                               ` Martin J. Bligh
2006-01-04 17:10                                                 ` Matt Mackall
2006-01-04 22:37                                                 ` Linus Torvalds
2006-01-05  0:55                                                   ` Martin Bligh
2006-01-04 17:36                                               ` Zwane Mwaikambo
2005-12-31  3:51                             ` Kurt Wall
2005-12-30  3:31                           ` Nicolas Pitre
2005-12-30  3:47                     ` Mark Lord
2005-12-30  3:56                       ` Dave Jones
2005-12-30  3:57                       ` Mark Lord
2005-12-30  4:02                         ` Dave Jones
2005-12-30  4:11                           ` Mark Lord
2005-12-30  4:14                             ` Mark Lord
2005-12-30  4:20                               ` Mark Lord
2005-12-30  5:04                                 ` Dave Jones
2005-12-29 23:16                 ` Willy Tarreau
2005-12-30  8:05                   ` Arjan van de Ven
2005-12-30  8:15                     ` Willy Tarreau
2005-12-30  8:24                       ` Arjan van de Ven
2005-12-30  9:20                         ` Willy Tarreau
2005-12-30 13:38                           ` Adrian Bunk
2005-12-30  8:33                   ` Jesper Juhl
2005-12-30  9:28                     ` Willy Tarreau
2005-12-30  9:37                       ` Jesper Juhl
2005-12-30  9:38                         ` Willy Tarreau
2005-12-30 19:53                   ` Alistair John Strachan
2005-12-29  7:49             ` Arjan van de Ven
2005-12-29 15:01               ` Horst von Brand
2005-12-30 15:28             ` Alan Cox
2005-12-30 20:59               ` Adrian Bunk
2005-12-30 22:12             ` Matt Mackall
2005-12-30 23:54               ` Adrian Bunk
2005-12-31  9:20               ` Arjan van de Ven
2005-12-29 14:38           ` Christoph Hellwig
2005-12-29 14:54             ` Arjan van de Ven
2005-12-29 15:35               ` Adrian Bunk
2005-12-29 15:38                 ` Arjan van de Ven
2005-12-29 15:42                 ` Jakub Jelinek
2005-12-29 19:14                   ` Adrian Bunk
2005-12-30  9:28                   ` Andi Kleen
2005-12-30  9:40                     ` Ingo Molnar
2005-12-30 10:14                       ` Ingo Molnar
2005-12-30 13:31                         ` Adrian Bunk
2005-12-30 14:08                         ` Christian Trefzer
2005-12-30 10:25                       ` Andi Kleen
2005-12-29  0:37         ` Rogério Brito
2006-01-03  3:36         ` Daniel Jacobowitz
2005-12-29  4:38 ` Adrian Bunk
2005-12-29  7:59   ` Ingo Molnar
2005-12-29 13:52     ` Adrian Bunk
2005-12-29 19:57       ` Horst von Brand
2005-12-29 20:25       ` Ingo Molnar
2005-12-31 15:22         ` Adrian Bunk

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=20060106004050.GA18727@elte.hu \
    --to=mingo@elte.hu \
    --cc=76306.1226@compuserve.com \
    --cc=akpm@osdl.org \
    --cc=arjan@infradead.org \
    --cc=bunk@stusta.de \
    --cc=davej@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mbligh@mbligh.org \
    --cc=mpm@selenic.com \
    --cc=tim@physik3.uni-rostock.de \
    --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;
as well as URLs for NNTP newsgroup(s).