Fri, 04 Oct 2013 13:33:02 +0200
8025526: VirtualSpace should support per-instance disabling of large pages
Summary: Add a new initialization function to VirtualSpace which allows the caller to override the max commit granularity.
Reviewed-by: stefank, ehelin, tschatzl
src/share/vm/runtime/virtualspace.cpp | file | annotate | diff | comparison | revisions | |
src/share/vm/runtime/virtualspace.hpp | file | annotate | diff | comparison | revisions |
1.1 --- a/src/share/vm/runtime/virtualspace.cpp Sat Oct 05 08:01:36 2013 -0700 1.2 +++ b/src/share/vm/runtime/virtualspace.cpp Fri Oct 04 13:33:02 2013 +0200 1.3 @@ -368,8 +368,15 @@ 1.4 1.5 1.6 bool VirtualSpace::initialize(ReservedSpace rs, size_t committed_size) { 1.7 + const size_t max_commit_granularity = os::page_size_for_region(rs.size(), rs.size(), 1); 1.8 + return initialize_with_granularity(rs, committed_size, max_commit_granularity); 1.9 +} 1.10 + 1.11 +bool VirtualSpace::initialize_with_granularity(ReservedSpace rs, size_t committed_size, size_t max_commit_granularity) { 1.12 if(!rs.is_reserved()) return false; // allocation failed. 1.13 assert(_low_boundary == NULL, "VirtualSpace already initialized"); 1.14 + assert(max_commit_granularity > 0, "Granularity must be non-zero."); 1.15 + 1.16 _low_boundary = rs.base(); 1.17 _high_boundary = low_boundary() + rs.size(); 1.18 1.19 @@ -390,7 +397,7 @@ 1.20 // No attempt is made to force large page alignment at the very top and 1.21 // bottom of the space if they are not aligned so already. 1.22 _lower_alignment = os::vm_page_size(); 1.23 - _middle_alignment = os::page_size_for_region(rs.size(), rs.size(), 1); 1.24 + _middle_alignment = max_commit_granularity; 1.25 _upper_alignment = os::vm_page_size(); 1.26 1.27 // End of each region 1.28 @@ -966,17 +973,52 @@ 1.29 1.30 1.31 class TestVirtualSpace : AllStatic { 1.32 + enum TestLargePages { 1.33 + Default, 1.34 + Disable, 1.35 + Reserve, 1.36 + Commit 1.37 + }; 1.38 + 1.39 + static ReservedSpace reserve_memory(size_t reserve_size_aligned, TestLargePages mode) { 1.40 + switch(mode) { 1.41 + default: 1.42 + case Default: 1.43 + case Reserve: 1.44 + return ReservedSpace(reserve_size_aligned); 1.45 + case Disable: 1.46 + case Commit: 1.47 + return ReservedSpace(reserve_size_aligned, 1.48 + os::vm_allocation_granularity(), 1.49 + /* large */ false, /* exec */ false); 1.50 + } 1.51 + } 1.52 + 1.53 + static bool initialize_virtual_space(VirtualSpace& vs, ReservedSpace rs, TestLargePages mode) { 1.54 + switch(mode) { 1.55 + default: 1.56 + case Default: 1.57 + case Reserve: 1.58 + return vs.initialize(rs, 0); 1.59 + case Disable: 1.60 + return vs.initialize_with_granularity(rs, 0, os::vm_page_size()); 1.61 + case Commit: 1.62 + return vs.initialize_with_granularity(rs, 0, os::page_size_for_region(rs.size(), rs.size(), 1)); 1.63 + } 1.64 + } 1.65 + 1.66 public: 1.67 - static void test_virtual_space_actual_committed_space(size_t reserve_size, size_t commit_size) { 1.68 + static void test_virtual_space_actual_committed_space(size_t reserve_size, size_t commit_size, 1.69 + TestLargePages mode = Default) { 1.70 size_t granularity = os::vm_allocation_granularity(); 1.71 size_t reserve_size_aligned = align_size_up(reserve_size, granularity); 1.72 1.73 - ReservedSpace reserved(reserve_size_aligned); 1.74 + ReservedSpace reserved = reserve_memory(reserve_size_aligned, mode); 1.75 1.76 assert(reserved.is_reserved(), "Must be"); 1.77 1.78 VirtualSpace vs; 1.79 - bool initialized = vs.initialize(reserved, 0); 1.80 + bool initialized = initialize_virtual_space(vs, reserved, mode); 1.81 assert(initialized, "Failed to initialize VirtualSpace"); 1.82 1.83 vs.expand_by(commit_size, false); 1.84 @@ -986,7 +1028,10 @@ 1.85 } else { 1.86 assert_ge(vs.actual_committed_size(), commit_size); 1.87 // Approximate the commit granularity. 1.88 - size_t commit_granularity = UseLargePages ? os::large_page_size() : os::vm_page_size(); 1.89 + // Make sure that we don't commit using large pages 1.90 + // if large pages has been disabled for this VirtualSpace. 1.91 + size_t commit_granularity = (mode == Disable || !UseLargePages) ? 1.92 + os::vm_page_size() : os::large_page_size(); 1.93 assert_lt(vs.actual_committed_size(), commit_size + commit_granularity); 1.94 } 1.95 1.96 @@ -1042,9 +1087,40 @@ 1.97 test_virtual_space_actual_committed_space(10 * M, 10 * M); 1.98 } 1.99 1.100 + static void test_virtual_space_disable_large_pages() { 1.101 + if (!UseLargePages) { 1.102 + return; 1.103 + } 1.104 + // These test cases verify that if we force VirtualSpace to disable large pages 1.105 + test_virtual_space_actual_committed_space(10 * M, 0, Disable); 1.106 + test_virtual_space_actual_committed_space(10 * M, 4 * K, Disable); 1.107 + test_virtual_space_actual_committed_space(10 * M, 8 * K, Disable); 1.108 + test_virtual_space_actual_committed_space(10 * M, 1 * M, Disable); 1.109 + test_virtual_space_actual_committed_space(10 * M, 2 * M, Disable); 1.110 + test_virtual_space_actual_committed_space(10 * M, 5 * M, Disable); 1.111 + test_virtual_space_actual_committed_space(10 * M, 10 * M, Disable); 1.112 + 1.113 + test_virtual_space_actual_committed_space(10 * M, 0, Reserve); 1.114 + test_virtual_space_actual_committed_space(10 * M, 4 * K, Reserve); 1.115 + test_virtual_space_actual_committed_space(10 * M, 8 * K, Reserve); 1.116 + test_virtual_space_actual_committed_space(10 * M, 1 * M, Reserve); 1.117 + test_virtual_space_actual_committed_space(10 * M, 2 * M, Reserve); 1.118 + test_virtual_space_actual_committed_space(10 * M, 5 * M, Reserve); 1.119 + test_virtual_space_actual_committed_space(10 * M, 10 * M, Reserve); 1.120 + 1.121 + test_virtual_space_actual_committed_space(10 * M, 0, Commit); 1.122 + test_virtual_space_actual_committed_space(10 * M, 4 * K, Commit); 1.123 + test_virtual_space_actual_committed_space(10 * M, 8 * K, Commit); 1.124 + test_virtual_space_actual_committed_space(10 * M, 1 * M, Commit); 1.125 + test_virtual_space_actual_committed_space(10 * M, 2 * M, Commit); 1.126 + test_virtual_space_actual_committed_space(10 * M, 5 * M, Commit); 1.127 + test_virtual_space_actual_committed_space(10 * M, 10 * M, Commit); 1.128 + } 1.129 + 1.130 static void test_virtual_space() { 1.131 test_virtual_space_actual_committed_space(); 1.132 test_virtual_space_actual_committed_space_one_large_page(); 1.133 + test_virtual_space_disable_large_pages(); 1.134 } 1.135 }; 1.136
2.1 --- a/src/share/vm/runtime/virtualspace.hpp Sat Oct 05 08:01:36 2013 -0700 2.2 +++ b/src/share/vm/runtime/virtualspace.hpp Fri Oct 04 13:33:02 2013 +0200 2.3 @@ -178,6 +178,7 @@ 2.4 public: 2.5 // Initialization 2.6 VirtualSpace(); 2.7 + bool initialize_with_granularity(ReservedSpace rs, size_t committed_byte_size, size_t max_commit_ganularity); 2.8 bool initialize(ReservedSpace rs, size_t committed_byte_size); 2.9 2.10 // Destruction