------------------------------------------------------------------------------
Solutions to selected assignments ::
Ch 6: Kernel and Memory Management Internals Essentials
(For your convenience, we have repeated the questions below and have provided
answers / solutions to some of them).
------------------------------------------------------------------------------
[Note: question 1 has been slightly edited; Apr '21]
1. Consider the following system scenario: there are a total of 125 processes
   alive; internally consisting of 164 threads, of which, 79 are kernel threads.
   Given this snapshot, how many:
   a) task structures will there be in kernel memory?
   b) userspace stacks will there be in user memory?
   c) kernel-mode stacks will there be in kernel memory?
A. 
a) 164 task structures (this is as _every_ thread has a task struct
   representing it)
b) every usermode thread will have 2 stacks - a user and a kernel stack;
   so, there will be (164 - 79) = 85 usermode threads, and thus 85
   usermode stacks
c) by the above logic, there will be (85 + 79) = 164 kernel-mode stacks,
   as there will be 85 usermode threads that have a kernel stack each + 79
   kernel threads that have a kernel stack each.

4. Run the show_kernel_seg kernel module on your x86_64 system (also enable
   showing the userspace details via the module parameter provided); study
   the output and understand the complete memory map it effectively displays
A.
   We've included two screenshots that display the output from:
   a) kseg-x86_64.png:
       screenshot of output on a native x86_64 box with 16 GB RAM running
	   Ubuntu 18.04 LTS
   b) kseg_on_bbb_arm32.png:
      screenshot of output on a BBB (BeagleBone Black) with 512 MB RAM; it
	  uses the TI AM35XX SoC (ARM core)
   Do look up and study them!
