Pull scheduler fixes from Ingo Molnar: "Misc fixes all over the place: - Fix NUMA over-balancing between lightly loaded nodes. This is fallout of the big load-balancer rewrite. - Fix the NOHZ remote loadavg update logic, which fixes anomalies like reported 150 loadavg on mostly idle CPUs. - Fix XFS performance/scalability - Fix throttled groups unbound task-execution bug - Fix PSI procfs boundary condition - Fix the cpu.uclamp.{min,max} cgroup configuration write checks - Fix DocBook annotations - Fix RCU annotations - Fix overly CPU-intensive housekeeper CPU logic loop on large CPU counts" * 'sched-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: sched/fair: Fix kernel-doc warning in attach_entity_load_avg() sched/core: Annotate curr pointer in rq with __rcu sched/psi: Fix OOB write when writing 0 bytes to PSI files sched/fair: Allow a per-CPU kthread waking a task to stack on the same CPU, to fix XFS performance regression sched/fair: Prevent unlimited runtime on throttled group sched/nohz: Optimize get_nohz_timer_target() sched/uclamp: Reject negative values in cpu_uclamp_write() sched/fair: Allow a small load imbalance between low utilisation SD_NUMA domains timers/nohz: Update NOHZ load in remote tick sched/core: Don't skip remote tick for idle CPUs
Unified · Split
| @@ -15,9 +15,11 @@ static inline void nohz_balance_enter_idle(int cpu) { } · 14 unmodified lines | |||
| 15 | 15 | ||
| 16 | #ifdef CONFIG_NO_HZ_COMMON | 16 | #ifdef CONFIG_NO_HZ_COMMON |
| 17 | void calc_load_nohz_start(void); | 17 | void calc_load_nohz_start(void); |
| 18 | void calc_load_nohz_remote(struct rq *rq); | ||
| 18 | void calc_load_nohz_stop(void); | 19 | void calc_load_nohz_stop(void); |
| 19 | #else | 20 | #else |
| 20 | static inline void calc_load_nohz_start(void) { } | 21 | static inline void calc_load_nohz_start(void) { } |
| 22 | static inline void calc_load_nohz_remote(struct rq *rq) { } | ||
| 21 | static inline void calc_load_nohz_stop(void) { } | 23 | static inline void calc_load_nohz_stop(void) { } |
| 22 | #endif /* CONFIG_NO_HZ_COMMON */ | 24 | #endif /* CONFIG_NO_HZ_COMMON */ |
| 23 | 25 | ||
| @@ -552,27 +552,32 @@ void resched_cpu(int cpu) · 551 unmodified lines | |||
| 552 | */ | 552 | */ |
| 553 | int get_nohz_timer_target(void) | 553 | int get_nohz_timer_target(void) |
| 554 | { | 554 | { |
| 555 | int i, cpu = smp_processor_id(); | 555 | int i, cpu = smp_processor_id(), default_cpu = -1; |
| 556 | struct sched_domain *sd; | 556 | struct sched_domain *sd; |
| 557 | 557 | ||
| 558 | if (!idle_cpu(cpu) && housekeeping_cpu(cpu, HK_FLAG_TIMER)) | 558 | if (housekeeping_cpu(cpu, HK_FLAG_TIMER)) { |
| 559 | return cpu; | 559 | if (!idle_cpu(cpu)) |
| 560 | return cpu; | ||
| 561 | default_cpu = cpu; | ||
| 562 | } | ||
| 560 | 563 | ||
| 561 | rcu_read_lock(); | 564 | rcu_read_lock(); |
| 562 | for_each_domain(cpu, sd) { | 565 | for_each_domain(cpu, sd) { |
| 563 | for_each_cpu(i, sched_domain_span(sd)) { | 566 | for_each_cpu_and(i, sched_domain_span(sd), |
| 567 | housekeeping_cpumask(HK_FLAG_TIMER)) { | ||
| 564 | if (cpu == i) | 568 | if (cpu == i) |
| 565 | continue; | 569 | continue; |
| 566 | 570 | ||
| 567 | if (!idle_cpu(i) && housekeeping_cpu(i, HK_FLAG_TIMER)) { | 571 | if (!idle_cpu(i)) { |
| 568 | cpu = i; | 572 | cpu = i; |
| 569 | goto unlock; | 573 | goto unlock; |
| 570 | } | 574 | } |
| 571 | } | 575 | } |
| 572 | } | 576 | } |
| 573 | 577 | ||
| 574 | if (!housekeeping_cpu(cpu, HK_FLAG_TIMER)) | 578 | if (default_cpu == -1) |
| 575 | cpu = housekeeping_any_cpu(HK_FLAG_TIMER); | 579 | default_cpu = housekeeping_any_cpu(HK_FLAG_TIMER); |
| 580 | cpu = default_cpu; | ||
| 576 | unlock: | 581 | unlock: |
| 577 | rcu_read_unlock(); | 582 | rcu_read_unlock(); |
| 578 | return cpu; | 583 | return cpu; |
| @@ -1442,17 +1447,6 @@ void check_preempt_curr(struct rq *rq, struct task_struct *p, int flags) · 863 unmodified lines | |||
| 1442 | 1447 | ||
| 1443 | #ifdef CONFIG_SMP | 1448 | #ifdef CONFIG_SMP |
| 1444 | 1449 | ||
| 1445 | static inline bool is_per_cpu_kthread(struct task_struct *p) | ||
| 1446 | { | ||
| 1447 | if (!(p->flags & PF_KTHREAD)) | ||
| 1448 | return false; | ||
| 1449 | |||
| 1450 | if (p->nr_cpus_allowed != 1) | ||
| 1451 | return false; | ||
| 1452 | |||
| 1453 | return true; | ||
| 1454 | } | ||
| 1455 | |||
| 1456 | /* | 1450 | /* |
| 1457 | * Per-CPU kthreads are allowed to run on !active && online CPUs, see | 1451 | * Per-CPU kthreads are allowed to run on !active && online CPUs, see |
| 1458 | * __set_cpus_allowed_ptr() and select_fallback_rq(). | 1452 | * __set_cpus_allowed_ptr() and select_fallback_rq(). |
| @@ -3669,28 +3663,32 @@ static void sched_tick_remote(struct work_struct *work) · 2210 unmodified lines | |||
| 3669 | * statistics and checks timeslices in a time-independent way, regardless | 3663 | * statistics and checks timeslices in a time-independent way, regardless |
| 3670 | * of when exactly it is running. | 3664 | * of when exactly it is running. |
| 3671 | */ | 3665 | */ |
| 3672 | if (idle_cpu(cpu) || !tick_nohz_tick_stopped_cpu(cpu)) | 3666 | if (!tick_nohz_tick_stopped_cpu(cpu)) |
| 3673 | goto out_requeue; | 3667 | goto out_requeue; |
| 3674 | 3668 | ||
| 3675 | rq_lock_irq(rq, &rf); | 3669 | rq_lock_irq(rq, &rf); |
| 3676 | curr = rq->curr; | 3670 | curr = rq->curr; |
| 3677 | if (is_idle_task(curr) || cpu_is_offline(cpu)) | 3671 | if (cpu_is_offline(cpu)) |
| 3678 | goto out_unlock; | 3672 | goto out_unlock; |
| 3679 | 3673 | ||
| 3674 | curr = rq->curr; | ||
| 3680 | update_rq_clock(rq); | 3675 | update_rq_clock(rq); |
| 3681 | delta = rq_clock_task(rq) - curr->se.exec_start; | ||
| 3682 | 3676 | ||
| 3683 | /* | 3677 | if (!is_idle_task(curr)) { |
| 3684 | * Make sure the next tick runs within a reasonable | 3678 | /* |
| 3685 | * amount of time. | 3679 | * Make sure the next tick runs within a reasonable |
| 3686 | */ | 3680 | * amount of time. |
| 3687 | WARN_ON_ONCE(delta > (u64)NSEC_PER_SEC * 3); | 3681 | */ |
| 3682 | delta = rq_clock_task(rq) - curr->se.exec_start; | ||
| 3683 | WARN_ON_ONCE(delta > (u64)NSEC_PER_SEC * 3); | ||
| 3684 | } | ||
| 3688 | curr->sched_class->task_tick(rq, curr, 0); | 3685 | curr->sched_class->task_tick(rq, curr, 0); |
| 3689 | 3686 | ||
| 3687 | calc_load_nohz_remote(rq); | ||
| 3690 | out_unlock: | 3688 | out_unlock: |
| 3691 | rq_unlock_irq(rq, &rf); | 3689 | rq_unlock_irq(rq, &rf); |
| 3692 | |||
| 3693 | out_requeue: | 3690 | out_requeue: |
| 3691 | |||
| 3694 | /* | 3692 | /* |
| 3695 | * Run the remote tick once per second (1Hz). This arbitrary | 3693 | * Run the remote tick once per second (1Hz). This arbitrary |
| 3696 | * frequency is large enough to avoid overload but short enough | 3694 | * frequency is large enough to avoid overload but short enough |
| @@ -7063,8 +7061,15 @@ void sched_move_task(struct task_struct *tsk) · 3366 unmodified lines | |||
| 7063 | 7061 | ||
| 7064 | if (queued) | 7062 | if (queued) |
| 7065 | enqueue_task(rq, tsk, queue_flags); | 7063 | enqueue_task(rq, tsk, queue_flags); |
| 7066 | if (running) | 7064 | if (running) { |
| 7067 | set_next_task(rq, tsk); | 7065 | set_next_task(rq, tsk); |
| 7066 | /* | ||
| 7067 | * After changing group, the running task may have joined a | ||
| 7068 | * throttled one but it's still the running task. Trigger a | ||
| 7069 | * resched to make sure that task can still run. | ||
| 7070 | */ | ||
| 7071 | resched_curr(rq); | ||
| 7072 | } | ||
| 7068 | 7073 | ||
| 7069 | task_rq_unlock(rq, tsk, &rf); | 7074 | task_rq_unlock(rq, tsk, &rf); |
| 7070 | } | 7075 | } |
| @@ -7260,7 +7265,7 @@ capacity_from_percent(char *buf) · 189 unmodified lines | |||
| 7260 | &req.percent); | 7265 | &req.percent); |
| 7261 | if (req.ret) | 7266 | if (req.ret) |
| 7262 | return req; | 7267 | return req; |
| 7263 | if (req.percent > UCLAMP_PERCENT_SCALE) { | 7268 | if ((u64)req.percent > UCLAMP_PERCENT_SCALE) { |
| 7264 | req.ret = -ERANGE; | 7269 | req.ret = -ERANGE; |
| 7265 | return req; | 7270 | return req; |
| 7266 | } | 7271 | } |
| @@ -3516,7 +3516,6 @@ update_cfs_rq_load_avg(u64 now, struct cfs_rq *cfs_rq) · 3515 unmodified lines | |||
| 3516 | * attach_entity_load_avg - attach this entity to its cfs_rq load avg | 3516 | * attach_entity_load_avg - attach this entity to its cfs_rq load avg |
| 3517 | * @cfs_rq: cfs_rq to attach to | 3517 | * @cfs_rq: cfs_rq to attach to |
| 3518 | * @se: sched_entity to attach | 3518 | * @se: sched_entity to attach |
| 3519 | * @flags: migration hints | ||
| 3520 | * | 3519 | * |
| 3521 | * Must call update_cfs_rq_load_avg() before this, since we rely on | 3520 | * Must call update_cfs_rq_load_avg() before this, since we rely on |
| 3522 | * cfs_rq->avg.last_update_time being current. | 3521 | * cfs_rq->avg.last_update_time being current. |
| @@ -5912,6 +5911,20 @@ static int select_idle_sibling(struct task_struct *p, int prev, int target) · 2389 unmodified lines | |||
| 5912 | (available_idle_cpu(prev) || sched_idle_cpu(prev))) | 5911 | (available_idle_cpu(prev) || sched_idle_cpu(prev))) |
| 5913 | return prev; | 5912 | return prev; |
| 5914 | 5913 | ||
| 5914 | /* | ||
| 5915 | * Allow a per-cpu kthread to stack with the wakee if the | ||
| 5916 | * kworker thread and the tasks previous CPUs are the same. | ||
| 5917 | * The assumption is that the wakee queued work for the | ||
| 5918 | * per-cpu kthread that is now complete and the wakeup is | ||
| 5919 | * essentially a sync wakeup. An obvious example of this | ||
| 5920 | * pattern is IO completions. | ||
| 5921 | */ | ||
| 5922 | if (is_per_cpu_kthread(current) && | ||
| 5923 | prev == smp_processor_id() && | ||
| 5924 | this_rq()->nr_running <= 1) { | ||
| 5925 | return prev; | ||
| 5926 | } | ||
| 5927 | |||
| 5915 | /* Check a recently used CPU as a potential idle candidate: */ | 5928 | /* Check a recently used CPU as a potential idle candidate: */ |
| 5916 | recent_used_cpu = p->recent_used_cpu; | 5929 | recent_used_cpu = p->recent_used_cpu; |
| 5917 | if (recent_used_cpu != prev && | 5930 | if (recent_used_cpu != prev && |
| @@ -8658,10 +8671,6 @@ static inline void calculate_imbalance(struct lb_env *env, struct sd_lb_stats *s · 2740 unmodified lines | |||
| 8658 | /* | 8671 | /* |
| 8659 | * Try to use spare capacity of local group without overloading it or | 8672 | * Try to use spare capacity of local group without overloading it or |
| 8660 | * emptying busiest. | 8673 | * emptying busiest. |
| 8661 | * XXX Spreading tasks across NUMA nodes is not always the best policy | ||
| 8662 | * and special care should be taken for SD_NUMA domain level before | ||
| 8663 | * spreading the tasks. For now, load_balance() fully relies on | ||
| 8664 | * NUMA_BALANCING and fbq_classify_group/rq to override the decision. | ||
| 8665 | */ | 8674 | */ |
| 8666 | if (local->group_type == group_has_spare) { | 8675 | if (local->group_type == group_has_spare) { |
| 8667 | if (busiest->group_type > group_fully_busy) { | 8676 | if (busiest->group_type > group_fully_busy) { |
| @@ -8701,16 +8710,37 @@ static inline void calculate_imbalance(struct lb_env *env, struct sd_lb_stats *s · 33 unmodified lines | |||
| 8701 | env->migration_type = migrate_task; | 8710 | env->migration_type = migrate_task; |
| 8702 | lsub_positive(&nr_diff, local->sum_nr_running); | 8711 | lsub_positive(&nr_diff, local->sum_nr_running); |
| 8703 | env->imbalance = nr_diff >> 1; | 8712 | env->imbalance = nr_diff >> 1; |
| 8704 | return; | 8713 | } else { |
| 8705 | } | ||
| 8706 | 8714 | ||
| 8707 | /* | 8715 | /* |
| 8708 | * If there is no overload, we just want to even the number of | 8716 | * If there is no overload, we just want to even the number of |
| 8709 | * idle cpus. | 8717 | * idle cpus. |
| 8710 | */ | 8718 | */ |
| 8711 | env->migration_type = migrate_task; | 8719 | env->migration_type = migrate_task; |
| 8712 | env->imbalance = max_t(long, 0, (local->idle_cpus - | 8720 | env->imbalance = max_t(long, 0, (local->idle_cpus - |
| 8713 | busiest->idle_cpus) >> 1); | 8721 | busiest->idle_cpus) >> 1); |
| 8722 | } | ||
| 8723 | |||
| 8724 | /* Consider allowing a small imbalance between NUMA groups */ | ||
| 8725 | if (env->sd->flags & SD_NUMA) { | ||
| 8726 | unsigned int imbalance_min; | ||
| 8727 | |||
| 8728 | /* | ||
| 8729 | * Compute an allowed imbalance based on a simple | ||
| 8730 | * pair of communicating tasks that should remain | ||
| 8731 | * local and ignore them. | ||
| 8732 | * | ||
| 8733 | * NOTE: Generally this would have been based on | ||
| 8734 | * the domain size and this was evaluated. However, | ||
| 8735 | * the benefit is similar across a range of workloads | ||
| 8736 | * and machines but scaling by the domain size adds | ||
| 8737 | * the risk that lower domains have to be rebalanced. | ||
| 8738 | */ | ||
| 8739 | imbalance_min = 2; | ||
| 8740 | if (busiest->sum_nr_running <= imbalance_min) | ||
| 8741 | env->imbalance = 0; | ||
| 8742 | } | ||
| 8743 | |||
| 8714 | return; | 8744 | return; |
| 8715 | } | 8745 | } |
| 8716 | 8746 | ||
| @@ -231,16 +231,11 @@ static inline int calc_load_read_idx(void) · 230 unmodified lines | |||
| 231 | return calc_load_idx & 1; | 231 | return calc_load_idx & 1; |
| 232 | } | 232 | } |
| 233 | 233 | ||
| 234 | void calc_load_nohz_start(void) | 234 | static void calc_load_nohz_fold(struct rq *rq) |
| 235 | { | 235 | { |
| 236 | struct rq *this_rq = this_rq(); | ||
| 237 | long delta; | 236 | long delta; |
| 238 | 237 | ||
| 239 | /* | 238 | delta = calc_load_fold_active(rq, 0); |
| 240 | * We're going into NO_HZ mode, if there's any pending delta, fold it | ||
| 241 | * into the pending NO_HZ delta. | ||
| 242 | */ | ||
| 243 | delta = calc_load_fold_active(this_rq, 0); | ||
| 244 | if (delta) { | 239 | if (delta) { |
| 245 | int idx = calc_load_write_idx(); | 240 | int idx = calc_load_write_idx(); |
| 246 | 241 | ||
| @@ -248,6 +243,24 @@ void calc_load_nohz_start(void) · 1 unmodified line | |||
| 248 | } | 243 | } |
| 249 | } | 244 | } |
| 250 | 245 | ||
| 246 | void calc_load_nohz_start(void) | ||
| 247 | { | ||
| 248 | /* | ||
| 249 | * We're going into NO_HZ mode, if there's any pending delta, fold it | ||
| 250 | * into the pending NO_HZ delta. | ||
| 251 | */ | ||
| 252 | calc_load_nohz_fold(this_rq()); | ||
| 253 | } | ||
| 254 | |||
| 255 | /* | ||
| 256 | * Keep track of the load for NOHZ_FULL, must be called between | ||
| 257 | * calc_load_nohz_{start,stop}(). | ||
| 258 | */ | ||
| 259 | void calc_load_nohz_remote(struct rq *rq) | ||
| 260 | { | ||
| 261 | calc_load_nohz_fold(rq); | ||
| 262 | } | ||
| 263 | |||
| 251 | void calc_load_nohz_stop(void) | 264 | void calc_load_nohz_stop(void) |
| 252 | { | 265 | { |
| 253 | struct rq *this_rq = this_rq(); | 266 | struct rq *this_rq = this_rq(); |
| @@ -268,7 +281,7 @@ void calc_load_nohz_stop(void) · 14 unmodified lines | |||
| 268 | this_rq->calc_load_update += LOAD_FREQ; | 281 | this_rq->calc_load_update += LOAD_FREQ; |
| 269 | } | 282 | } |
| 270 | 283 | ||
| 271 | static long calc_load_nohz_fold(void) | 284 | static long calc_load_nohz_read(void) |
| 272 | { | 285 | { |
| 273 | int idx = calc_load_read_idx(); | 286 | int idx = calc_load_read_idx(); |
| 274 | long delta = 0; | 287 | long delta = 0; |
| @@ -323,7 +336,7 @@ static void calc_global_nohz(void) · 48 unmodified lines | |||
| 323 | } | 336 | } |
| 324 | #else /* !CONFIG_NO_HZ_COMMON */ | 337 | #else /* !CONFIG_NO_HZ_COMMON */ |
| 325 | 338 | ||
| 326 | static inline long calc_load_nohz_fold(void) { return 0; } | 339 | static inline long calc_load_nohz_read(void) { return 0; } |
| 327 | static inline void calc_global_nohz(void) { } | 340 | static inline void calc_global_nohz(void) { } |
| 328 | 341 | ||
| 329 | #endif /* CONFIG_NO_HZ_COMMON */ | 342 | #endif /* CONFIG_NO_HZ_COMMON */ |
| @@ -346,7 +359,7 @@ void calc_global_load(unsigned long ticks) · 16 unmodified lines | |||
| 346 | /* | 359 | /* |
| 347 | * Fold the 'old' NO_HZ-delta to include all NO_HZ CPUs. | 360 | * Fold the 'old' NO_HZ-delta to include all NO_HZ CPUs. |
| 348 | */ | 361 | */ |
| 349 | delta = calc_load_nohz_fold(); | 362 | delta = calc_load_nohz_read(); |
| 350 | if (delta) | 363 | if (delta) |
| 351 | atomic_long_add(delta, &calc_load_tasks); | 364 | atomic_long_add(delta, &calc_load_tasks); |
| 352 | 365 | ||
| @@ -1199,6 +1199,9 @@ static ssize_t psi_write(struct file *file, const char __user *user_buf, · 1198 unmodified lines | |||
| 1199 | if (static_branch_likely(&psi_disabled)) | 1199 | if (static_branch_likely(&psi_disabled)) |
| 1200 | return -EOPNOTSUPP; | 1200 | return -EOPNOTSUPP; |
| 1201 | 1201 | ||
| 1202 | if (!nbytes) | ||
| 1203 | return -EINVAL; | ||
| 1204 | |||
| 1202 | buf_size = min(nbytes, sizeof(buf)); | 1205 | buf_size = min(nbytes, sizeof(buf)); |
| 1203 | if (copy_from_user(buf, user_buf, buf_size)) | 1206 | if (copy_from_user(buf, user_buf, buf_size)) |
| 1204 | return -EFAULT; | 1207 | return -EFAULT; |
| @@ -896,7 +896,7 @@ struct rq { · 895 unmodified lines | |||
| 896 | */ | 896 | */ |
| 897 | unsigned long nr_uninterruptible; | 897 | unsigned long nr_uninterruptible; |
| 898 | 898 | ||
| 899 | struct task_struct *curr; | 899 | struct task_struct __rcu *curr; |
| 900 | struct task_struct *idle; | 900 | struct task_struct *idle; |
| 901 | struct task_struct *stop; | 901 | struct task_struct *stop; |
| 902 | unsigned long next_balance; | 902 | unsigned long next_balance; |
| @@ -2479,3 +2479,16 @@ static inline void membarrier_switch_mm(struct rq *rq, · 1576 unmodified lines | |||
| 2479 | { | 2479 | { |
| 2480 | } | 2480 | } |
| 2481 | #endif | 2481 | #endif |
| 2482 | |||
| 2483 | #ifdef CONFIG_SMP | ||
| 2484 | static inline bool is_per_cpu_kthread(struct task_struct *p) | ||
| 2485 | { | ||
| 2486 | if (!(p->flags & PF_KTHREAD)) | ||
| 2487 | return false; | ||
| 2488 | |||
| 2489 | if (p->nr_cpus_allowed != 1) | ||
| 2490 | return false; | ||
| 2491 | |||
| 2492 | return true; | ||
| 2493 | } | ||
| 2494 | #endif | ||