Received: from mail-oo1-f47.google.com (mail-oo1-f47.google.com [209.85.161.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 018E92931E5 for ; Tue, 14 Jul 2026 19:16:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784056619; cv=none; b=gyUudTQVgpZJp56/QxBWgQOd0Bi59NN+rFoElUDmOVBbkfaoZs+NZcYy0P69owVHfaaHESJjy5A7CulcbDiRhISVjlTUp8hJbiOk9vxG0XjjokLe5FV976EB7eua2rsxIsR1j09x8nBkoIb2/sGesai4sgMHWcom8EYc1Cn9aak= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784056619; c=relaxed/simple; bh=ssvZVprKnIEl9GqKycdeDZqVcbpsRfjaM1S6vDr3m+s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sJn63NLjOgPOfv6bMN+WCx2N6Hp5fIKYiHA3TbQIFFd1+ZZNxeNPqs6VoFMY/7+hYiAnRO1LXDhUuA9eZqC9nvKEt2mA4jm9bgfcBKIrr4gvG0vYWzWzPXDGlM0h/g0qjnRIVObbvHx53P3Lg64C0v4qEMZiciidokYNGuwyL18= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Hf8jElD4; arc=none smtp.client-ip=209.85.161.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Hf8jElD4" Received: by mail-oo1-f47.google.com with SMTP id 006d021491bc7-6a2c1edb210so957958eaf.3 for ; Tue, 14 Jul 2026 12:16:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784056615; x=1784661415; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=ox3+tgSJ/1AGA/fdosn/WLv1EiJf5bYFeotrA4JXv6k=; b=Hf8jElD43uWgBJsBps6AUnAOZfY3B8WtUZHQemLmwGTTHmFYHzcQBGPDGJ+Z5V+s4y 14+YXwNwq3mZygsuSH6Kh9K/Wxt5QSxVVF7tz6uwy2736NVKcsX7XIea2j4bgtsZymIw B5Hgvfto/F/3v9qvOP8ycZze+wIDdv9wso472iiYGQ69cWdtBGPURmm+z/QsaKWR609K VFeE1dMmLSphK09RQ3Je4+oBoN4FMwq7j4fA3J/zJd4ZD3eQ3ZNs97XbE0DIEXvmcIBx uJI0iwevOWw32TJ1FpViXMnMzW8dJTp8DORGrEv7V9O2a+pvs5oBx4csGR2pboyIQSfQ Wv6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784056615; x=1784661415; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=ox3+tgSJ/1AGA/fdosn/WLv1EiJf5bYFeotrA4JXv6k=; b=ewctuBkTuGrVoRa1dWnSsLIwxv/OctqIZy/pBzP18ztjB0R/0DvoWXq+JylwNSalXw WevNH0Ki1KQ9wgwRcM4c/Vwy5UQ/OkrYGThHWmVMbKNwNlCydGWy022nKpUFOg6Sjg+u k8kXQ5I5FNXJXEPJu1ysIFun1bqehLk9h/ARtiHMU03W1hS02rqYMkH8vnqpi7Nyrcs5 mLR/PcS25NQlsjOLnOoxrMiC99BHbD2H8eYU5UyMt/3ujmPBr+m8qjTLMRynQVeXWPKZ L0b1POwOVxIt+rl36Seb8IcEql2wUXQ2o7/znjDiO9RolCJYlhjSt29roRdrh2o7DwXQ 33Lw== X-Forwarded-Encrypted: i=1; AFNElJ+7AJIAXL7CtDyd/AmkGFkv89+msE+YCbIk+lGiRmwI/SGX5k4r+wwMu1apqfdYkRplSXlbDm3E48ENuLA=@vger.kernel.org X-Gm-Message-State: AOJu0Yxp+KPSrEq2XyM84EMrACpinimNZ7b2GR3uiO/VTPTpr+31W+ll Hdki2FDG2/pu5ELCFKXkUcoZcxEqpwKN7/m7ExPvx7aVs4vnOxTZX/yXVMpskA== X-Gm-Gg: AfdE7ckIXKzOI4O+jeY1U+wp9h7OLKeXaoCpT8E865hr3EWiSts3Zh96G9fyQ24rz7n zmi0gu4svHM3Jc7vb9/mUmImBwrr2HxCVq/8SJdY7UWoYXwH9tiU2hzK5PeSLjO2oBvFp33CsU+ 8QdHiSQHdM+ivCKBnmFCIZbNab1UxKedGt04ZYT4zLG+nbmMBy25qcRwVbd1XAD6u0SOlp0tmty l4pfPwiNu3Hbw78UvqarWwfDoWkp/h+SwCb/08YP4ffavXxIK1gsO256yrDSBABD39yjBRBxArT Bx3K+jr8Anmk+EatcGHX1a6vtGdO8pZVBVO/y+YAkhie8u0GXMJAsOitnriHECYbQCUKa7ohSj2 +8N6I6uCBR9n8wKsy2MBgUV/UvA5UB4M4WeymNDGmdV6XnaWT4/0jvxNffGoVRyXenTJkdG6hL5 4YG0kNjVfELU0mRqFPw5AteMVRDuEFzfu6FqNZLVhoBA== X-Received: by 2002:a4a:ee19:0:b0:6a3:9853:acdd with SMTP id 006d021491bc7-6a3da002ed6mr39060eaf.33.1784056615491; Tue, 14 Jul 2026 12:16:55 -0700 (PDT) Received: from localhost ([2a03:2880:10ff:a::]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7ebcafdf8f2sm15761350a34.11.2026.07.14.12.16.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jul 2026 12:16:55 -0700 (PDT) From: Joshua Hahn To: "Aneesh Kumar K . V" Cc: linux-mm@kvack.org, Andrew Morton , David Hildenbrand , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , linux-kernel@vger.kernel.org, kernel-team@meta.com Subject: Re: [PATCH] mm/memory-tiers: cache top tier nodes Date: Tue, 14 Jul 2026 12:16:52 -0700 Message-ID: <20260714191653.829251-1-joshua.hahnjy@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit On Sun, 12 Jul 2026 14:13:24 +0530 Aneesh Kumar K.V wrote: > Joshua Hahn writes: > > > node_is_toptier() is called in a few hot paths: task_numa_fault(), > > should_numa_migrate_memory(), folio_migrate_flags(), etc. Each call > > takes an RCU read section and performs the tier distance check again. > > > > Tieredness for all nodes only changes on memory node hotplugs. Instead > > of recomputing toptier nodes inside each of the hot paths above, compute > > it only on memory node hotplug events and cache the results. > > > > Signed-off-by: Joshua Hahn > > --- > > mm/memory-tiers.c | 36 ++++++++++-------------------------- > > 1 file changed, 10 insertions(+), 26 deletions(-) > > > > diff --git a/mm/memory-tiers.c b/mm/memory-tiers.c > > index 54851d8a195b0..2e6e02ec1fce4 100644 > > --- a/mm/memory-tiers.c > > +++ b/mm/memory-tiers.c > > @@ -71,6 +71,7 @@ bool folio_use_access_time(struct folio *folio) > > > > #ifdef CONFIG_NUMA_MIGRATION > > static int top_tier_adistance; > > +static nodemask_t toptier_nodes __read_mostly = NODE_MASK_ALL; > > /* > > * node_demotion[] examples: > > * > > @@ -276,27 +277,7 @@ static struct memory_tier *__node_get_memory_tier(int node) > > #ifdef CONFIG_NUMA_MIGRATION > > bool node_is_toptier(int node) > > { > > - bool toptier; > > - pg_data_t *pgdat; > > - struct memory_tier *memtier; > > - > > - pgdat = NODE_DATA(node); > > - if (!pgdat) > > - return false; > > - > > - rcu_read_lock(); > > - memtier = rcu_dereference(pgdat->memtier); > > - if (!memtier) { > > - toptier = true; > > - goto out; > > - } > > - if (memtier->adistance_start <= top_tier_adistance) > > - toptier = true; > > - else > > - toptier = false; > > -out: > > - rcu_read_unlock(); > > - return toptier; > > + return node_isset(node, toptier_nodes); > > } > > > > void node_get_allowed_targets(pg_data_t *pgdat, nodemask_t *targets) > > @@ -497,19 +478,22 @@ static void establish_demotion_targets(void) > > } > > } > > /* > > - * Now build the lower_tier mask for each node collecting node mask from > > - * all memory tier below it. This allows us to fallback demotion page > > - * allocation to a set of nodes that is closer the above selected > > - * preferred node. > > + * A node stays toptier unless it belongs to a tier below > > + * top_tier_adistance, while each tier's lower_tier_mask collects the > > + * nodes of every tier below it so demotion page allocation can fall > > + * back to nodes closer to the selected preferred node. > > */ > > + toptier_nodes = node_states[N_MEMORY]; Hello Aneesh, thank you very much for your review! > Won't this result in a larger window where every node_is_toptier() call > can return an incorrect result? This change would make every memory node > a top-tier node until the loop below clears them from the toptier_nodes > nodemask. Yes, definitely. I think I should have instead constructed a local nodemask and then swapped it out at the end, I overlooked this part. > I assume an incorrect result from node_is_toptier() is not too bad, but > is the performance impact large enough to make this change? Yes, but I think it's still important to keep it correct. On the notion of performance impact, it's not too big in the upstream kernel, but I'm working on a series that adds more hotpaths that frequently checks whether a folio belongs to a toptier node or not. You can read more about it here [1]. Thank you again for your review, I'll send up a fixed version! Joshua [1] https://lore.kernel.org/all/20260423203445.2914963-1-joshua.hahnjy@gmail.com/