JustKernel

Ray Of Hope

CoLinux – Memory Management

monitor.c : Explanation of the #defines.
/*
* 4 GB of total virtual space. 0x00000000 – 0xffc00000 – approx 3.99GB (not to 0x100000000(4 GB) its 9 bits so not used)
* 3 GB of high total virtual space is user space ie from 0x00000000 – 0xc0000000
* 1 GB of low total virtual address space is kernel space i.e from 0xc0000000 – 0xffc00000
*+#define CO_VPTR_BASE (0xffc00000ul) //4 GB end boundary mark
*+#define CO_VPTR_PHYSICAL_TO_PSEUDO_PFN_MAP (CO_VPTR_BASE – 0x1000000ul) 4000MB – 16 MB (0xffc00000-0x1000000 = 0xFEC00000)
*+#define CO_VPTR_PSEUDO_RAM_PAGE_TABLES (CO_VPTR_BASE – 0x1100000ul) 4000MB – 17 MB (0xffc00000-0x1100000 = 0XFEB00000)
*+#define CO_VPTR_PASSAGE_PAGE (CO_VPTR_BASE – 0x1101000ul) 4000MB-17412KB (0xffc00000-0x1101000 = 0xFEAFF000)
*+#define
*+#define CO_VPTR_IO_AREA_SIZE (0x10000ul) 64 KB
*+#define CO_VPTR_IO_AREA_START (CO_VPTR_BASE – 0x1200000ul) 4000MB – 18 MB = 0xFEA00000
*+#define CO_VPTR_SELF_MAP (CO_VPTR_BASE – 0x1400000ul) 4000MB – 20 MB = 0xFE800000
*+#define CO_VPTR_BASE_START CO_VPTR_SELF_MAP 4000MB – 20MB = 0xFE800000
*+#define CO_VPTR_BASE_END CO_VPTR_BASE 0xFFC00000 = 0xFFC00000
*+#define CO_LOWMEMORY_MAX_MB 984

* #define PTRS_PER_PTE 1024
*#define PGDIR_SHIFT 22 //this is equal to 2^22(its used as >> PGDIR_SHIFT) meaning 4MB i.e size of each page.
#define PTRS_PER_PGD 1024

#define CO_ARCH_PMD_SHIFT 22
#define CO_ARCH_PMD_MASK (~(CO_ARCH_PMD_SIZE-1))
#define CO_ARCH_PMD_SIZE (1UL << CO_ARCH_PMD_SHIFT)

#define CO_ARCH_PAE_PGD_SHIFT 30 //this is equal to 2^30 means 1 GB
#define CO_ARCH_PAE_PGD_MASK (~(CO_ARCH_PAE_PGD_SIZE-1))
#define CO_ARCH_PAE_PGD_SIZE (1UL << CO_ARCH_PAE_PGD_SHIFT)

#define CO_ARCH_PAE_PMD_SHIFT 21 //this is equal to 2MB
#define CO_ARCH_PAE_PMD_MASK (~(CO_ARCH_PAE_PMD_SIZE-1))
#define CO_ARCH_PAE_PMD_SIZE (1UL << CO_ARCH_PAE_PMD_SHIFT)

#define CO_ARCH_PAGE_SHIFT 12 // this is equal to 4 K
#define CO_ARCH_PAGE_SIZE (1 << CO_ARCH_PAGE_SHIFT)
#define CO_ARCH_PAGE_MASK (~(CO_ARCH_PAGE_SIZE-1))
#define CO_ARCH_KERNEL_OFFSET 0xc0000000 // start of the kernel virtual space ..

 

*/

Some of the points that I noticed while working on colinux memory management.

  • monitor->pp_pfns[][] is a 2D array, where in first index points to pfn_group and 2nd index points to page table. Further page table will point to actual physical pages.

Suppose , actual physical page is allocated at 0x2000 and page table containing its entry is allocated at 0x1000. And assuming this is first allocation i.e till now page table and pp_pfns array was empty.

Then , monitor->pp_pfns[0][0] will point to to the actual physical page.. i.e will point to 0x2000

  1. PGD: Page Global Directory – the top level page table tree. The page table hierarchy is pgd->pud->pmd->pte
  2. PMD: Page Mid Level Directory.
  3. PTE : Page Table Entry
  4. PUD: Page upper level directory.

typedef struct { unsigned long pte_low; } pte_t;

typedef struct { unsigned logn pgd;} pgd_t;

Originally Posted On: 2011-07-17 18:51:37

Anshul makkar

mail your query :  anshul_makkar@justkernel.com

 

Tags:


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.