All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org,
	Andrew Morton <akpm@linux-foundation.org>,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	Paul Mackerras <paulus@samba.org>,
	Michael Ellerman <mpe@ellerman.id.au>,
	Thiago Jung Bauermann <bauerman@linux.ibm.com>,
	Geert Uytterhoeven <geert@linux-m68k.org>,
	Anshuman Khandual <khandual@linux.vnet.ibm.com>,
	Oliver O'Halloran <oohall@gmail.com>,
	Alexey Kardashevskiy <aik@ozlabs.ru>,
	"Enrico Weigelt, metux IT consult" <info@metux.net>,
	Thomas Gleixner <tglx@linutronix.de>,
	Allison Randal <allison@lohutok.net>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Pavel Tatashin <pasha.tatashin@soleen.com>,
	Arun KS <arunks@codeaurora.org>, Todd Kjos <tkjos@google.com>,
	Christian Brauner <christian@brauner.io>,
	Gao Xiang <xiang@kernel.org>,
	Greg Hackmann <ghackmann@google.com>,
	David Howells <dhowells@redhat.com>
Subject: Re: [PATCH v1 08/12] powerpc/pseries: CMM: Implement balloon compaction
Date: Thu, 31 Oct 2019 15:35:13 +0100	[thread overview]
Message-ID: <be7c1424-f240-b72c-8d6d-310ebbd816e1@redhat.com> (raw)
In-Reply-To: <20191031142933.10779-9-david@redhat.com>

On 31.10.19 15:29, David Hildenbrand wrote:
> We can now get rid of the cmm_lock and completely rely on the balloon
> compaction internals, which now also manage the page list and the lock.
> 
> Inflated/"loaned" pages are now movable. Memory blocks that contain
> such apges can get offlined. Also, all such pages will be marked
> PageOffline() and can therefore be excluded in memory dumps using recent
> versions of makedumpfile.
> 
> Don't switch to balloon_page_alloc() yet (due to the GFP_NOIO). Will
> do that separately to discuss this change in detail.
> 
> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> Cc: Paul Mackerras <paulus@samba.org>
> Cc: Michael Ellerman <mpe@ellerman.id.au>
> Cc: Thiago Jung Bauermann <bauerman@linux.ibm.com>
> Cc: Geert Uytterhoeven <geert@linux-m68k.org>
> Cc: Anshuman Khandual <khandual@linux.vnet.ibm.com>
> Cc: "Oliver O'Halloran" <oohall@gmail.com>
> Cc: Alexey Kardashevskiy <aik@ozlabs.ru>
> Cc: "Enrico Weigelt, metux IT consult" <info@metux.net>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Allison Randal <allison@lohutok.net>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Pavel Tatashin <pasha.tatashin@soleen.com>
> Cc: Arun KS <arunks@codeaurora.org>
> Cc: Todd Kjos <tkjos@google.com>
> Cc: Christian Brauner <christian@brauner.io>
> Cc: Gao Xiang <xiang@kernel.org>
> Cc: Greg Hackmann <ghackmann@google.com>
> Cc: David Howells <dhowells@redhat.com>
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
>   arch/powerpc/platforms/pseries/Kconfig |   1 +
>   arch/powerpc/platforms/pseries/cmm.c   | 132 ++++++++++++++++++++++---
>   include/uapi/linux/magic.h             |   1 +
>   3 files changed, 120 insertions(+), 14 deletions(-)
> 
> diff --git a/arch/powerpc/platforms/pseries/Kconfig b/arch/powerpc/platforms/pseries/Kconfig
> index 9e35cddddf73..595e9f8a6539 100644
> --- a/arch/powerpc/platforms/pseries/Kconfig
> +++ b/arch/powerpc/platforms/pseries/Kconfig
> @@ -108,6 +108,7 @@ config PPC_SMLPAR
>   config CMM
>   	tristate "Collaborative memory management"
>   	depends on PPC_SMLPAR
> +	select MEMORY_BALLOON
>   	default y
>   	help
>   	  Select this option, if you want to enable the kernel interface
> diff --git a/arch/powerpc/platforms/pseries/cmm.c b/arch/powerpc/platforms/pseries/cmm.c
> index 3a55dd1fdd39..235fd7fe9df1 100644
> --- a/arch/powerpc/platforms/pseries/cmm.c
> +++ b/arch/powerpc/platforms/pseries/cmm.c
> @@ -19,6 +19,10 @@
>   #include <linux/stringify.h>
>   #include <linux/swap.h>
>   #include <linux/device.h>
> +#include <linux/mount.h>
> +#include <linux/pseudo_fs.h>
> +#include <linux/magic.h>
> +#include <linux/balloon_compaction.h>
>   #include <asm/firmware.h>
>   #include <asm/hvcall.h>
>   #include <asm/mmu.h>
> @@ -77,13 +81,11 @@ static atomic_long_t loaned_pages;
>   static unsigned long loaned_pages_target;
>   static unsigned long oom_freed_pages;
>   
> -static LIST_HEAD(cmm_page_list);
> -static DEFINE_SPINLOCK(cmm_lock);
> -
>   static DEFINE_MUTEX(hotplug_mutex);
>   static int hotplug_occurred; /* protected by the hotplug mutex */
>   
>   static struct task_struct *cmm_thread_ptr;
> +static struct balloon_dev_info b_dev_info;
>   
>   static long plpar_page_set_loaned(struct page *page)
>   {
> @@ -149,19 +151,16 @@ static long cmm_alloc_pages(long nr)
>   				  __GFP_NOMEMALLOC);
>   		if (!page)
>   			break;
> -		spin_lock(&cmm_lock);
>   		rc = plpar_page_set_loaned(page);
>   		if (rc) {
>   			pr_err("%s: Can not set page to loaned. rc=%ld\n", __func__, rc);
> -			spin_unlock(&cmm_lock);
>   			__free_page(page);
>   			break;
>   		}
>   
> -		list_add(&page->lru, &cmm_page_list);
> +		balloon_page_enqueue(&b_dev_info, page);
>   		atomic_long_inc(&loaned_pages);
>   		adjust_managed_page_count(page, -1);
> -		spin_unlock(&cmm_lock);
>   		nr--;
>   	}
>   
> @@ -178,21 +177,19 @@ static long cmm_alloc_pages(long nr)
>    **/
>   static long cmm_free_pages(long nr)
>   {
> -	struct page *page, *tmp;
> +	struct page *page;
>   
>   	cmm_dbg("Begin free of %ld pages.\n", nr);
> -	spin_lock(&cmm_lock);
> -	list_for_each_entry_safe(page, tmp, &cmm_page_list, lru) {
> -		if (!nr)
> +	while (nr) {
> +		page = balloon_page_dequeue(&b_dev_info);
> +		if (!page)
>   			break;
>   		plpar_page_set_active(page);
> -		list_del(&page->lru);
>   		adjust_managed_page_count(page, 1);
>   		__free_page(page);
>   		atomic_long_dec(&loaned_pages);
>   		nr--;
>   	}
> -	spin_unlock(&cmm_lock);
>   	cmm_dbg("End request with %ld pages unfulfilled\n", nr);
>   	return nr;
>   }
> @@ -484,6 +481,105 @@ static struct notifier_block cmm_mem_nb = {
>   	.priority = CMM_MEM_HOTPLUG_PRI
>   };
>   
> +#ifdef CONFIG_BALLOON_COMPACTION
> +static struct vfsmount *balloon_mnt;
> +
> +static int cmm_init_fs_context(struct fs_context *fc)
> +{
> +	return init_pseudo(fc, PPC_CMM_MAGIC) ? 0 : -ENOMEM;
> +}
> +
> +static struct file_system_type balloon_fs = {
> +	.name = "ppc-cmm",
> +	.init_fs_context = cmm_init_fs_context,
> +	.kill_sb = kill_anon_super,
> +};
> +
> +static int cmm_migratepage(struct balloon_dev_info *b_dev_info,
> +			   struct page *newpage, struct page *page,
> +			   enum migrate_mode mode)
> +{
> +	unsigned long flags;
> +
> +	/*
> +	 * loan/"inflate" the newpage first.
> +	 *
> +	 * We might race against the cmm_thread who might discover after our
> +	 * loan request that another page is to be unloaned. However, once
> +	 * the cmm_thread runs again later, this error will automatically
> +	 * be corrected.
> +	 */
> +	if (plpar_page_set_loaned(newpage)) {
> +		/* Unlikely, but possible. Tell the caller not to retry now. */
> +		pr_err_ratelimited("%s: Cannot set page to loaned.", __func__);
> +		return -EBUSY;
> +	}
> +
> +	/* balloon page list reference */
> +	get_page(newpage);
> +
> +	spin_lock_irqsave(&b_dev_info->pages_lock, flags);
> +	balloon_page_insert(b_dev_info, newpage);
> +	balloon_page_delete(page);

I think I am missing a b_dev_info->isolated_pages-- here.

> +	spin_unlock_irqrestore(&b_dev_info->pages_lock, flags);


-- 

Thanks,

David / dhildenb


WARNING: multiple messages have this Message-ID (diff)
From: David Hildenbrand <david@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: Alexey Kardashevskiy <aik@ozlabs.ru>,
	David Howells <dhowells@redhat.com>,
	linux-mm@kvack.org, Oliver O'Halloran <oohall@gmail.com>,
	Paul Mackerras <paulus@samba.org>,
	Anshuman Khandual <khandual@linux.vnet.ibm.com>,
	Greg Hackmann <ghackmann@google.com>,
	Geert Uytterhoeven <geert@linux-m68k.org>,
	Christian Brauner <christian@brauner.io>,
	Gao Xiang <xiang@kernel.org>,
	Pavel Tatashin <pasha.tatashin@soleen.com>,
	linuxppc-dev@lists.ozlabs.org,
	Thomas Gleixner <tglx@linutronix.de>,
	Allison Randal <allison@lohutok.net>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Arun KS <arunks@codeaurora.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	"Enrico Weigelt, metux IT consult" <info@metux.net>,
	Thiago Jung Bauermann <bauerman@linux.ibm.com>,
	Todd Kjos <tkjos@google.com>
Subject: Re: [PATCH v1 08/12] powerpc/pseries: CMM: Implement balloon compaction
Date: Thu, 31 Oct 2019 15:35:13 +0100	[thread overview]
Message-ID: <be7c1424-f240-b72c-8d6d-310ebbd816e1@redhat.com> (raw)
In-Reply-To: <20191031142933.10779-9-david@redhat.com>

On 31.10.19 15:29, David Hildenbrand wrote:
> We can now get rid of the cmm_lock and completely rely on the balloon
> compaction internals, which now also manage the page list and the lock.
> 
> Inflated/"loaned" pages are now movable. Memory blocks that contain
> such apges can get offlined. Also, all such pages will be marked
> PageOffline() and can therefore be excluded in memory dumps using recent
> versions of makedumpfile.
> 
> Don't switch to balloon_page_alloc() yet (due to the GFP_NOIO). Will
> do that separately to discuss this change in detail.
> 
> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> Cc: Paul Mackerras <paulus@samba.org>
> Cc: Michael Ellerman <mpe@ellerman.id.au>
> Cc: Thiago Jung Bauermann <bauerman@linux.ibm.com>
> Cc: Geert Uytterhoeven <geert@linux-m68k.org>
> Cc: Anshuman Khandual <khandual@linux.vnet.ibm.com>
> Cc: "Oliver O'Halloran" <oohall@gmail.com>
> Cc: Alexey Kardashevskiy <aik@ozlabs.ru>
> Cc: "Enrico Weigelt, metux IT consult" <info@metux.net>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Allison Randal <allison@lohutok.net>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Pavel Tatashin <pasha.tatashin@soleen.com>
> Cc: Arun KS <arunks@codeaurora.org>
> Cc: Todd Kjos <tkjos@google.com>
> Cc: Christian Brauner <christian@brauner.io>
> Cc: Gao Xiang <xiang@kernel.org>
> Cc: Greg Hackmann <ghackmann@google.com>
> Cc: David Howells <dhowells@redhat.com>
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
>   arch/powerpc/platforms/pseries/Kconfig |   1 +
>   arch/powerpc/platforms/pseries/cmm.c   | 132 ++++++++++++++++++++++---
>   include/uapi/linux/magic.h             |   1 +
>   3 files changed, 120 insertions(+), 14 deletions(-)
> 
> diff --git a/arch/powerpc/platforms/pseries/Kconfig b/arch/powerpc/platforms/pseries/Kconfig
> index 9e35cddddf73..595e9f8a6539 100644
> --- a/arch/powerpc/platforms/pseries/Kconfig
> +++ b/arch/powerpc/platforms/pseries/Kconfig
> @@ -108,6 +108,7 @@ config PPC_SMLPAR
>   config CMM
>   	tristate "Collaborative memory management"
>   	depends on PPC_SMLPAR
> +	select MEMORY_BALLOON
>   	default y
>   	help
>   	  Select this option, if you want to enable the kernel interface
> diff --git a/arch/powerpc/platforms/pseries/cmm.c b/arch/powerpc/platforms/pseries/cmm.c
> index 3a55dd1fdd39..235fd7fe9df1 100644
> --- a/arch/powerpc/platforms/pseries/cmm.c
> +++ b/arch/powerpc/platforms/pseries/cmm.c
> @@ -19,6 +19,10 @@
>   #include <linux/stringify.h>
>   #include <linux/swap.h>
>   #include <linux/device.h>
> +#include <linux/mount.h>
> +#include <linux/pseudo_fs.h>
> +#include <linux/magic.h>
> +#include <linux/balloon_compaction.h>
>   #include <asm/firmware.h>
>   #include <asm/hvcall.h>
>   #include <asm/mmu.h>
> @@ -77,13 +81,11 @@ static atomic_long_t loaned_pages;
>   static unsigned long loaned_pages_target;
>   static unsigned long oom_freed_pages;
>   
> -static LIST_HEAD(cmm_page_list);
> -static DEFINE_SPINLOCK(cmm_lock);
> -
>   static DEFINE_MUTEX(hotplug_mutex);
>   static int hotplug_occurred; /* protected by the hotplug mutex */
>   
>   static struct task_struct *cmm_thread_ptr;
> +static struct balloon_dev_info b_dev_info;
>   
>   static long plpar_page_set_loaned(struct page *page)
>   {
> @@ -149,19 +151,16 @@ static long cmm_alloc_pages(long nr)
>   				  __GFP_NOMEMALLOC);
>   		if (!page)
>   			break;
> -		spin_lock(&cmm_lock);
>   		rc = plpar_page_set_loaned(page);
>   		if (rc) {
>   			pr_err("%s: Can not set page to loaned. rc=%ld\n", __func__, rc);
> -			spin_unlock(&cmm_lock);
>   			__free_page(page);
>   			break;
>   		}
>   
> -		list_add(&page->lru, &cmm_page_list);
> +		balloon_page_enqueue(&b_dev_info, page);
>   		atomic_long_inc(&loaned_pages);
>   		adjust_managed_page_count(page, -1);
> -		spin_unlock(&cmm_lock);
>   		nr--;
>   	}
>   
> @@ -178,21 +177,19 @@ static long cmm_alloc_pages(long nr)
>    **/
>   static long cmm_free_pages(long nr)
>   {
> -	struct page *page, *tmp;
> +	struct page *page;
>   
>   	cmm_dbg("Begin free of %ld pages.\n", nr);
> -	spin_lock(&cmm_lock);
> -	list_for_each_entry_safe(page, tmp, &cmm_page_list, lru) {
> -		if (!nr)
> +	while (nr) {
> +		page = balloon_page_dequeue(&b_dev_info);
> +		if (!page)
>   			break;
>   		plpar_page_set_active(page);
> -		list_del(&page->lru);
>   		adjust_managed_page_count(page, 1);
>   		__free_page(page);
>   		atomic_long_dec(&loaned_pages);
>   		nr--;
>   	}
> -	spin_unlock(&cmm_lock);
>   	cmm_dbg("End request with %ld pages unfulfilled\n", nr);
>   	return nr;
>   }
> @@ -484,6 +481,105 @@ static struct notifier_block cmm_mem_nb = {
>   	.priority = CMM_MEM_HOTPLUG_PRI
>   };
>   
> +#ifdef CONFIG_BALLOON_COMPACTION
> +static struct vfsmount *balloon_mnt;
> +
> +static int cmm_init_fs_context(struct fs_context *fc)
> +{
> +	return init_pseudo(fc, PPC_CMM_MAGIC) ? 0 : -ENOMEM;
> +}
> +
> +static struct file_system_type balloon_fs = {
> +	.name = "ppc-cmm",
> +	.init_fs_context = cmm_init_fs_context,
> +	.kill_sb = kill_anon_super,
> +};
> +
> +static int cmm_migratepage(struct balloon_dev_info *b_dev_info,
> +			   struct page *newpage, struct page *page,
> +			   enum migrate_mode mode)
> +{
> +	unsigned long flags;
> +
> +	/*
> +	 * loan/"inflate" the newpage first.
> +	 *
> +	 * We might race against the cmm_thread who might discover after our
> +	 * loan request that another page is to be unloaned. However, once
> +	 * the cmm_thread runs again later, this error will automatically
> +	 * be corrected.
> +	 */
> +	if (plpar_page_set_loaned(newpage)) {
> +		/* Unlikely, but possible. Tell the caller not to retry now. */
> +		pr_err_ratelimited("%s: Cannot set page to loaned.", __func__);
> +		return -EBUSY;
> +	}
> +
> +	/* balloon page list reference */
> +	get_page(newpage);
> +
> +	spin_lock_irqsave(&b_dev_info->pages_lock, flags);
> +	balloon_page_insert(b_dev_info, newpage);
> +	balloon_page_delete(page);

I think I am missing a b_dev_info->isolated_pages-- here.

> +	spin_unlock_irqrestore(&b_dev_info->pages_lock, flags);


-- 

Thanks,

David / dhildenb


  reply	other threads:[~2019-10-31 14:35 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-31 14:29 [PATCH v1 00/12] powerpc/pseries: CMM: Implement balloon compaction and remove isolate notifier David Hildenbrand
2019-10-31 14:29 ` David Hildenbrand
2019-10-31 14:29 ` [PATCH v1 01/12] powerpc/pseries: CMM: Implement release() function for sysfs device David Hildenbrand
2019-10-31 14:29   ` David Hildenbrand
2019-11-14  9:08   ` Michael Ellerman
2019-11-14  9:08     ` Michael Ellerman
2019-11-14 12:21     ` David Hildenbrand
2019-11-14 12:21       ` David Hildenbrand
2019-11-20 10:35     ` David Hildenbrand
2019-11-20 10:35       ` David Hildenbrand
2019-10-31 14:29 ` [PATCH v1 02/12] powerpc/pseries: CMM: Report errors when registering notifiers fails David Hildenbrand
2019-10-31 14:29   ` David Hildenbrand
2019-10-31 14:29 ` [PATCH v1 03/12] powerpc/pseries: CMM: Cleanup rc handling in cmm_init() David Hildenbrand
2019-10-31 14:29   ` David Hildenbrand
2019-10-31 14:29 ` [PATCH v1 04/12] powerpc/pseries: CMM: Drop page array David Hildenbrand
2019-10-31 14:29   ` David Hildenbrand
2019-10-31 14:29 ` [PATCH v1 05/12] powerpc/pseries: CMM: Use adjust_managed_page_count() insted of totalram_pages_* David Hildenbrand
2019-10-31 14:29   ` David Hildenbrand
2019-10-31 14:29 ` [PATCH v1 06/12] powerpc/pseries: CMM: Rip out memory isolate notifier David Hildenbrand
2019-10-31 14:29   ` David Hildenbrand
2019-10-31 14:29 ` [PATCH v1 07/12] powerpc/pseries: CMM: Convert loaned_pages to an atomic_long_t David Hildenbrand
2019-10-31 14:29   ` David Hildenbrand
2019-10-31 14:29 ` [PATCH v1 08/12] powerpc/pseries: CMM: Implement balloon compaction David Hildenbrand
2019-10-31 14:29   ` David Hildenbrand
2019-10-31 14:35   ` David Hildenbrand [this message]
2019-10-31 14:35     ` David Hildenbrand
2019-11-12 10:46     ` Michael Ellerman
2019-11-12 10:46       ` Michael Ellerman
2019-11-12 11:12       ` David Hildenbrand
2019-11-12 11:12         ` David Hildenbrand
2019-11-13 11:08         ` Michael Ellerman
2019-11-13 11:08           ` Michael Ellerman
2019-10-31 14:29 ` [PATCH v1 09/12] powerpc/pseries: CMM: Switch to balloon_page_alloc() David Hildenbrand
2019-10-31 14:29   ` David Hildenbrand
2019-10-31 14:29 ` [PATCH v1 10/12] powerpc/pseries: CMM: Simulation mode David Hildenbrand
2019-10-31 14:29   ` David Hildenbrand
2019-10-31 14:29 ` [PATCH v1 11/12] mm: remove the memory isolate notifier David Hildenbrand
2019-10-31 14:29   ` David Hildenbrand
2019-10-31 14:29 ` [PATCH v1 12/12] mm: remove "count" parameter from has_unmovable_pages() David Hildenbrand
2019-10-31 14:29   ` David Hildenbrand

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=be7c1424-f240-b72c-8d6d-310ebbd816e1@redhat.com \
    --to=david@redhat.com \
    --cc=aik@ozlabs.ru \
    --cc=akpm@linux-foundation.org \
    --cc=allison@lohutok.net \
    --cc=arunks@codeaurora.org \
    --cc=bauerman@linux.ibm.com \
    --cc=benh@kernel.crashing.org \
    --cc=christian@brauner.io \
    --cc=dhowells@redhat.com \
    --cc=geert@linux-m68k.org \
    --cc=ghackmann@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=info@metux.net \
    --cc=khandual@linux.vnet.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mpe@ellerman.id.au \
    --cc=oohall@gmail.com \
    --cc=pasha.tatashin@soleen.com \
    --cc=paulus@samba.org \
    --cc=tglx@linutronix.de \
    --cc=tkjos@google.com \
    --cc=xiang@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.