Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp10904881ybi; Thu, 25 Jul 2019 06:52:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqyptEgeTvfNtIXwYKmJO4qq2GFOU0/Na9byShZk0RXKyTPRfV5aGFvoOoqfjmCX5CqU7B50 X-Received: by 2002:a63:7455:: with SMTP id e21mr81359553pgn.439.1564062731175; Thu, 25 Jul 2019 06:52:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564062731; cv=none; d=google.com; s=arc-20160816; b=mzRzYgTnq7ARcc4KR0Uk2+Di7TphEDz1mscc6mlJjW0M8agXjoNNxk0kXAxvIY4Rz6 Mp5n3P8uHQyVrbvLyBbnqW+KwnEhXJz3R0d1KYxud8iiRw770OxRviOPQ1Y+UUMWUfnl L2zUJJGZz+8zj+a+4QbvrkskjP7pAiEnVYOyPjQdg9FKTWRKM+R/g4poi8x5ZBEBMoJO 0wGmWIGkyWN2ZaPah2IwN9TwmUodftSP421hKKFShztx2s3ybwk8TgWTrBzZ1rpBdc1K /L5cP5h8yhO7uj7kmACuomrBS5y/zNCfK5M2I2h29x1myNCXGD1ku1lb5r/kjlo9oA3W 9PgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:organization:autocrypt:openpgp:from:references:cc:to :subject; bh=kpzpSJi5e0fCtgugzze/wcqKykzhP8xLi9aj9Z4mxAQ=; b=hFdrCUFZkukYCTTk5ofsnHAHRWf6fQ7YZFnJgL36yvnOfYqXNO4MQTU16ejmEKQxYL aPwKwFzf11QDfELHJ57PrvFCtQ9ORB/hDHPdbOJrlZZuU1OjI0I0PXce4+TDGcOOs+bN tXX+Rod//T1kalasJOs8jpqYZ6eN+f6QfK4+9QvBepO2SRtGsMahx6GnTrpkA6b6DK9x mbspSW1z543yqfOXZZGq1bb1/DA2A9B8EE11bWzQtf5xLclbyheuNjRa6ZcTJnGRt7gF EeP3sbGydUqvVSYgNH74LyMY3BLKS2ibsXj3GQtGpGhW9UEdV/MLEV4q4MMDm+khMITI LZ1Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q10si18145957pgm.225.2019.07.25.06.51.56; Thu, 25 Jul 2019 06:52:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729557AbfGYLyx (ORCPT + 99 others); Thu, 25 Jul 2019 07:54:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45362 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726323AbfGYLyw (ORCPT ); Thu, 25 Jul 2019 07:54:52 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C11D78E233; Thu, 25 Jul 2019 11:54:51 +0000 (UTC) Received: from [10.36.117.70] (ovpn-117-70.ams2.redhat.com [10.36.117.70]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5A69260C05; Thu, 25 Jul 2019 11:54:40 +0000 (UTC) Subject: Re: [PATCH v2 4/5] mm: Introduce Hinted pages To: Nitesh Narayan Lal , Alexander Duyck , 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> <227bf405-a924-a8de-3f58-f7799f1ba7a1@redhat.com> From: David Hildenbrand Openpgp: preference=signencrypt Autocrypt: addr=david@redhat.com; prefer-encrypt=mutual; keydata= xsFNBFXLn5EBEAC+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 UucZa4OT27U5ZISjNg3Ev0rxU5UH2/pT4wJCfxwocmqaRr6UYmrtZmND89X0KigoFD/XSeVv jwBRNjPAubK9/k5NoRrYqztM9W6sJqrH8+UWZ1Idd/DdmogJh0gNC0+N42Za9yBRURfIdKSb B3JfpUqcWwE7vUaYrH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2MnQoeXKzD7O4WFbL55hhyGgfWTHwZ457iN9SgYi1JLPqWkZB0JRXIEtjd4JEQcx +8Umfre0Xt4713VxMygW0PnQt5aSQdMD58jHFxTk092mU+yIHj5LeYgvwSgZN4airXk5yRXl SE+xAvmumFBY Organization: Red Hat GmbH Message-ID: Date: Thu, 25 Jul 2019 13:54:39 +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: <227bf405-a924-a8de-3f58-f7799f1ba7a1@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 25 Jul 2019 11:54:52 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 25.07.19 13:46, Nitesh Narayan Lal wrote: > > On 7/25/19 4:53 AM, David Hildenbrand wrote: >> 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. > > Will it not conflict with the regular use case of PG_dirty bit somehow? AFAIK it is primarily used for pagecache pages only, so never with pages in the buddy. Unfortunately, page-flags.h lacks proper documentation. -- Thanks, David / dhildenb