Compare commits
1 Commits
artix-meso
...
cg2-only
| Author | SHA1 | Date | |
|---|---|---|---|
| d5ee2cde8e |
70
etc/rc.conf
70
etc/rc.conf
@@ -194,18 +194,6 @@ rc_tty_number=12
|
|||||||
##############################################################################
|
##############################################################################
|
||||||
# LINUX CGROUPS RESOURCE MANAGEMENT
|
# LINUX CGROUPS RESOURCE MANAGEMENT
|
||||||
|
|
||||||
# This sets the mode used to mount cgroups.
|
|
||||||
# "hybrid" mounts cgroups version 2 on /sys/fs/cgroup/unified and
|
|
||||||
# cgroups version 1 on /sys/fs/cgroup.
|
|
||||||
# "legacy" mounts cgroups version 1 on /sys/fs/cgroup
|
|
||||||
# "unified" mounts cgroups version 2 on /sys/fs/cgroup
|
|
||||||
#rc_cgroup_mode="unified"
|
|
||||||
|
|
||||||
# This is a list of controllers which should be enabled for cgroups version 2
|
|
||||||
# when hybrid mode is being used.
|
|
||||||
# Controllers listed here will not be available for cgroups version 1.
|
|
||||||
#rc_cgroup_controllers=""
|
|
||||||
|
|
||||||
# This variable contains the cgroups version 2 settings for your services.
|
# This variable contains the cgroups version 2 settings for your services.
|
||||||
# If this is set in this file, the settings will apply to all services.
|
# If this is set in this file, the settings will apply to all services.
|
||||||
# If you want different settings for each service, place the settings in
|
# If you want different settings for each service, place the settings in
|
||||||
@@ -224,64 +212,6 @@ rc_tty_number=12
|
|||||||
# source tree.
|
# source tree.
|
||||||
#rc_cgroup_settings=""
|
#rc_cgroup_settings=""
|
||||||
|
|
||||||
# This switch controls whether or not cgroups version 1 controllers are
|
|
||||||
# individually mounted under
|
|
||||||
# /sys/fs/cgroup in hybrid or legacy mode.
|
|
||||||
#rc_controller_cgroups="YES"
|
|
||||||
|
|
||||||
# The following setting turns on the memory.use_hierarchy setting in the
|
|
||||||
# root memory cgroup for cgroups v1.
|
|
||||||
# It must be set to yes in this file if you want this functionality.
|
|
||||||
#rc_cgroup_memory_use_hierarchy="NO"
|
|
||||||
|
|
||||||
# The following settings allow you to set up values for the cgroups version 1
|
|
||||||
# controllers for your services.
|
|
||||||
# They can be set in this file;, however, if you do this, the settings
|
|
||||||
# will apply to all of your services.
|
|
||||||
# If you want different settings for each service, place the settings in
|
|
||||||
# /etc/conf.d/foo for service foo.
|
|
||||||
# The format is to specify the names of the settings followed by their
|
|
||||||
# values. Each variable can hold multiple settings.
|
|
||||||
# For example, you would use this to set the cpu.shares setting in the
|
|
||||||
# cpu controller to 512 for your service.
|
|
||||||
# rc_cgroup_cpu="
|
|
||||||
# cpu.shares 512
|
|
||||||
# "
|
|
||||||
#
|
|
||||||
# For more information about the adjustments that can be made with
|
|
||||||
# cgroups version 1, see Documentation/cgroups-v1/* in the linux kernel
|
|
||||||
# source tree.
|
|
||||||
|
|
||||||
# Set the blkio controller settings for this service.
|
|
||||||
#rc_cgroup_blkio=""
|
|
||||||
|
|
||||||
# Set the cpu controller settings for this service.
|
|
||||||
#rc_cgroup_cpu=""
|
|
||||||
|
|
||||||
# Add this service to the cpuacct controller (any value means yes).
|
|
||||||
#rc_cgroup_cpuacct=""
|
|
||||||
|
|
||||||
# Set the cpuset controller settings for this service.
|
|
||||||
#rc_cgroup_cpuset=""
|
|
||||||
|
|
||||||
# Set the devices controller settings for this service.
|
|
||||||
#rc_cgroup_devices=""
|
|
||||||
|
|
||||||
# Set the hugetlb controller settings for this service.
|
|
||||||
#rc_cgroup_hugetlb=""
|
|
||||||
|
|
||||||
# Set the memory controller settings for this service.
|
|
||||||
#rc_cgroup_memory=""
|
|
||||||
|
|
||||||
# Set the net_cls controller settings for this service.
|
|
||||||
#rc_cgroup_net_cls=""
|
|
||||||
|
|
||||||
# Set the net_prio controller settings for this service.
|
|
||||||
#rc_cgroup_net_prio=""
|
|
||||||
|
|
||||||
# Set the pids controller settings for this service.
|
|
||||||
#rc_cgroup_pids=""
|
|
||||||
|
|
||||||
# Set this to YES if you want all of the processes in a service's cgroup
|
# Set this to YES if you want all of the processes in a service's cgroup
|
||||||
# killed when the service is stopped or restarted.
|
# killed when the service is stopped or restarted.
|
||||||
# Be aware that setting this to yes means all of a service's
|
# Be aware that setting this to yes means all of a service's
|
||||||
|
|||||||
@@ -19,53 +19,6 @@ depend()
|
|||||||
after sysfs
|
after sysfs
|
||||||
}
|
}
|
||||||
|
|
||||||
cgroup1_base()
|
|
||||||
{
|
|
||||||
grep -qw cgroup /proc/filesystems || return 0
|
|
||||||
if ! mountinfo -q /sys/fs/cgroup; then
|
|
||||||
ebegin "Mounting cgroup filesystem"
|
|
||||||
local opts="${cgroup_opts},mode=755,size=${rc_cgroupsize:-10m}"
|
|
||||||
mount -n -t tmpfs -o "${opts}" cgroup_root /sys/fs/cgroup
|
|
||||||
eend $?
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! mountinfo -q /sys/fs/cgroup/openrc; then
|
|
||||||
local agent="${RC_LIBEXECDIR}/sh/cgroup-release-agent.sh"
|
|
||||||
mkdir /sys/fs/cgroup/openrc
|
|
||||||
mount -n -t cgroup \
|
|
||||||
-o none,${cgroup_opts},name=openrc,release_agent="$agent" \
|
|
||||||
openrc /sys/fs/cgroup/openrc
|
|
||||||
printf 1 > /sys/fs/cgroup/openrc/notify_on_release
|
|
||||||
fi
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
cgroup1_controllers()
|
|
||||||
{
|
|
||||||
yesno "${rc_controller_cgroups:-YES}" && [ -e /proc/cgroups ] &&
|
|
||||||
grep -qw cgroup /proc/filesystems || return 0
|
|
||||||
while read -r name _ _ enabled _; do
|
|
||||||
case "${enabled}" in
|
|
||||||
1) mountinfo -q "/sys/fs/cgroup/${name}" && continue
|
|
||||||
local x
|
|
||||||
for x in $rc_cgroup_controllers; do
|
|
||||||
[ "${name}" = "blkio" ] && [ "${x}" = "io" ] &&
|
|
||||||
continue 2
|
|
||||||
[ "${name}" = "${x}" ] &&
|
|
||||||
continue 2
|
|
||||||
done
|
|
||||||
mkdir "/sys/fs/cgroup/${name}"
|
|
||||||
mount -n -t cgroup -o "${cgroup_opts},${name}" \
|
|
||||||
"${name}" "/sys/fs/cgroup/${name}"
|
|
||||||
yesno "${rc_cgroup_memory_use_hierarchy:-no}" &&
|
|
||||||
[ "${name}" = memory ] &&
|
|
||||||
echo 1 > /sys/fs/cgroup/memory/memory.use_hierarchy
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done < /proc/cgroups
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
cgroup2_base()
|
cgroup2_base()
|
||||||
{
|
{
|
||||||
grep -qw cgroup2 /proc/filesystems || return 0
|
grep -qw cgroup2 /proc/filesystems || return 0
|
||||||
@@ -87,35 +40,8 @@ cgroup2_controllers()
|
|||||||
[ ! -e "${cgroup_path}/cgroup.subtree_control" ]&& return 0
|
[ ! -e "${cgroup_path}/cgroup.subtree_control" ]&& return 0
|
||||||
read -r active < "${cgroup_path}/cgroup.controllers"
|
read -r active < "${cgroup_path}/cgroup.controllers"
|
||||||
for x in ${active}; do
|
for x in ${active}; do
|
||||||
case "${rc_cgroup_mode:-unified}" in
|
|
||||||
unified)
|
|
||||||
echo "+${x}" > "${cgroup_path}/cgroup.subtree_control"
|
echo "+${x}" > "${cgroup_path}/cgroup.subtree_control"
|
||||||
;;
|
|
||||||
hybrid)
|
|
||||||
for y in ${rc_cgroup_controllers}; do
|
|
||||||
if [ "$x" = "$y" ]; then
|
|
||||||
echo "+${x}" > "${cgroup_path}/cgroup.subtree_control"
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
cgroups_hybrid()
|
|
||||||
{
|
|
||||||
cgroup1_base
|
|
||||||
cgroup2_base
|
|
||||||
cgroup2_controllers
|
|
||||||
cgroup1_controllers
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
cgroups_legacy()
|
|
||||||
{
|
|
||||||
cgroup1_base
|
|
||||||
cgroup1_controllers
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,11 +54,7 @@ cgroups_unified()
|
|||||||
|
|
||||||
mount_cgroups()
|
mount_cgroups()
|
||||||
{
|
{
|
||||||
case "${rc_cgroup_mode:-unified}" in
|
cgroups_unified
|
||||||
hybrid) cgroups_hybrid ;;
|
|
||||||
legacy) cgroups_legacy ;;
|
|
||||||
unified) cgroups_unified ;;
|
|
||||||
esac
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ if os == 'Linux' and libexecdir == 'libexec'
|
|||||||
libexecdir = 'lib'
|
libexecdir = 'lib'
|
||||||
endif
|
endif
|
||||||
libexecdir = rootprefix / libexecdir
|
libexecdir = rootprefix / libexecdir
|
||||||
rc_libexecdir = libexecdir / get_option('librcdir')
|
rc_libexecdir = libexecdir / 'rc'
|
||||||
rc_bindir = rc_libexecdir / 'bin'
|
rc_bindir = rc_libexecdir / 'bin'
|
||||||
rc_sbindir = rc_libexecdir / 'sbin'
|
rc_sbindir = rc_libexecdir / 'sbin'
|
||||||
rc_shdir = rc_libexecdir / 'sh'
|
rc_shdir = rc_libexecdir / 'sh'
|
||||||
|
|||||||
@@ -30,5 +30,3 @@ option('sysvinit', type : 'boolean', value : false,
|
|||||||
description : 'enable SysVinit compatibility (linux only)')
|
description : 'enable SysVinit compatibility (linux only)')
|
||||||
option('zsh-completions', type : 'boolean',
|
option('zsh-completions', type : 'boolean',
|
||||||
description : 'install zsh completions')
|
description : 'install zsh completions')
|
||||||
option('librcdir', type : 'string', value : 'rc',
|
|
||||||
description : 'default location of rc libexec dir')
|
|
||||||
|
|||||||
@@ -259,20 +259,6 @@ for _cmd; do
|
|||||||
eerror "${RC_SVCNAME}: unable to apply RC_ULIMIT settings"
|
eerror "${RC_SVCNAME}: unable to apply RC_ULIMIT settings"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
# Apply cgroups settings if defined
|
|
||||||
if [ "$(command -v cgroup_add_service)" = "cgroup_add_service" ]
|
|
||||||
then
|
|
||||||
if grep -qs /sys/fs/cgroup /proc/1/mountinfo
|
|
||||||
then
|
|
||||||
if [ -d /sys/fs/cgroup -a ! -w /sys/fs/cgroup ]; then
|
|
||||||
eerror "No permission to apply cgroup settings"
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
cgroup_add_service
|
|
||||||
fi
|
|
||||||
[ "$(command -v cgroup_set_limits)" = "cgroup_set_limits" ] &&
|
|
||||||
cgroup_set_limits
|
|
||||||
[ "$(command -v cgroup2_set_limits)" = "cgroup2_set_limits" ] &&
|
[ "$(command -v cgroup2_set_limits)" = "cgroup2_set_limits" ] &&
|
||||||
[ "$_cmd" = start ] &&
|
[ "$_cmd" = start ] &&
|
||||||
cgroup2_set_limits
|
cgroup2_set_limits
|
||||||
|
|||||||
121
sh/rc-cgroup.sh
121
sh/rc-cgroup.sh
@@ -11,19 +11,6 @@
|
|||||||
extra_stopped_commands="${extra_stopped_commands} cgroup_cleanup"
|
extra_stopped_commands="${extra_stopped_commands} cgroup_cleanup"
|
||||||
description_cgroup_cleanup="Kill all processes in the cgroup"
|
description_cgroup_cleanup="Kill all processes in the cgroup"
|
||||||
|
|
||||||
cgroup_find_path()
|
|
||||||
{
|
|
||||||
local OIFS name dir result
|
|
||||||
[ -n "$1" ] || return 0
|
|
||||||
OIFS="$IFS"
|
|
||||||
IFS=":"
|
|
||||||
while read -r _ name dir; do
|
|
||||||
[ "$name" = "$1" ] && result="$dir"
|
|
||||||
done < /proc/1/cgroup
|
|
||||||
IFS="$OIFS"
|
|
||||||
printf "%s" "${result}"
|
|
||||||
}
|
|
||||||
|
|
||||||
# This extracts all pids in a cgroup and puts them in the cgroup_pids
|
# This extracts all pids in a cgroup and puts them in the cgroup_pids
|
||||||
# variable.
|
# variable.
|
||||||
# It is done this way to avoid subshells so we don't have to worry about
|
# It is done this way to avoid subshells so we don't have to worry about
|
||||||
@@ -36,8 +23,6 @@ cgroup_get_pids()
|
|||||||
cgroup_procs="$(cgroup2_find_path)"
|
cgroup_procs="$(cgroup2_find_path)"
|
||||||
if [ -n "${cgroup_procs}" ]; then
|
if [ -n "${cgroup_procs}" ]; then
|
||||||
cgroup_procs="${cgroup_procs}/openrc.${RC_SVCNAME}/cgroup.procs"
|
cgroup_procs="${cgroup_procs}/openrc.${RC_SVCNAME}/cgroup.procs"
|
||||||
else
|
|
||||||
cgroup_procs="/sys/fs/cgroup/openrc/${RC_SVCNAME}/tasks"
|
|
||||||
fi
|
fi
|
||||||
[ -f "${cgroup_procs}" ] || return 0
|
[ -f "${cgroup_procs}" ] || return 0
|
||||||
while read -r p; do
|
while read -r p; do
|
||||||
@@ -49,115 +34,13 @@ cgroup_get_pids()
|
|||||||
|
|
||||||
cgroup_running()
|
cgroup_running()
|
||||||
{
|
{
|
||||||
[ -d "/sys/fs/cgroup/unified/${RC_SVCNAME}" ] ||
|
[ -d "/sys/fs/cgroup/${RC_SVCNAME}" ]
|
||||||
[ -d "/sys/fs/cgroup/${RC_SVCNAME}" ] ||
|
|
||||||
[ -d "/sys/fs/cgroup/openrc/${RC_SVCNAME}" ]
|
|
||||||
}
|
|
||||||
|
|
||||||
cgroup_set_values()
|
|
||||||
{
|
|
||||||
[ -n "$1" ] && [ -n "$2" ] && [ -d "/sys/fs/cgroup/$1" ] || return 0
|
|
||||||
|
|
||||||
local controller h
|
|
||||||
controller="$1"
|
|
||||||
h=$(cgroup_find_path "$1")
|
|
||||||
cgroup="/sys/fs/cgroup/${1}${h}openrc_${RC_SVCNAME}"
|
|
||||||
[ -d "$cgroup" ] || mkdir -p "$cgroup"
|
|
||||||
|
|
||||||
set -- $2
|
|
||||||
local name val
|
|
||||||
while [ -n "$1" ] && [ "$controller" != "cpuacct" ]; do
|
|
||||||
case "$1" in
|
|
||||||
$controller.*)
|
|
||||||
if [ -n "${name}" ] && [ -w "${cgroup}/${name}" ] &&
|
|
||||||
[ -n "${val}" ]; then
|
|
||||||
veinfo "$RC_SVCNAME: Setting $cgroup/$name to $val"
|
|
||||||
printf "%s" "$val" > "$cgroup/$name"
|
|
||||||
fi
|
|
||||||
name=$1
|
|
||||||
val=
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
[ -n "$val" ] &&
|
|
||||||
val="$val $1" ||
|
|
||||||
val="$1"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
shift
|
|
||||||
done
|
|
||||||
if [ -n "${name}" ] && [ -w "${cgroup}/${name}" ] && [ -n "${val}" ]; then
|
|
||||||
veinfo "$RC_SVCNAME: Setting $cgroup/$name to $val"
|
|
||||||
printf "%s" "$val" > "$cgroup/$name"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -w "$cgroup/tasks" ]; then
|
|
||||||
veinfo "$RC_SVCNAME: adding to $cgroup/tasks"
|
|
||||||
printf "%d" 0 > "$cgroup/tasks"
|
|
||||||
fi
|
|
||||||
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
cgroup_add_service()
|
|
||||||
{
|
|
||||||
# relocate starting process to the top of the cgroup
|
|
||||||
# it prevents from unwanted inheriting of the user
|
|
||||||
# cgroups. But may lead to a problems where that inheriting
|
|
||||||
# is needed.
|
|
||||||
for d in /sys/fs/cgroup/* ; do
|
|
||||||
[ -w "${d}"/tasks ] && printf "%d" 0 > "${d}"/tasks
|
|
||||||
done
|
|
||||||
|
|
||||||
openrc_cgroup=/sys/fs/cgroup/openrc
|
|
||||||
if [ -d "$openrc_cgroup" ]; then
|
|
||||||
cgroup="$openrc_cgroup/$RC_SVCNAME"
|
|
||||||
mkdir -p "$cgroup"
|
|
||||||
[ -w "$cgroup/tasks" ] && printf "%d" 0 > "$cgroup/tasks"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
cgroup_set_limits()
|
|
||||||
{
|
|
||||||
local blkio="${rc_cgroup_blkio:-$RC_CGROUP_BLKIO}"
|
|
||||||
[ -n "$blkio" ] && cgroup_set_values blkio "$blkio"
|
|
||||||
|
|
||||||
local cpu="${rc_cgroup_cpu:-$RC_CGROUP_CPU}"
|
|
||||||
[ -n "$cpu" ] && cgroup_set_values cpu "$cpu"
|
|
||||||
|
|
||||||
local cpuacct="${rc_cgroup_cpuacct:-$RC_CGROUP_CPUACCT}"
|
|
||||||
[ -n "$cpuacct" ] && cgroup_set_values cpuacct "$cpuacct"
|
|
||||||
|
|
||||||
local cpuset="${rc_cgroup_cpuset:-$RC_CGROUP_cpuset}"
|
|
||||||
[ -n "$cpuset" ] && cgroup_set_values cpuset "$cpuset"
|
|
||||||
|
|
||||||
local devices="${rc_cgroup_devices:-$RC_CGROUP_DEVICES}"
|
|
||||||
[ -n "$devices" ] && cgroup_set_values devices "$devices"
|
|
||||||
|
|
||||||
local hugetlb="${rc_cgroup_hugetlb:-$RC_CGROUP_HUGETLB}"
|
|
||||||
[ -n "$hugetlb" ] && cgroup_set_values hugetlb "$hugetlb"
|
|
||||||
|
|
||||||
local memory="${rc_cgroup_memory:-$RC_CGROUP_MEMORY}"
|
|
||||||
[ -n "$memory" ] && cgroup_set_values memory "$memory"
|
|
||||||
|
|
||||||
local net_cls="${rc_cgroup_net_cls:-$RC_CGROUP_NET_CLS}"
|
|
||||||
[ -n "$net_cls" ] && cgroup_set_values net_cls "$net_cls"
|
|
||||||
|
|
||||||
local net_prio="${rc_cgroup_net_prio:-$RC_CGROUP_NET_PRIO}"
|
|
||||||
[ -n "$net_prio" ] && cgroup_set_values net_prio "$net_prio"
|
|
||||||
|
|
||||||
local pids="${rc_cgroup_pids:-$RC_CGROUP_PIDS}"
|
|
||||||
[ -n "$pids" ] && cgroup_set_values pids "$pids"
|
|
||||||
|
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cgroup2_find_path()
|
cgroup2_find_path()
|
||||||
{
|
{
|
||||||
if grep -qw cgroup2 /proc/filesystems; then
|
if grep -qw cgroup2 /proc/filesystems; then
|
||||||
case "${rc_cgroup_mode:-unified}" in
|
printf "/sys/fs/cgroup"
|
||||||
hybrid) printf "/sys/fs/cgroup/unified" ;;
|
|
||||||
unified) printf "/sys/fs/cgroup" ;;
|
|
||||||
esac
|
|
||||||
fi
|
fi
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user