Index | Thread | Search

From:
Kristaps Dzonsons <kristaps@bsd.lv>
Subject:
Patch: kf6/kcoreaddons
To:
"ports@openbsd.org" <ports@openbsd.org>
Date:
Sat, 1 Nov 2025 12:01:03 -0700

Download raw body.

Thread
Hi, enclosed is a source patch that provides the available physical 
memory (previously listed as a TODO) and refactors the total physical 
memory to qt6's core addons.  It should be added to the "patches" 
directory to enable.

This is because the available physical memory is used by digikam when 
deciding how to export "large" (not by today's standards, but whatever) 
photos with resizing.  Without this patch, digikam would fail to export.

I haven't tested this elsewhere, however: digikam is the only qt6 
application that I use.

Best,

Kristaps
Index: src/lib/util/kmemoryinfo.cpp
--- src/lib/util/kmemoryinfo.cpp.orig
+++ src/lib/util/kmemoryinfo.cpp
@@ -467,14 +467,23 @@ static int swap_usage(int *used, int *total)
 
 bool KMemoryInfo::update()
 {
-    // TODO: compute m_availablePhysical on OpenBSD
+    int64_t memSize = 0;
+    size_t sz = 0;
 
-    // tota phsycial memory
-    const long phys_pages = sysconf(_SC_PHYS_PAGES);
-    const long pagesize = sysconf(_SC_PAGESIZE);
-    if (phys_pages != -1 && pagesize != -1)
-        d->m_totalPhysical = ((uint64_t)phys_pages * (uint64_t)pagesize / 1024);
+    int usermem_mib[] = {CTL_HW, HW_USERMEM64};
+    sz = sizeof(memSize);
+    if (sysctl(usermem_mib, 2, &memSize, &sz, NULL, 0) != 0) {
+        return false;
+    }
+    d->m_availablePhysical = memSize;
 
+    int physmem_mib[] = {CTL_HW, HW_PHYSMEM64};
+    sz = sizeof(memSize);
+    if (sysctl(physmem_mib, 2, &memSize, &sz, NULL, 0) != 0) {
+        return false;
+    }
+    d->m_totalPhysical = memSize;
+
     int swap_free = 0;
     int swap_tot = 0;
     if (swap_usage(&swap_free, &swap_tot)) {
@@ -484,17 +493,18 @@ bool KMemoryInfo::update()
 
     int uvmexp_mib[] = {CTL_VM, VM_UVMEXP};
     struct uvmexp uvmexp;
-    size_t size = sizeof(uvmexp);
-    if (sysctl(uvmexp_mib, 2, &uvmexp, &size, NULL, 0) == -1) {
+    sz = sizeof(uvmexp);
+    if (sysctl(uvmexp_mib, 2, &uvmexp, &sz, NULL, 0) == -1) {
         bzero(&uvmexp, sizeof(uvmexp));
         return false;
     }
+    const long pagesize = sysconf(_SC_PAGESIZE);
     d->m_freePhysical = uvmexp.free * pagesize / 1024;
 
     int bcstats_mib[] = {CTL_VFS, VFS_GENERIC, VFS_BCACHESTAT};
     struct bcachestats bcstats;
-    size = sizeof(bcstats);
-    if (sysctl(bcstats_mib, 3, &bcstats, &size, NULL, 0) == -1) {
+    sz = sizeof(bcstats);
+    if (sysctl(bcstats_mib, 3, &bcstats, &sz, NULL, 0) == -1) {
         bzero(&bcstats, sizeof(bcstats));
         return false;
     }