DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Burakov, Anatoly" <anatoly.burakov@intel.com>
To: Venumadhav Josyula <vjosyula@parallelwireless.com>,
	Venumadhav Josyula <vjosyula@gmail.com>,
	"dev@dpdk.org" <dev@dpdk.org>
Subject: Re: [dpdk-dev] Api in dpdk to get total free physical memory
Date: Fri, 9 Mar 2018 10:56:10 +0000	[thread overview]
Message-ID: <1476c49a-732e-2d1e-c95b-fd9c42ad9c6e@intel.com> (raw)
In-Reply-To: <BN6PR19MB1347B7E1901AFFCA8768A261BFDE0@BN6PR19MB1347.namprd19.prod.outlook.com>

On 09-Mar-18 9:59 AM, Venumadhav Josyula wrote:
> 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

Hi Venumadhav,

Yes, i understand what you're referring to. I'm just saying that 1) 
getting malloc heap stats will provide you with similar (and arguably 
more practically useful) information, and 2) there are changes 
(hopefully) coming that will lessen usefulness of such an API because it 
would be possible to allocate hugepages at runtime, instead of 
preallocating them at startup.

You're welcome to submit your patches, of course, but i would question 
the usefulness of such an API in light of coming changes to memory 
subsystem, because the "free" memory will not be the actual amount of 
free memory you have. Imagine the following:

// you have roughly 1MB of free memory
free_mem = rte_eal_get_free_mem();
printf("%luMB\n", free_mem >> 20); // prints "1MB"

rte_malloc(1 << 20); // allocate 1MB of memory
                      // causes allocation of 1G page

free_mem = rte_eal_get_free_mem();
printf("%luMB\n", free_mem >> 20); // prints "1024MB"

A second ago you had 1MB of "free space", next second you have 1G free 
space, despite the fact that you didn't free any memory - you just 
allocated more pages. "Amount of free space" will have little meaning 
when you can allocate more pages on the fly. I hope i've explained it 
clearly enough.

> 
> *From:*dev [mailto:dev-bounces@dpdk.org] *On Behalf Of *Burakov, Anatoly
> *Sent:* Friday, March 09, 2018 2:36 PM
> *To:* Venumadhav Josyula <vjosyula@gmail.com>; dev@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
> 
> -- 
> Thanks,
> Anatoly
> 


-- 
Thanks,
Anatoly

  reply	other threads:[~2018-03-09 10:56 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-08 21:36 Venumadhav Josyula
2018-03-09  9:05 ` Burakov, Anatoly
2018-03-09  9:59   ` Venumadhav Josyula
2018-03-09 10:56     ` Burakov, Anatoly [this message]
  -- strict thread matches above, loose matches on Subject: below --
2017-10-05  5:56 [dpdk-dev] API " Venumadhav Josyula
2017-10-05  9:02 ` Burakov, Anatoly

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1476c49a-732e-2d1e-c95b-fd9c42ad9c6e@intel.com \
    --to=anatoly.burakov@intel.com \
    --cc=dev@dpdk.org \
    --cc=vjosyula@gmail.com \
    --cc=vjosyula@parallelwireless.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).