LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-06-2013, 06:09 AM   #1
barunparichha
Member
 
Registered: Jun 2006
Location: Bangalore,india
Distribution: Linux(Redhat,fedora,suse,ubantu), Solaris (s8/s9/s10/nevada/open-solaris)
Posts: 294

Rep: Reputation: 32
Memory management in 32 bit systems


Let's say I have a 32 bit machine (4GB virtual memory space) and 16 GB RAM (34 bit address needed to address all locations).

As per linux OS 4GB virual space = 3GB user space + 1GB kernel space.
Only kernel space address match directly to physical memory.

Here I have 2 questions:
Code:
 1. whether user space address to be mapped to kernel space address before accessing my RAM from user space application.
Code:
2. with 32 bit machine I can maximum access 4GB of RAM, what happens to rest 14GB ?? How it's taken care by memory manager or page manager ??
 
Old 02-06-2013, 06:16 AM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 18,913

Rep: Reputation: 3249Reputation: 3249Reputation: 3249Reputation: 3249Reputation: 3249Reputation: 3249Reputation: 3249Reputation: 3249Reputation: 3249Reputation: 3249Reputation: 3249
1). Nope.
Kernel addresses are real - no page translation. User-space uses page table to map virtual address to real address (when resident in real).
2). PAE. See http://en.wikipedia.org/wiki/Physical_Address_Extension
 
Old 02-06-2013, 07:57 AM   #3
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194
1) Question is so confused, I can't guess what you are trying to get at. But.
Quote:
Originally Posted by syg00 View Post
Kernel addresses are real - no page translation. User-space uses page table to map virtual address to real address (when resident in real).
No. Some obscure architectures running Linux act that way, but x86 certainly does not.
All addresses (kernel and user) go through page translation.

Linux was designed with the idea that virtual address space is larger than physical ram (back when 1GB of ram was too expensive to put in a single computer). So it was convenient to map all of physical ram to a contiguous subset of kernel virtual addresses, so a physical address can be accessed by just adding an offset. Current 32-bit Linux maps only a small part of physical ram that way. Certain kernel data structures are restricted to that small part of physical ram.

2). All addresses (kernel and user) go through page translation.

Every 32-bit virtual address is split by the CPU into a 20-bit virtual "page frame number" and a 12 bit offset within the page. Then the 20-bit number is looked up in a hardware translation system (translation look aside buffer) to produce a 24-bit physical PFN. The 24-bit PFN and original 12-bit offset are combined to produce the 36-bit physical memory address.

The kernel maintains a hierarchical set of page tables (for each process). When any 20-bit virtual PFN is missing from the "translation look aside buffer" hardware, the CPU automatically looks that PFN up in the page table structure to use and to copy into the TLB. If the translation is disabled in the page table structure, the CPU "faults" into kernel code to take appropriate action (such as physically reading in a page from a file mapping).

Back to the actual question (2): At any one moment (in any single core or hyperthread), the TLB and page table system can map at most 1048576 4KB pages (total 4GB) but that 4GB may be scattered anywhere through the 64GB physical address space. When the kernel switches to a different process, it flushes the TLB system and it switches to a different page table structure.

Each hyperthread has its own page table pointer. So if you had a 4 core CPU with hyperthreading enabled, there are eight independent page table pointers so eight different software threads could be using eight different 4GB subsets of the 64GB physical space.

By hardware design, each of those page tables hierarchies is totally independent. By Linux design (for 32-bit x86) all of those page table structures overlap and share their top 1GB of mappings. So kernel addresses are the same in every process address space.

One extra detail: There is actually an alternate translation method that can be mixed in. In that method only the top 11 (not 20) bits of virtual address are translated to the top 15 (not 24) bits of physical address. The bottom 21 bits of virtual address pass untranslated to the bottom 21 bits of physical address (just as normally the bottom 12 bits pass through untranslated). That is a more efficient system for use when a large area of physical memory is used contiguously in virtual address space, such as the Linux mapping of a big contiguous chunk of physical memory to be most of the kernel virtual space.

Last edited by johnsfine; 02-06-2013 at 08:21 AM.
 
Old 02-07-2013, 03:02 AM   #4
barunparichha
Member
 
Registered: Jun 2006
Location: Bangalore,india
Distribution: Linux(Redhat,fedora,suse,ubantu), Solaris (s8/s9/s10/nevada/open-solaris)
Posts: 294

Original Poster
Rep: Reputation: 32
Syg00 and Johnsfine,

I did not know that higher portion of virtual memory is process specific. So the same virtual address will map to different physical memory when it contetxt switches to a different process.

Thanks for your detailed clarifications.
 
Old 02-07-2013, 07:57 AM   #5
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194
Quote:
Originally Posted by barunparichha View Post
I did not know that higher portion of virtual memory is process specific.
It is the portion (3GB) with lower virtual addresses that Linux makes process specific. So your use of "higher" might be a misunderstanding (but I'm not sure what you meant by higher).

Quote:
So the same virtual address will map to different physical memory when it contetxt switches to a different process.
Yes.
 
Old 02-07-2013, 07:28 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 7.7 (?), Centos 8.1
Posts: 17,779

Rep: Reputation: 2537Reputation: 2537Reputation: 2537Reputation: 2537Reputation: 2537Reputation: 2537Reputation: 2537Reputation: 2537Reputation: 2537Reputation: 2537Reputation: 2537
@OP; do note that regardless of the memory addressing details, if you only have a 32bit OS and want to use more than the base 4GB of RAM, you'll need a PAE kernel as per syg00's 2nd point.
This is an OS requirement.
In other words, a 32bit OS cannot see beyond 4GB, unless you use eg PAE kernel.
 
  


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
running 32 bit C code .exe file using more memory to run on 64 bit machine? gajananh999 General 9 08-07-2012 08:16 AM
Linux memory management: Real memory or Cached buffers? gubbu Linux - Server 2 10-01-2010 01:58 AM
Memory Page Scanning and Reclaim/Memory Management ilfantomas Linux - Kernel 1 03-02-2010 08:31 PM
Memory bus is 64 bit but data access and register is only 32 bit for i386 lilzz Linux - Newbie 3 09-02-2006 12:35 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:00 PM.

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