mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/8] mm: remove unused functions
@ 2026-10-26 10:30 Shivank Garg
  2026-10-26 10:30 ` [PATCH 1/8] mm/vmstat: remove unused folio stat helpers Shivank Garg
                   ` (8 more replies)
  0 siblings, 9 replies; 11+ messages in thread
From: Shivank Garg @ 2026-10-26 10:30 UTC (permalink / raw)
  To: Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
	Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
	Suren Baghdasaryan, Michal Hocko, Kairui Song, Qi Zheng,
	Shakeel Butt, Barry Song, Axel Rasmussen, Yuanchu Xie, Wei Xu,
	Baoquan He, Baolin Wang, Matthew Wilcox (Oracle),
	Jan Kara, Hugh Dickins, Rik van Riel, Harry Yoo, Jann Horn,
	Lance Yang, Chris Li, Kemeng Shi, Nhat Pham, Youngjun Park,
	Jonathan Corbet, Shuah Khan, Johannes Weiner, Michal Hocko,
	Roman Gushchin, Muchun Song, Uladzislau Rezki, SJ Park,
	Minchan Kim, Sergey Senozhatsky, Alexander Potapenko,
	Marco Elver, Dmitry Vyukov, Pedro Falcato, Bharata B Rao
  Cc: linux-mm, linux-kernel, linux-fsdevel, cgroups, bpf, damon,
	kasan-dev, Shivank Garg

This series removes 16 functions and one variable in mm that have no
users left anywhere in the tree. The functions are all static inline
helpers in headers, which no compiler warns about: GCC never reports
unused static inline functions, and Clang only reports them in .c
files, and only with W=2. The variable is heap_stack_gap in
mm/nommu.c, unused since the start of git history. Each patch covers
one file or subsystem, so they can be picked or dropped independently.

How they were found:

I wrote some Python scripts, with the help of an LLM, that scan the
whole tree for every config and architecture at once. They look for
static inline functions without callers, and for non-static functions
named nowhere but in their own definition, declarations, stubs and
EXPORT_SYMBOL(). Where a ## macro could paste together one of the
names, they read every call of that macro to see whether one does.
The candidates were then cross-checked with a real build: a scratch
tree marks each one __deprecated, an x86_64 allmodconfig build is run,
and any candidate that triggers even one deprecation warning is
dropped. The final report labels a symbol "Sure" only when that build
confirms it unused, and "Unsure" when the build doesn't compile it or
the scripts can't rule out a use. 

Before posting, I searched lore with semcode MCP for removals that
others had already posted, to avoid duplicates. Each patch was also
build-tested on its own.

The scripts and a generated HTML report are here [1], if anyone wants
to play with them:

[1] https://github.com/AMDESE/linux-mm/tree/shivank/kunused

Left out on purpose:
- mmap_action_map_kernel_pages() and mmap_action_map_kernel_pages_full()
  are unused but documented in Documentation/filesystems/mmap_prepare.rst.
- zone_span_writelock() and zone_span_writeunlock() are unused, which
  means span_seqlock is never written while page_alloc.c still reads
  it. That deserves its own patch.
- cpupid_cpu_unset() and kmsan_poison_memory() are unused, but each is
  one half of a pair whose other half has users: cpupid_pid_unset() and
  kmsan_unpoison_memory(). I left them out to avoid breaking the
  pairing, but I'm happy to include them if that's okay.

Already posted by others, or about to get a caller, so not in this
series:
- __mm_flags_set_mask_bits_word(), by Kevin Brodsky:
  https://lore.kernel.org/r/20260714-remove_pgtable_cdtor-v1-1-44be8a7685d7@arm.com
- pfn_in_present_section(), by David Hildenbrand. His series also
  reworks the code around valid_section_nr(), so that one can wait until
  it has landed:
  https://lore.kernel.org/r/20260921-b4-sparsemem_cleanups-v2-7-54d81d65e125@kernel.org
- page_memcg_check() and mod_memcg_page_state(), by Sang-Heon Jeon and
  by Tal Zussman:
  https://lore.kernel.org/r/20260918165601.1014666-2-ekffu200098@gmail.com
  https://lore.kernel.org/r/20261014-memcg-unused-page-helpers-v1-0-240b37c53831@columbia.edu
- vmf_insert_mixed_mkwrite(), by Sang-Heon Jeon:
  https://lore.kernel.org/r/20261002160535.661399-1-ekffu200098@gmail.com
- folio_dup_file_rmap_pmd() has no caller today, but Konstantin
  Khorenko's fork rework fixes it and adds one:
  https://lore.kernel.org/r/20261021-b4-prep-vstor-149847-copy_huge_pmd-recheck-special-pmd-v4-0-66f00b7a564c@virtuozzo.com
- read_cache_page_gfp(), by Qu Wenruo, as the last patch of a btrfs
  series in January. It hasn't been applied yet, so I've left it to
  that series:
  https://lore.kernel.org/r/a5ffadf18dca846d6f8086b29366288e794a24b6.1768017091.git.wqu@suse.com
- folio_is_pfmemalloc() has no caller today, but Ameer Hamza's SUNRPC
  page recycling patch adds one:
  https://lore.kernel.org/r/20260817210811.3984663-3-ameer.hamza@truenas.com

I'm starting with mm. Across the whole tree the scripts currently find
about ~4000 symbols, and of which 3000 pass build checks, so there's plenty of
fun left for other subsystems :)

Signed-off-by: Shivank Garg <shivankg@amd.com>
---
Shivank Garg (8):
      mm/vmstat: remove unused folio stat helpers
      mm: remove unused folio refcount helpers
      mm/page_ext: remove unused page_ext_iter_get()
      mm: remove unused helpers from pagemap.h
      mm/swapops: remove unused make_guard_swp_entry()
      mm/swap: remove unused folio_to_swp_tb()
      mm/zsmalloc: remove unused zpdesc_lock()
      mm: nommu: remove unused heap_stack_gap

 include/linux/page_ext.h | 11 -----------
 include/linux/page_ref.h | 24 ------------------------
 include/linux/pagemap.h  | 11 -----------
 include/linux/swapops.h  |  5 -----
 include/linux/vmstat.h   | 36 ------------------------------------
 mm/nommu.c               |  1 -
 mm/swap_table.h          |  5 -----
 mm/zpdesc.h              |  5 -----
 8 files changed, 98 deletions(-)
---
base-commit: 6b4b543fa18757297ac756a6fe6e64f506b7844a
change-id: 20261024-unused-sym-f577a5b874fc

Best regards,
-- 
Shivank Garg <shivankg@amd.com>


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2026-10-26 11:14 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-26 10:30 [PATCH 0/8] mm: remove unused functions Shivank Garg
2026-10-26 10:30 ` [PATCH 1/8] mm/vmstat: remove unused folio stat helpers Shivank Garg
2026-10-26 10:30 ` [PATCH 2/8] mm: remove unused folio refcount helpers Shivank Garg
2026-10-26 10:30 ` [PATCH 3/8] mm/page_ext: remove unused page_ext_iter_get() Shivank Garg
2026-10-26 10:30 ` [PATCH 4/8] mm: remove unused helpers from pagemap.h Shivank Garg
2026-10-26 10:30 ` [PATCH 5/8] mm/swapops: remove unused make_guard_swp_entry() Shivank Garg
2026-10-26 10:30 ` [PATCH 6/8] mm/swap: remove unused folio_to_swp_tb() Shivank Garg
2026-10-26 10:30 ` [PATCH 7/8] mm/zsmalloc: remove unused zpdesc_lock() Shivank Garg
2026-10-26 10:30 ` [PATCH 8/8] mm: nommu: remove unused heap_stack_gap Shivank Garg
2026-10-26 10:32 ` [PATCH 0/8] mm: remove unused functions David Hildenbrand (Arm)
2026-10-26 11:14   ` Garg, Shivank

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®