kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
* user space vs kernel space address space
@ 2013-12-29  9:42 Pritam Bankar
  2013-12-29 13:34 ` Miles MH Chen
  0 siblings, 1 reply; 7+ messages in thread
From: Pritam Bankar @ 2013-12-29  9:42 UTC (permalink / raw)
  To: kernelnewbies

Lets consider 32 bit Linux system with 512 physical RAM. Suppose I have
standard 3:1 address space split. Now what I understand is

(In general)
1. In the fourth gigabyte I have kernel space
2. Out of 1GB for kernel address space only 896MB is used as direct mapping
and other 128 MB is used for Noncontiguous Memory Area Management, Fixed
Mapping and Permanent Mapping.

PCMIIW

Following are my doubts :
1. Since my system has only 512MB RAM, will there be only direct mappings
since 896 is enough to hold 512 RAM?
2. When user space program do malloc, we get some virtual address from
userspace region (from first 3GB) of process. So will it be like, when I
access some memory from that region, there is some physical frame
associated with it AND same physical frame will also be mapped in kernel
space ?
So what I want  to know, for every physical frame is there a mapping in
userspace as well as kernel space ? (given that some address in user space
of process map to same physical frame)
3. If we consider example of Linux system with 4GB, now if I do malloc from
user space from which memory region kernel will give memory ? Direct mapped
region or fixed map or permanent map ?

Thanks and regards,
Pritam Bankar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20131229/da827db9/attachment-0001.html 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* user space vs kernel space address space
  2013-12-29  9:42 user space vs kernel space address space Pritam Bankar
@ 2013-12-29 13:34 ` Miles MH Chen
  2013-12-30 14:28   ` Pritam Bankar
  0 siblings, 1 reply; 7+ messages in thread
From: Miles MH Chen @ 2013-12-29 13:34 UTC (permalink / raw)
  To: kernelnewbies

Hi Pritam,

1) Yes, all 512RAM will be direct mapped to kernel address space IF the
kernel have a 896MB direct mapping area.
Actually you can change the range of kernel direct mapping by the
vmalloc=<size> in boot command line.
In 32-bit and 3:1 split configuration, kernel direct mapping area + vmalloc
area is roughly 1G.

2) User space and kernel space can have different virtual addresses mapping
to the same physical frame at the same time.

3) Direct mapped or fixed map or permanent map are describing kernel
VIRTUAL address space, you can see the virtual memory
layout by 'dmesg'. When user space needs memory, the kernel allocates a
free memory frame, and remaps the frame to user space.
The frame does not have to have a valid kernel virtual address.

Regards,
MH


On Sun, Dec 29, 2013 at 5:42 PM, Pritam Bankar
<pritambankar1988@gmail.com>wrote:

> Lets consider 32 bit Linux system with 512 physical RAM. Suppose I have
> standard 3:1 address space split. Now what I understand is
>
> (In general)
> 1. In the fourth gigabyte I have kernel space
> 2. Out of 1GB for kernel address space only 896MB is used as direct
> mapping and other 128 MB is used for Noncontiguous Memory Area Management,
> Fixed Mapping and Permanent Mapping.
>
> PCMIIW
>
> Following are my doubts :
> 1. Since my system has only 512MB RAM, will there be only direct mappings
> since 896 is enough to hold 512 RAM?
> 2. When user space program do malloc, we get some virtual address from
> userspace region (from first 3GB) of process. So will it be like, when I
> access some memory from that region, there is some physical frame
> associated with it AND same physical frame will also be mapped in kernel
> space ?
> So what I want  to know, for every physical frame is there a mapping in
> userspace as well as kernel space ? (given that some address in user space
> of process map to same physical frame)
> 3. If we consider example of Linux system with 4GB, now if I do malloc
> from user space from which memory region kernel will give memory ? Direct
> mapped region or fixed map or permanent map ?
>
> Thanks and regards,
> Pritam Bankar
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20131229/a738c6fa/attachment.html 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* user space vs kernel space address space
  2013-12-29 13:34 ` Miles MH Chen
@ 2013-12-30 14:28   ` Pritam Bankar
  2013-12-30 15:31     ` Miles MH Chen
  0 siblings, 1 reply; 7+ messages in thread
From: Pritam Bankar @ 2013-12-30 14:28 UTC (permalink / raw)
  To: kernelnewbies

Miles thanks a lot for response but I still have some doubts please see my
comments inline.



On Sun, Dec 29, 2013 at 7:04 PM, Miles MH Chen <orca.chen@gmail.com> wrote:

> Hi Pritam,
>
> 1) Yes, all 512RAM will be direct mapped to kernel address space IF the
> kernel have a 896MB direct mapping area.
> Actually you can change the range of kernel direct mapping by the
> vmalloc=<size> in boot command line.
> In 32-bit and 3:1 split configuration, kernel direct mapping area +
> vmalloc area is roughly 1G.
>
> 2) User space and kernel space can have different virtual addresses
> mapping to the same physical frame at the same time.
>
> 3) Direct mapped or fixed map or permanent map are describing kernel
> VIRTUAL address space, you can see the virtual memory
> layout by 'dmesg'. When user space needs memory, the kernel allocates a
> free memory frame, and remaps the frame to user space.
> The frame does not have to have a valid kernel virtual address.
>
>

But all physical memory/frames are eventually controlled by kernel , then
how can there ever exist a frame which doesn't have mapping with kernel or
kernel virtual address ?




> Regards,
> MH
>
>
> On Sun, Dec 29, 2013 at 5:42 PM, Pritam Bankar <pritambankar1988@gmail.com
> > wrote:
>
>> Lets consider 32 bit Linux system with 512 physical RAM. Suppose I have
>> standard 3:1 address space split. Now what I understand is
>>
>> (In general)
>> 1. In the fourth gigabyte I have kernel space
>> 2. Out of 1GB for kernel address space only 896MB is used as direct
>> mapping and other 128 MB is used for Noncontiguous Memory Area Management,
>> Fixed Mapping and Permanent Mapping.
>>
>> PCMIIW
>>
>> Following are my doubts :
>> 1. Since my system has only 512MB RAM, will there be only direct mappings
>> since 896 is enough to hold 512 RAM?
>> 2. When user space program do malloc, we get some virtual address from
>> userspace region (from first 3GB) of process. So will it be like, when I
>> access some memory from that region, there is some physical frame
>> associated with it AND same physical frame will also be mapped in kernel
>> space ?
>> So what I want  to know, for every physical frame is there a mapping in
>> userspace as well as kernel space ? (given that some address in user space
>> of process map to same physical frame)
>> 3. If we consider example of Linux system with 4GB, now if I do malloc
>> from user space from which memory region kernel will give memory ? Direct
>> mapped region or fixed map or permanent map ?
>>
>> Thanks and regards,
>> Pritam Bankar
>>
>> _______________________________________________
>> Kernelnewbies mailing list
>> Kernelnewbies at kernelnewbies.org
>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>
>>
>

Thanks and regards,
Pritam Bankar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20131230/ea3e75ea/attachment.html 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* user space vs kernel space address space
  2013-12-30 14:28   ` Pritam Bankar
@ 2013-12-30 15:31     ` Miles MH Chen
  2013-12-31 12:38       ` Pritam Bankar
  0 siblings, 1 reply; 7+ messages in thread
From: Miles MH Chen @ 2013-12-30 15:31 UTC (permalink / raw)
  To: kernelnewbies

Hi Pritam,

Every page frame is controlled by kernel, but kernel does not have to map
all pages in all time.
On a 32-bit bit, 3:1 split Linux kernel, the kernel has at most 1GB VIRTUAL
address space. (user space has 3GB).
If there are 2GB of physical DRAM on the system, our kernel obviously
cannot map 2GB memory into 1GB virtual address space.

To solve this problem, the kernel map part of DRAM to normal area (1-to-1
mapping). A page from normal zone can be accessed
by kernel by using the existing mapping.
Other memory is called high memory. When kernel wants to access the high
memory pages,
it maps them to kernel address space (by vmalloc, fixed map or permanent
map).

(A 64-bit CPU can make life much easier. We can map a lot of DRAM directly.)

Regards,
MH


On Mon, Dec 30, 2013 at 10:28 PM, Pritam Bankar
<pritambankar1988@gmail.com>wrote:

>
> Miles thanks a lot for response but I still have some doubts please see my
> comments inline.
>
>
>
> On Sun, Dec 29, 2013 at 7:04 PM, Miles MH Chen <orca.chen@gmail.com>wrote:
>
>> Hi Pritam,
>>
>> 1) Yes, all 512RAM will be direct mapped to kernel address space IF the
>> kernel have a 896MB direct mapping area.
>> Actually you can change the range of kernel direct mapping by the
>> vmalloc=<size> in boot command line.
>> In 32-bit and 3:1 split configuration, kernel direct mapping area +
>> vmalloc area is roughly 1G.
>>
>> 2) User space and kernel space can have different virtual addresses
>> mapping to the same physical frame at the same time.
>>
>> 3) Direct mapped or fixed map or permanent map are describing kernel
>> VIRTUAL address space, you can see the virtual memory
>> layout by 'dmesg'. When user space needs memory, the kernel allocates a
>> free memory frame, and remaps the frame to user space.
>> The frame does not have to have a valid kernel virtual address.
>>
>>
>
> But all physical memory/frames are eventually controlled by kernel , then
> how can there ever exist a frame which doesn't have mapping with kernel or
> kernel virtual address ?
>
>
>
>
>> Regards,
>> MH
>>
>>
>> On Sun, Dec 29, 2013 at 5:42 PM, Pritam Bankar <
>> pritambankar1988 at gmail.com> wrote:
>>
>>> Lets consider 32 bit Linux system with 512 physical RAM. Suppose I have
>>> standard 3:1 address space split. Now what I understand is
>>>
>>> (In general)
>>> 1. In the fourth gigabyte I have kernel space
>>> 2. Out of 1GB for kernel address space only 896MB is used as direct
>>> mapping and other 128 MB is used for Noncontiguous Memory Area Management,
>>> Fixed Mapping and Permanent Mapping.
>>>
>>> PCMIIW
>>>
>>> Following are my doubts :
>>> 1. Since my system has only 512MB RAM, will there be only direct
>>> mappings since 896 is enough to hold 512 RAM?
>>> 2. When user space program do malloc, we get some virtual address from
>>> userspace region (from first 3GB) of process. So will it be like, when I
>>> access some memory from that region, there is some physical frame
>>> associated with it AND same physical frame will also be mapped in kernel
>>> space ?
>>> So what I want  to know, for every physical frame is there a mapping in
>>> userspace as well as kernel space ? (given that some address in user space
>>> of process map to same physical frame)
>>> 3. If we consider example of Linux system with 4GB, now if I do malloc
>>> from user space from which memory region kernel will give memory ? Direct
>>> mapped region or fixed map or permanent map ?
>>>
>>> Thanks and regards,
>>> Pritam Bankar
>>>
>>> _______________________________________________
>>> Kernelnewbies mailing list
>>> Kernelnewbies at kernelnewbies.org
>>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>>
>>>
>>
>
> Thanks and regards,
> Pritam Bankar
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20131230/e031c229/attachment-0001.html 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* user space vs kernel space address space
  2013-12-30 15:31     ` Miles MH Chen
@ 2013-12-31 12:38       ` Pritam Bankar
  2013-12-31 12:51         ` Anders Darander
  2014-01-07 18:56         ` parmenides
  0 siblings, 2 replies; 7+ messages in thread
From: Pritam Bankar @ 2013-12-31 12:38 UTC (permalink / raw)
  To: kernelnewbies

Thanks Miles, I was in assumption that every physical HAS to be mapped in
some kernel virtual address. I have come across one more doubt please see
my comments inline.




>
>>
>> On Sun, Dec 29, 2013 at 7:04 PM, Miles MH Chen <orca.chen@gmail.com>wrote:
>>
>>> Hi Pritam,
>>>
>>> 1) Yes, all 512RAM will be direct mapped to kernel address space IF the
>>> kernel have a 896MB direct mapping area.
>>> Actually you can change the range of kernel direct mapping by the
>>> vmalloc=<size> in boot command line.
>>> In 32-bit and 3:1 split configuration, kernel direct mapping area +
>>> vmalloc area is roughly 1G.
>>>
>>> 2) User space and kernel space can have different virtual addresses
>>> mapping to the same physical frame at the same time.
>>>
>>>
            How above scenario of user space and kernel space having
mapping to the same physical frame               is handled. This would be
like sharing kernel data with user which is not allowed.




> 3) Direct mapped or fixed map or permanent map are describing kernel
>>> VIRTUAL address space, you can see the virtual memory
>>> layout by 'dmesg'. When user space needs memory, the kernel allocates a
>>> free memory frame, and remaps the frame to user space.
>>> The frame does not have to have a valid kernel virtual address.
>>>
>>>
>>
>> But all physical memory/frames are eventually controlled by kernel , then
>> how can there ever exist a frame which doesn't have mapping with kernel or
>> kernel virtual address ?
>>
>>
>>
>>
>>>  Regards,
>>> MH
>>>
>>>
>>> On Sun, Dec 29, 2013 at 5:42 PM, Pritam Bankar <
>>> pritambankar1988 at gmail.com> wrote:
>>>
>>>> Lets consider 32 bit Linux system with 512 physical RAM. Suppose I have
>>>> standard 3:1 address space split. Now what I understand is
>>>>
>>>> (In general)
>>>> 1. In the fourth gigabyte I have kernel space
>>>> 2. Out of 1GB for kernel address space only 896MB is used as direct
>>>> mapping and other 128 MB is used for Noncontiguous Memory Area Management,
>>>> Fixed Mapping and Permanent Mapping.
>>>>
>>>> PCMIIW
>>>>
>>>> Following are my doubts :
>>>> 1. Since my system has only 512MB RAM, will there be only direct
>>>> mappings since 896 is enough to hold 512 RAM?
>>>> 2. When user space program do malloc, we get some virtual address from
>>>> userspace region (from first 3GB) of process. So will it be like, when I
>>>> access some memory from that region, there is some physical frame
>>>> associated with it AND same physical frame will also be mapped in kernel
>>>> space ?
>>>> So what I want  to know, for every physical frame is there a mapping in
>>>> userspace as well as kernel space ? (given that some address in user space
>>>> of process map to same physical frame)
>>>> 3. If we consider example of Linux system with 4GB, now if I do malloc
>>>> from user space from which memory region kernel will give memory ? Direct
>>>> mapped region or fixed map or permanent map ?
>>>>
>>>> Thanks and regards,
>>>> Pritam Bankar
>>>>
>>>> _______________________________________________
>>>> Kernelnewbies mailing list
>>>> Kernelnewbies at kernelnewbies.org
>>>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>>>
>>>>
>>>
>>
>> Thanks and regards,
>> Pritam Bankar
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20131231/80493efc/attachment.html 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* user space vs kernel space address space
  2013-12-31 12:38       ` Pritam Bankar
@ 2013-12-31 12:51         ` Anders Darander
  2014-01-07 18:56         ` parmenides
  1 sibling, 0 replies; 7+ messages in thread
From: Anders Darander @ 2013-12-31 12:51 UTC (permalink / raw)
  To: kernelnewbies

On 31 Dec 2013 13:39, "Pritam Bankar" <pritambankar1988@gmail.com> wrote:
>>> On Sun, Dec 29, 2013 at 7:04 PM, Miles MH Chen <orca.chen@gmail.com>
wrote:
>>>>
>>>> Hi Pritam,
>>>>
>>>> 1) Yes, all 512RAM will be direct mapped to kernel address space IF
the kernel have a 896MB direct mapping area.
>>>> Actually you can change the range of kernel direct mapping by the
vmalloc=<size> in boot command line.
>>>> In 32-bit and 3:1 split configuration, kernel direct mapping area +
vmalloc area is roughly 1G.
>>>>
>>>> 2) User space and kernel space can have different virtual addresses
mapping to the same physical frame at the same time.
>>>>
>
>             How above scenario of user space and kernel space having
mapping to the same physical frame               is handled. This would be
like sharing kernel data with user which is not allowed.
>

One trivial example would be a driver that meets the userspace application
to mmap a kernel buffer. In that case, there will exist both a kernelspace
and a userspace mapping to the same physical frame(s).

It'll let you share data between the two in a rather efficient way. Of
course, you need to handle any necessary syncing yourself, so that you're
not reading inconsistent data.

Cheers,
Anders
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20131231/a93f421c/attachment.html 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* user space vs kernel space address space
  2013-12-31 12:38       ` Pritam Bankar
  2013-12-31 12:51         ` Anders Darander
@ 2014-01-07 18:56         ` parmenides
  1 sibling, 0 replies; 7+ messages in thread
From: parmenides @ 2014-01-07 18:56 UTC (permalink / raw)
  To: kernelnewbies


>         But all physical memory/frames are eventually controlled by
>         kernel , then how can there ever exist a frame which doesn't
>         have mapping with kernel or kernel virtual address ?

The key point is that frames are in physical memory while pages are in 
virtual memory. For a 4G Linux system, low 896M physical memory (low 
memory) is mapped directly into kernel space(virtual), and the rest is 
high memory at all (initally not mapped into any virtual space).

If kernel needs more frames other than those directly mapped, it can map 
frames from high memory into its 128M virtaul space.

If a user task needs frames, these frames might be from low memory or 
from high memory. In the former case, kernel shares these frames with 
user task. While in the latter case, these frames are only used by the 
user task.

Therefore, some frames in high memory might not be mapped into kernel 
space at all.

In addition, 896M low memory(physical) can be used directly by kernel, 
while all physical memory frames are allocated and mapped by kernel.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-01-07 18:56 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-29  9:42 user space vs kernel space address space Pritam Bankar
2013-12-29 13:34 ` Miles MH Chen
2013-12-30 14:28   ` Pritam Bankar
2013-12-30 15:31     ` Miles MH Chen
2013-12-31 12:38       ` Pritam Bankar
2013-12-31 12:51         ` Anders Darander
2014-01-07 18:56         ` parmenides

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).