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