Bug 1459 - System.Diagnostics.Process.PrivateMemorySize64 rolls over as if it is returning a 32 bit int instead of 64 bit int
Summary: System.Diagnostics.Process.PrivateMemorySize64 rolls over as if it is returni...
Alias: None
Product: Runtime
Classification: Mono
Component: General ()
Version: unspecified
Hardware: Other Linux
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2011-10-12 14:10 UTC by David Evans
Modified: 2011-10-13 02:01 UTC (History)
3 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description David Evans 2011-10-12 14:10:51 UTC
System.Diagnostics.Process.PrivateMemorySize64 rolls over as if it is returning a 32 bit int instead of 64 bit int

Occurs when a mono 2.10.x process grows to be larger then 2 gigs of used memory. Used to work in Mono 2.6.4; problem was introduced since then.

Steps to reproduce:
1) Create a mono process that uses more then 2.2 gigs of memory
2) Call any System.Diagnostics.Process memory related methods

Observed Behavior: they return negative values when above 2 gigs
Expected Behavior: reporting values that match /proc/<pid>/status

When we upgraded from Mono 2.6.4 to 2.10.3 we noticed that the System.Diagnostics.Process memory related methods were returning negative values. Our app uses up to 20 gigs of memory sometimes. Tracked this down to a change in mono/utils/mono-proclib.c to move a 1024 multiplier for these values inside of a subroutine. But then the compiler does the multiplication within a 32 bit result of an "atoi" call (that converts the linux /proc/<pid>/status results from string to int). Our patch below resolved the issue, and involves making sure the compiler knows we want the multiplication to occur in a 64 bit value plus we switched from atoi to atol to future proof.

Patch to resolve the problem:
--- mono/utils/mono-proclib.c   2011-07-27 15:13:39.000000000 -0700
+++ /home/UNIXHOME/agottschalk/mono-proclib.c   2011-10-10 12:47:55.000004000 -0700
@@ -431,7 +431,7 @@

        s = get_pid_status_item_buf (pid, item, buf, sizeof (buf), error);
        if (s)
-               return atoi (s) * multiplier;
+               return ((gint64) atol (s)) * multiplier;
        return 0;
Comment 1 Zoltan Varga 2011-10-13 02:01:38 UTC
Applied to HEAD/mono-2-10 branch. Thanks for the patch.