mutableNUMASpace.hpp revision 263
/*
* Copyright 2006-2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
/*
* The NUMA-aware allocator (MutableNUMASpace) is basically a modification
* of MutableSpace which preserves interfaces but implements different
* functionality. The space is split into chunks for each locality group
* (resizing for adaptive size policy is also supported). For each thread
* allocations are performed in the chunk corresponding to the home locality
* group of the thread. Whenever any chunk fills-in the young generation
* collection occurs.
* The chunks can be also be adaptively resized. The idea behind the adaptive
* sizing is to reduce the loss of the space in the eden due to fragmentation.
* The main cause of fragmentation is uneven allocation rates of threads.
* The allocation rate difference between locality groups may be caused either by
* application specifics or by uneven LWP distribution by the OS. Besides,
* application can have less threads then the number of locality groups.
* In order to resize the chunk we measure the allocation rate of the
* application between collections. After that we reshape the chunks to reflect
* the allocation rate pattern. The AdaptiveWeightedAverage exponentially
* decaying average is used to smooth the measurements. The NUMASpaceResizeRate
* parameter is used to control the adaptation speed by restricting the number of
* bytes that can be moved during the adaptation phase.
* Chunks may contain pages from a wrong locality group. The page-scanner has
* been introduced to address the problem. Remote pages typically appear due to
* the memory shortage in the target locality group. Besides Solaris would
* allocate a large page from the remote locality group even if there are small
* local pages available. The page-scanner scans the pages right after the
* collection and frees remote pages in hope that subsequent reallocation would
* be more successful. This approach proved to be useful on systems with high
* load where multiple processes are competing for the memory.
*/
class MutableNUMASpace : public MutableSpace {
friend class VMStructs;
int _lgrp_id;
struct SpaceStats {
SpaceStats() {
_local_space = 0;
_remote_space = 0;
_unbiased_space = 0;
_uncommited_space = 0;
_large_pages = 0;
_small_pages = 0;
}
};
char* _last_page_scanned;
char* last_page_scanned() { return _last_page_scanned; }
void set_last_page_scanned(char* p) { _last_page_scanned = p; }
public:
_space = new MutableSpace();
}
~LGRPSpace() {
delete _space;
delete _alloc_rate;
}
void add_invalid_region(MemRegion r) {
if (!_invalid_region.is_empty()) {
} else {
_invalid_region = r;
}
}
return *(int*)lgrp_id_value == p->lgrp_id();
}
void sample() {
}
};
unsigned _adaptation_cycles, _samples_count;
unsigned adaptation_cycles() { return _adaptation_cycles; }
void set_adaptation_cycles(int v) { _adaptation_cycles = v; }
unsigned samples_count() { return _samples_count; }
void increment_samples_count() { ++_samples_count; }
// Check if the NUMA topology has changed. Add and remove spaces if needed.
// The update can be forced by setting the force parameter equal to true.
bool update_layout(bool force);
// Bias region towards the lgrp.
// Free pages in a given region.
// Get current chunk size.
size_t current_chunk_size(int i);
// Get default chunk size (equally divide the space).
// Adapt the chunk size to follow the allocation rate.
// Scan and free invalid pages.
// Return the bottom_region and the top_region. Align them to page_size() boundary.
// |------------------new_region---------------------------------|
// |----bottom_region--|---intersection---|------top_region------|
// Try to merge the invalid region with the bottom or top region by decreasing
// the intersection area. Return the invalid_region aligned to the page_size()
// boundary if it's inside the intersection. Return non-empty invalid_region
// if it lies inside the intersection (also page-aligned).
// |------------------new_region---------------------------------|
// |----------------|-------invalid---|--------------------------|
// |----bottom_region--|---intersection---|------top_region------|
public:
virtual ~MutableNUMASpace();
// Space initialization.
// Update space layout if necessary. Do all adaptive resizing job.
virtual void update();
// Update allocation rate averages.
virtual void accumulate_statistics();
virtual void clear(bool mangle_space);
virtual void mangle_unused_area() PRODUCT_RETURN;
virtual void mangle_unused_area_complete() PRODUCT_RETURN;
virtual void check_mangled_unused_area_complete() PRODUCT_RETURN;
virtual void set_top_for_allocations() PRODUCT_RETURN;
virtual void ensure_parsability();
virtual size_t used_in_words() const;
virtual size_t free_in_words() const;
// Allocation (return NULL if full)
// Debugging
virtual void verify(bool allow_dirty);
};