kernel, libroot: Add more memory info in system_info

system_info now contains all information previously available only
through __get_system_info_etc(B_MEMORY_INFO, ...).
This commit is contained in:
Pawel Dziepak
2013-12-16 04:53:46 +01:00
parent 1bc7045fdf
commit d02aaee17e
15 changed files with 55 additions and 106 deletions
+4 -3
View File
@@ -433,14 +433,15 @@ typedef struct {
uint64 max_pages; /* total # of accessible pages */
uint64 used_pages; /* # of accessible pages in use */
uint64 free_pages;
uint64 reserved_pages;
uint64 cached_pages;
uint64 block_cache_pages;
uint64 ignored_pages; /* # of ignored/inaccessible pages */
uint64 needed_memory;
uint64 free_memory;
uint64 max_swap_pages;
uint64 used_swap_pages;
uint64 free_swap_pages;
uint32 page_faults; /* # of page faults */
+1 -1
View File
@@ -142,7 +142,7 @@ status_t vm_get_physical_page_debug(phys_addr_t paddr, addr_t* vaddr,
void** _handle);
status_t vm_put_physical_page_debug(addr_t vaddr, void* handle);
void vm_get_info(struct system_memory_info *info);
void vm_get_info(system_info *info);
uint32 vm_num_page_faults(void);
off_t vm_available_memory(void);
off_t vm_available_not_needed_memory(void);
-2
View File
@@ -521,8 +521,6 @@ extern status_t _kern_get_cpu_topology_info(
cpu_topology_node_info* topologyInfos,
uint32* topologyInfoCount);
extern status_t _kern_get_system_info_etc(int32 id, void *buffer,
size_t bufferSize);
extern status_t _kern_analyze_scheduling(bigtime_t from, bigtime_t until,
void* buffer, size_t size,
struct scheduling_analysis* analysis);
-16
View File
@@ -9,21 +9,6 @@
#include <OS.h>
#define B_MEMORY_INFO 'memo'
struct system_memory_info {
uint64 max_memory;
uint64 free_memory;
uint64 needed_memory;
uint64 max_swap_space;
uint64 free_swap_space;
uint64 block_cache_memory;
uint32 page_faults;
// TODO: add active/inactive page counts, swap in/out, ...
};
enum {
// team creation or deletion; object == -1; either one also triggers on
// exec()
@@ -67,7 +52,6 @@ status_t __get_system_info(system_info* info);
status_t __get_cpu_info(uint32 firstCPU, uint32 cpuCount, cpu_info* info);
status_t __get_cpu_topology_info(cpu_topology_node_info* topologyInfos,
uint32* topologyInfoCount);
status_t __get_system_info_etc(int32 id, void* buffer, size_t bufferSize);
status_t __start_watching_system(int32 object, uint32 flags, port_id port,
int32 token);
+1 -7
View File
@@ -497,13 +497,7 @@ BlockCacheDataSource::Copy() const
int64
BlockCacheDataSource::NextValue(SystemInfo& info)
{
system_memory_info memoryInfo;
status_t status = __get_system_info_etc(B_MEMORY_INFO, &memoryInfo,
sizeof(system_memory_info));
if (status != B_OK)
return 0;
return memoryInfo.block_cache_memory;
return info.BlockCacheMemory();
}
+14 -8
View File
@@ -26,8 +26,6 @@ SystemInfo::SystemInfo(SystemInfoHandler* handler)
get_system_info(&fSystemInfo);
fCPUInfos = new cpu_info[fSystemInfo.cpu_count];
get_cpu_info(0, fSystemInfo.cpu_count, fCPUInfos);
__get_system_info_etc(B_MEMORY_INFO, &fMemoryInfo,
sizeof(system_memory_info));
if (handler != NULL) {
fRunningApps = handler->RunningApps();
@@ -50,45 +48,53 @@ uint64
SystemInfo::CachedMemory() const
{
#ifdef __HAIKU__
return (uint64)fSystemInfo.cached_pages * B_PAGE_SIZE;
return fSystemInfo.cached_pages * B_PAGE_SIZE;
#else
return 0LL;
#endif
}
uint64
SystemInfo::BlockCacheMemory() const
{
return fSystemInfo.block_cache_pages * B_PAGE_SIZE;
}
uint64
SystemInfo::UsedMemory() const
{
return (uint64)fSystemInfo.used_pages * B_PAGE_SIZE;
return fSystemInfo.used_pages * B_PAGE_SIZE;
}
uint64
SystemInfo::MaxMemory() const
{
return (uint64)fSystemInfo.max_pages * B_PAGE_SIZE;
return fSystemInfo.max_pages * B_PAGE_SIZE;
}
uint32
SystemInfo::PageFaults() const
{
return fMemoryInfo.page_faults;
return fSystemInfo.page_faults;
}
uint64
SystemInfo::UsedSwapSpace() const
{
return fMemoryInfo.max_swap_space - fMemoryInfo.free_swap_space;
return (fSystemInfo.max_swap_pages - fSystemInfo.free_swap_pages)
* B_PAGE_SIZE;
}
uint64
SystemInfo::MaxSwapSpace() const
{
return fMemoryInfo.max_swap_space;
return fSystemInfo.max_swap_pages * B_PAGE_SIZE;
}
+1 -1
View File
@@ -20,6 +20,7 @@ public:
~SystemInfo();
uint64 CachedMemory() const;
uint64 BlockCacheMemory() const;
uint64 UsedMemory() const;
uint64 MaxMemory() const;
@@ -64,7 +65,6 @@ private:
system_info fSystemInfo;
cpu_info* fCPUInfos;
system_memory_info fMemoryInfo;
bigtime_t fTime;
bool fRetrievedNetwork;
uint64 fBytesReceived;
+21 -17
View File
@@ -66,40 +66,44 @@ main(int argc, char** argv)
break;
}
}
system_memory_info info;
status_t status = __get_system_info_etc(B_MEMORY_INFO, &info,
sizeof(system_memory_info));
system_info info;
status_t status = get_system_info(&info);
if (status != B_OK) {
fprintf(stderr, "%s: cannot get system info: %s\n", kProgramName,
strerror(status));
return 1;
}
printf("max memory:\t\t%Lu\n", info.max_memory);
printf("max memory:\t\t%Lu\n", info.max_pages * B_PAGE_SIZE);
printf("free memory:\t\t%Lu\n", info.free_memory);
printf("needed memory:\t\t%Lu\n", info.needed_memory);
printf("block cache memory:\t%Lu\n", info.block_cache_memory);
printf("max swap space:\t\t%Lu\n", info.max_swap_space);
printf("free swap space:\t%Lu\n", info.free_swap_space);
printf("block cache memory:\t%Lu\n", info.block_cache_pages * B_PAGE_SIZE);
printf("max swap space:\t\t%Lu\n", info.max_swap_pages * B_PAGE_SIZE);
printf("free swap space:\t%Lu\n", info.free_swap_pages * B_PAGE_SIZE);
printf("page faults:\t\t%lu\n", info.page_faults);
if (periodically) {
puts("\npage faults used memory used swap block cache");
system_memory_info lastInfo = info;
system_info lastInfo = info;
while (true) {
snooze(rate);
__get_system_info_etc(B_MEMORY_INFO, &info,
sizeof(system_memory_info));
get_system_info(&info);
printf("%11ld %11Ld %11Ld %11Ld\n",
(int32)info.page_faults - lastInfo.page_faults,
(info.max_memory - info.free_memory)
- (lastInfo.max_memory - lastInfo.free_memory),
(info.max_swap_space - info.free_swap_space)
- (lastInfo.max_swap_space - lastInfo.free_swap_space),
info.block_cache_memory - lastInfo.block_cache_memory);
int32 pageFaults = info.page_faults - lastInfo.page_faults;
int64 usedMemory
= (info.max_pages * B_PAGE_SIZE - info.free_memory)
- (lastInfo.max_pages * B_PAGE_SIZE - lastInfo.free_memory);
int64 usedSwap
= ((info.max_swap_pages - info.free_swap_pages)
- (lastInfo.max_swap_pages - lastInfo.free_swap_pages))
* B_PAGE_SIZE;
int64 blockCache
= (info.block_cache_pages - lastInfo.block_cache_pages)
* B_PAGE_SIZE;
printf("%11" B_PRId32 " %11" B_PRId64 " %11" B_PRId64 " %11"
B_PRId64 "\n", pageFaults, usedMemory, usedSwap, blockCache);
lastInfo = info;
}
@@ -476,11 +476,12 @@ SettingsWindow::_Update()
void
SettingsWindow::_UpdateSwapInfo()
{
system_memory_info memInfo = {};
__get_system_info_etc(B_MEMORY_INFO, &memInfo, sizeof(memInfo));
system_info info;
get_system_info(&info);
off_t currentSwapSize = memInfo.max_swap_space;
off_t currentSwapUsed = (memInfo.max_swap_space - memInfo.free_swap_space);
off_t currentSwapSize = info.max_swap_pages * B_PAGE_SIZE;
off_t currentSwapUsed
= (info.max_swap_pages - info.free_swap_pages) * B_PAGE_SIZE;
char sizeStr[16];
BString swapSizeStr = string_for_size(currentSwapSize, sizeStr,
+1 -28
View File
@@ -418,6 +418,7 @@ get_system_info(system_info* info)
info->cpu_count = smp_get_num_cpus();
vm_page_get_stats(info);
vm_get_info(info);
info->used_threads = thread_used_threads();
info->max_threads = thread_max_threads();
@@ -428,8 +429,6 @@ get_system_info(system_info* info)
info->used_sems = sem_used_sems();
info->max_sems = sem_max_sems();
// TODO: fill the new fields
info->kernel_version = kKernelVersion;
strlcpy(info->kernel_name, kKernelName, B_FILE_NAME_LENGTH);
strlcpy(info->kernel_build_date, __DATE__, B_OS_NAME_LENGTH);
@@ -625,32 +624,6 @@ _user_get_cpu_topology_info(cpu_topology_node_info* topologyInfos,
}
status_t
_user_get_system_info_etc(int32 id, void* userInfo, size_t size)
{
if (userInfo == NULL || !IS_USER_ADDRESS(userInfo))
return B_BAD_ADDRESS;
switch (id) {
case B_MEMORY_INFO:
{
if (size < sizeof(system_memory_info))
return B_BAD_VALUE;
system_memory_info info;
vm_get_info(&info);
info.block_cache_memory = block_cache_used_memory();
return user_memcpy(userInfo, &info, sizeof(system_memory_info));
}
default:
return B_BAD_VALUE;
}
}
status_t
_user_start_watching_system(int32 object, uint32 flags, port_id port,
int32 token)
+3 -3
View File
@@ -1667,11 +1667,11 @@ swap_total_swap_pages()
void
swap_get_info(struct system_memory_info* info)
swap_get_info(system_info* info)
{
#if ENABLE_SWAP_SUPPORT
info->max_swap_space = (uint64)swap_total_swap_pages() * B_PAGE_SIZE;
info->free_swap_space = (uint64)swap_available_pages() * B_PAGE_SIZE;
info->max_swap_pages = swap_total_swap_pages();
info->free_swap_pages = swap_available_pages();
#else
info->max_swap_space = 0;
info->free_swap_space = 0;
+1 -1
View File
@@ -99,7 +99,7 @@ private:
#endif // ENABLE_SWAP_SUPPORT
extern "C" void swap_get_info(struct system_memory_info* info);
extern "C" void swap_get_info(system_info* info);
#endif /* _KERNEL_VM_STORE_ANONYMOUS_H */
+2 -5
View File
@@ -4628,16 +4628,13 @@ vm_put_physical_page_debug(addr_t vaddr, void* handle)
void
vm_get_info(system_memory_info* info)
vm_get_info(system_info* info)
{
swap_get_info(info);
info->max_memory = vm_page_num_pages() * B_PAGE_SIZE;
info->page_faults = sPageFaults;
MutexLocker locker(sAvailableMemoryLock);
info->free_memory = sAvailableMemory;
info->needed_memory = sNeededMemory;
info->free_memory = sAvailableMemory;
}
+1
View File
@@ -4059,6 +4059,7 @@ vm_page_get_stats(system_info *info)
// TODO: We should subtract the blocks that are in use ATM, since those
// can't really be freed in a low memory situation.
page_num_t blockCachePages = block_cache_used_memory() / B_PAGE_SIZE;
info->block_cache_pages = blockCachePages;
// Non-temporary modified pages are special as they represent pages that
// can be written back, so they could be freed if necessary, for us
-10
View File
@@ -198,16 +198,6 @@ __get_cpu_topology_info(cpu_topology_node_info* topologyInfos,
}
status_t
__get_system_info_etc(int32 id, void *info, size_t size)
{
if (info == NULL || size == 0 || id < 0)
return B_BAD_VALUE;
return _kern_get_system_info_etc(id, info, size);
}
status_t
__start_watching_system(int32 object, uint32 flags, port_id port, int32 token)
{