public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org>
To: cygwin-cvs@sourceware.org
Subject: [newlib-cygwin] Cygwin: get_mem_values: Return number of Cygwin pages in arguments
Date: Fri, 17 Aug 2018 18:34:00 -0000	[thread overview]
Message-ID: <20180817183438.113314.qmail@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=c2fa05899dba06eae0385c7223996d117020bc8c

commit c2fa05899dba06eae0385c7223996d117020bc8c
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Fri Aug 17 20:31:24 2018 +0200

    Cygwin: get_mem_values: Return number of Cygwin pages in arguments
    
    Simplify callers accordingly.
    
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 winsup/cygwin/fhandler_process.cc | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/winsup/cygwin/fhandler_process.cc b/winsup/cygwin/fhandler_process.cc
index 35bfbd4..03d9c32 100644
--- a/winsup/cygwin/fhandler_process.cc
+++ b/winsup/cygwin/fhandler_process.cc
@@ -1214,12 +1214,10 @@ format_process_status (void *data, char *&destbuf)
   if (!get_mem_values (p->dwProcessId, vmsize, vmrss, vmtext, vmdata,
 		       vmlib, vmshare))
     return 0;
-  size_t page_size = wincap.page_size ();
-  vmsize *= page_size; vmrss *= page_size; vmdata *= page_size;
-  vmtext *= page_size; vmlib *= page_size;
   /* The real uid value for *this* process is stored at cygheap->user.real_uid
      but we can't get at the real uid value for any other process, so
      just fake it as p->uid.  Similar for p->gid. */
+  size_t kb_per_page = wincap.allocation_granularity() / 1024;
   destbuf = (char *) crealloc_abort (destbuf, strlen (cmd) + 320);
   return __small_sprintf (destbuf, "Name:\t%s\n"
 				   "State:\t%c (%s)\n"
@@ -1245,8 +1243,9 @@ format_process_status (void *data, char *&destbuf)
 			  p->ppid,
 			  p->uid, p->uid, p->uid, p->uid,
 			  p->gid, p->gid, p->gid, p->gid,
-			  vmsize >> 10, 0, vmrss >> 10, vmdata >> 10, 0,
-			  vmtext >> 10, vmlib >> 10,
+			  vmsize * kb_per_page, 0UL, vmrss * kb_per_page,
+			  vmdata * kb_per_page, 0UL, vmtext * kb_per_page,
+			  vmlib * kb_per_page,
 			  0, 0, _my_tls.sigmask
 			  );
 }
@@ -1256,16 +1255,13 @@ format_process_statm (void *data, char *&destbuf)
 {
   _pinfo *p = (_pinfo *) data;
   size_t vmsize = 0, vmrss = 0, vmtext = 0, vmdata = 0, vmlib = 0, vmshare = 0;
-  size_t page_scale;
   if (!get_mem_values (p->dwProcessId, vmsize, vmrss, vmtext, vmdata,
 		       vmlib, vmshare))
     return 0;
 
-  page_scale = wincap.allocation_granularity() / wincap.page_size();
   destbuf = (char *) crealloc_abort (destbuf, 96);
   return __small_sprintf (destbuf, "%lu %lu %lu %lu %lu %lu 0\n",
-              vmsize / page_scale, vmrss / page_scale, vmshare / page_scale,
-              vmtext / page_scale, vmlib / page_scale, vmdata / page_scale);
+			  vmsize, vmrss, vmshare, vmtext, vmlib, vmdata);
 }
 
 extern "C" {
@@ -1446,6 +1442,8 @@ get_mem_values (DWORD dwProcessId, size_t &vmsize, unsigned long &vmrss,
   VM_COUNTERS vmc;
   PMEMORY_WORKING_SET_LIST p;
   SIZE_T n = 0x4000, length;
+  const size_t page_scale = wincap.allocation_granularity()
+			    / wincap.page_size();
 
   /* This appears to work despite MSDN claiming that QueryWorkingSet requires
      PROCESS_QUERY_INFORMATION *and* PROCESS_VM_READ.  Since we're trying to do
@@ -1510,6 +1508,14 @@ get_mem_values (DWORD dwProcessId, size_t &vmsize, unsigned long &vmrss,
       goto out;
     }
   vmsize = vmc.PagefileUsage / wincap.page_size ();
+  /* Return number of Cygwin pages.  Page size in Cygwin is equivalent
+     to Windows allocation_granularity. */
+  vmsize = howmany (vmsize, page_scale);
+  vmrss = howmany (vmrss, page_scale);
+  vmshare = howmany (vmshare, page_scale);
+  vmtext = howmany (vmtext, page_scale);
+  vmlib = howmany (vmlib, page_scale);
+  vmdata = howmany (vmdata, page_scale);
   res = true;
 out:
   free (p);


                 reply	other threads:[~2018-08-17 18:34 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180817183438.113314.qmail@sourceware.org \
    --to=corinna@sourceware.org \
    --cc=cygwin-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).