DPDK patches and discussions
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
Cc: "wuchangsheng (C)" <wuchangsheng2@huawei.com>,
	"anatoly.burakov@intel.com" <anatoly.burakov@intel.com>,
	"dev@dpdk.org" <dev@dpdk.org>,
	"jiangheng (G)" <jiangheng14@huawei.com>,
	"Yanan (Euler)" <yanan@huawei.com>,
	"Suweifeng (Weifeng, EulerOS)" <suweifeng1@huawei.com>
Subject: Re: [DPDK] heap memory fragmentation issue
Date: Tue, 18 Apr 2023 15:43:49 -0700	[thread overview]
Message-ID: <20230418154349.10b4261e@hermes.local> (raw)
In-Reply-To: <20230419003531.6f492cce@sovereign>

On Wed, 19 Apr 2023 00:35:31 +0300
Dmitry Kozlyuk <dmitry.kozliuk@gmail.com> wrote:

> Hi,
> 
> 2023-04-12 08:44 (UTC+0000), wuchangsheng (C):
> > When using rte_malloc and rte_free to request and release memory repeatedly, the usage of large pages gradually increases.  
> 
> Do you have a repro?
> 
> > Checking the relevant source code shows that memory requests and releases
> > are started from the head of the freelist chain list of the heap.
> > Memory fragmentation seems to result from this, which is considered because
> > the memory recently released may be in the cache, and requesting this
> > memory at the time of allocation may achieve higher performance?  
> 
> Could you please elaborate?
> DPDK uses "first fit" algorithm to select the free block,
> is that what you mean by "memory fragmentation seems to result from this"?
> 
> > How does the community consider the heap's memory fragmentation issue? Is
> > there a future plan for memory fragmentation optimization?  
> 
> From my experience with a production app, fragmentation is indeed an issue.

The problem is that simple first-fit is often not good enough.
Memory allocation algorithms are much researched area of operating system design.
You will find lots of lectures online like https://www.scs.stanford.edu/15au-cs140/notes/mem_allocation.pdf

If interested, some other malloc libraries:
https://en.wikipedia.org/wiki/C_dynamic_memory_allocation

Glibc https://sourceware.org/glibc/wiki/MallocInternals
Dimalloc
	Small (<256) use simple best fit power of two with splitting
	Medium bitwise trie
	Large use mmap

JeMalloc https://jemalloc.net/
	What FreeBSD uses, avoids fragmentation

Mimalloc https://microsoft.github.io/mimalloc/
	Uses free list sharding (ie free list per page)
	https://www.microsoft.com/en-us/research/uploads/prod/2019/06/mimalloc-tr-v1.pdf

If someone wants to go deeper, then looking into some combination
of these would be good. Some of these already are huge page aware
so probably DPDK could stop reinventing this.



  reply	other threads:[~2023-04-18 22:43 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-12  8:44 wuchangsheng (C)
2023-04-18 21:35 ` Dmitry Kozlyuk
2023-04-18 22:43   ` Stephen Hemminger [this message]
2023-04-18  2:48 wuchangsheng (C)

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=20230418154349.10b4261e@hermes.local \
    --to=stephen@networkplumber.org \
    --cc=anatoly.burakov@intel.com \
    --cc=dev@dpdk.org \
    --cc=dmitry.kozliuk@gmail.com \
    --cc=jiangheng14@huawei.com \
    --cc=suweifeng1@huawei.com \
    --cc=wuchangsheng2@huawei.com \
    --cc=yanan@huawei.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).