aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2020-02-21 15:25:37 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2020-02-21 15:25:37 +0100
commitda2e46dff6576c29fa1d379c943bb7943aa6e7ce (patch)
tree3c0d5871276db4d1e1bc3061e8de0529d39fa5f0
parent3ced804e3118d138781c3e4baa6bf1589b9f2dfd (diff)
downloadbusybox-w32-da2e46dff6576c29fa1d379c943bb7943aa6e7ce.tar.gz
busybox-w32-da2e46dff6576c29fa1d379c943bb7943aa6e7ce.tar.bz2
busybox-w32-da2e46dff6576c29fa1d379c943bb7943aa6e7ce.zip
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>
-rw-r--r--shell/ash.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/shell/ash.c b/shell/ash.c
index fd2fc9f23..8d1822847 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -1678,15 +1678,16 @@ popstackmark(struct stackmark *mark)
1678 * part of the block that has been used. 1678 * part of the block that has been used.
1679 */ 1679 */
1680static void 1680static void
1681growstackblock(void) 1681growstackblock(size_t min)
1682{ 1682{
1683 size_t newlen; 1683 size_t newlen;
1684 1684
1685 newlen = g_stacknleft * 2; 1685 newlen = g_stacknleft * 2;
1686 if (newlen < g_stacknleft) 1686 if (newlen < g_stacknleft)
1687 ash_msg_and_raise_error(bb_msg_memory_exhausted); 1687 ash_msg_and_raise_error(bb_msg_memory_exhausted);
1688 if (newlen < 128) 1688 min = SHELL_ALIGN(min | 128);
1689 newlen += 128; 1689 if (newlen < min)
1690 newlen += min;
1690 1691
1691 if (g_stacknxt == g_stackp->space && g_stackp != &stackbase) { 1692 if (g_stacknxt == g_stackp->space && g_stackp != &stackbase) {
1692 struct stack_block *sp; 1693 struct stack_block *sp;
@@ -1736,16 +1737,15 @@ static void *
1736growstackstr(void) 1737growstackstr(void)
1737{ 1738{
1738 size_t len = stackblocksize(); 1739 size_t len = stackblocksize();
1739 growstackblock(); 1740 growstackblock(0);
1740 return (char *)stackblock() + len; 1741 return (char *)stackblock() + len;
1741} 1742}
1742 1743
1743static char * 1744static char *
1744growstackto(size_t len) 1745growstackto(size_t len)
1745{ 1746{
1746 while (stackblocksize() < len) 1747 if (stackblocksize() < len)
1747 growstackblock(); 1748 growstackblock(len);
1748
1749 return stackblock(); 1749 return stackblock();
1750} 1750}
1751 1751