Sat, 27 Sep 2008 00:33:13 -0700
6740923: NUMA allocator: Ensure the progress of adaptive chunk resizing
Summary: Treat a chuck where the allocation has failed as fully used.
Reviewed-by: ysr
ysr@777 | 1 | /* |
ysr@777 | 2 | * Copyright 2001-2007 Sun Microsystems, Inc. All Rights Reserved. |
ysr@777 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ysr@777 | 4 | * |
ysr@777 | 5 | * This code is free software; you can redistribute it and/or modify it |
ysr@777 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ysr@777 | 7 | * published by the Free Software Foundation. |
ysr@777 | 8 | * |
ysr@777 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
ysr@777 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ysr@777 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ysr@777 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
ysr@777 | 13 | * accompanied this code). |
ysr@777 | 14 | * |
ysr@777 | 15 | * You should have received a copy of the GNU General Public License version |
ysr@777 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
ysr@777 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ysr@777 | 18 | * |
ysr@777 | 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
ysr@777 | 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
ysr@777 | 21 | * have any questions. |
ysr@777 | 22 | * |
ysr@777 | 23 | */ |
ysr@777 | 24 | |
ysr@777 | 25 | // COTracker keeps track of the concurrent overhead of a GC thread. |
ysr@777 | 26 | |
ysr@777 | 27 | // A thread that needs to be tracked must, itself, start up its |
ysr@777 | 28 | // tracker with the start() method and then call the update() method |
ysr@777 | 29 | // at regular intervals. What the tracker does is to calculate the |
ysr@777 | 30 | // concurrent overhead of a process at a given update period. The |
ysr@777 | 31 | // tracker starts and when is detects that it has exceeded the given |
ysr@777 | 32 | // period, it calculates the duration of the period in wall-clock time |
ysr@777 | 33 | // and the duration of the period in vtime (i.e. how much time the |
ysr@777 | 34 | // concurrent processes really took up during this period). The ratio |
ysr@777 | 35 | // of the latter over the former is the concurrent overhead of that |
ysr@777 | 36 | // process for that period over a single CPU. This overhead is stored |
ysr@777 | 37 | // on the tracker, "timestamped" with the wall-clock time of the end |
ysr@777 | 38 | // of the period. When the concurrent overhead of this process needs |
ysr@777 | 39 | // to be queried, this last "reading" provides a good approximation |
ysr@777 | 40 | // (we assume that the concurrent overhead of a particular thread |
ysr@777 | 41 | // stays largely constant over time). The timestamp is necessary to |
ysr@777 | 42 | // detect when the process has stopped working and the recorded |
ysr@777 | 43 | // reading hasn't been updated for some time. |
ysr@777 | 44 | |
ysr@777 | 45 | // Each concurrent GC thread is considered to be part of a "group" |
ysr@777 | 46 | // (i.e. any available concurrent marking threads are part of the |
ysr@777 | 47 | // "concurrent marking thread group"). A COTracker is associated with |
ysr@777 | 48 | // a single group at construction-time. It's up to each collector to |
ysr@777 | 49 | // decide how groups will be mapped to such an id (ids should start |
ysr@777 | 50 | // from 0 and be consecutive; there's a hardcoded max group num |
ysr@777 | 51 | // defined on the GCOverheadTracker class). The notion of a group has |
ysr@777 | 52 | // been introduced to be able to identify how much overhead was |
ysr@777 | 53 | // imposed by each group, instead of getting a single value that |
ysr@777 | 54 | // covers all concurrent overhead. |
ysr@777 | 55 | |
ysr@777 | 56 | class COTracker { |
ysr@777 | 57 | private: |
ysr@777 | 58 | // It indicates whether this tracker is enabled or not. When the |
ysr@777 | 59 | // tracker is disabled, then it returns 0.0 as the latest concurrent |
ysr@777 | 60 | // overhead and several methods (reset, start, and update) are not |
ysr@777 | 61 | // supposed to be called on it. This enabling / disabling facility |
ysr@777 | 62 | // is really provided to make a bit more explicit in the code when a |
ysr@777 | 63 | // particulary tracker of a processes that doesn't run all the time |
ysr@777 | 64 | // (e.g. concurrent marking) is supposed to be used and not it's not. |
ysr@777 | 65 | bool _enabled; |
ysr@777 | 66 | |
ysr@777 | 67 | // The ID of the group associated with this tracker. |
ysr@777 | 68 | int _group; |
ysr@777 | 69 | |
ysr@777 | 70 | // The update period of the tracker. A new value for the concurrent |
ysr@777 | 71 | // overhead of the associated process will be made at intervals no |
ysr@777 | 72 | // smaller than this. |
ysr@777 | 73 | double _update_period_sec; |
ysr@777 | 74 | |
ysr@777 | 75 | // The start times (both wall-block time and vtime) of the current |
ysr@777 | 76 | // interval. |
ysr@777 | 77 | double _period_start_time_sec; |
ysr@777 | 78 | double _period_start_vtime_sec; |
ysr@777 | 79 | |
ysr@777 | 80 | // Number seq of the concurrent overhead readings within a period |
ysr@777 | 81 | NumberSeq _conc_overhead_seq; |
ysr@777 | 82 | |
ysr@777 | 83 | // The latest reading of the concurrent overhead (over a single CPU) |
ysr@777 | 84 | // imposed by the associated concurrent thread, made available at |
ysr@777 | 85 | // the indicated wall-clock time. |
ysr@777 | 86 | double _conc_overhead; |
ysr@777 | 87 | double _time_stamp_sec; |
ysr@777 | 88 | |
ysr@777 | 89 | // The number of CPUs that the host machine has (for convenience |
ysr@777 | 90 | // really, as we'd have to keep translating it into a double) |
ysr@777 | 91 | static double _cpu_number; |
ysr@777 | 92 | |
ysr@777 | 93 | // Fields that keep a list of all trackers created. This is useful, |
ysr@777 | 94 | // since it allows us to sum up the concurrent overhead without |
ysr@777 | 95 | // having to write code for a specific collector to broadcast a |
ysr@777 | 96 | // request to all its concurrent processes. |
ysr@777 | 97 | COTracker* _next; |
ysr@777 | 98 | static COTracker* _head; |
ysr@777 | 99 | |
ysr@777 | 100 | // It indicates that a new period is starting by updating the |
ysr@777 | 101 | // _period_start_time_sec and _period_start_vtime_sec fields. |
ysr@777 | 102 | void resetPeriod(double now_sec, double vnow_sec); |
ysr@777 | 103 | // It updates the latest concurrent overhead reading, taken at a |
ysr@777 | 104 | // given wall-clock time. |
ysr@777 | 105 | void setConcOverhead(double time_stamp_sec, double conc_overhead); |
ysr@777 | 106 | |
ysr@777 | 107 | // It determines whether the time stamp of the latest concurrent |
ysr@777 | 108 | // overhead reading is out of date or not. |
ysr@777 | 109 | bool outOfDate(double now_sec) { |
ysr@777 | 110 | // The latest reading is considered out of date, if it was taken |
ysr@777 | 111 | // 1.2x the update period. |
ysr@777 | 112 | return (now_sec - _time_stamp_sec) > 1.2 * _update_period_sec; |
ysr@777 | 113 | } |
ysr@777 | 114 | |
ysr@777 | 115 | public: |
ysr@777 | 116 | // The constructor which associates the tracker with a group ID. |
ysr@777 | 117 | COTracker(int group); |
ysr@777 | 118 | |
ysr@777 | 119 | // Methods to enable / disable the tracker and query whether it is enabled. |
ysr@777 | 120 | void enable() { _enabled = true; } |
ysr@777 | 121 | void disable() { _enabled = false; } |
ysr@777 | 122 | bool enabled() { return _enabled; } |
ysr@777 | 123 | |
ysr@777 | 124 | // It resets the tracker and sets concurrent overhead reading to be |
ysr@777 | 125 | // the given parameter and the associated time stamp to be now. |
ysr@777 | 126 | void reset(double starting_conc_overhead = 0.0); |
ysr@777 | 127 | // The tracker starts tracking. IT should only be called from the |
ysr@777 | 128 | // concurrent thread that is tracked by this tracker. |
ysr@777 | 129 | void start(); |
ysr@777 | 130 | // It updates the tracker and, if the current period is longer than |
ysr@777 | 131 | // the update period, the concurrent overhead reading will be |
ysr@777 | 132 | // updated. force_end being true indicates that it's the last call |
ysr@777 | 133 | // to update() by this process before the tracker is disabled (the |
ysr@777 | 134 | // tracker can be re-enabled later if necessary). It should only be |
ysr@777 | 135 | // called from the concurrent thread that is tracked by this tracker |
ysr@777 | 136 | // and while the thread has joined the STS. |
ysr@777 | 137 | void update(bool force_end = false); |
ysr@777 | 138 | // It adjusts the contents of the tracker to take into account a STW |
ysr@777 | 139 | // pause. |
ysr@777 | 140 | void updateForSTW(double start_sec, double end_sec); |
ysr@777 | 141 | |
ysr@777 | 142 | // It returns the last concurrent overhead reading over a single |
ysr@777 | 143 | // CPU. If the reading is out of date, or the tracker is disabled, |
ysr@777 | 144 | // it returns 0.0. |
ysr@777 | 145 | double concCPUOverhead(double now_sec) { |
ysr@777 | 146 | if (!_enabled || outOfDate(now_sec)) |
ysr@777 | 147 | return 0.0; |
ysr@777 | 148 | else |
ysr@777 | 149 | return _conc_overhead; |
ysr@777 | 150 | } |
ysr@777 | 151 | |
ysr@777 | 152 | // It returns the last concurrent overhead reading over all CPUs |
ysr@777 | 153 | // that the host machine has. If the reading is out of date, or the |
ysr@777 | 154 | // tracker is disabled, it returns 0.0. |
ysr@777 | 155 | double concOverhead(double now_sec) { |
ysr@777 | 156 | return concCPUOverhead(now_sec) / _cpu_number; |
ysr@777 | 157 | } |
ysr@777 | 158 | |
ysr@777 | 159 | double predConcOverhead(); |
ysr@777 | 160 | |
ysr@777 | 161 | void resetPred(); |
ysr@777 | 162 | |
ysr@777 | 163 | // statics |
ysr@777 | 164 | |
ysr@777 | 165 | // It notifies all trackers about a STW pause. |
ysr@777 | 166 | static void updateAllForSTW(double start_sec, double end_sec); |
ysr@777 | 167 | |
ysr@777 | 168 | // It returns the sum of the concurrent overhead readings of all |
ysr@777 | 169 | // available (and enabled) trackers for the given time stamp. The |
ysr@777 | 170 | // overhead is over all the CPUs of the host machine. |
ysr@777 | 171 | |
ysr@777 | 172 | static double totalConcOverhead(double now_sec); |
ysr@777 | 173 | // Like the previous method, but it also sums up the overheads per |
ysr@777 | 174 | // group number. The length of the co_per_group array must be at |
ysr@777 | 175 | // least as large group_num |
ysr@777 | 176 | static double totalConcOverhead(double now_sec, |
ysr@777 | 177 | size_t group_num, |
ysr@777 | 178 | double* co_per_group); |
ysr@777 | 179 | |
ysr@777 | 180 | static double totalPredConcOverhead(); |
ysr@777 | 181 | }; |