Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp6096970rwr; Tue, 9 May 2023 10:08:28 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5dABFGoBN9K0mdE6ZMBGZgvIy8+Zk1B7qYp0W3JDINdyjK5fXNKBRcWYitd8DxDRRZVdzq X-Received: by 2002:a17:903:230e:b0:1ab:19f6:ef0f with SMTP id d14-20020a170903230e00b001ab19f6ef0fmr23506976plh.33.1683652107726; Tue, 09 May 2023 10:08:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683652107; cv=none; d=google.com; s=arc-20160816; b=rXBUtMdtDYOPH7zKsdbfvFSbDKJTgwYUq8SJ2Iw3u4TVmwzFB7xgJ/wPiMsxA82wGq caDuWEjxcXNb0ezghCZ1D78YrrcaxI8sIZM1XUBQlC9hLm1Gfm9TsPQW4+IacT1uRtIw xpAfiSvQgiZsneOeSpnZjcnoXpTgn0cq4QU+HHXE2cUUfZDIopbHWmgJeRA7oEF0mzED 0bmYeycTCdA75Y4Keguc7VbnQWZ3NnigCtCbC99Xj2SlE4+07wAvH9rv6GyWfDCXNGKM cZjo8A1rLswrn1ZxmoQFbeZUZQW81EsGMBPyGmosbaf+dtJI625RLYyTjzsJyj8iC0SZ eJDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=KXhu0IMdhm7TtmY2sdq2+bF9aYr9Sm4xuSQ9rgukQdg=; b=ZO4LEksu0F6opm4tYeiQ94NtqbTLJVVhoEXavY9CNp9eFX1HBElxrRmJxPpiTlw6ko TXeUFvWkGF9wjS7bLZpm4z4NDGwWfQbGMe4k82vFvfHyrrM4nPBkOZ17sYglgQUMXQjK mjkxfzwBHkN5BnDhTx3ym14zMBq6qMFgrh6MSf52URKfnYtKcRT+6mQmYw9hyrMZDINp qwkTJV6RNKMIF962I4A+taSKPVD+z011mGf2tYmy5u+DGu4z8Hl7CqUNZuUHC6wWz/gx Nj0Lt/G27OV5pJBRZWs9Pq2uLNiZuKiW8bSrSNj1JUWuikoShFrj+jghn3FrgmsgRbIz PJpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Gra0g7cw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h184-20020a636cc1000000b005304a8af2a2si718698pgc.404.2023.05.09.10.08.14; Tue, 09 May 2023 10:08:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Gra0g7cw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235015AbjEIQ70 (ORCPT + 99 others); Tue, 9 May 2023 12:59:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235013AbjEIQ6W (ORCPT ); Tue, 9 May 2023 12:58:22 -0400 Received: from out-20.mta1.migadu.com (out-20.mta1.migadu.com [95.215.58.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4908D525A for ; Tue, 9 May 2023 09:57:31 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1683651449; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KXhu0IMdhm7TtmY2sdq2+bF9aYr9Sm4xuSQ9rgukQdg=; b=Gra0g7cwhAqneFL51O788e/pMmLPbI05SL6bok25hYVdGn18I9cy8a3/KaT30uAxdqDTg2 SwDp+NtsmF5P0jw2xQkDhJ119T+9qju9K5I1q2D1uNjkIsQLuqoYRp9CqKmmQkS3AeA8xk Xg784HuVcBpPfrJnLnMCeN2m26D7MRs= From: Kent Overstreet To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-bcachefs@vger.kernel.org Cc: Dave Chinner , Alexander Viro , Christian Brauner , Kent Overstreet Subject: [PATCH 20/32] vfs: factor out inode hash head calculation Date: Tue, 9 May 2023 12:56:45 -0400 Message-Id: <20230509165657.1735798-21-kent.overstreet@linux.dev> In-Reply-To: <20230509165657.1735798-1-kent.overstreet@linux.dev> References: <20230509165657.1735798-1-kent.overstreet@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dave Chinner In preparation for changing the inode hash table implementation. Signed-off-by: Dave Chinner Cc: Alexander Viro Cc: Christian Brauner Cc: linux-fsdevel@vger.kernel.org Signed-off-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 4558dc2f13..41a10bcda1 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. @@ -506,16 +522,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 @@ -1163,7 +1169,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; again: @@ -1267,7 +1273,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); @@ -1335,7 +1341,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) { @@ -1422,7 +1428,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); @@ -1477,7 +1483,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); @@ -1526,7 +1532,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; @@ -1571,7 +1577,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(), @@ -1609,7 +1615,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(), @@ -1629,7 +1635,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.40.1