author | tschatzl |
Wed, 25 Nov 2015 14:43:29 +0100 | |
changeset 34300 | 6075c1e0e913 |
parent 34230 | b9c64b7c06c9 |
child 35061 | be6025ebffea |
permissions | -rw-r--r-- |
32379
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
1 |
/* |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
2 |
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
4 |
* |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
8 |
* |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
13 |
* accompanied this code). |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
14 |
* |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
18 |
* |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
21 |
* questions. |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
22 |
* |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
23 |
*/ |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
24 |
|
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
25 |
#include "precompiled.hpp" |
34230
b9c64b7c06c9
8141570: Fix Zero interpreter build for --disable-precompiled-headers
coleenp
parents:
33605
diff
changeset
|
26 |
#include "memory/allocation.inline.hpp" |
32379
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
27 |
#include "gc/g1/g1EvacStats.hpp" |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
28 |
#include "gc/shared/gcId.hpp" |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
29 |
#include "trace/tracing.hpp" |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
30 |
|
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
31 |
void G1EvacStats::adjust_desired_plab_sz() { |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
32 |
if (PrintPLAB) { |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
33 |
gclog_or_tty->print(" (allocated = " SIZE_FORMAT " wasted = " SIZE_FORMAT " " |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
34 |
"unused = " SIZE_FORMAT " used = " SIZE_FORMAT " " |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
35 |
"undo_waste = " SIZE_FORMAT " region_end_waste = " SIZE_FORMAT " " |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
36 |
"regions filled = %u direct_allocated = " SIZE_FORMAT " " |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
37 |
"failure_used = " SIZE_FORMAT " failure_waste = " SIZE_FORMAT ") ", |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
38 |
_allocated, _wasted, _unused, used(), _undo_wasted, _region_end_waste, |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
39 |
_regions_filled, _direct_allocated, _failure_used, _failure_waste); |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
40 |
} |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
41 |
|
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
42 |
if (ResizePLAB) { |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
43 |
|
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
44 |
assert(is_object_aligned(max_size()) && min_size() <= max_size(), |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
45 |
"PLAB clipping computation may be incorrect"); |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
46 |
|
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
47 |
if (_allocated == 0) { |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
48 |
assert((_unused == 0), |
33105
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
32822
diff
changeset
|
49 |
"Inconsistency in PLAB stats: " |
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
32822
diff
changeset
|
50 |
"_allocated: " SIZE_FORMAT ", " |
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
32822
diff
changeset
|
51 |
"_wasted: " SIZE_FORMAT ", " |
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
32822
diff
changeset
|
52 |
"_region_end_waste: " SIZE_FORMAT ", " |
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
32822
diff
changeset
|
53 |
"_unused: " SIZE_FORMAT ", " |
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
32822
diff
changeset
|
54 |
"_used : " SIZE_FORMAT, |
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
32822
diff
changeset
|
55 |
_allocated, _wasted, _region_end_waste, _unused, used()); |
32379
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
56 |
_allocated = 1; |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
57 |
} |
32602
27d046027824
8067341: Modify PLAB sizing algorithm to waste less
tschatzl
parents:
32379
diff
changeset
|
58 |
// The size of the PLAB caps the amount of space that can be wasted at the |
27d046027824
8067341: Modify PLAB sizing algorithm to waste less
tschatzl
parents:
32379
diff
changeset
|
59 |
// end of the collection. In the worst case the last PLAB could be completely |
27d046027824
8067341: Modify PLAB sizing algorithm to waste less
tschatzl
parents:
32379
diff
changeset
|
60 |
// empty. |
27d046027824
8067341: Modify PLAB sizing algorithm to waste less
tschatzl
parents:
32379
diff
changeset
|
61 |
// This allows us to calculate the new PLAB size to achieve the |
27d046027824
8067341: Modify PLAB sizing algorithm to waste less
tschatzl
parents:
32379
diff
changeset
|
62 |
// TargetPLABWastePct given the latest memory usage and that the last buffer |
27d046027824
8067341: Modify PLAB sizing algorithm to waste less
tschatzl
parents:
32379
diff
changeset
|
63 |
// will be G1LastPLABAverageOccupancy full. |
27d046027824
8067341: Modify PLAB sizing algorithm to waste less
tschatzl
parents:
32379
diff
changeset
|
64 |
// |
27d046027824
8067341: Modify PLAB sizing algorithm to waste less
tschatzl
parents:
32379
diff
changeset
|
65 |
// E.g. assume that if in the current GC 100 words were allocated and a |
27d046027824
8067341: Modify PLAB sizing algorithm to waste less
tschatzl
parents:
32379
diff
changeset
|
66 |
// TargetPLABWastePct of 10 had been set. |
27d046027824
8067341: Modify PLAB sizing algorithm to waste less
tschatzl
parents:
32379
diff
changeset
|
67 |
// |
27d046027824
8067341: Modify PLAB sizing algorithm to waste less
tschatzl
parents:
32379
diff
changeset
|
68 |
// So we could waste up to 10 words to meet that percentage. Given that we |
27d046027824
8067341: Modify PLAB sizing algorithm to waste less
tschatzl
parents:
32379
diff
changeset
|
69 |
// also assume that that buffer is typically half-full, the new desired PLAB |
27d046027824
8067341: Modify PLAB sizing algorithm to waste less
tschatzl
parents:
32379
diff
changeset
|
70 |
// size is set to 20 words. |
27d046027824
8067341: Modify PLAB sizing algorithm to waste less
tschatzl
parents:
32379
diff
changeset
|
71 |
// |
27d046027824
8067341: Modify PLAB sizing algorithm to waste less
tschatzl
parents:
32379
diff
changeset
|
72 |
// The amount of allocation performed should be independent of the number of |
27d046027824
8067341: Modify PLAB sizing algorithm to waste less
tschatzl
parents:
32379
diff
changeset
|
73 |
// threads, so should the maximum waste we can spend in total. So if |
27d046027824
8067341: Modify PLAB sizing algorithm to waste less
tschatzl
parents:
32379
diff
changeset
|
74 |
// we used n threads to allocate, each of them can spend maximum waste/n words in |
27d046027824
8067341: Modify PLAB sizing algorithm to waste less
tschatzl
parents:
32379
diff
changeset
|
75 |
// a first rough approximation. The number of threads only comes into play later |
27d046027824
8067341: Modify PLAB sizing algorithm to waste less
tschatzl
parents:
32379
diff
changeset
|
76 |
// when actually retrieving the actual desired PLAB size. |
27d046027824
8067341: Modify PLAB sizing algorithm to waste less
tschatzl
parents:
32379
diff
changeset
|
77 |
// |
27d046027824
8067341: Modify PLAB sizing algorithm to waste less
tschatzl
parents:
32379
diff
changeset
|
78 |
// After calculating this optimal PLAB size the algorithm applies the usual |
27d046027824
8067341: Modify PLAB sizing algorithm to waste less
tschatzl
parents:
32379
diff
changeset
|
79 |
// exponential decaying average over this value to guess the next PLAB size. |
27d046027824
8067341: Modify PLAB sizing algorithm to waste less
tschatzl
parents:
32379
diff
changeset
|
80 |
// |
27d046027824
8067341: Modify PLAB sizing algorithm to waste less
tschatzl
parents:
32379
diff
changeset
|
81 |
// We account region end waste fully to PLAB allocation (in the calculation of |
27d046027824
8067341: Modify PLAB sizing algorithm to waste less
tschatzl
parents:
32379
diff
changeset
|
82 |
// what we consider as "used_for_waste_calculation" below). This is not |
27d046027824
8067341: Modify PLAB sizing algorithm to waste less
tschatzl
parents:
32379
diff
changeset
|
83 |
// completely fair, but is a conservative assumption because PLABs may be sized |
27d046027824
8067341: Modify PLAB sizing algorithm to waste less
tschatzl
parents:
32379
diff
changeset
|
84 |
// flexibly while we cannot adjust inline allocations. |
27d046027824
8067341: Modify PLAB sizing algorithm to waste less
tschatzl
parents:
32379
diff
changeset
|
85 |
// Allocation during GC will try to minimize region end waste so this impact |
27d046027824
8067341: Modify PLAB sizing algorithm to waste less
tschatzl
parents:
32379
diff
changeset
|
86 |
// should be minimal. |
27d046027824
8067341: Modify PLAB sizing algorithm to waste less
tschatzl
parents:
32379
diff
changeset
|
87 |
// |
27d046027824
8067341: Modify PLAB sizing algorithm to waste less
tschatzl
parents:
32379
diff
changeset
|
88 |
// We need to cover overflow when calculating the amount of space actually used |
27d046027824
8067341: Modify PLAB sizing algorithm to waste less
tschatzl
parents:
32379
diff
changeset
|
89 |
// by objects in PLABs when subtracting the region end waste. |
27d046027824
8067341: Modify PLAB sizing algorithm to waste less
tschatzl
parents:
32379
diff
changeset
|
90 |
// Region end waste may be higher than actual allocation. This may occur if many |
27d046027824
8067341: Modify PLAB sizing algorithm to waste less
tschatzl
parents:
32379
diff
changeset
|
91 |
// threads do not allocate anything but a few rather large objects. In this |
27d046027824
8067341: Modify PLAB sizing algorithm to waste less
tschatzl
parents:
32379
diff
changeset
|
92 |
// degenerate case the PLAB size would simply quickly tend to minimum PLAB size, |
27d046027824
8067341: Modify PLAB sizing algorithm to waste less
tschatzl
parents:
32379
diff
changeset
|
93 |
// which is an okay reaction. |
27d046027824
8067341: Modify PLAB sizing algorithm to waste less
tschatzl
parents:
32379
diff
changeset
|
94 |
size_t const used_for_waste_calculation = used() > _region_end_waste ? used() - _region_end_waste : 0; |
27d046027824
8067341: Modify PLAB sizing algorithm to waste less
tschatzl
parents:
32379
diff
changeset
|
95 |
|
27d046027824
8067341: Modify PLAB sizing algorithm to waste less
tschatzl
parents:
32379
diff
changeset
|
96 |
size_t const total_waste_allowed = used_for_waste_calculation * TargetPLABWastePct; |
32822 | 97 |
size_t const cur_plab_sz = (size_t)((double)total_waste_allowed / G1LastPLABAverageOccupancy); |
32379
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
98 |
// Take historical weighted average |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
99 |
_filter.sample(cur_plab_sz); |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
100 |
// Clip from above and below, and align to object boundary |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
101 |
size_t plab_sz; |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
102 |
plab_sz = MAX2(min_size(), (size_t)_filter.average()); |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
103 |
plab_sz = MIN2(max_size(), plab_sz); |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
104 |
plab_sz = align_object_size(plab_sz); |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
105 |
// Latch the result |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
106 |
_desired_net_plab_sz = plab_sz; |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
107 |
if (PrintPLAB) { |
33597
5d42601232b1
8139903: G1EvacStats does not split log entries.
mchernov
parents:
33105
diff
changeset
|
108 |
gclog_or_tty->print(" (plab_sz = " SIZE_FORMAT " desired_plab_sz = " SIZE_FORMAT ") ", cur_plab_sz, plab_sz); |
32379
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
109 |
} |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
110 |
} |
33605
7cf76a278055
8140583: Without PrintPLAB, there are superfluous newlines in the GC log messages
tschatzl
parents:
33597
diff
changeset
|
111 |
if (PrintPLAB) { |
7cf76a278055
8140583: Without PrintPLAB, there are superfluous newlines in the GC log messages
tschatzl
parents:
33597
diff
changeset
|
112 |
gclog_or_tty->cr(); |
7cf76a278055
8140583: Without PrintPLAB, there are superfluous newlines in the GC log messages
tschatzl
parents:
33597
diff
changeset
|
113 |
} |
32379
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
114 |
// Clear accumulators for next round. |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
115 |
reset(); |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
116 |
} |
aa14adafaf0f
8073013: Add detailed information about PLAB memory usage
tschatzl
parents:
diff
changeset
|
117 |
|
34230
b9c64b7c06c9
8141570: Fix Zero interpreter build for --disable-precompiled-headers
coleenp
parents:
33605
diff
changeset
|
118 |
G1EvacStats::~G1EvacStats() { } |