From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8C6E7C38A2A for ; Thu, 7 May 2020 10:48:22 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 34B5A24965 for ; Thu, 7 May 2020 10:48:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="F6DGQWG9" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 34B5A24965 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id C22A3900011; Thu, 7 May 2020 06:48:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BF9A5900002; Thu, 7 May 2020 06:48:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B0FC7900011; Thu, 7 May 2020 06:48:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0060.hostedemail.com [216.40.44.60]) by kanga.kvack.org (Postfix) with ESMTP id 98175900002 for ; Thu, 7 May 2020 06:48:21 -0400 (EDT) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 50CE652B2 for ; Thu, 7 May 2020 10:48:21 +0000 (UTC) X-FDA: 76789598802.16.glass39_48e2f56b7e744 X-HE-Tag: glass39_48e2f56b7e744 X-Filterd-Recvd-Size: 14838 Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by imf22.hostedemail.com (Postfix) with ESMTP for ; Thu, 7 May 2020 10:48:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588848500; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HaCois34boazXE34ZbGTcYMI7c78Z+6ZxCZwta26PME=; b=F6DGQWG9X4eAiaJ+kJ7E8TUiz56kD423+fkiwoWfWOfNkjsnBFsokxAubpgGST9Te7STVA MI1pWXX0lEPJbaDf/w6/jfW72BBFc9WEeZjDEaQKPCPo52F2vSX5YdqCI3+m6PIqAl/60i 0qD92f1ShEafY1ukGfTPo4tidT83toc= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-79-g37F_CjQPLmkIIKl9ubnGg-1; Thu, 07 May 2020 06:48:18 -0400 X-MC-Unique: g37F_CjQPLmkIIKl9ubnGg-1 Received: by mail-wr1-f70.google.com with SMTP id u4so3194935wrm.13 for ; Thu, 07 May 2020 03:48:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=HDJlw7bDQi8Wi4/pLpjel0dn8YQBpbxuhOnB1M+bLZ8=; b=f0DDeqecRCzxz/FpDbIhgxE6s2MY7Oy/4D1e25Fd/T8YiyhIX02Bk15kAt+ftPeCTG vCOXmsKg2KkTzBLj/WO+BBQ5q8F59iEV9WDP8vjpFvSUESKqUlBut1tdwaVt2Rzkk2QZ 9hChINhcQHSpGNLM2GFc+jKh4G3un1lpHo7fhRIBd8S5577m1Y3u/isBBowOKtlSTWzw pmuYAZGlvcfN/L3Bh8fu3nvhsjWZGSwAa6k1fa3vsnOj89xvQiqjGdvbr1QA0z9z2QC6 aqFZmUsi/uUXWW8wqoR8rRJvAey23BDYYnwE1CVJHiDiC9v2NKu/7SOe/uNGehTP2aly 5hkQ== X-Gm-Message-State: AGi0Pua3EJB6P1ElQxtO6s818ga3tKq9FF8s4txCM6CKxNxwX82f3e36 cXd0b0XGd84bDGpQr2AkOt1HE1iI8MLZ6Ou5uzDW+z71XbBSaKczyAkzm0LPbI6QofaEbozkfbf km9KhhATy/l4= X-Received: by 2002:adf:a4c5:: with SMTP id h5mr14486161wrb.408.1588848497379; Thu, 07 May 2020 03:48:17 -0700 (PDT) X-Google-Smtp-Source: APiQypL4+7pUE08G0jxdS6pm75fKLU9uxI5bwpKwaX3aZ2jOo0uivuxhRm4gpV4SaVV9oM0knr2o7w== X-Received: by 2002:adf:a4c5:: with SMTP id h5mr14486114wrb.408.1588848496853; Thu, 07 May 2020 03:48:16 -0700 (PDT) Received: from redhat.com (bzq-109-66-7-121.red.bezeqint.net. [109.66.7.121]) by smtp.gmail.com with ESMTPSA id s14sm7033661wmh.18.2020.05.07.03.48.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 May 2020 03:48:16 -0700 (PDT) Date: Thu, 7 May 2020 06:48:12 -0400 From: "Michael S. Tsirkin" To: David Hildenbrand Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, virtio-dev@lists.oasis-open.org, virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, Michal Hocko , Andrew Morton , Alexander Duyck , Michal Hocko , Pankaj Gupta , Juergen Gross , Konrad Rzeszutek Wilk , Pavel Tatashin , Vlastimil Babka , Johannes Weiner , Anthony Yznaga , Oscar Salvador , Mel Gorman , Mike Rapoport , Dan Williams , Anshuman Khandual , Qian Cai , Pingfan Liu Subject: Re: [PATCH v3 05/15] mm: Allow to offline unmovable PageOffline() pages via MEM_GOING_OFFLINE Message-ID: <20200507064750-mutt-send-email-mst@kernel.org> References: <20200507103119.11219-1-david@redhat.com> <20200507103119.11219-6-david@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200507103119.11219-6-david@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu, May 07, 2020 at 12:31:09PM +0200, David Hildenbrand wrote: > virtio-mem wants to allow to offline memory blocks of which some parts > were unplugged (allocated via alloc_contig_range()), especially, to later > offline and remove completely unplugged memory blocks. The important part > is that PageOffline() has to remain set until the section is offline, so > these pages will never get accessed (e.g., when dumping). The pages shoul= d > not be handed back to the buddy (which would require clearing PageOffline= () > and result in issues if offlining fails and the pages are suddenly in the > buddy). >=20 > Let's allow to do that by allowing to isolate any PageOffline() page > when offlining. This way, we can reach the memory hotplug notifier > MEM_GOING_OFFLINE, where the driver can signal that he is fine with > offlining this page by dropping its reference count. PageOffline() pages > with a reference count of 0 can then be skipped when offlining the > pages (like if they were free, however they are not in the buddy). >=20 > Anybody who uses PageOffline() pages and does not agree to offline them > (e.g., Hyper-V balloon, XEN balloon, VMWare balloon for 2MB pages) will n= ot > decrement the reference count and make offlining fail when trying to > migrate such an unmovable page. So there should be no observable change. > Same applies to balloon compaction users (movable PageOffline() pages), t= he > pages will simply be migrated. >=20 > Note 1: If offlining fails, a driver has to increment the reference > =09count again in MEM_CANCEL_OFFLINE. >=20 > Note 2: A driver that makes use of this has to be aware that re-onlining > =09the memory block has to be handled by hooking into onlining code > =09(online_page_callback_t), resetting the page PageOffline() and > =09not giving them to the buddy. >=20 > Reviewed-by: Alexander Duyck > Acked-by: Michal Hocko > Tested-by: Pankaj Gupta > Cc: Andrew Morton > Cc: Juergen Gross > Cc: Konrad Rzeszutek Wilk > Cc: Pavel Tatashin > Cc: Alexander Duyck > Cc: Vlastimil Babka > Cc: Johannes Weiner > Cc: Anthony Yznaga > Cc: Michal Hocko > Cc: Oscar Salvador > Cc: Mel Gorman > Cc: Mike Rapoport > Cc: Dan Williams > Cc: Anshuman Khandual > Cc: Qian Cai > Cc: Pingfan Liu > Signed-off-by: David Hildenbrand Didn't you lose some Andrew Morton's ack on this? > --- > include/linux/page-flags.h | 10 +++++++++ > mm/memory_hotplug.c | 44 +++++++++++++++++++++++++++++--------- > mm/page_alloc.c | 24 +++++++++++++++++++++ > mm/page_isolation.c | 9 ++++++++ > 4 files changed, 77 insertions(+), 10 deletions(-) >=20 > diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h > index 222f6f7b2bb3..6be1aa559b1e 100644 > --- a/include/linux/page-flags.h > +++ b/include/linux/page-flags.h > @@ -777,6 +777,16 @@ PAGE_TYPE_OPS(Buddy, buddy) > * not onlined when onlining the section). > * The content of these pages is effectively stale. Such pages should no= t > * be touched (read/write/dump/save) except by their owner. > + * > + * If a driver wants to allow to offline unmovable PageOffline() pages w= ithout > + * putting them back to the buddy, it can do so via the memory notifier = by > + * decrementing the reference count in MEM_GOING_OFFLINE and incrementin= g the > + * reference count in MEM_CANCEL_OFFLINE. When offlining, the PageOfflin= e() > + * pages (now with a reference count of zero) are treated like free page= s, > + * allowing the containing memory block to get offlined. A driver that > + * relies on this feature is aware that re-onlining the memory block wil= l > + * require to re-set the pages PageOffline() and not giving them to the > + * buddy via online_page_callback_t. > */ > PAGE_TYPE_OPS(Offline, offline) > =20 > diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c > index 555137bd0882..936bfe208a6e 100644 > --- a/mm/memory_hotplug.c > +++ b/mm/memory_hotplug.c > @@ -1151,11 +1151,17 @@ struct zone *test_pages_in_a_zone(unsigned long s= tart_pfn, > =20 > /* > * Scan pfn range [start,end) to find movable/migratable pages (LRU page= s, > - * 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). Will skip over most unmovable > + * pages (esp., pages that can be skipped when offlining), but bail out = on > + * definitely unmovable pages. > + * > + * Returns: > + *=090 in case a movable page is found and movable_pfn was updated. > + *=09-ENOENT in case no movable page was found. > + *=09-EBUSY in case a definitely unmovable page was found. > */ > -static unsigned long scan_movable_pages(unsigned long start, unsigned lo= ng end) > +static int scan_movable_pages(unsigned long start, unsigned long end, > +=09=09=09 unsigned long *movable_pfn) > { > =09unsigned long pfn; > =20 > @@ -1167,18 +1173,30 @@ static unsigned long scan_movable_pages(unsigned = long start, unsigned long end) > =09=09=09continue; > =09=09page =3D pfn_to_page(pfn); > =09=09if (PageLRU(page)) > -=09=09=09return pfn; > +=09=09=09goto found; > =09=09if (__PageMovable(page)) > -=09=09=09return pfn; > +=09=09=09goto found; > + > +=09=09/* > +=09=09 * PageOffline() pages that are not marked __PageMovable() and > +=09=09 * have a reference count > 0 (after MEM_GOING_OFFLINE) are > +=09=09 * definitely unmovable. If their reference count would be 0, > +=09=09 * they could at least be skipped when offlining memory. > +=09=09 */ > +=09=09if (PageOffline(page) && page_count(page)) > +=09=09=09return -EBUSY; > =20 > =09=09if (!PageHuge(page)) > =09=09=09continue; > =09=09head =3D compound_head(page); > =09=09if (page_huge_active(head)) > -=09=09=09return pfn; > +=09=09=09goto found; > =09=09skip =3D compound_nr(head) - (page - head); > =09=09pfn +=3D skip - 1; > =09} > +=09return -ENOENT; > +found: > +=09*movable_pfn =3D pfn; > =09return 0; > } > =20 > @@ -1441,7 +1459,8 @@ static int __ref __offline_pages(unsigned long star= t_pfn, > =09} > =20 > =09do { > -=09=09for (pfn =3D start_pfn; pfn;) { > +=09=09pfn =3D start_pfn; > +=09=09do { > =09=09=09if (signal_pending(current)) { > =09=09=09=09ret =3D -EINTR; > =09=09=09=09reason =3D "signal backoff"; > @@ -1451,14 +1470,19 @@ static int __ref __offline_pages(unsigned long st= art_pfn, > =09=09=09cond_resched(); > =09=09=09lru_add_drain_all(); > =20 > -=09=09=09pfn =3D scan_movable_pages(pfn, end_pfn); > -=09=09=09if (pfn) { > +=09=09=09ret =3D scan_movable_pages(pfn, end_pfn, &pfn); > +=09=09=09if (!ret) { > =09=09=09=09/* > =09=09=09=09 * TODO: fatal migration failures should bail > =09=09=09=09 * out > =09=09=09=09 */ > =09=09=09=09do_migrate_range(pfn, end_pfn); > =09=09=09} > +=09=09} while (!ret); > + > +=09=09if (ret !=3D -ENOENT) { > +=09=09=09reason =3D "unmovable page"; > +=09=09=09goto failed_removal_isolated; > =09=09} > =20 > =09=09/* > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index 64fcaf86763b..6fb3dfca2a97 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -8230,6 +8230,19 @@ struct page *has_unmovable_pages(struct zone *zone= , struct page *page, > =09=09if ((flags & MEMORY_OFFLINE) && PageHWPoison(page)) > =09=09=09continue; > =20 > +=09=09/* > +=09=09 * We treat all PageOffline() pages as movable when offlining > +=09=09 * to give drivers a chance to decrement their reference count > +=09=09 * in MEM_GOING_OFFLINE in order to indicate that these pages > +=09=09 * can be offlined as there are no direct references anymore. > +=09=09 * For actually unmovable PageOffline() where the driver does > +=09=09 * not support this, we will fail later when trying to actually > +=09=09 * move these pages that still have a reference count > 0. > +=09=09 * (false negatives in this function only) > +=09=09 */ > +=09=09if ((flags & MEMORY_OFFLINE) && PageOffline(page)) > +=09=09=09continue; > + > =09=09if (__PageMovable(page) || PageLRU(page)) > =09=09=09continue; > =20 > @@ -8650,6 +8663,17 @@ __offline_isolated_pages(unsigned long start_pfn, = unsigned long end_pfn) > =09=09=09offlined_pages++; > =09=09=09continue; > =09=09} > +=09=09/* > +=09=09 * At this point all remaining PageOffline() pages have a > +=09=09 * reference count of 0 and can simply be skipped. > +=09=09 */ > +=09=09if (PageOffline(page)) { > +=09=09=09BUG_ON(page_count(page)); > +=09=09=09BUG_ON(PageBuddy(page)); > +=09=09=09pfn++; > +=09=09=09offlined_pages++; > +=09=09=09continue; > +=09=09} > =20 > =09=09BUG_ON(page_count(page)); > =09=09BUG_ON(!PageBuddy(page)); > diff --git a/mm/page_isolation.c b/mm/page_isolation.c > index 2c11a38d6e87..f6d07c5f0d34 100644 > --- a/mm/page_isolation.c > +++ b/mm/page_isolation.c > @@ -151,6 +151,7 @@ __first_valid_page(unsigned long pfn, unsigned long n= r_pages) > *=09=09=09a bit mask) > *=09=09=09MEMORY_OFFLINE - isolate to offline (!allocate) memory > *=09=09=09=09=09 e.g., skip over PageHWPoison() pages > + *=09=09=09=09=09 and PageOffline() pages. > *=09=09=09REPORT_FAILURE - report details about the failure to > *=09=09=09isolate the range > * > @@ -259,6 +260,14 @@ __test_page_isolated_in_pageblock(unsigned long pfn,= unsigned long end_pfn, > =09=09else if ((flags & MEMORY_OFFLINE) && PageHWPoison(page)) > =09=09=09/* A HWPoisoned page cannot be also PageBuddy */ > =09=09=09pfn++; > +=09=09else if ((flags & MEMORY_OFFLINE) && PageOffline(page) && > +=09=09=09 !page_count(page)) > +=09=09=09/* > +=09=09=09 * The responsible driver agreed to skip PageOffline() > +=09=09=09 * pages when offlining memory by dropping its > +=09=09=09 * reference in MEM_GOING_OFFLINE. > +=09=09=09 */ > +=09=09=09pfn++; > =09=09else > =09=09=09break; > =09} > --=20 > 2.25.3