浏览代码

daemon: faster image cache miss detection

Lookup the graph parent reference to detect a builder cache miss before
looping the whole graph image index to build a parent-children tree.

Signed-off-by: Antonio Murdaca <runcom@redhat.com>
Antonio Murdaca 9 年之前
父节点
当前提交
f9e81b40f4
共有 3 个文件被更改,包括 10 次插入3 次删除
  1. 8 0
      daemon/daemon.go
  2. 1 1
      daemon/image_delete.go
  3. 1 2
      graph/graph.go

+ 8 - 0
daemon/daemon.go

@@ -1147,6 +1147,14 @@ func (daemon *Daemon) GetRemappedUIDGID() (int, int) {
 // created. nil is returned if a child cannot be found. An error is
 // created. nil is returned if a child cannot be found. An error is
 // returned if the parent image cannot be found.
 // returned if the parent image cannot be found.
 func (daemon *Daemon) ImageGetCached(imgID string, config *runconfig.Config) (*image.Image, error) {
 func (daemon *Daemon) ImageGetCached(imgID string, config *runconfig.Config) (*image.Image, error) {
+	// for now just exit if imgID has no children.
+	// maybe parentRefs in graph could be used to store
+	// the Image obj children for faster lookup below but this can
+	// be quite memory hungry.
+	if !daemon.Graph().HasChildren(imgID) {
+		return nil, nil
+	}
+
 	// Retrieve all images
 	// Retrieve all images
 	images := daemon.Graph().Map()
 	images := daemon.Graph().Map()
 
 

+ 1 - 1
daemon/image_delete.go

@@ -337,5 +337,5 @@ func (daemon *Daemon) checkImageDeleteSoftConflict(img *image.Image) *imageDelet
 // that there are no repository references to the given image and it has no
 // that there are no repository references to the given image and it has no
 // child images.
 // child images.
 func (daemon *Daemon) imageIsDangling(img *image.Image) bool {
 func (daemon *Daemon) imageIsDangling(img *image.Image) bool {
-	return !(daemon.Repositories().HasReferences(img) || daemon.Graph().HasChildren(img.ID))
+	return !(daemon.repositories.HasReferences(img) || daemon.Graph().HasChildren(img.ID))
 }
 }

+ 1 - 2
graph/graph.go

@@ -512,8 +512,7 @@ func (graph *Graph) Release(sessionID string, layerIDs ...string) {
 func (graph *Graph) Heads() map[string]*image.Image {
 func (graph *Graph) Heads() map[string]*image.Image {
 	heads := make(map[string]*image.Image)
 	heads := make(map[string]*image.Image)
 	graph.walkAll(func(image *image.Image) {
 	graph.walkAll(func(image *image.Image) {
-		// If it's not in the byParent lookup table, then
-		// it's not a parent -> so it's a head!
+		// if it has no children, then it's not a parent, so it's an head
 		if !graph.HasChildren(image.ID) {
 		if !graph.HasChildren(image.ID) {
 			heads[image.ID] = image
 			heads[image.ID] = image
 		}
 		}