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 19enum { 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) 29struct 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 41struct 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 55struct 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 68void zram_group_meta_free(struct zram_group *zgrp); 69struct zram_group *zram_group_meta_alloc(u32 nr_obj, u32 nr_grp); 70void zgrp_obj_insert(struct zram_group *zgrp, u32 index, u16 gid); 71bool zgrp_obj_delete(struct zram_group *zgrp, u32 index, u16 gid); 72u32 zgrp_isolate_objs(struct zram_group *zgrp, u16 gid, u32 *idxs, u32 nr, bool *last); 73bool zgrp_obj_is_isolated(struct zram_group *zgrp, u32 index); 74void zgrp_obj_putback(struct zram_group *zgrp, u32 index, u16 gid); 75void zgrp_obj_stats_inc(struct zram_group *zgrp, u16 gid, u32 size); 76void zgrp_obj_stats_dec(struct zram_group *zgrp, u16 gid, u32 size); 77void zgrp_fault_stats_inc(struct zram_group *zgrp, u16 gid, u32 size); 78 79#ifdef CONFIG_ZRAM_GROUP_DEBUG 80void zram_group_dump(struct zram_group *zgrp, u16 gid, u32 index); 81#endif 82 83#ifdef CONFIG_ZRAM_GROUP_WRITEBACK 84void zram_group_remove_writeback(struct zram_group *zgrp); 85int zram_group_apply_writeback(struct zram_group *zgrp, u32 nr_ext); 86void zgrp_ext_insert(struct zram_group *zgrp, u32 eid, u16 gid); 87bool zgrp_ext_delete(struct zram_group *zgrp, u32 eid, u16 gid); 88u32 zgrp_isolate_exts(struct zram_group *zgrp, u16 gid, u32 *eids, u32 nr, bool *last); 89void zgrp_get_ext(struct zram_group *zgrp, u32 eid); 90bool zgrp_put_ext(struct zram_group *zgrp, u32 eid); 91void wbgrp_obj_insert(struct zram_group *zgrp, u32 index, u32 eid); 92bool wbgrp_obj_delete(struct zram_group *zgrp, u32 index, u32 eid); 93u32 wbgrp_isolate_objs(struct zram_group *zgrp, u32 eid, u32 *idxs, u32 nr, bool *last); 94void wbgrp_obj_stats_inc(struct zram_group *zgrp, u16 gid, u32 eid, u32 size); 95void wbgrp_obj_stats_dec(struct zram_group *zgrp, u16 gid, u32 eid, u32 size); 96void wbgrp_fault_stats_inc(struct zram_group *zgrp, u16 gid, u32 eid, u32 size); 97#endif 98#endif 99