linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
To: Zi Yan <zi.yan@sent.com>
Cc: "linux-mm@kvack.org" <linux-mm@kvack.org>,
	"dnellans@nvidia.com" <dnellans@nvidia.com>,
	"apopple@au1.ibm.com" <apopple@au1.ibm.com>,
	"paulmck@linux.vnet.ibm.com" <paulmck@linux.vnet.ibm.com>,
	"khandual@linux.vnet.ibm.com" <khandual@linux.vnet.ibm.com>,
	"zi.yan@cs.rutgers.edu" <zi.yan@cs.rutgers.edu>
Subject: Re: [RFC PATCH 07/14] migrate: Add copy_page_lists_mthread() function.
Date: Thu, 23 Feb 2017 08:54:20 +0000	[thread overview]
Message-ID: <20170223085419.GA28246@hori1.linux.bs1.fc.nec.co.jp> (raw)
In-Reply-To: <20170217150551.117028-8-zi.yan@sent.com>

On Fri, Feb 17, 2017 at 10:05:44AM -0500, Zi Yan wrote:
> From: Zi Yan <ziy@nvidia.com>
> 
> It supports copying a list of pages via multi-threaded process.
> It evenly distributes a list of pages to a group of threads and
> uses the same subroutine as copy_page_mthread()

The new function has many duplicate lines with copy_page_mthread(),
so please consider factoring out them into a common routine.
That makes your code more readable/maintainable.

Thanks,
Naoya Horiguchi

> 
> Signed-off-by: Zi Yan <ziy@nvidia.com>
> ---
>  mm/copy_pages.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  mm/internal.h   |  3 +++
>  2 files changed, 65 insertions(+)
> 
> diff --git a/mm/copy_pages.c b/mm/copy_pages.c
> index c357e7b01042..516c0a1a57f3 100644
> --- a/mm/copy_pages.c
> +++ b/mm/copy_pages.c
> @@ -84,3 +84,65 @@ int copy_pages_mthread(struct page *to, struct page *from, int nr_pages)
>  	kfree(work_items);
>  	return 0;
>  }
> +
> +int copy_page_lists_mthread(struct page **to, struct page **from, int nr_pages) 
> +{
> +	int err = 0;
> +	unsigned int cthreads, node = page_to_nid(*to);
> +	int i;
> +	struct copy_info *work_items;
> +	int nr_pages_per_page = hpage_nr_pages(*from);
> +	const struct cpumask *cpumask = cpumask_of_node(node);
> +	int cpu_id_list[32] = {0};
> +	int cpu;
> +
> +	cthreads = nr_copythreads;
> +	cthreads = min_t(unsigned int, cthreads, cpumask_weight(cpumask));
> +	cthreads = (cthreads / 2) * 2;
> +	cthreads = min_t(unsigned int, nr_pages, cthreads);
> +
> +	work_items = kzalloc(sizeof(struct copy_info)*nr_pages,
> +						 GFP_KERNEL);
> +	if (!work_items)
> +		return -ENOMEM;
> +
> +	i = 0;
> +	for_each_cpu(cpu, cpumask) {
> +		if (i >= cthreads)
> +			break;
> +		cpu_id_list[i] = cpu;
> +		++i;
> +	}
> +
> +	for (i = 0; i < nr_pages; ++i) {
> +		int thread_idx = i % cthreads;
> +
> +		INIT_WORK((struct work_struct *)&work_items[i], 
> +				  copythread);
> +
> +		work_items[i].to = kmap(to[i]);
> +		work_items[i].from = kmap(from[i]);
> +		work_items[i].chunk_size = PAGE_SIZE * hpage_nr_pages(from[i]);
> +
> +		BUG_ON(nr_pages_per_page != hpage_nr_pages(from[i]));
> +		BUG_ON(nr_pages_per_page != hpage_nr_pages(to[i]));
> +
> +
> +		queue_work_on(cpu_id_list[thread_idx], 
> +					  system_highpri_wq, 
> +					  (struct work_struct *)&work_items[i]);
> +	}
> +
> +	/* Wait until it finishes  */
> +	for (i = 0; i < cthreads; ++i)
> +		flush_work((struct work_struct *) &work_items[i]);
> +
> +	for (i = 0; i < nr_pages; ++i) {
> +			kunmap(to[i]);
> +			kunmap(from[i]);
> +	}
> +
> +	kfree(work_items);
> +
> +	return err;
> +}
> diff --git a/mm/internal.h b/mm/internal.h
> index ccfc2a2969f4..175e08ed524a 100644
> --- a/mm/internal.h
> +++ b/mm/internal.h
> @@ -498,4 +498,7 @@ extern const struct trace_print_flags pageflag_names[];
>  extern const struct trace_print_flags vmaflag_names[];
>  extern const struct trace_print_flags gfpflag_names[];
>  
> +extern int copy_page_lists_mthread(struct page **to,
> +			struct page **from, int nr_pages);
> +
>  #endif	/* __MM_INTERNAL_H */
> -- 
> 2.11.0
> 
> --
> To unsubscribe, send a message with 'unsubscribe linux-mm' in
> the body to majordomo@kvack.org.  For more info on Linux MM,
> see: http://www.linux-mm.org/ .
> Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2017-02-23  9:04 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-17 15:05 [RFC PATCH 00/14] Accelerating page migrations Zi Yan
2017-02-17 15:05 ` [RFC PATCH 01/14] mm/migrate: Add new mode parameter to migrate_page_copy() function Zi Yan
2017-02-17 15:05 ` [RFC PATCH 02/14] mm/migrate: Make migrate_mode types non-exclussive Zi Yan
2017-02-17 15:05 ` [RFC PATCH 03/14] mm/migrate: Add copy_pages_mthread function Zi Yan
2017-02-23  6:06   ` Naoya Horiguchi
2017-02-23  7:50     ` Anshuman Khandual
2017-02-23  8:02       ` Naoya Horiguchi
2017-03-09  5:35         ` Anshuman Khandual
2017-02-17 15:05 ` [RFC PATCH 04/14] mm/migrate: Add new migrate mode MIGRATE_MT Zi Yan
2017-02-23  6:54   ` Naoya Horiguchi
2017-02-23  7:54     ` Anshuman Khandual
2017-02-17 15:05 ` [RFC PATCH 05/14] mm/migrate: Add new migration flag MPOL_MF_MOVE_MT for syscalls Zi Yan
2017-02-17 15:05 ` [RFC PATCH 06/14] sysctl: Add global tunable mt_page_copy Zi Yan
2017-02-17 15:05 ` [RFC PATCH 07/14] migrate: Add copy_page_lists_mthread() function Zi Yan
2017-02-23  8:54   ` Naoya Horiguchi [this message]
2017-03-09 13:02     ` Anshuman Khandual
2017-02-17 15:05 ` [RFC PATCH 08/14] mm: migrate: Add concurrent page migration into move_pages syscall Zi Yan
2017-02-24  8:25   ` Naoya Horiguchi
2017-02-24 15:05     ` Zi Yan
2017-02-17 15:05 ` [RFC PATCH 09/14] mm: migrate: Add exchange_page_mthread() and exchange_page_lists_mthread() to exchange two pages or two page lists Zi Yan
2017-02-17 15:05 ` [RFC PATCH 10/14] mm: Add exchange_pages and exchange_pages_concur functions to exchange two lists of pages instead of two migrate_pages() Zi Yan
2017-02-17 15:05 ` [RFC PATCH 11/14] mm: migrate: Add exchange_pages syscall to exchange two page lists Zi Yan
2017-02-17 15:05 ` [RFC PATCH 12/14] migrate: Add copy_page_dma to use DMA Engine to copy pages Zi Yan
2017-02-17 15:05 ` [RFC PATCH 13/14] mm: migrate: Add copy_page_dma into migrate_page_copy Zi Yan
2017-02-17 15:05 ` [RFC PATCH 14/14] mm: Add copy_page_lists_dma_always to support copy a list of pages Zi Yan

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=20170223085419.GA28246@hori1.linux.bs1.fc.nec.co.jp \
    --to=n-horiguchi@ah.jp.nec.com \
    --cc=apopple@au1.ibm.com \
    --cc=dnellans@nvidia.com \
    --cc=khandual@linux.vnet.ibm.com \
    --cc=linux-mm@kvack.org \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=zi.yan@cs.rutgers.edu \
    --cc=zi.yan@sent.com \
    /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