Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3414142imu; Fri, 18 Jan 2019 09:57:40 -0800 (PST) X-Google-Smtp-Source: ALg8bN4tp4Lk1wnZe8qHgrodVMu7RS6UJ2x7G2mEOqrz60pWGeUzgmegs61/DClO5wOucBkF1orP X-Received: by 2002:a17:902:7107:: with SMTP id a7mr20052596pll.290.1547834260777; Fri, 18 Jan 2019 09:57:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547834260; cv=none; d=google.com; s=arc-20160816; b=UNAvt/wHwouiacAHN15JIYV7gJ7XuCzS6WBVqfRdMTOdTSs69AfvtVOyI6jXIfZSo3 G/26FZktG8LKX548jwkVEvx6YclqphDp7oFTXhZBgkHnhCvHMnjEZdr9TRKD5yiATCTP JNKAgH0/SGwg0OghBBuNVlf62SZsgOOrty6UvTh1wRfQZBGZPZAlqRxp8N2MpGcKrS+D WrWK3h8+h0W1r/8PlZmzfXfqdO6TgnzUgH2tlJZK9SFNHEtJoqTjmDsfQapoX0w9whCj L43YNKg6GtJeu+/csLcKjXJ7+/jwa71jzi/vkuwGD1ZGoZvwAnb57JnpCnqmRE+E0r4t h7Tg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=r+ZeJpz1lZS5QW4P1aAtJ+FjrlN8m7Grj1Z7u/uZEQM=; b=btAY1rt8gMUR8nRwh4eyvlwP0LxX3gDA3nqT3smAUTl89XcoKRNqbZR52KgJ/VjkYT 2bt0/mOgj3MxcmhGnA9u9hJh3tHhjd86pNR0E45FZMGN8WmOSqQXTQ/BRwoA2xEbYtVu Ok2r5zQWXWezo61IAdyr7s9+CUYVvpUVK7zVJkurogtRzJj0aa7aV+AMMb2sTcgjWG93 9N4qu/5lXIwEvp4BAkDphkPsOh/+YLxyBuI1uPjFzmappYYfhRywxB/xxa6Iks61lvDY w4vVIReoUp1lthW4L61gK2SqRgp9cXA5QxRiPGu9WEhPfzuZgSSEs0Q5MpNaFUBus92t 3afA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 123si5479938pfx.109.2019.01.18.09.57.22; Fri, 18 Jan 2019 09:57:40 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729049AbfARRzD (ORCPT + 99 others); Fri, 18 Jan 2019 12:55:03 -0500 Received: from outbound-smtp02.blacknight.com ([81.17.249.8]:46636 "EHLO outbound-smtp02.blacknight.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727673AbfARRzD (ORCPT ); Fri, 18 Jan 2019 12:55:03 -0500 Received: from mail.blacknight.com (pemlinmail03.blacknight.ie [81.17.254.16]) by outbound-smtp02.blacknight.com (Postfix) with ESMTPS id 44C7998BD2 for ; Fri, 18 Jan 2019 17:55:00 +0000 (UTC) Received: (qmail 7671 invoked from network); 18 Jan 2019 17:55:00 -0000 Received: from unknown (HELO stampy.163woodhaven.lan) (mgorman@techsingularity.net@[37.228.229.96]) by 81.17.254.9 with ESMTPA; 18 Jan 2019 17:55:00 -0000 From: Mel Gorman To: Andrew Morton Cc: David Rientjes , Andrea Arcangeli , Vlastimil Babka , Linux List Kernel Mailing , Linux-MM , Mel Gorman Subject: [PATCH 19/22] mm, compaction: Round-robin the order while searching the free lists for a target Date: Fri, 18 Jan 2019 17:51:33 +0000 Message-Id: <20190118175136.31341-20-mgorman@techsingularity.net> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190118175136.31341-1-mgorman@techsingularity.net> References: <20190118175136.31341-1-mgorman@techsingularity.net> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org As compaction proceeds and creates high-order blocks, the free list search gets less efficient as the larger blocks are used as compaction targets. Eventually, the larger blocks will be behind the migration scanner for partially migrated pageblocks and the search fails. This patch round-robins what orders are searched so that larger blocks can be ignored and find smaller blocks that can be used as migration targets. The overall impact was small on 1-socket but it avoids corner cases where the migration/free scanners meet prematurely or situations where many of the pageblocks encountered by the free scanner are almost full instead of being properly packed. Previous testing had indicated that without this patch there were occasional large spikes in the free scanner without this patch. [dan.carpenter@oracle.com: Fix static checker warning] Signed-off-by: Mel Gorman Acked-by: Vlastimil Babka --- mm/compaction.c | 33 ++++++++++++++++++++++++++++++--- mm/internal.h | 3 ++- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index 04ec7d4da719..7d39ff08269a 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -1147,6 +1147,24 @@ fast_isolate_around(struct compact_control *cc, unsigned long pfn, unsigned long set_pageblock_skip(page); } +/* Search orders in round-robin fashion */ +static int next_search_order(struct compact_control *cc, int order) +{ + order--; + if (order < 0) + order = cc->order - 1; + + /* Search wrapped around? */ + if (order == cc->search_order) { + cc->search_order--; + if (cc->search_order < 0) + cc->search_order = cc->order - 1; + return -1; + } + + return order; +} + static unsigned long fast_isolate_freepages(struct compact_control *cc) { @@ -1183,9 +1201,15 @@ fast_isolate_freepages(struct compact_control *cc) if (WARN_ON_ONCE(min_pfn > low_pfn)) low_pfn = min_pfn; - for (order = cc->order - 1; - order >= 0 && !page; - order--) { + /* + * Search starts from the last successful isolation order or the next + * order to search after a previous failure + */ + cc->search_order = min_t(unsigned int, cc->order - 1, cc->search_order); + + for (order = cc->search_order; + !page && order >= 0; + order = next_search_order(cc, order)) { struct free_area *area = &cc->zone->free_area[order]; struct list_head *freelist; struct page *freepage; @@ -1209,6 +1233,7 @@ fast_isolate_freepages(struct compact_control *cc) if (pfn >= low_pfn) { cc->fast_search_fail = 0; + cc->search_order = order; page = freepage; break; } @@ -2136,6 +2161,7 @@ static enum compact_result compact_zone_order(struct zone *zone, int order, .total_migrate_scanned = 0, .total_free_scanned = 0, .order = order, + .search_order = order, .gfp_mask = gfp_mask, .zone = zone, .mode = (prio == COMPACT_PRIO_ASYNC) ? @@ -2367,6 +2393,7 @@ static void kcompactd_do_work(pg_data_t *pgdat) struct zone *zone; struct compact_control cc = { .order = pgdat->kcompactd_max_order, + .search_order = pgdat->kcompactd_max_order, .total_migrate_scanned = 0, .total_free_scanned = 0, .classzone_idx = pgdat->kcompactd_classzone_idx, diff --git a/mm/internal.h b/mm/internal.h index d5b999e5eb5f..31bb0be6fd52 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -192,7 +192,8 @@ struct compact_control { struct zone *zone; unsigned long total_migrate_scanned; unsigned long total_free_scanned; - unsigned int fast_search_fail; /* failures to use free list searches */ + unsigned short fast_search_fail;/* failures to use free list searches */ + short search_order; /* order to start a fast search at */ const gfp_t gfp_mask; /* gfp mask of a direct compactor */ int order; /* order a direct compactor needs */ int migratetype; /* migratetype of direct compactor */ -- 2.16.4