Skip to contentSkip to conversation

rhashtable: compact struct rhashtable_params

PATCH Superseded Florian Westphal 2 participants 2 messages Apr 27, 2017 – May 1, 2017

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rhashtable: compact struct rhashtable_params

By using smaller datatypes this struct shrinks considerably (80 -> 48 bytes on x86_64).

As this is embedded in other structs, this also reduces size of several others, e.g. cls_fl_head and nft_hash.

---
 include/linux/rhashtable.h | 18 +++++++++---------
 lib/rhashtable.c           |  2 +-
 2 files changed, 10 insertions(+), 10 deletions(-)
include/linux/rhashtable.h +9 -9
index 8e628feb8708..77cf43166383 100644
@@ -127,23 +127,23 @@ struct rhashtable;
  * @head_offset: Offset of rhash_head in struct to be hashed
  * @max_size: Maximum size while expanding
  * @min_size: Minimum size while shrinking
- * @nulls_base: Base value to generate nulls marker
- * @automatic_shrinking: Enable automatic shrinking of tables
  * @locks_mul: Number of bucket locks to allocate per cpu (default: 128)
+ * @automatic_shrinking: Enable automatic shrinking of tables
+ * @nulls_base: Base value to generate nulls marker
  * @hashfn: Hash function (default: jhash2 if !(key_len % 4), or jhash)
  * @obj_hashfn: Function to hash object
  * @obj_cmpfn: Function to compare key with object
  */
 struct rhashtable_params {
-	size_t			nelem_hint;
-	size_t			key_len;
-	size_t			key_offset;
-	size_t			head_offset;
+	u16			nelem_hint;
+	u16			key_len;
+	u16			key_offset;
+	u16			head_offset;
 	unsigned int		max_size;
-	unsigned int		min_size;
-	u32			nulls_base;
+	u16			min_size;
 	bool			automatic_shrinking;
-	size_t			locks_mul;
+	u8			locks_mul;
+	u32			nulls_base;
 	rht_hashfn_t		hashfn;
 	rht_obj_hashfn_t	obj_hashfn;
 	rht_obj_cmpfn_t		obj_cmpfn;
lib/rhashtable.c +1 -1
index 1fd7986aa9b4..4462676a26f2 100644
@@ -961,7 +961,7 @@ int rhashtable_init(struct rhashtable *ht,
 	if (params->max_size)
 		ht->p.max_size = rounddown_pow_of_two(params->max_size);
 
-	ht->p.min_size = max(ht->p.min_size, HASH_MIN_SIZE);
+	ht->p.min_size = max_t(u16, ht->p.min_size, HASH_MIN_SIZE);
 
 	if (params->nelem_hint)
 		size = rounded_hashtable_size(&ht->p);
Signature · 1 line
2.10.2
maintainer
#1 lore raw

From: Florian Westphal <[email protected]>
Date: Thu, 27 Apr 2017 17:28:09 +0200

Quoted 7 lines

By using smaller datatypes this struct shrinks considerably (80 -> 48 bytes on x86_64).

As this is embedded in other structs, this also reduces size of several others, e.g. cls_fl_head and nft_hash.

This doesn't apply to net-next cleanly, please respin.

Thanks.