Received: by 2002:a05:7412:8d11:b0:fa:4934:9f with SMTP id bj17csp327000rdb; Sun, 14 Jan 2024 20:15:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IGG0XMjNu5j+939tfxc2n4f+eFRuOUZi83ROCSp6/nApcoeZl23oNeboVVoZxl39zeMXc8t X-Received: by 2002:a17:906:13c5:b0:a27:c856:d889 with SMTP id g5-20020a17090613c500b00a27c856d889mr2008375ejc.81.1705292129483; Sun, 14 Jan 2024 20:15:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705292129; cv=none; d=google.com; s=arc-20160816; b=GRKfdObpV1YRoMeyPptxfeNWVfiS63z77Hr5CXHzky8VVQdZzIUmloK1FMtKMxSrs2 EsEyJuuDGDJ3HQF4Vw6NOEFS9tf06s0sPVkaM5VMl6GVAffYqyLIzLnF0mroI4hyNIMO vxzaWp0jLhtmHnK74MpkkaWMWc0iUO+xGejhohG6m7HSXXI5SuvuQCS0sngrIwG/JrN0 wD6o00/XulMjn51cdX2/LDBwwbpH0E6kExoUnEx0pouiFzMukmi/okR/JllsYX0gEwy+ a/rik4g9yJwRVt93oXUE9nnPbUNPUSBzsJm3ERUQUoyScWinUMycgafl1Pon453abUic b/xQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:message-id:date:references:in-reply-to:subject:cc:to :from:dkim-signature; bh=i4OFXuIwcLt6vpkF87NvTYgnQ4Ps5vGKNy1EqmxfTqg=; fh=ryrXa84VX89n22zX2+jTSENKzqG95+HCTwKDwkJ9jek=; b=GgXRg9pfBcVfdXrzwe4GPmVzqvEhMJ2XdWG2fzA6KG8j/PvpcA36lSDfjFndkg8N2p xD/YxoJsewQPNaEZxg5/BJyP95PX2SbRKtqf6d7hd7Phk/50e+T/p2BSPeP6pvE9Iogb hdZSwMVJU1tB+muvhaBPQI+eemNEjqcpmhWuQ1EfpwEaAAzcHspMhYdxHhQPuHpQ7noK NDIdKCFO6cnJ9t5+UvcXdOmyoQ9RFvAjFP9iyn8XOHqz2nkq0DREe5391nylReajlz1v NH7iZLW4yOfzphfpCOP/KHz9kNegbJgPG5KcdWwG3Py70nFqfaY7c/tfRr5BACjUl9xX 8EYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=VvsjGS18; spf=pass (google.com: domain of linux-kernel+bounces-25613-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-25613-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id g9-20020a17090613c900b00a2c9f8cb856si2669023ejc.90.2024.01.14.20.15.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Jan 2024 20:15:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-25613-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=VvsjGS18; spf=pass (google.com: domain of linux-kernel+bounces-25613-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-25613-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id D53D61F21494 for ; Mon, 15 Jan 2024 04:15:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7C9C823BF; Mon, 15 Jan 2024 04:15:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="VvsjGS18" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5E62E1FAA; Mon, 15 Jan 2024 04:15:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1705292110; x=1736828110; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version; bh=7Qsp5bzx6xNs/s0xoZ3nIM0bf+kfLf2cz6nQNuDrFsc=; b=VvsjGS18RWlYBnsJZBVB3KKejYEY43vSAZ5jNrW8c/ySlB0oAEvMpefX 7ILL2nEj6jYeak5fdRC1GaBpRzsoVqS2MGGgDymqhBlAy9Fc8xxGOpjnU Eka9VCAgFoYgrmLUz/5aawYYYy6LV5abM4Q68gp+DaBOGHpHh9LSJqI9U /aZVQW5TGf0NHlWCQC7czfv/7kPCCtFylTwab5OJux/44HQky8NSsakzZ S2cdxcW4GSSOUdM0Jb46G2RGO5lTDvKW3VxwwDzcK0iHt1ECPFnfgTty2 UtXQTdiLwmhZA/qsjO9uuVhX0Iu7I3fKXS0fTOoGTFtj639MWBFPSq8xp Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10953"; a="6625112" X-IronPort-AV: E=Sophos;i="6.04,195,1695711600"; d="scan'208";a="6625112" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jan 2024 20:15:09 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10953"; a="786969049" X-IronPort-AV: E=Sophos;i="6.04,195,1695711600"; d="scan'208";a="786969049" Received: from yhuang6-desk2.sh.intel.com (HELO yhuang6-desk2.ccr.corp.intel.com) ([10.238.208.55]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jan 2024 20:15:03 -0800 From: "Huang, Ying" To: Gregory Price Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, corbet@lwn.net, akpm@linux-foundation.org, gregory.price@memverge.com, honggyu.kim@sk.com, rakie.kim@sk.com, hyeongtak.ji@sk.com, mhocko@kernel.org, vtavarespetr@micron.com, jgroves@micron.com, ravis.opensrc@micron.com, sthanneeru@micron.com, emirakhur@micron.com, Hasan.Maruf@amd.com, seungjun.ha@samsung.com, hannes@cmpxchg.org, dan.j.williams@intel.com Subject: Re: [PATCH 2/3] mm/mempolicy: refactor a read-once mechanism into a function for re-use In-Reply-To: <20240112210834.8035-3-gregory.price@memverge.com> (Gregory Price's message of "Fri, 12 Jan 2024 16:08:33 -0500") References: <20240112210834.8035-1-gregory.price@memverge.com> <20240112210834.8035-3-gregory.price@memverge.com> Date: Mon, 15 Jan 2024 12:13:06 +0800 Message-ID: <87h6jf1bfx.fsf@yhuang6-desk2.ccr.corp.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=ascii Gregory Price writes: > move the use of barrier() to force policy->nodemask onto the stack into > a function `read_once_policy_nodemask` so that it may be re-used. > > Suggested-by: Huang Ying > Signed-off-by: Gregory Price > --- > mm/mempolicy.c | 26 ++++++++++++++++---------- > 1 file changed, 16 insertions(+), 10 deletions(-) > > diff --git a/mm/mempolicy.c b/mm/mempolicy.c > index 5da4fd79fd18..0abd3a3394ef 100644 > --- a/mm/mempolicy.c > +++ b/mm/mempolicy.c > @@ -1907,6 +1907,20 @@ unsigned int mempolicy_slab_node(void) > } > } > > +static unsigned int read_once_policy_nodemask(struct mempolicy *pol, > + nodemask_t *mask) It may be more useful if we define this as memcpy_once(). That can be used not only for nodemask, but also other data structure. > +{ > + /* > + * barrier stabilizes the nodemask locally so that it can be iterated > + * over safely without concern for changes. Allocators validate node > + * selection does not violate mems_allowed, so this is safe. > + */ > + barrier(); > + __builtin_memcpy(mask, &pol->nodes, sizeof(nodemask_t)); We don't use __builtin_memcpy() in kernel itself directly. Although it is used in kernel tools. So, I think it's better to use memcpy() here. > + barrier(); > + return nodes_weight(*mask); > +} > + > /* > * Do static interleaving for interleave index @ilx. Returns the ilx'th > * node in pol->nodes (starting from ilx=0), wrapping around if ilx > @@ -1914,20 +1928,12 @@ unsigned int mempolicy_slab_node(void) > */ > static unsigned int interleave_nid(struct mempolicy *pol, pgoff_t ilx) > { > - nodemask_t nodemask = pol->nodes; > + nodemask_t nodemask; > unsigned int target, nnodes; > int i; > int nid; > - /* > - * The barrier will stabilize the nodemask in a register or on > - * the stack so that it will stop changing under the code. > - * > - * Between first_node() and next_node(), pol->nodes could be changed > - * by other threads. So we put pol->nodes in a local stack. > - */ > - barrier(); > > - nnodes = nodes_weight(nodemask); > + nnodes = read_once_policy_nodemask(pol, &nodemask); > if (!nnodes) > return numa_node_id(); > target = ilx % nnodes; -- Best Regards, Huang, Ying