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=-2.4 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no 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 59526C4BA01 for ; Tue, 25 Feb 2020 22:19:41 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CBD3720838 for ; Tue, 25 Feb 2020 22:19:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="GHTS+twZ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CBD3720838 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 2DFE76B0006; Tue, 25 Feb 2020 17:19:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 26C746B0007; Tue, 25 Feb 2020 17:19:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 10A5A6B0037; Tue, 25 Feb 2020 17:19:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0084.hostedemail.com [216.40.44.84]) by kanga.kvack.org (Postfix) with ESMTP id EAA626B0006 for ; Tue, 25 Feb 2020 17:19:39 -0500 (EST) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 8D632181AC9BF for ; Tue, 25 Feb 2020 22:19:39 +0000 (UTC) X-FDA: 76530067278.11.wash70_1a121db459839 X-HE-Tag: wash70_1a121db459839 X-Filterd-Recvd-Size: 12341 Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by imf37.hostedemail.com (Postfix) with ESMTP for ; Tue, 25 Feb 2020 22:19:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582669178; 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:autocrypt:autocrypt; bh=gCSArIx/3mY9oSIUMRjqx2+R3OvuPX6j2QVZuQeM+/k=; b=GHTS+twZm7rThRIRTIan3iEXMMTE22tyYPOnP0HDibeyc2iN4QA6J8xVzZ1eYEGNgIeo+K 7uAiQ0surOa3O/HWcIpbGl7SRFRIWJ8ODZEUJFjwTawr+RMy0bdb6WUWsvDPvlBZ5lnZaf 3Gpy7M1+EAIUHt9prW1N6Fy/s0U60to= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-478-W7WYJUYZNry96hYG-fYhtA-1; Tue, 25 Feb 2020 17:19:30 -0500 X-MC-Unique: W7WYJUYZNry96hYG-fYhtA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1AE78107ACC4; Tue, 25 Feb 2020 22:19:27 +0000 (UTC) Received: from [10.36.117.12] (ovpn-117-12.ams2.redhat.com [10.36.117.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id DA1208B759; Tue, 25 Feb 2020 22:19:18 +0000 (UTC) Subject: Re: [PATCH RFC v4 06/13] mm: Allow to offline unmovable PageOffline() pages via MEM_GOING_OFFLINE To: Alexander Duyck , 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 , Andrew Morton , "Michael S . Tsirkin" , Juergen Gross , Konrad Rzeszutek Wilk , Pavel Tatashin , Vlastimil Babka , Johannes Weiner , Anthony Yznaga , Michal Hocko , Oscar Salvador , Mel Gorman , Mike Rapoport , Dan Williams , Anshuman Khandual , Qian Cai , Pingfan Liu References: <20191212171137.13872-1-david@redhat.com> <20191212171137.13872-7-david@redhat.com> <6ec496580ddcb629d22589a1cba8cd61cbd53206.camel@linux.intel.com> <267ea186-aba8-1a93-bd55-ac641f78d07e@redhat.com> <3d719897039273a2bb8d0fe7d12563498ebd2897.camel@linux.intel.com> From: David Hildenbrand Autocrypt: addr=david@redhat.com; prefer-encrypt=mutual; keydata= mQINBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qaSr0ID2sz5jtBLRb15RMre27E1ImpaIv2Jw8NJgW0k/D1RyKCwaTsgRdwuK Kx/Y91XuSBdz0uOyU/S8kM1+ag0wvsGlpBVxRR/xw/E8M7TEwuCZQArqqTCmkG6HGcXFT0V9 PXFNNgV5jXMQRwU0O/ztJIQqsE5LsUomE//bLwzj9IVsaQpKDqW6TAPjcdBDPLHvriq7kGjt WhVhdl0qEYB8lkBEU7V2Yb+SYhmhpDrti9Fq1EsmhiHSkxJcGREoMK/63r9WLZYI3+4W2rAc UucZa4OT27U5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5tWzh6I0JrlcxJ ileZWLccC4XKD1037Hy2FLAjzfoWgwBLA6ULu0exOOdIa58H4PsXtkFPrUF980EEibUp0zFz GotRVekFAceUaRvAj7dh76cToeZkfsjAvBVb4COXuhgX6N4pofgNkW2AtgYu1nUsPAo+NftU CxrhjHtLn4QEBpkbErnXQyMjHpIatlYGutVMS91XTQXYydCh5crMPs7hYVsvnmGHIaB9ZMfB njnuI31KBiLUks+paRkHQlFcgS2N3gkRBzH7xSZ+t7Re3jvXdXEzKBbQ+dC3lpJB0wPnyMcX FOTT3aZT7IgePkt5iC/BKBk3hqKteTnJFeVIT7EC+a6YUFg= Organization: Red Hat GmbH Message-ID: Date: Tue, 25 Feb 2020 23:19:18 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <3d719897039273a2bb8d0fe7d12563498ebd2897.camel@linux.intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Content-Transfer-Encoding: quoted-printable 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 25.02.20 22:46, Alexander Duyck wrote: > On Tue, 2020-02-25 at 19:49 +0100, David Hildenbrand wrote: >>>> /* >>>> * Scan pfn range [start,end) to find movable/migratable pages (LRU= pages, >>>> - * non-lru movable pages and hugepages). We scan pfn because it's m= uch >>>> - * 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, unsign= ed long end) >>>> +static int scan_movable_pages(unsigned long start, unsigned long en= d, >>>> + unsigned long *movable_pfn) >>>> { >>>> unsigned long pfn; >>>> =20 >>>> @@ -1247,18 +1251,29 @@ static unsigned long scan_movable_pages(unsi= gned long start, unsigned long end) >>>> continue; >>>> page =3D 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 is= n't >>> about offlining memory, it is about finding movable pages. I had to d= o a >>> bit of digging to find the only consumer is __offline_pages, but if w= e 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 := ) >=20 > I dunno. What I was getting at is that the wording here would make it > clearer if you simply stated that these pages "can definately not be > moved". Saying you cannot offline a page that is PageOffline seems kind= of > redundant, then again calling it an Unmovable and then saying it cannot= be > moves is also redundant I suppose. In the end you don't move them, but So, in summary, there are - PageOffline() pages that are movable (balloon compaction). - PageOffline() pages that cannot be moved and cannot be offlined (e.g., no balloon compaction enabled, XEN, HyperV, ...) . page_count(page) >=3D 0 - PageOffline() pages that cannot be moved, but can be offlined. page_count(page) =3D=3D 0. > they can be switched to offline if the page count hits 0. When that > happens you simply end up skipping over them in the code for > __test_page_isolated_in_pageblock and __offline_isolated_pages. Yes. The thing with the wording is that pages with (PageOffline(page) && !page_count(page)) can also not really be moved, but they can be skipped when offlining. If we call that "moving them to /dev/null", then yes, they can be moved to some degree :) I can certainly do here e.g., /* * PageOffline() pages that are not marked __PageMovable() and have a * reference count > 0 (after MEM_GOING_OFFLINE) are definitely * unmovable. If their reference count would be 0, they could be skipped * when offlining memory sections. */ And maybe I'll add to the function doc, that unmovable pages that are skipped in this function can include pages that can be skipped when offlining (moving them to nirvana). Other suggestions? [...] >> >> [1] we detect a definite offlining blocker and >> >>>> + } while (!ret); >>>> + >>>> + if (ret !=3D -ENOENT) { >>>> + reason =3D "unmovable page"; >> >> [2] we abort offlining >> >>>> + goto failed_removal_isolated; >>>> } >>>> =20 >>>> /* >=20 > Yeah, this is the piece I misread. I knew the loop this was in previou= sly > was looping when returning -ENOENT so for some reason I had it in my he= ad > that you were still looping on -EBUSY. Ah okay, I see. Yeah, that wouldn't make sense for the use case I have :) >=20 > So the one question I would have is if at this point are we guaranteed > that the balloon drivers have already taken care of the page count for = all > the pages they set to PageOffline? Based on the patch description I was > thinking that this was going to be looping for a while waiting for the > driver to clear the pages and then walking through them at the end of t= he > loop via check_pages_isolated_cb. So, e.g., the patch description states "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." Any balloon driver that does not allow offlining (e.g., XEN, HyperV, virtio-balloon), will always have a refcount of (at least) 1. Drivers that want to make use of that (esp. virtio-mem, but eventually also HyperV), will drop their refcount via the MEM_GOING_OFFLINE call. So yes, at this point, all applicable users were notified via MEM_GOING_OFFLINE and had their chance to decrement the refcount. If they didn't, offlining will be aborted. Thanks again! --=20 Thanks, David / dhildenb