NetBSD Problem Report #56432

From www@netbsd.org  Sat Oct  2 03:28:40 2021
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 3042F1A9239
	for <gnats-bugs@gnats.NetBSD.org>; Sat,  2 Oct 2021 03:28:40 +0000 (UTC)
Message-Id: <20211002032838.DBE8C1A923A@mollari.NetBSD.org>
Date: Sat,  2 Oct 2021 03:28:38 +0000 (UTC)
From: schaecsn@gmx.net
Reply-To: schaecsn@gmx.net
To: gnats-bugs@NetBSD.org
Subject: sysutils/conky miscalculates mem requirements
X-Send-Pr-Version: www-1.0

>Number:         56432
>Category:       pkg
>Synopsis:       sysutils/conky miscalculates mem requirements
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    imil
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Oct 02 03:30:00 +0000 2021
>Last-Modified:  Sat Oct 02 12:30:28 +0000 2021
>Originator:     Stefan Schaeckeler
>Release:        pkgsrc-2021Q3
>Organization:
>Environment:
NetBSD xxx 9.2_STABLE NetBSD 9.2_STABLE (GENERIC) #2: Sat Sep 18 19:22:24 PDT 2021  root@xxx:/usr/obj/sys/arch/amd64/compile/GENERIC amd64
>Description:
I have 4 GB of memory

dmesg | grep memory
[     1.000000] total memory = 3963 MB
[     1.000000] avail memory = 3824 MB


That's what top shows at one point in time:

Memory: 1964M Act, 1144M Inact, 28M Wired, 49M Exec, 2974M File, 380M Free

For reasons unknown to me, we have active + file > 4 GB of memory. That's why these recently committed formulae to netbsd.c:update_meminfo() are not correct:

        info.mem = ((uvmexp.active + uvmexp.wired) * uvmexp.pagesize) / 1024;
        info.memmax = (uvmexp.npages * uvmexp.pagesize) / 1024;
        info.cached = ((uvmexp.filepages + uvmexp.execpages) * uvmexp.pagesize) / 1024;

        info.mem += info.cached;


They result in negative free memory:

memmax 3919468 | mem 5136828 | memfree -1217360 | cached 3095576
active 503126 | wired 7187 | filepages 761126 | execpages 12768 | pagesize 4096 | npages 979867


This negative memfree also shows up on conky's ~/.conkyrc $memfree. Basically, that's how I noticed this issue.
>How-To-Repeat:

Above log comes from adding to src/netbsd.c:update_meminfo() just before the return 0:

        printf("memmax %lld | mem %lld | memfree %lld | cached %lld\n", 
                   info.memmax, info.mem, info.memfree, info.cached );
        printf("active %ld | wired %ld | filepages %ld | execpages %ld | pagesize %ld | npages %ld\n", 
                   uvmexp.active, uvmexp.wired, uvmexp.filepages, uvmexp.execpages, uvmexp.pagesize, uvmexp.npages);


>Fix:

>Release-Note:

>Audit-Trail:

Responsible-Changed-From-To: pkg-manager->imil
Responsible-Changed-By: hauke@NetBSD.org
Responsible-Changed-When: Sat, 02 Oct 2021 12:30:28 +0000
Responsible-Changed-Why:
Over to maintainer.


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.46 2020/01/03 16:35:01 leot Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2020 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.