There are many great articles and videos on gray code, why/when we need gray code, how to compute gray code etc.. Here's a comprehensive one: https://en.wikipedia.org/wiki/Gray_code Among all those articles and videos, this formula is used (^ is logical xor, >> is right shift): num ^ (num >> 1) however, I can't find any good explanation about why. I'll try to explain it here in an easy to understand way (not mathematical way). First, we need to understand the easy way of generating sequence of gray code. You can read the wikipedia page of any other articles out there if you need a very detailed version. Here's my simple version. Let's start with 1 bit, that's easy Decimal Binary Gray 0 0 0 1 1 1 in order to expand to 2 bit, all we need to do is, flip (or mirror) all existing gray code, and prefix 0 to the top half, prefix 1 to the bottom half. so first flip/mirror: Decimal Binary Gray 0 00 0 1 01 1 2 10 1 3 11 0 then p
What happens when you have many levels of sub-directory of CPU cgroup? what's the expect behavior for each process inside or outside those sub-directory? I hope this post helps. TL;DR When Linux scheduler processes, each cgroup with running processes will be considered as a single entity the same other processes at the same level. Scheduler will assign CPU shares to each entity based on its weight (priority). Each group will then distribute CPU share to all processes and cgroups under it, follow the same rule Assumptions: 1. We have N running (running, not all) processes/threads all need lots of CPU (if there's on competition, then each process will get the CPU they need) 2. All processes have default priority/nice value 3. We only have 1 CPU (to make calculation simple) Case 1: No sub-directory/sub-group (this is same as without CPU cgroup) each process will get 1/N CPU time, so if N is 10, then each one will get 10% CPU Case 2: create