Skip to content

Commit

Permalink
flex_proportions: Allow N events instead of 1
Browse files Browse the repository at this point in the history
When batching events (such as writing back N pages in a single I/O), it
is better to do one flex_proportion operation instead of N.  There is
only one caller of __fprop_inc_percpu_max(), and it's the one we're
going to change in the next patch, so rename it instead of adding a
compatibility wrapper.

Signed-off-by: Matthew Wilcox (Oracle) <[email protected]>
Reviewed-by: Christoph Hellwig <[email protected]>
Reviewed-by: Jan Kara <[email protected]>
  • Loading branch information
Matthew Wilcox (Oracle) committed Oct 18, 2021
1 parent bd3488e commit be5f179
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
9 changes: 5 additions & 4 deletions include/linux/flex_proportions.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ struct fprop_local_percpu {

int fprop_local_init_percpu(struct fprop_local_percpu *pl, gfp_t gfp);
void fprop_local_destroy_percpu(struct fprop_local_percpu *pl);
void __fprop_inc_percpu(struct fprop_global *p, struct fprop_local_percpu *pl);
void __fprop_inc_percpu_max(struct fprop_global *p, struct fprop_local_percpu *pl,
int max_frac);
void __fprop_add_percpu(struct fprop_global *p, struct fprop_local_percpu *pl,
long nr);
void __fprop_add_percpu_max(struct fprop_global *p,
struct fprop_local_percpu *pl, int max_frac, long nr);
void fprop_fraction_percpu(struct fprop_global *p,
struct fprop_local_percpu *pl, unsigned long *numerator,
unsigned long *denominator);
Expand All @@ -96,7 +97,7 @@ void fprop_inc_percpu(struct fprop_global *p, struct fprop_local_percpu *pl)
unsigned long flags;

local_irq_save(flags);
__fprop_inc_percpu(p, pl);
__fprop_add_percpu(p, pl, 1);
local_irq_restore(flags);
}

Expand Down
28 changes: 19 additions & 9 deletions lib/flex_proportions.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,12 @@ static void fprop_reflect_period_percpu(struct fprop_global *p,
}

/* Event of type pl happened */
void __fprop_inc_percpu(struct fprop_global *p, struct fprop_local_percpu *pl)
void __fprop_add_percpu(struct fprop_global *p, struct fprop_local_percpu *pl,
long nr)
{
fprop_reflect_period_percpu(p, pl);
percpu_counter_add_batch(&pl->events, 1, PROP_BATCH);
percpu_counter_add(&p->events, 1);
percpu_counter_add_batch(&pl->events, nr, PROP_BATCH);
percpu_counter_add(&p->events, nr);
}

void fprop_fraction_percpu(struct fprop_global *p,
Expand Down Expand Up @@ -253,20 +254,29 @@ void fprop_fraction_percpu(struct fprop_global *p,
}

/*
* Like __fprop_inc_percpu() except that event is counted only if the given
* Like __fprop_add_percpu() except that event is counted only if the given
* type has fraction smaller than @max_frac/FPROP_FRAC_BASE
*/
void __fprop_inc_percpu_max(struct fprop_global *p,
struct fprop_local_percpu *pl, int max_frac)
void __fprop_add_percpu_max(struct fprop_global *p,
struct fprop_local_percpu *pl, int max_frac, long nr)
{
if (unlikely(max_frac < FPROP_FRAC_BASE)) {
unsigned long numerator, denominator;
s64 tmp;

fprop_fraction_percpu(p, pl, &numerator, &denominator);
if (numerator >
(((u64)denominator) * max_frac) >> FPROP_FRAC_SHIFT)
/* Adding 'nr' to fraction exceeds max_frac/FPROP_FRAC_BASE? */
tmp = (u64)denominator * max_frac -
((u64)numerator << FPROP_FRAC_SHIFT);
if (tmp < 0) {
/* Maximum fraction already exceeded? */
return;
} else if (tmp < nr * (FPROP_FRAC_BASE - max_frac)) {
/* Add just enough for the fraction to saturate */
nr = div_u64(tmp + FPROP_FRAC_BASE - max_frac - 1,
FPROP_FRAC_BASE - max_frac);
}
}

__fprop_inc_percpu(p, pl);
__fprop_add_percpu(p, pl, nr);
}
4 changes: 2 additions & 2 deletions mm/page-writeback.c
Original file line number Diff line number Diff line change
Expand Up @@ -566,8 +566,8 @@ static void wb_domain_writeout_inc(struct wb_domain *dom,
struct fprop_local_percpu *completions,
unsigned int max_prop_frac)
{
__fprop_inc_percpu_max(&dom->completions, completions,
max_prop_frac);
__fprop_add_percpu_max(&dom->completions, completions,
max_prop_frac, 1);
/* First event after period switching was turned off? */
if (unlikely(!dom->period_time)) {
/*
Expand Down

0 comments on commit be5f179

Please sign in to comment.