From: "Vlastimil Babka (SUSE)" <vbabka@kernel.org>
To: kernel test robot <lkp@intel.com>, Hao Li <hao.li@linux.dev>
Cc: oe-kbuild-all@lists.linux.dev, Harry Yoo <harry@kernel.org>
Subject: Re: [mm-slab:slab/for-next 1/2] mm/slab_common.c:1012 new_kmalloc_cache() warn: always true condition '(type >= 0) => (0-u32max >= 0)'
Date: Wed, 2 Dec 2026 12:00:34 +0100 [thread overview]
Message-ID: <ad7f1eaa-becd-4e30-92ff-fae19e86d6bb@kernel.org> (raw)
In-Reply-To: <20261120153115.isoaU88H-lkp@intel.com>
On 11/20/26 15:32, kernel test robot wrote:
> tree: https://git.kernel.org/pub/scm/linux/kernel/git/mm/slab.git slab/for-next
> head: c6e6bf9b097d69a06974b2f8b5400b33e1faeb31
> commit: ec81fa8f7dbcf89d9b4112544f76f47c8eb5c725 [1/2] mm/slab: don't set SLAB_MAY_ACCOUNT for KMALLOC_PARTITION_CACHES
> config: um-randconfig-2200-20261120 (https://download.01.org/0day-ci/archive/20261120/20261120153115.isoaU88H-lkp@intel.com/config)
> compiler: clang version 24.0.0git (https://github.com/llvm/llvm-project 8db60b003f961f25c5cafe91ee44176f61374279)
> smatch: v0.5.0-9187-g5189e3fb
>
> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> the same patch/commit), kindly add following tags
> | Reported-by: kernel test robot <lkp@intel.com>
> | Closes: https://lore.kernel.org/oe-kbuild-all/20261120153115.isoaU88H-lkp@intel.com/
>
> smatch warnings:
> mm/slab_common.c:1012 new_kmalloc_cache() warn: always true condition '(type >= 0) => (0-u32max >= 0)'
While the condition can become tautology in certain configs, I'm not sure if
it's worth complicating the code just to silence smatch, hm. AFAIU the
recommendation is "don't".
If we had more tests like this that could make adding a
"is_kmalloc_partition_type" helper useful on its own, then perhaps.
> vim +1012 mm/slab_common.c
>
> 1001
> 1002 /*
> 1003 * If memcg_kmem is enabled and this is a KMALLOC_NORMAL or
> 1004 * KMALLOC_PARTITION_CACHES cache and not aliased with any other type,
> 1005 * make sure it's never merged with any other cache.
> 1006 *
> 1007 * In other cases the kmalloc cache may end up being used for a
> 1008 * __GFP_ACCOUNT allocation so mark it as such. The exception is a
> 1009 * KMALLOC_NO_OBJ_EXT cache.
> 1010 */
> 1011 if (!mem_cgroup_kmem_disabled()) {
>> 1012 if (type >= KMALLOC_PARTITION_START &&
> 1013 type <= KMALLOC_PARTITION_END &&
> 1014 KMALLOC_RECLAIM != KMALLOC_NORMAL)
> 1015 flags |= SLAB_NO_MERGE;
> 1016 else if (!(flags & SLAB_NO_OBJ_EXT))
> 1017 flags |= SLAB_MAY_ACCOUNT;
> 1018 }
> 1019
> 1020 if (minalign > ARCH_KMALLOC_MINALIGN) {
> 1021 aligned_size = ALIGN(aligned_size, minalign);
> 1022 aligned_idx = __kmalloc_index(aligned_size, false);
> 1023 }
> 1024
> 1025 if (!kmalloc_caches[type][aligned_idx])
> 1026 kmalloc_caches[type][aligned_idx] = create_kmalloc_cache(
> 1027 kmalloc_info[aligned_idx].name[type],
> 1028 aligned_size, flags);
> 1029 if (idx != aligned_idx)
> 1030 kmalloc_caches[type][idx] = kmalloc_caches[type][aligned_idx];
> 1031 }
> 1032
>
prev parent reply other threads:[~2026-12-02 11:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 14:32 [mm-slab:slab/for-next 1/2] mm/slab_common.c:1012 new_kmalloc_cache() warn: always true condition '(type >= 0) => (0-u32max >= 0)' kernel test robot
2026-12-02 11:00 ` Vlastimil Babka (SUSE) [this message]
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=ad7f1eaa-becd-4e30-92ff-fae19e86d6bb@kernel.org \
--to=vbabka@kernel.org \
--cc=hao.li@linux.dev \
--cc=harry@kernel.org \
--cc=lkp@intel.com \
--cc=oe-kbuild-all@lists.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.