ProcessController: Report kernel memory and fix some TODOs.

* Restore logic for excluding app_server side of bitmaps
   (though this may not work for server-cloned areas, only
   server-allocated ones.)

 * Leave TODO in place for media buffers.

 * Add all kernel-writable areas of the system (kernel) team
   to writable memory, but exclude the block_cache.

Fixes display of kernel memory information in ProcessController's
memory usage menu.
This commit is contained in:
Augustin Cavalier
2025-03-10 22:35:55 -04:00
parent e2ffc7fd31
commit 992f1401b2
@@ -3,6 +3,7 @@
* Copyright 2022, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#include "MemoryBarMenuItem.h"
#include "Colors.h"
@@ -11,6 +12,7 @@
#include <Bitmap.h>
#include <ControlLook.h>
#include <KernelExport.h>
#include <StringForSize.h>
#include <stdio.h>
@@ -216,27 +218,44 @@ MemoryBarMenuItem::BarUpdate()
int64 lwram_size = 0;
bool exists = false;
const bool isAppServer = (strcmp(Label(), "app_server") == 0);
while (get_next_area_info(fTeamID, &cookie, &areaInfo) == B_OK) {
exists = true;
lram_size += areaInfo.ram_size;
// TODO: this won't work this way anymore under Haiku!
// int zone = (int (areaInfo.address) & 0xf0000000) >> 24;
if (isAppServer && strncmp(areaInfo.name, "a:", 2) == 0) {
// app_server side of client memory (e.g. bitmaps), ignore.
continue;
}
if (fTeamID == B_SYSTEM_TEAM) {
if ((areaInfo.protection & B_KERNEL_WRITE_AREA) != 0)
areaInfo.protection |= B_WRITE_AREA;
}
// TODO: Exclude media buffers
if ((areaInfo.protection & B_WRITE_AREA) != 0)
lwram_size += areaInfo.ram_size;
// && (zone & 0xf0) != 0xA0 // Exclude media buffers
// && (fTeamID != gAppServerTeamID || zone != 0x90)) // Exclude app_server side of bitmaps
}
if (!exists) {
if (fTeamID == B_SYSTEM_TEAM) {
system_info info;
status_t status = get_system_info(&info);
if (status == B_OK) {
// block_cache memory will be in writable areas
lwram_size -= info.block_cache_pages * B_PAGE_SIZE;
}
} else if (!exists) {
team_info info;
exists = get_team_info(fTeamID, &info) == B_OK;
if (!exists) {
fWriteMemory = -1;
return;
}
}
if (exists) {
fWriteMemory = lwram_size / 1024;
fAllMemory = lram_size / 1024;
DrawBar(false);
} else
fWriteMemory = -1;
fWriteMemory = lwram_size / 1024;
fAllMemory = lram_size / 1024;
DrawBar(false);
}