* [PATCH] mm/oom_kill: Remove unnecessary integer promotion in format string
@ 2025-12-28 15:44 Dipendra Khadka
2025-12-29 3:52 ` David Rientjes
2025-12-29 8:27 ` Michal Hocko
0 siblings, 2 replies; 5+ messages in thread
From: Dipendra Khadka @ 2025-12-28 15:44 UTC (permalink / raw)
To: Michal Hocko, Andrew Morton
Cc: David Rientjes, Shakeel Butt, linux-mm, linux-kernel, Dipendra Khadka
The 'h' length modifier in '%hd' is unnecessary as short integers are
promoted to int in variadic functions. Use '%d' instead.
Signed-off-by: Dipendra Khadka <kdipendra88@gmail.com>
---
mm/oom_kill.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/mm/oom_kill.c b/mm/oom_kill.c
index 5eb11fbba704..94066316e3ec 100644
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -458,7 +458,7 @@ static void dump_oom_victim(struct oom_control *oc, struct task_struct *victim)
static void dump_header(struct oom_control *oc)
{
- pr_warn("%s invoked oom-killer: gfp_mask=%#x(%pGg), order=%d, oom_score_adj=%hd\n",
+ pr_warn("%s invoked oom-killer: gfp_mask=%#x(%pGg), order=%d, oom_score_adj=%d\n",
current->comm, oc->gfp_mask, &oc->gfp_mask, oc->order,
current->signal->oom_score_adj);
if (!IS_ENABLED(CONFIG_COMPACTION) && oc->order)
@@ -958,7 +958,7 @@ static void __oom_kill_process(struct task_struct *victim, const char *message)
*/
do_send_sig_info(SIGKILL, SEND_SIG_PRIV, victim, PIDTYPE_TGID);
mark_oom_victim(victim);
- pr_err("%s: Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB, shmem-rss:%lukB, UID:%u pgtables:%lukB oom_score_adj:%hd\n",
+ pr_err("%s: Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB, shmem-rss:%lukB, UID:%u pgtables:%lukB oom_score_adj:%d\n",
message, task_pid_nr(victim), victim->comm, K(mm->total_vm),
K(get_mm_counter(mm, MM_ANONPAGES)),
K(get_mm_counter(mm, MM_FILEPAGES)),
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] mm/oom_kill: Remove unnecessary integer promotion in format string
2025-12-28 15:44 [PATCH] mm/oom_kill: Remove unnecessary integer promotion in format string Dipendra Khadka
@ 2025-12-29 3:52 ` David Rientjes
2025-12-29 8:27 ` Michal Hocko
1 sibling, 0 replies; 5+ messages in thread
From: David Rientjes @ 2025-12-29 3:52 UTC (permalink / raw)
To: Dipendra Khadka
Cc: Michal Hocko, Andrew Morton, Shakeel Butt, linux-mm, linux-kernel
On Sun, 28 Dec 2025, Dipendra Khadka wrote:
> The 'h' length modifier in '%hd' is unnecessary as short integers are
> promoted to int in variadic functions. Use '%d' instead.
>
> Signed-off-by: Dipendra Khadka <kdipendra88@gmail.com>
I don't have a strong opinion given this will result in the same output.
Acked-by: David Rientjes <rientjes@google.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] mm/oom_kill: Remove unnecessary integer promotion in format string
2025-12-28 15:44 [PATCH] mm/oom_kill: Remove unnecessary integer promotion in format string Dipendra Khadka
2025-12-29 3:52 ` David Rientjes
@ 2025-12-29 8:27 ` Michal Hocko
2025-12-30 20:33 ` Andrew Morton
1 sibling, 1 reply; 5+ messages in thread
From: Michal Hocko @ 2025-12-29 8:27 UTC (permalink / raw)
To: Dipendra Khadka
Cc: Andrew Morton, David Rientjes, Shakeel Butt, linux-mm, linux-kernel
On Sun 28-12-25 15:44:55, Dipendra Khadka wrote:
> The 'h' length modifier in '%hd' is unnecessary as short integers are
> promoted to int in variadic functions. Use '%d' instead.
>
> Signed-off-by: Dipendra Khadka <kdipendra88@gmail.com>
Why should we change the currently correct code in the first place?
What is an added value?
--
Michal Hocko
SUSE Labs
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] mm/oom_kill: Remove unnecessary integer promotion in format string
2025-12-29 8:27 ` Michal Hocko
@ 2025-12-30 20:33 ` Andrew Morton
2025-12-31 12:21 ` Dipendra Khadka
0 siblings, 1 reply; 5+ messages in thread
From: Andrew Morton @ 2025-12-30 20:33 UTC (permalink / raw)
To: Michal Hocko
Cc: Dipendra Khadka, David Rientjes, Shakeel Butt, linux-mm, linux-kernel
On Mon, 29 Dec 2025 09:27:18 +0100 Michal Hocko <mhocko@suse.com> wrote:
> On Sun 28-12-25 15:44:55, Dipendra Khadka wrote:
> > The 'h' length modifier in '%hd' is unnecessary as short integers are
> > promoted to int in variadic functions. Use '%d' instead.
> >
> > Signed-off-by: Dipendra Khadka <kdipendra88@gmail.com>
>
> Why should we change the currently correct code in the first place?
> What is an added value?
It reduces vmlinux by 2 bytes ;)
It's a teeny issue but I do like the present code - be very explicit
and careful about the types we're dealing with, don't rely on unobvious
C rules.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] mm/oom_kill: Remove unnecessary integer promotion in format string
2025-12-30 20:33 ` Andrew Morton
@ 2025-12-31 12:21 ` Dipendra Khadka
0 siblings, 0 replies; 5+ messages in thread
From: Dipendra Khadka @ 2025-12-31 12:21 UTC (permalink / raw)
To: akpm; +Cc: kdipendra88, linux-kernel, linux-mm, mhocko, rientjes, shakeel.butt
>It's a teeny issue but I do like the present code - be very explicit
>and careful about the types we're dealing with, don't rely on unobvious
>C rules.
Actually, the scenario here is that while printing a short, it is
**promoted** to int due to C's variadic argument promotion rules.
Yes, we must use %hd when the **semantic type** is short. However,
due to integer promotion, the value is already passed as a 4-byte int
on the stack. The %hd format specifier then casts it back to short
for display.
Since the value is already promoted to int internally, using %d is
simpler and avoids the unnecessary cast. The checkpatch warning
confirms this:
```
WARNING: Integer promotion: Using 'h' in '%hd' is unnecessary
#461: FILE: mm/oom_kill.c:461:
+ pr_warn("%s invoked oom-killer: gfp_mask=%#x(%pGg), order=%d, oom_score_adj=%hd\n",
+ current->comm, oc->gfp_mask, &oc->gfp_mask, oc->order,
+ current->signal->oom_score_adj);
WARNING: Integer promotion: Using 'h' in '%hd' is unnecessary
#961: FILE: mm/oom_kill.c:961:
+ pr_err("%s: Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB, shmem-rss:%lukB, UID:%u pgtables:%lukB oom_score_adj:%hd\n",
+ message, task_pid_nr(victim), victim->comm, K(mm->total_vm),
+ K(get_mm_counter(mm, MM_ANONPAGES)),
+ K(get_mm_counter(mm, MM_FILEPAGES)),
+ K(get_mm_counter(mm, MM_SHMEMPAGES)),
+ from_kuid(&init_user_ns, task_uid(victim)),
+ mm_pgtables_bytes(mm) >> 10, victim->signal->oom_score_adj);
```
Checkpatch flags the 'h' modifier as unnecessary for this reason,
and many other subsystems have moved to using %d for promoted types.
Hence, I think this patch aligns with kernel coding practices.
Best Rgards,
Dipendra Khadka
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-12-31 12:21 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-28 15:44 [PATCH] mm/oom_kill: Remove unnecessary integer promotion in format string Dipendra Khadka
2025-12-29 3:52 ` David Rientjes
2025-12-29 8:27 ` Michal Hocko
2025-12-30 20:33 ` Andrew Morton
2025-12-31 12:21 ` Dipendra Khadka
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox