qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] linux-user: ppoll: eliminate large alloca


From: Michael Tokarev
Subject: Re: [PATCH] linux-user: ppoll: eliminate large alloca
Date: Sun, 9 Apr 2023 14:31:42 +0300
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.0

(Replying to an old(ish) email... original thread:
https://patchwork.ozlabs.org/project/qemu-devel/patch/20221216192220.2881898-1-mjt@msgid.tls.msk.ru/
 )

16.12.2022 23:44, Richard Henderson wrote:
On 12/16/22 11:22, Michael Tokarev wrote:
do_ppoll() in linux-user/syscall.c uses alloca() to
allocate an array of struct pullfds on the stack.
The only upper boundary for number of entries for this
array is so that whole thing fits in INT_MAX. But this
is definitely too much for a stack allocation.

Use heap allocation when large number of entries
is requested (currently 128, arbitrary), and continue
to use alloca() for smaller allocations, to optimize
small operations for small sizes.

I think it would be cleaner to always use heap allocation, and use g_autofree 
for the pointer.

Yes it is cleaner to always use the same type of allocation.
Does it really unnecessary to try to avoid heap allocations
for small things? It costs not that much, but might speed
some things up. Dunno how much it saves though.  Maybe it
is from the "premature optimization" field :)

Speaking of g_autofree, we already have to unlock_user anyway
(which we forgot to call), - so it makes no difference
between marking it as g_autofree or explicitly freeing it.

Thanks,

/mjt



reply via email to

[Prev in Thread] Current Thread [Next in Thread]