| 4129 | } |
| 4130 | |
| 4131 | size_t |
| 4132 | batch_alloc(void **ptrs, size_t num, size_t size, int flags) { |
| 4133 | LOG("core.batch_alloc.entry", |
| 4134 | "ptrs: %p, num: %zu, size: %zu, flags: %d", ptrs, num, size, flags); |
| 4135 | |
| 4136 | tsd_t *tsd = tsd_fetch(); |
| 4137 | check_entry_exit_locking(tsd_tsdn(tsd)); |
| 4138 | |
| 4139 | size_t filled = 0; |
| 4140 | |
| 4141 | if (unlikely(tsd == NULL || tsd_reentrancy_level_get(tsd) > 0)) { |
| 4142 | goto label_done; |
| 4143 | } |
| 4144 | |
| 4145 | size_t alignment = MALLOCX_ALIGN_GET(flags); |
| 4146 | size_t usize; |
| 4147 | if (aligned_usize_get(size, alignment, &usize, NULL, false)) { |
| 4148 | goto label_done; |
| 4149 | } |
| 4150 | szind_t ind = sz_size2index(usize); |
| 4151 | bool zero = zero_get(MALLOCX_ZERO_GET(flags), /* slow */ true); |
| 4152 | |
| 4153 | /* |
| 4154 | * The cache bin and arena will be lazily initialized; it's hard to |
| 4155 | * know in advance whether each of them needs to be initialized. |
| 4156 | */ |
| 4157 | cache_bin_t *bin = NULL; |
| 4158 | arena_t *arena = NULL; |
| 4159 | |
| 4160 | size_t nregs = 0; |
| 4161 | if (likely(ind < SC_NBINS)) { |
| 4162 | nregs = bin_infos[ind].nregs; |
| 4163 | assert(nregs > 0); |
| 4164 | } |
| 4165 | |
| 4166 | while (filled < num) { |
| 4167 | size_t batch = num - filled; |
| 4168 | size_t surplus = SIZE_MAX; /* Dead store. */ |
| 4169 | bool prof_sample_event = config_prof && opt_prof |
| 4170 | && prof_active_get_unlocked() |
| 4171 | && te_prof_sample_event_lookahead_surplus(tsd, |
| 4172 | batch * usize, &surplus); |
| 4173 | |
| 4174 | if (prof_sample_event) { |
| 4175 | /* |
| 4176 | * Adjust so that the batch does not trigger prof |
| 4177 | * sampling. |
| 4178 | */ |
| 4179 | batch -= surplus / usize + 1; |
| 4180 | batch_alloc_prof_sample_assert(tsd, batch, usize); |
| 4181 | } |
| 4182 | |
| 4183 | size_t progress = 0; |
| 4184 | |
| 4185 | if (likely(ind < SC_NBINS) && batch >= nregs) { |
| 4186 | if (arena == NULL) { |
| 4187 | unsigned arena_ind = mallocx_arena_get(flags); |
| 4188 | if (arena_get_from_ind(tsd, arena_ind, |
no test coverage detected