From: Juergen Gross <jgross@suse.com>
To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org
Cc: Juergen Gross <jgross@suse.com>,
samuel.thibault@ens-lyon.org, wei.liu2@citrix.com
Subject: [PATCH v2 16/18] mini-os: map page allocator's bitmap to virtual kernel area for ballooning
Date: Fri, 5 Aug 2016 19:36:00 +0200 [thread overview]
Message-ID: <1470418562-11234-17-git-send-email-jgross@suse.com> (raw)
In-Reply-To: <1470418562-11234-1-git-send-email-jgross@suse.com>
In case of CONFIG_BALLOON the page allocator's bitmap needs some space
to be able to grow. Remap it to kernel virtual area if the preallocated
area isn't large enough.
Signed-off-by: Juergen Gross <jgross@suse.com>
---
balloon.c | 17 +++++++++++++++++
include/balloon.h | 2 ++
include/mm.h | 6 ++++++
mm.c | 19 ++++++++++---------
4 files changed, 35 insertions(+), 9 deletions(-)
diff --git a/balloon.c b/balloon.c
index 4c18c5c..75b87c8 100644
--- a/balloon.c
+++ b/balloon.c
@@ -44,3 +44,20 @@ void get_max_pages(void)
nr_max_pages = ret;
printk("Maximum memory size: %ld pages\n", nr_max_pages);
}
+
+void alloc_bitmap_remap(void)
+{
+ unsigned long i;
+
+ if ( alloc_bitmap_size >= ((nr_max_pages + 1) >> (PAGE_SHIFT + 3)) )
+ return;
+
+ for ( i = 0; i < alloc_bitmap_size; i += PAGE_SIZE )
+ {
+ map_frame_rw(virt_kernel_area_end + i,
+ virt_to_mfn((unsigned long)(alloc_bitmap) + i));
+ }
+
+ alloc_bitmap = (unsigned long *)virt_kernel_area_end;
+ virt_kernel_area_end += round_pgup((nr_max_pages + 1) >> (PAGE_SHIFT + 3));
+}
diff --git a/include/balloon.h b/include/balloon.h
index b8d9335..0e2340b 100644
--- a/include/balloon.h
+++ b/include/balloon.h
@@ -31,11 +31,13 @@ extern unsigned long virt_kernel_area_end;
void get_max_pages(void);
void arch_remap_p2m(unsigned long max_pfn);
+void alloc_bitmap_remap(void);
#else /* CONFIG_BALLOON */
static inline void get_max_pages(void) { }
static inline void arch_remap_p2m(unsigned long max_pfn) { }
+static inline void alloc_bitmap_remap(void) { }
#endif /* CONFIG_BALLOON */
#endif /* _BALLOON_H_ */
diff --git a/include/mm.h b/include/mm.h
index 6add683..73c59c4 100644
--- a/include/mm.h
+++ b/include/mm.h
@@ -42,8 +42,14 @@
#define STACK_SIZE_PAGE_ORDER __STACK_SIZE_PAGE_ORDER
#define STACK_SIZE __STACK_SIZE
+#define round_pgdown(_p) ((_p) & PAGE_MASK)
+#define round_pgup(_p) (((_p) + (PAGE_SIZE - 1)) & PAGE_MASK)
+
extern unsigned long nr_free_pages;
+extern unsigned long *alloc_bitmap;
+extern unsigned long alloc_bitmap_size;
+
void init_mm(void);
unsigned long alloc_pages(int order);
#define alloc_page() alloc_pages(0)
diff --git a/mm.c b/mm.c
index fd66115..13bb3e5 100644
--- a/mm.c
+++ b/mm.c
@@ -48,7 +48,9 @@
* One bit per page of memory. Bit set => page is allocated.
*/
-static unsigned long *alloc_bitmap;
+unsigned long *alloc_bitmap;
+unsigned long alloc_bitmap_size;
+
#define PAGES_PER_MAPWORD (sizeof(unsigned long) * 8)
#define allocated_in_map(_pn) \
@@ -137,9 +139,6 @@ static chunk_head_t *free_head[FREELIST_SIZE];
static chunk_head_t free_tail[FREELIST_SIZE];
#define FREELIST_EMPTY(_l) ((_l)->next == NULL)
-#define round_pgdown(_p) ((_p)&PAGE_MASK)
-#define round_pgup(_p) (((_p)+(PAGE_SIZE-1))&PAGE_MASK)
-
/*
* Initialise allocator, placing addresses [@min,@max] in free pool.
* @min and @max are PHYSICAL addresses.
@@ -147,7 +146,7 @@ static chunk_head_t free_tail[FREELIST_SIZE];
static void init_page_allocator(unsigned long min, unsigned long max)
{
int i;
- unsigned long range, bitmap_size;
+ unsigned long range;
chunk_head_t *ch;
chunk_tail_t *ct;
for ( i = 0; i < FREELIST_SIZE; i++ )
@@ -161,14 +160,14 @@ static void init_page_allocator(unsigned long min, unsigned long max)
max = round_pgdown(max);
/* Allocate space for the allocation bitmap. */
- bitmap_size = (max+1) >> (PAGE_SHIFT+3);
- bitmap_size = round_pgup(bitmap_size);
+ alloc_bitmap_size = (max + 1) >> (PAGE_SHIFT + 3);
+ alloc_bitmap_size = round_pgup(alloc_bitmap_size);
alloc_bitmap = (unsigned long *)to_virt(min);
- min += bitmap_size;
+ min += alloc_bitmap_size;
range = max - min;
/* All allocated by default. */
- memset(alloc_bitmap, ~0, bitmap_size);
+ memset(alloc_bitmap, ~0, alloc_bitmap_size);
/* Free up the memory we've been given to play with. */
map_free(PHYS_PFN(min), range>>PAGE_SHIFT);
@@ -198,6 +197,8 @@ static void init_page_allocator(unsigned long min, unsigned long max)
free_head[i] = ch;
ct->level = i;
}
+
+ alloc_bitmap_remap();
}
--
2.6.6
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2016-08-05 17:36 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-05 17:35 [PATCH v2 00/18] mini-os: support of auto-ballooning Juergen Gross
2016-08-05 17:35 ` [PATCH v2 01/18] mini-os: correct first free pfn Juergen Gross
2016-08-10 20:02 ` Samuel Thibault
2016-08-05 17:35 ` [PATCH v2 02/18] mini-os: remove unused alloc_contig_pages() function Juergen Gross
2016-08-10 20:02 ` Samuel Thibault
2016-08-05 17:35 ` [PATCH v2 03/18] mini-os: remove MM_DEBUG code Juergen Gross
2016-08-10 20:03 ` Samuel Thibault
2016-08-05 17:35 ` [PATCH v2 04/18] mini-os: add description of x86 memory usage Juergen Gross
2016-08-10 20:04 ` Samuel Thibault
2016-08-05 17:35 ` [PATCH v2 05/18] mini-os: add nr_free_pages counter Juergen Gross
2016-08-10 20:05 ` Samuel Thibault
2016-08-05 17:35 ` [PATCH v2 06/18] mini-os: let memory allocation fail if no free page available Juergen Gross
2016-08-10 20:06 ` Samuel Thibault
2016-08-05 17:35 ` [PATCH v2 07/18] mini-os: add ballooning config item Juergen Gross
2016-08-10 20:10 ` Samuel Thibault
2016-08-05 17:35 ` [PATCH v2 08/18] mini-os: get maximum memory size from hypervisor Juergen Gross
2016-08-10 20:11 ` Samuel Thibault
2016-08-05 17:35 ` [PATCH v2 09/18] mini-os: modify virtual memory layout for support of ballooning Juergen Gross
2016-08-10 20:16 ` Samuel Thibault
2016-08-05 17:35 ` [PATCH v2 10/18] mini-os: remove unused mem_test() function Juergen Gross
2016-08-10 20:17 ` Samuel Thibault
2016-08-05 17:35 ` [PATCH v2 11/18] mini-os: add checks for out of memory Juergen Gross
2016-08-10 20:18 ` Samuel Thibault
2016-08-05 17:35 ` [PATCH v2 12/18] mini-os: don't allocate new pages for level 1 p2m tree Juergen Gross
2016-08-10 20:24 ` Samuel Thibault
2016-08-05 17:35 ` [PATCH v2 13/18] mini-os: add function to map one frame Juergen Gross
2016-08-10 20:26 ` Samuel Thibault
2016-08-05 17:35 ` [PATCH v2 14/18] mini-os: move p2m related macros to header file Juergen Gross
2016-08-10 20:29 ` Samuel Thibault
2016-08-05 17:35 ` [PATCH v2 15/18] mini-os: remap p2m list in case of ballooning Juergen Gross
2016-08-10 20:35 ` Samuel Thibault
2016-08-10 20:41 ` Samuel Thibault
2016-08-11 4:04 ` Juergen Gross
2016-08-05 17:36 ` Juergen Gross [this message]
2016-08-10 20:45 ` [PATCH v2 16/18] mini-os: map page allocator's bitmap to virtual kernel area for ballooning Samuel Thibault
2016-08-11 4:05 ` Juergen Gross
2016-08-05 17:36 ` [PATCH v2 17/18] mini-os: add support for ballooning up Juergen Gross
2016-08-10 21:02 ` Samuel Thibault
2016-08-11 5:50 ` Juergen Gross
2016-08-05 17:36 ` [PATCH v2 18/18] mini-os: balloon up in case of oom Juergen Gross
2016-08-10 21:07 ` Samuel Thibault
2016-08-11 5:51 ` Juergen Gross
2016-08-10 21:07 ` [PATCH v2 00/18] mini-os: support of auto-ballooning Samuel Thibault
2016-08-11 5:52 ` Juergen Gross
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1470418562-11234-17-git-send-email-jgross@suse.com \
--to=jgross@suse.com \
--cc=minios-devel@lists.xenproject.org \
--cc=samuel.thibault@ens-lyon.org \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).