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

VOM should track Presence vrefs used in virtualized data, to inhibit dropImport #3133

Closed
warner opened this issue May 19, 2021 · 0 comments · Fixed by #3157
Closed

VOM should track Presence vrefs used in virtualized data, to inhibit dropImport #3133

warner opened this issue May 19, 2021 · 0 comments · Fixed by #3157
Assignees
Labels
enhancement New feature or request SwingSet package: SwingSet

Comments

@warner
Copy link
Member

warner commented May 19, 2021

What is the Problem Being Solved?

As described in #3106 (the section named "VOM tracks Presences in virtualized data, add-only"), if a Presence is used in the state of a virtual object or the value of a virtualized WeakStore, only it's vref is stored, not the Presence JS Object itself. If/when userspace drops the tangible Presence object, the liveslots GC finalizers will take note, and they want to call syscall.dropImport to let the kernel know that this vat can no longer reach that Presence (allowing the upstream Remotable to be dropped, eventually). But if some virtual data can be reanimated to re-introduce a new Presence object for that same vref, then the vref isn't really unreachable.

When the finalizer runs, the liveslots reachability manager will be asking the virtual object manager about the vref, and the VOM needs to be able to say "I can still reach the vref" or "I cannot".

To answer this question correctly requires refcounting of each vref (and a return notification mechanism to say "hey reachability manager, earlier I said yes, but that answer just changed to no, so if you don't still have a Presence for that vref, you should do dropImport now"). But we can defer that work because we don't have any users of this feature yet: the only thing that goes into state or virtualized data is one Remotable per ERTP issuer (a Brand).

So the immediate task is to simply remember a Set of all the Presence vrefs that have ever been included in virtualized data, and use that to conservatively answer the reachability manager's question.

Description of the Design

  • VOM adds a reachableVrefs Set whose type is strings (vrefs)
  • each time it serializes data (state setter or WeakStore .set()), scan the slots and identify the Presences (o-NN)
  • update the Set with the vrefs
  • add a VOM method like .isVrefReachable(vref), which just does return reachableVrefs.has(vref)

Later, when #2660 prepares to call syscall.dropImport, it will ask the VOM first.

Test Plan

Unit tests which create a VOM, forge a Presence, ask .isVrefReachable() and get back false, add the Presence to WeakStore value, ask .isVrefReachable() again and get back true. Then a separate test which does the same thing for the state of a virtual object.

For both tests, we should then delete the item and check that isVrefReachable() still returns true. We'll add a note to this test to remind ourselves that a complete implementation would return false, and to change the assertion when we finish that task some day.

@warner warner added enhancement New feature or request SwingSet package: SwingSet labels May 19, 2021
@warner warner assigned warner and unassigned FUDCo May 20, 2021
warner added a commit that referenced this issue May 22, 2021
If userspace puts a Presence into the `state` of a virtual object, or
somewhere inside the value stored in vref-keyed `makeWeakStore()` entry, it
gets serialized and stored as a vref, which doesn't (and should not) keep the
Presence object alive. Allowing this Presence to leave RAM, remembering only
the vref on disk, is a non-trivial part of the memory savings we obtain by
using virtualized data.

However, just because there is currently no Presence (for a given vref)
does *not* mean that the vat cannot reach the vref. Liveslots will observe
the Presence being collected (when the finalizer runs), but if the vref is
still stored somewhere in virtualized data, liveslots must not emit a
`syscall.dropImport` for it.

This changes the virtual object manager to keep track of Presences used in
virtualized data, and remember their vref in a Set. When liveslots' wants to
`dropImport` a vref that no longer has a Presence, it will ask the VOM first.
With this Set, the VOM can inhibit the `dropImport` call until later.

At this stage, we simply add the vref to a Set and never remove it. This is
safe but conservative. In the future, we'll need some form of refcounting to
detect when the vref is no longer mentioned anywhere in virtualized data. At
that point, the VOM will need to inform liveslots (or some sort of
"reachability manager") that the VOM no longer needs the vref kept alive. The
`syscall.dropImport` can be sent when neither the VOM nor a Presence is
causing the vref to remain reachable.

closes #3133
refs #3106
warner added a commit that referenced this issue May 24, 2021
If userspace puts a Presence into the `state` of a virtual object, or
somewhere inside the value stored in vref-keyed `makeWeakStore()` entry, it
gets serialized and stored as a vref, which doesn't (and should not) keep the
Presence object alive. Allowing this Presence to leave RAM, remembering only
the vref on disk, is a non-trivial part of the memory savings we obtain by
using virtualized data.

However, just because there is currently no Presence (for a given vref)
does *not* mean that the vat cannot reach the vref. Liveslots will observe
the Presence being collected (when the finalizer runs), but if the vref is
still stored somewhere in virtualized data, liveslots must not emit a
`syscall.dropImport` for it.

This changes the virtual object manager to keep track of Presences used in
virtualized data, and remember their vref in a Set. When liveslots' wants to
`dropImport` a vref that no longer has a Presence, it will ask the VOM first.
With this Set, the VOM can inhibit the `dropImport` call until later.

At this stage, we simply add the vref to a Set and never remove it. This is
safe but conservative. In the future, we'll need some form of refcounting to
detect when the vref is no longer mentioned anywhere in virtualized data. At
that point, the VOM will need to inform liveslots (or some sort of
"reachability manager") that the VOM no longer needs the vref kept alive. The
`syscall.dropImport` can be sent when neither the VOM nor a Presence is
causing the vref to remain reachable.

closes #3133
refs #3106
warner added a commit that referenced this issue May 25, 2021
If userspace puts a Presence into the `state` of a virtual object, or
somewhere inside the value stored in vref-keyed `makeWeakStore()` entry, it
gets serialized and stored as a vref, which doesn't (and should not) keep the
Presence object alive. Allowing this Presence to leave RAM, remembering only
the vref on disk, is a non-trivial part of the memory savings we obtain by
using virtualized data.

However, just because there is currently no Presence (for a given vref)
does *not* mean that the vat cannot reach the vref. Liveslots will observe
the Presence being collected (when the finalizer runs), but if the vref is
still stored somewhere in virtualized data, liveslots must not emit a
`syscall.dropImport` for it.

This changes the virtual object manager to keep track of Presences used in
virtualized data, and remember their vref in a Set. When liveslots' wants to
`dropImport` a vref that no longer has a Presence, it will ask the VOM first.
With this Set, the VOM can inhibit the `dropImport` call until later.

At this stage, we simply add the vref to a Set and never remove it. This is
safe but conservative. In the future, we'll need some form of refcounting to
detect when the vref is no longer mentioned anywhere in virtualized data. At
that point, the VOM will need to inform liveslots (or some sort of
"reachability manager") that the VOM no longer needs the vref kept alive. The
`syscall.dropImport` can be sent when neither the VOM nor a Presence is
causing the vref to remain reachable.

closes #3133
refs #3106
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request SwingSet package: SwingSet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants