1 Star 0 Fork 100

fly_fzc/systemd

forked from src-openEuler/systemd 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
backport-coredump-correctly-take-tmpfs-size-into-account-for-.patch 3.12 KB
一键复制 编辑 原始数据 按行查看 历史
w30023233 提交于 2024-12-24 16:16 . sync patches from systemd community
From 3dacca114bde3a216605ab51d2f5203c4a6b9707 Mon Sep 17 00:00:00 2001
From: Luca Boccassi <[email protected]>
Date: Tue, 2 Jul 2024 15:28:47 +0100
Subject: [PATCH] coredump: correctly take tmpfs size into account for
compression
We calculate the amount of uncompressed data we can write by taking the limits
into account and halving it to ensure there's room for switching to compression
on the fly when storing cores on a tmpfs (eg: due read-only rootfs).
But the logic is flawed, as taking into account the size of the tmpfs storage
was applied after the halving, so in practice when an uncompressed core file
was larger than the tmpfs, we fill it and then fail.
Rearrange the logic so that the halving is done after taking into account
the tmpfs size.
(cherry picked from commit e6b2508275aac2951aedfc842735d8ebc29850bb)
(cherry picked from commit a946258e9df627c675d13b2041ae186babf269dc)
Conflict:NA
Reference:https://github.com/systemd/systemd-stable/commit/3dacca114bde3a216605ab51d2f5203c4a6b9707
---
src/coredump/coredump.c | 20 ++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/src/coredump/coredump.c b/src/coredump/coredump.c
index 32c17664fd..f4adb32588 100644
--- a/src/coredump/coredump.c
+++ b/src/coredump/coredump.c
@@ -503,17 +503,21 @@ static int save_external_coredump(
bus_error_message(&error, r));
}
+ /* First, ensure we are not going to go over the cgroup limit */
max_size = MIN(cgroup_limit, max_size);
- max_size = LESS_BY(max_size, 1024U) / 2; /* Account for 1KB metadata overhead for compressing */
- max_size = MAX(PROCESS_SIZE_MIN, max_size); /* Impose a lower minimum */
-
- /* tmpfs might get full quickly, so check the available space too.
- * But don't worry about errors here, failing to access the storage
- * location will be better logged when writing to it. */
+ /* tmpfs might get full quickly, so check the available space too. But don't worry about
+ * errors here, failing to access the storage location will be better logged when writing to
+ * it. */
if (fstatvfs(fd, &sv) >= 0)
max_size = MIN((uint64_t)sv.f_frsize * (uint64_t)sv.f_bfree, max_size);
-
- log_debug("Limiting core file size to %" PRIu64 " bytes due to cgroup memory limits.", max_size);
+ /* Impose a lower minimum, otherwise we will miss the basic headers. */
+ max_size = MAX(PROCESS_SIZE_MIN, max_size);
+ /* Ensure we can always switch to compressing on the fly in case we are running out of space
+ * by keeping half of the space/memory available, plus 1KB metadata overhead from the
+ * compression algorithm. */
+ max_size = LESS_BY(max_size, 1024U) / 2;
+
+ log_debug("Limiting core file size to %" PRIu64 " bytes due to cgroup and/or filesystem limits.", max_size);
}
r = copy_bytes(input_fd, fd, max_size, 0);
--
2.33.0
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/fly_fzc/systemd.git
[email protected]:fly_fzc/systemd.git
fly_fzc
systemd
systemd
master

搜索帮助