[dpdk-dev] Api in dpdk to get total free physical memory

Venumadhav Josyula vjosyula at parallelwireless.com
Fri Mar 9 10:59:45 CET 2018


Hi Anatoly,

Like we have api, rte_eal_get_physmem_size, which returns the total memory physical Ram memory. This is eal_common_memory.c, we need following following which would return free memory. For that that I was referring we need to api get the free physical ram memory ‘rte_eal_get_physmem_free’ for the we wanted to submit patch.

Thanks,
Regards
Venumadhav

From: dev [mailto:dev-bounces at dpdk.org] On Behalf Of Burakov, Anatoly
Sent: Friday, March 09, 2018 2:36 PM
To: Venumadhav Josyula <vjosyula at gmail.com>; dev at dpdk.org
Subject: Re: [dpdk-dev] Api in dpdk to get total free physical memory

On 08-Mar-18 9:36 PM, Venumadhav Josyula wrote:
> Hi All,
>
>
>
> Like ‘rte_eal_get_physmem_size’ api to the total size of the physical
> memory. Is there an API to get to get total free memory physical memory
> available ?
>
>
>
> We want such API we are planning to implement such API for the same
>
>
>
> /* get the total size of memory */
>
> uint64_t
>
> rte_eal_get_physmem_free(int socket_id)
>
> {
>
> const struct rte_mem_config *mcfg;
>
> unsigned i = 0;
>
> uint64_t total_len = 0;
>
>
>
> /* get pointer to global configuration */
>
> mcfg = rte_eal_get_configuration()->mem_config;
>
>
>
> for (i=0; i<RTE_MAX_MEMSEG; i++) {
>
> if (mcfg->free_memseg[i].addr == NULL)
>
> break;
>
>
>
> if (mcfg->free_memseg[i].len == 0)
>
> continue;
>
>
>
> /* bad socket ID */
>
> if (socket_id != SOCKET_ID_ANY &&
>
> mcfg->free_memseg[i].socket_id != SOCKET_ID_ANY &&
>
> socket_id != mcfg->free_memseg[i].socket_id)
>
> continue;
>
>
>
> total_len += mcfg->free_memseg[i].len;
>
> }
>
>
>
> return total_len;
>
> }
>
>
>
> Thanks,
>
> Regards
>
> Venu
>

All memory is registered on the heap, so you might want to look at heap
stats to get the same information :) It would also arguably be more
useful because just the size of memory will not tell you how much you
can allocate, because memory may be heavily fragmented, and heap stats
will also tell you biggest free memory block size.

Bear in mind, however, that there is work in progress [1] to enable
mapping/unmapping hugepages at runtime, which would make such an API
more or less useless - just because you don't have much free space *now*
doesn't mean you can't allocate more :)

[1] http://dpdk.org/ml/archives/dev/2018-March/092070.html<http://dpdk.org/ml/archives/dev/2018-March/092070.html>

--
Thanks,
Anatoly


More information about the dev mailing list