Monday, October 28, 2013

Notes about Virtual memory and Highmem


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(DDR) = 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 using High mem, you will have a temporary mapping for High mem area. Virtual address for this temporary mapping depends on usage. Most of the allocation are for user space. Then virtual address will be user space virtual address. Kernel uses kmap function to map high mem area. In that case virtual address will be used  from vmalloc area.

High mem, in our case will be 200MB( 1024MB - 824 MB)
where as:
1024 MB is total ram size
824 MB is already mapped to kernel virtual space as low mem.

Permanent mapping also is available from high mem. But this VM space will be limited in size(eg 2MB).  This is know as pkmappings.

In general,
Low mem is the ram area which have permanent kernel address mapping.
High mem is mapped depending on the requirement, dynamically.

For more information have a look at page 253 of Linux kernel developement 3rd edition- Robert Love.

All this complexity will go into vents when 64 bit architeure comes because,
2^64 = 16ExtraByte(EB)
You have 16EB of virtual space compared to 4GB of virtual space for 32 bit architecure.

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.


Wednesday, October 9, 2013

git merge

Here is the procedure while porting kernel from 3.4.5 to 3.10 kernel.

$cd /projects/mobcom_andrwks_ext8/users/arunks/kernel-porting/aosp/

Clone the AOSP kernel,

Now move into 3.4.5 kernel,
$git remote add porting-3.10 /projects/mobcom_andrwks_ext8/users/arunks/kernel-porting/aosp/common
$git fetch porting-3.10

/*Set the renamelimit to make merge complete. Otherwise git merge will

stop rename resolution when default value of renamelimit is reached.*/
$git config merge.renameLimit 999999

Create a local branch with name android-3.10 tracking remotes/origin/experimental/android-3.10

$git merge -s recursive android-3.10

Now resolve all merge conflicts and git add or rm according.

Then do a git commit.