Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp682595pxf; Wed, 7 Apr 2021 09:06:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwPCiXrVBIrXRuZn3b+MaUSw2NFT0xt5pgaQKFCsQkRfS6nmtOI/0VbymzxjklGrOLcoasN X-Received: by 2002:a17:906:8496:: with SMTP id m22mr4482606ejx.313.1617811592791; Wed, 07 Apr 2021 09:06:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617811592; cv=none; d=google.com; s=arc-20160816; b=B0tCg3XN+JXNfjPxOhUB7rYWK5MiR2qVDElT8h9eFYYX0S9RoYxzXk5U7cg2oedlDg jlnizSfC437WzGX9Fdb8//znYsfh5veSrY1Dx0bl5b3VAOzJmBtOyVcg11rQBgR0fPiA VqIjHmL6kWWWr2gO2aKf/gW86mTo2bK8JsOgnDMODIXou/oq86Jjw4hPfjY/+KOj+WmV 31HIg1cl9I8yoP0XYk0zhUMQnW9dAHyQBCd/vCb56tQSf/mtycd9yGgjBtL1abZ6yM2k JGjFujeVjHqpku47T5FNFYedH99i3jU9pfOvrYgdLqbgfEzgcf5mo7/L7AVQ7scXb3Wk +DlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=JcELlbuxWwPI8dfTFSYAOzu9FA0v9IiB9zKDgpWQPYA=; b=bgRqhfrMYw/h6l8wxOTBcOe4T3uo8/NZlp4nvJim+dd+/rKej/fE3xHefL60q7Ua9N CLriEFZYkDJIhgLeWH3MBgtD2sYf9Azvw6PYf518jtxqjCl57JMz5YXCtAI3CQKXKCcf v9QqD70Sgej2Pouta2AtWW1zqyYATS05eBbuUEoLjyIdbF4Cffp6rdSB8rTBfAsUlQbH 6ZlsJvOgYuNhPQsYYe2u615BJwgnNRacerWaoHn1W+hhIKjfiK/DhwsyTiX8y0wPRqWF R8G56QYOIw22DPK6onVvHHxgrjflON7/4Qqn6GS8HVQyHOY0GpzuFi5/0ad36ZPTBjcU DJTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=gaReUITB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b23si8377393eja.608.2021.04.07.09.06.00; Wed, 07 Apr 2021 09:06:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=gaReUITB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229725AbhDFWHC (ORCPT + 99 others); Tue, 6 Apr 2021 18:07:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229687AbhDFWHA (ORCPT ); Tue, 6 Apr 2021 18:07:00 -0400 Received: from mail-qt1-x831.google.com (mail-qt1-x831.google.com [IPv6:2607:f8b0:4864:20::831]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C928C06174A; Tue, 6 Apr 2021 15:06:52 -0700 (PDT) Received: by mail-qt1-x831.google.com with SMTP id u8so12325907qtq.12; Tue, 06 Apr 2021 15:06:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=JcELlbuxWwPI8dfTFSYAOzu9FA0v9IiB9zKDgpWQPYA=; b=gaReUITBmTMOI4qcZIgcKs652nOhD6+Hv2CfiWWBBTmMDncXO03q4NS3QsXcszIgV+ 5SjtB+VXk+8/6dczGDc56/Isgh7qkvdTKQyFPvCsyIK/l6UVz/1BmYPytyl9gWI2+hTW v01BFJelID55zXOVvVUg9nVh9wYdtKE8OXSJ/p/16YibcOwwXXsnd3jurowgJhF0j4ih 9gszRi1cV6BOJ6NPO9dDZHoIb0P1QomVGRW+mu57sIrJ75t6zRAkdbQRjYWQTua9ODzu eaO6a6M3iZ5qN7l/LDRwPGPP95/0Xk1YPu1OspJ/D1/o5tM0u7Hi12UegCMWzllRpW8o yReA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=JcELlbuxWwPI8dfTFSYAOzu9FA0v9IiB9zKDgpWQPYA=; b=JfQUoLYSJmel8xVX8d+bjBJWPN2kE56F+AzlTlbjF3iPBRoUGu1JeuYflK9Lxh+a+T Dka2+ib6IQsJ3oLSPDF0AsRT6xS+fyi5vMfwAC/waVDTEmiCBWqpz6jHYIaK/LUWF/Nc eGRSNZIHBDFFA2hDEJfco3zTauFm3Z2rUpivLwLncrqppk1mPVZXHD0w4Njj5B8vwBpM c58UhZnoBgwo1kmRdPy7MCqHEIDwcPWAzWTL/Eskq6pS1+Be6OaNcu7OMKk07Q88hQO3 /eCBhivelg1XqXtlzaxgjp375nldowi0xp/axX9/hy8j3EgsY9pxF9CtV7NB6VMhUyS3 CX6w== X-Gm-Message-State: AOAM531mb/4inPVqkryCQJNsr/ej5FMt6pwXu2zP4Lc7AqZS8vgg7zYe iXI25jpbb167PogMMzv70+vp8Wx0QvwY X-Received: by 2002:a05:622a:d3:: with SMTP id p19mr129254qtw.53.1617746811782; Tue, 06 Apr 2021 15:06:51 -0700 (PDT) Received: from moria.home.lan (c-73-219-103-14.hsd1.vt.comcast.net. [73.219.103.14]) by smtp.gmail.com with ESMTPSA id n24sm15388135qtr.21.2021.04.06.15.06.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Apr 2021 15:06:51 -0700 (PDT) Date: Tue, 6 Apr 2021 18:06:49 -0400 From: Kent Overstreet To: Dave Chinner Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/3] vfs: factor out inode hash head calculation Message-ID: References: <20210406123343.1739669-1-david@fromorbit.com> <20210406123343.1739669-2-david@fromorbit.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210406123343.1739669-2-david@fromorbit.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 06, 2021 at 10:33:41PM +1000, Dave Chinner wrote: > From: Dave Chinner > > In preparation for changing the inode hash table implementation. > > Signed-off-by: Dave Chinner Reviewed-by: Kent Overstreet > --- > fs/inode.c | 44 +++++++++++++++++++++++++------------------- > 1 file changed, 25 insertions(+), 19 deletions(-) > > diff --git a/fs/inode.c b/fs/inode.c > index a047ab306f9a..b8d9eb3454dc 100644 > --- a/fs/inode.c > +++ b/fs/inode.c > @@ -60,6 +60,22 @@ static unsigned int i_hash_shift __read_mostly; > static struct hlist_head *inode_hashtable __read_mostly; > static __cacheline_aligned_in_smp DEFINE_SPINLOCK(inode_hash_lock); > > +static unsigned long hash(struct super_block *sb, unsigned long hashval) > +{ > + unsigned long tmp; > + > + tmp = (hashval * (unsigned long)sb) ^ (GOLDEN_RATIO_PRIME + hashval) / > + L1_CACHE_BYTES; > + tmp = tmp ^ ((tmp ^ GOLDEN_RATIO_PRIME) >> i_hash_shift); > + return tmp & i_hash_mask; > +} > + > +static inline struct hlist_head *i_hash_head(struct super_block *sb, > + unsigned int hashval) > +{ > + return inode_hashtable + hash(sb, hashval); > +} > + > /* > * Empty aops. Can be used for the cases where the user does not > * define any of the address_space operations. > @@ -475,16 +491,6 @@ static inline void inode_sb_list_del(struct inode *inode) > } > } > > -static unsigned long hash(struct super_block *sb, unsigned long hashval) > -{ > - unsigned long tmp; > - > - tmp = (hashval * (unsigned long)sb) ^ (GOLDEN_RATIO_PRIME + hashval) / > - L1_CACHE_BYTES; > - tmp = tmp ^ ((tmp ^ GOLDEN_RATIO_PRIME) >> i_hash_shift); > - return tmp & i_hash_mask; > -} > - > /** > * __insert_inode_hash - hash an inode > * @inode: unhashed inode > @@ -1073,7 +1079,7 @@ struct inode *inode_insert5(struct inode *inode, unsigned long hashval, > int (*test)(struct inode *, void *), > int (*set)(struct inode *, void *), void *data) > { > - struct hlist_head *head = inode_hashtable + hash(inode->i_sb, hashval); > + struct hlist_head *head = i_hash_head(inode->i_sb, hashval); > struct inode *old; > bool creating = inode->i_state & I_CREATING; > > @@ -1173,7 +1179,7 @@ EXPORT_SYMBOL(iget5_locked); > */ > struct inode *iget_locked(struct super_block *sb, unsigned long ino) > { > - struct hlist_head *head = inode_hashtable + hash(sb, ino); > + struct hlist_head *head = i_hash_head(sb, ino); > struct inode *inode; > again: > spin_lock(&inode_hash_lock); > @@ -1241,7 +1247,7 @@ EXPORT_SYMBOL(iget_locked); > */ > static int test_inode_iunique(struct super_block *sb, unsigned long ino) > { > - struct hlist_head *b = inode_hashtable + hash(sb, ino); > + struct hlist_head *b = i_hash_head(sb, ino); > struct inode *inode; > > hlist_for_each_entry_rcu(inode, b, i_hash) { > @@ -1328,7 +1334,7 @@ EXPORT_SYMBOL(igrab); > struct inode *ilookup5_nowait(struct super_block *sb, unsigned long hashval, > int (*test)(struct inode *, void *), void *data) > { > - struct hlist_head *head = inode_hashtable + hash(sb, hashval); > + struct hlist_head *head = i_hash_head(sb, hashval); > struct inode *inode; > > spin_lock(&inode_hash_lock); > @@ -1383,7 +1389,7 @@ EXPORT_SYMBOL(ilookup5); > */ > struct inode *ilookup(struct super_block *sb, unsigned long ino) > { > - struct hlist_head *head = inode_hashtable + hash(sb, ino); > + struct hlist_head *head = i_hash_head(sb, ino); > struct inode *inode; > again: > spin_lock(&inode_hash_lock); > @@ -1432,7 +1438,7 @@ struct inode *find_inode_nowait(struct super_block *sb, > void *), > void *data) > { > - struct hlist_head *head = inode_hashtable + hash(sb, hashval); > + struct hlist_head *head = i_hash_head(sb, hashval); > struct inode *inode, *ret_inode = NULL; > int mval; > > @@ -1477,7 +1483,7 @@ EXPORT_SYMBOL(find_inode_nowait); > struct inode *find_inode_rcu(struct super_block *sb, unsigned long hashval, > int (*test)(struct inode *, void *), void *data) > { > - struct hlist_head *head = inode_hashtable + hash(sb, hashval); > + struct hlist_head *head = i_hash_head(sb, hashval); > struct inode *inode; > > RCU_LOCKDEP_WARN(!rcu_read_lock_held(), > @@ -1515,7 +1521,7 @@ EXPORT_SYMBOL(find_inode_rcu); > struct inode *find_inode_by_ino_rcu(struct super_block *sb, > unsigned long ino) > { > - struct hlist_head *head = inode_hashtable + hash(sb, ino); > + struct hlist_head *head = i_hash_head(sb, ino); > struct inode *inode; > > RCU_LOCKDEP_WARN(!rcu_read_lock_held(), > @@ -1535,7 +1541,7 @@ int insert_inode_locked(struct inode *inode) > { > struct super_block *sb = inode->i_sb; > ino_t ino = inode->i_ino; > - struct hlist_head *head = inode_hashtable + hash(sb, ino); > + struct hlist_head *head = i_hash_head(sb, ino); > > while (1) { > struct inode *old = NULL; > -- > 2.31.0 >