incoming
Subsystems (75)
Andrew Morton
maintainerA few misc subsystems and some of MM.
178 patches, based on 8ca5297e7e38f2dc8c753d33a5092e7be181fff0.
Subsystems affected by this patch series:
ia64
kbuild
scripts
sh
ocfs2
kfifo
vfs
kernel/watchdog
mm/slab-generic
mm/slub
mm/kmemleak
mm/debug
mm/pagecache
mm/msync
mm/gup
mm/memremap
mm/memcg
mm/pagemap
mm/mremap
mm/dma
mm/sparsemem
mm/vmalloc
mm/documentation
mm/kasan
mm/initialization
mm/pagealloc
mm/memory-failure
Subsystem: ia64
Zhang Yunkai <[email protected]>:
arch/ia64/kernel/head.S: remove duplicate include
Bhaskar Chowdhury <[email protected]>:
arch/ia64/kernel/fsys.S: fix typos arch/ia64/include/asm/pgtable.h: minor typo fixes
Valentin Schneider <[email protected]>:
ia64: ensure proper NUMA distance and possible map initialization
Sergei Trofimovich <[email protected]>:
ia64: drop unused IA64_FW_EMU ifdef
ia64: simplify code flow around swiotlb init
Bhaskar Chowdhury <[email protected]>:
ia64: trivial spelling fixes
Sergei Trofimovich <[email protected]>:
ia64: fix EFI_DEBUG build
ia64: mca: always make IA64_MCA_DEBUG an expression
ia64: drop marked broken DISCONTIGMEM and VIRTUAL_MEM_MAP
ia64: module: fix symbolizer crash on fdescr
Subsystem: kbuild
Luc Van Oostenryck <[email protected]>:
include/linux/compiler-gcc.h: sparse can do constant folding of __builtin_bswap*()
Subsystem: scripts
Tom Saeger <[email protected]>:
scripts/spelling.txt: add entries for recent discoveries
Wan Jiabing <[email protected]>:
scripts: a new script for checking duplicate struct declaration
Subsystem: sh
Zhang Yunkai <[email protected]>:
arch/sh/include/asm/tlb.h: remove duplicate include
Subsystem: ocfs2
Yang Li <[email protected]>:
ocfs2: replace DEFINE_SIMPLE_ATTRIBUTE with DEFINE_DEBUGFS_ATTRIBUTE
Joseph Qi <[email protected]>:
ocfs2: map flags directly in flags_to_o2dlm()
Bhaskar Chowdhury <[email protected]>:
ocfs2: fix a typo
Jiapeng Chong <[email protected]>:
ocfs2/dlm: remove unused function
Subsystem: kfifo
Dan Carpenter <[email protected]>:
kfifo: fix ternary sign extension bugs
Subsystem: vfs
Randy Dunlap <[email protected]>:
vfs: fs_parser: clean up kernel-doc warnings
Subsystem: kernel/watchdog
Petr Mladek <[email protected]>:
Patch series "watchdog/softlockup: Report overall time and some cleanup", v2:
watchdog: rename __touch_watchdog() to a better descriptive name
watchdog: explicitly update timestamp when reporting softlockup watchdog/softlockup: report the overall time of softlockups watchdog/softlockup: remove logic that tried to prevent repeated reports
watchdog: fix barriers when printing backtraces from all CPUs
watchdog: cleanup handling of false positives
Subsystem: mm/slab-generic
Rafael Aquini <[email protected]>:
mm/slab_common: provide "slab_merge" option for !IS_ENABLED(CONFIG_SLAB_MERGE_DEFAULT) builds
Subsystem: mm/slub
Vlastimil Babka <[email protected]>:
mm, slub: enable slub_debug static key when creating cache with explicit debug flags
Oliver Glitta <[email protected]>:
kunit: add a KUnit test for SLUB debugging functionality
slub: remove resiliency_test() function
Bhaskar Chowdhury <[email protected]>:
mm/slub.c: trivial typo fixes
Subsystem: mm/kmemleak
Bhaskar Chowdhury <[email protected]>:
mm/kmemleak.c: fix a typo
Subsystem: mm/debug
Georgi Djakov <[email protected]>:
mm/page_owner: record the timestamp of all pages during free
zhongjiang-ali <[email protected]>:
mm, page_owner: remove unused parameter in __set_page_owner_handle
Sergei Trofimovich <[email protected]>:
mm: page_owner: fetch backtrace only for tracked pages
mm: page_owner: use kstrtobool() to parse bool option
mm: page_owner: detect page_owner recursion via task_struct
mm: page_poison: print page info when corruption is caught
Anshuman Khandual <[email protected]>:
mm/memtest: add ARCH_USE_MEMTEST
Subsystem: mm/pagecache
Jens Axboe <[email protected]>:
Patch series "Improve IOCB_NOWAIT O_DIRECT reads", v3:
mm: provide filemap_range_needs_writeback() helper
mm: use filemap_range_needs_writeback() for O_DIRECT reads
iomap: use filemap_range_needs_writeback() for O_DIRECT reads
"Matthew Wilcox (Oracle)" <[email protected]>:
mm/filemap: use filemap_read_page in filemap_fault mm/filemap: drop check for truncated page after I/O
Johannes Weiner <[email protected]>:
mm: page-writeback: simplify memcg handling in test_clear_page_writeback()
"Matthew Wilcox (Oracle)" <[email protected]>:
mm: move page_mapping_file to pagemap.h
Rui Sun <[email protected]>:
mm/filemap: update stale comment
Subsystem: mm/msync
Nikita Ermakov <[email protected]>:
mm/msync: exit early when the flags is an MS_ASYNC and start < vm_start
Subsystem: mm/gup
Joao Martins <[email protected]>:
Patch series "mm/gup: page unpining improvements", v4:
mm/gup: add compound page list iterator
mm/gup: decrement head page once for group of subpages mm/gup: add a range variant of unpin_user_pages_dirty_lock() RDMA/umem: batch page unpin in __ib_umem_release()
Yang Shi <[email protected]>:
mm: gup: remove FOLL_SPLIT
Subsystem: mm/memremap
Zhiyuan Dai <[email protected]>:
mm/memremap.c: fix improper SPDX comment style
Subsystem: mm/memcg
Muchun Song <[email protected]>:
mm: memcontrol: fix kernel stack account
Shakeel Butt <[email protected]>:
memcg: cleanup root memcg checks
memcg: enable memcg oom-kill for __GFP_NOFAIL
Johannes Weiner <[email protected]>:
Patch series "mm: memcontrol: switch to rstat", v3:
mm: memcontrol: fix cpuhotplug statistics flushing
mm: memcontrol: kill mem_cgroup_nodeinfo()
mm: memcontrol: privatize memcg_page_state query functions
cgroup: rstat: support cgroup1
cgroup: rstat: punt root-level optimization to individual controllers
mm: memcontrol: switch to rstat
mm: memcontrol: consolidate lruvec stat flushing
kselftests: cgroup: update kmem test for new vmstat implementation
Shakeel Butt <[email protected]>:
memcg: charge before adding to swapcache on swapin
Muchun Song <[email protected]>:
Patch series "Use obj_cgroup APIs to charge kmem pages", v5:
mm: memcontrol: slab: fix obtain a reference to a freeing memcg
mm: memcontrol: introduce obj_cgroup_{un}charge_pages
mm: memcontrol: directly access page->memcg_data in mm/page_alloc.c
mm: memcontrol: change ug->dummy_page only if memcg changed
mm: memcontrol: use obj_cgroup APIs to charge kmem pages
mm: memcontrol: inline __memcg_kmem_{un}charge() into obj_cgroup_{un}charge_pages()
mm: memcontrol: move PageMemcgKmem to the scope of CONFIG_MEMCG_KMEM
Wan Jiabing <[email protected]>:
linux/memcontrol.h: remove duplicate struct declaration
Johannes Weiner <[email protected]>:
mm: page_counter: mitigate consequences of a page_counter underflow
Subsystem: mm/pagemap
Wang Qing <[email protected]>:
mm/memory.c: do_numa_page(): delete bool "migrated"
Zhiyuan Dai <[email protected]>:
mm/interval_tree: add comments to improve code readability
Oscar Salvador <[email protected]>:
Patch series "Cleanup and fixups for vmemmap handling", v6:
x86/vmemmap: drop handling of 4K unaligned vmemmap range x86/vmemmap: drop handling of 1GB vmemmap ranges x86/vmemmap: handle unpopulated sub-pmd ranges
x86/vmemmap: optimize for consecutive sections in partial populated PMDs
Ovidiu Panait <[email protected]>:
mm, tracing: improve rss_stat tracepoint message
Christoph Hellwig <[email protected]>:
Patch series "add remap_pfn_range_notrack instead of reinventing it in i915", v2:
mm: add remap_pfn_range_notrack
mm: add a io_mapping_map_user helper
i915: use io_mapping_map_user
i915: fix remap_io_sg to verify the pgprot
Huang Ying <[email protected]>:
NUMA balancing: reduce TLB flush via delaying mapping on hint page fault
Subsystem: mm/mremap
Brian Geffon <[email protected]>:
Patch series "mm: Extend MREMAP_DONTUNMAP to non-anonymous mappings", v5:
mm: extend MREMAP_DONTUNMAP to non-anonymous mappings
Revert "mremap: don't allow MREMAP_DONTUNMAP on special_mappings and aio"
selftests: add a MREMAP_DONTUNMAP selftest for shmem
Subsystem: mm/dma
Zhiyuan Dai <[email protected]>:
mm/dmapool: switch from strlcpy to strscpy
Subsystem: mm/sparsemem
Wang Wensheng <[email protected]>:
mm/sparse: add the missing sparse_buffer_fini() in error branch
Subsystem: mm/vmalloc
Christoph Hellwig <[email protected]>:
Patch series "remap_vmalloc_range cleanups":
samples/vfio-mdev/mdpy: use remap_vmalloc_range
mm: unexport remap_vmalloc_range_partial
Serapheim Dimitropoulos <[email protected]>:
mm/vmalloc: use rb_tree instead of list for vread() lookups
Nicholas Piggin <[email protected]>:
Patch series "huge vmalloc mappings", v13:
ARM: mm: add missing pud_page define to 2-level page tables mm/vmalloc: fix HUGE_VMAP regression by enabling huge pages in vmalloc_to_page
mm: apply_to_pte_range warn and fail if a large pte is encountered mm/vmalloc: rename vmap_*_range vmap_pages_*_range
mm/ioremap: rename ioremap_*_range to vmap_*_range
mm: HUGE_VMAP arch support cleanup
powerpc: inline huge vmap supported functions
arm64: inline huge vmap supported functions
x86: inline huge vmap supported functions
mm/vmalloc: provide fallback arch huge vmap support functions
mm: move vmap_range from mm/ioremap.c to mm/vmalloc.c mm/vmalloc: add vmap_range_noflush variant
mm/vmalloc: hugepage vmalloc mappings
Patch series "mm/vmalloc: cleanup after hugepage series", v2:
mm/vmalloc: remove map_kernel_range
kernel/dma: remove unnecessary unmap_kernel_range
powerpc/xive: remove unnecessary unmap_kernel_range
mm/vmalloc: remove unmap_kernel_range
mm/vmalloc: improve allocation failure error messages
Vijayanand Jitta <[email protected]>:
mm: vmalloc: prevent use after free in _vm_unmap_aliases
"Uladzislau Rezki (Sony)" <[email protected]>:
lib/test_vmalloc.c: remove two kvfree_rcu() tests lib/test_vmalloc.c: add a new 'nr_threads' parameter vm/test_vmalloc.sh: adapt for updated driver interface mm/vmalloc: refactor the preloading loagic mm/vmalloc: remove an empty line
Subsystem: mm/documentation
"Matthew Wilcox (Oracle)" <[email protected]>:
mm/doc: fix fault_flag_allow_retry_first kerneldoc mm/doc: fix page_maybe_dma_pinned kerneldoc mm/doc: turn fault flags into an enum mm/doc: add mm.h and mm_types.h to the mm-api document
Lukas Bulwahn <[email protected]>:
Patch series "kernel-doc and MAINTAINERS clean-up":
MAINTAINERS: assign pagewalk.h to MEMORY MANAGEMENT
pagewalk: prefix struct kernel-doc descriptions
Subsystem: mm/kasan
Zhiyuan Dai <[email protected]>:
mm/kasan: switch from strlcpy to strscpy
Peter Collingbourne <[email protected]>:
kasan: fix kasan_byte_accessible() to be consistent with actual checks
Andrey Konovalov <[email protected]>:
kasan: initialize shadow to TAG_INVALID for SW_TAGS mm, kasan: don't poison boot memory with tag-based modes
Patch series "kasan: integrate with init_on_alloc/free", v3:
arm64: kasan: allow to init memory when setting tags
kasan: init memory in kasan_(un)poison for HW_TAGS kasan, mm: integrate page_alloc init with HW_TAGS kasan, mm: integrate slab init_on_alloc with HW_TAGS kasan, mm: integrate slab init_on_free with HW_TAGS
kasan: docs: clean up sections
kasan: docs: update overview section
kasan: docs: update usage section
kasan: docs: update error reports section
kasan: docs: update boot parameters section
kasan: docs: update GENERIC implementation details section
kasan: docs: update SW_TAGS implementation details section
kasan: docs: update HW_TAGS implementation details section
kasan: docs: update shadow memory section
kasan: docs: update ignoring accesses section
kasan: docs: update tests section
Walter Wu <[email protected]>:
kasan: record task_work_add() call stack
Andrey Konovalov <[email protected]>:
kasan: detect false-positives in tests
Zqiang <[email protected]>:
irq_work: record irq_work_queue() call stack
Subsystem: mm/initialization
Kefeng Wang <[email protected]>:
mm: move mem_init_print_info() into mm_init()
Subsystem: mm/pagealloc
David Hildenbrand <[email protected]>:
mm/page_alloc: drop pr_info_ratelimited() in alloc_contig_range()
Minchan Kim <[email protected]>:
mm: remove lru_add_drain_all in alloc_contig_range
Yu Zhao <[email protected]>:
include/linux/page-flags-layout.h: correctly determine LAST_CPUPID_WIDTH include/linux/page-flags-layout.h: cleanups
"Matthew Wilcox (Oracle)" <[email protected]>:
Patch series "Rationalise __alloc_pages wrappers", v3:
mm/page_alloc: rename alloc_mask to alloc_gfp mm/page_alloc: rename gfp_mask to gfp
mm/page_alloc: combine __alloc_pages and __alloc_pages_nodemask mm/mempolicy: rename alloc_pages_current to alloc_pages mm/mempolicy: rewrite alloc_pages documentation mm/mempolicy: rewrite alloc_pages_vma documentation mm/mempolicy: fix mpol_misplaced kernel-doc
Minchan Kim <[email protected]>:
mm: page_alloc: dump migrate-failed pages
Geert Uytterhoeven <[email protected]>:
mm/Kconfig: remove default DISCONTIGMEM_MANUAL
Kefeng Wang <[email protected]>:
mm, page_alloc: avoid page_to_pfn() in move_freepages()
zhouchuangao <[email protected]>:
mm/page_alloc: duplicate include linux/vmalloc.h
Mel Gorman <[email protected]>:
Patch series "Introduce a bulk order-0 page allocator with two in-tree users", v6:
mm/page_alloc: rename alloced to allocated
mm/page_alloc: add a bulk page allocator
mm/page_alloc: add an array-based interface to the bulk page allocator
Jesper Dangaard Brouer <[email protected]>:
mm/page_alloc: optimize code layout for __alloc_pages_bulk mm/page_alloc: inline __rmqueue_pcplist
Chuck Lever <[email protected]>:
Patch series "SUNRPC consumer for the bulk page allocator":
SUNRPC: set rq_page_end differently
SUNRPC: refresh rq_pages using a bulk page allocator
Jesper Dangaard Brouer <[email protected]>:
net: page_pool: refactor dma_map into own function page_pool_dma_map
net: page_pool: use alloc_pages_bulk in refill code path
Sergei Trofimovich <[email protected]>:
mm: page_alloc: ignore init_on_free=1 for debug_pagealloc=1
huxiang <[email protected]>:
mm/page_alloc: redundant definition variables of pfn in for loop
Mike Rapoport <[email protected]>:
mm/mmzone.h: fix existing kernel-doc comments and link them to core-api
Subsystem: mm/memory-failure
Jane Chu <[email protected]>:
mm/memory-failure: unnecessary amount of unmapping
Documentation/admin-guide/kernel-parameters.txt | 7 Documentation/admin-guide/mm/transhuge.rst | 2 Documentation/core-api/cachetlb.rst | 4 Documentation/core-api/mm-api.rst | 6 Documentation/dev-tools/kasan.rst | 355 +++++----- Documentation/vm/page_owner.rst | 2 Documentation/vm/transhuge.rst | 5 MAINTAINERS | 1 arch/Kconfig | 11 arch/alpha/mm/init.c | 1 arch/arc/mm/init.c | 1 arch/arm/Kconfig | 1 arch/arm/include/asm/pgtable-3level.h | 2 arch/arm/include/asm/pgtable.h | 3 arch/arm/mm/copypage-v4mc.c | 1 arch/arm/mm/copypage-v6.c | 1 arch/arm/mm/copypage-xscale.c | 1 arch/arm/mm/init.c | 2 arch/arm64/Kconfig | 1 arch/arm64/include/asm/memory.h | 4 arch/arm64/include/asm/mte-kasan.h | 39 - arch/arm64/include/asm/vmalloc.h | 38 - arch/arm64/mm/init.c | 4 arch/arm64/mm/mmu.c | 36 - arch/csky/abiv1/cacheflush.c | 1 arch/csky/mm/init.c | 1 arch/h8300/mm/init.c | 2 arch/hexagon/mm/init.c | 1 arch/ia64/Kconfig | 23 arch/ia64/configs/bigsur_defconfig | 1 arch/ia64/include/asm/meminit.h | 11 arch/ia64/include/asm/module.h | 6 arch/ia64/include/asm/page.h | 25 arch/ia64/include/asm/pgtable.h | 7 arch/ia64/kernel/Makefile | 2 arch/ia64/kernel/acpi.c | 7 arch/ia64/kernel/efi.c | 11 arch/ia64/kernel/fsys.S | 4 arch/ia64/kernel/head.S | 6 arch/ia64/kernel/ia64_ksyms.c | 12 arch/ia64/kernel/machine_kexec.c | 2 arch/ia64/kernel/mca.c | 4 arch/ia64/kernel/module.c | 29 arch/ia64/kernel/pal.S | 6 arch/ia64/mm/Makefile | 1 arch/ia64/mm/contig.c | 4 arch/ia64/mm/discontig.c | 21 arch/ia64/mm/fault.c | 15 arch/ia64/mm/init.c | 221 ------ arch/m68k/mm/init.c | 1 arch/microblaze/mm/init.c | 1 arch/mips/Kconfig | 1 arch/mips/loongson64/numa.c | 1 arch/mips/mm/cache.c | 1 arch/mips/mm/init.c | 1 arch/mips/sgi-ip27/ip27-memory.c | 1 arch/nds32/mm/init.c | 1 arch/nios2/mm/cacheflush.c | 1 arch/nios2/mm/init.c | 1 arch/openrisc/mm/init.c | 2 arch/parisc/mm/init.c | 2 arch/powerpc/Kconfig | 1 arch/powerpc/include/asm/vmalloc.h | 34 - arch/powerpc/kernel/isa-bridge.c | 4 arch/powerpc/kernel/pci_64.c | 2 arch/powerpc/mm/book3s64/radix_pgtable.c | 29 arch/powerpc/mm/ioremap.c | 2 arch/powerpc/mm/mem.c | 1 arch/powerpc/sysdev/xive/common.c | 4 arch/riscv/mm/init.c | 1 arch/s390/mm/init.c | 2 arch/sh/include/asm/tlb.h | 10 arch/sh/mm/cache-sh4.c | 1 arch/sh/mm/cache-sh7705.c | 1 arch/sh/mm/init.c | 1 arch/sparc/include/asm/pgtable_32.h | 3 arch/sparc/mm/init_32.c | 2 arch/sparc/mm/init_64.c | 1 arch/sparc/mm/tlb.c | 1 arch/um/kernel/mem.c | 1 arch/x86/Kconfig | 1 arch/x86/include/asm/vmalloc.h | 42 - arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 2 arch/x86/mm/init_32.c | 2 arch/x86/mm/init_64.c | 222 ++++-- arch/x86/mm/ioremap.c | 33 arch/x86/mm/pgtable.c | 13 arch/xtensa/Kconfig | 1 arch/xtensa/mm/init.c | 1 block/blk-cgroup.c | 17 drivers/gpu/drm/i915/Kconfig | 1 drivers/gpu/drm/i915/gem/i915_gem_mman.c | 9 drivers/gpu/drm/i915/i915_drv.h | 3 drivers/gpu/drm/i915/i915_mm.c | 117 --- drivers/infiniband/core/umem.c | 12 drivers/pci/pci.c | 2 fs/aio.c | 5 fs/fs_parser.c | 2 fs/iomap/direct-io.c | 24 fs/ocfs2/blockcheck.c | 2 fs/ocfs2/dlm/dlmrecovery.c | 7 fs/ocfs2/stack_o2cb.c | 36 - fs/ocfs2/stackglue.c | 2 include/linux/compiler-gcc.h | 8 include/linux/fs.h | 2 include/linux/gfp.h | 45 - include/linux/io-mapping.h | 3 include/linux/io.h | 9 include/linux/kasan.h | 51 + include/linux/memcontrol.h | 271 ++++---- include/linux/mm.h | 50 - include/linux/mmzone.h | 43 - include/linux/page-flags-layout.h | 64 - include/linux/pagemap.h | 10 include/linux/pagewalk.h | 4 include/linux/sched.h | 4 include/linux/slab.h | 2 include/linux/slub_def.h | 2 include/linux/vmalloc.h | 73 +- include/linux/vmstat.h | 24 include/net/page_pool.h | 2 include/trace/events/kmem.h | 24 init/main.c | 2 kernel/cgroup/cgroup.c | 34 - kernel/cgroup/rstat.c | 61 + kernel/dma/remap.c | 1 kernel/fork.c | 13 kernel/irq_work.c | 7 kernel/task_work.c | 3 kernel/watchdog.c | 102 +-- lib/Kconfig.debug | 14 lib/Makefile | 1 lib/test_kasan.c | 59 - lib/test_slub.c | 124 +++ lib/test_vmalloc.c | 128 +-- mm/Kconfig | 4 mm/Makefile | 1 mm/debug_vm_pgtable.c | 4 mm/dmapool.c | 2 mm/filemap.c | 61 + mm/gup.c | 145 +++- mm/hugetlb.c | 2 mm/internal.h | 25 mm/interval_tree.c | 2 mm/io-mapping.c | 29 mm/ioremap.c | 361 ++-------- mm/kasan/common.c | 53 - mm/kasan/generic.c | 12 mm/kasan/kasan.h | 28 mm/kasan/report_generic.c | 2 mm/kasan/shadow.c | 10 mm/kasan/sw_tags.c | 12 mm/kmemleak.c | 2 mm/memcontrol.c | 798 ++++++++++++------------ mm/memory-failure.c | 2 mm/memory.c | 191 +++-- mm/mempolicy.c | 78 -- mm/mempool.c | 4 mm/memremap.c | 2 mm/migrate.c | 2 mm/mm_init.c | 4 mm/mmap.c | 6 mm/mremap.c | 6 mm/msync.c | 6 mm/page-writeback.c | 9 mm/page_alloc.c | 430 +++++++++--- mm/page_counter.c | 8 mm/page_owner.c | 68 -- mm/page_poison.c | 6 mm/percpu-vm.c | 7 mm/slab.c | 43 - mm/slab.h | 24 mm/slab_common.c | 10 mm/slub.c | 215 ++---- mm/sparse.c | 1 mm/swap_state.c | 13 mm/util.c | 10 mm/vmalloc.c | 728 ++++++++++++++++----- net/core/page_pool.c | 127 ++- net/sunrpc/svc_xprt.c | 38 - samples/kfifo/bytestream-example.c | 8 samples/kfifo/inttype-example.c | 8 samples/kfifo/record-example.c | 8 samples/vfio-mdev/mdpy.c | 4 scripts/checkdeclares.pl | 53 + scripts/spelling.txt | 26 tools/testing/selftests/cgroup/test_kmem.c | 22 tools/testing/selftests/vm/mremap_dontunmap.c | 52 + tools/testing/selftests/vm/test_vmalloc.sh | 21 189 files changed, 3642 insertions(+), 3013 deletions(-)
Andrew Morton
maintainerPATCH 1/178 arch/ia64/kernel/head.S: remove duplicate include
From: Zhang Yunkai <[email protected]>
Subject: arch/ia64/kernel/head.S: remove duplicate include
'linux/pgtable.h' included in 'arch/ia64/kernel/head.S' is duplicated.
---
arch/ia64/kernel/head.S | 1 - 1 file changed, 1 deletion(-)
arch/ia64/kernel/head.S renamed from arch/ia64/kernel/head.S~module-remove-duplicate-include-in-arch-ia64-kernel-heads +0 -1
@@ -33,7 +33,6 @@ #include <asm/mca_asm.h> #include <linux/init.h> #include <linux/linkage.h> -#include <linux/pgtable.h> #include <asm/export.h> #ifdef CONFIG_HOTPLUG_CPU
_
Andrew Morton
maintainerPATCH 2/178 arch/ia64/kernel/fsys.S: fix typos
In reply to Andrew MortonFrom: Bhaskar Chowdhury <[email protected]>
Subject: arch/ia64/kernel/fsys.S: fix typos
Mundane spelling fixes.
---
arch/ia64/kernel/fsys.S | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/ia64/kernel/fsys.S renamed from arch/ia64/kernel/fsys.S~ia64-kernel-few-typos-fixed-in-the-file-fsyss +2 -2
@@ -172,7 +172,7 @@ ENTRY(fsys_gettimeofday) // r25 = itc_lastcycle value // r26 = address clocksource cycle_last // r27 = (not used) - // r28 = sequence number at the beginning of critcal section + // r28 = sequence number at the beginning of critical section // r29 = address of itc_jitter // r30 = time processing flags / memory address // r31 = pointer to result
@@ -432,7 +432,7 @@ GLOBAL_ENTRY(fsys_bubble_down) * - r29: psr * * We used to clear some PSR bits here but that requires slow - * serialization. Fortuntely, that isn't really necessary. + * serialization. Fortunately, that isn't really necessary. * The rationale is as follows: we used to clear bits * ~PSR_PRESERVED_BITS in PSR.L. Since * PSR_PRESERVED_BITS==PSR.{UP,MFL,MFH,PK,DT,PP,SP,RT,IC}, we
_
Andrew Morton
maintainerPATCH 3/178 arch/ia64/include/asm/pgtable.h: minor typo fixes
In reply to Andrew MortonFrom: Bhaskar Chowdhury <[email protected]>
Subject: arch/ia64/include/asm/pgtable.h: minor typo fixes
s/migraton/migration/
---
arch/ia64/include/asm/pgtable.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/ia64/include/asm/pgtable.h renamed from arch/ia64/include/asm/pgtable.h~ia64-include-asm-minor-typo-fixes-in-the-file-pgtableh +1 -1
@@ -328,7 +328,7 @@ extern void __ia64_sync_icache_dcache(ptstatic inline void set_pte (pte_t *ptep,pte_t pteval) {/* page is present && page is user && page is executable -* && (page swapin or new page or page migraton +* && (page swapin or new page or page migration * || copy_on_write with page copying.) */ if (pte_present_exec_user(pteval) &&
_
Andrew Morton
maintainerPATCH 4/178 ia64: ensure proper NUMA distance and possible map initialization
In reply to Andrew MortonFrom: Valentin Schneider <[email protected]>
Subject: ia64: ensure proper NUMA distance and possible map initialization
John Paul reported a warning about bogus NUMA distance values spurred by commit:
620a6dc40754 ("sched/topology: Make sched_init_numa() use a set for the deduplicating sort")
In this case, the afflicted machine comes up with a reported 256 possible nodes, all of which are 0 distance away from one another. This was previously silently ignored, but is now caught by the aforementioned commit.
The culprit is ia64's node_possible_map which remains unchanged from its initialization value of NODE_MASK_ALL. In John's case, the machine doesn't have any SRAT nor SLIT table, but AIUI the possible map remains untouched regardless of what ACPI tables end up being parsed. Thus, !online && possible nodes remain with a bogus distance of 0 (distances \in [0, 9] are "reserved and have no meaning" as per the ACPI spec).
Follow x86 / drivers/base/arch_numa's example and set the possible map to the parsed map, which in this case seems to be the online map.
---
arch/ia64/kernel/acpi.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
arch/ia64/kernel/acpi.c renamed from arch/ia64/kernel/acpi.c~ia64-ensure-proper-numa-distance-and-possible-map-initialization +5 -2
@@ -446,7 +446,8 @@ void __init acpi_numa_fixup(void)if (srat_num_cpus ==0 ) {node_set_online (0 ); node_cpuid[0 ].phys_id =hard_smp_processor_id (); -return ; +slit_distance (0 ,0 ) =LOCAL_DISTANCE ; + goto out; }/*
@@ -489,7 +490,7 @@ void __init acpi_numa_fixup(void)for (j =0 ; j <MAX_NUMNODES ; j++)slit_distance (i, j) = i == j ?LOCAL_DISTANCE :REMOTE_DISTANCE ; -return ; + goto out; }memset (numa_slit,-1 ,sizeof (numa_slit));
@@ -514,6 +515,8 @@ void __init acpi_numa_fixup(void)printk ("\n" ); }#endif +out: + node_possible_map = node_online_map; }#endif /* CONFIG_ACPI_NUMA */
_
Andrew Morton
maintainerPATCH 5/178 ia64: drop unused IA64_FW_EMU ifdef
In reply to Andrew MortonFrom: Sergei Trofimovich <[email protected]>
Subject: ia64: drop unused IA64_FW_EMU ifdef
It's a remnant of deleted hpsim emulation target removed in fc5bad037 ("ia64: remove the hpsim platform").
---
arch/ia64/kernel/head.S | 5 ----- 1 file changed, 5 deletions(-)
arch/ia64/kernel/head.S renamed from arch/ia64/kernel/head.S~ia64-drop-unused-ia64_fw_emu-ifdef +0 -5
@@ -404,11 +404,6 @@ start_ap: // This is executed by the bootstrap processor (bsp) only: -#ifdef CONFIG_IA64_FW_EMU - // initialize PAL & SAL emulator: - br.call.sptk.many rp=sys_fw_init -.ret1: -#endif br.call.sptk.many rp=start_kernel .ret2: addl r3=@ltoff(halt_msg),gp ;;
_
Andrew Morton
maintainerPATCH 6/178 ia64: simplify code flow around swiotlb init
In reply to Andrew MortonFrom: Sergei Trofimovich <[email protected]>
Subject: ia64: simplify code flow around swiotlb init
Before the change CONFIG_INTEL_IOMMU && !CONFIG_SWIOTLB && !CONFIG_FLATMEM could skip set_max_mapnr(max_low_pfn); if iommu is not present on system.
---
arch/ia64/mm/init.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
arch/ia64/mm/init.c renamed from arch/ia64/mm/init.c~ia64-simplify-code-flow-around-swiotlb-init +5 -2
@@ -644,13 +644,16 @@ mem_init (void)* _before_ any drivers that may need the PCI DMA interface are * initialized or bootmem has been freed. */ +do {#ifdef CONFIG_INTEL_IOMMU -detect_intel_iommu (); - if (!iommu_detected) +detect_intel_iommu (); +if (iommu_detected) +break ;#endif #ifdef CONFIG_SWIOTLB swiotlb_init (1 );#endif + }while (0 );#ifdef CONFIG_FLATMEM BUG_ON (!mem_map);
_
Andrew Morton
maintainerPATCH 7/178 ia64: trivial spelling fixes
In reply to Andrew MortonFrom: Bhaskar Chowdhury <[email protected]>
Subject: ia64: trivial spelling fixes
s/seralize/serialize/ .....three different places
---
arch/ia64/kernel/pal.S | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/ia64/kernel/pal.S renamed from arch/ia64/kernel/pal.S~ia64-trivial-spelling-fixes +3 -3
@@ -86,7 +86,7 @@ GLOBAL_ENTRY(ia64_pal_call_static) mov ar.pfs = loc1 mov rp = loc0 ;; - srlz.d // seralize restoration of psr.l + srlz.d // serialize restoration of psr.l br.ret.sptk.many b0 END(ia64_pal_call_static) EXPORT_SYMBOL(ia64_pal_call_static)
@@ -194,7 +194,7 @@ GLOBAL_ENTRY(ia64_pal_call_phys_static) mov rp = loc0 ;; mov ar.rsc=loc4 // restore RSE configuration - srlz.d // seralize restoration of psr.l + srlz.d // serialize restoration of psr.l br.ret.sptk.many b0 END(ia64_pal_call_phys_static) EXPORT_SYMBOL(ia64_pal_call_phys_static)
@@ -252,7 +252,7 @@ GLOBAL_ENTRY(ia64_pal_call_phys_stacked) mov rp = loc0 ;; mov ar.rsc=loc4 // restore RSE configuration - srlz.d // seralize restoration of psr.l + srlz.d // serialize restoration of psr.l br.ret.sptk.many b0 END(ia64_pal_call_phys_stacked) EXPORT_SYMBOL(ia64_pal_call_phys_stacked)
_
Andrew Morton
maintainerPATCH 8/178 ia64: fix EFI_DEBUG build
In reply to Andrew MortonFrom: Sergei Trofimovich <[email protected]>
Subject: ia64: fix EFI_DEBUG build
When enabled local debugging via #define EFI_DEBUG 1 noticed build failure:
arch/ia64/kernel/efi.c:564:8: error: 'i' undeclared (first use in this function)
While at it fixed benign string format mismatches visible only when EFI_DEBUG is enabled:
arch/ia64/kernel/efi.c:589:11:
warning: format '%lx' expects argument of type 'long unsigned int', but argument 5 has type 'u64' {aka 'long long unsigned int'} [-Wformat=]
---
arch/ia64/kernel/efi.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
arch/ia64/kernel/efi.c renamed from arch/ia64/kernel/efi.c~ia64-fix-efi_debug-build +6 -5
@@ -415,10 +415,10 @@ efi_get_pal_addr (void) mask = ~((1 <<IA64_GRANULE_SHIFT ) -1 );printk (KERN_INFO "CPU %d: mapping PAL code " -"[0x%lx-0x%lx) into [0x%lx-0x%lx)\n" , -smp_processor_id (), md->phys_addr, - md->phys_addr +efi_md_size (md), - vaddr & mask, (vaddr & mask) +IA64_GRANULE_SIZE ); +"[0x%llx-0x%llx) into [0x%llx-0x%llx)\n" , +smp_processor_id (), md->phys_addr, + md->phys_addr +efi_md_size (md), + vaddr & mask, (vaddr & mask) +IA64_GRANULE_SIZE );#endif return __va (md->phys_addr); }
@@ -560,6 +560,7 @@ efi_init (void) {efi_memory_desc_t *md;void *p; +unsigned int i;for (i =0 , p = efi_map_start; p < efi_map_end; ++i, p += efi_desc_size)
@@ -586,7 +587,7 @@ efi_init (void) }printk ("mem%02d: %s " -"range=[0x%016lx-0x%016lx) (%4lu%s)\n" , +"range=[0x%016llx-0x%016llx) (%4lu%s)\n" , i,efi_md_typeattr_format (buf,sizeof (buf), md), md->phys_addr, md->phys_addr +efi_md_size (md), size, unit);
_
Andrew Morton
maintainerPATCH 9/178 ia64: mca: always make IA64_MCA_DEBUG an expression
In reply to Andrew MortonFrom: Sergei Trofimovich <[email protected]>
Subject: ia64: mca: always make IA64_MCA_DEBUG an expression
At least ia64_mca_log_sal_error_record() expects some statement:
static void ia64_mca_log_sal_error_record(int sal_info_type) {
...
if (irq_safe)
IA64_MCA_DEBUG("CPU %d: SAL log contains %s error record
",
smp_processor_id(),
sal_info_type < ARRAY_SIZE(rec_name) ? rec_name[sal_info_type] : "UNKNOWN");
...
}Instead of fixing all callers the change expicitly makes IA64_MCA_DEBUG a non-empty expression.
---
arch/ia64/kernel/mca.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/ia64/kernel/mca.c renamed from arch/ia64/kernel/mca.c~ia64-mca-always-make-ia64_mca_debug-an-expression +2 -2
@@ -109,9 +109,9 @@#include "irq.h" #if defined(IA64_MCA_DEBUG_INFO ) -# define IA64_MCA_DEBUG(fmt...) printk(fmt) +# define IA64_MCA_DEBUG(fmt...) printk(fmt)#else -# define IA64_MCA_DEBUG(fmt...) +# define IA64_MCA_DEBUG(fmt...) do {} while (0)#endif #define NOTIFY_INIT (event, regs, arg, spin) \
_
Andrew Morton
maintainerPATCH 10/178 ia64: drop marked broken DISCONTIGMEM and VIRTUAL_MEM_MAP
In reply to Andrew MortonFrom: Sergei Trofimovich <[email protected]>
Subject: ia64: drop marked broken DISCONTIGMEM and VIRTUAL_MEM_MAP
DISCONTIGMEM was marked BROKEN in 5.11. Let's remove it.
Booted SPARSEMEM successfully on rx3600.
---
arch/ia64/Kconfig | 23 -- arch/ia64/configs/bigsur_defconfig | 1 arch/ia64/include/asm/meminit.h | 11 - arch/ia64/include/asm/page.h | 25 --- arch/ia64/include/asm/pgtable.h | 5 arch/ia64/kernel/Makefile | 2 arch/ia64/kernel/ia64_ksyms.c | 12 - arch/ia64/kernel/machine_kexec.c | 2 arch/ia64/mm/Makefile | 1 arch/ia64/mm/contig.c | 4 arch/ia64/mm/discontig.c | 21 -- arch/ia64/mm/fault.c | 15 - arch/ia64/mm/init.c | 213 --------------------------- 13 files changed, 4 insertions(+), 331 deletions(-)
arch/ia64/configs/bigsur_defconfig renamed from arch/ia64/configs/bigsur_defconfig~ia64-drop-marked-broken-discontigmem-and-virtual_mem_map +0 -1
@@ -9,7 +9,6 @@ CONFIG_SGI_PARTITION=y CONFIG_SMP=y CONFIG_NR_CPUS=2 CONFIG_PREEMPT=y -# CONFIG_VIRTUAL_MEM_MAP is not set CONFIG_IA64_PALINFO=y CONFIG_EFI_VARS=y CONFIG_BINFMT_MISC=m
arch/ia64/include/asm/meminit.h renamed from arch/ia64/include/asm/meminit.h~ia64-drop-marked-broken-discontigmem-and-virtual_mem_map +0 -11
@@ -58,15 +58,4 @@ extern int reserve_elfcorehdr(u64 *startextern int register_active_ranges (u64 start,u64 len,int nid); -#ifdef CONFIG_VIRTUAL_MEM_MAP -extern unsigned long VMALLOC_END ; -extern struct page *vmem_map; -extern int create_mem_map_page_table (u64 start,u64 end,void *arg); -extern int vmemmap_find_next_valid_pfn (int ,int ); -#else -static inline int vmemmap_find_next_valid_pfn (int node,int i) -{ -return i +1 ; -} -#endif #endif /* meminit_h */
arch/ia64/include/asm/page.h renamed from arch/ia64/include/asm/page.h~ia64-drop-marked-broken-discontigmem-and-virtual_mem_map +2 -23
@@ -95,31 +95,10 @@ do { \#define virt_addr_valid (kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT) -#ifdef CONFIG_VIRTUAL_MEM_MAP -extern int ia64_pfn_valid (unsigned long pfn); -#else -# define ia64_pfn_valid (pfn) 1 -#endif - -#ifdef CONFIG_VIRTUAL_MEM_MAP -extern struct page *vmem_map; -#ifdef CONFIG_DISCONTIGMEM -# define page_to_pfn (page) ((unsigned long) (page - vmem_map)) -# define pfn_to_page (pfn) (vmem_map + (pfn)) -# define __pfn_to_phys (pfn) PFN_PHYS(pfn) -#else -# include <asm-generic/memory_model.h> -#endif -#else -# include <asm-generic/memory_model.h> -#endif +#include <asm-generic/memory_model.h> #ifdef CONFIG_FLATMEM -# define pfn_valid (pfn) (((pfn) < max_mapnr) && ia64_pfn_valid(pfn)) -#elif defined(CONFIG_DISCONTIGMEM ) -extern unsigned long min_low_pfn; -extern unsigned long max_low_pfn; -# define pfn_valid (pfn) (((pfn) >= min_low_pfn) && ((pfn) < max_low_pfn) && ia64_pfn_valid(pfn)) +# define pfn_valid (pfn) ((pfn) < max_mapnr)#endif #define page_to_phys (page) (page_to_pfn(page) << PAGE_SHIFT)
arch/ia64/include/asm/pgtable.h renamed from arch/ia64/include/asm/pgtable.h~ia64-drop-marked-broken-discontigmem-and-virtual_mem_map +0 -5
@@ -223,10 +223,6 @@ ia64_phys_addr_valid (unsigned long addr#define VMALLOC_START (RGN_BASE(RGN_GATE) + 0x200000000UL) -#ifdef CONFIG_VIRTUAL_MEM_MAP -# define VMALLOC_END_INIT (RGN_BASE(RGN_GATE) + (1UL << (4*PAGE_SHIFT - 9))) -extern unsigned long VMALLOC_END ; -#else #if defined(CONFIG_SPARSEMEM ) && defined(CONFIG_SPARSEMEM_VMEMMAP )/* SPARSEMEM_VMEMMAP uses half of vmalloc... */ # define VMALLOC_END (RGN_BASE(RGN_GATE) + (1UL << (4*PAGE_SHIFT - 10)))
@@ -234,7 +230,6 @@ extern unsigned long VMALLOC_END;#else # define VMALLOC_END (RGN_BASE(RGN_GATE) + (1UL << (4*PAGE_SHIFT - 9)))#endif -#endif /* fs/proc/kcore.c */ #define kc_vaddr_to_offset (v) ((v) - RGN_BASE(RGN_GATE))
arch/ia64/Kconfig renamed from arch/ia64/Kconfig~ia64-drop-marked-broken-discontigmem-and-virtual_mem_map +0 -23
@@ -286,15 +286,6 @@ config FORCE_CPEI_RETARGET config ARCH_SELECT_MEMORY_MODEL def_bool y -config ARCH_DISCONTIGMEM_ENABLE - def_bool y - depends on BROKEN - help - Say Y to support efficient handling of discontiguous physical memory, - for architectures which are either NUMA (Non-Uniform Memory Access) - or have huge holes in the physical address space for other reasons. - See <file:Documentation/vm/numa.rst> for more. - config ARCH_FLATMEM_ENABLE def_bool y
@@ -325,22 +316,8 @@ config NODES_SHIFT MAX_NUMNODES will be 2^(This value). If in doubt, use the default. -# VIRTUAL_MEM_MAP and FLAT_NODE_MEM_MAP are functionally equivalent. -# VIRTUAL_MEM_MAP has been retained for historical reasons. -config VIRTUAL_MEM_MAP - bool "Virtual mem map" - depends on !SPARSEMEM && !FLATMEM - default y - help - Say Y to compile the kernel with support for a virtual mem map. - This code also only takes effect if a memory hole of greater than - 1 Gb is found during boot. You must turn this option on if you - require the DISCONTIGMEM option for your machine. If you are - unsure, say Y. - config HOLES_IN_ZONE bool - default y if VIRTUAL_MEM_MAP config HAVE_ARCH_NODEDATA_EXTENSION def_bool y
arch/ia64/kernel/ia64_ksyms.c deleted +0 -12
@@ -1,12 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* -* Architecture-specific kernel symbols -*/ - -#if defined(CONFIG_VIRTUAL_MEM_MAP ) || defined(CONFIG_DISCONTIGMEM ) -#include <linux/compiler.h> -#include <linux/export.h> -#include <linux/memblock.h> -EXPORT_SYMBOL (min_low_pfn);/* defined by bootmem.c, but not exported by generic code */ -EXPORT_SYMBOL (max_low_pfn);/* defined by bootmem.c, but not exported by generic code */ -#endif
arch/ia64/kernel/machine_kexec.c renamed from arch/ia64/kernel/machine_kexec.c~ia64-drop-marked-broken-discontigmem-and-virtual_mem_map +1 -1
@@ -143,7 +143,7 @@ void machine_kexec(struct kimage *image)void arch_crash_save_vmcoreinfo (void ) { -#if defined(CONFIG_DISCONTIGMEM ) || defined(CONFIG_SPARSEMEM ) +#if defined(CONFIG_SPARSEMEM )VMCOREINFO_SYMBOL (pgdat_list);VMCOREINFO_LENGTH (pgdat_list,MAX_NUMNODES );#endif
arch/ia64/kernel/Makefile renamed from arch/ia64/kernel/Makefile~ia64-drop-marked-broken-discontigmem-and-virtual_mem_map +1 -1
@@ -9,7 +9,7 @@ endif extra-y := head.o vmlinux.lds -obj-y := entry.o efi.o efi_stub.o gate-data.o fsys.o ia64_ksyms.o irq.o irq_ia64.o \ +obj-y := entry.o efi.o efi_stub.o gate-data.o fsys.o irq.o irq_ia64.o \ irq_lsapic.o ivt.o pal.o patch.o process.o ptrace.o sal.o \ salinfo.o setup.o signal.o sys_ia64.o time.o traps.o unaligned.o \ unwind.o mca.o mca_asm.o topology.o dma-mapping.o iosapic.o acpi.o \
arch/ia64/mm/contig.c renamed from arch/ia64/mm/contig.c~ia64-drop-marked-broken-discontigmem-and-virtual_mem_map +0 -4
@@ -153,11 +153,7 @@ find_memory (void)efi_memmap_walk (find_max_min_low_pfn,NULL ); max_pfn = max_low_pfn; -#ifdef CONFIG_VIRTUAL_MEM_MAP -efi_memmap_walk (filter_memory, register_active_ranges); -#else memblock_add_node (0 ,PFN_PHYS (max_low_pfn),0 ); -#endif find_initrd ();
arch/ia64/mm/discontig.c renamed from arch/ia64/mm/discontig.c~ia64-drop-marked-broken-discontigmem-and-virtual_mem_map +0 -21
@@ -585,25 +585,6 @@ void call_pernode_memory(unsigned long s } } -static void __init virtual_map_init (void ) -{ -#ifdef CONFIG_VIRTUAL_MEM_MAP -int node; - -VMALLOC_END -=PAGE_ALIGN (ALIGN (max_low_pfn,MAX_ORDER_NR_PAGES ) * -sizeof (struct page )); - vmem_map = (struct page *)VMALLOC_END ; -efi_memmap_walk (create_mem_map_page_table,NULL ); -printk ("Virtual mem_map starts at 0x%p\n" , vmem_map); - -for_each_online_node (node) { -unsigned long pfn_offset = mem_data[node].min_pfn; - -NODE_DATA (node)->node_mem_map = vmem_map + pfn_offset; - } -#endif -} -/** * paging_init - setup page tables *
@@ -619,8 +600,6 @@ void __init paging_init(void)sparse_init (); -virtual_map_init (); -memset (max_zone_pfns,0 ,sizeof (max_zone_pfns)); max_zone_pfns[ZONE_DMA32 ] = max_dma; max_zone_pfns[ZONE_NORMAL ] = max_low_pfn;
arch/ia64/mm/fault.c renamed from arch/ia64/mm/fault.c~ia64-drop-marked-broken-discontigmem-and-virtual_mem_map +0 -15
@@ -84,18 +84,6 @@ ia64_do_page_fault (unsigned long addresif (faulthandler_disabled () || !mm) goto no_context; -#ifdef CONFIG_VIRTUAL_MEM_MAP -/* -* If fault is in region 5 and we are in the kernel, we may already -* have the mmap_lock (pfn_valid macro is called during mmap). There -* is no vma for region 5 addr's anyway, so skip getting the semaphore -* and go directly to the exception handling code. -*/ - -if ((REGION_NUMBER (address) ==5 ) && !user_mode (regs)) - goto bad_area_no_up; -#endif -/* * This is to handle the kprobes on user space access instructions */
@@ -213,9 +201,6 @@ retry: bad_area:mmap_read_unlock (mm); -#ifdef CONFIG_VIRTUAL_MEM_MAP - bad_area_no_up: -#endif if ((isr &IA64_ISR_SP ) || ((isr &IA64_ISR_NA ) && (isr &IA64_ISR_CODE_MASK ) ==IA64_ISR_CODE_LFETCH )) {
arch/ia64/mm/init.c renamed from arch/ia64/mm/init.c~ia64-drop-marked-broken-discontigmem-and-virtual_mem_map +0 -213
225 lines not on this page · raw message
arch/ia64/mm/Makefile renamed from arch/ia64/mm/Makefile~ia64-drop-marked-broken-discontigmem-and-virtual_mem_map +0 -1
@@ -7,6 +7,5 @@ obj-y := init.o fault.o tlb.o extable.o obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o obj-$(CONFIG_NUMA) += numa.o -obj-$(CONFIG_DISCONTIGMEM) += discontig.o obj-$(CONFIG_SPARSEMEM) += discontig.o obj-$(CONFIG_FLATMEM) += contig.o
_
Andrew Morton
maintainerPATCH 11/178 ia64: module: fix symbolizer crash on fdescr
In reply to Andrew MortonFrom: Sergei Trofimovich <[email protected]>
Subject: ia64: module: fix symbolizer crash on fdescr
Noticed failure as a crash on ia64 when tried to symbolize all backtraces collected by page_owner=on:
$ cat /sys/kernel/debug/page_owner
<oops> CPU: 1 PID: 2074 Comm: cat Not tainted 5.12.0-rc4 #226
Hardware name: hp server rx3600, BIOS 04.03 04/08/2008
ip is at dereference_module_function_descriptor+0x41/0x100Crash happens at dereference_module_function_descriptor() due to use-after-free when dereferencing ".opd" section header.
All section headers are already freed after module is laoded successfully.
To keep symbolizer working the change stores ".opd" address and size after module is relocated to a new place and before section headers are discarded.
To make similar errors less obscure module_finalize() now zeroes out all variables relevant to module loading only.
---
arch/ia64/include/asm/module.h | 6 +++++- arch/ia64/kernel/module.c | 29 +++++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 5 deletions(-)
arch/ia64/include/asm/module.h renamed from arch/ia64/include/asm/module.h~ia64-module-fix-symbolizer-crash-on-fdescr +5 -1
@@ -14,16 +14,20 @@struct elf64_shdr ;/* forward declration */ struct mod_arch_specific { +/* Used only at module load time. */ struct elf64_shdr *core_plt;/* core PLT section */ struct elf64_shdr *init_plt;/* init PLT section */ struct elf64_shdr *got;/* global offset table */ struct elf64_shdr *opd;/* official procedure descriptors */ struct elf64_shdr *unwind;/* unwind-table section */ unsigned long gp;/* global-pointer for module */ +unsigned int next_got_entry;/* index of next available got entry */ +/* Used at module run and cleanup time. */ void *core_unw_table;/* core unwind-table cookie returned by unwinder */ void *init_unw_table;/* init unwind-table cookie returned by unwinder */ -unsigned int next_got_entry;/* index of next available got entry */ +void *opd_addr;/* symbolize uses .opd to get to actual function */ +unsigned long opd_size; };#define ARCH_SHF_SMALL SHF_IA_64_SHORT
arch/ia64/kernel/module.c renamed from arch/ia64/kernel/module.c~ia64-module-fix-symbolizer-crash-on-fdescr +25 -4
@@ -905,9 +905,31 @@ register_unwind_table (struct module *moint module_finalize (const Elf_Ehdr *hdr,const Elf_Shdr *sechdrs,struct module *mod) { +struct mod_arch_specific *mas = &mod->arch; +DEBUGP ("%s: init: entry=%p\n" , __func__, mod->init); -if (mod->arch.unwind) +if (mas->unwind)register_unwind_table (mod); + +/* +* ".opd" was already relocated to the final destination. Store +* it's address for use in symbolizer. +*/ + mas->opd_addr = (void *)mas->opd->sh_addr; + mas->opd_size = mas->opd->sh_size; + +/* +* Module relocation was already done at this point. Section +* headers are about to be deleted. Wipe out load-time context. +*/ + mas->core_plt =NULL ; + mas->init_plt =NULL ; + mas->got =NULL ; + mas->opd =NULL ; + mas->unwind =NULL ; + mas->gp =0 ; + mas->next_got_entry =0 ; +return 0 ; }
@@ -926,10 +948,9 @@ module_arch_cleanup (struct module *mod)void *dereference_module_function_descriptor (struct module *mod,void *ptr) { -Elf64_Shdr *opd = mod->arch.opd; +struct mod_arch_specific *mas = &mod->arch; -if (ptr < (void *)opd->sh_addr || - ptr >= (void *)(opd->sh_addr + opd->sh_size)) +if (ptr < mas->opd_addr || ptr >= mas->opd_addr + mas->opd_size)return ptr;return dereference_function_descriptor (ptr);
_
Andrew Morton
maintainerPATCH 12/178 include/linux/compiler-gcc.h: sparse can do constant folding of __builtin_bswap*()
In reply to Andrew MortonFrom: Luc Van Oostenryck <[email protected]>
Subject: include/linux/compiler-gcc.h: sparse can do constant folding of __builtin_bswap*()
Sparse can do constant folding of __builtin_bswap*() since 2017. Also, a much recent version of Sparse is needed anyway, see commit 6ec4476ac825 ("Raise gcc version requirement to 4.9").
So, remove the comment about sparse not being yet able to constant fold __builtin_bswap*() and remove the corresponding test of __CHECKER__.
---
include/linux/compiler-gcc.h | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
include/linux/compiler-gcc.h renamed from include/linux/compiler-gcc.h~sparse-can-do-constant-folding-of-__builtin_bswap +2 -6
@@ -90,15 +90,11 @@*/ #define asm_volatile_goto(x...) do { asm goto(x); asm (""); } while (0) -/* -* sparse (__CHECKER__) pretends to be gcc, but can't do constant -* folding in __builtin_bswap*() (yet), so don't set these for it. -*/ -#if defined(CONFIG_ARCH_USE_BUILTIN_BSWAP ) && !defined(__CHECKER__) +#if defined(CONFIG_ARCH_USE_BUILTIN_BSWAP )#define __HAVE_BUILTIN_BSWAP32__#define __HAVE_BUILTIN_BSWAP64__#define __HAVE_BUILTIN_BSWAP16__ -#endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP && !__CHECKER__ */ +#endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP */ #if GCC_VERSION >=70000 #define KASAN_ABI_VERSION 5
_
Andrew Morton
maintainerPATCH 13/178 scripts/spelling.txt: add entries for recent discoveries
In reply to Andrew MortonFrom: Tom Saeger <[email protected]>
Subject: scripts/spelling.txt: add entries for recent discoveries
Add a few entries for recent spelling fixes found.
Opportunistically de-dupe:
exeeds||exceeds
---
scripts/spelling.txt | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-)
scripts/spelling.txt renamed from scripts/spelling.txt~scripts-spellingtxt-add-entries-for-recent-discoveries +25 -1
@@ -84,6 +84,7 @@ againt||against agaist||against aggreataon||aggregation aggreation||aggregation +ajust||adjust albumns||albums alegorical||allegorical algined||aligned
@@ -161,10 +162,13 @@ asign||assign asser||assert assertation||assertion assertting||asserting +assgined||assigned assiged||assigned assigment||assignment assigments||assignments assistent||assistant +assocaited||associated +assocating||associating assocation||association associcated||associated assotiated||associated
@@ -177,9 +181,11 @@ asynchnous||asynchronous asynchromous||asynchronous asymetric||asymmetric asymmeric||asymmetric +atleast||at least atomatically||automatically atomicly||atomically atempt||attempt +atrributes||attributes attachement||attachment attatch||attach attched||attached
@@ -315,6 +321,7 @@ comminucation||communication commited||committed commiting||committing committ||commit +commnunication||communication commoditiy||commodity comsume||consume comsumer||consumer
@@ -349,6 +356,7 @@ condtion||condition conected||connected conector||connector configration||configuration +configred||configured configuartion||configuration configuation||configuration configued||configured
@@ -402,6 +410,7 @@ cunter||counter curently||currently cylic||cyclic dafault||default +deactive||deactivate deafult||default deamon||daemon debouce||debounce
@@ -417,6 +426,7 @@ deffered||deferred defferred||deferred definate||definite definately||definitely +definiation||definition defintion||definition defintions||definitions defualt||default
@@ -571,8 +581,9 @@ errror||error estbalishment||establishment etsablishment||establishment etsbalishment||establishment +evalute||evaluate +evalutes||evaluates evalution||evaluation -exeeds||exceeds excecutable||executable exceded||exceeded exceds||exceeds
@@ -696,6 +707,7 @@ hardare||hardware harware||hardware havind||having heirarchically||hierarchically +heirarchy||hierarchy helpfull||helpful heterogenous||heterogeneous hexdecimal||hexadecimal
@@ -796,6 +808,7 @@ interanl||internal interchangable||interchangeable interferring||interfering interger||integer +intergrated||integrated intermittant||intermittent internel||internal interoprability||interoperability
@@ -808,6 +821,7 @@ interrup||interrupt interrups||interrupts interruptted||interrupted interupted||interrupted +intiailized||initialized intial||initial intialisation||initialisation intialised||initialised
@@ -1091,11 +1105,14 @@ preemptable||preemptible prefered||preferred prefferably||preferably prefitler||prefilter +preform||perform premption||preemption prepaired||prepared preperation||preparation preprare||prepare pressre||pressure +presuambly||presumably +previosuly||previously primative||primitive princliple||principle priorty||priority
@@ -1265,6 +1282,7 @@ scarch||search schdule||schedule seach||search searchs||searches +secion||section secquence||sequence secund||second segement||segment
@@ -1312,6 +1330,8 @@ singed||signed sleeped||slept sliped||slipped softwares||software +soley||solely +souce||source speach||speech specfic||specific specfield||specified
@@ -1320,7 +1340,9 @@ specifc||specific specifed||specified specificatin||specification specificaton||specification +specificed||specified specifing||specifying +specifiy||specify specifiying||specifying speficied||specified speicify||specify
@@ -1436,6 +1458,7 @@ timout||timeout tmis||this toogle||toggle torerable||tolerable +traget||target traking||tracking tramsmitted||transmitted tramsmit||transmit
@@ -1558,6 +1581,7 @@ wiil||will wirte||write withing||within wnat||want +wont||won't workarould||workaround writeing||writing writting||writing
_
Andrew Morton
maintainerPATCH 14/178 scripts: a new script for checking duplicate struct declaration
In reply to Andrew MortonFrom: Wan Jiabing <[email protected]>
Subject: scripts: a new script for checking duplicate struct declaration
checkdeclares: find struct declared more than once. Inspired by checkincludes.pl.
This script checks for duplicate struct declares. Note that this will not take into consideration macros, so you should run this only if you know you do have real dups and do not have them under #ifdef's. You could also just review the results.
---
scripts/checkdeclares.pl | 53 +++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+)
scripts/checkdeclares.pl new file +53 -0
@@ -0,0 +1,53 @@ +#!/usr/bin/env perl +# SPDX-License-Identifier: GPL-2.0 +# +# checkdeclares: find struct declared more than once +# +# Copyright 2021 Wan Jiabing<[email protected]> +# Inspired by checkincludes.pl +# +# This script checks for duplicate struct declares. +# Note that this will not take into consideration macros so +# you should run this only if you know you do have real dups +# and do not have them under #ifdef's. +# You could also just review the results. + +use strict; + +sub usage { + print "Usage: checkdeclares.pl file1.h ...\n"; + print "Warns of struct declaration duplicates\n"; + exit 1; +} + +if ($#ARGV < 0) { + usage(); +} + +my $dup_counter = 0; + +foreach my $file (@ARGV) { + open(my $f, '<', $file) + or die "Cannot open $file: $!.\n"; + + my %declaredstructs = (); + + while (<$f>) { + if (m/^\s*struct\s*(\w*);$/o) { + ++$declaredstructs{$1}; + } + } + + close($f); + + foreach my $structname (keys %declaredstructs) { + if ($declaredstructs{$structname} > 1) { + print "$file: struct $structname is declared more than once.\n"; + ++$dup_counter; + } + } +} + +if ($dup_counter == 0) { + print "No duplicate struct declares found.\n"; +}
_
Andrew Morton
maintainerPATCH 15/178 arch/sh/include/asm/tlb.h: remove duplicate include
In reply to Andrew MortonFrom: Zhang Yunkai <[email protected]>
Subject: arch/sh/include/asm/tlb.h: remove duplicate include
'asm-generic/tlb.h' included in 'asm/tlb.h' is duplicated.
---
arch/sh/include/asm/tlb.h | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
arch/sh/include/asm/tlb.h renamed from arch/sh/include/asm/tlb.h~sh-remove-duplicate-include-in-tlbh +2 -8
@@ -4,12 +4,11 @@#ifndef __ASSEMBLY__#include <linux/pagemap.h> +#include <asm-generic/tlb.h> #ifdef CONFIG_MMU #include <linux/swap.h> -#include <asm-generic/tlb.h> -#if defined(CONFIG_CPU_SH4 )extern void tlb_wire_entry (struct vm_area_struct *,unsigned long ,pte_t );extern void tlb_unwire_entry (void );
@@ -24,12 +23,7 @@ static inline void tlb_unwire_entry(void {BUG (); } -#endif - -#else /* CONFIG_MMU */ - -#include <asm-generic/tlb.h> - +#endif /* CONFIG_CPU_SH4 */ #endif /* CONFIG_MMU */ #endif /* __ASSEMBLY__ */ #endif /* __ASM_SH_TLB_H */
_
Andrew Morton
maintainerPATCH 16/178 ocfs2: replace DEFINE_SIMPLE_ATTRIBUTE with DEFINE_DEBUGFS_ATTRIBUTE
In reply to Andrew MortonFrom: Yang Li <[email protected]>
Subject: ocfs2: replace DEFINE_SIMPLE_ATTRIBUTE with DEFINE_DEBUGFS_ATTRIBUTE
Fix the following coccicheck warning:
./fs/ocfs2/blockcheck.c:232:0-23: WARNING: blockcheck_fops should be defined with DEFINE_DEBUGFS_ATTRIBUTE
---
fs/ocfs2/blockcheck.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ocfs2/blockcheck.c renamed from fs/ocfs2/blockcheck.c~ocfs2-replace-define_simple_attribute-with-define_debugfs_attribute +1 -1
@@ -229,7 +229,7 @@ static int blockcheck_u64_get(void *data *val = *(u64 *)data;return 0 ; } -DEFINE_SIMPLE_ATTRIBUTE (blockcheck_fops, blockcheck_u64_get,NULL ,"%llu\n" ); +DEFINE_DEBUGFS_ATTRIBUTE (blockcheck_fops, blockcheck_u64_get,NULL ,"%llu\n" );static void ocfs2_blockcheck_debug_remove (struct ocfs2_blockcheck_stats *stats) {
_
Andrew Morton
maintainerPATCH 17/178 ocfs2: map flags directly in flags_to_o2dlm()
In reply to Andrew MortonFrom: Joseph Qi <[email protected]>
Subject: ocfs2: map flags directly in flags_to_o2dlm()
Use macro map_flag() is tricky and coccicheck outputs the following warning:
fs/ocfs2/stack_o2cb.c:69:5-16: Unneeded variable: "o2dlm_flags". So map flags directly in flags_to_o2dlm() to make coccicheck happy. And remove BUG_ON() here as well to simplify code since it runs well a long time.
---
fs/ocfs2/stack_o2cb.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-)
fs/ocfs2/stack_o2cb.c renamed from fs/ocfs2/stack_o2cb.c~ocfs2-map-flags-directly-in-flags_to_o2dlm +18 -18
@@ -59,31 +59,31 @@ static inline int mode_to_o2dlm(int modereturn mode; } -#define map_flag (_generic, _o2dlm) \ - if (flags & (_generic)) { \ - flags &= ~(_generic); \ - o2dlm_flags |= (_o2dlm); \ - }static int flags_to_o2dlm (u32 flags) {int o2dlm_flags =0 ; -map_flag (DLM_LKF_NOQUEUE ,LKM_NOQUEUE ); -map_flag (DLM_LKF_CANCEL ,LKM_CANCEL ); -map_flag (DLM_LKF_CONVERT ,LKM_CONVERT ); -map_flag (DLM_LKF_VALBLK ,LKM_VALBLK ); -map_flag (DLM_LKF_IVVALBLK ,LKM_INVVALBLK ); -map_flag (DLM_LKF_ORPHAN ,LKM_ORPHAN ); -map_flag (DLM_LKF_FORCEUNLOCK ,LKM_FORCE ); -map_flag (DLM_LKF_TIMEOUT ,LKM_TIMEOUT ); -map_flag (DLM_LKF_LOCAL ,LKM_LOCAL ); - -/* map_flag() should have cleared every flag passed in */ -BUG_ON (flags !=0 ); +if (flags &DLM_LKF_NOQUEUE ) + o2dlm_flags |=LKM_NOQUEUE ; +if (flags &DLM_LKF_CANCEL ) + o2dlm_flags |=LKM_CANCEL ; +if (flags &DLM_LKF_CONVERT ) + o2dlm_flags |=LKM_CONVERT ; +if (flags &DLM_LKF_VALBLK ) + o2dlm_flags |=LKM_VALBLK ; +if (flags &DLM_LKF_IVVALBLK ) + o2dlm_flags |=LKM_INVVALBLK ; +if (flags &DLM_LKF_ORPHAN ) + o2dlm_flags |=LKM_ORPHAN ; +if (flags &DLM_LKF_FORCEUNLOCK ) + o2dlm_flags |=LKM_FORCE ; +if (flags &DLM_LKF_TIMEOUT ) + o2dlm_flags |=LKM_TIMEOUT ; +if (flags &DLM_LKF_LOCAL ) + o2dlm_flags |=LKM_LOCAL ;return o2dlm_flags; } -#undef map_flag/* * Map an o2dlm status to standard errno values.
_
Andrew Morton
maintainerPATCH 18/178 ocfs2: fix a typo
In reply to Andrew MortonFrom: Bhaskar Chowdhury <[email protected]>
Subject: ocfs2: fix a typo
s/cluter/cluster/
---
fs/ocfs2/stackglue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ocfs2/stackglue.c renamed from fs/ocfs2/stackglue.c~ocfs2-fix-a-typo +1 -1
@@ -731,7 +731,7 @@ static void __exit ocfs2_stack_glue_exit }MODULE_AUTHOR ("Oracle" ); -MODULE_DESCRIPTION ("ocfs2 cluter stack glue layer" ); +MODULE_DESCRIPTION ("ocfs2 cluster stack glue layer" );MODULE_LICENSE ("GPL" );module_init (ocfs2_stack_glue_init);module_exit (ocfs2_stack_glue_exit);
_
Andrew Morton
maintainerPATCH 19/178 ocfs2/dlm: remove unused function
In reply to Andrew MortonFrom: Jiapeng Chong <[email protected]>
Subject: ocfs2/dlm: remove unused function
Fix the following clang warning:
fs/ocfs2/dlm/dlmrecovery.c:129:20: warning: unused function 'dlm_reset_recovery' [-Wunused-function].
---
fs/ocfs2/dlm/dlmrecovery.c | 7 ------- 1 file changed, 7 deletions(-)
fs/ocfs2/dlm/dlmrecovery.c renamed from fs/ocfs2/dlm/dlmrecovery.c~ocfs2-dlm-remove-unused-function +0 -7
@@ -126,13 +126,6 @@ static inline void __dlm_reset_recovery(dlm_set_reco_master (dlm,O2NM_INVALID_NODE_NUM ); } -static inline void dlm_reset_recovery (struct dlm_ctxt *dlm) -{ -spin_lock (&dlm->spinlock); -__dlm_reset_recovery (dlm); -spin_unlock (&dlm->spinlock); -} -/* Worker function used during recovery. */ void dlm_dispatch_work (struct work_struct *work) {
_
Andrew Morton
maintainerPATCH 20/178 kfifo: fix ternary sign extension bugs
In reply to Andrew MortonFrom: Dan Carpenter <[email protected]>
Subject: kfifo: fix ternary sign extension bugs
The intent with this code was to return negative error codes but instead it returns positives.
The problem is how type promotion works with ternary operations. These functions return long, "ret" is an int and "copied" is a u32. The negative error code is first cast to u32 so it becomes a high positive and then cast to long where it's still a positive.
We could fix this by declaring "ret" as a ssize_t but let's just get rid of the ternaries instead.
---
samples/kfifo/bytestream-example.c | 8 ++++++-- samples/kfifo/inttype-example.c | 8 ++++++-- samples/kfifo/record-example.c | 8 ++++++-- 3 files changed, 18 insertions(+), 6 deletions(-)
samples/kfifo/bytestream-example.c renamed from samples/kfifo/bytestream-example.c~kfifo-fix-ternary-sign-extension-bugs +6 -2
@@ -122,8 +122,10 @@ static ssize_t fifo_write(struct file *f ret =kfifo_from_user (&test, buf, count, &copied);mutex_unlock (&write_lock); +if (ret) +return ret; -return ret ? ret : copied; +return copied; } static ssize_t fifo_read(struct file *file, char __user *buf,
@@ -138,8 +140,10 @@ static ssize_t fifo_read(struct file *fi ret =kfifo_to_user (&test, buf, count, &copied);mutex_unlock (&read_lock); +if (ret) +return ret; -return ret ? ret : copied; +return copied; }static const struct proc_ops fifo_proc_ops = {
samples/kfifo/inttype-example.c renamed from samples/kfifo/inttype-example.c~kfifo-fix-ternary-sign-extension-bugs +6 -2
@@ -115,8 +115,10 @@ static ssize_t fifo_write(struct file *f ret =kfifo_from_user (&test, buf, count, &copied);mutex_unlock (&write_lock); +if (ret) +return ret; -return ret ? ret : copied; +return copied; } static ssize_t fifo_read(struct file *file, char __user *buf,
@@ -131,8 +133,10 @@ static ssize_t fifo_read(struct file *fi ret =kfifo_to_user (&test, buf, count, &copied);mutex_unlock (&read_lock); +if (ret) +return ret; -return ret ? ret : copied; +return copied; }static const struct proc_ops fifo_proc_ops = {
samples/kfifo/record-example.c renamed from samples/kfifo/record-example.c~kfifo-fix-ternary-sign-extension-bugs +6 -2
@@ -129,8 +129,10 @@ static ssize_t fifo_write(struct file *f ret =kfifo_from_user (&test, buf, count, &copied);mutex_unlock (&write_lock); +if (ret) +return ret; -return ret ? ret : copied; +return copied; } static ssize_t fifo_read(struct file *file, char __user *buf,
@@ -145,8 +147,10 @@ static ssize_t fifo_read(struct file *fi ret =kfifo_to_user (&test, buf, count, &copied);mutex_unlock (&read_lock); +if (ret) +return ret; -return ret ? ret : copied; +return copied; }static const struct proc_ops fifo_proc_ops = {
_
Andrew Morton
maintainerPATCH 21/178 vfs: fs_parser: clean up kernel-doc warnings
In reply to Andrew MortonFrom: Randy Dunlap <[email protected]>
Subject: vfs: fs_parser: clean up kernel-doc warnings
Fix kernel-doc notation function arguments to eliminate two kernel-doc warnings:
fs_parser.c:322: warning: Excess function parameter 'name' description in 'validate_constant_table' fs_parser.c:367: warning: Function parameter or member 'name' not described in 'fs_validate_description'
---
fs/fs_parser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/fs_parser.c renamed from fs/fs_parser.c~vfs-fs_parser-clean-up-kernel-doc-warnings +1 -1
@@ -310,7 +310,6 @@ EXPORT_SYMBOL(fs_param_is_path);#ifdef CONFIG_VALIDATE_FS_PARSER /** * validate_constant_table - Validate a constant table -* @name: Name to use in reporting * @tbl: The constant table to validate. * @tbl_size: The size of the table. * @low: The lowest permissible value.
@@ -360,6 +359,7 @@ bool validate_constant_table(const struc/** * fs_validate_description - Validate a parameter description +* @name: The parameter name to search for. * @desc: The parameter description to validate. */ bool fs_validate_description(const char *name,
_
Andrew Morton
maintainerPATCH 22/178 watchdog: rename __touch_watchdog() to a better descriptive name
In reply to Andrew MortonFrom: Petr Mladek <[email protected]>
Subject: watchdog: rename __touch_watchdog() to a better descriptive name
Patch series "watchdog/softlockup: Report overall time and some cleanup", v2.
I dug deep into the softlockup watchdog history when time permitted this year. And reworked the patchset that fixed timestamps and cleaned up the code[2].
I split it into very small steps and did even more code clean up. The result looks quite strightforward and I am pretty confident with the changes.
[1] v2: https://lore.kernel.org/r/[email protected]
[2] v1: https://lore.kernel.org/r/[email protected]
This patch (of 6):
There are many touch_*watchdog() functions. They are called in situations where the watchdog could report false positives or create unnecessary noise. For example, when CPU is entering idle mode, a virtual machine is stopped, or a lot of messages are printed in the atomic context.
These functions set SOFTLOCKUP_RESET instead of a real timestamp. It allows to call them even in a context where jiffies might be outdated. For example, in an atomic context.
The real timestamp is set by __touch_watchdog() that is called from the watchdog timer callback.
Rename this callback to update_touch_ts(). It better describes the effect and clearly distinguish is from the other touch_*watchdog() functions.
Another motivation is that two timestamps are going to be used. One will be used for the total softlockup time. The other will be used to measure time since the last report. The new function name will help to distinguish which timestamp is being updated.
---
kernel/watchdog.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
kernel/watchdog.c renamed from kernel/watchdog.c~watchdog-rename-__touch_watchdog-to-a-better-descriptive-name +4 -4
@@ -236,7 +236,7 @@ static void set_sample_period(void) }/* Commands for resetting the watchdog */ -static void __touch_watchdog (void ) +static void update_touch_ts (void ) {__this_cpu_write (watchdog_touch_ts,get_timestamp ()); }
@@ -332,7 +332,7 @@ static DEFINE_PER_CPU(struct cpu_stop_wo*/ static int softlockup_fn (void *data) { -__touch_watchdog (); +update_touch_ts ();complete (this_cpu_ptr (&softlockup_completion));return 0 ;
@@ -375,7 +375,7 @@ static enum hrtimer_restart watchdog_tim/* Clear the guest paused flag on watchdog reset */ kvm_check_and_clear_guest_paused (); -__touch_watchdog (); +update_touch_ts ();return HRTIMER_RESTART ; }
@@ -461,7 +461,7 @@ static void watchdog_enable(unsigned int HRTIMER_MODE_REL_PINNED_HARD);/* Initialize timestamp */ -__touch_watchdog (); +update_touch_ts ();/* Enable the perf event */ if (watchdog_enabled &NMI_WATCHDOG_ENABLED )watchdog_nmi_enable (cpu);
_
Andrew Morton
maintainerPATCH 23/178 watchdog: explicitly update timestamp when reporting softlockup
In reply to Andrew MortonFrom: Petr Mladek <[email protected]>
Subject: watchdog: explicitly update timestamp when reporting softlockup
The softlockup situation might stay for a long time or even forever. When it happens, the softlockup debug messages are printed in regular intervals defined by get_softlockup_thresh().
There is a mystery. The repeated message is printed after the full interval that is defined by get_softlockup_thresh(). But the timer callback is called more often as defined by sample_period. The code looks like the soflockup should get reported in every sample_period when it was once behind the thresh.
It works only by chance. The watchdog is touched when printing the stall report, for example, in printk_stack_address().
Make the behavior clear and predictable by explicitly updating the timestamp in watchdog_timer_fn() when the report gets printed.
---
kernel/watchdog.c | 3 +++ 1 file changed, 3 insertions(+)
kernel/watchdog.c renamed from kernel/watchdog.c~watchdog-explicitly-update-timestamp-when-reporting-softlockup +3 -0
@@ -410,6 +410,9 @@ static enum hrtimer_restart watchdog_tim } } +/* Start period for the next softlockup warning. */ +update_touch_ts (); +pr_emerg ("BUG: soft lockup - CPU#%d stuck for %us! [%s:%d]\n" ,smp_processor_id (), duration, current->comm,task_pid_nr (current));
_
Andrew Morton
maintainerPATCH 24/178 watchdog/softlockup: report the overall time of softlockups
In reply to Andrew MortonFrom: Petr Mladek <[email protected]>
Subject: watchdog/softlockup: report the overall time of softlockups
The softlockup detector currently shows the time spent since the last report. As a result it is not clear whether a CPU is infinitely hogged by a single task or if it is a repeated event.
The situation can be simulated with a simply busy loop:
while (true) cpu_relax();
The softlockup detector produces:
[ 168.277520] watchdog: BUG: soft lockup - CPU#1 stuck for 22s! [cat:4865] [ 196.277604] watchdog: BUG: soft lockup - CPU#1 stuck for 22s! [cat:4865] [ 236.277522] watchdog: BUG: soft lockup - CPU#1 stuck for 23s! [cat:4865]
But it should be, something like:
[ 480.372418] watchdog: BUG: soft lockup - CPU#2 stuck for 26s! [cat:4943] [ 508.372359] watchdog: BUG: soft lockup - CPU#2 stuck for 52s! [cat:4943] [ 548.372359] watchdog: BUG: soft lockup - CPU#2 stuck for 89s! [cat:4943] [ 576.372351] watchdog: BUG: soft lockup - CPU#2 stuck for 115s! [cat:4943]
For the better output, add an additional timestamp of the last report. Only this timestamp is reset when the watchdog is intentionally touched from slow code paths or when printing the report.
---
kernel/watchdog.c | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-)
kernel/watchdog.c renamed from kernel/watchdog.c~watchdog-softlockup-report-the-overall-time-of-softlockups +28 -12
@@ -154,7 +154,11 @@ static void lockup_detector_update_enabl#ifdef CONFIG_SOFTLOCKUP_DETECTOR -#define SOFTLOCKUP_RESET ULONG_MAX +/* +* Delay the soflockup report when running a known slow code. +* It does _not_ affect the timestamp of the last successdul reschedule. +*/ +#define SOFTLOCKUP_DELAY_REPORT ULONG_MAX#ifdef CONFIG_SMP int __read_mostly sysctl_softlockup_all_cpu_backtrace;
@@ -169,7 +173,10 @@ unsigned int __read_mostly softlockup_pastatic bool softlockup_initialized__read_mostly ;static u64 __read_mostly sample_period; +/* Timestamp taken after the last successful reschedule. */ static DEFINE_PER_CPU(unsigned long, watchdog_touch_ts); +/* Timestamp of the last softlockup report. */ +static DEFINE_PER_CPU(unsigned long, watchdog_report_ts); static DEFINE_PER_CPU(struct hrtimer, watchdog_hrtimer); static DEFINE_PER_CPU(bool, softlockup_touch_sync); static DEFINE_PER_CPU(bool, soft_watchdog_warn);
@@ -235,10 +242,16 @@ static void set_sample_period(void)watchdog_update_hrtimer_threshold (sample_period); } +static void update_report_ts (void ) +{ +__this_cpu_write (watchdog_report_ts,get_timestamp ()); +} +/* Commands for resetting the watchdog */ static void update_touch_ts (void ) {__this_cpu_write (watchdog_touch_ts,get_timestamp ()); +update_report_ts (); }/**
@@ -252,10 +265,10 @@ static void update_touch_ts(void) notrace void touch_softlockup_watchdog_sched(void) {/* -* Preemption can be enabled. It doesn't matter which CPU's timestamp -* gets zeroed here, so use the raw_ operation. +* Preemption can be enabled. It doesn't matter which CPU's watchdog +* report period gets restarted here, so use the raw_ operation. */ -raw_cpu_write (watchdog_touch_ts,SOFTLOCKUP_RESET ); +raw_cpu_write (watchdog_report_ts,SOFTLOCKUP_DELAY_REPORT ); } notrace void touch_softlockup_watchdog(void)
@@ -279,7 +292,7 @@ void touch_all_softlockup_watchdogs(void* the softlockup check. */ for_each_cpu (cpu, &watchdog_allowed_mask) { -per_cpu (watchdog_touch_ts, cpu) =SOFTLOCKUP_RESET ; +per_cpu (watchdog_report_ts, cpu) =SOFTLOCKUP_DELAY_REPORT ;wq_watchdog_touch (cpu); } }
@@ -287,16 +300,16 @@ void touch_all_softlockup_watchdogs(voidvoid touch_softlockup_watchdog_sync (void ) {__this_cpu_write (softlockup_touch_sync, true); -__this_cpu_write (watchdog_touch_ts,SOFTLOCKUP_RESET ); +__this_cpu_write (watchdog_report_ts,SOFTLOCKUP_DELAY_REPORT ); } -static int is_softlockup (unsigned long touch_ts) +static int is_softlockup (unsigned long touch_ts,unsigned long period_ts) {unsigned long now =get_timestamp ();if ((watchdog_enabled &SOFT_WATCHDOG_ENABLED ) && watchdog_thresh){/* Warn about unreasonable delays. */ -if (time_after (now, touch_ts +get_softlockup_thresh ())) +if (time_after (now, period_ts +get_softlockup_thresh ()))return now - touch_ts; }return 0 ;
@@ -342,6 +355,7 @@ static int softlockup_fn(void *data)static enum hrtimer_restart watchdog_timer_fn (struct hrtimer *hrtimer) {unsigned long touch_ts =__this_cpu_read (watchdog_touch_ts); +unsigned long period_ts =__this_cpu_read (watchdog_report_ts);struct pt_regs *regs =get_irq_regs ();int duration;int softlockup_all_cpu_backtrace = sysctl_softlockup_all_cpu_backtrace;
@@ -363,7 +377,8 @@ static enum hrtimer_restart watchdog_tim/* .. and repeat */ hrtimer_forward_now (hrtimer,ns_to_ktime (sample_period)); -if (touch_ts ==SOFTLOCKUP_RESET ) { +/* Reset the interval when touched externally by a known slow code. */ +if (period_ts ==SOFTLOCKUP_DELAY_REPORT ) {if (unlikely (__this_cpu_read (softlockup_touch_sync))) {/* * If the time stamp was touched atomically
@@ -375,7 +390,8 @@ static enum hrtimer_restart watchdog_tim/* Clear the guest paused flag on watchdog reset */ kvm_check_and_clear_guest_paused (); -update_touch_ts (); +update_report_ts (); +return HRTIMER_RESTART ; }
@@ -385,7 +401,7 @@ static enum hrtimer_restart watchdog_tim* indicate it is getting cpu time. If it hasn't then * this is a good indication some task is hogging the cpu */ - duration =is_softlockup (touch_ts); + duration =is_softlockup (touch_ts, period_ts);if (unlikely (duration)) {/* * If a virtual machine is stopped by the host it can look to
@@ -411,7 +427,7 @@ static enum hrtimer_restart watchdog_tim }/* Start period for the next softlockup warning. */ -update_touch_ts (); +update_report_ts (); pr_emerg("BUG: soft lockup - CPU#%d stuck for %us! [%s:%d]\n", smp_processor_id(), duration,
_
Andrew Morton
maintainerPATCH 25/178 watchdog/softlockup: remove logic that tried to prevent repeated reports
In reply to Andrew MortonFrom: Petr Mladek <[email protected]>
Subject: watchdog/softlockup: remove logic that tried to prevent repeated reports
The softlockup detector does some gymnastic with the variable soft_watchdog_warn. It was added by the commit 58687acba59266735ad ("lockup_detector: Combine nmi_watchdog and softlockup detector").
The purpose is not completely clear. There are the following clues. They describe the situation how it looked after the above mentioned commit:
1. The variable was checked with a comment "only warn once".
2. The variable was set when softlockup was reported. It was cleared only when the CPU was not longer in the softlockup state.
3. watchdog_touch_ts was not explicitly updated when the softlockup was reported. Without this variable, the report would normally be printed again during every following watchdog_timer_fn() invocation.
The logic has got even more tangled up by the commit ed235875e2ca98 ("kernel/watchdog.c: print traces for all cpus on lockup detection"). After this commit, soft_watchdog_warn is set only when softlockup_all_cpu_backtrace is enabled. But multiple reports from all CPUs are prevented by a new variable soft_lockup_nmi_warn.
Conclusion:
The variable probably never worked as intended. In each case, it has not worked last many years because the softlockup was reported repeatedly after the full period defined by watchdog_thresh.
The reason is that watchdog gets touched in many known slow paths, for example, in printk_stack_address(). This code is called also when printing the softlockup report. It means that the watchdog timestamp gets updated after each report.
Solution:
Simply remove the logic. People want the periodic report anyway.
---
kernel/watchdog.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-)
kernel/watchdog.c renamed from kernel/watchdog.c~watchdog-softlockup-remove-logic-that-tried-to-prevent-repeated-reports +2 -12
@@ -179,7 +179,6 @@ static DEFINE_PER_CPU(unsigned long, wat static DEFINE_PER_CPU(unsigned long, watchdog_report_ts); static DEFINE_PER_CPU(struct hrtimer, watchdog_hrtimer); static DEFINE_PER_CPU(bool, softlockup_touch_sync); -static DEFINE_PER_CPU(bool, soft_watchdog_warn); static DEFINE_PER_CPU(unsigned long, hrtimer_interrupts); static DEFINE_PER_CPU(unsigned long, hrtimer_interrupts_saved);static unsigned long soft_lockup_nmi_warn;
@@ -411,19 +410,12 @@ static enum hrtimer_restart watchdog_timif (kvm_check_and_clear_guest_paused ())return HRTIMER_RESTART ; -/* only warn once */ -if (__this_cpu_read (soft_watchdog_warn) == true) -return HRTIMER_RESTART ; -if (softlockup_all_cpu_backtrace) {/* Prevent multiple soft-lockup reports if one cpu is already * engaged in dumping cpu back traces */ -if (test_and_set_bit (0 , &soft_lockup_nmi_warn)) { -/* Someone else will report us. Let's give up */ -__this_cpu_write (soft_watchdog_warn, true); +if (test_and_set_bit (0 , &soft_lockup_nmi_warn))return HRTIMER_RESTART ; - } }/* Start period for the next softlockup warning. */
@@ -453,9 +445,7 @@ static enum hrtimer_restart watchdog_timadd_taint (TAINT_SOFTLOCKUP ,LOCKDEP_STILL_OK );if (softlockup_panic)panic ("softlockup: hung tasks" ); -__this_cpu_write (soft_watchdog_warn, true); - }else -__this_cpu_write (soft_watchdog_warn, false); + }return HRTIMER_RESTART ; }
_
Andrew Morton
maintainerPATCH 26/178 watchdog: fix barriers when printing backtraces from all CPUs
In reply to Andrew MortonFrom: Petr Mladek <[email protected]>
Subject: watchdog: fix barriers when printing backtraces from all CPUs
Any parallel softlockup reports are skipped when one CPU is already printing backtraces from all CPUs.
The exclusive rights are synchronized using one bit in soft_lockup_nmi_warn. There is also one memory barrier that does not make much sense.
Use two barriers on the right location to prevent mixing two reports.
---
kernel/watchdog.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-)
kernel/watchdog.c renamed from kernel/watchdog.c~watchdog-fix-barriers-when-printing-backtraces-from-all-cpus +6 -11
@@ -410,11 +410,12 @@ static enum hrtimer_restart watchdog_timif (kvm_check_and_clear_guest_paused ())return HRTIMER_RESTART ; +/* +* Prevent multiple soft-lockup reports if one cpu is already +* engaged in dumping all cpu back traces. +*/ if (softlockup_all_cpu_backtrace) { -/* Prevent multiple soft-lockup reports if one cpu is already -* engaged in dumping cpu back traces -*/ -if (test_and_set_bit (0 , &soft_lockup_nmi_warn)) +if (test_and_set_bit_lock (0 , &soft_lockup_nmi_warn))return HRTIMER_RESTART ; }
@@ -432,14 +433,8 @@ static enum hrtimer_restart watchdog_timdump_stack ();if (softlockup_all_cpu_backtrace) { -/* Avoid generating two back traces for current -* given that one is already made above -*/ trigger_allbutself_cpu_backtrace (); - -clear_bit (0 , &soft_lockup_nmi_warn); -/* Barrier to sync with other cpus */ -smp_mb__after_atomic (); +clear_bit_unlock (0 , &soft_lockup_nmi_warn); }add_taint (TAINT_SOFTLOCKUP ,LOCKDEP_STILL_OK );
_
Andrew Morton
maintainerPATCH 27/178 watchdog: cleanup handling of false positives
In reply to Andrew MortonFrom: Petr Mladek <[email protected]>
Subject: watchdog: cleanup handling of false positives
The commit d6ad3e286d2c075 ("softlockup: Add sched_clock_tick() to avoid kernel warning on kgdb resume") introduced touch_softlockup_watchdog_sync().
It solved a problem when the watchdog was touched in an atomic context, the timer callback was proceed right after releasing interrupts, and the local clock has not been updated yet. In this case, sched_clock_tick() was called in watchdog_timer_fn() before updating the timer.
So far so good.
Later the commit 5d1c0f4a80a6df73 ("watchdog: add check for suspended vm in softlockup detector") added two kvm_check_and_clear_guest_paused() calls. They touch the watchdog when the guest has been sleeping.
The code makes my head spin around.
Scenario 1:
+ guest did sleep:
+ PVCLOCK_GUEST_STOPPED is set
+ 1st watchdog_timer_fn() invocation:
+ the watchdog is not touched yet
+ is_softlockup() returns too big delay
+ kvm_check_and_clear_guest_paused():
+ clear PVCLOCK_GUEST_STOPPED
+ call touch_softlockup_watchdog_sync()
+ set SOFTLOCKUP_DELAY_REPORT
+ set softlockup_touch_sync
+ return from the timer callback
+ 2nd watchdog_timer_fn() invocation:
+ call sched_clock_tick() even though it is not needed. The timer callback was invoked again only because the clock has already been updated in the meantime.
+ call kvm_check_and_clear_guest_paused() that does nothing because PVCLOCK_GUEST_STOPPED has been cleared already.
+ call update_report_ts() and return. This is fine. Except that sched_clock_tick() might allow to set it already during the 1st invocation.
Scenario 2:
+ guest did sleep
+ 1st watchdog_timer_fn() invocation
+ same as in 1st scenario
+ guest did sleep again:
+ set PVCLOCK_GUEST_STOPPED again
+ 2nd watchdog_timer_fn() invocation
+ SOFTLOCKUP_DELAY_REPORT is set from 1st invocation
+ call sched_clock_tick()
+ call kvm_check_and_clear_guest_paused()
+ clear PVCLOCK_GUEST_STOPPED
+ call touch_softlockup_watchdog_sync()
+ set SOFTLOCKUP_DELAY_REPORT
+ set softlockup_touch_sync
+ call update_report_ts() (set real timestamp immediately)
+ return from the timer callback
+ 3rd watchdog_timer_fn() invocation
+ timestamp is set from 2nd invocation
+ softlockup_touch_sync is set but not checked because the real timestamp is already set
Make the code more straightforward:
1. Always call kvm_check_and_clear_guest_paused() at the very beginning to handle PVCLOCK_GUEST_STOPPED. It touches the watchdog when the quest did sleep.
2. Handle the situation when the watchdog has been touched (SOFTLOCKUP_DELAY_REPORT is set).
Call sched_clock_tick() when touch_*sync() variant was used. It makes sure that the timestamp will be up to date even when it has been touched in atomic context or quest did sleep.
As a result, kvm_check_and_clear_guest_paused() is called on a single location. And the right timestamp is always set when returning from the timer callback.
---
kernel/watchdog.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-)
kernel/watchdog.c renamed from kernel/watchdog.c~watchdog-cleanup-handling-of-false-positives +8 -12
@@ -376,7 +376,14 @@ static enum hrtimer_restart watchdog_tim/* .. and repeat */ hrtimer_forward_now (hrtimer,ns_to_ktime (sample_period)); -/* Reset the interval when touched externally by a known slow code. */ +/* +* If a virtual machine is stopped by the host it can look to +* the watchdog like a soft lockup. Check to see if the host +* stopped the vm before we process the timestamps. +*/ +kvm_check_and_clear_guest_paused (); + +/* Reset the interval when touched by known problematic code. */ if (period_ts ==SOFTLOCKUP_DELAY_REPORT ) {if (unlikely (__this_cpu_read (softlockup_touch_sync))) {/*
@@ -387,10 +394,7 @@ static enum hrtimer_restart watchdog_timsched_clock_tick (); } -/* Clear the guest paused flag on watchdog reset */ -kvm_check_and_clear_guest_paused ();update_report_ts (); -return HRTIMER_RESTART ; }
@@ -403,14 +407,6 @@ static enum hrtimer_restart watchdog_tim duration =is_softlockup (touch_ts, period_ts);if (unlikely (duration)) {/* -* If a virtual machine is stopped by the host it can look to -* the watchdog like a soft lockup, check to see if the host -* stopped the vm before we issue the warning -*/ -if (kvm_check_and_clear_guest_paused ()) -return HRTIMER_RESTART ; - -/* * Prevent multiple soft-lockup reports if one cpu is already * engaged in dumping all cpu back traces. */
_
Andrew Morton
maintainerPATCH 28/178 mm/slab_common: provide "slab_merge" option for !IS_ENABLED(CONFIG_SLAB_MERGE_DEFAULT) builds
In reply to Andrew MortonFrom: Rafael Aquini <[email protected]>
Subject: mm/slab_common: provide "slab_merge" option for !IS_ENABLED(CONFIG_SLAB_MERGE_DEFAULT) builds
This is a minor addition to the allocator setup options to provide a simple way to on demand enable back cache merging for builds that by default run with CONFIG_SLAB_MERGE_DEFAULT not set.
---
Documentation/admin-guide/kernel-parameters.txt | 7 +++++++ mm/slab_common.c | 8 ++++++++ 2 files changed, 15 insertions(+)
Documentation/admin-guide/kernel-parameters.txt renamed from Documentation/admin-guide/kernel-parameters.txt~mm-slab_common-provide-slab_merge-option-for-is_enabledconfig_slab_merge_default-builds +7 -0
@@ -4996,6 +4996,10 @@ slram= [HW,MTD] + slab_merge [MM] + Enable merging of slabs with similar size when the + kernel is built without CONFIG_SLAB_MERGE_DEFAULT. + slab_nomerge [MM] Disable merging of slabs with similar size. May be necessary if there is some reason to distinguish
@@ -5043,6 +5047,9 @@ lower than slub_max_order. For more information see Documentation/vm/slub.rst. + slub_merge [MM, SLUB] + Same with slab_merge. + slub_nomerge [MM, SLUB] Same with slab_nomerge. This is supported for legacy. See slab_nomerge for more information.
mm/slab_common.c renamed from mm/slab_common.c~mm-slab_common-provide-slab_merge-option-for-is_enabledconfig_slab_merge_default-builds +8 -0
@@ -71,11 +71,19 @@ static int __init setup_slab_nomerge(chareturn 1 ; } +static int __init setup_slab_merge (char *str) +{ + slab_nomerge = false; +return 1 ; +} +#ifdef CONFIG_SLUB __setup_param ("slub_nomerge" , slub_nomerge, setup_slab_nomerge,0 ); +__setup_param ("slub_merge" , slub_merge, setup_slab_merge,0 );#endif __setup ("slab_nomerge" , setup_slab_nomerge); +__setup ("slab_merge" , setup_slab_merge);/* * Determine the size of a slab object
_
Andrew Morton
maintainerPATCH 29/178 mm, slub: enable slub_debug static key when creating cache with explicit debug flags
In reply to Andrew MortonFrom: Vlastimil Babka <[email protected]>
Subject: mm, slub: enable slub_debug static key when creating cache with explicit debug flags
Commit ca0cab65ea2b ("mm, slub: introduce static key for slub_debug()") introduced a static key to optimize the case where no debugging is enabled for any cache. The static key is enabled when slub_debug boot parameter is passed, or CONFIG_SLUB_DEBUG_ON enabled.
However, some caches might be created with one or more debugging flags explicitly passed to kmem_cache_create(), and the commit missed this. Thus the debugging functionality would not be actually performed for these caches unless the static key gets enabled by boot param or config.
This patch fixes it by checking for debugging flags passed to kmem_cache_create() and enabling the static key accordingly.
Note such explicit debugging flags should not be used outside of debugging and testing as they will now enable the static key globally. btrfs_init_cachep() creates a cache with SLAB_RED_ZONE but that's a mistake that's being corrected [1]. rcu_torture_stats() creates a cache with SLAB_STORE_USER, but that is a testing module so it's OK and will start working as intended after this patch.
Also note that in case of backports to kernels before v5.12 that don't have 59450bbc12be ("mm, slab, slub: stop taking cpu hotplug lock"), static_branch_enable_cpuslocked() should be used.
[1] https://lore.kernel.org/linux-btrfs/[email protected]/
---
mm/slub.c | 9 +++++++++ 1 file changed, 9 insertions(+)
mm/slub.c renamed from mm/slub.c~mm-slub-enable-slub_debug-static-key-when-creating-cache-with-explicit-debug-flags +9 -0
@@ -3828,6 +3828,15 @@ static int calculate_sizes(struct kmem_cstatic int kmem_cache_open (struct kmem_cache *s,slab_flags_t flags) { +#ifdef CONFIG_SLUB_DEBUG +/* +* If no slub_debug was enabled globally, the static key is not yet +* enabled by setup_slub_debug(). Enable it if the cache is being +* created with any of the debugging flags passed explicitly. +*/ +if (flags &SLAB_DEBUG_FLAGS ) +static_branch_enable (&slub_debug_enabled); +#endif s->flags =kmem_cache_flags (s->size, flags, s->name);#ifdef CONFIG_SLAB_FREELIST_HARDENED s->random =get_random_long ();
_
Andrew Morton
maintainerPATCH 30/178 kunit: add a KUnit test for SLUB debugging functionality
In reply to Andrew MortonFrom: Oliver Glitta <[email protected]>
Subject: kunit: add a KUnit test for SLUB debugging functionality
SLUB has resiliency_test() function which is hidden behind #ifdef SLUB_RESILIENCY_TEST that is not part of Kconfig, so nobody runs it. KUnit should be a proper replacement for it.
Try changing byte in redzone after allocation and changing pointer to next free node, first byte, 50th byte and redzone byte. Check if validation finds errors.
There are several differences from the original resiliency test: Tests create own caches with known state instead of corrupting shared kmalloc caches.
The corruption of freepointer uses correct offset, the original resiliency test got broken with freepointer changes.
Scratch changing random byte test, because it does not have meaning in this form where we need deterministic results.
Add new option CONFIG_SLUB_KUNIT_TEST in Kconfig.
Add a counter field "errors" to struct kmem_cache to count number of errors detected in cache.
Silence bug report in SLUB test. Add SLAB_SILENT_ERRORS debug flag. Add SLAB_SILENT_ERRORS flag to SLAB_NEVER_MERGE, SLAB_DEBUG_FLAGS, SLAB_FLAGS_PERMITTED macros.
---
include/linux/slab.h | 2 include/linux/slub_def.h | 2 lib/Kconfig.debug | 5 + lib/Makefile | 1 lib/test_slub.c | 124 +++++++++++++++++++++++++++++++++++++ mm/slab.h | 7 +- mm/slab_common.c | 2 mm/slub.c | 64 +++++++++++++------ 8 files changed, 184 insertions(+), 23 deletions(-)
include/linux/slab.h renamed from include/linux/slab.h~kunit-add-a-kunit-test-for-slub-debugging-functionality +2 -0
@@ -25,6 +25,8 @@*/ /* DEBUG: Perform (expensive) checks on alloc/free */ #define SLAB_CONSISTENCY_CHECKS ((slab_flags_t __force)0x00000100U) +/* DEBUG: Silent bug reports */ +#define SLAB_SILENT_ERRORS ((slab_flags_t __force)0x00000200U)/* DEBUG: Red zone objs in a cache */ #define SLAB_RED_ZONE ((slab_flags_t __force)0x00000400U)/* DEBUG: Poison objects */
include/linux/slub_def.h renamed from include/linux/slub_def.h~kunit-add-a-kunit-test-for-slub-debugging-functionality +2 -0
@@ -133,6 +133,8 @@ struct kmem_cache {unsigned int usersize;/* Usercopy region size */ struct kmem_cache_node *node[MAX_NUMNODES ]; + +int errors;/* Number of errors in cache */ };#ifdef CONFIG_SLUB_CPU_PARTIAL
lib/Kconfig.debug renamed from lib/Kconfig.debug~kunit-add-a-kunit-test-for-slub-debugging-functionality +5 -0
@@ -2429,6 +2429,11 @@ config BITS_TEST If unsure, say N. +config SLUB_KUNIT_TEST + tristate "KUnit Test for SLUB cache error detection" if !KUNIT_ALL_TESTS + depends on SLUB_DEBUG && KUNIT + default KUNIT_ALL_TESTS + config TEST_UDELAY tristate "udelay test driver" help
lib/Makefile renamed from lib/Makefile~kunit-add-a-kunit-test-for-slub-debugging-functionality +1 -0
@@ -353,5 +353,6 @@ obj-$(CONFIG_LIST_KUNIT_TEST) += list-te obj-$(CONFIG_LINEAR_RANGES_TEST) += test_linear_ranges.o obj-$(CONFIG_BITS_TEST) += test_bits.o obj-$(CONFIG_CMDLINE_KUNIT_TEST) += cmdline_kunit.o +obj-$(CONFIG_SLUB_KUNIT_TEST) += test_slub.o obj-$(CONFIG_GENERIC_LIB_DEVMEM_IS_ALLOWED) += devmem_is_allowed.o
lib/test_slub.c new file +124 -0
124 lines not on this page · raw message
mm/slab_common.c renamed from mm/slab_common.c~kunit-add-a-kunit-test-for-slub-debugging-functionality +1 -1
@@ -55,7 +55,7 @@ static DECLARE_WORK(slab_caches_to_rcu_d*/ #define SLAB_NEVER_MERGE (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER | \ SLAB_TRACE | SLAB_TYPESAFE_BY_RCU | SLAB_NOLEAKTRACE | \ - SLAB_FAILSLAB | kasan_never_merge()) + SLAB_FAILSLAB | SLAB_SILENT_ERRORS | kasan_never_merge())#define SLAB_MERGE_SAME (SLAB_RECLAIM_ACCOUNT | SLAB_CACHE_DMA | \ SLAB_CACHE_DMA32 | SLAB_ACCOUNT)
mm/slab.h renamed from mm/slab.h~kunit-add-a-kunit-test-for-slub-debugging-functionality +5 -2
@@ -134,7 +134,8 @@ static inline slab_flags_t kmem_cache_fl#define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)#elif defined(CONFIG_SLUB_DEBUG )#define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER | \ - SLAB_TRACE | SLAB_CONSISTENCY_CHECKS) + SLAB_TRACE | SLAB_CONSISTENCY_CHECKS | \ + SLAB_SILENT_ERRORS)#else #define SLAB_DEBUG_FLAGS (0)#endif
@@ -164,7 +165,8 @@ static inline slab_flags_t kmem_cache_fl SLAB_NOLEAKTRACE | \ SLAB_RECLAIM_ACCOUNT | \ SLAB_TEMPORARY | \ - SLAB_ACCOUNT) + SLAB_ACCOUNT | \ + SLAB_SILENT_ERRORS)bool __kmem_cache_empty (struct kmem_cache *);int __kmem_cache_shutdown (struct kmem_cache *);
@@ -215,6 +217,7 @@ DECLARE_STATIC_KEY_TRUE(slub_debug_enablDECLARE_STATIC_KEY_FALSE (slub_debug_enabled);#endif extern void print_tracking (struct kmem_cache *s,void *object); +long validate_slab_cache (struct kmem_cache *s);#else static inline void print_tracking (struct kmem_cache *s,void *object) {
mm/slub.c renamed from mm/slub.c~kunit-add-a-kunit-test-for-slub-debugging-functionality +44 -20
166 lines not on this page · raw message
_
Re: [patch 030/178] kunit: add a KUnit test for SLUB debugging functionality
Quoted 30 lines · Andrew Morton
From: Oliver Glitta <[email protected]>
Subject: kunit: add a KUnit test for SLUB debugging functionalitySLUB has
resiliency_test()function which is hidden behind #ifdefSLUB_RESILIENCY_TESTthat is not part ofKconfig, so nobody runs it. KUnit should be a proper replacement for it.Try changing byte in redzone after allocation and changing pointer to next free node, first byte, 50th byte and redzone byte. Check if validation finds errors.
There are several differences from the original resiliency test: Tests create own caches with known state instead of corrupting shared kmalloc caches.
The corruption of freepointer uses correct offset, the original resiliency test got broken with freepointer changes.
Scratch changing random byte test, because it does not have meaning in this form where we need deterministic results.
Add new option
CONFIG_SLUB_KUNIT_TESTinKconfig.Add a counter field "errors" to struct
kmem_cacheto count number of errors detected in cache.Silence bug report in SLUB test. Add
SLAB_SILENT_ERRORSdebug flag. AddSLAB_SILENT_ERRORSflag toSLAB_NEVER_MERGE,SLAB_DEBUG_FLAGS,SLAB_FLAGS_PERMITTEDmacros.
Quoted 8 lines
Signed-off-by Oliver Glitta <[email protected]>Acked-by Vlastimil Babka <[email protected]>Cc Christoph Lameter <[email protected]>Cc David Rientjes <[email protected]>Cc Joonsoo Kim <[email protected]>Cc Pekka Enberg <[email protected]>Signed-off-by Andrew Morton <[email protected]>
Hi, but this is v3 [1]. Then there was v4 [2] (with a prerequisity [3]) with many changes after feedback with kunit folks, which would be better. We could apply v4 as improvement later but there would be extra churn (even the test .c file is named differently). Merging v4 directly would make more sense.
Anyway "[patch 031/178] slub: remove resiliency_test() function" (which the kunit test replaces) can go either way as that code is dead and broken.
Thanks.
[1] https://lkml.kernel.org/r/[email protected]
[2] https://lore.kernel.org/linux-kselftest/[email protected]/
[3] https://lore.kernel.org/linux-kselftest/[email protected]/
Quoted 407 lines
---
include/linux/slab.h | 2 include/linux/slub_def.h | 2 lib/Kconfig.debug | 5 + lib/Makefile | 1 lib/test_slub.c | 124 +++++++++++++++++++++++++++++++++++++ mm/slab.h | 7 +- mm/slab_common.c | 2 mm/slub.c | 64 +++++++++++++------ 8 files changed, 184 insertions(+), 23 deletions(-)include/linux/slab.h renamed from include/linux/slab.h~kunit-add-a-kunit-test-for-slub-debugging-functionality +2
-0@@ -25,6 +25,8 @@*/ /* DEBUG: Perform (expensive) checks on alloc/free */ #define SLAB_CONSISTENCY_CHECKS ((slab_flags_t __force)0x00000100U) +/* DEBUG: Silent bug reports */ +#define SLAB_SILENT_ERRORS ((slab_flags_t __force)0x00000200U)/* DEBUG: Red zone objs in a cache */ #define SLAB_RED_ZONE ((slab_flags_t __force)0x00000400U)/* DEBUG: Poison objects */ include/linux/slub_def.h renamed from include/linux/slub_def.h~kunit-add-a-kunit-test-for-slub-debugging-functionality +2
-0@@ -133,6 +133,8 @@ struct kmem_cache {unsigned int usersize;/* Usercopy region size */ struct kmem_cache_node *node[MAX_NUMNODES ]; + +int errors;/* Number of errors in cache */ };#ifdef CONFIG_SLUB_CPU_PARTIAL lib/Kconfig.debug renamed from lib/Kconfig.debug~kunit-add-a-kunit-test-for-slub-debugging-functionality +5
-0@@ -2429,6 +2429,11 @@ config BITS_TEST If unsure, say N. +config SLUB_KUNIT_TEST + tristate "KUnit Test for SLUB cache error detection" if !KUNIT_ALL_TESTS + depends on SLUB_DEBUG && KUNIT + default KUNIT_ALL_TESTS + config TEST_UDELAY tristate "udelay test driver" helplib/Makefile renamed from lib/Makefile~kunit-add-a-kunit-test-for-slub-debugging-functionality +1
-0@@ -353,5 +353,6 @@ obj-$(CONFIG_LIST_KUNIT_TEST) += list-te obj-$(CONFIG_LINEAR_RANGES_TEST) += test_linear_ranges.o obj-$(CONFIG_BITS_TEST) += test_bits.o obj-$(CONFIG_CMDLINE_KUNIT_TEST) += cmdline_kunit.o +obj-$(CONFIG_SLUB_KUNIT_TEST) += test_slub.o obj-$(CONFIG_GENERIC_LIB_DEVMEM_IS_ALLOWED) += devmem_is_allowed.olib/test_slub.c new file +124
-0@@ -0,0 +1,124 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <kunit/test.h> +#include <linux/mm.h> +#include <linux/slab.h> +#include <linux/module.h> +#include <linux/kernel.h> +#include "../mm/slab.h" + + +static void test_clobber_zone (struct kunit *test) +{ +struct kmem_cache *s =kmem_cache_create ("TestSlub_RZ_alloc" ,64 ,0 , +SLAB_RED_ZONE |SLAB_SILENT_ERRORS ,NULL ); +u8 *p =kmem_cache_alloc (s,GFP_KERNEL ); + + p[64 ] =0x12 ; + +validate_slab_cache (s); +KUNIT_EXPECT_EQ (test,1 , s->errors); + +kmem_cache_free (s, p); +kmem_cache_destroy (s); +} + +static void test_next_pointer (struct kunit *test) +{ +struct kmem_cache *s =kmem_cache_create ("TestSlub_next_ptr_free" ,64 ,0 , +SLAB_POISON |SLAB_SILENT_ERRORS ,NULL ); +u8 *p =kmem_cache_alloc (s,GFP_KERNEL ); +unsigned long tmp; +unsigned long *ptr_addr; + +kmem_cache_free (s, p); + + ptr_addr = (unsigned long *)(p + s->offset); + tmp = *ptr_addr; + p[s->offset] =0x12 ; + +/* +* Expecting two errors. +* One for the corrupted freechain and the other one for the wrong +* count of objects in use. +*/ +validate_slab_cache (s); +KUNIT_EXPECT_EQ (test,2 , s->errors); + +/* +* Try to repair corrupted freepointer. +* Still expecting one error for the wrong count of objects in use. +*/ + *ptr_addr = tmp; + +validate_slab_cache (s); +KUNIT_EXPECT_EQ (test,1 , s->errors); + +/* +* Previous validation repaired the count of objects in use. +* Now expecting no error. +*/ +validate_slab_cache (s); +KUNIT_EXPECT_EQ (test,0 , s->errors); + +kmem_cache_destroy (s); +} + +static void test_first_word (struct kunit *test) +{ +struct kmem_cache *s =kmem_cache_create ("TestSlub_1th_word_free" ,64 ,0 , +SLAB_POISON |SLAB_SILENT_ERRORS ,NULL ); +u8 *p =kmem_cache_alloc (s,GFP_KERNEL ); + +kmem_cache_free (s, p); + *p =0x78 ; + +validate_slab_cache (s); +KUNIT_EXPECT_EQ (test,1 , s->errors); + +kmem_cache_destroy (s); +} + +static void test_clobber_50th_byte (struct kunit *test) +{ +struct kmem_cache *s =kmem_cache_create ("TestSlub_50th_word_free" ,64 ,0 , +SLAB_POISON |SLAB_SILENT_ERRORS ,NULL ); +u8 *p =kmem_cache_alloc (s,GFP_KERNEL ); + +kmem_cache_free (s, p); + p[50 ] =0x9a ; + +validate_slab_cache (s); +KUNIT_EXPECT_EQ (test,1 , s->errors); +kmem_cache_destroy (s); +} + +static void test_clobber_redzone_free (struct kunit *test) +{ +struct kmem_cache *s =kmem_cache_create ("TestSlub_RZ_free" ,64 ,0 , +SLAB_RED_ZONE |SLAB_SILENT_ERRORS ,NULL ); +u8 *p =kmem_cache_alloc (s,GFP_KERNEL ); + +kmem_cache_free (s, p); + p[64 ] =0xab ; + +validate_slab_cache (s); +KUNIT_EXPECT_EQ (test,1 , s->errors); +kmem_cache_destroy (s); +} + +static struct kunit_case test_cases[] = { +KUNIT_CASE (test_clobber_zone), +KUNIT_CASE (test_next_pointer), +KUNIT_CASE (test_first_word), +KUNIT_CASE (test_clobber_50th_byte), +KUNIT_CASE (test_clobber_redzone_free), + {} +}; + +static struct kunit_suite test_suite = { + .name ="slub_test" , + .test_cases = test_cases, +}; +kunit_test_suite (test_suite); + +MODULE_LICENSE ("GPL" );mm/slab_common.c renamed from mm/slab_common.c~kunit-add-a-kunit-test-for-slub-debugging-functionality +1
-1@@ -55,7 +55,7 @@ static DECLARE_WORK(slab_caches_to_rcu_d*/ #define SLAB_NEVER_MERGE (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER | \ SLAB_TRACE | SLAB_TYPESAFE_BY_RCU | SLAB_NOLEAKTRACE | \ - SLAB_FAILSLAB | kasan_never_merge()) + SLAB_FAILSLAB | SLAB_SILENT_ERRORS | kasan_never_merge())#define SLAB_MERGE_SAME (SLAB_RECLAIM_ACCOUNT | SLAB_CACHE_DMA | \ SLAB_CACHE_DMA32 | SLAB_ACCOUNT)mm/slab.h renamed from mm/slab.h~kunit-add-a-kunit-test-for-slub-debugging-functionality +5
-2@@ -134,7 +134,8 @@ static inline slab_flags_t kmem_cache_fl#define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)#elif defined(CONFIG_SLUB_DEBUG )#define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER | \ - SLAB_TRACE | SLAB_CONSISTENCY_CHECKS) + SLAB_TRACE | SLAB_CONSISTENCY_CHECKS | \ + SLAB_SILENT_ERRORS)#else #define SLAB_DEBUG_FLAGS (0)#endif @@ -164,7 +165,8 @@ static inline slab_flags_t kmem_cache_fl SLAB_NOLEAKTRACE | \ SLAB_RECLAIM_ACCOUNT | \ SLAB_TEMPORARY | \ - SLAB_ACCOUNT) + SLAB_ACCOUNT | \ + SLAB_SILENT_ERRORS)bool __kmem_cache_empty (struct kmem_cache *);int __kmem_cache_shutdown (struct kmem_cache *);@@ -215,6 +217,7 @@ DECLARE_STATIC_KEY_TRUE(slub_debug_enablDECLARE_STATIC_KEY_FALSE (slub_debug_enabled);#endif extern void print_tracking (struct kmem_cache *s,void *object); +long validate_slab_cache (struct kmem_cache *s);#else static inline void print_tracking (struct kmem_cache *s,void *object) {mm/slub.c renamed from mm/slub.c~kunit-add-a-kunit-test-for-slub-debugging-functionality +44
-20@@ -674,14 +674,16 @@ static void slab_bug(struct kmem_cache *static void slab_fix (struct kmem_cache *s,char *fmt, ...) { -struct va_format vaf; -va_list args; - -va_start (args, fmt); - vaf.fmt = fmt; - vaf.va = &args; -pr_err ("FIX %s: %pV\n" , s->name, &vaf); -va_end (args); +if (!(s->flags &SLAB_SILENT_ERRORS )) { +struct va_format vaf; +va_list args; + +va_start (args, fmt); + vaf.fmt = fmt; + vaf.va = &args; +pr_err ("FIX %s: %pV\n" , s->name, &vaf); +va_end (args); + } } static bool freelist_corrupted(struct kmem_cache *s, struct page *page,@@ -740,8 +742,10 @@ static void print_trailer(struct kmem_cavoid object_err (struct kmem_cache *s,struct page *page,u8 *object,char *reason) { -slab_bug (s,"%s" , reason); -print_trailer (s, page, object); +if (!(s->flags &SLAB_SILENT_ERRORS )) { +slab_bug (s,"%s" , reason); +print_trailer (s, page, object); + } } static __printf(3, 4) void slab_err(struct kmem_cache *s, struct page *page,@@ -753,9 +757,11 @@ static __printf(3, 4) void slab_err(struva_start (args, fmt);vsnprintf (buf,sizeof (buf), fmt, args);va_end (args); -slab_bug (s,"%s" , buf); -print_page_info (page); -dump_stack (); +if (!(s->flags &SLAB_SILENT_ERRORS )) { +slab_bug (s,"%s" , buf); +print_page_info (page); +dump_stack (); + } }static void init_object (struct kmem_cache *s,void *object,u8 val)@@ -799,11 +805,13 @@ static int check_bytes_and_report(structwhile (end > fault && end[-1 ] == value) end--; -slab_bug (s,"%s overwritten" , what); -pr_err ("0x%p-0x%p @offset=%tu. First byte 0x%x instead of 0x%x\n" , +if (!(s->flags &SLAB_SILENT_ERRORS )) { +slab_bug (s,"%s overwritten" , what); +pr_err ("0x%p-0x%p @offset=%tu. First byte 0x%x instead of 0x%x\n" , fault, end -1 , fault - addr, fault[0 ], value); -print_trailer (s, page, object); +print_trailer (s, page, object); + }restore_bytes (s, what, value, fault, end);return 0 ;@@ -965,6 +973,7 @@ static int check_slab(struct kmem_cacheif (!PageSlab (page)) {slab_err (s, page,"Not a valid slab page" ); + s->errors +=1 ;return 0 ; }@@ -972,11 +981,13 @@ static int check_slab(struct kmem_cacheif (page->objects > maxobj) {slab_err (s, page,"objects %u > max %u" , page->objects, maxobj); + s->errors +=1 ;return 0 ; }if (page->inuse > page->objects) {slab_err (s, page,"inuse %u > max %u" , page->inuse, page->objects); + s->errors +=1 ;return 0 ; }/* Slab_pad_check fixes things up after itself */ @@ -1009,8 +1020,10 @@ static int on_freelist(struct kmem_cache page->freelist =NULL ; page->inuse = page->objects;slab_fix (s,"Freelist cleared" ); + s->errors +=1 ;return 0 ; } + s->errors +=1 ;break ; } object = fp;@@ -1027,12 +1040,14 @@ static int on_freelist(struct kmem_cache page->objects, max_objects); page->objects = max_objects;slab_fix (s,"Number of objects adjusted." ); + s->errors +=1 ; }if (page->inuse != page->objects - nr) {slab_err (s, page,"Wrong object count. Counter is %d but counted were %d" , page->inuse, page->objects - nr); page->inuse = page->objects - nr;slab_fix (s,"Object count adjusted." ); + s->errors +=1 ; }return search ==NULL ; }@@ -4641,8 +4656,10 @@ static void validate_slab(struct kmem_cau8 val =test_bit (__obj_to_index (s, addr, p), map) ?SLUB_RED_INACTIVE :SLUB_RED_ACTIVE ; -if (!check_object (s, page, p, val)) +if (!check_object (s, page, p, val)) { + s->errors +=1 ;break ; + } }put_map (map); unlock:@@ -4662,9 +4679,11 @@ static int validate_slab_node(struct kmevalidate_slab (s, page); count++; } -if (count != n->nr_partial) +if (count != n->nr_partial) {pr_err ("SLUB %s: %ld partial slabs counted but counter=%ld\n" , s->name, count, n->nr_partial); + s->errors +=1 ; + }if (!(s->flags &SLAB_STORE_USER )) goto out;@@ -4673,20 +4692,23 @@ static int validate_slab_node(struct kmevalidate_slab (s, page); count++; } -if (count !=atomic_long_read (&n->nr_slabs)) +if (count !=atomic_long_read (&n->nr_slabs)) {pr_err ("SLUB: %s %ld slabs counted but counter=%ld\n" , s->name, count,atomic_long_read (&n->nr_slabs)); + s->errors +=1 ; + } out:spin_unlock_irqrestore (&n->list_lock, flags);return count; } -static long validate_slab_cache (struct kmem_cache *s) +long validate_slab_cache (struct kmem_cache *s) {int node;unsigned long count =0 ;struct kmem_cache_node *n; + s->errors =0 ;flush_all (s);for_each_kmem_cache_node (s, node, n)@@ -4694,6 +4716,8 @@ static long validate_slab_cache(struct kreturn count; } +EXPORT_SYMBOL (validate_slab_cache); +/* * Generate lists of code addresses where slabcache objects are allocated * and freed. _
Re: [patch 030/178] kunit: add a KUnit test for SLUB debugging functionality
Quoted 8 lines · Vlastimil Babka
Hi, but this is v3 [1]. Then there was v4 [2] (with a prerequisity [3]) with many changes after feedback with kunit folks, which would be better. We could apply v4 as improvement later but there would be extra churn (even the test .c file is named differently). Merging v4 directly would make more sense.
Anyway "[patch 031/178] slub: remove
resiliency_test()function" (which the kunit test replaces) can go either way as that code is dead and broken.
I've removed patches 30 and 31 from the queue.
Linus
Andrew Morton
maintainerPATCH 31/178 slub: remove resiliency_test() function
In reply to Andrew MortonFrom: Oliver Glitta <[email protected]>
Subject: slub: remove resiliency_test() function
Function resiliency_test() is hidden behind #ifdef SLUB_RESILIENCY_TEST that is not part of Kconfig, so nobody runs it.
This function is replaced with KUnit test for SLUB added by the previous patch "selftests: add a KUnit test for SLUB debugging functionality".
---
mm/slub.c | 64 ---------------------------------------------------- 1 file changed, 64 deletions(-)
mm/slub.c renamed from mm/slub.c~slub-remove-resiliency_test-function +0 -64
@@ -153,9 +153,6 @@ static inline bool kmem_cache_has_cpu_pa* - Variable sizing of the per node arrays */ -/* Enable to test recovery from slab corruption on boot */ -#undef SLUB_RESILIENCY_TEST -/* Enable to log cmpxchg failures */ #undef SLUB_DEBUG_CMPXCHG
@@ -4935,66 +4932,6 @@ static int list_locations(struct kmem_ca }#endif /* CONFIG_SLUB_DEBUG */ -#ifdef SLUB_RESILIENCY_TEST -static void __init resiliency_test (void ) -{ -u8 *p; -int type =KMALLOC_NORMAL ; - -BUILD_BUG_ON (KMALLOC_MIN_SIZE >16 ||KMALLOC_SHIFT_HIGH <10 ); - -pr_err ("SLUB resiliency testing\n" ); -pr_err ("-----------------------\n" ); -pr_err ("A. Corruption after allocation\n" ); - - p =kzalloc (16 ,GFP_KERNEL ); - p[16 ] =0x12 ; -pr_err ("\n1. kmalloc-16: Clobber Redzone/next pointer 0x12->0x%p\n\n" , - p +16 ); - -validate_slab_cache (kmalloc_caches[type][4 ]); - -/* Hmmm... The next two are dangerous */ - p =kzalloc (32 ,GFP_KERNEL ); - p[32 +sizeof (void *)] =0x34 ; -pr_err ("\n2. kmalloc-32: Clobber next pointer/next slab 0x34 -> -0x%p\n" , - p); -pr_err ("If allocated object is overwritten then not detectable\n\n" ); - -validate_slab_cache (kmalloc_caches[type][5 ]); - p =kzalloc (64 ,GFP_KERNEL ); - p +=64 + (get_cycles () &0xff ) *sizeof (void *); - *p =0x56 ; -pr_err ("\n3. kmalloc-64: corrupting random byte 0x56->0x%p\n" , - p); -pr_err ("If allocated object is overwritten then not detectable\n\n" ); -validate_slab_cache (kmalloc_caches[type][6 ]); - -pr_err ("\nB. Corruption after free\n" ); - p =kzalloc (128 ,GFP_KERNEL ); -kfree (p); - *p =0x78 ; -pr_err ("1. kmalloc-128: Clobber first word 0x78->0x%p\n\n" , p); -validate_slab_cache (kmalloc_caches[type][7 ]); - - p =kzalloc (256 ,GFP_KERNEL ); -kfree (p); - p[50 ] =0x9a ; -pr_err ("\n2. kmalloc-256: Clobber 50th byte 0x9a->0x%p\n\n" , p); -validate_slab_cache (kmalloc_caches[type][8 ]); - - p =kzalloc (512 ,GFP_KERNEL ); -kfree (p); - p[512 ] =0xab ; -pr_err ("\n3. kmalloc-512: Clobber redzone 0xab->0x%p\n\n" , p); -validate_slab_cache (kmalloc_caches[type][9 ]); -} -#else -#ifdef CONFIG_SYSFS -static void resiliency_test (void ) {}; -#endif -#endif /* SLUB_RESILIENCY_TEST */ -#ifdef CONFIG_SYSFS enum slab_stat_type { SL_ALL, /* All slabs */
@@ -5843,7 +5780,6 @@ static int __init slab_sysfs_init(void) }mutex_unlock (&slab_mutex); -resiliency_test ();return 0 ; }
_
Andrew Morton
maintainerPATCH 32/178 mm/slub.c: trivial typo fixes
In reply to Andrew MortonFrom: Bhaskar Chowdhury <[email protected]>
Subject: mm/slub.c: trivial typo fixes
s/operatios/operations/
s/Mininum/Minimum/
s/mininum/minimum/ ......two different places.
---
mm/slub.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
mm/slub.c renamed from mm/slub.c~mm-slubc-trivial-typo-fixes +4 -4
@@ -3,7 +3,7 @@* SLUB: A slab allocator that limits cache line use instead of queuing * objects in per cpu and per node lists. * -* The allocator synchronizes using per slab locks or atomic operatios +* The allocator synchronizes using per slab locks or atomic operations * and only uses a centralized lock to manage a pool of partial slabs. * * (C) 2007 SGI, Christoph Lameter
@@ -157,7 +157,7 @@ static inline bool kmem_cache_has_cpu_pa#undef SLUB_DEBUG_CMPXCHG/* -* Mininum number of partial slabs. These will be left on the partial +* Minimum number of partial slabs. These will be left on the partial * lists even if they are empty. kmem_cache_shrink may reclaim them. */ #define MIN_PARTIAL 5
@@ -838,7 +838,7 @@ static int check_bytes_and_report(struct* * A. Free pointer (if we cannot overwrite object on free) * B. Tracking data for SLAB_STORE_USER -* C. Padding to reach required alignment boundary or at mininum +* C. Padding to reach required alignment boundary or at minimum * one word if debugging is on to be able to detect writes * before the word boundary. *
@@ -3434,7 +3434,7 @@ static unsigned int slub_min_objects;* * Higher order allocations also allow the placement of more objects in a * slab and thereby reduce object handling overhead. If the user has -* requested a higher mininum order then we start with that one instead of +* requested a higher minimum order then we start with that one instead of * the smallest order which will fit the object. */ static inline unsigned int slab_order(unsigned int size,
_
Andrew Morton
maintainerPATCH 33/178 mm/kmemleak.c: fix a typo
In reply to Andrew MortonFrom: Bhaskar Chowdhury <[email protected]>
Subject: mm/kmemleak.c: fix a typo
s/interruptable/interruptible/
---
mm/kmemleak.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/kmemleak.c renamed from mm/kmemleak.c~mm-kmemleak-fix-a-typo +1 -1
@@ -1203,7 +1203,7 @@ static void update_refs(struct kmemleak_ }/* -* Memory scanning is a long process and it needs to be interruptable. This +* Memory scanning is a long process and it needs to be interruptible. This * function checks whether such interrupt condition occurred. */ static int scan_should_stop (void )
_
Andrew Morton
maintainerPATCH 34/178 mm/page_owner: record the timestamp of all pages during free
In reply to Andrew MortonFrom: Georgi Djakov <[email protected]>
Subject: mm/page_owner: record the timestamp of all pages during free
Collect the time when each allocation is freed, to help with memory analysis with kdump/ramdump. Add the timestamp also in the page_owner debugfs file and print it in dump_page().
Having another timestamp when we free the page helps for debugging page migration issues. For example both alloc and free timestamps being the same can gave hints that there is an issue with migrating memory, as opposed to a page just being dropped during migration.
---
Documentation/vm/page_owner.rst | 2 +- mm/page_owner.c | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-)
Documentation/vm/page_owner.rst renamed from Documentation/vm/page_owner.rst~mm-page_owner-record-the-timestamp-of-all-pages-during-free +1 -1
@@ -47,7 +47,7 @@ size change due to this facility. text data bss dec hex filename 48800 2445 644 51889 cab1 mm/page_alloc.o - 6574 108 29 6711 1a37 mm/page_owner.o + 6662 108 29 6799 1a8f mm/page_owner.o 1025 8 8 1041 411 mm/page_ext.o Although, roughly, 8 KB code is added in total, page_alloc.o increase by
mm/page_owner.c renamed from mm/page_owner.c~mm-page_owner-record-the-timestamp-of-all-pages-during-free +8 -4
@@ -27,6 +27,7 @@ struct page_owner {depot_stack_handle_t handle;depot_stack_handle_t free_handle;u64 ts_nsec; +u64 free_ts_nsec;pid_t pid; };
@@ -148,6 +149,7 @@ void __reset_page_owner(struct page *pagstruct page_ext *page_ext;depot_stack_handle_t handle =0 ;struct page_owner *page_owner; +u64 free_ts_nsec =local_clock (); handle =save_stack (GFP_NOWAIT | __GFP_NOWARN);
@@ -158,6 +160,7 @@ void __reset_page_owner(struct page *pag__clear_bit (PAGE_EXT_OWNER_ALLOCATED , &page_ext->flags); page_owner =get_page_owner (page_ext); page_owner->free_handle = handle; + page_owner->free_ts_nsec = free_ts_nsec; page_ext =page_ext_next (page_ext); } }
@@ -243,6 +246,7 @@ void __copy_page_owner(struct page *oldp new_page_owner->handle = old_page_owner->handle; new_page_owner->pid = old_page_owner->pid; new_page_owner->ts_nsec = old_page_owner->ts_nsec; + new_page_owner->free_ts_nsec = old_page_owner->ts_nsec;/* * We don't clear the bit on the oldpage as it's going to be freed
@@ -356,10 +360,10 @@ print_page_owner(char __user *buf, size_return -ENOMEM ; ret =snprintf (kbuf, count, -"Page allocated via order %u, mask %#x(%pGg), pid %d, ts %llu ns\n" , +"Page allocated via order %u, mask %#x(%pGg), pid %d, ts %llu ns, free_ts %llu ns\n" , page_owner->order, page_owner->gfp_mask, &page_owner->gfp_mask, page_owner->pid, - page_owner->ts_nsec); + page_owner->ts_nsec, page_owner->free_ts_nsec);if (ret >= count) goto err;
@@ -435,9 +439,9 @@ void __dump_page_owner(struct page *pageelse pr_alert ("page_owner tracks the page as freed\n" ); -pr_alert ("page last allocated via order %u, migratetype %s, gfp_mask %#x(%pGg), pid %d, ts %llu\n" , +pr_alert ("page last allocated via order %u, migratetype %s, gfp_mask %#x(%pGg), pid %d, ts %llu, free_ts %llu\n" , page_owner->order, migratetype_names[mt], gfp_mask, &gfp_mask, - page_owner->pid, page_owner->ts_nsec); + page_owner->pid, page_owner->ts_nsec, page_owner->free_ts_nsec); handle =READ_ONCE (page_owner->handle);if (!handle) {
_
Andrew Morton
maintainerPATCH 35/178 mm, page_owner: remove unused parameter in __set_page_owner_handle
In reply to Andrew MortonFrom: zhongjiang-ali <[email protected]>
Subject: mm, page_owner: remove unused parameter in __set_page_owner_handle
Since commit 5556cfe8d994 ("mm, page_owner: fix off-by-one error in __set_page_owner_handle()") introduced, the parameter 'page' will not used, hence it need to be removed.
---
mm/page_owner.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
mm/page_owner.c renamed from mm/page_owner.c~mm-page_owner-remove-unused-parameter-in-__set_page_owner_handle +5 -5
@@ -165,9 +165,9 @@ void __reset_page_owner(struct page *pag } } -static inline void __set_page_owner_handle (struct page *page, -struct page_ext *page_ext,depot_stack_handle_t handle, -unsigned int order,gfp_t gfp_mask) +static inline void __set_page_owner_handle (struct page_ext *page_ext, +depot_stack_handle_t handle, +unsigned int order,gfp_t gfp_mask) {struct page_owner *page_owner;int i;
@@ -197,7 +197,7 @@ noinline void __set_page_owner(struct pareturn ; handle =save_stack (gfp_mask); -__set_page_owner_handle (page, page_ext, handle, order, gfp_mask); +__set_page_owner_handle (page_ext, handle, order, gfp_mask); }void __set_page_owner_migrate_reason (struct page *page,int reason)
@@ -616,7 +616,7 @@ static void init_pages_in_zone(pg_data_tcontinue ;/* Found early allocated page */ -__set_page_owner_handle (page, page_ext, early_handle, +__set_page_owner_handle (page_ext, early_handle,0 ,0 ); count++; }
_
Andrew Morton
maintainerPATCH 36/178 mm: page_owner: fetch backtrace only for tracked pages
In reply to Andrew MortonFrom: Sergei Trofimovich <[email protected]>
Subject: mm: page_owner: fetch backtrace only for tracked pages
Very minor optimization.
---
mm/page_owner.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
mm/page_owner.c renamed from mm/page_owner.c~mm-page_owner-fetch-backtrace-only-for-tracked-pages +3 -3
@@ -147,15 +147,15 @@ void __reset_page_owner(struct page *pag {int i;struct page_ext *page_ext; -depot_stack_handle_t handle =0 ; +depot_stack_handle_t handle;struct page_owner *page_owner;u64 free_ts_nsec =local_clock (); - handle =save_stack (GFP_NOWAIT | __GFP_NOWARN); - page_ext =lookup_page_ext (page);if (unlikely (!page_ext))return ; + + handle =save_stack (GFP_NOWAIT | __GFP_NOWARN);for (i =0 ; i < (1 << order); i++) {__clear_bit (PAGE_EXT_OWNER_ALLOCATED , &page_ext->flags); page_owner =get_page_owner (page_ext);
_
Andrew Morton
maintainerPATCH 37/178 mm: page_owner: use kstrtobool() to parse bool option
In reply to Andrew MortonFrom: Sergei Trofimovich <[email protected]>
Subject: mm: page_owner: use kstrtobool() to parse bool option
I tried to use page_owner=1 for a while noticed too late it had no effect as opposed to similar init_on_alloc=1 (these work).
Let's make them consistent.
The change decreses binary size slightly:
text data bss dec hex filename
12408 321 17 12746 31ca mm/page_owner.o.before 12320 321 17 12658 3172 mm/page_owner.o.after
---
mm/page_owner.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
mm/page_owner.c renamed from mm/page_owner.c~mm-page_owner-use-kstrtobool-to-parse-bool-option +1 -7
@@ -42,13 +42,7 @@ static void init_early_allocated_pages(vstatic int __init early_page_owner_param (char *buf) { -if (!buf) -return -EINVAL ; - -if (strcmp (buf,"on" ) ==0 ) - page_owner_enabled = true; - -return 0 ; +return kstrtobool (buf, &page_owner_enabled); }early_param ("page_owner" , early_page_owner_param);
_
Andrew Morton
maintainerPATCH 38/178 mm: page_owner: detect page_owner recursion via task_struct
In reply to Andrew MortonFrom: Sergei Trofimovich <[email protected]>
Subject: mm: page_owner: detect page_owner recursion via task_struct
Before the change page_owner recursion was detected via fetching backtrace and inspecting it for current instruction pointer. It has a few problems:
- it is slightly slow as it requires extra backtrace and a linear stack scan of the result
- it is too late to check if backtrace fetching required memory allocation itself (ia64's unwinder requires it).
To simplify recursion tracking let's use page_owner recursion flag in 'struct task_struct'.
The change make page_owner=on work on ia64 by avoiding infinite recursion in:
kmalloc()
-> __set_page_owner()
-> save_stack()
-> unwind() [ia64-specific]
-> build_script()
-> kmalloc()
-> __set_page_owner() [we short-circuit here]
-> save_stack()
-> unwind() [recursion]
---
include/linux/sched.h | 4 ++++ mm/page_owner.c | 32 ++++++++++---------------------- 2 files changed, 14 insertions(+), 22 deletions(-)
include/linux/sched.h renamed from include/linux/sched.h~mm-page_owner-detect-page_owner-recursion-via-task_struct +4 -0
@@ -841,6 +841,10 @@ struct task_struct {/* Stalled due to lack of memory */ unsigned in_memstall:1;#endif +#ifdef CONFIG_PAGE_OWNER +/* Used by page_owner=on to detect recursion in page tracking. */ + unsigned in_page_owner:1; +#endif unsigned long atomic_flags;/* Flags requiring atomic access. */
mm/page_owner.c renamed from mm/page_owner.c~mm-page_owner-detect-page_owner-recursion-via-task_struct +10 -22
@@ -98,42 +98,30 @@ static inline struct page_owner *get_pagreturn (void *)page_ext + page_owner_ops.offset; } -static inline bool check_recursive_alloc (unsigned long *entries, -unsigned int nr_entries, -unsigned long ip) -{ -unsigned int i; - -for (i =0 ; i < nr_entries; i++) { -if (entries[i] == ip) -return true; - } -return false; -} - static noinline depot_stack_handle_t save_stack(gfp_t flags) {unsigned long entries[PAGE_OWNER_STACK_DEPTH ];depot_stack_handle_t handle;unsigned int nr_entries; - nr_entries =stack_trace_save (entries,ARRAY_SIZE (entries),2 ); -/* -* We need to check recursion here because our request to -* stackdepot could trigger memory allocation to save new -* entry. New memory allocation would reach here and call -* stack_depot_save_entries() again if we don't catch it. There is -* still not enough memory in stackdepot so it would try to -* allocate memory again and loop forever. +* Avoid recursion. +* +* Sometimes page metadata allocation tracking requires more +* memory to be allocated: +* - when new stack trace is saved to stack depot +* - when backtrace itself is calculated (ia64) */ -if (check_recursive_alloc (entries, nr_entries, _RET_IP_)) +if (current->in_page_owner)return dummy_handle; + current->in_page_owner =1 ; + nr_entries =stack_trace_save (entries,ARRAY_SIZE (entries),2 ); handle =stack_depot_save (entries, nr_entries, flags);if (!handle) handle = failure_handle; + current->in_page_owner =0 ;return handle; }
_
Andrew Morton
maintainerPATCH 39/178 mm: page_poison: print page info when corruption is caught
In reply to Andrew MortonFrom: Sergei Trofimovich <[email protected]>
Subject: mm: page_poison: print page info when corruption is caught
When page_poison detects page corruption it's useful to see who freed a page recently to have a guess where write-after-free corruption happens.
After this change corruption report has extra page data. Example report from real corruption (includes only page_pwner part):
pagealloc: memory corruption
e00000014cd61d10: 11 00 00 00 00 00 00 00 30 1d d2 ff ff 0f 00 60 ........0......`
e00000014cd61d20: b0 1d d2 ff ff 0f 00 60 90 fe 1c 00 08 00 00 20 .......`.......
...
CPU: 1 PID: 220402 Comm: cc1plus Not tainted 5.12.0-rc5-00107-g9720c6f59ecf #245
Hardware name: hp server rx3600, BIOS 04.03 04/08/2008
...
Call Trace:
[<a000000100015210>] show_stack+0x90/0xc0
[<a000000101163390>] dump_stack+0x150/0x1c0
[<a0000001003f1e90>] __kernel_unpoison_pages+0x410/0x440
[<a0000001003c2460>] get_page_from_freelist+0x1460/0x2ca0
[<a0000001003c6be0>] __alloc_pages_nodemask+0x3c0/0x660
[<a0000001003ed690>] alloc_pages_vma+0xb0/0x500
[<a00000010037deb0>] __handle_mm_fault+0x1230/0x1fe0
[<a00000010037ef70>] handle_mm_fault+0x310/0x4e0
[<a00000010005dc70>] ia64_do_page_fault+0x1f0/0xb80
[<a00000010000ca00>] ia64_leave_kernel+0x0/0x270
page_owner tracks the page as freed
page allocated via order 0, migratetype Movable,
gfp_mask 0x100dca(GFP_HIGHUSER_MOVABLE|__GFP_ZERO), pid 37, ts 8173444098740
__reset_page_owner+0x40/0x200
free_pcp_prepare+0x4d0/0x600
free_unref_page+0x20/0x1c0
__put_page+0x110/0x1a0
migrate_pages+0x16d0/0x1dc0
compact_zone+0xfc0/0x1aa0
proactive_compact_node+0xd0/0x1e0
kcompactd+0x550/0x600
kthread+0x2c0/0x2e0
call_payload+0x50/0x80Here we can see that page was freed by page migration but something managed to write to it afterwards.
---
mm/page_poison.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
mm/page_poison.c renamed from mm/page_poison.c~mm-page_poison-print-page-owner-info-when-corruption-is-caught +4 -2
@@ -2,6 +2,7 @@#include <linux/kernel.h> #include <linux/string.h> #include <linux/mm.h> +#include <linux/mmdebug.h> #include <linux/highmem.h> #include <linux/page_ext.h> #include <linux/poison.h>
@@ -45,7 +46,7 @@ static bool single_bit_flip(unsigned chareturn error && !(error & (error -1 )); } -static void check_poison_mem (unsigned char *mem,size_t bytes) +static void check_poison_mem (struct page *page,unsigned char *mem,size_t bytes) { static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 10);unsigned char *start;
@@ -70,6 +71,7 @@ static void check_poison_mem(unsigned chprint_hex_dump (KERN_ERR ,"" ,DUMP_PREFIX_ADDRESS ,16 ,1 , start, end - start +1 ,1 );dump_stack (); +dump_page (page,"pagealloc: corrupted page details" ); }static void unpoison_page (struct page *page)
@@ -83,7 +85,7 @@ static void unpoison_page(struct page *p* that is freed to buddy. Thus no extra check is done to * see if a page was poisoned. */ -check_poison_mem (kasan_reset_tag (addr),PAGE_SIZE ); +check_poison_mem (page,kasan_reset_tag (addr),PAGE_SIZE );kasan_enable_current ();kunmap_atomic (addr); }
_
Andrew Morton
maintainerPATCH 40/178 mm/memtest: add ARCH_USE_MEMTEST
In reply to Andrew MortonFrom: Anshuman Khandual <[email protected]>
Subject: mm/memtest: add ARCH_USE_MEMTEST
early_memtest() does not get called from all architectures. Hence enabling CONFIG_MEMTEST and providing a valid memtest=[1..N] kernel command line option might not trigger the memory pattern tests as would be expected in normal circumstances. This situation is misleading.
The change here prevents the above mentioned problem after introducing a new config option ARCH_USE_MEMTEST that should be subscribed on platforms that call early_memtest(), in order to enable the config CONFIG_MEMTEST. Conversely CONFIG_MEMTEST cannot be enabled on platforms where it would not be tested anyway.
---
arch/arm/Kconfig | 1 + arch/arm64/Kconfig | 1 + arch/mips/Kconfig | 1 + arch/powerpc/Kconfig | 1 + arch/x86/Kconfig | 1 + arch/xtensa/Kconfig | 1 + lib/Kconfig.debug | 9 ++++++++- 7 files changed, 14 insertions(+), 1 deletion(-)
arch/arm64/Kconfig renamed from arch/arm64/Kconfig~mm-memtest-add-arch_use_memtest +1 -0
@@ -67,6 +67,7 @@ config ARM64 select ARCH_KEEP_MEMBLOCK select ARCH_USE_CMPXCHG_LOCKREF select ARCH_USE_GNU_PROPERTY + select ARCH_USE_MEMTEST select ARCH_USE_QUEUED_RWLOCKS select ARCH_USE_QUEUED_SPINLOCKS select ARCH_USE_SYM_ANNOTATIONS
arch/arm/Kconfig renamed from arch/arm/Kconfig~mm-memtest-add-arch_use_memtest +1 -0
@@ -33,6 +33,7 @@ config ARM select ARCH_SUPPORTS_ATOMIC_RMW select ARCH_USE_BUILTIN_BSWAP select ARCH_USE_CMPXCHG_LOCKREF + select ARCH_USE_MEMTEST select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT if MMU select ARCH_WANT_IPC_PARSE_VERSION select ARCH_WANT_LD_ORPHAN_WARN
arch/mips/Kconfig renamed from arch/mips/Kconfig~mm-memtest-add-arch_use_memtest +1 -0
@@ -16,6 +16,7 @@ config MIPS select ARCH_SUPPORTS_UPROBES select ARCH_USE_BUILTIN_BSWAP select ARCH_USE_CMPXCHG_LOCKREF if 64BIT + select ARCH_USE_MEMTEST select ARCH_USE_QUEUED_RWLOCKS select ARCH_USE_QUEUED_SPINLOCKS select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT if MMU
arch/powerpc/Kconfig renamed from arch/powerpc/Kconfig~mm-memtest-add-arch_use_memtest +1 -0
@@ -149,6 +149,7 @@ config PPC select ARCH_SUPPORTS_DEBUG_PAGEALLOC if PPC32 || PPC_BOOK3S_64 select ARCH_USE_BUILTIN_BSWAP select ARCH_USE_CMPXCHG_LOCKREF if PPC64 + select ARCH_USE_MEMTEST select ARCH_USE_QUEUED_RWLOCKS if PPC_QUEUED_SPINLOCKS select ARCH_USE_QUEUED_SPINLOCKS if PPC_QUEUED_SPINLOCKS select ARCH_WANT_IPC_PARSE_VERSION
arch/x86/Kconfig renamed from arch/x86/Kconfig~mm-memtest-add-arch_use_memtest +1 -0
@@ -100,6 +100,7 @@ config X86 select ARCH_SUPPORTS_LTO_CLANG if X86_64 select ARCH_SUPPORTS_LTO_CLANG_THIN if X86_64 select ARCH_USE_BUILTIN_BSWAP + select ARCH_USE_MEMTEST select ARCH_USE_QUEUED_RWLOCKS select ARCH_USE_QUEUED_SPINLOCKS select ARCH_USE_SYM_ANNOTATIONS
arch/xtensa/Kconfig renamed from arch/xtensa/Kconfig~mm-memtest-add-arch_use_memtest +1 -0
@@ -7,6 +7,7 @@ config XTENSA select ARCH_HAS_SYNC_DMA_FOR_CPU if MMU select ARCH_HAS_SYNC_DMA_FOR_DEVICE if MMU select ARCH_HAS_DMA_SET_UNCACHED if MMU + select ARCH_USE_MEMTEST select ARCH_USE_QUEUED_RWLOCKS select ARCH_USE_QUEUED_SPINLOCKS select ARCH_WANT_FRAME_POINTERS
lib/Kconfig.debug renamed from lib/Kconfig.debug~mm-memtest-add-arch_use_memtest +8 -1
@@ -2578,11 +2578,18 @@ config TEST_FPU endif # RUNTIME_TESTING_MENU +config ARCH_USE_MEMTEST + bool + help + An architecture should select this when it uses early_memtest() + during boot process. + config MEMTEST bool "Memtest" + depends on ARCH_USE_MEMTEST help This option adds a kernel parameter 'memtest', which allows memtest - to be set. + to be set and executed. memtest=0, mean disabled; -- default memtest=1, mean do 1 test pattern; ...
_
Andrew Morton
maintainerPATCH 41/178 mm: provide filemap_range_needs_writeback() helper
In reply to Andrew MortonFrom: Jens Axboe <[email protected]>
Subject: mm: provide filemap_range_needs_writeback() helper
Patch series "Improve IOCB_NOWAIT O_DIRECT reads", v3.
An internal workload complained because it was using too much CPU, and when I took a look, we had a lot of io_uring workers going to town. For an async buffered read like workload, I am normally expecting _zero_ offloads to a worker thread, but this one had tons of them. I'd drop caches and things would look good again, but then a minute later we'd regress back to using workers. Turns out that every minute something was reading parts of the device, which would add page cache for that inode. I put patches like these in for our kernel, and the problem was solved.
Don't -EAGAIN IOCB_NOWAIT dio reads just because we have page cache entries for the given range. This causes unnecessary work from the callers side, when the IO could have been issued totally fine without blocking on writeback when there is none.
This patch (of 3):
For O_DIRECT reads/writes, we check if we need to issue a call to filemap_write_and_wait_range() to issue and/or wait for writeback for any page in the given range. The existing mechanism just checks for a page in the range, which is suboptimal for IOCB_NOWAIT as we'll fallback to the slow path (and needing retry) if there's just a clean page cache page in the range.
Provide filemap_range_needs_writeback() which tries a little harder to check if we actually need to issue and/or wait for writeback in the range.
---
include/linux/fs.h | 2 ++ mm/filemap.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+)
include/linux/fs.h renamed from include/linux/fs.h~mm-provide-filemap_range_needs_writeback-helper +2 -0
@@ -2878,6 +2878,8 @@ static inline int filemap_fdatawait(struextern bool filemap_range_has_page (struct address_space *,loff_t lstart,loff_t lend); +extern bool filemap_range_needs_writeback (struct address_space *, +loff_t lstart,loff_t lend);extern int filemap_write_and_wait_range (struct address_space *mapping,loff_t lstart,loff_t lend); extern int __filemap_fdatawrite_range(struct address_space *mapping,
mm/filemap.c renamed from mm/filemap.c~mm-provide-filemap_range_needs_writeback-helper +43 -0
49 lines not on this page · raw message
_
Re: [patch 041/178] mm: provide filemap_range_needs_writeback() helper
Wait, what?
mm/filemap.c static bool mapping_needs_writeback(stru · line 665
Quoted 8 lines · Andrew Morton
mm/filemap.c renamed from mm/filemap.c~mm-provide-filemap_range_needs_writeback-helper +7
-0+if (!mapping_needs_writeback (mapping)) +return false; +if (!mapping_tagged (mapping,PAGECACHE_TAG_DIRTY ) && + !mapping_tagged (mapping,PAGECACHE_TAG_WRITEBACK )) +return false; +if (end_byte < start_byte) +return false;
Ok, good, get rid of the trivial cases first.
mm/filemap.c static bool mapping_needs_writeback(stru · line 676
Quoted 10 lines
mm/filemap.c renamed from mm/filemap.c~mm-provide-filemap_range_needs_writeback-helper +10
-0+rcu_read_lock (); +xas_for_each (&xas, page, max) { +if (xas_retry (&xas, page)) +continue ; +if (xa_is_value (page)) +continue ; +if (PageDirty (page) ||PageLocked (page) ||PageWriteback (page)) +break ; + } +rcu_read_unlock ();
Whee. This looks very very expensive indeed.
Why is is going to each page, why does it care about locked when the simple early cases did not?
Why isn't this just using xas_for_each_marked(), or maybe even just a single "xa_find()", since all it cares about is "is _any_ page.."
Maybe I'm missing something, but this really does look potentially horrendously slow.
Jens/Willy?
Linus
Matthew Wilcox
maintainerRe: [patch 041/178] mm: provide filemap_range_needs_writeback() helper
Quoted 26 lines · Linus Torvalds
Wait, what?
mm/filemap.c static bool mapping_needs_writeback(stru · line 665
Quoted 8 lines · Andrew Morton
mm/filemap.c renamed from mm/filemap.c~mm-provide-filemap_range_needs_writeback-helper +7
-0+if (!mapping_needs_writeback (mapping)) +return false; +if (!mapping_tagged (mapping,PAGECACHE_TAG_DIRTY ) && + !mapping_tagged (mapping,PAGECACHE_TAG_WRITEBACK )) +return false; +if (end_byte < start_byte) +return false;Ok, good, get rid of the trivial cases first.
mm/filemap.c static bool mapping_needs_writeback(stru · line 676
Quoted 10 lines
mm/filemap.c renamed from mm/filemap.c~mm-provide-filemap_range_needs_writeback-helper +10
-0+rcu_read_lock (); +xas_for_each (&xas, page, max) { +if (xas_retry (&xas, page)) +continue ; +if (xa_is_value (page)) +continue ; +if (PageDirty (page) ||PageLocked (page) ||PageWriteback (page)) +break ; + } +rcu_read_unlock ();
Quoted 4 lines
Whee. This looks very very expensive indeed.
Why is is going to each page, why does it care about locked when the simple early cases did not?
I was hoping Jens would answer this, but I guess he missed it so far. I don't know why it now cares about whether the page is locked or not. I presume it's not even the slightest bit slow for Jens because the common case is that there are no pages in the range, and so we never check any pages.
Quoted 2 lines
Why isn't this just using
xas_for_each_marked(), or maybe even just a single "xa_find()", since all it cares about is "is _any_ page.."
We don't have an iterator that looks for either mark A or mark B, so we'd have to iterate twice, once to look for dirty and once to look for writeback. For the common case of there being no pages in the range, that'd be slower.
I could add an iterator that returns the next entry in the given range that has any mark set (almost trivial; OR the mark bitmaps together before scanning them). But I don't know why we care about the Locked case, so I don't know if it'd be the right thing to do.
xa_find() isn't quite right because that'll return shadow entries, and we do want to skip those.
Matthew Wilcox
maintainerRe: [patch 041/178] mm: provide filemap_range_needs_writeback() helper
Quoted 16 lines · Matthew Wilcox
Quoted 15 lines · Linus Torvalds
Review
Quoted 10 lines · Andrew Morton
(quoted diff) +10
-0+ rcu_read_lock(); + xas_for_each(&xas, page, max) { + if (xas_retry(&xas, page)) + continue; + if (xa_is_value(page)) + continue; + if (PageDirty(page) || PageLocked(page) || PageWriteback(page)) + break; + } + rcu_read_unlock();Whee. This looks very very expensive indeed.
Quoted 8 lines
Quoted 2 lines
Why is is going to each page, why does it care about locked when the simple early cases did not?
I was hoping Jens would answer this, but I guess he missed it so far. I don't know why it now cares about whether the page is locked or not. I presume it's not even the slightest bit slow for Jens because the common case is that there are no pages in the range, and so we never check any pages.
Looking at this again, since the change to operate on folios, we're now living dangerously as we don't have a reference on the folio, so it can now be freed, turned into a tail page and trigger the VM_BUG_ON_PGFLAGS() in folio_flags().
Rather than take a refcount on the folio to prevent that from happening, we can just examine the pagecache flags in the XArray. like this. Assuming there really isn't a need to check the locked flag (which for obvious reasons we don't mirror into the xarray marks).
Jens, WDYT?
mm/filemap.c +2 -4
@@ -640,10 +640,8 @@ bool filemap_range_has_writeback(struct address_space *mapping,xas_for_each (&xas, folio, max) {if (xas_retry (&xas, folio))continue ; -if (xa_is_value (folio)) -continue ; -if (folio_test_dirty (folio) ||folio_test_locked (folio) || -folio_test_writeback (folio)) +if (xas_get_mark (&xas,PAGECACHE_TAG_DIRTY ) || +xas_get_mark (&xas,PAGECACHE_TAG_WRITEBACK ))break ; }rcu_read_unlock ();
Jens Axboe
maintainerRe: [patch 041/178] mm: provide filemap_range_needs_writeback() helper
Quoted 45 lines · Matthew Wilcox
Quoted 16 lines · Matthew Wilcox
Quoted 15 lines · Linus Torvalds
Review
Quoted 10 lines · Andrew Morton
(quoted diff) +10
-0+ rcu_read_lock(); + xas_for_each(&xas, page, max) { + if (xas_retry(&xas, page)) + continue; + if (xa_is_value(page)) + continue; + if (PageDirty(page) || PageLocked(page) || PageWriteback(page)) + break; + } + rcu_read_unlock();Whee. This looks very very expensive indeed.
Quoted 8 lines
Quoted 2 lines
Why is is going to each page, why does it care about locked when the simple early cases did not?
I was hoping Jens would answer this, but I guess he missed it so far. I don't know why it now cares about whether the page is locked or not. I presume it's not even the slightest bit slow for Jens because the common case is that there are no pages in the range, and so we never check any pages.
Looking at this again, since the change to operate on folios, we're now living dangerously as we don't have a reference on the folio, so it can now be freed, turned into a tail page and trigger the
VM_BUG_ON_PGFLAGS()infolio_flags().Rather than take a refcount on the folio to prevent that from happening, we can just examine the pagecache flags in the XArray. like this. Assuming there really isn't a need to check the locked flag (which for obvious reasons we don't mirror into the xarray marks).
Jens, WDYT?
mm/filemap.c +0
-0@@ -640,10 +640,8 @@ bool filemap_range_has_writeback(struct address_space *mapping,xas_for_each (&xas, folio, max) {if (xas_retry (&xas, folio))
mm/filemap.c bool filemap_range_has_writeback(struct address_space *mapping, · line 647
Quoted 10 lines
mm/filemap.c +2
-4continue ; -if (xa_is_value (folio)) -continue ; -if (folio_test_dirty (folio) ||folio_test_locked (folio) || -folio_test_writeback (folio)) +if (xas_get_mark (&xas,PAGECACHE_TAG_DIRTY ) || +xas_get_mark (&xas,PAGECACHE_TAG_WRITEBACK ))break ; }rcu_read_unlock ();
Blast from the past, guess I did miss it back then. This looks a lot more reasonable to me, also in terms of overhead, compared to the previous one.
Heading out for the rest of the week tomorrow morning, but I can give it a test spin as well once I'm back.
Signature · 1 line
Jens Axboe
Jan Kara
maintainerRe: [patch 041/178] mm: provide filemap_range_needs_writeback() helper
In reply to Matthew WilcoxQuoted 45 lines · Matthew Wilcox
Quoted 16 lines · Matthew Wilcox
Quoted 15 lines · Linus Torvalds
Review
Quoted 10 lines · Andrew Morton
(quoted diff) +10
-0+ rcu_read_lock(); + xas_for_each(&xas, page, max) { + if (xas_retry(&xas, page)) + continue; + if (xa_is_value(page)) + continue; + if (PageDirty(page) || PageLocked(page) || PageWriteback(page)) + break; + } + rcu_read_unlock();Whee. This looks very very expensive indeed.
Quoted 8 lines
Quoted 2 lines
Why is is going to each page, why does it care about locked when the simple early cases did not?
I was hoping Jens would answer this, but I guess he missed it so far. I don't know why it now cares about whether the page is locked or not. I presume it's not even the slightest bit slow for Jens because the common case is that there are no pages in the range, and so we never check any pages.
Looking at this again, since the change to operate on folios, we're now living dangerously as we don't have a reference on the folio, so it can now be freed, turned into a tail page and trigger the
VM_BUG_ON_PGFLAGS()infolio_flags().Rather than take a refcount on the folio to prevent that from happening, we can just examine the pagecache flags in the XArray. like this. Assuming there really isn't a need to check the locked flag (which for obvious reasons we don't mirror into the xarray marks).
Jens, WDYT?
mm/filemap.c +0
-0@@ -640,10 +640,8 @@ bool filemap_range_has_writeback(struct address_space *mapping,xas_for_each (&xas, folio, max) {if (xas_retry (&xas, folio))
mm/filemap.c bool filemap_range_has_writeback(struct address_space *mapping, · line 647
Quoted 10 lines
mm/filemap.c +2
-4continue ; -if (xa_is_value (folio)) -continue ; -if (folio_test_dirty (folio) ||folio_test_locked (folio) || -folio_test_writeback (folio)) +if (xas_get_mark (&xas,PAGECACHE_TAG_DIRTY ) || +xas_get_mark (&xas,PAGECACHE_TAG_WRITEBACK ))break ; }rcu_read_unlock ();
This looks good but it relies on a subtle detail in our writeback handling that we set the PAGECACHE_TAG_WRITEBACK tag in __folio_start_writeback() and only after that clear the PAGECACHE_TAG_DIRTY there (although we've cleared the page dirty bit much earlier in clear_page_dirty_for_io()). So please add a comment to filemap_range_has_writeback() and to __folio_start_writeback() about this to at least somewhat reduce the chances somebody is going to change the code and break this... Thanks!
Honza
Quoted 1 line
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Andrew Morton
maintainerPATCH 42/178 mm: use filemap_range_needs_writeback() for O_DIRECT reads
In reply to Andrew MortonFrom: Jens Axboe <[email protected]>
Subject: mm: use filemap_range_needs_writeback() for O_DIRECT reads
For the generic page cache read helper, use the better variant of checking for the need to call filemap_write_and_wait_range() when doing O_DIRECT reads. This avoids falling back to the slow path for IOCB_NOWAIT, if there are no pages to wait for (or write out).
---
mm/filemap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
mm/filemap.c renamed from mm/filemap.c~mm-use-filemap_range_needs_writeback-for-o_direct-reads +2 -2
@@ -2681,8 +2681,8 @@ generic_file_read_iter(struct kiocb *ioc size =i_size_read (inode);if (iocb->ki_flags &IOCB_NOWAIT ) { -if (filemap_range_has_page (mapping, iocb->ki_pos, - iocb->ki_pos + count -1 )) +if (filemap_range_needs_writeback (mapping, iocb->ki_pos, + iocb->ki_pos + count -1 ))return -EAGAIN ; }else { retval = filemap_write_and_wait_range(mapping,
_
Andrew Morton
maintainerPATCH 43/178 iomap: use filemap_range_needs_writeback() for O_DIRECT reads
In reply to Andrew MortonFrom: Jens Axboe <[email protected]>
Subject: iomap: use filemap_range_needs_writeback() for O_DIRECT reads
For reads, use the better variant of checking for the need to call filemap_write_and_wait_range() when doing O_DIRECT. This avoids falling back to the slow path for IOCB_NOWAIT, if there are no pages to wait for (or write out).
---
fs/iomap/direct-io.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-)
fs/iomap/direct-io.c renamed from fs/iomap/direct-io.c~iomap-use-filemap_range_needs_writeback-for-o_direct-reads +16 -8
@@ -487,12 +487,28 @@ __iomap_dio_rw(struct kiocb *iocb, strucif (pos >= dio->i_size) goto out_free_dio; +if (iocb->ki_flags &IOCB_NOWAIT ) { +if (filemap_range_needs_writeback (mapping, pos, end)) { + ret = -EAGAIN ; + goto out_free_dio; + } + iomap_flags |=IOMAP_NOWAIT ; + } +if (iter_is_iovec (iter)) dio->flags |=IOMAP_DIO_DIRTY ; }else { iomap_flags |=IOMAP_WRITE ; dio->flags |=IOMAP_DIO_WRITE ; +if (iocb->ki_flags &IOCB_NOWAIT ) { +if (filemap_range_has_page (mapping, pos, end)) { + ret = -EAGAIN ; + goto out_free_dio; + } + iomap_flags |=IOMAP_NOWAIT ; + } +/* for data sync or sync, we need sync completion processing */ if (iocb->ki_flags &IOCB_DSYNC ) dio->flags |=IOMAP_DIO_NEED_SYNC ;
@@ -507,14 +523,6 @@ __iomap_dio_rw(struct kiocb *iocb, struc dio->flags |=IOMAP_DIO_WRITE_FUA ; } -if (iocb->ki_flags &IOCB_NOWAIT ) { -if (filemap_range_has_page (mapping, pos, end)) { - ret = -EAGAIN ; - goto out_free_dio; - } - iomap_flags |=IOMAP_NOWAIT ; - } -if (dio_flags &IOMAP_DIO_OVERWRITE_ONLY ) { ret = -EAGAIN ;if (pos >= dio->i_size || pos + count > dio->i_size)
_
Andrew Morton
maintainerPATCH 44/178 mm/filemap: use filemap_read_page in filemap_fault
In reply to Andrew MortonFrom: "Matthew Wilcox (Oracle)" <[email protected]>
Subject: mm/filemap: use filemap_read_page in filemap_fault
After splitting generic_file_buffered_read() into smaller parts, it turns out we can reuse one of the parts in filemap_fault(). This fixes an oversight -- waiting for the I/O to complete is now interruptible by a fatal signal. And it saves us a few bytes of text in an unlikely path.
$ ./scripts/bloat-o-meter before.o after.o add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-207 (-207) Function old new delta filemap_fault 2187 1980 -207 Total: Before=37491, After=37284, chg -0.55%
---
mm/filemap.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)
mm/filemap.c renamed from mm/filemap.c~mm-filemap-use-filemap_read_page-in-filemap_fault +1 -9
@@ -2980,7 +2980,6 @@ vm_fault_t filemap_fault(struct vm_faultstruct file *file = vmf->vma->vm_file;struct file *fpin =NULL ;struct address_space *mapping = file->f_mapping; -struct file_ra_state *ra = &file->f_ra;struct inode *inode = mapping->host;pgoff_t offset = vmf->pgoff;pgoff_t max_off;
@@ -3067,14 +3066,8 @@ page_not_uptodate:* because there really aren't any performance issues here * and we need to check for errors. */ -ClearPageError (page); fpin =maybe_unlock_mmap_for_io (vmf, fpin); - error = mapping->a_ops->readpage (file, page); -if (!error) { -wait_on_page_locked (page); -if (!PageUptodate (page)) - error = -EIO ; - } + error =filemap_read_page (file, mapping, page);if (fpin) goto out_retry;put_page (page);
@@ -3082,7 +3075,6 @@ page_not_uptodate:if (!error || error ==AOP_TRUNCATED_PAGE ) goto retry_find; -shrink_readahead_size_eio (ra);return VM_FAULT_SIGBUS ; out_retry:
_
Andrew Morton
maintainerPATCH 45/178 mm/filemap: drop check for truncated page after I/O
In reply to Andrew MortonFrom: "Matthew Wilcox (Oracle)" <[email protected]>
Subject: mm/filemap: drop check for truncated page after I/O
If the I/O completed successfully, the page will remain Uptodate, even if it is subsequently truncated. If the I/O completed with an error, this check would cause us to retry the I/O if the page were truncated before we woke up. There is no need to retry the I/O; the I/O to fill the page failed, so we can legitimately just return -EIO.
This code was originally added by commit 56f0d5fe6851 ("[PATCH] readpage-vs-invalidate fix") in 2005 (this commit ID is from the linux-fullhistory tree; it is also commit ba1f08f14b52 in tglx-history).
At the time, truncate_complete_page() called ClearPageUptodate(), and so this was fixing a real bug. In 2008, commit 84209e02de48 ("mm: dont clear PG_uptodate on truncate/invalidate") removed the call to ClearPageUptodate, and this check has been unnecessary ever since.
It doesn't do any real harm, but there's no need to keep it.
---
mm/filemap.c | 2 -- 1 file changed, 2 deletions(-)
mm/filemap.c renamed from mm/filemap.c~mm-filemap-drop-check-for-truncated-page-after-i-o +0 -2
@@ -2348,8 +2348,6 @@ static int filemap_read_page(struct filereturn error;if (PageUptodate (page))return 0 ; -if (!page->mapping)/* page truncated */ -return AOP_TRUNCATED_PAGE ;shrink_readahead_size_eio (&file->f_ra);return -EIO ; }
_
Andrew Morton
maintainerPATCH 46/178 mm: page-writeback: simplify memcg handling in test_clear_page_writeback()
In reply to Andrew MortonFrom: Johannes Weiner <[email protected]>
Subject: mm: page-writeback: simplify memcg handling in test_clear_page_writeback()
Page writeback doesn't hold a page reference, which allows truncate to free a page the second PageWriteback is cleared. This used to require special attention in test_clear_page_writeback(), where we had to be careful not to rely on the unstable page->memcg binding and look up all the necessary information before clearing the writeback flag.
Since commit 073861ed77b6 ("mm: fix VM_BUG_ON(PageTail) and BUG_ON(PageWriteback)") test_clear_page_writeback() is called with an explicit reference on the page, and this dance is no longer needed.
Use unlock_page_memcg() and dec_lruvec_page_state() directly.
This removes the last user of the lock_page_memcg() return value, change it to void. Touch up the comments in there as well. This also removes the last extern user of __unlock_page_memcg(), make it static. Further, it removes the last user of dec_lruvec_state(), delete it, along with a few other unused helpers.
---
include/linux/memcontrol.h | 10 +-------- include/linux/vmstat.h | 24 ++--------------------- mm/memcontrol.c | 36 ++++++++++------------------------- mm/page-writeback.c | 9 ++------ 4 files changed, 19 insertions(+), 60 deletions(-)
include/linux/memcontrol.h renamed from include/linux/memcontrol.h~mm-page-writeback-simplify-memcg-handling-in-test_clear_page_writeback +2 -8
@@ -867,8 +867,7 @@ void mem_cgroup_print_oom_group(struct mextern bool cgroup_memory_noswap;#endif -struct mem_cgroup *lock_page_memcg (struct page *page); -void __unlock_page_memcg (struct mem_cgroup *memcg); +void lock_page_memcg (struct page *page);void unlock_page_memcg (struct page *page);/*
@@ -1289,12 +1288,7 @@ mem_cgroup_print_oom_meminfo(struct mem_ { } -static inline struct mem_cgroup *lock_page_memcg (struct page *page) -{ -return NULL ; -} - -static inline void __unlock_page_memcg (struct mem_cgroup *memcg) +static inline void lock_page_memcg (struct page *page) { }
include/linux/vmstat.h renamed from include/linux/vmstat.h~mm-page-writeback-simplify-memcg-handling-in-test_clear_page_writeback +3 -21
@@ -512,16 +512,10 @@ static inline void mod_lruvec_page_state#endif /* CONFIG_MEMCG */ -static inline void __inc_lruvec_state (struct lruvec *lruvec, -enum node_stat_item idx) -{ -__mod_lruvec_state (lruvec, idx,1 ); -} - -static inline void __dec_lruvec_state (struct lruvec *lruvec, -enum node_stat_item idx) +static inline void inc_lruvec_state (struct lruvec *lruvec, +enum node_stat_item idx) { -__mod_lruvec_state (lruvec, idx,-1 ); +mod_lruvec_state (lruvec, idx,1 ); } static inline void __inc_lruvec_page_state(struct page *page,
@@ -536,18 +530,6 @@ static inline void __dec_lruvec_page_sta__mod_lruvec_page_state (page, idx,-1 ); } -static inline void inc_lruvec_state (struct lruvec *lruvec, -enum node_stat_item idx) -{ -mod_lruvec_state (lruvec, idx,1 ); -} - -static inline void dec_lruvec_state (struct lruvec *lruvec, -enum node_stat_item idx) -{ -mod_lruvec_state (lruvec, idx,-1 ); -} -static inline void inc_lruvec_page_state (struct page *page,enum node_stat_item idx) {
mm/memcontrol.c renamed from mm/memcontrol.c~mm-page-writeback-simplify-memcg-handling-in-test_clear_page_writeback +11 -25
@@ -2118,11 +2118,10 @@ void mem_cgroup_print_oom_group(struct m* This function protects unlocked LRU pages from being moved to * another cgroup. * -* It ensures lifetime of the returned memcg. Caller is responsible -* for the lifetime of the page; __unlock_page_memcg() is available -* when @page might get freed inside the locked section. +* It ensures lifetime of the locked memcg. Caller is responsible +* for the lifetime of the page. */ -struct mem_cgroup *lock_page_memcg (struct page *page) +void lock_page_memcg (struct page *page) {struct page *head =compound_head (page);/* rmap on tail pages */ struct mem_cgroup *memcg;
@@ -2132,21 +2131,15 @@ struct mem_cgroup *lock_page_memcg(struc* The RCU lock is held throughout the transaction. The fast * path can get away without acquiring the memcg->move_lock * because page moving starts with an RCU grace period. -* -* The RCU lock also protects the memcg from being freed when -* the page state that is going to change is the only thing -* preventing the page itself from being freed. E.g. writeback -* doesn't hold a page reference and relies on PG_writeback to -* keep off truncation, migration and so forth. */ rcu_read_lock ();if (mem_cgroup_disabled ()) -return NULL ; +return ; again: memcg =page_memcg (head);if (unlikely (!memcg)) -return NULL ; +return ;#ifdef CONFIG_PROVE_LOCKING local_irq_save (flags);
@@ -2155,7 +2148,7 @@ again:#endif if (atomic_read (&memcg->moving_account) <=0 ) -return memcg; +return ;spin_lock_irqsave (&memcg->move_lock, flags);if (memcg !=page_memcg (head)) {
@@ -2164,24 +2157,17 @@ again: }/* -* When charge migration first begins, we can have locked and -* unlocked page stat updates happening concurrently. Track -* the task who has the lock for unlock_page_memcg(). +* When charge migration first begins, we can have multiple +* critical sections holding the fast-path RCU lock and one +* holding the slowpath move_lock. Track the task who has the +* move_lock for unlock_page_memcg(). */ memcg->move_lock_task = current; memcg->move_lock_flags = flags; - -return memcg; }EXPORT_SYMBOL (lock_page_memcg); -/** -* __unlock_page_memcg - unlock and unpin a memcg -* @memcg: the memcg -* -* Unlock and unpin a memcg returned by lock_page_memcg(). -*/ -void __unlock_page_memcg (struct mem_cgroup *memcg) +static void __unlock_page_memcg (struct mem_cgroup *memcg) {if (memcg && memcg->move_lock_task == current) {unsigned long flags = memcg->move_lock_flags;
mm/page-writeback.c renamed from mm/page-writeback.c~mm-page-writeback-simplify-memcg-handling-in-test_clear_page_writeback +3 -6
@@ -2722,12 +2722,9 @@ EXPORT_SYMBOL(clear_page_dirty_for_io);int test_clear_page_writeback (struct page *page) {struct address_space *mapping =page_mapping (page); -struct mem_cgroup *memcg; -struct lruvec *lruvec;int ret; - memcg =lock_page_memcg (page); - lruvec =mem_cgroup_page_lruvec (page,page_pgdat (page)); +lock_page_memcg (page);if (mapping &&mapping_use_writeback_tags (mapping)) {struct inode *inode = mapping->host;struct backing_dev_info *bdi =inode_to_bdi (inode);
@@ -2755,11 +2752,11 @@ int test_clear_page_writeback(struct pag ret =TestClearPageWriteback (page); }if (ret) { -dec_lruvec_state (lruvec,NR_WRITEBACK ); +dec_lruvec_page_state (page,NR_WRITEBACK );dec_zone_page_state (page,NR_ZONE_WRITE_PENDING );inc_node_page_state (page,NR_WRITTEN ); } -__unlock_page_memcg (memcg); +unlock_page_memcg (page);return ret; }
_
Andrew Morton
maintainerPATCH 47/178 mm: move page_mapping_file to pagemap.h
In reply to Andrew MortonFrom: "Matthew Wilcox (Oracle)" <[email protected]>
Subject: mm: move page_mapping_file to pagemap.h
page_mapping_file() is only used by some architectures, and then it is usually only used in one place. Make it a static inline function so other architectures don't have to carry this dead code.
---
arch/arm/mm/copypage-v4mc.c | 1 + arch/arm/mm/copypage-v6.c | 1 + arch/arm/mm/copypage-xscale.c | 1 + arch/csky/abiv1/cacheflush.c | 1 + arch/mips/mm/cache.c | 1 + arch/nios2/mm/cacheflush.c | 1 + arch/sh/mm/cache-sh4.c | 1 + arch/sh/mm/cache-sh7705.c | 1 + arch/sparc/mm/tlb.c | 1 + include/linux/mm.h | 1 - include/linux/pagemap.h | 10 ++++++++++ mm/util.c | 10 ---------- 12 files changed, 19 insertions(+), 11 deletions(-)
arch/arm/mm/copypage-v4mc.c renamed from arch/arm/mm/copypage-v4mc.c~mm-move-page_mapping_file-to-pagemaph +1 -0
@@ -13,6 +13,7 @@#include <linux/init.h> #include <linux/mm.h> #include <linux/highmem.h> +#include <linux/pagemap.h> #include <asm/tlbflush.h> #include <asm/cacheflush.h>
arch/arm/mm/copypage-v6.c renamed from arch/arm/mm/copypage-v6.c~mm-move-page_mapping_file-to-pagemaph +1 -0
@@ -8,6 +8,7 @@#include <linux/spinlock.h> #include <linux/mm.h> #include <linux/highmem.h> +#include <linux/pagemap.h> #include <asm/shmparam.h> #include <asm/tlbflush.h>
arch/arm/mm/copypage-xscale.c renamed from arch/arm/mm/copypage-xscale.c~mm-move-page_mapping_file-to-pagemaph +1 -0
@@ -13,6 +13,7 @@#include <linux/init.h> #include <linux/mm.h> #include <linux/highmem.h> +#include <linux/pagemap.h> #include <asm/tlbflush.h> #include <asm/cacheflush.h>
arch/csky/abiv1/cacheflush.c renamed from arch/csky/abiv1/cacheflush.c~mm-move-page_mapping_file-to-pagemaph +1 -0
@@ -4,6 +4,7 @@#include <linux/kernel.h> #include <linux/mm.h> #include <linux/fs.h> +#include <linux/pagemap.h> #include <linux/syscalls.h> #include <linux/spinlock.h> #include <asm/page.h>
arch/mips/mm/cache.c renamed from arch/mips/mm/cache.c~mm-move-page_mapping_file-to-pagemaph +1 -0
@@ -15,6 +15,7 @@#include <linux/syscalls.h> #include <linux/mm.h> #include <linux/highmem.h> +#include <linux/pagemap.h> #include <asm/cacheflush.h> #include <asm/processor.h>
arch/nios2/mm/cacheflush.c renamed from arch/nios2/mm/cacheflush.c~mm-move-page_mapping_file-to-pagemaph +1 -0
@@ -11,6 +11,7 @@#include <linux/sched.h> #include <linux/mm.h> #include <linux/fs.h> +#include <linux/pagemap.h> #include <asm/cacheflush.h> #include <asm/cpuinfo.h>
arch/sh/mm/cache-sh4.c renamed from arch/sh/mm/cache-sh4.c~mm-move-page_mapping_file-to-pagemaph +1 -0
@@ -16,6 +16,7 @@#include <linux/mutex.h> #include <linux/fs.h> #include <linux/highmem.h> +#include <linux/pagemap.h> #include <asm/mmu_context.h> #include <asm/cache_insns.h> #include <asm/cacheflush.h>
arch/sh/mm/cache-sh7705.c renamed from arch/sh/mm/cache-sh7705.c~mm-move-page_mapping_file-to-pagemaph +1 -0
@@ -13,6 +13,7 @@#include <linux/mman.h> #include <linux/mm.h> #include <linux/fs.h> +#include <linux/pagemap.h> #include <linux/threads.h> #include <asm/addrspace.h> #include <asm/page.h>
arch/sparc/mm/tlb.c renamed from arch/sparc/mm/tlb.c~mm-move-page_mapping_file-to-pagemaph +1 -0
@@ -9,6 +9,7 @@#include <linux/mm.h> #include <linux/swap.h> #include <linux/preempt.h> +#include <linux/pagemap.h> #include <asm/tlbflush.h> #include <asm/cacheflush.h>
include/linux/mm.h renamed from include/linux/mm.h~mm-move-page_mapping_file-to-pagemaph +0 -1
@@ -1629,7 +1629,6 @@ static inline pgoff_t page_index(structbool page_mapped (struct page *page);struct address_space *page_mapping (struct page *page); -struct address_space *page_mapping_file (struct page *page);/* * Return true only if the page has been allocated with
include/linux/pagemap.h renamed from include/linux/pagemap.h~mm-move-page_mapping_file-to-pagemaph +10 -0
@@ -158,6 +158,16 @@ static inline void filemap_nr_thps_dec(svoid release_pages (struct page **pages,int nr);/* +* For file cache pages, return the address_space, otherwise return NULL +*/ +static inline struct address_space *page_mapping_file (struct page *page) +{ +if (unlikely (PageSwapCache (page))) +return NULL ; +return page_mapping (page); +} + +/* * speculatively take a reference to a page. * If the page is free (_refcount == 0), then _refcount is untouched, and 0 * is returned. Otherwise, _refcount is incremented by 1 and 1 is returned.
mm/util.c renamed from mm/util.c~mm-move-page_mapping_file-to-pagemaph +0 -10
@@ -711,16 +711,6 @@ struct address_space *page_mapping(struc }EXPORT_SYMBOL (page_mapping); -/* -* For file cache pages, return the address_space, otherwise return NULL -*/ -struct address_space *page_mapping_file (struct page *page) -{ -if (unlikely (PageSwapCache (page))) -return NULL ; -return page_mapping (page); -} -/* Slow path of page_mapcount() for compound pages */ int __page_mapcount (struct page *page) {
_
Andrew Morton
maintainerPATCH 48/178 mm/filemap: update stale comment
In reply to Andrew MortonFrom: Rui Sun <[email protected]>
Subject: mm/filemap: update stale comment
Commit a6de4b4873e1 ("mm: convert find_get_entry to return the head page") uses @index instead of @offset, but the comment is stale, update it.
---
mm/filemap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/filemap.c renamed from mm/filemap.c~mm-filemap-update-stale-comment +1 -1
@@ -1767,7 +1767,7 @@ EXPORT_SYMBOL(page_cache_prev_miss);* @mapping: the address_space to search * @index: The page cache index. * -* Looks up the page cache slot at @mapping & @offset. If there is a +* Looks up the page cache slot at @mapping & @index. If there is a * page cache page, the head page is returned with an increased refcount. * * If the slot holds a shadow entry of a previously evicted page, or a
_
Andrew Morton
maintainerPATCH 49/178 mm/msync: exit early when the flags is an MS_ASYNC and start < vm_start
In reply to Andrew MortonFrom: Nikita Ermakov <[email protected]>
Subject: mm/msync: exit early when the flags is an MS_ASYNC and start < vm_start
If an unmapped region was found and the flag is MS_ASYNC (without MS_INVALIDATE) there is nothing to do and the result would be always -ENOMEM, so return immediately.
---
mm/msync.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
mm/msync.c renamed from mm/msync.c~mm-msync-exit-early-when-the-flags-is-an-ms_async-and-start-vm_start +5 -1
@@ -55,7 +55,9 @@ SYSCALL_DEFINE3(msync, unsigned long, st goto out;/* * If the interval [start,end) covers some unmapped address ranges, -* just ignore them, but return -ENOMEM at the end. +* just ignore them, but return -ENOMEM at the end. Besides, if the +* flag is MS_ASYNC (w/o MS_INVALIDATE) the result would be -ENOMEM +* anyway and there is nothing left to do, so return immediately. */ mmap_read_lock (mm); vma =find_vma (mm, start);
@@ -69,6 +71,8 @@ SYSCALL_DEFINE3(msync, unsigned long, st goto out_unlock;/* Here start < vma->vm_end. */ if (start < vma->vm_start) { +if (flags ==MS_ASYNC ) + goto out_unlock; start = vma->vm_start;if (start >= end) goto out_unlock;
_
Andrew Morton
maintainerPATCH 50/178 mm/gup: add compound page list iterator
In reply to Andrew MortonFrom: Joao Martins <[email protected]>
Subject: mm/gup: add compound page list iterator
Patch series "mm/gup: page unpining improvements", v4.
This series improves page unpinning, with an eye on improving MR deregistration for big swaths of memory (which is bound by the page unpining), particularly:
1) Decrement the head page by @ntails and thus reducing a lot the number of atomic operations per compound page. This is done by comparing individual tail pages heads, and counting number of consecutive tails on which they match heads and based on that update head page refcount. Should have a visible improvement in all page (un)pinners which use compound pages
2) Introducing a new API for unpinning page ranges (to avoid the trick in the previous item and be based on math), and use that in RDMA ib_mem_release (used for mr deregistration).
Performance improvements: unpin_user_pages() for hugetlbfs and THP improves ~3x (through gup_test) and RDMA MR dereg improves ~4.5x with the new API. See patches 2 and 4 for those.
This patch (of 4):
Add a helper that iterates over head pages in a list of pages. It essentially counts the tails until the next page to process has a different head that the current. This is going to be used by unpin_user_pages() family of functions, to batch the head page refcount updates once for all passed consecutive tail pages.
---
mm/gup.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
mm/gup.c renamed from mm/gup.c~mm-gup-add-compound-page-list-iterator +26 -0
@@ -213,6 +213,32 @@ void unpin_user_page(struct page *page) }EXPORT_SYMBOL (unpin_user_page); +static inline void compound_next (unsigned long i,unsigned long npages, +struct page **list,struct page **head, +unsigned int *ntails) +{ +struct page *page; +unsigned int nr; + +if (i >= npages) +return ; + + page =compound_head (list[i]); +for (nr = i +1 ; nr < npages; nr++) { +if (compound_head (list[nr]) != page) +break ; + } + + *head = page; + *ntails = nr - i; +} + +#define for_each_compound_head (__i, __list, __npages, __head, __ntails) \ + for (__i = 0, \ + compound_next(__i, __npages, __list, &(__head), &(__ntails)); \ + __i < __npages; __i += __ntails, \ + compound_next(__i, __npages, __list, &(__head), &(__ntails))) +/** * unpin_user_pages_dirty_lock() - release and optionally dirty gup-pinned pages * @pages: array of pages to be maybe marked dirty, and definitely released.
_
Andrew Morton
maintainerPATCH 51/178 mm/gup: decrement head page once for group of subpages
In reply to Andrew MortonFrom: Joao Martins <[email protected]>
Subject: mm/gup: decrement head page once for group of subpages
Rather than decrementing the head page refcount one by one, we walk the page array and checking which belong to the same compound_head. Later on we decrement the calculated amount of references in a single write to the head page. To that end switch to for_each_compound_head() does most of the work.
set_page_dirty() needs no adjustment as it's a nop for non-dirty head pages and it doesn't operate on tail pages.
This considerably improves unpinning of pages with THP and hugetlbfs:
- THPgup_test -t -m 16384 -r 10 [-L|-a] -S -n 512 -w PIN_LONGTERM_BENCHMARK (put values): ~87.6k us -> ~23.2k us
- 16G with 1G huge page sizegup_test -f /mnt/huge/file -m 16384 -r 10 [-L|-a] -S -n 512 -wPIN_LONGTERM_BENCHMARK: (put values): ~87.6k us -> ~27.5k us
---
mm/gup.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-)
mm/gup.c renamed from mm/gup.c~mm-gup-decrement-head-page-once-for-group-of-subpages +11 -18
@@ -265,20 +265,15 @@ void unpin_user_pages_dirty_lock(struct bool make_dirty) {unsigned long index; - -/* -* TODO: this can be optimized for huge pages: if a series of pages is -* physically contiguous and part of the same compound page, then a -* single operation to the head page should suffice. -*/ +struct page *head; +unsigned int ntails;if (!make_dirty) {unpin_user_pages (pages, npages);return ; } -for (index =0 ; index < npages; index++) { -struct page *page =compound_head (pages[index]); +for_each_compound_head (index, pages, npages, head, ntails) {/* * Checking PageDirty at this point may race with * clear_page_dirty_for_io(), but that's OK. Two key
@@ -299,9 +294,9 @@ void unpin_user_pages_dirty_lock(struct* written back, so it gets written back again in the * next writeback cycle. This is harmless. */ -if (!PageDirty (page)) -set_page_dirty_lock (page); -unpin_user_page (page); +if (!PageDirty (head)) +set_page_dirty_lock (head); +put_compound_head (head, ntails,FOLL_PIN ); } }EXPORT_SYMBOL (unpin_user_pages_dirty_lock);
@@ -318,6 +313,8 @@ EXPORT_SYMBOL(unpin_user_pages_dirty_locvoid unpin_user_pages (struct page **pages,unsigned long npages) {unsigned long index; +struct page *head; +unsigned int ntails;/* * If this WARN_ON() fires, then the system *might* be leaking pages (by
@@ -326,13 +323,9 @@ void unpin_user_pages(struct page **page*/ if (WARN_ON (IS_ERR_VALUE (npages)))return ; -/* -* TODO: this can be optimized for huge pages: if a series of pages is -* physically contiguous and part of the same compound page, then a -* single operation to the head page should suffice. -*/ -for (index =0 ; index < npages; index++) -unpin_user_page (pages[index]); + +for_each_compound_head (index, pages, npages, head, ntails) +put_compound_head (head, ntails,FOLL_PIN ); }EXPORT_SYMBOL (unpin_user_pages);
_
Andrew Morton
maintainerPATCH 52/178 mm/gup: add a range variant of unpin_user_pages_dirty_lock()
In reply to Andrew MortonFrom: Joao Martins <[email protected]>
Subject: mm/gup: add a range variant of unpin_user_pages_dirty_lock()
Add an unpin_user_page_range_dirty_lock() API which takes a starting page and how many consecutive pages we want to unpin and optionally dirty.
To that end, define another iterator for_each_compound_range() that operates in page ranges as opposed to page array.
For users (like RDMA mr_dereg) where each sg represents a contiguous set of pages, we're able to more efficiently unpin pages without having to supply an array of pages much of what happens today with unpin_user_pages().
---
include/linux/mm.h | 2 + mm/gup.c | 62 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+)
include/linux/mm.h renamed from include/linux/mm.h~mm-gup-add-a-range-variant-of-unpin_user_pages_dirty_lock +2 -0
@@ -1265,6 +1265,8 @@ static inline void put_page(struct pagevoid unpin_user_page (struct page *page);void unpin_user_pages_dirty_lock (struct page **pages,unsigned long npages,bool make_dirty); +void unpin_user_page_range_dirty_lock (struct page *page,unsigned long npages, +bool make_dirty);void unpin_user_pages (struct page **pages,unsigned long npages);/**
mm/gup.c renamed from mm/gup.c~mm-gup-add-a-range-variant-of-unpin_user_pages_dirty_lock +62 -0
74 lines not on this page · raw message
_
Andrew Morton
maintainerPATCH 53/178 RDMA/umem: batch page unpin in __ib_umem_release()
In reply to Andrew MortonFrom: Joao Martins <[email protected]>
Subject: RDMA/umem: batch page unpin in __ib_umem_release()
Use the newly added unpin_user_page_range_dirty_lock() for more quickly unpinning a consecutive range of pages represented as compound pages. This will also calculate number of pages to unpin (for the tail pages which matching head page) and thus batch the refcount update.
Running a test program which calls memory range reg/unreg on a region 1G in size and measures cost of both operations together (in a guest using rxe) with THP and hugetlbfs:
Before:
590 rounds in 5.003 sec: 8480.335 usec / round
6898 rounds in 60.001 sec: 8698.367 usec / round
After:
2688 rounds in 5.002 sec: 1860.786 usec / round
32517 rounds in 60.001 sec: 1845.225 usec / round
---
drivers/infiniband/core/umem.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/infiniband/core/umem.c renamed from drivers/infiniband/core/umem.c~rdma-umem-batch-page-unpin-in-__ib_umem_release +6 -6
@@ -47,17 +47,17 @@static void __ib_umem_release (struct ib_device *dev,struct ib_umem *umem,int dirty) { -struct sg_page_iter sg_iter; -struct page *page; +bool make_dirty = umem->writable && dirty; +struct scatterlist *sg; +unsigned int i;if (umem->nmap >0 )ib_dma_unmap_sg (dev, umem->sg_head.sgl, umem->sg_nents,DMA_BIDIRECTIONAL ); -for_each_sg_page (umem->sg_head.sgl, &sg_iter, umem->sg_nents,0 ) { - page =sg_page_iter_page (&sg_iter); -unpin_user_pages_dirty_lock (&page,1 , umem->writable && dirty); - } +for_each_sg (umem->sg_head.sgl, sg, umem->sg_nents, i) +unpin_user_page_range_dirty_lock (sg_page (sg), +DIV_ROUND_UP (sg->length,PAGE_SIZE ), make_dirty);sg_free_table (&umem->sg_head); }
_
Andrew Morton
maintainerPATCH 54/178 mm: gup: remove FOLL_SPLIT
In reply to Andrew MortonFrom: Yang Shi <[email protected]>
Subject: mm: gup: remove FOLL_SPLIT
Since commit 5a52c9df62b4 ("uprobe: use FOLL_SPLIT_PMD instead of FOLL_SPLIT") and commit ba925fa35057 ("s390/gmap: improve THP splitting") FOLL_SPLIT has not been used anymore. Remove the dead code.
---
Documentation/vm/transhuge.rst | 5 ----- include/linux/mm.h | 1 - mm/gup.c | 28 ++-------------------------- 3 files changed, 2 insertions(+), 32 deletions(-)
Documentation/vm/transhuge.rst renamed from Documentation/vm/transhuge.rst~mm-gup-remove-foll_split +0 -5
@@ -53,11 +53,6 @@ prevent the page from being split by any of handling GUP on hugetlbfs will also work fine on transparent hugepage backed mappings. -In case you can't handle compound pages if they're returned by -follow_page, the FOLL_SPLIT bit can be specified as a parameter to -follow_page, so that it will split the hugepages before returning -them. - Graceful fallback =================
include/linux/mm.h renamed from include/linux/mm.h~mm-gup-remove-foll_split +0 -1
@@ -2791,7 +2791,6 @@ struct page *follow_page(struct vm_area_#define FOLL_NOWAIT 0x20/* if a disk transfer is needed, start the IO * and return without waiting upon it */ #define FOLL_POPULATE 0x40/* fault in page */ -#define FOLL_SPLIT 0x80/* don't return transhuge pages, split them */ #define FOLL_HWPOISON 0x100/* check page is hwpoisoned */ #define FOLL_NUMA 0x200/* force NUMA hinting page fault */ #define FOLL_MIGRATION 0x400/* wait for page to replace migration entry */
mm/gup.c renamed from mm/gup.c~mm-gup-remove-foll_split +2 -26
@@ -516,18 +516,6 @@ retry: } } -if (flags &FOLL_SPLIT &&PageTransCompound (page)) { -get_page (page); -pte_unmap_unlock (ptep, ptl); -lock_page (page); - ret =split_huge_page (page); -unlock_page (page); -put_page (page); -if (ret) -return ERR_PTR (ret); - goto retry; - } -/* try_grab_page() does nothing unless FOLL_GET or FOLL_PIN is set. */ if (unlikely (!try_grab_page (page, flags))) { page =ERR_PTR (-ENOMEM );
@@ -672,7 +660,7 @@ retry_locked:spin_unlock (ptl);return follow_page_pte (vma, address, pmd, flags, &ctx->pgmap); } -if (flags & (FOLL_SPLIT |FOLL_SPLIT_PMD )) { +if (flags &FOLL_SPLIT_PMD ) {int ret; page =pmd_page (*pmd);if (is_huge_zero_page (page)) {
@@ -681,19 +669,7 @@ retry_locked:split_huge_pmd (vma, pmd, address);if (pmd_trans_unstable (pmd)) ret = -EBUSY ; - }else if (flags &FOLL_SPLIT ) { -if (unlikely (!try_get_page (page))) { -spin_unlock (ptl); -return ERR_PTR (-ENOMEM ); - } -spin_unlock (ptl); -lock_page (page); - ret =split_huge_page (page); -unlock_page (page); -put_page (page); -if (pmd_none (*pmd)) -return no_page_table (vma, flags); - }else {/* flags & FOLL_SPLIT_PMD */ + }else {spin_unlock (ptl);split_huge_pmd (vma, pmd, address); ret =pte_alloc (mm, pmd) ? -ENOMEM :0 ;
_
Andrew Morton
maintainerPATCH 55/178 mm/memremap.c: fix improper SPDX comment style
In reply to Andrew MortonFrom: Zhiyuan Dai <[email protected]>
Subject: mm/memremap.c: fix improper SPDX comment style
Replace /* */ comment with //, fix SPDX comment style.
see: Documentation/process/license-rules.rst
---
mm/memremap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/memremap.c renamed from mm/memremap.c~mm-memremap-fixes-improper-spdx-comment-style +1 -1
@@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +// SPDX-License-Identifier: GPL-2.0 /* Copyright(c) 2015 Intel Corporation. All rights reserved. */ #include <linux/device.h> #include <linux/io.h>
_
Andrew Morton
maintainerPATCH 56/178 mm: memcontrol: fix kernel stack account
In reply to Andrew MortonFrom: Muchun Song <[email protected]>
Subject: mm: memcontrol: fix kernel stack account
For simplification 991e7673859e ("mm: memcontrol: account kernel stack per node") has changed the per zone vmalloc backed stack pages accounting to per node. By doing that we have lost a certain precision because those pages might live in different NUMA nodes. In the end NR_KERNEL_STACK_KB exported to the userspace might be over estimated on some nodes while underestimated on others. But this is not a real world problem, just a problem found by reading the code. So there is no actual data to showing how much impact it has on users.
This doesn't impose any real problem to correctnes of the kernel behavior as the counter is not used for any internal processing but it can cause some confusion to the userspace.
Address the problem by accounting each vmalloc backing page to its own node.
---
kernel/fork.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
kernel/fork.c renamed from kernel/fork.c~mm-memcontrol-fix-kernel-stack-account +8 -5
@@ -380,14 +380,17 @@ static void account_kernel_stack(structvoid *stack =task_stack_page (tsk);struct vm_struct *vm =task_stack_vm_area (tsk); +if (vm) { +int i; -/* All stack pages are in the same node. */ -if (vm) -mod_lruvec_page_state (vm->pages[0 ],NR_KERNEL_STACK_KB , - account * (THREAD_SIZE /1024 )); -else +for (i =0 ; i <THREAD_SIZE /PAGE_SIZE ; i++) +mod_lruvec_page_state (vm->pages[i],NR_KERNEL_STACK_KB , + account * (PAGE_SIZE /1024 )); + }else { +/* All stack pages are in the same node. */ mod_lruvec_kmem_state (stack,NR_KERNEL_STACK_KB , account * (THREAD_SIZE /1024 )); + } }static int memcg_charge_kernel_stack (struct task_struct *tsk)
_
Andrew Morton
maintainerPATCH 57/178 memcg: cleanup root memcg checks
In reply to Andrew MortonFrom: Shakeel Butt <[email protected]>
Subject: memcg: cleanup root memcg checks
Replace the implicit checking of root memcg with explicit root memcg checking i.e. !css->parent with mem_cgroup_is_root().
---
mm/memcontrol.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
mm/memcontrol.c renamed from mm/memcontrol.c~memcg-cleanup-root-memcg-checks +2 -2
@@ -4123,7 +4123,7 @@ static int mem_cgroup_swappiness_write(sif (val >100 )return -EINVAL ; -if (css->parent) +if (!mem_cgroup_is_root (memcg)) memcg->swappiness = val;else vm_swappiness = val;
@@ -4473,7 +4473,7 @@ static int mem_cgroup_oom_control_write(struct mem_cgroup *memcg =mem_cgroup_from_css (css);/* cannot set to root cgroup and only 0 and 1 are allowed */ -if (!css->parent || !((val ==0 ) || (val ==1 ))) +if (mem_cgroup_is_root (memcg) || !((val ==0 ) || (val ==1 )))return -EINVAL ; memcg->oom_kill_disable = val;
_
Andrew Morton
maintainerPATCH 58/178 memcg: enable memcg oom-kill for __GFP_NOFAIL
In reply to Andrew MortonFrom: Shakeel Butt <[email protected]>
Subject: memcg: enable memcg oom-kill for __GFP_NOFAIL
In the era of async memcg oom-killer, the commit a0d8b00a3381 ("mm: memcg:
do not declare OOM from __GFP_NOFAIL allocations") added the code to skip memcg oom-killer for __GFP_NOFAIL allocations. The reason was that the __GFP_NOFAIL callers will not enter aync oom synchronization path and will keep the task marked as in memcg oom. At that time the tasks marked in memcg oom can bypass the memcg limits and the oom synchronization would have happened later in the later userspace triggered page fault. Thus letting the task marked as under memcg oom bypass the memcg limit for arbitrary time.
With the synchronous memcg oom-killer (commit 29ef680ae7c21 ("memcg, oom:
move out_of_memory back to the charge path")) and not letting the task marked under memcg oom to bypass the memcg limits (commit 1f14c1ac19aa4 ("mm: memcg: do not allow task about to OOM kill to bypass the limit")), we can again allow __GFP_NOFAIL allocations to trigger memcg oom-kill. This will make memcg oom behavior closer to page allocator oom behavior.
---
mm/memcontrol.c | 3 --- 1 file changed, 3 deletions(-)
mm/memcontrol.c renamed from mm/memcontrol.c~memcg-enable-memcg-oom-kill-for-__gfp_nofail +0 -3
@@ -2779,9 +2779,6 @@ retry:if (gfp_mask & __GFP_RETRY_MAYFAIL) goto nomem; -if (gfp_mask & __GFP_NOFAIL) - goto force; -if (fatal_signal_pending (current)) goto force;
_
Andrew Morton
maintainerPATCH 59/178 mm: memcontrol: fix cpuhotplug statistics flushing
In reply to Andrew MortonFrom: Johannes Weiner <[email protected]>
Subject: mm: memcontrol: fix cpuhotplug statistics flushing
Patch series "mm: memcontrol: switch to rstat", v3.
This series converts memcg stats tracking to the streamlined rstat infrastructure provided by the cgroup core code. rstat is already used by the CPU controller and the IO controller. This change is motivated by recent accuracy problems in memcg's custom stats code, as well as the benefits of sharing common infra with other controllers.
The current memcg implementation does batched tree aggregation on the write side: local stat changes are cached in per-cpu counters, which are then propagated upward in batches when a threshold (32 pages) is exceeded. This is cheap, but the error introduced by the lazy upward propagation adds up: 32 pages times CPUs times cgroups in the subtree. We've had complaints from service owners that the stats do not reliably track and react to allocation behavior as expected, sometimes swallowing the results of entire test applications.
The original memcg stat implementation used to do tree aggregation exclusively on the read side: local stats would only ever be tracked in per-cpu counters, and a memory.stat read would iterate the entire subtree and sum those counters up. This didn't keep up with the times:
- Cgroup trees are much bigger now. We switched to lazily-freed cgroups, where deleted groups would hang around until their remaining page cache has been reclaimed. This can result in large subtrees that are expensive to walk, while most of the groups are idle and their statistics don't change much anymore.
- Automated monitoring increased. With the proliferation of userspace oom killing, proactive reclaim, and higher-resolution logging of workload trends in general, top-level stat files are polled at least once a second in many deployments.
- The lifetime of cgroups got shorter. Where most cgroup setups in the past would have a few large policy-oriented cgroups for everything running on the system, newer cgroup deployments tend to create one group per application - which gets deleted again as the processes exit. An aggregation scheme that doesn't retain child data inside the parents loses event history of the subtree.
Rstat addresses all three of those concerns through intelligent, persistent read-side aggregation. As statistics change at the local level, rstat tracks - on a per-cpu basis - only those parts of a subtree that have changes pending and require aggregation. The actual aggregation occurs on the colder read side - which can now skip over (potentially large) numbers of recently idle cgroups.
===
The test_kmem cgroup selftest is currently failing due to excessive cumulative vmstat drift from 100 subgroups:
ok 1 test_kmem_basic
memory.current = 8810496
slab + anon + file + kernel_stack = 17074568
slab = 6101384
anon = 946176
file = 0
kernel_stack = 10027008
not ok 2 test_kmem_memcg_deletion
ok 3 test_kmem_proc_kpagecgroup
ok 4 test_kmem_kernel_stacks
ok 5 test_kmem_dead_cgroups
ok 6 test_percpu_basic
As you can see, memory.stat items far exceed memory.current. The kernel stack alone is bigger than all of charged memory. That's because the memory of the test has been uncharged from memory.current, but the negative vmstat deltas are still sitting in the percpu caches.
The test at this time isn't even counting percpu, pagetables etc. yet, which would further contribute to the error. The last patch in the series updates the test to include them - as well as reduces the vmstat tolerances in general to only expect page_counter batching.
With all patches applied, the (now more stringent) test succeeds:
ok 1 test_kmem_basic
ok 2 test_kmem_memcg_deletion
ok 3 test_kmem_proc_kpagecgroup
ok 4 test_kmem_kernel_stacks
ok 5 test_kmem_dead_cgroups
ok 6 test_percpu_basic
===
A kernel build test confirms that overhead is comparable. Two kernels are built simultaneously in a nested tree with several idle siblings:
root - kernelbuild - one - two - three - four - build-a (defconfig, make -j16)
`- build-b (defconfig, make -j16)
`- idle-1
`- ...
`- idle-9During the builds, kernelbuild/memory.stat is read once a second.
A perf diff shows that the changes in cycle distribution is minimal. Top 10 kernel symbols:
0.09% +0.08% [kernel.kallsyms] [k] __mod_memcg_lruvec_state
0.00% +0.06% [kernel.kallsyms] [k] cgroup_rstat_updated
0.08% -0.05% [kernel.kallsyms] [k] __mod_memcg_state.part.0
0.16% -0.04% [kernel.kallsyms] [k] release_pages
0.00% +0.03% [kernel.kallsyms] [k] __count_memcg_events
0.01% +0.03% [kernel.kallsyms] [k] mem_cgroup_charge_statistics.constprop.0
0.10% -0.02% [kernel.kallsyms] [k] get_mem_cgroup_from_mm
0.05% -0.02% [kernel.kallsyms] [k] mem_cgroup_update_lru_size
0.57% +0.01% [kernel.kallsyms] [k] asm_exc_page_fault===
The on-demand aggregated stats are now fully accurate:
$ grep -e nr_inactive_file /proc/vmstat | awk '{print($1,$2*4096)}'; \
grep -e inactive_file /sys/fs/cgroup/memory.statvanilla: patched:nr_inactive_file 1574105088 nr_inactive_file 1027801088
inactive_file 1577410560 inactive_file 1027801088
===
This patch (of 8):
The memcg hotunplug callback erroneously flushes counts on the local CPU, not the counts of the CPU going away; those counts will be lost.
Flush the CPU that is actually going away.
Also simplify the code a bit by using mod_memcg_state() and count_memcg_events() instead of open-coding the upward flush - this is comparable to how vmstat.c handles hotunplug flushing.
---
mm/memcontrol.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-)
mm/memcontrol.c renamed from mm/memcontrol.c~mm-memcontrol-fix-cpuhotplug-statistics-flushing +21 -14
@@ -2370,45 +2370,52 @@ static void drain_all_stock(struct mem_cstatic int memcg_hotplug_cpu_dead (unsigned int cpu) {struct memcg_stock_pcp *stock; -struct mem_cgroup *memcg, *mi; +struct mem_cgroup *memcg; stock = &per_cpu (memcg_stock, cpu);drain_stock (stock);for_each_mem_cgroup (memcg) { +struct memcg_vmstats_percpu *statc;int i; + statc =per_cpu_ptr (memcg->vmstats_percpu, cpu); +for (i =0 ; i <MEMCG_NR_STAT ; i++) {int nid; -long x; - x =this_cpu_xchg (memcg->vmstats_percpu->stat[i],0 ); -if (x) -for (mi = memcg; mi; mi =parent_mem_cgroup (mi)) -atomic_long_add (x, &memcg->vmstats[i]); +if (statc->stat[i]) { +mod_memcg_state (memcg, i, statc->stat[i]); + statc->stat[i] =0 ; + }if (i >=NR_VM_NODE_STAT_ITEMS )continue ;for_each_node (nid) { +struct batched_lruvec_stat *lstatc;struct mem_cgroup_per_node *pn; +long x; pn =mem_cgroup_nodeinfo (memcg, nid); - x =this_cpu_xchg (pn->lruvec_stat_cpu->count[i],0 ); -if (x) + lstatc =per_cpu_ptr (pn->lruvec_stat_cpu, cpu); + + x = lstatc->count[i]; + lstatc->count[i] =0 ; + +if (x) {do {atomic_long_add (x, &pn->lruvec_stat[i]); }while ((pn =parent_nodeinfo (pn, nid))); + } } }for (i =0 ; i <NR_VM_EVENT_ITEMS ; i++) { -long x; - - x =this_cpu_xchg (memcg->vmstats_percpu->events[i],0 ); -if (x) -for (mi = memcg; mi; mi =parent_mem_cgroup (mi)) -atomic_long_add (x, &memcg->vmevents[i]); +if (statc->events[i]) { +count_memcg_events (memcg, i, statc->events[i]); + statc->events[i] =0 ; + } } }
_
Andrew Morton
maintainerPATCH 60/178 mm: memcontrol: kill mem_cgroup_nodeinfo()
In reply to Andrew MortonFrom: Johannes Weiner <[email protected]>
Subject: mm: memcontrol: kill mem_cgroup_nodeinfo()
No need to encapsulate a simple struct member access.
---
include/linux/memcontrol.h | 8 +------- mm/memcontrol.c | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 17 deletions(-)
include/linux/memcontrol.h renamed from include/linux/memcontrol.h~mm-memcontrol-kill-mem_cgroup_nodeinfo +1 -7
@@ -602,12 +602,6 @@ void mem_cgroup_uncharge_list(struct lisvoid mem_cgroup_migrate (struct page *oldpage,struct page *newpage); -static struct mem_cgroup_per_node * -mem_cgroup_nodeinfo (struct mem_cgroup *memcg,int nid) -{ -return memcg->nodeinfo[nid]; -} -/** * mem_cgroup_lruvec - get the lru list vector for a memcg & node * @memcg: memcg of the wanted lruvec
@@ -631,7 +625,7 @@ static inline struct lruvec *mem_cgroup_if (!memcg) memcg = root_mem_cgroup; - mz =mem_cgroup_nodeinfo (memcg, pgdat->node_id); + mz = memcg->nodeinfo[pgdat->node_id]; lruvec = &mz->lruvec; out:/*
mm/memcontrol.c renamed from mm/memcontrol.c~mm-memcontrol-kill-mem_cgroup_nodeinfo +11 -10
@@ -414,13 +414,14 @@ static int memcg_expand_one_shrinker_map int size, int old_size) {struct memcg_shrinker_map *new, *old; +struct mem_cgroup_per_node *pn;int nid;lockdep_assert_held (&memcg_shrinker_map_mutex);for_each_node (nid) { - old =rcu_dereference_protected ( -mem_cgroup_nodeinfo (memcg, nid)->shrinker_map, true); + pn = memcg->nodeinfo[nid]; + old =rcu_dereference_protected (pn->shrinker_map, true);/* Not yet online memcg */ if (!old)return 0 ;
@@ -433,7 +434,7 @@ static int memcg_expand_one_shrinker_mapmemset (new->map, (int )0xff , old_size);memset ((void *)new->map + old_size,0 , size - old_size); -rcu_assign_pointer (memcg->nodeinfo[nid]->shrinker_map, new); +rcu_assign_pointer (pn->shrinker_map, new);call_rcu (&old->rcu, memcg_free_shrinker_map_rcu); }
@@ -450,7 +451,7 @@ static void memcg_free_shrinker_maps(strreturn ;for_each_node (nid) { - pn =mem_cgroup_nodeinfo (memcg, nid); + pn = memcg->nodeinfo[nid]; map =rcu_dereference_protected (pn->shrinker_map, true);kvfree (map);rcu_assign_pointer (pn->shrinker_map,NULL );
@@ -713,7 +714,7 @@ static void mem_cgroup_remove_from_treesint nid;for_each_node (nid) { - mz =mem_cgroup_nodeinfo (memcg, nid); + mz = memcg->nodeinfo[nid]; mctz =soft_limit_tree_node (nid);if (mctz)mem_cgroup_remove_exceeded (mz, mctz);
@@ -796,7 +797,7 @@ parent_nodeinfo(struct mem_cgroup_per_no parent =parent_mem_cgroup (pn->memcg);if (!parent)return NULL ; -return mem_cgroup_nodeinfo (parent, nid); +return parent->nodeinfo[nid]; } void __mod_memcg_lruvec_state(struct lruvec *lruvec, enum node_stat_item idx,
@@ -1136,7 +1137,7 @@ struct mem_cgroup *mem_cgroup_iter(strucif (reclaim) {struct mem_cgroup_per_node *mz; - mz =mem_cgroup_nodeinfo (root, reclaim->pgdat->node_id); + mz = root->nodeinfo[reclaim->pgdat->node_id]; iter = &mz->iter;if (prev && reclaim->generation != iter->generation)
@@ -1238,7 +1239,7 @@ static void __invalidate_reclaim_iteratoint nid;for_each_node (nid) { - mz =mem_cgroup_nodeinfo (from, nid); + mz = from->nodeinfo[nid]; iter = &mz->iter;cmpxchg (&iter->position, dead_memcg,NULL ); }
@@ -2397,7 +2398,7 @@ static int memcg_hotplug_cpu_dead(unsignstruct mem_cgroup_per_node *pn;long x; - pn =mem_cgroup_nodeinfo (memcg, nid); + pn = memcg->nodeinfo[nid]; lstatc =per_cpu_ptr (pn->lruvec_stat_cpu, cpu); x = lstatc->count[i];
@@ -4098,7 +4099,7 @@ static int memcg_stat_show(struct seq_fiunsigned long file_cost =0 ;for_each_online_pgdat (pgdat) { - mz =mem_cgroup_nodeinfo (memcg, pgdat->node_id); + mz = memcg->nodeinfo[pgdat->node_id]; anon_cost += mz->lruvec.anon_cost; file_cost += mz->lruvec.file_cost;
_
Andrew Morton
maintainerPATCH 61/178 mm: memcontrol: privatize memcg_page_state query functions
In reply to Andrew MortonFrom: Johannes Weiner <[email protected]>
Subject: mm: memcontrol: privatize memcg_page_state query functions
There are no users outside of the memory controller itself. The rest of the kernel cares either about node or lruvec stats.
---
include/linux/memcontrol.h | 44 ----------------------------------- mm/memcontrol.c | 32 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 44 deletions(-)
include/linux/memcontrol.h renamed from include/linux/memcontrol.h~mm-memcontrol-privatize-memcg_page_state-query-functions +0 -44
@@ -864,39 +864,6 @@ extern bool cgroup_memory_noswap;void lock_page_memcg (struct page *page);void unlock_page_memcg (struct page *page); -/* -* idx can be of type enum memcg_stat_item or node_stat_item. -* Keep in sync with memcg_exact_page_state(). -*/ -static inline unsigned long memcg_page_state (struct mem_cgroup *memcg,int idx) -{ -long x =atomic_long_read (&memcg->vmstats[idx]); -#ifdef CONFIG_SMP -if (x <0 ) - x =0 ; -#endif -return x; -} - -/* -* idx can be of type enum memcg_stat_item or node_stat_item. -* Keep in sync with memcg_exact_page_state(). -*/ -static inline unsigned long memcg_page_state_local (struct mem_cgroup *memcg, -int idx) -{ -long x =0 ; -int cpu; - -for_each_possible_cpu (cpu) - x +=per_cpu (memcg->vmstats_local->stat[idx], cpu); -#ifdef CONFIG_SMP -if (x <0 ) - x =0 ; -#endif -return x; -} -void __mod_memcg_state (struct mem_cgroup *memcg,int idx,int val);/* idx can be of type enum memcg_stat_item or node_stat_item */
@@ -1322,17 +1289,6 @@ static inline void mem_cgroup_print_oom_ { } -static inline unsigned long memcg_page_state (struct mem_cgroup *memcg,int idx) -{ -return 0 ; -} - -static inline unsigned long memcg_page_state_local (struct mem_cgroup *memcg, -int idx) -{ -return 0 ; -} -static inline void __mod_memcg_state (struct mem_cgroup *memcg,int idx,int nr)
mm/memcontrol.c renamed from mm/memcontrol.c~mm-memcontrol-privatize-memcg_page_state-query-functions +32 -0
@@ -789,6 +789,38 @@ void __mod_memcg_state(struct mem_cgroup__this_cpu_write (memcg->vmstats_percpu->stat[idx], x); } +/* +* idx can be of type enum memcg_stat_item or node_stat_item. +* Keep in sync with memcg_exact_page_state(). +*/ +static unsigned long memcg_page_state (struct mem_cgroup *memcg,int idx) +{ +long x =atomic_long_read (&memcg->vmstats[idx]); +#ifdef CONFIG_SMP +if (x <0 ) + x =0 ; +#endif +return x; +} + +/* +* idx can be of type enum memcg_stat_item or node_stat_item. +* Keep in sync with memcg_exact_page_state(). +*/ +static unsigned long memcg_page_state_local (struct mem_cgroup *memcg,int idx) +{ +long x =0 ; +int cpu; + +for_each_possible_cpu (cpu) + x +=per_cpu (memcg->vmstats_local->stat[idx], cpu); +#ifdef CONFIG_SMP +if (x <0 ) + x =0 ; +#endif +return x; +} +static struct mem_cgroup_per_node *parent_nodeinfo (struct mem_cgroup_per_node *pn,int nid) {
_
Andrew Morton
maintainerPATCH 62/178 cgroup: rstat: support cgroup1
In reply to Andrew MortonFrom: Johannes Weiner <[email protected]>
Subject: cgroup: rstat: support cgroup1
Rstat currently only supports the default hierarchy in cgroup2. In order to replace memcg's private stats infrastructure - used in both cgroup1 and cgroup2 - with rstat, the latter needs to support cgroup1.
The initialization and destruction callbacks for regular cgroups are already in place. Remove the cgroup_on_dfl() guards to handle cgroup1.
The initialization of the root cgroup is currently hardcoded to only handle cgrp_dfl_root.cgrp. Move those callbacks to cgroup_setup_root() and cgroup_destroy_root() to handle the default root as well as the various cgroup1 roots we may set up during mounting.
The linking of css to cgroups happens in code shared between cgroup1 and cgroup2 as well. Simply remove the cgroup_on_dfl() guard.
Linkage of the root css to the root cgroup is a bit trickier: per default, the root css of a subsystem controller belongs to the default hierarchy (i.e. the cgroup2 root). When a controller is mounted in its cgroup1 version, the root css is stolen and moved to the cgroup1 root; on unmount, the css moves back to the default hierarchy. Annotate rebind_subsystems() to move the root css linkage along between roots.
---
kernel/cgroup/cgroup.c | 34 +++++++++++++++++++++------------- kernel/cgroup/rstat.c | 2 -- 2 files changed, 21 insertions(+), 15 deletions(-)
kernel/cgroup/cgroup.c renamed from kernel/cgroup/cgroup.c~cgroup-rstat-support-cgroup1 +21 -13
@@ -1339,6 +1339,7 @@ static void cgroup_destroy_root(struct cmutex_unlock (&cgroup_mutex); +cgroup_rstat_exit (cgrp);kernfs_destroy_root (root->kf_root);cgroup_free_root (root); }
@@ -1751,6 +1752,12 @@ int rebind_subsystems(struct cgroup_root &dcgrp->e_csets[ss->id]);spin_unlock_irq (&css_set_lock); +if (ss->css_rstat_flush) { +list_del_rcu (&css->rstat_css_node); +list_add_rcu (&css->rstat_css_node, + &dcgrp->rstat_css_list); + } +/* default hierarchy doesn't enable controllers by default */ dst_root->subsys_mask |=1 << ssid;if (dst_root == &cgrp_dfl_root) {
@@ -1971,10 +1978,14 @@ int cgroup_setup_root(struct cgroup_rootif (ret) goto destroy_root; - ret =rebind_subsystems (root, ss_mask); + ret =cgroup_rstat_init (root_cgrp);if (ret) goto destroy_root; + ret =rebind_subsystems (root, ss_mask); +if (ret) + goto exit_stats; + ret =cgroup_bpf_inherit (root_cgrp);WARN_ON_ONCE (ret);
@@ -2006,6 +2017,8 @@ int cgroup_setup_root(struct cgroup_root ret =0 ; goto out; +exit_stats: +cgroup_rstat_exit (root_cgrp); destroy_root:kernfs_destroy_root (root->kf_root); root->kf_root =NULL ;
@@ -4934,8 +4947,7 @@ static void css_free_rwork_fn(struct worcgroup_put (cgroup_parent (cgrp));kernfs_put (cgrp->kn);psi_cgroup_free (cgrp); -if (cgroup_on_dfl (cgrp)) -cgroup_rstat_exit (cgrp); +cgroup_rstat_exit (cgrp);kfree (cgrp); }else {/*
@@ -4976,8 +4988,7 @@ static void css_release_work_fn(struct w/* cgroup release path */ TRACE_CGROUP_PATH (release, cgrp); -if (cgroup_on_dfl (cgrp)) -cgroup_rstat_flush (cgrp); +cgroup_rstat_flush (cgrp);spin_lock_irq (&css_set_lock); for (tcgrp = cgroup_parent(cgrp); tcgrp;
@@ -5034,7 +5045,7 @@ static void init_and_link_css(struct cgrcss_get (css->parent); } -if (cgroup_on_dfl (cgrp) && ss->css_rstat_flush) +if (ss->css_rstat_flush)list_add_rcu (&css->rstat_css_node, &cgrp->rstat_css_list);BUG_ON (cgroup_css (cgrp, ss));
@@ -5159,11 +5170,9 @@ static struct cgroup *cgroup_create(struif (ret) goto out_free_cgrp; -if (cgroup_on_dfl (parent)) { - ret =cgroup_rstat_init (cgrp); -if (ret) - goto out_cancel_ref; - } + ret =cgroup_rstat_init (cgrp); +if (ret) + goto out_cancel_ref;/* create the directory */ kn =kernfs_create_dir (parent->kn, name, mode, cgrp);
@@ -5250,8 +5259,7 @@ out_psi_free: out_kernfs_remove:kernfs_remove (cgrp->kn); out_stat_exit: -if (cgroup_on_dfl (parent)) -cgroup_rstat_exit (cgrp); +cgroup_rstat_exit (cgrp); out_cancel_ref:percpu_ref_exit (&cgrp->self.refcnt); out_free_cgrp:
kernel/cgroup/rstat.c renamed from kernel/cgroup/rstat.c~cgroup-rstat-support-cgroup1 +0 -2
@@ -285,8 +285,6 @@ void __init cgroup_rstat_boot(void)for_each_possible_cpu (cpu)raw_spin_lock_init (per_cpu_ptr (&cgroup_rstat_cpu_lock, cpu)); - -BUG_ON (cgroup_rstat_init (&cgrp_dfl_root.cgrp)); }/*
_
Andrew Morton
maintainerPATCH 63/178 cgroup: rstat: punt root-level optimization to individual controllers
In reply to Andrew MortonFrom: Johannes Weiner <[email protected]>
Subject: cgroup: rstat: punt root-level optimization to individual controllers
Current users of the rstat code can source root-level statistics from the native counters of their respective subsystem, allowing them to forego aggregation at the root level. This optimization is currently implemented inside the generic rstat code, which doesn't track the root cgroup and doesn't invoke the subsystem flush callbacks on it.
However, the memory controller cannot do this optimization, because cgroup1 breaks out memory specifically for the local level, including at the root level. In preparation for the memory controller switching to rstat, move the optimization from rstat core to the controllers.
Afterwards, rstat will always track the root cgroup for changes and invoke the subsystem callbacks on it; and it's up to the subsystem to special-case and skip aggregation of the root cgroup if it can source this information through other, cheaper means.
This is the case for the io controller and the cgroup base stats. In their respective flush callbacks, check whether the parent is the root cgroup, and if so, skip the unnecessary upward propagation.
The extra cost of tracking the root cgroup is negligible: on stat changes, we actually remove a branch that checks for the root. The queueing for a flush touches only per-cpu data, and only the first stat change since a flush requires a (per-cpu) lock.
---
block/blk-cgroup.c | 17 +++++++---- kernel/cgroup/rstat.c | 59 +++++++++++++++++++++++----------------- 2 files changed, 46 insertions(+), 30 deletions(-)
block/blk-cgroup.c renamed from block/blk-cgroup.c~cgroup-rstat-punt-root-level-optimization-to-individual-controllers +11 -6
@@ -764,6 +764,10 @@ static void blkcg_rstat_flush(struct cgrstruct blkcg *blkcg =css_to_blkcg (css);struct blkcg_gq *blkg; +/* Root-level stats are sourced from system-wide IO stats */ +if (!cgroup_parent (css->cgroup)) +return ; +rcu_read_lock ();hlist_for_each_entry_rcu (blkg, &blkcg->blkg_list, blkcg_node) {
@@ -786,8 +790,8 @@ static void blkcg_rstat_flush(struct cgrblkg_iostat_add (&bisc->last, &delta);u64_stats_update_end (&blkg->iostat.sync); -/* propagate global delta to parent */ -if (parent) { +/* propagate global delta to parent (unless that's root) */ +if (parent && parent->parent) {u64_stats_update_begin (&parent->iostat.sync);blkg_iostat_set (&delta, &blkg->iostat.cur);blkg_iostat_sub (&delta, &blkg->iostat.last);
@@ -801,10 +805,11 @@ static void blkcg_rstat_flush(struct cgr }/* -* The rstat algorithms intentionally don't handle the root cgroup to avoid -* incurring overhead when no cgroups are defined. For that reason, -* cgroup_rstat_flush in blkcg_print_stat does not actually fill out the -* iostat in the root cgroup's blkcg_gq. +* We source root cgroup stats from the system-wide stats to avoid +* tracking the same information twice and incurring overhead when no +* cgroups are defined. For that reason, cgroup_rstat_flush in +* blkcg_print_stat does not actually fill out the iostat in the root +* cgroup's blkcg_gq. * * However, we would like to re-use the printing code between the root and * non-root cgroups to the extent possible. For that reason, we simulate
kernel/cgroup/rstat.c renamed from kernel/cgroup/rstat.c~cgroup-rstat-punt-root-level-optimization-to-individual-controllers +35 -24
108 lines not on this page · raw message
_
Andrew Morton
maintainerPATCH 64/178 mm: memcontrol: switch to rstat
In reply to Andrew MortonFrom: Johannes Weiner <[email protected]>
Subject: mm: memcontrol: switch to rstat
Replace the memory controller's custom hierarchical stats code with the generic rstat infrastructure provided by the cgroup core.
The current implementation does batched upward propagation from the write side (i.e. as stats change). The per-cpu batches introduce an error, which is multiplied by the number of subgroups in a tree. In systems with many CPUs and sizable cgroup trees, the error can be large enough to confuse users (e.g. 32 batch pages * 32 CPUs * 32 subgroups results in an error of up to 128M per stat item). This can entirely swallow allocation bursts inside a workload that the user is expecting to see reflected in the statistics.
In the past, we've done read-side aggregation, where a memory.stat read would have to walk the entire subtree and add up per-cpu counts. This became problematic with lazily-freed cgroups: we could have large subtrees where most cgroups were entirely idle. Hence the switch to change-driven upward propagation. Unfortunately, it needed to trade accuracy for speed due to the write side being so hot.
Rstat combines the best of both worlds: from the write side, it cheaply maintains a queue of cgroups that have pending changes, so that the read side can do selective tree aggregation. This way the reported stats will always be precise and recent as can be, while the aggregation can skip over potentially large numbers of idle cgroups.
The way rstat works is that it implements a tree for tracking cgroups with pending local changes, as well as a flush function that walks the tree upwards. The controller then drives this by 1) telling rstat when a local cgroup stat changes (e.g. mod_memcg_state) and 2) when a flush is required to get uptodate hierarchy stats for a given subtree (e.g. when memory.stat is read). The controller also provides a flush callback that is called during the rstat flush walk for each cgroup and aggregates its local per-cpu counters and propagates them upwards.
This adds a second vmstats to struct mem_cgroup (MEMCG_NR_STAT + NR_VM_EVENT_ITEMS) to track pending subtree deltas during upward aggregation. It removes 3 words from the per-cpu data. It eliminates memcg_exact_page_state(), since memcg_page_state() is now exact.
---
include/linux/memcontrol.h | 67 ++++++---- mm/memcontrol.c | 218 +++++++++++++---------------------- 2 files changed, 127 insertions(+), 158 deletions(-)
include/linux/memcontrol.h renamed from include/linux/memcontrol.h~mm-memcontrol-switch-to-rstat +40 -27
@@ -76,10 +76,27 @@ enum mem_cgroup_events_target { };struct memcg_vmstats_percpu { -long stat[MEMCG_NR_STAT ]; -unsigned long events[NR_VM_EVENT_ITEMS ]; -unsigned long nr_page_events; -unsigned long targets[MEM_CGROUP_NTARGETS ]; +/* Local (CPU and cgroup) page state & events */ +long state[MEMCG_NR_STAT ]; +unsigned long events[NR_VM_EVENT_ITEMS ]; + +/* Delta calculation for lockless upward propagation */ +long state_prev[MEMCG_NR_STAT ]; +unsigned long events_prev[NR_VM_EVENT_ITEMS ]; + +/* Cgroup1: threshold notifications & softlimit tree updates */ +unsigned long nr_page_events; +unsigned long targets[MEM_CGROUP_NTARGETS ]; +}; + +struct memcg_vmstats { +/* Aggregated (CPU and subtree) page state & events */ +long state[MEMCG_NR_STAT ]; +unsigned long events[NR_VM_EVENT_ITEMS ]; + +/* Pending child counts during tree propagation */ +long state_pending[MEMCG_NR_STAT ]; +unsigned long events_pending[NR_VM_EVENT_ITEMS ]; };struct mem_cgroup_reclaim_iter {
@@ -287,8 +304,8 @@ struct mem_cgroup {MEMCG_PADDING (_pad1_); -atomic_long_t vmstats[MEMCG_NR_STAT ]; -atomic_long_t vmevents[NR_VM_EVENT_ITEMS ]; +/* memory.stat */ +struct memcg_vmstats vmstats;/* memory.events */ atomic_long_t memory_events[MEMCG_NR_MEMORY_EVENTS ];
@@ -315,10 +332,6 @@ struct mem_cgroup {atomic_t moving_account;struct task_struct *move_lock_task; -/* Legacy local VM stats and events */ -struct memcg_vmstats_percpu __percpu *vmstats_local; - -/* Subtree VM stats and events (batched updates) */ struct memcg_vmstats_percpu __percpu *vmstats_percpu;#ifdef CONFIG_CGROUP_WRITEBACK
@@ -939,10 +952,6 @@ static inline void mod_memcg_lruvec_statlocal_irq_restore (flags); } -unsigned long mem_cgroup_soft_limit_reclaim (pg_data_t *pgdat,int order, -gfp_t gfp_mask, -unsigned long *total_scanned); -void __count_memcg_events (struct mem_cgroup *memcg,enum vm_event_item idx,unsigned long count);
@@ -1023,6 +1032,10 @@ static inline void memcg_memory_event_mmvoid split_page_memcg (struct page *head,unsigned int nr); +unsigned long mem_cgroup_soft_limit_reclaim (pg_data_t *pgdat,int order, +gfp_t gfp_mask, +unsigned long *total_scanned); +#else /* CONFIG_MEMCG */ #define MEM_CGROUP_ID_SHIFT 0
@@ -1131,6 +1144,10 @@ static inline bool lruvec_holds_page_lrureturn lruvec == &pgdat->__lruvec; } +static inline void lruvec_memcg_debug (struct lruvec *lruvec,struct page *page) +{ +} +static inline struct mem_cgroup *parent_mem_cgroup (struct mem_cgroup *memcg) {return NULL ;
@@ -1334,18 +1351,6 @@ static inline void mod_lruvec_kmem_statemod_node_page_state (page_pgdat (page), idx, val); } -static inline -unsigned long mem_cgroup_soft_limit_reclaim (pg_data_t *pgdat,int order, -gfp_t gfp_mask, -unsigned long *total_scanned) -{ -return 0 ; -} - -static inline void split_page_memcg (struct page *head,unsigned int nr) -{ -} -static inline void count_memcg_events (struct mem_cgroup *memcg,enum vm_event_item idx,unsigned long count)
@@ -1368,9 +1373,17 @@ void count_memcg_event_mm(struct mm_stru { } -static inline void lruvec_memcg_debug (struct lruvec *lruvec,struct page *page) +static inline void split_page_memcg (struct page *head,unsigned int nr) { } + +static inline +unsigned long mem_cgroup_soft_limit_reclaim (pg_data_t *pgdat,int order, +gfp_t gfp_mask, +unsigned long *total_scanned) +{ +return 0 ; +}#endif /* CONFIG_MEMCG */ static inline void __inc_lruvec_kmem_state (void *p,enum node_stat_item idx)
mm/memcontrol.c renamed from mm/memcontrol.c~mm-memcontrol-switch-to-rstat +87 -131
364 lines not on this page · raw message
_
Andrew Morton
maintainerPATCH 65/178 mm: memcontrol: consolidate lruvec stat flushing
In reply to Andrew MortonFrom: Johannes Weiner <[email protected]>
Subject: mm: memcontrol: consolidate lruvec stat flushing
There are two functions to flush the per-cpu data of an lruvec into the rest of the cgroup tree: when the cgroup is being freed, and when a CPU disappears during hotplug. The difference is whether all CPUs or just one is being collected, but the rest of the flushing code is the same. Merge them into one function and share the common code.
---
mm/memcontrol.c | 76 +++++++++++++++++----------------------------- 1 file changed, 29 insertions(+), 47 deletions(-)
mm/memcontrol.c renamed from mm/memcontrol.c~mm-memcontrol-consolidate-lruvec-stat-flushing +29 -47
@@ -2364,6 +2364,29 @@ static void drain_all_stock(struct mem_cmutex_unlock (&percpu_charge_mutex); } +static void memcg_flush_lruvec_page_state (struct mem_cgroup *memcg,int cpu) +{ +int nid; + +for_each_node (nid) { +struct mem_cgroup_per_node *pn = memcg->nodeinfo[nid]; +unsigned long stat[NR_VM_NODE_STAT_ITEMS ]; +struct batched_lruvec_stat *lstatc; +int i; + + lstatc =per_cpu_ptr (pn->lruvec_stat_cpu, cpu); +for (i =0 ; i <NR_VM_NODE_STAT_ITEMS ; i++) { + stat[i] = lstatc->count[i]; + lstatc->count[i] =0 ; + } + +do { +for (i =0 ; i <NR_VM_NODE_STAT_ITEMS ; i++) +atomic_long_add (stat[i], &pn->lruvec_stat[i]); + }while ((pn =parent_nodeinfo (pn, nid))); + } +} +static int memcg_hotplug_cpu_dead (unsigned int cpu) {struct memcg_stock_pcp *stock;
@@ -2372,31 +2395,8 @@ static int memcg_hotplug_cpu_dead(unsign stock = &per_cpu (memcg_stock, cpu);drain_stock (stock); -for_each_mem_cgroup (memcg) { -int i; - -for (i =0 ; i <NR_VM_NODE_STAT_ITEMS ; i++) { -int nid; - -for_each_node (nid) { -struct batched_lruvec_stat *lstatc; -struct mem_cgroup_per_node *pn; -long x; - - pn = memcg->nodeinfo[nid]; - lstatc =per_cpu_ptr (pn->lruvec_stat_cpu, cpu); - - x = lstatc->count[i]; - lstatc->count[i] =0 ; - -if (x) { -do { -atomic_long_add (x, &pn->lruvec_stat[i]); - }while ((pn =parent_nodeinfo (pn, nid))); - } - } - } - } +for_each_mem_cgroup (memcg) +memcg_flush_lruvec_page_state (memcg, cpu);return 0 ; }
@@ -3583,27 +3583,6 @@ static u64 mem_cgroup_read_u64(struct cg } } -static void memcg_flush_lruvec_page_state (struct mem_cgroup *memcg) -{ -int node; - -for_each_node (node) { -struct mem_cgroup_per_node *pn = memcg->nodeinfo[node]; -unsigned long stat[NR_VM_NODE_STAT_ITEMS ] = {0 }; -struct mem_cgroup_per_node *pi; -int cpu, i; - -for_each_online_cpu (cpu) -for (i =0 ; i <NR_VM_NODE_STAT_ITEMS ; i++) - stat[i] +=per_cpu ( - pn->lruvec_stat_cpu->count[i], cpu); - -for (pi = pn; pi; pi =parent_nodeinfo (pi, node)) -for (i =0 ; i <NR_VM_NODE_STAT_ITEMS ; i++) -atomic_long_add (stat[i], &pi->lruvec_stat[i]); - } -} -#ifdef CONFIG_MEMCG_KMEM static int memcg_online_kmem (struct mem_cgroup *memcg) {
@@ -5139,12 +5118,15 @@ static void __mem_cgroup_free(struct memstatic void mem_cgroup_free (struct mem_cgroup *memcg) { +int cpu; +memcg_wb_domain_exit (memcg);/* * Flush percpu lruvec stats to guarantee the value * correctness on parent's and all ancestor levels. */ -memcg_flush_lruvec_page_state (memcg); +for_each_online_cpu (cpu) +memcg_flush_lruvec_page_state (memcg, cpu);__mem_cgroup_free (memcg); }
_
Andrew Morton
maintainerPATCH 66/178 kselftests: cgroup: update kmem test for new vmstat implementation
In reply to Andrew MortonFrom: Johannes Weiner <[email protected]>
Subject: kselftests: cgroup: update kmem test for new vmstat implementation
With memcg having switched to rstat, memory.stat output is precise. Update the cgroup selftest to reflect the expectations and error tolerances of the new implementation.
Also add newly tracked types of memory to the memory.stat side of the equation, since they're included in memory.current and could throw false positives.
---
tools/testing/selftests/cgroup/test_kmem.c | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-)
tools/testing/selftests/cgroup/test_kmem.c renamed from tools/testing/selftests/cgroup/test_kmem.c~kselftests-cgroup-update-kmem-test-for-new-vmstat-implementation +14 -8
@@ -19,12 +19,12 @@/* -* Memory cgroup charging and vmstat data aggregation is performed using -* percpu batches 32 pages big (look at MEMCG_CHARGE_BATCH). So the maximum -* discrepancy between charge and vmstat entries is number of cpus multiplied -* by 32 pages multiplied by 2. +* Memory cgroup charging is performed using percpu batches 32 pages +* big (look at MEMCG_CHARGE_BATCH), whereas memory.stat is exact. So +* the maximum discrepancy between charge and vmstat entries is number +* of cpus multiplied by 32 pages. */ -#define MAX_VMSTAT_ERROR (4096 * 32 * 2 * get_nprocs()) +#define MAX_VMSTAT_ERROR (4096 * 32 * get_nprocs())static int alloc_dcache (const char *cgroup,void *arg)
@@ -162,7 +162,7 @@ static int cg_run_in_subcgroups(const ch*/ static int test_kmem_memcg_deletion (const char *root) { -long current, slab, anon, file, kernel_stack, sum; +long current, slab, anon, file, kernel_stack, pagetables, percpu, sock, sum;int ret =KSFT_FAIL ;char *parent;
@@ -184,11 +184,14 @@ static int test_kmem_memcg_deletion(cons anon =cg_read_key_long (parent,"memory.stat" ,"anon " ); file =cg_read_key_long (parent,"memory.stat" ,"file " ); kernel_stack =cg_read_key_long (parent,"memory.stat" ,"kernel_stack " ); + pagetables =cg_read_key_long (parent,"memory.stat" ,"pagetables " ); + percpu =cg_read_key_long (parent,"memory.stat" ,"percpu " ); + sock =cg_read_key_long (parent,"memory.stat" ,"sock " );if (current <0 || slab <0 || anon <0 || file <0 || - kernel_stack <0 ) + kernel_stack <0 || pagetables <0 || percpu <0 || sock <0 ) goto cleanup; - sum = slab + anon + file + kernel_stack; + sum = slab + anon + file + kernel_stack + pagetables + percpu + sock;if (abs (sum - current) <MAX_VMSTAT_ERROR ) { ret =KSFT_PASS ; }else {
@@ -198,6 +201,9 @@ static int test_kmem_memcg_deletion(consprintf ("anon = %ld\n" , anon);printf ("file = %ld\n" , file);printf ("kernel_stack = %ld\n" , kernel_stack); +printf ("pagetables = %ld\n" , pagetables); +printf ("percpu = %ld\n" , percpu); +printf ("sock = %ld\n" , sock); } cleanup:
_
Andrew Morton
maintainerPATCH 67/178 memcg: charge before adding to swapcache on swapin
In reply to Andrew MortonFrom: Shakeel Butt <[email protected]>
Subject: memcg: charge before adding to swapcache on swapin
Currently the kernel adds the page, allocated for swapin, to the swapcache before charging the page. This is fine but now we want a per-memcg swapcache stat which is essential for folks who wants to transparently migrate from cgroup v1's memsw to cgroup v2's memory and swap counters. In addition charging a page before exposing it to other parts of the kernel is a step in the right direction.
To correctly maintain the per-memcg swapcache stat, this patch has adopted to charge the page before adding it to swapcache. One challenge in this option is the failure case of add_to_swap_cache() on which we need to undo the mem_cgroup_charge(). Specifically undoing mem_cgroup_uncharge_swap() is not simple.
To resolve the issue, this patch decouples the charging for swapin pages from mem_cgroup_charge(). Two new functions are introduced, mem_cgroup_swapin_charge_page() for just charging the swapin page and mem_cgroup_swapin_uncharge_swap() for uncharging the swap slot once the page has been successfully added to the swapcache.
---
include/linux/memcontrol.h | 13 +++ mm/memcontrol.c | 119 ++++++++++++++++++++++------------- mm/memory.c | 16 ++-- mm/swap_state.c | 13 +-- 4 files changed, 101 insertions(+), 60 deletions(-)
include/linux/memcontrol.h renamed from include/linux/memcontrol.h~memcg-charge-before-adding-to-swapcache-on-swapin +13 -0
@@ -609,6 +609,9 @@ static inline bool mem_cgroup_below_min( }int mem_cgroup_charge (struct page *page,struct mm_struct *mm,gfp_t gfp_mask); +int mem_cgroup_swapin_charge_page (struct page *page,struct mm_struct *mm, +gfp_t gfp,swp_entry_t entry); +void mem_cgroup_swapin_uncharge_swap (swp_entry_t entry);void mem_cgroup_uncharge (struct page *page);void mem_cgroup_uncharge_list (struct list_head *page_list);
@@ -1112,6 +1115,16 @@ static inline int mem_cgroup_charge(strureturn 0 ; } +static inline int mem_cgroup_swapin_charge_page (struct page *page, +struct mm_struct *mm,gfp_t gfp,swp_entry_t entry) +{ +return 0 ; +} + +static inline void mem_cgroup_swapin_uncharge_swap (swp_entry_t entry) +{ +} +static inline void mem_cgroup_uncharge (struct page *page) { }
mm/memcontrol.c renamed from mm/memcontrol.c~memcg-charge-before-adding-to-swapcache-on-swapin +75 -44
156 lines not on this page · raw message
mm/memory.c renamed from mm/memory.c~memcg-charge-before-adding-to-swapcache-on-swapin +7 -9
@@ -3309,28 +3309,26 @@ vm_fault_t do_swap_page(struct vm_fault page =alloc_page_vma (GFP_HIGHUSER_MOVABLE , vma, vmf->address);if (page) { -int err; -__SetPageLocked (page);__SetPageSwapBacked (page); -set_page_private (page, entry.val); -/* Tell memcg to use swap ownership records */ -SetPageSwapCache (page); - err =mem_cgroup_charge (page, vma->vm_mm, -GFP_KERNEL ); -ClearPageSwapCache (page); -if (err) { +if (mem_cgroup_swapin_charge_page (page, + vma->vm_mm,GFP_KERNEL , entry)) { ret =VM_FAULT_OOM ; goto out_page; } +mem_cgroup_swapin_uncharge_swap (entry); shadow =get_shadow_from_swap_cache (entry);if (shadow)workingset_refault (page, shadow);lru_cache_add (page); + +/* To provide entry to swap_readpage() */ +set_page_private (page, entry.val);swap_readpage (page, true); +set_page_private (page,0 ); } }else { page = swapin_readahead(entry, GFP_HIGHUSER_MOVABLE,
mm/swap_state.c renamed from mm/swap_state.c~memcg-charge-before-adding-to-swapcache-on-swapin +6 -7
@@ -497,16 +497,14 @@ struct page *__read_swap_cache_async(swp__SetPageLocked (page);__SetPageSwapBacked (page); -/* May fail (-ENOMEM) if XArray node allocation failed. */ -if (add_to_swap_cache (page, entry, gfp_mask &GFP_RECLAIM_MASK , &shadow)) { -put_swap_page (page, entry); +if (mem_cgroup_swapin_charge_page (page,NULL , gfp_mask, entry)) goto fail_unlock; - } -if (mem_cgroup_charge (page,NULL , gfp_mask)) { -delete_from_swap_cache (page); +/* May fail (-ENOMEM) if XArray node allocation failed. */ +if (add_to_swap_cache (page, entry, gfp_mask &GFP_RECLAIM_MASK , &shadow)) goto fail_unlock; - } + +mem_cgroup_swapin_uncharge_swap (entry);if (shadow)workingset_refault (page, shadow);
@@ -517,6 +515,7 @@ struct page *__read_swap_cache_async(swpreturn page; fail_unlock: +put_swap_page (page, entry);unlock_page (page);put_page (page);return NULL ;
_
Andrew Morton
maintainerPATCH 68/178 mm: memcontrol: slab: fix obtain a reference to a freeing memcg
In reply to Andrew MortonFrom: Muchun Song <[email protected]>
Subject: mm: memcontrol: slab: fix obtain a reference to a freeing memcg
Patch series "Use obj_cgroup APIs to charge kmem pages", v5.
Since Roman's series "The new cgroup slab memory controller" applied. All slab objects are charged with the new APIs of obj_cgroup. The new APIs introduce a struct obj_cgroup to charge slab objects. It prevents long-living objects from pinning the original memory cgroup in the memory. But there are still some corner objects (e.g. allocations larger than order-1 page on SLUB) which are not charged with the new APIs. Those objects (include the pages which are allocated from buddy allocator directly) are charged as kmem pages which still hold a reference to the memory cgroup.
E.g. We know that the kernel stack is charged as kmem pages because the size of the kernel stack can be greater than 2 pages (e.g. 16KB on x86_64 or arm64). If we create a thread (suppose the thread stack is charged to memory cgroup A) and then move it from memory cgroup A to memory cgroup B. Because the kernel stack of the thread hold a reference to the memory cgroup A. The thread can pin the memory cgroup A in the memory even if we remove the cgroup A. If we want to see this scenario by using the following script. We can see that the system has added 500 dying cgroups (This is not a real world issue, just a script to show that the large kmallocs are charged as kmem pages which can pin the memory cgroup in the memory).
#!/bin/bash
cat /proc/cgroups | grep memory
cd /sys/fs/cgroup/memory
echo 1 > memory.move_charge_at_immigrate
for i in range{1..500}
do
mkdir kmem_test
echo $$ > kmem_test/cgroup.procs
sleep 3600 &
echo $$ > cgroup.procs
echo cat kmem_test/cgroup.procs > cgroup.procs rmdir kmem_test
done
cat /proc/cgroups | grep memory
This patchset aims to make those kmem pages to drop the reference to memory cgroup by using the APIs of obj_cgroup. Finally, we can see that the number of the dying cgroups will not increase if we run the above test script.
This patch (of 7):
The rcu_read_lock/unlock only can guarantee that the memcg will not be freed, but it cannot guarantee the success of css_get (which is in the refill_stock when cached memcg changed) to memcg.
rcu_read_lock()
memcg = obj_cgroup_memcg(old)
__memcg_kmem_uncharge(memcg)
refill_stock(memcg)
if (stock->cached != memcg)
// css_get can change the ref counter from 0 back to 1.
css_get(&memcg->css) rcu_read_unlock()
This fix is very like the commit:
eefbfa7fd678 ("mm: memcg/slab: fix use after free in obj_cgroup_charge")
Fix this by holding a reference to the memcg which is passed to the __memcg_kmem_uncharge() before calling __memcg_kmem_uncharge().
---
mm/memcontrol.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
mm/memcontrol.c renamed from mm/memcontrol.c~mm-memcontrol-slab-fix-obtain-a-reference-to-a-freeing-memcg +9 -1
@@ -3150,9 +3150,17 @@ static void drain_obj_stock(struct memcgunsigned int nr_bytes = stock->nr_bytes & (PAGE_SIZE -1 );if (nr_pages) { +struct mem_cgroup *memcg; +rcu_read_lock (); -__memcg_kmem_uncharge (obj_cgroup_memcg (old), nr_pages); +retry: + memcg =obj_cgroup_memcg (old); +if (unlikely (!css_tryget (&memcg->css))) + goto retry;rcu_read_unlock (); + +__memcg_kmem_uncharge (memcg, nr_pages); +css_put (&memcg->css); }/*
_
Andrew Morton
maintainerPATCH 69/178 mm: memcontrol: introduce obj_cgroup_{un}charge_pages
In reply to Andrew MortonFrom: Muchun Song <[email protected]>
Subject: mm: memcontrol: introduce obj_cgroup_{un}charge_pages
We know that the unit of slab object charging is bytes, the unit of kmem page charging is PAGE_SIZE. If we want to reuse obj_cgroup APIs to charge the kmem pages, we should pass PAGE_SIZE (as third parameter) to obj_cgroup_charge(). Because the size is already PAGE_SIZE, we can skip touch the objcg stock. And obj_cgroup_{un}charge_pages() are introduced to charge in units of page level.
In the latter patch, we also can reuse those two helpers to charge or uncharge a number of kernel pages to a object cgroup. This is just a code movement without any functional changes.
---
mm/memcontrol.c | 63 +++++++++++++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 23 deletions(-)
mm/memcontrol.c renamed from mm/memcontrol.c~mm-memcontrol-introduce-obj_cgroup_uncharge_pages +40 -23
@@ -2874,6 +2874,20 @@ static void commit_charge(struct page *p page->memcg_data = (unsigned long )memcg; } +static struct mem_cgroup *get_mem_cgroup_from_objcg (struct obj_cgroup *objcg) +{ +struct mem_cgroup *memcg; + +rcu_read_lock (); +retry: + memcg =obj_cgroup_memcg (objcg); +if (unlikely (!css_tryget (&memcg->css))) + goto retry; +rcu_read_unlock (); + +return memcg; +} +#ifdef CONFIG_MEMCG_KMEM int memcg_alloc_page_obj_cgroups (struct page *page,struct kmem_cache *s,gfp_t gfp,bool new_page)
@@ -3025,6 +3039,29 @@ static void memcg_free_cache_id(int id)ida_simple_remove (&memcg_cache_ida, id); } +static void obj_cgroup_uncharge_pages (struct obj_cgroup *objcg, +unsigned int nr_pages) +{ +struct mem_cgroup *memcg; + + memcg =get_mem_cgroup_from_objcg (objcg); +__memcg_kmem_uncharge (memcg, nr_pages); +css_put (&memcg->css); +} + +static int obj_cgroup_charge_pages (struct obj_cgroup *objcg,gfp_t gfp, +unsigned int nr_pages) +{ +struct mem_cgroup *memcg; +int ret; + + memcg =get_mem_cgroup_from_objcg (objcg); + ret =__memcg_kmem_charge (memcg, gfp, nr_pages); +css_put (&memcg->css); + +return ret; +} +/** * __memcg_kmem_charge: charge a number of kernel pages to a memcg * @memcg: memory cgroup to charge
@@ -3149,19 +3186,8 @@ static void drain_obj_stock(struct memcgunsigned int nr_pages = stock->nr_bytes >>PAGE_SHIFT ;unsigned int nr_bytes = stock->nr_bytes & (PAGE_SIZE -1 ); -if (nr_pages) { -struct mem_cgroup *memcg; - -rcu_read_lock (); -retry: - memcg =obj_cgroup_memcg (old); -if (unlikely (!css_tryget (&memcg->css))) - goto retry; -rcu_read_unlock (); - -__memcg_kmem_uncharge (memcg, nr_pages); -css_put (&memcg->css); - } +if (nr_pages) +obj_cgroup_uncharge_pages (old, nr_pages);/* * The leftover is flushed to the centralized per-memcg value.
@@ -3219,7 +3245,6 @@ static void refill_obj_stock(struct obj_int obj_cgroup_charge (struct obj_cgroup *objcg,gfp_t gfp,size_t size) { -struct mem_cgroup *memcg;unsigned int nr_pages, nr_bytes;int ret;
@@ -3236,24 +3261,16 @@ int obj_cgroup_charge(struct obj_cgroup* refill_obj_stock(), called from this function or * independently later. */ -rcu_read_lock (); -retry: - memcg =obj_cgroup_memcg (objcg); -if (unlikely (!css_tryget (&memcg->css))) - goto retry; -rcu_read_unlock (); - nr_pages = size >>PAGE_SHIFT ; nr_bytes = size & (PAGE_SIZE -1 );if (nr_bytes) nr_pages +=1 ; - ret =__memcg_kmem_charge (memcg, gfp, nr_pages); + ret =obj_cgroup_charge_pages (objcg, gfp, nr_pages);if (!ret && nr_bytes)refill_obj_stock (objcg,PAGE_SIZE - nr_bytes); -css_put (&memcg->css);return ret; }
_
Andrew Morton
maintainerPATCH 70/178 mm: memcontrol: directly access page->memcg_data in mm/page_alloc.c
In reply to Andrew MortonFrom: Muchun Song <[email protected]>
Subject: mm: memcontrol: directly access page->memcg_data in mm/page_alloc.c
page_memcg() is not suitable for use by page_expected_state() and page_bad_reason(). Because it can BUG_ON() for the slab pages when CONFIG_DEBUG_VM is enabled. As neither lru, nor kmem, nor slab page should have anything left in there by the time the page is freed, what we care about is whether the value of page->memcg_data is 0. So just directly access page->memcg_data here.
---
mm/page_alloc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
mm/page_alloc.c renamed from mm/page_alloc.c~mm-memcontrol-directly-access-page-memcg_data-in-mm-page_allocc +2 -2
@@ -1103,7 +1103,7 @@ static inline bool page_expected_state(sif (unlikely ((unsigned long )page->mapping |page_ref_count (page) | #ifdef CONFIG_MEMCG - (unsigned long)page_memcg(page) | + page->memcg_data | #endif (page->flags & check_flags)))return false;
@@ -1128,7 +1128,7 @@ static const char *page_bad_reason(struc bad_reason ="PAGE_FLAGS_CHECK_AT_FREE flag(s) set" ; }#ifdef CONFIG_MEMCG -if (unlikely (page_memcg (page))) +if (unlikely (page->memcg_data)) bad_reason ="page still charged to cgroup" ;#endif return bad_reason;
_
Andrew Morton
maintainerPATCH 71/178 mm: memcontrol: change ug->dummy_page only if memcg changed
In reply to Andrew MortonFrom: Muchun Song <[email protected]>
Subject: mm: memcontrol: change ug->dummy_page only if memcg changed
Just like assignment to ug->memcg, we only need to update ug->dummy_page if memcg changed. So move it to there. This is a very small optimization.
---
mm/memcontrol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/memcontrol.c renamed from mm/memcontrol.c~mm-memcontrol-change-ug-dummy_page-only-if-memcg-changed +1 -1
@@ -6843,6 +6843,7 @@ static void uncharge_page(struct page *puncharge_gather_clear (ug); } ug->memcg =page_memcg (page); + ug->dummy_page = page;/* pairs with css_put in uncharge_batch */ css_get (&ug->memcg->css);
@@ -6856,7 +6857,6 @@ static void uncharge_page(struct page *pelse ug->pgpgout++; - ug->dummy_page = page; page->memcg_data =0 ;css_put (&ug->memcg->css); }
_
Andrew Morton
maintainerPATCH 72/178 mm: memcontrol: use obj_cgroup APIs to charge kmem pages
In reply to Andrew MortonFrom: Muchun Song <[email protected]>
Subject: mm: memcontrol: use obj_cgroup APIs to charge kmem pages
Since Roman's series "The new cgroup slab memory controller" applied. All slab objects are charged via the new APIs of obj_cgroup. The new APIs introduce a struct obj_cgroup to charge slab objects. It prevents long-living objects from pinning the original memory cgroup in the memory. But there are still some corner objects (e.g. allocations larger than order-1 page on SLUB) which are not charged via the new APIs. Those objects (include the pages which are allocated from buddy allocator directly) are charged as kmem pages which still hold a reference to the memory cgroup.
We want to reuse the obj_cgroup APIs to charge the kmem pages. If we do that, we should store an object cgroup pointer to page->memcg_data for the kmem pages.
Finally, page->memcg_data will have 3 different meanings.
1) For the slab pages, page->memcg_data points to an object cgroups vector.
2) For the kmem pages (exclude the slab pages), page->memcg_data points to an object cgroup.
3) For the user pages (e.g. the LRU pages), page->memcg_data points to a memory cgroup.
We do not change the behavior of page_memcg() and page_memcg_rcu(). They are also suitable for LRU pages and kmem pages. Why?
Because memory allocations pinning memcgs for a long time - it exists at a larger scale and is causing recurring problems in the real world: page cache doesn't get reclaimed for a long time, or is used by the second, third, fourth, ... instance of the same job that was restarted into a new cgroup every time. Unreclaimable dying cgroups pile up, waste memory, and make page reclaim very inefficient.
We can convert LRU pages and most other raw memcg pins to the objcg direction to fix this problem, and then the page->memcg will always point to an object cgroup pointer. At that time, LRU pages and kmem pages will be treated the same. The implementation of page_memcg() will remove the kmem page check.
This patch aims to charge the kmem pages by using the new APIs of obj_cgroup. Finally, the page->memcg_data of the kmem page points to an object cgroup. We can use the __page_objcg() to get the object cgroup associated with a kmem page. Or we can use page_memcg() to get the memory cgroup associated with a kmem page, but caller must ensure that the returned memcg won't be released (e.g. acquire the rcu_read_lock or css_set_lock).
---
include/linux/memcontrol.h | 120 ++++++++++++++++++++++++++++------- mm/memcontrol.c | 116 ++++++++++++++++----------------- 2 files changed, 155 insertions(+), 81 deletions(-)
include/linux/memcontrol.h renamed from include/linux/memcontrol.h~mm-memcontrol-use-obj_cgroup-apis-to-charge-kmem-pages +97 -23
@@ -371,6 +371,62 @@ enum page_memcg_data_flags {#define MEMCG_DATA_FLAGS_MASK (__NR_MEMCG_DATA_FLAGS - 1) +static inline bool PageMemcgKmem (struct page *page); + +/* +* After the initialization objcg->memcg is always pointing at +* a valid memcg, but can be atomically swapped to the parent memcg. +* +* The caller must ensure that the returned memcg won't be released: +* e.g. acquire the rcu_read_lock or css_set_lock. +*/ +static inline struct mem_cgroup *obj_cgroup_memcg (struct obj_cgroup *objcg) +{ +return READ_ONCE (objcg->memcg); +} + +/* +* __page_memcg - get the memory cgroup associated with a non-kmem page +* @page: a pointer to the page struct +* +* Returns a pointer to the memory cgroup associated with the page, +* or NULL. This function assumes that the page is known to have a +* proper memory cgroup pointer. It's not safe to call this function +* against some type of pages, e.g. slab pages or ex-slab pages or +* kmem pages. +*/ +static inline struct mem_cgroup *__page_memcg (struct page *page) +{ +unsigned long memcg_data = page->memcg_data; + +VM_BUG_ON_PAGE (PageSlab (page), page); +VM_BUG_ON_PAGE (memcg_data &MEMCG_DATA_OBJCGS , page); +VM_BUG_ON_PAGE (memcg_data &MEMCG_DATA_KMEM , page); + +return (struct mem_cgroup *)(memcg_data & ~MEMCG_DATA_FLAGS_MASK ); +} + +/* +* __page_objcg - get the object cgroup associated with a kmem page +* @page: a pointer to the page struct +* +* Returns a pointer to the object cgroup associated with the page, +* or NULL. This function assumes that the page is known to have a +* proper object cgroup pointer. It's not safe to call this function +* against some type of pages, e.g. slab pages or ex-slab pages or +* LRU pages. +*/ +static inline struct obj_cgroup *__page_objcg (struct page *page) +{ +unsigned long memcg_data = page->memcg_data; + +VM_BUG_ON_PAGE (PageSlab (page), page); +VM_BUG_ON_PAGE (memcg_data &MEMCG_DATA_OBJCGS , page); +VM_BUG_ON_PAGE (!(memcg_data &MEMCG_DATA_KMEM ), page); + +return (struct obj_cgroup *)(memcg_data & ~MEMCG_DATA_FLAGS_MASK ); +} +/* * page_memcg - get the memory cgroup associated with a page * @page: a pointer to the page struct
@@ -380,20 +436,23 @@ enum page_memcg_data_flags {* proper memory cgroup pointer. It's not safe to call this function * against some type of pages, e.g. slab pages or ex-slab pages. * -* Any of the following ensures page and memcg binding stability: +* For a non-kmem page any of the following ensures page and memcg binding +* stability: +* * - the page lock * - LRU isolation * - lock_page_memcg() * - exclusive reference +* +* For a kmem page a caller should hold an rcu read lock to protect memcg +* associated with a kmem page from being released. */ static inline struct mem_cgroup *page_memcg (struct page *page) { -unsigned long memcg_data = page->memcg_data; - -VM_BUG_ON_PAGE (PageSlab (page), page); -VM_BUG_ON_PAGE (memcg_data &MEMCG_DATA_OBJCGS , page); - -return (struct mem_cgroup *)(memcg_data & ~MEMCG_DATA_FLAGS_MASK ); +if (PageMemcgKmem (page)) +return obj_cgroup_memcg (__page_objcg (page)); +else +return __page_memcg (page); }/*
@@ -407,11 +466,19 @@ static inline struct mem_cgroup *page_me*/ static inline struct mem_cgroup *page_memcg_rcu (struct page *page) { +unsigned long memcg_data =READ_ONCE (page->memcg_data); +VM_BUG_ON_PAGE (PageSlab (page), page);WARN_ON_ONCE (!rcu_read_lock_held ()); -return (struct mem_cgroup *)(READ_ONCE (page->memcg_data) & - ~MEMCG_DATA_FLAGS_MASK ); +if (memcg_data &MEMCG_DATA_KMEM ) { +struct obj_cgroup *objcg; + + objcg = (void *)(memcg_data & ~MEMCG_DATA_FLAGS_MASK ); +return obj_cgroup_memcg (objcg); + } + +return (struct mem_cgroup *)(memcg_data & ~MEMCG_DATA_FLAGS_MASK ); }/*
@@ -419,15 +486,21 @@ static inline struct mem_cgroup *page_me* @page: a pointer to the page struct * * Returns a pointer to the memory cgroup associated with the page, -* or NULL. This function unlike page_memcg() can take any page +* or NULL. This function unlike page_memcg() can take any page * as an argument. It has to be used in cases when it's not known if a page -* has an associated memory cgroup pointer or an object cgroups vector. +* has an associated memory cgroup pointer or an object cgroups vector or +* an object cgroup. +* +* For a non-kmem page any of the following ensures page and memcg binding +* stability: * -* Any of the following ensures page and memcg binding stability: * - the page lock * - LRU isolation * - lock_page_memcg() * - exclusive reference +* +* For a kmem page a caller should hold an rcu read lock to protect memcg +* associated with a kmem page from being released. */ static inline struct mem_cgroup *page_memcg_check (struct page *page) {
@@ -440,6 +513,13 @@ static inline struct mem_cgroup *page_meif (memcg_data &MEMCG_DATA_OBJCGS )return NULL ; +if (memcg_data &MEMCG_DATA_KMEM ) { +struct obj_cgroup *objcg; + + objcg = (void *)(memcg_data & ~MEMCG_DATA_FLAGS_MASK ); +return obj_cgroup_memcg (objcg); + } +return (struct mem_cgroup *)(memcg_data & ~MEMCG_DATA_FLAGS_MASK ); }
@@ -718,21 +798,15 @@ static inline void obj_cgroup_get(structpercpu_ref_get (&objcg->refcnt); } -static inline void obj_cgroup_put (struct obj_cgroup *objcg) +static inline void obj_cgroup_get_many (struct obj_cgroup *objcg, +unsigned long nr) { -percpu_ref_put (&objcg->refcnt); +percpu_ref_get_many (&objcg->refcnt, nr); } -/* -* After the initialization objcg->memcg is always pointing at -* a valid memcg, but can be atomically swapped to the parent memcg. -* -* The caller must ensure that the returned memcg won't be released: -* e.g. acquire the rcu_read_lock or css_set_lock. -*/ -static inline struct mem_cgroup *obj_cgroup_memcg (struct obj_cgroup *objcg) +static inline void obj_cgroup_put (struct obj_cgroup *objcg) { -return READ_ONCE (objcg->memcg); +percpu_ref_put (&objcg->refcnt); }static inline void mem_cgroup_put (struct mem_cgroup *memcg)
mm/memcontrol.c renamed from mm/memcontrol.c~mm-memcontrol-use-obj_cgroup-apis-to-charge-kmem-pages +58 -58
221 lines not on this page · raw message
_
Andrew Morton
maintainerPATCH 73/178 mm: memcontrol: inline __memcg_kmem_{un}charge() into obj_cgroup_{un}charge_pages()
In reply to Andrew MortonFrom: Muchun Song <[email protected]>
Subject: mm: memcontrol: inline __memcg_kmem_{un}charge() into obj_cgroup_{un}charge_pages()
There is only one user of __memcg_kmem_charge(), so manually inline __memcg_kmem_charge() to obj_cgroup_charge_pages(). Similarly manually inline __memcg_kmem_uncharge() into obj_cgroup_uncharge_pages() and call obj_cgroup_uncharge_pages() in obj_cgroup_release().
This is just code cleanup without any functionality changes.
---
mm/memcontrol.c | 63 ++++++++++++++++++---------------------------- 1 file changed, 25 insertions(+), 38 deletions(-)
mm/memcontrol.c renamed from mm/memcontrol.c~mm-memcontrol-inline-__memcg_kmem_uncharge-into-obj_cgroup_uncharge_pages +25 -38
@@ -255,10 +255,8 @@ struct cgroup_subsys_state *vmpressure_t#ifdef CONFIG_MEMCG_KMEM extern spinlock_t css_set_lock; -static int __memcg_kmem_charge (struct mem_cgroup *memcg,gfp_t gfp, -unsigned int nr_pages); -static void __memcg_kmem_uncharge (struct mem_cgroup *memcg, -unsigned int nr_pages); +static void obj_cgroup_uncharge_pages (struct obj_cgroup *objcg, +unsigned int nr_pages);static void obj_cgroup_release (struct percpu_ref *ref) {
@@ -295,7 +293,7 @@ static void obj_cgroup_release(struct pespin_lock_irqsave (&css_set_lock, flags); memcg =obj_cgroup_memcg (objcg);if (nr_pages) -__memcg_kmem_uncharge (memcg, nr_pages); +obj_cgroup_uncharge_pages (objcg, nr_pages);list_del (&objcg->list);mem_cgroup_put (memcg);spin_unlock_irqrestore (&css_set_lock, flags);
@@ -3015,46 +3013,45 @@ static void memcg_free_cache_id(int id)ida_simple_remove (&memcg_cache_ida, id); } +/* +* obj_cgroup_uncharge_pages: uncharge a number of kernel pages from a objcg +* @objcg: object cgroup to uncharge +* @nr_pages: number of pages to uncharge +*/ static void obj_cgroup_uncharge_pages (struct obj_cgroup *objcg,unsigned int nr_pages) {struct mem_cgroup *memcg; memcg =get_mem_cgroup_from_objcg (objcg); -__memcg_kmem_uncharge (memcg, nr_pages); -css_put (&memcg->css); -} -static int obj_cgroup_charge_pages (struct obj_cgroup *objcg,gfp_t gfp, -unsigned int nr_pages) -{ -struct mem_cgroup *memcg; -int ret; +if (!cgroup_subsys_on_dfl (memory_cgrp_subsys)) +page_counter_uncharge (&memcg->kmem, nr_pages); +refill_stock (memcg, nr_pages); - memcg =get_mem_cgroup_from_objcg (objcg); - ret =__memcg_kmem_charge (memcg, gfp, nr_pages);css_put (&memcg->css); - -return ret; } -/** -* __memcg_kmem_charge: charge a number of kernel pages to a memcg -* @memcg: memory cgroup to charge +/* +* obj_cgroup_charge_pages: charge a number of kernel pages to a objcg +* @objcg: object cgroup to charge * @gfp: reclaim mode * @nr_pages: number of pages to charge * * Returns 0 on success, an error code on failure. */ -static int __memcg_kmem_charge (struct mem_cgroup *memcg,gfp_t gfp, -unsigned int nr_pages) +static int obj_cgroup_charge_pages (struct obj_cgroup *objcg,gfp_t gfp, +unsigned int nr_pages) {struct page_counter *counter; +struct mem_cgroup *memcg;int ret; + memcg =get_mem_cgroup_from_objcg (objcg); + ret =try_charge (memcg, gfp, nr_pages);if (ret) -return ret; + goto out;if (!cgroup_subsys_on_dfl (memory_cgrp_subsys) && !page_counter_try_charge (&memcg->kmem, nr_pages, &counter)) {
@@ -3066,25 +3063,15 @@ static int __memcg_kmem_charge(struct me*/ if (gfp & __GFP_NOFAIL) {page_counter_charge (&memcg->kmem, nr_pages); -return 0 ; + goto out; }cancel_charge (memcg, nr_pages); -return -ENOMEM ; + ret = -ENOMEM ; } -return 0 ; -} - -/** -* __memcg_kmem_uncharge: uncharge a number of kernel pages from a memcg -* @memcg: memcg to uncharge -* @nr_pages: number of pages to uncharge -*/ -static void __memcg_kmem_uncharge (struct mem_cgroup *memcg,unsigned int nr_pages) -{ -if (!cgroup_subsys_on_dfl (memory_cgrp_subsys)) -page_counter_uncharge (&memcg->kmem, nr_pages); +out: +css_put (&memcg->css); -refill_stock (memcg, nr_pages); +return ret; }/**
_
Andrew Morton
maintainerPATCH 74/178 mm: memcontrol: move PageMemcgKmem to the scope of CONFIG_MEMCG_KMEM
In reply to Andrew MortonFrom: Muchun Song <[email protected]>
Subject: mm: memcontrol: move PageMemcgKmem to the scope of CONFIG_MEMCG_KMEM
The page only can be marked as kmem when CONFIG_MEMCG_KMEM is enabled. So move PageMemcgKmem() to the scope of the CONFIG_MEMCG_KMEM.
As a bonus, on !CONFIG_MEMCG_KMEM build some code can be compiled out.
---
include/linux/memcontrol.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
include/linux/memcontrol.h renamed from include/linux/memcontrol.h~mm-memcontrol-move-pagememcgkmem-to-the-scope-of-config_memcg_kmem +6 -1
@@ -523,6 +523,7 @@ static inline struct mem_cgroup *page_mereturn (struct mem_cgroup *)(memcg_data & ~MEMCG_DATA_FLAGS_MASK ); } +#ifdef CONFIG_MEMCG_KMEM /* * PageMemcgKmem - check if the page has MemcgKmem flag set * @page: a pointer to the page struct
@@ -537,7 +538,6 @@ static inline bool PageMemcgKmem(structreturn page->memcg_data &MEMCG_DATA_KMEM ; } -#ifdef CONFIG_MEMCG_KMEM /* * page_objcgs - get the object cgroups vector associated with a page * @page: a pointer to the page struct
@@ -579,6 +579,11 @@ static inline struct obj_cgroup **page_o }#else +static inline bool PageMemcgKmem (struct page *page) +{ +return false; +} +static inline struct obj_cgroup **page_objcgs (struct page *page) {return NULL ;
_
Andrew Morton
maintainerPATCH 75/178 linux/memcontrol.h: remove duplicate struct declaration
In reply to Andrew MortonFrom: Wan Jiabing <[email protected]>
Subject: linux/memcontrol.h: remove duplicate struct declaration
struct mem_cgroup is declared twice. One has been declared at forward struct declaration. Remove the duplicate.
---
include/linux/memcontrol.h | 2 -- 1 file changed, 2 deletions(-)
include/linux/memcontrol.h renamed from include/linux/memcontrol.h~linux-memcontrolh-remove-duplicate-struct-declaration +0 -2
@@ -1123,8 +1123,6 @@ unsigned long mem_cgroup_soft_limit_recl#define MEM_CGROUP_ID_SHIFT 0#define MEM_CGROUP_ID_MAX 0 -struct mem_cgroup ; -static inline struct mem_cgroup *page_memcg (struct page *page) {return NULL ;
_
Andrew Morton
maintainerPATCH 76/178 mm: page_counter: mitigate consequences of a page_counter underflow
In reply to Andrew MortonFrom: Johannes Weiner <[email protected]>
Subject: mm: page_counter: mitigate consequences of a page_counter underflow
When the unsigned page_counter underflows, even just by a few pages, a cgroup will not be able to run anything afterwards and trigger the OOM killer in a loop.
Underflows shouldn't happen, but when they do in practice, we may just be off by a small amount that doesn't interfere with the normal operation - consequences don't need to be that dire.
Reset the page_counter to 0 upon underflow. We'll issue a warning that the accounting will be off and then try to keep limping along.
[ We used to do this with the original res_counter, where it was a
more straight-forward correction inside the spinlock section. I didn't carry it forward into the lockless page counters for simplicity, but it turns out this is quite useful in practice. ]
---
mm/page_counter.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
mm/page_counter.c renamed from mm/page_counter.c~mm-page_counter-mitigate-consequences-of-a-page_counter-underflow +6 -2
@@ -52,9 +52,13 @@ void page_counter_cancel(struct page_coulong new; new =atomic_long_sub_return (nr_pages, &counter->usage); -propagate_protected_usage (counter, new);/* More uncharges than charges? */ -WARN_ON_ONCE (new <0 ); +if (WARN_ONCE (new <0 ,"page_counter underflow: %ld nr_pages=%lu\n" , + new, nr_pages)) { + new =0 ; +atomic_long_set (&counter->usage, new); + } +propagate_protected_usage (counter, new); }/**
_
Andrew Morton
maintainerPATCH 77/178 mm/memory.c: do_numa_page(): delete bool "migrated"
In reply to Andrew MortonFrom: Wang Qing <[email protected]>
Subject: mm/memory.c: do_numa_page(): delete bool "migrated"
Smatch gives the warning:
do_numa_page() warn: assigning (-11) to unsigned variable 'migrated'
---
mm/memory.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
mm/memory.c renamed from mm/memory.c~mm-delete-bool-migrated +1 -3
@@ -4098,7 +4098,6 @@ static vm_fault_t do_numa_page(struct vmint page_nid =NUMA_NO_NODE ;int last_cpupid;int target_nid; -bool migrated = false;pte_t pte, old_pte;bool was_writable =pte_savedwrite (vmf->orig_pte);int flags =0 ;
@@ -4168,8 +4167,7 @@ static vm_fault_t do_numa_page(struct vm }/* Migrate to the requested node */ - migrated =migrate_misplaced_page (page, vma, target_nid); -if (migrated) { +if (migrate_misplaced_page (page, vma, target_nid)) { page_nid = target_nid; flags |=TNF_MIGRATED ; }else
_
Andrew Morton
maintainerPATCH 78/178 mm/interval_tree: add comments to improve code readability
In reply to Andrew MortonFrom: Zhiyuan Dai <[email protected]>
Subject: mm/interval_tree: add comments to improve code readability
Add a comment explaining the value of the ISSTATIC parameter, Inform the reader that this is not a coding style issue.
---
mm/interval_tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/interval_tree.c renamed from mm/interval_tree.c~mm-interval_tree-add-comments-to-improve-code-reading +1 -1
@@ -22,7 +22,7 @@ static inline unsigned long vma_last_pgo INTERVAL_TREE_DEFINE(struct vm_area_struct, shared.rb, unsigned long, shared.rb_subtree_last, - vma_start_pgoff, vma_last_pgoff,, vma_interval_tree) + vma_start_pgoff, vma_last_pgoff, /* empty */, vma_interval_tree)/* Insert node immediately after prev in the interval tree */ void vma_interval_tree_insert_after(struct vm_area_struct *node,
_
Andrew Morton
maintainerPATCH 79/178 x86/vmemmap: drop handling of 4K unaligned vmemmap range
In reply to Andrew MortonFrom: Oscar Salvador <[email protected]>
Subject: x86/vmemmap: drop handling of 4K unaligned vmemmap range
Patch series "Cleanup and fixups for vmemmap handling", v6.
This series contains cleanups to remove dead code that handles unaligned cases for 4K and 1GB pages (patch#1 and patch#2) when removing the vemmmap range, and a fix (patch#3) to handle the case when two vmemmap ranges intersect the same PMD.
This patch (of 4):
remove_pte_table() is prepared to handle the case where either the start or the end of the range is not PAGE aligned. This cannot actually happen:
__populate_section_memmap enforces the range to be PMD aligned, so as long as the size of the struct page remains multiple of 8, the vmemmap range will be aligned to PAGE_SIZE.
Drop the dead code and place a VM_BUG_ON in vmemmap_{populate,free} to catch nasty cases. Note that the VM_BUG_ON is placed in there because vmemmap_{populate,free= } is the gate of all removing and freeing page tables logic.
---
arch/x86/mm/init_64.c | 50 +++++++++++----------------------------- 1 file changed, 14 insertions(+), 36 deletions(-)
arch/x86/mm/init_64.c renamed from arch/x86/mm/init_64.c~x86-vmemmap-drop-handling-of-4k-unaligned-vmemmap-range +14 -36
@@ -962,7 +962,6 @@ remove_pte_table(pte_t *pte_start, unsig {unsigned long next, pages =0 ;pte_t *pte; -void *page_addr;phys_addr_t phys_addr; pte = pte_start +pte_index (addr);
@@ -983,42 +982,15 @@ remove_pte_table(pte_t *pte_start, unsigif (phys_addr < (phys_addr_t )0x40000000 )return ; -if (PAGE_ALIGNED (addr) &&PAGE_ALIGNED (next)) { -/* -* Do not free direct mapping pages since they were -* freed when offlining, or simply not in use. -*/ -if (!direct) -free_pagetable (pte_page (*pte),0 ); - -spin_lock (&init_mm.page_table_lock); -pte_clear (&init_mm, addr, pte); -spin_unlock (&init_mm.page_table_lock); - -/* For non-direct mapping, pages means nothing. */ - pages++; - }else { -/* -* If we are here, we are freeing vmemmap pages since -* direct mapped memory ranges to be freed are aligned. -* -* If we are not removing the whole page, it means -* other page structs in this page are being used and -* we cannot remove them. So fill the unused page_structs -* with 0xFD, and remove the page when it is wholly -* filled with 0xFD. -*/ -memset ((void *)addr,PAGE_INUSE , next - addr); - - page_addr =page_address (pte_page (*pte)); -if (!memchr_inv (page_addr,PAGE_INUSE ,PAGE_SIZE )) { -free_pagetable (pte_page (*pte),0 ); +if (!direct) +free_pagetable (pte_page (*pte),0 ); -spin_lock (&init_mm.page_table_lock); -pte_clear (&init_mm, addr, pte); -spin_unlock (&init_mm.page_table_lock); - } - } +spin_lock (&init_mm.page_table_lock); +pte_clear (&init_mm, addr, pte); +spin_unlock (&init_mm.page_table_lock); + +/* For non-direct mapping, pages means nothing. */ + pages++; }/* Call free_pte_table() in remove_pmd_table(). */
@@ -1197,6 +1169,9 @@ remove_pagetable(unsigned long start, unvoid __ref vmemmap_free (unsigned long start,unsigned long end,struct vmem_altmap *altmap) { +VM_BUG_ON (!IS_ALIGNED (start,PAGE_SIZE )); +VM_BUG_ON (!IS_ALIGNED (end,PAGE_SIZE )); +remove_pagetable (start, end, false, altmap); }
@@ -1556,6 +1531,9 @@ int __meminit vmemmap_populate(unsigned {int err; +VM_BUG_ON (!IS_ALIGNED (start,PAGE_SIZE )); +VM_BUG_ON (!IS_ALIGNED (end,PAGE_SIZE )); +if (end - start <PAGES_PER_SECTION *sizeof (struct page )) err =vmemmap_populate_basepages (start, end, node,NULL );else if (boot_cpu_has (X86_FEATURE_PSE ))
_
Andrew Morton
maintainerPATCH 80/178 x86/vmemmap: drop handling of 1GB vmemmap ranges
In reply to Andrew MortonFrom: Oscar Salvador <[email protected]>
Subject: x86/vmemmap: drop handling of 1GB vmemmap ranges
There is no code to allocate 1GB pages when mapping the vmemmap range as this might waste some memory and requires more complexity which is not really worth.
Drop the dead code both for the aligned and unaligned cases and leave only the direct map handling.
---
arch/x86/mm/init_64.c | 35 +++++++---------------------------- 1 file changed, 7 insertions(+), 28 deletions(-)
arch/x86/mm/init_64.c renamed from arch/x86/mm/init_64.c~x86-vmemmap-drop-handling-of-1gb-vmemmap-ranges +7 -28
@@ -1062,7 +1062,6 @@ remove_pud_table(pud_t *pud_start, unsigunsigned long next, pages =0 ;pmd_t *pmd_base;pud_t *pud; -void *page_addr; pud = pud_start +pud_index (addr);for (; addr < end; addr = next, pud++) {
@@ -1071,33 +1070,13 @@ remove_pud_table(pud_t *pud_start, unsigif (!pud_present (*pud))continue ; -if (pud_large (*pud)) { -if (IS_ALIGNED (addr,PUD_SIZE ) && -IS_ALIGNED (next,PUD_SIZE )) { -if (!direct) -free_pagetable (pud_page (*pud), -get_order (PUD_SIZE )); - -spin_lock (&init_mm.page_table_lock); -pud_clear (pud); -spin_unlock (&init_mm.page_table_lock); - pages++; - }else { -/* If here, we are freeing vmemmap pages. */ -memset ((void *)addr,PAGE_INUSE , next - addr); - - page_addr =page_address (pud_page (*pud)); -if (!memchr_inv (page_addr,PAGE_INUSE , -PUD_SIZE )) { -free_pagetable (pud_page (*pud), -get_order (PUD_SIZE )); - -spin_lock (&init_mm.page_table_lock); -pud_clear (pud); -spin_unlock (&init_mm.page_table_lock); - } - } - +if (pud_large (*pud) && +IS_ALIGNED (addr,PUD_SIZE ) && +IS_ALIGNED (next,PUD_SIZE )) { +spin_lock (&init_mm.page_table_lock); +pud_clear (pud); +spin_unlock (&init_mm.page_table_lock); + pages++;continue ; }
_
Andrew Morton
maintainerPATCH 81/178 x86/vmemmap: handle unpopulated sub-pmd ranges
In reply to Andrew MortonFrom: Oscar Salvador <[email protected]>
Subject: x86/vmemmap: handle unpopulated sub-pmd ranges
When sizeof(struct page) is not a power of 2, sections do not span a PMD anymore and so when populating them some parts of the PMD will remain unused.
Because of this, PMDs will be left behind when depopulating sections since remove_pmd_table() thinks that those unused parts are still in use.
Fix this by marking the unused parts with PAGE_UNUSED, so memchr_inv() will do the right thing and will let us free the PMD when the last user of it is gone.
This patch is based on a similar patch by David Hildenbrand:
https://lore.kernel.org/linux-mm/[email protected]/
---
arch/x86/mm/init_64.c | 68 ++++++++++++++++++++++++++++++++-------- 1 file changed, 55 insertions(+), 13 deletions(-)
arch/x86/mm/init_64.c renamed from arch/x86/mm/init_64.c~x86-vmemmap-handle-unpopulated-sub-pmd-ranges +55 -13
@@ -826,6 +826,51 @@ void __init paging_init(void)zone_sizes_init (); } +#ifdef CONFIG_SPARSEMEM_VMEMMAP +#define PAGE_UNUSED 0xFD + +/* Returns true if the PMD is completely unused and thus it can be freed */ +static bool __meminit vmemmap_pmd_is_unused (unsigned long addr,unsigned long end) +{ +unsigned long start =ALIGN_DOWN (addr,PMD_SIZE ); + +memset ((void *)addr,PAGE_UNUSED , end - addr); + +return !memchr_inv ((void *)start,PAGE_UNUSED ,PMD_SIZE ); +} + +static void __meminit vmemmap_use_sub_pmd (unsigned long start) +{ +/* +* As we expect to add in the same granularity as we remove, it's +* sufficient to mark only some piece used to block the memmap page from +* getting removed when removing some other adjacent memmap (just in +* case the first memmap never gets initialized e.g., because the memory +* block never gets onlined). +*/ +memset ((void *)start,0 ,sizeof (struct page )); +} + +static void __meminit vmemmap_use_new_sub_pmd (unsigned long start,unsigned long end) +{ +/* +* Could be our memmap page is filled with PAGE_UNUSED already from a +* previous remove. Make sure to reset it. +*/ +vmemmap_use_sub_pmd (start); + +/* +* Mark with PAGE_UNUSED the unused parts of the new memmap range +*/ +if (!IS_ALIGNED (start,PMD_SIZE )) +memset ((void *)start,PAGE_UNUSED , + start -ALIGN_DOWN (start,PMD_SIZE )); +if (!IS_ALIGNED (end,PMD_SIZE )) +memset ((void *)end,PAGE_UNUSED , +ALIGN (end,PMD_SIZE ) - end); +} +#endif +/* * Memory hotplug specific functions */
@@ -871,8 +916,6 @@ int arch_add_memory(int nid, u64 start,return add_pages (nid, start_pfn, nr_pages, params); } -#define PAGE_INUSE 0xFD -static void __meminit free_pagetable (struct page *page,int order) {unsigned long magic;
@@ -1006,7 +1049,6 @@ remove_pmd_table(pmd_t *pmd_start, unsigunsigned long next, pages =0 ;pte_t *pte_base;pmd_t *pmd; -void *page_addr; pmd = pmd_start +pmd_index (addr);for (; addr < end; addr = next, pmd++) {
@@ -1026,22 +1068,16 @@ remove_pmd_table(pmd_t *pmd_start, unsigpmd_clear (pmd);spin_unlock (&init_mm.page_table_lock); pages++; - }else { -/* If here, we are freeing vmemmap pages. */ -memset ((void *)addr,PAGE_INUSE , next - addr); - - page_addr =page_address (pmd_page (*pmd)); -if (!memchr_inv (page_addr,PAGE_INUSE , -PMD_SIZE )) { + } +#ifdef CONFIG_SPARSEMEM_VMEMMAP + else if (vmemmap_pmd_is_unused(addr, next)) {free_hugepage_table (pmd_page (*pmd), altmap); -spin_lock (&init_mm.page_table_lock);pmd_clear (pmd);spin_unlock (&init_mm.page_table_lock); - } } - +#endif continue ; }
@@ -1492,11 +1528,17 @@ static int __meminit vmemmap_populate_hu addr_end = addr +PMD_SIZE ; p_end = p +PMD_SIZE ; + +if (!IS_ALIGNED (addr,PMD_SIZE ) || + !IS_ALIGNED (next,PMD_SIZE )) +vmemmap_use_new_sub_pmd (addr, next); +continue ; }else if (altmap)return -ENOMEM ;/* no fallback */ }else if (pmd_large (*pmd)) {vmemmap_verify ((pte_t *)pmd, node, addr, next); +vmemmap_use_sub_pmd (addr);continue ; }if (vmemmap_populate_basepages (addr, next, node,NULL ))
_
Andrew Morton
maintainerPATCH 82/178 x86/vmemmap: optimize for consecutive sections in partial populated PMDs
In reply to Andrew MortonFrom: Oscar Salvador <[email protected]>
Subject: x86/vmemmap: optimize for consecutive sections in partial populated PMDs
We can optimize in the case we are adding consecutive sections, so no memset(PAGE_UNUSED) is needed.
In that case, let us keep track where the unused range of the previous memory range begins, so we can compare it with start of the range to be added. If they are equal, we know sections are added consecutively.
For that purpose, let us introduce 'unused_pmd_start', which always holds the beginning of the unused memory range.
In the case a section does not contiguously follow the previous one, we know we can memset [unused_pmd_start, PMD_BOUNDARY) with PAGE_UNUSE.
This patch is based on a similar patch by David Hildenbrand:
https://lore.kernel.org/linux-mm/[email protected]/
---
arch/x86/mm/init_64.c | 67 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 61 insertions(+), 6 deletions(-)
arch/x86/mm/init_64.c renamed from arch/x86/mm/init_64.c~x86-vmemmap-optimize-for-consecutive-sections-in-partial-populated-pmds +61 -6
@@ -829,17 +829,42 @@ void __init paging_init(void)#ifdef CONFIG_SPARSEMEM_VMEMMAP #define PAGE_UNUSED 0xFD +/* +* The unused vmemmap range, which was not yet memset(PAGE_UNUSED), ranges +* from unused_pmd_start to next PMD_SIZE boundary. +*/ +static unsigned long unused_pmd_start__meminitdata ; + +static void __meminit vmemmap_flush_unused_pmd (void ) +{ +if (!unused_pmd_start) +return ; +/* +* Clears (unused_pmd_start, PMD_END] +*/ +memset ((void *)unused_pmd_start,PAGE_UNUSED , +ALIGN (unused_pmd_start,PMD_SIZE ) - unused_pmd_start); + unused_pmd_start =0 ; +} + +#ifdef CONFIG_MEMORY_HOTPLUG /* Returns true if the PMD is completely unused and thus it can be freed */ static bool __meminit vmemmap_pmd_is_unused (unsigned long addr,unsigned long end) {unsigned long start =ALIGN_DOWN (addr,PMD_SIZE ); +/* +* Flush the unused range cache to ensure that memchr_inv() will work +* for the whole range. +*/ +vmemmap_flush_unused_pmd ();memset ((void *)addr,PAGE_UNUSED , end - addr);return !memchr_inv ((void *)start,PAGE_UNUSED ,PMD_SIZE ); } +#endif -static void __meminit vmemmap_use_sub_pmd (unsigned long start) +static void __meminit __vmemmap_use_sub_pmd (unsigned long start) {/* * As we expect to add in the same granularity as we remove, it's
@@ -851,23 +876,53 @@ static void __meminit vmemmap_use_sub_pmmemset ((void *)start,0 ,sizeof (struct page )); } +static void __meminit vmemmap_use_sub_pmd (unsigned long start,unsigned long end) +{ +/* +* We only optimize if the new used range directly follows the +* previously unused range (esp., when populating consecutive sections). +*/ +if (unused_pmd_start == start) { +if (likely (IS_ALIGNED (end,PMD_SIZE ))) + unused_pmd_start =0 ; +else + unused_pmd_start = end; +return ; + } + +/* +* If the range does not contiguously follows previous one, make sure +* to mark the unused range of the previous one so it can be removed. +*/ +vmemmap_flush_unused_pmd (); +__vmemmap_use_sub_pmd (start); +} + +static void __meminit vmemmap_use_new_sub_pmd (unsigned long start,unsigned long end) { +vmemmap_flush_unused_pmd (); +/* * Could be our memmap page is filled with PAGE_UNUSED already from a * previous remove. Make sure to reset it. */ -vmemmap_use_sub_pmd (start); +__vmemmap_use_sub_pmd (start);/* * Mark with PAGE_UNUSED the unused parts of the new memmap range */ if (!IS_ALIGNED (start,PMD_SIZE ))memset ((void *)start,PAGE_UNUSED , - start -ALIGN_DOWN (start,PMD_SIZE )); + start -ALIGN_DOWN (start,PMD_SIZE )); + +/* +* We want to avoid memset(PAGE_UNUSED) when populating the vmemmap of +* consecutive sections. Remember for the last added PMD where the +* unused range begins. +*/ if (!IS_ALIGNED (end,PMD_SIZE )) -memset ((void *)end,PAGE_UNUSED , -ALIGN (end,PMD_SIZE ) - end); + unused_pmd_start = end; }#endif
@@ -1538,7 +1593,7 @@ static int __meminit vmemmap_populate_hureturn -ENOMEM ;/* no fallback */ }else if (pmd_large (*pmd)) {vmemmap_verify ((pte_t *)pmd, node, addr, next); -vmemmap_use_sub_pmd (addr); +vmemmap_use_sub_pmd (addr, next);continue ; }if (vmemmap_populate_basepages (addr, next, node,NULL ))
_
Andrew Morton
maintainerPATCH 83/178 mm, tracing: improve rss_stat tracepoint message
In reply to Andrew MortonFrom: Ovidiu Panait <[email protected]>
Subject: mm, tracing: improve rss_stat tracepoint message
Adjust the rss_stat tracepoint to print the name of the resident page type that got updated (e.g. MM_ANONPAGES/MM_FILEPAGES), rather than the numeric index corresponding to it (the __entry->member value):
Before this patch:
------------------rss_stat: mm_id=1216113068 curr=0 member=1 size=28672Brss_stat: mm_id=1216113068 curr=0 member=1 size=0Brss_stat: mm_id=534402304 curr=1 member=0 size=188416Brss_stat: mm_id=534402304 curr=1 member=1 size=40960B
After this patch:
-----------------rss_stat: mm_id=1726253524 curr=1 type=MM_ANONPAGES size=40960Brss_stat: mm_id=1726253524 curr=1 type=MM_FILEPAGES size=663552Brss_stat: mm_id=1726253524 curr=1 type=MM_ANONPAGES size=65536Brss_stat: mm_id=1726253524 curr=1 type=MM_FILEPAGES size=647168B
Use TRACE_DEFINE_ENUM()/__print_symbolic() logic to map the enum values to the strings they represent, so that userspace tools can also parse the raw data correctly.
---
include/trace/events/kmem.h | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-)
include/trace/events/kmem.h renamed from include/trace/events/kmem.h~mm-tracing-improve-rss_stat-tracepoint-message +22 -2
@@ -343,6 +343,26 @@ static unsigned int __maybe_unused mm_pt#define __PTR_TO_HASHVAL#endif +#define TRACE_MM_PAGES \ + EM(MM_FILEPAGES) \ + EM(MM_ANONPAGES) \ + EM(MM_SWAPENTS) \ + EMe(MM_SHMEMPAGES) + +#undef EM +#undef EMe + +#define EM (a) TRACE_DEFINE_ENUM(a); +#define EMe (a) TRACE_DEFINE_ENUM(a); + +TRACE_MM_PAGES + +#undef EM +#undef EMe + +#define EM (a) { a, #a }, +#define EMe (a) { a, #a } + TRACE_EVENT(rss_stat, TP_PROTO(struct mm_struct *mm,
@@ -365,10 +385,10 @@ TRACE_EVENT(rss_stat, __entry->size = (count <<PAGE_SHIFT ); ), -TP_printk ("mm_id=%u curr=%d member=%d size=%ldB" , +TP_printk ("mm_id=%u curr=%d type=%s size=%ldB" , __entry->mm_id, __entry->curr, - __entry->member, +__print_symbolic (__entry->member,TRACE_MM_PAGES ), __entry->size) );#endif /* _TRACE_KMEM_H */
_
Andrew Morton
maintainerPATCH 84/178 mm: add remap_pfn_range_notrack
In reply to Andrew MortonFrom: Christoph Hellwig <[email protected]>
Subject: mm: add remap_pfn_range_notrack
Patch series "add remap_pfn_range_notrack instead of reinventing it in i915", v2.
i915 has some reason to want to avoid the track_pfn_remap overhead in remap_pfn_range. Add a function to the core VM to do just that rather than reinventing the functionality poorly in the driver.
Note that the remap_io_sg path does get exercises when using Xorg on my Thinkpad X1, so this should be considered lightly tested, I've not managed to hit the remap_io_mapping path at all.
This patch (of 4):
Add a version of remap_pfn_range that does not call track_pfn_range. This will be used to fix horrible abuses of VM internals in the i915 driver.
---
include/linux/mm.h | 2 + mm/memory.c | 51 ++++++++++++++++++++++++++----------------- 2 files changed, 33 insertions(+), 20 deletions(-)
include/linux/mm.h renamed from include/linux/mm.h~mm-add-remap_pfn_range_notrack +2 -0
@@ -2732,6 +2732,8 @@ unsigned long change_prot_numa(struct vmstruct vm_area_struct *find_extend_vma (struct mm_struct *,unsigned long addr);int remap_pfn_range (struct vm_area_struct *,unsigned long addr,unsigned long pfn,unsigned long size,pgprot_t ); +int remap_pfn_range_notrack (struct vm_area_struct *vma,unsigned long addr, +unsigned long pfn,unsigned long size,pgprot_t prot);int vm_insert_page (struct vm_area_struct *,unsigned long addr,struct page *);int vm_insert_pages (struct vm_area_struct *vma,unsigned long addr,struct page **pages,unsigned long *num);
mm/memory.c renamed from mm/memory.c~mm-add-remap_pfn_range_notrack +31 -20
79 lines not on this page · raw message
_
Andrew Morton
maintainerPATCH 85/178 mm: add a io_mapping_map_user helper
In reply to Andrew MortonFrom: Christoph Hellwig <[email protected]>
Subject: mm: add a io_mapping_map_user helper
Add a helper that calls remap_pfn_range for an struct io_mapping, relying on the pgprot pre-validation done when creating the mapping instead of doing it at runtime.
---
include/linux/io-mapping.h | 3 +++ mm/Kconfig | 3 +++ mm/Makefile | 1 + mm/io-mapping.c | 29 +++++++++++++++++++++++++++++ 4 files changed, 36 insertions(+)
include/linux/io-mapping.h renamed from include/linux/io-mapping.h~mm-add-a-io_mapping_map_user-helper +3 -0
@@ -220,3 +220,6 @@ io_mapping_free(struct io_mapping *iomap }#endif /* _LINUX_IO_MAPPING_H */ + +int io_mapping_map_user (struct io_mapping *iomap,struct vm_area_struct *vma, +unsigned long addr,unsigned long pfn,unsigned long size);
mm/io-mapping.c new file +29 -0
@@ -0,0 +1,29 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include <linux/mm.h> +#include <linux/io-mapping.h> + +/** +* io_mapping_map_user - remap an I/O mapping to userspace +* @iomap: the source io_mapping +* @vma: user vma to map to +* @addr: target user address to start at +* @pfn: physical address of kernel memory +* @size: size of map area +* +* Note: this is only safe if the mm semaphore is held when called. +*/ +int io_mapping_map_user (struct io_mapping *iomap,struct vm_area_struct *vma, +unsigned long addr,unsigned long pfn,unsigned long size) +{ +vm_flags_t expected_flags =VM_PFNMAP |VM_DONTEXPAND |VM_DONTDUMP ; + +if (WARN_ON_ONCE ((vma->vm_flags & expected_flags) != expected_flags)) +return -EINVAL ; + +/* We rely on prevalidation of the io-mapping to skip track_pfn(). */ +return remap_pfn_range_notrack (vma, addr, pfn, size, +__pgprot ((pgprot_val (iomap->prot) & _PAGE_CACHE_MASK) | + (pgprot_val (vma->vm_page_prot) & ~_PAGE_CACHE_MASK))); +} +EXPORT_SYMBOL_GPL (io_mapping_map_user);
mm/Kconfig renamed from mm/Kconfig~mm-add-a-io_mapping_map_user-helper +3 -0
@@ -871,4 +871,7 @@ config MAPPING_DIRTY_HELPERS config KMAP_LOCAL bool +# struct io_mapping based helper. Selected by drivers that need them +config IO_MAPPING + bool endmenu
mm/Makefile renamed from mm/Makefile~mm-add-a-io_mapping_map_user-helper +1 -0
@@ -120,3 +120,4 @@ obj-$(CONFIG_MEMFD_CREATE) += memfd.o obj-$(CONFIG_MAPPING_DIRTY_HELPERS) += mapping_dirty_helpers.o obj-$(CONFIG_PTDUMP_CORE) += ptdump.o obj-$(CONFIG_PAGE_REPORTING) += page_reporting.o +obj-$(CONFIG_IO_MAPPING) += io-mapping.o
_
Andrew Morton
maintainerPATCH 86/178 i915: use io_mapping_map_user
In reply to Andrew MortonFrom: Christoph Hellwig <[email protected]>
Subject: i915: use io_mapping_map_user
Replace the home-grown remap_io_mapping that abuses apply_to_page_range with the proper io_mapping_map_user interface.
---
drivers/gpu/drm/i915/Kconfig | 1 drivers/gpu/drm/i915/gem/i915_gem_mman.c | 9 +--- drivers/gpu/drm/i915/i915_drv.h | 3 - drivers/gpu/drm/i915/i915_mm.c | 44 --------------------- 4 files changed, 5 insertions(+), 52 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_mman.c renamed from drivers/gpu/drm/i915/gem/i915_gem_mman.c~i915-use-io_mapping_map_user +4 -5
@@ -367,11 +367,10 @@ retry: goto err_unpin;/* Finally, remap it using the new GTT offset */ - ret =remap_io_mapping (area, - area->vm_start + (vma->ggtt_view.partial.offset <<PAGE_SHIFT ), - (ggtt->gmadr.start + vma->node.start) >>PAGE_SHIFT , -min_t (u64, vma->size, area->vm_end - area->vm_start), - &ggtt->iomap); + ret =io_mapping_map_user (&ggtt->iomap, area, area->vm_start + + (vma->ggtt_view.partial.offset <<PAGE_SHIFT ), + (ggtt->gmadr.start + vma->node.start) >>PAGE_SHIFT , +min_t (u64, vma->size, area->vm_end - area->vm_start));if (ret) goto err_fence;
drivers/gpu/drm/i915/i915_drv.h renamed from drivers/gpu/drm/i915/i915_drv.h~i915-use-io_mapping_map_user +0 -3
@@ -1905,9 +1905,6 @@ int i915_reg_read_ioctl(struct drm_devic struct drm_file *file);/* i915_mm.c */ -int remap_io_mapping (struct vm_area_struct *vma, -unsigned long addr,unsigned long pfn,unsigned long size, -struct io_mapping *iomap);int remap_io_sg (struct vm_area_struct *vma,unsigned long addr,unsigned long size,struct scatterlist *sgl,resource_size_t iobase);
drivers/gpu/drm/i915/i915_mm.c renamed from drivers/gpu/drm/i915/i915_mm.c~i915-use-io_mapping_map_user +0 -44
57 lines not on this page · raw message
drivers/gpu/drm/i915/Kconfig renamed from drivers/gpu/drm/i915/Kconfig~i915-use-io_mapping_map_user +1 -0
@@ -20,6 +20,7 @@ config DRM_I915 select INPUT if ACPI select ACPI_VIDEO if ACPI select ACPI_BUTTON if ACPI + select IO_MAPPING select SYNC_FILE select IOSF_MBI select CRC32
_
Andrew Morton
maintainerPATCH 87/178 i915: fix remap_io_sg to verify the pgprot
In reply to Andrew MortonFrom: Christoph Hellwig <[email protected]>
Subject: i915: fix remap_io_sg to verify the pgprot
remap_io_sg claims that the pgprot is pre-verified using an io_mapping, but actually does not get passed an io_mapping and just uses the pgprot in the VMA. Remove the apply_to_page_range abuse and just loop over remap_pfn_range for each segment.
Note: this could use io_mapping_map_user by passing an iomap to remap_io_sg if the maintainers can verify that the pgprot in the iomap in the only caller is indeed the desired one here.
---
drivers/gpu/drm/i915/i915_mm.c | 73 +++++++++---------------------- 1 file changed, 23 insertions(+), 50 deletions(-)
drivers/gpu/drm/i915/i915_mm.c renamed from drivers/gpu/drm/i915/i915_mm.c~i915-fix-remap_io_sg-to-verify-the-pgprot +23 -50
@@ -28,46 +28,10 @@#include "i915_drv.h" -struct remap_pfn { -struct mm_struct *mm; -unsigned long pfn; -pgprot_t prot; - -struct sgt_iter sgt; -resource_size_t iobase; -}; +#define EXPECTED_FLAGS (VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP)#define use_dma (io) ((io) != -1) -static inline unsigned long sgt_pfn (const struct remap_pfn *r) -{ -if (use_dma (r->iobase)) -return (r->sgt.dma + r->sgt.curr + r->iobase) >>PAGE_SHIFT ; -else -return r->sgt.pfn + (r->sgt.curr >>PAGE_SHIFT ); -} - -static int remap_sg (pte_t *pte,unsigned long addr,void *data) -{ -struct remap_pfn *r = data; - -if (GEM_WARN_ON (!r->sgt.sgp)) -return -EINVAL ; - -/* Special PTE are not associated with any struct page */ -set_pte_at (r->mm, addr, pte, -pte_mkspecial (pfn_pte (sgt_pfn (r), r->prot))); - r->pfn++;/* track insertions in case we need to unwind later */ - - r->sgt.curr +=PAGE_SIZE ; -if (r->sgt.curr >= r->sgt.max) - r->sgt =__sgt_iter (__sg_next (r->sgt.sgp),use_dma (r->iobase)); - -return 0 ; -} - -#define EXPECTED_FLAGS (VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP) -/** * remap_io_sg - remap an IO mapping to userspace * @vma: user vma to map to
@@ -82,12 +46,7 @@ int remap_io_sg(struct vm_area_struct *v unsigned long addr, unsigned long size, struct scatterlist *sgl, resource_size_t iobase) { - struct remap_pfn r = { - .mm = vma->vm_mm, - .prot = vma->vm_page_prot, - .sgt =__sgt_iter (sgl,use_dma (iobase)), - .iobase = iobase, - }; + unsigned long pfn, len, remapped = 0;int err;/* We rely on prevalidation of the io-mapping to skip track_pfn(). */
@@ -96,11 +55,25 @@ int remap_io_sg(struct vm_area_struct *vif (!use_dma (iobase))flush_cache_range (vma, addr, size); - err =apply_to_page_range (r.mm, addr, size, remap_sg, &r); -if (unlikely (err)) { -zap_vma_ptes (vma, addr, r.pfn <<PAGE_SHIFT ); -return err; - } - -return 0 ; +do { +if (use_dma (iobase)) { +if (!sg_dma_len (sgl)) +break ; + pfn = (sg_dma_address (sgl) + iobase) >>PAGE_SHIFT ; + len =sg_dma_len (sgl); + }else { + pfn =page_to_pfn (sg_page (sgl)); + len = sgl->length; + } + + err =remap_pfn_range (vma, addr + remapped, pfn, len, + vma->vm_page_prot); +if (err) +break ; + remapped += len; + }while ((sgl =__sg_next (sgl))); + +if (err) +zap_vma_ptes (vma, addr, remapped); +return err; }
_
Andrew Morton
maintainerPATCH 88/178 NUMA balancing: reduce TLB flush via delaying mapping on hint page fault
In reply to Andrew MortonFrom: Huang Ying <[email protected]>
Subject: NUMA balancing: reduce TLB flush via delaying mapping on hint page fault
With NUMA balancing, in hint page fault handler, the faulting page will be migrated to the accessing node if necessary. During the migration, TLB will be shot down on all CPUs that the process has run on recently. Because in the hint page fault handler, the PTE will be made accessible before the migration is tried. The overhead of TLB shooting down can be high, so it's better to be avoided if possible. In fact, if we delay mapping the page until migration, that can be avoided. This is what this patch doing.
For the multiple threads applications, it's possible that a page is accessed by multiple threads almost at the same time. In the original implementation, because the first thread will install the accessible PTE before migrating the page, the other threads may access the page directly before the page is made inaccessible again during migration. While with the patch, the second thread will go through the page fault handler too. And because of the PageLRU() checking in the following code path,
migrate_misplaced_page()
numamigrate_isolate_page()
isolate_lru_page()
the migrate_misplaced_page() will return 0, and the PTE will be made accessible in the second thread.
This will introduce a little more overhead. But we think the possibility for a page to be accessed by the multiple threads at the same time is low, and the overhead difference isn't too large. If this becomes a problem in some workloads, we need to consider how to reduce the overhead.
To test the patch, we run a test case as follows on a 2-socket Intel server (1 NUMA node per socket) with 128GB DRAM (64GB per socket).
1. Run a memory eater on NUMA node 1 to use 40GB memory before running pmbench.
2. Run pmbench (normal accessing pattern) with 8 processes, and 8 threads per process, so there are 64 threads in total. The working-set size of each process is 8960MB, so the total working-set size is 8 * 8960MB = 70GB. The CPU of all pmbench processes is bound to node 1. The pmbench processes will access some DRAM on node 0.
3. After the pmbench processes run for 10 seconds, kill the memory eater. Now, some pages will be migrated from node 0 to node 1 via NUMA balancing.
Test results show that, with the patch, the pmbench throughput (page accesses/s) increases 5.5%. The number of the TLB shootdowns interrupts reduces 98% (from ~4.7e7 to ~9.7e5) with about 9.2e6 pages (35.8GB) migrated. From the perf profile, it can be found that the CPU cycles spent by try_to_unmap() and its callees reduces from 6.02% to 0.47%. That is, the CPU cycles spent by TLB shooting down decreases greatly.
---
mm/memory.c | 54 +++++++++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 22 deletions(-)
mm/memory.c renamed from mm/memory.c~numa-balancing-reduce-tlb-flush-via-delaying-mapping-on-hint-page-fault +32 -22
@@ -4125,29 +4125,17 @@ static vm_fault_t do_numa_page(struct vm goto out; } -/* -* Make it present again, Depending on how arch implementes non -* accessible ptes, some can allow access by kernel mode. -*/ - old_pte =ptep_modify_prot_start (vma, vmf->address, vmf->pte); +/* Get the normal PTE */ + old_pte =ptep_get (vmf->pte); pte =pte_modify (old_pte, vma->vm_page_prot); - pte =pte_mkyoung (pte); -if (was_writable) - pte =pte_mkwrite (pte); -ptep_modify_prot_commit (vma, vmf->address, vmf->pte, old_pte, pte); -update_mmu_cache (vma, vmf->address, vmf->pte); page =vm_normal_page (vma, vmf->address, pte); -if (!page) { -pte_unmap_unlock (vmf->pte, vmf->ptl); -return 0 ; - } +if (!page) + goto out_map;/* TODO: handle PTE-mapped THP */ -if (PageCompound (page)) { -pte_unmap_unlock (vmf->pte, vmf->ptl); -return 0 ; - } +if (PageCompound (page)) + goto out_map;/* * Avoid grouping on RO pages in general. RO pages shouldn't hurt as
@@ -4157,7 +4145,7 @@ static vm_fault_t do_numa_page(struct vm* pte_dirty has unpredictable behaviour between PTE scan updates, * background writeback, dirty balancing and application behaviour. */ -if (!pte_write (pte)) +if (!was_writable) flags |=TNF_NO_GROUP ;/*
@@ -4171,23 +4159,45 @@ static vm_fault_t do_numa_page(struct vm page_nid =page_to_nid (page); target_nid =numa_migrate_prep (page, vma, vmf->address, page_nid, &flags); -pte_unmap_unlock (vmf->pte, vmf->ptl);if (target_nid ==NUMA_NO_NODE ) {put_page (page); - goto out; + goto out_map; } +pte_unmap_unlock (vmf->pte, vmf->ptl);/* Migrate to the requested node */ if (migrate_misplaced_page (page, vma, target_nid)) { page_nid = target_nid; flags |=TNF_MIGRATED ; - }else + }else { flags |=TNF_MIGRATE_FAIL ; + vmf->pte =pte_offset_map (vmf->pmd, vmf->address); +spin_lock (vmf->ptl); +if (unlikely (!pte_same (*vmf->pte, vmf->orig_pte))) { +pte_unmap_unlock (vmf->pte, vmf->ptl); + goto out; + } + goto out_map; + } out:if (page_nid !=NUMA_NO_NODE )task_numa_fault (last_cpupid, page_nid,1 , flags);return 0 ; +out_map: +/* +* Make it present again, depending on how arch implements +* non-accessible ptes, some can allow access by kernel mode. +*/ + old_pte =ptep_modify_prot_start (vma, vmf->address, vmf->pte); + pte =pte_modify (old_pte, vma->vm_page_prot); + pte =pte_mkyoung (pte); +if (was_writable) + pte =pte_mkwrite (pte); +ptep_modify_prot_commit (vma, vmf->address, vmf->pte, old_pte, pte); +update_mmu_cache (vma, vmf->address, vmf->pte); +pte_unmap_unlock (vmf->pte, vmf->ptl); + goto out; }static inline vm_fault_t create_huge_pmd (struct vm_fault *vmf)
_
Andrew Morton
maintainerPATCH 89/178 mm: extend MREMAP_DONTUNMAP to non-anonymous mappings
In reply to Andrew MortonFrom: Brian Geffon <[email protected]>
Subject: mm: extend MREMAP_DONTUNMAP to non-anonymous mappings
Patch series "mm: Extend MREMAP_DONTUNMAP to non-anonymous mappings", v5.
This patch (of 3):
Currently MREMAP_DONTUNMAP only accepts private anonymous mappings. This restriction was placed initially for simplicity and not because there exists a technical reason to do so.
This change will widen the support to include any mappings which are not VM_DONTEXPAND or VM_PFNMAP. The primary use case is to support MREMAP_DONTUNMAP on mappings which may have been created from a memfd. This change will result in mremap(MREMAP_DONTUNMAP) returning -EINVAL if VM_DONTEXPAND or VM_PFNMAP mappings are specified.
Lokesh Gidra who works on the Android JVM, provided an explanation of how such a feature will improve Android JVM garbage collection: "Android is developing a new garbage collector (GC), based on userfaultfd. The garbage collector will use userfaultfd (uffd) on the java heap during compaction. On accessing any uncompacted page, the application threads will find it missing, at which point the thread will create the compacted page and then use UFFDIO_COPY ioctl to get it mapped and then resume execution. Before starting this compaction, in a stop-the-world pause the heap will be mremap(MREMAP_DONTUNMAP) so that the java heap is ready to receive UFFD_EVENT_PAGEFAULT events after resuming execution.
To speedup mremap operations, pagetable movement was optimized by moving PUD entries instead of PTE entries [1]. It was necessary as mremap of even modest sized memory ranges also took several milliseconds, and stopping the application for that long isn't acceptable in response-time sensitive cases.
With UFFDIO_CONTINUE feature [2], it will be even more efficient to implement this GC, particularly the 'non-moveable' portions of the heap. It will also help in reducing the need to copy (UFFDIO_COPY) the pages. However, for this to work, the java heap has to be on a 'shared' vma. Currently MREMAP_DONTUNMAP only supports private anonymous mappings, this patch will enable using UFFDIO_CONTINUE for the new userfaultfd-based heap compaction."
[1] https://lore.kernel.org/linux-mm/20201215030730.NC3CU98e4%[email protected]/
[2] https://lore.kernel.org/linux-mm/[email protected]/
---
mm/mremap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
mm/mremap.c renamed from mm/mremap.c~mm-extend-mremap_dontunmap-to-non-anonymous-mappings +2 -2
@@ -653,8 +653,8 @@ static struct vm_area_struct *vma_to_resreturn ERR_PTR (-EINVAL ); } -if (flags &MREMAP_DONTUNMAP && (!vma_is_anonymous (vma) || - vma->vm_flags &VM_SHARED )) +if ((flags &MREMAP_DONTUNMAP ) && + (vma->vm_flags & (VM_DONTEXPAND |VM_PFNMAP )))return ERR_PTR (-EINVAL );if (is_vm_hugetlb_page (vma))
_
Andrew Morton
maintainerPATCH 90/178 Revert "mremap: don't allow MREMAP_DONTUNMAP on special_mappings and aio"
In reply to Andrew MortonFrom: Brian Geffon <[email protected]>
Subject: Revert "mremap: don't allow MREMAP_DONTUNMAP on special_mappings and aio"
This reverts commit cd544fd1dc9293c6702fab6effa63dac1cc67e99.
As discussed in [1] this commit was a no-op because the mapping type was checked in vma_to_resize before move_vma is ever called. This meant that vm_ops->mremap() would never be called on such mappings. Furthermore, we've since expanded support of MREMAP_DONTUNMAP to non-anonymous mappings, and these special mappings are still protected by the existing check of !VM_DONTEXPAND and !VM_PFNMAP which will result in a -EINVAL.
1. https://lkml.org/lkml/2020/12/28/2340
---
arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 2 +- fs/aio.c | 5 +---- include/linux/mm.h | 2 +- mm/mmap.c | 6 +----- mm/mremap.c | 2 +- 5 files changed, 5 insertions(+), 12 deletions(-)
arch/x86/kernel/cpu/resctrl/pseudo_lock.c renamed from arch/x86/kernel/cpu/resctrl/pseudo_lock.c~revert-mremap-dont-allow-mremap_dontunmap-on-special_mappings-and-aio +1 -1
@@ -1458,7 +1458,7 @@ static int pseudo_lock_dev_release(strucreturn 0 ; } -static int pseudo_lock_dev_mremap (struct vm_area_struct *area,unsigned long flags) +static int pseudo_lock_dev_mremap (struct vm_area_struct *area) {/* Not supported */ return -EINVAL ;
fs/aio.c renamed from fs/aio.c~revert-mremap-dont-allow-mremap_dontunmap-on-special_mappings-and-aio +1 -4
@@ -323,16 +323,13 @@ static void aio_free_ring(struct kioctx } } -static int aio_ring_mremap (struct vm_area_struct *vma,unsigned long flags) +static int aio_ring_mremap (struct vm_area_struct *vma) {struct file *file = vma->vm_file;struct mm_struct *mm = vma->vm_mm;struct kioctx_table *table;int i, res = -EINVAL ; -if (flags &MREMAP_DONTUNMAP ) -return -EINVAL ; -spin_lock (&mm->ioctx_lock);rcu_read_lock (); table =rcu_dereference (mm->ioctx_table);
include/linux/mm.h renamed from include/linux/mm.h~revert-mremap-dont-allow-mremap_dontunmap-on-special_mappings-and-aio +1 -1
@@ -580,7 +580,7 @@ struct vm_operations_struct {void (*close)(struct vm_area_struct * area);/* Called any time before splitting to check if it's allowed */ int (*may_split)(struct vm_area_struct *area,unsigned long addr); -int (*mremap)(struct vm_area_struct *area,unsigned long flags); +int (*mremap)(struct vm_area_struct *area);/* * Called by mprotect() to make driver-specific permission * checks before mprotect() is finalised. The VMA must not
mm/mmap.c renamed from mm/mmap.c~revert-mremap-dont-allow-mremap_dontunmap-on-special_mappings-and-aio +1 -5
@@ -3409,14 +3409,10 @@ static const char *special_mapping_name(return ((struct vm_special_mapping *)vma->vm_private_data)->name; } -static int special_mapping_mremap (struct vm_area_struct *new_vma, -unsigned long flags) +static int special_mapping_mremap (struct vm_area_struct *new_vma) {struct vm_special_mapping *sm = new_vma->vm_private_data; -if (flags &MREMAP_DONTUNMAP ) -return -EINVAL ; -if (WARN_ON_ONCE (current->mm != new_vma->vm_mm))return -EFAULT ;
mm/mremap.c renamed from mm/mremap.c~revert-mremap-dont-allow-mremap_dontunmap-on-special_mappings-and-aio +1 -1
@@ -545,7 +545,7 @@ static unsigned long move_vma(struct vm_if (moved_len < old_len) { err = -ENOMEM ; }else if (vma->vm_ops && vma->vm_ops->mremap) { - err = vma->vm_ops->mremap (new_vma, flags); + err = vma->vm_ops->mremap (new_vma); }if (unlikely (err)) {
_
Andrew Morton
maintainerPATCH 91/178 selftests: add a MREMAP_DONTUNMAP selftest for shmem
In reply to Andrew MortonFrom: Brian Geffon <[email protected]>
Subject: selftests: add a MREMAP_DONTUNMAP selftest for shmem
This test extends the current mremap tests to validate that the MREMAP_DONTUNMAP operation can be performed on shmem mappings.
---
tools/testing/selftests/vm/mremap_dontunmap.c | 52 ++++++++++++++++ 1 file changed, 52 insertions(+)
tools/testing/selftests/vm/mremap_dontunmap.c renamed from tools/testing/selftests/vm/mremap_dontunmap.c~selftests-add-a-mremap_dontunmap-selftest-for-shmem +52 -0
@@ -127,6 +127,57 @@ static void mremap_dontunmap_simple() "unable to unmap source mapping"); } +// This test validates that MREMAP_DONTUNMAP on a shared mapping works as expected. +static void mremap_dontunmap_simple_shmem () +{ +unsigned long num_pages =5 ; + +int mem_fd =memfd_create ("memfd" ,MFD_CLOEXEC ); +BUG_ON (mem_fd <0 ,"memfd_create" ); + +BUG_ON (ftruncate (mem_fd, num_pages * page_size) <0 , +"ftruncate" ); + +void *source_mapping = +mmap (NULL , num_pages * page_size,PROT_READ |PROT_WRITE , +MAP_FILE |MAP_SHARED , mem_fd,0 ); +BUG_ON (source_mapping ==MAP_FAILED ,"mmap" ); + +BUG_ON (close (mem_fd) <0 ,"close" ); + +memset (source_mapping,'a' , num_pages * page_size); + +// Try to just move the whole mapping anywhere (not fixed). +void *dest_mapping = +mremap (source_mapping, num_pages * page_size, num_pages * page_size, +MREMAP_DONTUNMAP |MREMAP_MAYMOVE ,NULL ); +if (dest_mapping ==MAP_FAILED && errno ==EINVAL ) { +// Old kernel which doesn't support MREMAP_DONTUNMAP on shmem. +BUG_ON (munmap (source_mapping, num_pages * page_size) ==-1 , +"unable to unmap source mapping" ); +return ; + } + +BUG_ON (dest_mapping ==MAP_FAILED ,"mremap" ); + +// Validate that the pages have been moved, we know they were moved if +// the dest_mapping contains a's. +BUG_ON (check_region_contains_byte + (dest_mapping, num_pages * page_size,'a' ) !=0 , +"pages did not migrate" ); + +// Because the region is backed by shmem, we will actually see the same +// memory at the source location still. +BUG_ON (check_region_contains_byte + (source_mapping, num_pages * page_size,'a' ) !=0 , +"source should have no ptes" ); + +BUG_ON (munmap (dest_mapping, num_pages * page_size) ==-1 , +"unable to unmap destination mapping" ); +BUG_ON (munmap (source_mapping, num_pages * page_size) ==-1 , +"unable to unmap source mapping" ); +} +// This test validates MREMAP_DONTUNMAP will move page tables to a specific // destination using MREMAP_FIXED, also while validating that the source // remains intact.
@@ -300,6 +351,7 @@ int main(void)BUG_ON (page_buffer ==MAP_FAILED ,"unable to mmap a page." );mremap_dontunmap_simple (); +mremap_dontunmap_simple_shmem ();mremap_dontunmap_simple_fixed ();mremap_dontunmap_partial_mapping ();mremap_dontunmap_partial_mapping_overwrite ();
_
Andrew Morton
maintainerPATCH 92/178 mm/dmapool: switch from strlcpy to strscpy
In reply to Andrew MortonFrom: Zhiyuan Dai <[email protected]>
Subject: mm/dmapool: switch from strlcpy to strscpy
strlcpy is marked as deprecated in Documentation/process/deprecated.rst, and there is no functional difference when the caller expects truncation (when not checking the return value). strscpy is relatively better as it also avoids scanning the whole source string.
---
mm/dmapool.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/dmapool.c renamed from mm/dmapool.c~mm-dmapool-switch-from-strlcpy-to-strscpy +1 -1
@@ -157,7 +157,7 @@ struct dma_pool *dma_pool_create(const cif (!retval)return retval; -strlcpy (retval->name, name,sizeof (retval->name)); +strscpy (retval->name, name,sizeof (retval->name)); retval->dev = dev;
_
Andrew Morton
maintainerPATCH 93/178 mm/sparse: add the missing sparse_buffer_fini() in error branch
In reply to Andrew MortonFrom: Wang Wensheng <[email protected]>
Subject: mm/sparse: add the missing sparse_buffer_fini() in error branch
sparse_buffer_init() and sparse_buffer_fini() should appear in pair, or a WARN issue would be through the next time sparse_buffer_init() runs.
Add the missing sparse_buffer_fini() in error branch.
---
mm/sparse.c | 1 + 1 file changed, 1 insertion(+)
mm/sparse.c renamed from mm/sparse.c~mm-sparse-add-the-missing-sparse_buffer_fini-in-error-branch +1 -0
@@ -547,6 +547,7 @@ static void __init sparse_init_nid(int npr_err ("%s: node[%d] memory map backing failed. Some memory will not be available." , __func__, nid); pnum_begin = pnum; +sparse_buffer_fini (); goto failed; }check_usemap_section_nr (nid, usage);
_
Andrew Morton
maintainerPATCH 94/178 samples/vfio-mdev/mdpy: use remap_vmalloc_range
In reply to Andrew MortonFrom: Christoph Hellwig <[email protected]>
Subject: samples/vfio-mdev/mdpy: use remap_vmalloc_range
Patch series "remap_vmalloc_range cleanups".
This series removes an open coded instance of remap_vmalloc_range and removes the unused remap_vmalloc_range_partial export.
This patch (of 2):
Use remap_vmalloc_range instead of open coding it using remap_vmalloc_range_partial.
---
samples/vfio-mdev/mdpy.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
samples/vfio-mdev/mdpy.c renamed from samples/vfio-mdev/mdpy.c~samples-vfio-mdev-mdpy-use-remap_vmalloc_range +1 -3
@@ -406,9 +406,7 @@ static int mdpy_mmap(struct mdev_deviceif ((vma->vm_flags &VM_SHARED ) ==0 )return -EINVAL ; -return remap_vmalloc_range_partial (vma, vma->vm_start, - mdev_state->memblk,0 , - vma->vm_end - vma->vm_start); +return remap_vmalloc_range (vma, mdev_state->memblk,0 ); } static int mdpy_get_region_info(struct mdev_device *mdev,
_
Andrew Morton
maintainerPATCH 95/178 mm: unexport remap_vmalloc_range_partial
In reply to Andrew MortonFrom: Christoph Hellwig <[email protected]>
Subject: mm: unexport remap_vmalloc_range_partial
remap_vmalloc_range_partial is only used to implement remap_vmalloc_range and by procfs. Unexport it.
---
mm/vmalloc.c | 1 - 1 file changed, 1 deletion(-)
mm/vmalloc.c renamed from mm/vmalloc.c~mm-unexport-remap_vmalloc_range_partial +0 -1
@@ -3072,7 +3072,6 @@ int remap_vmalloc_range_partial(struct vreturn 0 ; } -EXPORT_SYMBOL (remap_vmalloc_range_partial);/** * remap_vmalloc_range - map vmalloc pages to userspace
_
Andrew Morton
maintainerPATCH 96/178 mm/vmalloc: use rb_tree instead of list for vread() lookups
In reply to Andrew MortonFrom: Serapheim Dimitropoulos <[email protected]>
Subject: mm/vmalloc: use rb_tree instead of list for vread() lookups
vread() has been linearly searching vmap_area_list for looking up vmalloc areas to read from. These same areas are also tracked by a rb_tree (vmap_area_root) which offers logarithmic lookup.
This patch modifies vread() to use the rb_tree structure instead of the list and the speedup for heavy /proc/kcore readers can be pretty significant. Below are the wall clock measurements of a Python application that leverages the drgn debugging library to read and interpret data read from /proc/kcore.
Before the patch:
-----
$ time sudo sdb -e 'dbuf | head 3000 | wc' (unsigned long)3000
real 0m22.446s
user 0m2.321s
sys 0m20.690s
-----
With the patch:
-----
$ time sudo sdb -e 'dbuf | head 3000 | wc' (unsigned long)3000
real 0m2.104s
user 0m2.043s
sys 0m0.921s
-----
---
mm/vmalloc.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
mm/vmalloc.c renamed from mm/vmalloc.c~mm-vmalloc-use-rb_tree-instead-of-list-for-vread-lookups +4 -1
@@ -2894,7 +2894,10 @@ long vread(char *buf, char *addr, unsign count = -(unsigned long ) addr;spin_lock (&vmap_area_lock); -list_for_each_entry (va, &vmap_area_list, list) { + va =__find_vmap_area ((unsigned long )addr); +if (!va) + goto finished; +list_for_each_entry_from (va, &vmap_area_list, list) {if (!count)break ;
_
Andrew Morton
maintainerPATCH 97/178 ARM: mm: add missing pud_page define to 2-level page tables
In reply to Andrew MortonFrom: Nicholas Piggin <[email protected]>
Subject: ARM: mm: add missing pud_page define to 2-level page tables
Patch series "huge vmalloc mappings", v13.
The kernel virtual mapping layer grew support for mapping memory with > PAGE_SIZE ptes with 0ddab1d2ed664 ("lib/ioremap.c: add huge I/O map capability interfaces"), and implemented support for using those huge page mappings with ioremap.
According to the submission, the use-case is mapping very large non-volatile memory devices, which could be GB or TB.
https://lore.kernel.org/lkml/[email protected]/
The benefit is said to be in the overhead of maintaining the mapping, perhaps both in memory overhead and setup / teardown time. Memory overhead for the mapping with a 4kB page and 8 byte page table is 2GB per TB of mapping, down to 4MB / TB with 2MB pages.
The same huge page vmap infrastructure can be quite easily adapted and used for mapping vmalloc memory pages without more complexity for arch or core vmap code. However unlike ioremap, vmalloc page table overhead is not a real problem, so the advantage to justify this is performance.
Several of the most structures in the kernel (e.g., vfs and network hash tables) are allocated with vmalloc on NUMA machines, in order to distribute access bandwidth over the machine. Mapping these with larger pages can improve TLB usage significantly, for example this reduces TLB misses by nearly 30x on a git diff workload on a 2-node POWER9 (59,800 -> 2,100) and reduces CPU cycles by 0.54%, due to vfs hashes being allocated with 2MB pages.
[ Other numbers?
- The difference is even larger in a guest due to more costly TLB misses.
- Eric Dumazet was keen on the network hash performance possibilities.
- Other archs? Ding was doing x86 testing. ]
The kernel module allocator also uses vmalloc to map module images even on non-NUMA, which can result in high iTLB pressure on highly modular distro type of kernels. This series does not implement huge mappings for modules yet, but it's a step along the way. Rick Edgecombe was looking at that IIRC.
The per-cpu allocator similarly might be able to take advantage of this. Also on the todo list.
The disadvantages of this I can see are:
* Memory fragmentation can waste some physical memory because it will attempt to allocate larger pages to fit the required size, rounding up (once the requested size is >= 2MB).
- I don't see it being a big problem in practice unless some user crops up that allocates thousands of 2.5MB ranges. We can tewak heuristics a bit there if needed to reduce peak waste.
* Less granular mappings can make the NUMA distribution less balanced.
- Similar to the above.
- Could also allocate all major system hashes with one allocation up-front and spread them all across the one block, which should help overall NUMA distribution and reduce fragmentation waste.
* Callers might expect something about the underlying allocated pages.
- Tried to keep the apperance of base PAGE_SIZE pages throughout the APIs and exposed data structures.
- Added a VM_NO_HUGE_VMAP flag to hammer troublesome cases with.
- Finally, added a nohugevmalloc boot option to turn it off (independent of nohugeiomap).
This patch (of 14):
ARM uses its own PMD folding scheme which is missing pud_page which should just pass through to pmd_page. Move this from the 3-level page table to common header.
---
arch/arm/include/asm/pgtable-3level.h | 2 -- arch/arm/include/asm/pgtable.h | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-)
arch/arm/include/asm/pgtable-3level.h renamed from arch/arm/include/asm/pgtable-3level.h~arm-mm-add-missing-pud_page-define-to-2-level-page-tables +0 -2
@@ -186,8 +186,6 @@ static inline pte_t pte_mkspecial(pte_t#define pmd_write (pmd) (pmd_isclear((pmd), L_PMD_SECT_RDONLY))#define pmd_dirty (pmd) (pmd_isset((pmd), L_PMD_SECT_DIRTY)) -#define pud_page (pud) pmd_page(__pmd(pud_val(pud))) -#define pud_write (pud) pmd_write(__pmd(pud_val(pud)))#define pmd_hugewillfault (pmd) (!pmd_young(pmd) || !pmd_write(pmd))#define pmd_thp_or_huge (pmd) (pmd_huge(pmd) || pmd_trans_huge(pmd))
arch/arm/include/asm/pgtable.h renamed from arch/arm/include/asm/pgtable.h~arm-mm-add-missing-pud_page-define-to-2-level-page-tables +3 -0
@@ -166,6 +166,9 @@ extern struct page *empty_zero_page;extern pgd_t swapper_pg_dir[PTRS_PER_PGD ]; +#define pud_page (pud) pmd_page(__pmd(pud_val(pud))) +#define pud_write (pud) pmd_write(__pmd(pud_val(pud))) +#define pmd_none (pmd) (!pmd_val(pmd))static inline pte_t *pmd_page_vaddr (pmd_t pmd)
_
Andrew Morton
maintainerPATCH 98/178 mm/vmalloc: fix HUGE_VMAP regression by enabling huge pages in vmalloc_to_page
In reply to Andrew MortonFrom: Nicholas Piggin <[email protected]>
Subject: mm/vmalloc: fix HUGE_VMAP regression by enabling huge pages in vmalloc_to_page
vmalloc_to_page returns NULL for addresses mapped by larger pages[*]. Whether or not a vmap is huge depends on the architecture details, alignments, boot options, etc., which the caller can not be expected to know. Therefore HUGE_VMAP is a regression for vmalloc_to_page.
This change teaches vmalloc_to_page about larger pages, and returns the struct page that corresponds to the offset within the large page. This makes the API agnostic to mapping implementation details.
[*] As explained by commit 029c54b095995 ("mm/vmalloc.c: huge-vmap:
fail gracefully on unexpected huge vmap mappings")
---
arch/sparc/include/asm/pgtable_32.h | 3 + mm/vmalloc.c | 41 ++++++++++++++++---------- 2 files changed, 29 insertions(+), 15 deletions(-)
arch/sparc/include/asm/pgtable_32.h renamed from arch/sparc/include/asm/pgtable_32.h~mm-vmalloc-fix-huge_vmap-regression-by-enabling-huge-pages-in-vmalloc_to_page +3 -0
@@ -321,6 +321,9 @@ static inline pte_t pte_modify(pte_t pte pgprot_val(newprot)); } +/* only used by the huge vmap code, should never be called */ +#define pud_page (pud) NULL +struct seq_file ;void mmu_info (struct seq_file *m);
mm/vmalloc.c renamed from mm/vmalloc.c~mm-vmalloc-fix-huge_vmap-regression-by-enabling-huge-pages-in-vmalloc_to_page +26 -15
71 lines not on this page · raw message
_
Andrew Morton
maintainerPATCH 99/178 mm: apply_to_pte_range warn and fail if a large pte is encountered
In reply to Andrew MortonFrom: Nicholas Piggin <[email protected]>
Subject: mm: apply_to_pte_range warn and fail if a large pte is encountered
apply_to_pte_range might mistake a large pte for bad, or treat it as a page table, resulting in a crash or corruption. Add a test to warn and return error if large entries are found.
---
mm/memory.c | 66 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 49 insertions(+), 17 deletions(-)
mm/memory.c renamed from mm/memory.c~mm-apply_to_pte_range-warn-and-fail-if-a-large-pte-is-encountered +49 -17
@@ -2457,13 +2457,21 @@ static int apply_to_pmd_range(struct mm_ }do { next =pmd_addr_end (addr, end); -if (create || !pmd_none_or_clear_bad (pmd)) { - err =apply_to_pte_range (mm, pmd, addr, next, fn, data, - create, mask); -if (err) -break ; +if (pmd_none (*pmd) && !create) +continue ; +if (WARN_ON_ONCE (pmd_leaf (*pmd))) +return -EINVAL ; +if (!pmd_none (*pmd) &&WARN_ON_ONCE (pmd_bad (*pmd))) { +if (!create) +continue ; +pmd_clear_bad (pmd); } + err =apply_to_pte_range (mm, pmd, addr, next, + fn, data, create, mask); +if (err) +break ; }while (pmd++, addr = next, addr != end); +return err; }
@@ -2485,13 +2493,21 @@ static int apply_to_pud_range(struct mm_ }do { next =pud_addr_end (addr, end); -if (create || !pud_none_or_clear_bad (pud)) { - err =apply_to_pmd_range (mm, pud, addr, next, fn, data, - create, mask); -if (err) -break ; +if (pud_none (*pud) && !create) +continue ; +if (WARN_ON_ONCE (pud_leaf (*pud))) +return -EINVAL ; +if (!pud_none (*pud) &&WARN_ON_ONCE (pud_bad (*pud))) { +if (!create) +continue ; +pud_clear_bad (pud); } + err =apply_to_pmd_range (mm, pud, addr, next, + fn, data, create, mask); +if (err) +break ; }while (pud++, addr = next, addr != end); +return err; }
@@ -2513,13 +2529,21 @@ static int apply_to_p4d_range(struct mm_ }do { next =p4d_addr_end (addr, end); -if (create || !p4d_none_or_clear_bad (p4d)) { - err =apply_to_pud_range (mm, p4d, addr, next, fn, data, - create, mask); -if (err) -break ; +if (p4d_none (*p4d) && !create) +continue ; +if (WARN_ON_ONCE (p4d_leaf (*p4d))) +return -EINVAL ; +if (!p4d_none (*p4d) &&WARN_ON_ONCE (p4d_bad (*p4d))) { +if (!create) +continue ; +p4d_clear_bad (p4d); } + err =apply_to_pud_range (mm, p4d, addr, next, + fn, data, create, mask); +if (err) +break ; }while (p4d++, addr = next, addr != end); +return err; }
@@ -2539,9 +2563,17 @@ static int __apply_to_page_range(struct pgd =pgd_offset (mm, addr);do { next =pgd_addr_end (addr, end); -if (!create &&pgd_none_or_clear_bad (pgd)) +if (pgd_none (*pgd) && !create)continue ; - err =apply_to_p4d_range (mm, pgd, addr, next, fn, data, create, &mask); +if (WARN_ON_ONCE (pgd_leaf (*pgd))) +return -EINVAL ; +if (!pgd_none (*pgd) &&WARN_ON_ONCE (pgd_bad (*pgd))) { +if (!create) +continue ; +pgd_clear_bad (pgd); + } + err =apply_to_p4d_range (mm, pgd, addr, next, + fn, data, create, &mask);if (err)break ; }while (pgd++, addr = next, addr != end);
_
Andrew Morton
maintainerPATCH 100/178 mm/vmalloc: rename vmap_*_range vmap_pages_*_range
In reply to Andrew MortonFrom: Nicholas Piggin <[email protected]>
Subject: mm/vmalloc: rename vmap_*_range vmap_pages_*_range
The vmalloc mapper operates on a struct page * array rather than a linear physical address, re-name it to make this distinction clear.
---
mm/vmalloc.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
mm/vmalloc.c renamed from mm/vmalloc.c~mm-vmalloc-rename-vmap__range-vmap_pages__range +8 -8
@@ -189,7 +189,7 @@ void unmap_kernel_range_noflush(unsignedarch_sync_kernel_mappings (start, end); } -static int vmap_pte_range (pmd_t *pmd,unsigned long addr, +static int vmap_pages_pte_range (pmd_t *pmd,unsigned long addr,unsigned long end,pgprot_t prot,struct page **pages,int *nr,pgtbl_mod_mask *mask) {
@@ -217,7 +217,7 @@ static int vmap_pte_range(pmd_t *pmd, unreturn 0 ; } -static int vmap_pmd_range (pud_t *pud,unsigned long addr, +static int vmap_pages_pmd_range (pud_t *pud,unsigned long addr,unsigned long end,pgprot_t prot,struct page **pages,int *nr,pgtbl_mod_mask *mask) {
@@ -229,13 +229,13 @@ static int vmap_pmd_range(pud_t *pud, unreturn -ENOMEM ;do { next =pmd_addr_end (addr, end); -if (vmap_pte_range (pmd, addr, next, prot, pages, nr, mask)) +if (vmap_pages_pte_range (pmd, addr, next, prot, pages, nr, mask))return -ENOMEM ; }while (pmd++, addr = next, addr != end);return 0 ; } -static int vmap_pud_range (p4d_t *p4d,unsigned long addr, +static int vmap_pages_pud_range (p4d_t *p4d,unsigned long addr,unsigned long end,pgprot_t prot,struct page **pages,int *nr,pgtbl_mod_mask *mask) {
@@ -247,13 +247,13 @@ static int vmap_pud_range(p4d_t *p4d, unreturn -ENOMEM ;do { next =pud_addr_end (addr, end); -if (vmap_pmd_range (pud, addr, next, prot, pages, nr, mask)) +if (vmap_pages_pmd_range (pud, addr, next, prot, pages, nr, mask))return -ENOMEM ; }while (pud++, addr = next, addr != end);return 0 ; } -static int vmap_p4d_range (pgd_t *pgd,unsigned long addr, +static int vmap_pages_p4d_range (pgd_t *pgd,unsigned long addr,unsigned long end,pgprot_t prot,struct page **pages,int *nr,pgtbl_mod_mask *mask) {
@@ -265,7 +265,7 @@ static int vmap_p4d_range(pgd_t *pgd, unreturn -ENOMEM ;do { next =p4d_addr_end (addr, end); -if (vmap_pud_range (p4d, addr, next, prot, pages, nr, mask)) +if (vmap_pages_pud_range (p4d, addr, next, prot, pages, nr, mask))return -ENOMEM ; }while (p4d++, addr = next, addr != end);return 0 ;
@@ -306,7 +306,7 @@ int map_kernel_range_noflush(unsigned lo next =pgd_addr_end (addr, end);if (pgd_bad (*pgd)) mask |=PGTBL_PGD_MODIFIED ; - err =vmap_p4d_range (pgd, addr, next, prot, pages, &nr, &mask); + err =vmap_pages_p4d_range (pgd, addr, next, prot, pages, &nr, &mask);if (err)return err; }while (pgd++, addr = next, addr != end);
_
Andrew Morton
maintainerPATCH 101/178 mm/ioremap: rename ioremap_*_range to vmap_*_range
In reply to Andrew MortonFrom: Nicholas Piggin <[email protected]>
Subject: mm/ioremap: rename ioremap_*_range to vmap_*_range
This will be used as a generic kernel virtual mapping function, so re-name it in preparation.
---
mm/ioremap.c | 64 +++++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 31 deletions(-)
mm/ioremap.c renamed from mm/ioremap.c~mm-ioremap-rename-ioremap__range-to-vmap__range +33 -31
@@ -61,9 +61,9 @@ static inline int ioremap_pud_enabled(vostatic inline int ioremap_pmd_enabled (void ) {return 0 ; }#endif /* CONFIG_HAVE_ARCH_HUGE_VMAP */ -static int ioremap_pte_range (pmd_t *pmd,unsigned long addr, -unsigned long end,phys_addr_t phys_addr,pgprot_t prot, -pgtbl_mod_mask *mask) +static int vmap_pte_range (pmd_t *pmd,unsigned long addr,unsigned long end, +phys_addr_t phys_addr,pgprot_t prot, +pgtbl_mod_mask *mask) {pte_t *pte;u64 pfn;
@@ -81,9 +81,8 @@ static int ioremap_pte_range(pmd_t *pmd,return 0 ; } -static int ioremap_try_huge_pmd (pmd_t *pmd,unsigned long addr, -unsigned long end,phys_addr_t phys_addr, -pgprot_t prot) +static int vmap_try_huge_pmd (pmd_t *pmd,unsigned long addr,unsigned long end, +phys_addr_t phys_addr,pgprot_t prot) {if (!ioremap_pmd_enabled ())return 0 ;
@@ -103,9 +102,9 @@ static int ioremap_try_huge_pmd(pmd_t *preturn pmd_set_huge (pmd, phys_addr, prot); } -static inline int ioremap_pmd_range (pud_t *pud,unsigned long addr, -unsigned long end,phys_addr_t phys_addr,pgprot_t prot, -pgtbl_mod_mask *mask) +static int vmap_pmd_range (pud_t *pud,unsigned long addr,unsigned long end, +phys_addr_t phys_addr,pgprot_t prot, +pgtbl_mod_mask *mask) {pmd_t *pmd;unsigned long next;
@@ -116,20 +115,19 @@ static inline int ioremap_pmd_range(pud_do { next =pmd_addr_end (addr, end); -if (ioremap_try_huge_pmd (pmd, addr, next, phys_addr, prot)) { +if (vmap_try_huge_pmd (pmd, addr, next, phys_addr, prot)) { *mask |=PGTBL_PMD_MODIFIED ;continue ; } -if (ioremap_pte_range (pmd, addr, next, phys_addr, prot, mask)) +if (vmap_pte_range (pmd, addr, next, phys_addr, prot, mask))return -ENOMEM ; }while (pmd++, phys_addr += (next - addr), addr = next, addr != end);return 0 ; } -static int ioremap_try_huge_pud (pud_t *pud,unsigned long addr, -unsigned long end,phys_addr_t phys_addr, -pgprot_t prot) +static int vmap_try_huge_pud (pud_t *pud,unsigned long addr,unsigned long end, +phys_addr_t phys_addr,pgprot_t prot) {if (!ioremap_pud_enabled ())return 0 ;
@@ -149,9 +147,9 @@ static int ioremap_try_huge_pud(pud_t *preturn pud_set_huge (pud, phys_addr, prot); } -static inline int ioremap_pud_range (p4d_t *p4d,unsigned long addr, -unsigned long end,phys_addr_t phys_addr,pgprot_t prot, -pgtbl_mod_mask *mask) +static int vmap_pud_range (p4d_t *p4d,unsigned long addr,unsigned long end, +phys_addr_t phys_addr,pgprot_t prot, +pgtbl_mod_mask *mask) {pud_t *pud;unsigned long next;
@@ -162,20 +160,19 @@ static inline int ioremap_pud_range(p4d_do { next =pud_addr_end (addr, end); -if (ioremap_try_huge_pud (pud, addr, next, phys_addr, prot)) { +if (vmap_try_huge_pud (pud, addr, next, phys_addr, prot)) { *mask |=PGTBL_PUD_MODIFIED ;continue ; } -if (ioremap_pmd_range (pud, addr, next, phys_addr, prot, mask)) +if (vmap_pmd_range (pud, addr, next, phys_addr, prot, mask))return -ENOMEM ; }while (pud++, phys_addr += (next - addr), addr = next, addr != end);return 0 ; } -static int ioremap_try_huge_p4d (p4d_t *p4d,unsigned long addr, -unsigned long end,phys_addr_t phys_addr, -pgprot_t prot) +static int vmap_try_huge_p4d (p4d_t *p4d,unsigned long addr,unsigned long end, +phys_addr_t phys_addr,pgprot_t prot) {if (!ioremap_p4d_enabled ())return 0 ;
@@ -195,9 +192,9 @@ static int ioremap_try_huge_p4d(p4d_t *preturn p4d_set_huge (p4d, phys_addr, prot); } -static inline int ioremap_p4d_range (pgd_t *pgd,unsigned long addr, -unsigned long end,phys_addr_t phys_addr,pgprot_t prot, -pgtbl_mod_mask *mask) +static int vmap_p4d_range (pgd_t *pgd,unsigned long addr,unsigned long end, +phys_addr_t phys_addr,pgprot_t prot, +pgtbl_mod_mask *mask) {p4d_t *p4d;unsigned long next;
@@ -208,19 +205,19 @@ static inline int ioremap_p4d_range(pgd_do { next =p4d_addr_end (addr, end); -if (ioremap_try_huge_p4d (p4d, addr, next, phys_addr, prot)) { +if (vmap_try_huge_p4d (p4d, addr, next, phys_addr, prot)) { *mask |=PGTBL_P4D_MODIFIED ;continue ; } -if (ioremap_pud_range (p4d, addr, next, phys_addr, prot, mask)) +if (vmap_pud_range (p4d, addr, next, phys_addr, prot, mask))return -ENOMEM ; }while (p4d++, phys_addr += (next - addr), addr = next, addr != end);return 0 ; } -int ioremap_page_range (unsigned long addr, -unsigned long end,phys_addr_t phys_addr,pgprot_t prot) +static int vmap_range (unsigned long addr,unsigned long end, +phys_addr_t phys_addr,pgprot_t prot) {pgd_t *pgd;unsigned long start;
@@ -235,8 +232,7 @@ int ioremap_page_range(unsigned long add pgd =pgd_offset_k (addr);do { next =pgd_addr_end (addr, end); - err =ioremap_p4d_range (pgd, addr, next, phys_addr, prot, - &mask); + err =vmap_p4d_range (pgd, addr, next, phys_addr, prot, &mask);if (err)break ; }while (pgd++, phys_addr += (next - addr), addr = next, addr != end);
@@ -249,6 +245,12 @@ int ioremap_page_range(unsigned long addreturn err; } +int ioremap_page_range (unsigned long addr, +unsigned long end,phys_addr_t phys_addr,pgprot_t prot) +{ +return vmap_range (addr, end, phys_addr, prot); +} +#ifdef CONFIG_GENERIC_IOREMAP void __iomem *ioremap_prot (phys_addr_t addr,size_t size,unsigned long prot) {
_
Andrew Morton
maintainerPATCH 102/178 mm: HUGE_VMAP arch support cleanup
In reply to Andrew MortonFrom: Nicholas Piggin <[email protected]>
Subject: mm: HUGE_VMAP arch support cleanup
This changes the awkward approach where architectures provide init functions to determine which levels they can provide large mappings for, to one where the arch is queried for each call.
This removes code and indirection, and allows constant-folding of dead code for unsupported levels.
This also adds a prot argument to the arch query. This is unused currently but could help with some architectures (e.g., some powerpc processors can't map uncacheable memory with large pages).
---
arch/arm64/include/asm/vmalloc.h | 8 + arch/arm64/mm/mmu.c | 10 +- arch/powerpc/include/asm/vmalloc.h | 8 + arch/powerpc/mm/book3s64/radix_pgtable.c | 8 - arch/x86/include/asm/vmalloc.h | 7 + arch/x86/mm/ioremap.c | 12 +- include/linux/io.h | 9 -- include/linux/vmalloc.h | 6 + init/main.c | 1 mm/debug_vm_pgtable.c | 4 mm/ioremap.c | 94 ++++++++------------- 11 files changed, 87 insertions(+), 80 deletions(-)
arch/arm64/include/asm/vmalloc.h renamed from arch/arm64/include/asm/vmalloc.h~mm-huge_vmap-arch-support-cleanup +8 -0
@@ -1,4 +1,12 @@#ifndef _ASM_ARM64_VMALLOC_H#define _ASM_ARM64_VMALLOC_H +#include <asm/page.h> + +#ifdef CONFIG_HAVE_ARCH_HUGE_VMAP +bool arch_vmap_p4d_supported (pgprot_t prot); +bool arch_vmap_pud_supported (pgprot_t prot); +bool arch_vmap_pmd_supported (pgprot_t prot); +#endif +#endif /* _ASM_ARM64_VMALLOC_H */
arch/arm64/mm/mmu.c renamed from arch/arm64/mm/mmu.c~mm-huge_vmap-arch-support-cleanup +5 -5
@@ -1339,12 +1339,12 @@ void *__init fixmap_remap_fdt(phys_addr_return dt_virt; } -int __init arch_ioremap_p4d_supported (void ) +bool arch_vmap_p4d_supported (pgprot_t prot) { -return 0 ; +return false; } -int __init arch_ioremap_pud_supported (void ) +bool arch_vmap_pud_supported (pgprot_t prot) {/* * Only 4k granule supports level 1 block mappings.
@@ -1354,9 +1354,9 @@ int __init arch_ioremap_pud_supported(vo !IS_ENABLED (CONFIG_PTDUMP_DEBUGFS ); } -int __init arch_ioremap_pmd_supported (void ) +bool arch_vmap_pmd_supported (pgprot_t prot) { -/* See arch_ioremap_pud_supported() */ +/* See arch_vmap_pud_supported() */ return !IS_ENABLED (CONFIG_PTDUMP_DEBUGFS ); }
arch/powerpc/include/asm/vmalloc.h renamed from arch/powerpc/include/asm/vmalloc.h~mm-huge_vmap-arch-support-cleanup +8 -0
@@ -1,4 +1,12 @@#ifndef _ASM_POWERPC_VMALLOC_H#define _ASM_POWERPC_VMALLOC_H +#include <asm/page.h> + +#ifdef CONFIG_HAVE_ARCH_HUGE_VMAP +bool arch_vmap_p4d_supported (pgprot_t prot); +bool arch_vmap_pud_supported (pgprot_t prot); +bool arch_vmap_pmd_supported (pgprot_t prot); +#endif +#endif /* _ASM_POWERPC_VMALLOC_H */
arch/powerpc/mm/book3s64/radix_pgtable.c renamed from arch/powerpc/mm/book3s64/radix_pgtable.c~mm-huge_vmap-arch-support-cleanup +4 -4
@@ -1082,13 +1082,13 @@ void radix__ptep_modify_prot_commit(struset_pte_at (mm, addr, ptep, pte); } -int __init arch_ioremap_pud_supported (void ) +bool arch_vmap_pud_supported (pgprot_t prot) {/* HPT does not cope with large pages in the vmalloc area */ return radix_enabled (); } -int __init arch_ioremap_pmd_supported (void ) +bool arch_vmap_pmd_supported (pgprot_t prot) {return radix_enabled (); }
@@ -1182,7 +1182,7 @@ int pmd_free_pte_page(pmd_t *pmd, unsignreturn 1 ; } -int __init arch_ioremap_p4d_supported (void ) +bool arch_vmap_p4d_supported (pgprot_t prot) { -return 0 ; +return false; }
arch/x86/include/asm/vmalloc.h renamed from arch/x86/include/asm/vmalloc.h~mm-huge_vmap-arch-support-cleanup +7 -0
@@ -1,6 +1,13 @@#ifndef _ASM_X86_VMALLOC_H#define _ASM_X86_VMALLOC_H +#include <asm/page.h> #include <asm/pgtable_areas.h> +#ifdef CONFIG_HAVE_ARCH_HUGE_VMAP +bool arch_vmap_p4d_supported (pgprot_t prot); +bool arch_vmap_pud_supported (pgprot_t prot); +bool arch_vmap_pmd_supported (pgprot_t prot); +#endif +#endif /* _ASM_X86_VMALLOC_H */
arch/x86/mm/ioremap.c renamed from arch/x86/mm/ioremap.c~mm-huge_vmap-arch-support-cleanup +7 -5
@@ -481,24 +481,26 @@ void iounmap(volatile void __iomem *addr }EXPORT_SYMBOL (iounmap); -int __init arch_ioremap_p4d_supported (void ) +#ifdef CONFIG_HAVE_ARCH_HUGE_VMAP +bool arch_vmap_p4d_supported (pgprot_t prot) { -return 0 ; +return false; } -int __init arch_ioremap_pud_supported (void ) +bool arch_vmap_pud_supported (pgprot_t prot) {#ifdef CONFIG_X86_64 return boot_cpu_has (X86_FEATURE_GBPAGES );#else -return 0 ; +return false;#endif } -int __init arch_ioremap_pmd_supported (void ) +bool arch_vmap_pmd_supported (pgprot_t prot) {return boot_cpu_has (X86_FEATURE_PSE ); } +#endif /* * Convert a physical pointer to a virtual kernel pointer for /dev/mem
include/linux/io.h renamed from include/linux/io.h~mm-huge_vmap-arch-support-cleanup +0 -9
@@ -31,15 +31,6 @@ static inline int ioremap_page_range(uns }#endif -#ifdef CONFIG_HAVE_ARCH_HUGE_VMAP -void __init ioremap_huge_init (void ); -int arch_ioremap_p4d_supported (void ); -int arch_ioremap_pud_supported (void ); -int arch_ioremap_pmd_supported (void ); -#else -static inline void ioremap_huge_init (void ) { } -#endif -/* * Managed iomap interface */
include/linux/vmalloc.h renamed from include/linux/vmalloc.h~mm-huge_vmap-arch-support-cleanup +6 -0
@@ -78,6 +78,12 @@ struct vmap_area { }; }; +#ifndef CONFIG_HAVE_ARCH_HUGE_VMAP +static inline bool arch_vmap_p4d_supported (pgprot_t prot) {return false; } +static inline bool arch_vmap_pud_supported (pgprot_t prot) {return false; } +static inline bool arch_vmap_pmd_supported (pgprot_t prot) {return false; } +#endif +/* * Highlevel APIs for driver use */
init/main.c renamed from init/main.c~mm-huge_vmap-arch-support-cleanup +0 -1
@@ -837,7 +837,6 @@ static void __init mm_init(void)pgtable_init ();debug_objects_mem_init ();vmalloc_init (); -ioremap_huge_init ();/* Should be run before the first non-init thread is created */ init_espfix_bsp ();/* Should be run after espfix64 is set up. */
mm/debug_vm_pgtable.c renamed from mm/debug_vm_pgtable.c~mm-huge_vmap-arch-support-cleanup +2 -2
@@ -247,7 +247,7 @@ static void __init pmd_huge_tests(pmd_t {pmd_t pmd; -if (!arch_ioremap_pmd_supported ()) +if (!arch_vmap_pmd_supported (prot))return ;pr_debug ("Validating PMD huge\n" );
@@ -385,7 +385,7 @@ static void __init pud_huge_tests(pud_t {pud_t pud; -if (!arch_ioremap_pud_supported ()) +if (!arch_vmap_pud_supported (prot))return ;pr_debug ("Validating PUD huge\n" );
mm/ioremap.c renamed from mm/ioremap.c~mm-huge_vmap-arch-support-cleanup +40 -54
189 lines not on this page · raw message
_
Andrew Morton
maintainerPATCH 103/178 powerpc: inline huge vmap supported functions
In reply to Andrew MortonFrom: Nicholas Piggin <[email protected]>
Subject: powerpc: inline huge vmap supported functions
This allows unsupported levels to be constant folded away, and so p4d_free_pud_page can be removed because it's no longer linked to.
---
arch/powerpc/include/asm/vmalloc.h | 19 ++++++++++++++++--- arch/powerpc/mm/book3s64/radix_pgtable.c | 21 --------------------- 2 files changed, 16 insertions(+), 24 deletions(-)
arch/powerpc/include/asm/vmalloc.h renamed from arch/powerpc/include/asm/vmalloc.h~powerpc-inline-huge-vmap-supported-functions +16 -3
@@ -1,12 +1,25 @@#ifndef _ASM_POWERPC_VMALLOC_H#define _ASM_POWERPC_VMALLOC_H +#include <asm/mmu.h> #include <asm/page.h> #ifdef CONFIG_HAVE_ARCH_HUGE_VMAP -bool arch_vmap_p4d_supported (pgprot_t prot); -bool arch_vmap_pud_supported (pgprot_t prot); -bool arch_vmap_pmd_supported (pgprot_t prot); +static inline bool arch_vmap_p4d_supported (pgprot_t prot) +{ +return false; +} + +static inline bool arch_vmap_pud_supported (pgprot_t prot) +{ +/* HPT does not cope with large pages in the vmalloc area */ +return radix_enabled (); +} + +static inline bool arch_vmap_pmd_supported (pgprot_t prot) +{ +return radix_enabled (); +}#endif #endif /* _ASM_POWERPC_VMALLOC_H */
arch/powerpc/mm/book3s64/radix_pgtable.c renamed from arch/powerpc/mm/book3s64/radix_pgtable.c~powerpc-inline-huge-vmap-supported-functions +0 -21
@@ -1082,22 +1082,6 @@ void radix__ptep_modify_prot_commit(struset_pte_at (mm, addr, ptep, pte); } -bool arch_vmap_pud_supported (pgprot_t prot) -{ -/* HPT does not cope with large pages in the vmalloc area */ -return radix_enabled (); -} - -bool arch_vmap_pmd_supported (pgprot_t prot) -{ -return radix_enabled (); -} - -int p4d_free_pud_page (p4d_t *p4d,unsigned long addr) -{ -return 0 ; -} -int pud_set_huge (pud_t *pud,phys_addr_t addr,pgprot_t prot) {pte_t *ptep = (pte_t *)pud;
@@ -1181,8 +1165,3 @@ int pmd_free_pte_page(pmd_t *pmd, unsignreturn 1 ; } - -bool arch_vmap_p4d_supported (pgprot_t prot) -{ -return false; -}
_
Andrew Morton
maintainerPATCH 104/178 arm64: inline huge vmap supported functions
In reply to Andrew MortonFrom: Nicholas Piggin <[email protected]>
Subject: arm64: inline huge vmap supported functions
This allows unsupported levels to be constant folded away, and so p4d_free_pud_page can be removed because it's no longer linked to.
---
arch/arm64/include/asm/vmalloc.h | 23 ++++++++++++++++++++--- arch/arm64/mm/mmu.c | 26 -------------------------- 2 files changed, 20 insertions(+), 29 deletions(-)
arch/arm64/include/asm/vmalloc.h renamed from arch/arm64/include/asm/vmalloc.h~arm64-inline-huge-vmap-supported-functions +20 -3
@@ -4,9 +4,26 @@#include <asm/page.h> #ifdef CONFIG_HAVE_ARCH_HUGE_VMAP -bool arch_vmap_p4d_supported (pgprot_t prot); -bool arch_vmap_pud_supported (pgprot_t prot); -bool arch_vmap_pmd_supported (pgprot_t prot); +static inline bool arch_vmap_p4d_supported (pgprot_t prot) +{ +return false; +} + +static inline bool arch_vmap_pud_supported (pgprot_t prot) +{ +/* +* Only 4k granule supports level 1 block mappings. +* SW table walks can't handle removal of intermediate entries. +*/ +return IS_ENABLED (CONFIG_ARM64_4K_PAGES ) && + !IS_ENABLED (CONFIG_PTDUMP_DEBUGFS ); +} + +static inline bool arch_vmap_pmd_supported (pgprot_t prot) +{ +/* See arch_vmap_pud_supported() */ +return !IS_ENABLED (CONFIG_PTDUMP_DEBUGFS ); +}#endif #endif /* _ASM_ARM64_VMALLOC_H */
arch/arm64/mm/mmu.c renamed from arch/arm64/mm/mmu.c~arm64-inline-huge-vmap-supported-functions +0 -26
@@ -1339,27 +1339,6 @@ void *__init fixmap_remap_fdt(phys_addr_return dt_virt; } -bool arch_vmap_p4d_supported (pgprot_t prot) -{ -return false; -} - -bool arch_vmap_pud_supported (pgprot_t prot) -{ -/* -* Only 4k granule supports level 1 block mappings. -* SW table walks can't handle removal of intermediate entries. -*/ -return IS_ENABLED (CONFIG_ARM64_4K_PAGES ) && - !IS_ENABLED (CONFIG_PTDUMP_DEBUGFS ); -} - -bool arch_vmap_pmd_supported (pgprot_t prot) -{ -/* See arch_vmap_pud_supported() */ -return !IS_ENABLED (CONFIG_PTDUMP_DEBUGFS ); -} -int pud_set_huge (pud_t *pudp,phys_addr_t phys,pgprot_t prot) {pud_t new_pud =pfn_pud (__phys_to_pfn (phys),mk_pud_sect_prot (prot));
@@ -1451,11 +1430,6 @@ int pud_free_pmd_page(pud_t *pudp, unsigreturn 1 ; } -int p4d_free_pud_page (p4d_t *p4d,unsigned long addr) -{ -return 0 ;/* Don't attempt a block mapping */ -} -#ifdef CONFIG_MEMORY_HOTPLUG static void __remove_pgd_mapping (pgd_t *pgdir,unsigned long start,u64 size) {
_
Andrew Morton
maintainerPATCH 105/178 x86: inline huge vmap supported functions
In reply to Andrew MortonFrom: Nicholas Piggin <[email protected]>
Subject: x86: inline huge vmap supported functions
This allows unsupported levels to be constant folded away, and so p4d_free_pud_page can be removed because it's no longer linked to.
---
arch/x86/include/asm/vmalloc.h | 22 +++++++++++++++++++--- arch/x86/mm/ioremap.c | 21 --------------------- arch/x86/mm/pgtable.c | 13 ------------- 3 files changed, 19 insertions(+), 37 deletions(-)
arch/x86/include/asm/vmalloc.h renamed from arch/x86/include/asm/vmalloc.h~x86-inline-huge-vmap-supported-functions +19 -3
@@ -1,13 +1,29 @@#ifndef _ASM_X86_VMALLOC_H#define _ASM_X86_VMALLOC_H +#include <asm/cpufeature.h> #include <asm/page.h> #include <asm/pgtable_areas.h> #ifdef CONFIG_HAVE_ARCH_HUGE_VMAP -bool arch_vmap_p4d_supported (pgprot_t prot); -bool arch_vmap_pud_supported (pgprot_t prot); -bool arch_vmap_pmd_supported (pgprot_t prot); +static inline bool arch_vmap_p4d_supported (pgprot_t prot) +{ +return false; +} + +static inline bool arch_vmap_pud_supported (pgprot_t prot) +{ +#ifdef CONFIG_X86_64 +return boot_cpu_has (X86_FEATURE_GBPAGES ); +#else +return false; +#endif +} + +static inline bool arch_vmap_pmd_supported (pgprot_t prot) +{ +return boot_cpu_has (X86_FEATURE_PSE ); +}#endif #endif /* _ASM_X86_VMALLOC_H */
arch/x86/mm/ioremap.c renamed from arch/x86/mm/ioremap.c~x86-inline-huge-vmap-supported-functions +0 -21
@@ -481,27 +481,6 @@ void iounmap(volatile void __iomem *addr }EXPORT_SYMBOL (iounmap); -#ifdef CONFIG_HAVE_ARCH_HUGE_VMAP -bool arch_vmap_p4d_supported (pgprot_t prot) -{ -return false; -} - -bool arch_vmap_pud_supported (pgprot_t prot) -{ -#ifdef CONFIG_X86_64 -return boot_cpu_has (X86_FEATURE_GBPAGES ); -#else -return false; -#endif -} - -bool arch_vmap_pmd_supported (pgprot_t prot) -{ -return boot_cpu_has (X86_FEATURE_PSE ); -} -#endif -/* * Convert a physical pointer to a virtual kernel pointer for /dev/mem * access
arch/x86/mm/pgtable.c renamed from arch/x86/mm/pgtable.c~x86-inline-huge-vmap-supported-functions +0 -13
@@ -780,14 +780,6 @@ int pmd_clear_huge(pmd_t *pmd)return 0 ; } -/* -* Until we support 512GB pages, skip them in the vmap area. -*/ -int p4d_free_pud_page (p4d_t *p4d,unsigned long addr) -{ -return 0 ; -} -#ifdef CONFIG_X86_64 /** * pud_free_pmd_page - Clear pud entry and free pmd page.
@@ -861,11 +853,6 @@ int pmd_free_pte_page(pmd_t *pmd, unsign#else /* !CONFIG_X86_64 */ -int pud_free_pmd_page (pud_t *pud,unsigned long addr) -{ -return pud_none (*pud); -} -/* * Disable free page handling on x86-PAE. This assures that ioremap() * does not update sync'd pmd entries. See vmalloc_sync_one().
_
Andrew Morton
maintainerPATCH 106/178 mm/vmalloc: provide fallback arch huge vmap support functions
In reply to Andrew MortonFrom: Nicholas Piggin <[email protected]>
Subject: mm/vmalloc: provide fallback arch huge vmap support functions
If an architecture doesn't support a particular page table level as a huge vmap page size then allow it to skip defining the support query function.
---
arch/arm64/include/asm/vmalloc.h | 7 +++---- arch/powerpc/include/asm/vmalloc.h | 7 +++---- arch/x86/include/asm/vmalloc.h | 13 +++++-------- include/linux/vmalloc.h | 24 ++++++++++++++++++++---- 4 files changed, 31 insertions(+), 20 deletions(-)
arch/arm64/include/asm/vmalloc.h renamed from arch/arm64/include/asm/vmalloc.h~mm-vmalloc-provide-fallback-arch-huge-vmap-support-functions +3 -4
@@ -4,11 +4,8 @@#include <asm/page.h> #ifdef CONFIG_HAVE_ARCH_HUGE_VMAP -static inline bool arch_vmap_p4d_supported (pgprot_t prot) -{ -return false; -} +#define arch_vmap_pud_supported arch_vmap_pud_supportedstatic inline bool arch_vmap_pud_supported (pgprot_t prot) {/*
@@ -19,11 +16,13 @@ static inline bool arch_vmap_pud_support !IS_ENABLED (CONFIG_PTDUMP_DEBUGFS ); } +#define arch_vmap_pmd_supported arch_vmap_pmd_supportedstatic inline bool arch_vmap_pmd_supported (pgprot_t prot) {/* See arch_vmap_pud_supported() */ return !IS_ENABLED (CONFIG_PTDUMP_DEBUGFS ); } +#endif #endif /* _ASM_ARM64_VMALLOC_H */
arch/powerpc/include/asm/vmalloc.h renamed from arch/powerpc/include/asm/vmalloc.h~mm-vmalloc-provide-fallback-arch-huge-vmap-support-functions +3 -4
@@ -5,21 +5,20 @@#include <asm/page.h> #ifdef CONFIG_HAVE_ARCH_HUGE_VMAP -static inline bool arch_vmap_p4d_supported (pgprot_t prot) -{ -return false; -} +#define arch_vmap_pud_supported arch_vmap_pud_supportedstatic inline bool arch_vmap_pud_supported (pgprot_t prot) {/* HPT does not cope with large pages in the vmalloc area */ return radix_enabled (); } +#define arch_vmap_pmd_supported arch_vmap_pmd_supportedstatic inline bool arch_vmap_pmd_supported (pgprot_t prot) {return radix_enabled (); } +#endif #endif /* _ASM_POWERPC_VMALLOC_H */
arch/x86/include/asm/vmalloc.h renamed from arch/x86/include/asm/vmalloc.h~mm-vmalloc-provide-fallback-arch-huge-vmap-support-functions +5 -8
@@ -6,24 +6,21 @@#include <asm/pgtable_areas.h> #ifdef CONFIG_HAVE_ARCH_HUGE_VMAP -static inline bool arch_vmap_p4d_supported (pgprot_t prot) -{ -return false; -} +#ifdef CONFIG_X86_64 +#define arch_vmap_pud_supported arch_vmap_pud_supportedstatic inline bool arch_vmap_pud_supported (pgprot_t prot) { -#ifdef CONFIG_X86_64 return boot_cpu_has (X86_FEATURE_GBPAGES ); -#else -return false; -#endif } +#endif +#define arch_vmap_pmd_supported arch_vmap_pmd_supportedstatic inline bool arch_vmap_pmd_supported (pgprot_t prot) {return boot_cpu_has (X86_FEATURE_PSE ); } +#endif #endif /* _ASM_X86_VMALLOC_H */
include/linux/vmalloc.h renamed from include/linux/vmalloc.h~mm-vmalloc-provide-fallback-arch-huge-vmap-support-functions +20 -4
@@ -78,10 +78,26 @@ struct vmap_area { }; }; -#ifndef CONFIG_HAVE_ARCH_HUGE_VMAP -static inline bool arch_vmap_p4d_supported (pgprot_t prot) {return false; } -static inline bool arch_vmap_pud_supported (pgprot_t prot) {return false; } -static inline bool arch_vmap_pmd_supported (pgprot_t prot) {return false; } +/* archs that select HAVE_ARCH_HUGE_VMAP should override one or more of these */ +#ifndef arch_vmap_p4d_supported +static inline bool arch_vmap_p4d_supported (pgprot_t prot) +{ +return false; +} +#endif + +#ifndef arch_vmap_pud_supported +static inline bool arch_vmap_pud_supported (pgprot_t prot) +{ +return false; +} +#endif + +#ifndef arch_vmap_pmd_supported +static inline bool arch_vmap_pmd_supported (pgprot_t prot) +{ +return false; +}#endif /*
_
Andrew Morton
maintainerPATCH 107/178 mm: move vmap_range from mm/ioremap.c to mm/vmalloc.c
In reply to Andrew MortonFrom: Nicholas Piggin <[email protected]>
Subject: mm: move vmap_range from mm/ioremap.c to mm/vmalloc.c
This is a generic kernel virtual memory mapper, not specific to ioremap.
Code is unchanged other than making vmap_range non-static.
---
include/linux/vmalloc.h | 3 mm/ioremap.c | 203 -------------------------------------- mm/vmalloc.c | 202 +++++++++++++++++++++++++++++++++++++ 3 files changed, 205 insertions(+), 203 deletions(-)
include/linux/vmalloc.h renamed from include/linux/vmalloc.h~mm-move-vmap_range-from-mm-ioremapc-to-mm-vmallocc +3 -0
@@ -189,6 +189,9 @@ extern struct vm_struct *remove_vm_area(extern struct vm_struct *find_vm_area (const void *addr);#ifdef CONFIG_MMU +int vmap_range (unsigned long addr,unsigned long end, +phys_addr_t phys_addr,pgprot_t prot, +unsigned int max_page_shift);extern int map_kernel_range_noflush (unsigned long start,unsigned long size,pgprot_t prot,struct page **pages); int map_kernel_range(unsigned long start, unsigned long size, pgprot_t prot,
mm/ioremap.c renamed from mm/ioremap.c~mm-move-vmap_range-from-mm-ioremapc-to-mm-vmallocc +0 -203
209 lines not on this page · raw message
mm/vmalloc.c renamed from mm/vmalloc.c~mm-move-vmap_range-from-mm-ioremapc-to-mm-vmallocc +202 -0
208 lines not on this page · raw message
_
Andrew Morton
maintainerPATCH 108/178 mm/vmalloc: add vmap_range_noflush variant
In reply to Andrew MortonFrom: Nicholas Piggin <[email protected]>
Subject: mm/vmalloc: add vmap_range_noflush variant
As a side-effect, the order of flush_cache_vmap() and arch_sync_kernel_mappings() calls are switched, but that now matches the other callers in this file.
---
mm/vmalloc.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
mm/vmalloc.c renamed from mm/vmalloc.c~mm-vmalloc-add-vmap_range_noflush-variant +13 -3
@@ -240,7 +240,7 @@ static int vmap_p4d_range(pgd_t *pgd, unreturn 0 ; } -int vmap_range (unsigned long addr,unsigned long end, +static int vmap_range_noflush (unsigned long addr,unsigned long end,phys_addr_t phys_addr,pgprot_t prot,unsigned int max_page_shift) {
@@ -263,13 +263,23 @@ int vmap_range(unsigned long addr, unsigbreak ; }while (pgd++, phys_addr += (next - addr), addr = next, addr != end); -flush_cache_vmap (start, end); -if (mask &ARCH_PAGE_TABLE_SYNC_MASK )arch_sync_kernel_mappings (start, end);return err; } + +int vmap_range (unsigned long addr,unsigned long end, +phys_addr_t phys_addr,pgprot_t prot, +unsigned int max_page_shift) +{ +int err; + + err =vmap_range_noflush (addr, end, phys_addr, prot, max_page_shift); +flush_cache_vmap (addr, end); + +return err; +}static void vunmap_pte_range (pmd_t *pmd,unsigned long addr,unsigned long end,pgtbl_mod_mask *mask)
_
Andrew Morton
maintainerPATCH 109/178 mm/vmalloc: hugepage vmalloc mappings
In reply to Andrew MortonFrom: Nicholas Piggin <[email protected]>
Subject: mm/vmalloc: hugepage vmalloc mappings
Support huge page vmalloc mappings. Config option HAVE_ARCH_HUGE_VMALLOC enables support on architectures that define HAVE_ARCH_HUGE_VMAP and supports PMD sized vmap mappings.
vmalloc will attempt to allocate PMD-sized pages if allocating PMD size or larger, and fall back to small pages if that was unsuccessful.
Architectures must ensure that any arch specific vmalloc allocations that require PAGE_SIZE mappings (e.g., module allocations vs strict module rwx) use the VM_NOHUGE flag to inhibit larger mappings.
This can result in more internal fragmentation and memory overhead for a given allocation, an option nohugevmalloc is added to disable at boot.
---
arch/Kconfig | 11 + include/linux/vmalloc.h | 21 +++ mm/page_alloc.c | 5 mm/vmalloc.c | 220 +++++++++++++++++++++++++++++--------- 4 files changed, 209 insertions(+), 48 deletions(-)
arch/Kconfig renamed from arch/Kconfig~mm-vmalloc-hugepage-vmalloc-mappings +11 -0
@@ -829,6 +829,17 @@ config HAVE_ARCH_TRANSPARENT_HUGEPAGE_PU config HAVE_ARCH_HUGE_VMAP bool +# +# Archs that select this would be capable of PMD-sized vmaps (i.e., +# arch_vmap_pmd_supported() returns true), and they must make no assumptions +# that vmalloc memory is mapped with PAGE_SIZE ptes. The VM_NO_HUGE_VMAP flag +# can be used to prohibit arch-specific allocations from using hugepages to +# help with this (e.g., modules may require it). +# +config HAVE_ARCH_HUGE_VMALLOC + depends on HAVE_ARCH_HUGE_VMAP + bool + config ARCH_WANT_HUGE_PMD_SHARE bool
include/linux/vmalloc.h renamed from include/linux/vmalloc.h~mm-vmalloc-hugepage-vmalloc-mappings +21 -0
@@ -26,6 +26,7 @@ struct notifier_block; /* in notifier.h#define VM_KASAN 0x00000080/* has allocated kasan shadow memory */ #define VM_FLUSH_RESET_PERMS 0x00000100/* reset direct map and flush TLB on unmap, can't be freed in atomic context */ #define VM_MAP_PUT_PAGES 0x00000200/* put pages and free array in vfree */ +#define VM_NO_HUGE_VMAP 0x00000400/* force PAGE_SIZE pte mapping */ /* * VM_KASAN is used slighly differently depending on CONFIG_KASAN_VMALLOC.
@@ -54,6 +55,9 @@ struct vm_struct {unsigned long size;unsigned long flags;struct page **pages; +#ifdef CONFIG_HAVE_ARCH_HUGE_VMALLOC +unsigned int page_order; +#endif unsigned int nr_pages;phys_addr_t phys_addr;const void *caller;
@@ -188,6 +192,22 @@ void free_vm_area(struct vm_struct *areaextern struct vm_struct *remove_vm_area (const void *addr);extern struct vm_struct *find_vm_area (const void *addr); +static inline bool is_vm_area_hugepages (const void *addr) +{ +/* +* This may not 100% tell if the area is mapped with > PAGE_SIZE +* page table entries, if for some reason the architecture indicates +* larger sizes are available but decides not to use them, nothing +* prevents that. This only indicates the size of the physical page +* allocated in the vmalloc layer. +*/ +#ifdef CONFIG_HAVE_ARCH_HUGE_VMALLOC +return find_vm_area (addr)->page_order >0 ; +#else +return false; +#endif +} +#ifdef CONFIG_MMU int vmap_range(unsigned long addr, unsigned long end, phys_addr_t phys_addr, pgprot_t prot,
@@ -205,6 +225,7 @@ static inline void set_vm_flush_reset_peif (vm) vm->flags |=VM_FLUSH_RESET_PERMS ; } +#else static inline int map_kernel_range_noflush(unsigned long start, unsigned long size,
mm/page_alloc.c renamed from mm/page_alloc.c~mm-vmalloc-hugepage-vmalloc-mappings +4 -1
@@ -72,6 +72,7 @@#include <linux/padata.h> #include <linux/khugepaged.h> #include <linux/buffer_head.h> +#include <linux/vmalloc.h> #include <asm/sections.h> #include <asm/tlbflush.h>
@@ -8222,6 +8223,7 @@ void *__init alloc_large_system_hash(convoid *table =NULL ;gfp_t gfp_flags;bool virt; +bool huge;/* allow the kernel cmdline to have a say */ if (!numentries) {
@@ -8289,6 +8291,7 @@ void *__init alloc_large_system_hash(con }else if (get_order (size) >=MAX_ORDER || hashdist) { table =__vmalloc (size, gfp_flags); virt = true; + huge =is_vm_area_hugepages (table); }else {/* * If bucketsize is not a power-of-two, we may free
@@ -8305,7 +8308,7 @@ void *__init alloc_large_system_hash(conpr_info ("%s hash table entries: %ld (order: %d, %lu bytes, %s)\n" , tablename,1UL << log2qty,ilog2 (size) -PAGE_SHIFT , size, - virt ?"vmalloc" :"linear" ); + virt ? (huge ?"vmalloc hugepage" :"vmalloc" ) :"linear" );if (_hash_shift) *_hash_shift = log2qty;
mm/vmalloc.c renamed from mm/vmalloc.c~mm-vmalloc-hugepage-vmalloc-mappings +173 -47
337 lines not on this page · raw message
_
Andrew Morton
maintainerPATCH 110/178 mm/vmalloc: remove map_kernel_range
In reply to Andrew MortonFrom: Nicholas Piggin <[email protected]>
Subject: mm/vmalloc: remove map_kernel_range
Patch series "mm/vmalloc: cleanup after hugepage series", v2.
Christoph pointed out some overdue cleanups required after the huge vmalloc series, and I had another failure error message improvement as well.
This patch (of 5):
This is a shim around vmap_pages_range, get rid of it.
Move the main API comment from the _noflush variant to the normal variant, and make _noflush internal to mm/.
---
Documentation/core-api/cachetlb.rst | 2 include/linux/vmalloc.h | 11 ---- mm/internal.h | 6 ++ mm/percpu-vm.c | 5 +- mm/vmalloc.c | 65 +++++++++++--------------- 5 files changed, 38 insertions(+), 51 deletions(-)
Documentation/core-api/cachetlb.rst renamed from Documentation/core-api/cachetlb.rst~mm-vmalloc-remove-map_kernel_range +1 -1
@@ -213,7 +213,7 @@ Here are the routines, one by one: there will be no entries in the cache for the kernel address space for virtual addresses in the range 'start' to 'end-1'. - The first of these two routines is invoked after map_kernel_range() + The first of these two routines is invoked after vmap_range() has installed the page table entries. The second is invoked before unmap_kernel_range() deletes the page table entries.
include/linux/vmalloc.h renamed from include/linux/vmalloc.h~mm-vmalloc-remove-map_kernel_range +0 -11
@@ -212,10 +212,6 @@ static inline bool is_vm_area_hugepages(int vmap_range (unsigned long addr,unsigned long end,phys_addr_t phys_addr,pgprot_t prot,unsigned int max_page_shift); -extern int map_kernel_range_noflush (unsigned long start,unsigned long size, -pgprot_t prot,struct page **pages); -int map_kernel_range (unsigned long start,unsigned long size,pgprot_t prot, -struct page **pages);extern void unmap_kernel_range_noflush (unsigned long addr,unsigned long size);extern void unmap_kernel_range (unsigned long addr,unsigned long size);static inline void set_vm_flush_reset_perms (void *addr)
@@ -227,13 +223,6 @@ static inline void set_vm_flush_reset_pe }#else -static inline int -map_kernel_range_noflush (unsigned long start,unsigned long size, -pgprot_t prot,struct page **pages) -{ -return size >>PAGE_SHIFT ; -} -#define map_kernel_range map_kernel_range_noflushstatic inline void unmap_kernel_range_noflush (unsigned long addr,unsigned long size) {
mm/internal.h renamed from mm/internal.h~mm-vmalloc-remove-map_kernel_range +6 -0
@@ -637,4 +637,10 @@ struct migration_target_control { gfp_t gfp_mask; }; +/* +* mm/vmalloc.c +*/ +int vmap_pages_range_noflush (unsigned long addr,unsigned long end, +pgprot_t prot,struct page **pages,unsigned int page_shift); +#endif /* __MM_INTERNAL_H */
mm/percpu-vm.c renamed from mm/percpu-vm.c~mm-vmalloc-remove-map_kernel_range +3 -2
@@ -8,6 +8,7 @@* Chunks are mapped into vmalloc areas and populated page by page. * This is the default chunk allocator. */ +#include "internal.h" static struct page *pcpu_chunk_page (struct pcpu_chunk *chunk,unsigned int cpu,int page_idx)
@@ -192,8 +193,8 @@ static void pcpu_post_unmap_tlb_flush(ststatic int __pcpu_map_pages (unsigned long addr,struct page **pages,int nr_pages) { -return map_kernel_range_noflush (addr, nr_pages <<PAGE_SHIFT , -PAGE_KERNEL , pages); +return vmap_pages_range_noflush (addr, addr + (nr_pages <<PAGE_SHIFT ), +PAGE_KERNEL , pages,PAGE_SHIFT ); }/**
mm/vmalloc.c renamed from mm/vmalloc.c~mm-vmalloc-remove-map_kernel_range +28 -37
107 lines not on this page · raw message
_
Andrew Morton
maintainerPATCH 111/178 kernel/dma: remove unnecessary unmap_kernel_range
In reply to Andrew MortonFrom: Nicholas Piggin <[email protected]>
Subject: kernel/dma: remove unnecessary unmap_kernel_range
vunmap will remove ptes.
---
kernel/dma/remap.c | 1 - 1 file changed, 1 deletion(-)
kernel/dma/remap.c renamed from kernel/dma/remap.c~kernel-dma-remove-unnecessary-unmap_kernel_range +0 -1
@@ -66,6 +66,5 @@ void dma_common_free_remap(void *cpu_addreturn ; } -unmap_kernel_range ((unsigned long )cpu_addr,PAGE_ALIGN (size));vunmap (cpu_addr); }
_
Andrew Morton
maintainerPATCH 112/178 powerpc/xive: remove unnecessary unmap_kernel_range
In reply to Andrew MortonFrom: Nicholas Piggin <[email protected]>
Subject: powerpc/xive: remove unnecessary unmap_kernel_range
iounmap will remove ptes.
---
arch/powerpc/sysdev/xive/common.c | 4 ---- 1 file changed, 4 deletions(-)
arch/powerpc/sysdev/xive/common.c renamed from arch/powerpc/sysdev/xive/common.c~powerpc-xive-remove-unnecessary-unmap_kernel_range +0 -4
@@ -959,16 +959,12 @@ EXPORT_SYMBOL_GPL(is_xive_irq);void xive_cleanup_irq_data (struct xive_irq_data *xd) {if (xd->eoi_mmio) { -unmap_kernel_range ((unsigned long )xd->eoi_mmio, -1u << xd->esb_shift);iounmap (xd->eoi_mmio);if (xd->eoi_mmio == xd->trig_mmio) xd->trig_mmio =NULL ; xd->eoi_mmio =NULL ; }if (xd->trig_mmio) { -unmap_kernel_range ((unsigned long )xd->trig_mmio, -1u << xd->esb_shift);iounmap (xd->trig_mmio); xd->trig_mmio =NULL ; }
_
Andrew Morton
maintainerPATCH 113/178 mm/vmalloc: remove unmap_kernel_range
In reply to Andrew MortonFrom: Nicholas Piggin <[email protected]>
Subject: mm/vmalloc: remove unmap_kernel_range
This is a shim around vunmap_range, get rid of it.
Move the main API comment from the _noflush variant to the normal variant, and make _noflush internal to mm/.
---
Documentation/core-api/cachetlb.rst | 2 arch/arm64/mm/init.c | 2 arch/powerpc/kernel/isa-bridge.c | 4 - arch/powerpc/kernel/pci_64.c | 2 arch/powerpc/mm/ioremap.c | 2 drivers/pci/pci.c | 2 include/linux/vmalloc.h | 8 --- mm/internal.h | 15 ++++++ mm/percpu-vm.c | 2 mm/vmalloc.c | 59 ++++++++++++-------------- 10 files changed, 51 insertions(+), 47 deletions(-)
arch/arm64/mm/init.c renamed from arch/arm64/mm/init.c~mm-vmalloc-remove-unmap_kernel_range +1 -1
@@ -521,7 +521,7 @@ void free_initmem(void)* prevents the region from being reused for kernel modules, which * is not supported by kallsyms. */ -unmap_kernel_range ((u64 )__init_begin, (u64)(__init_end - __init_begin)); +vunmap_range ((u64 )__init_begin, (u64 )__init_end); }void dump_mem_limit (void )
arch/powerpc/kernel/isa-bridge.c renamed from arch/powerpc/kernel/isa-bridge.c~mm-vmalloc-remove-unmap_kernel_range +2 -2
@@ -48,7 +48,7 @@ static void remap_isa_base(phys_addr_t pif (slab_is_available ()) {if (ioremap_page_range (ISA_IO_BASE ,ISA_IO_BASE + size, pa,pgprot_noncached (PAGE_KERNEL ))) -unmap_kernel_range (ISA_IO_BASE , size); +vunmap_range (ISA_IO_BASE ,ISA_IO_BASE + size); }else {early_ioremap_range (ISA_IO_BASE , pa, size,pgprot_noncached (PAGE_KERNEL ));
@@ -311,7 +311,7 @@ static void isa_bridge_remove(void) isa_bridge_pcidev =NULL ;/* Unmap the ISA area */ -unmap_kernel_range (ISA_IO_BASE ,0x10000 ); +vunmap_range (ISA_IO_BASE ,ISA_IO_BASE +0x10000 ); }/**
arch/powerpc/kernel/pci_64.c renamed from arch/powerpc/kernel/pci_64.c~mm-vmalloc-remove-unmap_kernel_range +1 -1
@@ -140,7 +140,7 @@ void __iomem *ioremap_phb(phys_addr_t pa addr = (unsigned long )area->addr;if (ioremap_page_range (addr, addr + size, paddr,pgprot_noncached (PAGE_KERNEL ))) { -unmap_kernel_range (addr, size); +vunmap_range (addr, addr + size);return NULL ; }
arch/powerpc/mm/ioremap.c renamed from arch/powerpc/mm/ioremap.c~mm-vmalloc-remove-unmap_kernel_range +1 -1
@@ -93,7 +93,7 @@ void __iomem *do_ioremap(phys_addr_t pa,if (!ret)return (void __iomem *)area->addr + offset; -unmap_kernel_range (va, size); +vunmap_range (va, va + size);free_vm_area (area);return NULL ;
Documentation/core-api/cachetlb.rst renamed from Documentation/core-api/cachetlb.rst~mm-vmalloc-remove-unmap_kernel_range +1 -1
@@ -215,7 +215,7 @@ Here are the routines, one by one: The first of these two routines is invoked after vmap_range() has installed the page table entries. The second is invoked - before unmap_kernel_range() deletes the page table entries. + before vunmap_range() deletes the page table entries. There exists another whole class of cpu cache issues which currently require a whole different set of interfaces to handle properly.
drivers/pci/pci.c renamed from drivers/pci/pci.c~mm-vmalloc-remove-unmap_kernel_range +1 -1
@@ -4102,7 +4102,7 @@ void pci_unmap_iospace(struct resource *#if defined(PCI_IOBASE ) && defined(CONFIG_MMU )unsigned long vaddr = (unsigned long )PCI_IOBASE + res->start; -unmap_kernel_range (vaddr,resource_size (res)); +vunmap_range (vaddr, vaddr +resource_size (res));#endif }EXPORT_SYMBOL (pci_unmap_iospace);
include/linux/vmalloc.h renamed from include/linux/vmalloc.h~mm-vmalloc-remove-unmap_kernel_range +1 -7
@@ -212,8 +212,7 @@ static inline bool is_vm_area_hugepages(int vmap_range (unsigned long addr,unsigned long end,phys_addr_t phys_addr,pgprot_t prot,unsigned int max_page_shift); -extern void unmap_kernel_range_noflush (unsigned long addr,unsigned long size); -extern void unmap_kernel_range (unsigned long addr,unsigned long size); +void vunmap_range (unsigned long addr,unsigned long end);static inline void set_vm_flush_reset_perms (void *addr) {struct vm_struct *vm =find_vm_area (addr);
@@ -223,11 +222,6 @@ static inline void set_vm_flush_reset_pe }#else -static inline void -unmap_kernel_range_noflush (unsigned long addr,unsigned long size) -{ -} -#define unmap_kernel_range unmap_kernel_range_noflushstatic inline void set_vm_flush_reset_perms (void *addr) { }
mm/internal.h renamed from mm/internal.h~mm-vmalloc-remove-unmap_kernel_range +14 -1
@@ -446,7 +446,9 @@ static inline struct file *maybe_unlock_static inline void clear_page_mlock (struct page *page) { }static inline void mlock_vma_page (struct page *page) { }static inline void mlock_migrate_page (struct page *new,struct page *old) { } - +static inline void vunmap_range_noflush (unsigned long start,unsigned long end) +{ +}#endif /* !CONFIG_MMU */ /*
@@ -640,7 +642,18 @@ struct migration_target_control {/* * mm/vmalloc.c */ +#ifdef CONFIG_MMU int vmap_pages_range_noflush (unsigned long addr,unsigned long end,pgprot_t prot,struct page **pages,unsigned int page_shift); +#else +static inline +int vmap_pages_range_noflush (unsigned long addr,unsigned long end, +pgprot_t prot,struct page **pages,unsigned int page_shift) +{ +return -EINVAL ; +} +#endif + +void vunmap_range_noflush (unsigned long start,unsigned long end);#endif /* __MM_INTERNAL_H */
mm/percpu-vm.c renamed from mm/percpu-vm.c~mm-vmalloc-remove-unmap_kernel_range +1 -1
@@ -134,7 +134,7 @@ static void pcpu_pre_unmap_flush(structstatic void __pcpu_unmap_pages (unsigned long addr,int nr_pages) { -unmap_kernel_range_noflush (addr, nr_pages <<PAGE_SHIFT ); +vunmap_range_noflush (addr, addr + (nr_pages <<PAGE_SHIFT )); }/**
mm/vmalloc.c renamed from mm/vmalloc.c~mm-vmalloc-remove-unmap_kernel_range +28 -31
93 lines not on this page · raw message
_
Andrew Morton
maintainerPATCH 114/178 mm/vmalloc: improve allocation failure error messages
In reply to Andrew MortonFrom: Nicholas Piggin <[email protected]>
Subject: mm/vmalloc: improve allocation failure error messages
There are several reasons why a vmalloc can fail, virtual space exhausted, page array allocation failure, page allocation failure, and kernel page table allocation failure.
Add distinct warning messages for the main causes of failure, with some added information like page order or allocation size where applicable.
---
mm/vmalloc.c | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-)
mm/vmalloc.c renamed from mm/vmalloc.c~mm-vmalloc-improve-allocation-failure-error-messages +27 -13
@@ -2790,6 +2790,10 @@ static void *__vmalloc_area_node(structif (!pages) {free_vm_area (area); +warn_alloc (gfp_mask,NULL , +"vmalloc size %lu allocation failure: " +"page array size %lu allocation failed" , + nr_small_pages *PAGE_SIZE , array_size);return NULL ; }
@@ -2814,6 +2818,10 @@ static void *__vmalloc_area_node(struct/* Successfully allocated i pages, free them in __vfree() */ area->nr_pages = i;atomic_long_add (area->nr_pages, &nr_vmalloc_pages); +warn_alloc (gfp_mask,NULL , +"vmalloc size %lu allocation failure: " +"page order %u allocation failed" , + area->nr_pages *PAGE_SIZE , page_order); goto fail; }
@@ -2825,15 +2833,17 @@ static void *__vmalloc_area_node(struct }atomic_long_add (area->nr_pages, &nr_vmalloc_pages); -if (vmap_pages_range (addr, addr + size, prot, pages, page_shift) <0 ) +if (vmap_pages_range (addr, addr + size, prot, pages, page_shift) <0 ) { +warn_alloc (gfp_mask,NULL , +"vmalloc size %lu allocation failure: " +"failed to map pages" , + area->nr_pages *PAGE_SIZE ); goto fail; + }return area->addr; fail: -warn_alloc (gfp_mask,NULL , -"vmalloc: allocation failure, allocated %ld of %ld bytes" , - (area->nr_pages*PAGE_SIZE ), size);__vfree (area->addr);return NULL ; }
@@ -2867,9 +2877,14 @@ void *__vmalloc_node_range(unsigned longunsigned long real_align = align;unsigned int shift =PAGE_SHIFT ; -if (!size || (size >>PAGE_SHIFT ) >totalram_pages ()) { - area =NULL ; - goto fail; +if (WARN_ON_ONCE (!size)) +return NULL ; + +if ((size >>PAGE_SHIFT ) >totalram_pages ()) { +warn_alloc (gfp_mask,NULL , +"vmalloc size %lu allocation failure: " +"exceeds total pages" , real_size); +return NULL ; } if (vmap_allow_huge && !(vm_flags & VM_NO_HUGE_VMAP) &&
@@ -2897,8 +2912,12 @@ again: size =PAGE_ALIGN (size); area =__get_vm_area_node (size, align,VM_ALLOC |VM_UNINITIALIZED | vm_flags, start, end, node, gfp_mask, caller); -if (!area) +if (!area) { +warn_alloc (gfp_mask,NULL , +"vmalloc size %lu allocation failure: " +"vm_struct allocation failed" , real_size); goto fail; + } addr =__vmalloc_area_node (area, gfp_mask, prot, shift, node);if (!addr)
@@ -2923,11 +2942,6 @@ fail: goto again; } -if (!area) { -/* Warn for area allocation, page allocations already warn */ -warn_alloc (gfp_mask,NULL , -"vmalloc: allocation failure: %lu bytes" , real_size); - }return NULL ; }
_
Andrew Morton
maintainerPATCH 115/178 mm: vmalloc: prevent use after free in _vm_unmap_aliases
In reply to Andrew MortonFrom: Vijayanand Jitta <[email protected]>
Subject: mm: vmalloc: prevent use after free in _vm_unmap_aliases
A potential use after free can occur in _vm_unmap_aliases where an already freed vmap_area could be accessed, Consider the following scenario:
Process 1 Process 2
__vm_unmap_aliases __vm_unmap_aliases
purge_fragmented_blocks_allcpus rcu_read_lock() rcu_read_lock() list_del_rcu(&vb->free_list) list_for_each_entry_rcu(vb .. ) __purge_vmap_area_lazy kmem_cache_free(va) va_start = vb->va->va_start
Here Process 1 is in purge path and it does list_del_rcu on vmap_block and later frees the vmap_area, since Process 2 was holding the rcu lock at this time vmap_block will still be present in and Process 2 accesse it and thereby it tries to access vmap_area of that vmap_block which was already freed by Process 1 and this results in use after free.
Fix this by adding a check for vb->dirty before accessing vmap_area structure since vb->dirty will be set to VMAP_BBMAP_BITS in purge path checking for this will prevent the use after free.
---
mm/vmalloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/vmalloc.c renamed from mm/vmalloc.c~mm-vmalloc-prevent-use-after-free-in-_vm_unmap_aliases +1 -1
@@ -2040,7 +2040,7 @@ static void _vm_unmap_aliases(unsigned lrcu_read_lock ();list_for_each_entry_rcu (vb, &vbq->free, free_list) {spin_lock (&vb->lock); -if (vb->dirty) { +if (vb->dirty && vb->dirty !=VMAP_BBMAP_BITS ) {unsigned long va_start = vb->va->va_start;unsigned long s, e;
_
Andrew Morton
maintainerPATCH 116/178 lib/test_vmalloc.c: remove two kvfree_rcu() tests
In reply to Andrew MortonFrom: "Uladzislau Rezki (Sony)" <[email protected]>
Subject: lib/test_vmalloc.c: remove two kvfree_rcu() tests
Remove two test cases related to kvfree_rcu() and SLAB. Those are considered as redundant now, because similar test functionality has recently been introduced in the "rcuscale" RCU test-suite.
---
lib/test_vmalloc.c | 40 ---------------------------------------- 1 file changed, 40 deletions(-)
lib/test_vmalloc.c renamed from lib/test_vmalloc.c~lib-test_vmallocc-remove-two-kvfree_rcu-tests +0 -40
@@ -47,8 +47,6 @@ __param(int, run_test_mask, INT_MAX,"\t\tid: 128, name: pcpu_alloc_test\n" "\t\tid: 256, name: kvfree_rcu_1_arg_vmalloc_test\n" "\t\tid: 512, name: kvfree_rcu_2_arg_vmalloc_test\n" -"\t\tid: 1024, name: kvfree_rcu_1_arg_slab_test\n" -"\t\tid: 2048, name: kvfree_rcu_2_arg_slab_test\n" /* Add a new test case description here. */ );
@@ -363,42 +361,6 @@ kvfree_rcu_2_arg_vmalloc_test(void)return 0 ; } -static int -kvfree_rcu_1_arg_slab_test (void ) -{ -struct test_kvfree_rcu *p; -int i; - -for (i =0 ; i < test_loop_count; i++) { - p =kmalloc (sizeof (*p),GFP_KERNEL ); -if (!p) -return -1 ; - - p->array[0 ] ='a' ; -kvfree_rcu (p); - } - -return 0 ; -} - -static int -kvfree_rcu_2_arg_slab_test (void ) -{ -struct test_kvfree_rcu *p; -int i; - -for (i =0 ; i < test_loop_count; i++) { - p =kmalloc (sizeof (*p),GFP_KERNEL ); -if (!p) -return -1 ; - - p->array[0 ] ='a' ; -kvfree_rcu (p, rcu); - } - -return 0 ; -} -struct test_case_desc {const char *test_name;int (*test_func)(void );
@@ -415,8 +377,6 @@ static struct test_case_desc test_case_a { "pcpu_alloc_test", pcpu_alloc_test }, { "kvfree_rcu_1_arg_vmalloc_test", kvfree_rcu_1_arg_vmalloc_test }, { "kvfree_rcu_2_arg_vmalloc_test", kvfree_rcu_2_arg_vmalloc_test }, - { "kvfree_rcu_1_arg_slab_test", kvfree_rcu_1_arg_slab_test }, - { "kvfree_rcu_2_arg_slab_test", kvfree_rcu_2_arg_slab_test }, /* Add a new test case here. */ };
_
Andrew Morton
maintainerPATCH 117/178 lib/test_vmalloc.c: add a new 'nr_threads' parameter
In reply to Andrew MortonFrom: "Uladzislau Rezki (Sony)" <[email protected]>
Subject: lib/test_vmalloc.c: add a new 'nr_threads' parameter
By using this parameter we can specify how many workers are created to perform vmalloc tests. By default it is one CPU. The maximum value is set to 1024.
As a result of this change a 'single_cpu_test' one becomes obsolete, therefore it is no longer needed.
---
lib/test_vmalloc.c | 88 +++++++++++++++++++------------------------ 1 file changed, 40 insertions(+), 48 deletions(-)
lib/test_vmalloc.c renamed from lib/test_vmalloc.c~lib-test_vmallocc-add-a-new-nr_threads-parameter +40 -48
@@ -23,8 +23,8 @@module_param (name, type,0444 ); \ MODULE_PARM_DESC(name, msg) \ -__param (bool, single_cpu_test, false, -"Use single first online CPU to run tests" ); +__param (int, nr_threads,0 , +"Number of workers to perform tests(min: 1 max: USHRT_MAX)" );__param (bool, sequential_test_order, false,"Use sequential stress tests order" );
@@ -51,13 +51,6 @@ __param(int, run_test_mask, INT_MAX, );/* -* Depends on single_cpu_test parameter. If it is true, then -* use first online CPU to trigger a test on, otherwise go with -* all online CPUs. -*/ -static cpumask_t cpus_run_test_mask =CPU_MASK_NONE ; - -/* * Read write semaphore for synchronization of setup * phase that is done in main thread and workers. */
@@ -386,16 +379,13 @@ struct test_case_data {u64 time; }; -/* Split it to get rid of: WARNING: line over 80 characters */ -static struct test_case_data - per_cpu_test_data[NR_CPUS ][ARRAY_SIZE (test_case_array)]; -static struct test_driver {struct task_struct *task; +struct test_case_data data[ARRAY_SIZE (test_case_array)]; +unsigned long start;unsigned long stop; -int cpu; -} per_cpu_test_driver[NR_CPUS ]; +} *tdriver;static void shuffle_array (int *arr,int n) {
@@ -423,9 +413,6 @@ static int test_func(void *private)ktime_t kt;u64 delta; -if (set_cpus_allowed_ptr (current,cpumask_of (t->cpu)) <0 ) -pr_err ("Failed to set affinity to %d CPU\n" , t->cpu); -for (i =0 ; i <ARRAY_SIZE (test_case_array); i++) random_array[i] = i;
@@ -450,9 +437,9 @@ static int test_func(void *private) kt =ktime_get ();for (j =0 ; j < test_repeat_count; j++) {if (!test_case_array[index].test_func ()) - per_cpu_test_data[t->cpu][index].test_passed++; + t->data[index].test_passed++;else - per_cpu_test_data[t->cpu][index].test_failed++; + t->data[index].test_failed++; }/*
@@ -461,7 +448,7 @@ static int test_func(void *private) delta = (u64 )ktime_us_delta (ktime_get (), kt);do_div (delta, (u32 ) test_repeat_count); - per_cpu_test_data[t->cpu][index].time = delta; + t->data[index].time = delta; } t->stop =get_cycles ();
@@ -477,53 +464,56 @@ static int test_func(void *private)return 0 ; } -static void +static int init_test_configurtion (void ) {/* -* Reset all data of all CPUs. +* A maximum number of workers is defined as hard-coded +* value and set to USHRT_MAX. We add such gap just in +* case and for potential heavy stressing. */ -memset (per_cpu_test_data,0 ,sizeof (per_cpu_test_data)); + nr_threads =clamp (nr_threads,1 , (int )USHRT_MAX ); -if (single_cpu_test) -cpumask_set_cpu (cpumask_first (cpu_online_mask), - &cpus_run_test_mask); -else -cpumask_and (&cpus_run_test_mask, cpu_online_mask, - cpu_online_mask); +/* Allocate the space for test instances. */ + tdriver =kvcalloc (nr_threads,sizeof (*tdriver),GFP_KERNEL ); +if (tdriver ==NULL ) +return -1 ;if (test_repeat_count <=0 ) test_repeat_count =1 ;if (test_loop_count <=0 ) test_loop_count =1 ; + +return 0 ; }static void do_concurrent_test (void ) { -int cpu, ret; +int i, ret;/* * Set some basic configurations plus sanity check. */ -init_test_configurtion (); + ret =init_test_configurtion (); +if (ret <0 ) +return ;/* * Put on hold all workers. */ down_write (&prepare_for_test_rwsem); -for_each_cpu (cpu, &cpus_run_test_mask) { -struct test_driver *t = &per_cpu_test_driver[cpu]; +for (i =0 ; i < nr_threads; i++) { +struct test_driver *t = &tdriver[i]; - t->cpu = cpu; - t->task =kthread_run (test_func, t,"vmalloc_test/%d" , cpu); + t->task =kthread_run (test_func, t,"vmalloc_test/%d" , i);if (!IS_ERR (t->task))/* Success. */ atomic_inc (&test_n_undone);else -pr_err ("Failed to start kthread for %d CPU\n" , cpu); +pr_err ("Failed to start %d kthread\n" , i); }/*
@@ -541,29 +531,31 @@ static void do_concurrent_test(void) ret =wait_for_completion_timeout (&test_all_done_comp,HZ ); }while (!ret); -for_each_cpu (cpu, &cpus_run_test_mask) { -struct test_driver *t = &per_cpu_test_driver[cpu]; -int i; +for (i =0 ; i < nr_threads; i++) { +struct test_driver *t = &tdriver[i]; +int j;if (!IS_ERR (t->task))kthread_stop (t->task); -for (i =0 ; i <ARRAY_SIZE (test_case_array); i++) { -if (!((run_test_mask & (1 << i)) >> i)) +for (j =0 ; j <ARRAY_SIZE (test_case_array); j++) { +if (!((run_test_mask & (1 << j)) >> j))continue ;pr_info ("Summary: %s passed: %d failed: %d repeat: %d loops: %d avg: %llu usec\n" , - test_case_array[i].test_name, - per_cpu_test_data[cpu][i].test_passed, - per_cpu_test_data[cpu][i].test_failed, + test_case_array[j].test_name, + t->data[j].test_passed, + t->data[j].test_failed, test_repeat_count, test_loop_count, - per_cpu_test_data[cpu][i].time); + t->data[j].time); } -pr_info ("All test took CPU%d=%lu cycles\n" , - cpu, t->stop - t->start); +pr_info ("All test took worker%d=%lu cycles\n" , + i, t->stop - t->start); } + +kvfree (tdriver); }static int vmalloc_test_init (void )
_