LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-20-2012, 11:44 AM   #1
khanhlun
LQ Newbie
 
Registered: Mar 2008
Posts: 4

Rep: Reputation: 0
Linux Address space


Hi folks,

I am reading a chapter about Linux memory and have questions:

1. Why in 32bit system, linux address space is plitted into 2 spaces: 1GB for kernel and 3 for user. Why do user processes can share the same space? and why can kernel and user not share 4GB space?

Thanks alot!
 
Old 03-22-2012, 09:58 AM   #2
tommylovell
Member
 
Registered: Nov 2005
Distribution: Fedora, Redhat
Posts: 372

Rep: Reputation: 101Reputation: 101
Well, I'll take a stab at this and maybe someone with a little more background in the history of Linux will correct me or add clarification.

Quote:
Originally Posted by khanhlun View Post
1. Why in 32bit system, linux address space is plitted into 2 spaces: 1GB for kernel and 3 for user.
I think your question is "why are the two spaces static in size and not variable depending on the kernel size and loaded modules, plus a guess at other memory the kernel might need."

I think that this was the easiest and most reliable way to engineer the kernel. When Linux was initially developed it had a monolithic kernel - everything you needed was compiled and linked into it. Later, they developed loadable modules. This development makes it harder to calculate what you need for storage for your kernel.

In "Mauerer, Wolfgang (2010-03-11). Professional Linux Kernel Architecture (p. 290). John Wiley and Sons. Kindle Edition." the author states:
Quote:
The virtual address space of each process starts at address 0 and extends to TASK_SIZE - 1; the kernel address space begins above this. On IA-32 systems with 2^32 = 4 GiB, the total address space is usually split in a 3:1 ratio on which we focus in the information below. The kernel is assigned 1 GiB, while 3 GiB is available to each userspace process. Other ratios are possible but yield benefits only on very specific configurations and with certain work loads, as discussed above.
So, I think it was ease of design of the kernel and experience with each architecture that determined the ratio.
There is a great diagram of memory layout in the web page, http://82.157.70.109/mirrorbooks/lin...-2-SECT-7.html.

When you looked at it, it was much better than the 2G/2G ration that Windows used (uses?) for 32-bit. And 3GB of virtual storage for an application was enormous at the time.

Quote:
Why do user processes can share the same space?
In not sure of the question. Each process has its own address space, that is, it's own segment and page tables (or whatever they are called in a particular architecture). That's a good thing. Your process thinks it has the whole 4GB (in the case of 32-bit) to itself, minus of course the space for the kernel and the memory that is shared with other address spaces.

In the case of threads, Linux decided to make a thread look like a process (so it has a process ID) in terms of dispatching, but share memory (so all of the related threads use a set of common segment and page tables). (That's my understanding of it and I hope I have the concept right.)

Quote:
and why can kernel and user not share 4GB space?
They do, but there is a dividing line between where user space memory ends and kernel memory begins. It's just that the line is fixed at kernel compile time. For a process, it is one linear addressable 4GB of virtual memory. And the process "next door" has its own isolated 4GB of virtual memory, but sharing the kernel and a few other areas.

You can look at it like it's a 4 story row of New York City brownstones (http://en.wikipedia.org/wiki/Brownst...ate_residences), all side-by-side, where they have a wall between each brownstone, but a common 4th floor with no walls. (Not likely to happen, especially not in NYC, but I needed an analogy...)

I hope I interpreted your questions properly. You've gotten a bit into design philosophy that I think we all just accept. There are good reasons for what was done, and the kernel has been enormously successful. Ask your phone, your server, your home router or maybe even your toaster.
 
Old 03-22-2012, 12:21 PM   #3
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181
Quote:
Originally Posted by khanhlun View Post
1. Why in 32bit system, linux address space is plitted into 2 spaces: 1GB for kernel and 3 for user. Why do user processes can share the same space? and why can kernel and user not share 4GB space?
Most of those "why" questions seem to be based on incorrect assumptions, but they aren't phrased clearly enough to be sure about what you are assuming. So some explanation of the basics may help:

Each process has its own 4GB address space, which is split into a kernel section and a use section.

The kernel section of each process's address space must match the kernel section of every other process's address space. An interrupt at any time might cause the kernel to do a little more work on a request from some process. But that is not likely to be the process that was interrupted. So the kernel memory mapped for one process is used while doing kernel work for a different process.

So the user range of virtual address 0 to 3GB is mapped to different physical memory in each different process, while the kernel range of virtual addresses 3GB to 4GB is mapped to the same physical memory across all processes.
 
Old 03-22-2012, 07:18 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,356

Rep: Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367
Another reason for rigidly ensuring the 1GB for the kernel is so that it never gets swapped out and can use direct mem addressing for speed.
As above, the exact numbers are a matter of pref for the Linux designers; they are likely different in eg Solaris or an IBM Mainframe, but the principle is the same.
Its all about the most efficient way to use Physical Mem vs Virtual Mem.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
shared memory address area in process address space nagaraju1024 Programming 3 02-22-2011 04:49 AM
Address Space Randomization on 2.6.28-15-generic ubuntu 9.04. Finding base address nullprocess Linux - Security 1 09-15-2009 12:56 AM
Address Space Randomization on 2.6.28-15-generic ubuntu 9.04. Finding base address nullprocess Linux - Kernel 1 09-14-2009 08:31 PM
Address Space Randomization on 2.6.28-15-generic ubuntu 9.04. Finding base address nullprocess Linux - Kernel 0 09-14-2009 10:45 AM
Process Address Space in linux fedora 2.6 swaroopjoshi Linux - General 2 11-14-2006 01:37 AM


All times are GMT -5. The time now is 05:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration