Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit ca2327a

Browse files
fix: correct RAM usage (#2019)
Co-authored-by: sangjanai <sang@jan.ai>
1 parent 3ff301a commit ca2327a

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

engine/utils/hardware/ram_info.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ inline Memory GetMemoryInfo() {
1717
hwinfo::Memory m;
1818
#if defined(__APPLE__) && defined(__MACH__)
1919
int64_t total_memory = 0;
20-
int64_t used_memory = 0;
20+
int64_t avail_memory = 0;
2121

2222
size_t length = sizeof(total_memory);
2323
sysctlbyname("hw.memsize", &total_memory, &length, NULL, 0);
2424

25-
// Get used memory (this is a rough estimate)
25+
// Get avail memory (this is a rough estimate)
2626
vm_size_t page_size;
2727
mach_msg_type_number_t count = HOST_VM_INFO_COUNT;
2828

@@ -31,12 +31,10 @@ inline Memory GetMemoryInfo() {
3131

3232
if (host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&vm_stat,
3333
&count) == KERN_SUCCESS) {
34-
used_memory =
35-
(vm_stat.active_count + vm_stat.inactive_count + vm_stat.wire_count) *
36-
page_size;
34+
avail_memory = (vm_stat.free_count + vm_stat.inactive_count) * page_size;
3735
}
3836
return Memory{.total_MiB = ByteToMiB(total_memory),
39-
.available_MiB = ByteToMiB(total_memory - used_memory)};
37+
.available_MiB = ByteToMiB(avail_memory)};
4038
#elif defined(__linux__) || defined(_WIN32)
4139
return Memory{.total_MiB = ByteToMiB(m.total_Bytes()),
4240
.available_MiB = ByteToMiB(m.available_Bytes())};

0 commit comments

Comments
 (0)