@@ -62,24 +62,51 @@ TEST_VM(metaspace, get_chunk) {
62
62
// Test ChunkManager::get_chunk, but with a commit limit.
63
63
TEST_VM (metaspace, get_chunk_with_commit_limit) {
64
64
65
- const size_t commit_limit_words = 1 * M;
66
- ChunkGtestContext context (commit_limit_words);
67
- Metachunk* c = NULL ;
65
+ // A commit limit that is smaller than the largest possible chunk size.
68
66
69
- for ( chunklevel_t pref_lvl = LOWEST_CHUNK_LEVEL; pref_lvl <= HIGHEST_CHUNK_LEVEL; pref_lvl++) {
67
+ // Here we test different combinations of commit limit, preferred and highest chunk level, and min_committed_size.
70
68
71
- for (chunklevel_t max_lvl = pref_lvl; max_lvl <= HIGHEST_CHUNK_LEVEL; max_lvl++) {
69
+ for (size_t commit_limit_words = Settings::commit_granule_words ();
70
+ commit_limit_words < MAX_CHUNK_WORD_SIZE * 2 ; commit_limit_words *= 2 ) {
72
71
73
- for ( size_t min_committed_words = Settings::commit_granule_words ( );
74
- min_committed_words <= word_size_for_level (max_lvl); min_committed_words *= 2 ) {
72
+ ChunkGtestContext context (commit_limit_words );
73
+ Metachunk* c = NULL ;
75
74
76
- if (min_committed_words <= commit_limit_words) {
77
- context.alloc_chunk_expect_success (&c, pref_lvl, max_lvl, min_committed_words);
78
- context.return_chunk (c);
79
- } else {
80
- context.alloc_chunk_expect_failure (pref_lvl, max_lvl, min_committed_words);
75
+ for (chunklevel_t pref_lvl = LOWEST_CHUNK_LEVEL; pref_lvl <= HIGHEST_CHUNK_LEVEL; pref_lvl++) {
76
+
77
+ for (chunklevel_t max_lvl = pref_lvl; max_lvl <= HIGHEST_CHUNK_LEVEL; max_lvl++) {
78
+
79
+ for (size_t min_committed_words = Settings::commit_granule_words ();
80
+ min_committed_words <= word_size_for_level (max_lvl); min_committed_words *= 2 ) {
81
+
82
+ // When should commit work? As long as min_committed_words is smaller than commit_limit_words.
83
+ bool commit_should_work = min_committed_words <= commit_limit_words;
84
+
85
+ // Exception: MetaspaceReclaimPolicy=none. Here, chunks are fully committed from the get go and
86
+ // min_committed_words is effectively ignored. So commit would fail if the chunk is larger than
87
+ // the commit limit. Unfortunately, the chunk size is difficult to predict (it will be between
88
+ // [pref_lvl, max_lvl]. To make matters simple, we skip the test if we don't know the level for
89
+ // sure.
90
+ if (Settings::new_chunks_are_fully_committed ()) {
91
+ if (pref_lvl == max_lvl) {
92
+ commit_should_work = word_size_for_level (max_lvl) <= commit_limit_words;
93
+ } else {
94
+ continue ;
95
+ }
96
+ }
97
+
98
+ // printf("commit_limit: " SIZE_FORMAT ", min_committed_words: " SIZE_FORMAT
99
+ // ", max chunk level: " CHKLVL_FORMAT ", preferred chunk level: " CHKLVL_FORMAT ", should work: %d\n",
100
+ // commit_limit_words, min_committed_words, max_lvl, pref_lvl, commit_should_work);
101
+ // fflush(stdout);
102
+
103
+ if (commit_should_work) {
104
+ context.alloc_chunk_expect_success (&c, pref_lvl, max_lvl, min_committed_words);
105
+ context.return_chunk (c);
106
+ } else {
107
+ context.alloc_chunk_expect_failure (pref_lvl, max_lvl, min_committed_words);
108
+ }
81
109
}
82
-
83
110
}
84
111
}
85
112
}
0 commit comments