Skip to content

Commit 18d4e97

Browse files
committed
Add support for ZSTD compression
1 parent c0542f4 commit 18d4e97

File tree

9 files changed

+396
-104
lines changed

9 files changed

+396
-104
lines changed

.github/workflows/ci-clang.yml

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,35 @@ jobs:
1414
run: |
1515
sudo apt-get update
1616
sudo apt-get install -y liblz4-dev liblz4-1
17+
sudo apt-get install -y libzstd-dev libzstd1
1718
sudo apt-get install -y libssl-dev libssl3
1819
1920
- name: build
2021
run: |
2122
make CC=clang
2223
make clean
2324
24-
- name: build lz4
25+
- name: build with lz4
2526
run: |
26-
make CC=clang COMPRESS_LZ4=1
27+
make COMPRESS_LZ4=1 CC=clang
2728
make clean
2829
29-
- name: build md5
30+
- name: build with zstd
3031
run: |
31-
make CC=clang CHECKSUM_MD5=1
32+
make COMPRESS_ZSTD=1 CC=clang
3233
make clean
3334
34-
- name: build lz4 md5 enc
35+
- name: build with md5
3536
run: |
36-
make CC=clang COMPRESS_LZ4=1 CHECKSUM_MD5=1 ENCRYPT=1
37+
make CHECKSUM_MD5=1 CC=clang
38+
make clean
39+
40+
- name: build with enc
41+
run: |
42+
make ENCRYPT=1 CC=clang
43+
make clean
44+
45+
- name: build with lz4 zstd md5 enc
46+
run: |
47+
make COMPRESS_LZ4=1 COMPRESS_ZSTD=1 CHECKSUM_MD5=1 ENCRYPT=1 CC=clang
3748
make clean

.github/workflows/ci-x86_64.yml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,35 @@ jobs:
1414
run: |
1515
sudo apt-get update
1616
sudo apt-get install -y liblz4-dev liblz4-1
17+
sudo apt-get install -y libzstd-dev libzstd1
1718
sudo apt-get install -y libssl-dev libssl3
1819
1920
- name: build
2021
run: |
2122
make
2223
make clean
2324
24-
- name: build lz4
25+
- name: build with lz4
2526
run: |
2627
make COMPRESS_LZ4=1
2728
make clean
2829
29-
- name: build md5
30+
- name: build with zstd
31+
run: |
32+
make COMPRESS_ZSTD=1
33+
make clean
34+
35+
- name: build with md5
3036
run: |
3137
make CHECKSUM_MD5=1
3238
make clean
3339
34-
- name: build lz4 md5 enc
40+
- name: build with enc
41+
run: |
42+
make ENCRYPT=1
43+
make clean
44+
45+
- name: build with lz4 zstd md5 enc
3546
run: |
36-
make COMPRESS_LZ4=1 CHECKSUM_MD5=1 ENCRYPT=1
47+
make COMPRESS_LZ4=1 COMPRESS_ZSTD=1 CHECKSUM_MD5=1 ENCRYPT=1
3748
make clean

Makefile

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#
22
# Copyright (C) 2022 Liberty Global Service B.V.
3+
# Copyright (C) 2022-2025 Mariusz Kozłowski
34
#
45
# This program is free software; you can redistribute it and/or
56
# modify it under the terms of the GNU General Public License
@@ -38,6 +39,11 @@ ifeq ($(COMPRESS_LZ4), 1)
3839
LDFLAGS += -llz4
3940
endif
4041

42+
ifeq ($(COMPRESS_ZSTD), 1)
43+
MCFLAGS += -DCOMPRESS_ZSTD
44+
LDFLAGS += -lzstd
45+
endif
46+
4147
ifeq ($(CHECKSUM_MD5), 1)
4248
MCFLAGS += -DCHECKSUM_MD5
4349
LDFLAGS += -lcrypto
@@ -142,10 +148,13 @@ $(B)/enter.o: arch/$(ARCH)/enter.c
142148
$(B)/cpu.o: arch/$(ARCH)/cpu.c
143149
$(CC) $(MCFLAGS) -c $^ -o $@
144150

151+
$(B)/compress.o: compress.c compress.h
152+
$(CC) $(MCFLAGS) -c $< -o $@
153+
145154
$(B)/memcr.o: memcr.c $(B)/parasite-blob.h
146155
$(CC) $(MCFLAGS) -DGIT_VERSION='"$(GIT_VERSION)"' -DARCH_NAME='"$(ARCH)"' -I$(B) -c $< -o $@
147156

148-
$(B)/memcr: $(B)/memcr.o $(B)/cpu.o $(B)/enter.o
157+
$(B)/memcr: $(B)/memcr.o $(B)/cpu.o $(B)/enter.o $(B)/compress.o
149158
$(CC) $(MCFLAGS) $^ $(LDFLAGS) -o $@
150159
@stat -c "-> %n: %s bytes <-" $@
151160
@size $@
@@ -193,18 +202,19 @@ clean:
193202

194203
help:
195204
@echo 'Build targets:'
196-
@echo ' all - build all targets'
197-
@echo ' memcr - build memcr binary'
205+
@echo ' all - build all targets'
206+
@echo ' memcr - build memcr binary'
198207
@echo ''
199208
@echo 'Compilation options:'
200-
@echo ' COMPRESS_LZ4=1 - compile in support for memory dump LZ4 compression'
201-
@echo ' CHECKSUM_MD5=1 - compile in support for memory dump MD5 checksumming'
202-
@echo ' ENCRYPT=1 - compile libencrypt.so that can be preloaded for memcr'
209+
@echo ' COMPRESS_LZ4=1 - compile in support for memory dump LZ4 compression'
210+
@echo ' COMPRESS_ZSTD=1 - compile in support for memory dump ZSTD compression'
211+
@echo ' CHECKSUM_MD5=1 - compile in support for memory dump MD5 checksumming'
212+
@echo ' ENCRYPT=1 - compile libencrypt.so that can be preloaded for memcr'
203213
@echo ''
204214
@echo 'Test targets:'
205-
@echo ' tests - build and run memcr tests'
215+
@echo ' tests - build and run memcr tests'
206216
@echo ''
207217
@echo 'Clean targets:'
208-
@echo ' clean - remove generated files'
218+
@echo ' clean - remove generated files'
209219

210220
.PHONY: all tests clean help

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,21 @@ make
1818
##### compilation options
1919
You can enable support for compression and checksumming of memory dump file:
2020
- `COMPRESS_LZ4=1` - requires liblz4
21+
- `COMPRESS_ZSTD=1` - requires libzstd
2122
- `CHECKSUM_MD5=1` - requires libcrypto and openssl headers
2223

2324
There is also `ENCRYPT` option for building `libencrypt.so` that provides sample implementation of encryption layer based on libcrypto API. memcr is not linked with libencrypt.so, but it can be preloaded with `LD_PRELOAD`.
2425
- `ENCRYPT=1` - requires libcrypto and openssl headers
2526

26-
##### compilation on Ubuntu 22.04:
27+
##### compilation on Ubuntu 24.04:
2728
```
2829
sudo apt-get install liblz4-dev liblz4-1
30+
sudo apt-get install libzstd-dev libzstd1
2931
sudo apt-get install libssl-dev libssl3
3032
```
3133

3234
```
33-
make COMPRESS_LZ4=1 CHECKSUM_MD5=1 ENCRYPT=1
35+
make COMPRESS_LZ4=1 COMPRESS_ZSTD=1 CHECKSUM_MD5=1 ENCRYPT=1
3436
```
3537

3638
##### cross compilation
@@ -52,15 +54,15 @@ memcr -p <target pid>
5254
```
5355
For the list of available options, check memcr help:
5456
```
55-
memcr [-h] [-p PID] [-d DIR] [-S DIR] [-l PORT|PATH] [-n] [-m] [-f] [-z] [-c] [-e] [-V]
57+
memcr [-h] [-p PID] [-d DIR] [-S DIR] [-G gid] [-N] [-l PORT|PATH] [-g gid] [-n] [-m] [-f] [-z lz4|zstd] [-c] [-e] [-t] [-V]
5658
options:
5759
-h --help help
5860
-p --pid target process pid
5961
-d --dir dir where memory dump is stored (defaults to /tmp)
6062
-S --parasite-socket-dir dir where socket to communicate with parasite is created
6163
(abstract socket will be used if no path specified)
62-
-G --parasite-socket-gid group ID for parasite UNIX domain socket file, valid only for if --parasite-socket-dir provided,
63-
note: the group ID provided need to be common for: the user running memcr daemon and the user running suspended process
64+
-G --parasite-socket-gid group ID for parasite UNIX domain socket file, valid only for if --parasite-socket-dir provided
65+
note: the group ID provided need to be common for: the user running memcr daemon and the user running suspended process
6466
-N --parasite-socket-netns use network namespace of parasite when connecting to socket
6567
(useful if parasite is running in a container with netns)
6668
-l --listen work as a service waiting for requests on a socket
@@ -70,12 +72,11 @@ options:
7072
-n --no-wait no wait for key press
7173
-m --proc-mem get pages from /proc/pid/mem
7274
-f --rss-file include file mapped memory
73-
-z --compress compress memory dump
75+
-z --compress compress memory dump with zstd or lz4 (default)
7476
-c --checksum enable md5 checksum for memory dump
7577
-e --encrypt enable encryption of memory dump
7678
-t --timeout timeout in seconds for checkpoint/restore execution in service mode
7779
-V --version print version and exit
78-
7980
```
8081
memcr also supports client / server scenario where memcr runs as a daemon and listens for commands from a client process. The main reason for supporting this is that memcr needs rather high privileges to hijack target process and it's a good idea to keep it separate from memcr-client that can run in a container with low privileges.
8182

0 commit comments

Comments
 (0)