[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Bash 5 increase in RAM from loop with many interations that append t
From: |
Chet Ramey |
Subject: |
Re: Bash 5 increase in RAM from loop with many interations that append to file |
Date: |
Tue, 27 Oct 2020 09:40:53 -0400 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.3.3 |
On 10/27/20 12:11 AM, Scott Kostyshak wrote:
> The following example uses more peak RAM on new bash versions than old
> versions:
>
> for i in {1..1000000}; do
> echo "${i}" >> example.txt
> done
>
> By measuring peak memory usage with time (/usr/bin/time -f "%E %P %M"),
> I get that newer versions of Bash use about 284M, where older versions
> use about 191M.
>
> Is this perceived increase in memory usage worth looking more into or is
> it intended?
My guess is that the huge list that results from the brace expansion caused
the bash malloc to cross over into a larger memory bin because of unrelated
memory allocation patterns that changed between bash versions. Once you
allocate that much memory, a binary bin allocation method is going to waste
some. In bash-5.0, that large allocation is going to use mmap, which adds
some overhead of its own.
If you can use valgrind or a similar tool to identify a memory leak, that
would be useful.
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU chet@case.edu http://tiswww.cwru.edu/~chet/