LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 04-14-2017, 03:19 AM   #1
ahmadnouralizadeh
LQ Newbie
 
Registered: Dec 2013
Posts: 15

Rep: Reputation: Disabled
Direct Mapping in Linux Kernel Virtual Memory


As noted in https://www.amazon.com/Linux-Device-.../dp/0596005903 the kernel virtual memory (top 1GB in IA-32 address space) is partitioned into kernel logical addresses and kernel virtual addresses. Kernel logical addresses are mapped directly which means that you can map virtual addresses to physical addresses by subtracting a certain (0xC0000000) value. For moving btwn mappings a pair of macros are defined: __pa() and __va().

My questions are: "What are the usecases for these macros?" and: "What is the benefit of direct mapping?"

I have heared that direct mapping allows using larger pages (e.g., 4MB) and consequently leads to more efficient translation. Are translations for the directly mapped region performed using page tables?
 
Old 04-14-2017, 08:27 AM   #2
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,632
Blog Entries: 4

Rep: Reputation: 3931Reputation: 3931Reputation: 3931Reputation: 3931Reputation: 3931Reputation: 3931Reputation: 3931Reputation: 3931Reputation: 3931Reputation: 3931Reputation: 3931
Unfortunately, this book published in 2005 no longer represents the actual implementations used within the Linux kernel today – twelve years later.

Physical addresses are those needed by DMA: a device controller card cannot perform memory-translation.

Virtual addresses, in both user-space and kernel-space, use the address-translation hardware. You must go through this translation process to determine where – and if – the memory resides in physical space.

It is erroneous to think that one translates from one to the other by means of "simple subtraction."

Today, the most up-to-date sources for device driver information today is the actual source-code itself. Go find a driver, one that is similar to the one you want, and study it carefully. Many drivers are "cabbaged" from other ones. In all cases it is critical that you are looking at current Linux source code, since fundamental changes (such as randomization of kernel-space addressing to reduce predictability) have occurred with every major-version release.

And this also bears emphasis: be sure that you are looking at the right CPU architecture branch. Device drivers work very close to the hardware. Macros simplify this coding considerably, but there still may be architecture-specific considerations throughout any driver(s).

Last edited by sundialsvcs; 04-14-2017 at 08:43 AM.
 
1 members found this post helpful.
Old 04-14-2017, 11:47 AM   #3
ahmadnouralizadeh
LQ Newbie
 
Registered: Dec 2013
Posts: 15

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by sundialsvcs View Post
Unfortunately, this book published in 2005 no longer represents the actual implementations used within the Linux kernel today – twelve years later.

Physical addresses are those needed by DMA: a device controller card cannot perform memory-translation.

Virtual addresses, in both user-space and kernel-space, use the address-translation hardware. You must go through this translation process to determine where – and if – the memory resides in physical space.

It is erroneous to think that one translates from one to the other by means of "simple subtraction."

Today, the most up-to-date sources for device driver information today is the actual source-code itself. Go find a driver, one that is similar to the one you want, and study it carefully. Many drivers are "cabbaged" from other ones. In all cases it is critical that you are looking at current Linux source code, since fundamental changes (such as randomization of kernel-space addressing to reduce predictability) have occurred with every major-version release.

And this also bears emphasis: be sure that you are looking at the right CPU architecture branch. Device drivers work very close to the hardware. Macros simplify this coding considerably, but there still may be architecture-specific considerations throughout any driver(s).
I have attached a picture from https://www.amazon.com/Professional-.../dp/0470343435. It seems that the kernel has a direct mapping to the physical RAM.
Attached Thumbnails
Click image for larger version

Name:	down.png
Views:	314
Size:	184.9 KB
ID:	24774  

Last edited by ahmadnouralizadeh; 04-14-2017 at 11:49 AM.
 
Old 04-14-2017, 12:11 PM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,604

Rep: Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960
Quote:
Originally Posted by ahmadnouralizadeh View Post
I have attached a picture from https://www.amazon.com/Professional-.../dp/0470343435. It seems that the kernel has a direct mapping to the physical RAM.
And it may have...NINE YEARS AGO when that second book was written.

Again; look at the source code and the documentation on kernel.org. THAT is going to be current and relevant.
 
3 members found this post helpful.
Old 05-27-2017, 01:56 AM   #5
Bharagavi
LQ Newbie
 
Registered: May 2017
Posts: 2

Rep: Reputation: 0
What is the benefit of direct mapping

A memory, any memory stores data, obviously, but also has another key attribute, which is the memory address. Without the address, a memory becomes very inefficient.

To look at it from a human analogy, a library obviously has books (data), but it also has a shelving system like the Dewey Decimal Classification (address). This allows efficient means to retrieve the data. An example from our memory in the brain is the Method of loci or memory palace. Normally we just dump "memories" data into our brain, this method provides a visual addressing system for retrieving tose memories efficiently. The keyword is obviously efficiency here. the memory could be disorganized, and we could retrieve information our of it, example, a cluttered desk, or a pile of books. But we will have to employ other means.

The associativity is an attempt to map the main memory addresses to the cache memory that provides flexibility (to store any addressed location anywhere is cache) while providing an efficient means to retrieve the location later. Remember that a cache entry is supposed to be accessed again and again. So if your addressing scheme is inefficient, that inefficiency will occur with each access.

Regards,
 
Old 05-29-2017, 09:58 AM   #6
ahmadnouralizadeh
LQ Newbie
 
Registered: Dec 2013
Posts: 15

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Bharagavi View Post
A memory, any memory stores data, obviously, but also has another key attribute, which is the memory address. Without the address, a memory becomes very inefficient.

To look at it from a human analogy, a library obviously has books (data), but it also has a shelving system like the Dewey Decimal Classification (address). This allows efficient means to retrieve the data. An example from our memory in the brain is the Method of loci or memory palace. Normally we just dump "memories" data into our brain, this method provides a visual addressing system for retrieving tose memories efficiently. The keyword is obviously efficiency here. the memory could be disorganized, and we could retrieve information our of it, example, a cluttered desk, or a pile of books. But we will have to employ other means.

The associativity is an attempt to map the main memory addresses to the cache memory that provides flexibility (to store any addressed location anywhere is cache) while providing an efficient means to retrieve the location later. Remember that a cache entry is supposed to be accessed again and again. So if your addressing scheme is inefficient, that inefficiency will occur with each access.

Regards,
I am talking about mapping of kernel virtual address to physical address of main memory. You are talking about mapping of memory address to cache blocks. I think that you have misunderstood my question.
 
Old 05-29-2017, 11:06 PM   #7
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,632
Blog Entries: 4

Rep: Reputation: 3931Reputation: 3931Reputation: 3931Reputation: 3931Reputation: 3931Reputation: 3931Reputation: 3931Reputation: 3931Reputation: 3931Reputation: 3931Reputation: 3931
No ... he did not misunderstand your question.

(And, I can say that "authoritatively.")
 
  


Reply

Tags
linux, linux kernels, memory


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
Mapping of linux kernel in memory and getting virtual addresses pogo77 Linux - General 1 05-07-2012 03:10 PM
Mapping Kernel virtual address space to Physical memory zones (ZONE_DMA, ZONE_NORMAL) kumart Linux - Newbie 2 04-03-2012 09:11 AM
Linux Virtual memory mapping to Board memory map !rajkums! Linux - Kernel 4 10-19-2008 12:27 PM
Kernel virtual memory map TO Board memory map -----> Mapping !rajkums! Linux - Embedded & Single-board computer 0 10-18-2008 09:21 AM

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

All times are GMT -5. The time now is 03:55 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
Open Source Consulting | Domain Registration