Skip to content

Commit f1ab283

Browse files
Tang Yizhouakpm00
authored andcommitted
writeback: let trace_balance_dirty_pages() take struct dtc as parameter
Patch series "Fix calculations in trace_balance_dirty_pages() for cgwb", v2. In my experiment, I found that the output of trace_balance_dirty_pages() in the cgroup writeback scenario was strange because trace_balance_dirty_pages() always uses global_wb_domain.dirty_limit for related calculations instead of the dirty_limit of the corresponding memcg's wb_domain. The basic idea of the fix is to store the hard dirty limit value computed in wb_position_ratio() into struct dirty_throttle_control and use it for calculations in trace_balance_dirty_pages(). This patch (of 3): Currently, trace_balance_dirty_pages() already has 12 parameters. In the patch #3, I initially attempted to introduce an additional parameter. However, in include/linux/trace_events.h, bpf_trace_run12() only supports up to 12 parameters and bpf_trace_run13() does not exist. To reduce the number of parameters in trace_balance_dirty_pages(), we can make it accept a pointer to struct dirty_throttle_control as a parameter. To achieve this, we need to move the definition of struct dirty_throttle_control from mm/page-writeback.c to include/linux/writeback.h. Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Tang Yizhou <[email protected]> Cc: Alexei Starovoitov <[email protected]> Cc: Christian Brauner <[email protected]> Cc: Steven Rostedt <[email protected]> Cc: Jan Kara <[email protected]> Cc: "Masami Hiramatsu (Google)" <[email protected]> Cc: Matthew Wilcow (Oracle) <[email protected]> Cc: Tang Yizhou <[email protected]> Cc: Tejun Heo <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 70478a5 commit f1ab283

File tree

3 files changed

+31
-43
lines changed

3 files changed

+31
-43
lines changed

include/linux/writeback.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,29 @@ static inline void cgroup_writeback_umount(struct super_block *sb)
313313
/*
314314
* mm/page-writeback.c
315315
*/
316+
/* consolidated parameters for balance_dirty_pages() and its subroutines */
317+
struct dirty_throttle_control {
318+
#ifdef CONFIG_CGROUP_WRITEBACK
319+
struct wb_domain *dom;
320+
struct dirty_throttle_control *gdtc; /* only set in memcg dtc's */
321+
#endif
322+
struct bdi_writeback *wb;
323+
struct fprop_local_percpu *wb_completions;
324+
325+
unsigned long avail; /* dirtyable */
326+
unsigned long dirty; /* file_dirty + write + nfs */
327+
unsigned long thresh; /* dirty threshold */
328+
unsigned long bg_thresh; /* dirty background threshold */
329+
330+
unsigned long wb_dirty; /* per-wb counterparts */
331+
unsigned long wb_thresh;
332+
unsigned long wb_bg_thresh;
333+
334+
unsigned long pos_ratio;
335+
bool freerun;
336+
bool dirty_exceeded;
337+
};
338+
316339
void laptop_io_completion(struct backing_dev_info *info);
317340
void laptop_sync_completion(void);
318341
void laptop_mode_timer_fn(struct timer_list *t);

include/trace/events/writeback.h

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -629,19 +629,15 @@ TRACE_EVENT(bdi_dirty_ratelimit,
629629
TRACE_EVENT(balance_dirty_pages,
630630

631631
TP_PROTO(struct bdi_writeback *wb,
632-
unsigned long thresh,
633-
unsigned long bg_thresh,
634-
unsigned long dirty,
635-
unsigned long bdi_thresh,
636-
unsigned long bdi_dirty,
632+
struct dirty_throttle_control *dtc,
637633
unsigned long dirty_ratelimit,
638634
unsigned long task_ratelimit,
639635
unsigned long dirtied,
640636
unsigned long period,
641637
long pause,
642638
unsigned long start_time),
643639

644-
TP_ARGS(wb, thresh, bg_thresh, dirty, bdi_thresh, bdi_dirty,
640+
TP_ARGS(wb, dtc,
645641
dirty_ratelimit, task_ratelimit,
646642
dirtied, period, pause, start_time),
647643

@@ -664,16 +660,16 @@ TRACE_EVENT(balance_dirty_pages,
664660
),
665661

666662
TP_fast_assign(
667-
unsigned long freerun = (thresh + bg_thresh) / 2;
663+
unsigned long freerun = (dtc->thresh + dtc->bg_thresh) / 2;
668664
strscpy_pad(__entry->bdi, bdi_dev_name(wb->bdi), 32);
669665

670666
__entry->limit = global_wb_domain.dirty_limit;
671667
__entry->setpoint = (global_wb_domain.dirty_limit +
672668
freerun) / 2;
673-
__entry->dirty = dirty;
669+
__entry->dirty = dtc->dirty;
674670
__entry->bdi_setpoint = __entry->setpoint *
675-
bdi_thresh / (thresh + 1);
676-
__entry->bdi_dirty = bdi_dirty;
671+
dtc->wb_thresh / (dtc->thresh + 1);
672+
__entry->bdi_dirty = dtc->wb_dirty;
677673
__entry->dirty_ratelimit = KBps(dirty_ratelimit);
678674
__entry->task_ratelimit = KBps(task_ratelimit);
679675
__entry->dirtied = dirtied;

mm/page-writeback.c

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -120,29 +120,6 @@ EXPORT_SYMBOL(laptop_mode);
120120

121121
struct wb_domain global_wb_domain;
122122

123-
/* consolidated parameters for balance_dirty_pages() and its subroutines */
124-
struct dirty_throttle_control {
125-
#ifdef CONFIG_CGROUP_WRITEBACK
126-
struct wb_domain *dom;
127-
struct dirty_throttle_control *gdtc; /* only set in memcg dtc's */
128-
#endif
129-
struct bdi_writeback *wb;
130-
struct fprop_local_percpu *wb_completions;
131-
132-
unsigned long avail; /* dirtyable */
133-
unsigned long dirty; /* file_dirty + write + nfs */
134-
unsigned long thresh; /* dirty threshold */
135-
unsigned long bg_thresh; /* dirty background threshold */
136-
137-
unsigned long wb_dirty; /* per-wb counterparts */
138-
unsigned long wb_thresh;
139-
unsigned long wb_bg_thresh;
140-
141-
unsigned long pos_ratio;
142-
bool freerun;
143-
bool dirty_exceeded;
144-
};
145-
146123
/*
147124
* Length of period for aging writeout fractions of bdis. This is an
148125
* arbitrarily chosen number. The longer the period, the slower fractions will
@@ -1962,11 +1939,7 @@ static int balance_dirty_pages(struct bdi_writeback *wb,
19621939
*/
19631940
if (pause < min_pause) {
19641941
trace_balance_dirty_pages(wb,
1965-
sdtc->thresh,
1966-
sdtc->bg_thresh,
1967-
sdtc->dirty,
1968-
sdtc->wb_thresh,
1969-
sdtc->wb_dirty,
1942+
sdtc,
19701943
dirty_ratelimit,
19711944
task_ratelimit,
19721945
pages_dirtied,
@@ -1991,11 +1964,7 @@ static int balance_dirty_pages(struct bdi_writeback *wb,
19911964

19921965
pause:
19931966
trace_balance_dirty_pages(wb,
1994-
sdtc->thresh,
1995-
sdtc->bg_thresh,
1996-
sdtc->dirty,
1997-
sdtc->wb_thresh,
1998-
sdtc->wb_dirty,
1967+
sdtc,
19991968
dirty_ratelimit,
20001969
task_ratelimit,
20011970
pages_dirtied,

0 commit comments

Comments
 (0)