gionice

package module
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 16, 2021 License: GPL-2.0 Imports: 4 Imported by: 3

README

gionice

This is an port of the core parts of the ionice utility from util-linux, to a Go module, without using cgo.

The command line utility chill (a drop-in replacement for ionice), uses this module.

This package can be used by any Go program that wishes to run without taking up the I/O capabilities of the current system.

Example use

To make your own Go program run as "idle" and not hog the I/O capabilities of the system, simply call ionice.Idle():

package main

import (
	"io/ioutil"
	"os"

	"github.com/xyproto/gionice"
)

func main() {
	// Make the current process group priority to be "idle" (level 7)
	gionice.Idle()

	// Generate I/O activity
	for {
		_ = ioutil.WriteFile("frenetic.dat", []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, 0644)
		_ = os.Remove("frenetic.dat")
	}
}

By using iotop it's easy to check that the process PRIO is now idle.

General info

Documentation

Overview

Package gionice is a port of the core parts of util-linux/ionice (GPL2 licensed)

Index

Constants

View Source
const (
	IOPRIO_CLASS_NONE PriClass = 0
	IOPRIO_CLASS_RT   PriClass = 1
	IOPRIO_CLASS_BE   PriClass = 2
	IOPRIO_CLASS_IDLE PriClass = 3

	IOPRIO_WHO_PROCESS = 1
	IOPRIO_WHO_PGRP    = 2
	IOPRIO_WHO_USER    = 3

	IOPRIO_CLASS_SHIFT = 13
)
View Source
const (
	// From include/bits/resource.h
	PRIO_PROCESS = 0
	PRIO_PGRP    = 1
	PRIO_USER    = 2
)

Variables

This section is empty.

Functions

func Idle added in v1.3.0

func Idle() error

Idle will set the current process group IO niceness to "idle", level 7, if permitted.

func Naughty added in v1.3.0

func Naughty() error

Naughty will try to set the current process group niceness to level -20.

func Nice added in v1.3.0

func Nice() error

Nice will try to set the current process group niceness to level 10.

func NicePri added in v1.3.0

func NicePri(which, who int) (int, error)

NicePri returns the IO priority for the given "which" (process, pgrp or user) and "who" (the ID).

func Pri

func Pri(which, who int) (uint, error)

Pri returns the IO priority for the given "which" (process, pgrp or user) and "who" (the ID).

func Print

func Print(pid, who int)

Print outputs the IO nice status for the given PID and "who"

func Realtime added in v1.3.0

func Realtime() error

Reltime will set the current process group IO niceness to "realtime", level 7, if permitted.

func SetIDPri

func SetIDPri(which int, ioclass PriClass, data, who int) error

func SetIdle

func SetIdle(pgid int) error

If permitted, set the given process group ID to "idle", level 7. Use 0 for the current process group.

func SetIdlePID added in v1.3.0

func SetIdlePID(pid int) error

If permitted, set the given process ID to "idle", level 7. Use 0 for the current process.

func SetNaughty added in v1.3.0

func SetNaughty(pgid int) error

If permitted, set the given process group nicess to level -20. Pass in PGID 0 for the current process group.

func SetNaughtyPID added in v1.3.0

func SetNaughtyPID(pid int) error

If permitted, set the given process nicess to level -20. Pass in PID 0 for the current process.

func SetNice added in v1.3.0

func SetNice(pgid int) error

If permitted, set the given process group niceness to level 10. Pass in PGID 0 for the current process group.

func SetNicePID added in v1.3.0

func SetNicePID(pid int) error

If permitted, set the given process niceness to level 10. Pass in PID 0 for the current process.

func SetNicePri added in v1.3.0

func SetNicePri(which, who, ioprio int) error

SetNicePri sets the IO priority for the given "which" (process, pgrp or user) and "who" (the ID), using the given io priority number.

func SetPri

func SetPri(which, who int, ioprio uint) (uint, error)

SetPri sets the IO priority for the given "which" (process, pgrp or user) and "who" (the ID), using the given io priority number.

func SetRealTime

func SetRealTime(pgid int) error

If permitted, set the given process group ID to "realtime", level 7. Use 0 for the current process group.

func SetRealTimePID added in v1.3.0

func SetRealTimePID(pid int) error

If permitted, set the given process ID to "realtime", level 7. Use 0 for the current process.

Types

type PriClass

type PriClass int

PriClass represents an IO class, like "realtime" or "idle"

func Parse

func Parse(ioprio string) (PriClass, error)

Parse converts a string containing either: "none", "realtime", best-effort" or "idle", to a corresponding IOPRIO_CLASS. will also handle "0", "1", "2" or "3" The parsing is case-insensitive, so "REALTIME" or "rEaLtImE" is also fine.

Directories

Path Synopsis
cmd
hog

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL