Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp2703317rdb; Mon, 5 Feb 2024 15:16:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IFksCXuOhXKtg2aE52c62hvUL/vCS/GU128ojg1S+jRERuY5ylRLqwwy4O8xc5tHjnNTQ6q X-Received: by 2002:a05:6a00:17a8:b0:6e0:3361:523b with SMTP id s40-20020a056a0017a800b006e03361523bmr877778pfg.29.1707174982162; Mon, 05 Feb 2024 15:16:22 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707174982; cv=pass; d=google.com; s=arc-20160816; b=vrwDXswWfaLEBiM/qdKglsnCWXgUXYFPgIEwygLN08hNE2oIpTGbKx3YbyvNs6uCEZ ekQZD62oPZtgoBpsNIfTK8oLmQ36nu9fwJU+7jCcZe3BbkFxfgV9Z8J98naFfNaesW5J eMv7O4qPQOvIHevTkVUrVQ+TYx5i9gAK3XE1v2IbF6h3r1LO4imHRkvTZBdPgjkvK92Z yltyM29CEXP4GJCqCVjtfI3WIQaT1kSytnDY2NHH7KxWxH4uhNzRbUSTui+Z1Y8Cl2+1 Sh24CGinmgIE1R5M5ca1ph61LhoHwMxZztm4c2bRHq9Qr8mOFyVT8hBlw60sJR4FNRfH pXPA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=HLDVauXDb3SkVjlIiWsDawP2Lrkb7uN8ijdb1ZnT3GM=; fh=rDjpqV0Jj6qDmZeKPZWRTKs1WKdjF7wEMbs022djxPA=; b=LVGtqaQN8QUXgkNSih2LL23OtSPbx70fo3a7nUxnXNCfJCsnTgSulikxotTBdNIOcE gYFEdRebbsTtFO8cwESShygQkO6I4Bx15qZD6Dtb1xrumLvD+oG7Cpe/C1UP+bivBjpj d4YheNTEQokWih+RYEYAwZTpqnvkmj+09aMKon8GFmheUD0S/WYHO0rkehihyTt8xlX1 PNjg9yjZRgHX1pI9ZcHw2VbHBlPuyOg4qby/yC3uFb4rNStp54PInbwgPZNNp57CN+ag gIMJYZ5OhBexMNFC9nVwUKxBpHVWmCfNKs8Qk30rZqbA9KLF2Ozrf8LnaP9doLu9Srzt sSKA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@fromorbit-com.20230601.gappssmtp.com header.s=20230601 header.b=tgmig1Xj; arc=pass (i=1 spf=pass spfdomain=fromorbit.com dkim=pass dkdomain=fromorbit-com.20230601.gappssmtp.com dmarc=pass fromdomain=fromorbit.com); spf=pass (google.com: domain of linux-kernel+bounces-54075-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54075-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=fromorbit.com X-Forwarded-Encrypted: i=1; AJvYcCXm9cw7dMveF8BU40vDNj75eajZfPIg11PTt59EDiYvC3KFzIDcVdZbYamboA1HUQURYnjvjxAhgEGaDYvRi3G04Mz0p8NiFFthBEtDsA== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id c28-20020a630d1c000000b005d8b68b191csi595059pgl.584.2024.02.05.15.16.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 15:16:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54075-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=@fromorbit-com.20230601.gappssmtp.com header.s=20230601 header.b=tgmig1Xj; arc=pass (i=1 spf=pass spfdomain=fromorbit.com dkim=pass dkdomain=fromorbit-com.20230601.gappssmtp.com dmarc=pass fromdomain=fromorbit.com); spf=pass (google.com: domain of linux-kernel+bounces-54075-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54075-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=fromorbit.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 C027928D2EC for ; Mon, 5 Feb 2024 23:16:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 553D24B5CD; Mon, 5 Feb 2024 23:15:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=fromorbit-com.20230601.gappssmtp.com header.i=@fromorbit-com.20230601.gappssmtp.com header.b="tgmig1Xj" Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 E507048786 for ; Mon, 5 Feb 2024 23:15:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707174956; cv=none; b=jPWvWAdWL/WgOUZokCwgcbhaZUa2rLOFYLxT/a6xSmHn49PLeDUIJ+sq6jtAA6PSuKRP/6eHAhfGdjzUtL2KC0i2Ww72ds5fYr8MtKD4bthb3JJ8bS82DWXdV/ulGj9hG/Dif9poUA5KxZIErPhTgldUBW7l5y4prD2Uj0QQAxM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707174956; c=relaxed/simple; bh=l+qBRd0uhtVCBi7FglZtnBJV6a/zqeKohi35eaar3og=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=rNtEAj6HT2OO5CwhXefneJz90CRVnOobSEs5DymJiMea7ZKfeUwzPEcLKNNHyDVBgWk7QLboTnFWl5OtoNT1SO1UwhXFa2VnhQ47WSc458hxf1tMpmJ20bL4qf8gToyWpqLIbD0SfGhC2DG+VpyoL3+g9yfXzSgdlKcRpwHR2po= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=fromorbit.com; spf=pass smtp.mailfrom=fromorbit.com; dkim=pass (2048-bit key) header.d=fromorbit-com.20230601.gappssmtp.com header.i=@fromorbit-com.20230601.gappssmtp.com header.b=tgmig1Xj; arc=none smtp.client-ip=209.85.214.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=fromorbit.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fromorbit.com Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-1d7858a469aso36596385ad.2 for ; Mon, 05 Feb 2024 15:15:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fromorbit-com.20230601.gappssmtp.com; s=20230601; t=1707174954; x=1707779754; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=HLDVauXDb3SkVjlIiWsDawP2Lrkb7uN8ijdb1ZnT3GM=; b=tgmig1XjpNVt8fwZ0rBr+vT+Au5hruM0C3p7k7fB+5NqvqEAWaXANSbNvoqZnHqCHL keZJLMuwTtrtOoUvsZRcWg72EfAwHhPn9tDtrv/cZ+Uav0u+NvU5B3GmDmGDpzeqSnhM FzkUc0MQa35dtE+cRymfw0gT1sRIe731Os53KO+w6gyfxWtJQhWc9Kw7LyyngBGD5sop yBboql/alkdugIkDIlnoWg2xpt2521sFCTyFyopiPnojFbN7pXvwAhjFUWoaUYJQ3WOn bAnPYSURGzIs8G1+h4TYKUohYydq53deqF0GXZ+ooVBOabyrBg5lxxETbAfPsEFbymYE mecg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707174954; x=1707779754; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=HLDVauXDb3SkVjlIiWsDawP2Lrkb7uN8ijdb1ZnT3GM=; b=VPequQa8enq1V5WWGAKr2T8izf0VupdSKUf5YUBdousY0gEaS8xoRlHl1Rra+RO8vf uvph3a6/dhGKIVBxbzDVtsCPk+IXEmQxMHBsIRVh+QwTJZcn71BRrlKK/0zRB5W8QTBs 1h311FU713Fo8M3t9FdJsAG66S49qLEBGQdB+SqDWbocRexDenQrvuQyWiJpfhVrXQat Y6yvcu2E2jTpZul71K8n5yXaGuJQX9VQwnO8bZZ6x0NyqIPPcFT9d29fxS9hvW5+jJKO uboGCHhIusErdIZNv5+x49ipStSE+g1qfgfAU9IcLWdm+fYyGrUh+PS1wQZB9mi50cqI Byow== X-Gm-Message-State: AOJu0YwPE7zpU8cpN4gvQ+Cfa0cmH7I0Cte0UidCfMLYLXxrdG48a5c9 F/bTGE+sV/bpR5uEbmGy8/AsjTQz3nB+dTStgd4fLt5CPSqvnHKt5cw+7mSESq0= X-Received: by 2002:a17:903:1cf:b0:1d9:a4bb:29f2 with SMTP id e15-20020a17090301cf00b001d9a4bb29f2mr720650plh.46.1707174954062; Mon, 05 Feb 2024 15:15:54 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCVg6EM1UWxQB4eSbUussRDKlEYCp9GsHdJ+mKzLNkffYzCq4qGIbm5Fa52ygPxyd12ROmIDr0EhKABFTm7jL0VxvipPjnimMW7859kFnuVmsGOH1hLbPjZQjmD4favBOWTRXCbwPbdTuHneqwjMlmz7qW5Xuseul9RRVQmJA+/UXci5wEhQo68jzK+qP2gUwQzkjB/BPgZng8GYtOhm8L8KdYuqbyW1WOC0qwew+olLEgsRbxzEtWnhVC6GsID24vXEwv50ASkcgyXy9OlkxOJb7nEsvNKjVfySPWR5jthwWt8j6Bm9ZFYf Received: from dread.disaster.area (pa49-181-38-249.pa.nsw.optusnet.com.au. [49.181.38.249]) by smtp.gmail.com with ESMTPSA id kb13-20020a170903338d00b001d9606aac46sm419329plb.212.2024.02.05.15.15.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 15:15:53 -0800 (PST) Received: from dave by dread.disaster.area with local (Exim 4.96) (envelope-from ) id 1rX8Bq-002aEM-3D; Tue, 06 Feb 2024 10:15:51 +1100 Date: Tue, 6 Feb 2024 10:15:50 +1100 From: Dave Chinner To: JonasZhou Cc: willy@infradead.org, CobeChen@zhaoxin.com, JonasZhou@zhaoxin.com, LouisQi@zhaoxin.com, brauner@kernel.org, jack@suse.cz, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, viro@zeniv.linux.org.uk Subject: Re: [PATCH] fs/address_space: move i_mmap_rwsem to mitigate a false sharing with i_mmap. Message-ID: References: <20240205062229.5283-1-jonaszhou-oc@zhaoxin.com> 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=us-ascii Content-Disposition: inline In-Reply-To: <20240205062229.5283-1-jonaszhou-oc@zhaoxin.com> On Mon, Feb 05, 2024 at 02:22:29PM +0800, JonasZhou wrote: > > On Fri, Feb 02, 2024 at 03:03:51PM +0000, Matthew Wilcox wrote: > > > On Fri, Feb 02, 2024 at 05:34:07PM +0800, JonasZhou-oc wrote: > > > > In the struct address_space, there is a 32-byte gap between i_mmap > > > > and i_mmap_rwsem. Due to the alignment of struct address_space > > > > variables to 8 bytes, in certain situations, i_mmap and > > > > i_mmap_rwsem may end up in the same CACHE line. > > > > > > > > While running Unixbench/execl, we observe high false sharing issues > > > > when accessing i_mmap against i_mmap_rwsem. We move i_mmap_rwsem > > > > after i_private_list, ensuring a 64-byte gap between i_mmap and > > > > i_mmap_rwsem. > > > > > > I'm confused. i_mmap_rwsem protects i_mmap. Usually you want the lock > > > and the thing it's protecting in the same cacheline. Why is that not > > > the case here? > > > > We actually had this seven months ago: > > > > https://lore.kernel.org/all/20230628105624.150352-1-lipeng.zhu@intel.com/ > > > > Unfortunately, no argumentation was forthcoming about *why* this was > > the right approach. All we got was a different patch and an assertion > > that it still improved performance. > > > > We need to understand what's going on! Please don't do the same thing > > as the other submitter and just assert that it does. > > When running UnixBench/execl, each execl process repeatedly performs > i_mmap_lock_write -> vma_interval_tree_remove/insert -> > i_mmap_unlock_write. As indicated below, when i_mmap and i_mmap_rwsem > are in the same CACHE Line, there will be more HITM. As I expected, your test is exercising the contention case rather than the single, uncontended case. As such, your patch is simply optimising the structure layout for the contended case at the expense of an extra cacheline miss in the uncontended case. I'm not an mm expert, so I don't know which case we should optimise for. However, the existing code is not obviously wrong, it's just that your micro-benchmark exercises the pathological worst case for the optimisation choices made for this structure. Whether the contention case is worth optimising is the first decision that needs to be made, then people can decide if hacking minor optimisations into the code is better than reworking the locking and/or algorithm to avoid the contention altogether is a better direction... -Dave. -- Dave Chinner david@fromorbit.com