Skip to content

Commit

Permalink
remove --remount
Browse files Browse the repository at this point in the history
  • Loading branch information
BenTheElder committed Mar 9, 2018
1 parent 5a27ab6 commit 73b5ad1
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 72 deletions.
45 changes: 0 additions & 45 deletions greenhouse/diskutil/diskutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,58 +18,13 @@ limitations under the License.
package diskutil

import (
"fmt"
"os/exec"
"strings"
"syscall"
"time"

"github.com/djherbis/atime"
log "github.com/sirupsen/logrus"
)

// exec command and returns lines of combined output
func commandLines(cmd []string) (lines []string, err error) {
c := exec.Command(cmd[0], cmd[1:]...)
b, err := c.CombinedOutput()
if err != nil {
return nil, err
}
return strings.Split(string(b), "\n"), nil
}

// FindMountForPath wraps `mount` to find the device / mountpoint
// on which path is mounted
func FindMountForPath(path string) (device, mountPoint string, err error) {
mounts, err := commandLines([]string{"mount"})
if err != nil {
return "", "", err
}
// these lines are like:
// $fs on $mountpoint type $fs_type ($mountopts)
device, mountPoint = "", ""
for _, mount := range mounts {
parts := strings.Fields(mount)
if len(parts) >= 3 {
currDevice := parts[0]
currMount := parts[2]
// we want the longest matching mountpoint
if strings.HasPrefix(path, currMount) && len(currMount) > len(mountPoint) {
device, mountPoint = currDevice, currMount
}
}
}
return device, mountPoint, nil
}

// Remount `wraps mount -o remount,options device mountPoint`
func Remount(device, mountPoint, options string) error {
_, err := commandLines([]string{
"mount", "-o", fmt.Sprintf("remount,%s", options), device, mountPoint,
})
return err
}

// GetDiskUsage wraps syscall.Statfs for usage in GCing the disk
func GetDiskUsage(path string) (percentBlocksFree float64, bytesFree, bytesUsed uint64, err error) {
var stat syscall.Statfs_t
Expand Down
5 changes: 4 additions & 1 deletion greenhouse/gce-storage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ metadata:
provisioner: kubernetes.io/gce-pd
parameters:
type: pd-ssd
# so we can get accurat eviction, note that lazytime only works on ext4
# we want to use a volume with strictatime,lazytime (and not noatime or relatime)
# so that file access times *are* recorded but are lazily flushed to the disk
# https://lwn.net/Articles/621046/
# https://unix.stackexchange.com/questions/276858/why-is-ext4-filesystem-mounted-with-both-relatime-and-lazytime
mountOptions: ["strictatime", "lazytime"]
---
# 3TB of SSD :-)
Expand Down
26 changes: 0 additions & 26 deletions greenhouse/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,6 @@ var evictUntilPercentBlocksFree = flag.Float64("evict-until-percent-blocks-free"
var diskCheckInterval = flag.Duration("disk-check-interval", time.Second*10,
"interval between checking disk usage (and potentially evicting entries)")

// NOTE: remount is a bit of a hack, unfortunately the kubernetes volumes
// don't really support this and to cleanly track entry access times we
// want to use a volume with strictatime,lazytime (and not noatime or relatime)
// so that file access times *are* recorded but are lazily flushed to the disk
// https://lwn.net/Articles/621046/
// https://unix.stackexchange.com/questions/276858/why-is-ext4-filesystem-mounted-with-both-relatime-and-lazytime
var remount = flag.Bool("remount", false,
"attempt to remount --dir with strictatime,lazyatime to improve eviction")

// global metrics object, see prometheus.go
var promMetrics *prometheusMetrics

Expand All @@ -85,23 +76,6 @@ func main() {
if *dir == "" {
logrus.Fatal("--dir must be set!")
}
if *remount {
device, mount, err := diskutil.FindMountForPath(*dir)
if err != nil {
logrus.WithError(err).Errorf("Failed to find mountpoint for %s", *dir)
} else {
logrus.Warnf(
"Attempting to remount %s on %s with 'strictatime,lazyatime'",
device, mount,
)
err = diskutil.Remount(device, mount, "strictatime,lazytime")
if err != nil {
logrus.WithError(err).Error("Failed to remount with lazyatime!")
} else {
logrus.Info("Remount complete")
}
}
}

cache := diskcache.NewCache(*dir)
go monitorDiskAndEvict(
Expand Down

0 comments on commit 73b5ad1

Please sign in to comment.