incoming
Subsystems (76)
Andrew Morton
maintainer212 patches, based on 4a3bb4200a5958d76cc26ebe4db4257efa56812b.
Subsystems affected by this patch series:
ia64
ocfs2
block
mm/slub
mm/debug
mm/pagecache
mm/gup
mm/swap
mm/shmem
mm/memcg
mm/selftests
mm/pagemap
mm/mremap
mm/bootmem
mm/sparsemem
mm/vmalloc
mm/kasan
mm/pagealloc
mm/memory-failure
mm/hugetlb
mm/userfaultfd
mm/vmscan
mm/compaction
mm/mempolicy
mm/memblock
mm/oom-kill
mm/migration
mm/ksm
mm/percpu
mm/vmstat
mm/madvise
Subsystem: ia64
Jason Wang <[email protected]>:
ia64: fix typo in a comment
Geert Uytterhoeven <[email protected]>:
Patch series "ia64: Miscellaneous fixes and cleanups":
ia64: fix #endif comment for reserve_elfcorehdr()
ia64: make reserve_elfcorehdr() static
ia64: make num_rsvd_regions static
Subsystem: ocfs2
Dan Carpenter <[email protected]>:
ocfs2: remove an unnecessary condition
Tuo Li <[email protected]>:
ocfs2: quota_local: fix possible uninitialized-variable access in ocfs2_local_read_info()
Gang He <[email protected]>:
ocfs2: ocfs2_downconvert_lock failure results in deadlock
Subsystem: block
kernel test robot <[email protected]>:
arch/csky/kernel/probes/kprobes.c: fix bugon.cocci warnings
Subsystem: mm/slub
Vlastimil Babka <[email protected]>:
Patch series "SLUB: reduce irq disabled scope and make it RT compatible", v4:
mm, slub: don't call flush_all() from slab_debug_trace_open()
mm, slub: allocate private object map for debugfs listings
mm, slub: allocate private object map for validate_slab_cache()
mm, slub: don't disable irq for debug_check_no_locks_freed()
mm, slub: remove redundant unfreeze_partials() from put_cpu_partial() mm, slub: unify cmpxchg_double_slab() and __cmpxchg_double_slab()
mm, slub: extract get_partial() from new_slab_objects()
mm, slub: dissolve new_slab_objects() into ___slab_alloc()
mm, slub: return slab page from get_partial() and set c->page afterwards mm, slub: restructure new page checks in ___slab_alloc()
mm, slub: simplify kmem_cache_cpu and tid setup
mm, slub: move disabling/enabling irqs to ___slab_alloc()
mm, slub: do initial checks in ___slab_alloc() with irqs enabled
mm, slub: move disabling irqs closer to get_partial() in ___slab_alloc() mm, slub: restore irqs around calling new_slab()
mm, slub: validate slab from partial list or page allocator before making it cpu slab mm, slub: check new pages with restored irqs
mm, slub: stop disabling irqs around get_partial()
mm, slub: move reset of c->page and freelist out of deactivate_slab() mm, slub: make locking in deactivate_slab() irq-safe
mm, slub: call deactivate_slab() without disabling irqs
mm, slub: move irq control into unfreeze_partials()
mm, slub: discard slabs in unfreeze_partials() without irqs disabled mm, slub: detach whole partial list at once in unfreeze_partials()
mm, slub: separate detaching of partial list in unfreeze_partials() from unfreezing mm, slub: only disable irq with spin_lock in __unfreeze_partials()
mm, slub: don't disable irqs in slub_cpu_dead()
mm, slab: make flush_slab() possible to call with irqs enabled
Sebastian Andrzej Siewior <[email protected]>:
mm: slub: move flush_cpu_slab() invocations __free_slab() invocations out of IRQ context
mm: slub: make object_map_lock a raw_spinlock_t
Vlastimil Babka <[email protected]>:
mm, slub: optionally save/restore irqs in slab_[un]lock()/ mm, slub: make slab_lock() disable irqs with PREEMPT_RT
mm, slub: protect put_cpu_partial() with disabled irqs instead of cmpxchg mm, slub: use migrate_disable() on PREEMPT_RT
mm, slub: convert kmem_cpu_slab protection to local_lock
Subsystem: mm/debug
Gavin Shan <[email protected]>:
Patch series "mm/debug_vm_pgtable: Enhancements", v6:
mm/debug_vm_pgtable: introduce struct pgtable_debug_args mm/debug_vm_pgtable: use struct pgtable_debug_args in basic tests mm/debug_vm_pgtable: use struct pgtable_debug_args in leaf and savewrite tests mm/debug_vm_pgtable: use struct pgtable_debug_args in protnone and devmap tests mm/debug_vm_pgtable: use struct pgtable_debug_args in soft_dirty and swap tests mm/debug_vm_pgtable: use struct pgtable_debug_args in migration and thp tests mm/debug_vm_pgtable: use struct pgtable_debug_args in PTE modifying tests mm/debug_vm_pgtable: use struct pgtable_debug_args in PMD modifying tests mm/debug_vm_pgtable: use struct pgtable_debug_args in PUD modifying tests mm/debug_vm_pgtable: use struct pgtable_debug_args in PGD and P4D modifying tests mm/debug_vm_pgtable: remove unused code
mm/debug_vm_pgtable: fix corrupted page flag
"Matthew Wilcox (Oracle)" <[email protected]>:
mm: report a more useful address for reclaim acquisition
liuhailong <[email protected]>:
mm: add kernel_misc_reclaimable in show_free_areas
Subsystem: mm/pagecache
Jan Kara <[email protected]>:
Patch series "writeback: Fix bandwidth estimates", v4:
writeback: track number of inodes under writeback
writeback: reliably update bandwidth estimation
writeback: fix bandwidth estimate for spiky workload
writeback: rename domain_update_bandwidth()
writeback: use READ_ONCE for unlocked reads of writeback stats
Johannes Weiner <[email protected]>:
mm: remove irqsave/restore locking from contexts with irqs enabled
fs: drop_caches: fix skipping over shadow cache inodes
fs: inode: count invalidated shadow pages in pginodesteal
Shakeel Butt <[email protected]>:
writeback: memcg: simplify cgroup_writeback_by_id
Jing Yangyang <[email protected]>:
include/linux/buffer_head.h: fix boolreturn.cocci warnings
Subsystem: mm/gup
Miaohe Lin <[email protected]>:
Patch series "Cleanups and fixup for gup":
mm: gup: remove set but unused local variable major
mm: gup: remove unneed local variable orig_refs
mm: gup: remove useless BUG_ON in __get_user_pages()
mm: gup: fix potential pgmap refcnt leak in __gup_device_huge()
mm: gup: use helper PAGE_ALIGNED in populate_vma_page_range()
John Hubbard <[email protected]>:
Patch series "A few gup refactorings and documentation updates", v3:
mm/gup: documentation corrections for gup/pup
mm/gup: small refactoring: simplify try_grab_page() mm/gup: remove try_get_page(), call try_get_compound_head() directly
Subsystem: mm/swap
Hugh Dickins <[email protected]>:
fs, mm: fix race in unlinking swapfile
John Hubbard <[email protected]>:
mm: delete unused get_kernel_page()
Subsystem: mm/shmem
Sebastian Andrzej Siewior <[email protected]>:
shmem: use raw_spinlock_t for ->stat_lock
Miaohe Lin <[email protected]>:
Patch series "Cleanups for shmem":
shmem: remove unneeded variable ret
shmem: remove unneeded header file
shmem: remove unneeded function forward declaration
shmem: include header file to declare swap_info
Hugh Dickins <[email protected]>:
Patch series "huge tmpfs: shmem_is_huge() fixes and cleanups":
huge tmpfs: fix fallocate(vanilla) advance over huge pages huge tmpfs: fix split_huge_page() after FALLOC_FL_KEEP_SIZE huge tmpfs: remove shrinklist addition from shmem_setattr() huge tmpfs: revert shmem's use of transhuge_vma_enabled() huge tmpfs: move shmem_huge_enabled() upwards huge tmpfs: SGP_NOALLOC to stop collapse_file() on race huge tmpfs: shmem_is_huge(vma, inode, index)
huge tmpfs: decide stat.st_blksize by shmem_is_huge()
shmem: shmem_writepage() split unlikely i915 THP
Subsystem: mm/memcg
Suren Baghdasaryan <[email protected]>:
mm, memcg: add mem_cgroup_disabled checks in vmpressure and swap-related functions mm, memcg: inline mem_cgroup_{charge/uncharge} to improve disabled memcg config mm, memcg: inline swap-related functions to improve disabled memcg config
Vasily Averin <[email protected]>:
memcg: enable accounting for pids in nested pid namespaces
Shakeel Butt <[email protected]>:
memcg: switch lruvec stats to rstat
memcg: infrastructure to flush memcg stats
Yutian Yang <[email protected]>:
memcg: charge fs_context and legacy_fs_context
Vasily Averin <[email protected]>:
Patch series "memcg accounting from OpenVZ", v7:
memcg: enable accounting for mnt_cache entries
memcg: enable accounting for pollfd and select bits arrays
memcg: enable accounting for file lock caches
memcg: enable accounting for fasync_cache
memcg: enable accounting for new namesapces and struct nsproxy
memcg: enable accounting of ipc resources
memcg: enable accounting for signals
memcg: enable accounting for posix_timers_cache slab
memcg: enable accounting for ldt_struct objects
Shakeel Butt <[email protected]>:
memcg: cleanup racy sum avoidance code
Vasily Averin <[email protected]>:
memcg: replace in_interrupt() by !in_task() in active_memcg()
Baolin Wang <[email protected]>:
mm: memcontrol: set the correct memcg swappiness restriction
Miaohe Lin <[email protected]>:
mm, memcg: remove unused functions
mm, memcg: save some atomic ops when flush is already true
Michal Hocko <[email protected]>:
memcg: fix up drain_local_stock comment
Shakeel Butt <[email protected]>:
memcg: make memcg->event_list_lock irqsafe
Subsystem: mm/selftests
Po-Hsu Lin <[email protected]>:
selftests/vm: use kselftest skip code for skipped tests
Colin Ian King <[email protected]>:
selftests: Fix spelling mistake "cann't" -> "cannot"
Subsystem: mm/pagemap
Nicholas Piggin <[email protected]>:
Patch series "shoot lazy tlbs", v4:
lazy tlb: introduce lazy mm refcount helper functions lazy tlb: allow lazy tlb mm refcounting to be configurable lazy tlb: shoot lazies, a non-refcounting lazy tlb option powerpc/64s: enable MMU_LAZY_TLB_SHOOTDOWN
Christoph Hellwig <[email protected]>:
Patch series "_kernel_dcache_page fixes and removal":
mmc: JZ4740: remove the flush_kernel_dcache_page call in jz4740_mmc_read_data
mmc: mmc_spi: replace flush_kernel_dcache_page with flush_dcache_page
scatterlist: replace flush_kernel_dcache_page with flush_dcache_page
mm: remove flush_kernel_dcache_page
Huang Ying <[email protected]>:
mm,do_huge_pmd_numa_page: remove unnecessary TLB flushing code
Greg Kroah-Hartman <[email protected]>:
mm: change fault_in_pages_* to have an unsigned size parameter
Luigi Rizzo <[email protected]>:
mm/pagemap: add mmap_assert_locked() annotations to find_vma*()
"Liam R. Howlett" <[email protected]>:
remap_file_pages: Use vma_lookup() instead of find_vma()
Subsystem: mm/mremap
Chen Wandun <[email protected]>:
mm/mremap: fix memory account on do_munmap() failure
Subsystem: mm/bootmem
Muchun Song <[email protected]>:
mm/bootmem_info.c: mark __init on register_page_bootmem_info_section
Subsystem: mm/sparsemem
Ohhoon Kwon <[email protected]>:
Patch series "mm: sparse: remove __section_nr() function", v4:
mm: sparse: pass section_nr to section_mark_present
mm: sparse: pass section_nr to find_memory_block
mm: sparse: remove __section_nr() function
Naoya Horiguchi <[email protected]>:
mm/sparse: set SECTION_NID_SHIFT to 6
Matthew Wilcox <[email protected]>:
include/linux/mmzone.h: avoid a warning in sparse memory support
Miles Chen <[email protected]>:
mm/sparse: clarify pgdat_to_phys
Subsystem: mm/vmalloc
"Uladzislau Rezki (Sony)" <[email protected]>:
mm/vmalloc: use batched page requests in bulk-allocator mm/vmalloc: remove gfpflags_allow_blocking() check lib/test_vmalloc.c: add a new 'nr_pages' parameter
Chen Wandun <[email protected]>:
mm/vmalloc: fix wrong behavior in vread
Subsystem: mm/kasan
Woody Lin <[email protected]>:
mm/kasan: move kasan.fault to mm/kasan/report.c
Andrey Konovalov <[email protected]>:
Patch series "kasan: test: avoid crashing the kernel with HW_TAGS", v2:
kasan: test: rework kmalloc_oob_right
kasan: test: avoid writing invalid memory
kasan: test: avoid corrupting memory via memset
kasan: test: disable kmalloc_memmove_invalid_size for HW_TAGS
kasan: test: only do kmalloc_uaf_memset for generic mode
kasan: test: clean up ksize_uaf
kasan: test: avoid corrupting memory in copy_user_test
kasan: test: avoid corrupting memory in kasan_rcu_uaf
Subsystem: mm/pagealloc
Mike Rapoport <[email protected]>:
Patch series "mm: ensure consistency of memory map poisoning":
mm/page_alloc: always initialize memory map for the holes
microblaze: simplify pte_alloc_one_kernel()
mm: introduce memmap_alloc() to unify memory map allocation
memblock: stop poisoning raw allocations
Nico Pache <[email protected]>:
mm/page_alloc.c: fix 'zone_id' may be used uninitialized in this function warning
Mike Rapoport <[email protected]>:
mm/page_alloc: make alloc_node_mem_map() __init rather than __ref
Vasily Averin <[email protected]>:
mm/page_alloc.c: use in_task()
"George G. Davis" <[email protected]>:
mm/page_isolation: tracing: trace all test_pages_isolated failures
Subsystem: mm/memory-failure
Miaohe Lin <[email protected]>:
Patch series "Cleanups and fixup for hwpoison":
mm/hwpoison: remove unneeded variable unmap_success mm/hwpoison: fix potential pte_unmap_unlock pte error mm/hwpoison: change argument struct page **hpagep to *hpage mm/hwpoison: fix some obsolete comments
Yang Shi <[email protected]>:
mm: hwpoison: don't drop slab caches for offlining non-LRU page
doc: hwpoison: correct the support for hugepage
mm: hwpoison: dump page for unhandlable page
Michael Wang <[email protected]>:
mm: fix panic caused by __page_handle_poison()
Subsystem: mm/hugetlb
Mike Kravetz <[email protected]>:
hugetlb: simplify prep_compound_gigantic_page ref count racing code
hugetlb: drop ref count earlier after page allocation
hugetlb: before freeing hugetlb page set dtor to appropriate value
hugetlb: fix hugetlb cgroup refcounting during vma split
Subsystem: mm/userfaultfd
Nadav Amit <[email protected]>:
Patch series "userfaultfd: minor bug fixes":
userfaultfd: change mmap_changing to atomic
userfaultfd: prevent concurrent API initialization selftests/vm/userfaultfd: wake after copy failure
Subsystem: mm/vmscan
Dave Hansen <[email protected]>:
Patch series "Migrate Pages in lieu of discard", v11:
mm/numa: automatically generate node migration order mm/migrate: update node demotion order on hotplug events
Yang Shi <[email protected]>:
mm/migrate: enable returning precise migrate_pages() success count
Dave Hansen <[email protected]>:
mm/migrate: demote pages during reclaim
Yang Shi <[email protected]>:
mm/vmscan: add page demotion counter
Dave Hansen <[email protected]>:
mm/vmscan: add helper for querying ability to age anonymous pages
Keith Busch <[email protected]>:
mm/vmscan: Consider anonymous pages without swap
Dave Hansen <[email protected]>:
mm/vmscan: never demote for memcg reclaim
Huang Ying <[email protected]>:
mm/migrate: add sysfs interface to enable reclaim migration
Hui Su <[email protected]>:
mm/vmpressure: replace vmpressure_to_css() with vmpressure_to_memcg()
Miaohe Lin <[email protected]>:
Patch series "Cleanups for vmscan", v2:
mm/vmscan: remove the PageDirty check after MADV_FREE pages are page_ref_freezed mm/vmscan: remove misleading setting to sc->priority
mm/vmscan: remove unneeded return value of kswapd_run()
mm/vmscan: add 'else' to remove check_pending label
Vlastimil Babka <[email protected]>:
mm, vmscan: guarantee drop_slab_node() termination
Subsystem: mm/compaction
Charan Teja Reddy <[email protected]>:
mm: compaction: optimize proactive compaction deferrals
mm: compaction: support triggering of proactive compaction by user
Subsystem: mm/mempolicy
Baolin Wang <[email protected]>:
mm/mempolicy: use readable NUMA_NO_NODE macro instead of magic number
Dave Hansen <[email protected]>:
Patch series "Introduce multi-preference mempolicy", v7:
mm/mempolicy: add MPOL_PREFERRED_MANY for multiple preferred nodes
Feng Tang <[email protected]>:
mm/memplicy: add page allocation function for MPOL_PREFERRED_MANY policy
Ben Widawsky <[email protected]>:
mm/hugetlb: add support for mempolicy MPOL_PREFERRED_MANY mm/mempolicy: advertise new MPOL_PREFERRED_MANY
Feng Tang <[email protected]>:
mm/mempolicy: unify the create() func for bind/interleave/prefer-many policies
Vasily Averin <[email protected]>:
mm/mempolicy.c: use in_task() in mempolicy_slab_node()
Subsystem: mm/memblock
Mike Rapoport <[email protected]>:
memblock: make memblock_find_in_range method private
Subsystem: mm/oom-kill
Suren Baghdasaryan <[email protected]>:
mm: introduce process_mrelease system call
mm: wire up syscall process_mrelease
Subsystem: mm/migration
Randy Dunlap <[email protected]>:
mm/migrate: correct kernel-doc notation
Subsystem: mm/ksm
Zhansaya Bagdauletkyzy <[email protected]>:
Patch series "add KSM selftests":
selftests: vm: add KSM merge test
selftests: vm: add KSM unmerge test
selftests: vm: add KSM zero page merging test
selftests: vm: add KSM merging across nodes test
mm: KSM: fix data type
Patch series "add KSM performance tests", v3:
selftests: vm: add KSM merging time test
selftests: vm: add COW time test for KSM pages
Subsystem: mm/percpu
Jing Xiangfeng <[email protected]>:
mm/percpu,c: remove obsolete comments of pcpu_chunk_populated()
Subsystem: mm/vmstat
Miaohe Lin <[email protected]>:
Patch series "Cleanup for vmstat":
mm/vmstat: correct some wrong comments mm/vmstat: simplify the array size calculation mm/vmstat: remove unneeded return value
Subsystem: mm/madvise
zhangkui <[email protected]>:
mm/madvise: add MADV_WILLNEED to process_madvise()
Documentation/ABI/testing/sysfs-kernel-mm-numa | 24 Documentation/admin-guide/mm/numa_memory_policy.rst | 15 Documentation/admin-guide/sysctl/vm.rst | 3 Documentation/core-api/cachetlb.rst | 86 - Documentation/dev-tools/kasan.rst | 13 Documentation/translations/zh_CN/core-api/cachetlb.rst | 9 Documentation/vm/hwpoison.rst | 1 arch/Kconfig | 28 arch/alpha/kernel/syscalls/syscall.tbl | 2 arch/arm/include/asm/cacheflush.h | 4 arch/arm/kernel/setup.c | 20 arch/arm/mach-rpc/ecard.c | 2 arch/arm/mm/flush.c | 33 arch/arm/mm/nommu.c | 6 arch/arm/tools/syscall.tbl | 2 arch/arm64/include/asm/unistd.h | 2 arch/arm64/include/asm/unistd32.h | 2 arch/arm64/kvm/hyp/reserved_mem.c | 9 arch/arm64/mm/init.c | 38 arch/csky/abiv1/cacheflush.c | 11 arch/csky/abiv1/inc/abi/cacheflush.h | 4 arch/csky/kernel/probes/kprobes.c | 3 arch/ia64/include/asm/meminit.h | 2 arch/ia64/kernel/acpi.c | 2 arch/ia64/kernel/setup.c | 55 arch/ia64/kernel/syscalls/syscall.tbl | 2 arch/m68k/kernel/syscalls/syscall.tbl | 2 arch/microblaze/include/asm/page.h | 3 arch/microblaze/include/asm/pgtable.h | 2 arch/microblaze/kernel/syscalls/syscall.tbl | 2 arch/microblaze/mm/init.c | 12 arch/microblaze/mm/pgtable.c | 17 arch/mips/include/asm/cacheflush.h | 8 arch/mips/kernel/setup.c | 14 arch/mips/kernel/syscalls/syscall_n32.tbl | 2 arch/mips/kernel/syscalls/syscall_n64.tbl | 2 arch/mips/kernel/syscalls/syscall_o32.tbl | 2 arch/nds32/include/asm/cacheflush.h | 3 arch/nds32/mm/cacheflush.c | 9 arch/parisc/include/asm/cacheflush.h | 8 arch/parisc/kernel/cache.c | 3 arch/parisc/kernel/syscalls/syscall.tbl | 2 arch/powerpc/Kconfig | 1 arch/powerpc/kernel/smp.c | 2 arch/powerpc/kernel/syscalls/syscall.tbl | 2 arch/powerpc/mm/book3s64/radix_tlb.c | 4 arch/powerpc/platforms/pseries/hotplug-memory.c | 4 arch/riscv/mm/init.c | 44 arch/s390/kernel/setup.c | 9 arch/s390/kernel/syscalls/syscall.tbl | 2 arch/s390/mm/fault.c | 2 arch/sh/include/asm/cacheflush.h | 8 arch/sh/kernel/syscalls/syscall.tbl | 2 arch/sparc/kernel/syscalls/syscall.tbl | 2 arch/x86/entry/syscalls/syscall_32.tbl | 1 arch/x86/entry/syscalls/syscall_64.tbl | 1 arch/x86/kernel/aperture_64.c | 5 arch/x86/kernel/ldt.c | 6 arch/x86/mm/init.c | 23 arch/x86/mm/numa.c | 5 arch/x86/mm/numa_emulation.c | 5 arch/x86/realmode/init.c | 2 arch/xtensa/kernel/syscalls/syscall.tbl | 2 block/blk-map.c | 2 drivers/acpi/tables.c | 5 drivers/base/arch_numa.c | 5 drivers/base/memory.c | 4 drivers/mmc/host/jz4740_mmc.c | 4 drivers/mmc/host/mmc_spi.c | 2 drivers/of/of_reserved_mem.c | 12 fs/drop_caches.c | 3 fs/exec.c | 12 fs/fcntl.c | 3 fs/fs-writeback.c | 28 fs/fs_context.c | 4 fs/inode.c | 2 fs/locks.c | 6 fs/namei.c | 8 fs/namespace.c | 7 fs/ocfs2/dlmglue.c | 14 fs/ocfs2/quota_global.c | 1 fs/ocfs2/quota_local.c | 2 fs/pipe.c | 2 fs/select.c | 4 fs/userfaultfd.c | 116 - include/linux/backing-dev-defs.h | 2 include/linux/backing-dev.h | 19 include/linux/buffer_head.h | 2 include/linux/compaction.h | 2 include/linux/highmem.h | 5 include/linux/hugetlb_cgroup.h | 12 include/linux/memblock.h | 2 include/linux/memcontrol.h | 118 + include/linux/memory.h | 2 include/linux/mempolicy.h | 16 include/linux/migrate.h | 14 include/linux/mm.h | 17 include/linux/mmzone.h | 4 include/linux/page-flags.h | 9 include/linux/pagemap.h | 4 include/linux/sched/mm.h | 35 include/linux/shmem_fs.h | 25 include/linux/slub_def.h | 6 include/linux/swap.h | 28 include/linux/syscalls.h | 1 include/linux/userfaultfd_k.h | 8 include/linux/vm_event_item.h | 2 include/linux/vmpressure.h | 2 include/linux/writeback.h | 4 include/trace/events/migrate.h | 3 include/uapi/asm-generic/unistd.h | 4 include/uapi/linux/mempolicy.h | 1 ipc/msg.c | 2 ipc/namespace.c | 2 ipc/sem.c | 9 ipc/shm.c | 2 kernel/cgroup/namespace.c | 2 kernel/cpu.c | 2 kernel/exit.c | 2 kernel/fork.c | 51 kernel/kthread.c | 21 kernel/nsproxy.c | 2 kernel/pid_namespace.c | 5 kernel/sched/core.c | 37 kernel/sched/sched.h | 4 kernel/signal.c | 2 kernel/sys_ni.c | 1 kernel/sysctl.c | 2 kernel/time/namespace.c | 4 kernel/time/posix-timers.c | 4 kernel/user_namespace.c | 2 lib/scatterlist.c | 5 lib/test_kasan.c | 80 - lib/test_kasan_module.c | 20 lib/test_vmalloc.c | 5 mm/backing-dev.c | 11 mm/bootmem_info.c | 4 mm/compaction.c | 69 - mm/debug_vm_pgtable.c | 982 +++++++++------ mm/filemap.c | 15 mm/gup.c | 109 - mm/huge_memory.c | 32 mm/hugetlb.c | 173 ++ mm/hwpoison-inject.c | 2 mm/internal.h | 9 mm/kasan/hw_tags.c | 43 mm/kasan/kasan.h | 1 mm/kasan/report.c | 29 mm/khugepaged.c | 2 mm/ksm.c | 8 mm/madvise.c | 1 mm/memblock.c | 22 mm/memcontrol.c | 234 +-- mm/memory-failure.c | 53 mm/memory_hotplug.c | 2 mm/mempolicy.c | 207 ++- mm/migrate.c | 319 ++++ mm/mmap.c | 7 mm/mremap.c | 2 mm/oom_kill.c | 70 + mm/page-writeback.c | 133 +- mm/page_alloc.c | 62 mm/page_isolation.c | 13 mm/percpu.c | 3 mm/shmem.c | 309 ++-- mm/slab_common.c | 2 mm/slub.c | 1085 ++++++++++------- mm/sparse.c | 46 mm/swap.c | 22 mm/swapfile.c | 14 mm/truncate.c | 28 mm/userfaultfd.c | 15 mm/vmalloc.c | 79 - mm/vmpressure.c | 10 mm/vmscan.c | 220 ++- mm/vmstat.c | 25 security/tomoyo/domain.c | 13 tools/testing/scatterlist/linux/mm.h | 1 tools/testing/selftests/vm/.gitignore | 1 tools/testing/selftests/vm/Makefile | 3 tools/testing/selftests/vm/charge_reserved_hugetlb.sh | 5 tools/testing/selftests/vm/hugetlb_reparenting_test.sh | 5 tools/testing/selftests/vm/ksm_tests.c | 696 ++++++++++ tools/testing/selftests/vm/mlock-random-test.c | 2 tools/testing/selftests/vm/run_vmtests.sh | 98 + tools/testing/selftests/vm/userfaultfd.c | 13 186 files changed, 4488 insertions(+), 2281 deletions(-)
Andrew Morton
maintainerQuoted 1 line · On Thu, 2 Sep 2021 14:48:20 -0700 Andrew Morton <[email protected]>…
212 patches, based on
4a3bb4200a5958d76cc26ebe4db4257efa56812b.
Make that "based on 7d2a07b769330c34b4deabeed939325c77a7ec2f".
Andrew Morton
maintainerPATCH 1/212 ia64: fix typo in a comment
In reply to Andrew MortonFrom: Jason Wang <[email protected]>
Subject: ia64: fix typo in a comment
s/when when/when/
---
arch/ia64/kernel/acpi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/ia64/kernel/acpi.c renamed from arch/ia64/kernel/acpi.c~ia64-fix-typo-in-a-comment +1 -1
@@ -906,6 +906,6 @@ EXPORT_SYMBOL(acpi_unregister_ioapic);/* * acpi_suspend_lowlevel() - save kernel state and suspend. * -* TBD when when IA64 starts to support suspend... +* TBD when IA64 starts to support suspend... */ int acpi_suspend_lowlevel (void ) {return 0 ; }
_
Andrew Morton
maintainerPATCH 2/212 ia64: fix #endif comment for reserve_elfcorehdr()
In reply to Andrew MortonFrom: Geert Uytterhoeven <[email protected]>
Subject: ia64: fix #endif comment for reserve_elfcorehdr()
Patch series "ia64: Miscellaneous fixes and cleanups".
This patch series contains some miscellaneous fixes and cleanups for ia64. The second patch fixes a naming conflict triggered by a patch for the FDT code.
This patch (of 3):
The definition of reserve_elfcorehdr() depends on CONFIG_CRASH_DUMP, not CONFIG_PROC_VMCORE.
---
arch/ia64/kernel/setup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/ia64/kernel/setup.c renamed from arch/ia64/kernel/setup.c~ia64-fix-endif-comment-for-reserve_elfcorehdr +1 -1
@@ -546,7 +546,7 @@ int __init reserve_elfcorehdr(u64 *start return 0; } -#endif /* CONFIG_PROC_VMCORE */ +#endif /* CONFIG_CRASH_DUMP */ void __init setup_arch (char **cmdline_p)
_
Andrew Morton
maintainerPATCH 3/212 ia64: make reserve_elfcorehdr() static
In reply to Andrew MortonFrom: Geert Uytterhoeven <[email protected]>
Subject: ia64: make reserve_elfcorehdr() static
There never was a reason for reserve_elfcorehdr() to be global. Make the function static, and move it before its sole caller.
---
arch/ia64/include/asm/meminit.h | 1 arch/ia64/kernel/setup.c | 51 ++++++++++++++---------------- 2 files changed, 25 insertions(+), 27 deletions(-)
arch/ia64/include/asm/meminit.h renamed from arch/ia64/include/asm/meminit.h~ia64-make-reserve_elfcorehdr-static +0 -1
@@ -40,7 +40,6 @@ extern unsigned long efi_memmap_init(u64extern int find_max_min_low_pfn (u64 ,u64 ,void *);extern unsigned long vmcore_find_descriptor_size (unsigned long address); -extern int reserve_elfcorehdr (u64 *start,u64 *end);/* * For rounding an address to the next IA64_GRANULE_SIZE or order
arch/ia64/kernel/setup.c renamed from arch/ia64/kernel/setup.c~ia64-make-reserve_elfcorehdr-static +25 -26
63 lines not on this page · raw message
_
Andrew Morton
maintainerPATCH 4/212 ia64: make num_rsvd_regions static
In reply to Andrew MortonFrom: Geert Uytterhoeven <[email protected]>
Subject: ia64: make num_rsvd_regions static
Commit f62800992e5917f2 ("ia64: switch to NO_BOOTMEM") removed the last user of num_rsvd_regions outside arch/ia64/kernel/setup.c.
---
arch/ia64/include/asm/meminit.h | 1 - arch/ia64/kernel/setup.c | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-)
arch/ia64/include/asm/meminit.h renamed from arch/ia64/include/asm/meminit.h~ia64-make-num_rsvd_regions-static +0 -1
@@ -29,7 +29,6 @@ struct rsvd_region { };extern struct rsvd_region rsvd_region[IA64_MAX_RSVD_REGIONS +1 ]; -extern int num_rsvd_regions;extern void find_memory (void );extern void reserve_memory (void );
arch/ia64/kernel/setup.c renamed from arch/ia64/kernel/setup.c~ia64-make-num_rsvd_regions-static +1 -1
@@ -131,7 +131,7 @@ unsigned long ia64_cache_stride_shift =* We use a special marker for the end of memory and it uses the extra (+1) slot */ struct rsvd_region rsvd_region[IA64_MAX_RSVD_REGIONS +1 ]__initdata ; -int num_rsvd_regions__initdata ; +static int num_rsvd_regions__initdata ;/*
_
Andrew Morton
maintainerPATCH 5/212 ocfs2: remove an unnecessary condition
In reply to Andrew MortonFrom: Dan Carpenter <[email protected]>
Subject: ocfs2: remove an unnecessary condition
The case where "tmp_oh" is NULL is handled at the start of the function. At this point we know it's non-NULL so this will always return 1.
---
fs/ocfs2/dlmglue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ocfs2/dlmglue.c renamed from fs/ocfs2/dlmglue.c~ocfs2-remove-an-unnecessary-condition +1 -1
@@ -2721,7 +2721,7 @@ int ocfs2_inode_lock_tracker(struct inodreturn status; } } -return tmp_oh ?1 :0 ; +return 1 ; } void ocfs2_inode_unlock_tracker(struct inode *inode,
_
Andrew Morton
maintainerPATCH 6/212 ocfs2: quota_local: fix possible uninitialized-variable access in ocfs2_local_read_info()
In reply to Andrew MortonFrom: Tuo Li <[email protected]>
Subject: ocfs2: quota_local: fix possible uninitialized-variable access in ocfs2_local_read_info()
A memory block is allocated through kmalloc(), and its return value is assigned to the pointer oinfo. However, oinfo->dqi_gqinode is not initialized but it is accessed in:
iput(oinfo->dqi_gqinode);
To fix this possible uninitialized-variable access, assign NULL to oinfo->dqi_gqinode, and add ocfs2_qinfo_lock_res_init() behind the assignment in ocfs2_local_read_info(). Remove ocfs2_qinfo_lock_res_init() in ocfs2_global_read_info().
---
fs/ocfs2/quota_global.c | 1 - fs/ocfs2/quota_local.c | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-)
fs/ocfs2/quota_global.c renamed from fs/ocfs2/quota_global.c~ocfs2-quota_local-fix-possible-uninitialized-variable-access-in-ocfs2_local_read_info +0 -1
@@ -357,7 +357,6 @@ int ocfs2_global_read_info(struct super_ } oinfo->dqi_gi.dqi_sb = sb; oinfo->dqi_gi.dqi_type = type; -ocfs2_qinfo_lock_res_init (&oinfo->dqi_gqlock, oinfo); oinfo->dqi_gi.dqi_entry_size =sizeof (struct ocfs2_global_disk_dqblk ); oinfo->dqi_gi.dqi_ops = &ocfs2_global_ops; oinfo->dqi_gqi_bh =NULL ;
fs/ocfs2/quota_local.c renamed from fs/ocfs2/quota_local.c~ocfs2-quota_local-fix-possible-uninitialized-variable-access-in-ocfs2_local_read_info +2 -0
@@ -702,6 +702,8 @@ static int ocfs2_local_read_info(struct info->dqi_priv = oinfo; oinfo->dqi_type = type;INIT_LIST_HEAD (&oinfo->dqi_chunk); + oinfo->dqi_gqinode =NULL ; +ocfs2_qinfo_lock_res_init (&oinfo->dqi_gqlock, oinfo); oinfo->dqi_rec =NULL ; oinfo->dqi_lqi_bh =NULL ; oinfo->dqi_libh =NULL ;
_
Andrew Morton
maintainerPATCH 7/212 ocfs2: ocfs2_downconvert_lock failure results in deadlock
In reply to Andrew MortonFrom: Gang He <[email protected]>
Subject: ocfs2: ocfs2_downconvert_lock failure results in deadlock
Usually, ocfs2_downconvert_lock() function always downconverts dlm lock to the expected level for satisfy dlm bast requests from the other nodes.
But there is a rare situation. When dlm lock conversion is being canceled, ocfs2_downconvert_lock() function will return -EBUSY. You need to be aware that ocfs2_cancel_convert() function is asynchronous in fsdlm implementation.
If we does not requeue this lockres entry, ocfs2 downconvert thread no longer handles this dlm lock bast request. Then, the other nodes will not get the dlm lock again, the current node's process will be blocked when acquire this dlm lock again.
---
fs/ocfs2/dlmglue.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
fs/ocfs2/dlmglue.c renamed from fs/ocfs2/dlmglue.c~ocfs2-ocfs2_downconvert_lock-failure-results-in-deadlock +12 -0
@@ -16,6 +16,7 @@#include <linux/debugfs.h> #include <linux/seq_file.h> #include <linux/time.h> +#include <linux/delay.h> #include <linux/quotaops.h> #include <linux/sched/signal.h>
@@ -3912,6 +3913,17 @@ downconvert:spin_unlock_irqrestore (&lockres->l_lock, flags); ret =ocfs2_downconvert_lock (osb, lockres, new_level, set_lvb, gen); +/* The dlm lock convert is being cancelled in background, +* ocfs2_cancel_convert() is asynchronous in fs/dlm, +* requeue it, try again later. +*/ +if (ret == -EBUSY ) { + ctl->requeue =1 ; +mlog (ML_BASTS ,"lockres %s, ReQ: Downconvert busy\n" , + lockres->l_name); + ret =0 ; +msleep (20 ); + } leave:if (ret)
_
Andrew Morton
maintainerPATCH 8/212 arch/csky/kernel/probes/kprobes.c: fix bugon.cocci warnings
In reply to Andrew MortonFrom: kernel test robot <[email protected]>
Subject: arch/csky/kernel/probes/kprobes.c: fix bugon.cocci warnings
Use BUG_ON instead of a if condition followed by BUG.
Generated by: scripts/coccinelle/misc/bugon.cocci
---
arch/csky/kernel/probes/kprobes.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
arch/csky/kernel/probes/kprobes.c renamed from arch/csky/kernel/probes/kprobes.c~lib-fix-bugoncocci-warnings +1 -2
@@ -283,8 +283,7 @@ int __kprobes kprobe_fault_handler(struc* normal page fault. */ regs->pc = (unsigned long ) cur->addr; -if (!instruction_pointer (regs)) -BUG (); +BUG_ON (!instruction_pointer (regs));if (kcb->kprobe_status ==KPROBE_REENTER )restore_previous_kprobe (kcb);
_
Andrew Morton
maintainerPATCH 9/212 mm, slub: don't call flush_all() from slab_debug_trace_open()
In reply to Andrew MortonFrom: Vlastimil Babka <[email protected]>
Subject: mm, slub: don't call flush_all() from slab_debug_trace_open()
Patch series "SLUB: reduce irq disabled scope and make it RT compatible", v4.
This series was initially inspired by Mel's pcplist local_lock rewrite, and also interest to better understand SLUB's locking and the new primitives and RT variants and implications. It should make SLUB more preemption-friendly, especially for RT, hopefully without noticeable regressions, as the fast paths are not affected.
The RFC/v1 version got basic performance screening by Mel that didn't show major regressions. Mike's testing with hackbench of v2 on !RT reported negligible differences [6]:
virgin(ish) tip
5.13.0.g60ab3ed-tip
7,320.67 msec task-clock # 7.792 CPUs utilized ( +- 0.31% )
221,215 context-switches # 0.030 M/sec ( +- 3.97% )
16,234 cpu-migrations # 0.002 M/sec ( +- 4.07% )
13,233 page-faults # 0.002 M/sec ( +- 0.91% )
27,592,205,252 cycles # 3.769 GHz ( +- 0.32% )
8,309,495,040 instructions # 0.30 insn per cycle ( +- 0.37% )
1,555,210,607 branches # 212.441 M/sec ( +- 0.42% )
5,484,209 branch-misses # 0.35% of all branches ( +- 2.13% ) 0.93949 +- 0.00423 seconds time elapsed ( +- 0.45% )
0.94608 +- 0.00384 seconds time elapsed ( +- 0.41% ) (repeat)
0.94422 +- 0.00410 seconds time elapsed ( +- 0.43% )5.13.0.g60ab3ed-tip +slub-local-lock-v2r3
7,343.57 msec task-clock # 7.776 CPUs utilized ( +- 0.44% )
223,044 context-switches # 0.030 M/sec ( +- 3.02% )
16,057 cpu-migrations # 0.002 M/sec ( +- 4.03% )
13,164 page-faults # 0.002 M/sec ( +- 0.97% )
27,684,906,017 cycles # 3.770 GHz ( +- 0.45% )
8,323,273,871 instructions # 0.30 insn per cycle ( +- 0.28% )
1,556,106,680 branches # 211.901 M/sec ( +- 0.31% )
5,463,468 branch-misses # 0.35% of all branches ( +- 1.33% ) 0.94440 +- 0.00352 seconds time elapsed ( +- 0.37% )
0.94830 +- 0.00228 seconds time elapsed ( +- 0.24% ) (repeat)
0.93813 +- 0.00440 seconds time elapsed ( +- 0.47% ) (repeat)RT configs showed some throughput regressions, but that's expected tradeoff for the preemption improvements through the RT mutex. It didn't prevent the v2 to be incorporated to the 5.13 RT tree [7], leading to testing exposure and bugfixes.
Before the series, SLUB is lockless in both allocation and free fast paths, but elsewhere, it's disabling irqs for considerable periods of time
- especially in allocation slowpath and the bulk allocation, where IRQs are re-enabled only when a new page from the page allocator is needed, and the context allows blocking. The irq disabled sections can then include deactivate_slab() which walks a full freelist and frees the slab back to page allocator or unfreeze_partials() going through a list of percpu partial slabs. The RT tree currently has some patches mitigating these, but we can do much better in mainline too.
Patches 1-6 are straightforward improvements or cleanups that could exist outside of this series too, but are prerequsities.
Patches 7-10 are also preparatory code changes without functional changes, but not so useful without the rest of the series.
Patch 11 simplifies the fast paths on systems with preemption, based on (hopefully correct) observation that the current loops to verify tid are unnecessary.
Patches 12-21 focus on reducing irq disabled scope in the allocation slowpath.
Patch 12 moves disabling of irqs into ___slab_alloc() from its callers, which are the allocation slowpath, and bulk allocation. Instead these callers only disable preemption to stabilize the cpu. The following patches then gradually reduce the scope of disabled irqs in ___slab_alloc() and the functions called from there. As of patch 15, the re-enabling of irqs based on gfp flags before calling the page allocator is removed from allocate_slab(). As of patch 18, it's possible to reach the page allocator (in case of existing slabs depleted) without disabling and re-enabling irqs a single time.
Pathces 22-27 reduce the scope of disabled irqs in functions related to unfreezing percpu partial slab.
Patch 28 is preparatory. Patch 29 is adopted from the RT tree and converts the flushing of percpu slabs on all cpus from using IPI to workqueue, so that the processing isn't happening with irqs disabled in the IPI handler. The flushing is not performance critical so it should be acceptable.
Patch 30 also comes from RT tree and makes object_map_lock RT compatible.
Patches 31-32 make slab_lock irq-safe on RT where we cannot rely on having irq disabled from the list_lock spin lock usage.
Patch 33 changes kmem_cache_cpu->partial handling in put_cpu_partial() from cmpxchg loop to a short irq disabled section, which is used by all other code modifying the field. This addresses a theoretical race scenario pointed out by Jann, and makes the critical section safe wrt with RT local_lock semantics after the conversion in patch 35.
Patch 34 changes preempt disable to migrate disable, so that the nested list_lock spinlock is safe to take on RT. Because migrate_disable() is a function call even on !RT, a small set of private wrappers is introduced to keep using the cheaper preempt_disable() on !PREEMPT_RT configurations.
As of this patch, SLUB should be compatible with RT's lock semantics, to the best of my knowledge.
Finally, patch 35 changes irq disabled sections that protect kmem_cache_cpu fields in the slow paths, with a local lock. However on PREEMPT_RT it means the lockless fast paths can now preempt slow paths which don't expect that, so the local lock has to be taken also in the fast paths and they are no longer lockless. It's up to RT folks to decide if this is a good tradeoff. The patch also updates the locking documentation in the file's comment.
The main results of this series:
* irq disabling is only done for minimum amount of time needed to protect the kmem_cache_cpu data and as part of spin lock, local lock and bit lock operations to make them irq-safe
* SLUB should be fully PREEMPT_RT compatible
This should have obvious implications for better preemptibility, especially on RT.
Some details are different than how the previous SLUB RT tree patches were implemented:
mm: sl[au]b: Change list_lock to raw_spinlock_t [2] - the SLAB part can be dropped as a different patch restricts RT to SLUB anyway. And after this series the list_lock in SLUB is never used with irqs disabled before taking the lock so it doesn't have to be converted to raw_spinlock_t.
mm: slub: Move discard_slab() invocations out of IRQ-off sections [3] should be unnecessary as this series does move these invocations outside irq disabled sections in a different way.
The remaining patches to upstream from the RT tree are small ones related to KConfig. The patch that restricts PREEMPT_RT to SLUB (not SLAB or SLOB) makes sense. The patch that disables CONFIG_SLUB_CPU_PARTIAL with PREEMPT_RT could perhaps be re-evaluated as the series addresses some latency issues with it.
[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-rt-devel.git/tree/patches/0001-mm-sl-au-b-Change-list_lock-to-raw_spinlock_t.patch?h=linux-5.12.y-rt-patches
[3] https://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-rt-devel.git/tree/patches/0004-mm-slub-Move-discard_slab-invocations-out-of-IRQ-off.patch?h=linux-5.12.y-rt-patches
[4] https://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-rt-devel.git/tree/patches/0005-mm-slub-Move-flush_cpu_slab-invocations-__free_slab-.patch?h=linux-5.12.y-rt-patches
[5] https://lore.kernel.org/lkml/[email protected]/
[6] https://lore.kernel.org/lkml/[email protected]
[7] https://lore.kernel.org/linux-rt-users/[email protected]/
[8] https://lore.kernel.org/lkml/[email protected]/
[9] https://lore.kernel.org/lkml/[email protected]/
This patch (of 35:
slab_debug_trace_open() can only be called on caches with SLAB_STORE_USER flag and as with all slub debugging flags, such caches avoid cpu or percpu partial slabs altogether, so there's nothing to flush.
---
mm/slub.c | 3 --- 1 file changed, 3 deletions(-)
mm/slub.c renamed from mm/slub.c~mm-slub-dont-call-flush_all-from-slab_debug_trace_open +0 -3
@@ -5825,9 +5825,6 @@ static int slab_debug_trace_open(structif (!alloc_loc_track (t,PAGE_SIZE /sizeof (struct location ),GFP_KERNEL ))return -ENOMEM ; -/* Push back cpu slabs */ -flush_all (s); -for_each_kmem_cache_node (s, node, n) {unsigned long flags;struct page *page;
_
Andrew Morton
maintainerPATCH 10/212 mm, slub: allocate private object map for debugfs listings
In reply to Andrew MortonFrom: Vlastimil Babka <[email protected]>
Subject: mm, slub: allocate private object map for debugfs listings
Slub has a static spinlock protected bitmap for marking which objects are on freelist when it wants to list them, for situations where dynamically allocating such map can lead to recursion or locking issues, and on-stack bitmap would be too large.
The handlers of debugfs files alloc_traces and free_traces also currently use this shared bitmap, but their syscall context makes it straightforward to allocate a private map before entering locked sections, so switch these processing paths to use a private bitmap.
---
mm/slub.c | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-)
mm/slub.c renamed from mm/slub.c~mm-slub-allocate-private-object-map-for-debugfs-listings +29 -15
@@ -454,6 +454,18 @@ static inline bool cmpxchg_double_slab(sstatic unsigned long object_map[BITS_TO_LONGS (MAX_OBJS_PER_PAGE )];static DEFINE_SPINLOCK (object_map_lock); +static void __fill_map (unsigned long *obj_map,struct kmem_cache *s, +struct page *page) +{ +void *addr =page_address (page); +void *p; + +bitmap_zero (obj_map, page->objects); + +for (p = page->freelist; p; p =get_freepointer (s, p)) +set_bit (__obj_to_index (s, addr, p), obj_map); +} +#if IS_ENABLED (CONFIG_KUNIT )static bool slab_add_kunit_errors (void ) {
@@ -483,17 +495,11 @@ static inline bool slab_add_kunit_errorsstatic unsigned long *get_map (struct kmem_cache *s,struct page *page) __acquires(&object_map_lock) { -void *p; -void *addr =page_address (page); -VM_BUG_ON (!irqs_disabled ());spin_lock (&object_map_lock); -bitmap_zero (object_map, page->objects); - -for (p = page->freelist; p; p =get_freepointer (s, p)) -set_bit (__obj_to_index (s, addr, p), object_map); +__fill_map (object_map, s, page);return object_map; }
@@ -4879,17 +4885,17 @@ static int add_location(struct loc_track }static void process_slab (struct loc_track *t,struct kmem_cache *s, -struct page *page,enum track_item alloc) +struct page *page,enum track_item alloc, +unsigned long *obj_map) {void *addr =page_address (page);void *p; -unsigned long *map; - map =get_map (s, page); +__fill_map (obj_map, s, page); +for_each_object (p, s, addr, page->objects) -if (!test_bit (__obj_to_index (s, addr, p), map)) +if (!test_bit (__obj_to_index (s, addr, p), obj_map))add_location (t, s,get_track (s, p, alloc)); -put_map (map); }#endif /* CONFIG_DEBUG_FS */ #endif /* CONFIG_SLUB_DEBUG */
@@ -5816,14 +5822,21 @@ static int slab_debug_trace_open(structstruct loc_track *t =__seq_open_private (filep, &slab_debugfs_sops,sizeof (struct loc_track ));struct kmem_cache *s =file_inode (filep)->i_private; +unsigned long *obj_map; + + obj_map =bitmap_alloc (oo_objects (s->oo),GFP_KERNEL ); +if (!obj_map) +return -ENOMEM ;if (strcmp (filep->f_path.dentry->d_name.name,"alloc_traces" ) ==0 ) alloc =TRACK_ALLOC ;else alloc =TRACK_FREE ; -if (!alloc_loc_track (t,PAGE_SIZE /sizeof (struct location ),GFP_KERNEL )) +if (!alloc_loc_track (t,PAGE_SIZE /sizeof (struct location ),GFP_KERNEL )) { +bitmap_free (obj_map);return -ENOMEM ; + }for_each_kmem_cache_node (s, node, n) {unsigned long flags;
@@ -5834,12 +5847,13 @@ static int slab_debug_trace_open(structspin_lock_irqsave (&n->list_lock, flags);list_for_each_entry (page, &n->partial, slab_list) -process_slab (t, s, page, alloc); +process_slab (t, s, page, alloc, obj_map);list_for_each_entry (page, &n->full, slab_list) -process_slab (t, s, page, alloc); +process_slab (t, s, page, alloc, obj_map);spin_unlock_irqrestore (&n->list_lock, flags); } +bitmap_free (obj_map);return 0 ; }
_
Andrew Morton
maintainerPATCH 11/212 mm, slub: allocate private object map for validate_slab_cache()
In reply to Andrew MortonFrom: Vlastimil Babka <[email protected]>
Subject: mm, slub: allocate private object map for validate_slab_cache()
validate_slab_cache() is called either to handle a sysfs write, or from a self-test context. In both situations it's straightforward to preallocate a private object bitmap instead of grabbing the shared static one meant for critical sections, so let's do that.
---
mm/slub.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-)
mm/slub.c renamed from mm/slub.c~mm-slub-allocate-private-object-map-for-validate_slab_cache +15 -9
@@ -4679,11 +4679,11 @@ static int count_total(struct page *page#endif #ifdef CONFIG_SLUB_DEBUG -static void validate_slab (struct kmem_cache *s,struct page *page) +static void validate_slab (struct kmem_cache *s,struct page *page, +unsigned long *obj_map) {void *p;void *addr =page_address (page); -unsigned long *map;slab_lock (page);
@@ -4691,21 +4691,20 @@ static void validate_slab(struct kmem_ca goto unlock;/* Now we know that a valid freelist exists */ - map =get_map (s, page); +__fill_map (obj_map, s, page);for_each_object (p, s, addr, page->objects) { -u8 val =test_bit (__obj_to_index (s, addr, p), map) ? +u8 val =test_bit (__obj_to_index (s, addr, p), obj_map) ?SLUB_RED_INACTIVE :SLUB_RED_ACTIVE ;if (!check_object (s, page, p, val))break ; } -put_map (map); unlock:slab_unlock (page); }static int validate_slab_node (struct kmem_cache *s, -struct kmem_cache_node *n) +struct kmem_cache_node *n,unsigned long *obj_map) {unsigned long count =0 ;struct page *page;
@@ -4714,7 +4713,7 @@ static int validate_slab_node(struct kmespin_lock_irqsave (&n->list_lock, flags);list_for_each_entry (page, &n->partial, slab_list) { -validate_slab (s, page); +validate_slab (s, page, obj_map); count++; }if (count != n->nr_partial) {
@@ -4727,7 +4726,7 @@ static int validate_slab_node(struct kme goto out;list_for_each_entry (page, &n->full, slab_list) { -validate_slab (s, page); +validate_slab (s, page, obj_map); count++; }if (count !=atomic_long_read (&n->nr_slabs)) {
@@ -4746,10 +4745,17 @@ long validate_slab_cache(struct kmem_cacint node;unsigned long count =0 ;struct kmem_cache_node *n; +unsigned long *obj_map; + + obj_map =bitmap_alloc (oo_objects (s->oo),GFP_KERNEL ); +if (!obj_map) +return -ENOMEM ;flush_all (s);for_each_kmem_cache_node (s, node, n) - count +=validate_slab_node (s, n); + count +=validate_slab_node (s, n, obj_map); + +bitmap_free (obj_map);return count; }
_
Andrew Morton
maintainerPATCH 12/212 mm, slub: don't disable irq for debug_check_no_locks_freed()
In reply to Andrew MortonFrom: Vlastimil Babka <[email protected]>
Subject: mm, slub: don't disable irq for debug_check_no_locks_freed()
In slab_free_hook() we disable irqs around the debug_check_no_locks_freed() call, which is unnecessary, as irqs are already being disabled inside the call. This seems to be leftover from the past where there were more calls inside the irq disabled sections. Remove the irq disable/enable operations.
Mel noted:
Quoted 1 line
Looks like it was needed for kmemcheck which went away back in 4.15
---
mm/slub.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-)
mm/slub.c renamed from mm/slub.c~mm-slub-dont-disable-irq-for-debug_check_no_locks_freed +1 -13
@@ -1591,20 +1591,8 @@ static __always_inline bool slab_free_ho {kmemleak_free_recursive (x, s->flags); -/* -* Trouble is that we may no longer disable interrupts in the fast path -* So in order to make the debug calls that expect irqs to be -* disabled we need to disable interrupts temporarily. -*/ -#ifdef CONFIG_LOCKDEP - { -unsigned long flags; +debug_check_no_locks_freed (x, s->object_size); -local_irq_save (flags); -debug_check_no_locks_freed (x, s->object_size); -local_irq_restore (flags); - } -#endif if (!(s->flags &SLAB_DEBUG_OBJECTS ))debug_check_no_obj_freed (x, s->object_size);
_
Andrew Morton
maintainerPATCH 13/212 mm, slub: remove redundant unfreeze_partials() from put_cpu_partial()
In reply to Andrew MortonFrom: Vlastimil Babka <[email protected]>
Subject: mm, slub: remove redundant unfreeze_partials() from put_cpu_partial()
Commit d6e0b7fa1186 ("slub: make dead caches discard free slabs immediately") introduced cpu partial flushing for kmemcg caches, based on setting the target cpu_partial to 0 and adding a flushing check in put_cpu_partial(). This code that sets cpu_partial to 0 was later moved by c9fc586403e7 ("slab: introduce __kmemcg_cache_deactivate()") and ultimately removed by 9855609bde03 ("mm: memcg/slab: use a single set of kmem_caches for all accounted allocations"). However the check and flush in put_cpu_partial() was never removed, although it's effectively a dead code. So this patch removes it.
Note that d6e0b7fa1186 also added preempt_disable()/enable() to unfreeze_partials() which could be thus also considered unnecessary. But further patches will rely on it, so keep it.
---
mm/slub.c | 7 ------- 1 file changed, 7 deletions(-)
mm/slub.c renamed from mm/slub.c~mm-slub-remove-redundant-unfreeze_partials-from-put_cpu_partial +0 -7
@@ -2466,13 +2466,6 @@ static void put_cpu_partial(struct kmem_ } while (this_cpu_cmpxchg(s->cpu_slab->partial, oldpage, page) != oldpage); -if (unlikely (!slub_cpu_partial (s))) { -unsigned long flags; - -local_irq_save (flags); -unfreeze_partials (s,this_cpu_ptr (s->cpu_slab)); -local_irq_restore (flags); - }preempt_enable ();#endif /* CONFIG_SLUB_CPU_PARTIAL */ }
_
Andrew Morton
maintainerPATCH 14/212 mm, slub: unify cmpxchg_double_slab() and __cmpxchg_double_slab()
In reply to Andrew MortonFrom: Vlastimil Babka <[email protected]>
Subject: mm, slub: unify cmpxchg_double_slab() and __cmpxchg_double_slab()
These functions differ only in irq disabling in the slow path. We can create a common function with an extra bool parameter to control the irq disabling. As the functions are inline and the parameter compile-time constant, there will be no runtime overhead due to this change.
Also change the DEBUG_VM based irqs disable assert to the more standard lockdep_assert based one.
---
mm/slub.c | 62 ++++++++++++++++++++-------------------------------- 1 file changed, 24 insertions(+), 38 deletions(-)
mm/slub.c renamed from mm/slub.c~mm-slub-unify-cmpxchg_double_slab-and-__cmpxchg_double_slab +24 -38
@@ -371,13 +371,13 @@ static __always_inline void slab_unlock(__bit_spin_unlock (PG_locked, &page->flags); } -/* Interrupts must be disabled (for the fallback code to work right) */ -static inline bool __cmpxchg_double_slab (struct kmem_cache *s,struct page *page, +static inline bool ___cmpxchg_double_slab (struct kmem_cache *s,struct page *page,void *freelist_old,unsigned long counters_old,void *freelist_new,unsigned long counters_new, -const char *n) +const char *n,bool disable_irqs) { -VM_BUG_ON (!irqs_disabled ()); +if (!disable_irqs) +lockdep_assert_irqs_disabled ();#if defined(CONFIG_HAVE_CMPXCHG_DOUBLE ) && \ defined(CONFIG_HAVE_ALIGNED_STRUCT_PAGE )if (s->flags & __CMPXCHG_DOUBLE) {
@@ -388,15 +388,23 @@ static inline bool __cmpxchg_double_slab } else#endif { +unsigned long flags; + +if (disable_irqs) +local_irq_save (flags);slab_lock (page);if (page->freelist == freelist_old && page->counters == counters_old) { page->freelist = freelist_new; page->counters = counters_new;slab_unlock (page); +if (disable_irqs) +local_irq_restore (flags);return true; }slab_unlock (page); +if (disable_irqs) +local_irq_restore (flags); }cpu_relax ();
@@ -409,45 +417,23 @@ static inline bool __cmpxchg_double_slabreturn false; } -static inline bool cmpxchg_double_slab (struct kmem_cache *s,struct page *page, +/* Interrupts must be disabled (for the fallback code to work right) */ +static inline bool __cmpxchg_double_slab (struct kmem_cache *s,struct page *page,void *freelist_old,unsigned long counters_old,void *freelist_new,unsigned long counters_new,const char *n) { -#if defined(CONFIG_HAVE_CMPXCHG_DOUBLE ) && \ - defined(CONFIG_HAVE_ALIGNED_STRUCT_PAGE ) -if (s->flags & __CMPXCHG_DOUBLE) { -if (cmpxchg_double (&page->freelist, &page->counters, - freelist_old, counters_old, - freelist_new, counters_new)) -return true; - } else -#endif - { -unsigned long flags; - -local_irq_save (flags); -slab_lock (page); -if (page->freelist == freelist_old && - page->counters == counters_old) { - page->freelist = freelist_new; - page->counters = counters_new; -slab_unlock (page); -local_irq_restore (flags); -return true; - } -slab_unlock (page); -local_irq_restore (flags); - } - -cpu_relax (); -stat (s,CMPXCHG_DOUBLE_FAIL ); - -#ifdef SLUB_DEBUG_CMPXCHG -pr_info ("%s %s: cmpxchg double redo " , n, s->name); -#endif +return ___cmpxchg_double_slab (s, page, freelist_old, counters_old, + freelist_new, counters_new, n, false); +} -return false; +static inline bool cmpxchg_double_slab (struct kmem_cache *s,struct page *page, +void *freelist_old,unsigned long counters_old, +void *freelist_new,unsigned long counters_new, +const char *n) +{ +return ___cmpxchg_double_slab (s, page, freelist_old, counters_old, + freelist_new, counters_new, n, true); }#ifdef CONFIG_SLUB_DEBUG
_
Andrew Morton
maintainerPATCH 15/212 mm, slub: extract get_partial() from new_slab_objects()
In reply to Andrew MortonFrom: Vlastimil Babka <[email protected]>
Subject: mm, slub: extract get_partial() from new_slab_objects()
The later patches will need more fine grained control over individual actions in ___slab_alloc(), the only caller of new_slab_objects(), so this is a first preparatory step with no functional change.
This adds a goto label that appears unnecessary at this point, but will be useful for later changes.
---
mm/slub.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
mm/slub.c renamed from mm/slub.c~mm-slub-extract-get_partial-from-new_slab_objects +6 -6
@@ -2599,17 +2599,12 @@ slab_out_of_memory(struct kmem_cache *s,static inline void *new_slab_objects (struct kmem_cache *s,gfp_t flags,int node,struct kmem_cache_cpu **pc) { -void *freelist; +void *freelist =NULL ;struct kmem_cache_cpu *c = *pc;struct page *page;WARN_ON_ONCE (s->ctor && (flags & __GFP_ZERO)); - freelist =get_partial (s, flags, node, c); - -if (freelist) -return freelist; - page =new_slab (s, flags, node);if (page) { c =raw_cpu_ptr (s->cpu_slab);
@@ -2773,6 +2768,10 @@ new_slab: goto redo; } + freelist =get_partial (s, gfpflags, node, c); +if (freelist) + goto check_new_page; + freelist =new_slab_objects (s, gfpflags, node, &c);if (unlikely (!freelist)) {
@@ -2780,6 +2779,7 @@ new_slab:return NULL ; } +check_new_page: page = c->page;if (likely (!kmem_cache_debug (s) &&pfmemalloc_match (page, gfpflags))) goto load_freelist;
_
Andrew Morton
maintainerPATCH 16/212 mm, slub: dissolve new_slab_objects() into ___slab_alloc()
In reply to Andrew MortonFrom: Vlastimil Babka <[email protected]>
Subject: mm, slub: dissolve new_slab_objects() into ___slab_alloc()
The later patches will need more fine grained control over individual actions in ___slab_alloc(), the only caller of new_slab_objects(), so dissolve it there. This is a preparatory step with no functional change.
The only minor change is moving WARN_ON_ONCE() for using a constructor together with __GFP_ZERO to new_slab(), which makes it somewhat less frequent, but still able to catch a development change introducing a systematic misuse.
---
mm/slub.c | 50 ++++++++++++++++++-------------------------------- 1 file changed, 18 insertions(+), 32 deletions(-)
mm/slub.c renamed from mm/slub.c~mm-slub-dissolve-new_slab_objects-into-___slab_alloc +18 -32
@@ -1871,6 +1871,8 @@ static struct page *new_slab(struct kmemif (unlikely (flags &GFP_SLAB_BUG_MASK )) flags =kmalloc_fix_flags (flags); +WARN_ON_ONCE (s->ctor && (flags & __GFP_ZERO)); +return allocate_slab (s, flags & (GFP_RECLAIM_MASK |GFP_CONSTRAINT_MASK ), node); }
@@ -2596,36 +2598,6 @@ slab_out_of_memory(struct kmem_cache *s,#endif } -static inline void *new_slab_objects (struct kmem_cache *s,gfp_t flags, -int node,struct kmem_cache_cpu **pc) -{ -void *freelist =NULL ; -struct kmem_cache_cpu *c = *pc; -struct page *page; - -WARN_ON_ONCE (s->ctor && (flags & __GFP_ZERO)); - - page =new_slab (s, flags, node); -if (page) { - c =raw_cpu_ptr (s->cpu_slab); -if (c->page) -flush_slab (s, c); - -/* -* No other reference to the page yet so we can -* muck around with it freely without cmpxchg -*/ - freelist = page->freelist; - page->freelist =NULL ; - -stat (s,ALLOC_SLAB ); - c->page = page; - *pc = c; - } - -return freelist; -} -static inline bool pfmemalloc_match (struct page *page,gfp_t gfpflags) {if (unlikely (PageSlabPfmemalloc (page)))
@@ -2772,13 +2744,27 @@ new_slab:if (freelist) goto check_new_page; - freelist =new_slab_objects (s, gfpflags, node, &c); + page =new_slab (s, gfpflags, node); -if (unlikely (!freelist)) { +if (unlikely (!page)) {slab_out_of_memory (s, gfpflags, node);return NULL ; } + c =raw_cpu_ptr (s->cpu_slab); +if (c->page) +flush_slab (s, c); + +/* +* No other reference to the page yet so we can +* muck around with it freely without cmpxchg +*/ + freelist = page->freelist; + page->freelist =NULL ; + +stat (s,ALLOC_SLAB ); + c->page = page; + check_new_page: page = c->page;if (likely (!kmem_cache_debug (s) &&pfmemalloc_match (page, gfpflags)))
_
Andrew Morton
maintainerPATCH 17/212 mm, slub: return slab page from get_partial() and set c->page afterwards
In reply to Andrew MortonFrom: Vlastimil Babka <[email protected]>
Subject: mm, slub: return slab page from get_partial() and set c->page afterwards
The function get_partial() finds a suitable page on a partial list, acquires and returns its freelist and assigns the page pointer to kmem_cache_cpu. In later patch we will need more control over the kmem_cache_cpu.page assignment, so instead of passing a kmem_cache_cpu pointer, pass a pointer to a pointer to a page that get_partial() can fill and the caller can assign the kmem_cache_cpu.page pointer. No functional change as all of this still happens with disabled IRQs.
---
mm/slub.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)
mm/slub.c renamed from mm/slub.c~mm-slub-return-slab-page-from-get_partial-and-set-c-page-afterwards +11 -10
@@ -2003,7 +2003,7 @@ static inline bool pfmemalloc_match(stru* Try to allocate a partial slab from a specific node. */ static void *get_partial_node (struct kmem_cache *s,struct kmem_cache_node *n, -struct kmem_cache_cpu *c,gfp_t flags) +struct page **ret_page,gfp_t flags) {struct page *page, *page2;void *object =NULL ;
@@ -2032,7 +2032,7 @@ static void *get_partial_node(struct kme available += objects;if (!object) { - c->page = page; + *ret_page = page;stat (s,ALLOC_FROM_PARTIAL ); object = t; }else {
@@ -2052,7 +2052,7 @@ static void *get_partial_node(struct kme* Get a page from somewhere. Search in increasing NUMA distances. */ static void *get_any_partial (struct kmem_cache *s,gfp_t flags, -struct kmem_cache_cpu *c) +struct page **ret_page) {#ifdef CONFIG_NUMA struct zonelist *zonelist;
@@ -2094,7 +2094,7 @@ static void *get_any_partial(struct kmemif (n &&cpuset_zone_allowed (zone, flags) && n->nr_partial > s->min_partial) { - object =get_partial_node (s, n, c, flags); + object =get_partial_node (s, n, ret_page, flags);if (object) {/* * Don't check read_mems_allowed_retry()
@@ -2116,7 +2116,7 @@ static void *get_any_partial(struct kmem* Get a partial page, lock it and return it. */ static void *get_partial (struct kmem_cache *s,gfp_t flags,int node, -struct kmem_cache_cpu *c) +struct page **ret_page) {void *object;int searchnode = node;
@@ -2124,11 +2124,11 @@ static void *get_partial(struct kmem_cacif (node ==NUMA_NO_NODE ) searchnode =numa_mem_id (); - object =get_partial_node (s,get_node (s, searchnode), c, flags); + object =get_partial_node (s,get_node (s, searchnode), ret_page, flags);if (object || node !=NUMA_NO_NODE )return object; -return get_any_partial (s, flags, c); +return get_any_partial (s, flags, ret_page); }#ifdef CONFIG_PREEMPTION
@@ -2740,9 +2740,11 @@ new_slab: goto redo; } - freelist =get_partial (s, gfpflags, node, c); -if (freelist) + freelist =get_partial (s, gfpflags, node, &page); +if (freelist) { + c->page = page; goto check_new_page; + } page =new_slab (s, gfpflags, node);
@@ -2766,7 +2768,6 @@ new_slab: c->page = page; check_new_page: - page = c->page;if (likely (!kmem_cache_debug (s) &&pfmemalloc_match (page, gfpflags))) goto load_freelist;
_
Andrew Morton
maintainerPATCH 18/212 mm, slub: restructure new page checks in ___slab_alloc()
In reply to Andrew MortonFrom: Vlastimil Babka <[email protected]>
Subject: mm, slub: restructure new page checks in ___slab_alloc()
When we allocate slab object from a newly acquired page (from node's partial list or page allocator), we usually also retain the page as a new percpu slab. There are two exceptions - when pfmemalloc status of the page doesn't match our gfp flags, or when the cache has debugging enabled.
The current code for these decisions is not easy to follow, so restructure it and add comments. The new structure will also help with the following changes. No functional change.
---
mm/slub.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-)
mm/slub.c renamed from mm/slub.c~mm-slub-restructure-new-page-checks-in-___slab_alloc +22 -6
@@ -2768,13 +2768,29 @@ new_slab: c->page = page; check_new_page: -if (likely (!kmem_cache_debug (s) &&pfmemalloc_match (page, gfpflags))) - goto load_freelist; -/* Only entered in the debug case */ -if (kmem_cache_debug (s) && - !alloc_debug_processing (s, page, freelist, addr)) - goto new_slab;/* Slab failed checks. Next slab needed */ +if (kmem_cache_debug (s)) { +if (!alloc_debug_processing (s, page, freelist, addr)) +/* Slab failed checks. Next slab needed */ + goto new_slab; +else +/* +* For debug case, we don't load freelist so that all +* allocations go through alloc_debug_processing() +*/ + goto return_single; + } + +if (unlikely (!pfmemalloc_match (page, gfpflags))) +/* +* For !pfmemalloc_match() case we don't load freelist so that +* we don't make further mismatched allocations easier. +*/ + goto return_single; + + goto load_freelist; + +return_single:deactivate_slab (s, page,get_freepointer (s, freelist), c);return freelist;
_
Andrew Morton
maintainerPATCH 19/212 mm, slub: simplify kmem_cache_cpu and tid setup
In reply to Andrew MortonFrom: Vlastimil Babka <[email protected]>
Subject: mm, slub: simplify kmem_cache_cpu and tid setup
In slab_alloc_node() and do_slab_free() fastpaths we need to guarantee that our kmem_cache_cpu pointer is from the same cpu as the tid value. Currently that's done by reading the tid first using this_cpu_read(), then the kmem_cache_cpu pointer and verifying we read the same tid using the pointer and plain READ_ONCE().
This can be simplified to just fetching kmem_cache_cpu pointer and then reading tid using the pointer. That guarantees they are from the same cpu. We don't need to read the tid using this_cpu_read() because the value will be validated by this_cpu_cmpxchg_double(), making sure we are on the correct cpu and the freelist didn't change by anyone preempting us since reading the tid.
---
mm/slub.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-)
mm/slub.c renamed from mm/slub.c~mm-slub-simplify-kmem_cache_cpu-and-tid-setup +9 -13
@@ -2868,15 +2868,14 @@ redo:* reading from one cpu area. That does not matter as long * as we end up on the original cpu again when doing the cmpxchg. * -* We should guarantee that tid and kmem_cache are retrieved on -* the same cpu. It could be different if CONFIG_PREEMPTION so we need -* to check if it is matched or not. +* We must guarantee that tid and kmem_cache_cpu are retrieved on the +* same cpu. We read first the kmem_cache_cpu pointer and use it to read +* the tid. If we are preempted and switched to another cpu between the +* two reads, it's OK as the two are still associated with the same cpu +* and cmpxchg later will validate the cpu. */ -do { - tid =this_cpu_read (s->cpu_slab->tid); - c =raw_cpu_ptr (s->cpu_slab); - }while (IS_ENABLED (CONFIG_PREEMPTION ) && -unlikely (tid !=READ_ONCE (c->tid))); + c =raw_cpu_ptr (s->cpu_slab); + tid =READ_ONCE (c->tid);/* * Irqless object alloc/free algorithm used here depends on sequence
@@ -3150,11 +3149,8 @@ redo:* data is retrieved via this pointer. If we are on the same cpu * during the cmpxchg then the free will succeed. */ -do { - tid =this_cpu_read (s->cpu_slab->tid); - c =raw_cpu_ptr (s->cpu_slab); - }while (IS_ENABLED (CONFIG_PREEMPTION ) && -unlikely (tid !=READ_ONCE (c->tid))); + c =raw_cpu_ptr (s->cpu_slab); + tid =READ_ONCE (c->tid);/* Same with comment on barrier() in slab_alloc_node() */ barrier ();
_
Andrew Morton
maintainerPATCH 20/212 mm, slub: move disabling/enabling irqs to ___slab_alloc()
In reply to Andrew MortonFrom: Vlastimil Babka <[email protected]>
Subject: mm, slub: move disabling/enabling irqs to ___slab_alloc()
Currently __slab_alloc() disables irqs around the whole ___slab_alloc(). This includes cases where this is not needed, such as when the allocation ends up in the page allocator and has to awkwardly enable irqs back based on gfp flags. Also the whole kmem_cache_alloc_bulk() is executed with irqs disabled even when it hits the __slab_alloc() slow path, and long periods with disabled interrupts are undesirable.
As a first step towards reducing irq disabled periods, move irq handling into ___slab_alloc(). Callers will instead prevent the s->cpu_slab percpu pointer from becoming invalid via get_cpu_ptr(), thus preempt_disable(). This does not protect against modification by an irq handler, which is still done by disabled irq for most of ___slab_alloc(). As a small immediate benefit, slab_out_of_memory() from ___slab_alloc() is now called with irqs enabled.
kmem_cache_alloc_bulk() disables irqs for its fastpath and then re-enables them before calling ___slab_alloc(), which then disables them at its discretion. The whole kmem_cache_alloc_bulk() operation also disables preemption.
When ___slab_alloc() calls new_slab() to allocate a new page, re-enable preemption, because new_slab() will re-enable interrupts in contexts that allow blocking (this will be improved by later patches).
The patch itself will thus increase overhead a bit due to disabled preemption (on configs where it matters) and increased disabling/enabling irqs in kmem_cache_alloc_bulk(), but that will be gradually improved in the following patches.
Note in __slab_alloc() we need to change the #ifdef CONFIG_PREEMPT guard to CONFIG_PREEMPT_COUNT to make sure preempt disable/enable is properly paired in all configurations. On configs without involuntary preemption and debugging the re-read of kmem_cache_cpu pointer is still compiled out as it was before.
---
mm/slub.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-)
mm/slub.c renamed from mm/slub.c~mm-slub-move-disabling-enabling-irqs-to-___slab_alloc +24 -12
@@ -2656,7 +2656,7 @@ static inline void *get_freelist(struct* we need to allocate a new slab. This is the slowest path since it involves * a call to the page allocator and the setup of a new slab. * -* Version of __slab_alloc to use when we know that interrupts are +* Version of __slab_alloc to use when we know that preemption is * already disabled (which is the case for bulk allocation). */ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node,
@@ -2664,9 +2664,11 @@ static void *___slab_alloc(struct kmem_c {void *freelist;struct page *page; +unsigned long flags;stat (s,ALLOC_SLOWPATH ); +local_irq_save (flags); page = c->page;if (!page) {/*
@@ -2729,6 +2731,7 @@ load_freelist:VM_BUG_ON (!c->page->frozen); c->freelist =get_freepointer (s, freelist); c->tid =next_tid (c->tid); +local_irq_restore (flags);return freelist; new_slab:
@@ -2746,14 +2749,16 @@ new_slab: goto check_new_page; } +put_cpu_ptr (s->cpu_slab); page =new_slab (s, gfpflags, node); + c =get_cpu_ptr (s->cpu_slab);if (unlikely (!page)) { +local_irq_restore (flags);slab_out_of_memory (s, gfpflags, node);return NULL ; } - c =raw_cpu_ptr (s->cpu_slab);if (c->page)flush_slab (s, c);
@@ -2793,31 +2798,33 @@ check_new_page: return_single:deactivate_slab (s, page,get_freepointer (s, freelist), c); +local_irq_restore (flags);return freelist; }/* -* Another one that disabled interrupt and compensates for possible -* cpu changes by refetching the per cpu area pointer. +* A wrapper for ___slab_alloc() for contexts where preemption is not yet +* disabled. Compensates for possible cpu changes by refetching the per cpu area +* pointer. */ static void *__slab_alloc (struct kmem_cache *s,gfp_t gfpflags,int node,unsigned long addr,struct kmem_cache_cpu *c) {void *p; -unsigned long flags; -local_irq_save (flags); -#ifdef CONFIG_PREEMPTION +#ifdef CONFIG_PREEMPT_COUNT /* * We may have been preempted and rescheduled on a different -* cpu before disabling interrupts. Need to reload cpu area +* cpu before disabling preemption. Need to reload cpu area * pointer. */ - c =this_cpu_ptr (s->cpu_slab); + c =get_cpu_ptr (s->cpu_slab);#endif p =___slab_alloc (s, gfpflags, node, addr, c); -local_irq_restore (flags); +#ifdef CONFIG_PREEMPT_COUNT +put_cpu_ptr (s->cpu_slab); +#endif return p; }
@@ -3345,8 +3352,8 @@ int kmem_cache_alloc_bulk(struct kmem_ca* IRQs, which protects against PREEMPT and interrupts * handlers invoking normal fastpath. */ + c =get_cpu_ptr (s->cpu_slab);local_irq_disable (); - c =this_cpu_ptr (s->cpu_slab);for (i =0 ; i < size; i++) {void *object =kfence_alloc (s, s->object_size, flags);
@@ -3367,6 +3374,8 @@ int kmem_cache_alloc_bulk(struct kmem_ca*/ c->tid =next_tid (c->tid); +local_irq_enable (); +/* * Invoking slow path likely have side-effect * of re-populating per CPU c->freelist
@@ -3379,6 +3388,8 @@ int kmem_cache_alloc_bulk(struct kmem_ca c =this_cpu_ptr (s->cpu_slab);maybe_wipe_obj_freeptr (s, p[i]); +local_irq_disable (); +continue ;/* goto for-loop */ } c->freelist =get_freepointer (s, object);
@@ -3387,6 +3398,7 @@ int kmem_cache_alloc_bulk(struct kmem_ca } c->tid =next_tid (c->tid);local_irq_enable (); +put_cpu_ptr (s->cpu_slab);/* * memcg and kmem_cache debug support and memory initialization.
@@ -3396,7 +3408,7 @@ int kmem_cache_alloc_bulk(struct kmem_ca slab_want_init_on_alloc(flags, s));return i; error: -local_irq_enable (); +put_cpu_ptr (s->cpu_slab);slab_post_alloc_hook (s, objcg, flags, i, p, false);__kmem_cache_free_bulk (s, i, p);return 0 ;
_
Andrew Morton
maintainerPATCH 21/212 mm, slub: do initial checks in ___slab_alloc() with irqs enabled
In reply to Andrew MortonFrom: Vlastimil Babka <[email protected]>
Subject: mm, slub: do initial checks in ___slab_alloc() with irqs enabled
As another step of shortening irq disabled sections in ___slab_alloc(), delay disabling irqs until we pass the initial checks if there is a cached percpu slab and it's suitable for our allocation.
Now we have to recheck c->page after actually disabling irqs as an allocation in irq handler might have replaced it.
Because we call pfmemalloc_match() as one of the checks, we might hit VM_BUG_ON_PAGE(!PageSlab(page)) in PageSlabPfmemalloc in case we get interrupted and the page is freed. Thus introduce a pfmemalloc_match_unsafe() variant that lacks the PageSlab check.
---
include/linux/page-flags.h | 9 +++++ mm/slub.c | 54 +++++++++++++++++++++++++++++------ 2 files changed, 54 insertions(+), 9 deletions(-)
include/linux/page-flags.h renamed from include/linux/page-flags.h~mm-slub-do-initial-checks-in-___slab_alloc-with-irqs-enabled +9 -0
@@ -815,6 +815,15 @@ static inline int PageSlabPfmemalloc(strreturn PageActive (page); } +/* +* A version of PageSlabPfmemalloc() for opportunistic checks where the page +* might have been freed under us and not be a PageSlab anymore. +*/ +static inline int __PageSlabPfmemalloc (struct page *page) +{ +return PageActive (page); +} +static inline void SetPageSlabPfmemalloc (struct page *page) {VM_BUG_ON_PAGE (!PageSlab (page), page);
mm/slub.c renamed from mm/slub.c~mm-slub-do-initial-checks-in-___slab_alloc-with-irqs-enabled +45 -9
102 lines not on this page · raw message
_
Andrew Morton
maintainerPATCH 22/212 mm, slub: move disabling irqs closer to get_partial() in ___slab_alloc()
In reply to Andrew MortonFrom: Vlastimil Babka <[email protected]>
Subject: mm, slub: move disabling irqs closer to get_partial() in ___slab_alloc()
Continue reducing the irq disabled scope. Check for per-cpu partial slabs with first with irqs enabled and then recheck with irqs disabled before grabbing the slab page. Mostly preparatory for the following patches.
---
mm/slub.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-)
mm/slub.c renamed from mm/slub.c~mm-slub-move-disabling-irqs-closer-to-get_partial-in-___slab_alloc +25 -9
@@ -2692,11 +2692,6 @@ reread_page:if (unlikely (node !=NUMA_NO_NODE && !node_isset (node, slab_nodes))) node =NUMA_NO_NODE ; -local_irq_save (flags); -if (unlikely (c->page)) { -local_irq_restore (flags); - goto reread_page; - } goto new_slab; } redo:
@@ -2737,6 +2732,7 @@ redo:if (!freelist) { c->page =NULL ; +local_irq_restore (flags);stat (s,DEACTIVATE_BYPASS ); goto new_slab; }
@@ -2766,12 +2762,19 @@ deactivate_slab: goto reread_page; }deactivate_slab (s, page, c->freelist, c); +local_irq_restore (flags); new_slab: -lockdep_assert_irqs_disabled (); -if (slub_percpu_partial (c)) { +local_irq_save (flags); +if (unlikely (c->page)) { +local_irq_restore (flags); + goto reread_page; + } +if (unlikely (!slub_percpu_partial (c))) + goto new_objects;/* stolen by an IRQ handler */ + page = c->page =slub_percpu_partial (c);slub_set_percpu_partial (c, page);local_irq_restore (flags);
@@ -2779,6 +2782,16 @@ new_slab: goto redo; } +local_irq_save (flags); +if (unlikely (c->page)) { +local_irq_restore (flags); + goto reread_page; + } + +new_objects: + +lockdep_assert_irqs_disabled (); + freelist =get_partial (s, gfpflags, node, &page);if (freelist) { c->page = page;
@@ -2811,15 +2824,18 @@ new_slab: check_new_page:if (kmem_cache_debug (s)) { -if (!alloc_debug_processing (s, page, freelist, addr)) +if (!alloc_debug_processing (s, page, freelist, addr)) {/* Slab failed checks. Next slab needed */ + c->page =NULL ; +local_irq_restore (flags); goto new_slab; -else + }else {/* * For debug case, we don't load freelist so that all * allocations go through alloc_debug_processing() */ goto return_single; + } }if (unlikely (!pfmemalloc_match (page, gfpflags)))
_
Andrew Morton
maintainerPATCH 23/212 mm, slub: restore irqs around calling new_slab()
In reply to Andrew MortonFrom: Vlastimil Babka <[email protected]>
Subject: mm, slub: restore irqs around calling new_slab()
allocate_slab() currently re-enables irqs before calling to the page allocator. It depends on gfpflags_allow_blocking() to determine if it's safe to do so. Now we can instead simply restore irq before calling it through new_slab(). The other caller early_kmem_cache_node_alloc() is unaffected by this.
---
mm/slub.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
mm/slub.c renamed from mm/slub.c~mm-slub-restore-irqs-around-calling-new_slab +2 -6
@@ -1795,9 +1795,6 @@ static struct page *allocate_slab(struct flags &= gfp_allowed_mask; -if (gfpflags_allow_blocking (flags)) -local_irq_enable (); - flags |= s->allocflags;/*
@@ -1856,8 +1853,6 @@ static struct page *allocate_slab(struct page->frozen =1 ; out: -if (gfpflags_allow_blocking (flags)) -local_irq_disable ();if (!page)return NULL ;
@@ -2798,16 +2793,17 @@ new_objects: goto check_new_page; } +local_irq_restore (flags);put_cpu_ptr (s->cpu_slab); page =new_slab (s, gfpflags, node); c =get_cpu_ptr (s->cpu_slab);if (unlikely (!page)) { -local_irq_restore (flags);slab_out_of_memory (s, gfpflags, node);return NULL ; } +local_irq_save (flags);if (c->page)flush_slab (s, c);
_
Andrew Morton
maintainerPATCH 24/212 mm, slub: validate slab from partial list or page allocator before making it cpu slab
In reply to Andrew MortonFrom: Vlastimil Babka <[email protected]>
Subject: mm, slub: validate slab from partial list or page allocator before making it cpu slab
When we obtain a new slab page from node partial list or page allocator, we assign it to kmem_cache_cpu, perform some checks, and if they fail, we undo the assignment.
In order to allow doing the checks without irq disabled, restructure the code so that the checks are done first, and kmem_cache_cpu.page assignment only after they pass.
---
mm/slub.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
mm/slub.c renamed from mm/slub.c~mm-slub-validate-slab-from-partial-list-or-page-allocator-before-making-it-cpu-slab +9 -8
@@ -2788,10 +2788,8 @@ new_objects:lockdep_assert_irqs_disabled (); freelist =get_partial (s, gfpflags, node, &page); -if (freelist) { - c->page = page; +if (freelist) goto check_new_page; - }local_irq_restore (flags);put_cpu_ptr (s->cpu_slab);
@@ -2804,9 +2802,6 @@ new_objects: }local_irq_save (flags); -if (c->page) -flush_slab (s, c); -/* * No other reference to the page yet so we can * muck around with it freely without cmpxchg
@@ -2815,14 +2810,12 @@ new_objects: page->freelist =NULL ;stat (s,ALLOC_SLAB ); - c->page = page; check_new_page:if (kmem_cache_debug (s)) {if (!alloc_debug_processing (s, page, freelist, addr)) {/* Slab failed checks. Next slab needed */ - c->page =NULL ;local_irq_restore (flags); goto new_slab; }else {
@@ -2841,10 +2834,18 @@ check_new_page:*/ goto return_single; +if (unlikely (c->page)) +flush_slab (s, c); + c->page = page; + goto load_freelist; return_single: +if (unlikely (c->page)) +flush_slab (s, c); + c->page = page; +deactivate_slab (s, page,get_freepointer (s, freelist), c);local_irq_restore (flags);return freelist;
_
Andrew Morton
maintainerPATCH 25/212 mm, slub: check new pages with restored irqs
In reply to Andrew MortonFrom: Vlastimil Babka <[email protected]>
Subject: mm, slub: check new pages with restored irqs
Building on top of the previous patch, re-enable irqs before checking new pages. alloc_debug_processing() is now called with enabled irqs so we need to remove VM_BUG_ON(!irqs_disabled()); in check_slab() - there doesn't seem to be a need for it anyway.
---
mm/slub.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
mm/slub.c renamed from mm/slub.c~mm-slub-check-new-pages-with-restored-irqs +3 -5
@@ -995,8 +995,6 @@ static int check_slab(struct kmem_cache {int maxobj; -VM_BUG_ON (!irqs_disabled ()); -if (!PageSlab (page)) {slab_err (s, page,"Not a valid slab page" );return 0 ;
@@ -2788,10 +2786,10 @@ new_objects:lockdep_assert_irqs_disabled (); freelist =get_partial (s, gfpflags, node, &page); +local_irq_restore (flags);if (freelist) goto check_new_page; -local_irq_restore (flags);put_cpu_ptr (s->cpu_slab); page =new_slab (s, gfpflags, node); c =get_cpu_ptr (s->cpu_slab);
@@ -2801,7 +2799,6 @@ new_objects:return NULL ; } -local_irq_save (flags);/* * No other reference to the page yet so we can * muck around with it freely without cmpxchg
@@ -2816,7 +2813,6 @@ check_new_page:if (kmem_cache_debug (s)) {if (!alloc_debug_processing (s, page, freelist, addr)) {/* Slab failed checks. Next slab needed */ -local_irq_restore (flags); goto new_slab; }else {/*
@@ -2834,6 +2830,7 @@ check_new_page:*/ goto return_single; +local_irq_save (flags);if (unlikely (c->page))flush_slab (s, c); c->page = page;
@@ -2842,6 +2839,7 @@ check_new_page: return_single: +local_irq_save (flags);if (unlikely (c->page))flush_slab (s, c); c->page = page;
_
Andrew Morton
maintainerPATCH 26/212 mm, slub: stop disabling irqs around get_partial()
In reply to Andrew MortonFrom: Vlastimil Babka <[email protected]>
Subject: mm, slub: stop disabling irqs around get_partial()
The function get_partial() does not need to have irqs disabled as a whole. It's sufficient to convert spin_lock operations to their irq saving/restoring versions.
As a result, it's now possible to reach the page allocator from the slab allocator without disabling and re-enabling interrupts on the way.
---
mm/slub.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-)
mm/slub.c renamed from mm/slub.c~mm-slub-stop-disabling-irqs-around-get_partial +8 -14
@@ -1996,11 +1996,12 @@ static inline bool pfmemalloc_match(stru* Try to allocate a partial slab from a specific node. */ static void *get_partial_node (struct kmem_cache *s,struct kmem_cache_node *n, -struct page **ret_page,gfp_t flags) +struct page **ret_page,gfp_t gfpflags) {struct page *page, *page2;void *object =NULL ;unsigned int available =0 ; +unsigned long flags;int objects;/*
@@ -2012,11 +2013,11 @@ static void *get_partial_node(struct kmeif (!n || !n->nr_partial)return NULL ; -spin_lock (&n->list_lock); +spin_lock_irqsave (&n->list_lock, flags);list_for_each_entry_safe (page, page2, &n->partial, slab_list) {void *t; -if (!pfmemalloc_match (page, flags)) +if (!pfmemalloc_match (page, gfpflags))continue ; t =acquire_slab (s, n, page, object ==NULL , &objects);
@@ -2037,7 +2038,7 @@ static void *get_partial_node(struct kmebreak ; } -spin_unlock (&n->list_lock); +spin_unlock_irqrestore (&n->list_lock, flags);return object; }
@@ -2765,8 +2766,10 @@ new_slab:local_irq_restore (flags); goto reread_page; } -if (unlikely (!slub_percpu_partial (c))) +if (unlikely (!slub_percpu_partial (c))) { +local_irq_restore (flags); goto new_objects;/* stolen by an IRQ handler */ + } page = c->page =slub_percpu_partial (c);slub_set_percpu_partial (c, page);
@@ -2775,18 +2778,9 @@ new_slab: goto redo; } -local_irq_save (flags); -if (unlikely (c->page)) { -local_irq_restore (flags); - goto reread_page; - } - new_objects: -lockdep_assert_irqs_disabled (); - freelist =get_partial (s, gfpflags, node, &page); -local_irq_restore (flags);if (freelist) goto check_new_page;
_
Andrew Morton
maintainerPATCH 27/212 mm, slub: move reset of c->page and freelist out of deactivate_slab()
In reply to Andrew MortonFrom: Vlastimil Babka <[email protected]>
Subject: mm, slub: move reset of c->page and freelist out of deactivate_slab()
deactivate_slab() removes the cpu slab by merging the cpu freelist with slab's freelist and putting the slab on the proper node's list. It also sets the respective kmem_cache_cpu pointers to NULL.
By extracting the kmem_cache_cpu operations from the function, we can make it not dependent on disabled irqs.
Also if we return a single free pointer from ___slab_alloc, we no longer have to assign kmem_cache_cpu.page before deactivation or care if somebody preempted us and assigned a different page to our kmem_cache_cpu in the process.
---
mm/slub.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-)
mm/slub.c renamed from mm/slub.c~mm-slub-move-reset-of-c-page-and-freelist-out-of-deactivate_slab +18 -13
@@ -2195,10 +2195,13 @@ static void init_kmem_cache_cpus(struct }/* -* Remove the cpu slab +* Finishes removing the cpu slab. Merges cpu's freelist with page's freelist, +* unfreezes the slabs and puts it on the proper list. +* Assumes the slab has been already safely taken away from kmem_cache_cpu +* by the caller. */ static void deactivate_slab (struct kmem_cache *s,struct page *page, -void *freelist,struct kmem_cache_cpu *c) +void *freelist) {enum slab_modes {M_NONE ,M_PARTIAL ,M_FULL ,M_FREE };struct kmem_cache_node *n =get_node (s,page_to_nid (page));
@@ -2327,9 +2330,6 @@ redo:discard_slab (s, page);stat (s,FREE_SLAB ); } - - c->page =NULL ; - c->freelist =NULL ; }/*
@@ -2454,10 +2454,16 @@ static void put_cpu_partial(struct kmem_static inline void flush_slab (struct kmem_cache *s,struct kmem_cache_cpu *c) { -stat (s,CPUSLAB_FLUSH ); -deactivate_slab (s, c->page, c->freelist, c); +void *freelist = c->freelist; +struct page *page = c->page; + c->page =NULL ; + c->freelist =NULL ; c->tid =next_tid (c->tid); + +deactivate_slab (s, page, freelist); + +stat (s,CPUSLAB_FLUSH ); }/*
@@ -2755,7 +2761,10 @@ deactivate_slab:local_irq_restore (flags); goto reread_page; } -deactivate_slab (s, page, c->freelist, c); + freelist = c->freelist; + c->page =NULL ; + c->freelist =NULL ; +deactivate_slab (s, page, freelist);local_irq_restore (flags); new_slab:
@@ -2834,11 +2843,7 @@ check_new_page: return_single:local_irq_save (flags); -if (unlikely (c->page)) -flush_slab (s, c); - c->page = page; - -deactivate_slab (s, page,get_freepointer (s, freelist), c); +deactivate_slab (s, page,get_freepointer (s, freelist));local_irq_restore (flags);return freelist; }
_
Andrew Morton
maintainerPATCH 28/212 mm, slub: make locking in deactivate_slab() irq-safe
In reply to Andrew MortonFrom: Vlastimil Babka <[email protected]>
Subject: mm, slub: make locking in deactivate_slab() irq-safe
dectivate_slab() now no longer touches the kmem_cache_cpu structure, so it will be possible to call it with irqs enabled. Just convert the spin_lock calls to their irq saving/restoring variants to make it irq-safe.
Note we now have to use cmpxchg_double_slab() for irq-safe slab_lock(), because in some situations we don't take the list_lock, which would disable irqs.
---
mm/slub.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
mm/slub.c renamed from mm/slub.c~mm-slub-make-locking-in-deactivate_slab-irq-safe +5 -4
@@ -2209,6 +2209,7 @@ static void deactivate_slab(struct kmem_enum slab_modes l =M_NONE , m =M_NONE ;void *nextfree, *freelist_iter, *freelist_tail;int tail =DEACTIVATE_TO_HEAD ; +unsigned long flags =0 ;struct page new;struct page old;
@@ -2284,7 +2285,7 @@ redo:* that acquire_slab() will see a slab page that * is frozen */ -spin_lock (&n->list_lock); +spin_lock_irqsave (&n->list_lock, flags); } }else { m =M_FULL ;
@@ -2295,7 +2296,7 @@ redo:* slabs from diagnostic functions will not see * any frozen slabs. */ -spin_lock (&n->list_lock); +spin_lock_irqsave (&n->list_lock, flags); } }
@@ -2312,14 +2313,14 @@ redo: } l = m; -if (!__cmpxchg_double_slab (s, page, +if (!cmpxchg_double_slab (s, page, old.freelist, old.counters, new.freelist, new.counters,"unfreezing slab" )) goto redo;if (lock) -spin_unlock (&n->list_lock); +spin_unlock_irqrestore (&n->list_lock, flags);if (m ==M_PARTIAL )stat (s, tail);
_
Andrew Morton
maintainerPATCH 29/212 mm, slub: call deactivate_slab() without disabling irqs
In reply to Andrew MortonFrom: Vlastimil Babka <[email protected]>
Subject: mm, slub: call deactivate_slab() without disabling irqs
The function is now safe to be called with irqs enabled, so move the calls outside of irq disabled sections.
When called from ___slab_alloc() -> flush_slab() we have irqs disabled, so to reenable them before deactivate_slab() we need to open-code flush_slab() in ___slab_alloc() and reenable irqs after modifying the kmem_cache_cpu fields. But that means a IRQ handler meanwhile might have assigned a new page to kmem_cache_cpu.page so we have to retry the whole check.
The remaining callers of flush_slab() are the IPI handler which has disabled irqs anyway, and slub_cpu_dead() which will be dealt with in the following patch.
---
mm/slub.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-)
mm/slub.c renamed from mm/slub.c~mm-slub-call-deactivate_slab-without-disabling-irqs +19 -5
@@ -2765,8 +2765,8 @@ deactivate_slab: freelist = c->freelist; c->page =NULL ; c->freelist =NULL ; -deactivate_slab (s, page, freelist);local_irq_restore (flags); +deactivate_slab (s, page, freelist); new_slab:
@@ -2834,18 +2834,32 @@ check_new_page:*/ goto return_single; +retry_load_page: +local_irq_save (flags); -if (unlikely (c->page)) -flush_slab (s, c); +if (unlikely (c->page)) { +void *flush_freelist = c->freelist; +struct page *flush_page = c->page; + + c->page =NULL ; + c->freelist =NULL ; + c->tid =next_tid (c->tid); + +local_irq_restore (flags); + +deactivate_slab (s, flush_page, flush_freelist); + +stat (s,CPUSLAB_FLUSH ); + + goto retry_load_page; + } c->page = page; goto load_freelist; return_single: -local_irq_save (flags);deactivate_slab (s, page,get_freepointer (s, freelist)); -local_irq_restore (flags);return freelist; }
_
Andrew Morton
maintainerPATCH 30/212 mm, slub: move irq control into unfreeze_partials()
In reply to Andrew MortonFrom: Vlastimil Babka <[email protected]>
Subject: mm, slub: move irq control into unfreeze_partials()
unfreeze_partials() can be optimized so that it doesn't need irqs disabled for the whole time. As the first step, move irq control into the function and remove it from the put_cpu_partial() caller.
---
mm/slub.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
mm/slub.c renamed from mm/slub.c~mm-slub-move-irq-control-into-unfreeze_partials +7 -6
@@ -2336,9 +2336,8 @@ redo:/* * Unfreeze all the cpu partial slabs. * -* This function must be called with interrupts disabled -* for the cpu using c (or some other guarantee must be there -* to guarantee no concurrent accesses). +* This function must be called with preemption or migration +* disabled with c local to the cpu. */ static void unfreeze_partials (struct kmem_cache *s,struct kmem_cache_cpu *c)
@@ -2346,6 +2345,9 @@ static void unfreeze_partials(struct kme#ifdef CONFIG_SLUB_CPU_PARTIAL struct kmem_cache_node *n =NULL , *n2 =NULL ;struct page *page, *discard_page =NULL ; +unsigned long flags; + +local_irq_save (flags);while ((page =slub_percpu_partial (c))) {struct page new;
@@ -2398,6 +2400,8 @@ static void unfreeze_partials(struct kmediscard_slab (s, page); stat(s, FREE_SLAB); } + +local_irq_restore (flags);#endif /* CONFIG_SLUB_CPU_PARTIAL */ }
@@ -2425,14 +2429,11 @@ static void put_cpu_partial(struct kmem_ pobjects = oldpage->pobjects; pages = oldpage->pages;if (drain && pobjects >slub_cpu_partial (s)) { -unsigned long flags;/* * partial array is full. Move the existing * set to the per node partial list. */ -local_irq_save (flags);unfreeze_partials (s,this_cpu_ptr (s->cpu_slab)); -local_irq_restore (flags); oldpage =NULL ; pobjects =0 ; pages =0 ;
_
Andrew Morton
maintainerPATCH 31/212 mm, slub: discard slabs in unfreeze_partials() without irqs disabled
In reply to Andrew MortonFrom: Vlastimil Babka <[email protected]>
Subject: mm, slub: discard slabs in unfreeze_partials() without irqs disabled
No need for disabled irqs when discarding slabs, so restore them before discarding.
---
mm/slub.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
mm/slub.c renamed from mm/slub.c~mm-slub-discard-slabs-in-unfreeze_partials-without-irqs-disabled +2 -1
@@ -2392,6 +2392,8 @@ static void unfreeze_partials(struct kmeif (n)spin_unlock (&n->list_lock); +local_irq_restore (flags); +while (discard_page) { page = discard_page; discard_page = discard_page->next;
@@ -2401,7 +2403,6 @@ static void unfreeze_partials(struct kme stat(s, FREE_SLAB); } -local_irq_restore (flags);#endif /* CONFIG_SLUB_CPU_PARTIAL */ }
_
Andrew Morton
maintainerPATCH 32/212 mm, slub: detach whole partial list at once in unfreeze_partials()
In reply to Andrew MortonFrom: Vlastimil Babka <[email protected]>
Subject: mm, slub: detach whole partial list at once in unfreeze_partials()
Instead of iterating through the live percpu partial list, detach it from the kmem_cache_cpu at once. This is simpler and will allow further optimization.
---
mm/slub.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
mm/slub.c renamed from mm/slub.c~mm-slub-detach-whole-partial-list-at-once-in-unfreeze_partials +7 -3
@@ -2344,16 +2344,20 @@ static void unfreeze_partials(struct kme {#ifdef CONFIG_SLUB_CPU_PARTIAL struct kmem_cache_node *n =NULL , *n2 =NULL ; -struct page *page, *discard_page =NULL ; +struct page *page, *partial_page, *discard_page =NULL ;unsigned long flags;local_irq_save (flags); -while ((page =slub_percpu_partial (c))) { + partial_page =slub_percpu_partial (c); + c->partial =NULL ; + +while (partial_page) {struct page new;struct page old; -slub_set_percpu_partial (c, page); + page = partial_page; + partial_page = page->next; n2 =get_node (s,page_to_nid (page));if (n != n2) {
_
Andrew Morton
maintainerPATCH 33/212 mm, slub: separate detaching of partial list in unfreeze_partials() from unfreezing
In reply to Andrew MortonFrom: Vlastimil Babka <[email protected]>
Subject: mm, slub: separate detaching of partial list in unfreeze_partials() from unfreezing
Unfreezing partial list can be split to two phases - detaching the list from struct kmem_cache_cpu, and processing the list. The whole operation does not need to be protected by disabled irqs. Restructure the code to separate the detaching (with disabled irqs) and unfreezing (with irq disabling to be reduced in the next patch).
Also, unfreeze_partials() can be called from another cpu on behalf of a cpu that is being offlined, where disabling irqs on the local cpu has no sense, so restructure the code as follows:
- __unfreeze_partials() is the bulk of unfreeze_partials() that processes the detached percpu partial list
- unfreeze_partials() detaches list from current cpu with irqs disabled and calls __unfreeze_partials()
- unfreeze_partials_cpu() is to be called for the offlined cpu so it needs no irq disabling, and is called from __flush_cpu_slab()
- flush_cpu_slab() is for the local cpu thus it needs to call unfreeze_partials(). So it can't simply call __flush_cpu_slab(smp_processor_id()) anymore and we have to open-code the proper calls.
---
mm/slub.c | 73 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 51 insertions(+), 22 deletions(-)
mm/slub.c renamed from mm/slub.c~mm-slub-separate-detaching-of-partial-list-in-unfreeze_partials-from-unfreezing +51 -22
@@ -2333,25 +2333,15 @@ redo: } } -/* -* Unfreeze all the cpu partial slabs. -* -* This function must be called with preemption or migration -* disabled with c local to the cpu. -*/ -static void unfreeze_partials (struct kmem_cache *s, -struct kmem_cache_cpu *c) -{#ifdef CONFIG_SLUB_CPU_PARTIAL +static void __unfreeze_partials (struct kmem_cache *s,struct page *partial_page) +{struct kmem_cache_node *n =NULL , *n2 =NULL ; -struct page *page, *partial_page, *discard_page =NULL ; +struct page *page, *discard_page =NULL ;unsigned long flags;local_irq_save (flags); - partial_page =slub_percpu_partial (c); - c->partial =NULL ; -while (partial_page) {struct page new;struct page old;
@@ -2406,10 +2396,45 @@ static void unfreeze_partials(struct kmediscard_slab (s, page); stat(s, FREE_SLAB); } +} -#endif /* CONFIG_SLUB_CPU_PARTIAL */ +/* +* Unfreeze all the cpu partial slabs. +*/ +static void unfreeze_partials (struct kmem_cache *s) +{ +struct page *partial_page; +unsigned long flags; + +local_irq_save (flags); + partial_page =this_cpu_read (s->cpu_slab->partial); +this_cpu_write (s->cpu_slab->partial,NULL ); +local_irq_restore (flags); + +if (partial_page) +__unfreeze_partials (s, partial_page); +} + +static void unfreeze_partials_cpu (struct kmem_cache *s, +struct kmem_cache_cpu *c) +{ +struct page *partial_page; + + partial_page =slub_percpu_partial (c); + c->partial =NULL ; + +if (partial_page) +__unfreeze_partials (s, partial_page); } +#else /* CONFIG_SLUB_CPU_PARTIAL */ + +static inline void unfreeze_partials (struct kmem_cache *s) { } +static inline void unfreeze_partials_cpu (struct kmem_cache *s, +struct kmem_cache_cpu *c) { } + +#endif /* CONFIG_SLUB_CPU_PARTIAL */ +/* * Put a page that was just frozen (in __slab_free|get_partial_node) into a * partial page slot if available.
@@ -2438,7 +2463,7 @@ static void put_cpu_partial(struct kmem_* partial array is full. Move the existing * set to the per node partial list. */ -unfreeze_partials (s,this_cpu_ptr (s->cpu_slab)); +unfreeze_partials (s); oldpage =NULL ; pobjects =0 ; pages =0 ;
@@ -2473,11 +2498,6 @@ static inline void flush_slab(struct kmestat (s,CPUSLAB_FLUSH ); } -/* -* Flush cpu slab. -* -* Called from IPI handler with interrupts disabled. -*/ static inline void __flush_cpu_slab (struct kmem_cache *s,int cpu) {struct kmem_cache_cpu *c =per_cpu_ptr (s->cpu_slab, cpu);
@@ -2485,14 +2505,23 @@ static inline void __flush_cpu_slab(struif (c->page)flush_slab (s, c); -unfreeze_partials (s, c); +unfreeze_partials_cpu (s, c); } +/* +* Flush cpu slab. +* +* Called from IPI handler with interrupts disabled. +*/ static void flush_cpu_slab (void *d) {struct kmem_cache *s = d; +struct kmem_cache_cpu *c =this_cpu_ptr (s->cpu_slab); + +if (c->page) +flush_slab (s, c); -__flush_cpu_slab (s,smp_processor_id ()); +unfreeze_partials (s); }static bool has_cpu_slab (int cpu,void *info)
_
Andrew Morton
maintainerPATCH 34/212 mm, slub: only disable irq with spin_lock in __unfreeze_partials()
In reply to Andrew MortonFrom: Vlastimil Babka <[email protected]>
Subject: mm, slub: only disable irq with spin_lock in __unfreeze_partials()
__unfreeze_partials() no longer needs to have irqs disabled, except for making the spin_lock operations irq-safe, so convert the spin_locks operations and remove the separate irq handling.
---
mm/slub.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
mm/slub.c renamed from mm/slub.c~mm-slub-only-disable-irq-with-spin_lock-in-__unfreeze_partials +4 -8
@@ -2338,9 +2338,7 @@ static void __unfreeze_partials(struct k {struct kmem_cache_node *n =NULL , *n2 =NULL ;struct page *page, *discard_page =NULL ; -unsigned long flags; - -local_irq_save (flags); +unsigned long flags =0 ;while (partial_page) {struct page new;
@@ -2352,10 +2350,10 @@ static void __unfreeze_partials(struct k n2 =get_node (s,page_to_nid (page));if (n != n2) {if (n) -spin_unlock (&n->list_lock); +spin_unlock_irqrestore (&n->list_lock, flags); n = n2; -spin_lock (&n->list_lock); +spin_lock_irqsave (&n->list_lock, flags); } do {
@@ -2384,9 +2382,7 @@ static void __unfreeze_partials(struct k }if (n) -spin_unlock (&n->list_lock); - -local_irq_restore (flags); +spin_unlock_irqrestore (&n->list_lock, flags);while (discard_page) { page = discard_page;
_
Andrew Morton
maintainerPATCH 35/212 mm, slub: don't disable irqs in slub_cpu_dead()
In reply to Andrew MortonFrom: Vlastimil Babka <[email protected]>
Subject: mm, slub: don't disable irqs in slub_cpu_dead()
slub_cpu_dead() cleans up for an offlined cpu from another cpu and calls only functions that are now irq safe, so we don't need to disable irqs anymore.
---
mm/slub.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
mm/slub.c renamed from mm/slub.c~mm-slub-dont-disable-irqs-in-slub_cpu_dead +1 -5
@@ -2540,14 +2540,10 @@ static void flush_all(struct kmem_cachestatic int slub_cpu_dead (unsigned int cpu) {struct kmem_cache *s; -unsigned long flags;mutex_lock (&slab_mutex); -list_for_each_entry (s, &slab_caches, list) { -local_irq_save (flags); +list_for_each_entry (s, &slab_caches, list)__flush_cpu_slab (s, cpu); -local_irq_restore (flags); - }mutex_unlock (&slab_mutex);return 0 ; }
_
Andrew Morton
maintainerPATCH 36/212 mm, slab: make flush_slab() possible to call with irqs enabled
In reply to Andrew MortonFrom: Vlastimil Babka <[email protected]>
Subject: mm, slab: make flush_slab() possible to call with irqs enabled
Currently flush_slab() is always called with disabled IRQs if it's needed, but the following patches will change that, so add a parameter to control IRQ disabling within the function, which only protects the kmem_cache_cpu manipulation and not the call to deactivate_slab() which doesn't need it.
---
mm/slub.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-)
mm/slub.c renamed from mm/slub.c~mm-slab-make-flush_slab-possible-to-call-with-irqs-enabled +18 -6
@@ -2480,16 +2480,28 @@ static void put_cpu_partial(struct kmem_#endif /* CONFIG_SLUB_CPU_PARTIAL */ } -static inline void flush_slab (struct kmem_cache *s,struct kmem_cache_cpu *c) +static inline void flush_slab (struct kmem_cache *s,struct kmem_cache_cpu *c, +bool lock) { -void *freelist = c->freelist; -struct page *page = c->page; +unsigned long flags; +void *freelist; +struct page *page; + +if (lock) +local_irq_save (flags); + + freelist = c->freelist; + page = c->page; c->page =NULL ; c->freelist =NULL ; c->tid =next_tid (c->tid); -deactivate_slab (s, page, freelist); +if (lock) +local_irq_restore (flags); + +if (page) +deactivate_slab (s, page, freelist);stat (s,CPUSLAB_FLUSH ); }
@@ -2499,7 +2511,7 @@ static inline void __flush_cpu_slab(strustruct kmem_cache_cpu *c =per_cpu_ptr (s->cpu_slab, cpu);if (c->page) -flush_slab (s, c); +flush_slab (s, c, false);unfreeze_partials_cpu (s, c); }
@@ -2515,7 +2527,7 @@ static void flush_cpu_slab(void *d)struct kmem_cache_cpu *c =this_cpu_ptr (s->cpu_slab);if (c->page) -flush_slab (s, c); +flush_slab (s, c, false);unfreeze_partials (s); }
_
Re: [patch 036/212] mm, slab: make flush_slab() possible to call with irqs enabled
Quoted 8 lines · Andrew Morton
From: Vlastimil Babka <[email protected]>
Subject: mm, slab: makeflush_slab()possible to call with irqs enabledCurrently
flush_slab()is always called with disabled IRQs if it's needed, but the following patches will change that, so add a parameter to control IRQ disabling within the function, which only protects thekmem_cache_cpumanipulation and not the call todeactivate_slab()which doesn't need it.
I absolutely DETEST this patch.
Code like this is just garbage:
Quoted 3 lines
mm/slub.c renamed from mm/slub.c~mm-slab-make-flush_slab-possible-to-call-with-irqs-enabled +2
-1-static inline void flush_slab (struct kmem_cache *s,struct kmem_cache_cpu *c) +static inline void flush_slab (struct kmem_cache *s,struct kmem_cache_cpu *c, +bool lock)
....
mm/slub.c static void put_cpu_partial(struct kmem_ · line 2491
Quoted 2 lines
mm/slub.c renamed from mm/slub.c~mm-slab-make-flush_slab-possible-to-call-with-irqs-enabled +2
-0+if (lock) +local_irq_save (flags);
with actively misleading names ("lock"? WTF? There's no lock there!) and just disgusting semantics with conditionals etc.
And the thing is, I don't even see that this would be in the least required.
If that function had just been split into two: the first part that needed to absolutely be called with interrupts disabled, and the latter part that didn't, then none of this stupid ugly code would be needed at all.
So flush_slab() could have been split into "that first part that returned the freelist and page, and then the second part that did the deactivate_slab() and the stats update.
Then somebody who had interrupts disabled anyway (ie existing cases) would just do both.
And then the new code that you want to have with interrupts disabled just for the first part would do the first part with interrupts disabled, and the second part without.
See? No need for a "flags" field and odd conditional interrupt disables.
And yes, I realize that the "inline" means that *most* of the time, the compiler will inline things, the "conditional" will become static, and it will not be a run-time conditional.
But it's the human-readable conditional that is the ugly part here. Now any sane human that reads that flush_slab() code will see "oh, sometimes interrupts are disabled, and sometimes they aren't".
Because that is what the code does, at that level.
But no, what's actually going on is that interrupts are *always* disabled - it's just that sometimes they will have already been disabled in the caller. So all that misleading and misnamed "lock" argument does is really "were interrupts already disabled so that I don't need to disable and re-enable them".
That's what the code actually *does*, but it's not how the code reads, and it's not how the code is written, or how the argument in question is named.
So it's all very misleading, and ugly.
I'm going to sleep on this, and maybe tomorrow morning my reaction will be "whatever, the code probably works".
But more likely, tomorrow morning I will take another look, and still say "no, this is actually making the code less maintainable and actively misleading", and just throw the whole slab series out the window.
Linus
Re: [patch 036/212] mm, slab: make flush_slab() possible to call with irqs enabled
Quoted 7 lines · Linus Torvalds
....
mm/slub.c static void put_cpu_partial(struct kmem_ · line 2491
Quoted 2 lines
mm/slub.c renamed from mm/slub.c~mm-slab-make-flush_slab-possible-to-call-with-irqs-enabled +2
-0+if (lock) +local_irq_save (flags);with actively misleading names ("lock"? WTF? There's no lock there!) and just disgusting semantics with conditionals etc.
.. and I see that "mm, slub: convert kmem_cpu_slab protection to local_lock" makes that local_irq_save() make it use a local_lock, which may have been the cause of the naming.
But that doesn't make my other objections about this go away.
Instead of having it lock/unlock halfway through the function (and have magic "Oh, the caller already holds the lock, so don't lock" semantics except with misleading names) I really think that function should just have been split in two, and then the locked region can be minimized in the caller only taking it for the first part.
Linus
Re: [patch 036/212] mm, slab: make flush_slab() possible to call with irqs enabled
[ Talking to myself while mulling this series over ... ]
Quoted 6 lines · Linus Torvalds
Instead of having it lock/unlock halfway through the function (and have magic "Oh, the caller already holds the lock, so don't lock" semantics except with misleading names) I really think that function should just have been split in two, and then the locked region can be minimized in the caller only taking it for the first part.
If there's some reason why it can't sanely be split into two (too many common variables or some odd control flow or whatever), at least the locking logic should be changed from
if (lock)
local_irq_save(flags);to something along the lines of
if (!caller_already_locked)
local_irq_save(flags);so that when you read that function on its own, it's clear that the lock is always held over that critical section - and the issue is that perhaps the lock was already taken by the caller.
This ignores the whole misleading "lock" name when it isn't even yet a lock.
Linus
Re: [patch 036/212] mm, slab: make flush_slab() possible to call with irqs enabled
Quoted 10 lines · Linus Torvalds
[ Talking to myself while mulling this series over ... ]
Quoted 6 lines · Linus Torvalds
Instead of having it lock/unlock halfway through the function (and have magic "Oh, the caller already holds the lock, so don't lock" semantics except with misleading names) I really think that function should just have been split in two, and then the locked region can be minimized in the caller only taking it for the first part.
Normally I would have done that, similarly to " [patch 033/212] mm,
slub: separate detaching of partial list in unfreeze_partials() from unfreezing"
Quoted 3 lines
If there's some reason why it can't sanely be split into two (too many common variables or some odd control flow or whatever), at least the locking logic should be changed from
I think what discouraged me was that the second part is to call deactivate_slab() and to that we need to return two values from the first part (page and freelist), so one of them has to be a return parameter. On the other hand the second part does so little it can be opencoded. See below.
Quoted 4 lines
if (lock)
local_irq_save(flags);Quoted 8 lines
to something along the lines of
if (!caller_already_locked) local_irq_save(flags);so that when you read that function on its own, it's clear that the lock is always held over that critical section - and the issue is that perhaps the lock was already taken by the caller.
Actually that "already taken" becomes "caller does not need it/can't even take the local lock as it's not local" (it's a cpu hot remove handler on behalf of another, dead cpu).
So would it work with something like the following cleanup on top later after proper testing? (now just compile tested).
---8<---
mm/slub.c +24 -19
@@ -2566,38 +2566,33 @@ static inline void unfreeze_partials_cpu(struct kmem_cache *s,#endif /* CONFIG_SLUB_CPU_PARTIAL */ -static inline void flush_slab (struct kmem_cache *s,struct kmem_cache_cpu *c, -bool lock) +static inline struct page * +__detach_cpu_slab (struct kmem_cache *s,struct kmem_cache_cpu *c, +void **freelist) { -unsigned long flags; -void *freelist;struct page *page; -if (lock) -local_lock_irqsave (&s->cpu_slab->lock, flags); - - freelist = c->freelist; page = c->page; + *freelist = c->freelist; c->page =NULL ; c->freelist =NULL ; c->tid =next_tid (c->tid); -if (lock) -local_unlock_irqrestore (&s->cpu_slab->lock, flags); - -if (page) -deactivate_slab (s, page, freelist); - -stat (s,CPUSLAB_FLUSH ); +return page; }static inline void __flush_cpu_slab (struct kmem_cache *s,int cpu) {struct kmem_cache_cpu *c =per_cpu_ptr (s->cpu_slab, cpu); +struct page *page; +void *freelist; -if (c->page) -flush_slab (s, c, false); +if (c->page) { + page =__detach_cpu_slab (s, c, &freelist); +deactivate_slab (s, page, freelist); +stat (s,CPUSLAB_FLUSH ); + }unfreeze_partials_cpu (s, c); }
@@ -2618,14 +2613,24 @@ static void flush_cpu_slab(struct work_struct *w)struct kmem_cache *s;struct kmem_cache_cpu *c;struct slub_flush_work *sfw; +struct page *page; +void *freelist; +unsigned long flags; sfw = container_of(w, struct slub_flush_work, work); s = sfw->s; c =this_cpu_ptr (s->cpu_slab); -if (c->page) -flush_slab (s, c, true); +if (c->page) { +local_lock_irqsave (&s->cpu_slab->lock, flags); + page =__detach_cpu_slab (s, c, &freelist); +local_unlock_irqrestore (&s->cpu_slab->lock, flags); + +if (page) +deactivate_slab (s, page, freelist); +stat (s,CPUSLAB_FLUSH ); + }unfreeze_partials (s); }
Re: [patch 036/212] mm, slab: make flush_slab() possible to call with irqs enabled
Quoted 10 lines
Quoted 3 lines
so that when you read that function on its own, it's clear that the lock is always held over that critical section - and the issue is that perhaps the lock was already taken by the caller.
Actually that "already taken" becomes "caller does not need it/can't even take the local lock as it's not local" (it's a cpu hot remove handler on behalf of another, dead cpu).
So would it work with something like the following cleanup on top later after proper testing? (now just compile tested).
Scroll downward...
Quoted 75 lines
---8<---
mm/slub.c +0
-0@@ -2566,38 +2566,33 @@ static inline void unfreeze_partials_cpu(struct kmem_cache *s,
#endif /*CONFIG_SLUB_CPU_PARTIAL*/mm/slub.c +3
-2-static inline void flush_slab (struct kmem_cache *s,struct kmem_cache_cpu *c, - bool lock) +static inline struct page * +__detach_cpu_slab (struct kmem_cache *s,struct kmem_cache_cpu *c, + void **freelist){
- unsigned long flags;
- void *freelist;
struct page *page;
- if (lock)
- local_lock_irqsave(&s->cpu_slab->lock, flags); -
- freelist =c->freelist;
page =c->page;
+ *freelist =c->freelist;
c->page = NULL;
c->freelist = NULL;
c->tid =next_tid(c->tid);
- if (lock)
- local_unlock_irqrestore(&s->cpu_slab->lock, flags);mm/slub.c +1
-5- - if (page) - deactivate_slab(s, page, freelist); - - stat(s, CPUSLAB_FLUSH); + return page;}
static inline void__flush_cpu_slab(struct kmem_cache *s, int cpu){
structkmem_cache_cpu*c =per_cpu_ptr(s->cpu_slab, cpu); + struct page *page;
+ void *freelist;
- if (c->page)
- flush_slab(s, c, false);
+ if (c->page) {
+ page =__detach_cpu_slab(s, c, &freelist); + deactivate_slab(s, page, freelist);
+ stat(s,CPUSLAB_FLUSH);
+ }
unfreeze_partials_cpu(s, c);
}mm/slub.c +3
-0@@ -2618,14 +2613,24 @@ static void flush_cpu_slab(struct work_struct *w) struct kmem_cache *s; struct kmem_cache_cpu *c; struct slub_flush_work *sfw; + struct page *page; + void *freelist; + unsigned long flags;
sfw =container_of(w, struct slub_flush_work, work);
s =sfw->s;
c =this_cpu_ptr(s->cpu_slab);
- if (c->page)
- flush_slab(s, c, true);
+ if (c->page) {
+ local_lock_irqsave(&s->cpu_slab->lock, flags); + page =__detach_cpu_slab(s, c, &freelist); + local_unlock_irqrestore(&s->cpu_slab->lock, flags);
Quoted 8 lines
+
+ if (page)
+ deactivate_slab(s, page, freelist); + stat(s,CPUSLAB_FLUSH);
+ }
unfreeze_partials(s);
}
To my eyeballs, below duplication of a couple lines of initialization needed by the lockless function is less icky than the double return.
--- mm/slub.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-)
mm/slub.c +14 -9
@@ -2566,15 +2566,13 @@ static inline void unfreeze_partials_cpu#endif /* CONFIG_SLUB_CPU_PARTIAL */ -static inline void flush_slab (struct kmem_cache *s,struct kmem_cache_cpu *c, -bool lock) +static inline void flush_slab (struct kmem_cache *s,struct kmem_cache_cpu *c) {unsigned long flags;void *freelist;struct page *page; -if (lock) -local_lock_irqsave (&s->cpu_slab->lock, flags); +local_lock_irqsave (&s->cpu_slab->lock, flags); freelist = c->freelist; page = c->page;
@@ -2583,8 +2581,7 @@ static inline void flush_slab(struct kme c->freelist =NULL ; c->tid =next_tid (c->tid); -if (lock) -local_unlock_irqrestore (&s->cpu_slab->lock, flags); +local_unlock_irqrestore (&s->cpu_slab->lock, flags);if (page)deactivate_slab (s, page, freelist);
@@ -2595,11 +2592,19 @@ static inline void flush_slab(struct kmestatic inline void __flush_cpu_slab (struct kmem_cache *s,int cpu) {struct kmem_cache_cpu *c =per_cpu_ptr (s->cpu_slab, cpu); +struct page *page = c->page; +void *freelist = c->freelist; -if (c->page) -flush_slab (s, c, false); + c->page =NULL ; + c->freelist =NULL ; + c->tid =next_tid (c->tid); + +if (page) +deactivate_slab (s, page, freelist);unfreeze_partials_cpu (s, c); + +stat (s,CPUSLAB_FLUSH ); }struct slub_flush_work {
@@ -2625,7 +2630,7 @@ static void flush_cpu_slab(struct work_s c =this_cpu_ptr (s->cpu_slab);if (c->page) -flush_slab (s, c, true); +flush_slab (s, c);unfreeze_partials (s); }
Re: [patch 036/212] mm, slab: make flush_slab() possible to call with irqs enabled
Quoted 5 lines · Mike Galbraith
Quoted 5 lines
Quoted 3 lines
so that when you read that function on its own, it's clear that the lock is always held over that critical section - and the issue is that perhaps the lock was already taken by the caller.
Actually that "already taken" becomes "caller does not need it/can't
Meant to say "... later in the series becomes ...".
Quoted 8 lines
Quoted 5 lines
even take the local lock as it's not local" (it's a cpu hot remove handler on behalf of another, dead cpu).
So would it work with something like the following cleanup on top later after proper testing? (now just compile tested).
To my eyeballs, below duplication of a couple lines of initialization needed by the lockless function is less icky than the double return.
Yeah, that's better, thanks Mike.
Re: [patch 036/212] mm, slab: make flush_slab() possible to call with irqs enabled
Quoted 12 lines · Vlastimil Babka
Quoted 5 lines · Mike Galbraith
Quoted 5 lines
Quoted 3 lines
so that when you read that function on its own, it's clear that the lock is always held over that critical section - and the issue is that perhaps the lock was already taken by the caller.
Actually that "already taken" becomes "caller does not need it/can't
Meant to say "... later in the series becomes ...".
Quoted 3 lines
Quoted 3 lines
even take the local lock as it's not local" (it's a cpu hot remove handler on behalf of another, dead cpu).
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
So would it work with something like the following cleanup on top later after proper testing? (now just compile tested).
To my eyeballs, below duplication of a couple lines of initialization needed by the lockless function is less icky than the double return.
Yeah, that's better, thanks Mike.
Formal patch below, also added to my git branch:
https://git.kernel.org/pub/scm/linux/kernel/git/vbabka/linux.git/log/?h=slub-local-lock-v5r1
----8<----
From b67952ce67528f3ebeaae58e0eae22a6dbae64b5 Mon Sep 17 00:00:00 2001
From: Vlastimil Babka <[email protected]>
Date: Fri, 3 Sep 2021 12:59:25 +0200
Subject: [PATCH] mm, slub: remove conditional locking parameter from
flush_slab()
flush_slab() is called either as part of work scheduled on given live cpu, or called as a cleanup for another cpu that went offline. In the first case it needs to hold the cpu_slab->lock local lock when updating the protected kmem_cache_cpu fields. This is now achieved by a "bool lock" parameter.
To avoid the conditional locking, we can instead lock unconditionally in flush_slab() for live cpus, and opencode the variant without locking in __flush_cpu_slab() for the dead cpus.
--- mm/slub.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-)
mm/slub.c +14 -9
@@ -2566,15 +2566,13 @@ static inline void unfreeze_partials_cpu(struct kmem_cache *s,#endif /* CONFIG_SLUB_CPU_PARTIAL */ -static inline void flush_slab (struct kmem_cache *s,struct kmem_cache_cpu *c, -bool lock) +static inline void flush_slab (struct kmem_cache *s,struct kmem_cache_cpu *c) {unsigned long flags;void *freelist;struct page *page; -if (lock) -local_lock_irqsave (&s->cpu_slab->lock, flags); +local_lock_irqsave (&s->cpu_slab->lock, flags); freelist = c->freelist; page = c->page;
@@ -2583,8 +2581,7 @@ static inline void flush_slab(struct kmem_cache *s, struct kmem_cache_cpu *c, c->freelist =NULL ; c->tid =next_tid (c->tid); -if (lock) -local_unlock_irqrestore (&s->cpu_slab->lock, flags); +local_unlock_irqrestore (&s->cpu_slab->lock, flags);if (page)deactivate_slab (s, page, freelist);
@@ -2595,9 +2592,17 @@ static inline void flush_slab(struct kmem_cache *s, struct kmem_cache_cpu *c,static inline void __flush_cpu_slab (struct kmem_cache *s,int cpu) {struct kmem_cache_cpu *c =per_cpu_ptr (s->cpu_slab, cpu); +struct page *page = c->page; +void *freelist = c->freelist; -if (c->page) -flush_slab (s, c, false); + c->page =NULL ; + c->freelist =NULL ; + c->tid =next_tid (c->tid); + +if (page) { +deactivate_slab (s, page, freelist); +stat (s,CPUSLAB_FLUSH ); + }unfreeze_partials_cpu (s, c); }
@@ -2625,7 +2630,7 @@ static void flush_cpu_slab(struct work_struct *w) c =this_cpu_ptr (s->cpu_slab);if (c->page) -flush_slab (s, c, true); +flush_slab (s, c);unfreeze_partials (s); }
Signature · 1 line
2.33.0
Re: [patch 036/212] mm, slab: make flush_slab() possible to call with irqs enabled
In reply to Mike GalbraithQuoted 3 lines · Mike Galbraith
To my eyeballs, below duplication of a couple lines of initialization needed by the lockless function is less icky than the double return.
Ack. Something like this seems to avoid the whole issue.
Vlastimil - the alternative I was actually going to suggest for that "double return value" thing is something we use elsewhere in the VM code - just use a structure for "state".
It's not hugely common, and I think Mike's solution in this case is the much simpler one, but I'll mention it anyway because it's actually been quite successful in the few cases we use it, and it's both readable to humans and generates fairly good code.
The "generates fairly good code" is generally more true when inlining, but it's not horrible even outside of that.
So the idea with the "state structure" is that you just pass in both the arguments and the return values in a struct.
Some examples of this are
- 'struct follow_page_context' in mm/gup.c is an example of a small local one.
- 'struct vm_fault' is an example of a *big* one, that has a lot of
state, and that is actually exported as an interface.
That 'struct vm_fault' one is interesting as an example because it does that "both inputs and outputs", and has that unnamed "const struct" member to actually catch mis-uses where some callee would change those fields (which is a no-no).
It's also an example of something that generates good code despite not inlining, because it actively makes argument passing simpler and avoids copying arguments as you call other functions.
Those issues are non-issues in this case, which is why I point to that 'follow_page_context' in the gup code as a very different example of this, which is much more along the lines of the slub case. It's purely local to that call chain, and it's basically used to return more state.
In both cases, the top-level caller just initializes things on the stack. For that 'struct vm_fault' case you actually *have* to use an initializer, since the constant fields cannot be changed later. It makes for pretty legible code, and when things are inlined, all those fields actually act exactly like just regular local variables shared across functions.
When things aren't inlined, it can generate extra memory accesses, but that 'struct vm_fault' is an example of when that isn't even necessarily worse.
Anyway, I wanted to just point that out as a pattern that has been quite successful.
Side note: one very special case of that pattern goes back decades:
the VM use of structures that get returned and passed *as* structures. It's in fact so common that people don't even think about it: 'pte_t' and friends. They are designed to be opaque data types that are often multi-word structures.
Quite often those structures have only one or two words in them, which helps code generation (returning two words can be done in registers), but they _can_ have more.
Eg x86:
typedef union {
struct {
unsigned long pte_low, pte_high;
};
pteval_t pte;
} pte_t;or some powerpc cases:
typedef struct { pte_basic_t pte, pte1, pte2, pte3; } pte_t;just to show that you can actually pass structures not by reference, but by value, and it's not even unusual in the kernel. That can also be used to return multiple values if you want to.
Note: code generation really matters, and when doing those multi-value structures, for code generation it's generally important to limit it to at most two words.
Anything more, and the compiler will generally be forced to pass it by copying it to the stack and using a pointer to it, and then you get the worst of both worlds. You're better off just passing the structure by reference, and avoiding extra copies on the stack.
ANYWAY.
I'll drop this part from Andrew's patch-bomb, and I can take it later in its cleaned-up form. You mentioned a git tree elsewhere, maybe even that way.
Linus
Andrew Morton
maintainerPATCH 37/212 mm: slub: move flush_cpu_slab() invocations __free_slab() invocations out of IRQ context
In reply to Andrew MortonFrom: Sebastian Andrzej Siewior <[email protected]>
Subject: mm: slub: move flush_cpu_slab() invocations __free_slab() invocations out of IRQ context
flush_all() flushes a specific SLAB cache on each CPU (where the cache is present). The deactivate_slab()/__free_slab() invocation happens within IPI handler and is problematic for PREEMPT_RT.
The flush operation is not a frequent operation or a hot path. The per-CPU flush operation can be moved to within a workqueue.
---
mm/slab_common.c | 2 + mm/slub.c | 79 +++++++++++++++++++++++++++++++++++++-------- 2 files changed, 68 insertions(+), 13 deletions(-)
mm/slab_common.c renamed from mm/slab_common.c~mm-slub-move-flush_cpu_slab-invocations-__free_slab-invocations-out-of-irq-context +2 -0
@@ -502,6 +502,7 @@ void kmem_cache_destroy(struct kmem_cachif (unlikely (!s))return ; +cpus_read_lock ();mutex_lock (&slab_mutex); s->refcount--;
@@ -516,6 +517,7 @@ void kmem_cache_destroy(struct kmem_cach } out_unlock:mutex_unlock (&slab_mutex); +cpus_read_unlock (); }EXPORT_SYMBOL (kmem_cache_destroy);
mm/slub.c renamed from mm/slub.c~mm-slub-move-flush_cpu_slab-invocations-__free_slab-invocations-out-of-irq-context +66 -13
133 lines not on this page · raw message
_
Andrew Morton
maintainerPATCH 38/212 mm: slub: make object_map_lock a raw_spinlock_t
In reply to Andrew MortonFrom: Sebastian Andrzej Siewior <[email protected]>
Subject: mm: slub: make object_map_lock a raw_spinlock_t
The variable object_map is protected by object_map_lock. The lock is always acquired in debug code and within already atomic context
Make object_map_lock a raw_spinlock_t.
---
mm/slub.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
mm/slub.c renamed from mm/slub.c~mm-slub-make-object_map_lock-a-raw_spinlock_t +3 -3
@@ -438,7 +438,7 @@ static inline bool cmpxchg_double_slab(s#ifdef CONFIG_SLUB_DEBUG static unsigned long object_map[BITS_TO_LONGS (MAX_OBJS_PER_PAGE )]; -static DEFINE_SPINLOCK (object_map_lock); +static DEFINE_RAW_SPINLOCK (object_map_lock);static void __fill_map (unsigned long *obj_map,struct kmem_cache *s,struct page *page)
@@ -483,7 +483,7 @@ static unsigned long *get_map(struct kme {VM_BUG_ON (!irqs_disabled ()); -spin_lock (&object_map_lock); +raw_spin_lock (&object_map_lock);__fill_map (object_map, s, page);
@@ -493,7 +493,7 @@ static unsigned long *get_map(struct kme static void put_map(unsigned long *map) __releases(&object_map_lock) {VM_BUG_ON (map != object_map); -spin_unlock (&object_map_lock); +raw_spin_unlock (&object_map_lock); }static inline unsigned int size_from_object (struct kmem_cache *s)
_
Andrew Morton
maintainerPATCH 39/212 mm, slub: optionally save/restore irqs in slab_[un]lock()/
In reply to Andrew MortonFrom: Vlastimil Babka <[email protected]>
Subject: mm, slub: optionally save/restore irqs in slab_[un]lock()/
For PREEMPT_RT we will need to disable irqs for this bit spinlock. As a preparation, add a flags parameter, and an internal version that takes additional bool parameter to control irq saving/restoring (the flags parameter is compile-time unused if the bool is a constant false).
Convert ___cmpxchg_double_slab(), which also comes with the same bool parameter, to use the internal version.
---
mm/slub.c | 52 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 19 deletions(-)
mm/slub.c renamed from mm/slub.c~mm-slub-optionally-save-restore-irqs-in-slab_lock +33 -19
@@ -359,16 +359,33 @@ static inline unsigned int oo_objects(st/* * Per slab locking using the pagelock */ -static __always_inline void slab_lock(struct page *page) +static __always_inline void +__slab_lock (struct page *page,unsigned long *flags,bool disable_irqs) {VM_BUG_ON_PAGE (PageTail (page), page); +if (disable_irqs) +local_irq_save (*flags);bit_spin_lock (PG_locked, &page->flags); } -static __always_inline void slab_unlock(struct page *page) +static __always_inline void +__slab_unlock (struct page *page,unsigned long *flags,bool disable_irqs) {VM_BUG_ON_PAGE (PageTail (page), page);__bit_spin_unlock (PG_locked, &page->flags); +if (disable_irqs) +local_irq_restore (*flags); +} + +static __always_inline void +slab_lock (struct page *page,unsigned long *flags) +{ +__slab_lock (page, flags, false); +} + +static __always_inline void slab_unlock(struct page *page, unsigned long *flags) +{ +__slab_unlock (page, flags, false); } static inline bool ___cmpxchg_double_slab(struct kmem_cache *s, struct page *page,
@@ -388,23 +405,18 @@ static inline bool ___cmpxchg_double_sla } else#endif { -unsigned long flags; +/* init to 0 to prevent spurious warnings */ +unsigned long flags =0 ; -if (disable_irqs) -local_irq_save (flags); -slab_lock (page); +__slab_lock (page, &flags, disable_irqs);if (page->freelist == freelist_old && page->counters == counters_old) { page->freelist = freelist_new; page->counters = counters_new; -slab_unlock (page); -if (disable_irqs) -local_irq_restore (flags); +__slab_unlock (page, &flags, disable_irqs);return true; } -slab_unlock (page); -if (disable_irqs) -local_irq_restore (flags); +__slab_unlock (page, &flags, disable_irqs); }cpu_relax ();
@@ -1255,11 +1267,11 @@ static noinline int free_debug_processinstruct kmem_cache_node *n =get_node (s,page_to_nid (page));void *object = head;int cnt =0 ; -unsigned long flags; +unsigned long flags, flags2;int ret =0 ;spin_lock_irqsave (&n->list_lock, flags); -slab_lock (page); +slab_lock (page, &flags2);if (s->flags &SLAB_CONSISTENCY_CHECKS ) {if (!check_slab (s, page))
@@ -1292,7 +1304,7 @@ out:slab_err (s, page,"Bulk freelist count(%d) invalid(%d)\n" , bulk_cnt, cnt); -slab_unlock (page); +slab_unlock (page, &flags2);spin_unlock_irqrestore (&n->list_lock, flags);if (!ret)slab_fix (s,"Object at 0x%p not freed" , object);
@@ -4070,9 +4082,10 @@ static void list_slab_objects(struct kmevoid *addr =page_address (page);unsigned long *map;void *p; +unsigned long flags;slab_err (s, page, text, s->name); -slab_lock (page); +slab_lock (page, &flags); map =get_map (s, page);for_each_object (p, s, addr, page->objects) {
@@ -4083,7 +4096,7 @@ static void list_slab_objects(struct kme } }put_map (map); -slab_unlock (page); +slab_unlock (page, &flags);#endif }
@@ -4815,8 +4828,9 @@ static void validate_slab(struct kmem_ca {void *p;void *addr =page_address (page); +unsigned long flags; -slab_lock (page); +slab_lock (page, &flags);if (!check_slab (s, page) || !on_freelist (s, page,NULL )) goto unlock;
@@ -4831,7 +4845,7 @@ static void validate_slab(struct kmem_cabreak ; } unlock: -slab_unlock (page); +slab_unlock (page, &flags); } static int validate_slab_node(struct kmem_cache *s,
_
Andrew Morton
maintainerPATCH 40/212 mm, slub: make slab_lock() disable irqs with PREEMPT_RT
In reply to Andrew MortonFrom: Vlastimil Babka <[email protected]>
Subject: mm, slub: make slab_lock() disable irqs with PREEMPT_RT
We need to disable irqs around slab_lock() (a bit spinlock) to make it irq-safe. The calls to slab_lock() are nested under spin_lock_irqsave() which doesn't disable irqs on PREEMPT_RT, so add explicit disabling with PREEMPT_RT.
We also distinguish cmpxchg_double_slab() where we do the disabling explicitly and __cmpxchg_double_slab() for contexts with already disabled irqs. However these context are also typically spin_lock_irqsave() thus insufficient on PREEMPT_RT. Thus, change __cmpxchg_double_slab() to be same as cmpxchg_double_slab() on PREEMPT_RT.
---
mm/slub.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
mm/slub.c renamed from mm/slub.c~mm-slub-make-slab_lock-disable-irqs-with-preempt_rt +9 -4
@@ -380,12 +380,12 @@ __slab_unlock(struct page *page, unsigne static __always_inline voidslab_lock (struct page *page,unsigned long *flags) { -__slab_lock (page, flags, false); +__slab_lock (page, flags,IS_ENABLED (CONFIG_PREEMPT_RT )); } static __always_inline void slab_unlock(struct page *page, unsigned long *flags) { -__slab_unlock (page, flags, false); +__slab_unlock (page, flags,IS_ENABLED (CONFIG_PREEMPT_RT )); } static inline bool ___cmpxchg_double_slab(struct kmem_cache *s, struct page *page,
@@ -429,14 +429,19 @@ static inline bool ___cmpxchg_double_slareturn false; } -/* Interrupts must be disabled (for the fallback code to work right) */ +/* +* Interrupts must be disabled (for the fallback code to work right), typically +* by an _irqsave() lock variant. Except on PREEMPT_RT where locks are different +* so we disable interrupts explicitly here. +*/ static inline bool __cmpxchg_double_slab (struct kmem_cache *s,struct page *page,void *freelist_old,unsigned long counters_old,void *freelist_new,unsigned long counters_new,const char *n) {return ___cmpxchg_double_slab (s, page, freelist_old, counters_old, - freelist_new, counters_new, n, false); + freelist_new, counters_new, n, +IS_ENABLED (CONFIG_PREEMPT_RT )); } static inline bool cmpxchg_double_slab(struct kmem_cache *s, struct page *page,
_
Andrew Morton
maintainerPATCH 41/212 mm, slub: protect put_cpu_partial() with disabled irqs instead of cmpxchg
In reply to Andrew MortonFrom: Vlastimil Babka <[email protected]>
Subject: mm, slub: protect put_cpu_partial() with disabled irqs instead of cmpxchg
Jann Horn reported [1] the following theoretically possible race:
task A: put_cpu_partial() calls preempt_disable()
task A: oldpage = this_cpu_read(s->cpu_slab->partial)
interrupt: kfree() reaches unfreeze_partials() and discards the page task B (on another CPU): reallocates page as page cache
task A: reads page->pages and page->pobjects, which are actually halves of the pointer page->lru.prev
task B (on another CPU): frees page
interrupt: allocates page as SLUB page and places it on the percpu partial list task A: this_cpu_cmpxchg() succeeds
which would cause page->pages and page->pobjects to end up containing halves of pointers that would then influence when put_cpu_partial() happens and show up in root-only sysfs files. Maybe that's acceptable, I don't know. But there should probably at least be a comment for now to point out that we're reading union fields of a page that might be in a completely different state.
Additionally, the this_cpu_cmpxchg() approach in put_cpu_partial() is only safe against s->cpu_slab->partial manipulation in ___slab_alloc() if the latter disables irqs, otherwise a __slab_free() in an irq handler could call put_cpu_partial() in the middle of ___slab_alloc() manipulating ->partial and corrupt it. This becomes an issue on RT after a local_lock is introduced in later patch. The fix means taking the local_lock also in put_cpu_partial() on RT.
After debugging this issue, Mike Galbraith suggested [2] that to avoid different locking schemes on RT and !RT, we can just protect put_cpu_partial() with disabled irqs (to be converted to local_lock_irqsave() later) everywhere. This should be acceptable as it's not a fast path, and moving the actual partial unfreezing outside of the irq disabled section makes it short, and with the retry loop gone the code can be also simplified. In addition, the race reported by Jann should no longer be possible.
[1] https://lore.kernel.org/lkml/CAG48ez1mvUuXwg0YPH5ANzhQLpbphqk-ZS+jbRz+H66fvm4FcA@mail.gmail.com/
[2] https://lore.kernel.org/linux-rt-users/[email protected]/
---
mm/slub.c | 83 ++++++++++++++++++++++++++++------------------------ 1 file changed, 45 insertions(+), 38 deletions(-)
mm/slub.c renamed from mm/slub.c~mm-slub-protect-put_cpu_partial-with-disabled-irqs-instead-of-cmpxchg +45 -38
@@ -2006,7 +2006,12 @@ static inline void *acquire_slab(structreturn freelist; } +#ifdef CONFIG_SLUB_CPU_PARTIAL static void put_cpu_partial (struct kmem_cache *s,struct page *page,int drain); +#else +static inline void put_cpu_partial (struct kmem_cache *s,struct page *page, +int drain) { } +#endif static inline bool pfmemalloc_match (struct page *page,gfp_t gfpflags);/*
@@ -2440,14 +2445,6 @@ static void unfreeze_partials_cpu(struct__unfreeze_partials (s, partial_page); } -#else /* CONFIG_SLUB_CPU_PARTIAL */ - -static inline void unfreeze_partials (struct kmem_cache *s) { } -static inline void unfreeze_partials_cpu (struct kmem_cache *s, -struct kmem_cache_cpu *c) { } - -#endif /* CONFIG_SLUB_CPU_PARTIAL */ -/* * Put a page that was just frozen (in __slab_free|get_partial_node) into a * partial page slot if available.
@@ -2457,46 +2454,56 @@ static inline void unfreeze_partials_cpu*/ static void put_cpu_partial (struct kmem_cache *s,struct page *page,int drain) { -#ifdef CONFIG_SLUB_CPU_PARTIAL struct page *oldpage; -int pages; -int pobjects; +struct page *page_to_unfreeze =NULL ; +unsigned long flags; +int pages =0 ; +int pobjects =0 ; -preempt_disable (); -do { - pages =0 ; - pobjects =0 ; - oldpage =this_cpu_read (s->cpu_slab->partial); +local_irq_save (flags); + + oldpage =this_cpu_read (s->cpu_slab->partial); -if (oldpage) { +if (oldpage) { +if (drain && oldpage->pobjects >slub_cpu_partial (s)) { +/* +* Partial array is full. Move the existing set to the +* per node partial list. Postpone the actual unfreezing +* outside of the critical section. +*/ + page_to_unfreeze = oldpage; + oldpage =NULL ; + }else { pobjects = oldpage->pobjects; pages = oldpage->pages; -if (drain && pobjects >slub_cpu_partial (s)) { -/* -* partial array is full. Move the existing -* set to the per node partial list. -*/ -unfreeze_partials (s); - oldpage =NULL ; - pobjects =0 ; - pages =0 ; -stat (s,CPU_PARTIAL_DRAIN ); - } } + } - pages++; - pobjects += page->objects - page->inuse; + pages++; + pobjects += page->objects - page->inuse; - page->pages = pages; - page->pobjects = pobjects; - page->next = oldpage; - - }while (this_cpu_cmpxchg (s->cpu_slab->partial, oldpage, page) - != oldpage); -preempt_enable (); -#endif /* CONFIG_SLUB_CPU_PARTIAL */ + page->pages = pages; + page->pobjects = pobjects; + page->next = oldpage; + +this_cpu_write (s->cpu_slab->partial, page); + +local_irq_restore (flags); + +if (page_to_unfreeze) { +__unfreeze_partials (s, page_to_unfreeze); +stat (s,CPU_PARTIAL_DRAIN ); + } } +#else /* CONFIG_SLUB_CPU_PARTIAL */ + +static inline void unfreeze_partials (struct kmem_cache *s) { } +static inline void unfreeze_partials_cpu (struct kmem_cache *s, +struct kmem_cache_cpu *c) { } + +#endif /* CONFIG_SLUB_CPU_PARTIAL */ +static inline void flush_slab (struct kmem_cache *s,struct kmem_cache_cpu *c,bool lock) {
_
Andrew Morton
maintainerPATCH 42/212 mm, slub: use migrate_disable() on PREEMPT_RT
In reply to Andrew MortonFrom: Vlastimil Babka <[email protected]>
Subject: mm, slub: use migrate_disable() on PREEMPT_RT
We currently use preempt_disable() (directly or via get_cpu_ptr()) to stabilize the pointer to kmem_cache_cpu. On PREEMPT_RT this would be incompatible with the list_lock spinlock. We can use migrate_disable() instead, but that increases overhead on !PREEMPT_RT as it's an unconditional function call.
In order to get the best available mechanism on both PREEMPT_RT and !PREEMPT_RT, introduce private slub_get_cpu_ptr() and slub_put_cpu_ptr() wrappers and use them.
---
mm/slub.c | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-)
mm/slub.c renamed from mm/slub.c~mm-slub-use-migrate_disable-on-preempt_rt +30 -9
@@ -118,6 +118,26 @@* the fast path and disables lockless freelists. */ +/* +* We could simply use migrate_disable()/enable() but as long as it's a +* function call even on !PREEMPT_RT, use inline preempt_disable() there. +*/ +#ifndef CONFIG_PREEMPT_RT +#define slub_get_cpu_ptr (var) get_cpu_ptr(var) +#define slub_put_cpu_ptr (var) put_cpu_ptr(var) +#else +#define slub_get_cpu_ptr (var) \ +({ \ + migrate_disable(); \ + this_cpu_ptr(var); \ +}) +#define slub_put_cpu_ptr (var) \ +do { \ + (void)(var); \ + migrate_enable(); \ +} while (0) +#endif +#ifdef CONFIG_SLUB_DEBUG #ifdef CONFIG_SLUB_DEBUG_ON DEFINE_STATIC_KEY_TRUE (slub_debug_enabled);
@@ -2828,7 +2848,7 @@ redo:if (unlikely (!pfmemalloc_match_unsafe (page, gfpflags))) goto deactivate_slab; -/* must check again c->page in case IRQ handler changed it */ +/* must check again c->page in case we got preempted and it changed */ local_irq_save (flags);if (unlikely (page != c->page)) {local_irq_restore (flags);
@@ -2887,7 +2907,8 @@ new_slab: }if (unlikely (!slub_percpu_partial (c))) {local_irq_restore (flags); - goto new_objects;/* stolen by an IRQ handler */ +/* we were preempted and partial list got empty */ + goto new_objects; } page = c->page =slub_percpu_partial (c);
@@ -2903,9 +2924,9 @@ new_objects:if (freelist) goto check_new_page; -put_cpu_ptr (s->cpu_slab); +slub_put_cpu_ptr (s->cpu_slab); page =new_slab (s, gfpflags, node); - c =get_cpu_ptr (s->cpu_slab); + c =slub_get_cpu_ptr (s->cpu_slab);if (unlikely (!page)) {slab_out_of_memory (s, gfpflags, node);
@@ -2988,12 +3009,12 @@ static void *__slab_alloc(struct kmem_ca* cpu before disabling preemption. Need to reload cpu area * pointer. */ - c =get_cpu_ptr (s->cpu_slab); + c =slub_get_cpu_ptr (s->cpu_slab);#endif p =___slab_alloc (s, gfpflags, node, addr, c);#ifdef CONFIG_PREEMPT_COUNT -put_cpu_ptr (s->cpu_slab); +slub_put_cpu_ptr (s->cpu_slab);#endif return p; }
@@ -3522,7 +3543,7 @@ int kmem_cache_alloc_bulk(struct kmem_ca* IRQs, which protects against PREEMPT and interrupts * handlers invoking normal fastpath. */ - c =get_cpu_ptr (s->cpu_slab); + c =slub_get_cpu_ptr (s->cpu_slab);local_irq_disable ();for (i =0 ; i < size; i++) {
@@ -3568,7 +3589,7 @@ int kmem_cache_alloc_bulk(struct kmem_ca } c->tid =next_tid (c->tid);local_irq_enable (); -put_cpu_ptr (s->cpu_slab); +slub_put_cpu_ptr (s->cpu_slab);/* * memcg and kmem_cache debug support and memory initialization.
@@ -3578,7 +3599,7 @@ int kmem_cache_alloc_bulk(struct kmem_ca slab_want_init_on_alloc(flags, s));return i; error: -put_cpu_ptr (s->cpu_slab); +slub_put_cpu_ptr (s->cpu_slab);slab_post_alloc_hook (s, objcg, flags, i, p, false);__kmem_cache_free_bulk (s, i, p);return 0 ;
_
Andrew Morton
maintainerPATCH 43/212 mm, slub: convert kmem_cpu_slab protection to local_lock
In reply to Andrew MortonFrom: Vlastimil Babka <[email protected]>
Subject: mm, slub: convert kmem_cpu_slab protection to local_lock
Embed local_lock into struct kmem_cpu_slab and use the irq-safe versions of local_lock instead of plain local_irq_save/restore. On !PREEMPT_RT that's equivalent, with better lockdep visibility. On PREEMPT_RT that means better preemption.
However, the cost on PREEMPT_RT is the loss of lockless fast paths which only work with cpu freelist. Those are designed to detect and recover from being preempted by other conflicting operations (both fast or slow path), but the slow path operations assume they cannot be preempted by a fast path operation, which is guaranteed naturally with disabled irqs. With local locks on PREEMPT_RT, the fast paths now also need to take the local lock to avoid races.
In the allocation fastpath slab_alloc_node() we can just defer to the slowpath __slab_alloc() which also works with cpu freelist, but under the local lock. In the free fastpath do_slab_free() we have to add a new local lock protected version of freeing to the cpu freelist, as the existing slowpath only works with the page freelist.
Also update the comment about locking scheme in SLUB to reflect changes done by this series.
---
include/linux/slub_def.h | 6 + mm/slub.c | 142 ++++++++++++++++++++++++++++--------- 2 files changed, 115 insertions(+), 33 deletions(-)
include/linux/slub_def.h renamed from include/linux/slub_def.h~mm-slub-convert-kmem_cpu_slab-protection-to-local_lock +6 -0
@@ -10,6 +10,7 @@#include <linux/kfence.h> #include <linux/kobject.h> #include <linux/reciprocal_div.h> +#include <linux/local_lock.h> enum stat_item {ALLOC_FASTPATH ,/* Allocation from cpu slab */
@@ -40,6 +41,10 @@ enum stat_item {CPU_PARTIAL_DRAIN ,/* Drain cpu partial to node partial */ NR_SLUB_STAT_ITEMS }; +/* +* When changing the layout, make sure freelist and tid are still compatible +* with this_cpu_cmpxchg_double() alignment requirements. +*/ struct kmem_cache_cpu {void **freelist;/* Pointer to next available object */ unsigned long tid;/* Globally unique transaction id */
@@ -47,6 +52,7 @@ struct kmem_cache_cpu {#ifdef CONFIG_SLUB_CPU_PARTIAL struct page *partial;/* Partially allocated frozen slabs */ #endif +local_lock_t lock;/* Protects the fields above */ #ifdef CONFIG_SLUB_STATS unsigned stat[NR_SLUB_STAT_ITEMS ];#endif
mm/slub.c renamed from mm/slub.c~mm-slub-convert-kmem_cpu_slab-protection-to-local_lock +109 -33
314 lines not on this page · raw message
_
Andrew Morton
maintainerPATCH 44/212 mm/debug_vm_pgtable: introduce struct pgtable_debug_args
In reply to Andrew MortonFrom: Gavin Shan <[email protected]>
Subject: mm/debug_vm_pgtable: introduce struct pgtable_debug_args
Patch series "mm/debug_vm_pgtable: Enhancements", v6.
There are a couple of issues with current implementations and this series tries to resolve the issues:
(a) All needed information are scattered in variables, passed to various test functions. The code is organized in pretty much relaxed fashion.
(b) The page isn't allocated from buddy during page table entry modifying tests. The page can be invalid, conflicting to the implementations of set_xxx_at() on ARM64. The target page is accessed so that the iCache can be flushed when execution permission is given on ARM64. Besides, the target page can be unmapped and accessing to it causes kernel crash.
"struct pgtable_debug_args" is introduced to address issue (a). For issue (b), the used page is allocated from buddy in page table entry modifying tests. The corresponding tets will be skipped if we fail to allocate the (huge) page. For other test cases, the original page around to kernel symbol (@start_kernel) is still used.
The patches are organized as below. PATCH[2-10] could be combined to one patch, but it will make the review harder:
PATCH[1] introduces "struct pgtable_debug_args" as place holder of all
needed information. With it, the old and new implementation can coexist.
PATCH[2-10] uses "struct pgtable_debug_args" in various test functions. PATCH[11] removes the unused code for old implementation. PATCH[12] fixes the issue of corrupted page flag for ARM64
This patch (of 6):
In debug_vm_pgtable(), there are many local variables introduced to track the needed information and they are passed to the functions for various test cases. It'd better to introduce a struct as place holder for these information. With it, what the tests functions need is the struct. In this way, the code is simplified and easier to be maintained.
Besides, set_xxx_at() could access the data on the corresponding pages in the page table modifying tests. So the accessed pages in the tests should have been allocated from buddy. Otherwise, we're accessing pages that aren't owned by us. This causes issues like page flag corruption or kernel crash on accessing unmapped page when CONFIG_DEBUG_PAGEALLOC is enabled.
This introduces "struct pgtable_debug_args". The struct is initialized and destroyed, but the information in the struct isn't used yet. It will be used in subsequent patches.
---
mm/debug_vm_pgtable.c | 270 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 269 insertions(+), 1 deletion(-)
mm/debug_vm_pgtable.c renamed from mm/debug_vm_pgtable.c~mm-debug_vm_pgtable-introduce-struct-pgtable_debug_args +269 -1
@@ -58,6 +58,37 @@#define RANDOM_ORVALUE (GENMASK(BITS_PER_LONG - 1, 0) & ~ARCH_SKIP_MASK)#define RANDOM_NZVALUE GENMASK(7, 0) +struct pgtable_debug_args { +struct mm_struct *mm; +struct vm_area_struct *vma; + +pgd_t *pgdp; +p4d_t *p4dp; +pud_t *pudp; +pmd_t *pmdp; +pte_t *ptep; + +p4d_t *start_p4dp; +pud_t *start_pudp; +pmd_t *start_pmdp; +pgtable_t start_ptep; + +unsigned long vaddr; +pgprot_t page_prot; +pgprot_t page_prot_none; + +bool is_contiguous_page; +unsigned long pud_pfn; +unsigned long pmd_pfn; +unsigned long pte_pfn; + +unsigned long fixed_pgd_pfn; +unsigned long fixed_p4d_pfn; +unsigned long fixed_pud_pfn; +unsigned long fixed_pmd_pfn; +unsigned long fixed_pte_pfn; +}; +static void __init pte_basic_tests (unsigned long pfn,int idx) {pgprot_t prot = protection_map[idx];
@@ -955,8 +986,239 @@ static unsigned long __init get_random_vreturn random_vaddr; } +static void __init destroy_args (struct pgtable_debug_args *args) +{ +struct page *page =NULL ; + +/* Free (huge) page */ +if (IS_ENABLED (CONFIG_TRANSPARENT_HUGEPAGE ) && +IS_ENABLED (CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD ) && +has_transparent_hugepage () && + args->pud_pfn !=ULONG_MAX ) { +if (args->is_contiguous_page) { +free_contig_range (args->pud_pfn, + (1 << (HPAGE_PUD_SHIFT -PAGE_SHIFT ))); + }else { + page =pfn_to_page (args->pud_pfn); +__free_pages (page,HPAGE_PUD_SHIFT -PAGE_SHIFT ); + } + + args->pud_pfn =ULONG_MAX ; + args->pmd_pfn =ULONG_MAX ; + args->pte_pfn =ULONG_MAX ; + } + +if (IS_ENABLED (CONFIG_TRANSPARENT_HUGEPAGE ) && +has_transparent_hugepage () && + args->pmd_pfn !=ULONG_MAX ) { +if (args->is_contiguous_page) { +free_contig_range (args->pmd_pfn, (1 <<HPAGE_PMD_ORDER )); + }else { + page =pfn_to_page (args->pmd_pfn); +__free_pages (page,HPAGE_PMD_ORDER ); + } + + args->pmd_pfn =ULONG_MAX ; + args->pte_pfn =ULONG_MAX ; + } + +if (args->pte_pfn !=ULONG_MAX ) { + page =pfn_to_page (args->pte_pfn); +__free_pages (page,0 ); + + args->pte_pfn =ULONG_MAX ; + } + +/* Free page table entries */ +if (args->start_ptep) { +pte_free (args->mm, args->start_ptep); +mm_dec_nr_ptes (args->mm); + } + +if (args->start_pmdp) { +pmd_free (args->mm, args->start_pmdp); +mm_dec_nr_pmds (args->mm); + } + +if (args->start_pudp) { +pud_free (args->mm, args->start_pudp); +mm_dec_nr_puds (args->mm); + } + +if (args->start_p4dp) +p4d_free (args->mm, args->start_p4dp); + +/* Free vma and mm struct */ +if (args->vma) +vm_area_free (args->vma); + +if (args->mm) +mmdrop (args->mm); +} + +static struct page *__init +debug_vm_pgtable_alloc_huge_page (struct pgtable_debug_args *args,int order) +{ +struct page *page =NULL ; + +#ifdef CONFIG_CONTIG_ALLOC +if (order >=MAX_ORDER ) { + page =alloc_contig_pages ((1 << order),GFP_KERNEL , + first_online_node,NULL ); +if (page) { + args->is_contiguous_page = true; +return page; + } + } +#endif + +if (order <MAX_ORDER ) + page =alloc_pages (GFP_KERNEL , order); + +return page; +} + +static int __init init_args (struct pgtable_debug_args *args) +{ +struct page *page =NULL ; +phys_addr_t phys; +int ret =0 ; + +/* +* Initialize the debugging data. +* +* __P000 (or even __S000) will help create page table entries with +* PROT_NONE permission as required for pxx_protnone_tests(). +*/ +memset (args,0 ,sizeof (*args)); + args->vaddr =get_random_vaddr (); + args->page_prot =vm_get_page_prot (VMFLAGS ); + args->page_prot_none = __P000; + args->is_contiguous_page = false; + args->pud_pfn =ULONG_MAX ; + args->pmd_pfn =ULONG_MAX ; + args->pte_pfn =ULONG_MAX ; + args->fixed_pgd_pfn =ULONG_MAX ; + args->fixed_p4d_pfn =ULONG_MAX ; + args->fixed_pud_pfn =ULONG_MAX ; + args->fixed_pmd_pfn =ULONG_MAX ; + args->fixed_pte_pfn =ULONG_MAX ; + +/* Allocate mm and vma */ + args->mm =mm_alloc (); +if (!args->mm) { +pr_err ("Failed to allocate mm struct\n" ); + ret = -ENOMEM ; + goto error; + } + + args->vma =vm_area_alloc (args->mm); +if (!args->vma) { +pr_err ("Failed to allocate vma\n" ); + ret = -ENOMEM ; + goto error; + } + +/* +* Allocate page table entries. They will be modified in the tests. +* Lets save the page table entries so that they can be released +* when the tests are completed. +*/ + args->pgdp =pgd_offset (args->mm, args->vaddr); + args->p4dp =p4d_alloc (args->mm, args->pgdp, args->vaddr); +if (!args->p4dp) { +pr_err ("Failed to allocate p4d entries\n" ); + ret = -ENOMEM ; + goto error; + } + args->start_p4dp =p4d_offset (args->pgdp,0UL ); +WARN_ON (!args->start_p4dp); + + args->pudp =pud_alloc (args->mm, args->p4dp, args->vaddr); +if (!args->pudp) { +pr_err ("Failed to allocate pud entries\n" ); + ret = -ENOMEM ; + goto error; + } + args->start_pudp =pud_offset (args->p4dp,0UL ); +WARN_ON (!args->start_pudp); + + args->pmdp =pmd_alloc (args->mm, args->pudp, args->vaddr); +if (!args->pmdp) { +pr_err ("Failed to allocate pmd entries\n" ); + ret = -ENOMEM ; + goto error; + } + args->start_pmdp =pmd_offset (args->pudp,0UL ); +WARN_ON (!args->start_pmdp); + +if (pte_alloc (args->mm, args->pmdp)) { +pr_err ("Failed to allocate pte entries\n" ); + ret = -ENOMEM ; + goto error; + } + args->start_ptep =pmd_pgtable (READ_ONCE (*args->pmdp)); +WARN_ON (!args->start_ptep); + +/* +* PFN for mapping at PTE level is determined from a standard kernel +* text symbol. But pfns for higher page table levels are derived by +* masking lower bits of this real pfn. These derived pfns might not +* exist on the platform but that does not really matter as pfn_pxx() +* helpers will still create appropriate entries for the test. This +* helps avoid large memory block allocations to be used for mapping +* at higher page table levels in some of the tests. +*/ + phys =__pa_symbol (&start_kernel); + args->fixed_pgd_pfn =__phys_to_pfn (phys &PGDIR_MASK ); + args->fixed_p4d_pfn =__phys_to_pfn (phys &P4D_MASK ); + args->fixed_pud_pfn =__phys_to_pfn (phys &PUD_MASK ); + args->fixed_pmd_pfn =__phys_to_pfn (phys &PMD_MASK ); + args->fixed_pte_pfn =__phys_to_pfn (phys &PAGE_MASK ); +WARN_ON (!pfn_valid (args->fixed_pte_pfn)); + +/* +* Allocate (huge) pages because some of the tests need to access +* the data in the pages. The corresponding tests will be skipped +* if we fail to allocate (huge) pages. +*/ +if (IS_ENABLED (CONFIG_TRANSPARENT_HUGEPAGE ) && +IS_ENABLED (CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD ) && +has_transparent_hugepage ()) { + page =debug_vm_pgtable_alloc_huge_page (args, +HPAGE_PUD_SHIFT -PAGE_SHIFT ); +if (page) { + args->pud_pfn =page_to_pfn (page); + args->pmd_pfn = args->pud_pfn; + args->pte_pfn = args->pud_pfn; +return 0 ; + } + } + +if (IS_ENABLED (CONFIG_TRANSPARENT_HUGEPAGE ) && +has_transparent_hugepage ()) { + page =debug_vm_pgtable_alloc_huge_page (args,HPAGE_PMD_ORDER ); +if (page) { + args->pmd_pfn =page_to_pfn (page); + args->pte_pfn = args->pmd_pfn; +return 0 ; + } + } + + page =alloc_pages (GFP_KERNEL ,0 ); +if (page) + args->pte_pfn =page_to_pfn (page); + +return 0 ; + +error: +destroy_args (args); +return ret; +} +static int __init debug_vm_pgtable (void ) { +struct pgtable_debug_args args;struct vm_area_struct *vma;struct mm_struct *mm;pgd_t *pgdp;
@@ -970,9 +1232,13 @@ static int __init debug_vm_pgtable(void)unsigned long vaddr, pte_aligned, pmd_aligned;unsigned long pud_aligned, p4d_aligned, pgd_aligned;spinlock_t *ptl =NULL ; -int idx; +int idx, ret;pr_info ("Validating architecture page table helpers\n" ); + ret =init_args (&args); +if (ret) +return ret; + prot =vm_get_page_prot (VMFLAGS ); vaddr =get_random_vaddr (); mm =mm_alloc ();
@@ -1127,6 +1393,8 @@ static int __init debug_vm_pgtable(void)mm_dec_nr_pmds (mm);mm_dec_nr_ptes (mm);mmdrop (mm); + +destroy_args (&args);return 0 ; }late_initcall (debug_vm_pgtable);
_
Andrew Morton
maintainerPATCH 45/212 mm/debug_vm_pgtable: use struct pgtable_debug_args in basic tests
In reply to Andrew MortonFrom: Gavin Shan <[email protected]>
Subject: mm/debug_vm_pgtable: use struct pgtable_debug_args in basic tests
This uses struct pgtable_debug_args in the basic test functions. The unused variables @pgd_aligned and @p4d_aligned in debug_vm_pgtable() are dropped.
---
mm/debug_vm_pgtable.c | 50 +++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 26 deletions(-)
mm/debug_vm_pgtable.c renamed from mm/debug_vm_pgtable.c~mm-debug_vm_pgtable-use-struct-pgtable_debug_args-in-basic-tests +24 -26
@@ -89,10 +89,10 @@ struct pgtable_debug_args {unsigned long fixed_pte_pfn; }; -static void __init pte_basic_tests (unsigned long pfn,int idx) +static void __init pte_basic_tests (struct pgtable_debug_args *args,int idx) {pgprot_t prot = protection_map[idx]; -pte_t pte =pfn_pte (pfn, prot); +pte_t pte =pfn_pte (args->fixed_pte_pfn, prot);unsigned long val = idx, *ptr = &val;pr_debug ("Validating PTE basic (%pGv)\n" , ptr);
@@ -174,7 +174,7 @@ static void __init pte_savedwrite_tests( }#ifdef CONFIG_TRANSPARENT_HUGEPAGE -static void __init pmd_basic_tests (unsigned long pfn,int idx) +static void __init pmd_basic_tests (struct pgtable_debug_args *args,int idx) {pgprot_t prot = protection_map[idx];unsigned long val = idx, *ptr = &val;
@@ -184,7 +184,7 @@ static void __init pmd_basic_tests(unsigreturn ;pr_debug ("Validating PMD basic (%pGv)\n" , ptr); - pmd =pfn_pmd (pfn, prot); + pmd =pfn_pmd (args->fixed_pmd_pfn, prot);/* * This test needs to be executed after the given page table entry
@@ -296,7 +296,7 @@ static void __init pmd_savedwrite_tests( }#ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD -static void __init pud_basic_tests (struct mm_struct *mm,unsigned long pfn,int idx) +static void __init pud_basic_tests (struct pgtable_debug_args *args,int idx) {pgprot_t prot = protection_map[idx];unsigned long val = idx, *ptr = &val;
@@ -306,7 +306,7 @@ static void __init pud_basic_tests(strucreturn ;pr_debug ("Validating PUD basic (%pGv)\n" , ptr); - pud =pfn_pud (pfn, prot); + pud =pfn_pud (args->fixed_pud_pfn, prot);/* * This test needs to be executed after the given page table entry
@@ -327,7 +327,7 @@ static void __init pud_basic_tests(strucWARN_ON (pud_dirty (pud_wrprotect (pud_mkclean (pud))));WARN_ON (!pud_dirty (pud_wrprotect (pud_mkdirty (pud)))); -if (mm_pmd_folded (mm)) +if (mm_pmd_folded (args->mm))return ;/*
@@ -404,7 +404,7 @@ static void __init pud_leaf_tests(unsignWARN_ON (!pud_leaf (pud)); }#else /* !CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD */ -static void __init pud_basic_tests (struct mm_struct *mm,unsigned long pfn,int idx) { } +static void __init pud_basic_tests (struct pgtable_debug_args *args,int idx) { } static void __init pud_advanced_tests(struct mm_struct *mm, struct vm_area_struct *vma, pud_t *pudp, unsigned long pfn, unsigned long vaddr,
@@ -414,8 +414,8 @@ static void __init pud_advanced_tests(ststatic void __init pud_leaf_tests (unsigned long pfn,pgprot_t prot) { }#endif /* CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD */ #else /* !CONFIG_TRANSPARENT_HUGEPAGE */ -static void __init pmd_basic_tests (unsigned long pfn,int idx) { } -static void __init pud_basic_tests (struct mm_struct *mm,unsigned long pfn,int idx) { } +static void __init pmd_basic_tests (struct pgtable_debug_args *args,int idx) { } +static void __init pud_basic_tests (struct pgtable_debug_args *args,int idx) { } static void __init pmd_advanced_tests(struct mm_struct *mm, struct vm_area_struct *vma, pmd_t *pmdp, unsigned long pfn, unsigned long vaddr,
@@ -476,7 +476,7 @@ static void __init pmd_huge_tests(pmd_tstatic void __init pud_huge_tests (pud_t *pudp,unsigned long pfn,pgprot_t prot) { }#endif /* CONFIG_HAVE_ARCH_HUGE_VMAP */ -static void __init p4d_basic_tests (unsigned long pfn,pgprot_t prot) +static void __init p4d_basic_tests (struct pgtable_debug_args *args) {p4d_t p4d;
@@ -485,7 +485,7 @@ static void __init p4d_basic_tests(unsigWARN_ON (!p4d_same (p4d, p4d)); } -static void __init pgd_basic_tests (unsigned long pfn,pgprot_t prot) +static void __init pgd_basic_tests (struct pgtable_debug_args *args) {pgd_t pgd;
@@ -890,7 +890,7 @@ static void __init swap_migration_tests( }#ifdef CONFIG_HUGETLB_PAGE -static void __init hugetlb_basic_tests (unsigned long pfn,pgprot_t prot) +static void __init hugetlb_basic_tests (struct pgtable_debug_args *args) {struct page *page;pte_t pte;
@@ -900,21 +900,21 @@ static void __init hugetlb_basic_tests(u* Accessing the page associated with the pfn is safe here, * as it was previously derived from a real kernel symbol. */ - page =pfn_to_page (pfn); - pte =mk_huge_pte (page, prot); + page =pfn_to_page (args->fixed_pmd_pfn); + pte =mk_huge_pte (page, args->page_prot);WARN_ON (!huge_pte_dirty (huge_pte_mkdirty (pte)));WARN_ON (!huge_pte_write (huge_pte_mkwrite (huge_pte_wrprotect (pte))));WARN_ON (huge_pte_write (huge_pte_wrprotect (huge_pte_mkwrite (pte))));#ifdef CONFIG_ARCH_WANT_GENERAL_HUGETLB - pte =pfn_pte (pfn, prot); + pte =pfn_pte (args->fixed_pmd_pfn, args->page_prot);WARN_ON (!pte_huge (pte_mkhuge (pte))); #endif /* CONFIG_ARCH_WANT_GENERAL_HUGETLB */ }#else /* !CONFIG_HUGETLB_PAGE */ -static void __init hugetlb_basic_tests (unsigned long pfn,pgprot_t prot) { } +static void __init hugetlb_basic_tests (struct pgtable_debug_args *args) { }#endif /* CONFIG_HUGETLB_PAGE */ #ifdef CONFIG_TRANSPARENT_HUGEPAGE
@@ -1230,7 +1230,7 @@ static int __init debug_vm_pgtable(void)pgprot_t prot, protnone;phys_addr_t paddr;unsigned long vaddr, pte_aligned, pmd_aligned; -unsigned long pud_aligned, p4d_aligned, pgd_aligned; +unsigned long pud_aligned;spinlock_t *ptl =NULL ;int idx, ret;
@@ -1273,8 +1273,6 @@ static int __init debug_vm_pgtable(void) pte_aligned = (paddr &PAGE_MASK ) >>PAGE_SHIFT ; pmd_aligned = (paddr &PMD_MASK ) >>PAGE_SHIFT ; pud_aligned = (paddr &PUD_MASK ) >>PAGE_SHIFT ; - p4d_aligned = (paddr &P4D_MASK ) >>PAGE_SHIFT ; - pgd_aligned = (paddr &PGDIR_MASK ) >>PAGE_SHIFT ;WARN_ON (!pfn_valid (pte_aligned)); pgdp =pgd_offset (mm, vaddr);
@@ -1308,9 +1306,9 @@ static int __init debug_vm_pgtable(void)* given page table entry. */ for (idx =0 ; idx <ARRAY_SIZE (protection_map); idx++) { -pte_basic_tests (pte_aligned, idx); -pmd_basic_tests (pmd_aligned, idx); -pud_basic_tests (mm, pud_aligned, idx); +pte_basic_tests (&args, idx); +pmd_basic_tests (&args, idx); +pud_basic_tests (&args, idx); }/*
@@ -1320,8 +1318,8 @@ static int __init debug_vm_pgtable(void)* the above iteration for now to save some test execution * time. */ -p4d_basic_tests (p4d_aligned, prot); -pgd_basic_tests (pgd_aligned, prot); +p4d_basic_tests (&args); +pgd_basic_tests (&args);pmd_leaf_tests (pmd_aligned, prot);pud_leaf_tests (pud_aligned, prot);
@@ -1350,7 +1348,7 @@ static int __init debug_vm_pgtable(void)pmd_thp_tests (pmd_aligned, prot);pud_thp_tests (pud_aligned, prot); -hugetlb_basic_tests (pte_aligned, prot); +hugetlb_basic_tests (&args);/* * Page table modifying tests. They need to hold
_
Andrew Morton
maintainerPATCH 46/212 mm/debug_vm_pgtable: use struct pgtable_debug_args in leaf and savewrite tests
In reply to Andrew MortonFrom: Gavin Shan <[email protected]>
Subject: mm/debug_vm_pgtable: use struct pgtable_debug_args in leaf and savewrite tests
This uses struct pgtable_debug_args in the leaf and savewrite test functions.
---
mm/debug_vm_pgtable.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-)
mm/debug_vm_pgtable.c renamed from mm/debug_vm_pgtable.c~mm-debug_vm_pgtable-use-struct-pgtable_debug_args-in-leaf-and-savewrite-tests +16 -16
@@ -161,9 +161,9 @@ static void __init pte_advanced_tests(stWARN_ON (pte_young (pte)); } -static void __init pte_savedwrite_tests (unsigned long pfn,pgprot_t prot) +static void __init pte_savedwrite_tests (struct pgtable_debug_args *args) { -pte_t pte =pfn_pte (pfn, prot); +pte_t pte =pfn_pte (args->fixed_pte_pfn, args->page_prot_none);if (!IS_ENABLED (CONFIG_NUMA_BALANCING ))return ;
@@ -262,7 +262,7 @@ static void __init pmd_advanced_tests(st pgtable =pgtable_trans_huge_withdraw (mm, pmdp); } -static void __init pmd_leaf_tests (unsigned long pfn,pgprot_t prot) +static void __init pmd_leaf_tests (struct pgtable_debug_args *args) {pmd_t pmd;
@@ -270,7 +270,7 @@ static void __init pmd_leaf_tests(unsignreturn ;pr_debug ("Validating PMD leaf\n" ); - pmd =pfn_pmd (pfn, prot); + pmd =pfn_pmd (args->fixed_pmd_pfn, args->page_prot);/* * PMD based THP is a leaf entry.
@@ -279,7 +279,7 @@ static void __init pmd_leaf_tests(unsignWARN_ON (!pmd_leaf (pmd)); } -static void __init pmd_savedwrite_tests (unsigned long pfn,pgprot_t prot) +static void __init pmd_savedwrite_tests (struct pgtable_debug_args *args) {pmd_t pmd;
@@ -290,7 +290,7 @@ static void __init pmd_savedwrite_tests(return ;pr_debug ("Validating PMD saved write\n" ); - pmd =pfn_pmd (pfn, prot); + pmd =pfn_pmd (args->fixed_pmd_pfn, args->page_prot_none);WARN_ON (!pmd_savedwrite (pmd_mk_savedwrite (pmd_clear_savedwrite (pmd))));WARN_ON (pmd_savedwrite (pmd_clear_savedwrite (pmd_mk_savedwrite (pmd)))); }
@@ -388,7 +388,7 @@ static void __init pud_advanced_tests(stpudp_huge_get_and_clear (mm, vaddr, pudp); } -static void __init pud_leaf_tests (unsigned long pfn,pgprot_t prot) +static void __init pud_leaf_tests (struct pgtable_debug_args *args) {pud_t pud;
@@ -396,7 +396,7 @@ static void __init pud_leaf_tests(unsignreturn ;pr_debug ("Validating PUD leaf\n" ); - pud =pfn_pud (pfn, prot); + pud =pfn_pud (args->fixed_pud_pfn, args->page_prot);/* * PUD based THP is a leaf entry. */
@@ -411,7 +411,7 @@ static void __init pud_advanced_tests(st pgprot_t prot) { } -static void __init pud_leaf_tests (unsigned long pfn,pgprot_t prot) { } +static void __init pud_leaf_tests (struct pgtable_debug_args *args) { }#endif /* CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD */ #else /* !CONFIG_TRANSPARENT_HUGEPAGE */ static void __init pmd_basic_tests (struct pgtable_debug_args *args,int idx) { }
@@ -428,9 +428,9 @@ static void __init pud_advanced_tests(st pgprot_t prot) { } -static void __init pmd_leaf_tests (unsigned long pfn,pgprot_t prot) { } -static void __init pud_leaf_tests (unsigned long pfn,pgprot_t prot) { } -static void __init pmd_savedwrite_tests (unsigned long pfn,pgprot_t prot) { } +static void __init pmd_leaf_tests (struct pgtable_debug_args *args) { } +static void __init pud_leaf_tests (struct pgtable_debug_args *args) { } +static void __init pmd_savedwrite_tests (struct pgtable_debug_args *args) { }#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ #ifdef CONFIG_HAVE_ARCH_HUGE_VMAP
@@ -1321,11 +1321,11 @@ static int __init debug_vm_pgtable(void)p4d_basic_tests (&args);pgd_basic_tests (&args); -pmd_leaf_tests (pmd_aligned, prot); -pud_leaf_tests (pud_aligned, prot); +pmd_leaf_tests (&args); +pud_leaf_tests (&args); -pte_savedwrite_tests (pte_aligned, protnone); -pmd_savedwrite_tests (pmd_aligned, protnone); +pte_savedwrite_tests (&args); +pmd_savedwrite_tests (&args);pte_special_tests (pte_aligned, prot);pte_protnone_tests (pte_aligned, protnone);
_
Andrew Morton
maintainerPATCH 47/212 mm/debug_vm_pgtable: use struct pgtable_debug_args in protnone and devmap tests
In reply to Andrew MortonFrom: Gavin Shan <[email protected]>
Subject: mm/debug_vm_pgtable: use struct pgtable_debug_args in protnone and devmap tests
This uses struct pgtable_debug_args in protnone and devmap test functions. After that, the unused variable @protnone in debug_vm_pgtable() is dropped.
---
mm/debug_vm_pgtable.c | 60 ++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 33 deletions(-)
mm/debug_vm_pgtable.c renamed from mm/debug_vm_pgtable.c~mm-debug_vm_pgtable-use-struct-pgtable_debug_args-in-protnone-and-devmap-tests +27 -33
@@ -662,9 +662,9 @@ static void __init pmd_populate_tests(stWARN_ON (pmd_bad (pmd)); } -static void __init pte_special_tests (unsigned long pfn,pgprot_t prot) +static void __init pte_special_tests (struct pgtable_debug_args *args) { -pte_t pte =pfn_pte (pfn, prot); +pte_t pte =pfn_pte (args->fixed_pte_pfn, args->page_prot);if (!IS_ENABLED (CONFIG_ARCH_HAS_PTE_SPECIAL ))return ;
@@ -673,9 +673,9 @@ static void __init pte_special_tests(unsWARN_ON (!pte_special (pte_mkspecial (pte))); } -static void __init pte_protnone_tests (unsigned long pfn,pgprot_t prot) +static void __init pte_protnone_tests (struct pgtable_debug_args *args) { -pte_t pte =pfn_pte (pfn, prot); +pte_t pte =pfn_pte (args->fixed_pte_pfn, args->page_prot_none);if (!IS_ENABLED (CONFIG_NUMA_BALANCING ))return ;
@@ -686,7 +686,7 @@ static void __init pte_protnone_tests(un }#ifdef CONFIG_TRANSPARENT_HUGEPAGE -static void __init pmd_protnone_tests (unsigned long pfn,pgprot_t prot) +static void __init pmd_protnone_tests (struct pgtable_debug_args *args) {pmd_t pmd;
@@ -697,25 +697,25 @@ static void __init pmd_protnone_tests(unreturn ;pr_debug ("Validating PMD protnone\n" ); - pmd =pmd_mkhuge (pfn_pmd (pfn, prot)); + pmd =pmd_mkhuge (pfn_pmd (args->fixed_pmd_pfn, args->page_prot_none));WARN_ON (!pmd_protnone (pmd));WARN_ON (!pmd_present (pmd)); }#else /* !CONFIG_TRANSPARENT_HUGEPAGE */ -static void __init pmd_protnone_tests (unsigned long pfn,pgprot_t prot) { } +static void __init pmd_protnone_tests (struct pgtable_debug_args *args) { }#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ #ifdef CONFIG_ARCH_HAS_PTE_DEVMAP -static void __init pte_devmap_tests(unsigned long pfn, pgprot_t prot) +static void __init pte_devmap_tests(struct pgtable_debug_args *args) { - pte_t pte = pfn_pte(pfn, prot); + pte_t pte = pfn_pte(args->fixed_pte_pfn, args->page_prot); pr_debug("Validating PTE devmap\n"); WARN_ON(!pte_devmap(pte_mkdevmap(pte))); } #ifdef CONFIG_TRANSPARENT_HUGEPAGE -static void __init pmd_devmap_tests(unsigned long pfn, pgprot_t prot) +static void __init pmd_devmap_tests(struct pgtable_debug_args *args) { pmd_t pmd;
@@ -723,12 +723,12 @@ static void __init pmd_devmap_tests(unsireturn ;pr_debug ("Validating PMD devmap\n" ); - pmd =pfn_pmd (pfn, prot); + pmd =pfn_pmd (args->fixed_pmd_pfn, args->page_prot);WARN_ON (!pmd_devmap (pmd_mkdevmap (pmd))); }#ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD -static void __init pud_devmap_tests (unsigned long pfn,pgprot_t prot) +static void __init pud_devmap_tests (struct pgtable_debug_args *args) {pud_t pud;
@@ -736,20 +736,20 @@ static void __init pud_devmap_tests(unsireturn ;pr_debug ("Validating PUD devmap\n" ); - pud =pfn_pud (pfn, prot); + pud =pfn_pud (args->fixed_pud_pfn, args->page_prot);WARN_ON (!pud_devmap (pud_mkdevmap (pud))); }#else /* !CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD */ -static void __init pud_devmap_tests (unsigned long pfn,pgprot_t prot) { } +static void __init pud_devmap_tests (struct pgtable_debug_args *args) { }#endif /* CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD */ #else /* CONFIG_TRANSPARENT_HUGEPAGE */ -static void __init pmd_devmap_tests (unsigned long pfn,pgprot_t prot) { } -static void __init pud_devmap_tests (unsigned long pfn,pgprot_t prot) { } +static void __init pmd_devmap_tests (struct pgtable_debug_args *args) { } +static void __init pud_devmap_tests (struct pgtable_debug_args *args) { }#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ #else -static void __init pte_devmap_tests (unsigned long pfn,pgprot_t prot) { } -static void __init pmd_devmap_tests (unsigned long pfn,pgprot_t prot) { } -static void __init pud_devmap_tests (unsigned long pfn,pgprot_t prot) { } +static void __init pte_devmap_tests (struct pgtable_debug_args *args) { } +static void __init pmd_devmap_tests (struct pgtable_debug_args *args) { } +static void __init pud_devmap_tests (struct pgtable_debug_args *args) { }#endif /* CONFIG_ARCH_HAS_PTE_DEVMAP */ static void __init pte_soft_dirty_tests (unsigned long pfn,pgprot_t prot)
@@ -1227,7 +1227,7 @@ static int __init debug_vm_pgtable(void)pmd_t *pmdp, *saved_pmdp, pmd;pte_t *ptep;pgtable_t saved_ptep; -pgprot_t prot, protnone; +pgprot_t prot;phys_addr_t paddr;unsigned long vaddr, pte_aligned, pmd_aligned;unsigned long pud_aligned;
@@ -1247,12 +1247,6 @@ static int __init debug_vm_pgtable(void)return 1 ; } -/* -* __P000 (or even __S000) will help create page table entries with -* PROT_NONE permission as required for pxx_protnone_tests(). -*/ - protnone = __P000; - vma =vm_area_alloc (mm);if (!vma) {pr_err ("vma allocation failed\n" );
@@ -1327,13 +1321,13 @@ static int __init debug_vm_pgtable(void)pte_savedwrite_tests (&args);pmd_savedwrite_tests (&args); -pte_special_tests (pte_aligned, prot); -pte_protnone_tests (pte_aligned, protnone); -pmd_protnone_tests (pmd_aligned, protnone); - -pte_devmap_tests (pte_aligned, prot); -pmd_devmap_tests (pmd_aligned, prot); -pud_devmap_tests (pud_aligned, prot); +pte_special_tests (&args); +pte_protnone_tests (&args); +pmd_protnone_tests (&args); + +pte_devmap_tests (&args); +pmd_devmap_tests (&args); +pud_devmap_tests (&args);pte_soft_dirty_tests (pte_aligned, prot);pmd_soft_dirty_tests (pmd_aligned, prot);
_
Andrew Morton
maintainerPATCH 48/212 mm/debug_vm_pgtable: use struct pgtable_debug_args in soft_dirty and swap tests
In reply to Andrew MortonFrom: Gavin Shan <[email protected]>
Subject: mm/debug_vm_pgtable: use struct pgtable_debug_args in soft_dirty and swap tests
This uses struct pgtable_debug_args in the soft_dirty and swap test functions.
---
mm/debug_vm_pgtable.c | 48 +++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 25 deletions(-)
mm/debug_vm_pgtable.c renamed from mm/debug_vm_pgtable.c~mm-debug_vm_pgtable-use-struct-pgtable_debug_args-in-soft_dirty-and-swap-tests +23 -25
@@ -752,9 +752,9 @@ static void __init pmd_devmap_tests(strustatic void __init pud_devmap_tests (struct pgtable_debug_args *args) { }#endif /* CONFIG_ARCH_HAS_PTE_DEVMAP */ -static void __init pte_soft_dirty_tests (unsigned long pfn,pgprot_t prot) +static void __init pte_soft_dirty_tests (struct pgtable_debug_args *args) { -pte_t pte =pfn_pte (pfn, prot); +pte_t pte =pfn_pte (args->fixed_pte_pfn, args->page_prot);if (!IS_ENABLED (CONFIG_MEM_SOFT_DIRTY ))return ;
@@ -764,9 +764,9 @@ static void __init pte_soft_dirty_tests(WARN_ON (pte_soft_dirty (pte_clear_soft_dirty (pte))); } -static void __init pte_swap_soft_dirty_tests (unsigned long pfn,pgprot_t prot) +static void __init pte_swap_soft_dirty_tests (struct pgtable_debug_args *args) { -pte_t pte =pfn_pte (pfn, prot); +pte_t pte =pfn_pte (args->fixed_pte_pfn, args->page_prot);if (!IS_ENABLED (CONFIG_MEM_SOFT_DIRTY ))return ;
@@ -777,7 +777,7 @@ static void __init pte_swap_soft_dirty_t }#ifdef CONFIG_TRANSPARENT_HUGEPAGE -static void __init pmd_soft_dirty_tests (unsigned long pfn,pgprot_t prot) +static void __init pmd_soft_dirty_tests (struct pgtable_debug_args *args) {pmd_t pmd;
@@ -788,12 +788,12 @@ static void __init pmd_soft_dirty_tests(return ;pr_debug ("Validating PMD soft dirty\n" ); - pmd =pfn_pmd (pfn, prot); + pmd =pfn_pmd (args->fixed_pmd_pfn, args->page_prot);WARN_ON (!pmd_soft_dirty (pmd_mksoft_dirty (pmd)));WARN_ON (pmd_soft_dirty (pmd_clear_soft_dirty (pmd))); } -static void __init pmd_swap_soft_dirty_tests (unsigned long pfn,pgprot_t prot) +static void __init pmd_swap_soft_dirty_tests (struct pgtable_debug_args *args) {pmd_t pmd;
@@ -805,31 +805,29 @@ static void __init pmd_swap_soft_dirty_treturn ;pr_debug ("Validating PMD swap soft dirty\n" ); - pmd =pfn_pmd (pfn, prot); + pmd =pfn_pmd (args->fixed_pmd_pfn, args->page_prot);WARN_ON (!pmd_swp_soft_dirty (pmd_swp_mksoft_dirty (pmd)));WARN_ON (pmd_swp_soft_dirty (pmd_swp_clear_soft_dirty (pmd))); }#else /* !CONFIG_TRANSPARENT_HUGEPAGE */ -static void __init pmd_soft_dirty_tests (unsigned long pfn,pgprot_t prot) { } -static void __init pmd_swap_soft_dirty_tests (unsigned long pfn,pgprot_t prot) -{ -} +static void __init pmd_soft_dirty_tests (struct pgtable_debug_args *args) { } +static void __init pmd_swap_soft_dirty_tests (struct pgtable_debug_args *args) { }#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ -static void __init pte_swap_tests (unsigned long pfn,pgprot_t prot) +static void __init pte_swap_tests (struct pgtable_debug_args *args) {swp_entry_t swp;pte_t pte;pr_debug ("Validating PTE swap\n" ); - pte =pfn_pte (pfn, prot); + pte =pfn_pte (args->fixed_pte_pfn, args->page_prot); swp =__pte_to_swp_entry (pte); pte =__swp_entry_to_pte (swp); -WARN_ON (pfn !=pte_pfn (pte)); +WARN_ON (args->fixed_pte_pfn !=pte_pfn (pte)); }#ifdef CONFIG_ARCH_ENABLE_THP_MIGRATION -static void __init pmd_swap_tests (unsigned long pfn,pgprot_t prot) +static void __init pmd_swap_tests (struct pgtable_debug_args *args) {swp_entry_t swp;pmd_t pmd;
@@ -838,13 +836,13 @@ static void __init pmd_swap_tests(unsignreturn ;pr_debug ("Validating PMD swap\n" ); - pmd =pfn_pmd (pfn, prot); + pmd =pfn_pmd (args->fixed_pmd_pfn, args->page_prot); swp =__pmd_to_swp_entry (pmd); pmd =__swp_entry_to_pmd (swp); - WARN_ON(pfn != pmd_pfn(pmd)); + WARN_ON(args->fixed_pmd_pfn != pmd_pfn(pmd)); }#else /* !CONFIG_ARCH_ENABLE_THP_MIGRATION */ -static void __init pmd_swap_tests (unsigned long pfn,pgprot_t prot) { } +static void __init pmd_swap_tests (struct pgtable_debug_args *args) { }#endif /* CONFIG_ARCH_ENABLE_THP_MIGRATION */ static void __init swap_migration_tests (void )
@@ -1329,13 +1327,13 @@ static int __init debug_vm_pgtable(void)pmd_devmap_tests (&args);pud_devmap_tests (&args); -pte_soft_dirty_tests (pte_aligned, prot); -pmd_soft_dirty_tests (pmd_aligned, prot); -pte_swap_soft_dirty_tests (pte_aligned, prot); -pmd_swap_soft_dirty_tests (pmd_aligned, prot); +pte_soft_dirty_tests (&args); +pmd_soft_dirty_tests (&args); +pte_swap_soft_dirty_tests (&args); +pmd_swap_soft_dirty_tests (&args); -pte_swap_tests (pte_aligned, prot); -pmd_swap_tests (pmd_aligned, prot); +pte_swap_tests (&args); +pmd_swap_tests (&args);swap_migration_tests ();
_
Andrew Morton
maintainerPATCH 49/212 mm/debug_vm_pgtable: use struct pgtable_debug_args in migration and thp tests
In reply to Andrew MortonFrom: Gavin Shan <[email protected]>
Subject: mm/debug_vm_pgtable: use struct pgtable_debug_args in migration and thp tests
This uses struct pgtable_debug_args in the migration and thp test functions. It's notable that the pre-allocated page is used in swap_migration_tests() as set_pte_at() is used there.
---
mm/debug_vm_pgtable.c | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-)
mm/debug_vm_pgtable.c renamed from mm/debug_vm_pgtable.c~mm-debug_vm_pgtable-use-struct-pgtable_debug_args-in-migration-and-thp-tests +17 -19
@@ -845,7 +845,7 @@ static void __init pmd_swap_tests(structstatic void __init pmd_swap_tests (struct pgtable_debug_args *args) { }#endif /* CONFIG_ARCH_ENABLE_THP_MIGRATION */ -static void __init swap_migration_tests (void ) +static void __init swap_migration_tests (struct pgtable_debug_args *args) {struct page *page;swp_entry_t swp;
@@ -853,19 +853,18 @@ static void __init swap_migration_tests(if (!IS_ENABLED (CONFIG_MIGRATION ))return ; -pr_debug ("Validating swap migration\n" );/* * swap_migration_tests() requires a dedicated page as it needs to * be locked before creating a migration entry from it. Locking the * page that actually maps kernel text ('start_kernel') can be real -* problematic. Lets allocate a dedicated page explicitly for this -* purpose that will be freed subsequently. +* problematic. Lets use the allocated page explicitly for this +* purpose. */ - page =alloc_page (GFP_KERNEL ); -if (!page) { -pr_err ("page allocation failed\n" ); + page = (args->pte_pfn !=ULONG_MAX ) ?pfn_to_page (args->pte_pfn) :NULL ; +if (!page)return ; - } + +pr_debug ("Validating swap migration\n" );/* * make_migration_entry() expects given page to be
@@ -884,7 +883,6 @@ static void __init swap_migration_tests(WARN_ON (!is_migration_entry (swp));WARN_ON (is_writable_migration_entry (swp));__ClearPageLocked (page); -__free_page (page); }#ifdef CONFIG_HUGETLB_PAGE
@@ -916,7 +914,7 @@ static void __init hugetlb_basic_tests(s#endif /* CONFIG_HUGETLB_PAGE */ #ifdef CONFIG_TRANSPARENT_HUGEPAGE -static void __init pmd_thp_tests (unsigned long pfn,pgprot_t prot) +static void __init pmd_thp_tests (struct pgtable_debug_args *args) {pmd_t pmd;
@@ -935,7 +933,7 @@ static void __init pmd_thp_tests(unsigne* needs to return true. pmd_present() should be true whenever * pmd_trans_huge() returns true. */ - pmd =pfn_pmd (pfn, prot); + pmd =pfn_pmd (args->fixed_pmd_pfn, args->page_prot);WARN_ON (!pmd_trans_huge (pmd_mkhuge (pmd)));#ifndef __HAVE_ARCH_PMDP_INVALIDATE
@@ -945,7 +943,7 @@ static void __init pmd_thp_tests(unsigne }#ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD -static void __init pud_thp_tests (unsigned long pfn,pgprot_t prot) +static void __init pud_thp_tests (struct pgtable_debug_args *args) {pud_t pud;
@@ -953,7 +951,7 @@ static void __init pud_thp_tests(unsignereturn ;pr_debug ("Validating PUD based THP\n" ); - pud =pfn_pud (pfn, prot); + pud =pfn_pud (args->fixed_pud_pfn, args->page_prot);WARN_ON (!pud_trans_huge (pud_mkhuge (pud)));/*
@@ -965,11 +963,11 @@ static void __init pud_thp_tests(unsigne*/ }#else /* !CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD */ -static void __init pud_thp_tests (unsigned long pfn,pgprot_t prot) { } +static void __init pud_thp_tests (struct pgtable_debug_args *args) { }#endif /* CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD */ #else /* !CONFIG_TRANSPARENT_HUGEPAGE */ -static void __init pmd_thp_tests (unsigned long pfn,pgprot_t prot) { } -static void __init pud_thp_tests (unsigned long pfn,pgprot_t prot) { } +static void __init pmd_thp_tests (struct pgtable_debug_args *args) { } +static void __init pud_thp_tests (struct pgtable_debug_args *args) { }#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ static unsigned long __init get_random_vaddr (void )
@@ -1335,10 +1333,10 @@ static int __init debug_vm_pgtable(void)pte_swap_tests (&args);pmd_swap_tests (&args); -swap_migration_tests (); +swap_migration_tests (&args); -pmd_thp_tests (pmd_aligned, prot); -pud_thp_tests (pud_aligned, prot); +pmd_thp_tests (&args); +pud_thp_tests (&args);hugetlb_basic_tests (&args);
_
Andrew Morton
maintainerPATCH 50/212 mm/debug_vm_pgtable: use struct pgtable_debug_args in PTE modifying tests
In reply to Andrew MortonFrom: Gavin Shan <[email protected]>
Subject: mm/debug_vm_pgtable: use struct pgtable_debug_args in PTE modifying tests
This uses struct pgtable_debug_args in PTE modifying tests. The allocated page is used as set_pte_at() is used there. The tests are skipped if the allocated page doesn't exist. It's notable that args->ptep need to be mapped before the tests. The reason why we don't map args->ptep at the beginning is PTE entry is only mapped and accessible in atomic context when CONFIG_HIGHPTE is enabled. So we avoid to do that so that atomic context is only enabled if needed.
Besides, the unused variable @pte_aligned and @ptep in debug_vm_pgtable() are dropped.
---
mm/debug_vm_pgtable.c | 67 +++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 35 deletions(-)
mm/debug_vm_pgtable.c renamed from mm/debug_vm_pgtable.c~mm-debug_vm_pgtable-use-struct-pgtable_debug_args-in-pte-modifying-tests +32 -35
@@ -117,10 +117,7 @@ static void __init pte_basic_tests(strucWARN_ON (!pte_dirty (pte_wrprotect (pte_mkdirty (pte)))); } -static void __init pte_advanced_tests (struct mm_struct *mm, -struct vm_area_struct *vma,pte_t *ptep, -unsigned long pfn,unsigned long vaddr, -pgprot_t prot) +static void __init pte_advanced_tests (struct pgtable_debug_args *args) {pte_t pte;
@@ -129,35 +126,37 @@ static void __init pte_advanced_tests(st* This requires set_pte_at to be not used to update an * existing pte entry. Clear pte before we do set_pte_at */ +if (args->pte_pfn ==ULONG_MAX ) +return ;pr_debug ("Validating PTE advanced\n" ); - pte =pfn_pte (pfn, prot); -set_pte_at (mm, vaddr, ptep, pte); -ptep_set_wrprotect (mm, vaddr, ptep); - pte =ptep_get (ptep); + pte =pfn_pte (args->pte_pfn, args->page_prot); +set_pte_at (args->mm, args->vaddr, args->ptep, pte); +ptep_set_wrprotect (args->mm, args->vaddr, args->ptep); + pte =ptep_get (args->ptep);WARN_ON (pte_write (pte)); -ptep_get_and_clear (mm, vaddr, ptep); - pte =ptep_get (ptep); +ptep_get_and_clear (args->mm, args->vaddr, args->ptep); + pte =ptep_get (args->ptep);WARN_ON (!pte_none (pte)); - pte =pfn_pte (pfn, prot); + pte =pfn_pte (args->pte_pfn, args->page_prot); pte =pte_wrprotect (pte); pte =pte_mkclean (pte); -set_pte_at (mm, vaddr, ptep, pte); +set_pte_at (args->mm, args->vaddr, args->ptep, pte); pte =pte_mkwrite (pte); pte =pte_mkdirty (pte); -ptep_set_access_flags (vma, vaddr, ptep, pte,1 ); - pte =ptep_get (ptep); +ptep_set_access_flags (args->vma, args->vaddr, args->ptep, pte,1 ); + pte =ptep_get (args->ptep);WARN_ON (!(pte_write (pte) &&pte_dirty (pte))); -ptep_get_and_clear_full (mm, vaddr, ptep,1 ); - pte =ptep_get (ptep); +ptep_get_and_clear_full (args->mm, args->vaddr, args->ptep,1 ); + pte =ptep_get (args->ptep);WARN_ON (!pte_none (pte)); - pte =pfn_pte (pfn, prot); + pte =pfn_pte (args->pte_pfn, args->page_prot); pte =pte_mkyoung (pte); -set_pte_at (mm, vaddr, ptep, pte); -ptep_test_and_clear_young (vma, vaddr, ptep); - pte =ptep_get (ptep); +set_pte_at (args->mm, args->vaddr, args->ptep, pte); +ptep_test_and_clear_young (args->vma, args->vaddr, args->ptep); + pte =ptep_get (args->ptep);WARN_ON (pte_young (pte)); }
@@ -618,20 +617,21 @@ static void __init pgd_populate_tests(st }#endif /* PAGETABLE_P4D_FOLDED */ -static void __init pte_clear_tests (struct mm_struct *mm,pte_t *ptep, -unsigned long pfn,unsigned long vaddr, -pgprot_t prot) +static void __init pte_clear_tests (struct pgtable_debug_args *args) { -pte_t pte =pfn_pte (pfn, prot); +pte_t pte =pfn_pte (args->pte_pfn, args->page_prot); + +if (args->pte_pfn ==ULONG_MAX ) +return ;pr_debug ("Validating PTE clear\n" );#ifndef CONFIG_RISCV pte =__pte (pte_val (pte) |RANDOM_ORVALUE );#endif -set_pte_at (mm, vaddr, ptep, pte); +set_pte_at (args->mm, args->vaddr, args->ptep, pte);barrier (); -pte_clear (mm, vaddr, ptep); - pte =ptep_get (ptep); +pte_clear (args->mm, args->vaddr, args->ptep); + pte =ptep_get (args->ptep);WARN_ON (!pte_none (pte)); }
@@ -1221,11 +1221,10 @@ static int __init debug_vm_pgtable(void)p4d_t *p4dp, *saved_p4dp;pud_t *pudp, *saved_pudp;pmd_t *pmdp, *saved_pmdp, pmd; -pte_t *ptep;pgtable_t saved_ptep;pgprot_t prot;phys_addr_t paddr; -unsigned long vaddr, pte_aligned, pmd_aligned; +unsigned long vaddr, pmd_aligned;unsigned long pud_aligned;spinlock_t *ptl =NULL ;int idx, ret;
@@ -1260,10 +1259,8 @@ static int __init debug_vm_pgtable(void)*/ paddr =__pa_symbol (&start_kernel); - pte_aligned = (paddr &PAGE_MASK ) >>PAGE_SHIFT ; pmd_aligned = (paddr &PMD_MASK ) >>PAGE_SHIFT ; pud_aligned = (paddr &PUD_MASK ) >>PAGE_SHIFT ; -WARN_ON (!pfn_valid (pte_aligned)); pgdp =pgd_offset (mm, vaddr); p4dp =p4d_alloc (mm, pgdp, vaddr);
@@ -1345,10 +1342,10 @@ static int __init debug_vm_pgtable(void)* proper page table lock. */ - ptep =pte_offset_map_lock (mm, pmdp, vaddr, &ptl); -pte_clear_tests (mm, ptep, pte_aligned, vaddr, prot); -pte_advanced_tests (mm, vma, ptep, pte_aligned, vaddr, prot); -pte_unmap_unlock (ptep, ptl); + args.ptep =pte_offset_map_lock (args.mm, args.pmdp, args.vaddr, &ptl); +pte_clear_tests (&args); +pte_advanced_tests (&args); +pte_unmap_unlock (args.ptep, ptl); ptl =pmd_lock (mm, pmdp);pmd_clear_tests (mm, pmdp);
_
Andrew Morton
maintainerPATCH 51/212 mm/debug_vm_pgtable: use struct pgtable_debug_args in PMD modifying tests
In reply to Andrew MortonFrom: Gavin Shan <[email protected]>
Subject: mm/debug_vm_pgtable: use struct pgtable_debug_args in PMD modifying tests
This uses struct pgtable_debug_args in PMD modifying tests. The allocated huge page is used when set_pmd_at() is used. The corresponding tests are skipped if the huge page doesn't exist. Besides, the unused variable @pmd_aligned in debug_vm_pgtable() is dropped.
---
mm/debug_vm_pgtable.c | 98 ++++++++++++++++++---------------------- 1 file changed, 46 insertions(+), 52 deletions(-)
mm/debug_vm_pgtable.c renamed from mm/debug_vm_pgtable.c~mm-debug_vm_pgtable-use-struct-pgtable_debug_args-in-pmd-modifying-tests +46 -52
@@ -211,54 +211,55 @@ static void __init pmd_basic_tests(strucWARN_ON (!pmd_bad (pmd_mkhuge (pmd))); } -static void __init pmd_advanced_tests (struct mm_struct *mm, -struct vm_area_struct *vma,pmd_t *pmdp, -unsigned long pfn,unsigned long vaddr, -pgprot_t prot,pgtable_t pgtable) +static void __init pmd_advanced_tests (struct pgtable_debug_args *args) {pmd_t pmd; +unsigned long vaddr = args->vaddr;if (!has_transparent_hugepage ())return ; +if (args->pmd_pfn ==ULONG_MAX ) +return ; +pr_debug ("Validating PMD advanced\n" );/* Align the address wrt HPAGE_PMD_SIZE */ vaddr &=HPAGE_PMD_MASK ; -pgtable_trans_huge_deposit (mm, pmdp, pgtable); +pgtable_trans_huge_deposit (args->mm, args->pmdp, args->start_ptep); - pmd =pfn_pmd (pfn, prot); -set_pmd_at (mm, vaddr, pmdp, pmd); -pmdp_set_wrprotect (mm, vaddr, pmdp); - pmd =READ_ONCE (*pmdp); + pmd =pfn_pmd (args->pmd_pfn, args->page_prot); +set_pmd_at (args->mm, vaddr, args->pmdp, pmd); +pmdp_set_wrprotect (args->mm, vaddr, args->pmdp); + pmd =READ_ONCE (*args->pmdp);WARN_ON (pmd_write (pmd)); -pmdp_huge_get_and_clear (mm, vaddr, pmdp); - pmd =READ_ONCE (*pmdp); +pmdp_huge_get_and_clear (args->mm, vaddr, args->pmdp); + pmd =READ_ONCE (*args->pmdp);WARN_ON (!pmd_none (pmd)); - pmd =pfn_pmd (pfn, prot); + pmd =pfn_pmd (args->pmd_pfn, args->page_prot); pmd =pmd_wrprotect (pmd); pmd =pmd_mkclean (pmd); -set_pmd_at (mm, vaddr, pmdp, pmd); +set_pmd_at (args->mm, vaddr, args->pmdp, pmd); pmd =pmd_mkwrite (pmd); pmd =pmd_mkdirty (pmd); -pmdp_set_access_flags (vma, vaddr, pmdp, pmd,1 ); - pmd =READ_ONCE (*pmdp); +pmdp_set_access_flags (args->vma, vaddr, args->pmdp, pmd,1 ); + pmd =READ_ONCE (*args->pmdp);WARN_ON (!(pmd_write (pmd) &&pmd_dirty (pmd))); -pmdp_huge_get_and_clear_full (vma, vaddr, pmdp,1 ); - pmd =READ_ONCE (*pmdp); +pmdp_huge_get_and_clear_full (args->vma, vaddr, args->pmdp,1 ); + pmd =READ_ONCE (*args->pmdp);WARN_ON (!pmd_none (pmd)); - pmd =pmd_mkhuge (pfn_pmd (pfn, prot)); + pmd =pmd_mkhuge (pfn_pmd (args->pmd_pfn, args->page_prot)); pmd =pmd_mkyoung (pmd); -set_pmd_at (mm, vaddr, pmdp, pmd); -pmdp_test_and_clear_young (vma, vaddr, pmdp); - pmd =READ_ONCE (*pmdp); +set_pmd_at (args->mm, vaddr, args->pmdp, pmd); +pmdp_test_and_clear_young (args->vma, vaddr, args->pmdp); + pmd =READ_ONCE (*args->pmdp);WARN_ON (pmd_young (pmd));/* Clear the pte entries */ -pmdp_huge_get_and_clear (mm, vaddr, pmdp); - pgtable =pgtable_trans_huge_withdraw (mm, pmdp); +pmdp_huge_get_and_clear (args->mm, vaddr, args->pmdp); +pgtable_trans_huge_withdraw (args->mm, args->pmdp); }static void __init pmd_leaf_tests (struct pgtable_debug_args *args)
@@ -415,12 +416,7 @@ static void __init pud_leaf_tests(struct#else /* !CONFIG_TRANSPARENT_HUGEPAGE */ static void __init pmd_basic_tests (struct pgtable_debug_args *args,int idx) { }static void __init pud_basic_tests (struct pgtable_debug_args *args,int idx) { } -static void __init pmd_advanced_tests (struct mm_struct *mm, -struct vm_area_struct *vma,pmd_t *pmdp, -unsigned long pfn,unsigned long vaddr, -pgprot_t prot,pgtable_t pgtable) -{ -} +static void __init pmd_advanced_tests (struct pgtable_debug_args *args) { } static void __init pud_advanced_tests(struct mm_struct *mm, struct vm_area_struct *vma, pud_t *pudp, unsigned long pfn, unsigned long vaddr,
@@ -433,11 +429,11 @@ static void __init pmd_savedwrite_tests(#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ #ifdef CONFIG_HAVE_ARCH_HUGE_VMAP -static void __init pmd_huge_tests (pmd_t *pmdp,unsigned long pfn,pgprot_t prot) +static void __init pmd_huge_tests (struct pgtable_debug_args *args) {pmd_t pmd; -if (!arch_vmap_pmd_supported (prot)) +if (!arch_vmap_pmd_supported (args->page_prot))return ;pr_debug ("Validating PMD huge\n" );
@@ -445,10 +441,10 @@ static void __init pmd_huge_tests(pmd_t* X86 defined pmd_set_huge() verifies that the given * PMD is not a populated non-leaf entry. */ -WRITE_ONCE (*pmdp,__pmd (0 )); -WARN_ON (!pmd_set_huge (pmdp,__pfn_to_phys (pfn), prot)); -WARN_ON (!pmd_clear_huge (pmdp)); - pmd =READ_ONCE (*pmdp); +WRITE_ONCE (*args->pmdp,__pmd (0 )); +WARN_ON (!pmd_set_huge (args->pmdp,__pfn_to_phys (args->fixed_pmd_pfn), args->page_prot)); +WARN_ON (!pmd_clear_huge (args->pmdp)); + pmd =READ_ONCE (*args->pmdp);WARN_ON (!pmd_none (pmd)); }
@@ -471,7 +467,7 @@ static void __init pud_huge_tests(pud_t WARN_ON(!pud_none(pud)); }#else /* !CONFIG_HAVE_ARCH_HUGE_VMAP */ -static void __init pmd_huge_tests (pmd_t *pmdp,unsigned long pfn,pgprot_t prot) { } +static void __init pmd_huge_tests (struct pgtable_debug_args *args) { }static void __init pud_huge_tests (pud_t *pudp,unsigned long pfn,pgprot_t prot) { }#endif /* CONFIG_HAVE_ARCH_HUGE_VMAP */
@@ -635,20 +631,19 @@ static void __init pte_clear_tests(strucWARN_ON (!pte_none (pte)); } -static void __init pmd_clear_tests (struct mm_struct *mm,pmd_t *pmdp) +static void __init pmd_clear_tests (struct pgtable_debug_args *args) { -pmd_t pmd =READ_ONCE (*pmdp); +pmd_t pmd =READ_ONCE (*args->pmdp);pr_debug ("Validating PMD clear\n" ); pmd =__pmd (pmd_val (pmd) |RANDOM_ORVALUE ); -WRITE_ONCE (*pmdp, pmd); -pmd_clear (pmdp); - pmd =READ_ONCE (*pmdp); +WRITE_ONCE (*args->pmdp, pmd); +pmd_clear (args->pmdp); + pmd =READ_ONCE (*args->pmdp);WARN_ON (!pmd_none (pmd)); } -static void __init pmd_populate_tests (struct mm_struct *mm,pmd_t *pmdp, -pgtable_t pgtable) +static void __init pmd_populate_tests (struct pgtable_debug_args *args) {pmd_t pmd;
@@ -657,8 +652,8 @@ static void __init pmd_populate_tests(st* This entry points to next level page table page. * Hence this must not qualify as pmd_bad(). */ -pmd_populate (mm, pmdp, pgtable); - pmd =READ_ONCE (*pmdp); +pmd_populate (args->mm, args->pmdp, args->start_ptep); + pmd =READ_ONCE (*args->pmdp);WARN_ON (pmd_bad (pmd)); }
@@ -1224,7 +1219,7 @@ static int __init debug_vm_pgtable(void)pgtable_t saved_ptep;pgprot_t prot;phys_addr_t paddr; -unsigned long vaddr, pmd_aligned; +unsigned long vaddr;unsigned long pud_aligned;spinlock_t *ptl =NULL ;int idx, ret;
@@ -1259,7 +1254,6 @@ static int __init debug_vm_pgtable(void)*/ paddr =__pa_symbol (&start_kernel); - pmd_aligned = (paddr &PMD_MASK ) >>PAGE_SHIFT ; pud_aligned = (paddr &PUD_MASK ) >>PAGE_SHIFT ; pgdp =pgd_offset (mm, vaddr);
@@ -1347,11 +1341,11 @@ static int __init debug_vm_pgtable(void)pte_advanced_tests (&args);pte_unmap_unlock (args.ptep, ptl); - ptl =pmd_lock (mm, pmdp); -pmd_clear_tests (mm, pmdp); -pmd_advanced_tests (mm, vma, pmdp, pmd_aligned, vaddr, prot, saved_ptep); -pmd_huge_tests (pmdp, pmd_aligned, prot); -pmd_populate_tests (mm, pmdp, saved_ptep); + ptl =pmd_lock (args.mm, args.pmdp); +pmd_clear_tests (&args); +pmd_advanced_tests (&args); +pmd_huge_tests (&args); +pmd_populate_tests (&args);spin_unlock (ptl); ptl =pud_lock (mm, pudp);
_
Andrew Morton
maintainerPATCH 52/212 mm/debug_vm_pgtable: use struct pgtable_debug_args in PUD modifying tests
In reply to Andrew MortonFrom: Gavin Shan <[email protected]>
Subject: mm/debug_vm_pgtable: use struct pgtable_debug_args in PUD modifying tests
This uses struct pgtable_debug_args in PUD modifying tests. The allocated huge page is used when set_pud_at() is used. The corresponding tests are skipped if the huge page doesn't exist. Besides, the following unused variables in debug_vm_pgtable() are dropped: @prot, @paddr, @pud_aligned.
---
mm/debug_vm_pgtable.c | 126 +++++++++++++++------------------------- 1 file changed, 48 insertions(+), 78 deletions(-)
mm/debug_vm_pgtable.c renamed from mm/debug_vm_pgtable.c~mm-debug_vm_pgtable-use-struct-pgtable_debug_args-in-pud-modifying-tests +48 -78
@@ -337,55 +337,56 @@ static void __init pud_basic_tests(strucWARN_ON (!pud_bad (pud_mkhuge (pud))); } -static void __init pud_advanced_tests (struct mm_struct *mm, -struct vm_area_struct *vma,pud_t *pudp, -unsigned long pfn,unsigned long vaddr, -pgprot_t prot) +static void __init pud_advanced_tests (struct pgtable_debug_args *args) { +unsigned long vaddr = args->vaddr;pud_t pud;if (!has_transparent_hugepage ())return ; +if (args->pud_pfn ==ULONG_MAX ) +return ; +pr_debug ("Validating PUD advanced\n" );/* Align the address wrt HPAGE_PUD_SIZE */ vaddr &=HPAGE_PUD_MASK ; - pud =pfn_pud (pfn, prot); -set_pud_at (mm, vaddr, pudp, pud); -pudp_set_wrprotect (mm, vaddr, pudp); - pud =READ_ONCE (*pudp); + pud =pfn_pud (args->pud_pfn, args->page_prot); +set_pud_at (args->mm, vaddr, args->pudp, pud); +pudp_set_wrprotect (args->mm, vaddr, args->pudp); + pud =READ_ONCE (*args->pudp);WARN_ON (pud_write (pud));#ifndef __PAGETABLE_PMD_FOLDED -pudp_huge_get_and_clear (mm, vaddr, pudp); - pud =READ_ONCE (*pudp); +pudp_huge_get_and_clear (args->mm, vaddr, args->pudp); + pud =READ_ONCE (*args->pudp);WARN_ON (!pud_none (pud));#endif /* __PAGETABLE_PMD_FOLDED */ - pud =pfn_pud (pfn, prot); + pud =pfn_pud (args->pud_pfn, args->page_prot); pud =pud_wrprotect (pud); pud =pud_mkclean (pud); -set_pud_at (mm, vaddr, pudp, pud); +set_pud_at (args->mm, vaddr, args->pudp, pud); pud =pud_mkwrite (pud); pud =pud_mkdirty (pud); -pudp_set_access_flags (vma, vaddr, pudp, pud,1 ); - pud =READ_ONCE (*pudp); +pudp_set_access_flags (args->vma, vaddr, args->pudp, pud,1 ); + pud =READ_ONCE (*args->pudp);WARN_ON (!(pud_write (pud) &&pud_dirty (pud)));#ifndef __PAGETABLE_PMD_FOLDED -pudp_huge_get_and_clear_full (mm, vaddr, pudp,1 ); - pud =READ_ONCE (*pudp); +pudp_huge_get_and_clear_full (args->mm, vaddr, args->pudp,1 ); + pud =READ_ONCE (*args->pudp);WARN_ON (!pud_none (pud));#endif /* __PAGETABLE_PMD_FOLDED */ - pud =pfn_pud (pfn, prot); + pud =pfn_pud (args->pud_pfn, args->page_prot); pud =pud_mkyoung (pud); -set_pud_at (mm, vaddr, pudp, pud); -pudp_test_and_clear_young (vma, vaddr, pudp); - pud =READ_ONCE (*pudp); +set_pud_at (args->mm, vaddr, args->pudp, pud); +pudp_test_and_clear_young (args->vma, vaddr, args->pudp); + pud =READ_ONCE (*args->pudp);WARN_ON (pud_young (pud)); -pudp_huge_get_and_clear (mm, vaddr, pudp); +pudp_huge_get_and_clear (args->mm, vaddr, args->pudp); }static void __init pud_leaf_tests (struct pgtable_debug_args *args)
@@ -405,24 +406,14 @@ static void __init pud_leaf_tests(struct }#else /* !CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD */ static void __init pud_basic_tests (struct pgtable_debug_args *args,int idx) { } -static void __init pud_advanced_tests (struct mm_struct *mm, -struct vm_area_struct *vma,pud_t *pudp, -unsigned long pfn,unsigned long vaddr, -pgprot_t prot) -{ -} +static void __init pud_advanced_tests (struct pgtable_debug_args *args) { }static void __init pud_leaf_tests (struct pgtable_debug_args *args) { }#endif /* CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD */ #else /* !CONFIG_TRANSPARENT_HUGEPAGE */ static void __init pmd_basic_tests (struct pgtable_debug_args *args,int idx) { }static void __init pud_basic_tests (struct pgtable_debug_args *args,int idx) { }static void __init pmd_advanced_tests (struct pgtable_debug_args *args) { } -static void __init pud_advanced_tests (struct mm_struct *mm, -struct vm_area_struct *vma,pud_t *pudp, -unsigned long pfn,unsigned long vaddr, -pgprot_t prot) -{ -} +static void __init pud_advanced_tests (struct pgtable_debug_args *args) { }static void __init pmd_leaf_tests (struct pgtable_debug_args *args) { }static void __init pud_leaf_tests (struct pgtable_debug_args *args) { }static void __init pmd_savedwrite_tests (struct pgtable_debug_args *args) { }
@@ -448,11 +439,11 @@ static void __init pmd_huge_tests(structWARN_ON (!pmd_none (pmd)); } -static void __init pud_huge_tests (pud_t *pudp,unsigned long pfn,pgprot_t prot) +static void __init pud_huge_tests (struct pgtable_debug_args *args) {pud_t pud; -if (!arch_vmap_pud_supported (prot)) +if (!arch_vmap_pud_supported (args->page_prot))return ;pr_debug ("Validating PUD huge\n" );
@@ -460,15 +451,15 @@ static void __init pud_huge_tests(pud_t* X86 defined pud_set_huge() verifies that the given * PUD is not a populated non-leaf entry. */ -WRITE_ONCE (*pudp,__pud (0 )); -WARN_ON (!pud_set_huge (pudp,__pfn_to_phys (pfn), prot)); -WARN_ON (!pud_clear_huge (pudp)); - pud =READ_ONCE (*pudp); +WRITE_ONCE (*args->pudp,__pud (0 )); +WARN_ON (!pud_set_huge (args->pudp,__pfn_to_phys (args->fixed_pud_pfn), args->page_prot)); +WARN_ON (!pud_clear_huge (args->pudp)); + pud =READ_ONCE (*args->pudp); WARN_ON(!pud_none(pud)); }#else /* !CONFIG_HAVE_ARCH_HUGE_VMAP */ static void __init pmd_huge_tests (struct pgtable_debug_args *args) { } -static void __init pud_huge_tests (pud_t *pudp,unsigned long pfn,pgprot_t prot) { } +static void __init pud_huge_tests (struct pgtable_debug_args *args) { }#endif /* CONFIG_HAVE_ARCH_HUGE_VMAP */ static void __init p4d_basic_tests (struct pgtable_debug_args *args)
@@ -490,27 +481,26 @@ static void __init pgd_basic_tests(struc }#ifndef __PAGETABLE_PUD_FOLDED -static void __init pud_clear_tests (struct mm_struct *mm,pud_t *pudp) +static void __init pud_clear_tests (struct pgtable_debug_args *args) { -pud_t pud =READ_ONCE (*pudp); +pud_t pud =READ_ONCE (*args->pudp); -if (mm_pmd_folded (mm)) +if (mm_pmd_folded (args->mm))return ;pr_debug ("Validating PUD clear\n" ); pud =__pud (pud_val (pud) |RANDOM_ORVALUE ); -WRITE_ONCE (*pudp, pud); -pud_clear (pudp); - pud =READ_ONCE (*pudp); +WRITE_ONCE (*args->pudp, pud); +pud_clear (args->pudp); + pud =READ_ONCE (*args->pudp);WARN_ON (!pud_none (pud)); } -static void __init pud_populate_tests (struct mm_struct *mm,pud_t *pudp, -pmd_t *pmdp) +static void __init pud_populate_tests (struct pgtable_debug_args *args) {pud_t pud; -if (mm_pmd_folded (mm)) +if (mm_pmd_folded (args->mm))return ;pr_debug ("Validating PUD populate\n" );
@@ -518,16 +508,13 @@ static void __init pud_populate_tests(st* This entry points to next level page table page. * Hence this must not qualify as pud_bad(). */ -pud_populate (mm, pudp, pmdp); - pud =READ_ONCE (*pudp); +pud_populate (args->mm, args->pudp, args->start_pmdp); + pud =READ_ONCE (*args->pudp); WARN_ON(pud_bad(pud)); }#else /* !__PAGETABLE_PUD_FOLDED */ -static void __init pud_clear_tests (struct mm_struct *mm,pud_t *pudp) { } -static void __init pud_populate_tests (struct mm_struct *mm,pud_t *pudp, -pmd_t *pmdp) -{ -} +static void __init pud_clear_tests (struct pgtable_debug_args *args) { } +static void __init pud_populate_tests (struct pgtable_debug_args *args) { }#endif /* PAGETABLE_PUD_FOLDED */ #ifndef __PAGETABLE_P4D_FOLDED
@@ -1217,10 +1204,7 @@ static int __init debug_vm_pgtable(void)pud_t *pudp, *saved_pudp;pmd_t *pmdp, *saved_pmdp, pmd;pgtable_t saved_ptep; -pgprot_t prot; -phys_addr_t paddr;unsigned long vaddr; -unsigned long pud_aligned;spinlock_t *ptl =NULL ;int idx, ret;
@@ -1229,7 +1213,6 @@ static int __init debug_vm_pgtable(void)if (ret)return ret; - prot =vm_get_page_prot (VMFLAGS ); vaddr =get_random_vaddr (); mm =mm_alloc ();if (!mm) {
@@ -1243,19 +1226,6 @@ static int __init debug_vm_pgtable(void)return 1 ; } -/* -* PFN for mapping at PTE level is determined from a standard kernel -* text symbol. But pfns for higher page table levels are derived by -* masking lower bits of this real pfn. These derived pfns might not -* exist on the platform but that does not really matter as pfn_pxx() -* helpers will still create appropriate entries for the test. This -* helps avoid large memory block allocations to be used for mapping -* at higher page table levels. -*/ - paddr =__pa_symbol (&start_kernel); - - pud_aligned = (paddr &PUD_MASK ) >>PAGE_SHIFT ; - pgdp =pgd_offset (mm, vaddr); p4dp =p4d_alloc (mm, pgdp, vaddr); pudp =pud_alloc (mm, p4dp, vaddr);
@@ -1348,11 +1318,11 @@ static int __init debug_vm_pgtable(void)pmd_populate_tests (&args);spin_unlock (ptl); - ptl =pud_lock (mm, pudp); -pud_clear_tests (mm, pudp); -pud_advanced_tests (mm, vma, pudp, pud_aligned, vaddr, prot); -pud_huge_tests (pudp, pud_aligned, prot); -pud_populate_tests (mm, pudp, saved_pmdp); + ptl =pud_lock (args.mm, args.pudp); +pud_clear_tests (&args); +pud_advanced_tests (&args); +pud_huge_tests (&args); +pud_populate_tests (&args);spin_unlock (ptl);spin_lock (&mm->page_table_lock);
_
Andrew Morton
maintainerPATCH 53/212 mm/debug_vm_pgtable: use struct pgtable_debug_args in PGD and P4D modifying tests
In reply to Andrew MortonFrom: Gavin Shan <[email protected]>
Subject: mm/debug_vm_pgtable: use struct pgtable_debug_args in PGD and P4D modifying tests
This uses struct pgtable_debug_args in PGD/P4D modifying tests. No allocated huge page is used in these tests. Besides, the unused variable @saved_p4dp and @saved_pudp are dropped.
---
mm/debug_vm_pgtable.c | 86 +++++++++++++++++----------------------- 1 file changed, 38 insertions(+), 48 deletions(-)
mm/debug_vm_pgtable.c renamed from mm/debug_vm_pgtable.c~mm-debug_vm_pgtable-use-struct-pgtable_debug_args-in-pgd-and-p4d-modifying-tests +38 -48
@@ -518,27 +518,26 @@ static void __init pud_populate_tests(st#endif /* PAGETABLE_PUD_FOLDED */ #ifndef __PAGETABLE_P4D_FOLDED -static void __init p4d_clear_tests (struct mm_struct *mm,p4d_t *p4dp) +static void __init p4d_clear_tests (struct pgtable_debug_args *args) { -p4d_t p4d =READ_ONCE (*p4dp); +p4d_t p4d =READ_ONCE (*args->p4dp); -if (mm_pud_folded (mm)) +if (mm_pud_folded (args->mm))return ;pr_debug ("Validating P4D clear\n" ); p4d =__p4d (p4d_val (p4d) |RANDOM_ORVALUE ); -WRITE_ONCE (*p4dp, p4d); -p4d_clear (p4dp); - p4d =READ_ONCE (*p4dp); +WRITE_ONCE (*args->p4dp, p4d); +p4d_clear (args->p4dp); + p4d =READ_ONCE (*args->p4dp);WARN_ON (!p4d_none (p4d)); } -static void __init p4d_populate_tests (struct mm_struct *mm,p4d_t *p4dp, -pud_t *pudp) +static void __init p4d_populate_tests (struct pgtable_debug_args *args) {p4d_t p4d; -if (mm_pud_folded (mm)) +if (mm_pud_folded (args->mm))return ;pr_debug ("Validating P4D populate\n" );
@@ -546,34 +545,33 @@ static void __init p4d_populate_tests(st* This entry points to next level page table page. * Hence this must not qualify as p4d_bad(). */ -pud_clear (pudp); -p4d_clear (p4dp); -p4d_populate (mm, p4dp, pudp); - p4d =READ_ONCE (*p4dp); +pud_clear (args->pudp); +p4d_clear (args->p4dp); +p4d_populate (args->mm, args->p4dp, args->start_pudp); + p4d =READ_ONCE (*args->p4dp);WARN_ON (p4d_bad (p4d)); } -static void __init pgd_clear_tests (struct mm_struct *mm,pgd_t *pgdp) +static void __init pgd_clear_tests (struct pgtable_debug_args *args) { -pgd_t pgd =READ_ONCE (*pgdp); +pgd_t pgd =READ_ONCE (*(args->pgdp)); -if (mm_p4d_folded (mm)) +if (mm_p4d_folded (args->mm))return ;pr_debug ("Validating PGD clear\n" ); pgd =__pgd (pgd_val (pgd) |RANDOM_ORVALUE ); -WRITE_ONCE (*pgdp, pgd); -pgd_clear (pgdp); - pgd =READ_ONCE (*pgdp); +WRITE_ONCE (*args->pgdp, pgd); +pgd_clear (args->pgdp); + pgd =READ_ONCE (*args->pgdp);WARN_ON (!pgd_none (pgd)); } -static void __init pgd_populate_tests (struct mm_struct *mm,pgd_t *pgdp, -p4d_t *p4dp) +static void __init pgd_populate_tests (struct pgtable_debug_args *args) {pgd_t pgd; -if (mm_p4d_folded (mm)) +if (mm_p4d_folded (args->mm))return ;pr_debug ("Validating PGD populate\n" );
@@ -581,23 +579,17 @@ static void __init pgd_populate_tests(st* This entry points to next level page table page. * Hence this must not qualify as pgd_bad(). */ -p4d_clear (p4dp); -pgd_clear (pgdp); -pgd_populate (mm, pgdp, p4dp); - pgd =READ_ONCE (*pgdp); +p4d_clear (args->p4dp); +pgd_clear (args->pgdp); +pgd_populate (args->mm, args->pgdp, args->start_p4dp); + pgd =READ_ONCE (*args->pgdp); WARN_ON(pgd_bad(pgd)); }#else /* !__PAGETABLE_P4D_FOLDED */ -static void __init p4d_clear_tests (struct mm_struct *mm,p4d_t *p4dp) { } -static void __init pgd_clear_tests (struct mm_struct *mm,pgd_t *pgdp) { } -static void __init p4d_populate_tests (struct mm_struct *mm,p4d_t *p4dp, -pud_t *pudp) -{ -} -static void __init pgd_populate_tests (struct mm_struct *mm,pgd_t *pgdp, -p4d_t *p4dp) -{ -} +static void __init p4d_clear_tests (struct pgtable_debug_args *args) { } +static void __init pgd_clear_tests (struct pgtable_debug_args *args) { } +static void __init p4d_populate_tests (struct pgtable_debug_args *args) { } +static void __init pgd_populate_tests (struct pgtable_debug_args *args) { }#endif /* PAGETABLE_P4D_FOLDED */ static void __init pte_clear_tests (struct pgtable_debug_args *args)
@@ -1200,8 +1192,8 @@ static int __init debug_vm_pgtable(void)struct vm_area_struct *vma;struct mm_struct *mm;pgd_t *pgdp; -p4d_t *p4dp, *saved_p4dp; -pud_t *pudp, *saved_pudp; +p4d_t *p4dp; +pud_t *pudp;pmd_t *pmdp, *saved_pmdp, pmd;pgtable_t saved_ptep;unsigned long vaddr;
@@ -1245,8 +1237,6 @@ static int __init debug_vm_pgtable(void)* page table pages. */ pmd =READ_ONCE (*pmdp); - saved_p4dp =p4d_offset (pgdp,0UL ); - saved_pudp =pud_offset (p4dp,0UL ); saved_pmdp =pmd_offset (pudp,0UL ); saved_ptep =pmd_pgtable (pmd);
@@ -1325,15 +1315,15 @@ static int __init debug_vm_pgtable(void)pud_populate_tests (&args);spin_unlock (ptl); -spin_lock (&mm->page_table_lock); -p4d_clear_tests (mm, p4dp); -pgd_clear_tests (mm, pgdp); -p4d_populate_tests (mm, p4dp, saved_pudp); -pgd_populate_tests (mm, pgdp, saved_p4dp); -spin_unlock (&mm->page_table_lock); +spin_lock (&(args.mm->page_table_lock)); +p4d_clear_tests (&args); +pgd_clear_tests (&args); +p4d_populate_tests (&args); +pgd_populate_tests (&args); +spin_unlock (&(args.mm->page_table_lock)); -p4d_free (mm, saved_p4dp); -pud_free (mm, saved_pudp); +p4d_free (mm,p4d_offset (pgdp,0UL )); +pud_free (mm,pud_offset (p4dp,0UL ));pmd_free (mm, saved_pmdp);pte_free (mm, saved_ptep);
_
Andrew Morton
maintainerPATCH 54/212 mm/debug_vm_pgtable: remove unused code
In reply to Andrew MortonFrom: Gavin Shan <[email protected]>
Subject: mm/debug_vm_pgtable: remove unused code
The variables used by old implementation isn't needed as we switched to "struct pgtable_debug_args". Lets remove them and related code in debug_vm_pgtable().
---
mm/debug_vm_pgtable.c | 54 ---------------------------------------- 1 file changed, 54 deletions(-)
mm/debug_vm_pgtable.c renamed from mm/debug_vm_pgtable.c~mm-debug_vm_pgtable-remove-unused-code +0 -54
@@ -1189,14 +1189,6 @@ error:static int __init debug_vm_pgtable (void ) {struct pgtable_debug_args args; -struct vm_area_struct *vma; -struct mm_struct *mm; -pgd_t *pgdp; -p4d_t *p4dp; -pud_t *pudp; -pmd_t *pmdp, *saved_pmdp, pmd; -pgtable_t saved_ptep; -unsigned long vaddr;spinlock_t *ptl =NULL ;int idx, ret;
@@ -1205,41 +1197,6 @@ static int __init debug_vm_pgtable(void)if (ret)return ret; - vaddr =get_random_vaddr (); - mm =mm_alloc (); -if (!mm) { -pr_err ("mm_struct allocation failed\n" ); -return 1 ; - } - - vma =vm_area_alloc (mm); -if (!vma) { -pr_err ("vma allocation failed\n" ); -return 1 ; - } - - pgdp =pgd_offset (mm, vaddr); - p4dp =p4d_alloc (mm, pgdp, vaddr); - pudp =pud_alloc (mm, p4dp, vaddr); - pmdp =pmd_alloc (mm, pudp, vaddr); -/* -* Allocate pgtable_t -*/ -if (pte_alloc (mm, pmdp)) { -pr_err ("pgtable allocation failed\n" ); -return 1 ; - } - -/* -* Save all the page table page addresses as the page table -* entries will be used for testing with random or garbage -* values. These saved addresses will be used for freeing -* page table pages. -*/ - pmd =READ_ONCE (*pmdp); - saved_pmdp =pmd_offset (pudp,0UL ); - saved_ptep =pmd_pgtable (pmd); -/* * Iterate over the protection_map[] to make sure that all * the basic page table transformation validations just hold
@@ -1322,17 +1279,6 @@ static int __init debug_vm_pgtable(void)pgd_populate_tests (&args);spin_unlock (&(args.mm->page_table_lock)); -p4d_free (mm,p4d_offset (pgdp,0UL )); -pud_free (mm,pud_offset (p4dp,0UL )); -pmd_free (mm, saved_pmdp); -pte_free (mm, saved_ptep); - -vm_area_free (vma); -mm_dec_nr_puds (mm); -mm_dec_nr_pmds (mm); -mm_dec_nr_ptes (mm); -mmdrop (mm); -destroy_args (&args);return 0 ; }
_
Andrew Morton
maintainerPATCH 55/212 mm/debug_vm_pgtable: fix corrupted page flag
In reply to Andrew MortonFrom: Gavin Shan <[email protected]>
Subject: mm/debug_vm_pgtable: fix corrupted page flag
In page table entry modifying tests, set_xxx_at() are used to populate the page table entries. On ARM64, PG_arch_1 (PG_dcache_clean) flag is set to the target page flag if execution permission is given. The logic exits since commit 4f04d8f00545 ("arm64: MMU definitions"). The page flag is kept when the page is free'd to buddy's free area list. However, it will trigger page checking failure when it's pulled from the buddy's free area list, as the following warning messages indicate.
BUG: Bad page state in process memhog pfn:08000
page:0000000015c0a628 refcount:0 mapcount:0 \
mapping:0000000000000000 index:0x1 pfn:0x8000
flags: 0x7ffff8000000800(arch_1|node=0|zone=0|lastcpupid=0xfffff)
raw: 07ffff8000000800 dead000000000100 dead000000000122 0000000000000000
raw: 0000000000000001 0000000000000000 00000000ffffffff 0000000000000000
page dumped because: PAGE_FLAGS_CHECK_AT_PREP flag(s) setThis fixes the issue by clearing PG_arch_1 through flush_dcache_page() after set_xxx_at() is called. For architectures other than ARM64, the unexpected overhead of cache flushing is acceptable.
---
mm/debug_vm_pgtable.c | 55 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 4 deletions(-)
mm/debug_vm_pgtable.c renamed from mm/debug_vm_pgtable.c~mm-debug_vm_pgtable-fix-corrupted-page-flag +51 -4
@@ -29,6 +29,8 @@#include <linux/start_kernel.h> #include <linux/sched/mm.h> #include <linux/io.h> + +#include <asm/cacheflush.h> #include <asm/pgalloc.h> #include <asm/tlbflush.h>
@@ -119,19 +121,28 @@ static void __init pte_basic_tests(strucstatic void __init pte_advanced_tests (struct pgtable_debug_args *args) { +struct page *page;pte_t pte;/* * Architectures optimize set_pte_at by avoiding TLB flush. * This requires set_pte_at to be not used to update an * existing pte entry. Clear pte before we do set_pte_at +* +* flush_dcache_page() is called after set_pte_at() to clear +* PG_arch_1 for the page on ARM64. The page flag isn't cleared +* when it's released and page allocation check will fail when +* the page is allocated again. For architectures other than ARM64, +* the unexpected overhead of cache flushing is acceptable. */ -if (args->pte_pfn ==ULONG_MAX ) + page = (args->pte_pfn !=ULONG_MAX ) ?pfn_to_page (args->pte_pfn) :NULL ; +if (!page)return ;pr_debug ("Validating PTE advanced\n" ); pte =pfn_pte (args->pte_pfn, args->page_prot);set_pte_at (args->mm, args->vaddr, args->ptep, pte); +flush_dcache_page (page);ptep_set_wrprotect (args->mm, args->vaddr, args->ptep); pte =ptep_get (args->ptep);WARN_ON (pte_write (pte));
@@ -143,6 +154,7 @@ static void __init pte_advanced_tests(st pte =pte_wrprotect (pte); pte =pte_mkclean (pte);set_pte_at (args->mm, args->vaddr, args->ptep, pte); +flush_dcache_page (page); pte =pte_mkwrite (pte); pte =pte_mkdirty (pte);ptep_set_access_flags (args->vma, args->vaddr, args->ptep, pte,1 );
@@ -155,6 +167,7 @@ static void __init pte_advanced_tests(st pte =pfn_pte (args->pte_pfn, args->page_prot); pte =pte_mkyoung (pte);set_pte_at (args->mm, args->vaddr, args->ptep, pte); +flush_dcache_page (page);ptep_test_and_clear_young (args->vma, args->vaddr, args->ptep); pte =ptep_get (args->ptep);WARN_ON (pte_young (pte));
@@ -213,15 +226,24 @@ static void __init pmd_basic_tests(strucstatic void __init pmd_advanced_tests (struct pgtable_debug_args *args) { +struct page *page;pmd_t pmd;unsigned long vaddr = args->vaddr;if (!has_transparent_hugepage ())return ; -if (args->pmd_pfn ==ULONG_MAX ) + page = (args->pmd_pfn !=ULONG_MAX ) ?pfn_to_page (args->pmd_pfn) :NULL ; +if (!page)return ; +/* +* flush_dcache_page() is called after set_pmd_at() to clear +* PG_arch_1 for the page on ARM64. The page flag isn't cleared +* when it's released and page allocation check will fail when +* the page is allocated again. For architectures other than ARM64, +* the unexpected overhead of cache flushing is acceptable. +*/ pr_debug ("Validating PMD advanced\n" );/* Align the address wrt HPAGE_PMD_SIZE */ vaddr &=HPAGE_PMD_MASK ;
@@ -230,6 +252,7 @@ static void __init pmd_advanced_tests(st pmd =pfn_pmd (args->pmd_pfn, args->page_prot);set_pmd_at (args->mm, vaddr, args->pmdp, pmd); +flush_dcache_page (page);pmdp_set_wrprotect (args->mm, vaddr, args->pmdp); pmd =READ_ONCE (*args->pmdp);WARN_ON (pmd_write (pmd));
@@ -241,6 +264,7 @@ static void __init pmd_advanced_tests(st pmd =pmd_wrprotect (pmd); pmd =pmd_mkclean (pmd);set_pmd_at (args->mm, vaddr, args->pmdp, pmd); +flush_dcache_page (page); pmd =pmd_mkwrite (pmd); pmd =pmd_mkdirty (pmd);pmdp_set_access_flags (args->vma, vaddr, args->pmdp, pmd,1 );
@@ -253,6 +277,7 @@ static void __init pmd_advanced_tests(st pmd =pmd_mkhuge (pfn_pmd (args->pmd_pfn, args->page_prot)); pmd =pmd_mkyoung (pmd);set_pmd_at (args->mm, vaddr, args->pmdp, pmd); +flush_dcache_page (page);pmdp_test_and_clear_young (args->vma, vaddr, args->pmdp); pmd =READ_ONCE (*args->pmdp);WARN_ON (pmd_young (pmd));
@@ -339,21 +364,31 @@ static void __init pud_basic_tests(strucstatic void __init pud_advanced_tests (struct pgtable_debug_args *args) { +struct page *page;unsigned long vaddr = args->vaddr;pud_t pud;if (!has_transparent_hugepage ())return ; -if (args->pud_pfn ==ULONG_MAX ) + page = (args->pud_pfn !=ULONG_MAX ) ?pfn_to_page (args->pud_pfn) :NULL ; +if (!page)return ; +/* +* flush_dcache_page() is called after set_pud_at() to clear +* PG_arch_1 for the page on ARM64. The page flag isn't cleared +* when it's released and page allocation check will fail when +* the page is allocated again. For architectures other than ARM64, +* the unexpected overhead of cache flushing is acceptable. +*/ pr_debug ("Validating PUD advanced\n" );/* Align the address wrt HPAGE_PUD_SIZE */ vaddr &=HPAGE_PUD_MASK ; pud =pfn_pud (args->pud_pfn, args->page_prot);set_pud_at (args->mm, vaddr, args->pudp, pud); +flush_dcache_page (page);pudp_set_wrprotect (args->mm, vaddr, args->pudp); pud =READ_ONCE (*args->pudp);WARN_ON (pud_write (pud));
@@ -367,6 +402,7 @@ static void __init pud_advanced_tests(st pud =pud_wrprotect (pud); pud =pud_mkclean (pud);set_pud_at (args->mm, vaddr, args->pudp, pud); +flush_dcache_page (page); pud =pud_mkwrite (pud); pud =pud_mkdirty (pud);pudp_set_access_flags (args->vma, vaddr, args->pudp, pud,1 );
@@ -382,6 +418,7 @@ static void __init pud_advanced_tests(st pud =pfn_pud (args->pud_pfn, args->page_prot); pud =pud_mkyoung (pud);set_pud_at (args->mm, vaddr, args->pudp, pud); +flush_dcache_page (page);pudp_test_and_clear_young (args->vma, vaddr, args->pudp); pud =READ_ONCE (*args->pudp);WARN_ON (pud_young (pud));
@@ -594,16 +631,26 @@ static void __init pgd_populate_tests(ststatic void __init pte_clear_tests (struct pgtable_debug_args *args) { +struct page *page;pte_t pte =pfn_pte (args->pte_pfn, args->page_prot); -if (args->pte_pfn ==ULONG_MAX ) + page = (args->pte_pfn !=ULONG_MAX ) ?pfn_to_page (args->pte_pfn) :NULL ; +if (!page)return ; +/* +* flush_dcache_page() is called after set_pte_at() to clear +* PG_arch_1 for the page on ARM64. The page flag isn't cleared +* when it's released and page allocation check will fail when +* the page is allocated again. For architectures other than ARM64, +* the unexpected overhead of cache flushing is acceptable. +*/ pr_debug ("Validating PTE clear\n" );#ifndef CONFIG_RISCV pte =__pte (pte_val (pte) |RANDOM_ORVALUE );#endif set_pte_at (args->mm, args->vaddr, args->ptep, pte); +flush_dcache_page (page);barrier ();pte_clear (args->mm, args->vaddr, args->ptep); pte =ptep_get (args->ptep);
_
Andrew Morton
maintainerPATCH 56/212 mm: report a more useful address for reclaim acquisition
In reply to Andrew MortonFrom: "Matthew Wilcox (Oracle)" <[email protected]>
Subject: mm: report a more useful address for reclaim acquisition
A recent lockdep report included these lines:
[ 96.177910] 3 locks held by containerd/770:
[ 96.177934] #0: ffff88810815ea28 (&mm->mmap_lock#2){++++}-{3:3},
at: do_user_addr_fault+0x115/0x770
[ 96.177999] #1: ffffffff82915020 (rcu_read_lock){....}-{1:2}, at:
get_swap_device+0x33/0x140
[ 96.178057] #2: ffffffff82955ba0 (fs_reclaim){+.+.}-{0:0}, at:__fs_reclaim_acquire+0x5/0x30
While it was not useful to that bug report to know where the reclaim lock had been acquired, it might be useful under other circumstances. Allow the caller of __fs_reclaim_acquire to specify the instruction pointer to use.
---
include/linux/sched/mm.h | 8 ++++---- mm/page_alloc.c | 12 ++++++------ mm/vmscan.c | 8 ++++---- 3 files changed, 14 insertions(+), 14 deletions(-)
include/linux/sched/mm.h renamed from include/linux/sched/mm.h~mm-report-a-more-useful-address-for-reclaim-acquisition +4 -4
@@ -174,13 +174,13 @@ static inline gfp_t current_gfp_context( }#ifdef CONFIG_LOCKDEP -extern void __fs_reclaim_acquire (void ); -extern void __fs_reclaim_release (void ); +extern void __fs_reclaim_acquire (unsigned long ip); +extern void __fs_reclaim_release (unsigned long ip);extern void fs_reclaim_acquire (gfp_t gfp_mask);extern void fs_reclaim_release (gfp_t gfp_mask);#else -static inline void __fs_reclaim_acquire (void ) { } -static inline void __fs_reclaim_release (void ) { } +static inline void __fs_reclaim_acquire (unsigned long ip) { } +static inline void __fs_reclaim_release (unsigned long ip) { }static inline void fs_reclaim_acquire (gfp_t gfp_mask) { }static inline void fs_reclaim_release (gfp_t gfp_mask) { }#endif
mm/page_alloc.c renamed from mm/page_alloc.c~mm-report-a-more-useful-address-for-reclaim-acquisition +6 -6
@@ -4549,14 +4549,14 @@ static bool __need_reclaim(gfp_t gfp_masreturn true; } -void __fs_reclaim_acquire (void ) +void __fs_reclaim_acquire (unsigned long ip) { -lock_map_acquire (&__fs_reclaim_map); +lock_acquire_exclusive (&__fs_reclaim_map,0 ,0 ,NULL , ip); } -void __fs_reclaim_release (void ) +void __fs_reclaim_release (unsigned long ip) { -lock_map_release (&__fs_reclaim_map); +lock_release (&__fs_reclaim_map, ip); }void fs_reclaim_acquire (gfp_t gfp_mask)
@@ -4565,7 +4565,7 @@ void fs_reclaim_acquire(gfp_t gfp_mask)if (__need_reclaim (gfp_mask)) {if (gfp_mask & __GFP_FS) -__fs_reclaim_acquire (); +__fs_reclaim_acquire (_RET_IP_);#ifdef CONFIG_MMU_NOTIFIER lock_map_acquire (&__mmu_notifier_invalidate_range_start_map);
@@ -4582,7 +4582,7 @@ void fs_reclaim_release(gfp_t gfp_mask)if (__need_reclaim (gfp_mask)) {if (gfp_mask & __GFP_FS) -__fs_reclaim_release (); +__fs_reclaim_release (_RET_IP_); } }EXPORT_SYMBOL_GPL (fs_reclaim_release);
mm/vmscan.c renamed from mm/vmscan.c~mm-report-a-more-useful-address-for-reclaim-acquisition +4 -4
@@ -3812,7 +3812,7 @@ static int balance_pgdat(pg_data_t *pgdaset_task_reclaim_state (current, &sc.reclaim_state);psi_memstall_enter (&pflags); -__fs_reclaim_acquire (); +__fs_reclaim_acquire (_THIS_IP_);count_vm_event (PAGEOUTRUN );
@@ -3938,9 +3938,9 @@ restart:wake_up_all (&pgdat->pfmemalloc_wait);/* Check if kswapd should be suspending */ -__fs_reclaim_release (); +__fs_reclaim_release (_THIS_IP_); ret =try_to_freeze (); -__fs_reclaim_acquire (); +__fs_reclaim_acquire (_THIS_IP_);if (ret ||kthread_should_stop ())break ;
@@ -3992,7 +3992,7 @@ out: }snapshot_refaults (NULL , pgdat); -__fs_reclaim_release (); +__fs_reclaim_release (_THIS_IP_);psi_memstall_leave (&pflags);set_task_reclaim_state (current,NULL );
_
Andrew Morton
maintainerPATCH 57/212 mm: add kernel_misc_reclaimable in show_free_areas
In reply to Andrew MortonFrom: liuhailong <[email protected]>
Subject: mm: add kernel_misc_reclaimable in show_free_areas
Print NR_KERNEL_MISC_RECLAIMABLE stat from show_free_areas() so users can check whether the shrinker is working correctly and to show the current memory usage.
---
mm/page_alloc.c | 2 ++ 1 file changed, 2 insertions(+)
mm/page_alloc.c renamed from mm/page_alloc.c~mm-add-kernel_misc_reclaimable-in-show_free_areas +2 -0
@@ -5903,6 +5903,7 @@ void show_free_areas(unsigned int filter" unevictable:%lu dirty:%lu writeback:%lu\n" " slab_reclaimable:%lu slab_unreclaimable:%lu\n" " mapped:%lu shmem:%lu pagetables:%lu bounce:%lu\n" +" kernel_misc_reclaimable:%lu\n" " free:%lu free_pcp:%lu free_cma:%lu\n" ,global_node_page_state (NR_ACTIVE_ANON ), global_node_page_state(NR_INACTIVE_ANON),
@@ -5919,6 +5920,7 @@ void show_free_areas(unsigned int filterglobal_node_page_state (NR_SHMEM ),global_node_page_state (NR_PAGETABLE ),global_zone_page_state (NR_BOUNCE ), +global_node_page_state (NR_KERNEL_MISC_RECLAIMABLE ),global_zone_page_state (NR_FREE_PAGES ), free_pcp, global_zone_page_state(NR_FREE_CMA_PAGES));
_
Andrew Morton
maintainerPATCH 58/212 writeback: track number of inodes under writeback
In reply to Andrew MortonFrom: Jan Kara <[email protected]>
Subject: writeback: track number of inodes under writeback
Patch series "writeback: Fix bandwidth estimates", v4.
Fix estimate of writeback throughput when device is not fully busy doing writeback. Michael Stapelberg has reported that such workload (e.g. generated by linking) tends to push estimated throughput down to 0 and as a result writeback on the device is practically stalled.
The first three patches fix the reported issue, the remaining two patches are unrelated cleanups of problems I've noticed when reading the code.
This patch (of 4):
Track number of inodes under writeback for each bdi_writeback structure. We will use this to decide whether wb does any IO and so we can estimate its writeback throughput. In principle we could use number of pages under writeback (WB_WRITEBACK counter) for this however normal percpu counter reads are too inaccurate for our purposes and summing the counter is too expensive.
---
fs/fs-writeback.c | 5 +++++ include/linux/backing-dev-defs.h | 1 + mm/backing-dev.c | 1 + mm/page-writeback.c | 22 ++++++++++++++++++++-- 4 files changed, 27 insertions(+), 2 deletions(-)
fs/fs-writeback.c renamed from fs/fs-writeback.c~writeback-track-number-of-inodes-under-writeback +5 -0
@@ -406,6 +406,11 @@ static bool inode_do_switch_wbs(struct iinc_wb_stat (new_wb,WB_WRITEBACK ); } +if (mapping_tagged (mapping,PAGECACHE_TAG_WRITEBACK )) { +atomic_dec (&old_wb->writeback_inodes); +atomic_inc (&new_wb->writeback_inodes); + } +wb_get (new_wb);/*
include/linux/backing-dev-defs.h renamed from include/linux/backing-dev-defs.h~writeback-track-number-of-inodes-under-writeback +1 -0
@@ -116,6 +116,7 @@ struct bdi_writeback {struct list_head b_dirty_time;/* time stamps are dirty */ spinlock_t list_lock;/* protects the b_* lists */ +atomic_t writeback_inodes;/* number of inodes under writeback */ struct percpu_counter stat[NR_WB_STAT_ITEMS ];unsigned long congested;/* WB_[a]sync_congested flags */
mm/backing-dev.c renamed from mm/backing-dev.c~writeback-track-number-of-inodes-under-writeback +1 -0
@@ -293,6 +293,7 @@ static int wb_init(struct bdi_writebackINIT_LIST_HEAD (&wb->b_dirty_time);spin_lock_init (&wb->list_lock); +atomic_set (&wb->writeback_inodes,0 ); wb->bw_time_stamp = jiffies; wb->balanced_dirty_ratelimit =INIT_BW ; wb->dirty_ratelimit =INIT_BW ;
mm/page-writeback.c renamed from mm/page-writeback.c~writeback-track-number-of-inodes-under-writeback +20 -2
@@ -2731,6 +2731,16 @@ int clear_page_dirty_for_io(struct page }EXPORT_SYMBOL (clear_page_dirty_for_io); +static void wb_inode_writeback_start (struct bdi_writeback *wb) +{ +atomic_inc (&wb->writeback_inodes); +} + +static void wb_inode_writeback_end (struct bdi_writeback *wb) +{ +atomic_dec (&wb->writeback_inodes); +} +int test_clear_page_writeback (struct page *page) {struct address_space *mapping =page_mapping (page);
@@ -2752,6 +2762,9 @@ int test_clear_page_writeback(struct pagdec_wb_stat (wb,WB_WRITEBACK );__wb_writeout_inc (wb); +if (!mapping_tagged (mapping, +PAGECACHE_TAG_WRITEBACK )) +wb_inode_writeback_end (wb); } }
@@ -2794,8 +2807,13 @@ int __test_set_page_writeback(struct pag PAGECACHE_TAG_WRITEBACK);xas_set_mark (&xas,PAGECACHE_TAG_WRITEBACK ); -if (bdi->capabilities &BDI_CAP_WRITEBACK_ACCT ) -inc_wb_stat (inode_to_wb (inode),WB_WRITEBACK ); +if (bdi->capabilities &BDI_CAP_WRITEBACK_ACCT ) { +struct bdi_writeback *wb =inode_to_wb (inode); + +inc_wb_stat (wb,WB_WRITEBACK ); +if (!on_wblist) +wb_inode_writeback_start (wb); + }/* * We can come through here when swapping anonymous
_
Andrew Morton
maintainerPATCH 59/212 writeback: reliably update bandwidth estimation
In reply to Andrew MortonFrom: Jan Kara <[email protected]>
Subject: writeback: reliably update bandwidth estimation
Currently we trigger writeback bandwidth estimation from balance_dirty_pages() and from wb_writeback(). However neither of these need to trigger when the system is relatively idle and writeback is triggered e.g. from fsync(2). Make sure writeback estimates happen reliably by triggering them from do_writepages().
---
fs/fs-writeback.c | 3 -- include/linux/backing-dev.h | 19 ++++++++++++++++ include/linux/writeback.h | 1 mm/page-writeback.c | 39 +++++++++++++++++++++++----------- 4 files changed, 46 insertions(+), 16 deletions(-)
fs/fs-writeback.c renamed from fs/fs-writeback.c~writeback-reliably-update-bandwidth-estimation +0 -3
@@ -2004,7 +2004,6 @@ static long writeback_inodes_wb(struct bstatic long wb_writeback (struct bdi_writeback *wb,struct wb_writeback_work *work) { -unsigned long wb_start = jiffies;long nr_pages = work->nr_pages;unsigned long dirtied_before = jiffies;struct inode *inode;
@@ -2058,8 +2057,6 @@ static long wb_writeback(struct bdi_writ progress =__writeback_inodes_wb (wb, work);trace_writeback_written (wb, work); -wb_update_bandwidth (wb, wb_start); -/* * Did we write something? Try for more *
include/linux/backing-dev.h renamed from include/linux/backing-dev.h~writeback-reliably-update-bandwidth-estimation +19 -0
@@ -288,6 +288,17 @@ static inline struct bdi_writeback *inodreturn inode->i_wb; } +static inline struct bdi_writeback *inode_to_wb_wbc ( +struct inode *inode, +struct writeback_control *wbc) +{ +/* +* If wbc does not have inode attached, it means cgroup writeback was +* disabled when wbc started. Just use the default wb in that case. +*/ +return wbc->wb ? wbc->wb : &inode_to_bdi (inode)->wb; +} +/** * unlocked_inode_to_wb_begin - begin unlocked inode wb access transaction * @inode: target inode
@@ -366,6 +377,14 @@ static inline struct bdi_writeback *inodreturn &inode_to_bdi (inode)->wb; } +static inline struct bdi_writeback *inode_to_wb_wbc ( +struct inode *inode, +struct writeback_control *wbc) +{ +return inode_to_wb (inode); +} + +static inline struct bdi_writeback *unlocked_inode_to_wb_begin (struct inode *inode,struct wb_lock_cookie *cookie) {
include/linux/writeback.h renamed from include/linux/writeback.h~writeback-reliably-update-bandwidth-estimation +0 -1
@@ -379,7 +379,6 @@ int dirty_writeback_centisecs_handler(stvoid global_dirty_limits (unsigned long *pbackground,unsigned long *pdirty);unsigned long wb_calc_thresh (struct bdi_writeback *wb,unsigned long thresh); -void wb_update_bandwidth (struct bdi_writeback *wb,unsigned long start_time);void balance_dirty_pages_ratelimited (struct address_space *mapping);bool wb_over_bg_thresh (struct bdi_writeback *wb);
mm/page-writeback.c renamed from mm/page-writeback.c~writeback-reliably-update-bandwidth-estimation +27 -12
@@ -1332,7 +1332,6 @@ static void wb_update_dirty_ratelimit(ststatic void __wb_update_bandwidth (struct dirty_throttle_control *gdtc,struct dirty_throttle_control *mdtc, -unsigned long start_time,bool update_ratelimit) {struct bdi_writeback *wb = gdtc->wb;
@@ -1352,13 +1351,6 @@ static void __wb_update_bandwidth(struct dirtied =percpu_counter_read (&wb->stat[WB_DIRTIED ]); written =percpu_counter_read (&wb->stat[WB_WRITTEN ]); -/* -* Skip quiet periods when disk bandwidth is under-utilized. -* (at least 1s idle time between two flusher runs) -*/ -if (elapsed >HZ &&time_before (wb->bw_time_stamp, start_time)) - goto snapshot; -if (update_ratelimit) {domain_update_bandwidth (gdtc, now);wb_update_dirty_ratelimit (gdtc, dirtied, elapsed);
@@ -1374,17 +1366,36 @@ static void __wb_update_bandwidth(struct }wb_update_write_bandwidth (wb, elapsed, written); -snapshot: wb->dirtied_stamp = dirtied; wb->written_stamp = written; wb->bw_time_stamp = now; } -void wb_update_bandwidth (struct bdi_writeback *wb,unsigned long start_time) +static void wb_update_bandwidth (struct bdi_writeback *wb) {struct dirty_throttle_control gdtc = {GDTC_INIT (wb) }; -__wb_update_bandwidth (&gdtc,NULL , start_time, false); +spin_lock (&wb->list_lock); +__wb_update_bandwidth (&gdtc,NULL , false); +spin_unlock (&wb->list_lock); +} + +/* Interval after which we consider wb idle and don't estimate bandwidth */ +#define WB_BANDWIDTH_IDLE_JIF (HZ) + +static void wb_bandwidth_estimate_start (struct bdi_writeback *wb) +{ +unsigned long now = jiffies; +unsigned long elapsed = now -READ_ONCE (wb->bw_time_stamp); + +if (elapsed >WB_BANDWIDTH_IDLE_JIF && + !atomic_read (&wb->writeback_inodes)) { +spin_lock (&wb->list_lock); + wb->dirtied_stamp =wb_stat (wb,WB_DIRTIED ); + wb->written_stamp =wb_stat (wb,WB_WRITTEN ); + wb->bw_time_stamp = now; +spin_unlock (&wb->list_lock); + } }/*
@@ -1713,7 +1724,7 @@ free_running:if (time_is_before_jiffies (wb->bw_time_stamp +BANDWIDTH_INTERVAL )) {spin_lock (&wb->list_lock); -__wb_update_bandwidth (gdtc, mdtc, start_time, true); +__wb_update_bandwidth (gdtc, mdtc, true);spin_unlock (&wb->list_lock); }
@@ -2347,9 +2358,12 @@ EXPORT_SYMBOL(generic_writepages);int do_writepages (struct address_space *mapping,struct writeback_control *wbc) {int ret; +struct bdi_writeback *wb;if (wbc->nr_to_write <=0 )return 0 ; + wb =inode_to_wb_wbc (mapping->host, wbc); +wb_bandwidth_estimate_start (wb);while (1 ) {if (mapping->a_ops->writepages) ret = mapping->a_ops->writepages (mapping, wbc);
@@ -2360,6 +2374,7 @@ int do_writepages(struct address_space *cond_resched ();congestion_wait (BLK_RW_ASYNC ,HZ /50 ); } +wb_update_bandwidth (wb);return ret; }
_
Andrew Morton
maintainerPATCH 60/212 writeback: fix bandwidth estimate for spiky workload
In reply to Andrew MortonFrom: Jan Kara <[email protected]>
Subject: writeback: fix bandwidth estimate for spiky workload
Michael Stapelberg has reported that for workload with short big spikes of writes (GCC linker seem to trigger this frequently) the write throughput is heavily underestimated and tends to steadily sink until it reaches zero. This has rather bad impact on writeback throttling (causing stalls). The problem is that writeback throughput estimate gets updated at most once per 200 ms. One update happens early after we submit pages for writeback (at that point writeout of only small fraction of pages is completed and thus observed throughput is tiny). Next update happens only during the next write spike (updates happen only from inode writeback and dirty throttling code) and if that is more than 1s after previous spike, we decide system was idle and just ignore whatever was written until this moment.
Fix the problem by making sure writeback throughput estimate is also updated shortly after writeback completes to get reasonable estimate of throughput for spiky workloads.
---
include/linux/backing-dev-defs.h | 1 include/linux/writeback.h | 1 mm/backing-dev.c | 10 +++++++ mm/page-writeback.c | 39 ++++++++++++++++++----------- 4 files changed, 37 insertions(+), 14 deletions(-)
include/linux/backing-dev-defs.h renamed from include/linux/backing-dev-defs.h~writeback-fix-bandwidth-estimate-for-spiky-workload +1 -0
@@ -143,6 +143,7 @@ struct bdi_writeback {spinlock_t work_lock;/* protects work_list & dwork scheduling */ struct list_head work_list;struct delayed_work dwork;/* work item used for writeback */ +struct delayed_work bw_dwork;/* work item used for bandwidth estimate */ unsigned long dirty_sleep;/* last wait */
include/linux/writeback.h renamed from include/linux/writeback.h~writeback-fix-bandwidth-estimate-for-spiky-workload +1 -0
@@ -379,6 +379,7 @@ int dirty_writeback_centisecs_handler(stvoid global_dirty_limits (unsigned long *pbackground,unsigned long *pdirty);unsigned long wb_calc_thresh (struct bdi_writeback *wb,unsigned long thresh); +void wb_update_bandwidth (struct bdi_writeback *wb);void balance_dirty_pages_ratelimited (struct address_space *mapping);bool wb_over_bg_thresh (struct bdi_writeback *wb);
mm/backing-dev.c renamed from mm/backing-dev.c~writeback-fix-bandwidth-estimate-for-spiky-workload +10 -0
@@ -271,6 +271,14 @@ void wb_wakeup_delayed(struct bdi_writebspin_unlock_bh (&wb->work_lock); } +static void wb_update_bandwidth_workfn (struct work_struct *work) +{ +struct bdi_writeback *wb =container_of (to_delayed_work (work), + struct bdi_writeback, bw_dwork); + +wb_update_bandwidth (wb); +} +/* * Initial write bandwidth: 100 MB/s */
@@ -303,6 +311,7 @@ static int wb_init(struct bdi_writebackspin_lock_init (&wb->work_lock);INIT_LIST_HEAD (&wb->work_list);INIT_DELAYED_WORK (&wb->dwork, wb_workfn); +INIT_DELAYED_WORK (&wb->bw_dwork, wb_update_bandwidth_workfn); wb->dirty_sleep = jiffies; err =fprop_local_init_percpu (&wb->completions, gfp);
@@ -351,6 +360,7 @@ static void wb_shutdown(struct bdi_writemod_delayed_work (bdi_wq, &wb->dwork,0 );flush_delayed_work (&wb->dwork);WARN_ON (!list_empty (&wb->work_list)); +flush_delayed_work (&wb->bw_dwork); }static void wb_exit (struct bdi_writeback *wb)
mm/page-writeback.c renamed from mm/page-writeback.c~writeback-fix-bandwidth-estimate-for-spiky-workload +25 -14
@@ -1336,18 +1336,19 @@ static void __wb_update_bandwidth(struct {struct bdi_writeback *wb = gdtc->wb;unsigned long now = jiffies; -unsigned long elapsed = now - wb->bw_time_stamp; +unsigned long elapsed;unsigned long dirtied;unsigned long written; -lockdep_assert_held (&wb->list_lock); +spin_lock (&wb->list_lock);/* -* rate-limit, only update once every 200ms. +* Lockless checks for elapsed time are racy and delayed update after +* IO completion doesn't do it at all (to make sure written pages are +* accounted reasonably quickly). Make sure elapsed >= 1 to avoid +* division errors. */ -if (elapsed <BANDWIDTH_INTERVAL ) -return ; - + elapsed =max (now - wb->bw_time_stamp,1UL ); dirtied =percpu_counter_read (&wb->stat[WB_DIRTIED ]); written =percpu_counter_read (&wb->stat[WB_WRITTEN ]);
@@ -1369,15 +1370,14 @@ static void __wb_update_bandwidth(struct wb->dirtied_stamp = dirtied; wb->written_stamp = written; wb->bw_time_stamp = now; +spin_unlock (&wb->list_lock); } -static void wb_update_bandwidth (struct bdi_writeback *wb) +void wb_update_bandwidth (struct bdi_writeback *wb) {struct dirty_throttle_control gdtc = {GDTC_INIT (wb) }; -spin_lock (&wb->list_lock);__wb_update_bandwidth (&gdtc,NULL , false); -spin_unlock (&wb->list_lock); }/* Interval after which we consider wb idle and don't estimate bandwidth */
@@ -1722,11 +1722,8 @@ free_running: wb->dirty_exceeded =1 ;if (time_is_before_jiffies (wb->bw_time_stamp + -BANDWIDTH_INTERVAL )) { -spin_lock (&wb->list_lock); +BANDWIDTH_INTERVAL ))__wb_update_bandwidth (gdtc, mdtc, true); -spin_unlock (&wb->list_lock); - }/* throttle according to the chosen dtc */ dirty_ratelimit = wb->dirty_ratelimit;
@@ -2374,7 +2371,13 @@ int do_writepages(struct address_space *cond_resched ();congestion_wait (BLK_RW_ASYNC ,HZ /50 ); } -wb_update_bandwidth (wb); +/* +* Usually few pages are written by now from those we've just submitted +* but if there's constant writeback being submitted, this makes sure +* writeback bandwidth is updated once in a while. +*/ +if (time_is_before_jiffies (wb->bw_time_stamp +BANDWIDTH_INTERVAL )) +wb_update_bandwidth (wb);return ret; }
@@ -2754,6 +2757,14 @@ static void wb_inode_writeback_start(strstatic void wb_inode_writeback_end (struct bdi_writeback *wb) {atomic_dec (&wb->writeback_inodes); +/* +* Make sure estimate of writeback throughput gets updated after +* writeback completed. We delay the update by BANDWIDTH_INTERVAL +* (which is the interval other bandwidth updates use for batching) so +* that if multiple inodes end writeback at a similar time, they get +* batched into one bandwidth update. +*/ +queue_delayed_work (bdi_wq, &wb->bw_dwork,BANDWIDTH_INTERVAL ); }int test_clear_page_writeback (struct page *page)
_
Andrew Morton
maintainerPATCH 61/212 writeback: rename domain_update_bandwidth()
In reply to Andrew MortonFrom: Jan Kara <[email protected]>
Subject: writeback: rename domain_update_bandwidth()
Rename domain_update_bandwidth() to domain_update_dirty_limit(). The original name is a misnomer. The function has nothing to do with a bandwidth, it updates dirty limits.
---
mm/page-writeback.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
mm/page-writeback.c renamed from mm/page-writeback.c~writeback-rename-domain_update_bandwidth +4 -4
@@ -1147,8 +1147,8 @@ update: dom->dirty_limit = limit; } -static void domain_update_bandwidth (struct dirty_throttle_control *dtc, -unsigned long now) +static void domain_update_dirty_limit (struct dirty_throttle_control *dtc, +unsigned long now) {struct wb_domain *dom =dtc_dom (dtc);
@@ -1353,7 +1353,7 @@ static void __wb_update_bandwidth(struct written =percpu_counter_read (&wb->stat[WB_WRITTEN ]);if (update_ratelimit) { -domain_update_bandwidth (gdtc, now); +domain_update_dirty_limit (gdtc, now);wb_update_dirty_ratelimit (gdtc, dirtied, elapsed);/*
@@ -1361,7 +1361,7 @@ static void __wb_update_bandwidth(struct* compiler has no way to figure that out. Help it. */ if (IS_ENABLED (CONFIG_CGROUP_WRITEBACK ) && mdtc) { -domain_update_bandwidth (mdtc, now); +domain_update_dirty_limit (mdtc, now);wb_update_dirty_ratelimit (mdtc, dirtied, elapsed); } }
_
Andrew Morton
maintainerPATCH 62/212 writeback: use READ_ONCE for unlocked reads of writeback stats
In reply to Andrew MortonFrom: Jan Kara <[email protected]>
Subject: writeback: use READ_ONCE for unlocked reads of writeback stats
We do some unlocked reads of writeback statistics like avg_write_bandwidth, dirty_ratelimit, or bw_time_stamp. Generally we are fine with getting somewhat out-of-date values but actually getting different values in various parts of the functions because the compiler decided to reload value from original memory location could confuse calculations. Use READ_ONCE for these unlocked accesses and WRITE_ONCE for the updates to be on the safe side.
---
mm/page-writeback.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-)
mm/page-writeback.c renamed from mm/page-writeback.c~writeback-use-read_once-for-unlocked-reads-of-writeback-stats +13 -12
@@ -183,7 +183,7 @@ static struct fprop_local_percpu *wb_memstatic void wb_min_max_ratio (struct bdi_writeback *wb,unsigned long *minp,unsigned long *maxp) { -unsigned long this_bw = wb->avg_write_bandwidth; +unsigned long this_bw =READ_ONCE (wb->avg_write_bandwidth);unsigned long tot_bw =atomic_long_read (&wb->bdi->tot_write_bandwidth);unsigned long long min = wb->bdi->min_ratio;unsigned long long max = wb->bdi->max_ratio;
@@ -892,7 +892,7 @@ static long long pos_ratio_polynom(unsigstatic void wb_position_ratio (struct dirty_throttle_control *dtc) {struct bdi_writeback *wb = dtc->wb; -unsigned long write_bw = wb->avg_write_bandwidth; +unsigned long write_bw =READ_ONCE (wb->avg_write_bandwidth);unsigned long freerun =dirty_freerun_ceiling (dtc->thresh, dtc->bg_thresh);unsigned long limit =hard_dirty_limit (dtc_dom (dtc), dtc->thresh);unsigned long wb_thresh = dtc->wb_thresh;
@@ -1115,7 +1115,7 @@ out: &wb->bdi->tot_write_bandwidth) <= 0); } wb->write_bandwidth = bw; - wb->avg_write_bandwidth = avg; +WRITE_ONCE (wb->avg_write_bandwidth, avg); }static void update_dirty_limit (struct dirty_throttle_control *dtc)
@@ -1324,7 +1324,7 @@ static void wb_update_dirty_ratelimit(stelse dirty_ratelimit -= step; - wb->dirty_ratelimit =max (dirty_ratelimit,1UL ); +WRITE_ONCE (wb->dirty_ratelimit,max (dirty_ratelimit,1UL )); wb->balanced_dirty_ratelimit = balanced_dirty_ratelimit;trace_bdi_dirty_ratelimit (wb, dirty_rate, task_ratelimit);
@@ -1369,7 +1369,7 @@ static void __wb_update_bandwidth(struct wb->dirtied_stamp = dirtied; wb->written_stamp = written; - wb->bw_time_stamp = now; +WRITE_ONCE (wb->bw_time_stamp, now);spin_unlock (&wb->list_lock); }
@@ -1393,7 +1393,7 @@ static void wb_bandwidth_estimate_start(spin_lock (&wb->list_lock); wb->dirtied_stamp =wb_stat (wb,WB_DIRTIED ); wb->written_stamp =wb_stat (wb,WB_WRITTEN ); - wb->bw_time_stamp = now; +WRITE_ONCE (wb->bw_time_stamp, now);spin_unlock (&wb->list_lock); } }
@@ -1418,7 +1418,7 @@ static unsigned long dirty_poll_intervalstatic unsigned long wb_max_pause (struct bdi_writeback *wb,unsigned long wb_dirty) { -unsigned long bw = wb->avg_write_bandwidth; +unsigned long bw =READ_ONCE (wb->avg_write_bandwidth);unsigned long t;/*
@@ -1440,8 +1440,8 @@ static long wb_min_pause(struct bdi_writunsigned long dirty_ratelimit, int *nr_dirtied_pause) { - long hi = ilog2(wb->avg_write_bandwidth); -long lo =ilog2 (wb->dirty_ratelimit); + long hi = ilog2(READ_ONCE(wb->avg_write_bandwidth)); +long lo =ilog2 (READ_ONCE (wb->dirty_ratelimit));long t;/* target pause */ long pause;/* estimated next pause */ int pages;/* target nr_dirtied_pause */
@@ -1721,12 +1721,12 @@ free_running:if (dirty_exceeded && !wb->dirty_exceeded) wb->dirty_exceeded =1 ; -if (time_is_before_jiffies (wb->bw_time_stamp + +if (time_is_before_jiffies (READ_ONCE (wb->bw_time_stamp) +BANDWIDTH_INTERVAL ))__wb_update_bandwidth (gdtc, mdtc, true);/* throttle according to the chosen dtc */ - dirty_ratelimit = wb->dirty_ratelimit; + dirty_ratelimit =READ_ONCE (wb->dirty_ratelimit); task_ratelimit = ((u64 )dirty_ratelimit * sdtc->pos_ratio) >>RATELIMIT_CALC_SHIFT ; max_pause =wb_max_pause (wb, sdtc->wb_dirty);
@@ -2376,7 +2376,8 @@ int do_writepages(struct address_space ** but if there's constant writeback being submitted, this makes sure * writeback bandwidth is updated once in a while. */ -if (time_is_before_jiffies (wb->bw_time_stamp +BANDWIDTH_INTERVAL )) +if (time_is_before_jiffies (READ_ONCE (wb->bw_time_stamp) + +BANDWIDTH_INTERVAL ))wb_update_bandwidth (wb);return ret; }
_
Andrew Morton
maintainerPATCH 63/212 mm: remove irqsave/restore locking from contexts with irqs enabled
In reply to Andrew MortonFrom: Johannes Weiner <[email protected]>
Subject: mm: remove irqsave/restore locking from contexts with irqs enabled
The page cache deletion paths all have interrupts enabled, so no need to use irqsafe/irqrestore locking variants.
They used to have irqs disabled by the memcg lock added in commit c4843a7593a9 ("memcg: add per cgroup dirty page accounting"), but that has since been replaced by memcg taking the page lock instead, commit 0a31bc97c80c ("mm: memcontrol: rewrite uncharge AP").
---
mm/filemap.c | 15 ++++++--------- mm/truncate.c | 8 +++----- mm/vmscan.c | 9 ++++----- 3 files changed, 13 insertions(+), 19 deletions(-)
mm/filemap.c renamed from mm/filemap.c~mm-remove-irqsave-restore-locking-from-contexts-with-irqs-enabled +6 -9
@@ -258,12 +258,11 @@ static void page_cache_free_page(structvoid delete_from_page_cache (struct page *page) {struct address_space *mapping =page_mapping (page); -unsigned long flags;BUG_ON (!PageLocked (page)); -xa_lock_irqsave (&mapping->i_pages, flags); +xa_lock_irq (&mapping->i_pages);__delete_from_page_cache (page,NULL ); -xa_unlock_irqrestore (&mapping->i_pages, flags); +xa_unlock_irq (&mapping->i_pages);page_cache_free_page (mapping, page); }
@@ -335,19 +334,18 @@ void delete_from_page_cache_batch(struct struct pagevec *pvec) {int i; -unsigned long flags;if (!pagevec_count (pvec))return ; -xa_lock_irqsave (&mapping->i_pages, flags); +xa_lock_irq (&mapping->i_pages);for (i =0 ; i <pagevec_count (pvec); i++) {trace_mm_filemap_delete_from_page_cache (pvec->pages[i]);unaccount_page_cache_page (mapping, pvec->pages[i]); }page_cache_delete_batch (mapping, pvec); -xa_unlock_irqrestore (&mapping->i_pages, flags); +xa_unlock_irq (&mapping->i_pages);for (i =0 ; i <pagevec_count (pvec); i++)page_cache_free_page (mapping, pvec->pages[i]);
@@ -821,7 +819,6 @@ void replace_page_cache_page(struct pagevoid (*freepage)(struct page *) = mapping->a_ops->freepage;pgoff_t offset = old->index;XA_STATE (xas, &mapping->i_pages, offset); -unsigned long flags;VM_BUG_ON_PAGE (!PageLocked (old), old);VM_BUG_ON_PAGE (!PageLocked (new), new);
@@ -833,7 +830,7 @@ void replace_page_cache_page(struct pagemem_cgroup_migrate (old, new); -xas_lock_irqsave (&xas, flags); +xas_lock_irq (&xas);xas_store (&xas, new); old->mapping =NULL ;
@@ -846,7 +843,7 @@ void replace_page_cache_page(struct page__dec_lruvec_page_state (old,NR_SHMEM );if (PageSwapBacked (new))__inc_lruvec_page_state (new,NR_SHMEM ); -xas_unlock_irqrestore (&xas, flags); +xas_unlock_irq (&xas);if (freepage)freepage (old);put_page (old);
mm/truncate.c renamed from mm/truncate.c~mm-remove-irqsave-restore-locking-from-contexts-with-irqs-enabled +3 -5
@@ -560,21 +560,19 @@ void invalidate_mapping_pagevec(struct astatic int invalidate_complete_page2 (struct address_space *mapping,struct page *page) { -unsigned long flags; -if (page->mapping != mapping)return 0 ;if (page_has_private (page) && !try_to_release_page (page,GFP_KERNEL ))return 0 ; -xa_lock_irqsave (&mapping->i_pages, flags); +xa_lock_irq (&mapping->i_pages);if (PageDirty (page)) goto failed;BUG_ON (page_has_private (page));__delete_from_page_cache (page,NULL ); -xa_unlock_irqrestore (&mapping->i_pages, flags); +xa_unlock_irq (&mapping->i_pages);if (mapping->a_ops->freepage) mapping->a_ops->freepage (page);
@@ -582,7 +580,7 @@ invalidate_complete_page2(struct addressput_page (page);/* pagecache ref */ return 1 ; failed: -xa_unlock_irqrestore (&mapping->i_pages, flags); +xa_unlock_irq (&mapping->i_pages);return 0 ; }
mm/vmscan.c renamed from mm/vmscan.c~mm-remove-irqsave-restore-locking-from-contexts-with-irqs-enabled +4 -5
@@ -1052,14 +1052,13 @@ static pageout_t pageout(struct page *pastatic int __remove_mapping (struct address_space *mapping,struct page *page,bool reclaimed,struct mem_cgroup *target_memcg) { -unsigned long flags;int refcount;void *shadow =NULL ;BUG_ON (!PageLocked (page));BUG_ON (mapping !=page_mapping (page)); -xa_lock_irqsave (&mapping->i_pages, flags); +xa_lock_irq (&mapping->i_pages);/* * The non racy check for a busy page. *
@@ -1100,7 +1099,7 @@ static int __remove_mapping(struct addreif (reclaimed && !mapping_exiting (mapping)) shadow =workingset_eviction (page, target_memcg);__delete_from_swap_cache (page, swap, shadow); -xa_unlock_irqrestore (&mapping->i_pages, flags); +xa_unlock_irq (&mapping->i_pages);put_swap_page (page, swap); }else {void (*freepage)(struct page *);
@@ -1126,7 +1125,7 @@ static int __remove_mapping(struct addre !mapping_exiting(mapping) && !dax_mapping(mapping)) shadow =workingset_eviction (page, target_memcg);__delete_from_page_cache (page, shadow); -xa_unlock_irqrestore (&mapping->i_pages, flags); +xa_unlock_irq (&mapping->i_pages);if (freepage !=NULL )freepage (page);
@@ -1135,7 +1134,7 @@ static int __remove_mapping(struct addrereturn 1 ; cannot_free: -xa_unlock_irqrestore (&mapping->i_pages, flags); +xa_unlock_irq (&mapping->i_pages);return 0 ; }
_
Andrew Morton
maintainerPATCH 64/212 fs: drop_caches: fix skipping over shadow cache inodes
In reply to Andrew MortonFrom: Johannes Weiner <[email protected]>
Subject: fs: drop_caches: fix skipping over shadow cache inodes
When drop_caches truncates the page cache in an inode it also includes any shadow entries for evicted pages. However, there is a preliminary check on whether the inode has pages: if it has *only* shadow entries, it will skip running truncation on the inode and leave it behind.
Fix the check to mapping_empty(), such that it runs truncation on any inode that has cache entries at all.
---
fs/drop_caches.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/drop_caches.c renamed from fs/drop_caches.c~fs-drop_caches-fix-skipping-over-shadow-cache-inodes +2 -1
@@ -3,6 +3,7 @@* Implement the manual drop-all-pagecache function */ +#include <linux/pagemap.h> #include <linux/kernel.h> #include <linux/mm.h> #include <linux/fs.h>
@@ -27,7 +28,7 @@ static void drop_pagecache_sb(struct sup* we need to reschedule to avoid softlockups. */ if ((inode->i_state & (I_FREEING |I_WILL_FREE |I_NEW )) || - (inode->i_mapping->nrpages ==0 && !need_resched ())) { + (mapping_empty (inode->i_mapping) && !need_resched ())) {spin_unlock (&inode->i_lock);continue ; }
_
Andrew Morton
maintainerPATCH 65/212 fs: inode: count invalidated shadow pages in pginodesteal
In reply to Andrew MortonFrom: Johannes Weiner <[email protected]>
Subject: fs: inode: count invalidated shadow pages in pginodesteal
pginodesteal is supposed to capture the impact that inode reclaim has on the page cache state. Currently, it doesn't consider shadow pages that get dropped this way, even though this can have a significant impact on paging behavior, memory pressure calculations etc.
To improve visibility into these effects, make sure shadow pages get counted when they get dropped through inode reclaim.
This changes the return value semantics of invalidate_mapping_pages() semantics slightly, but the only two users are the inode shrinker itsel and a usb driver that logs it for debugging purposes.
---
fs/inode.c | 2 +- mm/truncate.c | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-)
fs/inode.c renamed from fs/inode.c~fs-inode-count-invalidated-shadow-pages-in-pginodesteal +1 -1
@@ -768,7 +768,7 @@ static enum lru_status inode_lru_isolatereturn LRU_ROTATE ; } -if (inode_has_buffers (inode) || inode->i_data.nrpages) { +if (inode_has_buffers (inode) || !mapping_empty (&inode->i_data)) {__iget (inode);spin_unlock (&inode->i_lock);spin_unlock (lru_lock);
mm/truncate.c renamed from mm/truncate.c~fs-inode-count-invalidated-shadow-pages-in-pginodesteal +10 -10
@@ -483,8 +483,9 @@ static unsigned long __invalidate_mappin index = indices[i];if (xa_is_value (page)) { -invalidate_exceptional_entry (mapping, index, - page); + count +=invalidate_exceptional_entry (mapping, + index, + page);continue ; } index +=thp_nr_pages (page) -1 ;
@@ -512,19 +513,18 @@ static unsigned long __invalidate_mappin }/** -* invalidate_mapping_pages - Invalidate all the unlocked pages of one inode -* @mapping: the address_space which holds the pages to invalidate +* invalidate_mapping_pages - Invalidate all clean, unlocked cache of one inode +* @mapping: the address_space which holds the cache to invalidate * @start: the offset 'from' which to invalidate * @end: the offset 'to' which to invalidate (inclusive) * -* This function only removes the unlocked pages, if you want to -* remove all the pages of one inode, you must call truncate_inode_pages. +* This function removes pages that are clean, unmapped and unlocked, +* as well as shadow entries. It will not block on IO activity. * -* invalidate_mapping_pages() will not block on IO activity. It will not -* invalidate pages which are dirty, locked, under writeback or mapped into -* pagetables. +* If you want to remove all the pages of one inode, regardless of +* their use and writeback state, use truncate_inode_pages(). * -* Return: the number of the pages that were invalidated +* Return: the number of the cache entries that were invalidated */ unsigned long invalidate_mapping_pages (struct address_space *mapping,pgoff_t start,pgoff_t end)
_
Andrew Morton
maintainerPATCH 66/212 writeback: memcg: simplify cgroup_writeback_by_id
In reply to Andrew MortonFrom: Shakeel Butt <[email protected]>
Subject: writeback: memcg: simplify cgroup_writeback_by_id
Currently cgroup_writeback_by_id calls mem_cgroup_wb_stats() to get dirty pages for a memcg. However mem_cgroup_wb_stats() does a lot more than just get the number of dirty pages. Just directly get the number of dirty pages instead of calling mem_cgroup_wb_stats(). Also cgroup_writeback_by_id() is only called for best-effort dirty flushing, so remove the unused 'nr' parameter and no need to explicitly flush memcg stats.
---
fs/fs-writeback.c | 20 +++++++++----------- include/linux/memcontrol.h | 15 +++++++++++++++ include/linux/writeback.h | 2 +- mm/memcontrol.c | 13 +------------ 4 files changed, 26 insertions(+), 24 deletions(-)
fs/fs-writeback.c renamed from fs/fs-writeback.c~writeback-memcg-simplify-cgroup_writeback_by_id +9 -11
@@ -1039,20 +1039,20 @@ restart:* cgroup_writeback_by_id - initiate cgroup writeback from bdi and memcg IDs * @bdi_id: target bdi id * @memcg_id: target memcg css id -* @nr: number of pages to write, 0 for best-effort dirty flushing * @reason: reason why some writeback work initiated * @done: target wb_completion * * Initiate flush of the bdi_writeback identified by @bdi_id and @memcg_id * with the specified parameters. */ -int cgroup_writeback_by_id (u64 bdi_id,int memcg_id,unsigned long nr, +int cgroup_writeback_by_id (u64 bdi_id,int memcg_id,enum wb_reason reason,struct wb_completion *done) {struct backing_dev_info *bdi;struct cgroup_subsys_state *memcg_css;struct bdi_writeback *wb;struct wb_writeback_work *work; +unsigned long dirty;int ret;/* lookup bdi and memcg */
@@ -1081,24 +1081,22 @@ int cgroup_writeback_by_id(u64 bdi_id, i }/* -* If @nr is zero, the caller is attempting to write out most of +* The caller is attempting to write out most of * the currently dirty pages. Let's take the current dirty page * count and inflate it by 25% which should be large enough to * flush out most dirty pages while avoiding getting livelocked by * concurrent dirtiers. +* +* BTW the memcg stats are flushed periodically and this is best-effort +* estimation, so some potential error is ok. */ -if (!nr) { -unsigned long filepages, headroom, dirty, writeback; - -mem_cgroup_wb_stats (wb, &filepages, &headroom, &dirty, - &writeback); - nr = dirty *10 /8 ; - } + dirty =memcg_page_state (mem_cgroup_from_css (memcg_css),NR_FILE_DIRTY ); + dirty = dirty *10 /8 ;/* issue the writeback work */ work =kzalloc (sizeof (*work),GFP_NOWAIT | __GFP_NOWARN);if (work) { - work->nr_pages = nr; + work->nr_pages = dirty; work->sync_mode =WB_SYNC_NONE ; work->range_cyclic =1 ; work->reason = reason;
include/linux/memcontrol.h renamed from include/linux/memcontrol.h~writeback-memcg-simplify-cgroup_writeback_by_id +15 -0
@@ -955,6 +955,16 @@ static inline void mod_memcg_state(struclocal_irq_restore (flags); } +static inline unsigned long memcg_page_state (struct mem_cgroup *memcg,int idx) +{ +long x =READ_ONCE (memcg->vmstats.state[idx]); +#ifdef CONFIG_SMP +if (x <0 ) + x =0 ; +#endif +return x; +} +static inline unsigned long lruvec_page_state (struct lruvec *lruvec,enum node_stat_item idx) {
@@ -1391,6 +1401,11 @@ static inline void mod_memcg_state(struc { } +static inline unsigned long memcg_page_state (struct mem_cgroup *memcg,int idx) +{ +return 0 ; +} +static inline unsigned long lruvec_page_state (struct lruvec *lruvec,enum node_stat_item idx) {
include/linux/writeback.h renamed from include/linux/writeback.h~writeback-memcg-simplify-cgroup_writeback_by_id +1 -1
@@ -218,7 +218,7 @@ void wbc_attach_and_unlock_inode(structvoid wbc_detach_inode (struct writeback_control *wbc);void wbc_account_cgroup_owner (struct writeback_control *wbc,struct page *page,size_t bytes); -int cgroup_writeback_by_id (u64 bdi_id,int memcg_id,unsigned long nr_pages, +int cgroup_writeback_by_id (u64 bdi_id,int memcg_id,enum wb_reason reason,struct wb_completion *done);void cgroup_writeback_umount (void );bool cleanup_offline_cgwb (struct bdi_writeback *wb);
mm/memcontrol.c renamed from mm/memcontrol.c~writeback-memcg-simplify-cgroup_writeback_by_id +1 -12
@@ -646,17 +646,6 @@ void __mod_memcg_state(struct mem_cgroup }/* idx can be of type enum memcg_stat_item or node_stat_item. */ -static unsigned long memcg_page_state (struct mem_cgroup *memcg,int idx) -{ -long x =READ_ONCE (memcg->vmstats.state[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. */ static unsigned long memcg_page_state_local (struct mem_cgroup *memcg,int idx) {long x =0 ;
@@ -4668,7 +4657,7 @@ void mem_cgroup_flush_foreign(struct bdi atomic_read(&frn->done.cnt) == 1) { frn->at =0 ;trace_flush_foreign (wb, frn->bdi_id, frn->memcg_id); -cgroup_writeback_by_id (frn->bdi_id, frn->memcg_id,0 , +cgroup_writeback_by_id (frn->bdi_id, frn->memcg_id,WB_REASON_FOREIGN_FLUSH , &frn->done); }
_
Andrew Morton
maintainerPATCH 67/212 include/linux/buffer_head.h: fix boolreturn.cocci warnings
In reply to Andrew MortonFrom: Jing Yangyang <[email protected]>
Subject: include/linux/buffer_head.h: fix boolreturn.cocci warnings
./include/linux/buffer_head.h:412:64-65:WARNING:return of 0/1 in function 'has_bh_in_lru' with return type bool
Return statements in functions returning bool should use true/false instead of 1/0.
Generated by: scripts/coccinelle/misc/boolreturn.cocci
---
include/linux/buffer_head.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/buffer_head.h renamed from include/linux/buffer_head.h~include-buffer_head-fix-boolreturncocci-warnings +1 -1
@@ -409,7 +409,7 @@ static inline void invalidate_inode_buffstatic inline int remove_inode_buffers (struct inode *inode) {return 1 ; }static inline int sync_mapping_buffers (struct address_space *mapping) {return 0 ; }static inline void invalidate_bh_lrus_cpu (int cpu) {} -static inline bool has_bh_in_lru (int cpu,void *dummy) {return 0 ; } +static inline bool has_bh_in_lru (int cpu,void *dummy) {return false; }#define buffer_heads_over_limit 0#endif /* CONFIG_BLOCK */
_
Andrew Morton
maintainerPATCH 68/212 mm: gup: remove set but unused local variable major
In reply to Andrew MortonFrom: Miaohe Lin <[email protected]>
Subject: mm: gup: remove set but unused local variable major
Patch series "Cleanups and fixup for gup".
This series contains cleanups to remove unneeded variable, useless BUG_ON and use helper to improve readability. Also we fix a potential pgmap refcnt leak. More details can be found in the respective changelogs.
This patch (of 5):
Since commit a2beb5f1efed ("mm: clean up the last pieces of page fault accountings"), the local variable major is unused. Remove it.
---
mm/gup.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
mm/gup.c renamed from mm/gup.c~mm-gup-remove-set-but-unused-local-variable-major +1 -2
@@ -1276,7 +1276,7 @@ int fixup_user_fault(struct mm_struct *m bool *unlocked) {struct vm_area_struct *vma; -vm_fault_t ret, major =0 ; +vm_fault_t ret; address =untagged_addr (address);
@@ -1296,7 +1296,6 @@ retry:return -EINTR ; ret =handle_mm_fault (vma, address, fault_flags,NULL ); - major |= ret &VM_FAULT_MAJOR ;if (ret &VM_FAULT_ERROR ) {int err =vm_fault_to_errno (ret,0 );
_
Andrew Morton
maintainerPATCH 69/212 mm: gup: remove unneed local variable orig_refs
In reply to Andrew MortonFrom: Miaohe Lin <[email protected]>
Subject: mm: gup: remove unneed local variable orig_refs
Remove unneed local variable orig_refs since refs is unchanged now.
---
mm/gup.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
mm/gup.c renamed from mm/gup.c~mm-gup-remove-unneed-local-variable-orig_refs +1 -3
@@ -117,8 +117,6 @@ __maybe_unused struct page *try_grab_comif (flags &FOLL_GET )return try_get_compound_head (page, refs);else if (flags &FOLL_PIN ) { -int orig_refs = refs; -/* * Can't do FOLL_LONGTERM + FOLL_PIN gup fast path if not in a * right zone, so fail and let the caller fall back to the slow
@@ -150,7 +148,7 @@ __maybe_unused struct page *try_grab_compage_ref_add (page, refs * (GUP_PIN_COUNTING_BIAS -1 ));mod_node_page_state (page_pgdat (page),NR_FOLL_PIN_ACQUIRED , - orig_refs); + refs);return page; }
_
Andrew Morton
maintainerPATCH 70/212 mm: gup: remove useless BUG_ON in __get_user_pages()
In reply to Andrew MortonFrom: Miaohe Lin <[email protected]>
Subject: mm: gup: remove useless BUG_ON in __get_user_pages()
Indeed, this BUG_ON couldn't catch anything useful. We are sure ret == 0 here because we would already bail out if ret != 0 and ret is untouched till here.
---
mm/gup.c | 1 - 1 file changed, 1 deletion(-)
mm/gup.c renamed from mm/gup.c~mm-gup-remove-useless-bug_on-in-__get_user_pages +0 -1
@@ -1149,7 +1149,6 @@ static long __get_user_pages(struct mm_s* We must stop here. */ BUG_ON (gup_flags &FOLL_NOWAIT ); -BUG_ON (ret !=0 ); goto out; }continue ;
_
Andrew Morton
maintainerPATCH 71/212 mm: gup: fix potential pgmap refcnt leak in __gup_device_huge()
In reply to Andrew MortonFrom: Miaohe Lin <[email protected]>
Subject: mm: gup: fix potential pgmap refcnt leak in __gup_device_huge()
When failed to try_grab_page, put_dev_pagemap() is missed. So pgmap refcnt will leak in this case. Also we remove the check for pgmap against NULL as it's also checked inside the put_dev_pagemap().
---
mm/gup.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
mm/gup.c renamed from mm/gup.c~mm-gup-fix-potential-pgmap-refcnt-leak-in-__gup_device_huge +7 -5
@@ -2240,6 +2240,7 @@ static int __gup_device_huge(unsigned lo {int nr_start = *nr;struct dev_pagemap *pgmap =NULL ; +int ret =1 ; do { struct page *page = pfn_to_page(pfn);
@@ -2247,21 +2248,22 @@ static int __gup_device_huge(unsigned lo pgmap =get_dev_pagemap (pfn, pgmap);if (unlikely (!pgmap)) {undo_dev_pagemap (nr, nr_start, flags, pages); -return 0 ; + ret =0 ; +break ; }SetPageReferenced (page); pages[*nr] = page;if (unlikely (!try_grab_page (page, flags))) {undo_dev_pagemap (nr, nr_start, flags, pages); -return 0 ; + ret =0 ; +break ; } (*nr)++; pfn++; }while (addr +=PAGE_SIZE , addr != end); -if (pgmap) -put_dev_pagemap (pgmap); -return 1 ; +put_dev_pagemap (pgmap); +return ret; } static int __gup_device_huge_pmd(pmd_t orig, pmd_t *pmdp, unsigned long addr,
_
Re: [patch 071/212] mm: gup: fix potential pgmap refcnt leak in __gup_device_huge()
Quoted 2 lines · Andrew Morton
+ int ret = 1;
..
Quoted 2 lines
(quoted diff) +2
-0+ ret = 0; + break;
..
Quoted 2 lines
(quoted diff) +2
-0+ ret = 0; + break;
..
Quoted 1 line
+ return ret;
Hmm. I think "ret" is unnecessary, and this could just have been
return addr == end;
at the end to check that we did it all.
No?
Linus
John Hubbard
reviewerRe: [patch 071/212] mm: gup: fix potential pgmap refcnt leak in __gup_device_huge()
Quoted 12 lines · Linus Torvalds
Quoted 2 lines · Andrew Morton
+ int ret = 1;
..
Quoted 2 lines
(quoted diff) +2
-0+ ret = 0; + break;..
Quoted 2 lines
(quoted diff) +2
-0+ ret = 0; + break;..
Quoted 1 line
+ return ret;
Quoted 8 lines
Hmm. I think "ret" is unnecessary, and this could just have been
return addr == end;at the end to check that we did it all.
No?
Yes, definitely.
So, to be extra clear even though this is tiny and trivial: this incremental change, on top of the current patch, looks good to me:
mm/gup.c +1 -4
@@ -2241,7 +2241,6 @@ static int __gup_device_huge(unsigned long pfn, unsigned long addr, {int nr_start = *nr;struct dev_pagemap *pgmap =NULL ; -int ret =1 ; do { struct page *page = pfn_to_page(pfn);
@@ -2249,14 +2248,12 @@ static int __gup_device_huge(unsigned long pfn, unsigned long addr, pgmap =get_dev_pagemap (pfn, pgmap);if (unlikely (!pgmap)) {undo_dev_pagemap (nr, nr_start, flags, pages); - ret =0 ;break ; }SetPageReferenced (page); pages[*nr] = page;if (unlikely (!try_grab_page (page, flags))) {undo_dev_pagemap (nr, nr_start, flags, pages); - ret =0 ;break ; } (*nr)++;
@@ -2264,7 +2261,7 @@ static int __gup_device_huge(unsigned long pfn, unsigned long addr, }while (addr +=PAGE_SIZE , addr != end);put_dev_pagemap (pgmap); -return ret; +return addr == end; } static int __gup_device_huge_pmd(pmd_t orig, pmd_t *pmdp, unsigned long addr,
thanks,
Signature · 2 lines
John Hubbard NVIDIA
Re: [patch 071/212] mm: gup: fix potential pgmap refcnt leak in __gup_device_huge()
Quoted 5 lines · John Hubbard
Quoted 3 lines · Linus Torvalds
Hmm. I think "ret" is unnecessary, and this could just have been
Quoted 8 lines
Quoted 3 lines
return addr == end;at the end to check that we did it all.
Yes, definitely.
So, to be extra clear even though this is tiny and trivial: this incremental change, on top of the current patch, looks good to me:
Ack. I did the merge of Andrew's series as-is, to avoid even more disruption (I already skipped two sub-series in there), but wouldn't mind this simplification.
That said, it's not like it's a big deal, just me reacting to that patch being larger than strictly needed. It's not like the extra "ret" thing is confusing or wrong per se.
So I'll leave it to others if they want to pursue this.
Linus
Andrew Morton
maintainerPATCH 72/212 mm: gup: use helper PAGE_ALIGNED in populate_vma_page_range()
In reply to Andrew MortonFrom: Miaohe Lin <[email protected]>
Subject: mm: gup: use helper PAGE_ALIGNED in populate_vma_page_range()
Use helper PAGE_ALIGNED to check if address is aligned to PAGE_SIZE. Minor readability improvement.
---
mm/gup.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
mm/gup.c renamed from mm/gup.c~mm-gup-use-helper-page_aligned-in-populate_vma_page_range +2 -2
@@ -1471,8 +1471,8 @@ long populate_vma_page_range(struct vm_aunsigned long nr_pages = (end - start) /PAGE_SIZE ;int gup_flags; -VM_BUG_ON (start & ~PAGE_MASK ); -VM_BUG_ON (end & ~PAGE_MASK ); +VM_BUG_ON (!PAGE_ALIGNED (start)); +VM_BUG_ON (!PAGE_ALIGNED (end));VM_BUG_ON_VMA (start < vma->vm_start, vma);VM_BUG_ON_VMA (end > vma->vm_end, vma);mmap_assert_locked (mm);
_
Andrew Morton
maintainerPATCH 73/212 mm/gup: documentation corrections for gup/pup
In reply to Andrew MortonFrom: John Hubbard <[email protected]>
Subject: mm/gup: documentation corrections for gup/pup
Patch series "A few gup refactorings and documentation updates", v3.
While reviewing some of the other things going on around gup.c, I noticed that the documentation was wrong for a few of the routines that I wrote. And then I noticed that there was some significant code duplication too. So this fixes those issues.
This is not entirely risk-free, but after looking closely at this, I think it's actually a useful improvement, getting rid of the code duplication here.
This patch (of 3):
The documentation for try_grab_compound_head() and try_grab_page() has fallen a little out of date. Update and clarify a few points.
Also make it kerneldoc-correct, by adding @args documentation.
---
mm/gup.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-)
mm/gup.c renamed from mm/gup.c~mm-gup-documentation-corrections-for-gup-pup +20 -7
@@ -92,10 +92,17 @@ static inline struct page *try_get_comporeturn head; } -/* +/** * try_grab_compound_head() - attempt to elevate a page's refcount, by a * flags-dependent amount. * +* Even though the name includes "compound_head", this function is still +* appropriate for callers that have a non-compound @page to get. +* +* @page: pointer to page to be grabbed +* @refs: the value to (effectively) add to the page's refcount +* @flags: gup flags: these are the FOLL_* flag values. +* * "grab" names in this file mean, "look at flags to decide whether to use * FOLL_PIN or FOLL_GET behavior, when incrementing the page's refcount. *
@@ -103,8 +110,14 @@ static inline struct page *try_get_compo* same time. (That's true throughout the get_user_pages*() and * pin_user_pages*() APIs.) Cases: * -* FOLL_GET: page's refcount will be incremented by 1. -* FOLL_PIN: page's refcount will be incremented by GUP_PIN_COUNTING_BIAS. +* FOLL_GET: page's refcount will be incremented by @refs. +* +* FOLL_PIN on compound pages that are > two pages long: page's refcount will +* be incremented by @refs, and page[2].hpage_pinned_refcount will be +* incremented by @refs * GUP_PIN_COUNTING_BIAS. +* +* FOLL_PIN on normal pages, or compound pages that are two pages long: +* page's refcount will be incremented by @refs * GUP_PIN_COUNTING_BIAS. * * Return: head page (with refcount appropriately incremented) for success, or * NULL upon failure. If neither FOLL_GET nor FOLL_PIN was set, that's
@@ -141,6 +154,8 @@ __maybe_unused struct page *try_grab_com* * However, be sure to *also* increment the normal page refcount * field at least once, so that the page really is pinned. +* That's why the refcount from the earlier +* try_get_compound_head() is left intact. */ if (hpage_pincount_available (page))hpage_pincount_add (page, refs);
@@ -184,10 +199,8 @@ static void put_compound_head(struct pag* @flags: gup flags: these are the FOLL_* flag values. * * Either FOLL_PIN or FOLL_GET (or neither) may be set, but not both at the same -* time. Cases: -* -* FOLL_GET: page's refcount will be incremented by 1. -* FOLL_PIN: page's refcount will be incremented by GUP_PIN_COUNTING_BIAS. +* time. Cases: please see the try_grab_compound_head() documentation, with +* "refs=1". * * Return: true for success, or if no action was required (if neither FOLL_PIN * nor FOLL_GET was set, nothing is done). False for failure: FOLL_GET or
_
Andrew Morton
maintainerPATCH 74/212 mm/gup: small refactoring: simplify try_grab_page()
In reply to Andrew MortonFrom: John Hubbard <[email protected]>
Subject: mm/gup: small refactoring: simplify try_grab_page()
try_grab_page() does the same thing as try_grab_compound_head(..., refs=1, ...), just with a different API. So there is a lot of code duplication there.
Change try_grab_page() to call try_grab_compound_head(), while keeping the API contract identical for callers.
Also, now that try_grab_compound_head() always has a caller, remove the __maybe_unused annotation.
---
include/linux/mm.h | 4 ++-- mm/gup.c | 35 +++++------------------------------ 2 files changed, 7 insertions(+), 32 deletions(-)
include/linux/mm.h renamed from include/linux/mm.h~mm-gup-small-refactoring-simplify-try_grab_page +2 -2
@@ -1214,8 +1214,8 @@ static inline void get_page(struct page }bool __must_check try_grab_page (struct page *page,unsigned int flags); -__maybe_unused struct page *try_grab_compound_head (struct page *page,int refs, -unsigned int flags); +struct page *try_grab_compound_head (struct page *page,int refs, +unsigned int flags);static inline __must_check bool try_get_page (struct page *page)
mm/gup.c renamed from mm/gup.c~mm-gup-small-refactoring-simplify-try_grab_page +5 -30
@@ -124,8 +124,8 @@ static inline struct page *try_get_compo* considered failure, and furthermore, a likely bug in the caller, so a warning * is also emitted. */ -__maybe_unused struct page *try_grab_compound_head (struct page *page, -int refs,unsigned int flags) +struct page *try_grab_compound_head (struct page *page, +int refs,unsigned int flags) {if (flags &FOLL_GET )return try_get_compound_head (page, refs);
@@ -208,35 +208,10 @@ static void put_compound_head(struct pag*/ bool __must_check try_grab_page (struct page *page,unsigned int flags) { -WARN_ON_ONCE ((flags & (FOLL_GET |FOLL_PIN )) == (FOLL_GET |FOLL_PIN )); +if (!(flags & (FOLL_GET |FOLL_PIN ))) +return true; -if (flags &FOLL_GET ) -return try_get_page (page); -else if (flags &FOLL_PIN ) { -int refs =1 ; - - page =compound_head (page); - -if (WARN_ON_ONCE (page_ref_count (page) <=0 )) -return false; - -if (hpage_pincount_available (page)) -hpage_pincount_add (page,1 ); -else - refs =GUP_PIN_COUNTING_BIAS ; - -/* -* Similar to try_grab_compound_head(): even if using the -* hpage_pincount_add/_sub() routines, be sure to -* *also* increment the normal page refcount field at least -* once, so that the page really is pinned. -*/ -page_ref_add (page, refs); - -mod_node_page_state (page_pgdat (page),NR_FOLL_PIN_ACQUIRED ,1 ); - } - -return true; +return try_grab_compound_head (page,1 , flags); }/**
_
Andrew Morton
maintainerPATCH 75/212 mm/gup: remove try_get_page(), call try_get_compound_head() directly
In reply to Andrew MortonFrom: John Hubbard <[email protected]>
Subject: mm/gup: remove try_get_page(), call try_get_compound_head() directly
try_get_page() is very similar to try_get_compound_head(), and in fact try_get_page() has fallen a little behind in terms of maintenance:try_get_compound_head() handles speculative page references more thoroughly.
There are only two try_get_page() callsites, so just call try_get_compound_head() directly from those, and remove try_get_page() entirely.
Also, seeing as how this changes try_get_compound_head() into a non-static function, provide some kerneldoc documentation for it.
---
arch/s390/mm/fault.c | 2 +- fs/pipe.c | 2 +- include/linux/mm.h | 10 +--------- mm/gup.c | 21 +++++++++++++++++---- 4 files changed, 20 insertions(+), 15 deletions(-)
arch/s390/mm/fault.c renamed from arch/s390/mm/fault.c~mm-gup-remove-try_get_page-call-try_get_compound_head-directly +1 -1
@@ -817,7 +817,7 @@ void do_secure_storage_access(struct pt_break ;case KERNEL_FAULT : page =phys_to_page (addr); -if (unlikely (!try_get_page (page))) +if (unlikely (!try_get_compound_head (page,1 )))break ; rc =arch_make_page_accessible (page);put_page (page);
fs/pipe.c renamed from fs/pipe.c~mm-gup-remove-try_get_page-call-try_get_compound_head-directly +1 -1
@@ -191,7 +191,7 @@ EXPORT_SYMBOL(generic_pipe_buf_try_steal*/ bool generic_pipe_buf_get (struct pipe_inode_info *pipe,struct pipe_buffer *buf) { -return try_get_page (buf->page); +return try_get_compound_head (buf->page,1 ); }EXPORT_SYMBOL (generic_pipe_buf_get);
include/linux/mm.h renamed from include/linux/mm.h~mm-gup-remove-try_get_page-call-try_get_compound_head-directly +1 -9
@@ -1217,15 +1217,7 @@ bool __must_check try_grab_page(struct pstruct page *try_grab_compound_head (struct page *page,int refs,unsigned int flags); - -static inline __must_check bool try_get_page (struct page *page) -{ - page =compound_head (page); -if (WARN_ON_ONCE (page_ref_count (page) <=0 )) -return false; -page_ref_inc (page); -return true; -} +struct page *try_get_compound_head (struct page *page,int refs);static inline void put_page (struct page *page) {
mm/gup.c renamed from mm/gup.c~mm-gup-remove-try_get_page-call-try_get_compound_head-directly +17 -4
@@ -62,11 +62,24 @@ static void put_page_refs(struct page *pput_page (page); } -/* -* Return the compound head page with ref appropriately incremented, -* or NULL if that failed. +/** +* try_get_compound_head() - return the compound head page with refcount +* appropriately incremented, or NULL if that failed. +* +* This handles potential refcount overflow correctly. It also works correclty +* for various lockless get_user_pages()-related callers, due to the use of +* page_cache_add_speculative(). +* +* Even though the name includes "compound_head", this function is still +* appropriate for callers that have a non-compound @page to get. +* +* @page: pointer to page to be gotten +* @refs: the value to add to the page's refcount +* +* Return: head page (with refcount appropriately incremented) for success, or +* NULL upon failure. */ -static inline struct page *try_get_compound_head (struct page *page,int refs) +struct page *try_get_compound_head (struct page *page,int refs) {struct page *head =compound_head (page);
_
John Hubbard
reviewerRe: [patch 075/212] mm/gup: remove try_get_page(), call try_get_compound_head() directly
On 9/2/21 2:53 PM, Andrew Morton wrote:
...
Quoted 4 lines
mm/gup.c renamed from mm/gup.c~mm-gup-remove-try_get_page-call-try_get_compound_head-directly +0
-0@@ -62,11 +62,24 @@ static void put_page_refs(struct page *pput_page (page);
mm/gup.c static void put_page_refs(struct page *p · line 69
Quoted 10 lines
mm/gup.c renamed from mm/gup.c~mm-gup-remove-try_get_page-call-try_get_compound_head-directly +5
-3} -/* -* Return the compound head page with ref appropriately incremented, -* or NULL if that failed. +/** +* try_get_compound_head() - return the compound head page with refcount +* appropriately incremented, or NULL if that failed. +* +* This handles potential refcount overflow correctly. It also works correclty
s/correclty/correctly/
...that is, if it is reasonable to do a typo fixup at this stage in the cycle.
thanks,
Signature · 2 lines
John Hubbard NVIDIA
Andrew Morton
maintainerPATCH 76/212 fs, mm: fix race in unlinking swapfile
In reply to Andrew MortonFrom: Hugh Dickins <[email protected]>
Subject: fs, mm: fix race in unlinking swapfile
We had a recurring situation in which admin procedures setting up swapfiles would race with test preparation clearing away swapfiles; and just occasionally that got stuck on a swapfile "(deleted)" which could never be swapped off. That is not supposed to be possible.
2.6.28 commit f9454548e17c ("don't unlink an active swapfile") admitted that it was leaving a race window open: now close it.
may_delete() makes the IS_SWAPFILE check (amongst many others) before inode_lock has been taken on target: now repeat just that simple check in vfs_unlink() and vfs_rename(), after taking inode_lock.
Which goes most of the way to fixing the race, but swapon() must also check after it acquires inode_lock, that the file just opened has not already been unlinked.
---
fs/namei.c | 8 +++++++- mm/swapfile.c | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-)
fs/namei.c renamed from fs/namei.c~fs-mm-fix-race-in-unlinking-swapfile +7 -1
@@ -4024,7 +4024,9 @@ int vfs_unlink(struct user_namespace *mnreturn -EPERM ;inode_lock (target); -if (is_local_mountpoint (dentry)) +if (IS_SWAPFILE (target)) + error = -EPERM ; +else if (is_local_mountpoint (dentry)) error = -EBUSY ;else { error =security_inode_unlink (dir, dentry);
@@ -4526,6 +4528,10 @@ int vfs_rename(struct renamedata *rd)else if (target)inode_lock (target); + error = -EPERM ; +if (IS_SWAPFILE (source) || (target &&IS_SWAPFILE (target))) + goto out; + error = -EBUSY ;if (is_local_mountpoint (old_dentry) ||is_local_mountpoint (new_dentry)) goto out;
mm/swapfile.c renamed from mm/swapfile.c~fs-mm-fix-race-in-unlinking-swapfile +6 -0
@@ -3130,6 +3130,7 @@ SYSCALL_DEFINE2(swapon, const char __usestruct filename *name;struct file *swap_file =NULL ;struct address_space *mapping; +struct dentry *dentry;int prio;int error;union swap_header *swap_header;
@@ -3173,6 +3174,7 @@ SYSCALL_DEFINE2(swapon, const char __use p->swap_file = swap_file; mapping = swap_file->f_mapping; + dentry = swap_file->f_path.dentry; inode = mapping->host; error =claim_swapfile (p, inode);
@@ -3180,6 +3182,10 @@ SYSCALL_DEFINE2(swapon, const char __use goto bad_swap;inode_lock (inode); +if (d_unlinked (dentry) ||cant_mount (dentry)) { + error = -ENOENT ; + goto bad_swap_unlock_inode; + }if (IS_SWAPFILE (inode)) { error = -EBUSY ; goto bad_swap_unlock_inode;
_
Andrew Morton
maintainerPATCH 77/212 mm: delete unused get_kernel_page()
In reply to Andrew MortonFrom: John Hubbard <[email protected]>
Subject: mm: delete unused get_kernel_page()
get_kernel_page() was added in 2012 by [1]. It was used for a while for NFS, but then in 2014, a refactoring [2] removed all callers, and it has apparently not been used since.
Remove get_kernel_page() because it has no callers.
[1] commit 18022c5d8627 ("mm: add get_kernel_page[s] for pinning of kernel addresses for I/O")
[2] commit 91f79c43d1b5 ("new helper: iov_iter_get_pages_alloc()")
---
include/linux/mm.h | 1 - mm/swap.c | 22 ---------------------- 2 files changed, 23 deletions(-)
include/linux/mm.h renamed from include/linux/mm.h~mm-delete-unused-get_kernel_page +0 -1
@@ -1839,7 +1839,6 @@ int __account_locked_vm(struct mm_structstruct kvec ;int get_kernel_pages (const struct kvec *iov,int nr_pages,int write,struct page **pages); -int get_kernel_page (unsigned long start,int write,struct page **pages);struct page *get_dump_page (unsigned long addr);extern int try_to_release_page (struct page * page,gfp_t gfp_mask);
mm/swap.c renamed from mm/swap.c~mm-delete-unused-get_kernel_page +0 -22
@@ -179,28 +179,6 @@ int get_kernel_pages(const struct kvec * }EXPORT_SYMBOL_GPL (get_kernel_pages); -/* -* get_kernel_page() - pin a kernel page in memory -* @start: starting kernel address -* @write: pinning for read/write, currently ignored -* @pages: array that receives pointer to the page pinned. -* Must be at least nr_segs long. -* -* Returns 1 if page is pinned. If the page was not pinned, returns -* -errno. The page returned must be released with a put_page() call -* when it is finished with. -*/ -int get_kernel_page (unsigned long start,int write,struct page **pages) -{ -const struct kvec kiov = { - .iov_base = (void *)start, - .iov_len =PAGE_SIZE - }; - -return get_kernel_pages (&kiov,1 , write, pages); -} -EXPORT_SYMBOL_GPL (get_kernel_page); -static void pagevec_lru_move_fn (struct pagevec *pvec,void (*move_fn)(struct page *page,struct lruvec *lruvec)) {
_
Andrew Morton
maintainerPATCH 78/212 shmem: use raw_spinlock_t for ->stat_lock
In reply to Andrew MortonFrom: Sebastian Andrzej Siewior <[email protected]>
Subject: shmem: use raw_spinlock_t for ->stat_lock
Each CPU has SHMEM_INO_BATCH inodes available in ->ino_batch' which is per-CPU. Access here is serialized by disabling preemption. If the pool is empty, it gets reloaded from ->next_ino'. Access here is serialized by ->stat_lock which is a spinlock_t and can not be acquired with disabled preemption.
One way around it would make per-CPU ino_batch struct containing the inode number a local_lock_t.
Another solution is to promote ->stat_lock to a raw_spinlock_t. The critical sections are short. The mpol_put() must be moved outside of the critical section to avoid invoking the destructor with disabled preemption.
---
include/linux/shmem_fs.h | 2 +- mm/shmem.c | 31 +++++++++++++++++-------------- 2 files changed, 18 insertions(+), 15 deletions(-)
include/linux/shmem_fs.h renamed from include/linux/shmem_fs.h~shmem-use-raw_spinlock_t-for-stat_lock +1 -1
@@ -31,7 +31,7 @@ struct shmem_sb_info {struct percpu_counter used_blocks;/* How many are allocated */ unsigned long max_inodes;/* How many inodes are allowed */ unsigned long free_inodes;/* How many are left for allocation */ -spinlock_t stat_lock;/* Serialize shmem_sb_info changes */ +raw_spinlock_t stat_lock;/* Serialize shmem_sb_info changes */ umode_t mode;/* Mount mode for root directory */ unsigned char huge;/* Whether to try for hugepages */ kuid_t uid;/* Mount uid for root directory */
mm/shmem.c renamed from mm/shmem.c~shmem-use-raw_spinlock_t-for-stat_lock +17 -14
@@ -278,10 +278,10 @@ static int shmem_reserve_inode(struct suino_t ino;if (!(sb->s_flags &SB_KERNMOUNT )) { -spin_lock (&sbinfo->stat_lock); +raw_spin_lock (&sbinfo->stat_lock);if (sbinfo->max_inodes) {if (!sbinfo->free_inodes) { -spin_unlock (&sbinfo->stat_lock); +raw_spin_unlock (&sbinfo->stat_lock);return -ENOSPC ; } sbinfo->free_inodes--;
@@ -304,7 +304,7 @@ static int shmem_reserve_inode(struct su } *inop = ino; } -spin_unlock (&sbinfo->stat_lock); +raw_spin_unlock (&sbinfo->stat_lock); }else if (inop) {/* * __shmem_file_setup, one of our callers, is lock-free: it
@@ -319,13 +319,14 @@ static int shmem_reserve_inode(struct su* to worry about things like glibc compatibility. */ ino_t *next_ino; + next_ino =per_cpu_ptr (sbinfo->ino_batch,get_cpu ()); ino = *next_ino;if (unlikely (ino %SHMEM_INO_BATCH ==0 )) { -spin_lock (&sbinfo->stat_lock); +raw_spin_lock (&sbinfo->stat_lock); ino = sbinfo->next_ino; sbinfo->next_ino +=SHMEM_INO_BATCH ; -spin_unlock (&sbinfo->stat_lock); +raw_spin_unlock (&sbinfo->stat_lock);if (unlikely (is_zero_ino (ino))) ino++; }
@@ -341,9 +342,9 @@ static void shmem_free_inode(struct supe {struct shmem_sb_info *sbinfo =SHMEM_SB (sb);if (sbinfo->max_inodes) { -spin_lock (&sbinfo->stat_lock); +raw_spin_lock (&sbinfo->stat_lock); sbinfo->free_inodes++; -spin_unlock (&sbinfo->stat_lock); +raw_spin_unlock (&sbinfo->stat_lock); } }
@@ -1453,10 +1454,10 @@ static struct mempolicy *shmem_get_sbmpo {struct mempolicy *mpol =NULL ;if (sbinfo->mpol) { -spin_lock (&sbinfo->stat_lock);/* prevent replace/use races */ +raw_spin_lock (&sbinfo->stat_lock);/* prevent replace/use races */ mpol = sbinfo->mpol;mpol_get (mpol); -spin_unlock (&sbinfo->stat_lock); +raw_spin_unlock (&sbinfo->stat_lock); }return mpol; }
@@ -3488,9 +3489,10 @@ static int shmem_reconfigure(struct fs_cstruct shmem_options *ctx = fc->fs_private;struct shmem_sb_info *sbinfo =SHMEM_SB (fc->root->d_sb);unsigned long inodes; +struct mempolicy *mpol =NULL ;const char *err; -spin_lock (&sbinfo->stat_lock); +raw_spin_lock (&sbinfo->stat_lock); inodes = sbinfo->max_inodes - sbinfo->free_inodes;if ((ctx->seen &SHMEM_SEEN_BLOCKS ) && ctx->blocks) {if (!sbinfo->max_blocks) {
@@ -3535,14 +3537,15 @@ static int shmem_reconfigure(struct fs_c* Preserve previous mempolicy unless mpol remount option was specified. */ if (ctx->mpol) { -mpol_put (sbinfo->mpol); + mpol = sbinfo->mpol; sbinfo->mpol = ctx->mpol;/* transfers initial ref */ ctx->mpol =NULL ; } -spin_unlock (&sbinfo->stat_lock); +raw_spin_unlock (&sbinfo->stat_lock); +mpol_put (mpol);return 0 ; out: -spin_unlock (&sbinfo->stat_lock); +raw_spin_unlock (&sbinfo->stat_lock);return invalfc (fc,"%s" , err); }
@@ -3659,7 +3662,7 @@ static int shmem_fill_super(struct super sbinfo->mpol = ctx->mpol; ctx->mpol =NULL ; -spin_lock_init (&sbinfo->stat_lock); +raw_spin_lock_init (&sbinfo->stat_lock);if (percpu_counter_init (&sbinfo->used_blocks,0 ,GFP_KERNEL )) goto failed;spin_lock_init (&sbinfo->shrinklist_lock);
_
Andrew Morton
maintainerPATCH 79/212 shmem: remove unneeded variable ret
In reply to Andrew MortonFrom: Miaohe Lin <[email protected]>
Subject: shmem: remove unneeded variable ret
Patch series "Cleanups for shmem".
This series contains cleanups to remove unneeded variable, header file, function forward declaration and so on. More details can be found in the respective changelogs.
This patch (of 4):
The local variable ret is always equal to -ENOMEM and never touched. So remove it and return -ENOMEM directly to simplify the code.
---
mm/shmem.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
mm/shmem.c renamed from mm/shmem.c~shmem-remove-unneeded-variable-ret +1 -2
@@ -3616,7 +3616,6 @@ static int shmem_fill_super(struct superstruct shmem_options *ctx = fc->fs_private;struct inode *inode;struct shmem_sb_info *sbinfo; -int err = -ENOMEM ;/* Round up to L1_CACHE_BYTES to resist false sharing */ sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
@@ -3694,7 +3693,7 @@ static int shmem_fill_super(struct super failed:shmem_put_super (sb); -return err; +return -ENOMEM ; }static int shmem_get_tree (struct fs_context *fc)
_
Andrew Morton
maintainerPATCH 80/212 shmem: remove unneeded header file
In reply to Andrew MortonFrom: Miaohe Lin <[email protected]>
Subject: shmem: remove unneeded header file
mfill_atomic_install_pte() is introduced to install pte and update mmu cache since commit bf6ebd97aba0 ("userfaultfd/shmem: modify shmem_mfill_atomic_pte to use install_pte()"). So we should remove tlbflush.h as update_mmu_cache() is not called here now.
---
mm/shmem.c | 2 -- 1 file changed, 2 deletions(-)
mm/shmem.c renamed from mm/shmem.c~shmem-remove-unneeded-header-file +0 -2
@@ -39,8 +39,6 @@#include <linux/frontswap.h> #include <linux/fs_parser.h> -#include <asm/tlbflush.h> /* for arch/microblaze update_mmu_cache() */ -static struct vfsmount *shm_mnt;#ifdef CONFIG_SHMEM
_
Andrew Morton
maintainerPATCH 81/212 shmem: remove unneeded function forward declaration
In reply to Andrew MortonFrom: Miaohe Lin <[email protected]>
Subject: shmem: remove unneeded function forward declaration
The forward declaration for shmem_should_replace_page() and shmem_replace_page() is unnecessary. Remove them.
---
mm/shmem.c | 3 --- 1 file changed, 3 deletions(-)
mm/shmem.c renamed from mm/shmem.c~shmem-remove-unneeded-function-forward-declaration +0 -3
@@ -135,9 +135,6 @@ static unsigned long shmem_default_max_i }#endif -static bool shmem_should_replace_page (struct page *page,gfp_t gfp); -static int shmem_replace_page (struct page **pagep,gfp_t gfp, -struct shmem_inode_info *info,pgoff_t index); static int shmem_swapin_page(struct inode *inode, pgoff_t index, struct page **pagep, enum sgp_type sgp, gfp_t gfp, struct vm_area_struct *vma,
_
Andrew Morton
maintainerPATCH 82/212 shmem: include header file to declare swap_info
In reply to Andrew MortonFrom: Miaohe Lin <[email protected]>
Subject: shmem: include header file to declare swap_info
It's bad to extern swap_info[] in .c. Include corresponding header file instead.
---
mm/shmem.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
mm/shmem.c renamed from mm/shmem.c~shmem-include-header-file-to-declare-swap_info +1 -2
@@ -38,6 +38,7 @@#include <linux/hugetlb.h> #include <linux/frontswap.h> #include <linux/fs_parser.h> +#include <linux/swapfile.h> static struct vfsmount *shm_mnt;
@@ -1152,8 +1153,6 @@ static void shmem_evict_inode(struct inoclear_inode (inode); } -extern struct swap_info_struct *swap_info[]; - static int shmem_find_swap_entries(struct address_space *mapping, pgoff_t start, unsigned int nr_entries, struct page **entries, pgoff_t *indices,
_
Andrew Morton
maintainerPATCH 83/212 huge tmpfs: fix fallocate(vanilla) advance over huge pages
In reply to Andrew MortonFrom: Hugh Dickins <[email protected]>
Subject: huge tmpfs: fix fallocate(vanilla) advance over huge pages
Patch series "huge tmpfs: shmem_is_huge() fixes and cleanups".
A series of huge tmpfs fixes and cleanups.
This patch (of 9):
shmem_fallocate() goes to a lot of trouble to leave its newly allocated pages !Uptodate, partly to identify and undo them on failure, partly to leave the overhead of clearing them until later. But the huge page case did not skip to the end of the extent, walked through the tail pages one by one, and appeared to work just fine: but in doing so, cleared and Uptodated the huge page, so there was no way to undo it on failure.
And by setting Uptodate too soon, it messed up both its nr_falloced and nr_unswapped counts, so that the intended "time to give up" heuristic did not work at all.
Now advance immediately to the end of the huge extent, with a comment on why this is more than just an optimization. But although this speeds up huge tmpfs fallocation, it does leave the clearing until first use, and some users may have come to appreciate slow fallocate but fast first use:
if they complain, then we can consider adding a pass to clear at the end.
---
mm/shmem.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-)
mm/shmem.c renamed from mm/shmem.c~huge-tmpfs-fix-fallocatevanilla-advance-over-huge-pages +16 -3
@@ -2719,7 +2719,7 @@ static long shmem_fallocate(struct file inode->i_private = &shmem_falloc;spin_unlock (&inode->i_lock); -for (index = start; index < end; index++) { +for (index = start; index < end; ) {struct page *page;/*
@@ -2742,13 +2742,26 @@ static long shmem_fallocate(struct file goto undone; } + index++; +/* +* Here is a more important optimization than it appears: +* a second SGP_FALLOC on the same huge page will clear it, +* making it PageUptodate and un-undoable if we fail later. +*/ +if (PageTransCompound (page)) { + index =round_up (index,HPAGE_PMD_NR ); +/* Beware 32-bit wraparound */ +if (!index) + index--; + } +/* * Inform shmem_writepage() how far we have reached. * No need for lock or barrier: we have the page lock. */ - shmem_falloc.next++;if (!PageUptodate (page)) - shmem_falloc.nr_falloced++; + shmem_falloc.nr_falloced += index - shmem_falloc.next; + shmem_falloc.next = index;/* * If !PageUptodate, leave it that way so that freeable pages
_
Andrew Morton
maintainerPATCH 84/212 huge tmpfs: fix split_huge_page() after FALLOC_FL_KEEP_SIZE
In reply to Andrew MortonFrom: Hugh Dickins <[email protected]>
Subject: huge tmpfs: fix split_huge_page() after FALLOC_FL_KEEP_SIZE
A successful shmem_fallocate() guarantees that the extent has been reserved, even beyond i_size when the FALLOC_FL_KEEP_SIZE flag was used. But that guarantee is broken by shmem_unused_huge_shrink()'s attempts to split huge pages and free their excess beyond i_size; and by other uses of split_huge_page() near i_size.
It's sad to add a shmem inode field just for this, but I did not find a better way to keep the guarantee. A flag to say KEEP_SIZE has been used would be cheaper, but I'm averse to unclearable flags. The fallocend field is not perfect either (many disjoint ranges might be fallocated), but good enough; and gains another use later on.
---
include/linux/shmem_fs.h | 13 +++++++++++++ mm/huge_memory.c | 6 ++++-- mm/shmem.c | 15 ++++++++++++++- 3 files changed, 31 insertions(+), 3 deletions(-)
include/linux/shmem_fs.h renamed from include/linux/shmem_fs.h~huge-tmpfs-fix-split_huge_page-after-falloc_fl_keep_size +13 -0
@@ -18,6 +18,7 @@ struct shmem_inode_info {unsigned long flags;unsigned long alloced;/* data pages alloced to file */ unsigned long swapped;/* subtotal assigned to swap */ +pgoff_t fallocend;/* highest fallocate endindex */ struct list_head shrinklist;/* shrinkable hpage inodes */ struct list_head swaplist;/* chain of maybes on swap */ struct shared_policy policy;/* NUMA memory alloc policy */
@@ -119,6 +120,18 @@ static inline bool shmem_file(struct filreturn shmem_mapping (file->f_mapping); } +/* +* If fallocate(FALLOC_FL_KEEP_SIZE) has been used, there may be pages +* beyond i_size's notion of EOF, which fallocate has committed to reserving: +* which split_huge_page() must therefore not delete. This use of a single +* "fallocend" per inode errs on the side of not deleting a reservation when +* in doubt: there are plenty of cases when it preserves unreserved pages. +*/ +static inline pgoff_t shmem_fallocend (struct inode *inode,pgoff_t eof) +{ +return max (eof,SHMEM_I (inode)->fallocend); +} +extern bool shmem_charge (struct inode *inode,long pages);extern void shmem_uncharge (struct inode *inode,long pages);
mm/huge_memory.c renamed from mm/huge_memory.c~huge-tmpfs-fix-split_huge_page-after-falloc_fl_keep_size +4 -2
@@ -2454,11 +2454,11 @@ static void __split_huge_page(struct pagfor (i = nr -1 ; i >=1 ; i--) {__split_huge_page_tail (head, i, lruvec, list); -/* Some pages can be beyond i_size: drop them from page cache */ +/* Some pages can be beyond EOF: drop them from page cache */ if (head[i].index >= end) {ClearPageDirty (head + i);__delete_from_page_cache (head + i,NULL ); -if (IS_ENABLED (CONFIG_SHMEM ) &&PageSwapBacked (head)) +if (shmem_mapping (head->mapping))shmem_uncharge (head->mapping->host,1 );put_page (head + i); }else if (!PageAnon (page)) {
@@ -2686,6 +2686,8 @@ int split_huge_page_to_list(struct page* head page lock is good enough to serialize the trimming. */ end =DIV_ROUND_UP (i_size_read (mapping->host),PAGE_SIZE ); +if (shmem_mapping (mapping)) + end =shmem_fallocend (mapping->host, end); }/*
mm/shmem.c renamed from mm/shmem.c~huge-tmpfs-fix-split_huge_page-after-falloc_fl_keep_size +14 -1
@@ -902,6 +902,9 @@ static void shmem_undo_range(struct inodif (lend ==-1 ) end =-1 ;/* unsigned, so actually very big */ +if (info->fallocend > start && info->fallocend <= end && !unfalloc) + info->fallocend = start; +pagevec_init (&pvec); index = start; while (index < end && find_lock_entries(mapping, index, end - 1,
@@ -2650,7 +2653,7 @@ static long shmem_fallocate(struct filestruct shmem_sb_info *sbinfo =SHMEM_SB (inode->i_sb);struct shmem_inode_info *info =SHMEM_I (inode);struct shmem_falloc shmem_falloc; -pgoff_t start, index, end; +pgoff_t start, index, end, undo_fallocend;int error;if (mode & ~(FALLOC_FL_KEEP_SIZE |FALLOC_FL_PUNCH_HOLE ))
@@ -2719,6 +2722,15 @@ static long shmem_fallocate(struct file inode->i_private = &shmem_falloc;spin_unlock (&inode->i_lock); +/* +* info->fallocend is only relevant when huge pages might be +* involved: to prevent split_huge_page() freeing fallocated +* pages when FALLOC_FL_KEEP_SIZE committed beyond i_size. +*/ + undo_fallocend = info->fallocend; +if (info->fallocend < end) + info->fallocend = end; +for (index = start; index < end; ) {struct page *page;
@@ -2733,6 +2745,7 @@ static long shmem_fallocate(struct fileelse error =shmem_getpage (inode, index, &page,SGP_FALLOC );if (error) { + info->fallocend = undo_fallocend;/* Remove the !PageUptodate pages we added */ if (index > start) { shmem_undo_range(inode,
_
Andrew Morton
maintainerPATCH 85/212 huge tmpfs: remove shrinklist addition from shmem_setattr()
In reply to Andrew MortonFrom: Hugh Dickins <[email protected]>
Subject: huge tmpfs: remove shrinklist addition from shmem_setattr()
There's a block of code in shmem_setattr() to add the inode to shmem_unused_huge_shrink()'s shrinklist when lowering i_size: it dates from before 5.7 changed truncation to do split_huge_page() for itself, and should have been removed at that time.
I am over-stating that: split_huge_page() can fail (notably if there's an extra reference to the page at that time), so there might be value in retrying. But there were already retries as truncation worked through the tails, and this addition risks repeating unsuccessful retries
indefinitely: I'd rather remove it now, and work on reducing the chance of split_huge_page() failures separately, if we need to.
---
mm/shmem.c | 19 ------------------- 1 file changed, 19 deletions(-)
mm/shmem.c renamed from mm/shmem.c~huge-tmpfs-remove-shrinklist-addition-from-shmem_setattr +0 -19
@@ -1058,7 +1058,6 @@ static int shmem_setattr(struct user_nam {struct inode *inode =d_inode (dentry);struct shmem_inode_info *info =SHMEM_I (inode); -struct shmem_sb_info *sbinfo =SHMEM_SB (inode->i_sb);int error; error =setattr_prepare (&init_user_ns, dentry, attr);
@@ -1094,24 +1093,6 @@ static int shmem_setattr(struct user_namif (oldsize > holebegin)unmap_mapping_range (inode->i_mapping, holebegin,0 ,1 ); - -/* -* Part of the huge page can be beyond i_size: subject -* to shrink under memory pressure. -*/ -if (IS_ENABLED (CONFIG_TRANSPARENT_HUGEPAGE )) { -spin_lock (&sbinfo->shrinklist_lock); -/* -* _careful to defend against unlocked access to -* ->shrink_list in shmem_unused_huge_shrink() -*/ -if (list_empty_careful (&info->shrinklist)) { -list_add_tail (&info->shrinklist, - &sbinfo->shrinklist); - sbinfo->shrinklist_len++; - } -spin_unlock (&sbinfo->shrinklist_lock); - } } }
_
Andrew Morton
maintainerPATCH 86/212 huge tmpfs: revert shmem's use of transhuge_vma_enabled()
In reply to Andrew MortonFrom: Hugh Dickins <[email protected]>
Subject: huge tmpfs: revert shmem's use of transhuge_vma_enabled()
5.14 commit e6be37b2e7bd ("mm/huge_memory.c: add missing read-only THP checking in transparent_hugepage_enabled()") added transhuge_vma_enabled() as a wrapper for two very different checks (one check is whether the app has marked its address range not to use THPs, the other check is whether the app is running in a hierarchy that has been marked never to use THPs). shmem_huge_enabled() prefers to show those two checks explicitly, as before.
---
mm/shmem.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
mm/shmem.c renamed from mm/shmem.c~huge-tmpfs-revert-shmems-use-of-transhuge_vma_enabled +2 -1
@@ -3987,7 +3987,8 @@ bool shmem_huge_enabled(struct vm_area_sloff_t i_size;pgoff_t off; -if (!transhuge_vma_enabled (vma, vma->vm_flags)) +if ((vma->vm_flags &VM_NOHUGEPAGE ) || +test_bit (MMF_DISABLE_THP , &vma->vm_mm->flags))return false;if (shmem_huge ==SHMEM_HUGE_FORCE )return true;
_
Andrew Morton
maintainerPATCH 87/212 huge tmpfs: move shmem_huge_enabled() upwards
In reply to Andrew MortonFrom: Hugh Dickins <[email protected]>
Subject: huge tmpfs: move shmem_huge_enabled() upwards
shmem_huge_enabled() is about to be enhanced into shmem_is_huge(), so that it can be used more widely throughout: before making functional changes, shift it to its final position (to avoid forward declaration).
---
mm/shmem.c | 72 ++++++++++++++++++++++++--------------------------- 1 file changed, 35 insertions(+), 37 deletions(-)
mm/shmem.c renamed from mm/shmem.c~huge-tmpfs-move-shmem_huge_enabled-upwards +35 -37
@@ -473,6 +473,41 @@ static bool shmem_confirm_swap(struct adstatic int shmem_huge__read_mostly ; +bool shmem_huge_enabled (struct vm_area_struct *vma) +{ +struct inode *inode =file_inode (vma->vm_file); +struct shmem_sb_info *sbinfo =SHMEM_SB (inode->i_sb); +loff_t i_size; +pgoff_t off; + +if ((vma->vm_flags &VM_NOHUGEPAGE ) || +test_bit (MMF_DISABLE_THP , &vma->vm_mm->flags)) +return false; +if (shmem_huge ==SHMEM_HUGE_FORCE ) +return true; +if (shmem_huge ==SHMEM_HUGE_DENY ) +return false; +switch (sbinfo->huge) { +case SHMEM_HUGE_NEVER : +return false; +case SHMEM_HUGE_ALWAYS : +return true; +case SHMEM_HUGE_WITHIN_SIZE : + off =round_up (vma->vm_pgoff,HPAGE_PMD_NR ); + i_size =round_up (i_size_read (inode),PAGE_SIZE ); +if (i_size >=HPAGE_PMD_SIZE && + i_size >>PAGE_SHIFT >= off) +return true; + fallthrough; +case SHMEM_HUGE_ADVISE : +/* TODO: implement fadvise() hints */ +return (vma->vm_flags &VM_HUGEPAGE ); +default : +VM_BUG_ON (1 ); +return false; + } +} +#if defined(CONFIG_SYSFS )static int shmem_parse_huge (const char *str) {
@@ -3979,43 +4014,6 @@ struct kobj_attribute shmem_enabled_attr__ATTR (shmem_enabled,0644 , shmem_enabled_show, shmem_enabled_store);#endif /* CONFIG_TRANSPARENT_HUGEPAGE && CONFIG_SYSFS */ -#ifdef CONFIG_TRANSPARENT_HUGEPAGE -bool shmem_huge_enabled (struct vm_area_struct *vma) -{ -struct inode *inode =file_inode (vma->vm_file); -struct shmem_sb_info *sbinfo =SHMEM_SB (inode->i_sb); -loff_t i_size; -pgoff_t off; - -if ((vma->vm_flags &VM_NOHUGEPAGE ) || -test_bit (MMF_DISABLE_THP , &vma->vm_mm->flags)) -return false; -if (shmem_huge ==SHMEM_HUGE_FORCE ) -return true; -if (shmem_huge ==SHMEM_HUGE_DENY ) -return false; -switch (sbinfo->huge) { -case SHMEM_HUGE_NEVER : -return false; -case SHMEM_HUGE_ALWAYS : -return true; -case SHMEM_HUGE_WITHIN_SIZE : - off =round_up (vma->vm_pgoff,HPAGE_PMD_NR ); - i_size =round_up (i_size_read (inode),PAGE_SIZE ); -if (i_size >=HPAGE_PMD_SIZE && - i_size >>PAGE_SHIFT >= off) -return true; - fallthrough; -case SHMEM_HUGE_ADVISE : -/* TODO: implement fadvise() hints */ -return (vma->vm_flags &VM_HUGEPAGE ); -default : -VM_BUG_ON (1 ); -return false; - } -} -#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ -#else /* !CONFIG_SHMEM */ /*
_
Andrew Morton
maintainerPATCH 88/212 huge tmpfs: SGP_NOALLOC to stop collapse_file() on race
In reply to Andrew MortonFrom: Hugh Dickins <[email protected]>
Subject: huge tmpfs: SGP_NOALLOC to stop collapse_file() on race
khugepaged's collapse_file() currently uses SGP_NOHUGE to tell shmem_getpage() not to try allocating a huge page, in the very unlikely event that a racing hole-punch removes the swapped or fallocated page as soon as i_pages lock is dropped.
We want to consolidate shmem's huge decisions, removing SGP_HUGE and SGP_NOHUGE; but cannot quite persuade ourselves that it's okay to regress the protection in this case - Yang Shi points out that the huge page would remain indefinitely, charged to root instead of the intended memcg.
collapse_file() should not even allocate a small page in this case: why proceed if someone is punching a hole? SGP_READ is almost the right flag here, except that it optimizes away from a fallocated page, with NULL to tell caller to fill with zeroes (like a hole); whereas collapse_file()'s sequence relies on using a cache page. Add SGP_NOALLOC just for this.
There are too many consecutive "if (page"s there in shmem_getpage_gfp():
group it better; and fix the outdated "bring it back from swap" comment.
---
include/linux/shmem_fs.h | 1 + mm/khugepaged.c | 2 +- mm/shmem.c | 29 +++++++++++++++++------------ 3 files changed, 19 insertions(+), 13 deletions(-)
include/linux/shmem_fs.h renamed from include/linux/shmem_fs.h~huge-tmpfs-sgp_noalloc-to-stop-collapse_file-on-race +1 -0
@@ -94,6 +94,7 @@ extern unsigned long shmem_partial_swap_/* Flag allocation requirements to shmem_getpage */ enum sgp_type {SGP_READ ,/* don't exceed i_size, don't allocate page */ +SGP_NOALLOC ,/* similar, but fail on hole or use fallocated page */ SGP_CACHE ,/* don't exceed i_size, may allocate page */ SGP_NOHUGE ,/* like SGP_CACHE, but no huge pages */ SGP_HUGE ,/* like SGP_CACHE, huge pages preferred */
mm/khugepaged.c renamed from mm/khugepaged.c~huge-tmpfs-sgp_noalloc-to-stop-collapse_file-on-race +1 -1
@@ -1721,7 +1721,7 @@ static void collapse_file(struct mm_struxas_unlock_irq (&xas);/* swap in or instantiate fallocated page */ if (shmem_getpage (mapping->host, index, &page, -SGP_NOHUGE )) { +SGP_NOALLOC )) { result =SCAN_FAIL ; goto xa_unlocked; }
mm/shmem.c renamed from mm/shmem.c~huge-tmpfs-sgp_noalloc-to-stop-collapse_file-on-race +17 -12
@@ -1854,26 +1854,31 @@ repeat:return error; } -if (page) +if (page) { hindex = page->index; -if (page && sgp ==SGP_WRITE ) -mark_page_accessed (page); - -/* fallocated page? */ -if (page && !PageUptodate (page)) { +if (sgp ==SGP_WRITE ) +mark_page_accessed (page); +if (PageUptodate (page)) + goto out; +/* fallocated page */ if (sgp !=SGP_READ ) goto clear;unlock_page (page);put_page (page); - page =NULL ; - hindex = index; } -if (page || sgp ==SGP_READ ) - goto out;/* -* Fast cache lookup did not find it: -* bring it back from swap or allocate. +* SGP_READ: succeed on hole, with NULL page, letting caller zero. +* SGP_NOALLOC: fail on hole, with NULL page, letting caller fail. +*/ + *pagep =NULL ; +if (sgp ==SGP_READ ) +return 0 ; +if (sgp ==SGP_NOALLOC ) +return -ENOENT ; + +/* +* Fast cache lookup and swap lookup did not find it: allocate. */ if (vma &&userfaultfd_missing (vma)) {
_
Andrew Morton
maintainerPATCH 89/212 huge tmpfs: shmem_is_huge(vma, inode, index)
In reply to Andrew MortonFrom: Hugh Dickins <[email protected]>
Subject: huge tmpfs: shmem_is_huge(vma, inode, index)
Extend shmem_huge_enabled(vma) to shmem_is_huge(vma, inode, index), so that a consistent set of checks can be applied, even when the inode is accessed through read/write syscalls (with NULL vma) instead of mmaps (the index argument is seldom of interest, but required by mount option "huge=within_size"). Clean up and rearrange the checks a little.
This then replaces the checks which shmem_fault() and shmem_getpage_gfp() were making, and eliminates the SGP_HUGE and SGP_NOHUGE modes.
Replace a couple of 0s by explicit SHMEM_HUGE_NEVERs; and replace the obscure !shmem_mapping() symlink check by explicit S_ISLNK() - nothing else needs that symlink check, so leave it there in shmem_getpage_gfp().
---
include/linux/shmem_fs.h | 9 ++- mm/shmem.c | 84 +++++++++++-------------------------- 2 files changed, 31 insertions(+), 62 deletions(-)
include/linux/shmem_fs.h renamed from include/linux/shmem_fs.h~huge-tmpfs-shmem_is_hugevma-inode-index +6 -3
@@ -86,7 +86,12 @@ extern void shmem_truncate_range(structextern int shmem_unuse (unsigned int type,bool frontswap,unsigned long *fs_pages_to_unuse); -extern bool shmem_huge_enabled (struct vm_area_struct *vma); +extern bool shmem_is_huge (struct vm_area_struct *vma, +struct inode *inode,pgoff_t index); +static inline bool shmem_huge_enabled (struct vm_area_struct *vma) +{ +return shmem_is_huge (vma,file_inode (vma->vm_file), vma->vm_pgoff); +}extern unsigned long shmem_swap_usage (struct vm_area_struct *vma);extern unsigned long shmem_partial_swap_usage (struct address_space *mapping,pgoff_t start,pgoff_t end);
@@ -96,8 +101,6 @@ enum sgp_type {SGP_READ ,/* don't exceed i_size, don't allocate page */ SGP_NOALLOC ,/* similar, but fail on hole or use fallocated page */ SGP_CACHE ,/* don't exceed i_size, may allocate page */ -SGP_NOHUGE ,/* like SGP_CACHE, but no huge pages */ -SGP_HUGE ,/* like SGP_CACHE, huge pages preferred */ SGP_WRITE ,/* may exceed i_size, may allocate !Uptodate page */ SGP_FALLOC, /* like SGP_WRITE, but make existing page Uptodate */ };
mm/shmem.c renamed from mm/shmem.c~huge-tmpfs-shmem_is_hugevma-inode-index +25 -59
150 lines not on this page · raw message
_
Andrew Morton
maintainerPATCH 90/212 huge tmpfs: decide stat.st_blksize by shmem_is_huge()
In reply to Andrew MortonFrom: Hugh Dickins <[email protected]>
Subject: huge tmpfs: decide stat.st_blksize by shmem_is_huge()
4.18 commit 89fdcd262fd4 ("mm: shmem: make stat.st_blksize return huge page size if THP is on") added is_huge_enabled() to decide st_blksize: if hugeness is to be defined per file, that will need to be replaced by shmem_is_huge().
This does give a different answer (No) for small files on a "huge=within_size" mount: but that can be considered a minor bugfix. And a different answer (No) for default files on a "huge=advise" mount: I'm reluctant to complicate it, just to reproduce the same debatable answer as before.
---
mm/shmem.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-)
mm/shmem.c renamed from mm/shmem.c~huge-tmpfs-decide-statst_blksize-by-shmem_is_huge +1 -11
@@ -686,15 +686,6 @@ static unsigned long shmem_unused_huge_s }#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ -static inline bool is_huge_enabled (struct shmem_sb_info *sbinfo) -{ -if (IS_ENABLED (CONFIG_TRANSPARENT_HUGEPAGE ) && - (shmem_huge ==SHMEM_HUGE_FORCE || sbinfo->huge) && - shmem_huge !=SHMEM_HUGE_DENY ) -return true; -return false; -} -/* * Like add_to_page_cache_locked, but error if expected item has gone. */
@@ -1075,7 +1066,6 @@ static int shmem_getattr(struct user_nam {struct inode *inode = path->dentry->d_inode;struct shmem_inode_info *info =SHMEM_I (inode); -struct shmem_sb_info *sb_info =SHMEM_SB (inode->i_sb);if (info->alloced - info->swapped != inode->i_mapping->nrpages) {spin_lock_irq (&info->lock);
@@ -1084,7 +1074,7 @@ static int shmem_getattr(struct user_nam }generic_fillattr (&init_user_ns, inode, stat); -if (is_huge_enabled (sb_info)) +if (shmem_is_huge (NULL , inode,0 )) stat->blksize =HPAGE_PMD_SIZE ;return 0 ;
_
Andrew Morton
maintainerPATCH 91/212 shmem: shmem_writepage() split unlikely i915 THP
In reply to Andrew MortonFrom: Hugh Dickins <[email protected]>
Subject: shmem: shmem_writepage() split unlikely i915 THP
drivers/gpu/drm/i915/gem/i915_gem_shmem.c contains a shmem_writeback() which calls shmem_writepage() from a shrinker: that usually works well enough; but if /sys/kernel/mm/transparent_hugepage/shmem_enabled has been set to "always" (intended to be usable) or "force" (forces huge everywhere for easy testing), shmem_writepage() is surprised to be called with a huge page, and crashes on the VM_BUG_ON_PAGE(PageCompound) (I did not find out where the crash happens when CONFIG_DEBUG_VM is off).
LRU page reclaim always splits the shmem huge page first: I'd prefer not to demand that of i915, so check and split compound in shmem_writepage().
Patch history: when first sent last year
http://lkml.kernel.org/r/[email protected]
https://lore.kernel.org/linux-mm/20200919042009.bomzxmrg7%[email protected]/
Matthew Wilcox noticed that tail pages were wrongly left clean. This version brackets the split with Set and Clear PageDirty as he suggested:
which works very well, even if it falls short of our aspirations. And recently I realized that the crash is not limited to the testing option "force", but affects "always" too: which is more important to fix.
---
mm/shmem.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
mm/shmem.c renamed from mm/shmem.c~shmem-shmem_writepage-split-unlikely-i915-thp +13 -1
@@ -1344,7 +1344,19 @@ static int shmem_writepage(struct page *swp_entry_t swap;pgoff_t index; -VM_BUG_ON_PAGE (PageCompound (page), page); +/* +* If /sys/kernel/mm/transparent_hugepage/shmem_enabled is "always" or +* "force", drivers/gpu/drm/i915/gem/i915_gem_shmem.c gets huge pages, +* and its shmem_writeback() needs them to be split when swapping. +*/ +if (PageTransCompound (page)) { +/* Ensure the subpages are still dirty */ +SetPageDirty (page); +if (split_huge_page (page) <0 ) + goto redirty; +ClearPageDirty (page); + } +BUG_ON (!PageLocked (page)); mapping = page->mapping; index = page->index;
_
Andrew Morton
maintainerPATCH 92/212 mm, memcg: add mem_cgroup_disabled checks in vmpressure and swap-related functions
In reply to Andrew MortonFrom: Suren Baghdasaryan <[email protected]>
Subject: mm, memcg: add mem_cgroup_disabled checks in vmpressure and swap-related functions
Add mem_cgroup_disabled check in vmpressure, mem_cgroup_uncharge_swap and cgroup_throttle_swaprate functions. This minimizes the memcg overhead in the pagefault and exit_mmap paths when memcgs are disabled using cgroup_disable=memory command-line option.
This change results in ~2.1% overhead reduction when running PFT test [1] comparing {CONFIG_MEMCG=n, CONFIG_MEMCG_SWAP=n} against {CONFIG_MEMCG=y, CONFIG_MEMCG_SWAP=y, cgroup_disable=memory} configuration on an 8-core ARM64 Android device.
[1] https://lkml.org/lkml/2006/8/29/294 also used in mmtests suite
---
mm/memcontrol.c | 3 +++ mm/swapfile.c | 3 +++ mm/vmpressure.c | 7 ++++++- 3 files changed, 12 insertions(+), 1 deletion(-)
mm/memcontrol.c renamed from mm/memcontrol.c~mm-memcg-add-mem_cgroup_disabled-checks-in-vmpressure-and-swap-related-functions +3 -0
@@ -7297,6 +7297,9 @@ void mem_cgroup_uncharge_swap(swp_entry_struct mem_cgroup *memcg;unsigned short id; +if (mem_cgroup_disabled ()) +return ; + id =swap_cgroup_record (entry,0 , nr_pages);rcu_read_lock (); memcg =mem_cgroup_from_id (id);
mm/swapfile.c renamed from mm/swapfile.c~mm-memcg-add-mem_cgroup_disabled-checks-in-vmpressure-and-swap-related-functions +3 -0
@@ -3784,6 +3784,9 @@ void cgroup_throttle_swaprate(struct pagstruct swap_info_struct *si, *next;int nid =page_to_nid (page); +if (mem_cgroup_disabled ()) +return ; +if (!(gfp_mask & __GFP_IO))return ;
mm/vmpressure.c renamed from mm/vmpressure.c~mm-memcg-add-mem_cgroup_disabled-checks-in-vmpressure-and-swap-related-functions +6 -1
@@ -240,7 +240,12 @@ static void vmpressure_work_fn(struct wovoid vmpressure (gfp_t gfp,struct mem_cgroup *memcg,bool tree,unsigned long scanned,unsigned long reclaimed) { -struct vmpressure *vmpr =memcg_to_vmpressure (memcg); +struct vmpressure *vmpr; + +if (mem_cgroup_disabled ()) +return ; + + vmpr =memcg_to_vmpressure (memcg);/* * Here we only want to account pressure that userland is able to
_
Andrew Morton
maintainerPATCH 93/212 mm, memcg: inline mem_cgroup_{charge/uncharge} to improve disabled memcg config
In reply to Andrew MortonFrom: Suren Baghdasaryan <[email protected]>
Subject: mm, memcg: inline mem_cgroup_{charge/uncharge} to improve disabled memcg config
Inline mem_cgroup_{charge/uncharge} and mem_cgroup_uncharge_list functions functions to perform mem_cgroup_disabled static key check inline before calling the main body of the function. This minimizes the memcg overhead in the pagefault and exit_mmap paths when memcgs are disabled using cgroup_disable=memory command-line option.
This change results in ~0.4% overhead reduction when running PFT test [1] comparing {CONFIG_MEMCG=n} against {CONFIG_MEMCG=y, cgroup_disable=memory} configuration on an 8-core ARM64 Android device.
[1] https://lkml.org/lkml/2006/8/29/294 also used in mmtests suite
---
include/linux/memcontrol.h | 28 +++++++++++++++++++++++++--- mm/memcontrol.c | 33 ++++++++++++--------------------- 2 files changed, 37 insertions(+), 24 deletions(-)
include/linux/memcontrol.h renamed from include/linux/memcontrol.h~mm-memcg-inline-mem_cgroup_charge-uncharge-to-improve-disabled-memcg-config +25 -3
@@ -693,13 +693,35 @@ static inline bool mem_cgroup_below_min(page_counter_read (&memcg->memory); } -int mem_cgroup_charge (struct page *page,struct mm_struct *mm,gfp_t gfp_mask); +int __mem_cgroup_charge (struct page *page,struct mm_struct *mm, +gfp_t gfp_mask); +static inline int mem_cgroup_charge (struct page *page,struct mm_struct *mm, +gfp_t gfp_mask) +{ +if (mem_cgroup_disabled ()) +return 0 ; +return __mem_cgroup_charge (page, mm, 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); +void __mem_cgroup_uncharge (struct page *page); +static inline void mem_cgroup_uncharge (struct page *page) +{ +if (mem_cgroup_disabled ()) +return ; +__mem_cgroup_uncharge (page); +} + +void __mem_cgroup_uncharge_list (struct list_head *page_list); +static inline void mem_cgroup_uncharge_list (struct list_head *page_list) +{ +if (mem_cgroup_disabled ()) +return ; +__mem_cgroup_uncharge_list (page_list); +}void mem_cgroup_migrate (struct page *oldpage,struct page *newpage);
mm/memcontrol.c renamed from mm/memcontrol.c~mm-memcg-inline-mem_cgroup_charge-uncharge-to-improve-disabled-memcg-config +12 -21
@@ -6693,8 +6693,7 @@ void mem_cgroup_calculate_protection(str atomic_long_read(&parent->memory.children_low_usage))); } -static int __mem_cgroup_charge (struct page *page,struct mem_cgroup *memcg, -gfp_t gfp) +static int charge_memcg (struct page *page,struct mem_cgroup *memcg,gfp_t gfp) {unsigned int nr_pages =thp_nr_pages (page);int ret;
@@ -6715,7 +6714,7 @@ out: }/** -* mem_cgroup_charge - charge a newly allocated page to a cgroup +* __mem_cgroup_charge - charge a newly allocated page to a cgroup * @page: page to charge * @mm: mm context of the victim * @gfp_mask: reclaim mode
@@ -6728,16 +6727,14 @@ out:* * Returns 0 on success. Otherwise, an error code is returned. */ -int mem_cgroup_charge (struct page *page,struct mm_struct *mm,gfp_t gfp_mask) +int __mem_cgroup_charge (struct page *page,struct mm_struct *mm, +gfp_t gfp_mask) {struct mem_cgroup *memcg;int ret; -if (mem_cgroup_disabled ()) -return 0 ; - memcg =get_mem_cgroup_from_mm (mm); - ret =__mem_cgroup_charge (page, memcg, gfp_mask); + ret =charge_memcg (page, memcg, gfp_mask);css_put (&memcg->css);return ret;
@@ -6772,7 +6769,7 @@ int mem_cgroup_swapin_charge_page(struct memcg =get_mem_cgroup_from_mm (mm);rcu_read_unlock (); - ret =__mem_cgroup_charge (page, memcg, gfp); + ret =charge_memcg (page, memcg, gfp);css_put (&memcg->css);return ret;
@@ -6908,18 +6905,15 @@ static void uncharge_page(struct page *p }/** -* mem_cgroup_uncharge - uncharge a page +* __mem_cgroup_uncharge - uncharge a page * @page: page to uncharge * -* Uncharge a page previously charged with mem_cgroup_charge(). +* Uncharge a page previously charged with __mem_cgroup_charge(). */ -void mem_cgroup_uncharge (struct page *page) +void __mem_cgroup_uncharge (struct page *page) {struct uncharge_gather ug; -if (mem_cgroup_disabled ()) -return ; -/* Don't touch page->lru of any random page, pre-check: */ if (!page_memcg (page))return ;
@@ -6930,20 +6924,17 @@ void mem_cgroup_uncharge(struct page *pa }/** -* mem_cgroup_uncharge_list - uncharge a list of page +* __mem_cgroup_uncharge_list - uncharge a list of page * @page_list: list of pages to uncharge * * Uncharge a list of pages previously charged with -* mem_cgroup_charge(). +* __mem_cgroup_charge(). */ -void mem_cgroup_uncharge_list (struct list_head *page_list) +void __mem_cgroup_uncharge_list (struct list_head *page_list) {struct uncharge_gather ug;struct page *page; -if (mem_cgroup_disabled ()) -return ; -uncharge_gather_clear (&ug);list_for_each_entry (page, page_list, lru)uncharge_page (page, &ug);
_
Andrew Morton
maintainerPATCH 94/212 mm, memcg: inline swap-related functions to improve disabled memcg config
In reply to Andrew MortonFrom: Suren Baghdasaryan <[email protected]>
Subject: mm, memcg: inline swap-related functions to improve disabled memcg config
Inline mem_cgroup_try_charge_swap, mem_cgroup_uncharge_swap and cgroup_throttle_swaprate functions to perform mem_cgroup_disabled static key check inline before calling the main body of the function. This minimizes the memcg overhead in the pagefault and exit_mmap paths when memcgs are disabled using cgroup_disable=memory command-line option. This change results in ~1% overhead reduction when running PFT test [1] comparing {CONFIG_MEMCG=n} against {CONFIG_MEMCG=y, cgroup_disable=memory} configuration on an 8-core ARM64 Android device.
[1] https://lkml.org/lkml/2006/8/29/294 also used in mmtests suite
---
include/linux/swap.h | 26 +++++++++++++++++++++++--- mm/memcontrol.c | 14 ++++---------- mm/swapfile.c | 5 +---- 3 files changed, 28 insertions(+), 17 deletions(-)
include/linux/swap.h renamed from include/linux/swap.h~mm-memcg-inline-swap-related-functions-to-improve-disabled-memcg-config +23 -3
@@ -721,7 +721,13 @@ static inline int mem_cgroup_swappiness(#endif #if defined(CONFIG_SWAP ) && defined(CONFIG_MEMCG ) && defined(CONFIG_BLK_CGROUP ) -extern void cgroup_throttle_swaprate (struct page *page,gfp_t gfp_mask); +extern void __cgroup_throttle_swaprate (struct page *page,gfp_t gfp_mask); +static inline void cgroup_throttle_swaprate (struct page *page,gfp_t gfp_mask) +{ +if (mem_cgroup_disabled ()) +return ; +__cgroup_throttle_swaprate (page, gfp_mask); +}#else static inline void cgroup_throttle_swaprate (struct page *page,gfp_t gfp_mask) {
@@ -730,8 +736,22 @@ static inline void cgroup_throttle_swapr#ifdef CONFIG_MEMCG_SWAP extern void mem_cgroup_swapout (struct page *page,swp_entry_t entry); -extern int mem_cgroup_try_charge_swap (struct page *page,swp_entry_t entry); -extern void mem_cgroup_uncharge_swap (swp_entry_t entry,unsigned int nr_pages); +extern int __mem_cgroup_try_charge_swap (struct page *page,swp_entry_t entry); +static inline int mem_cgroup_try_charge_swap (struct page *page,swp_entry_t entry) +{ +if (mem_cgroup_disabled ()) +return 0 ; +return __mem_cgroup_try_charge_swap (page, entry); +} + +extern void __mem_cgroup_uncharge_swap (swp_entry_t entry,unsigned int nr_pages); +static inline void mem_cgroup_uncharge_swap (swp_entry_t entry,unsigned int nr_pages) +{ +if (mem_cgroup_disabled ()) +return ; +__mem_cgroup_uncharge_swap (entry, nr_pages); +} +extern long mem_cgroup_get_nr_swap_pages (struct mem_cgroup *memcg);extern bool mem_cgroup_swap_full (struct page *page);#else
mm/memcontrol.c renamed from mm/memcontrol.c~mm-memcg-inline-swap-related-functions-to-improve-disabled-memcg-config +4 -10
@@ -7226,7 +7226,7 @@ void mem_cgroup_swapout(struct page *pag }/** -* mem_cgroup_try_charge_swap - try charging swap space for a page +* __mem_cgroup_try_charge_swap - try charging swap space for a page * @page: page being added to swap * @entry: swap entry to charge *
@@ -7234,16 +7234,13 @@ void mem_cgroup_swapout(struct page *pag* * Returns 0 on success, -ENOMEM on failure. */ -int mem_cgroup_try_charge_swap (struct page *page,swp_entry_t entry) +int __mem_cgroup_try_charge_swap (struct page *page,swp_entry_t entry) {unsigned int nr_pages =thp_nr_pages (page);struct page_counter *counter;struct mem_cgroup *memcg;unsigned short oldid; -if (mem_cgroup_disabled ()) -return 0 ; -if (!cgroup_subsys_on_dfl (memory_cgrp_subsys))return 0 ;
@@ -7279,18 +7276,15 @@ int mem_cgroup_try_charge_swap(struct pa }/** -* mem_cgroup_uncharge_swap - uncharge swap space +* __mem_cgroup_uncharge_swap - uncharge swap space * @entry: swap entry to uncharge * @nr_pages: the amount of swap space to uncharge */ -void mem_cgroup_uncharge_swap (swp_entry_t entry,unsigned int nr_pages) +void __mem_cgroup_uncharge_swap (swp_entry_t entry,unsigned int nr_pages) {struct mem_cgroup *memcg;unsigned short id; -if (mem_cgroup_disabled ()) -return ; - id =swap_cgroup_record (entry,0 , nr_pages);rcu_read_lock (); memcg =mem_cgroup_from_id (id);
mm/swapfile.c renamed from mm/swapfile.c~mm-memcg-inline-swap-related-functions-to-improve-disabled-memcg-config +1 -4
@@ -3779,14 +3779,11 @@ static void free_swap_count_continuation }#if defined(CONFIG_MEMCG ) && defined(CONFIG_BLK_CGROUP ) -void cgroup_throttle_swaprate (struct page *page,gfp_t gfp_mask) +void __cgroup_throttle_swaprate (struct page *page,gfp_t gfp_mask) {struct swap_info_struct *si, *next;int nid =page_to_nid (page); -if (mem_cgroup_disabled ()) -return ; -if (!(gfp_mask & __GFP_IO))return ;
_
Andrew Morton
maintainerPATCH 95/212 memcg: enable accounting for pids in nested pid namespaces
In reply to Andrew MortonFrom: Vasily Averin <[email protected]>
Subject: memcg: enable accounting for pids in nested pid namespaces
Commit 5d097056c9a0 ("kmemcg: account certain kmem allocations to memcg") enabled memcg accounting for pids allocated from init_pid_ns.pid_cachep, but forgot to adjust the setting for nested pid namespaces. As a result, pid memory is not accounted exactly where it is really needed, inside memcg-limited containers with their own pid namespaces.
Pid was one the first kernel objects enabled for memcg accounting. init_pid_ns.pid_cachep marked by SLAB_ACCOUNT and we can expect that any new pids in the system are memcg-accounted.
Though recently I've noticed that it is wrong. nested pid namespaces creates own slab caches for pid objects, nested pids have increased size because contain id both for all parent and for own pid namespaces. The problem is that these slab caches are _NOT_ marked by SLAB_ACCOUNT, as a result any pids allocated in nested pid namespaces are not memcg-accounted.
Pid struct in nested pid namespace consumes up to 500 bytes memory, 100000 such objects gives us up to ~50Mb unaccounted memory, this allow container to exceed assigned memcg limits.
---
kernel/pid_namespace.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/pid_namespace.c renamed from kernel/pid_namespace.c~memcg-enable-accounting-for-pids-in-nested-pid-namespaces +2 -1
@@ -51,7 +51,8 @@ static struct kmem_cache *create_pid_cacmutex_lock (&pid_caches_mutex);/* Name collision forces to do allocation under mutex. */ if (!*pkc) - *pkc =kmem_cache_create (name, len,0 ,SLAB_HWCACHE_ALIGN ,0 ); + *pkc =kmem_cache_create (name, len,0 , +SLAB_HWCACHE_ALIGN |SLAB_ACCOUNT ,0 );mutex_unlock (&pid_caches_mutex);/* current can fail, but someone else can succeed. */ return READ_ONCE (*pkc);
_
Andrew Morton
maintainerPATCH 96/212 memcg: switch lruvec stats to rstat
In reply to Andrew MortonFrom: Shakeel Butt <[email protected]>
Subject: memcg: switch lruvec stats to rstat
The commit 2d146aa3aa84 ("mm: memcontrol: switch to rstat") switched memcg stats to rstat infrastructure but skipped the conversion of the lruvec stats as such stats are read in the performance critical code paths and flushing stats may have impacted the performances of the applications. This patch converts the lruvec stats to rstat and later patches add mechanisms to keep the performance impact to minimum.
The rstat conversion comes with the price i.e. memory cost. Effectively this patch reverts the savings done by the commit f3344adf38bd ("mm:
memcontrol: optimize per-lruvec stats counter memory usage"). However this cost is justified due to negative impact of the inaccurate lruvec stats on many heuristics. One such case is reported in [1].
The memory reclaim code is filled with plethora of heuristics and many of those heuristics reads the lruvec stats. So, inaccurate stats can make such heuristics ineffective. [1] reports the impact of inaccurate lruvec stats on the "cache trim mode" heuristic. Inaccurate lruvec stats can impact the deactivation and aging anon heuristics as well.
[1] https://lore.kernel.org/linux-mm/[email protected]/
---
include/linux/memcontrol.h | 42 ++++++------ mm/memcontrol.c | 114 +++++++++++------------------------ 2 files changed, 58 insertions(+), 98 deletions(-)
include/linux/memcontrol.h renamed from include/linux/memcontrol.h~memcg-switch-lruvec-stats-to-rstat +20 -22
@@ -105,14 +105,6 @@ struct mem_cgroup_reclaim_iter {unsigned int generation; }; -struct lruvec_stat { -long count[NR_VM_NODE_STAT_ITEMS ]; -}; - -struct batched_lruvec_stat { -s32 count[NR_VM_NODE_STAT_ITEMS ]; -}; -/* * Bitmap and deferred work of shrinker::id corresponding to memcg-aware * shrinkers, which have elements charged to this memcg.
@@ -123,24 +115,30 @@ struct shrinker_info {unsigned long *map; }; +struct lruvec_stats_percpu { +/* Local (CPU and cgroup) state */ +long state[NR_VM_NODE_STAT_ITEMS ]; + +/* Delta calculation for lockless upward propagation */ +long state_prev[NR_VM_NODE_STAT_ITEMS ]; +}; + +struct lruvec_stats { +/* Aggregated (CPU and subtree) state */ +long state[NR_VM_NODE_STAT_ITEMS ]; + +/* Pending child counts during tree propagation */ +long state_pending[NR_VM_NODE_STAT_ITEMS ]; +}; +/* * per-node information in memory controller. */ struct mem_cgroup_per_node {struct lruvec lruvec; -/* -* Legacy local VM stats. This should be struct lruvec_stat and -* cannot be optimized to struct batched_lruvec_stat. Because -* the threshold of the lruvec_stat_cpu can be as big as -* MEMCG_CHARGE_BATCH * PAGE_SIZE. It can fit into s32. But this -* filed has no upper limit. -*/ -struct lruvec_stat __percpu *lruvec_stat_local; - -/* Subtree VM stats (batched updates) */ -struct batched_lruvec_stat __percpu *lruvec_stat_cpu; -atomic_long_t lruvec_stat[NR_VM_NODE_STAT_ITEMS ]; +struct lruvec_stats_percpu __percpu *lruvec_stats_percpu; +struct lruvec_stats lruvec_stats;unsigned long lru_zone_size[MAX_NR_ZONES ][NR_LRU_LISTS ];
@@ -997,7 +995,7 @@ static inline unsigned long lruvec_page_return node_page_state (lruvec_pgdat (lruvec), idx); pn = container_of(lruvec, struct mem_cgroup_per_node, lruvec); - x =atomic_long_read (&pn->lruvec_stat[idx]); + x =READ_ONCE (pn->lruvec_stats.state[idx]);#ifdef CONFIG_SMP if (x <0 ) x =0 ;
@@ -1017,7 +1015,7 @@ static inline unsigned long lruvec_page_ pn = container_of(lruvec, struct mem_cgroup_per_node, lruvec);for_each_possible_cpu (cpu) - x +=per_cpu (pn->lruvec_stat_local->count[idx], cpu); + x +=per_cpu (pn->lruvec_stats_percpu->state[idx], cpu);#ifdef CONFIG_SMP if (x <0 ) x =0 ;
mm/memcontrol.c renamed from mm/memcontrol.c~memcg-switch-lruvec-stats-to-rstat +38 -76
181 lines not on this page · raw message
_
Andrew Morton
maintainerPATCH 97/212 memcg: infrastructure to flush memcg stats
In reply to Andrew MortonFrom: Shakeel Butt <[email protected]>
Subject: memcg: infrastructure to flush memcg stats
At the moment memcg stats are read in four contexts:
1. memcg stat user interfaces
2. dirty throttling
3. page fault
4. memory reclaim
Currently the kernel flushes the stats for first two cases. Flushing the stats for remaining two casese may have performance impact. Always flushing the memcg stats on the page fault code path may negatively impacts the performance of the applications. In addition flushing in the memory reclaim code path, though treated as slowpath, can become the source of contention for the global lock taken for stat flushing because when system or memcg is under memory pressure, many tasks may enter the reclaim path.
This patch uses following mechanisms to solve these challenges:
1. Periodically flush the stats from root memcg every 2 seconds. This will time limit the out of sync stats.
2. Asynchronously flush the stats after fixed number of stat updates. In the worst case the stat can be out of sync by O(nr_cpus * BATCH) for 2 seconds.
3. For avoiding thundering herd to flush the stats particularly from the memory reclaim context, introduce memcg local spinlock and let only one flusher active at a time. This could have been done through cgroup_rstat_lock lock but that lock is used by other subsystem and for userspace reading memcg stats. So, it is better to keep flushers introduced by this patch decoupled from cgroup_rstat_lock. However we would have to use irqsafe version of rstat flush but that is fine as this code path will be flushing for whole tree and do the work for everyone. No one will be waiting for that worker.
---
include/linux/memcontrol.h | 6 ++++++ mm/memcontrol.c | 34 ++++++++++++++++++++++++++++++++++ mm/vmscan.c | 6 ++++++ 3 files changed, 46 insertions(+)
include/linux/memcontrol.h renamed from include/linux/memcontrol.h~memcg-infrastructure-to-flush-memcg-stats +6 -0
@@ -1023,6 +1023,8 @@ static inline unsigned long lruvec_page_return x; } +void mem_cgroup_flush_stats (void ); +void __mod_memcg_lruvec_state (struct lruvec *lruvec,enum node_stat_item idx,int val);void __mod_lruvec_kmem_state (void *p,enum node_stat_item idx,int val);
@@ -1438,6 +1440,10 @@ static inline unsigned long lruvec_page_return node_page_state (lruvec_pgdat (lruvec), idx); } +static inline void mem_cgroup_flush_stats (void ) +{ +} +static inline void __mod_memcg_lruvec_state (struct lruvec *lruvec,enum node_stat_item idx,int val) {
mm/memcontrol.c renamed from mm/memcontrol.c~memcg-infrastructure-to-flush-memcg-stats +34 -0
@@ -103,6 +103,14 @@ static bool do_memsw_account(void)return !cgroup_subsys_on_dfl (memory_cgrp_subsys) && !cgroup_memory_noswap; } +/* memcg and lruvec stats flushing */ +static void flush_memcg_stats_dwork (struct work_struct *w); +static DECLARE_DEFERRABLE_WORK(stats_flush_dwork, flush_memcg_stats_dwork); +static void flush_memcg_stats_work (struct work_struct *w); +static DECLARE_WORK(stats_flush_work, flush_memcg_stats_work); +static DEFINE_PER_CPU(unsigned int, stats_flush_threshold); +static DEFINE_SPINLOCK (stats_flush_lock); +#define THRESHOLDS_EVENTS_TARGET 128#define SOFTLIMIT_EVENTS_TARGET 1024
@@ -674,6 +682,8 @@ void __mod_memcg_lruvec_state(struct lru/* Update lruvec */ __this_cpu_add (pn->lruvec_stats_percpu->state[idx], val); +if (!(__this_cpu_inc_return (stats_flush_threshold) %MEMCG_CHARGE_BATCH )) +queue_work (system_unbound_wq, &stats_flush_work); }/**
@@ -5240,6 +5250,10 @@ static int mem_cgroup_css_online(struct/* Online state pins memcg ID, memcg ID pins CSS */ refcount_set (&memcg->id.ref,1 );css_get (css); + +if (unlikely (mem_cgroup_is_root (memcg))) +queue_delayed_work (system_unbound_wq, &stats_flush_dwork, +2UL *HZ );return 0 ; }
@@ -5331,6 +5345,26 @@ static void mem_cgroup_css_reset(structmemcg_wb_domain_size_changed (memcg); } +void mem_cgroup_flush_stats (void ) +{ +if (!spin_trylock (&stats_flush_lock)) +return ; + +cgroup_rstat_flush_irqsafe (root_mem_cgroup->css.cgroup); +spin_unlock (&stats_flush_lock); +} + +static void flush_memcg_stats_dwork (struct work_struct *w) +{ +mem_cgroup_flush_stats (); +queue_delayed_work (system_unbound_wq, &stats_flush_dwork,2UL *HZ ); +} + +static void flush_memcg_stats_work (struct work_struct *w) +{ +mem_cgroup_flush_stats (); +} +static void mem_cgroup_css_rstat_flush (struct cgroup_subsys_state *css,int cpu) {struct mem_cgroup *memcg =mem_cgroup_from_css (css);
mm/vmscan.c renamed from mm/vmscan.c~memcg-infrastructure-to-flush-memcg-stats +6 -0
@@ -2897,6 +2897,12 @@ static void shrink_node(pg_data_t *pgdat target_lruvec =mem_cgroup_lruvec (sc->target_mem_cgroup, pgdat); again: +/* +* Flush the memory cgroup stats, so that we read accurate per-memcg +* lruvec stats for heuristics. +*/ +mem_cgroup_flush_stats (); +memset (&sc->nr,0 ,sizeof (sc->nr)); nr_reclaimed = sc->nr_reclaimed;
_