| 1153 | } |
| 1154 | |
| 1155 | static int |
| 1156 | sync_chunk(struct rte_memseg_list *primary_msl, |
| 1157 | struct rte_memseg_list *local_msl, struct hugepage_info *hi, |
| 1158 | unsigned int msl_idx, bool used, int start, int end) |
| 1159 | { |
| 1160 | struct rte_fbarray *l_arr, *p_arr; |
| 1161 | int i, ret, chunk_len, diff_len; |
| 1162 | |
| 1163 | l_arr = &local_msl->memseg_arr; |
| 1164 | p_arr = &primary_msl->memseg_arr; |
| 1165 | |
| 1166 | /* we need to aggregate allocations/deallocations into bigger chunks, |
| 1167 | * as we don't want to spam the user with per-page callbacks. |
| 1168 | * |
| 1169 | * to avoid any potential issues, we also want to trigger |
| 1170 | * deallocation callbacks *before* we actually deallocate |
| 1171 | * memory, so that the user application could wrap up its use |
| 1172 | * before it goes away. |
| 1173 | */ |
| 1174 | |
| 1175 | chunk_len = end - start; |
| 1176 | |
| 1177 | /* find how many contiguous pages we can map/unmap for this chunk */ |
| 1178 | diff_len = used ? |
| 1179 | rte_fbarray_find_contig_free(l_arr, start) : |
| 1180 | rte_fbarray_find_contig_used(l_arr, start); |
| 1181 | |
| 1182 | /* has to be at least one page */ |
| 1183 | if (diff_len < 1) |
| 1184 | return -1; |
| 1185 | |
| 1186 | diff_len = RTE_MIN(chunk_len, diff_len); |
| 1187 | |
| 1188 | /* if we are freeing memory, notify the application */ |
| 1189 | if (!used) { |
| 1190 | struct rte_memseg *ms; |
| 1191 | void *start_va; |
| 1192 | size_t len, page_sz; |
| 1193 | |
| 1194 | ms = rte_fbarray_get(l_arr, start); |
| 1195 | start_va = ms->addr; |
| 1196 | page_sz = (size_t)primary_msl->page_sz; |
| 1197 | len = page_sz * diff_len; |
| 1198 | |
| 1199 | eal_memalloc_mem_event_notify(RTE_MEM_EVENT_FREE, |
| 1200 | start_va, len); |
| 1201 | } |
| 1202 | |
| 1203 | for (i = 0; i < diff_len; i++) { |
| 1204 | struct rte_memseg *p_ms, *l_ms; |
| 1205 | int seg_idx = start + i; |
| 1206 | |
| 1207 | l_ms = rte_fbarray_get(l_arr, seg_idx); |
| 1208 | p_ms = rte_fbarray_get(p_arr, seg_idx); |
| 1209 | |
| 1210 | if (l_ms == NULL || p_ms == NULL) |
| 1211 | return -1; |
| 1212 |
no test coverage detected