From patchwork Wed Aug 7 22:41:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Duyck X-Patchwork-Id: 11082795 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B0EF31399 for ; Wed, 7 Aug 2019 22:41:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9EDDC28AB8 for ; Wed, 7 Aug 2019 22:41:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 928CC28ABE; Wed, 7 Aug 2019 22:41:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C0AF428AB8 for ; Wed, 7 Aug 2019 22:41:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CB68B6B0006; Wed, 7 Aug 2019 18:41:51 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C671B6B0007; Wed, 7 Aug 2019 18:41:51 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B2E0A6B0008; Wed, 7 Aug 2019 18:41:51 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) by kanga.kvack.org (Postfix) with ESMTP id 7D8D46B0006 for ; Wed, 7 Aug 2019 18:41:51 -0400 (EDT) Received: by mail-pf1-f198.google.com with SMTP id x10so57700260pfa.23 for ; Wed, 07 Aug 2019 15:41:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:subject:from:to:cc:date :message-id:in-reply-to:references:user-agent:mime-version :content-transfer-encoding; bh=8Up9pojviE1H2/TRQbKOgpo0f8QQ8J9T+rPQMo69VKw=; b=AB1U9Ki3Eo2cIz9IPkR7voRpeRayYlnJmyj2+SfbMGEDMyou53cvc9Hwq6TMufHo4e A3lxxkeS7D0Zh4oNnZ4q0rkCgEiS4i0PIdwqlOVBBCCTnOlA3sKmtliy5qH6CdMC8umj h2tkSl4Esb4/N+at6yV4BxbxUMIOHzYqm4Wbl4IAvY3iWw8yS3W41F8c/ipMu7FA0mi6 X2S8psarpHHqaxqfCLpPqLvqmXg3+/8/dyKM1xN4DIovk+mtd/JWyf2LmoAR3cGfRM1X FtxlZZPig+E4YyJYFAcYsqC7/OInmZwOSv+SgICYc5mz1uf/L8n+mZRFvVcukZZec/tq MN9Q== X-Gm-Message-State: APjAAAWGDfBBNQtP8Sy9VTWnCJDtl0aEGoYh8jdOH/ToHX0krrOrSVbx nwMS9Nsw9T5L6QpqN60qdcMJhmvR/ju0tXE3SKvFzOxOzQi0CRE/DZh/haSX3AbFuqFb3q1Ob5O VLVRZN5l1R2pSxV2daVcxAO0I6Cuzr9E1l/lyyGk27lfERGkz/igiqFsKZiPdVTCBsg== X-Received: by 2002:a17:902:bf09:: with SMTP id bi9mr9754639plb.143.1565217711152; Wed, 07 Aug 2019 15:41:51 -0700 (PDT) X-Received: by 2002:a17:902:bf09:: with SMTP id bi9mr9754558plb.143.1565217709640; Wed, 07 Aug 2019 15:41:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565217709; cv=none; d=google.com; s=arc-20160816; b=062vO8CpJR+MHiK03w/akOdKETx1lUCzSywsjpUGK4+v+uE2B6ek7MkwFeB5EI+3VM U4FXWQAuRCCh+3sfG5GwphFx1T4NlL+nq9HoRI3+t/RVKT10TIE/a5/4dvN9iMaCHHTp 1y+O8nmK18o0NsdD3MI8Oh0hT4ojRsJQkm1YV+7e5QhOKh27UW8ox2r5EPSh7+C+FrEv WPq5OTBst1Cb1mHBCtco3k9B/94opb5/CM8Z821ZeivMC3hPNmq3z+lQkN1WVFG7bVL6 egHQXnyNzPHRUW+Iu2Gb3v67sLOHP8TkPqv5/P/WaufEi2GcOxZcAXPd9b6rIxQGpFI9 AjsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:message-id:date:cc:to:from:subject:dkim-signature; bh=8Up9pojviE1H2/TRQbKOgpo0f8QQ8J9T+rPQMo69VKw=; b=gofj2FCCwAs8T+9eWdAQjpdVQAYcGIzzhh55uRd9O0/VgCh4JIrxGhLlxSCoL38h0C 11EVObgeYVEPjfHgnz2yn4doC655gmHxr7zFjCHoPQNlHpkxvXRqgTpygHN6dqULlWis R+n+4VUD83989081kDS8X+RfOqmGCQDMe10CmQsp/4/jj5x/f8LeErWbA6mM1KQV/vUk N5VFA4RHsK8SbMmrMXSDzZRVMnYkHOmPJdkVFjaHAOROEA7TU1WxYJx4Ftyi4LtnGwic gtZh62ds4SjBkkPGNLq6WVqRubqKN6lnnkwFeVLoSB3ZV0xfreTwAcbGvvQOG6+W/KQ7 gaQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=twb1ChdF; spf=pass (google.com: domain of alexander.duyck@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=alexander.duyck@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id 36sor108674244pla.71.2019.08.07.15.41.49 for (Google Transport Security); Wed, 07 Aug 2019 15:41:49 -0700 (PDT) Received-SPF: pass (google.com: domain of alexander.duyck@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=twb1ChdF; spf=pass (google.com: domain of alexander.duyck@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=alexander.duyck@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=8Up9pojviE1H2/TRQbKOgpo0f8QQ8J9T+rPQMo69VKw=; b=twb1ChdF9mm5/SvP8D3BdlAipF9NU/SRUc2oKaJaq2HvxfIMq1sDXROsXi9oqZm0Wp jwxvuvI9hpXnWvy+Di39xcUS3oboVUe6uSLWAnyivbiG40k/p2yfAQTq5U1XB9QAJZt3 1AoKB9PxKn2loUBcQvFKMFRptyxW5ZIm+5FJ6S14sqX72LMuspE37gx8GrOlkQSndkQZ MnRCOnJlyk/mdsSsQO6mDo8Pi0CFSOG6X8oZ8byIE6bgNx294Sl1XJks2/15qJbJjKKF ZgIii5Dh0tn/LFL1v0scJKFSe4n2mOxusG4+qCtQpwoWH3ED5EH2wTWZrJV2k0WwZ2fF +pwA== X-Google-Smtp-Source: APXvYqzJYNarpgUwsZTkESntRvxWWyR0+dg59kN/YLV2Jg+dXU7+K5XQ4gsIwZaf1qs3yMJICG3T8Q== X-Received: by 2002:a17:902:8f93:: with SMTP id z19mr9988466plo.97.1565217709173; Wed, 07 Aug 2019 15:41:49 -0700 (PDT) Received: from localhost.localdomain ([2001:470:b:9c3:9e5c:8eff:fe4f:f2d0]) by smtp.gmail.com with ESMTPSA id h6sm93055440pfb.20.2019.08.07.15.41.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Aug 2019 15:41:48 -0700 (PDT) Subject: [PATCH v4 1/6] mm: Adjust shuffle code to allow for future coalescing From: Alexander Duyck To: nitesh@redhat.com, kvm@vger.kernel.org, david@redhat.com, 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, willy@infradead.org, lcapitulino@redhat.com, wei.w.wang@intel.com, aarcange@redhat.com, pbonzini@redhat.com, dan.j.williams@intel.com, alexander.h.duyck@linux.intel.com Date: Wed, 07 Aug 2019 15:41:47 -0700 Message-ID: <20190807224147.6891.8246.stgit@localhost.localdomain> In-Reply-To: <20190807224037.6891.53512.stgit@localhost.localdomain> References: <20190807224037.6891.53512.stgit@localhost.localdomain> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 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: X-Virus-Scanned: ClamAV using ClamSMTP From: Alexander Duyck This patch is meant to move the head/tail adding logic out of the shuffle code and into the __free_one_page function since ultimately that is where it is really needed anyway. By doing this we should be able to reduce the overhead and can consolidate all of the list addition bits in one spot. Signed-off-by: Alexander Duyck --- include/linux/mmzone.h | 12 -------- mm/page_alloc.c | 70 +++++++++++++++++++++++++++--------------------- mm/shuffle.c | 24 ---------------- mm/shuffle.h | 32 ++++++++++++++++++++++ 4 files changed, 71 insertions(+), 67 deletions(-) diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index aa0dd8ca36c8..c6bd8e9bb476 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -116,18 +116,6 @@ static inline void add_to_free_area_tail(struct page *page, struct free_area *ar area->nr_free++; } -#ifdef CONFIG_SHUFFLE_PAGE_ALLOCATOR -/* Used to preserve page allocation order entropy */ -void add_to_free_area_random(struct page *page, struct free_area *area, - int migratetype); -#else -static inline void add_to_free_area_random(struct page *page, - struct free_area *area, int migratetype) -{ - add_to_free_area(page, area, migratetype); -} -#endif - /* Used for pages which are on another list */ static inline void move_to_free_area(struct page *page, struct free_area *area, int migratetype) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index af29c05e23aa..e3cb6e7aa296 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -877,6 +877,36 @@ static inline struct capture_control *task_capc(struct zone *zone) #endif /* CONFIG_COMPACTION */ /* + * If this is not the largest possible page, check if the buddy + * of the next-highest order is free. If it is, it's possible + * that pages are being freed that will coalesce soon. In case, + * that is happening, add the free page to the tail of the list + * so it's less likely to be used soon and more likely to be merged + * as a higher order page + */ +static inline bool +buddy_merge_likely(unsigned long pfn, unsigned long buddy_pfn, + struct page *page, unsigned int order) +{ + struct page *higher_page, *higher_buddy; + unsigned long combined_pfn; + + if (order >= MAX_ORDER - 2) + return false; + + if (!pfn_valid_within(buddy_pfn)) + return false; + + combined_pfn = buddy_pfn & pfn; + higher_page = page + (combined_pfn - pfn); + buddy_pfn = __find_buddy_pfn(combined_pfn, order + 1); + higher_buddy = higher_page + (buddy_pfn - combined_pfn); + + return pfn_valid_within(buddy_pfn) && + page_is_buddy(higher_page, higher_buddy, order + 1); +} + +/* * Freeing function for a buddy system allocator. * * The concept of a buddy system is to maintain direct-mapped table @@ -905,11 +935,12 @@ static inline void __free_one_page(struct page *page, struct zone *zone, unsigned int order, int migratetype) { - unsigned long combined_pfn; + struct capture_control *capc = task_capc(zone); unsigned long uninitialized_var(buddy_pfn); - struct page *buddy; + unsigned long combined_pfn; + struct free_area *area; unsigned int max_order; - struct capture_control *capc = task_capc(zone); + struct page *buddy; max_order = min_t(unsigned int, MAX_ORDER, pageblock_order + 1); @@ -978,35 +1009,12 @@ static inline void __free_one_page(struct page *page, done_merging: set_page_order(page, order); - /* - * If this is not the largest possible page, check if the buddy - * of the next-highest order is free. If it is, it's possible - * that pages are being freed that will coalesce soon. In case, - * that is happening, add the free page to the tail of the list - * so it's less likely to be used soon and more likely to be merged - * as a higher order page - */ - if ((order < MAX_ORDER-2) && pfn_valid_within(buddy_pfn) - && !is_shuffle_order(order)) { - struct page *higher_page, *higher_buddy; - combined_pfn = buddy_pfn & pfn; - higher_page = page + (combined_pfn - pfn); - buddy_pfn = __find_buddy_pfn(combined_pfn, order + 1); - higher_buddy = higher_page + (buddy_pfn - combined_pfn); - if (pfn_valid_within(buddy_pfn) && - page_is_buddy(higher_page, higher_buddy, order + 1)) { - add_to_free_area_tail(page, &zone->free_area[order], - migratetype); - return; - } - } - - if (is_shuffle_order(order)) - add_to_free_area_random(page, &zone->free_area[order], - migratetype); + area = &zone->free_area[order]; + if (is_shuffle_order(order) ? shuffle_add_to_tail() : + buddy_merge_likely(pfn, buddy_pfn, page, order)) + add_to_free_area_tail(page, area, migratetype); else - add_to_free_area(page, &zone->free_area[order], migratetype); - + add_to_free_area(page, area, migratetype); } /* diff --git a/mm/shuffle.c b/mm/shuffle.c index 3ce12481b1dc..55d592e62526 100644 --- a/mm/shuffle.c +++ b/mm/shuffle.c @@ -4,7 +4,6 @@ #include #include #include -#include #include #include "internal.h" #include "shuffle.h" @@ -182,26 +181,3 @@ void __meminit __shuffle_free_memory(pg_data_t *pgdat) for (z = pgdat->node_zones; z < pgdat->node_zones + MAX_NR_ZONES; z++) shuffle_zone(z); } - -void add_to_free_area_random(struct page *page, struct free_area *area, - int migratetype) -{ - static u64 rand; - static u8 rand_bits; - - /* - * The lack of locking is deliberate. If 2 threads race to - * update the rand state it just adds to the entropy. - */ - if (rand_bits == 0) { - rand_bits = 64; - rand = get_random_u64(); - } - - if (rand & 1) - add_to_free_area(page, area, migratetype); - else - add_to_free_area_tail(page, area, migratetype); - rand_bits--; - rand >>= 1; -} diff --git a/mm/shuffle.h b/mm/shuffle.h index 777a257a0d2f..add763cc0995 100644 --- a/mm/shuffle.h +++ b/mm/shuffle.h @@ -3,6 +3,7 @@ #ifndef _MM_SHUFFLE_H #define _MM_SHUFFLE_H #include +#include /* * SHUFFLE_ENABLE is called from the command line enabling path, or by @@ -43,6 +44,32 @@ static inline bool is_shuffle_order(int order) return false; return order >= SHUFFLE_ORDER; } + +static inline bool shuffle_add_to_tail(void) +{ + static u64 rand; + static u8 rand_bits; + u64 rand_old; + + /* + * The lack of locking is deliberate. If 2 threads race to + * update the rand state it just adds to the entropy. + */ + if (rand_bits-- == 0) { + rand_bits = 64; + rand = get_random_u64(); + } + + /* + * Test highest order bit while shifting our random value. This + * should result in us testing for the carry flag following the + * shift. + */ + rand_old = rand; + rand <<= 1; + + return rand < rand_old; +} #else static inline void shuffle_free_memory(pg_data_t *pgdat) { @@ -60,5 +87,10 @@ static inline bool is_shuffle_order(int order) { return false; } + +static inline bool shuffle_add_to_tail(void) +{ + return false; +} #endif #endif /* _MM_SHUFFLE_H */ From patchwork Wed Aug 7 22:41:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Duyck X-Patchwork-Id: 11082799 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 92D201399 for ; Wed, 7 Aug 2019 22:41:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 823D428ABA for ; Wed, 7 Aug 2019 22:41:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 75FAA28ABE; Wed, 7 Aug 2019 22:41:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F092628ABA for ; Wed, 7 Aug 2019 22:41:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 209196B0007; Wed, 7 Aug 2019 18:41:58 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 1C31A6B0008; Wed, 7 Aug 2019 18:41:58 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0CF066B000A; Wed, 7 Aug 2019 18:41:58 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) by kanga.kvack.org (Postfix) with ESMTP id CA3926B0007 for ; Wed, 7 Aug 2019 18:41:57 -0400 (EDT) Received: by mail-pl1-f197.google.com with SMTP id k9so54284500pls.13 for ; Wed, 07 Aug 2019 15:41:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:subject:from:to:cc:date :message-id:in-reply-to:references:user-agent:mime-version :content-transfer-encoding; bh=gP7k43mJSv5f3YSNOpp9K4LaCXk5lNEqmssvOI0R3mU=; b=r1FSD6ZBf+jXf3TIXg2ZvpnheQtZU8mlObQpqcRJL9c6LE4u667ZQkI1A1IrkI2++N +EkDaMQjJ/Af2ZJJpc+N2ehzwfWGjD14emCaAb8e58aCFsoxEaizx+i9/kiBAt2QS6Y3 wAWiYNnMcyTv3rWU703AEVjzN6bcPG43qWFFzOYkmY93fVR8vAdS9VT3M3i3GIskU8mp ga6sQlT42FIcCovFUOCHvMBXbUlxTxyedWGciRcbky3kReiXVaLpc2bAaZ1HfrQj6+XC KpyvexhV734g5MOgYFWHqlCJ/TUB5NFib7Q4K2LRF0gI9j62Sw+v8YkwUOk8w/QanETG DyFw== X-Gm-Message-State: APjAAAXac5lcmHeAiTZ3q6o9Z20HMT462OuFDrC/1xJq1EOmkRTaNbYc Bkqvvc1GiIyb6ytXHzPw9IkZugcFQktIvyN8ebfyQR4d5/0Hn4TQ0JVf2UuBxhR2L+wi6vb24Wt BlLtmLxbiiBwaysVAMhlXkrrwI2vCvcpXj8ibbM2zgjyNP68GCVW3KwR/8hp1L1bxkQ== X-Received: by 2002:a63:8ac3:: with SMTP id y186mr9733234pgd.13.1565217717305; Wed, 07 Aug 2019 15:41:57 -0700 (PDT) X-Received: by 2002:a63:8ac3:: with SMTP id y186mr9733187pgd.13.1565217716080; Wed, 07 Aug 2019 15:41:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565217716; cv=none; d=google.com; s=arc-20160816; b=wbyw/SfEcjEWbEowCK6inS6MJEgk9hRvqIjGr90w9eam5aZsbMI28WMr0ebQWXMEfT ssZGolxcy53ZJveK+jfKzWYG1sJOjAgeZMU6PYccDuGXitrPVcULD1A+GQ+zaUo+Ot3Q aDTujIRLF4oeSbObpQV2DCr8+BxL2PYZTl/MNTffsNOStHdMd5x6a+kFh6cmDN/qjiAP Uap9ukOvJYfBD0xHS5CP0dSlHLPNps3G74Kp+FkHVisITUCsFMPpBHUd+Eoy6d/cI3No n4soBCa0LgMTunljpJc2HKw+D7j15KoVwwPVQ3njdlSfC7fb1hbOVbhlxuqdOQTQpvCc 22VA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:message-id:date:cc:to:from:subject:dkim-signature; bh=gP7k43mJSv5f3YSNOpp9K4LaCXk5lNEqmssvOI0R3mU=; b=oRA7w9X7+6hLDQot+QlXf1g8lTeNY32A+zRgxCnDuE+nF0NfAEwWEycKLZw3U9psQ4 P87uJuyD7fz0ogZL9f6filncS62SarjgzvOrbBlrcsZdna+AXpB64Br3AqlmfgZyT+Bv a1zFPrHOMhx2if526lNwfxzvdBX0S2S27CH806yiU3md9CMqPYMv22g9yFLf6+5Mh9yW l5M0C/s0CJNha7EwlOr/ELl9WW/pYmRGn4+Gy0M/LLR+D43b3WMMKhU9UXjn/W4GkDOb +V3QyXprJS+pByv6mGtwlttlnhJIb39bVAioU4FcTThvXiHJK4BoLXu2DEAGT5+7JHfQ TWRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=M47wq6oa; spf=pass (google.com: domain of alexander.duyck@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=alexander.duyck@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id a6sor44964238pgt.14.2019.08.07.15.41.55 for (Google Transport Security); Wed, 07 Aug 2019 15:41:56 -0700 (PDT) Received-SPF: pass (google.com: domain of alexander.duyck@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=M47wq6oa; spf=pass (google.com: domain of alexander.duyck@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=alexander.duyck@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=gP7k43mJSv5f3YSNOpp9K4LaCXk5lNEqmssvOI0R3mU=; b=M47wq6oaadwL5mKkByQrptrnOULI9VDmL0/6L+92fOzfVvfitjC/ElFoAnWigW6Tgl 2BH+ULIYowkwt5Hra57TrApc83fuelgXBZL+tmKfGBj6Y3DLb7RmXg85Th88SRjxi/k6 TfW4pMsajAECj1ptU2TDe/SNHCHtERvlsBgXaRyx/NIKpv1HlsNIIm8klzHtptg4KiAJ jvM5DgvkZSawumIhfZwbBoqk+Z9YLeG36U2JqC4FPSXlD5VjeyMI7yHlnv9J64LCuUO+ sBW0JPMMK8sjF5cZxgEemkrTFFuMEQENWnSKtZQPgOUbzPCV7zCmtK+6VxwlUyc6tk4A Is0g== X-Google-Smtp-Source: APXvYqw7+iGCoVEpaok0NeV0fhf636bWennC5o7JVfoBsRlCRu3ykru0N0YOA2U0+OillUts6lvxTA== X-Received: by 2002:a63:3147:: with SMTP id x68mr10013656pgx.212.1565217715594; Wed, 07 Aug 2019 15:41:55 -0700 (PDT) Received: from localhost.localdomain ([2001:470:b:9c3:9e5c:8eff:fe4f:f2d0]) by smtp.gmail.com with ESMTPSA id a6sm209209pjs.31.2019.08.07.15.41.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Aug 2019 15:41:55 -0700 (PDT) Subject: [PATCH v4 2/6] mm: Move set/get_pcppage_migratetype to mmzone.h From: Alexander Duyck To: nitesh@redhat.com, kvm@vger.kernel.org, david@redhat.com, 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, willy@infradead.org, lcapitulino@redhat.com, wei.w.wang@intel.com, aarcange@redhat.com, pbonzini@redhat.com, dan.j.williams@intel.com, alexander.h.duyck@linux.intel.com Date: Wed, 07 Aug 2019 15:41:54 -0700 Message-ID: <20190807224154.6891.29107.stgit@localhost.localdomain> In-Reply-To: <20190807224037.6891.53512.stgit@localhost.localdomain> References: <20190807224037.6891.53512.stgit@localhost.localdomain> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 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: X-Virus-Scanned: ClamAV using ClamSMTP From: Alexander Duyck In order to support page reporting it will be necessary to store and retrieve the migratetype of a page. To enable that I am moving the set and get operations for pcppage_migratetype into the mm/internal.h header so that they can be used outside of the page_alloc.c file. Signed-off-by: Alexander Duyck --- mm/internal.h | 18 ++++++++++++++++++ mm/page_alloc.c | 18 ------------------ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/mm/internal.h b/mm/internal.h index 0d5f720c75ab..e4a1a57bbd40 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -549,6 +549,24 @@ static inline bool is_migrate_highatomic_page(struct page *page) return get_pageblock_migratetype(page) == MIGRATE_HIGHATOMIC; } +/* + * A cached value of the page's pageblock's migratetype, used when the page is + * put on a pcplist. Used to avoid the pageblock migratetype lookup when + * freeing from pcplists in most cases, at the cost of possibly becoming stale. + * Also the migratetype set in the page does not necessarily match the pcplist + * index, e.g. page might have MIGRATE_CMA set but be on a pcplist with any + * other index - this ensures that it will be put on the correct CMA freelist. + */ +static inline int get_pcppage_migratetype(struct page *page) +{ + return page->index; +} + +static inline void set_pcppage_migratetype(struct page *page, int migratetype) +{ + page->index = migratetype; +} + void setup_zone_pageset(struct zone *zone); extern struct page *alloc_new_node_page(struct page *page, unsigned long node); #endif /* __MM_INTERNAL_H */ diff --git a/mm/page_alloc.c b/mm/page_alloc.c index e3cb6e7aa296..f04192f5ec3c 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -185,24 +185,6 @@ static int __init early_init_on_free(char *buf) } early_param("init_on_free", early_init_on_free); -/* - * A cached value of the page's pageblock's migratetype, used when the page is - * put on a pcplist. Used to avoid the pageblock migratetype lookup when - * freeing from pcplists in most cases, at the cost of possibly becoming stale. - * Also the migratetype set in the page does not necessarily match the pcplist - * index, e.g. page might have MIGRATE_CMA set but be on a pcplist with any - * other index - this ensures that it will be put on the correct CMA freelist. - */ -static inline int get_pcppage_migratetype(struct page *page) -{ - return page->index; -} - -static inline void set_pcppage_migratetype(struct page *page, int migratetype) -{ - page->index = migratetype; -} - #ifdef CONFIG_PM_SLEEP /* * The following functions are used by the suspend/hibernate code to temporarily From patchwork Wed Aug 7 22:42:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Duyck X-Patchwork-Id: 11082803 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E73DE1399 for ; Wed, 7 Aug 2019 22:42:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D6DB028AB8 for ; Wed, 7 Aug 2019 22:42:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CA2F928ABC; Wed, 7 Aug 2019 22:42:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EE98F28AB8 for ; Wed, 7 Aug 2019 22:42:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0F8056B0008; Wed, 7 Aug 2019 18:42:04 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 0A8636B000A; Wed, 7 Aug 2019 18:42:04 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E3C586B000C; Wed, 7 Aug 2019 18:42:03 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f200.google.com (mail-pf1-f200.google.com [209.85.210.200]) by kanga.kvack.org (Postfix) with ESMTP id A93946B0008 for ; Wed, 7 Aug 2019 18:42:03 -0400 (EDT) Received: by mail-pf1-f200.google.com with SMTP id q14so57708209pff.8 for ; Wed, 07 Aug 2019 15:42:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:subject:from:to:cc:date :message-id:in-reply-to:references:user-agent:mime-version :content-transfer-encoding; bh=poWy5H00eMbbkhDbizAoNp/mHsmKg4j5qADSq+zADLA=; b=mo0xu3n82nglhY+PmLZ3YbdycC1mr/vIzCFYpzKK4jYExQQwNXbh8LlH7lcUzImwXo ejk9y9lPUId7B020Qj/Qu4cBgMu6JoqKACndoDyVyhtAoYZtL9OtSw/VcvHtVKTvStkL bTOVNSRjjRfxO7xFT3yBbA3hVfhUJO9NGO0Om8Jxb5Nrx6w04xrYMmcknoBPg0KdgD/4 Hal5Q+Bq6BoOf/PwtJnX28NyZLweDuaOmESayR8NwkFjK5GOwNK4tmHemC2poJZHC92K CrLwJQe1AIUjvm5qVueRi+RgrfClcapXZ1X+rV2NIwUX1QQ3DEWtI8UwoCk/QaR25fHL KeLA== X-Gm-Message-State: APjAAAUup8U3OYtnAKWIlnapK/1ixNo4VbbgWwtyIWwnFxhMbpNbZcMf zJXIg1zZN5+xY8uuBxj82al/Obkxl+AKAxqLT93XhaR/Au84Mz4fmZnIOBTLTqcR0ksTbcLOfGv /WFOgKVyg6hDnjV89XaPhvG7rgNrKbj15wECnCCZySWC2Vh7bQp7B39UAm/iv/uBq/A== X-Received: by 2002:a65:64cf:: with SMTP id t15mr9503713pgv.88.1565217723283; Wed, 07 Aug 2019 15:42:03 -0700 (PDT) X-Received: by 2002:a65:64cf:: with SMTP id t15mr9503659pgv.88.1565217722228; Wed, 07 Aug 2019 15:42:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565217722; cv=none; d=google.com; s=arc-20160816; b=ZWSn5/kqJ31lKVNeqMqtqArXbdhJPkYaURYa4Ba+/eNdsZL3cqzwUyS6zePTBgxgFW hrgnsNdWSZluOFPfYRcxoGsLQO5KouvZhCnORSJc8/Ng15NWMBUjFwV7Z/qLbf0OwN7+ aK9h/FzwOWJDTGWJh74JsexzutB6x/i6KGk+esFQmXkGrlA+e6pgydzNsbQf8tVnQWFB nZiRs5I+tbqN5A25Lvh9pLauoigyohmDogClTwptPwRSfcpq3x2yI4z7s728z+I/vSsT EyVhBuKorRyG9E6FkO8m2JSm2lxymdtPRJlUWX+u258WJdNMOOzK6w4vuxO7pbtPf7Ve FzuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:message-id:date:cc:to:from:subject:dkim-signature; bh=poWy5H00eMbbkhDbizAoNp/mHsmKg4j5qADSq+zADLA=; b=iWBLBkPYVpf5eFqcThCzVdiHj+tLgmXTw/Pg9FPUT0RzhFsRiJQ0fZ+ImPa/kMjytf LRZ2r2u7EbfH2CCnCpjYHtPe+QWv06G+gZCbV9TMhazNSI4pPjUPJEd3QJHs8x3Y+5BU jhjNirwDtg73EoZJ2jOO3U94OxO5JAVei5R4ISTM9YSpSPk6Fhv24pCHTzHrhDNY7ofq DW1LlK6/XGEVUEIVRnPiJiehu/xUrUc1wld3T1V3hRfxKCm8OtnfxPpKdYZKr/7zS7Z4 sO91Lu5V6Gm3cI1wbWdyMsgfFndEcY0lTGsvnq1fqxYnETPpjx6JZHlyqfq+cRFN+6xt Is2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=g6hBF2r7; spf=pass (google.com: domain of alexander.duyck@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=alexander.duyck@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id h63sor520608pjb.6.2019.08.07.15.42.02 for (Google Transport Security); Wed, 07 Aug 2019 15:42:02 -0700 (PDT) Received-SPF: pass (google.com: domain of alexander.duyck@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=g6hBF2r7; spf=pass (google.com: domain of alexander.duyck@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=alexander.duyck@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=poWy5H00eMbbkhDbizAoNp/mHsmKg4j5qADSq+zADLA=; b=g6hBF2r7WDPHrgJhy1vmfJ9sEalu/lSmYgmQ7s3RlTRFadjUuZSww8JvgzL+ULhoNk p9DHTuPoVndY8HxqUsRV9hKFUsXqXIx+BOPo07E7hpw85yFttrHzVr7hTJoXVPdo8Ipz 2I0WQI1bA26dcfLA7v5a45wDwnGiEO6FPre8VYY/rdKcD5OVXugi2yVZJPuz+foJ4TTu gCKAro4LzGV1ahasd3xiiG8kxY3KlmGGwcO3gb8I6Sb1IWXy14uIdxQmvGP+30iK4CWP zTYkTTEzIiPBD56QjlCipO/lolXia5FPWWvstXbrmT3DKS2eJ1Q5Vidt3Sn+yL9pOOtr BWKQ== X-Google-Smtp-Source: APXvYqybauW2gI30Xi6XqcAdulH2GVOgYW3VwFTSqW0neJAGQv4mWsFCIkkDEXI5yU/IpmqLkkiYkA== X-Received: by 2002:a17:90a:5887:: with SMTP id j7mr725275pji.136.1565217721744; Wed, 07 Aug 2019 15:42:01 -0700 (PDT) Received: from localhost.localdomain ([2001:470:b:9c3:9e5c:8eff:fe4f:f2d0]) by smtp.gmail.com with ESMTPSA id o95sm242201pjb.4.2019.08.07.15.42.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Aug 2019 15:42:01 -0700 (PDT) Subject: [PATCH v4 3/6] mm: Use zone and order instead of free area in free_list manipulators From: Alexander Duyck To: nitesh@redhat.com, kvm@vger.kernel.org, david@redhat.com, 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, willy@infradead.org, lcapitulino@redhat.com, wei.w.wang@intel.com, aarcange@redhat.com, pbonzini@redhat.com, dan.j.williams@intel.com, alexander.h.duyck@linux.intel.com Date: Wed, 07 Aug 2019 15:42:00 -0700 Message-ID: <20190807224200.6891.69731.stgit@localhost.localdomain> In-Reply-To: <20190807224037.6891.53512.stgit@localhost.localdomain> References: <20190807224037.6891.53512.stgit@localhost.localdomain> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 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: X-Virus-Scanned: ClamAV using ClamSMTP From: Alexander Duyck In order to enable the use of the zone from the list manipulator functions I will need access to the zone pointer. As it turns out most of the accessors were always just being directly passed &zone->free_area[order] anyway so it would make sense to just fold that into the function itself and pass the zone and order as arguments instead of the free area. In order to be able to reference the zone we need to move the declaration of the functions down so that we have the zone defined before we define the list manipulation functions. Signed-off-by: Alexander Duyck --- include/linux/mmzone.h | 70 ++++++++++++++++++++++++++---------------------- mm/page_alloc.c | 30 ++++++++------------- 2 files changed, 49 insertions(+), 51 deletions(-) diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index c6bd8e9bb476..2f2b6f968ed3 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -100,29 +100,6 @@ struct free_area { unsigned long nr_free; }; -/* Used for pages not on another list */ -static inline void add_to_free_area(struct page *page, struct free_area *area, - int migratetype) -{ - list_add(&page->lru, &area->free_list[migratetype]); - area->nr_free++; -} - -/* Used for pages not on another list */ -static inline void add_to_free_area_tail(struct page *page, struct free_area *area, - int migratetype) -{ - list_add_tail(&page->lru, &area->free_list[migratetype]); - area->nr_free++; -} - -/* Used for pages which are on another list */ -static inline void move_to_free_area(struct page *page, struct free_area *area, - int migratetype) -{ - list_move(&page->lru, &area->free_list[migratetype]); -} - static inline struct page *get_page_from_free_area(struct free_area *area, int migratetype) { @@ -130,15 +107,6 @@ static inline struct page *get_page_from_free_area(struct free_area *area, struct page, lru); } -static inline void del_page_from_free_area(struct page *page, - struct free_area *area) -{ - list_del(&page->lru); - __ClearPageBuddy(page); - set_page_private(page, 0); - area->nr_free--; -} - static inline bool free_area_empty(struct free_area *area, int migratetype) { return list_empty(&area->free_list[migratetype]); @@ -789,6 +757,44 @@ static inline bool pgdat_is_empty(pg_data_t *pgdat) return !pgdat->node_start_pfn && !pgdat->node_spanned_pages; } +/* 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) +{ + struct free_area *area = &zone->free_area[order]; + + list_add(&page->lru, &area->free_list[migratetype]); + area->nr_free++; +} + +/* Used for pages not on another list */ +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]; + + list_add_tail(&page->lru, &area->free_list[migratetype]); + area->nr_free++; +} + +/* Used for pages which are on another list */ +static inline void move_to_free_list(struct page *page, struct zone *zone, + unsigned int order, int migratetype) +{ + struct free_area *area = &zone->free_area[order]; + + 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) +{ + list_del(&page->lru); + __ClearPageBuddy(page); + set_page_private(page, 0); + zone->free_area[order].nr_free--; +} + #include void build_all_zonelists(pg_data_t *pgdat); diff --git a/mm/page_alloc.c b/mm/page_alloc.c index f04192f5ec3c..4b5812c3800e 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -920,7 +920,6 @@ static inline void __free_one_page(struct page *page, struct capture_control *capc = task_capc(zone); unsigned long uninitialized_var(buddy_pfn); unsigned long combined_pfn; - struct free_area *area; unsigned int max_order; struct page *buddy; @@ -957,7 +956,7 @@ static inline void __free_one_page(struct page *page, if (page_is_guard(buddy)) clear_page_guard(zone, buddy, order, migratetype); else - del_page_from_free_area(buddy, &zone->free_area[order]); + del_page_from_free_list(buddy, zone, order); combined_pfn = buddy_pfn & pfn; page = page + (combined_pfn - pfn); pfn = combined_pfn; @@ -991,12 +990,11 @@ static inline void __free_one_page(struct page *page, done_merging: set_page_order(page, order); - area = &zone->free_area[order]; if (is_shuffle_order(order) ? shuffle_add_to_tail() : buddy_merge_likely(pfn, buddy_pfn, page, order)) - add_to_free_area_tail(page, area, migratetype); + add_to_free_list_tail(page, zone, order, migratetype); else - add_to_free_area(page, area, migratetype); + add_to_free_list(page, zone, order, migratetype); } /* @@ -2000,13 +1998,11 @@ void __init init_cma_reserved_pageblock(struct page *page) * -- nyc */ static inline void expand(struct zone *zone, struct page *page, - int low, int high, struct free_area *area, - int migratetype) + int low, int high, int migratetype) { unsigned long size = 1 << high; while (high > low) { - area--; high--; size >>= 1; VM_BUG_ON_PAGE(bad_range(zone, &page[size]), &page[size]); @@ -2020,7 +2016,7 @@ static inline void expand(struct zone *zone, struct page *page, if (set_page_guard(zone, &page[size], high, migratetype)) continue; - add_to_free_area(&page[size], area, migratetype); + add_to_free_list(&page[size], zone, high, migratetype); set_page_order(&page[size], high); } } @@ -2178,8 +2174,8 @@ struct page *__rmqueue_smallest(struct zone *zone, unsigned int order, page = get_page_from_free_area(area, migratetype); if (!page) continue; - del_page_from_free_area(page, area); - expand(zone, page, order, current_order, area, migratetype); + del_page_from_free_list(page, zone, current_order); + expand(zone, page, order, current_order, migratetype); set_pcppage_migratetype(page, migratetype); return page; } @@ -2187,7 +2183,6 @@ struct page *__rmqueue_smallest(struct zone *zone, unsigned int order, return NULL; } - /* * This array describes the order lists are fallen back to when * the free lists for the desirable migrate type are depleted @@ -2264,7 +2259,7 @@ static int move_freepages(struct zone *zone, } order = page_order(page); - move_to_free_area(page, &zone->free_area[order], migratetype); + move_to_free_list(page, zone, order, migratetype); page += 1 << order; pages_moved += 1 << order; } @@ -2380,7 +2375,6 @@ static void steal_suitable_fallback(struct zone *zone, struct page *page, unsigned int alloc_flags, int start_type, bool whole_block) { unsigned int current_order = page_order(page); - struct free_area *area; int free_pages, movable_pages, alike_pages; int old_block_type; @@ -2451,8 +2445,7 @@ static void steal_suitable_fallback(struct zone *zone, struct page *page, return; single_page: - area = &zone->free_area[current_order]; - move_to_free_area(page, area, start_type); + move_to_free_list(page, zone, current_order, start_type); } /* @@ -3123,7 +3116,6 @@ void split_page(struct page *page, unsigned int order) int __isolate_free_page(struct page *page, unsigned int order) { - struct free_area *area = &page_zone(page)->free_area[order]; unsigned long watermark; struct zone *zone; int mt; @@ -3149,7 +3141,7 @@ int __isolate_free_page(struct page *page, unsigned int order) /* Remove page from free list */ - del_page_from_free_area(page, area); + del_page_from_free_list(page, zone, order); /* * Set the pageblock if the isolated page is at least half of a @@ -8568,7 +8560,7 @@ void zone_pcp_reset(struct zone *zone) pr_info("remove from free list %lx %d %lx\n", pfn, 1 << order, end_pfn); #endif - del_page_from_free_area(page, &zone->free_area[order]); + del_page_from_free_list(page, zone, order); for (i = 0; i < (1 << order); i++) SetPageReserved((page+i)); pfn += (1 << order); From patchwork Wed Aug 7 22:42:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Duyck X-Patchwork-Id: 11082807 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7C3B614DB for ; Wed, 7 Aug 2019 22:42:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6888728AB8 for ; Wed, 7 Aug 2019 22:42:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5BEA628ABC; Wed, 7 Aug 2019 22:42:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7A5C228ABA for ; Wed, 7 Aug 2019 22:42:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 86FC16B000A; Wed, 7 Aug 2019 18:42:11 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 820BD6B000C; Wed, 7 Aug 2019 18:42:11 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6E8FC6B000D; Wed, 7 Aug 2019 18:42:11 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) by kanga.kvack.org (Postfix) with ESMTP id 260626B000A for ; Wed, 7 Aug 2019 18:42:11 -0400 (EDT) Received: by mail-pf1-f199.google.com with SMTP id j22so57627445pfe.11 for ; Wed, 07 Aug 2019 15:42:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:subject:from:to:cc:date :message-id:in-reply-to:references:user-agent:mime-version :content-transfer-encoding; bh=mZ+HvfXGt3zJGdKV/fUhhBovj4E4lx8QREB1CVpLNH8=; b=aJuFKcEItDIFDUT4UsHXg5pg3gDBAxhgHDbhaNLUAO6m1+EYkzu5HN3Bc0oProhCbY 5bn/MlHLcwLuA/BmBsShPRD3/uXPh8ZEv72bu7qs93BVSXIu1D9TGQSKFh9Ai1sri9Y3 CLoBnOwETye3gkTFRKbcX55QkoM3UMk+Gr4WpPABt7lTlGb90BGUeNI9sGcryoiPszky sROTBEaTPyYhna+N7w+C/meYgpoV88j0eyfF3kxaojtn1Tn0RIYwkwwYqZPa2wlHGrCr Boil9Ji/P/X/AFKVR90KgMUMHXZW6hc7kD54DAVqejn/spXMm+neO2OfX3Y6ZUUoeG7j oLQQ== X-Gm-Message-State: APjAAAW2n4aAJljIb5MpkJJOOMUQEjLpyhDq9UFkN/KlVUgfzZyKY37o KMpY5v528oAmJz1AdoTC2BfGz4JCnyFGcml/d+9pEv6H5yZC0xHTRSwZJS9DB2rctot1a/s9PZc GAmqOssbARWuMfTu0jCWhEK9JsUzvZKk1hl0p11fc08RqzjT/bZMV+bIluwH4ivgK+w== X-Received: by 2002:aa7:84d4:: with SMTP id x20mr11740051pfn.60.1565217730681; Wed, 07 Aug 2019 15:42:10 -0700 (PDT) X-Received: by 2002:aa7:84d4:: with SMTP id x20mr11739930pfn.60.1565217728694; Wed, 07 Aug 2019 15:42:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565217728; cv=none; d=google.com; s=arc-20160816; b=ooWzir1dyK04CQwAo1GDIva0AwedyEK+bZWZ09S+WuvMhtnzw5tZ3oyxHNp+I267Rm piN0nws8Kn+oBixcZJ8vXGi2R84vvCvvmk0eJWnaaMrVxabYolrWx/cvVVY0cWdB4SQY b0Kaj/ivxT8dld90iPnfU5cdjPhgbBmu+UAPRFvu4uAxsbJ2J4IkP9ea9SjfEBQ5SOn7 zuko9TFnF4C/PHWF0a+YiHoWWC/+CgECjMAKdW8kFwhoHVqGIIvE16t82Rq4fz9oz/Ih MvsLaolGUWz6mxl/E3rMToMCCcUklABIz3yyqdV5V+CplfXchQsc06nEny1SqiTxyQTs k2LA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:message-id:date:cc:to:from:subject:dkim-signature; bh=mZ+HvfXGt3zJGdKV/fUhhBovj4E4lx8QREB1CVpLNH8=; b=JWJUZXhD/hhOW2jNNIYAswE6pAYWdsVEyokXKpKncOCnPt1G8HWFN6lR5Zz14DGlu+ XWRTR84WBLqdTQEd6aK/dWqcRduRLBm1VDNK0L7mxuXGXVcIt90C5dBp4hF2gUQve6sy N0PKauD009NUZaT8vcJlFeMSsI8FIsC+CGdC1c4a8PgDBdxFiDsCHVdV9JScIfLTPkvL Ny4iAf2ZZf0PkC7th3H/7a/bz0Bhu1KdpuRl4GdFpt6ZZDWIX71GTv9ZQkqiWM91+uiD jMFOuA1kHyGJqN/98LkI1S30kXPwyq9u/z7a3FOOPwGnuH3Q+I7rbwTOlIO7vpk/yP1g b3qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=l6edgr2Y; spf=pass (google.com: domain of alexander.duyck@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=alexander.duyck@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id k6sor65723916pgs.79.2019.08.07.15.42.08 for (Google Transport Security); Wed, 07 Aug 2019 15:42:08 -0700 (PDT) Received-SPF: pass (google.com: domain of alexander.duyck@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=l6edgr2Y; spf=pass (google.com: domain of alexander.duyck@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=alexander.duyck@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=mZ+HvfXGt3zJGdKV/fUhhBovj4E4lx8QREB1CVpLNH8=; b=l6edgr2Y1dRUsKqhfqlpBj5zDukKkPJon+0ltCQgYeety1kyc1OlSf6kdcWnvRxWKw Nemw1tT0mzmz/6ABResOyMgJYQtLyEAmvZ8ge9FGOlm3gkRnRZV/t2/8xylQE7utyt7W kZSEVoNOeZbHBYvN+KEFEuYbRmqd8vScR8ZtxQjrxlhylL5ytqEHKVeD22xaFV3vhO9y KcXMOmKfbFFOvqD500J8NLekAX5g1/+KZpH64Ja6iYYrZlCBWgbQtBN4Svw5LWFlnFJa jjO0EumGvQJUgwA0MYzQ3KCSTikoYisHSArHHs7gdF++IDWj4R8LzYklOZ5OMMUGx2NX BgPg== X-Google-Smtp-Source: APXvYqyKx00wvNrTxwcHaKz74w1VTx47gNJNM+U4t3pVO73dR/ouYCxvEGZMWV3KY1sa0wjY/ubZaQ== X-Received: by 2002:a65:620a:: with SMTP id d10mr9653726pgv.8.1565217727931; Wed, 07 Aug 2019 15:42:07 -0700 (PDT) Received: from localhost.localdomain ([2001:470:b:9c3:9e5c:8eff:fe4f:f2d0]) by smtp.gmail.com with ESMTPSA id l26sm109379404pgb.90.2019.08.07.15.42.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Aug 2019 15:42:07 -0700 (PDT) Subject: [PATCH v4 4/6] mm: Introduce Reported pages From: Alexander Duyck To: nitesh@redhat.com, kvm@vger.kernel.org, david@redhat.com, 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, willy@infradead.org, lcapitulino@redhat.com, wei.w.wang@intel.com, aarcange@redhat.com, pbonzini@redhat.com, dan.j.williams@intel.com, alexander.h.duyck@linux.intel.com Date: Wed, 07 Aug 2019 15:42:06 -0700 Message-ID: <20190807224206.6891.81215.stgit@localhost.localdomain> In-Reply-To: <20190807224037.6891.53512.stgit@localhost.localdomain> References: <20190807224037.6891.53512.stgit@localhost.localdomain> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 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: X-Virus-Scanned: ClamAV using ClamSMTP From: Alexander Duyck In order to pave the way for free page reporting 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 Reported Buddy, which is essentially meant to just be the Uptodate flag 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 unreported and reported 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 reporting 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 reported 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 reports 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 reported pages that were likely evicted from the guest memory. Since we will only be reporting one zone at a time we keep the boundary limited to being defined for just the zone we are currently reporting pages from. 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 reporting and the boundaries are active. The determination of when to start reporting is based on the tracking of the number of free pages in a given area versus the number of reported pages in that area. We keep track of the number of reported 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 | 11 + include/linux/page_reporting.h | 138 ++++++++++++++++++ mm/Kconfig | 5 + mm/Makefile | 1 mm/memory_hotplug.c | 1 mm/page_alloc.c | 136 +++++++++++++++++ mm/page_reporting.c | 313 ++++++++++++++++++++++++++++++++++++++++ 8 files changed, 637 insertions(+), 8 deletions(-) create mode 100644 include/linux/page_reporting.h create mode 100644 mm/page_reporting.c diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index 2f2b6f968ed3..b8ed926552b1 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -462,6 +462,14 @@ struct zone { seqlock_t span_seqlock; #endif +#ifdef CONFIG_PAGE_REPORTING + /* + * Pointer to reported page tracking statistics array. The size of + * the array is MAX_ORDER - PAGE_REPORTING_MIN_ORDER. NULL when + * unused page reporting is not present. + */ + unsigned long *reported_pages; +#endif int initialized; /* Write-intensive fields used from the page allocator */ @@ -537,6 +545,14 @@ enum zone_flags { ZONE_BOOSTED_WATERMARK, /* zone recently boosted watermarks. * Cleared when kswapd is woken. */ + ZONE_PAGE_REPORTING_REQUESTED, /* zone enabled page reporting and has + * requested flushing the data out of + * higher order pages. + */ + ZONE_PAGE_REPORTING_ACTIVE, /* zone enabled page reporting and is + * activly flushing the data out of + * higher order pages. + */ }; static inline unsigned long zone_managed_pages(struct zone *zone) @@ -757,6 +773,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) @@ -771,10 +789,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_unreported_tail(zone, order, migratetype); - list_add_tail(&page->lru, &area->free_list[migratetype]); - area->nr_free++; + /* + * To prevent the unreported pages from being interleaved with the + * reported ones while we are actively processing pages we will use + * the head of the reported 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 */ @@ -783,12 +807,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 reported pages + * at the top of the free_list. It is cheaper to just process this + * page again than to walk around a page that is already reported. + */ + clear_page_reported(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 Reported flag, if present, before resetting page type */ + clear_page_reported(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 f91cb8898ff0..759a3b3956f2 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -163,6 +163,9 @@ enum pageflags { /* non-lru isolated movable page */ PG_isolated = PG_reclaim, + + /* Buddy pages. Used to track which pages have been reported */ + PG_reported = PG_uptodate, }; #ifndef __GENERATING_BOUNDS_H @@ -432,6 +435,14 @@ static inline bool set_hwpoison_free_buddy_page(struct page *page) #endif /* + * PageReported() is used to track reported free pages within the Buddy + * allocator. We can use the non-atomic version of the test and set + * operations as both should be shielded with the zone lock to prevent + * any possible races on the setting or clearing of the bit. + */ +__PAGEFLAG(Reported, reported, PF_NO_COMPOUND) + +/* * On an anonymous page mapped into a user virtual memory area, * page->mapping points to its anon_vma, not to a struct address_space; * with the PAGE_MAPPING_ANON bit set to distinguish it. See rmap.h. diff --git a/include/linux/page_reporting.h b/include/linux/page_reporting.h new file mode 100644 index 000000000000..498bde6ea764 --- /dev/null +++ b/include/linux/page_reporting.h @@ -0,0 +1,138 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_PAGE_REPORTING_H +#define _LINUX_PAGE_REPORTING_H + +#include +#include +#include +#include + +#define PAGE_REPORTING_MIN_ORDER pageblock_order +#define PAGE_REPORTING_HWM 32 + +#ifdef CONFIG_PAGE_REPORTING +struct page_reporting_dev_info { + /* function that alters pages to make them "reported" */ + void (*report)(struct page_reporting_dev_info *phdev, + unsigned int nents); + + /* scatterlist containing pages to be processed */ + struct scatterlist *sg; + + /* + * Upper limit on the number of pages that the react function + * expects to be placed into the batch list to be processed. + */ + unsigned long capacity; + + /* work struct for processing reports */ + struct delayed_work work; + + /* + * The number of zones requesting reporting, plus one additional if + * processing thread is active. + */ + atomic_t refcnt; +}; + +extern struct static_key page_reporting_notify_enabled; + +/* Boundary functions */ +struct list_head *__page_reporting_get_boundary(unsigned int order, + int migratetype); +void page_reporting_del_from_boundary(struct page *page, struct zone *zone); +void page_reporting_add_to_boundary(struct page *page, struct zone *zone, + int migratetype); + +/* Hinted page accessors, defined in page_alloc.c */ +struct page *get_unreported_page(struct zone *zone, unsigned int order, + int migratetype); +void put_reported_page(struct zone *zone, struct page *page); + +void __page_reporting_request(struct zone *zone); +void __page_reporting_free_stats(struct zone *zone); + +/* Tear-down and bring-up for page reporting devices */ +void page_reporting_shutdown(struct page_reporting_dev_info *phdev); +int page_reporting_startup(struct page_reporting_dev_info *phdev); +#endif /* CONFIG_PAGE_REPORTING */ + +static inline struct list_head * +get_unreported_tail(struct zone *zone, unsigned int order, int migratetype) +{ +#ifdef CONFIG_PAGE_REPORTING + if (order >= PAGE_REPORTING_MIN_ORDER && + test_bit(ZONE_PAGE_REPORTING_ACTIVE, &zone->flags)) + return __page_reporting_get_boundary(order, migratetype); +#endif + return &zone->free_area[order].free_list[migratetype]; +} + +static inline void clear_page_reported(struct page *page, + struct zone *zone) +{ +#ifdef CONFIG_PAGE_REPORTING + if (likely(!PageReported(page))) + return; + + /* push boundary back if we removed the upper boundary */ + if (test_bit(ZONE_PAGE_REPORTING_ACTIVE, &zone->flags)) + page_reporting_del_from_boundary(page, zone); + + __ClearPageReported(page); + + /* page_private will contain the page order, so just use it directly */ + zone->reported_pages[page_private(page) - PAGE_REPORTING_MIN_ORDER]--; +#endif +} + +/* Free reported_pages and reset reported page tracking count to 0 */ +static inline void page_reporting_reset(struct zone *zone) +{ +#ifdef CONFIG_PAGE_REPORTING + if (zone->reported_pages) + __page_reporting_free_stats(zone); +#endif +} + +/** + * page_reporting_notify_free - Free page notification to start page processing + * @zone: Pointer to current zone of last page processed + * @order: Order of last page added to zone + * + * This function is meant to act as a screener for __page_reporting_request + * which will determine if a give zone has crossed over the high-water mark + * that will justify us beginning page treatment. If we have crossed that + * threshold then it will start the process of pulling some pages and + * placing them in the batch list for treatment. + */ +static inline void page_reporting_notify_free(struct zone *zone, int order) +{ +#ifdef CONFIG_PAGE_REPORTING + unsigned long nr_reported; + + /* Called from hot path in __free_one_page() */ + if (!static_key_false(&page_reporting_notify_enabled)) + return; + + /* Limit notifications only to higher order pages */ + if (order < PAGE_REPORTING_MIN_ORDER) + return; + + /* Do not bother with tests if we have already requested reporting */ + if (test_bit(ZONE_PAGE_REPORTING_REQUESTED, &zone->flags)) + return; + + /* If reported_pages is not populated, assume 0 */ + nr_reported = zone->reported_pages ? + zone->reported_pages[order - PAGE_REPORTING_MIN_ORDER] : 0; + + /* Only request it if we have enough to begin the page reporting */ + if (zone->free_area[order].nr_free < nr_reported + PAGE_REPORTING_HWM) + return; + + /* This is slow, but should be called very rarely */ + __page_reporting_request(zone); +#endif +} +#endif /*_LINUX_PAGE_REPORTING_H */ diff --git a/mm/Kconfig b/mm/Kconfig index 06f758786e4a..52c6c49f0f69 100644 --- a/mm/Kconfig +++ b/mm/Kconfig @@ -237,6 +237,11 @@ config COMPACTION linux-mm@kvack.org. # +# support for unused page reporting +config PAGE_REPORTING + bool + +# # support for page migration # config MIGRATION diff --git a/mm/Makefile b/mm/Makefile index d0b295c3b764..1e17ba0ed2f0 100644 --- a/mm/Makefile +++ b/mm/Makefile @@ -105,3 +105,4 @@ obj-$(CONFIG_PERCPU_STATS) += percpu-stats.o obj-$(CONFIG_ZONE_DEVICE) += memremap.o obj-$(CONFIG_HMM_MIRROR) += hmm.o obj-$(CONFIG_MEMFD_CREATE) += memfd.o +obj-$(CONFIG_PAGE_REPORTING) += page_reporting.o diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 5b8811945bbb..bd40beac293b 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1612,6 +1612,7 @@ static int __ref __offline_pages(unsigned long start_pfn, if (!populated_zone(zone)) { zone_pcp_reset(zone); build_all_zonelists(NULL); + page_reporting_reset(zone); } else zone_pcp_update(zone); diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 4b5812c3800e..d0d3fb12ba54 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -68,6 +68,7 @@ #include #include #include +#include #include #include @@ -915,7 +916,7 @@ static inline struct capture_control *task_capc(struct zone *zone) static inline void __free_one_page(struct page *page, unsigned long pfn, struct zone *zone, unsigned int order, - int migratetype) + int migratetype, bool reported) { struct capture_control *capc = task_capc(zone); unsigned long uninitialized_var(buddy_pfn); @@ -990,11 +991,20 @@ static inline void __free_one_page(struct page *page, done_merging: set_page_order(page, order); - if (is_shuffle_order(order) ? shuffle_add_to_tail() : - buddy_merge_likely(pfn, buddy_pfn, page, order)) + if (reported || + (is_shuffle_order(order) ? shuffle_add_to_tail() : + buddy_merge_likely(pfn, buddy_pfn, page, order))) add_to_free_list_tail(page, zone, order, migratetype); else add_to_free_list(page, zone, order, migratetype); + + /* + * No need to notify on a reported page as the total count of + * unreported pages will not have increased since we have essentially + * merged the reported page with one or more unreported pages. + */ + if (!reported) + page_reporting_notify_free(zone, order); } /* @@ -1305,7 +1315,7 @@ static void free_pcppages_bulk(struct zone *zone, int count, if (unlikely(isolated_pageblocks)) mt = get_pageblock_migratetype(page); - __free_one_page(page, page_to_pfn(page), zone, 0, mt); + __free_one_page(page, page_to_pfn(page), zone, 0, mt, false); trace_mm_page_pcpu_drain(page, 0, mt); } spin_unlock(&zone->lock); @@ -1321,7 +1331,7 @@ static void free_one_page(struct zone *zone, is_migrate_isolate(migratetype))) { migratetype = get_pfnblock_migratetype(page, pfn); } - __free_one_page(page, pfn, zone, order, migratetype); + __free_one_page(page, pfn, zone, order, migratetype, false); spin_unlock(&zone->lock); } @@ -2183,6 +2193,122 @@ struct page *__rmqueue_smallest(struct zone *zone, unsigned int order, return NULL; } +#ifdef CONFIG_PAGE_REPORTING +/** + * get_unreported_page - Pull an unreported page from the free_list + * @zone: Zone to draw pages from + * @order: Order to draw pages from + * @mt: Migratetype to draw pages from + * + * This function will obtain a page from the free list. It will start by + * attempting to pull from the tail of the free list and if that is already + * reported on it will instead pull the head if that is unreported. + * + * The page will have the migrate type and order stored in the page + * metadata. While being processed the page will not be avaialble for + * allocation. + * + * Return: page pointer if raw page found, otherwise NULL + */ +struct page *get_unreported_page(struct zone *zone, unsigned int order, int mt) +{ + struct list_head *tail = get_unreported_tail(zone, order, mt); + struct free_area *area = &(zone->free_area[order]); + struct list_head *list = &area->free_list[mt]; + struct page *page; + + /* zone lock should be held when this function is called */ + lockdep_assert_held(&zone->lock); + + /* Find a page of the appropriate size in the preferred list */ + page = list_last_entry(tail, struct page, lru); + list_for_each_entry_from_reverse(page, list, lru) { + /* If we entered this loop then the "raw" list isn't empty */ + + /* If the page is reported try the head of the list */ + if (PageReported(page)) { + page = list_first_entry(list, struct page, lru); + + /* + * If both the head and tail are reported then reset + * the boundary so that we read as an empty list + * next time and bail out. + */ + if (PageReported(page)) { + page_reporting_add_to_boundary(page, zone, mt); + break; + } + } + + del_page_from_free_list(page, zone, order); + + /* record migratetype and order within page */ + set_pcppage_migratetype(page, mt); + set_page_private(page, order); + + /* + * Page will not be available for allocation while we are + * processing it so update the freepage state. + */ + __mod_zone_freepage_state(zone, -(1 << order), mt); + + return page; + } + + return NULL; +} + +/** + * put_reported_page - Return a now-reported page back where we got it + * @zone: Zone to return pages to + * @page: Page that was reported + * + * This function will pull the migratetype and order information out + * of the page and attempt to return it where it found it. If the page + * is added to the free list without changes we will mark it as being + * reported. + */ +void put_reported_page(struct zone *zone, struct page *page) +{ + unsigned int order, mt; + unsigned long pfn; + + /* zone lock should be held when this function is called */ + lockdep_assert_held(&zone->lock); + + mt = get_pcppage_migratetype(page); + pfn = page_to_pfn(page); + + if (unlikely(has_isolate_pageblock(zone) || is_migrate_isolate(mt))) { + mt = get_pfnblock_migratetype(page, pfn); + set_pcppage_migratetype(page, mt); + } + + order = page_private(page); + set_page_private(page, 0); + + __free_one_page(page, pfn, zone, order, mt, true); + + /* + * If page was comingled with another page we cannot consider + * the result to be "reported" since part of the page hasn't been. + * In this case we will simply exit and not update the "reported" + * state. Instead just treat the result as a unreported page. + */ + if (!PageBuddy(page) || page_order(page) != order) + return; + + /* update areated page accounting */ + zone->reported_pages[order - PAGE_REPORTING_MIN_ORDER]++; + + /* update boundary of new migratetype and record it */ + page_reporting_add_to_boundary(page, zone, mt); + + /* flag page as reported */ + __SetPageReported(page); +} +#endif /* CONFIG_PAGE_REPORTING */ + /* * This array describes the order lists are fallen back to when * the free lists for the desirable migrate type are depleted diff --git a/mm/page_reporting.c b/mm/page_reporting.c new file mode 100644 index 000000000000..ae26dd77bce9 --- /dev/null +++ b/mm/page_reporting.c @@ -0,0 +1,313 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include +#include +#include +#include +#include +#include "internal.h" + +static struct page_reporting_dev_info __rcu *ph_dev_info __read_mostly; +struct static_key page_reporting_notify_enabled; + +struct list_head *boundary[MAX_ORDER - PAGE_REPORTING_MIN_ORDER][MIGRATE_TYPES]; + +static void page_reporting_reset_boundary(struct zone *zone, unsigned int order, + unsigned int migratetype) +{ + boundary[order - PAGE_REPORTING_MIN_ORDER][migratetype] = + &zone->free_area[order].free_list[migratetype]; +} + +#define for_each_reporting_migratetype_order(_order, _type) \ + for (_order = MAX_ORDER; _order-- != PAGE_REPORTING_MIN_ORDER;) \ + for (_type = MIGRATE_TYPES; _type--;) + +static int page_reporting_populate_metadata(struct zone *zone) +{ + unsigned int order, mt; + + /* + * We need to make sure we have somewhere to store the tracking + * data for how many reported pages are in the zone. To do that + * we need to make certain zone->reported_pages is populated. + */ + if (!zone->reported_pages) { + zone->reported_pages = + kcalloc(MAX_ORDER - PAGE_REPORTING_MIN_ORDER, + sizeof(unsigned long), + GFP_KERNEL); + if (!zone->reported_pages) + return -ENOMEM; + } + + /* Update boundary data to reflect the zone we are currently working */ + for_each_reporting_migratetype_order(order, mt) + page_reporting_reset_boundary(zone, order, mt); + + return 0; +} + +struct list_head *__page_reporting_get_boundary(unsigned int order, + int migratetype) +{ + return boundary[order - PAGE_REPORTING_MIN_ORDER][migratetype]; +} + +void page_reporting_del_from_boundary(struct page *page, struct zone *zone) +{ + unsigned int order = page_private(page) - PAGE_REPORTING_MIN_ORDER; + int mt = get_pcppage_migratetype(page); + struct list_head **tail = &boundary[order][mt]; + + if (*tail == &page->lru) + *tail = page->lru.next; +} + +void page_reporting_add_to_boundary(struct page *page, struct zone *zone, + int migratetype) +{ + unsigned int order = page_private(page) - PAGE_REPORTING_MIN_ORDER; + struct list_head **tail = &boundary[order][migratetype]; + + *tail = &page->lru; +} + +static unsigned int page_reporting_fill(struct zone *zone, + struct page_reporting_dev_info *phdev) +{ + struct scatterlist *sg = phdev->sg; + unsigned int order, mt, count = 0; + + sg_init_table(phdev->sg, phdev->capacity); + + for_each_reporting_migratetype_order(order, mt) { + struct page *page; + + /* + * Pull pages from free list until we have drained + * it or we have reached capacity. + */ + while ((page = get_unreported_page(zone, order, mt))) { + sg_set_page(&sg[count], page, PAGE_SIZE << order, 0); + + if (++count == phdev->capacity) + return count; + } + } + + /* mark end of scatterlist due to underflow */ + if (count) + sg_mark_end(&sg[count - 1]); + + /* + * If there are no longer enough free pages to fully populate + * the scatterlist, then we can just shut it down for this zone. + */ + __clear_bit(ZONE_PAGE_REPORTING_REQUESTED, &zone->flags); + atomic_dec(&phdev->refcnt); + + return count; +} + +static void page_reporting_drain(struct zone *zone, + struct page_reporting_dev_info *phdev) +{ + struct scatterlist *sg = phdev->sg; + + /* + * Drain the now reported pages back into their respective + * free lists/areas. We assume at least one page is populated. + */ + do { + put_reported_page(zone, sg_page(sg)); + } while (!sg_is_last(sg++)); +} + +/* + * The page reporting cycle consists of 4 stages, fill, report, drain, and idle. + * We will cycle through the first 3 stages until we fail to obtain any + * pages, in that case we will switch to idle. + */ +static void page_reporting_cycle(struct zone *zone, + struct page_reporting_dev_info *phdev) +{ + /* + * Guarantee boundaries and stats are populated before we + * start placing reported pages in the zone. + */ + if (page_reporting_populate_metadata(zone)) + return; + + spin_lock(&zone->lock); + + /* set bit indicating boundaries are present */ + __set_bit(ZONE_PAGE_REPORTING_ACTIVE, &zone->flags); + + do { + /* Pull pages out of allocator into a scaterlist */ + unsigned int nents = page_reporting_fill(zone, phdev); + + /* no pages were acquired, give up */ + if (!nents) + break; + + spin_unlock(&zone->lock); + + /* begin processing pages in local list */ + phdev->report(phdev, nents); + + spin_lock(&zone->lock); + + /* + * We should have a scatterlist of pages that have been + * processed. Return them to their original free lists. + */ + page_reporting_drain(zone, phdev); + + /* keep pulling pages till there are none to pull */ + } while (test_bit(ZONE_PAGE_REPORTING_REQUESTED, &zone->flags)); + + /* processing of the zone is complete, we can disable boundaries */ + __clear_bit(ZONE_PAGE_REPORTING_ACTIVE, &zone->flags); + + spin_unlock(&zone->lock); +} + +static void page_reporting_process(struct work_struct *work) +{ + struct delayed_work *d_work = to_delayed_work(work); + struct page_reporting_dev_info *phdev = + container_of(d_work, struct page_reporting_dev_info, work); + struct zone *zone = first_online_pgdat()->node_zones; + + do { + if (test_bit(ZONE_PAGE_REPORTING_REQUESTED, &zone->flags)) + page_reporting_cycle(zone, phdev); + + /* + * Move to next zone, if at the end of the list + * test to see if we can just go into idle. + */ + zone = next_zone(zone); + if (zone) + continue; + zone = first_online_pgdat()->node_zones; + + /* + * As long as refcnt has not reached zero there are still + * zones to be processed. + */ + } while (atomic_read(&phdev->refcnt)); +} + +/* request page reporting on this zone */ +void __page_reporting_request(struct zone *zone) +{ + struct page_reporting_dev_info *phdev; + + rcu_read_lock(); + + /* + * We use RCU to protect the ph_dev_info pointer. In almost all + * cases this should be present, however in the unlikely case of + * a shutdown this will be NULL and we should exit. + */ + phdev = rcu_dereference(ph_dev_info); + if (unlikely(!phdev)) + return; + + /* + * We can use separate test and set operations here as there + * is nothing else that can set or clear this bit while we are + * holding the zone lock. The advantage to doing it this way is + * that we don't have to dirty the cacheline unless we are + * changing the value. + */ + __set_bit(ZONE_PAGE_REPORTING_REQUESTED, &zone->flags); + + /* + * Delay the start of work to allow a sizable queue to + * build. For now we are limiting this to running no more + * than 10 times per second. + */ + if (!atomic_fetch_inc(&phdev->refcnt)) + schedule_delayed_work(&phdev->work, HZ / 10); + + rcu_read_unlock(); +} + +void __page_reporting_free_stats(struct zone *zone) +{ + /* free reported_page statisitics */ + kfree(zone->reported_pages); + zone->reported_pages = NULL; +} + +static DEFINE_MUTEX(page_reporting_mutex); + +void page_reporting_shutdown(struct page_reporting_dev_info *phdev) +{ + mutex_lock(page_reporting_mutex); + + if (rcu_access_pointer(ph_dev_info) == phdev) { + /* Disable page reporting notification */ + static_key_slow_dec(&page_reporting_notify_enabled); + RCU_INIT_POINTER(ph_dev_info, NULL); + synchronize_rcu(); + + /* Flush any existing work, and lock it out */ + cancel_delayed_work_sync(&phdev->work); + + /* Free scatterlist */ + kfree(phdev->sg); + phdev->sg = NULL; + } + + mutex_unlock(page_reporting_mutex); +} +EXPORT_SYMBOL_GPL(page_reporting_shutdown); + +int page_reporting_startup(struct page_reporting_dev_info *phdev) +{ + struct zone *zone; + int err = 0; + + mutex_lock(page_reporting_mutex); + + /* nothing to do if already in use */ + if (rcu_access_pointer(ph_dev_info)) { + err = -EBUSY; + goto err_out; + } + + /* allocate scatterlist to store pages being reported on */ + phdev->sg = kcalloc(phdev->capacity, sizeof(*phdev->sg), GFP_KERNEL); + if (!phdev->sg) { + err = -ENOMEM; + goto err_out; + } + + /* initialize refcnt and work structures */ + atomic_set(&phdev->refcnt, 0); + INIT_DELAYED_WORK(&phdev->work, &page_reporting_process); + + /* assign device, and begin initial flush of populated zones */ + rcu_assign_pointer(ph_dev_info, phdev); + for_each_populated_zone(zone) { + spin_lock(&zone->lock); + __page_reporting_request(zone); + spin_unlock(&zone->lock); + } + + /* enable page reporting notification */ + static_key_slow_inc(&page_reporting_notify_enabled); +err_out: + mutex_unlock(page_reporting_mutex); + + return err; +} +EXPORT_SYMBOL_GPL(page_reporting_startup); + From patchwork Wed Aug 7 22:42:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Duyck X-Patchwork-Id: 11082811 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2C40114DB for ; Wed, 7 Aug 2019 22:42:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1BA0828AB8 for ; Wed, 7 Aug 2019 22:42:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0FE7B28ABC; Wed, 7 Aug 2019 22:42:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8615228AB8 for ; Wed, 7 Aug 2019 22:42:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9A8366B000C; Wed, 7 Aug 2019 18:42:16 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 959726B000D; Wed, 7 Aug 2019 18:42:16 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 848416B000E; Wed, 7 Aug 2019 18:42:16 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) by kanga.kvack.org (Postfix) with ESMTP id 4D1EC6B000C for ; Wed, 7 Aug 2019 18:42:16 -0400 (EDT) Received: by mail-pf1-f199.google.com with SMTP id 21so57678402pfu.9 for ; Wed, 07 Aug 2019 15:42:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:subject:from:to:cc:date :message-id:in-reply-to:references:user-agent:mime-version :content-transfer-encoding; bh=ee1mc4VxnFFfQeQcZzbu/0JmrNIJIkJCiHbNbTiM9tQ=; b=ss/Sg0LliuNo+XuL4DF5OuMHoPv8C4PwawYXNE6L5eL6d+fQnDN2rAoH+zA6RnLQ/O WDJgXES3RMpox92vHvrQoosung7DqO09W+KrNehxYoBeycOpr27udQ76kJj9WhFiBbMh RkUeoxT0v1PRdxCsp1U4Waa1dHZhSTejtrPt/umDNU+3slH6GosJ3OeYkpzxf9QFQO2J UXI4YCXc8kiTk32XUF7sqWDmomr7ITqqAOsb0O/ENLtZganSeMRfygruwR9WgKL3kgqj CAe9D0dwwZVTyWmDDADtbKCQQul2Ds57Yyf7T/IZDDGaTYRUa092Efeu+R1haBGnVU9u Xdpw== X-Gm-Message-State: APjAAAVNmk14/1ZUYTEbNLmzsUVn9tVO6bpzzaPBN2aKrT6/eMpyBzvb V6EO7JyXN+rpgA+Ncjv4hnmG4GlJp/H1IQ4MX0Law+HWjl9IDqyKBB7yc+8MB/27VDnXkHmKlbI IbGK6Eg7YwO4xRiTw6qzIjSWbxKDHLWxwUgVj/1sLYbmspUme0B35rJt1ti04DDpOgg== X-Received: by 2002:a17:90a:290b:: with SMTP id g11mr733387pjd.122.1565217735991; Wed, 07 Aug 2019 15:42:15 -0700 (PDT) X-Received: by 2002:a17:90a:290b:: with SMTP id g11mr733303pjd.122.1565217734680; Wed, 07 Aug 2019 15:42:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565217734; cv=none; d=google.com; s=arc-20160816; b=Ko0c4MkB+/kziJrNLYYUvcxj3jmFKMkmjB2gTfNtd3kfYtiohhwbR+ef2C/aCmENpG kcvW4pwC/o5ZgA/yk/jCOcMOL+CooJvsBOqxZrd88XLPyN/twZfJTVUuRwoAupJCov3D D9ldQ+28eluxrhzlPz4jzSwOORhuT0Mhzl6U/pZsAzPc9WanNqRi8RBp2SukgO5/0wI9 aYhbKZiPQIKnqbqPWelfwc4E7/v5Y+GIvXnQHKBISZA9b4SQgaIiyigK/zSgx741HIIS TBr1PHxDDWNybKOaWy8KRIwXRPdfw1cIGSVmVcRAsc0H07cwj8uWr/QHeK3ZC0caJK0n KAMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:message-id:date:cc:to:from:subject:dkim-signature; bh=ee1mc4VxnFFfQeQcZzbu/0JmrNIJIkJCiHbNbTiM9tQ=; b=yX0JvaFePawG4CwJKnjkelKMi0J+fYQIsONWu5SEZKwHmz8ifvB0E5uQTwwgr7pLbI 6DezLLREAIYcPaFvg9sYiXA7DEyXkjxDCtTTNeVWkKZpJb9X6oa2uoAETvtVqxAW3ZDa GPCK/fW/Mkq8CNixBx/RG0Rjdd9G8CTuzbCa3JPPTrdAt3dhMAln1srvpwIZGKXoEW+W QwPYf12aqVxgq3kwG2eqopXrv0Ig5nfpO7ElRbuv92m5uwXBKhggGNkLcglATQjRT9di CjM/qaD1akWgTLJTHw9O/V6qia8gIgt33xAf9u8Bslt+h4hGvbC4ZBrK4zDZxzERrgsi oPuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=r8JTp1EZ; spf=pass (google.com: domain of alexander.duyck@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=alexander.duyck@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id m93sor521959pje.1.2019.08.07.15.42.14 for (Google Transport Security); Wed, 07 Aug 2019 15:42:14 -0700 (PDT) Received-SPF: pass (google.com: domain of alexander.duyck@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=r8JTp1EZ; spf=pass (google.com: domain of alexander.duyck@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=alexander.duyck@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=ee1mc4VxnFFfQeQcZzbu/0JmrNIJIkJCiHbNbTiM9tQ=; b=r8JTp1EZK6OewkxZ8F+auXR18QN902AIqN0vePsif429O7Lq1avQFEozAWWPhbBC9B Q9LrzH1hVnA8Tuytm9wyTDaPe2zY89WCnOGZ+pmOgCSFL0FfcUlG86M+YIKKRTuLggiL 6a3p5U1HW3Ics5uUYZHYDvdHKCG8SGNS9YoTjADP6wdCGmzP4vQe8EwOTA78fFKT/Yrm IQe3D3oxce6LDsVEss9rrkHamPvBurz9AguWf5yuxH/xJjMpuTsoRGPGsIoVB6ZG5jWU gR4O33MmIUVJ/jUHWmGeBwFfXD56gNpy593tW446eui/cfRgMlcJc88tGxIODG0qgKia BHrA== X-Google-Smtp-Source: APXvYqzDgU1Eu3TfqN8qYWP+6kqzZlo0qvhlv0y+xOqs55iUCb5VENOWMnPojOI+y+v9CnUzrfywew== X-Received: by 2002:a17:90a:8a17:: with SMTP id w23mr681830pjn.139.1565217734198; Wed, 07 Aug 2019 15:42:14 -0700 (PDT) Received: from localhost.localdomain ([2001:470:b:9c3:9e5c:8eff:fe4f:f2d0]) by smtp.gmail.com with ESMTPSA id v184sm90677862pfb.82.2019.08.07.15.42.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Aug 2019 15:42:13 -0700 (PDT) Subject: [PATCH v4 5/6] virtio-balloon: Pull page poisoning config out of free page hinting From: Alexander Duyck To: nitesh@redhat.com, kvm@vger.kernel.org, david@redhat.com, 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, willy@infradead.org, lcapitulino@redhat.com, wei.w.wang@intel.com, aarcange@redhat.com, pbonzini@redhat.com, dan.j.williams@intel.com, alexander.h.duyck@linux.intel.com Date: Wed, 07 Aug 2019 15:42:13 -0700 Message-ID: <20190807224213.6891.38062.stgit@localhost.localdomain> In-Reply-To: <20190807224037.6891.53512.stgit@localhost.localdomain> References: <20190807224037.6891.53512.stgit@localhost.localdomain> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 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: X-Virus-Scanned: ClamAV using ClamSMTP From: Alexander Duyck Currently the page poisoning setting wasn't being enabled unless free page hinting was enabled. However we will need the page poisoning tracking logic as well for unused page reporting. As such pull it out and make it a separate bit of config in the probe function. In addition we can actually wrap the code in a check for NO_SANITY. If we don't care what is actually in the page we can just default to 0 and leave it there. Signed-off-by: Alexander Duyck --- drivers/virtio/virtio_balloon.c | 19 +++++++++++++------ mm/page_reporting.c | 8 ++++---- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c index 226fbb995fb0..2c19457ab573 100644 --- a/drivers/virtio/virtio_balloon.c +++ b/drivers/virtio/virtio_balloon.c @@ -842,7 +842,6 @@ static int virtio_balloon_register_shrinker(struct virtio_balloon *vb) static int virtballoon_probe(struct virtio_device *vdev) { struct virtio_balloon *vb; - __u32 poison_val; int err; if (!vdev->config->get) { @@ -909,11 +908,19 @@ static int virtballoon_probe(struct virtio_device *vdev) VIRTIO_BALLOON_CMD_ID_STOP); spin_lock_init(&vb->free_page_list_lock); INIT_LIST_HEAD(&vb->free_page_list); - if (virtio_has_feature(vdev, VIRTIO_BALLOON_F_PAGE_POISON)) { - memset(&poison_val, PAGE_POISON, sizeof(poison_val)); - virtio_cwrite(vb->vdev, struct virtio_balloon_config, - poison_val, &poison_val); - } + } + if (virtio_has_feature(vdev, VIRTIO_BALLOON_F_PAGE_POISON)) { + __u32 poison_val = 0; + +#if !defined(CONFIG_PAGE_POISONING_NO_SANITY) + /* + * Let hypervisor know that we are expecting a specific + * value to be written back in unused pages. + */ + memset(&poison_val, PAGE_POISON, sizeof(poison_val)); +#endif + virtio_cwrite(vb->vdev, struct virtio_balloon_config, + poison_val, &poison_val); } /* * We continue to use VIRTIO_BALLOON_F_DEFLATE_ON_OOM to decide if a diff --git a/mm/page_reporting.c b/mm/page_reporting.c index ae26dd77bce9..68dccfc7d629 100644 --- a/mm/page_reporting.c +++ b/mm/page_reporting.c @@ -250,7 +250,7 @@ void __page_reporting_free_stats(struct zone *zone) void page_reporting_shutdown(struct page_reporting_dev_info *phdev) { - mutex_lock(page_reporting_mutex); + mutex_lock(&page_reporting_mutex); if (rcu_access_pointer(ph_dev_info) == phdev) { /* Disable page reporting notification */ @@ -266,7 +266,7 @@ void page_reporting_shutdown(struct page_reporting_dev_info *phdev) phdev->sg = NULL; } - mutex_unlock(page_reporting_mutex); + mutex_unlock(&page_reporting_mutex); } EXPORT_SYMBOL_GPL(page_reporting_shutdown); @@ -275,7 +275,7 @@ int page_reporting_startup(struct page_reporting_dev_info *phdev) struct zone *zone; int err = 0; - mutex_lock(page_reporting_mutex); + mutex_lock(&page_reporting_mutex); /* nothing to do if already in use */ if (rcu_access_pointer(ph_dev_info)) { @@ -305,7 +305,7 @@ int page_reporting_startup(struct page_reporting_dev_info *phdev) /* enable page reporting notification */ static_key_slow_inc(&page_reporting_notify_enabled); err_out: - mutex_unlock(page_reporting_mutex); + mutex_unlock(&page_reporting_mutex); return err; }