DPDK patches and discussions
 help / color / mirror / Atom feed
From: =?gb18030?B?bWFubnl3YW5nKM3108C35Sk=?= <mannywang@tencent.com>
To: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>,
	Konstantin Ananyev <konstantin.ananyev@huawei.com>
Cc: dev@dpdk.org
Subject: Re: [Internet]Re: [PATCH v3] acl: support custom memory allocator
Date: Wed, 26 Nov 2025 10:44:45 +0800	[thread overview]
Message-ID: <7E45BE076ACCC3B2+d9eeffa0-a442-4766-b45f-406cd99700e9@tencent.com> (raw)
In-Reply-To: <8e00f0b5-84de-40ce-bec3-673c4b9dd3f1@gmail.com>

Thanks for sharing this suggestion.

We actually evaluated the heap-based approach before implementing this 
patch.
It can help in some scenarios, but unfortunately it does not fully solve our
use cases. Specifically:

1. **Heap count / scalability**
    Our application maintains at least ~200 rte_acl_ctx instances (due 
to the
    total rule count and multi-tenant isolation). Allowing a dedicated 
heap per
    context would exceed the practical limits of the current rte_malloc heap
    model. The number of heaps that can be created is not unlimited, and
    maintaining hundreds of separate heaps would introduce considerable
    management overhead.

2. **Temporary allocations in build stage**
    During `rte_acl_build`, a significant portion of memory is allocated 
through
    `calloc()` for internal temporary structures. These allocations are 
freed
    right after the build completes. Even if runtime memory could come 
from a
    custom heap, these temporary allocations would still need an independent
    allocator or callback mechanism to avoid fragmentation and repeated
    malloc/free cycles.

The goal of this patch is to provide allocator callbacks so that 
applications
can apply their own memory model consistently — static region for 
runtime, and
resettable pool for build — without relying on uncontrolled internal
allocations.

On 11/26/2025 2:01 AM, Dmitry Kozlyuk wrote:
> On 11/25/25 15:14, mannywang(王永峰) wrote:
>> Reduce memory fragmentation caused by dynamic memory allocations
>> by allowing users to provide custom memory allocator.
>>
>> Add new members to struct rte_acl_config to allow passing custom
>> allocator callbacks to rte_acl_build:
>>
>> - running_alloc: allocator callback for run-time internal memory
>> - running_free: free callback for run-time internal memory
>> - running_ctx: user-defined context passed to running_alloc/free
>>
>> - temp_alloc: allocator callback for temporary memory during ACL build
>> - temp_reset: reset callback for temporary allocator
>> - temp_ctx: user-defined context passed to temp_alloc/reset
>>
>> These callbacks allow users to provide their own memory pools or
>> allocators for both persistent runtime structures and temporary
>> build-time data.
>>
>> A typical approach is to pre-allocate a static memory region
>> for rte_acl_ctx, and to provide a global temporary memory manager
>> that supports multipleallocations and a single reset during ACL build.
>>
>> Since tb_mem_pool handles allocation failures using siglongjmp,
>> temp_alloc follows the same approach for failure handling.
> 
> If a static memory region would suffice for runtime memory,
> could you have solved the issue using existing API as follows?
> 1. Allocate memory in any way, may even use `rte_malloc_*()`.
> 2. Create a new heap using `rte_malloc_heap_create()`.
> 3. Attach the memory to the heap using `rte_malloc_heap_memory_add()`.
> 4. Get the heap "socket ID" using `rte_malloc_heap_get_socket()`.
> 5. Pass the heap "socket ID" to `rte_acl_create()`.
> 
> In https://inbox.dpdk.org/dev/tencent_4125B1322F9238892BFA5F38@qq.com/
> you said that the issue is runtime memory fragmentation,
> but also did "propose extending the ACL API to support
> external memory buffers for the build process".
> What is the issue with build-time allocations?
> 
> 



      reply	other threads:[~2025-11-26  2:44 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-14  2:51 [RFC] rte_acl_build memory fragmentation concern and proposal for external memory support mannywang(王永峰)
2025-11-17 12:51 ` Konstantin Ananyev
2025-11-25  9:40   ` [PATCH] acl: support custom memory allocator =?gb18030?B?bWFubnl3YW5nKM3108C35Sk=?=
2025-11-25 12:06   ` [PATCH v2] " =?gb18030?B?bWFubnl3YW5nKM3108C35Sk=?=
2025-11-25 12:14   ` [PATCH v3] " =?gb18030?B?bWFubnl3YW5nKM3108C35Sk=?=
2025-11-25 14:59     ` Stephen Hemminger
2025-11-26  2:37       ` [Internet]Re: " =?gb18030?B?bWFubnl3YW5nKM3108C35Sk=?=
2025-11-25 18:01     ` Dmitry Kozlyuk
2025-11-26  2:44       ` =?gb18030?B?bWFubnl3YW5nKM3108C35Sk=?= [this message]

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=7E45BE076ACCC3B2+d9eeffa0-a442-4766-b45f-406cd99700e9@tencent.com \
    --to=mannywang@tencent.com \
    --cc=dev@dpdk.org \
    --cc=dmitry.kozliuk@gmail.com \
    --cc=konstantin.ananyev@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).