Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3393871ybt; Tue, 30 Jun 2020 01:24:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw5uzLK8bGcWQuiEdm6kyljk1ClBWQCWN8OIur+sFIemSzIUa4+5unUV+aV9UWCKRjsTRtb X-Received: by 2002:a50:9b0b:: with SMTP id o11mr22640580edi.22.1593505467525; Tue, 30 Jun 2020 01:24:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593505467; cv=none; d=google.com; s=arc-20160816; b=jWJ53v8WnyMf5VxxN8B/pF2vsdnsIFJPX3aPRdfRmczPh1/f0zRQKAZLi4IMnq+quv rcv45wb3CwmDNNSmm1BhJ9BqazC0UJzreR5vaYCKtNCMVEfEVQD9LEXQWcGK3MTcZSwC beIMZ1tupfPIc/V0ZCdpeaCeOX6DZXNhNXB15obRmZ8R76GDwrFnpG+mjRWhVmfRmQKK pLZk8jrlgZW8Ai9bHXNKWKtWJcOMT4a/i2wsb4NUDXf+xzd7wlOecmKAZL3qf1JtwPmH Pq2v7ebQ127Z2t4S8ApHSlbKFYHsrBfCwRvvx4nau7vEzAoqbJl2NKyHZDnvwXzT027F JrVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:message-id :in-reply-to:date:references:subject:cc:to:from:ironport-sdr :ironport-sdr; bh=2VcK6SycQaxCpr9KrKh5sEEQrp6twsU6mDToD9vKF/k=; b=GaBTGtmJJME9y6ANmnUG1rgbPyO/0UF2R7tJ3Bvbk/HFdYmBEY0EYJESwm5x/0Yop1 //vtd7z+RIJQJJQ5Gf5cHzC5FR3LGgpXzFNWbP7ZyU16HAhLV/KhO7m5Y9+WXUDIm5d0 zjlGBAz3TRlOL5mNS4+VMnCp2htQybaQ1qpaqDPlhoqFSQO5xi4vC7sT2GTpQDbctRIa rayowO0Vya/9ZQfj9ImMGBeWGssO46DbcNvwA/XE+aVCv6LRfV9rxnx3krWSf03Umsu4 Y8o5XFlKR1typ5IbZGQS1UbsOj9zACONyaoNn9RrskRLRbNjBkb/FNcyf1RyBXkieUKf jWnw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dd5si1297710ejb.399.2020.06.30.01.24.04; Tue, 30 Jun 2020 01:24:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731216AbgF3IWu (ORCPT + 99 others); Tue, 30 Jun 2020 04:22:50 -0400 Received: from mga06.intel.com ([134.134.136.31]:20753 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727919AbgF3IWu (ORCPT ); Tue, 30 Jun 2020 04:22:50 -0400 IronPort-SDR: nnUluNpXypDeC3y033Z3GNmGgiGr9zmxIThehqZT8VNxmCB+cl+E9yg8EtU4wCqP4tNtjlBy7P PU5ItE2xfIlQ== X-IronPort-AV: E=McAfee;i="6000,8403,9666"; a="207689809" X-IronPort-AV: E=Sophos;i="5.75,296,1589266800"; d="scan'208";a="207689809" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jun 2020 01:22:49 -0700 IronPort-SDR: Sm85a8BcaRvXV1JjJmavq1vsPR+FFG9Gm9Heo+bchclIS2GjzV4T9qT/IXAQiGwLGm+xfJeoFV CJclhTFeLCcA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,296,1589266800"; d="scan'208";a="321326416" Received: from yhuang-dev.sh.intel.com (HELO yhuang-dev) ([10.239.159.23]) by orsmga007.jf.intel.com with ESMTP; 30 Jun 2020 01:22:47 -0700 From: "Huang\, Ying" To: Dave Hansen Cc: , , , , Subject: Re: [RFC][PATCH 5/8] mm/numa: automatically generate node migration order References: <20200629234503.749E5340@viggo.jf.intel.com> <20200629234512.F34EDC44@viggo.jf.intel.com> Date: Tue, 30 Jun 2020 16:22:46 +0800 In-Reply-To: <20200629234512.F34EDC44@viggo.jf.intel.com> (Dave Hansen's message of "Mon, 29 Jun 2020 16:45:12 -0700") Message-ID: <87ftadotd5.fsf@yhuang-dev.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=ascii Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Dave Hansen writes: > +/* > + * Find an automatic demotion target for 'node'. > + * Failing here is OK. It might just indicate > + * being at the end of a chain. > + */ > +static int establish_migrate_target(int node, nodemask_t *used) > +{ > + int migration_target; > + > + /* > + * Can not set a migration target on a > + * node with it already set. > + * > + * No need for READ_ONCE() here since this > + * in the write path for node_demotion[]. > + * This should be the only thread writing. > + */ > + if (node_demotion[node] != NUMA_NO_NODE) > + return NUMA_NO_NODE; > + > + migration_target = find_next_best_node(node, used); > + if (migration_target == NUMA_NO_NODE) > + return NUMA_NO_NODE; > + > + node_demotion[node] = migration_target; > + > + return migration_target; > +} > + > +/* > + * When memory fills up on a node, memory contents can be > + * automatically migrated to another node instead of > + * discarded at reclaim. > + * > + * Establish a "migration path" which will start at nodes > + * with CPUs and will follow the priorities used to build the > + * page allocator zonelists. > + * > + * The difference here is that cycles must be avoided. If > + * node0 migrates to node1, then neither node1, nor anything > + * node1 migrates to can migrate to node0. > + * > + * This function can run simultaneously with readers of > + * node_demotion[]. However, it can not run simultaneously > + * with itself. Exclusion is provided by memory hotplug events > + * being single-threaded. > + */ > +void set_migration_target_nodes(void) > +{ > + nodemask_t next_pass = NODE_MASK_NONE; > + nodemask_t this_pass = NODE_MASK_NONE; > + nodemask_t used_targets = NODE_MASK_NONE; > + int node; > + > + get_online_mems(); > + /* > + * Avoid any oddities like cycles that could occur > + * from changes in the topology. This will leave > + * a momentary gap when migration is disabled. > + */ > + disable_all_migrate_targets(); > + > + /* > + * Ensure that the "disable" is visible across the system. > + * Readers will see either a combination of before+disable > + * state or disable+after. They will never see before and > + * after state together. > + * > + * The before+after state together might have cycles and > + * could cause readers to do things like loop until this > + * function finishes. This ensures they can only see a > + * single "bad" read and would, for instance, only loop > + * once. > + */ > + smp_wmb(); > + > + /* > + * Allocations go close to CPUs, first. Assume that > + * the migration path starts at the nodes with CPUs. > + */ > + next_pass = node_states[N_CPU]; > +again: > + this_pass = next_pass; > + next_pass = NODE_MASK_NONE; > + /* > + * To avoid cycles in the migration "graph", ensure > + * that migration sources are not future targets by > + * setting them in 'used_targets'. > + * > + * But, do this only once per pass so that multiple > + * source nodes can share a target node. establish_migrate_target() calls find_next_best_node(), which will set target_node in used_targets. So it seems that the nodes_or() below is only necessary to initialize used_targets, and multiple source nodes cannot share one target node in current implementation. Best Regards, Huang, Ying > + */ > + nodes_or(used_targets, used_targets, this_pass); > + for_each_node_mask(node, this_pass) { > + int target_node = establish_migrate_target(node, &used_targets); > + > + if (target_node == NUMA_NO_NODE) > + continue; > + > + /* Visit targets from this pass in the next pass: */ > + node_set(target_node, next_pass); > + } > + /* Is another pass necessary? */ > + if (!nodes_empty(next_pass)) > + goto again; > + > + put_online_mems(); > +}