1 /*
2 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
29 #include "gc/shared/gcId.hpp"
30 #include "logging/log.hpp"
31 #include "trace/tracing.hpp"
32
33 void G1EvacStats::log_plab_allocation() {
34 PLABStats::log_plab_allocation();
35 log_debug(gc, plab)("%s other allocation: "
36 "region end waste: " SIZE_FORMAT "B, "
37 "regions filled: %u, "
38 "direct allocated: " SIZE_FORMAT "B, "
39 "failure used: " SIZE_FORMAT "B, "
40 "failure wasted: " SIZE_FORMAT "B",
41 _description,
42 _region_end_waste * HeapWordSize,
43 _regions_filled,
44 _direct_allocated * HeapWordSize,
45 _failure_used * HeapWordSize,
46 _failure_waste * HeapWordSize);
47 }
48
49 void G1EvacStats::adjust_desired_plab_sz() {
50 log_plab_allocation();
51
52 if (!ResizePLAB) {
53 // Clear accumulators for next round.
54 reset();
55 return;
56 }
57
58 assert(is_object_aligned(max_size()) && min_size() <= max_size(),
59 "PLAB clipping computation may be incorrect");
60
61 if (_allocated == 0) {
62 assert((_unused == 0),
63 "Inconsistency in PLAB stats: "
64 "_allocated: " SIZE_FORMAT ", "
65 "_wasted: " SIZE_FORMAT ", "
66 "_region_end_waste: " SIZE_FORMAT ", "
67 "_unused: " SIZE_FORMAT ", "
68 "_used : " SIZE_FORMAT,
69 _allocated, _wasted, _region_end_waste, _unused, used());
70 _allocated = 1;
71 }
72 // The size of the PLAB caps the amount of space that can be wasted at the
73 // end of the collection. In the worst case the last PLAB could be completely
74 // empty.
75 // This allows us to calculate the new PLAB size to achieve the
76 // TargetPLABWastePct given the latest memory usage and that the last buffer
77 // will be G1LastPLABAverageOccupancy full.
78 //
79 // E.g. assume that if in the current GC 100 words were allocated and a
80 // TargetPLABWastePct of 10 had been set.
81 //
82 // So we could waste up to 10 words to meet that percentage. Given that we
83 // also assume that that buffer is typically half-full, the new desired PLAB
84 // size is set to 20 words.
85 //
86 // The amount of allocation performed should be independent of the number of
87 // threads, so should the maximum waste we can spend in total. So if
88 // we used n threads to allocate, each of them can spend maximum waste/n words in
89 // a first rough approximation. The number of threads only comes into play later
90 // when actually retrieving the actual desired PLAB size.
91 //
92 // After calculating this optimal PLAB size the algorithm applies the usual
93 // exponential decaying average over this value to guess the next PLAB size.
94 //
95 // We account region end waste fully to PLAB allocation (in the calculation of
96 // what we consider as "used_for_waste_calculation" below). This is not
97 // completely fair, but is a conservative assumption because PLABs may be sized
98 // flexibly while we cannot adjust inline allocations.
99 // Allocation during GC will try to minimize region end waste so this impact
100 // should be minimal.
101 //
102 // We need to cover overflow when calculating the amount of space actually used
103 // by objects in PLABs when subtracting the region end waste.
104 // Region end waste may be higher than actual allocation. This may occur if many
105 // threads do not allocate anything but a few rather large objects. In this
106 // degenerate case the PLAB size would simply quickly tend to minimum PLAB size,
107 // which is an okay reaction.
108 size_t const used_for_waste_calculation = used() > _region_end_waste ? used() - _region_end_waste : 0;
109
110 size_t const total_waste_allowed = used_for_waste_calculation * TargetPLABWastePct;
111 size_t const cur_plab_sz = (size_t)((double)total_waste_allowed / G1LastPLABAverageOccupancy);
112 // Take historical weighted average
113 _filter.sample(cur_plab_sz);
114 _desired_net_plab_sz = MAX2(min_size(), (size_t)_filter.average());
115
116 log_sizing(cur_plab_sz, _desired_net_plab_sz);
117 // Clear accumulators for next round.
118 reset();
119 }
120
121 G1EvacStats::G1EvacStats(const char* description, size_t desired_plab_sz_, unsigned wt) :
122 PLABStats(description, desired_plab_sz_, wt),
123 _region_end_waste(0),
124 _regions_filled(0),
125 _direct_allocated(0),
126 _failure_used(0),
127 _failure_waste(0) {
128 }
129
130
131 G1EvacStats::~G1EvacStats() { }
|
1 /*
2 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
29 #include "gc/shared/gcId.hpp"
30 #include "logging/log.hpp"
31 #include "trace/tracing.hpp"
32
33 void G1EvacStats::log_plab_allocation() {
34 PLABStats::log_plab_allocation();
35 log_debug(gc, plab)("%s other allocation: "
36 "region end waste: " SIZE_FORMAT "B, "
37 "regions filled: %u, "
38 "direct allocated: " SIZE_FORMAT "B, "
39 "failure used: " SIZE_FORMAT "B, "
40 "failure wasted: " SIZE_FORMAT "B",
41 _description,
42 _region_end_waste * HeapWordSize,
43 _regions_filled,
44 _direct_allocated * HeapWordSize,
45 _failure_used * HeapWordSize,
46 _failure_waste * HeapWordSize);
47 }
48
49 size_t G1EvacStats::compute_desired_plab_sz() {
50 // The size of the PLAB caps the amount of space that can be wasted at the
51 // end of the collection. In the worst case the last PLAB could be completely
52 // empty.
53 // This allows us to calculate the new PLAB size to achieve the
54 // TargetPLABWastePct given the latest memory usage and that the last buffer
55 // will be G1LastPLABAverageOccupancy full.
56 //
57 // E.g. assume that if in the current GC 100 words were allocated and a
58 // TargetPLABWastePct of 10 had been set.
59 //
60 // So we could waste up to 10 words to meet that percentage. Given that we
61 // also assume that that buffer is typically half-full, the new desired PLAB
62 // size is set to 20 words.
63 //
64 // The amount of allocation performed should be independent of the number of
65 // threads, so should the maximum waste we can spend in total. So if
66 // we used n threads to allocate, each of them can spend maximum waste/n words in
67 // a first rough approximation. The number of threads only comes into play later
68 // when actually retrieving the actual desired PLAB size.
69 //
70 // After calculating this optimal PLAB size the algorithm applies the usual
71 // exponential decaying average over this value to guess the next PLAB size.
72 //
73 // We account region end waste fully to PLAB allocation (in the calculation of
74 // what we consider as "used_for_waste_calculation" below). This is not
75 // completely fair, but is a conservative assumption because PLABs may be sized
76 // flexibly while we cannot adjust inline allocations.
77 // Allocation during GC will try to minimize region end waste so this impact
78 // should be minimal.
79 //
80 // We need to cover overflow when calculating the amount of space actually used
81 // by objects in PLABs when subtracting the region end waste.
82 // Region end waste may be higher than actual allocation. This may occur if many
83 // threads do not allocate anything but a few rather large objects. In this
84 // degenerate case the PLAB size would simply quickly tend to minimum PLAB size,
85 // which is an okay reaction.
86 size_t const used_for_waste_calculation = used() > _region_end_waste ? used() - _region_end_waste : 0;
87
88 size_t const total_waste_allowed = used_for_waste_calculation * TargetPLABWastePct;
89 size_t const cur_plab_sz = (size_t)((double)total_waste_allowed / G1LastPLABAverageOccupancy);
90 return cur_plab_sz;
91 }
92
93 G1EvacStats::G1EvacStats(const char* description, size_t desired_plab_sz_, unsigned wt) :
94 PLABStats(description, desired_plab_sz_, wt),
95 _region_end_waste(0),
96 _regions_filled(0),
97 _direct_allocated(0),
98 _failure_used(0),
99 _failure_waste(0) {
100 }
101
102
103 G1EvacStats::~G1EvacStats() { }
|