kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: Alexander Duyck <alexander.h.duyck@linux.intel.com>,
	linux-kernel@vger.kernel.org
Cc: linux-mm@kvack.org, virtio-dev@lists.oasis-open.org,
	virtualization@lists.linux-foundation.org, kvm@vger.kernel.org,
	Michal Hocko <mhocko@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	"Michael S . Tsirkin" <mst@redhat.com>,
	Juergen Gross <jgross@suse.com>,
	Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
	Pavel Tatashin <pavel.tatashin@microsoft.com>,
	Vlastimil Babka <vbabka@suse.cz>,
	Johannes Weiner <hannes@cmpxchg.org>,
	Anthony Yznaga <anthony.yznaga@oracle.com>,
	Michal Hocko <mhocko@suse.com>,
	Oscar Salvador <osalvador@suse.de>,
	Mel Gorman <mgorman@techsingularity.net>,
	Mike Rapoport <rppt@linux.ibm.com>,
	Dan Williams <dan.j.williams@intel.com>,
	Anshuman Khandual <anshuman.khandual@arm.com>,
	Qian Cai <cai@lca.pw>, Pingfan Liu <kernelfans@gmail.com>
Subject: Re: [PATCH RFC v4 06/13] mm: Allow to offline unmovable PageOffline() pages via MEM_GOING_OFFLINE
Date: Tue, 25 Feb 2020 19:49:21 +0100	[thread overview]
Message-ID: <267ea186-aba8-1a93-bd55-ac641f78d07e@redhat.com> (raw)
In-Reply-To: <6ec496580ddcb629d22589a1cba8cd61cbd53206.camel@linux.intel.com>

>>  /*
>>   * Scan pfn range [start,end) to find movable/migratable pages (LRU pages,
>> - * non-lru movable pages and hugepages). We scan pfn because it's much
>> - * easier than scanning over linked list. This function returns the pfn
>> - * of the first found movable page if it's found, otherwise 0.
>> + * non-lru movable pages and hugepages).
>> + *
>> + * Returns:
>> + *	0 in case a movable page is found and movable_pfn was updated.
>> + *	-ENOENT in case no movable page was found.
>> + *	-EBUSY in case a definetly unmovable page was found.
>>   */
>> -static unsigned long scan_movable_pages(unsigned long start, unsigned long end)
>> +static int scan_movable_pages(unsigned long start, unsigned long end,
>> +			      unsigned long *movable_pfn)
>>  {
>>  	unsigned long pfn;
>>  
>> @@ -1247,18 +1251,29 @@ static unsigned long scan_movable_pages(unsigned long start, unsigned long end)
>>  			continue;
>>  		page = pfn_to_page(pfn);
>>  		if (PageLRU(page))
>> -			return pfn;
>> +			goto found;
>>  		if (__PageMovable(page))
>> -			return pfn;
>> +			goto found;
>> +
>> +		/*
>> +		 * Unmovable PageOffline() pages where somebody still holds
>> +		 * a reference count (after MEM_GOING_OFFLINE) can definetly
>> +		 * not be offlined.
>> +		 */
>> +		if (PageOffline(page) && page_count(page))
>> +			return -EBUSY;
> 
> So the comment confused me a bit because technically this function isn't
> about offlining memory, it is about finding movable pages. I had to do a
> bit of digging to find the only consumer is __offline_pages, but if we are
> going to talk about "offlining" instead of "moving" in this function it
> might make sense to rename it.

Well, it's contained in memory_hotplug.c, and the only user of moving
pages around in there is offlining code :) And it's job is to locate
movable pages, skip over some (temporary? unmovable ones) and (now)
indicate definitely unmovable ones.

Any idea for a better name?
scan_movable_pages_and_stop_on_definitely_unmovable() is not so nice :)


> 
>>  
>>  		if (!PageHuge(page))
>>  			continue;
>>  		head = compound_head(page);
>>  		if (page_huge_active(head))
>> -			return pfn;
>> +			goto found;
>>  		skip = compound_nr(head) - (page - head);
>>  		pfn += skip - 1;
>>  	}
>> +	return -ENOENT;
>> +found:
>> +	*movable_pfn = pfn;
>>  	return 0;
>>  }
> 
> So I am looking at this function and it seems like your change completely
> changes the behavior. The code before would walk the entire range and if
> at least 1 page was available to move you would return the PFN of that
> page. Now what seems to happen is that you will return -EBUSY as soon as
> you encounter an offline page with a page count. I would think that would
> slow down the offlining process since you have made the Unmovable
> PageOffline() page a head of line blocker that you have to wait to get
> around.

So, the comment says "Unmovable PageOffline() pages where somebody still
holds a reference count (after MEM_GOING_OFFLINE) can definitely not be
offlined". And the doc "-EBUSY in case a definitely unmovable page was
found."

So why would this make offlining slow? Offlining will be aborted,
because offlining is not possible.

Please note that this is the exact old behavior, where isolating the
page range would have failed directly and offlining would have been
aborted early. The old offlining failure in the case in the offlining
path would have been "failure to isolate range".

Also, note that the users of PageOffline() with unmovable pages are very
rare (only balloon drivers for now).

> 
> Would it perhaps make more sense to add a return value initialized to
> ENOENT, and if you encounter one of these offline pages you change the
> return value to EBUSY, and then if you walk through the entire list
> without finding a movable page you just return the value?

Did you have a look in  which context this function is used, especially
[1] and [2]?

> 
> Otherwise you might want to add a comment explaining why the function
> should stall instead of skipping over the unmovable section that will
> hopefully become movable later.

So we have "-EBUSY in case a definitely unmovable page was found.". Do
you have a better suggestion?

> 
>> @@ -1528,7 +1543,8 @@ static int __ref __offline_pages(unsigned long start_pfn,
>>  	}
>>  
>>  	do {
>> -		for (pfn = start_pfn; pfn;) {
>> +		pfn = start_pfn;
>> +		do {
>>  			if (signal_pending(current)) {
>>  				ret = -EINTR;
>>  				reason = "signal backoff";
>> @@ -1538,14 +1554,19 @@ static int __ref __offline_pages(unsigned long start_pfn,
>>  			cond_resched();
>>  			lru_add_drain_all();
>>  
>> -			pfn = scan_movable_pages(pfn, end_pfn);
>> -			if (pfn) {
>> +			ret = scan_movable_pages(pfn, end_pfn, &pfn);
>> +			if (!ret) {
>>  				/*
>>  				 * TODO: fatal migration failures should bail
>>  				 * out
>>  				 */
>>  				do_migrate_range(pfn, end_pfn);
>>  			}

[1] we detect a definite offlining blocker and

>> +		} while (!ret);
>> +
>> +		if (ret != -ENOENT) {
>> +			reason = "unmovable page";

[2] we abort offlining

>> +			goto failed_removal_isolated;
>>  		}
>>  
>>  		/*
>> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
>> index 5334decc9e06..840c0bbe2d9f 100644
>> --- a/mm/page_alloc.c
>> +++ b/mm/page_alloc.c
>> @@ -8256,6 +8256,19 @@ bool has_unmovable_pages(struct zone *zone, struct page *page, int count,
>>  		if ((flags & MEMORY_OFFLINE) && PageHWPoison(page))
>>  			continue;
>>  
>> +		/*
>> +		 * We treat all PageOffline() pages as movable when offlining
>> +		 * to give drivers a chance to decrement their reference count
>> +		 * in MEM_GOING_OFFLINE in order to signalize that these pages
> 
> You can probably just use "signal" or "indicate" instead of "signalize".

Makes sense, "indicate" it is!

Thanks!

-- 
Thanks,

David / dhildenb


  reply	other threads:[~2020-02-25 18:49 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-12 17:11 [PATCH RFC v4 00/13] virtio-mem: paravirtualized memory David Hildenbrand
2019-12-12 17:11 ` [PATCH RFC v4 01/13] ACPI: NUMA: export pxm_to_node David Hildenbrand
2019-12-12 21:43   ` Rafael J. Wysocki
2019-12-13  9:41     ` David Hildenbrand
2019-12-13  9:47       ` Rafael J. Wysocki
2019-12-12 17:11 ` [PATCH RFC v4 02/13] virtio-mem: Paravirtualized memory hotplug David Hildenbrand
2019-12-12 17:11 ` [PATCH RFC v4 03/13] virtio-mem: Paravirtualized memory hotunplug part 1 David Hildenbrand
2019-12-12 17:11 ` [PATCH RFC v4 04/13] mm: Export alloc_contig_range() / free_contig_range() David Hildenbrand
2019-12-12 17:11 ` [PATCH RFC v4 05/13] virtio-mem: Paravirtualized memory hotunplug part 2 David Hildenbrand
2019-12-12 17:11 ` [PATCH RFC v4 06/13] mm: Allow to offline unmovable PageOffline() pages via MEM_GOING_OFFLINE David Hildenbrand
2020-02-25 18:26   ` Alexander Duyck
2020-02-25 18:49     ` David Hildenbrand [this message]
2020-02-25 21:46       ` Alexander Duyck
2020-02-25 22:19         ` David Hildenbrand
2020-02-26 16:27           ` Alexander Duyck
2019-12-12 17:11 ` [PATCH RFC v4 07/13] virtio-mem: Allow to offline partially unplugged memory blocks David Hildenbrand
2019-12-12 17:11 ` [PATCH RFC v4 08/13] mm/memory_hotplug: Introduce offline_and_remove_memory() David Hildenbrand
2020-02-25 14:11   ` Michal Hocko
2020-02-25 14:27     ` David Hildenbrand
2020-03-02 12:48       ` Michal Hocko
2020-03-02 12:53         ` David Hildenbrand
2019-12-12 17:11 ` [PATCH RFC v4 09/13] virtio-mem: Offline and remove completely unplugged memory blocks David Hildenbrand
2019-12-12 17:11 ` [PATCH RFC v4 10/13] virtio-mem: Better retry handling David Hildenbrand
2019-12-12 17:11 ` [PATCH RFC v4 11/13] mm/vmscan: Move count_vm_event(DROP_SLAB) into drop_slab() David Hildenbrand
2020-02-25 14:13   ` Michal Hocko
2019-12-12 17:11 ` [PATCH RFC v4 12/13] mm/vmscan: Export drop_slab() and drop_slab_node() David Hildenbrand
2020-02-25 14:58   ` Michal Hocko
2020-02-25 15:09     ` David Hildenbrand
2020-02-25 17:06       ` Michal Hocko
2020-02-25 17:23         ` David Hildenbrand
2019-12-12 17:11 ` [PATCH RFC v4 13/13] virtio-mem: Drop slab objects when unplug continues to fail David Hildenbrand
2019-12-13 20:15 ` [PATCH RFC v4 00/13] virtio-mem: paravirtualized memory Konrad Rzeszutek Wilk
2019-12-16 11:03   ` David Hildenbrand
2019-12-24  6:58 ` teawater
2019-12-24  9:28   ` David Hildenbrand
2020-01-09 13:48 ` David Hildenbrand
2020-01-29  9:41   ` David Hildenbrand
2020-02-25  9:58     ` David Hildenbrand
2020-06-05  8:55   ` Alex Shi
2020-06-05  9:08     ` David Hildenbrand
2020-06-05  9:36       ` David Hildenbrand
2020-06-05 10:05         ` David Hildenbrand
2020-06-05 10:46           ` Alex Shi
2020-06-05 12:18             ` David Hildenbrand
2020-06-09  3:05               ` Alex Shi
2020-06-05 10:08         ` Alex Shi
2020-06-05 10:06       ` Alex Shi

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=267ea186-aba8-1a93-bd55-ac641f78d07e@redhat.com \
    --to=david@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=alexander.h.duyck@linux.intel.com \
    --cc=anshuman.khandual@arm.com \
    --cc=anthony.yznaga@oracle.com \
    --cc=cai@lca.pw \
    --cc=dan.j.williams@intel.com \
    --cc=hannes@cmpxchg.org \
    --cc=jgross@suse.com \
    --cc=kernelfans@gmail.com \
    --cc=konrad.wilk@oracle.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mgorman@techsingularity.net \
    --cc=mhocko@kernel.org \
    --cc=mhocko@suse.com \
    --cc=mst@redhat.com \
    --cc=osalvador@suse.de \
    --cc=pavel.tatashin@microsoft.com \
    --cc=rppt@linux.ibm.com \
    --cc=vbabka@suse.cz \
    --cc=virtio-dev@lists.oasis-open.org \
    --cc=virtualization@lists.linux-foundation.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).