Skip to content

Commit

Permalink
mm: multigenerational lru: add /sys/kernel/mm/lru_gen/min_ttl_ms
Browse files Browse the repository at this point in the history
Add /sys/kernel/mm/lru_gen/min_ttl_ms to protect generations that are
younger than the value of this file. The multigenerational lru will
not consider those generations. And if there are no older generations
left, it will oom kill. The default value 0 means this feature is
disabled.

Signed-off-by: Yu Zhao <yuzhao@google.com>
  • Loading branch information
yuzhaogoogle authored and intersectRaven committed Aug 18, 2021
1 parent 984994e commit 9572b4f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mm/memcontrol.c
Original file line number Diff line number Diff line change
Expand Up @@ -6002,7 +6002,7 @@ static void mem_cgroup_attach(struct cgroup_taskset *tset)
struct task_struct *task = NULL;

cgroup_taskset_for_each_leader(task, css, tset)
;
break;

if (!task)
return;
Expand Down
46 changes: 46 additions & 0 deletions mm/vmscan.c
Original file line number Diff line number Diff line change
Expand Up @@ -4333,6 +4333,8 @@ static int get_swappiness(struct lruvec *lruvec)
return swappiness;
}

static DEFINE_RATELIMIT_STATE(lru_gen_min_ttl, 0, 1);

static unsigned long get_nr_to_scan(struct lruvec *lruvec, struct scan_control *sc,
int swappiness)
{
Expand Down Expand Up @@ -4362,6 +4364,11 @@ static unsigned long get_nr_to_scan(struct lruvec *lruvec, struct scan_control *
nr_gens = max_nr_gens(max_seq, min_seq, swappiness);

if (current_is_kswapd()) {
gen = lru_gen_from_seq(max_seq - nr_gens + 1);
if (time_is_before_eq_jiffies(READ_ONCE(lrugen->timestamps[gen]) +
READ_ONCE(lru_gen_min_ttl.interval)))
sc->file_is_tiny = 0;

/* leave the work to age_lru_gens() */
if (nr_gens == MIN_NR_GENS)
return 0;
Expand Down Expand Up @@ -4466,6 +4473,21 @@ static void lru_gen_age_node(struct pglist_data *pgdat, struct scan_control *sc)

VM_BUG_ON(!current_is_kswapd());

if (sc->file_is_tiny && READ_ONCE(lru_gen_min_ttl.interval) &&
__ratelimit(&lru_gen_min_ttl)) {
struct oom_control oc = {
.gfp_mask = sc->gfp_mask,
.order = sc->order,
};

if (mutex_trylock(&oom_lock)) {
out_of_memory(&oc);
mutex_unlock(&oom_lock);
}
}

sc->file_is_tiny = 1;

if (!mem_cgroup_disabled() && !sc->force_deactivate) {
/* we may clear this later in get_nr_to_scan() */
sc->force_deactivate = 1;
Expand Down Expand Up @@ -4730,6 +4752,29 @@ static struct kobj_attribute lru_gen_spread_attr = __ATTR(
spread, 0644, show_lru_gen_spread, store_lru_gen_spread
);

static ssize_t show_lru_gen_min_ttl(struct kobject *kobj, struct kobj_attribute *attr,
char *buf)
{
return sprintf(buf, "%u\n", jiffies_to_msecs(READ_ONCE(lru_gen_min_ttl.interval)));
}

static ssize_t store_lru_gen_min_ttl(struct kobject *kobj, struct kobj_attribute *attr,
const char *buf, size_t len)
{
unsigned int msecs;

if (kstrtouint(buf, 10, &msecs))
return -EINVAL;

WRITE_ONCE(lru_gen_min_ttl.interval, msecs_to_jiffies(msecs));

return len;
}

static struct kobj_attribute lru_gen_min_ttl_attr = __ATTR(
min_ttl_ms, 0644, show_lru_gen_min_ttl, store_lru_gen_min_ttl
);

static ssize_t show_lru_gen_enabled(struct kobject *kobj, struct kobj_attribute *attr,
char *buf)
{
Expand All @@ -4755,6 +4800,7 @@ static struct kobj_attribute lru_gen_enabled_attr = __ATTR(

static struct attribute *lru_gen_attrs[] = {
&lru_gen_spread_attr.attr,
&lru_gen_min_ttl_attr.attr,
&lru_gen_enabled_attr.attr,
NULL
};
Expand Down

0 comments on commit 9572b4f

Please sign in to comment.