From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id 665184C8E for ; Fri, 9 Mar 2018 10:05:49 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Mar 2018 01:05:48 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,444,1515484800"; d="scan'208";a="181261180" Received: from aburakov-mobl.ger.corp.intel.com (HELO [10.252.24.59]) ([10.252.24.59]) by orsmga004.jf.intel.com with ESMTP; 09 Mar 2018 01:05:46 -0800 To: Venumadhav Josyula , dev@dpdk.org References: From: "Burakov, Anatoly" Message-ID: <07d7fd2f-4b73-4e79-160b-2f30e80fdb19@intel.com> Date: Fri, 9 Mar 2018 09:05:45 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Subject: Re: [dpdk-dev] Api in dpdk to get total free physical memory X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 09 Mar 2018 09:05:49 -0000 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 > 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