18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * fs/hmdfs/client_writeback.h 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (c) 2020-2021 Huawei Device Co., Ltd. 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#ifndef CLIENT_WRITEBACK_H 98c2ecf20Sopenharmony_ci#define CLIENT_WRITEBACK_H 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#include "hmdfs.h" 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci/* 148c2ecf20Sopenharmony_ci * HM_DEFAULT_WRITEBACK_INTERVAL - centiseconds 158c2ecf20Sopenharmony_ci * HMDFS_FILE_BG_WB_BYTES - background per-file threshold 10M 168c2ecf20Sopenharmony_ci * HMDFS_FS_BG_WB_BYTES - background per-fs threshold 50M 178c2ecf20Sopenharmony_ci * HMDFS_FILE_WB_BYTES - per-file throttle threshold 188c2ecf20Sopenharmony_ci * HMDFS_FS_WB_BYTES - per-fs throttle threshold 198c2ecf20Sopenharmony_ci */ 208c2ecf20Sopenharmony_ci#define HM_DEFAULT_WRITEBACK_INTERVAL 500 218c2ecf20Sopenharmony_ci#define HMDFS_FILE_BG_WB_BYTES (10 * 1024 * 1024) 228c2ecf20Sopenharmony_ci#define HMDFS_FS_BG_WB_BYTES (50 * 1024 * 1024) 238c2ecf20Sopenharmony_ci#define HMDFS_FILE_WB_BYTES (HMDFS_FILE_BG_WB_BYTES << 1) 248c2ecf20Sopenharmony_ci#define HMDFS_FS_WB_BYTES (HMDFS_FS_BG_WB_BYTES << 1) 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci/* writeback time limit (default 5s) */ 278c2ecf20Sopenharmony_ci#define HMDFS_DEF_WB_TIMELIMIT (5 * HZ) 288c2ecf20Sopenharmony_ci#define HMDFS_MAX_WB_TIMELIMIT (30 * HZ) 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci/* bandwidth adjusted lower limit (default 1MB/s) */ 318c2ecf20Sopenharmony_ci#define HMDFS_BW_THRESH_MIN_LIMIT (1 << (20 - PAGE_SHIFT)) 328c2ecf20Sopenharmony_ci#define HMDFS_BW_THRESH_MAX_LIMIT (100 << (20 - PAGE_SHIFT)) 338c2ecf20Sopenharmony_ci#define HMDFS_BW_THRESH_DEF_LIMIT HMDFS_BW_THRESH_MIN_LIMIT 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci#define HMDFS_DIRTY_EXCEED_RATELIMIT (32 >> (PAGE_SHIFT - 10)) 368c2ecf20Sopenharmony_ci#define HMDFS_RATELIMIT_PAGES_GAP 16 378c2ecf20Sopenharmony_ci#define HMDFS_DEF_RATELIMIT_PAGES 32 388c2ecf20Sopenharmony_ci#define HMDFS_MIN_RATELIMIT_PAGES 1 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_cistruct hmdfs_dirty_throttle_control { 418c2ecf20Sopenharmony_ci struct hmdfs_writeback *hwb; 428c2ecf20Sopenharmony_ci /* last time threshes are updated */ 438c2ecf20Sopenharmony_ci unsigned long thresh_time_stamp; 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci unsigned long file_bg_thresh; 468c2ecf20Sopenharmony_ci unsigned long fs_bg_thresh; 478c2ecf20Sopenharmony_ci unsigned long file_thresh; 488c2ecf20Sopenharmony_ci unsigned long fs_thresh; 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci unsigned long file_nr_dirty; 518c2ecf20Sopenharmony_ci unsigned long fs_nr_dirty; 528c2ecf20Sopenharmony_ci unsigned long file_nr_reclaimable; 538c2ecf20Sopenharmony_ci unsigned long fs_nr_reclaimable; 548c2ecf20Sopenharmony_ci}; 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_cistruct hmdfs_writeback { 578c2ecf20Sopenharmony_ci struct hmdfs_sb_info *sbi; 588c2ecf20Sopenharmony_ci struct bdi_writeback *wb; 598c2ecf20Sopenharmony_ci /* enable hmdfs dirty writeback control */ 608c2ecf20Sopenharmony_ci bool dirty_writeback_control; 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci /* writeback per-file inode list */ 638c2ecf20Sopenharmony_ci struct list_head inode_list_head; 648c2ecf20Sopenharmony_ci spinlock_t inode_list_lock; 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci /* centiseconds */ 678c2ecf20Sopenharmony_ci unsigned int dirty_writeback_interval; 688c2ecf20Sopenharmony_ci /* per-file background threshold */ 698c2ecf20Sopenharmony_ci unsigned long dirty_file_bg_bytes; 708c2ecf20Sopenharmony_ci unsigned long dirty_file_bg_thresh; 718c2ecf20Sopenharmony_ci /* per-fs background threshold */ 728c2ecf20Sopenharmony_ci unsigned long dirty_fs_bg_bytes; 738c2ecf20Sopenharmony_ci unsigned long dirty_fs_bg_thresh; 748c2ecf20Sopenharmony_ci /* per-file throttle threshold */ 758c2ecf20Sopenharmony_ci unsigned long dirty_file_bytes; 768c2ecf20Sopenharmony_ci unsigned long dirty_file_thresh; 778c2ecf20Sopenharmony_ci /* per-fs throttle threshold */ 788c2ecf20Sopenharmony_ci unsigned long dirty_fs_bytes; 798c2ecf20Sopenharmony_ci unsigned long dirty_fs_thresh; 808c2ecf20Sopenharmony_ci /* ratio between background thresh and throttle thresh */ 818c2ecf20Sopenharmony_ci unsigned long fs_bg_ratio; 828c2ecf20Sopenharmony_ci unsigned long file_bg_ratio; 838c2ecf20Sopenharmony_ci /* ratio between file and fs throttle thresh */ 848c2ecf20Sopenharmony_ci unsigned long fs_file_ratio; 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci /* 878c2ecf20Sopenharmony_ci * Enable auto-thresh. If enabled, the background and throttle 888c2ecf20Sopenharmony_ci * thresh are nolonger a fixed value storeed in dirty_*_bytes, 898c2ecf20Sopenharmony_ci * they are determined by the bandwidth of the network and the 908c2ecf20Sopenharmony_ci * writeback timelimit. 918c2ecf20Sopenharmony_ci */ 928c2ecf20Sopenharmony_ci bool dirty_auto_threshold; 938c2ecf20Sopenharmony_ci unsigned int writeback_timelimit; 948c2ecf20Sopenharmony_ci /* bandwitdh adjusted filesystem throttle thresh */ 958c2ecf20Sopenharmony_ci unsigned long bw_fs_thresh; 968c2ecf20Sopenharmony_ci /* bandwidth adjusted per-file throttle thresh */ 978c2ecf20Sopenharmony_ci unsigned long bw_file_thresh; 988c2ecf20Sopenharmony_ci /* bandwidth adjusted thresh lower limit */ 998c2ecf20Sopenharmony_ci unsigned long bw_thresh_lowerlimit; 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ci /* reclaimable pages exceed throttle thresh */ 1028c2ecf20Sopenharmony_ci bool dirty_exceeded; 1038c2ecf20Sopenharmony_ci /* percpu dirty pages ratelimit */ 1048c2ecf20Sopenharmony_ci long ratelimit_pages; 1058c2ecf20Sopenharmony_ci /* count percpu dirty pages */ 1068c2ecf20Sopenharmony_ci int __percpu *bdp_ratelimits; 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_ci /* per-fs writeback work */ 1098c2ecf20Sopenharmony_ci struct workqueue_struct *dirty_sb_writeback_wq; 1108c2ecf20Sopenharmony_ci struct delayed_work dirty_sb_writeback_work; 1118c2ecf20Sopenharmony_ci /* per-file writeback work */ 1128c2ecf20Sopenharmony_ci struct workqueue_struct *dirty_inode_writeback_wq; 1138c2ecf20Sopenharmony_ci struct delayed_work dirty_inode_writeback_work; 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci /* per-fs writeback bandwidth */ 1168c2ecf20Sopenharmony_ci spinlock_t write_bandwidth_lock; 1178c2ecf20Sopenharmony_ci unsigned long max_write_bandwidth; 1188c2ecf20Sopenharmony_ci unsigned long min_write_bandwidth; 1198c2ecf20Sopenharmony_ci unsigned long avg_write_bandwidth; 1208c2ecf20Sopenharmony_ci}; 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_civoid hmdfs_writeback_inodes_sb_handler(struct work_struct *work); 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_civoid hmdfs_writeback_inode_handler(struct work_struct *work); 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_civoid hmdfs_calculate_dirty_thresh(struct hmdfs_writeback *hwb); 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_civoid hmdfs_update_ratelimit(struct hmdfs_writeback *hwb); 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_civoid hmdfs_balance_dirty_pages_ratelimited(struct address_space *mapping); 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_civoid hmdfs_destroy_writeback(struct hmdfs_sb_info *sbi); 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_ciint hmdfs_init_writeback(struct hmdfs_sb_info *sbi); 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci#endif 137