Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mono] Fix sgen_gc_info.memory_load_bytes #53364

Merged
merged 3 commits into from
May 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/mono/mono/sgen/sgen-memory-governor.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ update_gc_info (mword used_slots_size)

sgen_gc_info.heap_size_bytes = major_size + sgen_los_memory_usage_total;
sgen_gc_info.fragmented_bytes = sgen_gc_info.heap_size_bytes - sgen_los_memory_usage - major_size_in_use;
sgen_gc_info.memory_load_bytes = mono_determine_physical_ram_available_size ();
guint64 physical_ram_size = mono_determine_physical_ram_size ();
sgen_gc_info.memory_load_bytes = physical_ram_size ? sgen_gc_info.total_available_memory_bytes - (guint64)(((double)sgen_gc_info.total_available_memory_bytes*mono_determine_physical_ram_available_size ())/physical_ram_size) : 0;
sgen_gc_info.total_committed_bytes = major_size_in_use + sgen_los_memory_usage;
sgen_gc_info.total_promoted_bytes = sgen_total_promoted_size - total_promoted_size_start;
sgen_gc_info.total_major_size_bytes = major_size;
Expand Down
32 changes: 17 additions & 15 deletions src/mono/mono/utils/memfuncs.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ mono_gc_memmove_atomic (void *dest, const void *src, size_t size)
mono_gc_memmove_aligned (dest, src, size);
}

#define _DEFAULT_MEM_SIZE 134217728

guint64
mono_determine_physical_ram_size (void)
{
Expand Down Expand Up @@ -267,30 +269,30 @@ mono_determine_physical_ram_size (void)

sysctl (mib, 2, &value, &size_sys, NULL, 0);
if (value == 0)
return 134217728;
return _DEFAULT_MEM_SIZE;

return (guint64)value;
#elif defined (HAVE_SYSCONF)
guint64 page_size = 0, num_pages = 0;
gint64 page_size = -1, num_pages = -1;

/* sysconf works on most *NIX operating systems, if your system doesn't have it or if it
* reports invalid values, please add your OS specific code below. */
#ifdef _SC_PAGESIZE
page_size = (guint64)sysconf (_SC_PAGESIZE);
page_size = (gint64)sysconf (_SC_PAGESIZE);
#endif

#ifdef _SC_PHYS_PAGES
num_pages = (guint64)sysconf (_SC_PHYS_PAGES);
num_pages = (gint64)sysconf (_SC_PHYS_PAGES);
#endif

if (!page_size || !num_pages) {
if (page_size == -1 || num_pages == -1) {
g_warning ("Your operating system's sysconf (3) function doesn't correctly report physical memory size!");
return 134217728;
return _DEFAULT_MEM_SIZE;
}

return page_size * num_pages;
return (guint64)page_size * (guint64)num_pages;
#else
return 134217728;
return _DEFAULT_MEM_SIZE;
#endif
}

Expand Down Expand Up @@ -342,25 +344,25 @@ mono_determine_physical_ram_available_size (void)
return (guint64) vmstat.free_count * page_size;

#elif defined (HAVE_SYSCONF)
guint64 page_size = 0, num_pages = 0;
gint64 page_size = -1, num_pages = -1;

/* sysconf works on most *NIX operating systems, if your system doesn't have it or if it
* reports invalid values, please add your OS specific code below. */
#ifdef _SC_PAGESIZE
page_size = (guint64)sysconf (_SC_PAGESIZE);
page_size = (gint64)sysconf (_SC_PAGESIZE);
#endif

#ifdef _SC_AVPHYS_PAGES
num_pages = (guint64)sysconf (_SC_AVPHYS_PAGES);
num_pages = (gint64)sysconf (_SC_AVPHYS_PAGES);
#endif

if (!page_size || !num_pages) {
if (page_size == -1 || num_pages == -1) {
g_warning ("Your operating system's sysconf (3) function doesn't correctly report physical memory size!");
return 0;
return _DEFAULT_MEM_SIZE;
}

return page_size * num_pages;
return (guint64)page_size * (guint64)num_pages;
#else
return 0;
return _DEFAULT_MEM_SIZE;
#endif
}