| 176 | }; |
| 177 | |
| 178 | static int |
| 179 | alloc_seg_walk(const struct rte_memseg_list *msl, void *arg) |
| 180 | { |
| 181 | struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config; |
| 182 | struct alloc_walk_param *wa = arg; |
| 183 | struct rte_memseg_list *cur_msl; |
| 184 | size_t page_sz; |
| 185 | int cur_idx, start_idx, j; |
| 186 | unsigned int msl_idx, need, i; |
| 187 | |
| 188 | if (msl->page_sz != wa->page_sz) |
| 189 | return 0; |
| 190 | if (msl->socket_id != wa->socket) |
| 191 | return 0; |
| 192 | |
| 193 | page_sz = (size_t)msl->page_sz; |
| 194 | |
| 195 | msl_idx = msl - mcfg->memsegs; |
| 196 | cur_msl = &mcfg->memsegs[msl_idx]; |
| 197 | |
| 198 | need = wa->n_segs; |
| 199 | |
| 200 | /* try finding space in memseg list */ |
| 201 | if (wa->exact) { |
| 202 | /* if we require exact number of pages in a list, find them */ |
| 203 | cur_idx = rte_fbarray_find_next_n_free( |
| 204 | &cur_msl->memseg_arr, 0, need); |
| 205 | if (cur_idx < 0) |
| 206 | return 0; |
| 207 | start_idx = cur_idx; |
| 208 | } else { |
| 209 | int cur_len; |
| 210 | |
| 211 | /* we don't require exact number of pages, so we're going to go |
| 212 | * for best-effort allocation. that means finding the biggest |
| 213 | * unused block, and going with that. |
| 214 | */ |
| 215 | cur_idx = rte_fbarray_find_biggest_free( |
| 216 | &cur_msl->memseg_arr, 0); |
| 217 | if (cur_idx < 0) |
| 218 | return 0; |
| 219 | start_idx = cur_idx; |
| 220 | /* adjust the size to possibly be smaller than original |
| 221 | * request, but do not allow it to be bigger. |
| 222 | */ |
| 223 | cur_len = rte_fbarray_find_contig_free( |
| 224 | &cur_msl->memseg_arr, cur_idx); |
| 225 | need = RTE_MIN(need, (unsigned int)cur_len); |
| 226 | } |
| 227 | |
| 228 | for (i = 0; i < need; i++, cur_idx++) { |
| 229 | struct rte_memseg *cur; |
| 230 | void *map_addr; |
| 231 | |
| 232 | cur = rte_fbarray_get(&cur_msl->memseg_arr, cur_idx); |
| 233 | map_addr = RTE_PTR_ADD(cur_msl->base_va, cur_idx * page_sz); |
| 234 | |
| 235 | if (alloc_seg(cur, map_addr, wa->socket, wa->hi)) { |
nothing calls this directly
no test coverage detected