Calculating the disk usage based on available bytes instead of usage bytes to account for reserved blocks in image GC
This commit is contained in:
		@@ -213,8 +213,12 @@ func (im *realImageManager) GarbageCollect() error {
 | 
				
			|||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	usage := int64(fsInfo.Usage)
 | 
					 | 
				
			||||||
	capacity := int64(fsInfo.Capacity)
 | 
						capacity := int64(fsInfo.Capacity)
 | 
				
			||||||
 | 
						available := int64(fsInfo.Available)
 | 
				
			||||||
 | 
						if available > capacity {
 | 
				
			||||||
 | 
							glog.Warningf("available %d is larger than capacity %d", available, capacity)
 | 
				
			||||||
 | 
							available = capacity
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Check valid capacity.
 | 
						// Check valid capacity.
 | 
				
			||||||
	if capacity == 0 {
 | 
						if capacity == 0 {
 | 
				
			||||||
@@ -224,9 +228,9 @@ func (im *realImageManager) GarbageCollect() error {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// If over the max threshold, free enough to place us at the lower threshold.
 | 
						// If over the max threshold, free enough to place us at the lower threshold.
 | 
				
			||||||
	usagePercent := int(usage * 100 / capacity)
 | 
						usagePercent := 100 - int(available*100/capacity)
 | 
				
			||||||
	if usagePercent >= im.policy.HighThresholdPercent {
 | 
						if usagePercent >= im.policy.HighThresholdPercent {
 | 
				
			||||||
		amountToFree := usage - (int64(im.policy.LowThresholdPercent) * capacity / 100)
 | 
							amountToFree := capacity*int64(100-im.policy.LowThresholdPercent)/100 - available
 | 
				
			||||||
		glog.Infof("[ImageManager]: Disk usage on %q (%s) is at %d%% which is over the high threshold (%d%%). Trying to free %d bytes", fsInfo.Device, fsInfo.Mountpoint, usagePercent, im.policy.HighThresholdPercent, amountToFree)
 | 
							glog.Infof("[ImageManager]: Disk usage on %q (%s) is at %d%% which is over the high threshold (%d%%). Trying to free %d bytes", fsInfo.Device, fsInfo.Mountpoint, usagePercent, im.policy.HighThresholdPercent, amountToFree)
 | 
				
			||||||
		freed, err := im.freeSpace(amountToFree, time.Now())
 | 
							freed, err := im.freeSpace(amountToFree, time.Now())
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -374,7 +374,7 @@ func TestGarbageCollectBelowLowThreshold(t *testing.T) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	// Expect 40% usage.
 | 
						// Expect 40% usage.
 | 
				
			||||||
	mockCadvisor.On("ImagesFsInfo").Return(cadvisorapiv2.FsInfo{
 | 
						mockCadvisor.On("ImagesFsInfo").Return(cadvisorapiv2.FsInfo{
 | 
				
			||||||
		Usage:    400,
 | 
							Available: 600,
 | 
				
			||||||
		Capacity:  1000,
 | 
							Capacity:  1000,
 | 
				
			||||||
	}, nil)
 | 
						}, nil)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -401,7 +401,7 @@ func TestGarbageCollectBelowSuccess(t *testing.T) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	// Expect 95% usage and most of it gets freed.
 | 
						// Expect 95% usage and most of it gets freed.
 | 
				
			||||||
	mockCadvisor.On("ImagesFsInfo").Return(cadvisorapiv2.FsInfo{
 | 
						mockCadvisor.On("ImagesFsInfo").Return(cadvisorapiv2.FsInfo{
 | 
				
			||||||
		Usage:    950,
 | 
							Available: 50,
 | 
				
			||||||
		Capacity:  1000,
 | 
							Capacity:  1000,
 | 
				
			||||||
	}, nil)
 | 
						}, nil)
 | 
				
			||||||
	fakeRuntime.ImageList = []container.Image{
 | 
						fakeRuntime.ImageList = []container.Image{
 | 
				
			||||||
@@ -420,7 +420,7 @@ func TestGarbageCollectNotEnoughFreed(t *testing.T) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	// Expect 95% usage and little of it gets freed.
 | 
						// Expect 95% usage and little of it gets freed.
 | 
				
			||||||
	mockCadvisor.On("ImagesFsInfo").Return(cadvisorapiv2.FsInfo{
 | 
						mockCadvisor.On("ImagesFsInfo").Return(cadvisorapiv2.FsInfo{
 | 
				
			||||||
		Usage:    950,
 | 
							Available: 50,
 | 
				
			||||||
		Capacity:  1000,
 | 
							Capacity:  1000,
 | 
				
			||||||
	}, nil)
 | 
						}, nil)
 | 
				
			||||||
	fakeRuntime.ImageList = []container.Image{
 | 
						fakeRuntime.ImageList = []container.Image{
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user