Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1544093rdb; Wed, 31 Jan 2024 01:39:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IF5+mofKY2GqVJI0ZiK5aL6EjMPZnASQD6fLs5/mKbldUyWGOT72yBJnvVEWw66cNfgx2Px X-Received: by 2002:a9d:4d0b:0:b0:6dd:ec89:1e79 with SMTP id n11-20020a9d4d0b000000b006ddec891e79mr855319otf.22.1706693988207; Wed, 31 Jan 2024 01:39:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706693988; cv=pass; d=google.com; s=arc-20160816; b=fztuIshnditR7osZBsGUTn/weiBqY/LYns/p15uwwbGEa/zcpvA6cxUCjZrLsu01Vi PLAOh3ZdcDP3LkPYl/TMw2M7unP3L18Na3d+kD9Yk4z6g6cCKaoAW5O0xZZbCp8qPyfr QC5cNFb3E8iINZmqftnDWRDBvS7YtLm6bTH3FCc4lnw4gc5XXZa+hRzBdP4y3wlayUN7 Cah+/HdOPiAGj0eI0bz1a83qL0e0iQWzhPHk50FFCQzFJhPR1w0a5rrUAs7y8Ih8N2/J VV5/6IkJ1UmYycPxsA8DidbsM4MBBZ2zVQ3/+LMUkgqXQyuTY3buIWDRZC+TRYGQdkhZ XeHw== ARC-Message-Signature: i=2; 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=qQ9tEr4YW1sl4QOEdLADkqv9jsTAisR2aLGCJeaidBM=; fh=koMF0+/y+Zee2AfEFhieOW9icFqCwDzxmt/TW+GqKG8=; b=mDIe2PphGgH4FOZY2653KgbF2sK1SIOIZw3lwLDG5qWGGbha3vIntLwj6cKdylVM8D yvyH6BqPDqoDrXvj07C059G+SMjIuEnpQURz7xiCptGhY3wLiPYw/95jYOt7l2Hb8m2D +FBL9xBXPfgsbZbAHtxnmYRHBgCb80slmCs5d7hTOr3rNE0CJLN6dIABkkbnMzyObBwP b5Zo5z3qKR0CpTI7nc9KjaUztgYbKAPhWpposFKS/1dOJEZu4zOTOPavTN2KxYR+t2TE c/9Br6hwwYkkUwUmazKtmfiN/i/EAYa5vDdJ9KSIDG+9FFR9B3a22M1au0KvRtZ1yOcJ BO5w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="Wohi/Frx"; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-46128-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46128-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=1; AJvYcCUrMULuLtaxfzZ909fPpQPrAGWas4p2DrKZKBPhKPMTep6CkGN/eejxNs5S51y3ydn0q6psbXOYrt7UH7Mp2ZeIvOZsqmt//5vEGSoHVA== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id o15-20020a637e4f000000b005d8bb44b20bsi6948605pgn.564.2024.01.31.01.39.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 01:39:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-46128-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="Wohi/Frx"; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-46128-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46128-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id A7934296CC0 for ; Wed, 31 Jan 2024 09:22:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9D1456775E; Wed, 31 Jan 2024 09:22:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Wohi/Frx" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.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 000A260885; Wed, 31 Jan 2024 09:22:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.13 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706692928; cv=none; b=J8UJQ5KBv7R7jCcenqwVp4qz+5O1XFaVcfJap4fz6IhcQI5zaQNECnfagKWT/O+8HJYjskkyJLiWA8+zMc8M0nVveTzJmz7tdBhVqaDR+3v0+IcTj5MrZANH7JGMK3cY3246j4ZZyjJZGRPDhdfFRbCgEVBZqEBPC9cfy+snBYE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706692928; c=relaxed/simple; bh=CIUpGUXPv7s5EVwneVuhL8R9G3KLULjDTGG/TKf9KI0=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=C9bZLv4lchSpi5+CYuxQyK7QyqMP3rgimvDaz+cNzAdEM2NpuhRPiqzax3/H24hfWVwEs2/y5j+qzHpgBTcpHXdtn97038XWgNAQco8R5rCiDLD8fH1W3ZQEfKcEXK+sH5v9n4GLyiJQy/sCv2xZl3bEKXdzswxBKa3at8uTfUI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Wohi/Frx; arc=none smtp.client-ip=192.198.163.13 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=1706692927; x=1738228927; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version; bh=CIUpGUXPv7s5EVwneVuhL8R9G3KLULjDTGG/TKf9KI0=; b=Wohi/FrxDs8Yw8IVCJP877C7l70mB6IXxfzpTxQsRRncNWkrsxzmckIO 7hucbdRJQ72RB5VUtwJpNV+LbLL5jG9qZHTR0QfUi+sG0prPe5HPLCqlS cgCSa998yKOmK9ofOdrrMSCj1x9NmrtdhXYGAtK0DXiGXwzE3o7ZR/cNm UqkZlfWrzaUdno3VdwOejzNtCjUYWH2yLs4OBgPqatu09Y7CVBKiPpHVF Hp0GRlGh49HrNQDxwMtmcrjQJ/rxuSka88NLXrgwub1bnEpEs6dXzvOpl 6Lx5tiBAbMiS/JGprmhHDUHa++nfXxdIVo3zypXJ1iKUPO9MRo8TeQmqc Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10969"; a="2480966" X-IronPort-AV: E=Sophos;i="6.05,231,1701158400"; d="scan'208";a="2480966" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Jan 2024 01:21:54 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10969"; a="738034755" X-IronPort-AV: E=Sophos;i="6.05,231,1701158400"; d="scan'208";a="738034755" Received: from yhuang6-desk2.sh.intel.com (HELO yhuang6-desk2.ccr.corp.intel.com) ([10.238.208.55]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Jan 2024 01:21:47 -0800 From: "Huang, Ying" To: Gregory Price Cc: Gregory Price , , , , , , , , , , , , , , , , , , , , , Srinivasulu Thanneeru Subject: Re: [PATCH v4 3/3] mm/mempolicy: introduce MPOL_WEIGHTED_INTERLEAVE for weighted interleaving In-Reply-To: (Gregory Price's message of "Wed, 31 Jan 2024 02:43:16 -0500") References: <20240130182046.74278-1-gregory.price@memverge.com> <20240130182046.74278-4-gregory.price@memverge.com> <877cjqgfzz.fsf@yhuang6-desk2.ccr.corp.intel.com> Date: Wed, 31 Jan 2024 17:19:51 +0800 Message-ID: <87y1c5g8qw.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: > On Wed, Jan 31, 2024 at 02:43:12PM +0800, Huang, Ying wrote: >> Gregory Price writes: >> > >> > +static unsigned int weighted_interleave_nodes(struct mempolicy *policy) >> > +{ >> > + unsigned int node = current->il_prev; >> > + >> > + if (!current->il_weight || !node_isset(node, policy->nodes)) { >> > + node = next_node_in(node, policy->nodes); >> > + /* can only happen if nodemask is being rebound */ >> > + if (node == MAX_NUMNODES) >> > + return node; >> >> I feel a little unsafe to read policy->nodes at same time of writing in >> rebound. Is it better to use a seqlock to guarantee its consistency? >> It's unnecessary to be a part of this series though. >> > > I think this is handled already? It is definitely an explicit race > condition that is documented elsewhere: > > /* > * mpol_rebind_policy - Migrate a policy to a different set of nodes > * > * Per-vma policies are protected by mmap_lock. Allocations using per-task > * policies are protected by task->mems_allowed_seq to prevent a premature > * OOM/allocation failure due to parallel nodemask modification. > */ Thanks for pointing this out! If we use task->mems_allowed_seq reader side in weighted_interleave_nodes() we can guarantee the consistency of policy->nodes. That may be not deserved, because it's not a big deal to allocate 1 page in a wrong node. It makes more sense to do that in alloc_pages_bulk_array_weighted_interleave(), because a lot of pages may be allocated there. > example from slub: > > do { > cpuset_mems_cookie = read_mems_allowed_begin(); > zonelist = node_zonelist(mempolicy_slab_node(), pc->flags); > ... > } while (read_mems_allowed_retry(cpuset_mems_cookie)); > > quick perusal through other allocators, show similar checks. > > page_alloc.c - check_retry_cpusetset() > filemap.c - filemap_alloc_folio() > > If we ever want mempolicy to be swappable from outside the current task > context, this will have to change most likely - but that's another > feature for another day. > -- Best Regards, Huang, Ying