Default function to populate the mempool: allocate memory in memzones, * and populate them. Return the number of objects added, or a negative * value on error. */
| 481 | * value on error. |
| 482 | */ |
| 483 | int |
| 484 | rte_mempool_populate_default(struct rte_mempool *mp) |
| 485 | { |
| 486 | unsigned int mz_flags = RTE_MEMZONE_1GB|RTE_MEMZONE_SIZE_HINT_ONLY; |
| 487 | char mz_name[RTE_MEMZONE_NAMESIZE]; |
| 488 | const struct rte_memzone *mz; |
| 489 | ssize_t mem_size; |
| 490 | size_t align, pg_sz, pg_shift = 0; |
| 491 | rte_iova_t iova; |
| 492 | unsigned mz_id, n; |
| 493 | int ret; |
| 494 | bool need_iova_contig_obj; |
| 495 | size_t max_alloc_size = SIZE_MAX; |
| 496 | |
| 497 | ret = mempool_ops_alloc_once(mp); |
| 498 | if (ret != 0) |
| 499 | return ret; |
| 500 | |
| 501 | /* mempool must not be populated */ |
| 502 | if (mp->nb_mem_chunks != 0) |
| 503 | return -EEXIST; |
| 504 | |
| 505 | /* |
| 506 | * the following section calculates page shift and page size values. |
| 507 | * |
| 508 | * these values impact the result of calc_mem_size operation, which |
| 509 | * returns the amount of memory that should be allocated to store the |
| 510 | * desired number of objects. when not zero, it allocates more memory |
| 511 | * for the padding between objects, to ensure that an object does not |
| 512 | * cross a page boundary. in other words, page size/shift are to be set |
| 513 | * to zero if mempool elements won't care about page boundaries. |
| 514 | * there are several considerations for page size and page shift here. |
| 515 | * |
| 516 | * if we don't need our mempools to have physically contiguous objects, |
| 517 | * then just set page shift and page size to 0, because the user has |
| 518 | * indicated that there's no need to care about anything. |
| 519 | * |
| 520 | * if we do need contiguous objects (if a mempool driver has its |
| 521 | * own calc_size() method returning min_chunk_size = mem_size), |
| 522 | * there is also an option to reserve the entire mempool memory |
| 523 | * as one contiguous block of memory. |
| 524 | * |
| 525 | * if we require contiguous objects, but not necessarily the entire |
| 526 | * mempool reserved space to be contiguous, pg_sz will be != 0, |
| 527 | * and the default ops->populate() will take care of not placing |
| 528 | * objects across pages. |
| 529 | * |
| 530 | * if our IO addresses are physical, we may get memory from bigger |
| 531 | * pages, or we might get memory from smaller pages, and how much of it |
| 532 | * we require depends on whether we want bigger or smaller pages. |
| 533 | * However, requesting each and every memory size is too much work, so |
| 534 | * what we'll do instead is walk through the page sizes available, pick |
| 535 | * the smallest one and set up page shift to match that one. We will be |
| 536 | * wasting some space this way, but it's much nicer than looping around |
| 537 | * trying to reserve each and every page size. |
| 538 | * |
| 539 | * If we fail to get enough contiguous memory, then we'll go and |
| 540 | * reserve space in smaller chunks. |