lineReader reads line-by-line using only a single fixed scratch buffer.
When a single line is too long for the scratch buffer, the remainder of the
line will be skipped. // read reached EOF.fdint // bytes of scratch in use. // index of the first newline in scratch.readfunc(fd int, b []byte) (int, uintptr)scratch[]byte line returns a view of the current line, excluding the trailing newline.
If [r.next] returned errIncompleteLine, then this returns only the beginning
of the line.
Preconditions: [r.next] is called prior to the first call to line.
Postconditions: The caller must not keep a reference to the returned slice. next advances to the next line.
May return errIncompleteLine if the scratch buffer is too small to hold the
entire line, in which case [r.line] will return the beginning of the line. A
subsequent call to next will skip the remainder of the incomplete line.
N.B. this behavior is important for /proc/self/mountinfo. Some lines
(mounts), such as overlayfs, may be extremely long due to long super-block
options, but we don't care about those. The mount type will appear early in
the line.
Returns errEOF when there are no more lines.
func newLineReader(fd int, scratch []byte, read func(fd int, b []byte) (n int, errno uintptr)) *lineReader
stringError is a trival implementation of error, equivalent to errors.New,
which cannot be imported from a runtime package.( stringError) Error() string
stringError : error
Package-Level Functions (total 18, in which 5 are exported)
FindCPU finds the path to the CPU cgroup that this process is a member of
and places it in out. scratch is a scratch buffer for internal use.
out must have length PathSize. scratch must have length ParseSize.
Returns the number of bytes written to out and the cgroup version (1 or 2).
Returns ErrNoCgroup if the process is not in a CPU cgroup.
FindCPUCgroup finds the path to the CPU cgroup that this process is a member of
and places it in out. scratch is a scratch buffer for internal use.
out must have length PathSize. scratch must have length ParseSize.
Returns the number of bytes written to out and the cgroup version (1 or 2).
Returns ErrNoCgroup if the process is not in a CPU cgroup.
FindCPUMountPoint finds the mount point containing the specified cgroup and
version with cpu controller, and compose the full path to the cgroup in out.
scratch is a scratch buffer for internal use.
out must have length PathSize, may overlap with cgroup.
scratch must have length ParseSize.
Returns the number of bytes written to out.
Returns ErrNoCgroup if no matching mount point is found.
OpenCPU returns a CPU for the CPU cgroup containing the current process, or
ErrNoCgroup if the process is not in a CPU cgroup.
scratch must have length ScratchSize.
Returns average CPU throughput limit from the cgroup, or ok false if there
is no limit.
newLineReader returns a lineReader which reads lines from fd.
fd is the file descriptor to read from.
scratch is the scratch buffer to read into. Note that len(scratch) is the
longest line that can be read. Lines longer than len(scratch) will have the
remainder of the line skipped. See next for more details.
read is the function used to read more bytes from fd. This is usually
internal/runtime/syscall/linux.Read. Note that this follows syscall semantics (not
io.Reader), so EOF is indicated with n=0, errno=0.
Finds the path of the current process's CPU cgroup and writes it to out.
fd is a file descriptor for /proc/self/cgroup.
Returns the number of bytes written and the cgroup version (1 or 2).
Returns the path to the specified cgroup and version with cpu controller
fd is a file descriptor for /proc/self/mountinfo.
Returns the number of bytes written.
unescapePath copies in to out, unescaping escape sequences generated by
Linux's show_path.
That is, '\', ' ', '\t', and '\n' are converted to octal escape sequences,
like '\040' for space.
Caller must ensure that out at least has unescapedLen(in) bytes.
in and out may alias; in-place unescaping is supported.
Returns the number of bytes written to out.
Also see escapePath in cgroup_linux_test.go.
Package-Level Variables (total 7, in which 1 is exported)
Package-Level Constants (total 11, in which 6 are exported)
Required space to parse /proc/self/mountinfo and /proc/self/cgroup.
See findCPUMount and findCPURelativePath.
Required space to store a path of the cgroup in the filesystem.
Required amount of scratch space for CPULimit.
TODO(prattmic): This is shockingly large (~70KiB) due to the (very
unlikely) combination of extremely long paths consisting mostly
escaped characters. The scratch buffer ends up in .bss in package
runtime, so it doesn't contribute to binary size and generally won't
be faulted in, but it would still be nice to shrink this. A more
complex parser that did not need to keep entire lines in memory
could get away with much less. Alternatively, we could do a one-off
mmap allocation for this buffer, which is only mapped larger if we
actually need the extra space.
/proc/self/mountinfo path escape sequences are 4 characters long, so
a path consisting entirely of escaped characters could be 4 times
larger.
Include explicit NUL to be sure we include it in the slice.
Include explicit NUL to be sure we include it in the slice.
Include explicit NUL to be sure we include it in the slice.
The pages are generated with Goldsv0.8.4. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.