File tree 3 files changed +35
-0
lines changed
3 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -310,6 +310,13 @@ matras_dealloc_range(struct matras *m, matras_id_t range_count);
310
310
int
311
311
matras_touch_reserve (struct matras * m , int count );
312
312
313
+ /**
314
+ * Reserve the max amount of extents required to successfully allocate @p count
315
+ * blocks. The extents are reserved in the allocator given on construction.
316
+ */
317
+ int
318
+ matras_alloc_reserve (struct matras * m , int count );
319
+
313
320
/**
314
321
* Convert block id into block address.
315
322
*/
Original file line number Diff line number Diff line change 88
88
# define lengthof (array ) (sizeof (array) / sizeof ((array)[0]))
89
89
#endif
90
90
91
+ #define SMALL_DIV_ROUND_UP (a , b ) ((a) + (b) - 1) / (b)
92
+
91
93
#define small_xmalloc (size ) \
92
94
({ \
93
95
void *ret = malloc(size); \
Original file line number Diff line number Diff line change 12
12
#pragma intrinsic (_BitScanReverse)
13
13
#endif
14
14
15
+ #include "util.h"
16
+
15
17
/**
16
18
* Dummy thread-local matras_stats struct used if matras_stats wasn't
17
19
* passed to matras_create().
@@ -364,6 +366,30 @@ matras_touch_reserve(struct matras *m, int count)
364
366
return matras_allocator_reserve (m -> allocator , max_extents_required );
365
367
}
366
368
369
+ /**
370
+ * Reserve the max amount of extents required to successfully allocate @p count
371
+ * blocks. The extents are reserved in the allocator given on construction.
372
+ */
373
+ int
374
+ matras_alloc_reserve (struct matras * m , int count )
375
+ {
376
+ assert (count >= 0 );
377
+
378
+ /* No allocations planned. */
379
+ if (count == 0 )
380
+ return 0 ;
381
+
382
+ /*
383
+ * This reserves up to 3 extents more than required, but it should be OK
384
+ * since the reserved memory is generic for all matras_allocator users.
385
+ */
386
+ int l3_count = SMALL_DIV_ROUND_UP (m -> block_size * count ,
387
+ m -> allocator -> extent_size );
388
+ int l2_count = SMALL_DIV_ROUND_UP (l3_count * sizeof (void * ),
389
+ m -> allocator -> extent_size );
390
+ return matras_allocator_reserve (m -> allocator , l3_count + l2_count + 1 );
391
+ }
392
+
367
393
/**
368
394
* Return the number of allocated extents (of size m->extent_size each)
369
395
*/
You can’t perform that action at this time.
0 commit comments