mm: move offset_in_page() to page_helpers.h
Subsystems (4)
PATCH 1/3 mm: move offset_in_page() to page_helpers.h
Move offset_in_page() out of linux/mm.h so users that only need page offset calculations can include this lightweight header instead of pulling in all of linux/mm.h.
--- include/linux/mm.h | 2 +- include/linux/page_helpers.h | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 include/linux/page_helpers.h
include/linux/mm.h +1 -1
@@ -17,6 +17,7 @@#include <linux/mm_types.h> #include <linux/mmap_lock.h> #include <linux/range.h> +#include <linux/page_helpers.h> #include <linux/pfn.h> #include <linux/percpu-refcount.h> #include <linux/bit_spinlock.h>
@@ -3033,7 +3034,6 @@ static inline void clear_page_pfmemalloc(struct page *page)*/ extern void pagefault_out_of_memory (void ); -#define offset_in_page (p) ((unsigned long)(p) & ~PAGE_MASK)#define offset_in_folio (folio, p) ((unsigned long)(p) & (folio_size(folio) - 1))/*
include/linux/page_helpers.h new file +10 -0
@@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef _LINUX_PAGE_HELPERS_H +#define _LINUX_PAGE_HELPERS_H + +#include <asm/page.h> + +#define offset_in_page (p) ((unsigned long)(p) & ~PAGE_MASK) + +#endif /* _LINUX_PAGE_HELPERS_H */
PATCH 2/3 mm: add bytes_to_page_end() helper
Add bytes_to_page_end() for the common PAGE_SIZE - offset_in_page() calculation.
--- include/linux/page_helpers.h | 1 + 1 file changed, 1 insertion(+)
include/linux/page_helpers.h +1 -0
@@ -6,5 +6,6 @@#include <asm/page.h> #define offset_in_page (p) ((unsigned long)(p) & ~PAGE_MASK) +#define bytes_to_page_end (p) (PAGE_SIZE - offset_in_page(p))#endif /* _LINUX_PAGE_HELPERS_H */
PATCH 3/3 lib/bitmap: use bytes_to_page_end() helper
In reply to Thorsten Blumbitmap-str.c includes linux/mm.h for offset_in_page() and kfree(). Instead, include linux/page_helpers.h and linux/slab.h directly, and use bytes_to_page_end() to simplify the code.
--- lib/bitmap-str.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
lib/bitmap-str.c +3 -2
@@ -7,7 +7,8 @@#include <linux/export.h> #include <linux/hex.h> #include <linux/kernel.h> -#include <linux/mm.h> +#include <linux/page_helpers.h> +#include <linux/slab.h> #include <linux/string.h> #include "kstrtox.h"
@@ -58,7 +59,7 @@ EXPORT_SYMBOL(bitmap_parse_user);int bitmap_print_to_pagebuf (bool list,char *buf,const unsigned long *maskp,int nmaskbits) { -ptrdiff_t len =PAGE_SIZE -offset_in_page (buf); +ptrdiff_t len =bytes_to_page_end (buf);return list ?scnprintf (buf, len,"%*pbl\n" , nmaskbits, maskp) :scnprintf (buf, len,"%*pb\n" , nmaskbits, maskp);
Re: [PATCH 2/3] mm: add bytes_to_page_end() helper
In reply to Thorsten BlumQuoted 14 lines · Thorsten Blum
Add
bytes_to_page_end()for the commonPAGE_SIZE-offset_in_page()calculation.Suggested-by Andy Shevchenko <[email protected]>Signed-off-by Thorsten Blum <[email protected]>--- include/linux/page_helpers.h | 1 + 1 file changed, 1 insertion(+)include/linux/page_helpers.h +0
-0
include/linux/page_helpers.h line 11
Quoted 6 lines
include/linux/page_helpers.h +1
-0@@ -6,5 +6,6 @@#include <asm/page.h> #define offset_in_page (p) ((unsigned long)(p) & ~PAGE_MASK) +#define bytes_to_page_end (p) (PAGE_SIZE - offset_in_page(p))#endif /* _LINUX_PAGE_HELPERS_H */
I've got a series for this
https://lore.kernel.org/all/[email protected]/
The feedback is surprisingly negative. Please add people from that thread. Maybe you'll be more successful convincing them.
Thanks,
Yury
Re: [PATCH 2/3] mm: add bytes_to_page_end() helper
Quoted 1 line · Yury Norov
On Sun, May 17, 2026 at 02:34:30PM +0200, Thorsten Blum wrote:
...
Quoted 6 lines
I've got a series for this
https://lore.kernel.org/all/[email protected]/
The feedback is surprisingly negative. Please add people from that thread. Maybe you'll be more successful convincing them.
We always can simply fork, but I truly do not understand the pushback. These are simple macros that are way spread in the kernel, "include everything" kinda linux/mm.h is not needed in vast majority of the users, hence the split is logical step.
I'm in favour of this series.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 2/3] mm: add bytes_to_page_end() helper
In reply to Thorsten BlumQuoted 2 lines · Thorsten Blum
Add
bytes_to_page_end()for the commonPAGE_SIZE-offset_in_page()calculation.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 3 lines · Thorsten Blum
Move
offset_in_page()out oflinux/mm.hso users that only need page offset calculations can include this lightweight header instead of pulling in all oflinux/mm.h.
Yep, the whole mm.h is rarely used in the cases where this and a new one (next patch) are being (going to be) used.
(Do we need to update MAINTAINERS / Documentation parts anywhere?)
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 2/3] mm: add bytes_to_page_end() helper
In reply to Yury NorovQuoted 20 lines · On Sun, 17 May 2026 11:28:05 -0400 Yury Norov <[email protected]> wrote:
Quoted 19 lines · Thorsten Blum
Add
bytes_to_page_end()for the commonPAGE_SIZE-offset_in_page()calculation.Suggested-by Andy Shevchenko <[email protected]>Signed-off-by Thorsten Blum <[email protected]>--- include/linux/page_helpers.h | 1 + 1 file changed, 1 insertion(+)include/linux/page_helpers.h +1
-0@@ -6,5 +6,6 @@#include <asm/page.h> #define offset_in_page (p) ((unsigned long)(p) & ~PAGE_MASK) +#define bytes_to_page_end (p) (PAGE_SIZE - offset_in_page(p))
Quoted 8 lines
include/linux/page_helpers.h line 11
Quoted 1 line
include/linux/page_helpers.h +0
-0#endif /* _LINUX_PAGE_HELPERS_H */ I've got a series for this
https://lore.kernel.org/all/[email protected]/
The feedback is surprisingly negative. Please add people from that thread. Maybe you'll be more successful convincing them.
I don't think you need a another new header.
There is already vdso/page.h which is where PAGE_MASK comes from.
-- David
Quoted 4 lines
Thanks,
Yury
Lorenzo Stoakes
reviewerSeriously, please resend this.
This is 3 patches with 2 in-reply-to 1/3, that's not how we do series in mm, take a look around :)
Write a cover letter, and have all the patches in-reply-to that.
Was there not previous versions of this? I _seem_ to remember that, but might be misremembering :)
Also I'm really questioning the value of this, you've not sold why we should take this whatsoever.
'Add a random new header file we have to maintain because it's smaller' is not really hugely compelling.
Also a _lot_ of stuff in the kernel ultimately pulls in mm.h. So what exactly has the specific requirement of both needing this define and (somehow) doesn't use mm?
Quoted 3 lines · Thorsten Blum
Move
offset_in_page()out oflinux/mm.hso users that only need page offset calculations can include this lightweight header instead of pulling in all oflinux/mm.h.
What's the motivation? What caused you to want to do this? Why should we have a new tiny header with only this define? What makes that important?
Why is pulling in a 'big' header file such an issue?
This commit message is pretty useless right now, you're just saying what you're doing, yeah I can see that from the diff.
You should use the commit message to explain why and what for etc.
Quoted 5 lines
Signed-off-by Thorsten Blum <[email protected]>--- include/linux/mm.h | 2 +- include/linux/page_helpers.h | 10 ++++++++++
You've added a new file and not updated MAINTAINERS, nor indicated that it will be caught by a glob?
Also super super restrictive to have 'page helpers', that's likely to be tiny forever, why not just move this macro to mm_types.h and import that instead? It's highly likely it's already imported wherever you need it, anyway.
Quoted 29 lines
2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 include/linux/page_helpers.hinclude/linux/mm.h +1
-1@@ -17,6 +17,7 @@#include <linux/mm_types.h> #include <linux/mmap_lock.h> #include <linux/range.h> +#include <linux/page_helpers.h> #include <linux/pfn.h> #include <linux/percpu-refcount.h> #include <linux/bit_spinlock.h> @@ -3033,7 +3034,6 @@ static inline void clear_page_pfmemalloc(struct page *page)*/ extern void pagefault_out_of_memory (void ); -#define offset_in_page (p) ((unsigned long)(p) & ~PAGE_MASK)#define offset_in_folio (folio, p) ((unsigned long)(p) & (folio_size(folio) - 1))/* include/linux/page_helpers.h new file +0
-0
include/linux/page_helpers.h line 1
Quoted 1 line
include/linux/page_helpers.h new file +1
-0@@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0 */
No description of what this is for?
include/linux/page_helpers.h line 8
Quoted 7 lines
include/linux/page_helpers.h new file +7
-0+ +#ifndef _LINUX_PAGE_HELPERS_H +#define _LINUX_PAGE_HELPERS_H + +#include <asm/page.h> + +#define offset_in_page (p) ((unsigned long)(p) & ~PAGE_MASK)
Why are you only porting the page version when ostensibly folios are more likely to be the unit-of-operation in future?
include/linux/page_helpers.h line 10
Quoted 2 lines
include/linux/page_helpers.h new file +2
-0+ +#endif /* _LINUX_PAGE_HELPERS_H */
Thanks, Lorenzo
Lorenzo Stoakes
reviewerRe: [PATCH 2/3] mm: add bytes_to_page_end() helper
In reply to Andy ShevchenkoQuoted 11 lines · Andy Shevchenko
Quoted 1 line · Yury Norov
On Sun, May 17, 2026 at 02:34:30PM +0200, Thorsten Blum wrote:
...
Quoted 6 lines
I've got a series for this
https://lore.kernel.org/all/[email protected]/
The feedback is surprisingly negative. Please add people from that thread. Maybe you'll be more successful convincing them.
There's a cost to adding yet more super-specific headers where stuff gets hidden and people don't know where to put what, things quickly become a mess and header dependencies are already a nightmare.
Also in the case of this helper, I don't see the value in adding a vague, untyped, confusingly-named macro when PAGE_SIZE - offset_in_page() is perfectly cromulent and clear in what it's doing?
Quoted 2 lines
We always can simply fork, but I truly do not understand the pushback.
Well, be my guest? This isn't a hugely helpful or friendly comment.
Quoted 3 lines
These are simple macros that are way spread in the kernel, "include everything" kinda
linux/mm.his not needed in vast majority of the users, hence the split is logical step.
Right but that's completely orthogonal to adding this macro?
I'm fine with moving offset_in_page() to e.g. mm_types.h.
But a series that doesn't even give any actual motivation for the change is not convicing, and we aren't required to just accept any change.
Quoted 2 lines
I'm in favour of this series.
OK, I'm not :)
Quoted 6 lines
--
With Best Regards,
Andy Shevchenko
Thanks, Lorenzo
Lorenzo Stoakes
reviewerRe: [PATCH 2/3] mm: add bytes_to_page_end() helper
In reply to Thorsten BlumWhy is this a separate commit? It's tiny, I don't think it needs to be separated at all.
Quoted 2 lines · Thorsten Blum
Add
bytes_to_page_end()for the commonPAGE_SIZE-offset_in_page()calculation.
This is a totally useless commit message. Again you're not indicating why it's needed. Please look around mm to get a sense of how commit messages should look.
Also it's so common that you have exactly zero callers updated here or elsewhere?
I see uses which are all pretty specific. I wonder if it's really useful to make this its own thing?
And it's untyped and etc. etc. yeah, it's a no really to this.
Quoted 2 lines
Suggested-by Andy Shevchenko <[email protected]>
Was there a previous discussion that led to this series? You should really give some background somewhere (like a cover letter, and if previous revisions were sent, a history of them below the ---)
Quoted 1 line
Signed-off-by Thorsten Blum <[email protected]>
Again I'm really unconvinced you need to do any of this.
include/linux/page_helpers.h line 8
Quoted 12 lines
--- include/linux/page_helpers.h | 1 + 1 file changed, 1 insertion(+)include/linux/page_helpers.h +0
-0@@ -6,5 +6,6 @@#include <asm/page.h> #define offset_in_page (p) ((unsigned long)(p) & ~PAGE_MASK)
I mean another thing about this (and yes this was existing but since you're proposing making this rather special it's worth raising) is that it's enormously un-typesafe and 'p' is vague, what if somebody put a (struct page *) here?
It'd be better if it was a static inline function, maybe there's places which use this already that require it to be a macro but perhaps not.
include/linux/page_helpers.h line 9
Quoted 1 line
include/linux/page_helpers.h +1
-0+#define bytes_to_page_end (p) (PAGE_SIZE - offset_in_page(p))
Here, since, you're adding it, there's no excuse at all for it being a macro. And you're implementing something just as horribly vague as the other form, it's not obvious 'p' is meant to be a pointer. Page begins with p too :)
Anyway I'm not really convinced this is useful.
include/linux/page_helpers.h line 11
Quoted 2 lines
include/linux/page_helpers.h +0
-0#endif /* _LINUX_PAGE_HELPERS_H */
Thanks, Lorenzo
Lorenzo Stoakes
reviewerRe: [PATCH 2/3] mm: add bytes_to_page_end() helper
In reply to David LaightQuoted 27 lines · David Laight
Quoted 24 lines · On Sun, 17 May 2026 11:28:05 -0400 Yury Norov <[email protected]> wrote:
Quoted 14 lines · Thorsten Blum
Add
bytes_to_page_end()for the commonPAGE_SIZE-offset_in_page()calculation.Suggested-by Andy Shevchenko <[email protected]>Signed-off-by Thorsten Blum <[email protected]>--- include/linux/page_helpers.h | 1 + 1 file changed, 1 insertion(+)include/linux/page_helpers.h +0
-0include/linux/page_helpers.h line 11
Quoted 6 lines
include/linux/page_helpers.h +1
-0@@ -6,5 +6,6 @@#include <asm/page.h> #define offset_in_page (p) ((unsigned long)(p) & ~PAGE_MASK) +#define bytes_to_page_end (p) (PAGE_SIZE - offset_in_page(p))#endif /* _LINUX_PAGE_HELPERS_H */ I've got a series for this
Quoted 7 lines
Quoted 4 lines
https://lore.kernel.org/all/[email protected]/
The feedback is surprisingly negative. Please add people from that thread. Maybe you'll be more successful convincing them.
I don't think you need a another new header.
There is alreadyvdso/page.hwhich is wherePAGE_MASKcomes from.
Yeah please don't, that's already a weird situation I don't really love the idea of extending that.
mm_types.h seems the more appropriate place.
Quoted 8 lines
-- David
Quoted 4 lines
Thanks,
Yury
Thanks, Lorenzo
Lorenzo Stoakes
reviewerRe: [PATCH 3/3] lib/bitmap: use bytes_to_page_end() helper
In reply to Thorsten BlumQuoted 1 line · Thorsten Blum
bitmap-str.cincludeslinux/mm.hforoffset_in_page()andkfree().
I'd specifically say that it's including linux/mm.h which in turn includes linux/slab.h and that you're fixing this, because saying you include mm.h for kfree() is a little confusing.
Quoted 2 lines
Instead, include
linux/page_helpers.handlinux/slab.hdirectly, and usebytes_to_page_end()to simplify the code.
This is again, a useless commit message. You're not explaining why what for, how etc., you're putting in words what the code is doing.
And I'm still very confused as to what the motive is here overall. What's so problematic about including that header? Longer compile times, somehow? If so, what are the measurements before/after this change? What was the problem that led to it? Etc.
We could end up with hundreds of super specific headers files for things, so there really has to be a good reason for it.
Quoted 21 lines
Signed-off-by Thorsten Blum <[email protected]>--- lib/bitmap-str.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)lib/bitmap-str.c +2
-1@@ -7,7 +7,8 @@#include <linux/export.h> #include <linux/hex.h> #include <linux/kernel.h> -#include <linux/mm.h> +#include <linux/page_helpers.h> +#include <linux/slab.h> #include <linux/string.h> #include "kstrtox.h"
lib/bitmap-str.c EXPORT_SYMBOL(bitmap_parse_user); · line 62
Quoted 5 lines
lib/bitmap-str.c +1
-1@@ -58,7 +59,7 @@ EXPORT_SYMBOL(bitmap_parse_user);int bitmap_print_to_pagebuf (bool list,char *buf,const unsigned long *maskp,int nmaskbits) { -ptrdiff_t len =PAGE_SIZE -offset_in_page (buf); +ptrdiff_t len =bytes_to_page_end (buf);
yeah this is kind of nasty, going from a clear thing to a 'I wonder how that is implemented' mystery meat function. I think the original is better.
lib/bitmap-str.c EXPORT_SYMBOL(bitmap_parse_user); · line 65
Quoted 3 lines
lib/bitmap-str.c +0
-0return list ?scnprintf (buf, len,"%*pbl\n" , nmaskbits, maskp) :scnprintf (buf, len,"%*pb\n" , nmaskbits, maskp);
Thanks, Lorenzo
Re: [PATCH 2/3] mm: add bytes_to_page_end() helper
In reply to Lorenzo StoakesAs with Lorenzo's concerns, my biggest issue with this change is that it becomes unclear what "page" means in this context.
Is it a base PAGE_SIZE page? A 2 MB "large" page? A 1 GB "huge" page on architectures that support it?
The "rest_of_page()" macro masks that distinction, where the current code’s explicit reference to PAGE_SIZE makes the basis of the calculation obvious.
I don’t see why we would want to obscure that behind a macro, especially when it makes the code harder to follow.
Quoted 53 lines · Lorenzo Stoakes
Quoted 11 lines · Andy Shevchenko
Quoted 2 lines · Yury Norov
On Sun, May 17, 2026 at 02:34:30PM +0200, Thorsten Blum wrote:
...
Quoted 6 lines
I've got a series for this
https://lore.kernel.org/all/[email protected]/
The feedback is surprisingly negative. Please add people from that thread. Maybe you'll be more successful convincing them.
There's a cost to adding yet more super-specific headers where stuff gets hidden and people don't know where to put what, things quickly become a mess and header dependencies are already a nightmare.
Also in the case of this helper, I don't see the value in adding a vague, untyped, confusingly-named macro when
PAGE_SIZE-offset_in_page()is perfectly cromulent and clear in what it's doing?Quoted 2 lines
We always can simply fork, but I truly do not understand the pushback.
Well, be my guest? This isn't a hugely helpful or friendly comment.
Quoted 3 lines
These are simple macros that are way spread in the kernel, "include everything" kinda
linux/mm.his not needed in vast majority of the users, hence the split is logical step.Right but that's completely orthogonal to adding this macro?
I'm fine with moving
offset_in_page()to e.g.mm_types.h.But a series that doesn't even give any actual motivation for the change is not convicing, and we aren't required to just accept any change.
Quoted 2 lines
I'm in favour of this series.
OK, I'm not :)
Quoted 6 lines
--
With Best Regards,
Andy ShevchenkoThanks, Lorenzo
Re: [PATCH 2/3] mm: add bytes_to_page_end() helper
In reply to Lorenzo Stoakes(My apologies for the earlier HTML encoding.)
As with Lorenzo's concerns, my biggest issue with this change is that it becomes unclear what "page" means in this context.
Is it a base PAGE_SIZE page? A 2 MB "large" page? A 1 GB "huge" page on architectures that support it?
The "rest_of_page()" macro masks that distinction, where the current code’s explicit reference to PAGE_SIZE makes the basis of the calculation obvious.
I don’t see why we would want to obscure that behind a macro, especially when it makes the code harder to follow.
Thanks,
Bill
Quoted 53 lines · Lorenzo Stoakes
Quoted 11 lines · Andy Shevchenko
Quoted 1 line · Yury Norov
On Sun, May 17, 2026 at 02:34:30PM +0200, Thorsten Blum wrote:
...
Quoted 6 lines
I've got a series for this
https://lore.kernel.org/all/[email protected]/
The feedback is surprisingly negative. Please add people from that thread. Maybe you'll be more successful convincing them.
There's a cost to adding yet more super-specific headers where stuff gets hidden and people don't know where to put what, things quickly become a mess and header dependencies are already a nightmare.
Also in the case of this helper, I don't see the value in adding a vague, untyped, confusingly-named macro when
PAGE_SIZE-offset_in_page()is perfectly cromulent and clear in what it's doing?Quoted 2 lines
We always can simply fork, but I truly do not understand the pushback.
Well, be my guest? This isn't a hugely helpful or friendly comment.
Quoted 3 lines
These are simple macros that are way spread in the kernel, "include everything" kinda
linux/mm.his not needed in vast majority of the users, hence the split is logical step.Right but that's completely orthogonal to adding this macro?
I'm fine with moving
offset_in_page()to e.g.mm_types.h.But a series that doesn't even give any actual motivation for the change is not convicing, and we aren't required to just accept any change.
Quoted 2 lines
I'm in favour of this series.
OK, I'm not :)
Quoted 6 lines
--
With Best Regards,
Andy ShevchenkoThanks, Lorenzo
Hi Lorenzo,
Quoted 6 lines · Lorenzo Stoakes
Seriously, please resend this.
This is 3 patches with 2 in-reply-to 1/3, that's not how we do series in mm, take a look around :)
Write a cover letter, and have all the patches in-reply-to that.
A cover letter seemed unnecessary for such a seemingly trivial 3-patch series, but this thread [1] might have been helpful for context.
[1] https://lore.kernel.org/lkml/CAHp75VfQNkqEYsO4Uup0c-uiYuVyAWit=tmCz2BsYLp-sjXsZw@mail.gmail.com/
Quoted 2 lines
Was there not previous versions of this? I _seem_ to remember that, but might be misremembering :)
I only know about the one Yury mentioned. This is v1 of my series.
Quoted 9 lines
Also I'm really questioning the value of this, you've not sold why we should take this whatsoever.
'Add a random new header file we have to maintain because it's smaller' is not really hugely compelling.
Also a _lot_ of stuff in the kernel ultimately pulls in
mm.h. So what exactly has the specific requirement of both needing this define and (somehow) doesn't use mm?
Patch 3/3 is one of many examples that pulls in all of mm.h just for offset_in_page(). lib/string.c from the same thread [1] is another example that would need to include mm.h just for offset_in_page().
Many other files (hundreds) don't use offset_in_page(), but open-code it in many different ways instead:
(unsigned long)p & ~PAGE_MASK (unsigned long)p & (PAGE_SIZE - 1) (long)p & (PAGE_SIZE - 1) ...
I can't tell whether they didn't know about offset_in_page(), or deliberately chose not to include mm.h.
Thanks,
Thorsten
Lorenzo Stoakes
reviewerQuoted 5 lines · Thorsten Blum
Hi Lorenzo,
Quoted 2 lines · Lorenzo Stoakes
Seriously, please resend this.
Quoted 7 lines
Quoted 4 lines
This is 3 patches with 2 in-reply-to 1/3, that's not how we do series in mm, take a look around :)
Write a cover letter, and have all the patches in-reply-to that.
A cover letter seemed unnecessary for such a seemingly trivial 3-patch series, but this thread [1] might have been helpful for context.
OK, but this is how we do multi-patch series in mm, as I said. It's always a good idea to look around a subsystem to get a sense of how things are done as a courtesy.
So politely request you do this :) though as I said I question this being broken out into as many patches as it is.
Quoted 14 lines
[1] https://lore.kernel.org/lkml/CAHp75VfQNkqEYsO4Uup0c-uiYuVyAWit=tmCz2BsYLp-sjXsZw@mail.gmail.com/
Quoted 2 lines
Was there not previous versions of this? I _seem_ to remember that, but might be misremembering :)
I only know about the one Yury mentioned. This is v1 of my series.
Quoted 6 lines
Also I'm really questioning the value of this, you've not sold why we should take this whatsoever.
'Add a random new header file we have to maintain because it's smaller' is not really hugely compelling.
Quoted 7 lines
Quoted 3 lines
Also a _lot_ of stuff in the kernel ultimately pulls in
mm.h. So what exactly has the specific requirement of both needing this define and (somehow) doesn't use mm?Patch 3/3 is one of many examples that pulls in all of
mm.hjust foroffset_in_page().lib/string.cfrom the same thread [1] is another example that would need to includemm.hjust foroffset_in_page().
And that's a problem why? Compile time? Somehow binary bloat? Conflicts? Confusion?
Quoted 11 lines
Many other files (hundreds) don't use
offset_in_page(), but open-code it in many different ways instead:(unsigned long)p & ~PAGE_MASK (unsigned long)p & (PAGE_SIZE - 1) (long)p & (PAGE_SIZE - 1) ...I can't tell whether they didn't know about
offset_in_page(), or deliberately chose not to includemm.h.
OK but this series doesn't address any of that? It just adds a new header, a questionable macro and uses it in one place? So those justifications are rather moot here.
Quoted 3 lines
Thanks,
Thorsten
Cheers, Lorenzo
David Hildenbrand (Arm)
maintainerQuoted 5 lines · Thorsten Blum
Hi Lorenzo,
Quoted 2 lines · Lorenzo Stoakes
Seriously, please resend this.
Quoted 7 lines
Quoted 4 lines
This is 3 patches with 2 in-reply-to 1/3, that's not how we do series in mm, take a look around :)
Write a cover letter, and have all the patches in-reply-to that.
A cover letter seemed unnecessary for such a seemingly trivial 3-patch series, but this thread [1] might have been helpful for context.
And that's, for example, something to point out in a very basic cover letter.
b4 and git-send-mail can automate the creation of a cover letter for you.
Signature · 3 lines
Cheers, David
David Hildenbrand (Arm)
maintainerRe: [PATCH 2/3] mm: add bytes_to_page_end() helper
In reply to Lorenzo StoakesQuoted 12 lines · Lorenzo Stoakes
Quoted 11 lines · David Laight
Quoted 7 lines · On Sun, 17 May 2026 11:28:05 -0400 Yury Norov <[email protected]> wrote:
I've got a series for this
https://lore.kernel.org/all/[email protected]/
The feedback is surprisingly negative. Please add people from that thread. Maybe you'll be more successful convincing them.
Quoted 7 lines
Quoted 2 lines
I don't think you need a another new header.
There is alreadyvdso/page.hwhich is wherePAGE_MASKcomes from.Yeah please don't, that's already a weird situation I don't really love the idea of extending that.
mm_types.hseems the more appropriate place.
I think I'd prefer vdso/page.h for something as basic as that.
But definitely no new header unless really unavoidable :)
Signature · 3 lines
Cheers, David
Lorenzo Stoakes
reviewerRe: [PATCH 2/3] mm: add bytes_to_page_end() helper
Quoted 16 lines · David Hildenbrand (Arm)
Quoted 15 lines · Lorenzo Stoakes
Quoted 13 lines · David Laight
Quoted 7 lines · On Sun, 17 May 2026 11:28:05 -0400 Yury Norov <[email protected]> wrote:
I've got a series for this
https://lore.kernel.org/all/[email protected]/
The feedback is surprisingly negative. Please add people from that thread. Maybe you'll be more successful convincing them.
I don't think you need a another new header.
There is alreadyvdso/page.hwhich is wherePAGE_MASKcomes from.
Quoted 8 lines
Quoted 4 lines
Yeah please don't, that's already a weird situation I don't really love the idea of extending that.
mm_types.hseems the more appropriate place.I think I'd prefer
vdso/page.hfor something as basic as that.But definitely no new header unless really unavoidable :)
I just find vdso/page.h an extremely weird beast. what does the VDSO have to do with it and why are we smuggling some basic definitions there...
I'm still waiting for an explanation as to why this series is necessary, I'm guessing build times (though I wonder what the actual delta is).
But yeah, I mean if you're fine with something else going there then fine, that or mm_types.h or some existing header, the new header is the nope thing here.
Quoted 5 lines
--
Cheers,David
Thanks, Lorenzo
David Hildenbrand (Arm)
maintainerRe: [PATCH 2/3] mm: add bytes_to_page_end() helper
Quoted 6 lines · Lorenzo Stoakes
Quoted 5 lines · David Hildenbrand (Arm)
Quoted 4 lines · Lorenzo Stoakes
Yeah please don't, that's already a weird situation I don't really love the idea of extending that.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
mm_types.hseems the more appropriate place.I think I'd prefer
vdso/page.hfor something as basic as that.But definitely no new header unless really unavoidable :)
I just find
vdso/page.han extremely weird beast. what does the VDSO have to do with it and why are we smuggling some basic definitions there...
Yeah, I don't know the history of all that, but I know that BIT(), ALIGN() etc are also in vdso/ ... and confused me in the past.
So as long as PAGE_MASK etc is in there, I guess adding simple helpers in there as well is the right thing to do. (I don't know if the defines could be reasonably moved at this point)
Signature · 3 lines
Cheers, David
Quoted 8 lines · Lorenzo Stoakes
Quoted 4 lines · Thorsten Blum
[...]
Patch 3/3 is one of many examples that pulls in all ofmm.hjust foroffset_in_page().lib/string.cfrom the same thread [1] is another example that would need to includemm.hjust foroffset_in_page().And that's a problem why? Compile time? Somehow binary bloat? Conflicts? Confusion?
This is more about separation of concerns than about compile time, which can still matter here, since mm.h is large, pulls in many other headers, and any changes to those can cause unrelated files to be recompiled.
I don't mind including mm.h where the code already depends on MM interfaces, but offset_in_page() itself is a small page-arithmetic helper. Having it buried 3000+ lines into mm.h also makes it less discoverable, which may be one reason it's not used more often.
Quoted 8 lines
Quoted 8 lines
Many other files (hundreds) don't use
offset_in_page(), but open-code it in many different ways instead:(unsigned long)p & ~PAGE_MASK (unsigned long)p & (PAGE_SIZE - 1) (long)p & (PAGE_SIZE - 1) ...
Quoted 6 lines
Quoted 2 lines
I can't tell whether they didn't know about
offset_in_page(), or deliberately chose not to includemm.h.OK but this series doesn't address any of that? It just adds a new header, a questionable macro and uses it in one place? So those justifications are rather moot here.
My intent was to make the helper available from a smaller header first, and to use patch 3/3 as a concrete example where including all of mm.h is unnecessary. Other call sites can then be converted incrementally over time, rather than sending a tree-wide conversion in the same series.
Thanks,
Thorsten
Lorenzo Stoakes
reviewerRe: [PATCH 2/3] mm: add bytes_to_page_end() helper
In reply to David Hildenbrand (Arm)Quoted 16 lines · David Hildenbrand (Arm)
Quoted 6 lines · Lorenzo Stoakes
Quoted 5 lines · David Hildenbrand (Arm)
Quoted 4 lines · Lorenzo Stoakes
Yeah please don't, that's already a weird situation I don't really love the idea of extending that.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
mm_types.hseems the more appropriate place.I think I'd prefer
vdso/page.hfor something as basic as that.But definitely no new header unless really unavoidable :)
I just find
vdso/page.han extremely weird beast. what does the VDSO have to do with it and why are we smuggling some basic definitions there...
Quoted 6 lines
Yeah, I don't know the history of all that, but I know that
BIT(),ALIGN()etc are also in vdso/ ... and confused me in the past.So as long as
PAGE_MASKetc is in there, I guess adding simple helpers in there as well is the right thing to do. (I don't know if the defines could be reasonably moved at this point)
OK then begrudgingly I guess that's fine :) (don't get me started on linux/sched/mm.h btw, in the same vein as this file :)
Thorsten - this might be the easiest solution here. Then the series becomes move the helper macro there (I don't love the new one so would rather you didn't add that) as 1 patch, and updating the bitmap code as a 2nd patch (with a cover letter obviously :)
Quoted 5 lines
--
Cheers,David
Thanks, Lorenzo
Lorenzo Stoakes
reviewerQuoted 10 lines · Thorsten Blum
Quoted 8 lines · Lorenzo Stoakes
Quoted 4 lines · Thorsten Blum
[...]
Patch 3/3 is one of many examples that pulls in all ofmm.hjust foroffset_in_page().lib/string.cfrom the same thread [1] is another example that would need to includemm.hjust foroffset_in_page().And that's a problem why? Compile time? Somehow binary bloat? Conflicts? Confusion?
Quoted 8 lines
This is more about separation of concerns than about compile time, which can still matter here, since
mm.his large, pulls in many other headers, and any changes to those can cause unrelated files to be recompiled.I don't mind including
mm.hwhere the code already depends on MM interfaces, butoffset_in_page()itself is a small page-arithmetic helper. Having it buried 3000+ lines intomm.halso makes it less discoverable, which may be one reason it's not used more often.
See the side thread with David, putting it in vdso/page.h is fine, and should achieve your aims.
Quoted 16 lines
Quoted 9 lines
Quoted 9 lines
Many other files (hundreds) don't use
offset_in_page(), but open-code it in many different ways instead:(unsigned long)p & ~PAGE_MASK (unsigned long)p & (PAGE_SIZE - 1) (long)p & (PAGE_SIZE - 1) ...Quoted 6 lines
Quoted 2 lines
I can't tell whether they didn't know about
offset_in_page(), or deliberately chose not to includemm.h.OK but this series doesn't address any of that? It just adds a new header, a questionable macro and uses it in one place? So those justifications are rather moot here.
Quoted 5 lines
My intent was to make the helper available from a smaller header first, and to use patch 3/3 as a concrete example where including all of
mm.his unnecessary. Other call sites can then be converted incrementally over time, rather than sending a tree-wide conversion in the same series.
Yeah I'm not sure it's at all clear anybody will pay attention to that (by not sure I mean - happy to bet a beer or 2 against :)
Anyway I'm not going to demand that you update all the callsites, if you split this into 2 patches as per above + send w/cover letter this is fine.
Quoted 3 lines
Thanks,
Thorsten
Thanks, Lorenzo
Re: [PATCH 2/3] mm: add bytes_to_page_end() helper
In reply to Lorenzo StoakesQuoted 20 lines · Lorenzo Stoakes
Quoted 19 lines · David Hildenbrand (Arm)
Quoted 18 lines · Lorenzo Stoakes
Quoted 6 lines · David Laight
Quoted 3 lines · On Sun, 17 May 2026 11:28:05 -0400 Yury Norov <[email protected]> wrote:
I've got a series for this
Quoted 7 lines
Quoted 4 lines
https://lore.kernel.org/all/[email protected]/
The feedback is surprisingly negative. Please add people from that thread. Maybe you'll be more successful convincing them.
I don't think you need a another new header.
There is alreadyvdso/page.hwhich is wherePAGE_MASKcomes from.Yeah please don't, that's already a weird situation I don't really love the idea of extending that.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
mm_types.hseems the more appropriate place.I think I'd prefer
vdso/page.hfor something as basic as that.But definitely no new header unless really unavoidable :)
I just find
vdso/page.han extremely weird beast. what does the VDSO have to do with it and why are we smuggling some basic definitions there...
The idea behind the vdso/ header namespace is that it can be used from vDSO userspace code. A weird middleground between linux/*.h and uapi/linux/*.h. Also in a compat vDSO anything depending on BITS_PER_LONG is wrong, and instead __BITS_PER_LONG needs to be used. A bunch of kconfig settings, like CONFIG_64BIT can also be off. Additionally internal kernel symbols are obviously not reachable from vDSO code.
Regular kernel code should not use the vdso/ namespace but instead use the regular linux/ headers, which in turn include the corresponding vdso/ one.
(...)
David Hildenbrand (Arm)
maintainerRe: [PATCH 2/3] mm: add bytes_to_page_end() helper
Quoted 17 lines · Thomas Weißschuh
Quoted 8 lines · Lorenzo Stoakes
Quoted 4 lines · David Hildenbrand (Arm)
I think I'd prefer
vdso/page.hfor something as basic as that.But definitely no new header unless really unavoidable :)
I just find
vdso/page.han extremely weird beast. what does the VDSO have to do with it and why are we smuggling some basic definitions there...The idea behind the vdso/ header namespace is that it can be used from vDSO userspace code. A weird middleground between linux/*.h and uapi/linux/*.h. Also in a compat vDSO anything depending on
BITS_PER_LONGis wrong, and instead__BITS_PER_LONGneeds to be used. A bunch of kconfig settings, likeCONFIG_64BITcan also be off. Additionally internal kernel symbols are obviously not reachable from vDSO code.
Quoted 2 lines
Regular kernel code should not use the vdso/ namespace but instead use the regular linux/ headers, which in turn include the corresponding vdso/ one.
offset_in_page() is that trivial that I don't see how it shouldn't just go next to PAGE_SIZE / PAGE_MASK, though?
In any case, a new header for this feels very wrong.
Signature · 3 lines
Cheers, David
Re: [PATCH 2/3] mm: add bytes_to_page_end() helper
Quoted 18 lines · David Hildenbrand (Arm)
Quoted 17 lines · Thomas Weißschuh
Quoted 8 lines · Lorenzo Stoakes
Quoted 4 lines · David Hildenbrand (Arm)
I think I'd prefer
vdso/page.hfor something as basic as that.But definitely no new header unless really unavoidable :)
I just find
vdso/page.han extremely weird beast. what does the VDSO have to do with it and why are we smuggling some basic definitions there...The idea behind the vdso/ header namespace is that it can be used from vDSO userspace code. A weird middleground between linux/*.h and uapi/linux/*.h. Also in a compat vDSO anything depending on
BITS_PER_LONGis wrong, and instead__BITS_PER_LONGneeds to be used. A bunch of kconfig settings, likeCONFIG_64BITcan also be off. Additionally internal kernel symbols are obviously not reachable from vDSO code.
Quoted 5 lines
Quoted 2 lines
Regular kernel code should not use the vdso/ namespace but instead use the regular linux/ headers, which in turn include the corresponding vdso/ one.
offset_in_page()is that trivial that I don't see how it shouldn't just go next toPAGE_SIZE/PAGE_MASK, though?
Yes, IMO it could go into vdso/page.h. The related offset_in_folio() which is defined right next to offset_in_page() however can not go there, as folios do not exist in the vDSO userspace context.
Personally I don't care about where this goes and just wanted to clarify the background of the vDSO headers.
Thomas
Re: [PATCH 3/3] lib/bitmap: use bytes_to_page_end() helper
In reply to Thorsten BlumQuoted 1 line · Thorsten Blum
bitmap-str.cincludeslinux/mm.hforoffset_in_page()andkfree().
And there's nothing wrong with that because it's a .c file, right?
Quoted 2 lines
Instead, include
linux/page_helpers.handlinux/slab.hdirectly, and usebytes_to_page_end()to simplify the code.
I'm OK about narrowing down inclusions in broadly-used headers. But here in a regular .c file it doesn't look like it fixes anything. Maybe some circular dependency you've not mentioned?
Quoted 20 lines
Signed-off-by Thorsten Blum <[email protected]>--- lib/bitmap-str.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)lib/bitmap-str.c +2
-1@@ -7,7 +7,8 @@#include <linux/export.h> #include <linux/hex.h> #include <linux/kernel.h> -#include <linux/mm.h> +#include <linux/page_helpers.h> +#include <linux/slab.h> #include <linux/string.h> #include "kstrtox.h"
lib/bitmap-str.c EXPORT_SYMBOL(bitmap_parse_user); · line 62
Quoted 5 lines
lib/bitmap-str.c +1
-1@@ -58,7 +59,7 @@ EXPORT_SYMBOL(bitmap_parse_user);int bitmap_print_to_pagebuf (bool list,char *buf,const unsigned long *maskp,int nmaskbits) { -ptrdiff_t len =PAGE_SIZE -offset_in_page (buf); +ptrdiff_t len =bytes_to_page_end (buf);
Don't worry about this function - it's on a schedule for deletion in this cycle. Now that you're fixing the only user that is going to disappear anyways, this new macro is going to become a dead code.
Can you please check the other ~90 users over the kernel. I already mentioned the series taking care of them.
https://lore.kernel.org/all/[email protected]/
Maybe just start from there?
Thanks,
Yury
Quoted 2 lines
lib/bitmap-str.c +0
-0return list ?scnprintf (buf, len,"%*pbl\n" , nmaskbits, maskp) :scnprintf (buf, len,"%*pb\n" , nmaskbits, maskp);
David Hildenbrand (Arm)
maintainerRe: [PATCH 2/3] mm: add bytes_to_page_end() helper
In reply to Thomas WeißschuhQuoted 13 lines · Thomas Weißschuh
Quoted 12 lines · David Hildenbrand (Arm)
Quoted 10 lines · Thomas Weißschuh
The idea behind the vdso/ header namespace is that it can be used from vDSO userspace code. A weird middleground between linux/*.h and uapi/linux/*.h. Also in a compat vDSO anything depending on
BITS_PER_LONGis wrong, and instead__BITS_PER_LONGneeds to be used. A bunch of kconfig settings, likeCONFIG_64BITcan also be off. Additionally internal kernel symbols are obviously not reachable from vDSO code.Regular kernel code should not use the vdso/ namespace but instead use the regular linux/ headers, which in turn include the corresponding vdso/ one.
Quoted 6 lines
Quoted 2 lines
offset_in_page()is that trivial that I don't see how it shouldn't just go next toPAGE_SIZE/PAGE_MASK, though?Yes, IMO it could go into
vdso/page.h. The relatedoffset_in_folio()which is defined right next tooffset_in_page()however can not go there, as folios do not exist in the vDSO userspace context.
yes, folio stuff should not go in there indeed.
Quoted 3 lines
Personally I don't care about where this goes and just wanted to clarify the background of the vDSO headers.
Yes, thanks!
Signature · 3 lines
Cheers, David