virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2, part1 01/29] mm: introduce common help functions to deal with reserved/managed pages
       [not found] <1362896833-21104-1-git-send-email-jiang.liu@huawei.com>
@ 2013-03-10  6:26 ` Jiang Liu
  2013-03-10  9:20   ` Geert Uytterhoeven
       [not found]   ` <CAMuHMdXLEkKVfhPu-MfBE37SuHDoVtrEG92PZq2-nD3xw6GNQw@mail.gmail.com>
  0 siblings, 2 replies; 3+ messages in thread
From: Jiang Liu @ 2013-03-10  6:26 UTC (permalink / raw)
  To: Andrew Morton, David Rientjes
  Cc: xen-devel, Jeremy Fitzhardinge, x86, Aurelien Jacquiot,
	Benjamin Herrenschmidt, Heiko Carstens, linux-snps-arc, Tang Chen,
	Michal Hocko, Chen Liqin, Paul Mackerras, H. Peter Anvin,
	Guan Xuetao, Sam Ravnborg, Lennox Wu, Maciej Rutecki, Jonas Bonn,
	Mark Salter, Michel Lespinasse, Mikael Starvik, Yoshinori Sato,
	Helge Deller, Konrad Rzeszutek Wilk, James E.J. Bottomley

Code to deal with reserved/managed pages are duplicated by many
architectures, so introduce common help functions to reduce duplicated
code. These common help functions will also be used to concentrate code
to modify totalram_pages and zone->managed_pages, which makes the code
much more clear.

Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
---
 include/linux/mm.h |   48 ++++++++++++++++++++++++++++++++++++++++++++++++
 mm/page_alloc.c    |   20 ++++++++++++++++++++
 2 files changed, 68 insertions(+)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index 7acc9dc..d75c14b 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -1295,6 +1295,54 @@ extern void free_area_init_node(int nid, unsigned long * zones_size,
 		unsigned long zone_start_pfn, unsigned long *zholes_size);
 extern void free_initmem(void);
 
+/*
+ * Free reserved pages within range [PAGE_ALIGN(start), end & PAGE_MASK)
+ * into the buddy system. The freed pages will be poisoned with pattern
+ * "poison" if it's non-zero.
+ * Return pages freed into the buddy system.
+ */
+extern unsigned long free_reserved_area(unsigned long start, unsigned long end,
+					int poison, char *s);
+
+static inline void adjust_managed_page_count(struct page *page, long count)
+{
+	totalram_pages += count;
+}
+
+/* Free the reserved page into the buddy system, so it gets managed. */
+static inline void __free_reserved_page(struct page *page)
+{
+	ClearPageReserved(page);
+	init_page_count(page);
+	__free_page(page);
+}
+
+static inline void free_reserved_page(struct page *page)
+{
+	__free_reserved_page(page);
+	adjust_managed_page_count(page, 1);
+}
+
+static inline void mark_page_reserved(struct page *page)
+{
+	SetPageReserved(page);
+	adjust_managed_page_count(page, -1);
+}
+
+/*
+ * Default method to free all the __init memory into the buddy system.
+ * The freed pages will be poisoned with pattern "poison" if it is
+ * non-zero. Return pages freed into the buddy system.
+ */
+static inline unsigned long free_initmem_default(int poison)
+{
+	extern char __init_begin[], __init_end[];
+
+	return free_reserved_area(PAGE_ALIGN((unsigned long)&__init_begin) ,
+				  ((unsigned long)&__init_end) & PAGE_MASK,
+				  poison, "unused kernel");
+}
+
 #ifdef CONFIG_HAVE_MEMBLOCK_NODE_MAP
 /*
  * With CONFIG_HAVE_MEMBLOCK_NODE_MAP set, an architecture may initialise its
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 8fcced7..0fadb09 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -5113,6 +5113,26 @@ early_param("movablecore", cmdline_parse_movablecore);
 
 #endif /* CONFIG_HAVE_MEMBLOCK_NODE_MAP */
 
+unsigned long free_reserved_area(unsigned long start, unsigned long end,
+				 int poison, char *s)
+{
+	unsigned long pages, pos;
+
+	pos = start = PAGE_ALIGN(start);
+	end &= PAGE_MASK;
+	for (pages = 0; pos < end; pos += PAGE_SIZE, pages++) {
+		if (poison)
+			memset((void *)pos, poison, PAGE_SIZE);
+		free_reserved_page(virt_to_page(pos));
+	}
+
+	if (pages && s)
+		pr_info("Freeing %s memory: %ldK (%lx - %lx)\n",
+			s, pages << (PAGE_SHIFT - 10), start, end);
+
+	return pages;
+}
+
 /**
  * set_dma_reserve - set the specified number of pages reserved in the first zone
  * @new_dma_reserve: The number of pages to mark reserved
-- 
1.7.9.5

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

* Re: [PATCH v2, part1 01/29] mm: introduce common help functions to deal with reserved/managed pages
  2013-03-10  6:26 ` [PATCH v2, part1 01/29] mm: introduce common help functions to deal with reserved/managed pages Jiang Liu
@ 2013-03-10  9:20   ` Geert Uytterhoeven
       [not found]   ` <CAMuHMdXLEkKVfhPu-MfBE37SuHDoVtrEG92PZq2-nD3xw6GNQw@mail.gmail.com>
  1 sibling, 0 replies; 3+ messages in thread
From: Geert Uytterhoeven @ 2013-03-10  9:20 UTC (permalink / raw)
  To: Jiang Liu
  Cc: xen-devel, Jeremy Fitzhardinge, x86, Aurelien Jacquiot,
	Catalin Marinas, Heiko Carstens, linux-snps-arc, Tang Chen,
	David Howells, Chen Liqin, Paul Mackerras, H. Peter Anvin,
	Guan Xuetao, Sam Ravnborg, Lennox Wu, Maciej Rutecki, Jonas Bonn,
	Mark Salter, Michel Lespinasse, Mikael Starvik, Yoshinori Sato,
	Helge Deller, Konrad Rzeszutek Wilk, James E.J. Bottomley

On Sun, Mar 10, 2013 at 7:26 AM, Jiang Liu <liuj97@gmail.com> wrote:
> Code to deal with reserved/managed pages are duplicated by many
> architectures, so introduce common help functions to reduce duplicated
> code. These common help functions will also be used to concentrate code
> to modify totalram_pages and zone->managed_pages, which makes the code
> much more clear.
>
> Signed-off-by: Jiang Liu <jiang.liu@huawei.com>

I have a few minor comments (see below), but apart from that:
Acked-by: Geert Uytterhoeven <geert@linux-m68k.org>

> ---
>  include/linux/mm.h |   48 ++++++++++++++++++++++++++++++++++++++++++++++++
>  mm/page_alloc.c    |   20 ++++++++++++++++++++
>  2 files changed, 68 insertions(+)
>
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index 7acc9dc..d75c14b 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -1295,6 +1295,54 @@ extern void free_area_init_node(int nid, unsigned long * zones_size,
>                 unsigned long zone_start_pfn, unsigned long *zholes_size);
>  extern void free_initmem(void);
>
> +/*
> + * Free reserved pages within range [PAGE_ALIGN(start), end & PAGE_MASK)
> + * into the buddy system. The freed pages will be poisoned with pattern
> + * "poison" if it's non-zero.

What if you want to poison with zero?
As poison is a full int, but memset only uses the least-significant
byte, you can
change it to poison if it's positive (i.e. >= 0)?

> +/*
> + * Default method to free all the __init memory into the buddy system.
> + * The freed pages will be poisoned with pattern "poison" if it is
> + * non-zero. Return pages freed into the buddy system.
> + */
> +static inline unsigned long free_initmem_default(int poison)
> +{
> +       extern char __init_begin[], __init_end[];
> +
> +       return free_reserved_area(PAGE_ALIGN((unsigned long)&__init_begin) ,
> +                                 ((unsigned long)&__init_end) & PAGE_MASK,

The "PAGE_ALIGN(...)" and "& PAGE_MASK" are superfluous, as
free_reserved_area() already does that.

> +                                 poison, "unused kernel");
> +}
> +

> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 8fcced7..0fadb09 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -5113,6 +5113,26 @@ early_param("movablecore", cmdline_parse_movablecore);
>
>  #endif /* CONFIG_HAVE_MEMBLOCK_NODE_MAP */
>
> +unsigned long free_reserved_area(unsigned long start, unsigned long end,
> +                                int poison, char *s)
> +{

> +       if (pages && s)
> +               pr_info("Freeing %s memory: %ldK (%lx - %lx)\n",

"%luKiB (0x%lx - 0x%lx)"?

> +                       s, pages << (PAGE_SHIFT - 10), start, end);
> +
> +       return pages;
> +}

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH v2, part1 01/29] mm: introduce common help functions to deal with reserved/managed pages
       [not found]   ` <CAMuHMdXLEkKVfhPu-MfBE37SuHDoVtrEG92PZq2-nD3xw6GNQw@mail.gmail.com>
@ 2013-03-11 22:17     ` Jiang Liu
  0 siblings, 0 replies; 3+ messages in thread
From: Jiang Liu @ 2013-03-11 22:17 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: xen-devel, Jeremy Fitzhardinge, x86, Aurelien Jacquiot,
	Catalin Marinas, Heiko Carstens, linux-snps-arc, Tang Chen,
	David Howells, Chen Liqin, Paul Mackerras, H. Peter Anvin,
	Guan Xuetao, Sam Ravnborg, Lennox Wu, Maciej Rutecki, Jonas Bonn,
	Mark Salter, Michel Lespinasse, Mikael Starvik, Yoshinori Sato,
	Helge Deller, Konrad Rzeszutek Wilk, James E.J. Bottomley

Hi Geert,
	Thanks for review!

On 03/10/2013 05:20 PM, Geert Uytterhoeven wrote:
> On Sun, Mar 10, 2013 at 7:26 AM, Jiang Liu <liuj97@gmail.com> wrote:
>> Code to deal with reserved/managed pages are duplicated by many
>> architectures, so introduce common help functions to reduce duplicated
>> code. These common help functions will also be used to concentrate code
>> to modify totalram_pages and zone->managed_pages, which makes the code
>> much more clear.
>>
>> Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
> 
> I have a few minor comments (see below), but apart from that:
> Acked-by: Geert Uytterhoeven <geert@linux-m68k.org>
> 
>> ---
>>  include/linux/mm.h |   48 ++++++++++++++++++++++++++++++++++++++++++++++++
>>  mm/page_alloc.c    |   20 ++++++++++++++++++++
>>  2 files changed, 68 insertions(+)
>>
>> diff --git a/include/linux/mm.h b/include/linux/mm.h
>> index 7acc9dc..d75c14b 100644
>> --- a/include/linux/mm.h
>> +++ b/include/linux/mm.h
>> @@ -1295,6 +1295,54 @@ extern void free_area_init_node(int nid, unsigned long * zones_size,
>>                 unsigned long zone_start_pfn, unsigned long *zholes_size);
>>  extern void free_initmem(void);
>>
>> +/*
>> + * Free reserved pages within range [PAGE_ALIGN(start), end & PAGE_MASK)
>> + * into the buddy system. The freed pages will be poisoned with pattern
>> + * "poison" if it's non-zero.
> 
> What if you want to poison with zero?
> As poison is a full int, but memset only uses the least-significant
> byte, you can
> change it to poison if it's positive (i.e. >= 0)?
Good point, ARM64 does poison memory with 0. Will implement that way in next version.

> 
>> +/*
>> + * Default method to free all the __init memory into the buddy system.
>> + * The freed pages will be poisoned with pattern "poison" if it is
>> + * non-zero. Return pages freed into the buddy system.
>> + */
>> +static inline unsigned long free_initmem_default(int poison)
>> +{
>> +       extern char __init_begin[], __init_end[];
>> +
>> +       return free_reserved_area(PAGE_ALIGN((unsigned long)&__init_begin) ,
>> +                                 ((unsigned long)&__init_end) & PAGE_MASK,
> 
> The "PAGE_ALIGN(...)" and "& PAGE_MASK" are superfluous, as
> free_reserved_area() already does that.
Will remove the redundant ops next version.

> 
>> +                                 poison, "unused kernel");
>> +}
>> +
> 
>> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
>> index 8fcced7..0fadb09 100644
>> --- a/mm/page_alloc.c
>> +++ b/mm/page_alloc.c
>> @@ -5113,6 +5113,26 @@ early_param("movablecore", cmdline_parse_movablecore);
>>
>>  #endif /* CONFIG_HAVE_MEMBLOCK_NODE_MAP */
>>
>> +unsigned long free_reserved_area(unsigned long start, unsigned long end,
>> +                                int poison, char *s)
>> +{
> 
>> +       if (pages && s)
>> +               pr_info("Freeing %s memory: %ldK (%lx - %lx)\n",
> 
> "%luKiB (0x%lx - 0x%lx)"?
Sure.

Regards!
Gerry

> 
>> +                       s, pages << (PAGE_SHIFT - 10), start, end);
>> +
>> +       return pages;
>> +}
> 
> Gr{oetje,eeting}s,
> 
>                         Geert
> 
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
> 
> In personal conversations with technical people, I call myself a hacker. But
> when I'm talking to journalists I just say "programmer" or something like that.
>                                 -- Linus Torvalds
> 

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

end of thread, other threads:[~2013-03-11 22:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <1362896833-21104-1-git-send-email-jiang.liu@huawei.com>
2013-03-10  6:26 ` [PATCH v2, part1 01/29] mm: introduce common help functions to deal with reserved/managed pages Jiang Liu
2013-03-10  9:20   ` Geert Uytterhoeven
     [not found]   ` <CAMuHMdXLEkKVfhPu-MfBE37SuHDoVtrEG92PZq2-nD3xw6GNQw@mail.gmail.com>
2013-03-11 22:17     ` Jiang 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).