mirror of https://github.com/mirror/busybox.git
ash: memalloc: Avoid looping in growstackto
Upstream commit: Date: Thu, 31 May 2018 01:51:48 +0800 memalloc: Avoid looping in growstackto Currently growstackto will repeatedly call growstackblock until the requisite size is obtained. This is wasteful. This patch changes growstackblock to take a minimum size instead. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>1_32_stable
parent
3ced804e31
commit
da2e46dff6
14
shell/ash.c
14
shell/ash.c
|
@ -1678,15 +1678,16 @@ popstackmark(struct stackmark *mark)
|
||||||
* part of the block that has been used.
|
* part of the block that has been used.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
growstackblock(void)
|
growstackblock(size_t min)
|
||||||
{
|
{
|
||||||
size_t newlen;
|
size_t newlen;
|
||||||
|
|
||||||
newlen = g_stacknleft * 2;
|
newlen = g_stacknleft * 2;
|
||||||
if (newlen < g_stacknleft)
|
if (newlen < g_stacknleft)
|
||||||
ash_msg_and_raise_error(bb_msg_memory_exhausted);
|
ash_msg_and_raise_error(bb_msg_memory_exhausted);
|
||||||
if (newlen < 128)
|
min = SHELL_ALIGN(min | 128);
|
||||||
newlen += 128;
|
if (newlen < min)
|
||||||
|
newlen += min;
|
||||||
|
|
||||||
if (g_stacknxt == g_stackp->space && g_stackp != &stackbase) {
|
if (g_stacknxt == g_stackp->space && g_stackp != &stackbase) {
|
||||||
struct stack_block *sp;
|
struct stack_block *sp;
|
||||||
|
@ -1736,16 +1737,15 @@ static void *
|
||||||
growstackstr(void)
|
growstackstr(void)
|
||||||
{
|
{
|
||||||
size_t len = stackblocksize();
|
size_t len = stackblocksize();
|
||||||
growstackblock();
|
growstackblock(0);
|
||||||
return (char *)stackblock() + len;
|
return (char *)stackblock() + len;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
growstackto(size_t len)
|
growstackto(size_t len)
|
||||||
{
|
{
|
||||||
while (stackblocksize() < len)
|
if (stackblocksize() < len)
|
||||||
growstackblock();
|
growstackblock(len);
|
||||||
|
|
||||||
return stackblock();
|
return stackblock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue