ccn-lite icon indicating copy to clipboard operation
ccn-lite copied to clipboard

malloc: ccnl_prefix_to_path_detailed

Open cgundogan opened this issue 7 years ago • 10 comments

ccnl_prefix_to_path_detailed() is used in a lot of places throughout the code. It basically just allocates (via malloc) a buffer, and passes it to ccnl_prefix_to_str_detailed().

Instead of relying on malloc in the core libs of ccn-lite (core, fwd,...), should we rather use a statically allocated memory block and call _str_detailed() directly, instead of _path_detailed()?

The benefit is: no malloc at all, so all the mandatory ccnl_free's() can be dropped. A disadvantage would be that in a multi-threaded scenario, the (global) statically allocated memory block needs to be guarded against concurrent (write) access. CCN-lite itself does not support multi-threading, but a CCN-lite API user might call functions in a multi-threaded fashion. I am sure we can find a solution for that without introducing mutexes, though.

Opinions, ideas?

cgundogan avatar Feb 06 '18 12:02 cgundogan

for reference: https://github.com/cn-uofbasel/ccn-lite/blob/master/src/ccnl-core/src/ccnl-prefix.c#L557

cgundogan avatar Feb 06 '18 12:02 cgundogan

I am sure we can find a solution for that without introducing mutexes, though.

You mean a lock-free memory allocator which allocates memory from a pre-defined memory block?

mfrey avatar Feb 06 '18 12:02 mfrey

You mean a lock free memory allocator which allocates memory from a pre-defined memory block?

sounds like malloc to me (:

cgundogan avatar Feb 06 '18 12:02 cgundogan

the first thing would be to evaluate, if there are any calls to _path_detailed() from API functions. If not, then there's no problem at all.

cgundogan avatar Feb 06 '18 12:02 cgundogan

sounds like malloc to me (:

I'm not an expert on lock-free memory allocation, but I've thought it's a bit more complex (see also Scalable Lock-Free Dynamic Memory Allocation)

mfrey avatar Feb 06 '18 12:02 mfrey

the first thing would be to evaluate, if there are any calls to _path_detailed() from API functions. If not, then there's no ürpblem at all.

git grep to the rescue

mfrey avatar Feb 06 '18 12:02 mfrey

tl;dr i'm happy that you address potential issues with multi-threading and we should keep this in mind

We've discussed the parallel access issue during our last project meeting in Hamburg and the corresponding workaround. Honestly, I'm still not convinced that this is the way to go and I think ccn-lite in the long run should support multi-threading/parallel access.

Saying that, no matter how we (or whoever is addressing this issue (and related topics)) handle the malloc situation, we shouldn't make things worse if at some point somebody wants to add support for multi-threading.

mfrey avatar Feb 06 '18 13:02 mfrey

and I think ccn-lite in the long run should support multi-threading/parallel access

do you mean the ccn-lite core (or forwarding daemon) should support multi-threadding? Or should the user API just be thread-safe?

cgundogan avatar Feb 06 '18 13:02 cgundogan

do you mean the ccn-lite core (or forwarding daemon) should support multi-threadding? Or should the user API just be thread-safe?

From the perspective of RIOT, making the forwarder multi-threaded is probably a no-go. Making the API calls thread-safe is however necessary, be it for RIOT or Linux/OSX

cgundogan avatar Feb 06 '18 13:02 cgundogan

From the perspective of RIOT, making the forwarder multi-threaded is probably a no-go. Making the API calls thread-safe is however necessary, be it for RIOT or Linux/OSX

The API needs to be thread-safe. Basically every essential data structure is part of struct ccnl_relay_s which will make this a cumbersome endeavour.

mfrey avatar Feb 06 '18 13:02 mfrey