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=-8.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable 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 36FCFC7618B for ; Thu, 25 Jul 2019 08:53:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DB26522BED for ; Thu, 25 Jul 2019 08:53:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DB26522BED 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 6AA816B0283; Thu, 25 Jul 2019 04:53:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 634438E0031; Thu, 25 Jul 2019 04:53:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4D5906B0285; Thu, 25 Jul 2019 04:53:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by kanga.kvack.org (Postfix) with ESMTP id 262FD6B0283 for ; Thu, 25 Jul 2019 04:53:28 -0400 (EDT) Received: by mail-qt1-f197.google.com with SMTP id y19so43951011qtm.0 for ; Thu, 25 Jul 2019 01:53:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:subject:to:cc :references:from:openpgp:autocrypt:organization:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=4ivvoK5UgzU2OMXYCcff3WUBgt6SD9abgskYDqHcU5E=; b=KWuGyjiBqgMsp+mwyMBA/F1ryjb8TrOmEiEpSq+a0wIGTOk0szfoCJuEW87Wg8cCrC Za4IuITYx1y7toTgxzCnJq2PJv0fDaaq1/Zbr2rnnQcy/8+vomMfBcYM08Dctsy/7h2i Go3rl46Fu3nxUB+ICVnJkt6JsER+LqndtduTUfWjy3pksxiVvfSn5BTs8GN9xn8sWMga a/SFTvEzPYcpcZuXngXdTSiEA+yXFx95YfzyGmVB9+cGthYZ1FEuZKRfiDI/vCjdlgIF Mdri/6CDOSZbQAje+PhTKCELG8Mn8Ga3WV/T2xv+YnZvdhRQ/vOnsXa2heG/uX3uOyF8 I1Yg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of david@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: APjAAAW/FLG7Bf0PcCxltNvJIvDFqiE8SmnRTYNrRvw0BGvjntoASd1l R8Yed8NbYE502NqtkG7HcwocfXvtBKbiRbNnVW4RfCZ5P1y+vUBaM25uj6Ix/d9O2Q/2cOesctD dkvfa6FVl5qb5KNEeVIZSCWnAYGawmL0zML+YooGDqHxqfFQWHQ5CTEoNX8COS8hXbw== X-Received: by 2002:a0c:b4ab:: with SMTP id c43mr60661699qve.157.1564044807892; Thu, 25 Jul 2019 01:53:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqxNjkumr7c19raylhmBUo+pVz+LMsK/3pmPwGK4UiDhgvzAUnUFwVlnRoPeM9WxYrgCJfwM X-Received: by 2002:a0c:b4ab:: with SMTP id c43mr60661667qve.157.1564044807022; Thu, 25 Jul 2019 01:53:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564044807; cv=none; d=google.com; s=arc-20160816; b=PuS5+P4FTh4pksSwAj+ms/oDouXXBz0pv5qcbC7Ns85fr80VCXcM3qg4tIj+QiZ/HL YCOO8+K1nta73Ae3gXGSAYN7bL2o7usCTS1/6/5xO6YcZcdE28TDQjj92cEdISKGH+U5 RIAeYJPDgsbY3etqURaBygYMr5nsu0s5UP4+lFXyxiUmzLTVQbX35Z2qjv1mhRE9qzwj Z7lUensB4sUJ7X4qonOQT0GBPCQ/t9Y/CvOzeFDfTWy73MfrowARiqwfqsDDoPePdh38 uazwmn4SD3957l6UXXsa4SEI1BSTdM8WQmBzKnZ788wP5mfzqqU+DuwhmDYqxxcvZfNj Qn8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:organization:autocrypt:openpgp:from :references:cc:to:subject; bh=4ivvoK5UgzU2OMXYCcff3WUBgt6SD9abgskYDqHcU5E=; b=QWUPsVz2uBm3RHrXE/ypqPMMazbC70HxS1wNkYqtY9qYOx7JpZem4VeZHz1/ONmfIe trJjJ7edzWGJtcbwoCyKgEzQNhhQ4phctb1U/epMwUbCZy5fbwswwOJC8UQnoHmVkdt3 gTuAuNygxBCdT886HYpkm9146WBCvZvNz/rvQ2GIghd34vmICfsQlPPqxWuX04NiOnkY rCnVJo1SRmKfInqiwMrc5E9An5UqORd/3abSkgcCfRmLc6mIRwGxiYgLJdMdqqfTM4Fg O3Gro5Qf5PI/yHBAqOBo/AoqHM+4WTcmimoU42QsXY5U2qBwflRglbbjRiNwEev+DruU 0tTw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of david@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id p54si31499903qtc.371.2019.07.25.01.53.26 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Jul 2019 01:53:27 -0700 (PDT) Received-SPF: pass (google.com: domain of david@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of david@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 13CFA3E2D7; Thu, 25 Jul 2019 08:53:26 +0000 (UTC) Received: from [10.36.117.212] (ovpn-117-212.ams2.redhat.com [10.36.117.212]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8510C5DD94; Thu, 25 Jul 2019 08:53:14 +0000 (UTC) Subject: Re: [PATCH v2 4/5] mm: Introduce Hinted pages To: Alexander Duyck , nitesh@redhat.com, kvm@vger.kernel.org, mst@redhat.com, dave.hansen@intel.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, akpm@linux-foundation.org Cc: yang.zhang.wz@gmail.com, pagupta@redhat.com, riel@surriel.com, konrad.wilk@oracle.com, lcapitulino@redhat.com, wei.w.wang@intel.com, aarcange@redhat.com, pbonzini@redhat.com, dan.j.williams@intel.com, Matthew Wilcox References: <20190724165158.6685.87228.stgit@localhost.localdomain> <20190724170259.6685.18028.stgit@localhost.localdomain> From: David Hildenbrand Openpgp: preference=signencrypt Autocrypt: addr=david@redhat.com; prefer-encrypt=mutual; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQa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b/iXVbM+fmSHOjEshl KMwEl/m5iLj3iHnHPVLBUWrXPdS7iQijJA/VLxjnFknhaS60hkUNWexDMxVVP/6lbOrs4bDZ NEWDMktAeqJaFtxackPszlcpRVkAs6Msn9tu8hlvB517pyUgvuD7ZS9gGOMmYwFQDyytpepo YApVV00P0u3AaE0Cj/o71STqGJKZxcVhPaZ+LR+UCBZOyKfEyq+ZN311VpOJZ1IvTExf+S/5 lqnciDtbO3I4Wq0ArLX1gs1q1XlXLaVaA3yVqeC8E7kOchDNinD3hJS4OX0e1gdsx/e6COvy qNg5aL5n0Kl4fcVqM0LdIhsubVs4eiNCa5XMSYpXmVi3HAuFyg9dN+x8thSwI836FoMASwOl C7tHsTjnSGufB+D7F7ZBT61BffNBBIm1KdMxcxqLUVXpBQHHlGkbwI+3Ye+nE6HmZH7IwLwV W+Ajl7oYF+jeKaH4DZFtgLYGLtZ1LDwKPjX7VAsa4Yx7S5+EBAaZGxK510MjIx6SGrZWBrrV TEvdV00F2MnQoeXKzD7O4WFbL55hhyGgfWTHwZ457iN9SgYi1JLPqWkZB0JRXIEtjd4JEQcx +8Umfre0Xt4713VxMygW0PnQt5aSQdMD58jHFxTk092mU+yIHj5LeYgvwSgZN4airXk5yRXl SE+xAvmumFBY Organization: Red Hat GmbH Message-ID: Date: Thu, 25 Jul 2019 10:53:13 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: <20190724170259.6685.18028.stgit@localhost.localdomain> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 25 Jul 2019 08:53:26 +0000 (UTC) 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 24.07.19 19:03, Alexander Duyck wrote: > From: Alexander Duyck > > In order to pave the way for free page hinting in virtualized environments > we will need a way to get pages out of the free lists and identify those > pages after they have been returned. To accomplish this, this patch adds > the concept of a Hinted Buddy, which is essentially meant to just be the > Offline page type used in conjunction with the Buddy page type. > > It adds a set of pointers we shall call "boundary" which represents the > upper boundary between the unhinted and hinted pages. The general idea is > that in order for a page to cross from one side of the boundary to the > other it will need to go through the hinting process. Ultimately a > free_list has been fully processed when the boundary has been moved from > the tail all they way up to occupying the first entry in the list. > > Doing this we should be able to make certain that we keep the hinted > pages as one contiguous block in each free list. This will allow us to > efficiently manipulate the free lists whenever we need to go in and start > sending hints to the hypervisor that there are new pages that have been > freed and are no longer in use. > > An added advantage to this approach is that we should be reducing the > overall memory footprint of the guest as it will be more likely to recycle > warm pages versus trying to allocate the hinted pages that were likely > evicted from the guest memory. > > Since we will only be hinting one zone at a time we keep the boundary > limited to being defined for just the zone we are currently placing hinted > pages into. Doing this we can keep the number of additional pointers needed > quite small. To flag that the boundaries are in place we use a single bit > in the zone to indicate that hinting and the boundaries are active. > > The determination of when to start hinting is based on the tracking of the > number of free pages in a given area versus the number of hinted pages in > that area. We keep track of the number of hinted pages per free_area in a > separate zone specific area. We do this to avoid modifying the free_area > structure as this can lead to false sharing for the highest order with the > zone lock which leads to a noticeable performance degradation. > > Signed-off-by: Alexander Duyck > --- > include/linux/mmzone.h | 40 +++++- > include/linux/page-flags.h | 8 + > include/linux/page_hinting.h | 139 ++++++++++++++++++++ > mm/Kconfig | 5 + > mm/Makefile | 1 > mm/memory_hotplug.c | 1 > mm/page_alloc.c | 136 ++++++++++++++++++- > mm/page_hinting.c | 298 ++++++++++++++++++++++++++++++++++++++++++ > 8 files changed, 620 insertions(+), 8 deletions(-) > create mode 100644 include/linux/page_hinting.h > create mode 100644 mm/page_hinting.c > > diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h > index f0c68b6b6154..42bdebb20484 100644 > --- a/include/linux/mmzone.h > +++ b/include/linux/mmzone.h > @@ -460,6 +460,14 @@ struct zone { > seqlock_t span_seqlock; > #endif > > +#ifdef CONFIG_PAGE_HINTING > + /* > + * Pointer to hinted page tracking statistics array. The size of > + * the array is MAX_ORDER - PAGE_HINTING_MIN_ORDER. NULL when > + * page hinting is not present. > + */ > + unsigned long *hinted_pages; > +#endif > int initialized; > > /* Write-intensive fields used from the page allocator */ > @@ -535,6 +543,14 @@ enum zone_flags { > ZONE_BOOSTED_WATERMARK, /* zone recently boosted watermarks. > * Cleared when kswapd is woken. > */ > + ZONE_PAGE_HINTING_REQUESTED, /* zone enabled page hinting and has > + * requested flushing the data out of > + * higher order pages. > + */ > + ZONE_PAGE_HINTING_ACTIVE, /* zone enabled page hinting and is > + * activly flushing the data out of > + * higher order pages. > + */ > }; > > static inline unsigned long zone_managed_pages(struct zone *zone) > @@ -755,6 +771,8 @@ static inline bool pgdat_is_empty(pg_data_t *pgdat) > return !pgdat->node_start_pfn && !pgdat->node_spanned_pages; > } > > +#include > + > /* Used for pages not on another list */ > static inline void add_to_free_list(struct page *page, struct zone *zone, > unsigned int order, int migratetype) > @@ -769,10 +787,16 @@ static inline void add_to_free_list(struct page *page, struct zone *zone, > static inline void add_to_free_list_tail(struct page *page, struct zone *zone, > unsigned int order, int migratetype) > { > - struct free_area *area = &zone->free_area[order]; > + struct list_head *tail = get_unhinted_tail(zone, order, migratetype); > > - list_add_tail(&page->lru, &area->free_list[migratetype]); > - area->nr_free++; > + /* > + * To prevent the unhinted pages from being interleaved with the > + * hinted ones while we are actively processing pages we will use > + * the head of the hinted pages to determine the tail of the free > + * list. > + */ > + list_add_tail(&page->lru, tail); > + zone->free_area[order].nr_free++; > } > > /* Used for pages which are on another list */ > @@ -781,12 +805,22 @@ static inline void move_to_free_list(struct page *page, struct zone *zone, > { > struct free_area *area = &zone->free_area[order]; > > + /* > + * Clear Hinted flag, if present, to avoid placing hinted pages > + * at the top of the free_list. It is cheaper to just process this > + * page again, then have to walk around a page that is already hinted. > + */ > + clear_page_hinted(page, zone); > + > list_move(&page->lru, &area->free_list[migratetype]); > } > > static inline void del_page_from_free_list(struct page *page, struct zone *zone, > unsigned int order) > { > + /* Clear Hinted flag, if present, before clearing the Buddy flag */ > + clear_page_hinted(page, zone); > + > list_del(&page->lru); > __ClearPageBuddy(page); > set_page_private(page, 0); > diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h > index b848517da64c..b753dbf673cb 100644 > --- a/include/linux/page-flags.h > +++ b/include/linux/page-flags.h > @@ -745,6 +745,14 @@ static inline int page_has_type(struct page *page) > PAGE_TYPE_OPS(Offline, offline) > > /* > + * PageHinted() is an alias for Offline, however it is not meant to be an > + * exclusive value. It should be combined with PageBuddy() when seen as it > + * is meant to indicate that the page has been scrubbed while waiting in > + * the buddy system. > + */ > +PAGE_TYPE_OPS(Hinted, offline) CCing Matthew I am still not sure if I like the idea of having two page types at a time. 1. Once we run out of page type bits (which can happen easily looking at it getting more and more user - e.g., maybe for vmmap pages soon), we might want to convert again back to a value-based, not bit-based type detection. This will certainly make this switch harder. 2. It will complicate the kexec/kdump handling. I assume it can be fixed some way - e.g., making the elf interface aware of the exact notion of page type bits compared to mapcount values we have right now (e.g., PAGE_BUDDY_MAPCOUNT_VALUE). Not addressed in this series yet. Can't we reuse one of the traditional page flags for that, not used along with buddy pages? E.g., PG_dirty: Pages that were not hinted yet are dirty. Matthew, what's your take? -- Thanks, David / dhildenb