Download raw body.
Patch: kf6/kcoreaddons
On 2025/11/01 12:01, Kristaps Dzonsons wrote:
> 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
gah, this is the _third_ port I have seen this weekend that cares about
available memory, which is not a useful metric on a multiprocessing
system that runs other stuff...
while that diff might be useful for a cosmetic improvement for anything
displaying memory, for the digikam problem, wouldn't it make more sense
to kill that "if (fullSize > (qint64)(100 * 1024 * 1024))" block in
DImgLoader::checkAllocation() (core/libs/dimg/loaders/dimgloader.cpp)
which I guess is what you're running into?
> 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;
> }
Patch: kf6/kcoreaddons