LCOW: Dynamic sandbox management#34170
Conversation
|
@PatrickLang FYI. |
|
And @gupta-ak FYI too. |
64ef85f to
5b5b641
Compare
| // -- Possible values: Any local path that is not a mapped drive | ||
| // -- Default if ommitted: %ProgramFiles%\Linux Containers | ||
| // | ||
| // * lcow.kernel - Specifies a custom kernel file located in the `lcow.kirdpath` path |
There was a problem hiding this comment.
nit: it maybe good to mention that a custom kernel needs to be embedded in UEFI boot program
There was a problem hiding this comment.
That information is in the build instructions in the Microsoft/opengcs repo. I don't think it belongs here.
|
Just to clarify - this isn't testable on Windows builds 16237 or 16241. Will be in a later build |
|
@johnstep do you have time to look? Thx |
|
This all LGTM, but I'm not a maintainer. I'll address any comments while John is on vacation. |
johnstep
left a comment
There was a problem hiding this comment.
Looks pretty good, just a couple small things.
daemon/graphdriver/lcow/lcow.go
Outdated
| // | ||
| // * lcow.vhdx - Specifies a custom vhdx file to boot (instead of a kernel+initrd) | ||
| // -- Possible values: Any valid filename | ||
| // -- Default if ommitted: C:\Program Files\Linux Containers\uvm.vhdx |
There was a problem hiding this comment.
Nit: This default is really %ProgramFiles%\Linux Containers\uvm.vhdx, but, more precisely, it's uvm.vhdx under lcow.kirdpath.
There was a problem hiding this comment.
Sure, that'll be fixed in the next push.
| ci.refCount++ | ||
| logrus.Debugf("incremented refcount on cache item %+v", ci) | ||
| } | ||
|
|
There was a problem hiding this comment.
How about a corresponding decrementRefCount for Put, replacing the following code:
// Are we just decrementing the reference count?
logrus.Debugf("%s: locking cache item for possible decrement", title)
entry.Lock()
if entry.refCount > 1 {
entry.refCount--
logrus.Debugf("%s: releasing cache item for decrement and early get-out as refCount is now %d", title, entry.refCount)
entry.Unlock()
logrus.Debugf("%s: refCount decremented to %d. Releasing cacheMutex", title, entry.refCount)
d.cacheMutex.Unlock()
return nil
}
logrus.Debugf("%s: releasing cache item", title)
entry.Unlock()...with something like this:
// Are we just decrementing the reference count?
if entry.decrementRefCount() > 0 {
d.cacheMutex.Unlock()
return nil
}There was a problem hiding this comment.
I didn't do that deliberately. It's currently a conditional decrement rather than absolute decrement - it just seemed clearer the way it currently is. IMO.
There was a problem hiding this comment.
Fair enough, and slightly more efficient, but my proposal seems easier to read, providing symmetry to the increment function. It doesn't matter if the condition is checked before or after, and decrementing makes the debug log accurate about reaching zero. :)
daemon/graphdriver/lcow/lcow.go
Outdated
| } | ||
| d.cache[id] = cacheEntry | ||
| logrus.Debugf("%s: added cache entry %+v", title, cacheEntry) | ||
| logrus.Debugf("%s: added cache item %+v", title, cacheEntry) |
There was a problem hiding this comment.
Are you not renaming variables from entry (and cacheEntry) to item (or ci) to simplify this change?
There was a problem hiding this comment.
Yeah, I missed a few. Fixing them up :)
daemon/graphdriver/lcow/lcow.go
Outdated
| if fileInfo, err = os.Stat(ld.filename); err != nil { | ||
| if os.IsNotExist(err) { | ||
| return "", 0, isSandbox, fmt.Errorf("could not find layer or sandbox in %s", folder) | ||
| return nil, fmt.Errorf("could not find layer or sandbox in %s", folder) |
There was a problem hiding this comment.
Nit: Minor, and not a regression, but if Stat fails for a layer, but the file exists, this message is technically inaccurate. However, that seems like an unlikely scenario. I'm not sure this existence check is worthwhile.
| svm.Lock() | ||
| if err := svm.config.CreateSandbox(d.cachedScratchFile, client.DefaultSandboxSizeMB, d.cachedSandboxFile); err != nil { | ||
| logrus.Debugf("%s (%s): releasing serviceVM on error path", title, context) | ||
| if err := svm.config.CreateExt4Vhdx(scratchTargetFile, client.DefaultVhdxSizeGB, d.cachedScratchFile); err != nil { |
There was a problem hiding this comment.
Is the last parameter supposed to be d.cachedSandboxFile, like it was before? This is a little confusing to me.
There was a problem hiding this comment.
Ah, no this is correct. First parameter is the target (which in this case the scratch we're trying to create). Last parameter is both the source and target of a cached file - if it exists, it's a straight CopyFileW from the cache to target file; if it doesn't then first the target file gets created, then it's cached to the cache location. Make sense?
|
@johnstep - Update pushed with comments addressed. |
|
@thaJeztah PTAL. Addressed John's comments (and also fixed your decrement/increment comment from the previous PR, with helper functions). |
|
Note: If #34272 gets merged first, I'll need to update the vendoring on this to reflect versions with lowercase |
|
#34272 is merged. Vendoring updated to match. |
|
Ugh. |
|
@mlaventure @thaJeztah @vdemeester Do you guys have time to look at this? There's a few other LCOW related PRs not yet submitted which are backed up behind this being merged. On the bright side, it only affects LCOW code, so the risk of regressing other functionality (it doesn't.....) is as close as it gets to zero. It's also already had some pretty thorough reviews from @johnstep & @darrenstahlmsft |
|
@jhowardmsft LGTM, but could you switch to |
Signed-off-by: John Howard <jhoward@microsoft.com>
Signed-off-by: John Howard <jhoward@microsoft.com>
Signed-off-by: John Howard <jhoward@microsoft.com> This changes the graphdriver to perform dynamic sandbox management. Previously, as a temporary 'hack', the service VM had a prebuilt sandbox in it. With this change, management is under the control of the client (docker) and executes a mkfs.ext4 on it. This enables sandboxes of non-default sizes too (a TODO previously in the code). It also addresses moby#33969 (comment) Requires: - go-winio: v0.4.3 - opengcs: v0.0.12 - hcsshim: v0.6.x
|
@mlaventure Yes, that's bumped to |
mlaventure
left a comment
There was a problem hiding this comment.
LGTM
Anyone seeing this green on Windows can just merge :)
|
Darn |
Signed-off-by: John Howard jhoward@microsoft.com
This changes the graphdriver to perform dynamic sandbox management. Previously, as a temporary 'hack', the service VM had a prebuilt sandbox in it. With this change, management is under the control of the client (docker) and executes a mkfs.ext4 on it. This enables sandboxes of non-default sizes too (a TODO previously in the code).
It also addresses #33969 (comment) from @thaJeztah
Requires:
- go-winio: v0.4.3 (v0.4.4 is vendored)
- opengcs: v0.0.12
- hcsshim: v0.6.x (merged as part of 34272 so not in this PR)
@johnstep PTAL. Note, you won't be able to use this on current builds you have, as to create the sandbox and scratch space blank VHDX's in the cache, it relies on HCS APIs which aren't present in your builds. You can temporarily work around this by keeping sandbox.vhdx and scratch.vhdx from \lcow\lcow\cache safe somewhere, and copying them manually so that they are in place.
@darrenstahlmsft Can you track/address feedback comments while I'm on vacation?