xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/9] mini-os: prepare for support of ballooning
@ 2016-07-19  8:44 Juergen Gross
  2016-07-19  8:44 ` [PATCH 1/9] mini-os: correct first free pfn Juergen Gross
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: Juergen Gross @ 2016-07-19  8:44 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: Juergen Gross, samuel.thibault, wei.liu2

Do some cleanups, a small correction and add some basic features to
lay groundwork for support of ballooning in Mini-OS.

The main visible change is the virtual memory layout: to be able to
add memory to the running Mini-OS we need to have some spare areas
especially after the 1:1 mapping of physical memory.

The whole series has been tested with:

- pure mini-os
- xenstore stubdom
- ioemu stubdom
- pvgrub 64 bit

pvgrub 32 bit didn't work before applying the series, it just entered
the grub shell. With the series applied the behavior was exactly the
same.

Juergen Gross (9):
  mini-os: correct first free pfn
  mini-os: remove unused alloc_contig_pages() function
  mini-os: remove MM_DEBUG code
  mini-os: add description of x86 memory usage
  mini-os: add nr_free_pages counter
  mini-os: let memory allocation fail if no free page available
  mini-os: add ballooning config item
  mini-os: get maximum memory size from hypervisor
  mini-os: modify virtual memory layout for support of ballooning

 Makefile              |   2 +
 arch/arm/mm.c         |   2 +-
 arch/x86/mm.c         | 191 ++++----------------------------------------------
 include/mm.h          |   5 +-
 include/x86/arch_mm.h |  44 ++++++++++++
 mm.c                  |  95 +++++++++----------------
 6 files changed, 97 insertions(+), 242 deletions(-)

-- 
2.6.6


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

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

* [PATCH 1/9] mini-os: correct first free pfn
  2016-07-19  8:44 [PATCH 0/9] mini-os: prepare for support of ballooning Juergen Gross
@ 2016-07-19  8:44 ` Juergen Gross
  2016-07-19  8:44 ` [PATCH 2/9] mini-os: remove unused alloc_contig_pages() function Juergen Gross
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Juergen Gross @ 2016-07-19  8:44 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: Juergen Gross, samuel.thibault, wei.liu2

The first free pfn available for allocation is calculated by adding the
number of page table frames to the pfn of the first page table and
then the magic number 3 to account for start info page et al.

As the start info page, xenstore page and console page are allocated
_before_ the page tables leaving room for these pages behind the page
tables makes no sense.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 arch/x86/mm.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/arch/x86/mm.c b/arch/x86/mm.c
index 51aa966..ae1036e 100644
--- a/arch/x86/mm.c
+++ b/arch/x86/mm.c
@@ -867,9 +867,8 @@ void arch_init_mm(unsigned long* start_pfn_p, unsigned long* max_pfn_p)
     printk("stack start: %p(VA)\n", stack);
     printk("       _end: %p(VA)\n", &_end);
 
-    /* First page follows page table pages and 3 more pages (store page etc) */
-    start_pfn = PFN_UP(to_phys(start_info.pt_base)) + 
-        start_info.nr_pt_frames + 3;
+    /* First page follows page table pages. */
+    start_pfn = PFN_UP(to_phys(start_info.pt_base)) + start_info.nr_pt_frames;
     max_pfn = start_info.nr_pages;
 
     /* We need room for demand mapping and heap, clip available memory */
-- 
2.6.6


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

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

* [PATCH 2/9] mini-os: remove unused alloc_contig_pages() function
  2016-07-19  8:44 [PATCH 0/9] mini-os: prepare for support of ballooning Juergen Gross
  2016-07-19  8:44 ` [PATCH 1/9] mini-os: correct first free pfn Juergen Gross
@ 2016-07-19  8:44 ` Juergen Gross
  2016-07-19  8:44 ` [PATCH 3/9] mini-os: remove MM_DEBUG code Juergen Gross
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Juergen Gross @ 2016-07-19  8:44 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: Juergen Gross, samuel.thibault, wei.liu2

alloc_contig_pages() is never used anywhere in mini-os. Remove it.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 arch/x86/mm.c | 142 ----------------------------------------------------------
 include/mm.h  |   1 -
 2 files changed, 143 deletions(-)

diff --git a/arch/x86/mm.c b/arch/x86/mm.c
index ae1036e..c59a5d3 100644
--- a/arch/x86/mm.c
+++ b/arch/x86/mm.c
@@ -652,148 +652,6 @@ int unmap_frames(unsigned long va, unsigned long num_frames)
 }
 
 /*
- * Allocate pages which are contiguous in machine memory.
- * Returns a VA to where they are mapped or 0 on failure.
- * 
- * addr_bits indicates if the region has restrictions on where it is
- * located. Typical values are 32 (if for example PCI devices can't access
- * 64bit memory) or 0 for no restrictions.
- *
- * Allocated pages can be freed using the page allocators free_pages() 
- * function.
- *
- * based on Linux function xen_create_contiguous_region()
- */
-#define MAX_CONTIG_ORDER 9 /* 2MB */
-unsigned long alloc_contig_pages(int order, unsigned int addr_bits)
-{
-    unsigned long in_va, va;
-    unsigned long in_frames[1UL << order], out_frames, mfn;
-    multicall_entry_t call[1UL << order];
-    unsigned int i, num_pages = 1UL << order;
-    int ret, exch_success;
-
-    /* pass in num_pages 'extends' of size 1 and
-     * request 1 extend of size 'order */
-    struct xen_memory_exchange exchange = {
-        .in = {
-            .nr_extents   = num_pages,
-            .extent_order = 0,
-            .domid        = DOMID_SELF
-        },
-        .out = {
-            .nr_extents   = 1,
-            .extent_order = order,
-            .address_bits = addr_bits,
-            .domid        = DOMID_SELF
-        },
-        .nr_exchanged = 0
-    };
-
-    if ( order > MAX_CONTIG_ORDER )
-    {
-        printk("alloc_contig_pages: order too large 0x%x > 0x%x\n",
-               order, MAX_CONTIG_ORDER);
-        return 0;
-    }
-
-    /* Allocate some potentially discontiguous pages */
-    in_va = alloc_pages(order);
-    if ( !in_va )
-    {
-        printk("alloc_contig_pages: could not get enough pages (order=0x%x\n",
-               order);
-        return 0;
-    }
-
-    /* set up arguments for exchange hyper call */
-    set_xen_guest_handle(exchange.in.extent_start, in_frames);
-    set_xen_guest_handle(exchange.out.extent_start, &out_frames);
-
-    /* unmap current frames, keep a list of MFNs */
-    for ( i = 0; i < num_pages; i++ )
-    {
-        int arg = 0;
-
-        va = in_va + (PAGE_SIZE * i);
-        in_frames[i] = virt_to_mfn(va);
-
-        /* update P2M mapping */
-        phys_to_machine_mapping[virt_to_pfn(va)] = INVALID_P2M_ENTRY;
-
-        /* build multi call */
-        call[i].op = __HYPERVISOR_update_va_mapping;
-        call[i].args[arg++] = va;
-        call[i].args[arg++] = 0;
-#ifdef __i386__
-        call[i].args[arg++] = 0;
-#endif  
-        call[i].args[arg++] = UVMF_INVLPG;
-    }
-
-    ret = HYPERVISOR_multicall(call, i);
-    if ( ret )
-    {
-        printk("Odd, update_va_mapping hypercall failed with rc=%d.\n", ret);
-        return 0;
-    }
-
-    /* try getting a contig range of MFNs */
-    out_frames = virt_to_pfn(in_va); /* PFNs to populate */
-    ret = HYPERVISOR_memory_op(XENMEM_exchange, &exchange);
-    if ( ret ) {
-        printk("mem exchanged order=0x%x failed with rc=%d, nr_exchanged=%lu\n",
-               order, ret, exchange.nr_exchanged);
-        /* we still need to return the allocated pages above to the pool
-         * ie. map them back into the 1:1 mapping etc. so we continue but 
-         * in the end return the pages to the page allocator and return 0. */
-        exch_success = 0;
-    }
-    else
-        exch_success = 1;
-
-    /* map frames into 1:1 and update p2m */
-    for ( i = 0; i < num_pages; i++ )
-    {
-        int arg = 0;
-        pte_t pte;
-
-        va = in_va + (PAGE_SIZE * i);
-        mfn = i < exchange.nr_exchanged ? (out_frames + i) : in_frames[i];
-        pte = __pte(mfn << PAGE_SHIFT | L1_PROT);
-
-        /* update P2M mapping */
-        phys_to_machine_mapping[virt_to_pfn(va)] = mfn;
-
-        /* build multi call */
-        call[i].op = __HYPERVISOR_update_va_mapping;
-        call[i].args[arg++] = va;
-#ifdef __x86_64__
-        call[i].args[arg++] = (pgentry_t)pte.pte;
-#else
-        call[i].args[arg++] = pte.pte_low;
-        call[i].args[arg++] = pte.pte_high;
-#endif  
-        call[i].args[arg++] = UVMF_INVLPG;
-    }
-    ret = HYPERVISOR_multicall(call, i);
-    if ( ret )
-    {
-        printk("update_va_mapping hypercall no. 2 failed with rc=%d.\n", ret);
-        return 0;
-    }
-
-    if ( !exch_success )
-    {
-        /* since the exchanged failed we just free the pages as well */
-        free_pages((void *) in_va, order);
-        return 0;
-    }
-    
-    return in_va;
-}
-
-/*
  * Clear some of the bootstrap memory
  */
 static void clear_bootstrap(void)
diff --git a/include/mm.h b/include/mm.h
index f57d8ab..a48f485 100644
--- a/include/mm.h
+++ b/include/mm.h
@@ -71,7 +71,6 @@ void do_map_frames(unsigned long addr,
         const unsigned long *f, unsigned long n, unsigned long stride,
 	unsigned long increment, domid_t id, int *err, unsigned long prot);
 int unmap_frames(unsigned long va, unsigned long num_frames);
-unsigned long alloc_contig_pages(int order, unsigned int addr_bits);
 #ifdef HAVE_LIBC
 extern unsigned long heap, brk, heap_mapped, heap_end;
 #endif
-- 
2.6.6


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

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

* [PATCH 3/9] mini-os: remove MM_DEBUG code
  2016-07-19  8:44 [PATCH 0/9] mini-os: prepare for support of ballooning Juergen Gross
  2016-07-19  8:44 ` [PATCH 1/9] mini-os: correct first free pfn Juergen Gross
  2016-07-19  8:44 ` [PATCH 2/9] mini-os: remove unused alloc_contig_pages() function Juergen Gross
@ 2016-07-19  8:44 ` Juergen Gross
  2016-07-19  8:44 ` [PATCH 4/9] mini-os: add description of x86 memory usage Juergen Gross
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Juergen Gross @ 2016-07-19  8:44 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: Juergen Gross, samuel.thibault, wei.liu2

mm.c contains unused code inside #ifdef MM_DEBUG areas. Its usability
is rather questionable and some parts are even wrong (e.g.
print_chunks() called with nr_pages > 1000 will clobber an arbitrary
stack content with a 0 byte).

Remove this code.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 mm.c | 60 ------------------------------------------------------------
 1 file changed, 60 deletions(-)

diff --git a/mm.c b/mm.c
index 31aaf83..0dd4862 100644
--- a/mm.c
+++ b/mm.c
@@ -42,13 +42,6 @@
 #include <mini-os/lib.h>
 #include <mini-os/xmalloc.h>
 
-#ifdef MM_DEBUG
-#define DEBUG(_f, _a...) \
-    printk("MINI_OS(file=mm.c, line=%d) " _f "\n", __LINE__, ## _a)
-#else
-#define DEBUG(_f, _a...)    ((void)0)
-#endif
-
 /*********************
  * ALLOCATION BITMAP
  *  One bit per page of memory. Bit set => page is allocated.
@@ -140,59 +133,6 @@ static chunk_head_t  free_tail[FREELIST_SIZE];
 #define round_pgdown(_p)  ((_p)&PAGE_MASK)
 #define round_pgup(_p)    (((_p)+(PAGE_SIZE-1))&PAGE_MASK)
 
-#ifdef MM_DEBUG
-/*
- * Prints allocation[0/1] for @nr_pages, starting at @start
- * address (virtual).
- */
-USED static void print_allocation(void *start, int nr_pages)
-{
-    unsigned long pfn_start = virt_to_pfn(start);
-    int count;
-    for(count = 0; count < nr_pages; count++)
-        if(allocated_in_map(pfn_start + count)) printk("1");
-        else printk("0");
-        
-    printk("\n");        
-}
-
-/*
- * Prints chunks (making them with letters) for @nr_pages starting
- * at @start (virtual).
- */
-USED static void print_chunks(void *start, int nr_pages)
-{
-    char chunks[1001], current='A';
-    int order, count;
-    chunk_head_t *head;
-    unsigned long pfn_start = virt_to_pfn(start);
-   
-    memset(chunks, (int)'_', 1000);
-    if(nr_pages > 1000) 
-    {
-        DEBUG("Can only pring 1000 pages. Increase buffer size.");
-    }
-    
-    for(order=0; order < FREELIST_SIZE; order++)
-    {
-        head = free_head[order];
-        while(!FREELIST_EMPTY(head))
-        {
-            for(count = 0; count < 1UL<< head->level; count++)
-            {
-                if(count + virt_to_pfn(head) - pfn_start < 1000)
-                    chunks[count + virt_to_pfn(head) - pfn_start] = current;
-            }
-            head = head->next;
-            current++;
-        }
-    }
-    chunks[nr_pages] = '\0';
-    printk("%s\n", chunks);
-}
-#endif
-
-
 /*
  * Initialise allocator, placing addresses [@min,@max] in free pool.
  * @min and @max are PHYSICAL addresses.
-- 
2.6.6


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

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

* [PATCH 4/9] mini-os: add description of x86 memory usage
  2016-07-19  8:44 [PATCH 0/9] mini-os: prepare for support of ballooning Juergen Gross
                   ` (2 preceding siblings ...)
  2016-07-19  8:44 ` [PATCH 3/9] mini-os: remove MM_DEBUG code Juergen Gross
@ 2016-07-19  8:44 ` Juergen Gross
  2016-07-19  8:44 ` [PATCH 5/9] mini-os: add nr_free_pages counter Juergen Gross
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Juergen Gross @ 2016-07-19  8:44 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: Juergen Gross, samuel.thibault, wei.liu2

Add a brief description how the physical and virtual address usage
looks like on x86 to include/x86/arch_mm.h

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 include/x86/arch_mm.h | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/include/x86/arch_mm.h b/include/x86/arch_mm.h
index 58f29fc..f756dab 100644
--- a/include/x86/arch_mm.h
+++ b/include/x86/arch_mm.h
@@ -36,6 +36,26 @@
 #endif
 #endif
 
+/*
+ * Physical address space usage:
+ *
+ * 0..._edata: kernel text/data
+ * *stack    : kernel stack (thread 0)
+ * hypervisor allocated data: p2m_list, start_info page, xenstore page,
+ *                            console page, initial page tables
+ * bitmap of allocated pages
+ * pages controlled by the page allocator
+ *
+ *
+ * Virtual address space usage:
+ *
+ * 1:1 mapping of physical memory starting at VA(0)
+ * 1 unallocated page
+ * demand map area (32 bits: 2 GB, 64 bits: 128 GB) for virtual allocations
+ * 1 unallocated page
+ * with libc: heap area (32 bits: 1 GB, 64 bits: 128 GB)
+ */
+
 #define L1_FRAME                1
 #define L2_FRAME                2
 #define L3_FRAME                3
-- 
2.6.6


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

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

* [PATCH 5/9] mini-os: add nr_free_pages counter
  2016-07-19  8:44 [PATCH 0/9] mini-os: prepare for support of ballooning Juergen Gross
                   ` (3 preceding siblings ...)
  2016-07-19  8:44 ` [PATCH 4/9] mini-os: add description of x86 memory usage Juergen Gross
@ 2016-07-19  8:44 ` Juergen Gross
  2016-07-19  8:44 ` [PATCH 6/9] mini-os: let memory allocation fail if no free page available Juergen Gross
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Juergen Gross @ 2016-07-19  8:44 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: Juergen Gross, samuel.thibault, wei.liu2

Add a variable holding the number of available memory pages. This will
aid auto-ballooning later.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 include/mm.h | 1 +
 mm.c         | 6 ++++++
 2 files changed, 7 insertions(+)

diff --git a/include/mm.h b/include/mm.h
index a48f485..b97b43e 100644
--- a/include/mm.h
+++ b/include/mm.h
@@ -42,6 +42,7 @@
 #define STACK_SIZE_PAGE_ORDER __STACK_SIZE_PAGE_ORDER
 #define STACK_SIZE __STACK_SIZE
 
+extern unsigned long nr_free_pages;
 
 void init_mm(void);
 unsigned long alloc_pages(int order);
diff --git a/mm.c b/mm.c
index 0dd4862..263a356 100644
--- a/mm.c
+++ b/mm.c
@@ -53,6 +53,8 @@ static unsigned long *alloc_bitmap;
 #define allocated_in_map(_pn) \
 (alloc_bitmap[(_pn)/PAGES_PER_MAPWORD] & (1UL<<((_pn)&(PAGES_PER_MAPWORD-1))))
 
+unsigned long nr_free_pages;
+
 /*
  * Hint regarding bitwise arithmetic in map_{alloc,free}:
  *  -(1<<n)  sets all bits >= n. 
@@ -81,6 +83,8 @@ static void map_alloc(unsigned long first_page, unsigned long nr_pages)
         while ( ++curr_idx < end_idx ) alloc_bitmap[curr_idx] = ~0UL;
         alloc_bitmap[curr_idx] |= (1UL<<end_off)-1;
     }
+
+    nr_free_pages -= nr_pages;
 }
 
 
@@ -93,6 +97,8 @@ static void map_free(unsigned long first_page, unsigned long nr_pages)
     end_idx   = (first_page + nr_pages) / PAGES_PER_MAPWORD;
     end_off   = (first_page + nr_pages) & (PAGES_PER_MAPWORD-1);
 
+    nr_free_pages += nr_pages;
+
     if ( curr_idx == end_idx )
     {
         alloc_bitmap[curr_idx] &= -(1UL<<end_off) | ((1UL<<start_off)-1);
-- 
2.6.6


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

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

* [PATCH 6/9] mini-os: let memory allocation fail if no free page available
  2016-07-19  8:44 [PATCH 0/9] mini-os: prepare for support of ballooning Juergen Gross
                   ` (4 preceding siblings ...)
  2016-07-19  8:44 ` [PATCH 5/9] mini-os: add nr_free_pages counter Juergen Gross
@ 2016-07-19  8:44 ` Juergen Gross
  2016-07-19  8:44 ` [PATCH 7/9] mini-os: add ballooning config item Juergen Gross
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Juergen Gross @ 2016-07-19  8:44 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: Juergen Gross, samuel.thibault, wei.liu2

Instead of panicing when no page can be allocated try to fail the
memory allocation by returning NULL instead.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 mm.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/mm.c b/mm.c
index 263a356..185a8a5 100644
--- a/mm.c
+++ b/mm.c
@@ -335,6 +335,11 @@ void *sbrk(ptrdiff_t increment)
     
     if (new_brk > heap_mapped) {
         unsigned long n = (new_brk - heap_mapped + PAGE_SIZE - 1) / PAGE_SIZE;
+        if (n > nr_free_pages) {
+            printk("Memory exhausted: want %ld pages, but only %ld are left\n",
+                   n, nr_free_pages);
+            return NULL;
+        }
         do_map_zero(heap_mapped, n);
         heap_mapped += n * PAGE_SIZE;
     }
-- 
2.6.6


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

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

* [PATCH 7/9] mini-os: add ballooning config item
  2016-07-19  8:44 [PATCH 0/9] mini-os: prepare for support of ballooning Juergen Gross
                   ` (5 preceding siblings ...)
  2016-07-19  8:44 ` [PATCH 6/9] mini-os: let memory allocation fail if no free page available Juergen Gross
@ 2016-07-19  8:44 ` Juergen Gross
  2016-07-19  8:44 ` [PATCH 8/9] mini-os: get maximum memory size from hypervisor Juergen Gross
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Juergen Gross @ 2016-07-19  8:44 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: Juergen Gross, samuel.thibault, wei.liu2

Add CONFIG_BALLOON defaulting to 'n' as a config item to Mini-OS.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 Makefile | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/Makefile b/Makefile
index 2e4bdba..61d960c 100644
--- a/Makefile
+++ b/Makefile
@@ -33,6 +33,7 @@ CONFIG_CONSFRONT ?= y
 CONFIG_XENBUS ?= y
 CONFIG_XC ?=y
 CONFIG_LWIP ?= $(lwip)
+CONFIG_BALLOON ?= n
 
 # Export config items as compiler directives
 flags-$(CONFIG_START_NETWORK) += -DCONFIG_START_NETWORK
@@ -48,6 +49,7 @@ flags-$(CONFIG_KBDFRONT) += -DCONFIG_KBDFRONT
 flags-$(CONFIG_FBFRONT) += -DCONFIG_FBFRONT
 flags-$(CONFIG_CONSFRONT) += -DCONFIG_CONSFRONT
 flags-$(CONFIG_XENBUS) += -DCONFIG_XENBUS
+flags-$(CONFIG_BALLOON) += -DCONFIG_BALLOON
 
 DEF_CFLAGS += $(flags-y)
 
-- 
2.6.6


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

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

* [PATCH 8/9] mini-os: get maximum memory size from hypervisor
  2016-07-19  8:44 [PATCH 0/9] mini-os: prepare for support of ballooning Juergen Gross
                   ` (6 preceding siblings ...)
  2016-07-19  8:44 ` [PATCH 7/9] mini-os: add ballooning config item Juergen Gross
@ 2016-07-19  8:44 ` Juergen Gross
  2016-07-19  8:44 ` [PATCH 9/9] mini-os: modify virtual memory layout for support of ballooning Juergen Gross
  2016-07-25 13:52 ` [PATCH 0/9] mini-os: prepare " Wei Liu
  9 siblings, 0 replies; 11+ messages in thread
From: Juergen Gross @ 2016-07-19  8:44 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: Juergen Gross, samuel.thibault, wei.liu2

Add support for obtaining the maximum memory size from the hypervisor.
This will make it possible to support ballooning.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 include/mm.h |  1 +
 mm.c         | 22 ++++++++++++++++++++++
 2 files changed, 23 insertions(+)

diff --git a/include/mm.h b/include/mm.h
index b97b43e..161483f 100644
--- a/include/mm.h
+++ b/include/mm.h
@@ -43,6 +43,7 @@
 #define STACK_SIZE __STACK_SIZE
 
 extern unsigned long nr_free_pages;
+extern unsigned long nr_max_pages;
 
 void init_mm(void);
 unsigned long alloc_pages(int order);
diff --git a/mm.c b/mm.c
index 185a8a5..d4a8f1e 100644
--- a/mm.c
+++ b/mm.c
@@ -54,6 +54,7 @@ static unsigned long *alloc_bitmap;
 (alloc_bitmap[(_pn)/PAGES_PER_MAPWORD] & (1UL<<((_pn)&(PAGES_PER_MAPWORD-1))))
 
 unsigned long nr_free_pages;
+unsigned long nr_max_pages;
 
 /*
  * Hint regarding bitwise arithmetic in map_{alloc,free}:
@@ -350,7 +351,27 @@ void *sbrk(ptrdiff_t increment)
 }
 #endif
 
+#ifdef CONFIG_BALLOON
+static void get_max_pages(void)
+{
+    long ret;
+    domid_t domid = DOMID_SELF;
 
+    ret = HYPERVISOR_memory_op(XENMEM_maximum_reservation, &domid);
+    if (ret < 0) {
+        printk("Could not get maximum pfn\n");
+        return;
+    }
+
+    nr_max_pages = ret;
+    printk("Maximum memory size: %ld pages\n", nr_max_pages);
+}
+#else
+static unsigned long get_max_pages(void)
+{
+    return 0;
+}
+#endif
 
 void init_mm(void)
 {
@@ -359,6 +380,7 @@ void init_mm(void)
 
     printk("MM: Init\n");
 
+    get_max_pages();
     arch_init_mm(&start_pfn, &max_pfn);
     /*
      * now we can initialise the page allocator
-- 
2.6.6


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

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

* [PATCH 9/9] mini-os: modify virtual memory layout for support of ballooning
  2016-07-19  8:44 [PATCH 0/9] mini-os: prepare for support of ballooning Juergen Gross
                   ` (7 preceding siblings ...)
  2016-07-19  8:44 ` [PATCH 8/9] mini-os: get maximum memory size from hypervisor Juergen Gross
@ 2016-07-19  8:44 ` Juergen Gross
  2016-07-25 13:52 ` [PATCH 0/9] mini-os: prepare " Wei Liu
  9 siblings, 0 replies; 11+ messages in thread
From: Juergen Gross @ 2016-07-19  8:44 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: Juergen Gross, samuel.thibault, wei.liu2

In order to be able to support ballooning the virtual memory layout
of Mini-OS has to be modified: instead of a (nearly) consecutive
area used for physical memory mapping, on demand mappings, and heap
we need enough spare place for adding new memory.

So instead of dynamically place the different regions based on found
memory size locate them statically at fixed virtual addresses:

area                           x86-64               x86-32
------------------------------------------------------------
mapped physical memory       00000000             00000000
kernel virtual mappings    8000000000             3f000000
demand mappings          100000000000             40000000
heap                     200000000000             c0000000

This will enable Mini-OS to support up to 512GB of domain memory with
a 64 bit kernel and nearly 1GB with a 32 bit kernel.

The kernel virtual mappings are a new area needed for being able to
grow the p2m list without having to relocate it in physical memory.

Modify the placement of the demand mappings and heap and adjust the
memory layout description.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 arch/arm/mm.c         |  2 +-
 arch/x86/mm.c         | 44 +++++++++++---------------------------------
 include/mm.h          |  2 +-
 include/x86/arch_mm.h | 34 +++++++++++++++++++++++++++++-----
 mm.c                  |  2 +-
 5 files changed, 43 insertions(+), 41 deletions(-)

diff --git a/arch/arm/mm.c b/arch/arm/mm.c
index efecc51..f75888d 100644
--- a/arch/arm/mm.c
+++ b/arch/arm/mm.c
@@ -75,7 +75,7 @@ void arch_init_p2m(unsigned long max_pfn)
 {
 }
 
-void arch_init_demand_mapping_area(unsigned long cur_pfn)
+void arch_init_demand_mapping_area(void)
 {
 }
 
diff --git a/arch/x86/mm.c b/arch/x86/mm.c
index c59a5d3..088583e 100644
--- a/arch/x86/mm.c
+++ b/arch/x86/mm.c
@@ -442,37 +442,21 @@ pgentry_t *need_pgt(unsigned long va)
  * Reserve an area of virtual address space for mappings and Heap
  */
 static unsigned long demand_map_area_start;
-#ifdef __x86_64__
-#define DEMAND_MAP_PAGES ((128ULL << 30) / PAGE_SIZE)
-#else
-#define DEMAND_MAP_PAGES ((2ULL << 30) / PAGE_SIZE)
-#endif
-
-#ifndef HAVE_LIBC
-#define HEAP_PAGES 0
-#else
+static unsigned long demand_map_area_end;
+#ifdef HAVE_LIBC
 unsigned long heap, brk, heap_mapped, heap_end;
-#ifdef __x86_64__
-#define HEAP_PAGES ((128ULL << 30) / PAGE_SIZE)
-#else
-#define HEAP_PAGES ((1ULL << 30) / PAGE_SIZE)
-#endif
 #endif
 
-void arch_init_demand_mapping_area(unsigned long cur_pfn)
+void arch_init_demand_mapping_area(void)
 {
-    cur_pfn++;
-
-    demand_map_area_start = (unsigned long) pfn_to_virt(cur_pfn);
-    cur_pfn += DEMAND_MAP_PAGES;
-    printk("Demand map pfns at %lx-%p.\n", 
-           demand_map_area_start, pfn_to_virt(cur_pfn));
+    demand_map_area_start = VIRT_DEMAND_AREA;
+    demand_map_area_end = demand_map_area_start + DEMAND_MAP_PAGES * PAGE_SIZE;
+    printk("Demand map pfns at %lx-%lx.\n", demand_map_area_start,
+           demand_map_area_end);
 
 #ifdef HAVE_LIBC
-    cur_pfn++;
-    heap_mapped = brk = heap = (unsigned long) pfn_to_virt(cur_pfn);
-    cur_pfn += HEAP_PAGES;
-    heap_end = (unsigned long) pfn_to_virt(cur_pfn);
+    heap_mapped = brk = heap = VIRT_HEAP_AREA;
+    heap_end = heap_mapped + HEAP_PAGES * PAGE_SIZE;
     printk("Heap resides at %lx-%lx.\n", brk, heap_end);
 #endif
 }
@@ -729,14 +713,8 @@ void arch_init_mm(unsigned long* start_pfn_p, unsigned long* max_pfn_p)
     start_pfn = PFN_UP(to_phys(start_info.pt_base)) + start_info.nr_pt_frames;
     max_pfn = start_info.nr_pages;
 
-    /* We need room for demand mapping and heap, clip available memory */
-#if defined(__i386__)
-    {
-        unsigned long virt_pfns = 1 + DEMAND_MAP_PAGES + 1 + HEAP_PAGES;
-        if (max_pfn + virt_pfns >= 0x100000)
-            max_pfn = 0x100000 - virt_pfns - 1;
-    }
-#endif
+    if (max_pfn >= MAX_MEM_SIZE / PAGE_SIZE)
+        max_pfn = MAX_MEM_SIZE / PAGE_SIZE - 1;
 
     printk("  start_pfn: %lx\n", start_pfn);
     printk("    max_pfn: %lx\n", max_pfn);
diff --git a/include/mm.h b/include/mm.h
index 161483f..155ea69 100644
--- a/include/mm.h
+++ b/include/mm.h
@@ -60,7 +60,7 @@ static __inline__ int get_order(unsigned long size)
     return order;
 }
 
-void arch_init_demand_mapping_area(unsigned long max_pfn);
+void arch_init_demand_mapping_area(void);
 void arch_init_mm(unsigned long* start_pfn_p, unsigned long* max_pfn_p);
 void arch_init_p2m(unsigned long max_pfn_p);
 
diff --git a/include/x86/arch_mm.h b/include/x86/arch_mm.h
index f756dab..b5317ca 100644
--- a/include/x86/arch_mm.h
+++ b/include/x86/arch_mm.h
@@ -49,11 +49,13 @@
  *
  * Virtual address space usage:
  *
- * 1:1 mapping of physical memory starting at VA(0)
- * 1 unallocated page
- * demand map area (32 bits: 2 GB, 64 bits: 128 GB) for virtual allocations
- * 1 unallocated page
- * with libc: heap area (32 bits: 1 GB, 64 bits: 128 GB)
+ *  area                           x86-64               x86-32
+ *  ------------------------------------------------------------
+ *  mapped physical memory       00000000             00000000
+ *  kernel virtual mappings    8000000000             3f000000
+ *  demand mappings          100000000000             40000000
+ *  heap (with libc only)    200000000000             c0000000
+ *
  */
 
 #define L1_FRAME                1
@@ -81,6 +83,14 @@
 typedef uint64_t pgentry_t;
 #endif
 
+#define MAX_MEM_SIZE            0x3f000000UL
+#define VIRT_KERNEL_AREA        0x3f000000UL
+#define VIRT_DEMAND_AREA        0x40000000UL
+#define VIRT_HEAP_AREA          0xc0000000UL
+
+#define DEMAND_MAP_PAGES        0x7ffffUL
+#define HEAP_PAGES_MAX          0x3ffffUL
+
 #elif defined(__x86_64__)
 
 #define L2_PAGETABLE_SHIFT      21
@@ -106,6 +116,20 @@ typedef uint64_t pgentry_t;
 typedef unsigned long pgentry_t;
 #endif
 
+#define MAX_MEM_SIZE            (512ULL << 30)
+#define VIRT_KERNEL_AREA        0x0000008000000000UL
+#define VIRT_DEMAND_AREA        0x0000100000000000UL
+#define VIRT_HEAP_AREA          0x0000200000000000UL
+
+#define DEMAND_MAP_PAGES        0x8000000UL
+#define HEAP_PAGES_MAX          0x8000000UL
+
+#endif
+
+#ifndef HAVE_LIBC
+#define HEAP_PAGES 0
+#else
+#define HEAP_PAGES   HEAP_PAGES_MAX
 #endif
 
 #define L1_MASK  ((1UL << L2_PAGETABLE_SHIFT) - 1)
diff --git a/mm.c b/mm.c
index d4a8f1e..21a01df 100644
--- a/mm.c
+++ b/mm.c
@@ -393,7 +393,7 @@ void init_mm(void)
 
     arch_init_p2m(max_pfn);
     
-    arch_init_demand_mapping_area(max_pfn);
+    arch_init_demand_mapping_area();
 }
 
 void fini_mm(void)
-- 
2.6.6


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

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

* Re: [PATCH 0/9] mini-os: prepare for support of ballooning
  2016-07-19  8:44 [PATCH 0/9] mini-os: prepare for support of ballooning Juergen Gross
                   ` (8 preceding siblings ...)
  2016-07-19  8:44 ` [PATCH 9/9] mini-os: modify virtual memory layout for support of ballooning Juergen Gross
@ 2016-07-25 13:52 ` Wei Liu
  9 siblings, 0 replies; 11+ messages in thread
From: Wei Liu @ 2016-07-25 13:52 UTC (permalink / raw)
  To: Juergen Gross; +Cc: minios-devel, xen-devel, wei.liu2, samuel.thibault

Series:

Reviewed-by: Wei Liu <wei.liu2@citrix.com>

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

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

end of thread, other threads:[~2016-07-25 13:52 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-19  8:44 [PATCH 0/9] mini-os: prepare for support of ballooning Juergen Gross
2016-07-19  8:44 ` [PATCH 1/9] mini-os: correct first free pfn Juergen Gross
2016-07-19  8:44 ` [PATCH 2/9] mini-os: remove unused alloc_contig_pages() function Juergen Gross
2016-07-19  8:44 ` [PATCH 3/9] mini-os: remove MM_DEBUG code Juergen Gross
2016-07-19  8:44 ` [PATCH 4/9] mini-os: add description of x86 memory usage Juergen Gross
2016-07-19  8:44 ` [PATCH 5/9] mini-os: add nr_free_pages counter Juergen Gross
2016-07-19  8:44 ` [PATCH 6/9] mini-os: let memory allocation fail if no free page available Juergen Gross
2016-07-19  8:44 ` [PATCH 7/9] mini-os: add ballooning config item Juergen Gross
2016-07-19  8:44 ` [PATCH 8/9] mini-os: get maximum memory size from hypervisor Juergen Gross
2016-07-19  8:44 ` [PATCH 9/9] mini-os: modify virtual memory layout for support of ballooning Juergen Gross
2016-07-25 13:52 ` [PATCH 0/9] mini-os: prepare " Wei Liu

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