diff --git a/be/src/common/cgroup_memory_ctl.cpp b/be/src/common/cgroup_memory_ctl.cpp index 3d48ec8b37c9f6..a29432bdb4ede5 100644 --- a/be/src/common/cgroup_memory_ctl.cpp +++ b/be/src/common/cgroup_memory_ctl.cpp @@ -61,13 +61,13 @@ struct CgroupsV1Reader : CGroupMemoryCtl::ICgroupsReader { explicit CgroupsV1Reader(std::filesystem::path mount_file_dir) : _mount_file_dir(std::move(mount_file_dir)) {} - Status read_memory_limit(uint64_t* value) override { + Status read_memory_limit(int64_t* value) override { RETURN_IF_ERROR(CGroupUtil::read_int_line_from_cgroup_file( - (_mount_file_dir / "memory.limit_in_bytes"), (int64_t*)value)); + (_mount_file_dir / "memory.limit_in_bytes"), value)); return Status::OK(); } - Status read_memory_usage(uint64_t* value) override { + Status read_memory_usage(int64_t* value) override { std::unordered_map metrics_map; CGroupUtil::read_int_metric_from_cgroup_file((_mount_file_dir / "memory.stat"), metrics_map); @@ -83,17 +83,17 @@ struct CgroupsV2Reader : CGroupMemoryCtl::ICgroupsReader { explicit CgroupsV2Reader(std::filesystem::path mount_file_dir) : _mount_file_dir(std::move(mount_file_dir)) {} - Status read_memory_limit(uint64_t* value) override { + Status read_memory_limit(int64_t* value) override { RETURN_IF_ERROR(CGroupUtil::read_int_line_from_cgroup_file((_mount_file_dir / "memory.max"), - (int64_t*)value)); + value)); return Status::OK(); } - Status read_memory_usage(uint64_t* value) override { + Status read_memory_usage(int64_t* value) override { // memory.current contains a single number // the reason why we subtract it described here: https://github.com/ClickHouse/ClickHouse/issues/64652#issuecomment-2149630667 RETURN_IF_ERROR(CGroupUtil::read_int_line_from_cgroup_file( - (_mount_file_dir / "memory.current"), (int64_t*)value)); + (_mount_file_dir / "memory.current"), value)); std::unordered_map metrics_map; CGroupUtil::read_int_metric_from_cgroup_file((_mount_file_dir / "memory.stat"), metrics_map); @@ -152,14 +152,14 @@ Status get_cgroups_reader(std::shared_ptr& read return Status::OK(); } -Status CGroupMemoryCtl::find_cgroup_mem_limit(uint64_t* bytes) { +Status CGroupMemoryCtl::find_cgroup_mem_limit(int64_t* bytes) { std::shared_ptr reader; RETURN_IF_ERROR(get_cgroups_reader(reader)); RETURN_IF_ERROR(reader->read_memory_limit(bytes)); return Status::OK(); } -Status CGroupMemoryCtl::find_cgroup_mem_usage(uint64_t* bytes) { +Status CGroupMemoryCtl::find_cgroup_mem_usage(int64_t* bytes) { std::shared_ptr reader; RETURN_IF_ERROR(get_cgroups_reader(reader)); RETURN_IF_ERROR(reader->read_memory_usage(bytes)); @@ -178,10 +178,10 @@ std::string CGroupMemoryCtl::debug_string() { CGroupUtil::cgroupsv1_enable()); } - uint64_t mem_limit; + int64_t mem_limit; auto mem_limit_st = find_cgroup_mem_limit(&mem_limit); - uint64_t mem_usage; + int64_t mem_usage; auto mem_usage_st = find_cgroup_mem_usage(&mem_usage); return fmt::format( diff --git a/be/src/common/cgroup_memory_ctl.h b/be/src/common/cgroup_memory_ctl.h index 29872c8ba966e9..83f33e03cda17e 100644 --- a/be/src/common/cgroup_memory_ctl.h +++ b/be/src/common/cgroup_memory_ctl.h @@ -25,19 +25,19 @@ class CGroupMemoryCtl { struct ICgroupsReader { virtual ~ICgroupsReader() = default; - virtual Status read_memory_limit(uint64_t* value) = 0; + virtual Status read_memory_limit(int64_t* value) = 0; - virtual Status read_memory_usage(uint64_t* value) = 0; + virtual Status read_memory_usage(int64_t* value) = 0; }; // Determines the CGroup memory limit from the current processes' cgroup. // If the limit is more than INT64_MAX, INT64_MAX is returned (since that is // effectively unlimited anyway). Does not take into account memory limits // set on any ancestor CGroups. - static Status find_cgroup_mem_limit(uint64_t* bytes); + static Status find_cgroup_mem_limit(int64_t* bytes); // https://serverfault.com/questions/902009/the-memory-usage-reported-in-cgroup-differs-from-the-free-command - static Status find_cgroup_mem_usage(uint64_t* bytes); + static Status find_cgroup_mem_usage(int64_t* bytes); // Returns a human-readable string with information about CGroups. static std::string debug_string(); diff --git a/be/src/util/mem_info.cpp b/be/src/util/mem_info.cpp index a13f930bf54e7a..07ee16d1d4f9fb 100644 --- a/be/src/util/mem_info.cpp +++ b/be/src/util/mem_info.cpp @@ -74,8 +74,8 @@ std::atomic MemInfo::_s_je_dirty_pages_mem = std::numeric_limits MemInfo::_s_je_dirty_pages_mem_limit = std::numeric_limits::max(); std::atomic MemInfo::_s_virtual_memory_used = 0; -uint64_t MemInfo::_s_cgroup_mem_limit = std::numeric_limits::max(); -uint64_t MemInfo::_s_cgroup_mem_usage = std::numeric_limits::min(); +int64_t MemInfo::_s_cgroup_mem_limit = std::numeric_limits::max(); +int64_t MemInfo::_s_cgroup_mem_usage = std::numeric_limits::min(); bool MemInfo::_s_cgroup_mem_refresh_state = false; int64_t MemInfo::_s_cgroup_mem_refresh_wait_times = 0; @@ -190,8 +190,8 @@ void MemInfo::refresh_proc_meminfo() { // refresh cgroup memory if (_s_cgroup_mem_refresh_wait_times >= 0 && config::enable_use_cgroup_memory_info) { - uint64_t cgroup_mem_limit = -1; - uint64_t cgroup_mem_usage = -1; + int64_t cgroup_mem_limit = -1; + int64_t cgroup_mem_usage = -1; std::string cgroup_mem_info_file_path; _s_cgroup_mem_refresh_state = true; Status status = CGroupMemoryCtl::find_cgroup_mem_limit(&cgroup_mem_limit); @@ -234,7 +234,7 @@ void MemInfo::refresh_proc_meminfo() { if (physical_mem < 0) { physical_mem = _s_cgroup_mem_limit; } else { - physical_mem = std::min(physical_mem, (int64_t)_s_cgroup_mem_limit); + physical_mem = std::min(physical_mem, _s_cgroup_mem_limit); } } @@ -280,8 +280,7 @@ void MemInfo::refresh_proc_meminfo() { if (mem_available < 0) { mem_available = _s_cgroup_mem_limit - _s_cgroup_mem_usage; } else { - mem_available = - std::min(mem_available, (int64_t)(_s_cgroup_mem_limit - _s_cgroup_mem_usage)); + mem_available = std::min(mem_available, (_s_cgroup_mem_limit - _s_cgroup_mem_usage)); } } if (mem_available < 0) { diff --git a/be/src/util/mem_info.h b/be/src/util/mem_info.h index cfac5754c96b2a..10d2d086801540 100644 --- a/be/src/util/mem_info.h +++ b/be/src/util/mem_info.h @@ -217,8 +217,8 @@ class MemInfo { static std::atomic _s_je_dirty_pages_mem_limit; static std::atomic _s_virtual_memory_used; - static uint64_t _s_cgroup_mem_limit; - static uint64_t _s_cgroup_mem_usage; + static int64_t _s_cgroup_mem_limit; + static int64_t _s_cgroup_mem_usage; static bool _s_cgroup_mem_refresh_state; static int64_t _s_cgroup_mem_refresh_wait_times;