From: "David Hildenbrand (Red Hat)" <david@kernel.org>
To: Andrew Morton <akpm@linux-foundation.org>,
Barry Song <21cnbao@gmail.com>
Cc: Wale Zhang <wale.zhang.ftd@gmail.com>,
chrisl@kernel.org, ziy@nvidia.com, lorenzo.stoakes@oracle.com,
matthew.brost@intel.com, linux-mm@kvack.org
Subject: Re: [PATCH v2] mm/swapops,rmap: remove should-never-be-compiled codes.
Date: Tue, 30 Dec 2025 22:59:39 +0100 [thread overview]
Message-ID: <4029d13c-3bfc-4ace-8da0-3895dfc001b1@kernel.org> (raw)
In-Reply-To: <20251230133522.e15135c3a17826428f472a2e@linux-foundation.org>
On 12/30/25 22:35, Andrew Morton wrote:
> On Wed, 31 Dec 2025 10:28:25 +1300 Barry Song <21cnbao@gmail.com> wrote:
>
>> On Wed, Dec 31, 2025 at 8:50 AM David Hildenbrand (Red Hat)
>> <david@kernel.org> wrote:
>>>
>>>
>>>> - break;
>>>> +#ifdef CONFIG_NO_PAGE_MAPCOUNT
>>>> + last = atomic_add_negative(-1, &folio->_entire_mapcount);
>>>> + if (level == PGTABLE_LEVEL_PMD && last)
>>>> + nr_pmdmapped = folio_large_nr_pages(folio);
>>>> + nr = folio_dec_return_large_mapcount(folio, vma);
>>>> + if (!nr) {
>>>> + /* Now completely unmapped. */
>>>> + nr = folio_large_nr_pages(folio);
>>>> + } else {
>>>> + partially_mapped = last &&
>>>> + nr < folio_large_nr_pages(folio);
>>>> + nr = 0;
>>>
>>> The whole code was written to avoid ifdefs.
>>
>> The #ifdefs are only for -O0 builds, which are never a
>> mainline requirement. However, dropping functions that
>> contain nothing but a BUILD_BUG() seems reasonable?
>
> Let's not make -O0 an objective, please. We often make assumptions
> about dead code elimination in order to keep kernel code more pleasing
> to read and to maintain.
>
>> If those functions were actually required, the compiler
>> would fail anyway. In that case, there doesn’t seem to be
>> much value in keeping wrapper functions whose sole purpose
>> is to contain a single BUILD_BUG().
>
> I agree with that part of the patch - if the thing only does a
> BUILD_BUG() then let's simply remove it. If somehow the compiler tries
> to reference the now-not-present function then we'll get an error message
> anyway.
>
The change
+#ifdef CONFIG_NO_PAGE_MAPCOUNT
+#define folio_inc_return_large_mapcount(folio, vma) \
+ folio_add_return_large_mapcount(folio, 1, vma)
#define folio_dec_return_large_mapcount(folio, vma) \
folio_sub_return_large_mapcount(folio, 1, vma)
+#endif
In the patch is wrong. It must be CONFIG_MM_ID.
So if the following makes compilers happy, fine with me:
diff --git a/include/linux/rmap.h b/include/linux/rmap.h
index daa92a58585d9..9d782826e8579 100644
--- a/include/linux/rmap.h
+++ b/include/linux/rmap.h
@@ -336,6 +336,11 @@ static __always_inline int folio_sub_return_large_mapcount(struct folio *folio,
return new_mapcount_val + 1;
}
#define folio_sub_large_mapcount folio_sub_return_large_mapcount
+
+#define folio_inc_return_large_mapcount(folio, vma) \
+ folio_add_return_large_mapcount(folio, 1, vma)
+#define folio_dec_return_large_mapcount(folio, vma) \
+ folio_sub_return_large_mapcount(folio, 1, vma)
#else /* !CONFIG_MM_ID */
/*
* See __folio_rmap_sanity_checks(), we might map large folios even without
@@ -354,33 +359,17 @@ static inline void folio_add_large_mapcount(struct folio *folio,
atomic_add(diff, &folio->_large_mapcount);
}
-static inline int folio_add_return_large_mapcount(struct folio *folio,
- int diff, struct vm_area_struct *vma)
-{
- BUILD_BUG();
-}
-
static inline void folio_sub_large_mapcount(struct folio *folio,
int diff, struct vm_area_struct *vma)
{
atomic_sub(diff, &folio->_large_mapcount);
}
-
-static inline int folio_sub_return_large_mapcount(struct folio *folio,
- int diff, struct vm_area_struct *vma)
-{
- BUILD_BUG();
-}
#endif /* CONFIG_MM_ID */
#define folio_inc_large_mapcount(folio, vma) \
folio_add_large_mapcount(folio, 1, vma)
-#define folio_inc_return_large_mapcount(folio, vma) \
- folio_add_return_large_mapcount(folio, 1, vma)
#define folio_dec_large_mapcount(folio, vma) \
folio_sub_large_mapcount(folio, 1, vma)
-#define folio_dec_return_large_mapcount(folio, vma) \
- folio_sub_return_large_mapcount(folio, 1, vma)
/* RMAP flags, currently only relevant for some anon rmap operations. */
typedef int __bitwise rmap_t;
Use a config with !CONFIG_TRANSPARENT_HUGEPAGE:
$ LANG=C make mm/rmap.o
CALL scripts/checksyscalls.sh
DESCEND objtool
INSTALL libsubcmd_headers
DESCEND bpf/resolve_btfids
INSTALL libsubcmd_headers
CC mm/rmap.o
mm/rmap.c: In function '__folio_add_rmap':
mm/rmap.c:1249:30: error: implicit declaration of function 'folio_add_return_large_mapcount'; did you mean 'folio_add_large_mapcount'? [-Wimplicit-function-declaration]
1249 | nr = folio_add_return_large_mapcount(folio, orig_nr_pages, vma);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| folio_add_large_mapcount
mm/rmap.c:1274:30: error: implicit declaration of function 'folio_inc_return_large_mapcount'; did you mean 'folio_inc_large_mapcount'? [-Wimplicit-function-declaration]
1274 | nr = folio_inc_return_large_mapcount(folio, vma);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| folio_inc_large_mapcount
mm/rmap.c: In function '__folio_remove_rmap':
mm/rmap.c:1673:30: error: implicit declaration of function 'folio_sub_return_large_mapcount'; did you mean 'folio_sub_large_mapcount'? [-Wimplicit-function-declaration]
1673 | nr = folio_sub_return_large_mapcount(folio, nr_pages, vma);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| folio_sub_large_mapcount
mm/rmap.c:1702:30: error: implicit declaration of function 'folio_dec_return_large_mapcount'; did you mean 'folio_dec_large_mapcount'? [-Wimplicit-function-declaration]
1702 | nr = folio_dec_return_large_mapcount(folio, vma);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| folio_dec_large_mapcount
make[3]: *** [scripts/Makefile.build:287: mm/rmap.o] Error 1
make[2]: *** [scripts/Makefile.build:556: mm] Error 2
make[1]: *** [/home/dhildenb/git/linux/Makefile:2054: .] Error 2
make: *** [Makefile:248: __sub-make] Error 2
--
Cheers
David
next prev parent reply other threads:[~2025-12-30 21:59 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-30 13:01 Wale Zhang
2025-12-30 18:10 ` Andrew Morton
2025-12-30 19:50 ` David Hildenbrand (Red Hat)
2025-12-30 21:28 ` Barry Song
2025-12-30 21:35 ` Andrew Morton
2025-12-30 21:59 ` David Hildenbrand (Red Hat) [this message]
2025-12-31 11:58 ` wale zhang
2025-12-31 12:17 ` David Hildenbrand (Red Hat)
2025-12-31 9:30 ` wale zhang
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=4029d13c-3bfc-4ace-8da0-3895dfc001b1@kernel.org \
--to=david@kernel.org \
--cc=21cnbao@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=chrisl@kernel.org \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=matthew.brost@intel.com \
--cc=wale.zhang.ftd@gmail.com \
--cc=ziy@nvidia.com \
/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