Mon, 09 Jun 2008 07:18:59 -0700
6711930: NUMA allocator: ParOld can create a hole less than minimal object size in the lgrp chunk
Summary: The fix takes care of three issues that can create a hole less a minimal object in the lgrp chunk
Reviewed-by: ysr, apetrusenko
duke@435 | 1 | /* |
duke@435 | 2 | * Copyright 2002-2005 Sun Microsystems, Inc. All Rights Reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
duke@435 | 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
duke@435 | 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
duke@435 | 21 | * have any questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
duke@435 | 25 | // Catch-all file for utility classes |
duke@435 | 26 | |
duke@435 | 27 | // A weighted average maintains a running, weighted average |
duke@435 | 28 | // of some float value (templates would be handy here if we |
duke@435 | 29 | // need different types). |
duke@435 | 30 | // |
duke@435 | 31 | // The average is adaptive in that we smooth it for the |
duke@435 | 32 | // initial samples; we don't use the weight until we have |
duke@435 | 33 | // enough samples for it to be meaningful. |
duke@435 | 34 | // |
duke@435 | 35 | // This serves as our best estimate of a future unknown. |
duke@435 | 36 | // |
duke@435 | 37 | class AdaptiveWeightedAverage : public CHeapObj { |
duke@435 | 38 | private: |
duke@435 | 39 | float _average; // The last computed average |
duke@435 | 40 | unsigned _sample_count; // How often we've sampled this average |
duke@435 | 41 | unsigned _weight; // The weight used to smooth the averages |
duke@435 | 42 | // A higher weight favors the most |
duke@435 | 43 | // recent data. |
duke@435 | 44 | |
duke@435 | 45 | protected: |
duke@435 | 46 | float _last_sample; // The last value sampled. |
duke@435 | 47 | |
duke@435 | 48 | void increment_count() { _sample_count++; } |
duke@435 | 49 | void set_average(float avg) { _average = avg; } |
duke@435 | 50 | |
duke@435 | 51 | // Helper function, computes an adaptive weighted average |
duke@435 | 52 | // given a sample and the last average |
duke@435 | 53 | float compute_adaptive_average(float new_sample, float average); |
duke@435 | 54 | |
duke@435 | 55 | public: |
duke@435 | 56 | // Input weight must be between 0 and 100 |
duke@435 | 57 | AdaptiveWeightedAverage(unsigned weight) : |
duke@435 | 58 | _average(0.0), _sample_count(0), _weight(weight), _last_sample(0.0) { |
duke@435 | 59 | } |
duke@435 | 60 | |
duke@435 | 61 | // Accessors |
duke@435 | 62 | float average() const { return _average; } |
duke@435 | 63 | unsigned weight() const { return _weight; } |
duke@435 | 64 | unsigned count() const { return _sample_count; } |
duke@435 | 65 | float last_sample() const { return _last_sample; } |
duke@435 | 66 | |
duke@435 | 67 | // Update data with a new sample. |
duke@435 | 68 | void sample(float new_sample); |
duke@435 | 69 | |
duke@435 | 70 | static inline float exp_avg(float avg, float sample, |
duke@435 | 71 | unsigned int weight) { |
duke@435 | 72 | assert(0 <= weight && weight <= 100, "weight must be a percent"); |
duke@435 | 73 | return (100.0F - weight) * avg / 100.0F + weight * sample / 100.0F; |
duke@435 | 74 | } |
duke@435 | 75 | static inline size_t exp_avg(size_t avg, size_t sample, |
duke@435 | 76 | unsigned int weight) { |
duke@435 | 77 | // Convert to float and back to avoid integer overflow. |
duke@435 | 78 | return (size_t)exp_avg((float)avg, (float)sample, weight); |
duke@435 | 79 | } |
duke@435 | 80 | }; |
duke@435 | 81 | |
duke@435 | 82 | |
duke@435 | 83 | // A weighted average that includes a deviation from the average, |
duke@435 | 84 | // some multiple of which is added to the average. |
duke@435 | 85 | // |
duke@435 | 86 | // This serves as our best estimate of an upper bound on a future |
duke@435 | 87 | // unknown. |
duke@435 | 88 | class AdaptivePaddedAverage : public AdaptiveWeightedAverage { |
duke@435 | 89 | private: |
duke@435 | 90 | float _padded_avg; // The last computed padded average |
duke@435 | 91 | float _deviation; // Running deviation from the average |
duke@435 | 92 | unsigned _padding; // A multiple which, added to the average, |
duke@435 | 93 | // gives us an upper bound guess. |
duke@435 | 94 | |
duke@435 | 95 | protected: |
duke@435 | 96 | void set_padded_average(float avg) { _padded_avg = avg; } |
duke@435 | 97 | void set_deviation(float dev) { _deviation = dev; } |
duke@435 | 98 | |
duke@435 | 99 | public: |
duke@435 | 100 | AdaptivePaddedAverage() : |
duke@435 | 101 | AdaptiveWeightedAverage(0), |
duke@435 | 102 | _padded_avg(0.0), _deviation(0.0), _padding(0) {} |
duke@435 | 103 | |
duke@435 | 104 | AdaptivePaddedAverage(unsigned weight, unsigned padding) : |
duke@435 | 105 | AdaptiveWeightedAverage(weight), |
duke@435 | 106 | _padded_avg(0.0), _deviation(0.0), _padding(padding) {} |
duke@435 | 107 | |
duke@435 | 108 | // Placement support |
duke@435 | 109 | void* operator new(size_t ignored, void* p) { return p; } |
duke@435 | 110 | // Allocator |
duke@435 | 111 | void* operator new(size_t size) { return CHeapObj::operator new(size); } |
duke@435 | 112 | |
duke@435 | 113 | // Accessor |
duke@435 | 114 | float padded_average() const { return _padded_avg; } |
duke@435 | 115 | float deviation() const { return _deviation; } |
duke@435 | 116 | unsigned padding() const { return _padding; } |
duke@435 | 117 | |
duke@435 | 118 | // Override |
duke@435 | 119 | void sample(float new_sample); |
duke@435 | 120 | }; |
duke@435 | 121 | |
duke@435 | 122 | // A weighted average that includes a deviation from the average, |
duke@435 | 123 | // some multiple of which is added to the average. |
duke@435 | 124 | // |
duke@435 | 125 | // This serves as our best estimate of an upper bound on a future |
duke@435 | 126 | // unknown. |
duke@435 | 127 | // A special sort of padded average: it doesn't update deviations |
duke@435 | 128 | // if the sample is zero. The average is allowed to change. We're |
duke@435 | 129 | // preventing the zero samples from drastically changing our padded |
duke@435 | 130 | // average. |
duke@435 | 131 | class AdaptivePaddedNoZeroDevAverage : public AdaptivePaddedAverage { |
duke@435 | 132 | public: |
duke@435 | 133 | AdaptivePaddedNoZeroDevAverage(unsigned weight, unsigned padding) : |
duke@435 | 134 | AdaptivePaddedAverage(weight, padding) {} |
duke@435 | 135 | // Override |
duke@435 | 136 | void sample(float new_sample); |
duke@435 | 137 | }; |
duke@435 | 138 | // Use a least squares fit to a set of data to generate a linear |
duke@435 | 139 | // equation. |
duke@435 | 140 | // y = intercept + slope * x |
duke@435 | 141 | |
duke@435 | 142 | class LinearLeastSquareFit : public CHeapObj { |
duke@435 | 143 | double _sum_x; // sum of all independent data points x |
duke@435 | 144 | double _sum_x_squared; // sum of all independent data points x**2 |
duke@435 | 145 | double _sum_y; // sum of all dependent data points y |
duke@435 | 146 | double _sum_xy; // sum of all x * y. |
duke@435 | 147 | double _intercept; // constant term |
duke@435 | 148 | double _slope; // slope |
duke@435 | 149 | // The weighted averages are not currently used but perhaps should |
duke@435 | 150 | // be used to get decaying averages. |
duke@435 | 151 | AdaptiveWeightedAverage _mean_x; // weighted mean of independent variable |
duke@435 | 152 | AdaptiveWeightedAverage _mean_y; // weighted mean of dependent variable |
duke@435 | 153 | |
duke@435 | 154 | public: |
duke@435 | 155 | LinearLeastSquareFit(unsigned weight); |
duke@435 | 156 | void update(double x, double y); |
duke@435 | 157 | double y(double x); |
duke@435 | 158 | double slope() { return _slope; } |
duke@435 | 159 | // Methods to decide if a change in the dependent variable will |
duke@435 | 160 | // achive a desired goal. Note that these methods are not |
duke@435 | 161 | // complementary and both are needed. |
duke@435 | 162 | bool decrement_will_decrease(); |
duke@435 | 163 | bool increment_will_decrease(); |
duke@435 | 164 | }; |
duke@435 | 165 | |
duke@435 | 166 | class GCPauseTimer : StackObj { |
duke@435 | 167 | elapsedTimer* _timer; |
duke@435 | 168 | public: |
duke@435 | 169 | GCPauseTimer(elapsedTimer* timer) { |
duke@435 | 170 | _timer = timer; |
duke@435 | 171 | _timer->stop(); |
duke@435 | 172 | } |
duke@435 | 173 | ~GCPauseTimer() { |
duke@435 | 174 | _timer->start(); |
duke@435 | 175 | } |
duke@435 | 176 | }; |