MCPcopy Create free account
hub / github.com/ByConity/ByConity / getMemoryAmountOrZero

Function getMemoryAmountOrZero

base/common/getMemoryAmount.cpp:17–42  ·  view source on GitHub ↗

Returns the size of physical memory (RAM) in bytes. * Returns 0 on unsupported platform */

Source from the content-addressed store, hash-verified

15 * Returns 0 on unsupported platform
16 */
17uint64_t getMemoryAmountOrZero()
18{
19 int64_t num_pages = sysconf(_SC_PHYS_PAGES);
20 if (num_pages <= 0)
21 return 0;
22
23 int64_t page_size = getPageSize();
24 if (page_size <= 0)
25 return 0;
26
27 uint64_t memory_amount = num_pages * page_size;
28
29#if defined(OS_LINUX)
30 // Try to lookup at the Cgroup limit
31 std::ifstream cgroup_limit("/sys/fs/cgroup/memory/memory.limit_in_bytes");
32 if (cgroup_limit.is_open())
33 {
34 uint64_t memory_limit = 0; // in case of read error
35 cgroup_limit >> memory_limit;
36 if (memory_limit > 0 && memory_limit < memory_amount)
37 memory_amount = memory_limit;
38 }
39#endif
40
41 return memory_amount;
42}
43
44
45uint64_t getMemoryAmount()

Callers 2

getMemoryAmountFunction · 0.85
setExtrasFunction · 0.85

Calls 1

getPageSizeFunction · 0.85

Tested by

no test coverage detected