2015-05-23 00:13:32 +03:00
|
|
|
#ifndef __LINUX_BACKING_DEV_DEFS_H
|
|
|
|
#define __LINUX_BACKING_DEV_DEFS_H
|
|
|
|
|
|
|
|
#include <linux/list.h>
|
2015-05-23 00:13:37 +03:00
|
|
|
#include <linux/radix-tree.h>
|
|
|
|
#include <linux/rbtree.h>
|
2015-05-23 00:13:32 +03:00
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/percpu_counter.h>
|
2015-05-23 00:13:37 +03:00
|
|
|
#include <linux/percpu-refcount.h>
|
2015-05-23 00:13:32 +03:00
|
|
|
#include <linux/flex_proportions.h>
|
|
|
|
#include <linux/timer.h>
|
|
|
|
#include <linux/workqueue.h>
|
2017-02-02 17:56:51 +03:00
|
|
|
#include <linux/kref.h>
|
2015-05-23 00:13:32 +03:00
|
|
|
|
|
|
|
struct page;
|
|
|
|
struct device;
|
|
|
|
struct dentry;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Bits in bdi_writeback.state
|
|
|
|
*/
|
|
|
|
enum wb_state {
|
|
|
|
WB_registered, /* bdi_register() was done */
|
2017-03-23 03:36:57 +03:00
|
|
|
WB_shutting_down, /* wb_shutdown() in progress */
|
2015-05-23 00:13:32 +03:00
|
|
|
WB_writeback_running, /* Writeback is in progress */
|
2015-05-23 00:13:45 +03:00
|
|
|
WB_has_dirty_io, /* Dirty inodes on ->b_{dirty|io|more_io} */
|
2015-05-23 00:13:32 +03:00
|
|
|
};
|
|
|
|
|
2015-05-23 00:13:35 +03:00
|
|
|
enum wb_congested_state {
|
|
|
|
WB_async_congested, /* The async (write) queue is getting full */
|
|
|
|
WB_sync_congested, /* The sync queue is getting full */
|
|
|
|
};
|
|
|
|
|
2015-05-23 00:13:32 +03:00
|
|
|
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)))
|
|
|
|
|
2015-05-23 00:13:37 +03:00
|
|
|
/*
|
|
|
|
* For cgroup writeback, multiple wb's may map to the same blkcg. Those
|
|
|
|
* wb's can operate mostly independently but should share the congested
|
|
|
|
* state. To facilitate such sharing, the congested state is tracked using
|
|
|
|
* the following struct which is created on demand, indexed by blkcg ID on
|
|
|
|
* its bdi, and refcounted.
|
|
|
|
*/
|
2015-05-23 00:13:35 +03:00
|
|
|
struct bdi_writeback_congested {
|
|
|
|
unsigned long state; /* WB_[a]sync_congested flags */
|
2015-07-02 17:44:34 +03:00
|
|
|
atomic_t refcnt; /* nr of attached wb's and blkg */
|
2015-05-23 00:13:37 +03:00
|
|
|
|
|
|
|
#ifdef CONFIG_CGROUP_WRITEBACK
|
2017-03-23 03:36:54 +03:00
|
|
|
struct backing_dev_info *__bdi; /* the associated bdi, set to NULL
|
|
|
|
* on bdi unregistration. For memcg-wb
|
|
|
|
* internal use only! */
|
2015-05-23 00:13:37 +03:00
|
|
|
int blkcg_id; /* ID of the associated blkcg */
|
|
|
|
struct rb_node rb_node; /* on bdi->cgwb_congestion_tree */
|
|
|
|
#endif
|
2015-05-23 00:13:35 +03:00
|
|
|
};
|
|
|
|
|
2015-05-23 00:13:37 +03:00
|
|
|
/*
|
|
|
|
* Each wb (bdi_writeback) can perform writeback operations, is measured
|
|
|
|
* and throttled, independently. Without cgroup writeback, each bdi
|
|
|
|
* (bdi_writeback) is served by its embedded bdi->wb.
|
|
|
|
*
|
|
|
|
* On the default hierarchy, blkcg implicitly enables memcg. This allows
|
|
|
|
* using memcg's page ownership for attributing writeback IOs, and every
|
|
|
|
* memcg - blkcg combination can be served by its own wb by assigning a
|
|
|
|
* dedicated wb to each memcg, which enables isolation across different
|
|
|
|
* cgroups and propagation of IO back pressure down from the IO layer upto
|
|
|
|
* the tasks which are generating the dirty pages to be written back.
|
|
|
|
*
|
|
|
|
* A cgroup wb is indexed on its bdi by the ID of the associated memcg,
|
|
|
|
* refcounted with the number of inodes attached to it, and pins the memcg
|
|
|
|
* and the corresponding blkcg. As the corresponding blkcg for a memcg may
|
|
|
|
* change as blkcg is disabled and enabled higher up in the hierarchy, a wb
|
|
|
|
* is tested for blkcg after lookup and removed from index on mismatch so
|
|
|
|
* that a new wb for the combination can be created.
|
|
|
|
*/
|
2015-05-23 00:13:32 +03:00
|
|
|
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];
|
|
|
|
|
2015-05-23 00:13:35 +03:00
|
|
|
struct bdi_writeback_congested *congested;
|
|
|
|
|
2015-05-23 00:13:32 +03:00
|
|
|
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 */
|
2015-05-23 00:13:47 +03:00
|
|
|
unsigned long avg_write_bandwidth; /* further smoothed write bw, > 0 */
|
2015-05-23 00:13:32 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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 */
|
2015-05-23 00:13:37 +03:00
|
|
|
|
2016-09-01 19:20:33 +03:00
|
|
|
unsigned long dirty_sleep; /* last wait */
|
|
|
|
|
2015-10-02 21:47:05 +03:00
|
|
|
struct list_head bdi_node; /* anchored at bdi->wb_list */
|
|
|
|
|
2015-05-23 00:13:37 +03:00
|
|
|
#ifdef CONFIG_CGROUP_WRITEBACK
|
|
|
|
struct percpu_ref refcnt; /* used only for !root wb's */
|
2015-05-23 01:23:33 +03:00
|
|
|
struct fprop_local_percpu memcg_completions;
|
2015-05-23 00:13:37 +03:00
|
|
|
struct cgroup_subsys_state *memcg_css; /* the associated memcg */
|
|
|
|
struct cgroup_subsys_state *blkcg_css; /* and blkcg */
|
|
|
|
struct list_head memcg_node; /* anchored at memcg->cgwb_list */
|
|
|
|
struct list_head blkcg_node; /* anchored at blkcg->cgwb_list */
|
|
|
|
|
|
|
|
union {
|
|
|
|
struct work_struct release_work;
|
|
|
|
struct rcu_head rcu;
|
|
|
|
};
|
|
|
|
#endif
|
2015-05-23 00:13:32 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct backing_dev_info {
|
|
|
|
struct list_head bdi_list;
|
2016-04-01 15:29:48 +03:00
|
|
|
unsigned long ra_pages; /* max readahead in PAGE_SIZE units */
|
mm: don't cap request size based on read-ahead setting
We ran into a funky issue, where someone doing 256K buffered reads saw
128K requests at the device level. Turns out it is read-ahead capping
the request size, since we use 128K as the default setting. This
doesn't make a lot of sense - if someone is issuing 256K reads, they
should see 256K reads, regardless of the read-ahead setting, if the
underlying device can support a 256K read in a single command.
This patch introduces a bdi hint, io_pages. This is the soft max IO
size for the lower level, I've hooked it up to the bdev settings here.
Read-ahead is modified to issue the maximum of the user request size,
and the read-ahead max size, but capped to the max request size on the
device side. The latter is done to avoid reading ahead too much, if the
application asks for a huge read. With this patch, the kernel behaves
like the application expects.
Link: http://lkml.kernel.org/r/1479498073-8657-1-git-send-email-axboe@fb.com
Signed-off-by: Jens Axboe <axboe@fb.com>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-12-13 03:43:26 +03:00
|
|
|
unsigned long io_pages; /* max allowed IO size */
|
2015-05-23 00:13:32 +03:00
|
|
|
congested_fn *congested_fn; /* Function pointer if device is md/dm */
|
|
|
|
void *congested_data; /* Pointer to aux data for congested func */
|
|
|
|
|
2017-04-12 13:24:28 +03:00
|
|
|
const char *name;
|
2015-05-23 00:13:32 +03:00
|
|
|
|
2017-02-02 17:56:51 +03:00
|
|
|
struct kref refcnt; /* Reference counter for the structure */
|
2016-12-13 03:43:29 +03:00
|
|
|
unsigned int capabilities; /* Device capabilities */
|
2015-05-23 00:13:32 +03:00
|
|
|
unsigned int min_ratio;
|
|
|
|
unsigned int max_ratio, max_prop_frac;
|
|
|
|
|
2015-05-23 00:13:47 +03:00
|
|
|
/*
|
|
|
|
* Sum of avg_write_bw of wbs with dirty inodes. > 0 if there are
|
|
|
|
* any dirty wbs, which is depended upon by bdi_has_dirty().
|
|
|
|
*/
|
|
|
|
atomic_long_t tot_write_bandwidth;
|
2015-05-23 00:13:46 +03:00
|
|
|
|
2015-05-23 00:13:37 +03:00
|
|
|
struct bdi_writeback wb; /* the root writeback info for this bdi */
|
2015-10-02 21:47:05 +03:00
|
|
|
struct list_head wb_list; /* list of all wbs */
|
2015-05-23 00:13:37 +03:00
|
|
|
#ifdef CONFIG_CGROUP_WRITEBACK
|
|
|
|
struct radix_tree_root cgwb_tree; /* radix tree of active cgroup wbs */
|
|
|
|
struct rb_root cgwb_congested_tree; /* their congested states */
|
2015-07-02 17:44:34 +03:00
|
|
|
#else
|
|
|
|
struct bdi_writeback_congested *wb_congested;
|
2015-05-23 00:13:37 +03:00
|
|
|
#endif
|
2015-05-23 00:13:58 +03:00
|
|
|
wait_queue_head_t wb_waitq;
|
|
|
|
|
2015-05-23 00:13:32 +03:00
|
|
|
struct device *dev;
|
2016-07-31 21:15:13 +03:00
|
|
|
struct device *owner;
|
2015-05-23 00:13:32 +03:00
|
|
|
|
|
|
|
struct timer_list laptop_mode_wb_timer;
|
|
|
|
|
|
|
|
#ifdef CONFIG_DEBUG_FS
|
|
|
|
struct dentry *debug_dir;
|
|
|
|
struct dentry *debug_stats;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
BLK_RW_ASYNC = 0,
|
|
|
|
BLK_RW_SYNC = 1,
|
|
|
|
};
|
|
|
|
|
2015-05-23 00:13:41 +03:00
|
|
|
void clear_wb_congested(struct bdi_writeback_congested *congested, int sync);
|
|
|
|
void set_wb_congested(struct bdi_writeback_congested *congested, int sync);
|
|
|
|
|
|
|
|
static inline void clear_bdi_congested(struct backing_dev_info *bdi, int sync)
|
|
|
|
{
|
|
|
|
clear_wb_congested(bdi->wb.congested, sync);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void set_bdi_congested(struct backing_dev_info *bdi, int sync)
|
|
|
|
{
|
|
|
|
set_wb_congested(bdi->wb.congested, sync);
|
|
|
|
}
|
2015-05-23 00:13:32 +03:00
|
|
|
|
2015-05-28 21:50:49 +03:00
|
|
|
#ifdef CONFIG_CGROUP_WRITEBACK
|
|
|
|
|
|
|
|
/**
|
|
|
|
* wb_tryget - try to increment a wb's refcount
|
|
|
|
* @wb: bdi_writeback to get
|
|
|
|
*/
|
|
|
|
static inline bool wb_tryget(struct bdi_writeback *wb)
|
|
|
|
{
|
|
|
|
if (wb != &wb->bdi->wb)
|
|
|
|
return percpu_ref_tryget(&wb->refcnt);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* wb_get - increment a wb's refcount
|
|
|
|
* @wb: bdi_writeback to get
|
|
|
|
*/
|
|
|
|
static inline void wb_get(struct bdi_writeback *wb)
|
|
|
|
{
|
|
|
|
if (wb != &wb->bdi->wb)
|
|
|
|
percpu_ref_get(&wb->refcnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* wb_put - decrement a wb's refcount
|
|
|
|
* @wb: bdi_writeback to put
|
|
|
|
*/
|
|
|
|
static inline void wb_put(struct bdi_writeback *wb)
|
|
|
|
{
|
|
|
|
if (wb != &wb->bdi->wb)
|
|
|
|
percpu_ref_put(&wb->refcnt);
|
|
|
|
}
|
|
|
|
|
2015-05-28 21:50:57 +03:00
|
|
|
/**
|
|
|
|
* wb_dying - is a wb dying?
|
|
|
|
* @wb: bdi_writeback of interest
|
|
|
|
*
|
|
|
|
* Returns whether @wb is unlinked and being drained.
|
|
|
|
*/
|
|
|
|
static inline bool wb_dying(struct bdi_writeback *wb)
|
|
|
|
{
|
|
|
|
return percpu_ref_is_dying(&wb->refcnt);
|
|
|
|
}
|
|
|
|
|
2015-05-28 21:50:49 +03:00
|
|
|
#else /* CONFIG_CGROUP_WRITEBACK */
|
|
|
|
|
|
|
|
static inline bool wb_tryget(struct bdi_writeback *wb)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void wb_get(struct bdi_writeback *wb)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void wb_put(struct bdi_writeback *wb)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-05-28 21:50:57 +03:00
|
|
|
static inline bool wb_dying(struct bdi_writeback *wb)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-05-28 21:50:49 +03:00
|
|
|
#endif /* CONFIG_CGROUP_WRITEBACK */
|
|
|
|
|
2015-05-23 00:13:32 +03:00
|
|
|
#endif /* __LINUX_BACKING_DEV_DEFS_H */
|