Skip to content

Commit

Permalink
binfmt/loadable: move binary_s to stack to avoid access allocator
Browse files Browse the repository at this point in the history
Improve performance by reducing allocator accesses

Signed-off-by: chao an <[email protected]>
  • Loading branch information
anchao authored and xiaoxiang781216 committed Dec 13, 2024
1 parent 5abcc49 commit c6dfdba
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions binfmt/binfmt_exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,22 @@ static int exec_internal(FAR const char *filename,
irqstate_t flags;
int pid;
int ret;
#ifndef CONFIG_BINFMT_LOADABLE
struct binary_s sbin;

bin = &sbin;
#else

/* Allocate the load information */

bin = kmm_zalloc(sizeof(struct binary_s));
if (!bin)
if (bin == NULL)
{
berr("ERROR: Failed to allocate binary_s\n");
ret = -ENOMEM;
goto errout;
}
#endif

/* Load the module into memory */

Expand Down Expand Up @@ -154,15 +160,9 @@ static int exec_internal(FAR const char *filename,
if (ret < 0)
{
berr("ERROR: Failed to schedule unload '%s': %d\n", filename, ret);
goto errout_with_lock;
}

#else
/* Free the binary_s structure here */

kmm_free(bin);

/* TODO: How does the module get unloaded in this case? */

#endif

sched_unlock();
Expand All @@ -174,8 +174,10 @@ static int exec_internal(FAR const char *filename,
leave_critical_section(flags);
unload_module(bin);
errout_with_bin:
#ifdef CONFIG_BINFMT_LOADABLE
kmm_free(bin);
errout:
#endif
return ret;
}

Expand Down

0 comments on commit c6dfdba

Please sign in to comment.