From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7620CC433DB for ; Tue, 2 Feb 2021 17:50:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 46F7B64DCC for ; Tue, 2 Feb 2021 17:50:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237928AbhBBRtk (ORCPT ); Tue, 2 Feb 2021 12:49:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237785AbhBBRrc (ORCPT ); Tue, 2 Feb 2021 12:47:32 -0500 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74EF4C0617A7 for ; Tue, 2 Feb 2021 09:46:52 -0800 (PST) Received: by mail-ej1-x633.google.com with SMTP id a9so12917898ejr.2 for ; Tue, 02 Feb 2021 09:46:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ZGI/zcEe0Yt+bxNAd+ZCrR6roUoFCN6DKRYdKgfHGTo=; b=dn0kQpEE8uzdEC3sYSZKK96Y1R4SyTF8SQ++wUCnfT8U7YdqxyodVjFScTsZDUlz2n KXg1Dw+ctFq/Dk2HuQqOumasQ3G3q02khzesSRbG5uN4Ex1jxRPwfgQq7SyPS8eexJcj 0/GfCZpmy+aF81ygQgdOI5YT/qoJNbogDX68XaZy+mqpSgoH8aeK6qAc82a4vH+GPZdR lZ7l6G74LFud0yjEfSEjbtn6W5GDktU+8rXMXfsGDWXCRBcjbriVGr79SHijhun74lqQ LArbTXnvlK5ey46TqSx5UZmskyWGW67xW0k4frniCllwf2pIqDldTzka/QONLnkOz3bp 1F6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ZGI/zcEe0Yt+bxNAd+ZCrR6roUoFCN6DKRYdKgfHGTo=; b=cYk3hUWkwqqIlkJ73mo76ElGchHXKM4nOHDdqjT03JIQd8l7tURyfip72Tz6nujh7p GLumFZyou5sJ1b1l23cdjSDj5ROkPN9DhpkZaKSOz39jbT4ooeReNBdm6rHwCtiG7n4H boC+MYtbWPTVi+b+okJbRKLlOzcgXeBEF8ebhV0M6txysTs3PqQ8n5ujeT9vsStisdBe UG1lzE5Pn1aTf8Zga3KE1rfKUypId058j+8sac10eSNPxQ5QSEf5iqwLh1wZ/dg1tpVL YxTxR9vsQyfObNTh4773nVkfMgFc2ydxFcrWvBiyavRmSDLpmmZcwaGDh2hdGQif5aOk /Vmw== X-Gm-Message-State: AOAM530onnyiz87j5mGYYk39SyWvYogIyAYU+9YL+QZDHwZzWydN0cRm bJEmyxuz01C6yBuaZmS/8FfLnpJ1xmyD1L2cDHdywlKW X-Google-Smtp-Source: ABdhPJwswex2voGStCOUsnNL01gx3JAAwJ4/V3+iqItDVUhsO/oc14DWZpKkTcMicL+pke/SiErAG604f5qaxUrOYUw= X-Received: by 2002:a17:906:eddd:: with SMTP id sb29mr14357090ejb.383.1612288011231; Tue, 02 Feb 2021 09:46:51 -0800 (PST) MIME-Version: 1.0 References: <20210126003411.2AC51464@viggo.jf.intel.com> <20210126003421.45897BF4@viggo.jf.intel.com> <317d4c23-76a7-b653-87a4-bab642fa1717@intel.com> In-Reply-To: <317d4c23-76a7-b653-87a4-bab642fa1717@intel.com> From: Yang Shi Date: Tue, 2 Feb 2021 09:46:39 -0800 Message-ID: Subject: Re: [RFC][PATCH 05/13] mm/numa: automatically generate node migration order To: Dave Hansen Cc: Dave Hansen , Linux Kernel Mailing List , Linux MM , Yang Shi , David Rientjes , Huang Ying , Dan Williams , David Hildenbrand , Oscar Salvador Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 1, 2021 at 11:13 AM Dave Hansen wrote: > > On 1/29/21 12:46 PM, Yang Shi wrote: > ... > >> int next_demotion_node(int node) > >> { > >> - return node_demotion[node]; > >> + /* > >> + * node_demotion[] is updated without excluding > >> + * this function from running. READ_ONCE() avoids > >> + * reading multiple, inconsistent 'node' values > >> + * during an update. > >> + */ > > > > Don't we need a smp_rmb() here? The single write barrier might be not > > enough in migration target set. Typically a write barrier should be > > used in pairs with a read barrier. > > I don't think we need one, practically. > > Since there is no locking against node_demotion[] updates, although a > smp_rmb() would ensure that this read is up-to-date, it could change > freely after the smp_rmb(). Yes, but this should be able to guarantee we see "disable + after" state. Isn't it more preferred? > > In other words, smp_rmb() would shrink the window where a "stale" read > could occur but would not eliminate it. > > >> + return READ_ONCE(node_demotion[node]); > > > > Why not consolidate the patch #4 in this patch? The patch #4 just add > > the definition of node_demotion and the function, then the function is > > changed in this patch, and the function is not used by anyone between > > the adding and changing. > > I really wanted to highlight that the locking scheme and the READ_ONCE() > (or lack thereof) was specifically due to how node_demotion[] was being > updated. > > The READ_ONCE() is not, for instance, inherent to the data structure. > > ... > >> +/* > >> + * 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. > > > > Maybe an example diagram for the physical topology and how the > > migration target is generated in the comment seems helpful to > > understand the code. > > Sure. Were you thinking of a code comment, or enhanced changelog? I'd prefer a code comment. > > Let's say there's a system with two sockets each with the same three > classes of memory: fast, medium and slow. Each memory class is placed > in its own NUMA node and the CPUs are attached to the fast memory. That > leaves 6 NUMA nodes (0-5): > > Socket A: 0, 1, 2 > Socket B: 3, 4, 5 > > The migration path for this configuration path would start on the nodes > with the processors and fast memory, progress through medium and end > with the slow memory: > > 0 -> 1 -> 2 -> stop > 3 -> 4 -> 5 -> stop > > This is represented in the node_demotion[] like this: > > { 1, // Node 0 migrates to 1 > 2, // Node 1 migrates to 2 > -1, // Node 2 does not migrate > 4, // Node 3 migrates to 1 > 5, // Node 4 migrates to 2 > -1} // Node 5 does not migrate > > Is that what you were thinking of? Perfect. > > ... > >> +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'. Do this only > >> + * once per pass so that multiple source nodes can > >> + * share a target node. > >> + * > >> + * 'used_targets' will become unavailable in future > >> + * passes. This limits some opportunities for > >> + * multiple source nodes to share a desintation. > > > > s/desination/destination > > Fixed, thanks. > > >> + */ > >> + 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; > >> +} > >> + > >> +void set_migration_target_nodes(void) > > > > It seems this function is not called outside migrate.c, so it should be static. > > Fixed, thanks. From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CFB1DC433DB for ; Tue, 2 Feb 2021 17:46:54 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 629F064F86 for ; Tue, 2 Feb 2021 17:46:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 629F064F86 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A68116B0071; Tue, 2 Feb 2021 12:46:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9F1906B0072; Tue, 2 Feb 2021 12:46:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8E0B26B0073; Tue, 2 Feb 2021 12:46:53 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0209.hostedemail.com [216.40.44.209]) by kanga.kvack.org (Postfix) with ESMTP id 74DD06B0071 for ; Tue, 2 Feb 2021 12:46:53 -0500 (EST) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 3B86D1EF1 for ; Tue, 2 Feb 2021 17:46:53 +0000 (UTC) X-FDA: 77774058306.18.sail00_180be9b275cc Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin18.hostedemail.com (Postfix) with ESMTP id 06192100ED9DF for ; Tue, 2 Feb 2021 17:46:52 +0000 (UTC) X-HE-Tag: sail00_180be9b275cc X-Filterd-Recvd-Size: 8172 Received: from mail-ej1-f49.google.com (mail-ej1-f49.google.com [209.85.218.49]) by imf31.hostedemail.com (Postfix) with ESMTP for ; Tue, 2 Feb 2021 17:46:52 +0000 (UTC) Received: by mail-ej1-f49.google.com with SMTP id y9so9695731ejp.10 for ; Tue, 02 Feb 2021 09:46:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ZGI/zcEe0Yt+bxNAd+ZCrR6roUoFCN6DKRYdKgfHGTo=; b=dn0kQpEE8uzdEC3sYSZKK96Y1R4SyTF8SQ++wUCnfT8U7YdqxyodVjFScTsZDUlz2n KXg1Dw+ctFq/Dk2HuQqOumasQ3G3q02khzesSRbG5uN4Ex1jxRPwfgQq7SyPS8eexJcj 0/GfCZpmy+aF81ygQgdOI5YT/qoJNbogDX68XaZy+mqpSgoH8aeK6qAc82a4vH+GPZdR lZ7l6G74LFud0yjEfSEjbtn6W5GDktU+8rXMXfsGDWXCRBcjbriVGr79SHijhun74lqQ LArbTXnvlK5ey46TqSx5UZmskyWGW67xW0k4frniCllwf2pIqDldTzka/QONLnkOz3bp 1F6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ZGI/zcEe0Yt+bxNAd+ZCrR6roUoFCN6DKRYdKgfHGTo=; b=NN6ZdEs2MRR4rXGnrMGJQt4NpmOOlK7C2T00ZezEz+Ghp03MctVs2H4inszeaYfhp4 Ccg3Z3gnkWv4t7HDO9SpRfqyPTYmy8MneWchAtpgKUCQbHm8WjReVkmnhU5Pk19Z+Dsc uK0QazqNu63b0Ld6mSJuk9zmpagGNVEs36eg3MQPuORKCSspamOzKdpApQRtfA9VFaH9 MYd4tCd4v9lfCARwVJlNzcOEd23lis+404vcvfHipVLKO9AlJkGtGfdU+noYpvmLa9mM fjE79rEDcNAcPC+xrAoOrEJveBfLdMwIr7hH53leQeZXcmw8Kqf5HwVYO9KXqlSV4NnE 3q8A== X-Gm-Message-State: AOAM532FVUrGzGcODcJ7EdQnckbmQpDpxROavX6t+Us8VKD2gJQcnlDX XCmiaA7KVktTFYc/jTs1KTndqxHxBHa//3/i2dw= X-Google-Smtp-Source: ABdhPJwswex2voGStCOUsnNL01gx3JAAwJ4/V3+iqItDVUhsO/oc14DWZpKkTcMicL+pke/SiErAG604f5qaxUrOYUw= X-Received: by 2002:a17:906:eddd:: with SMTP id sb29mr14357090ejb.383.1612288011231; Tue, 02 Feb 2021 09:46:51 -0800 (PST) MIME-Version: 1.0 References: <20210126003411.2AC51464@viggo.jf.intel.com> <20210126003421.45897BF4@viggo.jf.intel.com> <317d4c23-76a7-b653-87a4-bab642fa1717@intel.com> In-Reply-To: <317d4c23-76a7-b653-87a4-bab642fa1717@intel.com> From: Yang Shi Date: Tue, 2 Feb 2021 09:46:39 -0800 Message-ID: Subject: Re: [RFC][PATCH 05/13] mm/numa: automatically generate node migration order To: Dave Hansen Cc: Dave Hansen , Linux Kernel Mailing List , Linux MM , Yang Shi , David Rientjes , Huang Ying , Dan Williams , David Hildenbrand , Oscar Salvador Content-Type: text/plain; charset="UTF-8" X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, Feb 1, 2021 at 11:13 AM Dave Hansen wrote: > > On 1/29/21 12:46 PM, Yang Shi wrote: > ... > >> int next_demotion_node(int node) > >> { > >> - return node_demotion[node]; > >> + /* > >> + * node_demotion[] is updated without excluding > >> + * this function from running. READ_ONCE() avoids > >> + * reading multiple, inconsistent 'node' values > >> + * during an update. > >> + */ > > > > Don't we need a smp_rmb() here? The single write barrier might be not > > enough in migration target set. Typically a write barrier should be > > used in pairs with a read barrier. > > I don't think we need one, practically. > > Since there is no locking against node_demotion[] updates, although a > smp_rmb() would ensure that this read is up-to-date, it could change > freely after the smp_rmb(). Yes, but this should be able to guarantee we see "disable + after" state. Isn't it more preferred? > > In other words, smp_rmb() would shrink the window where a "stale" read > could occur but would not eliminate it. > > >> + return READ_ONCE(node_demotion[node]); > > > > Why not consolidate the patch #4 in this patch? The patch #4 just add > > the definition of node_demotion and the function, then the function is > > changed in this patch, and the function is not used by anyone between > > the adding and changing. > > I really wanted to highlight that the locking scheme and the READ_ONCE() > (or lack thereof) was specifically due to how node_demotion[] was being > updated. > > The READ_ONCE() is not, for instance, inherent to the data structure. > > ... > >> +/* > >> + * 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. > > > > Maybe an example diagram for the physical topology and how the > > migration target is generated in the comment seems helpful to > > understand the code. > > Sure. Were you thinking of a code comment, or enhanced changelog? I'd prefer a code comment. > > Let's say there's a system with two sockets each with the same three > classes of memory: fast, medium and slow. Each memory class is placed > in its own NUMA node and the CPUs are attached to the fast memory. That > leaves 6 NUMA nodes (0-5): > > Socket A: 0, 1, 2 > Socket B: 3, 4, 5 > > The migration path for this configuration path would start on the nodes > with the processors and fast memory, progress through medium and end > with the slow memory: > > 0 -> 1 -> 2 -> stop > 3 -> 4 -> 5 -> stop > > This is represented in the node_demotion[] like this: > > { 1, // Node 0 migrates to 1 > 2, // Node 1 migrates to 2 > -1, // Node 2 does not migrate > 4, // Node 3 migrates to 1 > 5, // Node 4 migrates to 2 > -1} // Node 5 does not migrate > > Is that what you were thinking of? Perfect. > > ... > >> +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'. Do this only > >> + * once per pass so that multiple source nodes can > >> + * share a target node. > >> + * > >> + * 'used_targets' will become unavailable in future > >> + * passes. This limits some opportunities for > >> + * multiple source nodes to share a desintation. > > > > s/desination/destination > > Fixed, thanks. > > >> + */ > >> + 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; > >> +} > >> + > >> +void set_migration_target_nodes(void) > > > > It seems this function is not called outside migrate.c, so it should be static. > > Fixed, thanks.