4

I am confused with the segments in RAM memory,please clarify following doubts

  1. RAM has been been dived as User space and Kernel space;is this memory division is done by O/S or it is done by H/W(CPU).

  2. What are the contents of kernel space;as far as i have understood there will be kernel image only,please correct me if i am wrong.

  3. Where does this code,data,stack and heap segments exist?

    a) Does User and Kernel space has separate code,data,stack and heap segments?

    b) Is this segments are created by H/W or (O/S).

  4. Can i find the amount of memory occupied by Kernel space and User Space?

    a) Is there any Linux command (or) system calls to find this?

  5. Why the RAM has been divided into user space and kernel space?

    a) I fell it is done to keep the kernel safe from application program is it so?is this is the only reason.

I am a beginner so please suggest me some good books,links and the way to approach these concepts.

artless noise
  • 21,212
  • 6
  • 68
  • 105
user2972122
  • 161
  • 8
  • Most of your questions are too broad and require complex, lengthy answers. I suspect that you're gonna get closed. Do some more reading/googling. – Martin James Nov 09 '13 at 15:35
  • Try to ask one question at a time. I can't select which question I should answer here. – harper Nov 09 '13 at 15:58

1 Answers1

5

I took up the challenge and tried with rather short answers:

  1. Execution happens in user and kernel space. BIOS & CPU support the OS at detecting and separating resources/address ranges such as main memory and devices (-> related question) to establish the protected mode. In protected mode, memory is separated via virtual address spaces, which are mapped page wise (usually blocks of 4096 byte) to real addresses of physical memory via the MMU (Memory Management Unit).

    From user space, one cannot accesses memory directly (in real mode), one has to access it via the MMU, which acts like a transparent proxy with access protection. Access errors are known as segmentation fault, access violation, segmentation violation (SIGSEGV), which are abstracted with NullPointerException (NPE) in high level programming languages like Java.

    Read about protected mode, real mode and 'rings'.

    Note: Special CPUs, such as in embedded systems, don't necessarily have an MMU and could therefore be limited to special OSes like µClinux or FreeRTOS.

  2. A kernel does also allocate buffers, the same goes for drivers (e.g. IO buffers for disks, network interfaces and GPUs).

  3. Generally, resources exist per space and process/thread
    a) The kernel puts its own, protected stack on top of the user space stack (per thread) and has also separate code (also 'text'), data and heap segments. Also, each process has its own resources.
    b) CPU architectures have certain requirements (depends upon the degree of support they offer), but in the end, it is the software (kernel & user space libraries used for interfacing), which create these structures.

  4. Every reasonable OS provides at least one way to do that.
    a) Try sudo cat /proc/slabinfo or simply sudo slabtop

  5. Read 1.
    a) Primarily, yes, just like user space processes are isolated from each other, except for special techniques such as CMA (Cross Memory Attach) for fast direct access in newer kernels.

Community
  • 1
  • 1
Sam
  • 7,778
  • 1
  • 23
  • 49
  • 1
    Hi sam thanks for spending time to answer my questions,it was really helpful.Will get back and after doing more self studying. – user2972122 Nov 10 '13 at 06:23
  • @artless noise: Thanks for your comment. I really should have mentioned the MMU, so I updated the answer. – Sam Nov 11 '13 at 19:30