From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 43564 invoked by alias); 17 Aug 2018 14:05:15 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 43553 invoked by uid 89); 17 Aug 2018 14:05:14 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 spammy=1220, H*c:alternative, H*F:D*it X-HELO: mail-qt0-f178.google.com Received: from mail-qt0-f178.google.com (HELO mail-qt0-f178.google.com) (209.85.216.178) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 17 Aug 2018 14:05:12 +0000 Received: by mail-qt0-f178.google.com with SMTP id d4-v6so8802337qtn.13 for ; Fri, 17 Aug 2018 07:05:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bertacco-it.20150623.gappssmtp.com; s=20150623; h=mime-version:sender:from:date:message-id:subject:to; bh=TmBjjahBpl8UdMVSIjjxHLP+v/gQnijY6jU9fapIK3E=; b=axuKFUs4uBImMHTLwkcrVSBdBiWGvEOV06mgCITuEgsMT53Oe17xQlJB8/ixQK/f7X NWj7TzEHlmOeWVnF1q+xElk+Vr2NTGNWBFhjmfI7sCcvHQVtIA92n21AYekpIRlVjtnq 7MUMWN81DAT9B9bvlqZiLotJWi8W8wTwr3KtOl6XbiNjzRrTmNsvMS1ymO5mxIy/aT9n hGdU7OwhrnfZweMwbKpiYkRxGDtjKJyhiJv5kq83entM8pWOwoyZIoLhFxEERjwdsx4I utx+RwNLe4f1fjxdBhfiod4uQIvDkO5if36UVGEqw95DwEo51Nwj/Qvha/BuYiE22Fa5 xuJg== MIME-Version: 1.0 Sender: livio@bertacco.it Received: by 2002:a0c:be12:0:0:0:0:0 with HTTP; Fri, 17 Aug 2018 07:05:09 -0700 (PDT) From: Livio Bertacco Date: Fri, 17 Aug 2018 15:35:00 -0000 Message-ID: Subject: memory reported in /proc/pid/status is wrongly scaled To: cygwin@cygwin.com Content-Type: text/plain; charset="UTF-8" X-SW-Source: 2018-08/txt/msg00227.txt.bz2 Hi, While playing with reading process memory usage in Linux and cygwin, I found that cygwin reports too large values in /proc/self/status (in 2.10.0 and earlier). Whenever I was allocating a few kB in my test program, the VmSize line in /proc/self/status was growing several times faster. Small bash script to show the issue: #!/bin/bash pid=$$ vmsizesplit=($(grep VmSize /proc/$pid/status)) vmsize1="${vmsizesplit[1]}" echo Initial memory reported in status: $vmsize1 kB echo Allocating a 1000 kB string (bash can use more memory) eat=$(printf '%1024000s') vmsizesplit=($(grep VmSize /proc/$pid/status)) vmsize2="${vmsizesplit[1]}" echo Current memory reported in status: $vmsize2 kB echo Difference is $[$vmsize2-$vmsize1] kB Running this in cygwin on my laptop I get: Initial memory reported in status: 84928 kB Allocating a 1000 kB string (bash can use more memory) Current memory reported in status: 106880 kB Difference is 21952 kB While bash may use quite more than 1000 kb in this case, 22x times larger doesn't seem right. Checking source file fhandler_process.cc, the function format_process_status which writes the "status" proc file retrieves memory usage via get_mem_values. Get_mem_values obtains that info from NtQueryInformationProcess/PagefileUsage which is in bytes, then it scales it to pages dividing by wincap.page_size: 1515: *vmsize = vmc.PagefileUsage / wincap.page_size (); Then format_process_status scales it back, in theory to bytes, and shifts it by 10 bits in order to print it out in kB: 1219: unsigned page_size = wincap.allocation_granularity (); 1220: vmsize *= page_size; The first observation is that scaling and unscaling are using different factors, causing the issue. Same for the other memory amounts reported in the "status" file (VmLck, VmRSS, etc....). Memory reported in the "stat" file seems ok, and regarding the "statm" file, I'm not really sure (since I'm not sure about what the correct page size should be in cygwin). A second observation is that the same struct that contains PagefileUsage also contains PeakPagefileUsage, so it would be very easy to also add the VmPeak line to the "status" file (as in Linux). Regards, Livio -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple