<s>
The	O
Brain	B-Application
Fuck	I-Application
Scheduler	I-Application
(	O
BFS	O
)	O
is	O
a	O
process	O
scheduler	O
designed	O
for	O
the	O
Linux	B-Operating_System
kernel	I-Operating_System
in	O
August	O
2009	O
as	O
an	O
alternative	O
to	O
the	O
Completely	B-Application
Fair	I-Application
Scheduler	I-Application
(	O
CFS	O
)	O
and	O
the	O
O(1 )	O
scheduler	O
.	O
</s>
<s>
BFS	O
was	O
created	O
by	O
an	O
experienced	O
kernel	B-Operating_System
programmer	O
Con	O
Kolivas	O
.	O
</s>
<s>
The	O
objective	O
of	O
BFS	O
,	O
compared	O
to	O
other	O
schedulers	O
,	O
is	O
to	O
provide	O
a	O
scheduler	O
with	O
a	O
simpler	O
algorithm	O
,	O
that	O
does	O
not	O
require	O
adjustment	O
of	O
heuristics	B-Algorithm
or	O
tuning	O
parameters	O
to	O
tailor	O
performance	O
to	O
a	O
specific	O
type	O
of	O
computational	O
workload	O
.	O
</s>
<s>
BFS	O
has	O
been	O
reported	O
to	O
improve	O
responsiveness	O
on	O
Linux	B-Operating_System
desktop	O
computers	O
with	O
fewer	O
than	O
16	O
cores	B-Architecture
.	O
</s>
<s>
Shortly	O
following	O
its	O
introduction	O
,	O
the	O
new	O
scheduler	O
made	O
headlines	O
within	O
the	O
Linux	B-Operating_System
community	O
,	O
appearing	O
on	O
Slashdot	O
,	O
with	O
reviews	O
in	O
Linux	B-Operating_System
Magazine	O
and	O
Linux	B-Operating_System
Pro	O
Magazine	O
.	O
</s>
<s>
Although	O
there	O
have	O
been	O
varied	O
reviews	O
of	O
improved	O
performance	O
and	O
responsiveness	O
,	O
Con	O
Kolivas	O
did	O
not	O
intend	O
for	O
BFS	O
to	O
be	O
integrated	O
into	O
the	O
mainline	O
kernel	B-Operating_System
.	O
</s>
<s>
In	O
2009	O
,	O
BFS	O
was	O
introduced	O
and	O
had	O
originally	O
used	O
a	O
doubly	B-Data_Structure
linked	I-Data_Structure
list	I-Data_Structure
data	O
structure	O
,	O
but	O
the	O
data	O
structure	O
is	O
treated	O
like	O
a	O
queue	B-Operating_System
.	O
</s>
<s>
It	O
uses	O
a	O
single	O
global	O
run	B-Application
queue	I-Application
which	O
all	O
CPUs	O
use	O
.	O
</s>
<s>
Tasks	O
are	O
ordered	O
(	O
or	O
distributed	O
)	O
and	O
chosen	O
based	O
on	O
the	O
virtual	O
deadline	O
formula	O
in	O
all	O
policies	O
except	O
for	O
the	O
realtime	B-General_Concept
and	O
Isochronous	O
priority	O
classes	O
.	O
</s>
<s>
The	O
execution	O
behavior	O
is	O
still	O
a	O
weighted	O
variation	O
of	O
the	O
Round-Robin	B-Algorithm
Scheduler	I-Algorithm
especially	O
when	O
tasks	O
have	O
the	O
same	O
priority	O
below	O
the	O
Isochronous	O
policy	O
.	O
</s>
<s>
All	O
tasks	O
get	O
the	O
same	O
time	O
slice	O
with	O
the	O
exception	O
of	O
realtime	B-General_Concept
FIFO	B-Operating_System
which	O
is	O
assumed	O
to	O
have	O
infinite	O
time	O
slice	O
.	O
</s>
<s>
Kolivas	O
explained	O
the	O
reason	O
why	O
he	O
choose	O
to	O
go	O
with	O
the	O
doubly	B-Data_Structure
linked	I-Data_Structure
list	I-Data_Structure
mono-runqueue	O
than	O
the	O
multi-runqueue	O
(	O
round	O
robin	O
)	O
priority	O
array	O
per	O
CPU	O
that	O
was	O
used	O
in	O
his	O
RDSL	O
scheduler	O
was	O
to	O
put	O
to	O
ease	O
fairness	O
among	O
the	O
multiple	O
CPU	O
scenario	O
and	O
remove	O
complexity	O
that	O
each	O
runqueue	O
in	O
a	O
multi-runqueue	O
scenario	O
had	O
to	O
maintain	O
its	O
own	O
latencies	O
and	O
 [ task ] 	O
fairness	O
.	O
</s>
<s>
The	O
virtual	O
deadline	O
formula	O
is	O
a	O
future	O
deadline	O
time	O
that	O
is	O
the	O
scaled	O
round	O
robin	O
timeslice	O
based	O
on	O
the	O
nice	B-Device
level	I-Device
offset	O
by	O
the	O
current	O
time	O
(	O
in	O
niffy	O
units	O
or	O
nanosecond	O
jiffies	B-Operating_System
,	O
an	O
internal	O
kernel	B-Operating_System
time	O
counter	O
)	O
.	O
</s>
<s>
It	O
increases	O
10%	O
each	O
nice	B-Device
level	I-Device
.	O
</s>
<s>
It	O
follows	O
a	O
parabolic	O
pattern	O
if	O
graphed	O
,	O
and	O
the	O
niced	O
tasks	O
are	O
distributed	O
as	O
a	O
moving	O
squared	O
function	O
from	O
0	O
to	O
39	O
(	O
corresponding	O
from	O
highest	O
to	O
lowest	O
nice	B-Device
priority	O
)	O
as	O
the	O
domain	O
and	O
128	O
to	O
5089	O
as	O
the	O
range	O
.	O
</s>
<s>
The	O
task	O
's	O
nice-to-index	O
mapping	O
function	O
is	O
mapped	O
from	O
nice	B-Device
−	O
20	O
...	O
19	O
to	O
index	O
0	O
...	O
39	O
to	O
be	O
used	O
as	O
the	O
input	O
to	O
the	O
prio	O
ratio	O
lookup	O
table	O
.	O
</s>
<s>
This	O
mapping	O
function	O
is	O
the	O
macro	O
in	O
sched.h	O
in	O
the	O
kernel	B-Operating_System
header	I-Operating_System
.	O
</s>
<s>
The	O
internal	O
kernel	B-Operating_System
implementation	O
slightly	O
differs	O
with	O
range	O
between	O
100	O
and	O
140	O
static	O
priority	O
but	O
users	O
will	O
see	O
it	O
as	O
−	O
20	O
...	O
19	O
nice	B-Device
.	O
</s>
<s>
where	O
is	O
the	O
virtual	O
deadline	O
in	O
u64	O
integer	O
nanoseconds	O
as	O
a	O
function	O
of	O
nice	B-Device
and	O
which	O
is	O
the	O
current	O
time	O
in	O
niffies	O
,	O
is	O
the	O
prio	O
ratio	O
table	O
lookup	O
as	O
a	O
function	O
of	O
index	O
,	O
is	O
the	O
task	O
's	O
nice-to-index	O
mapping	O
function	O
,	O
is	O
the	O
round	O
robin	O
timeslice	O
in	O
milliseconds	O
,	O
is	O
a	O
constant	O
of	O
1	O
millisecond	O
in	O
terms	O
of	O
nanoseconds	O
as	O
a	O
latency	O
reducing	O
approximation	O
of	O
the	O
conversion	O
factor	O
of	O
but	O
Kolivas	O
uses	O
a	O
base	O
2	O
constant	O
with	O
approximately	O
that	O
scale	O
.	O
</s>
<s>
Smaller	O
values	O
of	O
mean	O
that	O
the	O
virtual	O
deadline	O
is	O
earlier	O
corresponding	O
to	O
negative	O
nice	B-Device
values	O
.	O
</s>
<s>
Larger	O
values	O
of	O
indicate	O
the	O
virtual	O
deadline	O
is	O
pushed	O
back	O
later	O
corresponding	O
to	O
positive	O
nice	B-Device
values	O
.	O
</s>
<s>
In	O
the	O
v0.462	O
edition	O
(	O
used	O
in	O
the	O
-ck	O
4.0	O
kernel	B-Operating_System
patchset	O
)	O
,	O
there	O
are	O
total	O
of	O
103	O
"	O
priority	O
queues	O
"	O
(	O
aka	O
prio	O
)	O
or	O
allowed	O
values	O
that	O
it	O
can	O
take	O
.	O
</s>
<s>
No	O
actual	O
special	O
data	O
structure	O
was	O
used	O
as	O
the	O
priority	O
queue	B-Operating_System
but	O
only	O
the	O
doubly	B-Data_Structure
linked	I-Data_Structure
list	I-Data_Structure
runqueue	O
itself	O
.	O
</s>
<s>
The	O
realtime	B-General_Concept
policy	O
was	O
designed	O
for	O
realtime	B-General_Concept
tasks	O
.	O
</s>
<s>
Priority	O
classes	O
considered	O
under	O
the	O
realtime	B-General_Concept
policy	O
by	O
the	O
scheduler	O
are	O
those	O
marked	O
SCHED_RR	O
and	O
SCHED_FIFO	O
.	O
</s>
<s>
The	O
scheduler	O
treats	O
realtime	B-General_Concept
round	O
robin	O
(	O
SCHED_RR	O
)	O
and	O
realtime	B-General_Concept
FIFO	B-Operating_System
(	O
SCHED_FIFO	O
)	O
differently	O
.	O
</s>
<s>
The	O
task	O
that	O
will	O
get	O
chosen	O
for	O
execution	O
is	O
based	O
on	O
task	O
availability	O
of	O
the	O
lowest	O
value	O
of	O
prio	O
of	O
the	O
100	O
queues	O
and	O
FIFO	B-Operating_System
scheduling	O
.	O
</s>
<s>
On	O
forks	B-Language
,	O
the	O
process	O
priority	O
will	O
be	O
demoted	O
to	O
normal	O
policy	O
.	O
</s>
<s>
non-root	O
user	O
)	O
of	O
sched_setscheduler	O
called	O
with	O
a	O
request	O
for	O
realtime	B-General_Concept
policy	O
class	O
,	O
the	O
scheduler	O
will	O
demote	O
the	O
task	O
to	O
Isochronous	O
policy	O
.	O
</s>
<s>
The	O
Isochronous	O
policy	O
was	O
designed	O
for	O
near	O
realtime	B-General_Concept
performance	O
for	O
non-root	O
users	O
.	O
</s>
<s>
The	O
design	O
laid	O
out	O
1	O
priority	O
queue	B-Operating_System
that	O
by	O
default	O
ran	O
as	O
pseudo-realtime	O
tasks	O
,	O
but	O
can	O
be	O
tuned	O
as	O
a	O
degree	O
of	O
realtime	B-General_Concept
.	O
</s>
<s>
The	O
timer	O
frequency	O
is	O
set	O
to	O
250	O
by	O
default	O
and	O
editable	O
in	O
the	O
kernel	B-Operating_System
,	O
but	O
usually	O
tuned	O
to	O
100	O
Hz	O
for	O
servers	O
and	O
1000	O
Hz	O
for	O
interactive	O
desktops	O
.	O
</s>
<s>
Setting	O
to	O
100	O
made	O
tasks	O
behave	O
as	O
realtime	B-General_Concept
and	O
0	O
made	O
it	O
not	O
pseudo-realtime	O
and	O
anything	O
in	O
the	O
middle	O
was	O
pseudo-realtime	O
.	O
</s>
<s>
The	O
task	O
that	O
had	O
an	O
earliest	O
virtual	O
deadline	O
was	O
chosen	O
for	O
execution	O
,	O
but	O
when	O
multiple	O
Isochronous	O
tasks	O
are	O
in	O
existence	O
,	O
they	O
schedule	O
as	O
round	O
robin	O
allowing	O
tasks	O
to	O
run	O
the	O
tuneable	O
round	O
robin	O
value	O
(	O
with	O
6	O
ms	O
as	O
the	O
default	O
)	O
one	O
after	O
another	O
in	O
a	O
fair	O
equal	O
chance	O
without	O
considering	O
the	O
nice	B-Device
level	I-Device
.	O
</s>
<s>
The	O
design	O
laid	O
out	O
one	O
priority	O
queue	B-Operating_System
and	O
tasks	O
are	O
chosen	O
to	O
be	O
executed	O
first	O
based	O
on	O
earliest	O
virtual	O
deadline	O
.	O
</s>
<s>
The	O
idle	O
priority	O
was	O
designed	O
for	O
background	O
processes	O
such	O
as	O
distributed	B-Architecture
programs	I-Architecture
and	O
transcoders	B-Algorithm
so	O
that	O
foreground	O
processes	O
or	O
those	O
above	O
this	O
scheduling	O
policy	O
can	O
run	O
uninterrupted	O
.	O
</s>
<s>
The	O
design	O
laid	O
out	O
1	O
priority	O
queue	B-Operating_System
and	O
tasks	O
can	O
be	O
promoted	B-Operating_System
to	O
normal	O
policy	O
automatically	O
to	O
prevent	O
indefinite	B-Operating_System
resource	I-Operating_System
hold	I-Operating_System
.	O
</s>
<s>
Preemption	B-Operating_System
can	O
occur	O
when	O
a	O
newly	O
ready	O
task	O
with	O
a	O
higher	O
priority	O
policy	O
(	O
i.e.	O
</s>
<s>
higher	O
prio	O
)	O
has	O
an	O
earlier	O
virtual	O
deadline	O
than	O
the	O
currently	O
running	O
task	O
-	O
which	O
will	O
be	O
descheduled	O
and	O
put	O
at	O
the	O
back	O
of	O
the	O
queue	B-Operating_System
.	O
</s>
<s>
If	O
the	O
scheduler	O
found	O
the	O
task	O
at	O
the	O
higher	O
prio	O
with	O
the	O
earliest	O
virtual	O
deadline	O
,	O
it	O
will	O
execute	O
in	O
place	O
of	O
the	O
less	O
important	O
currently	O
running	O
task	O
only	O
if	O
all	O
logical	O
CPUs	O
(	O
including	O
hyperthreaded	B-Operating_System
cores	B-Architecture
/	O
SMT	B-Operating_System
threads	O
)	O
are	O
busy	O
.	O
</s>
<s>
The	O
scheduler	O
will	O
delay	O
preemption	B-Operating_System
as	O
long	O
as	O
possible	O
if	O
there	O
are	O
unused	O
logical	O
CPUs	O
.	O
</s>
<s>
If	O
a	O
task	O
is	O
marked	O
idle	O
priority	O
policy	O
,	O
it	O
cannot	O
preempt	O
at	O
all	O
even	O
other	O
idle	O
policy	O
marked	O
tasks	O
but	O
rather	O
use	O
cooperative	B-Operating_System
multitasking	I-Operating_System
.	O
</s>
<s>
The	O
scheduler	O
favors	O
most	O
the	O
idle	O
hyperthreaded	B-Operating_System
cores	B-Architecture
(	O
or	O
idle	O
SMT	B-Operating_System
threads	O
)	O
first	O
on	O
the	O
same	O
CPU	O
that	O
the	O
task	O
executed	O
on	O
,	O
then	O
the	O
other	O
idle	O
core	O
of	O
a	O
multicore	B-Architecture
CPU	I-Architecture
,	O
then	O
the	O
other	O
CPUs	O
on	O
the	O
same	O
NUMA	B-Operating_System
node	O
,	O
then	O
all	O
busy	O
hyperthreaded	B-Operating_System
cores	B-Architecture
/	O
SMT	B-Operating_System
threads	O
/	O
logical	O
CPUs	O
to	O
be	O
preempted	O
on	O
the	O
same	O
NUMA	B-Operating_System
node	O
,	O
then	O
the	O
other	O
(	O
remote	O
)	O
NUMA	B-Operating_System
node	O
and	O
is	O
ranked	O
on	O
a	O
preference	O
list	O
.	O
</s>
<s>
The	O
preemption	B-Operating_System
order	O
is	O
similar	O
to	O
the	O
above	O
paragraph	O
.	O
</s>
<s>
The	O
preemption	B-Operating_System
order	O
is	O
hyperthreaded	B-Operating_System
core	O
/	O
SMT	B-Operating_System
units	O
on	O
the	O
same	O
multicore	B-Architecture
first	O
,	O
then	O
the	O
other	O
core	O
in	O
the	O
multicore	B-Architecture
,	O
then	O
the	O
other	O
CPU	O
on	O
the	O
same	O
NUMA	B-Operating_System
node	O
.	O
</s>
<s>
When	O
it	O
goes	O
scanning	O
for	O
a	O
task	O
to	O
preempt	O
in	O
the	O
other	O
remote	O
NUMA	B-Operating_System
node	O
,	O
the	O
preemption	B-Operating_System
is	O
just	O
any	O
busy	O
threads	O
with	O
lower	O
to	O
equal	O
prio	O
or	O
later	O
virtual	O
deadline	O
assuming	O
that	O
all	O
logical	O
CPUs	O
(	O
including	O
hyperthreaded	B-Operating_System
core	O
/	O
SMT	B-Operating_System
threads	O
)	O
in	O
the	O
machine	O
are	O
all	O
busy	O
.	O
</s>
<s>
Local	O
preemption	B-Operating_System
has	O
a	O
higher	O
rank	O
than	O
scanning	O
for	O
a	O
remote	O
idle	O
NUMA	B-Operating_System
unit	O
.	O
</s>
<s>
When	O
a	O
task	O
is	O
involuntary	O
preempted	O
at	O
the	O
time	O
the	O
CPU	O
is	O
slowed	O
down	O
as	O
a	O
result	O
of	O
kernel	B-Operating_System
mediated	O
CPU	B-General_Concept
frequency	I-General_Concept
scaling	I-General_Concept
(	O
aka	O
CPU	O
frequency	O
governor	O
)	O
,	O
the	O
task	O
is	O
specially	O
marked	O
"	O
sticky	O
"	O
except	O
those	O
marked	O
as	O
realtime	B-General_Concept
policy	O
.	O
</s>
<s>
It	O
is	O
not	O
desirable	O
to	O
migrate	O
the	O
task	O
to	O
other	O
places	O
but	O
make	O
it	O
idle	O
instead	O
because	O
of	O
increased	O
latency	O
brought	O
about	O
of	O
overhead	O
to	O
migrating	O
the	O
task	O
to	O
another	O
CPU	O
or	O
NUMA	B-Operating_System
node	O
.	O
</s>
<s>
The	O
priority	O
class	O
can	O
be	O
manipulated	O
at	O
the	O
code	O
level	O
with	O
a	O
syscall	B-Operating_System
like	O
sched_setscheduler	O
only	O
available	O
to	O
root	B-Application
,	O
which	O
schedtool	O
uses	O
.	O
</s>
<s>
In	O
a	O
contemporary	O
study	O
,	O
the	O
author	O
compared	O
the	O
BFS	O
to	O
the	O
CFS	O
using	O
the	O
Linux	B-Operating_System
kernel	I-Operating_System
v3.6.2	O
and	O
several	O
performance-based	O
endpoints	O
.	O
</s>
<s>
The	O
purpose	O
of	O
this	O
study	O
was	O
to	O
evaluate	O
the	O
Completely	B-Application
Fair	I-Application
Scheduler	I-Application
(	O
CFS	O
)	O
in	O
the	O
vanilla	B-General_Concept
Linux	B-Operating_System
kernel	I-Operating_System
and	O
the	O
BFS	O
in	O
the	O
corresponding	O
kernel	B-Operating_System
patched	O
with	O
the	O
ck1	O
patchset	O
.	O
</s>
<s>
Kernels	B-Operating_System
patched	O
with	O
the	O
ck1	O
patch	O
set	O
including	O
the	O
BFS	O
outperformed	O
the	O
vanilla	B-General_Concept
kernel	B-Operating_System
using	O
the	O
CFS	O
at	O
nearly	O
all	O
the	O
performance-based	O
benchmarks	O
tested	O
.	O
</s>
<s>
Further	O
study	O
with	O
a	O
larger	O
test	O
set	O
could	O
be	O
conducted	O
,	O
but	O
based	O
on	O
the	O
small	O
test	O
set	O
of	O
7	O
PCs	O
evaluated	O
,	O
these	O
increases	O
in	O
process	O
queuing	O
,	O
efficiency/speed	O
are	O
,	O
on	O
the	O
whole	O
,	O
independent	O
of	O
CPU	O
type	O
(	O
mono	O
,	O
dual	O
,	O
quad	O
,	O
hyperthreaded	B-Operating_System
,	O
etc	O
.	O
</s>
<s>
Moreover	O
,	O
on	O
several	O
"	O
modern	O
"	O
CPUs	O
,	O
such	O
as	O
the	O
Intel	O
Core	O
2	O
Duo	O
and	O
Core	B-Device
i7	I-Device
,	O
that	O
represent	O
common	O
workstations	O
and	O
laptops	O
,	O
BFS	O
consistently	O
outperformed	O
the	O
CFS	O
in	O
the	O
vanilla	B-General_Concept
kernel	B-Operating_System
at	O
all	O
benchmarks	O
.	O
</s>
<s>
BFS	O
is	O
the	O
default	O
scheduler	O
for	O
the	O
following	O
desktop	O
Linux	B-Operating_System
distributions	O
:	O
</s>
<s>
Additionally	O
,	O
BFS	O
has	O
been	O
added	O
to	O
an	O
experimental	O
branch	O
of	O
Google	B-Application
's	I-Application
Android	I-Application
development	O
repository	O
.	O
</s>
<s>
BFS	O
has	O
been	O
retired	O
in	O
favour	O
of	O
MuQSS	O
,	O
known	O
formally	O
as	O
the	O
Multiple	O
Queue	B-Operating_System
Skiplist	O
Scheduler	O
,	O
a	O
rewritten	O
implementation	O
of	O
the	O
same	O
concept	O
.	O
</s>
<s>
The	O
next	O
task	O
for	O
execution	O
is	O
per	O
runqueue	O
,	O
but	O
the	O
scheduler	O
examines	O
every	O
other	O
runqueues	O
to	O
maintain	O
task	O
fairness	O
among	O
CPUs	O
,	O
for	O
latency	O
or	O
balancing	O
(	O
to	O
maximize	O
CPU	O
usage	O
and	O
cache	O
coherency	O
on	O
the	O
same	O
NUMA	B-Operating_System
node	O
over	O
those	O
that	O
access	O
across	O
NUMA	B-Operating_System
nodes	O
)	O
,	O
so	O
ultimately	O
.	O
</s>
<s>
Tasks	O
are	O
ordered	O
as	O
a	O
gradient	O
in	O
the	O
skip	O
list	O
in	O
a	O
way	O
that	O
realtime	B-General_Concept
policy	O
priority	O
comes	O
first	O
and	O
idle	O
policy	O
priority	O
comes	O
last	O
.	O
</s>
<s>
Normal	O
and	O
idle	O
priority	O
policy	O
still	O
get	O
sorted	O
by	O
virtual	O
deadline	O
which	O
uses	O
nice	B-Device
values	O
.	O
</s>
<s>
Realtime	B-General_Concept
and	O
Isochronous	O
policy	O
tasks	O
are	O
run	O
in	O
FIFO	B-Operating_System
order	O
ignoring	O
nice	B-Device
values	O
.	O
</s>
<s>
New	O
tasks	O
with	O
same	O
key	O
are	O
placed	O
in	O
FIFO	B-Operating_System
order	O
meaning	O
that	O
newer	O
tasks	O
get	O
placed	O
at	O
the	O
end	O
of	O
the	O
list	O
(	O
i.e.	O
</s>
<s>
The	O
user	O
can	O
choose	O
to	O
share	O
runqueues	O
among	O
multicore	B-Architecture
or	O
have	O
a	O
runqueue	O
per	O
logical	O
CPU	O
.	O
</s>
