Skip to contentSkip to conversation

mm: remove offset check on page->compound_head and folio->lru

PATCH In review Wei Yang 4 participants 18 messages Jan 6, 2022 – Feb 24, 2022 MM core

lore
Share & tools
lore

Wei Yang

author
#0 lore raw

PATCH 1/1 mm: remove offset check on page->compound_head and folio->lru

FOLIO_MATCH() is used to make sure struct page and folio has identical layout for the first several words.

The comparison of offset between page->compound_head and folio->lru is more like an internal check in struct page.

This patch just removes it.

---
 include/linux/mm_types.h | 1 -
 1 file changed, 1 deletion(-)
include/linux/mm_types.h +0 -1
index 0a2de709fe40..087d6768bc78 100644
@@ -289,7 +289,6 @@ static_assert(sizeof(struct page) == sizeof(struct folio));
 FOLIO_MATCH(flags, flags);
 FOLIO_MATCH(lru, lru);
 FOLIO_MATCH(mapping, mapping);
-FOLIO_MATCH(compound_head, lru);
 FOLIO_MATCH(index, index);
 FOLIO_MATCH(private, private);
 FOLIO_MATCH(_mapcount, _mapcount);
Signature · 1 line
2.33.1
#1 lore raw
Quoted 9 lines · Wei Yang

FOLIO_MATCH() is used to make sure struct page and folio has identical layout for the first several words.

The comparison of offset between page->compound_head and folio->lru is more like an internal check in struct page.

This patch just removes it.

No.

author
#2 lore raw
Quoted 4 lines · Matthew Wilcox
Quoted 3 lines · Wei Yang

FOLIO_MATCH() is used to make sure struct page and folio has identical layout for the first several words.

Quoted 8 lines
Quoted 6 lines

The comparison of offset between page->compound_head and folio->lru is more like an internal check in struct page.

This patch just removes it.

No.

Hi, Matthew

Would you mind sharing some insight on this check?

Signature · 2 lines
Wei Yang
Help you, Help me
#3 lore raw
Quoted 10 lines · Wei Yang
Quoted 9 lines · Matthew Wilcox
Quoted 8 lines · Wei Yang

FOLIO_MATCH() is used to make sure struct page and folio has identical layout for the first several words.

The comparison of offset between page->compound_head and folio->lru is more like an internal check in struct page.

This patch just removes it.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

No.

Hi, Matthew

Would you mind sharing some insight on this check?

It's right there in the comments. If you can't be bothered to read, why should I write?

maintainer
#4 lore raw
Quoted 13 lines · On Fri, 7 Jan 2022 22:11:20 +0000 Matthew Wilcox <[email protected]> wrote:
Quoted 12 lines · Wei Yang
Quoted 11 lines · Matthew Wilcox
Quoted 9 lines · Wei Yang

FOLIO_MATCH() is used to make sure struct page and folio has identical layout for the first several words.

The comparison of offset between page->compound_head and folio->lru is more like an internal check in struct page.

This patch just removes it.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

No.

Hi, Matthew

Would you mind sharing some insight on this check?

It's right there in the comments.

Well I can't figure out which comment you're referring to?

Quoted 1 line

If you can't be bothered to read, why should I write?

I don't think the punishment comes close to fitting the crime here :(

#5 lore raw
Quoted 17 lines · Andrew Morton
Quoted 15 lines · On Fri, 7 Jan 2022 22:11:20 +0000 Matthew Wilcox <[email protected]> wrote:
Quoted 14 lines · Wei Yang
Quoted 12 lines · Matthew Wilcox
Quoted 9 lines · Wei Yang

FOLIO_MATCH() is used to make sure struct page and folio has identical layout for the first several words.

The comparison of offset between page->compound_head and folio->lru is more like an internal check in struct page.

This patch just removes it.

No.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Hi, Matthew

Would you mind sharing some insight on this check?

It's right there in the comments.

Well I can't figure out which comment you're referring to?

* WARNING: bit 0 of the first word is used for PageTail(). That
* means the other users of this union MUST NOT use the bit to
* avoid collision and false-positive PageTail().

Quoted 3 lines
Quoted 1 line

If you can't be bothered to read, why should I write?

I don't think the punishment comes close to fitting the crime here :(

I felt I had to NACk it as quickly as possible so you didn't apply it. Otherwise I'd've waited until I was back from holiday before replying to the earlier patch. But you applied that lickety-split, so clearly I'm not allowed to take a week off.

maintainer
#6 lore raw
Quoted 8 lines · On Sat, 8 Jan 2022 00:49:53 +0000 Matthew Wilcox <[email protected]> wrote:
Quoted 3 lines
Quoted 1 line

If you can't be bothered to read, why should I write?

I don't think the punishment comes close to fitting the crime here :(

I felt I had to NACk it as quickly as possible so you didn't apply it. Otherwise I'd've waited until I was back from holiday before replying to the earlier patch. But you applied that lickety-split, so clearly I'm not allowed to take a week off.

https://lkml.kernel.org/r/[email protected] ?

Yeah, I stashed that away on top of linux-next so it wouldn't fall through the cracks. But folios is Matthew stuff so I wouldn't expect to be sending it upstream without you having commented on it.

author
#7 lore raw
In reply to Matthew Wilcox
Quoted 7 lines · Matthew Wilcox
Quoted 6 lines · Andrew Morton
Quoted 4 lines · On Fri, 7 Jan 2022 22:11:20 +0000 Matthew Wilcox <[email protected]> wrote:
Quoted 3 lines

Hi, Matthew

Would you mind sharing some insight on this check?

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

It's right there in the comments.

Well I can't figure out which comment you're referring to?

* WARNING: bit 0 of the first word is used for PageTail(). That
* means the other users of this union MUST NOT use the bit to
* avoid collision and false-positive PageTail().

I know this requirement on bit 0 of first word. But I don't see the connection between this and the check of page->compound_head and folio->lru.

This is more like a internal requirement on struct page. There are 8 struct in this five words union. And this requirement apply to bit 0 of first word of all those five struct.

To me, if folio has the same layout of page, folio meets this requirement. I still not catch the point why we need this check here.

Signature · 2 lines
Wei Yang
Help you, Help me
author
#8 lore raw
Quoted 20 lines · Wei Yang
Quoted 7 lines · Matthew Wilcox
Quoted 6 lines · Andrew Morton
Quoted 4 lines · On Fri, 7 Jan 2022 22:11:20 +0000 Matthew Wilcox <[email protected]> wrote:
Quoted 3 lines

Hi, Matthew

Would you mind sharing some insight on this check?

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

It's right there in the comments.

Well I can't figure out which comment you're referring to?

* WARNING: bit 0 of the first word is used for PageTail(). That
* means the other users of this union MUST NOT use the bit to
* avoid collision and false-positive PageTail().

I know this requirement on bit 0 of first word. But I don't see the connection between this and the check of page->compound_head and folio->lru.

Quoted 7 lines

This is more like a internal requirement on struct page. There are 8 struct in this five words union. And this requirement apply to bit 0 of first word of all those five struct.

To me, if folio has the same layout of page, folio meets this requirement. I still not catch the point why we need this check here.

Hi, Matthew

Are you back from vocation? If you could give more insight on this check, I would be appreciated.

Signature · 2 lines
Wei Yang
Help you, Help me
#9 lore raw
Quoted 25 lines · Wei Yang
Quoted 24 lines · Wei Yang
Quoted 7 lines · Matthew Wilcox
Quoted 6 lines · Andrew Morton
Quoted 4 lines · On Fri, 7 Jan 2022 22:11:20 +0000 Matthew Wilcox <[email protected]> wrote:
Quoted 3 lines

Hi, Matthew

Would you mind sharing some insight on this check?

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

It's right there in the comments.

Well I can't figure out which comment you're referring to?

* WARNING: bit 0 of the first word is used for PageTail(). That
* means the other users of this union MUST NOT use the bit to
* avoid collision and false-positive PageTail().

I know this requirement on bit 0 of first word. But I don't see the connection between this and the check of page->compound_head and folio->lru.

This is more like a internal requirement on struct page. There are 8 struct in this five words union. And this requirement apply to bit 0 of first word of all those five struct.

Quoted 8 lines
Quoted 3 lines

To me, if folio has the same layout of page, folio meets this requirement. I still not catch the point why we need this check here.

Hi, Matthew

Are you back from vocation? If you could give more insight on this check, I would be appreciated.

I can offer my insight (which might be of course wrong). Ideally one day page.lru will be gone and only folio will be used for LRU pages. Then there won't be a FOLIO_MATCH(lru, lru); and FOLIO_MATCH(compound_head, lru); won't appear to be redundant anymore. lru is list_head so two pointers and thus valid pointers are aligned in such a way they can't accidentaly set the bit 0.

author
#10 lore raw
Quoted 32 lines · Vlastimil Babka
Quoted 31 lines · Wei Yang
Quoted 20 lines · Wei Yang
Quoted 7 lines · Matthew Wilcox
Quoted 6 lines · Andrew Morton
Quoted 4 lines · On Fri, 7 Jan 2022 22:11:20 +0000 Matthew Wilcox <[email protected]> wrote:
Quoted 3 lines

Hi, Matthew

Would you mind sharing some insight on this check?

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

It's right there in the comments.

Well I can't figure out which comment you're referring to?

* WARNING: bit 0 of the first word is used for PageTail(). That
* means the other users of this union MUST NOT use the bit to
* avoid collision and false-positive PageTail().

I know this requirement on bit 0 of first word. But I don't see the connection between this and the check of page->compound_head and folio->lru.

Quoted 7 lines

This is more like a internal requirement on struct page. There are 8 struct in this five words union. And this requirement apply to bit 0 of first word of all those five struct.

To me, if folio has the same layout of page, folio meets this requirement. I still not catch the point why we need this check here.

Hi, Matthew

Quoted 7 lines
Quoted 2 lines

Are you back from vocation? If you could give more insight on this check, I would be appreciated.

I can offer my insight (which might be of course wrong). Ideally one day page.lru will be gone and only folio will be used for LRU pages. Then there won't be a FOLIO_MATCH(lru, lru); and FOLIO_MATCH(compound_head, lru); won't appear to be redundant anymore. lru is list_head so two pointers and

Thanks for your comment.

I can't imagine the final result. If we would remove page.lru, we could remove FOLIO_MATCH(lru, lru) and add FOLIO_MATCH(compound_head, lru) at that moment?

Quoted 3 lines

thus valid pointers are aligned in such a way they can't accidentaly set the bit 0.

Signature · 2 lines
Wei Yang
Help you, Help me
#11 lore raw
Quoted 20 lines · Wei Yang
Quoted 11 lines · Vlastimil Babka
Quoted 10 lines · Wei Yang
Quoted 6 lines · Wei Yang
Quoted 1 line · Matthew Wilcox

On Fri, Jan 07, 2022 at 04:08:25PM -0800, Andrew Morton wrote:

To me, if folio has the same layout of page, folio meets this requirement. I still not catch the point why we need this check here.

Hi, Matthew

Quoted 7 lines
Quoted 2 lines

Are you back from vocation? If you could give more insight on this check, I would be appreciated.

I can offer my insight (which might be of course wrong). Ideally one day page.lru will be gone and only folio will be used for LRU pages. Then there won't be a FOLIO_MATCH(lru, lru); and FOLIO_MATCH(compound_head, lru); won't appear to be redundant anymore. lru is list_head so two pointers and

Quoted 4 lines

Thanks for your comment.

I can't imagine the final result. If we would remove page.lru, we could remove FOLIO_MATCH(lru, lru) and add FOLIO_MATCH(compound_head, lru) at that moment?

Yes, or we could forget to do it. Adding it right now is another option that Matthew has chosen and I don't see a strong reason to change it. Can you measure a kernel build speedup thanks to removing the now redundant check?

Quoted 4 lines
Quoted 3 lines

thus valid pointers are aligned in such a way they can't accidentaly set the bit 0.

author
#12 lore raw
Quoted 21 lines · Vlastimil Babka
Quoted 20 lines · Wei Yang
Quoted 18 lines · Vlastimil Babka
Quoted 4 lines · Wei Yang
Quoted 3 lines · Wei Yang
Quoted 1 line · Matthew Wilcox

On Fri, Jan 07, 2022 at 04:08:25PM -0800, Andrew Morton wrote:

Quoted 8 lines
Quoted 3 lines

To me, if folio has the same layout of page, folio meets this requirement. I still not catch the point why we need this check here.

Hi, Matthew

Are you back from vocation? If you could give more insight on this check, I would be appreciated.

I can offer my insight (which might be of course wrong). Ideally one day page.lru will be gone and only folio will be used for LRU pages. Then there won't be a FOLIO_MATCH(lru, lru); and FOLIO_MATCH(compound_head, lru); won't appear to be redundant anymore. lru is list_head so two pointers and

Quoted 9 lines
Quoted 4 lines

Thanks for your comment.

I can't imagine the final result. If we would remove page.lru, we could remove FOLIO_MATCH(lru, lru) and add FOLIO_MATCH(compound_head, lru) at that moment?

Yes, or we could forget to do it. Adding it right now is another option that Matthew has chosen and I don't see a strong reason to change it. Can you measure a kernel build speedup thanks to removing the now redundant check?

If we forget to do it, the compile would fail, right?

Put it here for a future reason is not persuasive.

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

thus valid pointers are aligned in such a way they can't accidentaly set the bit 0.

Signature · 2 lines
Wei Yang
Help you, Help me
#13 lore raw
Quoted 15 lines · Wei Yang
Quoted 14 lines · Vlastimil Babka
Quoted 12 lines · Wei Yang
Quoted 6 lines · Vlastimil Babka

On 1/23/22 02:38, Wei Yang wrote:

I can offer my insight (which might be of course wrong). Ideally one day page.lru will be gone and only folio will be used for LRU pages. Then there won't be a FOLIO_MATCH(lru, lru); and FOLIO_MATCH(compound_head, lru); won't appear to be redundant anymore. lru is list_head so two pointers and

Thanks for your comment.

I can't imagine the final result. If we would remove page.lru, we could remove FOLIO_MATCH(lru, lru) and add FOLIO_MATCH(compound_head, lru) at that moment?

Quoted 6 lines
Quoted 4 lines

Yes, or we could forget to do it. Adding it right now is another option that Matthew has chosen and I don't see a strong reason to change it. Can you measure a kernel build speedup thanks to removing the now redundant check?

If we forget to do it, the compile would fail, right?

No, FOLIO_MATCH is like a build-time assert. It can only fail if the assert is there, and the condition evaluates to false.
If it's not there and the condition is false, it will instead mysteriously crash on runtime, which is worse.

Quoted 7 lines

Put it here for a future reason is not persuasive.

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

thus valid pointers are aligned in such a way they can't accidentaly set the bit 0.

author
#14 lore raw
Quoted 21 lines · Vlastimil Babka
Quoted 20 lines · Wei Yang
Quoted 18 lines · Vlastimil Babka
Quoted 8 lines · Wei Yang
Quoted 6 lines · Vlastimil Babka

On 1/23/22 02:38, Wei Yang wrote:

I can offer my insight (which might be of course wrong). Ideally one day page.lru will be gone and only folio will be used for LRU pages. Then there won't be a FOLIO_MATCH(lru, lru); and FOLIO_MATCH(compound_head, lru); won't appear to be redundant anymore. lru is list_head so two pointers and

Quoted 4 lines

Thanks for your comment.

I can't imagine the final result. If we would remove page.lru, we could remove FOLIO_MATCH(lru, lru) and add FOLIO_MATCH(compound_head, lru) at that moment?

Yes, or we could forget to do it. Adding it right now is another option that Matthew has chosen and I don't see a strong reason to change it. Can you measure a kernel build speedup thanks to removing the now redundant check?

Quoted 4 lines
Quoted 1 line

If we forget to do it, the compile would fail, right?

No, FOLIO_MATCH is like a build-time assert. It can only fail if the assert is there, and the condition evaluates to false.

Currently we have this check

FOLIO_MATCH(lru, lru)

Which checks page->lru and folio->lru.

As you mentioned page->lru would be gone. So this check would fail at compile?

Signature · 2 lines
Wei Yang
Help you, Help me
author
#15 lore raw
In reply to Vlastimil Babka

On Mon, Jan 24, 2022 at 11:30:10AM +0100, Vlastimil Babka wrote:
[...]

Quoted 5 lines
Quoted 4 lines

Hi, Matthew

Are you back from vocation? If you could give more insight on this check, I would be appreciated.

Quoted 7 lines

I can offer my insight (which might be of course wrong). Ideally one day page.lru will be gone and only folio will be used for LRU pages. Then there won't be a FOLIO_MATCH(lru, lru); and FOLIO_MATCH(compound_head, lru); won't appear to be redundant anymore. lru is list_head so two pointers and thus valid pointers are aligned in such a way they can't accidentaly set the bit 0.

Hmm... I see your change on struct slab. I guess I got your point.

Seems we would shrink struct page...

Signature · 2 lines
Wei Yang
Help you, Help me
author
#16 lore raw
In reply to Matthew Wilcox
Quoted 3 lines · Matthew Wilcox
Quoted 2 lines · Andrew Morton

On Fri, 7 Jan 2022 22:11:20 +0000 Matthew Wilcox <[email protected]> wrote:

[...]

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

Hi, Matthew

Would you mind sharing some insight on this check?

Quoted 10 lines
Quoted 3 lines
Quoted 1 line

It's right there in the comments.

Well I can't figure out which comment you're referring to?

* WARNING: bit 0 of the first word is used for PageTail(). That
* means the other users of this union MUST NOT use the bit to
* avoid collision and false-positive PageTail().

Quoted 2 lines
Quoted 1 line

If you can't be bothered to read, why should I write?

Hi, Matthew

This change is introduced in commit 1d798ca3f164 'mm: make compound_head() robust'.

As mentioned in the changelog.

```
    That means page->compound_head shares storage space with:

    - page->lru.next;
    - page->next;
    - page->rcu_head.next;
```

We need to make sure those fields in page don't use bit 0 of the word.

So this is an internal guarantee in struct page. I don't see the reason to compare page->compound_head and folio->lru here.

Maybe I miss something. If you would explain a little, I would appreciate much.

Signature · 2 lines
Wei Yang
Help you, Help me
author
#17 lore raw
In reply to Matthew Wilcox
Quoted 6 lines · Matthew Wilcox
Quoted 3 lines

Hi, Matthew

Would you mind sharing some insight on this check?

It's right there in the comments. If you can't be bothered to read, why should I write?

I am not sure which comments it refers to.

Maybe we can add a "Refer to comment" above this code?

Signature · 2 lines
Wei Yang
Help you, Help me