Skip to content

LCOW: Dynamic sandbox management#34170

Merged
johnstep merged 3 commits intomoby:masterfrom
microsoft:jjh/sandbox
Aug 3, 2017
Merged

LCOW: Dynamic sandbox management#34170
johnstep merged 3 commits intomoby:masterfrom
microsoft:jjh/sandbox

Conversation

@lowenna
Copy link
Member

@lowenna lowenna commented Jul 18, 2017

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?

@lowenna
Copy link
Member Author

lowenna commented Jul 18, 2017

@PatrickLang FYI.

@lowenna
Copy link
Member Author

lowenna commented Jul 18, 2017

And @gupta-ak FYI too.

// -- 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
Copy link
Member

Choose a reason for hiding this comment

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

nit: it maybe good to mention that a custom kernel needs to be embedded in UEFI boot program

Copy link
Member Author

Choose a reason for hiding this comment

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

That information is in the build instructions in the Microsoft/opengcs repo. I don't think it belongs here.

@PatrickLang
Copy link

Just to clarify - this isn't testable on Windows builds 16237 or 16241. Will be in a later build

@lowenna
Copy link
Member Author

lowenna commented Jul 25, 2017

@johnstep do you have time to look? Thx

@darstahl
Copy link
Contributor

This all LGTM, but I'm not a maintainer. I'll address any comments while John is on vacation.

Copy link
Member

@johnstep johnstep left a comment

Choose a reason for hiding this comment

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

Looks pretty good, just a couple small things.

//
// * 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
Copy link
Member

Choose a reason for hiding this comment

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

Nit: This default is really %ProgramFiles%\Linux Containers\uvm.vhdx, but, more precisely, it's uvm.vhdx under lcow.kirdpath.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, that'll be fixed in the next push.

ci.refCount++
logrus.Debugf("incremented refcount on cache item %+v", ci)
}

Copy link
Member

Choose a reason for hiding this comment

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

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
	}

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 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.

Copy link
Member

@johnstep johnstep Jul 31, 2017

Choose a reason for hiding this comment

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

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. :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

}
d.cache[id] = cacheEntry
logrus.Debugf("%s: added cache entry %+v", title, cacheEntry)
logrus.Debugf("%s: added cache item %+v", title, cacheEntry)
Copy link
Member

Choose a reason for hiding this comment

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

Are you not renaming variables from entry (and cacheEntry) to item (or ci) to simplify this change?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I missed a few. Fixing them up :)

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)
Copy link
Member

Choose a reason for hiding this comment

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

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's fair. Fixed.

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 {
Copy link
Member

Choose a reason for hiding this comment

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

Is the last parameter supposed to be d.cachedSandboxFile, like it was before? This is a little confusing to me.

Copy link
Member Author

Choose a reason for hiding this comment

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

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?

@lowenna
Copy link
Member Author

lowenna commented Jul 31, 2017

@johnstep - Update pushed with comments addressed.

Copy link
Member

@johnstep johnstep left a comment

Choose a reason for hiding this comment

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

LGTM

@lowenna
Copy link
Member Author

lowenna commented Jul 31, 2017

@thaJeztah PTAL. Addressed John's comments (and also fixed your decrement/increment comment from the previous PR, with helper functions).

Copy link
Member

@johnstep johnstep left a comment

Choose a reason for hiding this comment

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

The update looks good.

@lowenna
Copy link
Member Author

lowenna commented Aug 1, 2017

Note: If #34272 gets merged first, I'll need to update the vendoring on this to reflect versions with lowercase s for Sirupsen.

@lowenna
Copy link
Member Author

lowenna commented Aug 2, 2017

#34272 is merged. Vendoring updated to match.

@lowenna
Copy link
Member Author

lowenna commented Aug 3, 2017

Ugh. z is sooooooo flaky. Restarting. 4th time lucky 😭

@lowenna
Copy link
Member Author

lowenna commented Aug 3, 2017

@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

@mlaventure
Copy link
Contributor

@jhowardmsft LGTM, but could you switch to go-winio v0.4.4 ? It fixes a couple of possible deadlock/race conditions

John Howard added 3 commits August 3, 2017 09:06
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
@lowenna
Copy link
Member Author

lowenna commented Aug 3, 2017

@mlaventure Yes, that's bumped to go-winio v0.4.4 now

Copy link
Contributor

@mlaventure mlaventure left a comment

Choose a reason for hiding this comment

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

LGTM

Anyone seeing this green on Windows can just merge :)

@lowenna
Copy link
Member Author

lowenna commented Aug 3, 2017

Darn z. I've kicked it off for the 3rd attempt at https://jenkins.dockerproject.org/job/Docker-PRs-s390x/4797/console (not showing below for some reason).

@johnstep johnstep merged commit a3ffc42 into moby:master Aug 3, 2017
@lowenna lowenna deleted the jjh/sandbox branch August 3, 2017 23:08
@thaJeztah thaJeztah added the area/lcow Issues and PR's related to the experimental LCOW feature label Oct 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/lcow Issues and PR's related to the experimental LCOW feature status/2-code-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants