[PATCH v5 24/35] list_lru.h: move declarations to list_lru_types.h

From: Max Kellermann
Date: Mon Feb 12 2024 - 06:59:51 EST


By providing declarations in a lean header, we can reduce header
dependencies.

Signed-off-by: Max Kellermann <max.kellermann@xxxxxxxxx>
---
fs/super.c | 1 +
include/linux/fs.h | 2 +-
include/linux/list_lru.h | 36 +----------------------------
include/linux/list_lru_types.h | 42 ++++++++++++++++++++++++++++++++++
4 files changed, 45 insertions(+), 36 deletions(-)
create mode 100644 include/linux/list_lru_types.h

diff --git a/fs/super.c b/fs/super.c
index 2ab97cc49374..6a8cc1c49940 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -34,6 +34,7 @@
#include <linux/rculist_bl.h>
#include <linux/fscrypt.h>
#include <linux/fsnotify.h>
+#include <linux/list_lru.h>
#include <linux/lockdep.h>
#include <linux/user_namespace.h>
#include <linux/fs_context.h>
diff --git a/include/linux/fs.h b/include/linux/fs.h
index c5ea7eb41bca..c2e21611496e 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -10,7 +10,7 @@
#include <linux/stat.h>
#include <linux/cache.h>
#include <linux/list.h>
-#include <linux/list_lru.h>
+#include <linux/list_lru_types.h>
#include <linux/llist.h>
#include <linux/xarray.h>
#include <linux/rbtree.h>
diff --git a/include/linux/list_lru.h b/include/linux/list_lru.h
index 5e8cd106dae4..bb348492037f 100644
--- a/include/linux/list_lru.h
+++ b/include/linux/list_lru.h
@@ -8,14 +8,10 @@
#ifndef _LRU_LIST_H
#define _LRU_LIST_H

-#include <linux/list.h>
+#include <linux/list_lru_types.h>
#include <linux/nodemask.h>
#include <linux/shrinker.h>

-#ifdef CONFIG_MEMCG_KMEM
-#include <linux/xarray_types.h>
-#endif
-
struct mem_cgroup;

/* list_lru_walk_cb has to always return one of those */
@@ -31,36 +27,6 @@ enum lru_status {
internally, but has to return locked. */
};

-struct list_lru_one {
- struct list_head list;
- /* may become negative during memcg reparenting */
- long nr_items;
-};
-
-struct list_lru_memcg {
- struct rcu_head rcu;
- /* array of per cgroup per node lists, indexed by node id */
- struct list_lru_one node[];
-};
-
-struct list_lru_node {
- /* protects all lists on the node, including per cgroup */
- spinlock_t lock;
- /* global list, used for the root cgroup in cgroup aware lrus */
- struct list_lru_one lru;
- long nr_items;
-} ____cacheline_aligned_in_smp;
-
-struct list_lru {
- struct list_lru_node *node;
-#ifdef CONFIG_MEMCG_KMEM
- struct list_head list;
- int shrinker_id;
- bool memcg_aware;
- struct xarray xa;
-#endif
-};
-
void list_lru_destroy(struct list_lru *lru);
int __list_lru_init(struct list_lru *lru, bool memcg_aware,
struct lock_class_key *key, struct shrinker *shrinker);
diff --git a/include/linux/list_lru_types.h b/include/linux/list_lru_types.h
new file mode 100644
index 000000000000..51ccef0d6994
--- /dev/null
+++ b/include/linux/list_lru_types.h
@@ -0,0 +1,42 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LRU_LIST_TYPES_H
+#define _LRU_LIST_TYPES_H
+
+#include <linux/list.h>
+
+#ifdef CONFIG_MEMCG_KMEM
+#include <linux/types.h> // for bool
+#include <linux/xarray_types.h>
+#endif
+
+struct list_lru_one {
+ struct list_head list;
+ /* may become negative during memcg reparenting */
+ long nr_items;
+};
+
+struct list_lru_memcg {
+ struct rcu_head rcu;
+ /* array of per cgroup per node lists, indexed by node id */
+ struct list_lru_one node[];
+};
+
+struct list_lru_node {
+ /* protects all lists on the node, including per cgroup */
+ spinlock_t lock;
+ /* global list, used for the root cgroup in cgroup aware lrus */
+ struct list_lru_one lru;
+ long nr_items;
+} ____cacheline_aligned_in_smp;
+
+struct list_lru {
+ struct list_lru_node *node;
+#ifdef CONFIG_MEMCG_KMEM
+ struct list_head list;
+ int shrinker_id;
+ bool memcg_aware;
+ struct xarray xa;
+#endif
+};
+
+#endif /* _LRU_LIST_TYPES_H */
--
2.39.2