18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * drivers/block/zram/zram_group/zram_group.h 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (c) 2020-2022 Huawei Technologies Co., Ltd. 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#ifndef _ZRAM_GROUP_H_ 98c2ecf20Sopenharmony_ci#define _ZRAM_GROUP_H_ 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#include <linux/kernel.h> 128c2ecf20Sopenharmony_ci#include <linux/mutex.h> 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci#include "zlist.h" 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci#define ZGRP_MAX_GRP USHRT_MAX 178c2ecf20Sopenharmony_ci#define ZGRP_MAX_OBJ (1 << 30) 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_cienum { 208c2ecf20Sopenharmony_ci ZGRP_NONE = 0, 218c2ecf20Sopenharmony_ci ZGRP_TRACK, 228c2ecf20Sopenharmony_ci#ifdef CONFIG_ZRAM_GROUP_WRITEBACK 238c2ecf20Sopenharmony_ci ZGRP_WRITE, 248c2ecf20Sopenharmony_ci#endif 258c2ecf20Sopenharmony_ci}; 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci#ifdef CONFIG_ZRAM_GROUP_WRITEBACK 288c2ecf20Sopenharmony_ci#define ZGRP_MAX_EXT (ZLIST_IDX_MAX - ZGRP_MAX_GRP - ZGRP_MAX_OBJ) 298c2ecf20Sopenharmony_cistruct writeback_group { 308c2ecf20Sopenharmony_ci bool enable; 318c2ecf20Sopenharmony_ci u32 nr_ext; 328c2ecf20Sopenharmony_ci struct zlist_node *grp_ext_head; 338c2ecf20Sopenharmony_ci struct zlist_node *ext; 348c2ecf20Sopenharmony_ci struct zlist_table *ext_tab; 358c2ecf20Sopenharmony_ci struct zlist_node *ext_obj_head; 368c2ecf20Sopenharmony_ci struct mutex init_lock; 378c2ecf20Sopenharmony_ci wait_queue_head_t fault_wq; 388c2ecf20Sopenharmony_ci}; 398c2ecf20Sopenharmony_ci#endif 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_cistruct zram_group_stats { 428c2ecf20Sopenharmony_ci atomic64_t zram_size; 438c2ecf20Sopenharmony_ci atomic_t zram_pages; 448c2ecf20Sopenharmony_ci atomic64_t zram_fault; 458c2ecf20Sopenharmony_ci#ifdef CONFIG_ZRAM_GROUP_WRITEBACK 468c2ecf20Sopenharmony_ci atomic64_t wb_size; 478c2ecf20Sopenharmony_ci atomic_t wb_pages; 488c2ecf20Sopenharmony_ci atomic64_t wb_fault; 498c2ecf20Sopenharmony_ci atomic_t wb_exts; 508c2ecf20Sopenharmony_ci atomic64_t write_size; 518c2ecf20Sopenharmony_ci atomic64_t read_size; 528c2ecf20Sopenharmony_ci#endif 538c2ecf20Sopenharmony_ci}; 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_cistruct zram_group { 568c2ecf20Sopenharmony_ci u32 nr_obj; 578c2ecf20Sopenharmony_ci u32 nr_grp; 588c2ecf20Sopenharmony_ci struct zlist_node *grp_obj_head; 598c2ecf20Sopenharmony_ci struct zlist_node *obj; 608c2ecf20Sopenharmony_ci struct zlist_table *obj_tab; 618c2ecf20Sopenharmony_ci#ifdef CONFIG_ZRAM_GROUP_WRITEBACK 628c2ecf20Sopenharmony_ci struct writeback_group wbgrp; 638c2ecf20Sopenharmony_ci#endif 648c2ecf20Sopenharmony_ci struct group_swap_device *gsdev; 658c2ecf20Sopenharmony_ci struct zram_group_stats *stats; 668c2ecf20Sopenharmony_ci}; 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_civoid zram_group_meta_free(struct zram_group *zgrp); 698c2ecf20Sopenharmony_cistruct zram_group *zram_group_meta_alloc(u32 nr_obj, u32 nr_grp); 708c2ecf20Sopenharmony_civoid zgrp_obj_insert(struct zram_group *zgrp, u32 index, u16 gid); 718c2ecf20Sopenharmony_cibool zgrp_obj_delete(struct zram_group *zgrp, u32 index, u16 gid); 728c2ecf20Sopenharmony_ciu32 zgrp_isolate_objs(struct zram_group *zgrp, u16 gid, u32 *idxs, u32 nr, bool *last); 738c2ecf20Sopenharmony_cibool zgrp_obj_is_isolated(struct zram_group *zgrp, u32 index); 748c2ecf20Sopenharmony_civoid zgrp_obj_putback(struct zram_group *zgrp, u32 index, u16 gid); 758c2ecf20Sopenharmony_civoid zgrp_obj_stats_inc(struct zram_group *zgrp, u16 gid, u32 size); 768c2ecf20Sopenharmony_civoid zgrp_obj_stats_dec(struct zram_group *zgrp, u16 gid, u32 size); 778c2ecf20Sopenharmony_civoid zgrp_fault_stats_inc(struct zram_group *zgrp, u16 gid, u32 size); 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci#ifdef CONFIG_ZRAM_GROUP_DEBUG 808c2ecf20Sopenharmony_civoid zram_group_dump(struct zram_group *zgrp, u16 gid, u32 index); 818c2ecf20Sopenharmony_ci#endif 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci#ifdef CONFIG_ZRAM_GROUP_WRITEBACK 848c2ecf20Sopenharmony_civoid zram_group_remove_writeback(struct zram_group *zgrp); 858c2ecf20Sopenharmony_ciint zram_group_apply_writeback(struct zram_group *zgrp, u32 nr_ext); 868c2ecf20Sopenharmony_civoid zgrp_ext_insert(struct zram_group *zgrp, u32 eid, u16 gid); 878c2ecf20Sopenharmony_cibool zgrp_ext_delete(struct zram_group *zgrp, u32 eid, u16 gid); 888c2ecf20Sopenharmony_ciu32 zgrp_isolate_exts(struct zram_group *zgrp, u16 gid, u32 *eids, u32 nr, bool *last); 898c2ecf20Sopenharmony_civoid zgrp_get_ext(struct zram_group *zgrp, u32 eid); 908c2ecf20Sopenharmony_cibool zgrp_put_ext(struct zram_group *zgrp, u32 eid); 918c2ecf20Sopenharmony_civoid wbgrp_obj_insert(struct zram_group *zgrp, u32 index, u32 eid); 928c2ecf20Sopenharmony_cibool wbgrp_obj_delete(struct zram_group *zgrp, u32 index, u32 eid); 938c2ecf20Sopenharmony_ciu32 wbgrp_isolate_objs(struct zram_group *zgrp, u32 eid, u32 *idxs, u32 nr, bool *last); 948c2ecf20Sopenharmony_civoid wbgrp_obj_stats_inc(struct zram_group *zgrp, u16 gid, u32 eid, u32 size); 958c2ecf20Sopenharmony_civoid wbgrp_obj_stats_dec(struct zram_group *zgrp, u16 gid, u32 eid, u32 size); 968c2ecf20Sopenharmony_civoid wbgrp_fault_stats_inc(struct zram_group *zgrp, u16 gid, u32 eid, u32 size); 978c2ecf20Sopenharmony_ci#endif 988c2ecf20Sopenharmony_ci#endif 99