安装libpam-systemd

时间:2015-12-01 11:11:42

标签: linux pam ubuntu-15.04

尝试使用SCHED_FIFO政策将sched优先级设置为max。安装libpam-systemd后,此代码开始抛出错误。

编辑:归结为以下两个问题,尽可能清楚地说明这些问题。

strace的:

  

sched_setscheduler(564,SCHED_FIFO,{99})= -1 EPERM(操作不是   允许的)

param.sched_priority = sched_get_priority_max(SCHED_FIFO);
printf("priority %d \n", param.sched_priority);

ret1 = sched_setscheduler(getpid(), SCHED_FIFO, &param);
printf("sched_setscheduler ret %d \n", ret1);
if(ret1 == -1){
    perror("sched_setscheduler");
    goto fail;
}

问题:root用户为什么要获得EPERM?

还尝试在/etc/security/limits.conf下面设置,但没有运气。

root   soft   rtprio       99    
root   hard   rtprio       99

来自KENREL CONFIG FILE

#CONFIG_SCHED_AUTOGROUP is not set
CONFIG_CGROUP_SCHED=y
CONFIG_FAIR_GROUP_SCHED=y
CONFIG_CFS_BANDWIDTH=y
CONFIG_RT_GROUP_SCHED=y
CONFIG_GENERIC_SCHED_CLOCK=y
CONFIG_CGROUPS=y
CONFIG_CGROUP_DEBUG=y
CONFIG_CGROUP_FREEZER=y

更新 文件linux/kernel/sched/core.c

中的内核代码出错
#ifdef CONFIG_RT_GROUP_SCHED
    /*
     * Do not allow realtime tasks into groups that have no runtime
     * assigned.
     */
    if (rt_bandwidth_enabled() && rt_policy(policy) &&
            task_group(p)->rt_bandwidth.rt_runtime == 0 &&
            !task_group_is_autogroup(task_group(p))) {
        task_rq_unlock(rq, p, &flags);
        return -EPERM;
    }
#endif

通过案例:没有libpam-systemd,我会得到以下值

[   36.278241] rt_bandwidth_enabled(): 1 
[   36.281977] rt_policy(policy) : 1 
[   36.285367] task_group_is_autogroup(task_group(p)) : 0 
[   36.289883] task_group(p)->rt_bandwidth.rt_runtime : 950000000 

失败案例:使用libpam-systemd,我得到以下值

[ 2096.713855] rt_bandwidth_enabled(): 1 
[ 2096.717871] rt_policy(policy) : 1 
[ 2096.721408] task_group_is_autogroup(task_group(p)) : 0 
[ 2096.726180] task_group(p)->rt_bandwidth.rt_runtime: 0

问题:为什么libpam-systemd会修改root用户的rt运行时带宽?

来自proc

的计划程序RT运行时值
root@jarvis:/home/jarvis# cat /proc/sys/kernel/sched_rt_runtime_us 
950000
root@jarvis:/home/jarvis# cat /proc/sys/kernel/sched_rt_period_us
1000000

任何帮助都非常感谢。

1 个答案:

答案 0 :(得分:3)

systemd为每个用户和每个服务创建一个单独的cgroup。检查/proc/self/cgroup以查看差异。请注意,known problems有RT调度:

    We recommend to turn off Real-Time group scheduling in the
    kernel when using systemd. RT group scheduling effectively
    makes RT scheduling unavailable for most userspace, since it
    requires explicit assignment of RT budgets to each unit whose
    processes making use of RT. As there's no sensible way to
    assign these budgets automatically this cannot really be
    fixed, and it's best to disable group scheduling hence.
       CONFIG_RT_GROUP_SCHED=n