Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 17a1bd5

Browse files
committed
libsys/free: Differentiate between free and available memory
1 parent c102905 commit 17a1bd5

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

libraries/libsys/Memory.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ namespace Sys::Mem {
7171
inline Amount free() const {
7272
return {(size_t) usable - (size_t) used};
7373
}
74+
75+
inline Amount available() const {
76+
return {(size_t) usable - (size_t) used + (size_t) kernel_disk_cache};
77+
}
78+
79+
inline double available_frac() const {
80+
return (double)((long double) available() / (long double) usable);
81+
}
7482
};
7583

7684
Duck::ResultRet<Info> get_info(Duck::InputStream& file);

programs/coreutils/free.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ int main(int argc, char** argv, char** envp) {
4444
if(human_readable) {
4545
printf("Total: %s\n", info.usable.readable().c_str());
4646
printf("Used: %s (%.2f%%)\n", info.used.readable().c_str(), info.used_frac() * 100.0);
47-
printf("Available: %s (%.2f%%)\n", info.free().readable().c_str(), info.free_frac() * 100.0);
47+
printf("Free: %s (%.2f%%)\n", info.free().readable().c_str(), info.free_frac() * 100.0);
48+
printf("Available: %s (%.2f%%)\n", info.available().readable().c_str(), info.available_frac() * 100.0);
4849
if(kernel_memory) {
4950
printf("Kernel physical: %s\n", info.kernel_phys.readable().c_str());
5051
printf("Kernel virtual: %s\n", info.kernel_virt.readable().c_str());
@@ -54,7 +55,8 @@ int main(int argc, char** argv, char** envp) {
5455
} else {
5556
printf("Total: %lu\n", info.usable.bytes);
5657
printf("Used: %lu (%.2f%%)\n", info.used.bytes, info.used_frac() * 100.0);
57-
printf("Available: %lu (%.2f%%)\n", info.free().bytes, info.free_frac() * 100.0);
58+
printf("Free: %lu (%.2f%%)\n", info.free().bytes, info.free_frac() * 100.0);
59+
printf("Available: %lu (%.2f%%)\n", info.available().bytes, info.available_frac() * 100.0);
5860
if(kernel_memory) {
5961
printf("Kernel physical: %lu\n", info.kernel_phys.bytes);
6062
printf("Kernel virtual: %lu\n", info.kernel_virt.bytes);

0 commit comments

Comments
 (0)