Skip to content

region memory limit#48691

Merged
Maoni0 merged 1 commit intodotnet:masterfrom
Maoni0:regions_mem_limit
Feb 26, 2021
Merged

region memory limit#48691
Maoni0 merged 1 commit intodotnet:masterfrom
Maoni0:regions_mem_limit

Conversation

@Maoni0
Copy link
Member

@Maoni0 Maoni0 commented Feb 24, 2021

  • implemented the logic to handle when we are really running out of memory.
    We need to be resilient to it during a GC. We might need an empty region
    per heap so we try to get it up front and if we can't get it and find out
    that we do need it, we resort to a special sweep mode.
  • also take virtual memory load into consideration
  • fixed the logic to decide whether we should compact based on space.
  • fixed various places when we can't get a region, we need to make sure we
    don't thread 0 into the region list.
  • made allocated_since_last_gc per more_space_lock otherwise we are not doing
    the accounting correctly
  • moved the pinning for STRESS_REGIONS into a blocking GC otherwise we can have
    AV from BGC trying to mark the pinned object while it's being constructed
  • got rid of the places that use the hard coded REGION_SIZE
  • included one perf change in reset_memory

@ghost ghost added the area-GC-coreclr label Feb 24, 2021
@ghost
Copy link

ghost commented Feb 24, 2021

Tagging subscribers to this area: @dotnet/gc
See info in area-owners.md if you want to be subscribed.

Issue Details
  • implemented the logic to handle when we are really running out of memory.
    We need to be resilient to it during a GC. We might need an empty region
    per heap so we try to get it up front and if we can't get it and find out
    that we do need it, we resort to a special sweep mode.
  • also take virtual memory load into consideration
  • fixed the logic to decide whether we should compact based on space.
  • fixed various places when we can't get a region, we need to make sure we
    don't thread 0 into the region list.
  • made allocated_since_last_gc per more_space_lock otherwise we are not doing
    the accounting correctly
  • moved the pinning for STRESS_REGIONS into a blocking GC otherwise we can have
    AV from BGC trying to mark the pinned object while it's being constructed
  • got rid of the places that use the hard coded REGION_SIZE
  • included one perf change in reset_memory
Author: Maoni0
Assignees: -
Labels:

area-GC-coreclr

Milestone: -

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this just be < ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, will change it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the dprintf level be REGIONS_LOG here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will change all of the dprintf's in region_allocator to REGIONS_LOG.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use dprintf level REGIONS_LOG here as well?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about the case where init_table_for_region fails because the mark array cannot be committed? It seems that we would return true in this case, but likely still fail when we later try to get the region.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch! I did check for this (I set region to 0 in init_table_for_region when we can't commit) but I made a mistake when I refactored it out to its own method. should have init_table_for_region return false if we can't commit.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this AV if commit_mark_array_new_seg failed above?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it wouldn't - right now the GC bookkeeping datastructure is completely committed for the region's range except for the mark array part.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but above, you set region to 0, so as heap_segment_mem dereferences it, you would AV before you even get to the brick_of part.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh I misunderstood your intention for the question...absolutely, I shouldn't call this when the region is already set to 0

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

@Maoni0
Copy link
Member Author

Maoni0 commented Feb 25, 2021

I found a problem with aging handles for the special sweep case. will fix it later today.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this could be a local variable instead of a field.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I specifically wanted this to be a global so it introduces some variation instead of always pinning the 1st, 3rd, etc gen0 region. but I changed it to size_t instead of int.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be helpful to put a comment, e.g. "Pin one object at the beginning".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto: "Pin one object near the middle".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why we need a new free region here - could you explain?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's to prepare for possibly needing to get a new region for gen0 in the later phases.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In your comments for the PR, you said in this case we will do a special kind of sweep. The dprintf says we do a full compacting GC. Is there a contradiction, or what am I missing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's the "and find out that we do need it," part - we try to get a new region here just to prepare for if we need it, as long as we don't actually need it, we will be doing a full compacting GC. but if we can't get it here and later find that we actually need it that's when we absolute run out of memory and we only do the special sweep then.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, thanks!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you put a comment why this should be true?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be good to put a comment explaining how the special sweep mode works, i.e. what's special about it.

+ implemented the logic to handle when we are really running out of memory.
  We need to be resilient to it during a GC. We might need an empty region
  per heap so we try to get it up front and if we can't get it and find out
  that we do need it, we resort to a special sweep mode.
+ also take virtual memory load into consideration
+ fixed the logic to decide whether we should compact based on space.
+ fixed various places when we can't get a region, we need to make sure we
  don't thread 0 into the region list.
+ made allocated_since_last_gc per more_space_lock otherwise we are not doing
  the accounting correctly
+ moved the pinning for STRESS_REGIONS into a blocking GC otherwise we can have
  AV from BGC trying to mark the pinned object while it's being constructed
+ got rid of the places that use the hard coded REGION_SIZE
+ included one perf change in reset_memory
@Maoni0 Maoni0 merged commit c41894d into dotnet:master Feb 26, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Mar 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants