History

Posix timers: limit number of timers firing at once

Bursty timers aren't good for anybody, very much including latency for other programs when we trigger lots of timers in interrupt context. So set a random limit, after which we'll handle the rest on the next timer tick. Noted by Oleg Nesterov <oleg@tv-sign.ru>

Linus Torvalds committed 21 years ago

Commit e80eda91 parent d475f3f1 file · +14 −6Browse files

Showing the changes to kernel (1 of 1 file). Show all

Unified · Split

kernel/posix-cpu-timers.c+14−6
@@ -961,14 +961,16 @@ void posix_cpu_timer_get(struct k_itimer *timer, struct itimerspec *itp) · 960 unmodified lines
961961 static void check_thread_timers(struct task_struct *tsk,
962962 struct list_head *firing)
963963 {
964+ int maxfire;
964965 struct list_head *timers = tsk->cpu_timers;
965966
967+ maxfire = 20;
966968 tsk->it_prof_expires = cputime_zero;
967969 while (!list_empty(timers)) {
968970 struct cpu_timer_list *t = list_entry(timers->next,
969971 struct cpu_timer_list,
970972 entry);
971− if (cputime_lt(prof_ticks(tsk), t->expires.cpu)) {
973+ if (!--maxfire || cputime_lt(prof_ticks(tsk), t->expires.cpu)) {
972974 tsk->it_prof_expires = t->expires.cpu;
973975 break;
974976 }
@@ -977,12 +979,13 @@ static void check_thread_timers(struct task_struct *tsk, · 2 unmodified lines
977979 }
978980
979981 ++timers;
982+ maxfire = 20;
980983 tsk->it_virt_expires = cputime_zero;
981984 while (!list_empty(timers)) {
982985 struct cpu_timer_list *t = list_entry(timers->next,
983986 struct cpu_timer_list,
984987 entry);
985− if (cputime_lt(virt_ticks(tsk), t->expires.cpu)) {
988+ if (!--maxfire || cputime_lt(virt_ticks(tsk), t->expires.cpu)) {
986989 tsk->it_virt_expires = t->expires.cpu;
987990 break;
988991 }
@@ -991,12 +994,13 @@ static void check_thread_timers(struct task_struct *tsk, · 2 unmodified lines
991994 }
992995
993996 ++timers;
997+ maxfire = 20;
994998 tsk->it_sched_expires = 0;
995999 while (!list_empty(timers)) {
9961000 struct cpu_timer_list *t = list_entry(timers->next,
9971001 struct cpu_timer_list,
9981002 entry);
999− if (tsk->sched_time < t->expires.sched) {
1003+ if (!--maxfire || tsk->sched_time < t->expires.sched) {
10001004 tsk->it_sched_expires = t->expires.sched;
10011005 break;
10021006 }
@@ -1013,6 +1017,7 @@ static void check_thread_timers(struct task_struct *tsk, · 10 unmodified lines
10131017 static void check_process_timers(struct task_struct *tsk,
10141018 struct list_head *firing)
10151019 {
1020+ int maxfire;
10161021 struct signal_struct *const sig = tsk->signal;
10171022 cputime_t utime, stime, ptime, virt_expires, prof_expires;
10181023 unsigned long long sched_time, sched_expires;
@@ -1045,12 +1050,13 @@ static void check_process_timers(struct task_struct *tsk, · 26 unmodified lines
10451050 } while (t != tsk);
10461051 ptime = cputime_add(utime, stime);
10471052
1053+ maxfire = 20;
10481054 prof_expires = cputime_zero;
10491055 while (!list_empty(timers)) {
10501056 struct cpu_timer_list *t = list_entry(timers->next,
10511057 struct cpu_timer_list,
10521058 entry);
1053− if (cputime_lt(ptime, t->expires.cpu)) {
1059+ if (!--maxfire || cputime_lt(ptime, t->expires.cpu)) {
10541060 prof_expires = t->expires.cpu;
10551061 break;
10561062 }
@@ -1059,12 +1065,13 @@ static void check_process_timers(struct task_struct *tsk, · 2 unmodified lines
10591065 }
10601066
10611067 ++timers;
1068+ maxfire = 20;
10621069 virt_expires = cputime_zero;
10631070 while (!list_empty(timers)) {
10641071 struct cpu_timer_list *t = list_entry(timers->next,
10651072 struct cpu_timer_list,
10661073 entry);
1067− if (cputime_lt(utime, t->expires.cpu)) {
1074+ if (!--maxfire || cputime_lt(utime, t->expires.cpu)) {
10681075 virt_expires = t->expires.cpu;
10691076 break;
10701077 }
@@ -1073,12 +1080,13 @@ static void check_process_timers(struct task_struct *tsk, · 2 unmodified lines
10731080 }
10741081
10751082 ++timers;
1083+ maxfire = 20;
10761084 sched_expires = 0;
10771085 while (!list_empty(timers)) {
10781086 struct cpu_timer_list *t = list_entry(timers->next,
10791087 struct cpu_timer_list,
10801088 entry);
1081− if (sched_time < t->expires.sched) {
1089+ if (!--maxfire || sched_time < t->expires.sched) {
10821090 sched_expires = t->expires.sched;
10831091 break;
10841092 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t