diff mbox series

[1/3] frontswap: support backing_dev

Message ID 20230710221659.2473460-2-minchan@kernel.org (mailing list archive)
State New
Headers show
Series zram: use frontswap for zram swap usecase | expand

Commit Message

Minchan Kim July 10, 2023, 10:16 p.m. UTC
Modify frontswap to be used as a block device driver for swap
partitions.

Signed-off-by: Minchan Kim <minchan@kernel.org>
---
 include/linux/frontswap.h | 7 +++++--
 mm/frontswap.c            | 4 ++--
 mm/swapfile.c             | 3 ++-
 mm/zswap.c                | 2 +-
 4 files changed, 10 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
index eaa0ac5f9003..466d617dc3c7 100644
--- a/include/linux/frontswap.h
+++ b/include/linux/frontswap.h
@@ -7,8 +7,10 @@ 
 #include <linux/bitops.h>
 #include <linux/jump_label.h>
 
+struct block_device;
+
 struct frontswap_ops {
-	void (*init)(unsigned); /* this swap type was just swapon'ed */
+	void (*init)(unsigned, struct block_device *); /* this swap type was just swapon'ed */
 	int (*store)(unsigned, pgoff_t, struct page *); /* store a page */
 	int (*load)(unsigned, pgoff_t, struct page *, bool *); /* load a page */
 	void (*invalidate_page)(unsigned, pgoff_t); /* page no longer needed */
@@ -17,7 +19,8 @@  struct frontswap_ops {
 
 int frontswap_register_ops(const struct frontswap_ops *ops);
 
-extern void frontswap_init(unsigned type, unsigned long *map);
+extern void frontswap_init(unsigned type, unsigned long *map,
+			   struct block_device *bdev);
 extern int __frontswap_store(struct page *page);
 extern int __frontswap_load(struct page *page);
 extern void __frontswap_invalidate_page(unsigned, pgoff_t);
diff --git a/mm/frontswap.c b/mm/frontswap.c
index 2fb5df3384b8..967ce610a1de 100644
--- a/mm/frontswap.c
+++ b/mm/frontswap.c
@@ -107,7 +107,7 @@  int frontswap_register_ops(const struct frontswap_ops *ops)
 /*
  * Called when a swap device is swapon'd.
  */
-void frontswap_init(unsigned type, unsigned long *map)
+void frontswap_init(unsigned type, unsigned long *map, struct block_device *bdev)
 {
 	struct swap_info_struct *sis = swap_info[type];
 
@@ -128,7 +128,7 @@  void frontswap_init(unsigned type, unsigned long *map)
 
 	if (!frontswap_enabled())
 		return;
-	frontswap_ops->init(type);
+	frontswap_ops->init(type, bdev);
 }
 
 static bool __frontswap_test(struct swap_info_struct *sis,
diff --git a/mm/swapfile.c b/mm/swapfile.c
index a6945c2e0d03..a9424fd226bc 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -2339,7 +2339,8 @@  static void enable_swap_info(struct swap_info_struct *p, int prio,
 				unsigned long *frontswap_map)
 {
 	if (IS_ENABLED(CONFIG_FRONTSWAP))
-		frontswap_init(p->type, frontswap_map);
+		frontswap_init(p->type, frontswap_map, p->bdev);
+
 	spin_lock(&swap_lock);
 	spin_lock(&p->lock);
 	setup_swap_info(p, prio, swap_map, cluster_info);
diff --git a/mm/zswap.c b/mm/zswap.c
index c122f042a49d..9247e3adc21f 100644
--- a/mm/zswap.c
+++ b/mm/zswap.c
@@ -1510,7 +1510,7 @@  static void zswap_frontswap_invalidate_area(unsigned type)
 	zswap_trees[type] = NULL;
 }
 
-static void zswap_frontswap_init(unsigned type)
+static void zswap_frontswap_init(unsigned type, struct block_device *bdev)
 {
 	struct zswap_tree *tree;