20
20
#include "opal_config.h"
21
21
#include "opal/mca/allocator/bucket/allocator_bucket_alloc.h"
22
22
#include "opal/constants.h"
23
+ #include "opal/util/show_help.h"
24
+
23
25
/**
24
26
* The define controls the size in bytes of the 1st bucket and hence every one
25
27
* afterwards.
31
33
*/
32
34
#define MCA_ALLOCATOR_BUCKET_1_BITSHIFTS 3
33
35
36
+ static int max_bucket_idx ;
37
+
34
38
/*
35
39
* Initializes the mca_allocator_bucket_options_t data structure for the passed
36
40
* parameters.
@@ -47,6 +51,9 @@ mca_allocator_bucket_init(mca_allocator_base_module_t *mem, int num_buckets,
47
51
if (num_buckets <= 0 ) {
48
52
num_buckets = 30 ;
49
53
}
54
+
55
+ max_bucket_idx = num_buckets - 1 ;
56
+
50
57
/* initialize the array of buckets */
51
58
size = sizeof (mca_allocator_bucket_bucket_t ) * num_buckets ;
52
59
mem_options -> buckets = (mca_allocator_bucket_bucket_t * ) malloc (size );
@@ -89,6 +96,13 @@ void *mca_allocator_bucket_alloc(mca_allocator_base_module_t *mem, size_t size)
89
96
bucket_size <<= 1 ;
90
97
}
91
98
99
+ if ( bucket_num > max_bucket_idx ) {
100
+ size_t sz_bucket = MCA_ALLOCATOR_BUCKET_1_SIZE ;
101
+ opal_show_help ("help-mca-allocator-bucket.txt" , "buffer too large" , size , sz_bucket << max_bucket_idx ,
102
+ "allocator_bucket_num_buckets" , bucket_num + 1 );
103
+ return (NULL );
104
+ }
105
+
92
106
/* now that we know what bucket it will come from, we must get the lock */
93
107
OPAL_THREAD_LOCK (& (mem_options -> buckets [bucket_num ].lock ));
94
108
/* see if there is already a free chunk */
@@ -191,6 +205,14 @@ void *mca_allocator_bucket_alloc_align(mca_allocator_base_module_t *mem, size_t
191
205
bucket_size >>= 1 ;
192
206
bucket_num ++ ;
193
207
}
208
+
209
+ if ( bucket_num > max_bucket_idx ) {
210
+ size_t sz_bucket = MCA_ALLOCATOR_BUCKET_1_SIZE ;
211
+ opal_show_help ("help-mca-allocator-bucket.txt" , "aligned buffer too large" , allocated_size , sz_bucket << max_bucket_idx ,
212
+ "allocator_bucket_num_buckets" , bucket_num + 1 );
213
+ return (NULL );
214
+ }
215
+
194
216
bucket_size = 1 ;
195
217
bucket_size <<= MCA_ALLOCATOR_BUCKET_1_BITSHIFTS + bucket_num ;
196
218
0 commit comments