All of lore.kernel.org
 help / color / mirror / Atom feed
From: Minchan Kim <minchan.kim@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm <linux-mm@kvack.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Johannes Weiner <hannes@cmpxchg.org>,
	KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>,
	KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>,
	Mel Gorman <mgorman@suse.de>, Rik van Riel <riel@redhat.com>,
	Michal Hocko <mhocko@suse.cz>,
	Andrea Arcangeli <aarcange@redhat.com>
Subject: Re: [PATCH v4 06/10] migration: introudce migrate_ilru_pages
Date: Mon, 1 Aug 2011 01:21:13 +0900	[thread overview]
Message-ID: <20110731162113.GA2864@barrios-desktop> (raw)
In-Reply-To: <20110727131357.cc5a42ce.akpm@linux-foundation.org>

On Wed, Jul 27, 2011 at 01:13:57PM -0700, Andrew Morton wrote:
> On Mon,  4 Jul 2011 23:04:39 +0900
> Minchan Kim <minchan.kim@gmail.com> wrote:
> 
> > This patch defines new APIs to put back new page into old page's position as LRU order.
> > for LRU churning of compaction.
> > 
> > The idea I suggested in LSF/MM is simple.
> >
> > ...
> >
> > +static bool same_lru(struct page *page, struct page *prev)
> > +{
> > +	bool ret = false;
> > +	if (!prev || !PageLRU(prev))
> 
> Both parts of this test need explanations so readers can understand why
> they are here.
> 
> > +		goto out;
> > +
> > +	if (unlikely(PageUnevictable(prev)))
> 
> As does this.

Will do.

> 
> > +		goto out;
> > +
> > +	if (page_lru_base_type(page) != page_lru_base_type(prev))
> > +		goto out;
> 
> This (and testing for PageLRU) is the only part of this function whcih
> is sufficiently obvious to leave undocumented.

> 
> > +	ret = true;
> > +out:
> > +	return ret;
> > +}
> > +
> > +void putback_ilru_pages(struct inorder_lru *l)
> > +{
> > +	struct zone *zone;
> > +	struct page *page, *page2, *prev;
> > +
> > +	list_for_each_ilru_entry_safe(page, page2, l, ilru) {
> > +		ilru_list_del(page, l);
> > +		dec_zone_page_state(page, NR_ISOLATED_ANON +
> > +				page_is_file_cache(page));
> > +		zone = page_zone(page);
> > +		spin_lock_irq(&zone->lru_lock);
> > +		prev = page->ilru.prev_page;
> > +		if (same_lru(page, prev)) {
> > +			putback_page_to_lru(page, prev);
> > +			spin_unlock_irq(&zone->lru_lock);
> > +			put_page(page);
> > +		} else {
> > +			spin_unlock_irq(&zone->lru_lock);
> > +			putback_lru_page(page);
> > +		}
> > +	}
> > +}
> 
> This function takes lru_lock at lest once per page, up to twice per
> page.  The spinlocking frequency here could be optimised tremendously.

Yes. Mel is pointed out and I sent a [8/10] patch about it.

> 
> The trick of hanging onto zone->lru_lock is the zone didn't change gets
> hard if we want to do a put_page() inside the loop.
> 
> We have functions "putback_page_to_lru()" and "putback_lru_page()". 
> Ugh.  Can we think of better naming?

Yes. The name is bad but It's disappeared at [8/10].

> 
> Does this function even need to exist if CONFIG_MIGRATION=n?

Of course, NOT.
I will nullify it in case of no migration.

> 
> > +/*
> >   * Restore a potential migration pte to a working pte entry
> >   */
> >
> > ...
> >
> > +void __put_ilru_pages(struct page *page, struct page *newpage,
> > +		struct inorder_lru *prev_lru, struct inorder_lru *ihead)
> 
> The function name leaves me wondering where we put the pages, and
> there's no documentation telling me.

It seems remained thing to me is to add documentation.
I will add documentation in next version.

> 
> > +{
> > +	struct page *prev_page;
> > +	struct zone *zone;
> > +	prev_page = page->ilru.prev_page;
> > +	/*
> > +	 * A page that has been migrated has all references
> > +	 * removed and will be freed. A page that has not been
> > +	 * migrated will have kepts its references and be
> > +	 * restored.
> > +	 */
> > +	ilru_list_del(page, prev_lru);
> > +	dec_zone_page_state(page, NR_ISOLATED_ANON +
> > +			page_is_file_cache(page));
> > +
> > +	/*
> > +	 * Move the new page to the LRU. If migration was not successful
> > +	 * then this will free the page.
> > +	 */
> > +	zone = page_zone(newpage);
> > +	spin_lock_irq(&zone->lru_lock);
> > +	if (same_lru(page, prev_page)) {
> > +		putback_page_to_lru(newpage, prev_page);
> > +		spin_unlock_irq(&zone->lru_lock);
> > +		/*
> > +		 * The newpage replaced LRU position of old page and
> > +		 * old one would be freed. So let's adjust prev_page of pages
> > +		 * remained in inorder_lru list.
> > +		 */
> > +		adjust_ilru_prev_page(ihead, page, newpage);
> > +		put_page(newpage);
> > +	} else {
> > +		spin_unlock_irq(&zone->lru_lock);
> > +		putback_lru_page(newpage);
> > +	}
> 
> The same spinlocking frequency issue.
> 
> > +	putback_lru_page(page);
> > +}
> > +
> >
> > ...
> >
> > +int migrate_ilru_pages(struct inorder_lru *ihead, new_page_t get_new_page,
> > +		unsigned long private, bool offlining, bool sync)
> > +{
> > +	int retry = 1;
> > +	int nr_failed = 0;
> > +	int pass = 0;
> > +	struct page *page, *page2;
> > +	struct inorder_lru *prev;
> > +	int swapwrite = current->flags & PF_SWAPWRITE;
> > +	int rc;
> > +
> > +	if (!swapwrite)
> > +		current->flags |= PF_SWAPWRITE;
> > +
> > +	for (pass = 0; pass < 10 && retry; pass++) {
> 
> That ten-passes thing was too ugly to live, and now it's breeding.  Argh.

Personally, I hope we remove it.
I will consider it later version or as independent patch.
Thanks for the review, Andrew!
-- 
Kind regards,
Minchan Kim

WARNING: multiple messages have this Message-ID (diff)
From: Minchan Kim <minchan.kim@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm <linux-mm@kvack.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Johannes Weiner <hannes@cmpxchg.org>,
	KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>,
	KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>,
	Mel Gorman <mgorman@suse.de>, Rik van Riel <riel@redhat.com>,
	Michal Hocko <mhocko@suse.cz>,
	Andrea Arcangeli <aarcange@redhat.com>
Subject: Re: [PATCH v4 06/10] migration: introudce migrate_ilru_pages
Date: Mon, 1 Aug 2011 01:21:13 +0900	[thread overview]
Message-ID: <20110731162113.GA2864@barrios-desktop> (raw)
In-Reply-To: <20110727131357.cc5a42ce.akpm@linux-foundation.org>

On Wed, Jul 27, 2011 at 01:13:57PM -0700, Andrew Morton wrote:
> On Mon,  4 Jul 2011 23:04:39 +0900
> Minchan Kim <minchan.kim@gmail.com> wrote:
> 
> > This patch defines new APIs to put back new page into old page's position as LRU order.
> > for LRU churning of compaction.
> > 
> > The idea I suggested in LSF/MM is simple.
> >
> > ...
> >
> > +static bool same_lru(struct page *page, struct page *prev)
> > +{
> > +	bool ret = false;
> > +	if (!prev || !PageLRU(prev))
> 
> Both parts of this test need explanations so readers can understand why
> they are here.
> 
> > +		goto out;
> > +
> > +	if (unlikely(PageUnevictable(prev)))
> 
> As does this.

Will do.

> 
> > +		goto out;
> > +
> > +	if (page_lru_base_type(page) != page_lru_base_type(prev))
> > +		goto out;
> 
> This (and testing for PageLRU) is the only part of this function whcih
> is sufficiently obvious to leave undocumented.

> 
> > +	ret = true;
> > +out:
> > +	return ret;
> > +}
> > +
> > +void putback_ilru_pages(struct inorder_lru *l)
> > +{
> > +	struct zone *zone;
> > +	struct page *page, *page2, *prev;
> > +
> > +	list_for_each_ilru_entry_safe(page, page2, l, ilru) {
> > +		ilru_list_del(page, l);
> > +		dec_zone_page_state(page, NR_ISOLATED_ANON +
> > +				page_is_file_cache(page));
> > +		zone = page_zone(page);
> > +		spin_lock_irq(&zone->lru_lock);
> > +		prev = page->ilru.prev_page;
> > +		if (same_lru(page, prev)) {
> > +			putback_page_to_lru(page, prev);
> > +			spin_unlock_irq(&zone->lru_lock);
> > +			put_page(page);
> > +		} else {
> > +			spin_unlock_irq(&zone->lru_lock);
> > +			putback_lru_page(page);
> > +		}
> > +	}
> > +}
> 
> This function takes lru_lock at lest once per page, up to twice per
> page.  The spinlocking frequency here could be optimised tremendously.

Yes. Mel is pointed out and I sent a [8/10] patch about it.

> 
> The trick of hanging onto zone->lru_lock is the zone didn't change gets
> hard if we want to do a put_page() inside the loop.
> 
> We have functions "putback_page_to_lru()" and "putback_lru_page()". 
> Ugh.  Can we think of better naming?

Yes. The name is bad but It's disappeared at [8/10].

> 
> Does this function even need to exist if CONFIG_MIGRATION=n?

Of course, NOT.
I will nullify it in case of no migration.

> 
> > +/*
> >   * Restore a potential migration pte to a working pte entry
> >   */
> >
> > ...
> >
> > +void __put_ilru_pages(struct page *page, struct page *newpage,
> > +		struct inorder_lru *prev_lru, struct inorder_lru *ihead)
> 
> The function name leaves me wondering where we put the pages, and
> there's no documentation telling me.

It seems remained thing to me is to add documentation.
I will add documentation in next version.

> 
> > +{
> > +	struct page *prev_page;
> > +	struct zone *zone;
> > +	prev_page = page->ilru.prev_page;
> > +	/*
> > +	 * A page that has been migrated has all references
> > +	 * removed and will be freed. A page that has not been
> > +	 * migrated will have kepts its references and be
> > +	 * restored.
> > +	 */
> > +	ilru_list_del(page, prev_lru);
> > +	dec_zone_page_state(page, NR_ISOLATED_ANON +
> > +			page_is_file_cache(page));
> > +
> > +	/*
> > +	 * Move the new page to the LRU. If migration was not successful
> > +	 * then this will free the page.
> > +	 */
> > +	zone = page_zone(newpage);
> > +	spin_lock_irq(&zone->lru_lock);
> > +	if (same_lru(page, prev_page)) {
> > +		putback_page_to_lru(newpage, prev_page);
> > +		spin_unlock_irq(&zone->lru_lock);
> > +		/*
> > +		 * The newpage replaced LRU position of old page and
> > +		 * old one would be freed. So let's adjust prev_page of pages
> > +		 * remained in inorder_lru list.
> > +		 */
> > +		adjust_ilru_prev_page(ihead, page, newpage);
> > +		put_page(newpage);
> > +	} else {
> > +		spin_unlock_irq(&zone->lru_lock);
> > +		putback_lru_page(newpage);
> > +	}
> 
> The same spinlocking frequency issue.
> 
> > +	putback_lru_page(page);
> > +}
> > +
> >
> > ...
> >
> > +int migrate_ilru_pages(struct inorder_lru *ihead, new_page_t get_new_page,
> > +		unsigned long private, bool offlining, bool sync)
> > +{
> > +	int retry = 1;
> > +	int nr_failed = 0;
> > +	int pass = 0;
> > +	struct page *page, *page2;
> > +	struct inorder_lru *prev;
> > +	int swapwrite = current->flags & PF_SWAPWRITE;
> > +	int rc;
> > +
> > +	if (!swapwrite)
> > +		current->flags |= PF_SWAPWRITE;
> > +
> > +	for (pass = 0; pass < 10 && retry; pass++) {
> 
> That ten-passes thing was too ugly to live, and now it's breeding.  Argh.

Personally, I hope we remove it.
I will consider it later version or as independent patch.
Thanks for the review, Andrew!
-- 
Kind regards,
Minchan Kim

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2011-07-31 16:21 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-04 14:04 [PATCH v4 00/10] Prevent LRU churning Minchan Kim
2011-07-04 14:04 ` Minchan Kim
2011-07-04 14:04 ` [PATCH v4 01/10] compaction: trivial clean up acct_isolated Minchan Kim
2011-07-04 14:04   ` Minchan Kim
2011-07-04 14:04 ` [PATCH v4 02/10] Change isolate mode from #define to bitwise type Minchan Kim
2011-07-04 14:04   ` Minchan Kim
2011-07-04 14:04 ` [PATCH v4 03/10] compaction: make isolate_lru_page with filter aware Minchan Kim
2011-07-04 14:04   ` Minchan Kim
2011-07-04 14:04 ` [PATCH v4 04/10] zone_reclaim: " Minchan Kim
2011-07-04 14:04   ` Minchan Kim
2011-07-04 14:04 ` [PATCH v4 05/10] migration: clean up unmap_and_move Minchan Kim
2011-07-04 14:04   ` Minchan Kim
2011-07-04 14:04 ` [PATCH v4 06/10] migration: introudce migrate_ilru_pages Minchan Kim
2011-07-04 14:04   ` Minchan Kim
2011-07-27 20:13   ` Andrew Morton
2011-07-27 20:13     ` Andrew Morton
2011-07-31 16:21     ` Minchan Kim [this message]
2011-07-31 16:21       ` Minchan Kim
2011-07-04 14:04 ` [PATCH v4 07/10] compaction: make compaction use in-order putback Minchan Kim
2011-07-04 14:04   ` Minchan Kim
2011-07-04 14:04 ` [PATCH v4 08/10] ilru: reduce zone->lru_lock Minchan Kim
2011-07-04 14:04   ` Minchan Kim
2011-07-27 20:14   ` Andrew Morton
2011-07-27 20:14     ` Andrew Morton
2011-07-31 16:31     ` Minchan Kim
2011-07-31 16:31       ` Minchan Kim
2011-07-04 14:04 ` [PATCH v4 09/10] add inorder-lru tracepoints for just measurement Minchan Kim
2011-07-04 14:04   ` Minchan Kim
2011-07-04 14:04 ` [PATCH v4 10/10] compaction: add drain ilru of pagevec Minchan Kim
2011-07-04 14:04   ` Minchan Kim
2011-07-27 20:16 ` [PATCH v4 00/10] Prevent LRU churning Andrew Morton
2011-07-27 20:16   ` Andrew Morton
2011-07-29  8:23   ` Minchan Kim
2011-07-29  8:23     ` Minchan Kim
  -- strict thread matches above, loose matches on Subject: below --
2011-06-30 14:55 Minchan Kim
2011-06-30 14:55 ` [PATCH v4 06/10] migration: introudce migrate_ilru_pages Minchan Kim
2011-06-30 14:55   ` Minchan Kim

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=20110731162113.GA2864@barrios-desktop \
    --to=minchan.kim@gmail.com \
    --cc=aarcange@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=hannes@cmpxchg.org \
    --cc=kamezawa.hiroyu@jp.fujitsu.com \
    --cc=kosaki.motohiro@jp.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mgorman@suse.de \
    --cc=mhocko@suse.cz \
    --cc=riel@redhat.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 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.