• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * drivers/block/zram/zram_group/zram_group.h
4  *
5  * Copyright (c) 2020-2022 Huawei Technologies Co., Ltd.
6  */
7 
8 #ifndef _ZRAM_GROUP_H_
9 #define _ZRAM_GROUP_H_
10 
11 #include <linux/kernel.h>
12 #include <linux/mutex.h>
13 
14 #include "zlist.h"
15 
16 #define ZGRP_MAX_GRP USHRT_MAX
17 #define ZGRP_MAX_OBJ (1 << 30)
18 
19 enum {
20 	ZGRP_NONE = 0,
21 	ZGRP_TRACK,
22 #ifdef CONFIG_ZRAM_GROUP_WRITEBACK
23 	ZGRP_WRITE,
24 #endif
25 };
26 
27 #ifdef CONFIG_ZRAM_GROUP_WRITEBACK
28 #define ZGRP_MAX_EXT (ZLIST_IDX_MAX - ZGRP_MAX_GRP - ZGRP_MAX_OBJ)
29 struct writeback_group {
30 	bool enable;
31 	u32 nr_ext;
32 	struct zlist_node *grp_ext_head;
33 	struct zlist_node *ext;
34 	struct zlist_table *ext_tab;
35 	struct zlist_node *ext_obj_head;
36 	struct mutex init_lock;
37 	wait_queue_head_t fault_wq;
38 };
39 #endif
40 
41 struct zram_group_stats {
42 	atomic64_t zram_size;
43 	atomic_t zram_pages;
44 	atomic64_t zram_fault;
45 #ifdef CONFIG_ZRAM_GROUP_WRITEBACK
46 	atomic64_t wb_size;
47 	atomic_t wb_pages;
48 	atomic64_t wb_fault;
49 	atomic_t wb_exts;
50 	atomic64_t write_size;
51 	atomic64_t read_size;
52 #endif
53 };
54 
55 struct zram_group {
56 	u32 nr_obj;
57 	u32 nr_grp;
58 	struct zlist_node *grp_obj_head;
59 	struct zlist_node *obj;
60 	struct zlist_table *obj_tab;
61 #ifdef CONFIG_ZRAM_GROUP_WRITEBACK
62 	struct writeback_group wbgrp;
63 #endif
64 	struct group_swap_device *gsdev;
65 	struct zram_group_stats *stats;
66 };
67 
68 void zram_group_meta_free(struct zram_group *zgrp);
69 struct zram_group *zram_group_meta_alloc(u32 nr_obj, u32 nr_grp);
70 void zgrp_obj_insert(struct zram_group *zgrp, u32 index, u16 gid);
71 bool zgrp_obj_delete(struct zram_group *zgrp, u32 index, u16 gid);
72 u32 zgrp_isolate_objs(struct zram_group *zgrp, u16 gid,	u32 *idxs, u32 nr, bool *last);
73 bool zgrp_obj_is_isolated(struct zram_group *zgrp, u32 index);
74 void zgrp_obj_putback(struct zram_group *zgrp, u32 index, u16 gid);
75 void zgrp_obj_stats_inc(struct zram_group *zgrp, u16 gid, u32 size);
76 void zgrp_obj_stats_dec(struct zram_group *zgrp, u16 gid, u32 size);
77 void zgrp_fault_stats_inc(struct zram_group *zgrp, u16 gid, u32 size);
78 
79 #ifdef CONFIG_ZRAM_GROUP_DEBUG
80 void zram_group_dump(struct zram_group *zgrp, u16 gid, u32 index);
81 #endif
82 
83 #ifdef CONFIG_ZRAM_GROUP_WRITEBACK
84 void zram_group_remove_writeback(struct zram_group *zgrp);
85 int zram_group_apply_writeback(struct zram_group *zgrp, u32 nr_ext);
86 void zgrp_ext_insert(struct zram_group *zgrp, u32 eid, u16 gid);
87 bool zgrp_ext_delete(struct zram_group *zgrp, u32 eid, u16 gid);
88 u32 zgrp_isolate_exts(struct zram_group *zgrp, u16 gid, u32 *eids, u32 nr, bool *last);
89 void zgrp_get_ext(struct zram_group *zgrp, u32 eid);
90 bool zgrp_put_ext(struct zram_group *zgrp, u32 eid);
91 void wbgrp_obj_insert(struct zram_group *zgrp, u32 index, u32 eid);
92 bool wbgrp_obj_delete(struct zram_group *zgrp, u32 index, u32 eid);
93 u32 wbgrp_isolate_objs(struct zram_group *zgrp, u32 eid, u32 *idxs, u32 nr, bool *last);
94 void wbgrp_obj_stats_inc(struct zram_group *zgrp, u16 gid, u32 eid, u32 size);
95 void wbgrp_obj_stats_dec(struct zram_group *zgrp, u16 gid, u32 eid, u32 size);
96 void wbgrp_fault_stats_inc(struct zram_group *zgrp, u16 gid, u32 eid, u32 size);
97 #endif
98 #endif
99