From: der.herr@hofr.at (Nicholas Mc Guire)
To: kernelnewbies@lists.kernelnewbies.org
Subject: Why Completely Fair Scheduler(CFS) using Red-Black tree instead of Min-heap?
Date: Sun, 18 Oct 2015 06:55:19 +0000 [thread overview]
Message-ID: <20151018065519.GC27232@osadl.at> (raw)
In-Reply-To: <CAHmFiJDD7HTvYfNzd55s7hXgNbE1xTvKCT6Vf7B9zOVT8x-1PA@mail.gmail.com>
On Sat, Oct 17, 2015 at 11:55:29PM +0530, venu gangireddy wrote:
> Hi,
>
> Currently, I am learning about CFS scheduler in linux, and I want to know
> reason about the data structure chooses in CFS implementation.
>
> CFS scheduler picks next process based on minimum virtual time and to get
> this value efficiently its using Red-Black tree(rbtree), using rbtree we
> will get minimum O(h) here h is height of rbtree. But, using min-heap we
> can get min virtual time process in O(1) time only. I just want to know why
hmm... min heap insertion/deletion is O(log N) as you may have to swap up to
log N elements in the tree.
> min-heap is not consider in CFS implementation and is there any
> difficulties using min-heap in kernel level?
>
I don't think there is any fundamental obstacle to use min-heap
but the advantage is not clear to me - a rbtree is self-balancing so
search will stay O(log N) while in non-balanced trees it can
degenerate to O(n). If you always only need min/max then min-heap
could have an advantage - but if that is actually the
case in the scheduler I don't know. I suspect that the main reason
for rbtrees is simply that they have a constant cost for all of
the operations which reduces strange corner-case behavior.
thx!
hofrat
next prev parent reply other threads:[~2015-10-18 6:55 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-17 18:25 Why Completely Fair Scheduler(CFS) using Red-Black tree instead of Min-heap? venu gangireddy
2015-10-18 6:55 ` Nicholas Mc Guire [this message]
2015-10-18 7:35 ` anish singh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20151018065519.GC27232@osadl.at \
--to=der.herr@hofr.at \
--cc=kernelnewbies@lists.kernelnewbies.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).