Need of different memory zones
Arun KS
getarunks at gmail.com
Fri Mar 15 06:24:18 EDT 2013
Hi Niroj,
On Fri, Mar 15, 2013 at 2:39 PM, Niroj Pokhrel <nirojpokhrel at gmail.com> wrote:
>
> On Fri, Mar 15, 2013 at 12:31 PM, Arun KS <getarunks at gmail.com> wrote:
>>
>> Hi Niroj,
>>
>> On Wed, Mar 13, 2013 at 3:16 PM, Niroj Pokhrel <nirojpokhrel at gmail.com>
>> wrote:
>> > Hi All,
>> >
>> > I have been studying Memory Management in linux. But I am confused with
>> > the
>> > division of different ZONE. The use of ZONE_DMA and ZONE_NORMAL is fine.
>> > But
>> > I am confused with ZONE_HIGHMEM, if the system is 32 bit then why can't
>> > it
>> > map 4GB memory (2^32). I had thought that ZONE_NORMAL was for the kernel
>> > usage so directly mapped and ZONE_HIGHMEM for the user process and is
>> > not
>> > directly mapped to facilitate virtual addressing. But I know I am not
>> > getting something right. While going through Ch - 15 of Rubini's Linux
>> > Device Driver (Memory Management and DMA) I came across following line
>> >
>> > "a 64-bit architecture such as Intel’s x86-64 can fully map and handle
>> > 64-bits of memory.Thus, x86-64 has no ZONE_HIGHMEM and all physical
>> > memory
>> > is contained within ZONE_DMA and ZONE_NORMAL." So, if it can be
>> > directly
>> > mapped why not in 32 bit architecture.
>> >
>> > I am really confused. Please Help. Thanking you in Advance
>>
>> On a 1:3 VM split, kernel has 1GB of virtual space.
>> This 1GB kenel VM is split accross I/O mapped registers, Interrupt
>> vector table, VMALLOC area
>> and your system memory(ie RAM).
>>
>> For example let's say,
>> I/O mapped register + VMALLOC area + vector table = 200MB.
>> So virtual space left for System memory = 1024MB - 200MB = 824MB.
>> Now consider you have 1GB of System memory(RAM). How will you use it?
>>
>> Two ways
>> 1) You can change VM split(user space:kernel space) to 2:2, or
>> 2) Use High Mem.
>>
>> If using 2:2 VM split, then your kernel space is 2GB and you have
>> plenty of space to map system memory.
>>
>> If High mem, you will have a temporary mapping to High mem area. This
>> mapping is usually used from vmalloc area.
>> High mem, in our case is 200MB( 1024MB of total ram - 824 MB which is
>> already mapped to kernel virtual space)
>> Permanent mapping also is available from high mem. But this VM space
>> will be limited in size(eg 2MB). This is know as pkmappings.
>>
>> For more information have a look at page 253 of Linux kernel
>> development 3rd edition- Robert Love.
>>
>> All this complexity will go into vents when 64 bit architecture comes
>> because,
>> 2^64 = 16ExtraByte(EB)
>> You have 16EB of virtual space compared to 4GB of virtual space for 32
>> bit architecture.
>>
>> HTH
>>
>> Arun
>> >
>> >
>> > Yours,
>> > Niroj Pokhrel
>> >
>> > _______________________________________________
>> > Kernelnewbies mailing list
>> > Kernelnewbies at kernelnewbies.org
>> > http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>> >
>
>
>
> Thanks Arun,
> That explains a lot and I almost understand it but still have a doubt.
> So, when we create Kernel thread why do they need the page tables (though
> the mm points to NULL, the kernel thread uses memory descriptor of whatever
> processes ran earlier, right ??). First, we already have 896 MB of directly
> mapped space ( and I think we don't need page table entries for this one)
> and if it is for the HIGH_MEMORY area then doesn't the memory gets
> deallocated and hence the page table entries when the process exit so what
> info exactly is obtained by the kernel thread from that memory descriptor's
> page table entries. Thanking you in advance.
When Virtual memory is enabled, every memory your cpu generates is a
virtual address. Which has to be converted to physical memory by MMU.
MMU uses page tables(setup by kernel) to accomplish this task.
So when ever a kernel thread runs, it uses the mm pointer of the
previous task which was preempted.
All the process has its own page tables, in which the page table
entries pointing to the last 1GB address space(which is for kernel
space) is same for all process.
So kernel thread uses previous process mm to access information
relating to kernel space memory.
Thanks,
Arun
>
> Yours,
> Niroj Pokhrel
More information about the Kernelnewbies
mailing list