LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* Mapping memory between kernel and user space
@ 2011-02-09 23:45 Sri Ram Vemulpali
  2011-02-15  5:54 ` Ankita Garg
  0 siblings, 1 reply; 6+ messages in thread
From: Sri Ram Vemulpali @ 2011-02-09 23:45 UTC (permalink / raw)
  To: Kernel-newbies, linux-kernel-mail

Hi all,

  How do I map some space between kernel and user space. Can anyone
point me in to right direction. I was trying to map the packets from
my netfilter function to kernel user space, to avoid over head of
copying. Thanks in advance.

-- 
Regards,
Sri.

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

* Re: Mapping memory between kernel and user space
  2011-02-09 23:45 Mapping memory between kernel and user space Sri Ram Vemulpali
@ 2011-02-15  5:54 ` Ankita Garg
  2011-02-15 17:15   ` Sri Ram Vemulpali
  0 siblings, 1 reply; 6+ messages in thread
From: Ankita Garg @ 2011-02-15  5:54 UTC (permalink / raw)
  To: Sri Ram Vemulpali; +Cc: Kernel-newbies, linux-kernel-mail

On Wed, Feb 09, 2011 at 06:45:42PM -0500, Sri Ram Vemulpali wrote:
> Hi all,
> 
>   How do I map some space between kernel and user space. Can anyone
> point me in to right direction. I was trying to map the packets from
> my netfilter function to kernel user space, to avoid over head of
> copying. Thanks in advance.
>

You can take a look at remap_pfn_range() routine when implementing mmap
in your driver.
 
-- 
Regards,
Ankita Garg (ankita@in.ibm.com)
Linux Technology Center
IBM India Systems & Technology Labs,
Bangalore, India

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

* Re: Mapping memory between kernel and user space
  2011-02-15  5:54 ` Ankita Garg
@ 2011-02-15 17:15   ` Sri Ram Vemulpali
  2011-02-16  5:09     ` Ankita Garg
  2011-02-16  5:52     ` Rajat Sharma
  0 siblings, 2 replies; 6+ messages in thread
From: Sri Ram Vemulpali @ 2011-02-15 17:15 UTC (permalink / raw)
  To: Ankita Garg; +Cc: Kernel-newbies, linux-kernel-mail

As was suggested I started reading chap 15v from LDD. I ran more into
confusion state.

I know that virtual address(process space), linear address
(segmentation) and physical address. And how are they resolved from
virtual to physical.
But coming to kernel they distinguish logical address from virtual
address. What is the main difference.
Also, they emphasize on high memory and low memory. Why can not high
memory can be mapped in to kernel completely.
Why is that kernel has less visibility of complete space available on RAM.
Linux MM is it a very specific implementation of linux, or Is that a
traditional implementation.

what is very minimal implementation of MMU for real time systems.

Thanks in advance.

--Sri.

On Tue, Feb 15, 2011 at 12:54 AM, Ankita Garg <ankita@in.ibm.com> wrote:
> On Wed, Feb 09, 2011 at 06:45:42PM -0500, Sri Ram Vemulpali wrote:
>> Hi all,
>>
>>   How do I map some space between kernel and user space. Can anyone
>> point me in to right direction. I was trying to map the packets from
>> my netfilter function to kernel user space, to avoid over head of
>> copying. Thanks in advance.
>>
>
> You can take a look at remap_pfn_range() routine when implementing mmap
> in your driver.
>
> --
> Regards,
> Ankita Garg (ankita@in.ibm.com)
> Linux Technology Center
> IBM India Systems & Technology Labs,
> Bangalore, India
>



-- 
Regards,
Sri.

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

* Re: Mapping memory between kernel and user space
  2011-02-15 17:15   ` Sri Ram Vemulpali
@ 2011-02-16  5:09     ` Ankita Garg
  2011-02-16  5:52     ` Rajat Sharma
  1 sibling, 0 replies; 6+ messages in thread
From: Ankita Garg @ 2011-02-16  5:09 UTC (permalink / raw)
  To: Sri Ram Vemulpali; +Cc: Kernel-newbies, linux-kernel-mail

Hi,

On Tue, Feb 15, 2011 at 12:15:08PM -0500, Sri Ram Vemulpali wrote:
> As was suggested I started reading chap 15v from LDD. I ran more into
> confusion state.
> 
> I know that virtual address(process space), linear address
> (segmentation) and physical address. And how are they resolved from
> virtual to physical.
> But coming to kernel they distinguish logical address from virtual
> address. What is the main difference.
> Also, they emphasize on high memory and low memory. Why can not high
> memory can be mapped in to kernel completely.
> Why is that kernel has less visibility of complete space available on RAM.
> Linux MM is it a very specific implementation of linux, or Is that a
> traditional implementation.
> 

You may want to go through the literature available on the VM subsystem.
Especially, Mel Gorman's book:

http://ptgmedia.pearsoncmg.com/images/0131453483/downloads/gorman_book.pdf

> what is very minimal implementation of MMU for real time systems.
>

Linux VM subsystem for the RT kernel is not different from traditional
one. The application has to ensure that it pins/locks its pages during
execution.
 
> Thanks in advance.
> 
> --Sri.
> 
> On Tue, Feb 15, 2011 at 12:54 AM, Ankita Garg <ankita@in.ibm.com> wrote:
> > On Wed, Feb 09, 2011 at 06:45:42PM -0500, Sri Ram Vemulpali wrote:
> >> Hi all,
> >>
> >>   How do I map some space between kernel and user space. Can anyone
> >> point me in to right direction. I was trying to map the packets from
> >> my netfilter function to kernel user space, to avoid over head of
> >> copying. Thanks in advance.
> >>
> >
> > You can take a look at remap_pfn_range() routine when implementing mmap
> > in your driver.
> >
> > --
> > Regards,
> > Ankita Garg (ankita@in.ibm.com)
> > Linux Technology Center
> > IBM India Systems & Technology Labs,
> > Bangalore, India
> >
> 
> 
> 
> -- 
> Regards,
> Sri.

-- 
Regards,
Ankita Garg (ankita@in.ibm.com)
Linux Technology Center
IBM India Systems & Technology Labs,
Bangalore, India

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

* Re: Mapping memory between kernel and user space
  2011-02-15 17:15   ` Sri Ram Vemulpali
  2011-02-16  5:09     ` Ankita Garg
@ 2011-02-16  5:52     ` Rajat Sharma
       [not found]       ` <AANLkTinEuS-TgtxE7tGdL=XbJ2UUqqdqji1UA3F_BH2R@mail.gmail.com>
  1 sibling, 1 reply; 6+ messages in thread
From: Rajat Sharma @ 2011-02-16  5:52 UTC (permalink / raw)
  To: Sri Ram Vemulpali; +Cc: Ankita Garg, Kernel-newbies, linux-kernel-mail

> But coming to kernel they distinguish logical address from virtual
> address. What is the main difference.

kernel logical address has linear (one-to-one) mapping of physical
address to virtual address range. e.g. kernel logical address (linear
address) from 3G to 4G (on x86) can map physical memory of 0-1G, so it
is intutive to get physical address from a logical address by
subtrating 3G from logical address.

while kernel virtual address can be though of as logical address with
no restriction of linear mapping. Then how they map to physical pages?
Well this is achieved through page tables mapping like user space
address, however the virtual address range falls in 3G-4G (on x86)
range only. Basically you can say it is the process mapping of kernel
virtual address range (3G-4G) in its page tables. CPU works through
page-tables hence requires kernel virtual address in code
instructions. So, it is possible thats a kernel page has kernel
virtual address as well as logical address.

> Also, they emphasize on high memory and low memory. Why can not high
> memory can be mapped in to kernel completely.
> Why is that kernel has less visibility of complete space available on RAM.

For a limited address space range of linear mapping, physical memory
has to be limited (one-to-one mapping). So, if your system (x86) has
more than 1G physical RAM, Linux provides some mechanism releasing
some small slot between (3G + 896M) to 4G for dynamically mapping High
phyical memory page frames (>896M physical address), since you can't
always map the complete physical RAM all the time. This dynamic
mapping is done through kmap().

> what is very minimal implementation of MMU for real time systems.
# CONFIG_MMU is not set
means linear mapping of all physical address to virtual address. Not
sure, but seems it requires processor support to work on linear
address bypassing page-tables conversion.

Rajat

On Tue, Feb 15, 2011 at 10:45 PM, Sri Ram Vemulpali
<sri.ram.gmu06@gmail.com> wrote:
> As was suggested I started reading chap 15v from LDD. I ran more into
> confusion state.
>
> I know that virtual address(process space), linear address
> (segmentation) and physical address. And how are they resolved from
> virtual to physical.
> But coming to kernel they distinguish logical address from virtual
> address. What is the main difference.
> Also, they emphasize on high memory and low memory. Why can not high
> memory can be mapped in to kernel completely.
> Why is that kernel has less visibility of complete space available on RAM.
> Linux MM is it a very specific implementation of linux, or Is that a
> traditional implementation.
>
> what is very minimal implementation of MMU for real time systems.
>
> Thanks in advance.
>
> --Sri.
>
> On Tue, Feb 15, 2011 at 12:54 AM, Ankita Garg <ankita@in.ibm.com> wrote:
>> On Wed, Feb 09, 2011 at 06:45:42PM -0500, Sri Ram Vemulpali wrote:
>>> Hi all,
>>>
>>>   How do I map some space between kernel and user space. Can anyone
>>> point me in to right direction. I was trying to map the packets from
>>> my netfilter function to kernel user space, to avoid over head of
>>> copying. Thanks in advance.
>>>
>>
>> You can take a look at remap_pfn_range() routine when implementing mmap
>> in your driver.
>>
>> --
>> Regards,
>> Ankita Garg (ankita@in.ibm.com)
>> Linux Technology Center
>> IBM India Systems & Technology Labs,
>> Bangalore, India
>>
>
>
>
> --
> Regards,
> Sri.
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>

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

* Re: Mapping memory between kernel and user space
       [not found]       ` <AANLkTinEuS-TgtxE7tGdL=XbJ2UUqqdqji1UA3F_BH2R@mail.gmail.com>
@ 2011-02-16 15:32         ` Rajat Sharma
  0 siblings, 0 replies; 6+ messages in thread
From: Rajat Sharma @ 2011-02-16 15:32 UTC (permalink / raw)
  To: anish singh
  Cc: Sri Ram Vemulpali, Ankita Garg, Kernel-newbies, linux-kernel-mail

> So virtual address allocated to processes in user space is mapped to kernel
> virtual address(3g-4g range)  using page tables?

there are two types of virtual address - user mode virtual address,
which is mapped between 0-3G and kernel mode virtual address which are
mapped from 3G-4G.

kernel mode virtual addresses page table entries are taken from a
reference master kernel page-table. Basically any function which
establishes a kernel virtual address -> page frame mapping (e.g.
vmalloc() returns kernel virtual address) makes an entry into Master
kernel page table. If a process tries to access same virtual address,
the page fault handler tries to lookup same address mapping into the
Master page table before giving up. If an entry is found, process page
table is updated with this entry. You can say a user process' kernel
mode virtual address range mapping is established only on access.

This scheme allows each process, kernel thread, interrupt handler,
basically all possible kernel mode context to share same kernel
virtual addresses, because all mappings are coming from Master page
table entries.

Thanks,
Rajat

On Wed, Feb 16, 2011 at 1:32 PM, anish singh
<anish198519851985@gmail.com> wrote:
>
> On Wed, Feb 16, 2011 at 11:22 AM, Rajat Sharma <fs.rajat@gmail.com> wrote:
>>
>> > But coming to kernel they distinguish logical address from virtual
>> > address. What is the main difference.
>>
>> kernel logical address has linear (one-to-one) mapping of physical
>> address to virtual address range. e.g. kernel logical address (linear
>> address) from 3G to 4G (on x86) can map physical memory of 0-1G, so it
>> is intutive to get physical address from a logical address by
>> subtrating 3G from logical address.
>>
>> while kernel virtual address can be though of as logical address with
>> no restriction of linear mapping. Then how they map to physical pages?
>> Well this is achieved through page tables mapping like user space
>> address, however the virtual address range falls in 3G-4G (on x86)
>> range only. Basically you can say it is the process mapping of kernel
>> virtual address range (3G-4G) in its page tables. CPU works through
>> page-tables hence requires kernel virtual address in code
>> instructions. So, it is possible thats a kernel page has kernel
>> virtual address as well as logical address.
>
> So virtual address allocated to processes in user space is mapped to kernel
> virtual address(3g-4g range)  using page tables?
>>
>> > Also, they emphasize on high memory and low memory. Why can not high
>> > memory can be mapped in to kernel completely.
>> > Why is that kernel has less visibility of complete space available on
>> > RAM.
>>
>> For a limited address space range of linear mapping, physical memory
>> has to be limited (one-to-one mapping). So, if your system (x86) has
>> more than 1G physical RAM, Linux provides some mechanism releasing
>> some small slot between (3G + 896M) to 4G for dynamically mapping High
>> phyical memory page frames (>896M physical address), since you can't
>> always map the complete physical RAM all the time. This dynamic
>> mapping is done through kmap().
>>
>> > what is very minimal implementation of MMU for real time systems.
>> # CONFIG_MMU is not set
>> means linear mapping of all physical address to virtual address. Not
>> sure, but seems it requires processor support to work on linear
>> address bypassing page-tables conversion.
>>
>> Rajat
>>
>> On Tue, Feb 15, 2011 at 10:45 PM, Sri Ram Vemulpali
>> <sri.ram.gmu06@gmail.com> wrote:
>> > As was suggested I started reading chap 15v from LDD. I ran more into
>> > confusion state.
>> >
>> > I know that virtual address(process space), linear address
>> > (segmentation) and physical address. And how are they resolved from
>> > virtual to physical.
>> > But coming to kernel they distinguish logical address from virtual
>> > address. What is the main difference.
>> > Also, they emphasize on high memory and low memory. Why can not high
>> > memory can be mapped in to kernel completely.
>> > Why is that kernel has less visibility of complete space available on
>> > RAM.
>> > Linux MM is it a very specific implementation of linux, or Is that a
>> > traditional implementation.
>> >
>> > what is very minimal implementation of MMU for real time systems.
>> >
>> > Thanks in advance.
>> >
>> > --Sri.
>> >
>> > On Tue, Feb 15, 2011 at 12:54 AM, Ankita Garg <ankita@in.ibm.com> wrote:
>> >> On Wed, Feb 09, 2011 at 06:45:42PM -0500, Sri Ram Vemulpali wrote:
>> >>> Hi all,
>> >>>
>> >>>   How do I map some space between kernel and user space. Can anyone
>> >>> point me in to right direction. I was trying to map the packets from
>> >>> my netfilter function to kernel user space, to avoid over head of
>> >>> copying. Thanks in advance.
>> >>>
>> >>
>> >> You can take a look at remap_pfn_range() routine when implementing mmap
>> >> in your driver.
>> >>
>> >> --
>> >> Regards,
>> >> Ankita Garg (ankita@in.ibm.com)
>> >> Linux Technology Center
>> >> IBM India Systems & Technology Labs,
>> >> Bangalore, India
>> >>
>> >
>> >
>> >
>> > --
>> > Regards,
>> > Sri.
>> >
>> > _______________________________________________
>> > Kernelnewbies mailing list
>> > Kernelnewbies@kernelnewbies.org
>> > http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>> >
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>> Please read the FAQ at  http://www.tux.org/lkml/
>
>

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

end of thread, other threads:[~2011-02-16 15:32 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-09 23:45 Mapping memory between kernel and user space Sri Ram Vemulpali
2011-02-15  5:54 ` Ankita Garg
2011-02-15 17:15   ` Sri Ram Vemulpali
2011-02-16  5:09     ` Ankita Garg
2011-02-16  5:52     ` Rajat Sharma
     [not found]       ` <AANLkTinEuS-TgtxE7tGdL=XbJ2UUqqdqji1UA3F_BH2R@mail.gmail.com>
2011-02-16 15:32         ` Rajat Sharma

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).