From owner-freebsd-current@freebsd.org Mon Jul 10 13:51:50 2017 Return-Path: Delivered-To: freebsd-current@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A477FDA8D5D for ; Mon, 10 Jul 2017 13:51:50 +0000 (UTC) (envelope-from otacilio.neto@bsd.com.br) Received: from mail-qk0-x231.google.com (mail-qk0-x231.google.com [IPv6:2607:f8b0:400d:c09::231]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 6413365766 for ; Mon, 10 Jul 2017 13:51:49 +0000 (UTC) (envelope-from otacilio.neto@bsd.com.br) Received: by mail-qk0-x231.google.com with SMTP id 16so73834666qkg.2 for ; Mon, 10 Jul 2017 06:51:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsd.com.br; s=capeta; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=3LaFIACulUqP+Gk5+tayOIIBBadB6xL6S/vSBUV3wK0=; b=ckqZ0BF/J5+Gf+tyAmxFt0M4dONuzZ3SAy1wKudhYN20FEVGTCiE5UYjYUHgJh4LTS Ii35cw1hq37XPuuX5Oqwdk5bCksWQUH48kEFVwMYzQ7nLQGTqvuw/7spxYumBm6WWuOb ysWuDFBcJk977pDEwy0MMbKxJCm9upj5afgiY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=3LaFIACulUqP+Gk5+tayOIIBBadB6xL6S/vSBUV3wK0=; b=sZQOP4+rCAdjKyuUVHDv8LRaSISx5S6jWEAhVBfy/1bJ/dbEj5GxJ+IV+ToRs9EM1j JL8C6LEYDywdCuXq+AdN6JszvQrpjfNYFGSlxprhs+6VVuiK10uZQb8//Cd7fHHFVjHd igkqM5PUlX/qq8Y7Q6Mg3aM/iuLJXDp9mPDFNhvakFF3DcwCy2RKyV9ur+sIjYTeyXzF MIf92NX9l9bpb0ss2LmbCm+ubbJzg17MjY98JaS4CSD0eLfGj4TONertRfCvuS5UrrCX chjCHRFL8FLyZtiLwZYZu9y2VQUyfu+f3+Ra6PIV8qF10ltX5H+0ZW6QZawbV0TmFZac avag== X-Gm-Message-State: AIVw112MLNBYdDuq5P4pMhtLrcbZ7xCXYj2ILoJhcoyVEYZwV3/iTd1c fSB5yQFVfLQdYaSu+I0= X-Received: by 10.55.19.13 with SMTP id d13mr3927291qkh.214.1499694708593; Mon, 10 Jul 2017 06:51:48 -0700 (PDT) Received: from [10.51.223.89] ([177.20.152.129]) by smtp.googlemail.com with ESMTPSA id j17sm8772907qta.49.2017.07.10.06.51.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Jul 2017 06:51:47 -0700 (PDT) Subject: Re: type of vm.stats.vm.v_vnodepgsin vm.stats.vm.v_swappgsin, vm.stats.vm.v_vnodepgsout vm.stats.vm.v_swappgsout on AMD64 r320730 To: Konstantin Belousov , Tomoaki AOKI References: <1c37db96-7cd2-91c9-011c-967a32a97f05@bsd.com.br> <20170710154046.58c3d7b14a227a20bea3e55b@dec.sakura.ne.jp> <20170710071807.GO1935@kib.kiev.ua> <20170710184528.8677740bc55681e331c2fbea@dec.sakura.ne.jp> <20170710094922.GQ1935@kib.kiev.ua> Cc: freebsd-current@freebsd.org From: =?UTF-8?B?T3RhY8OtbGlv?= Message-ID: Date: Mon, 10 Jul 2017 10:51:43 -0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <20170710094922.GQ1935@kib.kiev.ua> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 10 Jul 2017 13:51:50 -0000 Em 10/07/2017 06:49, Konstantin Belousov escreveu: > On Mon, Jul 10, 2017 at 06:45:28PM +0900, Tomoaki AOKI wrote: >> Hm, for example, sysutils/lsof (userspace app) depends on kernel >> source, and I thought the one Otacilio mentioned is something like it. > lsof purpose is to dig into a kernel memory to gather information about > the process state and opened files. To do this, lsof authors have to use > internal kernel data structures. > > The library which is discussed in the thread uses public interfaces, > but then tries to pack the returned data into internal kernel structure. > If this is true, then the breakage is on the library side. Hello This following simple program behaves in the same manner that xosview. It shows corrects answers for pages_in and pages_out on FreeBSD 11 amd64 and FreeBSD10.3 i386. On FreeBSD 12 r320730 it shows the error answer that I related previously. If the lines pageinfo[0] = (uint64_t)vm.v_vnodepgsin + (uint64_t)vm.v_swappgsin; pageinfo[1] = (uint64_t)vm.v_vnodepgsout + (uint64_t)vm.v_swappgsout; are patched to pageinfo[0] = (uint32_t)((uint64_t)vm.v_vnodepgsin + (uint64_t)vm.v_swappgsin); pageinfo[1] = (uint32_t)((uint64_t)vm.v_vnodepgsout + (uint64_t)vm.v_swappgsout); The program works on all FreeBSD version. My doubt is why now this type cast (uint32_t) is necessary? []'s -Otacilio #include #include #include #define _WANT_VMMETER #include /* meminfo[5] = { active, inactive, wired, cached, free } */ /* pageinfo[2] = { pages_in, pages_out } */ void BSDGetPageStats(uint64_t *meminfo, uint64_t *pageinfo) { struct vmmeter vm; size_t size = sizeof(unsigned int); #define GET_VM_STATS(name) sysctlbyname("vm.stats.vm." #name, &vm.name, &size, NULL, 0) GET_VM_STATS(v_active_count); GET_VM_STATS(v_inactive_count); GET_VM_STATS(v_wire_count); GET_VM_STATS(v_free_count); GET_VM_STATS(v_page_size); GET_VM_STATS(v_vnodepgsin); GET_VM_STATS(v_vnodepgsout); GET_VM_STATS(v_swappgsin); GET_VM_STATS(v_swappgsout); if (meminfo) { meminfo[0] = (uint64_t)vm.v_active_count * vm.v_page_size; meminfo[1] = (uint64_t)vm.v_inactive_count * vm.v_page_size; meminfo[2] = (uint64_t)vm.v_wire_count * vm.v_page_size; meminfo[4] = (uint64_t)vm.v_free_count * vm.v_page_size; } if (pageinfo) { pageinfo[0] = (uint64_t)vm.v_vnodepgsin + (uint64_t)vm.v_swappgsin; pageinfo[1] = (uint64_t)vm.v_vnodepgsout + (uint64_t)vm.v_swappgsout; } } int main(int argc, char **argv){ uint64_t meminfo[5]; uint64_t pageinfo[2]; BSDGetPageStats(meminfo, pageinfo); printf("active memory = %lu bytes\n", meminfo[0]); printf("inactive memory = %lu bytes\n", meminfo[1]); printf("wired memory = %lu bytes\n", meminfo[2]); printf("cached memory = %lu bytes\n", meminfo[3]); printf("free memory = %lu bytes\n", meminfo[4]); printf("\npages_in = %lu bytes\n", pageinfo[0]); printf("pages_out = %lu bytes\n", pageinfo[1]); return 0; }