[PATCH 05/12] mm/oom_kill: add `const` to pointer parameter

Max Kellermann posted 12 patches 1 month ago
There is a newer version of this series
[PATCH 05/12] mm/oom_kill: add `const` to pointer parameter
Posted by Max Kellermann 1 month ago
For improved const-correctness.

Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
---
 include/linux/mm.h | 2 +-
 mm/oom_kill.c      | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index a40a3c42c904..a795deef93eb 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -3840,7 +3840,7 @@ static inline int in_gate_area(struct mm_struct *mm, unsigned long addr)
 }
 #endif	/* __HAVE_ARCH_GATE_AREA */
 
-extern bool process_shares_mm(struct task_struct *p, struct mm_struct *mm);
+extern bool process_shares_mm(struct task_struct *p, const struct mm_struct *mm);
 
 void drop_slab(void);
 
diff --git a/mm/oom_kill.c b/mm/oom_kill.c
index 17650f0b516e..69c4fc9d90e6 100644
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -490,7 +490,7 @@ static bool oom_killer_disabled __read_mostly;
  * task's threads: if one of those is using this mm then this task was also
  * using it.
  */
-bool process_shares_mm(struct task_struct *p, struct mm_struct *mm)
+bool process_shares_mm(struct task_struct *p, const struct mm_struct *mm)
 {
 	struct task_struct *t;
 
-- 
2.47.2
Re: [PATCH 05/12] mm/oom_kill: add `const` to pointer parameter
Posted by Vishal Moola (Oracle) 1 month ago
On Fri, Aug 29, 2025 at 08:31:52PM +0200, Max Kellermann wrote:
> For improved const-correctness.
> 
> Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
> ---
>  include/linux/mm.h | 2 +-
>  mm/oom_kill.c      | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index a40a3c42c904..a795deef93eb 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -3840,7 +3840,7 @@ static inline int in_gate_area(struct mm_struct *mm, unsigned long addr)
>  }
>  #endif	/* __HAVE_ARCH_GATE_AREA */
>  
> -extern bool process_shares_mm(struct task_struct *p, struct mm_struct *mm);
> +extern bool process_shares_mm(struct task_struct *p, const struct mm_struct *mm);

Nowadays we're dropping the extern keyword.

Also, Is there any reason you didn't also make the task_struct pointer const?
Re: [PATCH 05/12] mm/oom_kill: add `const` to pointer parameter
Posted by Max Kellermann 1 month ago
On Sat, Aug 30, 2025 at 1:03 AM Vishal Moola (Oracle)
<vishal.moola@gmail.com> wrote:
> > -extern bool process_shares_mm(struct task_struct *p, struct mm_struct *mm);
> > +extern bool process_shares_mm(struct task_struct *p, const struct mm_struct *mm);
>
> Nowadays we're dropping the extern keyword.

I can do that - is it acceptable to do that in the same patch?

> Also, Is there any reason you didn't also make the task_struct pointer const?

I wasn't sure whether for_each_thread() is const-safe. I think I
looked at the wrong definition; for_each_thread() looks safe, only
for_other_threads() is not because it uses next_thread() which takes a
non-const pointer. I'll amend the patch.
Re: [PATCH 05/12] mm/oom_kill: add `const` to pointer parameter
Posted by Andrew Morton 1 month ago
On Sat, 30 Aug 2025 08:26:07 +0200 Max Kellermann <max.kellermann@ionos.com> wrote:

> On Sat, Aug 30, 2025 at 1:03 AM Vishal Moola (Oracle)
> <vishal.moola@gmail.com> wrote:
> > > -extern bool process_shares_mm(struct task_struct *p, struct mm_struct *mm);
> > > +extern bool process_shares_mm(struct task_struct *p, const struct mm_struct *mm);
> >
> > Nowadays we're dropping the extern keyword.
> 
> I can do that - is it acceptable to do that in the same patch?

The culture is "ooh ooh ooh, you can't do two things in the same
patch".  My culture is well, gee, it's simple and obvious and makes the
kernel better, so I think we can handle it.