aboutsummaryrefslogtreecommitdiffstats
path: root/executor
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2022-11-22 17:45:08 +0100
committerDmitry Vyukov <dvyukov@google.com>2022-11-23 09:09:39 +0100
commitf2248a0a06cf02cc83adfc073a0fab1ab53b344f (patch)
treed355752a42754d184ac3339a8c2aba0f1417389c /executor
parent3c4ffce72a611aaf547c0e0047b4aefc0dde86fd (diff)
executor: reduce zlib memory consumption
The images we unpack has huge ranges of 0s. Currently we write all bytes and as the result page in whole unpacked image. Don't write 0s since we just mmaped zero memory. This reduces btrfs_0 seed memory consumption from 130MB to 6MB.
Diffstat (limited to 'executor')
-rw-r--r--executor/common_zlib.h13
1 files changed, 8 insertions, 5 deletions
diff --git a/executor/common_zlib.h b/executor/common_zlib.h
index 5f8124318..24382ac0c 100644
--- a/executor/common_zlib.h
+++ b/executor/common_zlib.h
@@ -98,8 +98,10 @@ static int puff_stored(struct puff_state* s)
return 2; // not enough input
if (s->outcnt + len > s->outlen)
return 1; // not enough output space
- while (len--)
- s->out[s->outcnt++] = s->in[s->incnt++];
+ for (; len--; s->outcnt++, s->incnt++) {
+ if (s->in[s->incnt])
+ s->out[s->outcnt] = s->in[s->incnt];
+ }
// done with a valid stored block
return 0;
@@ -243,7 +245,8 @@ static int puff_codes(struct puff_state* s,
// write out the literal
if (s->outcnt == s->outlen)
return 1;
- s->out[s->outcnt] = symbol;
+ if (symbol)
+ s->out[s->outcnt] = symbol;
s->outcnt++;
} else if (symbol > 256) { // length
// get and compute length
@@ -264,8 +267,8 @@ static int puff_codes(struct puff_state* s,
if (s->outcnt + len > s->outlen)
return 1;
while (len--) {
- s->out[s->outcnt] =
- dist > s->outcnt ? 0 : s->out[s->outcnt - dist];
+ if (dist <= s->outcnt && s->out[s->outcnt - dist])
+ s->out[s->outcnt] = s->out[s->outcnt - dist];
s->outcnt++;
}
}