From: Dipendra Khadka <kdipendra88@gmail.com>
To: akpm@linux-foundation.org
Cc: kdipendra88@gmail.com, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, mhocko@suse.com, rientjes@google.com,
shakeel.butt@linux.dev
Subject: Re: [PATCH] mm/oom_kill: Remove unnecessary integer promotion in format string
Date: Wed, 31 Dec 2025 12:21:17 +0000 [thread overview]
Message-ID: <20251231122117.7683-1-kdipendra88@gmail.com> (raw)
In-Reply-To: <20251230123336.ef33f8a55df71f3e3f782532@linux-foundation.org>
>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
next prev parent reply other threads:[~2025-12-31 12:21 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-28 15:44 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 message]
2026-01-01 1:45 ` Andrew Morton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251231122117.7683-1-kdipendra88@gmail.com \
--to=kdipendra88@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
--cc=rientjes@google.com \
--cc=shakeel.butt@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox