Skip to content

Conversation

Cellule
Copy link
Contributor

@Cellule Cellule commented Aug 2, 2017

Make reporting external memory allocation cleaner with a wrapper and ensure we don't end up in a bad state after ReAlloc


This change is Reviewable

if (!RequestExternalMemoryAllocation(size))
{
// Attempt to free some memory then try again
CollectNow<CollectOnTypedArrayAllocation>();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right now CollectOnTypedArrayAllocation is the only case we would use this allocation method. Should I make it generic anyway ?


AutoDiscardPTR<Js::ArrayBufferDetachedStateBase> state(DetachAndGetState());
state->MarkAsClaimed();
// Detach the buffer from this ArrayBuffer
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Getting the state with DetachAndGetState then immediately calling state->MarkAsClaimed() was effectively only detaching the buffer.
So calling a version that detach, but doesn't create a state reduces overhead and increases readability

@Cellule Cellule self-assigned this Aug 2, 2017
@Cellule Cellule added this to the 1.6 milestone Aug 2, 2017
@Cellule Cellule force-pushed the users/micfer/wasm/grow_memory branch from 50acfef to 5156c9b Compare August 2, 2017 19:31
virtual BOOL GetDiagValueString(StringBuilder<ArenaAllocator>* stringBuilder, ScriptContext* requestContext) override;

virtual ArrayBufferDetachedStateBase* DetachAndGetState();
void Detach();
Copy link
Contributor

@akroshg akroshg Aug 2, 2017

Choose a reason for hiding this comment

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

make it private member function as I don't see it is called externally. #Closed

Copy link
Contributor

Choose a reason for hiding this comment

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

or protected.


In reply to: 130999054 [](ancestors = 130999054)

struct AutoFailFastOnBadState
{
bool isStateValid = true;
~AutoFailFastOnBadState()
Copy link
Contributor

Choose a reason for hiding this comment

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

QueryContinue can throw javascript exception. In that case we fail fast?
Check AutoDisableInterrupt in threadcontext.h, which is suited for this need.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure I understand your point. What is the link between QueryContinue and WebAssembly.GrowMemory ?
After we've called ReAlloc, this->buffer is freed. Which means, any kind of exception before we detach the buffer will leave us in a bad state and there isn't much we can do to recover at that point.
This should be a very rare scenario, most of the time in very intense memory usage and thus it makes sense to failfast.

Copy link
Contributor

Choose a reason for hiding this comment

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

QueryContinue is the service called from the host to interrupt on memory allocation. Upon querycontinue the interrupt service will determine if we have crossed the time-threshold. When that happens E_Abort exception will thrown. If you want to exclude the QueryContinue from the list of bad things could happen you need to disable that, otherwise it is fine.


In reply to: 131007291 [](ancestors = 131007291)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, so you mean, in order to minimize the kind of things that can throw here, I should use AutoDisableInterrupt when it becomes a bad state so it won't failfast.
Do I get this right ?

@Cellule
Copy link
Contributor Author

Cellule commented Aug 3, 2017

@akroshg can you take a look on my review fixes ?

ReportDifferentialAllocation(newBufferLength, reportFailedFn);
if (failedReport)
// Disable QC while doing a ReAlloc to minimize chances to end up in a bad state
AutoDisableInterrupt autoDisableInterrupt(this->GetScriptContext()->GetThreadContext()->GetInterruptPoller(), true);
Copy link
Contributor

Choose a reason for hiding this comment

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

true [](start = 122, length = 4)

I think you need to pass false here - as you don't want explicit completion. True here means that you are going to call the autoDisableInterrupt.Completed() in this block.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The true means that I want to disable Interrupt polling

AutoDisableInterrupt(InterruptPoller* interruptPoller, bool disable)
        : interruptPoller(interruptPoller)
    {
        if (interruptPoller != nullptr)
        {
            previousState = interruptPoller->IsDisabled();
            interruptPoller->SetDisabled(disable);
        }
    }

@Cellule Cellule force-pushed the users/micfer/wasm/grow_memory branch from 7028755 to 49a6269 Compare August 4, 2017 01:21
@Cellule
Copy link
Contributor Author

Cellule commented Aug 4, 2017

I have reworked WebAssemblyArrayBuffer::GrowMemory a lot, so I decided to just squash my changes + rebase on top of #3479.
@tcare Could you take a look at how I use AutoDisableInterrupt as well

@Cellule Cellule requested a review from tcare August 4, 2017 01:23
}
}

void RequireExplicitCompletion() { m_explicitCompletion = true; }
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: SetRequireExplicitCompletion

@tcare
Copy link
Contributor

tcare commented Aug 4, 2017

Interrupt use LGTM

@akroshg
Copy link
Contributor

akroshg commented Aug 4, 2017

:shipit:

@chakrabot chakrabot merged commit 49a6269 into chakra-core:release/1.6 Aug 9, 2017
chakrabot pushed a commit that referenced this pull request Aug 9, 2017
Merge pull request #3468 from Cellule:users/micfer/wasm/grow_memory

Make reporting external memory allocation cleaner with a wrapper and ensure we don't end up in a bad state after ReAlloc
@Cellule Cellule deleted the users/micfer/wasm/grow_memory branch August 10, 2017 00:14
chakrabot pushed a commit that referenced this pull request Aug 10, 2017
…owMemory

Merge pull request #3468 from Cellule:users/micfer/wasm/grow_memory

Make reporting external memory allocation cleaner with a wrapper and ensure we don't end up in a bad state after ReAlloc
chakrabot pushed a commit that referenced this pull request Aug 10, 2017
…rrayBuffer.GrowMemory

Merge pull request #3468 from Cellule:users/micfer/wasm/grow_memory

Make reporting external memory allocation cleaner with a wrapper and ensure we don't end up in a bad state after ReAlloc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants