annotate src/share/vm/gc_implementation/shared/mutableNUMASpace.hpp @ 196:d1605aabd0a1 jdk7-b30

6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
author xdono
date Wed, 02 Jul 2008 12:55:16 -0700
parents d1635bf93939
children 850fdf70db2b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
196
d1605aabd0a1 6719955: Update copyright year
xdono
parents: 190
diff changeset
2 * Copyright 2006-2008 Sun Microsystems, Inc. All Rights Reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
26 * The NUMA-aware allocator (MutableNUMASpace) is basically a modification
a61af66fc99e Initial load
duke
parents:
diff changeset
27 * of MutableSpace which preserves interfaces but implements different
a61af66fc99e Initial load
duke
parents:
diff changeset
28 * functionality. The space is split into chunks for each locality group
a61af66fc99e Initial load
duke
parents:
diff changeset
29 * (resizing for adaptive size policy is also supported). For each thread
a61af66fc99e Initial load
duke
parents:
diff changeset
30 * allocations are performed in the chunk corresponding to the home locality
a61af66fc99e Initial load
duke
parents:
diff changeset
31 * group of the thread. Whenever any chunk fills-in the young generation
a61af66fc99e Initial load
duke
parents:
diff changeset
32 * collection occurs.
a61af66fc99e Initial load
duke
parents:
diff changeset
33 * The chunks can be also be adaptively resized. The idea behind the adaptive
a61af66fc99e Initial load
duke
parents:
diff changeset
34 * sizing is to reduce the loss of the space in the eden due to fragmentation.
a61af66fc99e Initial load
duke
parents:
diff changeset
35 * The main cause of fragmentation is uneven allocation rates of threads.
a61af66fc99e Initial load
duke
parents:
diff changeset
36 * The allocation rate difference between locality groups may be caused either by
a61af66fc99e Initial load
duke
parents:
diff changeset
37 * application specifics or by uneven LWP distribution by the OS. Besides,
a61af66fc99e Initial load
duke
parents:
diff changeset
38 * application can have less threads then the number of locality groups.
a61af66fc99e Initial load
duke
parents:
diff changeset
39 * In order to resize the chunk we measure the allocation rate of the
a61af66fc99e Initial load
duke
parents:
diff changeset
40 * application between collections. After that we reshape the chunks to reflect
a61af66fc99e Initial load
duke
parents:
diff changeset
41 * the allocation rate pattern. The AdaptiveWeightedAverage exponentially
a61af66fc99e Initial load
duke
parents:
diff changeset
42 * decaying average is used to smooth the measurements. The NUMASpaceResizeRate
a61af66fc99e Initial load
duke
parents:
diff changeset
43 * parameter is used to control the adaptation speed by restricting the number of
a61af66fc99e Initial load
duke
parents:
diff changeset
44 * bytes that can be moved during the adaptation phase.
a61af66fc99e Initial load
duke
parents:
diff changeset
45 * Chunks may contain pages from a wrong locality group. The page-scanner has
a61af66fc99e Initial load
duke
parents:
diff changeset
46 * been introduced to address the problem. Remote pages typically appear due to
a61af66fc99e Initial load
duke
parents:
diff changeset
47 * the memory shortage in the target locality group. Besides Solaris would
a61af66fc99e Initial load
duke
parents:
diff changeset
48 * allocate a large page from the remote locality group even if there are small
a61af66fc99e Initial load
duke
parents:
diff changeset
49 * local pages available. The page-scanner scans the pages right after the
a61af66fc99e Initial load
duke
parents:
diff changeset
50 * collection and frees remote pages in hope that subsequent reallocation would
a61af66fc99e Initial load
duke
parents:
diff changeset
51 * be more successful. This approach proved to be useful on systems with high
a61af66fc99e Initial load
duke
parents:
diff changeset
52 * load where multiple processes are competing for the memory.
a61af66fc99e Initial load
duke
parents:
diff changeset
53 */
a61af66fc99e Initial load
duke
parents:
diff changeset
54
a61af66fc99e Initial load
duke
parents:
diff changeset
55 class MutableNUMASpace : public MutableSpace {
a61af66fc99e Initial load
duke
parents:
diff changeset
56 friend class VMStructs;
a61af66fc99e Initial load
duke
parents:
diff changeset
57
a61af66fc99e Initial load
duke
parents:
diff changeset
58 class LGRPSpace : public CHeapObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
59 int _lgrp_id;
a61af66fc99e Initial load
duke
parents:
diff changeset
60 MutableSpace* _space;
a61af66fc99e Initial load
duke
parents:
diff changeset
61 MemRegion _invalid_region;
a61af66fc99e Initial load
duke
parents:
diff changeset
62 AdaptiveWeightedAverage *_alloc_rate;
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
64 struct SpaceStats {
a61af66fc99e Initial load
duke
parents:
diff changeset
65 size_t _local_space, _remote_space, _unbiased_space, _uncommited_space;
a61af66fc99e Initial load
duke
parents:
diff changeset
66 size_t _large_pages, _small_pages;
a61af66fc99e Initial load
duke
parents:
diff changeset
67
a61af66fc99e Initial load
duke
parents:
diff changeset
68 SpaceStats() {
a61af66fc99e Initial load
duke
parents:
diff changeset
69 _local_space = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
70 _remote_space = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
71 _unbiased_space = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
72 _uncommited_space = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
73 _large_pages = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
74 _small_pages = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
75 }
a61af66fc99e Initial load
duke
parents:
diff changeset
76 };
a61af66fc99e Initial load
duke
parents:
diff changeset
77
a61af66fc99e Initial load
duke
parents:
diff changeset
78 SpaceStats _space_stats;
a61af66fc99e Initial load
duke
parents:
diff changeset
79
a61af66fc99e Initial load
duke
parents:
diff changeset
80 char* _last_page_scanned;
a61af66fc99e Initial load
duke
parents:
diff changeset
81 char* last_page_scanned() { return _last_page_scanned; }
a61af66fc99e Initial load
duke
parents:
diff changeset
82 void set_last_page_scanned(char* p) { _last_page_scanned = p; }
a61af66fc99e Initial load
duke
parents:
diff changeset
83 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
84 LGRPSpace(int l) : _lgrp_id(l), _last_page_scanned(NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
85 _space = new MutableSpace();
a61af66fc99e Initial load
duke
parents:
diff changeset
86 _alloc_rate = new AdaptiveWeightedAverage(NUMAChunkResizeWeight);
a61af66fc99e Initial load
duke
parents:
diff changeset
87 }
a61af66fc99e Initial load
duke
parents:
diff changeset
88 ~LGRPSpace() {
a61af66fc99e Initial load
duke
parents:
diff changeset
89 delete _space;
a61af66fc99e Initial load
duke
parents:
diff changeset
90 delete _alloc_rate;
a61af66fc99e Initial load
duke
parents:
diff changeset
91 }
a61af66fc99e Initial load
duke
parents:
diff changeset
92
a61af66fc99e Initial load
duke
parents:
diff changeset
93 void add_invalid_region(MemRegion r) {
a61af66fc99e Initial load
duke
parents:
diff changeset
94 if (!_invalid_region.is_empty()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
95 _invalid_region.set_start(MIN2(_invalid_region.start(), r.start()));
a61af66fc99e Initial load
duke
parents:
diff changeset
96 _invalid_region.set_end(MAX2(_invalid_region.end(), r.end()));
a61af66fc99e Initial load
duke
parents:
diff changeset
97 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
98 _invalid_region = r;
a61af66fc99e Initial load
duke
parents:
diff changeset
99 }
a61af66fc99e Initial load
duke
parents:
diff changeset
100 }
a61af66fc99e Initial load
duke
parents:
diff changeset
101
a61af66fc99e Initial load
duke
parents:
diff changeset
102 static bool equals(void* lgrp_id_value, LGRPSpace* p) {
a61af66fc99e Initial load
duke
parents:
diff changeset
103 return *(int*)lgrp_id_value == p->lgrp_id();
a61af66fc99e Initial load
duke
parents:
diff changeset
104 }
a61af66fc99e Initial load
duke
parents:
diff changeset
105
a61af66fc99e Initial load
duke
parents:
diff changeset
106 void sample() {
a61af66fc99e Initial load
duke
parents:
diff changeset
107 alloc_rate()->sample(space()->used_in_bytes());
a61af66fc99e Initial load
duke
parents:
diff changeset
108 }
a61af66fc99e Initial load
duke
parents:
diff changeset
109
a61af66fc99e Initial load
duke
parents:
diff changeset
110 MemRegion invalid_region() const { return _invalid_region; }
a61af66fc99e Initial load
duke
parents:
diff changeset
111 void set_invalid_region(MemRegion r) { _invalid_region = r; }
a61af66fc99e Initial load
duke
parents:
diff changeset
112 int lgrp_id() const { return _lgrp_id; }
a61af66fc99e Initial load
duke
parents:
diff changeset
113 MutableSpace* space() const { return _space; }
a61af66fc99e Initial load
duke
parents:
diff changeset
114 AdaptiveWeightedAverage* alloc_rate() const { return _alloc_rate; }
a61af66fc99e Initial load
duke
parents:
diff changeset
115 SpaceStats* space_stats() { return &_space_stats; }
a61af66fc99e Initial load
duke
parents:
diff changeset
116 void clear_space_stats() { _space_stats = SpaceStats(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
117
a61af66fc99e Initial load
duke
parents:
diff changeset
118 void accumulate_statistics(size_t page_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
119 void scan_pages(size_t page_size, size_t page_count);
a61af66fc99e Initial load
duke
parents:
diff changeset
120 };
a61af66fc99e Initial load
duke
parents:
diff changeset
121
a61af66fc99e Initial load
duke
parents:
diff changeset
122 GrowableArray<LGRPSpace*>* _lgrp_spaces;
a61af66fc99e Initial load
duke
parents:
diff changeset
123 size_t _page_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
124 unsigned _adaptation_cycles, _samples_count;
a61af66fc99e Initial load
duke
parents:
diff changeset
125
a61af66fc99e Initial load
duke
parents:
diff changeset
126 void set_page_size(size_t psz) { _page_size = psz; }
a61af66fc99e Initial load
duke
parents:
diff changeset
127 size_t page_size() const { return _page_size; }
a61af66fc99e Initial load
duke
parents:
diff changeset
128
a61af66fc99e Initial load
duke
parents:
diff changeset
129 unsigned adaptation_cycles() { return _adaptation_cycles; }
a61af66fc99e Initial load
duke
parents:
diff changeset
130 void set_adaptation_cycles(int v) { _adaptation_cycles = v; }
a61af66fc99e Initial load
duke
parents:
diff changeset
131
a61af66fc99e Initial load
duke
parents:
diff changeset
132 unsigned samples_count() { return _samples_count; }
a61af66fc99e Initial load
duke
parents:
diff changeset
133 void increment_samples_count() { ++_samples_count; }
a61af66fc99e Initial load
duke
parents:
diff changeset
134
a61af66fc99e Initial load
duke
parents:
diff changeset
135 size_t _base_space_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
136 void set_base_space_size(size_t v) { _base_space_size = v; }
a61af66fc99e Initial load
duke
parents:
diff changeset
137 size_t base_space_size() const { return _base_space_size; }
a61af66fc99e Initial load
duke
parents:
diff changeset
138
a61af66fc99e Initial load
duke
parents:
diff changeset
139 // Check if the NUMA topology has changed. Add and remove spaces if needed.
a61af66fc99e Initial load
duke
parents:
diff changeset
140 // The update can be forced by setting the force parameter equal to true.
a61af66fc99e Initial load
duke
parents:
diff changeset
141 bool update_layout(bool force);
141
fcbfc50865ab 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 0
diff changeset
142 // Bias region towards the lgrp.
fcbfc50865ab 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 0
diff changeset
143 void bias_region(MemRegion mr, int lgrp_id);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
144 // Free pages in a given region.
a61af66fc99e Initial load
duke
parents:
diff changeset
145 void free_region(MemRegion mr);
a61af66fc99e Initial load
duke
parents:
diff changeset
146 // Get current chunk size.
a61af66fc99e Initial load
duke
parents:
diff changeset
147 size_t current_chunk_size(int i);
a61af66fc99e Initial load
duke
parents:
diff changeset
148 // Get default chunk size (equally divide the space).
a61af66fc99e Initial load
duke
parents:
diff changeset
149 size_t default_chunk_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
150 // Adapt the chunk size to follow the allocation rate.
a61af66fc99e Initial load
duke
parents:
diff changeset
151 size_t adaptive_chunk_size(int i, size_t limit);
a61af66fc99e Initial load
duke
parents:
diff changeset
152 // Scan and free invalid pages.
a61af66fc99e Initial load
duke
parents:
diff changeset
153 void scan_pages(size_t page_count);
a61af66fc99e Initial load
duke
parents:
diff changeset
154 // Return the bottom_region and the top_region. Align them to page_size() boundary.
a61af66fc99e Initial load
duke
parents:
diff changeset
155 // |------------------new_region---------------------------------|
a61af66fc99e Initial load
duke
parents:
diff changeset
156 // |----bottom_region--|---intersection---|------top_region------|
a61af66fc99e Initial load
duke
parents:
diff changeset
157 void select_tails(MemRegion new_region, MemRegion intersection,
a61af66fc99e Initial load
duke
parents:
diff changeset
158 MemRegion* bottom_region, MemRegion *top_region);
a61af66fc99e Initial load
duke
parents:
diff changeset
159 // Try to merge the invalid region with the bottom or top region by decreasing
a61af66fc99e Initial load
duke
parents:
diff changeset
160 // the intersection area. Return the invalid_region aligned to the page_size()
a61af66fc99e Initial load
duke
parents:
diff changeset
161 // boundary if it's inside the intersection. Return non-empty invalid_region
a61af66fc99e Initial load
duke
parents:
diff changeset
162 // if it lies inside the intersection (also page-aligned).
a61af66fc99e Initial load
duke
parents:
diff changeset
163 // |------------------new_region---------------------------------|
a61af66fc99e Initial load
duke
parents:
diff changeset
164 // |----------------|-------invalid---|--------------------------|
a61af66fc99e Initial load
duke
parents:
diff changeset
165 // |----bottom_region--|---intersection---|------top_region------|
a61af66fc99e Initial load
duke
parents:
diff changeset
166 void merge_regions(MemRegion new_region, MemRegion* intersection,
a61af66fc99e Initial load
duke
parents:
diff changeset
167 MemRegion *invalid_region);
a61af66fc99e Initial load
duke
parents:
diff changeset
168
a61af66fc99e Initial load
duke
parents:
diff changeset
169 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
170 GrowableArray<LGRPSpace*>* lgrp_spaces() const { return _lgrp_spaces; }
a61af66fc99e Initial load
duke
parents:
diff changeset
171 MutableNUMASpace();
a61af66fc99e Initial load
duke
parents:
diff changeset
172 virtual ~MutableNUMASpace();
a61af66fc99e Initial load
duke
parents:
diff changeset
173 // Space initialization.
a61af66fc99e Initial load
duke
parents:
diff changeset
174 virtual void initialize(MemRegion mr, bool clear_space);
a61af66fc99e Initial load
duke
parents:
diff changeset
175 // Update space layout if necessary. Do all adaptive resizing job.
a61af66fc99e Initial load
duke
parents:
diff changeset
176 virtual void update();
a61af66fc99e Initial load
duke
parents:
diff changeset
177 // Update allocation rate averages.
a61af66fc99e Initial load
duke
parents:
diff changeset
178 virtual void accumulate_statistics();
a61af66fc99e Initial load
duke
parents:
diff changeset
179
a61af66fc99e Initial load
duke
parents:
diff changeset
180 virtual void clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
181 virtual void mangle_unused_area();
a61af66fc99e Initial load
duke
parents:
diff changeset
182 virtual void ensure_parsability();
a61af66fc99e Initial load
duke
parents:
diff changeset
183 virtual size_t used_in_words() const;
a61af66fc99e Initial load
duke
parents:
diff changeset
184 virtual size_t free_in_words() const;
a61af66fc99e Initial load
duke
parents:
diff changeset
185 virtual size_t tlab_capacity(Thread* thr) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
186 virtual size_t unsafe_max_tlab_alloc(Thread* thr) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
187
a61af66fc99e Initial load
duke
parents:
diff changeset
188 // Allocation (return NULL if full)
a61af66fc99e Initial load
duke
parents:
diff changeset
189 virtual HeapWord* allocate(size_t word_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
190 virtual HeapWord* cas_allocate(size_t word_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
191
a61af66fc99e Initial load
duke
parents:
diff changeset
192 // Debugging
a61af66fc99e Initial load
duke
parents:
diff changeset
193 virtual void print_on(outputStream* st) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
194 virtual void print_short_on(outputStream* st) const;
190
d1635bf93939 6711930: NUMA allocator: ParOld can create a hole less than minimal object size in the lgrp chunk
iveresov
parents: 141
diff changeset
195 virtual void verify(bool allow_dirty);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
196
a61af66fc99e Initial load
duke
parents:
diff changeset
197 virtual void set_top(HeapWord* value);
a61af66fc99e Initial load
duke
parents:
diff changeset
198 };