mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-11-25 15:20:53 +07:00
f0054bb1e1
Currently, a bdi (backing_dev_info) embeds single wb (bdi_writeback) and the role of the separation is unclear. For cgroup support for writeback IOs, a bdi will be updated to host multiple wb's where each wb serves writeback IOs of a different cgroup on the bdi. To achieve that, a wb should carry all states necessary for servicing writeback IOs for a cgroup independently. This patch moves bdi->wb_lock and ->worklist into wb. * The lock protects bdi->worklist and bdi->wb.dwork scheduling. While moving, rename it to wb->work_lock as wb->wb_lock is confusing. Also, move wb->dwork downwards so that it's colocated with the new ->work_lock and ->work_list fields. * bdi_writeback_workfn() -> wb_workfn() bdi_wakeup_thread_delayed(bdi) -> wb_wakeup_delayed(wb) bdi_wakeup_thread(bdi) -> wb_wakeup(wb) bdi_queue_work(bdi, ...) -> wb_queue_work(wb, ...) __bdi_start_writeback(bdi, ...) -> __wb_start_writeback(wb, ...) get_next_work_item(bdi) -> get_next_work_item(wb) * bdi_wb_shutdown() is renamed to wb_shutdown() and now takes @wb. The function contained parts which belong to the containing bdi rather than the wb itself - testing cap_writeback_dirty and bdi_remove_from_list() invocation. Those are moved to bdi_unregister(). * bdi_wb_{init|exit}() are renamed to wb_{init|exit}(). Initializations of the moved bdi->wb_lock and ->work_list are relocated from bdi_init() to wb_init(). * As there's still only one bdi_writeback per backing_dev_info, all uses of bdi->state are mechanically replaced with bdi->wb.state introducing no behavior changes. Signed-off-by: Tejun Heo <tj@kernel.org> Reviewed-by: Jan Kara <jack@suse.cz> Cc: Jens Axboe <axboe@kernel.dk> Cc: Wu Fengguang <fengguang.wu@intel.com> Signed-off-by: Jens Axboe <axboe@fb.com>
319 lines
8.8 KiB
C
319 lines
8.8 KiB
C
/*
|
|
* include/linux/backing-dev.h
|
|
*
|
|
* low-level device information and state which is propagated up through
|
|
* to high-level code.
|
|
*/
|
|
|
|
#ifndef _LINUX_BACKING_DEV_H
|
|
#define _LINUX_BACKING_DEV_H
|
|
|
|
#include <linux/percpu_counter.h>
|
|
#include <linux/log2.h>
|
|
#include <linux/flex_proportions.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/fs.h>
|
|
#include <linux/sched.h>
|
|
#include <linux/timer.h>
|
|
#include <linux/writeback.h>
|
|
#include <linux/atomic.h>
|
|
#include <linux/sysctl.h>
|
|
#include <linux/workqueue.h>
|
|
|
|
struct page;
|
|
struct device;
|
|
struct dentry;
|
|
|
|
/*
|
|
* Bits in bdi_writeback.state
|
|
*/
|
|
enum wb_state {
|
|
WB_async_congested, /* The async (write) queue is getting full */
|
|
WB_sync_congested, /* The sync queue is getting full */
|
|
WB_registered, /* bdi_register() was done */
|
|
WB_writeback_running, /* Writeback is in progress */
|
|
};
|
|
|
|
typedef int (congested_fn)(void *, int);
|
|
|
|
enum wb_stat_item {
|
|
WB_RECLAIMABLE,
|
|
WB_WRITEBACK,
|
|
WB_DIRTIED,
|
|
WB_WRITTEN,
|
|
NR_WB_STAT_ITEMS
|
|
};
|
|
|
|
#define WB_STAT_BATCH (8*(1+ilog2(nr_cpu_ids)))
|
|
|
|
struct bdi_writeback {
|
|
struct backing_dev_info *bdi; /* our parent bdi */
|
|
|
|
unsigned long state; /* Always use atomic bitops on this */
|
|
unsigned long last_old_flush; /* last old data flush */
|
|
|
|
struct list_head b_dirty; /* dirty inodes */
|
|
struct list_head b_io; /* parked for writeback */
|
|
struct list_head b_more_io; /* parked for more writeback */
|
|
struct list_head b_dirty_time; /* time stamps are dirty */
|
|
spinlock_t list_lock; /* protects the b_* lists */
|
|
|
|
struct percpu_counter stat[NR_WB_STAT_ITEMS];
|
|
|
|
unsigned long bw_time_stamp; /* last time write bw is updated */
|
|
unsigned long dirtied_stamp;
|
|
unsigned long written_stamp; /* pages written at bw_time_stamp */
|
|
unsigned long write_bandwidth; /* the estimated write bandwidth */
|
|
unsigned long avg_write_bandwidth; /* further smoothed write bw */
|
|
|
|
/*
|
|
* The base dirty throttle rate, re-calculated on every 200ms.
|
|
* All the bdi tasks' dirty rate will be curbed under it.
|
|
* @dirty_ratelimit tracks the estimated @balanced_dirty_ratelimit
|
|
* in small steps and is much more smooth/stable than the latter.
|
|
*/
|
|
unsigned long dirty_ratelimit;
|
|
unsigned long balanced_dirty_ratelimit;
|
|
|
|
struct fprop_local_percpu completions;
|
|
int dirty_exceeded;
|
|
|
|
spinlock_t work_lock; /* protects work_list & dwork scheduling */
|
|
struct list_head work_list;
|
|
struct delayed_work dwork; /* work item used for writeback */
|
|
};
|
|
|
|
struct backing_dev_info {
|
|
struct list_head bdi_list;
|
|
unsigned long ra_pages; /* max readahead in PAGE_CACHE_SIZE units */
|
|
unsigned int capabilities; /* Device capabilities */
|
|
congested_fn *congested_fn; /* Function pointer if device is md/dm */
|
|
void *congested_data; /* Pointer to aux data for congested func */
|
|
|
|
char *name;
|
|
|
|
unsigned int min_ratio;
|
|
unsigned int max_ratio, max_prop_frac;
|
|
|
|
struct bdi_writeback wb; /* default writeback info for this bdi */
|
|
|
|
struct device *dev;
|
|
|
|
struct timer_list laptop_mode_wb_timer;
|
|
|
|
#ifdef CONFIG_DEBUG_FS
|
|
struct dentry *debug_dir;
|
|
struct dentry *debug_stats;
|
|
#endif
|
|
};
|
|
|
|
struct backing_dev_info *inode_to_bdi(struct inode *inode);
|
|
|
|
int __must_check bdi_init(struct backing_dev_info *bdi);
|
|
void bdi_destroy(struct backing_dev_info *bdi);
|
|
|
|
__printf(3, 4)
|
|
int bdi_register(struct backing_dev_info *bdi, struct device *parent,
|
|
const char *fmt, ...);
|
|
int bdi_register_dev(struct backing_dev_info *bdi, dev_t dev);
|
|
void bdi_unregister(struct backing_dev_info *bdi);
|
|
int __must_check bdi_setup_and_register(struct backing_dev_info *, char *);
|
|
void bdi_start_writeback(struct backing_dev_info *bdi, long nr_pages,
|
|
enum wb_reason reason);
|
|
void bdi_start_background_writeback(struct backing_dev_info *bdi);
|
|
void wb_workfn(struct work_struct *work);
|
|
int bdi_has_dirty_io(struct backing_dev_info *bdi);
|
|
void wb_wakeup_delayed(struct bdi_writeback *wb);
|
|
|
|
extern spinlock_t bdi_lock;
|
|
extern struct list_head bdi_list;
|
|
|
|
extern struct workqueue_struct *bdi_wq;
|
|
|
|
static inline int wb_has_dirty_io(struct bdi_writeback *wb)
|
|
{
|
|
return !list_empty(&wb->b_dirty) ||
|
|
!list_empty(&wb->b_io) ||
|
|
!list_empty(&wb->b_more_io);
|
|
}
|
|
|
|
static inline void __add_wb_stat(struct bdi_writeback *wb,
|
|
enum wb_stat_item item, s64 amount)
|
|
{
|
|
__percpu_counter_add(&wb->stat[item], amount, WB_STAT_BATCH);
|
|
}
|
|
|
|
static inline void __inc_wb_stat(struct bdi_writeback *wb,
|
|
enum wb_stat_item item)
|
|
{
|
|
__add_wb_stat(wb, item, 1);
|
|
}
|
|
|
|
static inline void inc_wb_stat(struct bdi_writeback *wb, enum wb_stat_item item)
|
|
{
|
|
unsigned long flags;
|
|
|
|
local_irq_save(flags);
|
|
__inc_wb_stat(wb, item);
|
|
local_irq_restore(flags);
|
|
}
|
|
|
|
static inline void __dec_wb_stat(struct bdi_writeback *wb,
|
|
enum wb_stat_item item)
|
|
{
|
|
__add_wb_stat(wb, item, -1);
|
|
}
|
|
|
|
static inline void dec_wb_stat(struct bdi_writeback *wb, enum wb_stat_item item)
|
|
{
|
|
unsigned long flags;
|
|
|
|
local_irq_save(flags);
|
|
__dec_wb_stat(wb, item);
|
|
local_irq_restore(flags);
|
|
}
|
|
|
|
static inline s64 wb_stat(struct bdi_writeback *wb, enum wb_stat_item item)
|
|
{
|
|
return percpu_counter_read_positive(&wb->stat[item]);
|
|
}
|
|
|
|
static inline s64 __wb_stat_sum(struct bdi_writeback *wb,
|
|
enum wb_stat_item item)
|
|
{
|
|
return percpu_counter_sum_positive(&wb->stat[item]);
|
|
}
|
|
|
|
static inline s64 wb_stat_sum(struct bdi_writeback *wb, enum wb_stat_item item)
|
|
{
|
|
s64 sum;
|
|
unsigned long flags;
|
|
|
|
local_irq_save(flags);
|
|
sum = __wb_stat_sum(wb, item);
|
|
local_irq_restore(flags);
|
|
|
|
return sum;
|
|
}
|
|
|
|
extern void wb_writeout_inc(struct bdi_writeback *wb);
|
|
|
|
/*
|
|
* maximal error of a stat counter.
|
|
*/
|
|
static inline unsigned long wb_stat_error(struct bdi_writeback *wb)
|
|
{
|
|
#ifdef CONFIG_SMP
|
|
return nr_cpu_ids * WB_STAT_BATCH;
|
|
#else
|
|
return 1;
|
|
#endif
|
|
}
|
|
|
|
int bdi_set_min_ratio(struct backing_dev_info *bdi, unsigned int min_ratio);
|
|
int bdi_set_max_ratio(struct backing_dev_info *bdi, unsigned int max_ratio);
|
|
|
|
/*
|
|
* Flags in backing_dev_info::capability
|
|
*
|
|
* The first three flags control whether dirty pages will contribute to the
|
|
* VM's accounting and whether writepages() should be called for dirty pages
|
|
* (something that would not, for example, be appropriate for ramfs)
|
|
*
|
|
* WARNING: these flags are closely related and should not normally be
|
|
* used separately. The BDI_CAP_NO_ACCT_AND_WRITEBACK combines these
|
|
* three flags into a single convenience macro.
|
|
*
|
|
* BDI_CAP_NO_ACCT_DIRTY: Dirty pages shouldn't contribute to accounting
|
|
* BDI_CAP_NO_WRITEBACK: Don't write pages back
|
|
* BDI_CAP_NO_ACCT_WB: Don't automatically account writeback pages
|
|
* BDI_CAP_STRICTLIMIT: Keep number of dirty pages below bdi threshold.
|
|
*/
|
|
#define BDI_CAP_NO_ACCT_DIRTY 0x00000001
|
|
#define BDI_CAP_NO_WRITEBACK 0x00000002
|
|
#define BDI_CAP_NO_ACCT_WB 0x00000004
|
|
#define BDI_CAP_STABLE_WRITES 0x00000008
|
|
#define BDI_CAP_STRICTLIMIT 0x00000010
|
|
|
|
#define BDI_CAP_NO_ACCT_AND_WRITEBACK \
|
|
(BDI_CAP_NO_WRITEBACK | BDI_CAP_NO_ACCT_DIRTY | BDI_CAP_NO_ACCT_WB)
|
|
|
|
extern struct backing_dev_info noop_backing_dev_info;
|
|
|
|
int writeback_in_progress(struct backing_dev_info *bdi);
|
|
|
|
static inline int bdi_congested(struct backing_dev_info *bdi, int bdi_bits)
|
|
{
|
|
if (bdi->congested_fn)
|
|
return bdi->congested_fn(bdi->congested_data, bdi_bits);
|
|
return (bdi->wb.state & bdi_bits);
|
|
}
|
|
|
|
static inline int bdi_read_congested(struct backing_dev_info *bdi)
|
|
{
|
|
return bdi_congested(bdi, 1 << WB_sync_congested);
|
|
}
|
|
|
|
static inline int bdi_write_congested(struct backing_dev_info *bdi)
|
|
{
|
|
return bdi_congested(bdi, 1 << WB_async_congested);
|
|
}
|
|
|
|
static inline int bdi_rw_congested(struct backing_dev_info *bdi)
|
|
{
|
|
return bdi_congested(bdi, (1 << WB_sync_congested) |
|
|
(1 << WB_async_congested));
|
|
}
|
|
|
|
enum {
|
|
BLK_RW_ASYNC = 0,
|
|
BLK_RW_SYNC = 1,
|
|
};
|
|
|
|
void clear_bdi_congested(struct backing_dev_info *bdi, int sync);
|
|
void set_bdi_congested(struct backing_dev_info *bdi, int sync);
|
|
long congestion_wait(int sync, long timeout);
|
|
long wait_iff_congested(struct zone *zone, int sync, long timeout);
|
|
int pdflush_proc_obsolete(struct ctl_table *table, int write,
|
|
void __user *buffer, size_t *lenp, loff_t *ppos);
|
|
|
|
static inline bool bdi_cap_stable_pages_required(struct backing_dev_info *bdi)
|
|
{
|
|
return bdi->capabilities & BDI_CAP_STABLE_WRITES;
|
|
}
|
|
|
|
static inline bool bdi_cap_writeback_dirty(struct backing_dev_info *bdi)
|
|
{
|
|
return !(bdi->capabilities & BDI_CAP_NO_WRITEBACK);
|
|
}
|
|
|
|
static inline bool bdi_cap_account_dirty(struct backing_dev_info *bdi)
|
|
{
|
|
return !(bdi->capabilities & BDI_CAP_NO_ACCT_DIRTY);
|
|
}
|
|
|
|
static inline bool bdi_cap_account_writeback(struct backing_dev_info *bdi)
|
|
{
|
|
/* Paranoia: BDI_CAP_NO_WRITEBACK implies BDI_CAP_NO_ACCT_WB */
|
|
return !(bdi->capabilities & (BDI_CAP_NO_ACCT_WB |
|
|
BDI_CAP_NO_WRITEBACK));
|
|
}
|
|
|
|
static inline bool mapping_cap_writeback_dirty(struct address_space *mapping)
|
|
{
|
|
return bdi_cap_writeback_dirty(inode_to_bdi(mapping->host));
|
|
}
|
|
|
|
static inline bool mapping_cap_account_dirty(struct address_space *mapping)
|
|
{
|
|
return bdi_cap_account_dirty(inode_to_bdi(mapping->host));
|
|
}
|
|
|
|
static inline int bdi_sched_wait(void *word)
|
|
{
|
|
schedule();
|
|
return 0;
|
|
}
|
|
|
|
#endif /* _LINUX_BACKING_DEV_H */
|