MCPcopy Create free account
hub / github.com/F-Stack/f-stack / calc_mem_size

Function calc_mem_size

dpdk/app/test-pmd/testpmd.c:820–855  ·  view source on GitHub ↗

extremely pessimistic estimation of memory required to create a mempool */

Source from the content-addressed store, hash-verified

818#ifndef RTE_EXEC_ENV_WINDOWS
819/* extremely pessimistic estimation of memory required to create a mempool */
820static int
821calc_mem_size(uint32_t nb_mbufs, uint32_t mbuf_sz, size_t pgsz, size_t *out)
822{
823 unsigned int n_pages, mbuf_per_pg, leftover;
824 uint64_t total_mem, mbuf_mem, obj_sz;
825
826 /* there is no good way to predict how much space the mempool will
827 * occupy because it will allocate chunks on the fly, and some of those
828 * will come from default DPDK memory while some will come from our
829 * external memory, so just assume 128MB will be enough for everyone.
830 */
831 uint64_t hdr_mem = 128 << 20;
832
833 /* account for possible non-contiguousness */
834 obj_sz = rte_mempool_calc_obj_size(mbuf_sz, 0, NULL);
835 if (obj_sz > pgsz) {
836 TESTPMD_LOG(ERR, "Object size is bigger than page size\n");
837 return -1;
838 }
839
840 mbuf_per_pg = pgsz / obj_sz;
841 leftover = (nb_mbufs % mbuf_per_pg) > 0;
842 n_pages = (nb_mbufs / mbuf_per_pg) + leftover;
843
844 mbuf_mem = n_pages * pgsz;
845
846 total_mem = RTE_ALIGN(hdr_mem + mbuf_mem, pgsz);
847
848 if (total_mem > SIZE_MAX) {
849 TESTPMD_LOG(ERR, "Memory size too big\n");
850 return -1;
851 }
852 *out = (size_t)total_mem;
853
854 return 0;
855}
856
857static int
858pagesz_flags(uint64_t page_sz)

Callers 1

create_extmemFunction · 0.85

Calls 1

Tested by

no test coverage detected