From f2248a0a06cf02cc83adfc073a0fab1ab53b344f Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Tue, 22 Nov 2022 17:45:08 +0100 Subject: 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. --- pkg/csource/generated.go | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'pkg/csource/generated.go') diff --git a/pkg/csource/generated.go b/pkg/csource/generated.go index 9ee0705c2..61b95e4cf 100644 --- a/pkg/csource/generated.go +++ b/pkg/csource/generated.go @@ -6387,8 +6387,10 @@ static int puff_stored(struct puff_state* s) return 2; if (s->outcnt + len > s->outlen) return 1; - 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]; + } return 0; } struct puff_huffman { @@ -6483,7 +6485,8 @@ static int puff_codes(struct puff_state* s, if (symbol < 256) { 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) { symbol -= 257; @@ -6499,8 +6502,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++; } } @@ -11528,8 +11531,10 @@ static int puff_stored(struct puff_state* s) return 2; if (s->outcnt + len > s->outlen) return 1; - 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]; + } return 0; } struct puff_huffman { @@ -11624,7 +11629,8 @@ static int puff_codes(struct puff_state* s, if (symbol < 256) { 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) { symbol -= 257; @@ -11640,8 +11646,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++; } } -- cgit mrf-deployment