Skip to contentSkip to conversation

mm: workingset: clarify eviction order and distance calculation

PATCH Applied Oscar Salvador 2 participants 4 messages Feb 1, 2021 – Feb 11, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm: workingset: clarify eviction order and distance calculation

The premise of the refault distance is that it can be seen as a deficit of the inactive list space, so that if the inactive list would have had (R - E) more slots, the page would not have been evicted but promoted to the active list instead.

However, the way the code is ordered right now set us to be off by one, so the real number of slots would be (R - E) + 1.
I stumbled upon this when trying to understand the code and it puzzled me that the comments did not match what the code did.

This it not an issue at all since evictions and refaults tend to happen in a number large enough that being off-by-one does not have any impact
- and since the compiler and CPUs are free to rearrange the execution sequence anyway.
But as Johannes says, it is better to re-arrange the code in the proper order since otherwise would be misleading to somebody who is actively reading and trying to understand the logic of the code - like it happened to me.

---
 mm/workingset.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/workingset.c +1 -1
index 10e96de945b3..0201aa1ff320 100644
@@ -263,10 +263,10 @@ void *workingset_eviction(struct page *page, struct mem_cgroup *target_memcg)
 	VM_BUG_ON_PAGE(!PageLocked(page), page);
 
 	lruvec = mem_cgroup_lruvec(target_memcg, pgdat);
-	workingset_age_nonresident(lruvec, thp_nr_pages(page));
 	/* XXX: target_memcg can be NULL, go through lruvec */
 	memcgid = mem_cgroup_id(lruvec_memcg(lruvec));
 	eviction = atomic_long_read(&lruvec->nonresident_age);
+	workingset_age_nonresident(lruvec, thp_nr_pages(page));
 	return pack_shadow(memcgid, pgdat, eviction, PageWorkingset(page));
 }
 
Signature · 1 line
2.26.2
Acked-by on v1 1/1
#1 lore raw
Quoted 19 lines · Oscar Salvador

The premise of the refault distance is that it can be seen as a deficit of the inactive list space, so that if the inactive list would have had (R - E) more slots, the page would not have been evicted but promoted to the active list instead.

However, the way the code is ordered right now set us to be off by one, so the real number of slots would be (R - E) + 1.
I stumbled upon this when trying to understand the code and it puzzled me that the comments did not match what the code did.

This it not an issue at all since evictions and refaults tend to happen in a number large enough that being off-by-one does not have any impact
- and since the compiler and CPUs are free to rearrange the execution sequence anyway.
But as Johannes says, it is better to re-arrange the code in the proper order since otherwise would be misleading to somebody who is actively reading and trying to understand the logic of the code - like it happened to me.

Quoted 2 lines
Quoted 21 lines
---
 mm/workingset.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/workingset.c +1 -1
index 10e96de945b3..0201aa1ff320 100644
@@ -263,10 +263,10 @@ void *workingset_eviction(struct page *page, struct mem_cgroup *target_memcg)
 	VM_BUG_ON_PAGE(!PageLocked(page), page);
 
 	lruvec = mem_cgroup_lruvec(target_memcg, pgdat);
-	workingset_age_nonresident(lruvec, thp_nr_pages(page));
 	/* XXX: target_memcg can be NULL, go through lruvec */
 	memcgid = mem_cgroup_id(lruvec_memcg(lruvec));
 	eviction = atomic_long_read(&lruvec->nonresident_age);
+	workingset_age_nonresident(lruvec, thp_nr_pages(page));
 	return pack_shadow(memcgid, pgdat, eviction, PageWorkingset(page));
 }
 
#2 lore raw
In reply to Oscar Salvador
Quoted 19 lines · Oscar Salvador

The premise of the refault distance is that it can be seen as a deficit of the inactive list space, so that if the inactive list would have had (R - E) more slots, the page would not have been evicted but promoted to the active list instead.

However, the way the code is ordered right now set us to be off by one, so the real number of slots would be (R - E) + 1.
I stumbled upon this when trying to understand the code and it puzzled me that the comments did not match what the code did.

This it not an issue at all since evictions and refaults tend to happen in a number large enough that being off-by-one does not have any impact
- and since the compiler and CPUs are free to rearrange the execution sequence anyway.
But as Johannes says, it is better to re-arrange the code in the proper order since otherwise would be misleading to somebody who is actively reading and trying to understand the logic of the code - like it happened to me.

Quoted 2 lines

Hi Andrew,

is this on your radar?

Thanks!

Signature · 2 lines
Oscar Salvador
SUSE L3
#3 lore raw
Quoted 3 lines · Oscar Salvador

Hi Andrew,

is this on your radar?

Please, disregard this, I was obviously blind as I did not spot it in mmotm.

Quoted 7 lines

Thanks!

Signature · 2 lines
Oscar Salvador
SUSE L3
Signature · 2 lines
Oscar Salvador
SUSE L3