Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp865810lqp; Thu, 21 Mar 2024 19:40:28 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVE3rVMkigS9TXHG8CY6cTC0Cb2FYkmlw+/ug//IaWUk9TfRvpPf/zXR5/IpNAgVFnubWmrugnNWI6D6SDSw2gMGujl2jJQpnL5aHnY0A== X-Google-Smtp-Source: AGHT+IHCL/pwy5tu8TIP8OxpgpY68ewUEcAXUlrAdhdynhP8CMj9ePlKFv71HS0lz7Xtms6Er7ZM X-Received: by 2002:a05:6a00:1388:b0:6e6:b4e5:d878 with SMTP id t8-20020a056a00138800b006e6b4e5d878mr1693854pfg.1.1711075227799; Thu, 21 Mar 2024 19:40:27 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711075227; cv=pass; d=google.com; s=arc-20160816; b=nw/d0+LF5qWqUWb2AxpZUNmYb3O85azM68kqrHzJHAT9+Kga7qSdEgSzB04a5rFfkr YyFQwGoSPukcKVziXYGnDkar8HD4yrtDZTAAbrOshndZ9IbWubmnXa8BOAUazqL7m3CR uvIy0Umsptpx2N22+WNJlHjZF1y4Kp/FwivLyJAV5BhRME6WQ7A/Xe/I1bHSTQDLBh1/ UsuzXnCwevYRXPmvNQV62xlVYUU5c+bFcjTOtfyhgUz0b0//y5JF5Vo8JPrT8tnZ5/B0 IU6ujZjAjXfC1ccBtI3UBUBoNQtr86vVkHnyUxpJM+QEToT+jpYuDshrTUn6Xis1HLPW nG8A== 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=OVAeBSmUtQa1X9FCqE2V2M5WyxVQa1ANrsNJNdUNjkE=; fh=TxfUfV4ivNLvpSQHyrzP5l6AP6hnfOGhSfhOtEztySA=; b=xverR+ypUJ4yH5GrdR6RHyjKxOh7YxA6K087KxsNPML4gUY3+5mwBYqe8jJQ9LMQv2 Lczl9m87+rnTW5h0pAslOfz4XLU/A8C64PpwUifr01tree+bOmut0OGF76CLpekRGUGp gj3w6kXkGYRzqQ7MI/a9Af6AjM6l5fwRgggmyDhwAb5iWNU+qZXxqJDTn/Z3hS0Eep8O ViMYluC3Fzq8c6LYj1Tgs4vnhZOTQdG4CZNY1pCaMF+J7h2yDbWI1r0IfY5KZ89IsbSr DB5DWmmZqnP/L41DQMSwLw6HucQWkfLYQvtHDbJakFO7LndtVYIWd1OyN9RDHKDG+NVa HzKg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=hvAwU9GN; 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-110885-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-110885-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 34-20020a630f62000000b005dc4fca7d3csi1022166pgp.200.2024.03.21.19.40.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 19:40:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-110885-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=hvAwU9GN; 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-110885-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-110885-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 79099285DB8 for ; Fri, 22 Mar 2024 02:40:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 18BF04C69; Fri, 22 Mar 2024 02:40:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="hvAwU9GN" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 9BF873D6D for ; Fri, 22 Mar 2024 02:40:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711075220; cv=none; b=F9KCX5fx5AHnpA2En/mdjoPUSh8cVYS30tp+/2sfxWqjyMUb96ZB1xvyU439A3gvDc/GRSD0OSFsiDgghmkUHbrdyr7NNydLmu/fCZqyLwl5LPIaDrQU3FbYksOrR4nVF5VuTa2HYYRTglRrqnbhwsSN+M0dClqQp+j+H7K4BPU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711075220; c=relaxed/simple; bh=SKFE/yv9BlwXNs2v+wBuGnWL2pZl/FThKVv5URfkHyA=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=c4gH/iwCL7wB0IeKYjcbMOWPT1cujCiTnl52/OrAQaHERW5Hh7oQzUI7UBloyfDlAuhvnEboh3veY75MmFeSZ1pvOVKwy6mx9VJhIvj5hFjuf/ILOcFGXgpBFp/Cy5cwCuX2cpMApFcqtCsovixYL8NoglVlbfa5FlLBEOYpuec= 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=hvAwU9GN; arc=none smtp.client-ip=198.175.65.19 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=1711075219; x=1742611219; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version; bh=SKFE/yv9BlwXNs2v+wBuGnWL2pZl/FThKVv5URfkHyA=; b=hvAwU9GN2Ctzfa8Xiy50uDfajRa5UJVNn2/Dv9fMW7yn+fK/5GiuQHLU AaxFCqTXRCs87iPdDR8FY2hOzkHtpMBHw/H06BBkSIX8fNL0QmRAuIfRw OGHEzKxxOz+S+yJWBbQeIoDAsHOIiWPPp9us0J6jjHbeKsKSQsSGXgg/1 wjejCwLHmUvKnHyLph/5G1L0K74b3yD5fLKjTjx7TMoHTzpn+E+fx/RKw edpZQicfrC/BL+yzOw1zs48Dte5a50Wrw5YCdhl8hRX7u182qO/NASX8m nUngysibrBdEXl0L4g/bEdZKvz++UxmJe9Wk6OBk/m5ED4HBqLayg3eyQ w==; X-IronPort-AV: E=McAfee;i="6600,9927,11020"; a="5972581" X-IronPort-AV: E=Sophos;i="6.07,144,1708416000"; d="scan'208";a="5972581" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Mar 2024 19:40:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,144,1708416000"; d="scan'208";a="15151100" Received: from yhuang6-desk2.sh.intel.com (HELO yhuang6-desk2.ccr.corp.intel.com) ([10.238.208.55]) by orviesa007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Mar 2024 19:40:14 -0700 From: "Huang, Ying" To: "Paul E. McKenney" Cc: Ryan Roberts , Andrew Morton , David Hildenbrand , Matthew Wilcox , Gao Xiang , Yu Zhao , Yang Shi , Michal Hocko , Kefeng Wang , Barry Song <21cnbao@gmail.com>, Chris Li , , Subject: Can you help us on memory barrier usage? (was Re: [PATCH v4 4/6] mm: swap: Allow storage of all mTHP orders) In-Reply-To: (Ryan Roberts's message of "Thu, 21 Mar 2024 12:21:46 +0000") References: <20240311150058.1122862-1-ryan.roberts@arm.com> <20240311150058.1122862-5-ryan.roberts@arm.com> <87jzm751n3.fsf@yhuang6-desk2.ccr.corp.intel.com> <8734skryev.fsf@yhuang6-desk2.ccr.corp.intel.com> Date: Fri, 22 Mar 2024 10:38:20 +0800 Message-ID: <87r0g3q9cz.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 Hi, Paul, Can you help us on WRITE_ONCE()/READ_ONCE()/barrier() usage as follows? For some example kernel code as follows, " unsigned char x[16]; void writer(void) { memset(x, 1, sizeof(x)); /* To make memset() take effect ASAP */ barrier(); } unsigned char reader(int n) { return READ_ONCE(x[n]); } " where, writer() and reader() may be called on 2 CPUs without any lock. It's acceptable for reader() to read the written value a little later. Our questions are, 1. because it's impossible for accessing "unsigned char" to cause tearing. So, WRITE_ONCE()/READ_ONCE()/barrier() isn't necessary for correctness, right? 2. we use barrier() and READ_ONCE() in writer() and reader(), because we want to make writing take effect ASAP. Is it a good practice? Or it's a micro-optimization that should be avoided? -- Best Regards, Huang, Ying