Gentoo Archives: gentoo-amd64

From: Duncan <1i5t5.duncan@×××.net>
To: gentoo-amd64@l.g.o
Subject: [gentoo-amd64] Re: Advice On Enabling Transparent Hugepage
Date: Thu, 02 May 2013 22:39:03
Message-Id: pan$8070b$e14cf172$46299bca$856aaa41@cox.net
In Reply to: [gentoo-amd64] Advice On Enabling Transparent Hugepage by Frank Peters
1 Frank Peters posted on Thu, 02 May 2013 16:33:09 -0400 as excerpted:
2
3 > During kernel configuration there is an option called
4 > CONFIG_TRANSPARENT_HUGEPAGE which allows the use of Transparent
5 > Hugepages or application memory pages larger than the traditional 4K
6 > size. This option has been available for a while but I've never enabled
7 > it. However, it would seem like a good idea to use.
8 >
9 > Searching for more information I can find no comments on actual Hugepage
10 > performance for a simple desktop Linux system. Can anyone verify or
11 > refute the idea that Transparent Hugepages will lead to improvements on
12 > a desktop system? Does an application have to specifically request
13 > Hugepages or does the allocation occur for all applications?
14
15 In addition to what Paul says (which is generally correct, AFAIK)...
16
17 As I understand it, the whole idea of "huge pages" is based on making
18 better use of a relatively limited hardware resource, the TLB entries,
19 translation lookaside buffer entries. The TLB is a sort of memory
20 mapping cache index, the memory mapping itself being between virtual and
21 physical memory. The technical details of TLB are beyond me, so I'll
22 simply refer you to wikipedia:
23
24 http://en.wikipedia.org/wiki/Translation_lookaside_buffer
25
26 But basically, the TLB is an index with a limit of (from wikipedia)
27 12-4096 entries, depending on architecture and specific CPU.
28
29 The key is that each memory page requires an entry, and normal memory
30 pages are 4k in size, so normal TLB coverage is relatively small, a few
31 megabytes of RAM can be indexed at a time, that's it.
32
33 Which is where huge pages come in, since each huge page entry requires
34 the same index line as a normal page would, but indexes and allows fast
35 access to a far larger bit of memory, often 2 MB. If all TLB line
36 entries were for huge-pages, then, coverage would be several GB instead
37 of several MB.
38
39 The problem was to implement that in the kernel. Originally, there was a
40 huge page interface that individual apps could use, but only if they
41 specifically requested it, which of course required that they be
42 rewritten in ordered to do so.
43
44 Which is where the transparent comes in. With transparent huge-pages,
45 apps work as normal -- it's the kernel that manages the huge pages
46 "transparently".
47
48 Practical value depends on your work load, but in general, it won't hurt.
49
50 Two further notes: 1) Because I regularly run mainline git kernels, I was
51 exposed to the option early on, and based on the coverage in (2) below, I
52 enabled them. But at one point in a pre-release kernel there was a bug,
53 of course long since fixed. The details aren't important as it is long
54 fixed, but due to that bug, I *DID* discover ONE app that ends up using
55 huge-pages a LOT -- firefox! Evidently, huge pages only really come into
56 play when individual app memory usage is relatively high, and firefox hit
57 that threshold, as well as some other requirements for huge pages, plus
58 some corner-cases that were required to hit this particular bug (which
59 was with zero-pages, in the second kernel that had huge-page support as
60 they added zero-page support, a different "trick" that wasn't initially
61 applied to huge-pages, only normal pages).
62
63 So for that period, I simply disabled huge-page support again, until the
64 bug was fixed. Then I enabled it and haven't disabled it since.
65
66 2) LWN has several articles covering kernel huge-page support as well as
67 transparent-huge-pages, including a 5-part-series covering the initial
68 non-transparent version, the first part (with further links to the other
69 parts) of which is found here:
70
71 http://lwn.net/Articles/374424/
72
73 That'll let you get pretty deep into the technology, if you like.
74 There's benchmarks, ways to discover what the TLBs are for your hardware,
75 etc.
76
77 Here's a google search limited to site:lwn.net for transparent huge pages:
78
79 http://www.google.com/search?q=site%3Alwn.net+transparent+huge+pages
80
81 Of interest, down the first page of hits a bit you can see overage of the
82 "adding a huge zero page" discussion, the source of the bug I mentioned
83 above, again, now long fixed.
84
85 That should give you quite enough information to get you started. =:^)
86
87 --
88 Duncan - List replies preferred. No HTML msgs.
89 "Every nonfree program has a lord, a master --
90 and if you use the program, he is your master." Richard Stallman