incoming
Subsystems (98)
Andrew Morton
maintainer- a few random little subsystems
- almost all of the MM patches which are staged ahead of linux-next material. I'll trickle to post-linux-next work in as the dependents get merged up.
200 patches, based on 2c85ebc57b3e1817b6ce1a6b703928e113a90442.
Subsystems affected by this patch series:
kthread
kbuild
ide
ntfs
ocfs2
arch
mm/slab-generic
mm/slab
mm/slub
mm/dax
mm/debug
mm/pagecache
mm/gup
mm/swap
mm/shmem
mm/memcg
mm/pagemap
mm/mremap
mm/hmm
mm/vmalloc
mm/documentation
mm/kasan
mm/pagealloc
mm/memory-failure
mm/hugetlb
mm/vmscan
mm/z3fold
mm/compaction
mm/oom-kill
mm/migration
mm/cma
mm/page-poison
mm/userfaultfd
mm/zswap
mm/zsmalloc
mm/uaccess
mm/zram
mm/cleanups
Subsystem: kthread
Rob Clark <[email protected]>:
kthread: add kthread_work tracepoints
Petr Mladek <[email protected]>:
kthread_worker: document CPU hotplug handling
Subsystem: kbuild
Petr Vorel <[email protected]>:
uapi: move constants from <linux/kernel.h> to <linux/const.h>
Subsystem: ide
Sebastian Andrzej Siewior <[email protected]>:
ide/falcon: remove in_interrupt() usage
ide: remove BUG_ON(in_interrupt() || irqs_disabled()) from ide_unregister()
Subsystem: ntfs
Alex Shi <[email protected]>:
fs/ntfs: remove unused varibles
fs/ntfs: remove unused variable attr_len
Subsystem: ocfs2
Tom Rix <[email protected]>:
fs/ocfs2/cluster/tcp.c: remove unneeded break
Mauricio Faria de Oliveira <[email protected]>:
ocfs2: ratelimit the 'max lookup times reached' notice
Subsystem: arch
Colin Ian King <[email protected]>:
arch/Kconfig: fix spelling mistakes
Subsystem: mm/slab-generic
Hui Su <[email protected]>:
mm/slab_common.c: use list_for_each_entry in dump_unreclaimable_slab()
Bartosz Golaszewski <[email protected]>:
Patch series "slab: provide and use krealloc_array()", v3:
mm: slab: clarify krealloc()'s behavior with __GFP_ZERO
mm: slab: provide krealloc_array()
ALSA: pcm: use krealloc_array()
vhost: vringh: use krealloc_array()
pinctrl: use krealloc_array()
edac: ghes: use krealloc_array()
drm: atomic: use krealloc_array()
hwtracing: intel: use krealloc_array()
dma-buf: use krealloc_array()
Vlastimil Babka <[email protected]>:
mm, slab, slub: clear the slab_cache field when freeing page
Subsystem: mm/slab
Alexander Popov <[email protected]>:
mm/slab: rerform init_on_free earlier
Subsystem: mm/slub
Vlastimil Babka <[email protected]>:
mm, slub: use kmem_cache_debug_flags() in deactivate_slab()
Bharata B Rao <[email protected]>:
mm/slub: let number of online CPUs determine the slub page order
Subsystem: mm/dax
Dan Williams <[email protected]>:
device-dax/kmem: use struct_size()
Subsystem: mm/debug
Zhenhua Huang <[email protected]>:
mm: fix page_owner initializing issue for arm32
Liam Mark <[email protected]>:
mm/page_owner: record timestamp and pid
Subsystem: mm/pagecache
Kent Overstreet <[email protected]>:
Patch series "generic_file_buffered_read() improvements", v2:
mm/filemap/c: break generic_file_buffered_read up into multiple functions mm/filemap.c: generic_file_buffered_read() now uses find_get_pages_contig
Alex Shi <[email protected]>:
mm/truncate: add parameter explanation for invalidate_mapping_pagevec
Hailong Liu <[email protected]>:
mm/filemap.c: remove else after a return
Subsystem: mm/gup
John Hubbard <[email protected]>:
Patch series "selftests/vm: gup_test, hmm-tests, assorted improvements", v3:
mm/gup_benchmark: rename to mm/gup_test
selftests/vm: use a common gup_test.h
selftests/vm: rename run_vmtests --> run_vmtests.sh selftests/vm: minor cleanup: Makefile and gup_test.c selftests/vm: only some gup_test items are really benchmarks selftests/vm: gup_test: introduce the dump_pages() sub-test selftests/vm: run_vmtests.sh: update and clean up gup_test invocation selftests/vm: hmm-tests: remove the libhugetlbfs dependency selftests/vm: 2x speedup for run_vmtests.sh
Barry Song <[email protected]>:
mm/gup_test.c: mark gup_test_init as __init function mm/gup_test: GUP_TEST depends on DEBUG_FS
Jason Gunthorpe <[email protected]>:
Patch series "Add a seqcount between gup_fast and copy_page_range()", v4:
mm/gup: reorganize internal_get_user_pages_fast()
mm/gup: prevent gup_fast from racing with COW during fork mm/gup: remove the vma allocation from gup_longterm_locked() mm/gup: combine put_compound_head() and unpin_user_page()
Subsystem: mm/swap
Ralph Campbell <[email protected]>:
mm: handle zone device pages in release_pages()
Miaohe Lin <[email protected]>:
mm/swapfile.c: use helper function swap_count() in add_swap_count_continuation() mm/swap_state: skip meaningless swap cache readahead when ra_info.win == 0 mm/swapfile.c: remove unnecessary out label in __swap_duplicate() mm/swapfile.c: use memset to fill the swap_map with SWAP_HAS_CACHE
Jeff Layton <[email protected]>:
mm: remove pagevec_lookup_range_nr_tag()
Subsystem: mm/shmem
Hui Su <[email protected]>:
mm/shmem.c: make shmem_mapping() inline
Randy Dunlap <[email protected]>:
tmpfs: fix Documentation nits
Subsystem: mm/memcg
Johannes Weiner <[email protected]>:
mm: memcontrol: add file_thp, shmem_thp to memory.stat
Muchun Song <[email protected]>:
mm: memcontrol: remove unused mod_memcg_obj_state()
Miaohe Lin <[email protected]>:
mm: memcontrol: eliminate redundant check in __mem_cgroup_insert_exceeded()
Muchun Song <[email protected]>:
mm: memcg/slab: fix return of child memcg objcg for root memcg
mm: memcg/slab: fix use after free in obj_cgroup_charge
Shakeel Butt <[email protected]>:
mm/rmap: always do TTU_IGNORE_ACCESS
Alex Shi <[email protected]>:
mm/memcg: update page struct member in comments
Roman Gushchin <[email protected]>:
mm: memcg: fix obsolete code comments
Patch series "mm: memcg: deprecate cgroup v1 non-hierarchical mode", v1:
mm: memcg: deprecate the non-hierarchical mode
docs: cgroup-v1: reflect the deprecation of the non-hierarchical mode
cgroup: remove obsoleted broken_hierarchy and warned_broken_hierarchy
Hui Su <[email protected]>:
mm/page_counter: use page_counter_read in page_counter_set_max
Lukas Bulwahn <[email protected]>:
mm: memcg: remove obsolete memcg_has_children()
Muchun Song <[email protected]>:
mm: memcg/slab: rename *_lruvec_slab_state to *_lruvec_kmem_state
Kaixu Xia <[email protected]>:
mm: memcontrol: sssign boolean values to a bool variable
Alex Shi <[email protected]>:
mm/memcg: remove incorrect comment
Shakeel Butt <[email protected]>:
Patch series "memcg: add pagetable comsumption to memory.stat", v2:
mm: move lruvec stats update functions to vmstat.h
mm: memcontrol: account pagetables per node
Subsystem: mm/pagemap
Dan Williams <[email protected]>:
xen/unpopulated-alloc: consolidate pgmap manipulation
Kalesh Singh <[email protected]>:
Patch series "Speed up mremap on large regions", v4:
kselftests: vm: add mremap tests
mm: speedup mremap on 1GB or larger regions
arm64: mremap speedup - enable HAVE_MOVE_PUD
x86: mremap speedup - Enable HAVE_MOVE_PUD
John Hubbard <[email protected]>:
mm: cleanup: remove unused tsk arg from __access_remote_vm
Alex Shi <[email protected]>:
mm/mapping_dirty_helpers: enhance the kernel-doc markups mm/page_vma_mapped.c: add colon to fix kernel-doc markups error for check_pte
Axel Rasmussen <[email protected]>:
mm: mmap_lock: add tracepoints around lock acquisition
"Matthew Wilcox (Oracle)" <[email protected]>:
sparc: fix handling of page table constructor failure
mm: move free_unref_page to mm/internal.h
Subsystem: mm/mremap
Dmitry Safonov <[email protected]>:
Patch series "mremap: move_vma() fixes":
mm/mremap: account memory on do_munmap() failure mm/mremap: for MREMAP_DONTUNMAP check security_vm_enough_memory_mm()
mremap: don't allow MREMAP_DONTUNMAP on special_mappings and aio
vm_ops: rename .split() callback to .may_split()
mremap: check if it's possible to split original vma
mm: forbid splitting special mappings
Subsystem: mm/hmm
Daniel Vetter <[email protected]>:
mm: track mmu notifiers in fs_reclaim_acquire/release
mm: extract might_alloc() debug check locking/selftests: add testcases for fs_reclaim
Subsystem: mm/vmalloc
Andrew Morton <[email protected]>:
mm/vmalloc.c:__vmalloc_area_node(): avoid 32-bit overflow
"Uladzislau Rezki (Sony)" <[email protected]>:
mm/vmalloc: use free_vm_area() if an allocation fails mm/vmalloc: rework the drain logic
Alex Shi <[email protected]>:
mm/vmalloc: add 'align' parameter explanation for pvm_determine_end_from_reverse
Baolin Wang <[email protected]>:
mm/vmalloc.c: remove unnecessary return statement
Waiman Long <[email protected]>:
mm/vmalloc: Fix unlock order in s_stop()
Subsystem: mm/documentation
Alex Shi <[email protected]>:
docs/vm: remove unused 3 items explanation for /proc/vmstat
Subsystem: mm/kasan
Vincenzo Frascino <[email protected]>:
mm/vmalloc.c: fix kasan shadow poisoning size
Walter Wu <[email protected]>:
Patch series "kasan: add workqueue stack for generic KASAN", v5:
workqueue: kasan: record workqueue stack
kasan: print workqueue stack
lib/test_kasan.c: add workqueue test case
kasan: update documentation for generic kasan
Marco Elver <[email protected]>:
lkdtm: disable KASAN for rodata.o
Subsystem: mm/pagealloc
Mike Rapoport <[email protected]>:
Patch series "arch, mm: deprecate DISCONTIGMEM", v2:
alpha: switch from DISCONTIGMEM to SPARSEMEM
ia64: remove custom __early_pfn_to_nid()
ia64: remove 'ifdef CONFIG_ZONE_DMA32' statements
ia64: discontig: paging_init(): remove local max_pfn calculation
ia64: split virtual map initialization out of paging_init()
ia64: forbid using VIRTUAL_MEM_MAP with FLATMEM
ia64: make SPARSEMEM default and disable DISCONTIGMEM
arm: remove CONFIG_ARCH_HAS_HOLES_MEMORYMODEL
arm, arm64: move free_unused_memmap() to generic mm
arc: use FLATMEM with freeing of unused memory map instead of DISCONTIGMEM m68k/mm: make node data and node setup depend on CONFIG_DISCONTIGMEM m68k/mm: enable use of generic memory_model.h for !DISCONTIGMEM
m68k: deprecate DISCONTIGMEM
Patch series "arch, mm: improve robustness of direct map manipulation", v7:
mm: introduce debug_pagealloc_{map,unmap}_pages() helpers
PM: hibernate: make direct map manipulations more explicit arch, mm: restore dependency of __kernel_map_pages() on DEBUG_PAGEALLOC arch, mm: make kernel_page_present() always available
Vlastimil Babka <[email protected]>:
Patch series "disable pcplists during memory offline", v3:
mm, page_alloc: clean up pageset high and batch update mm, page_alloc: calculate pageset high and batch once per zone mm, page_alloc: remove setup_pageset()
mm, page_alloc: simplify pageset_update()
mm, page_alloc: cache pageset high and batch in struct zone mm, page_alloc: move draining pcplists to page isolation users mm, page_alloc: disable pcplists during memory offline
Miaohe Lin <[email protected]>:
include/linux/page-flags.h: remove unused __[Set|Clear]PagePrivate
"Matthew Wilcox (Oracle)" <[email protected]>:
mm/page-flags: fix comment mm/page_alloc: add __free_pages() documentation
Zou Wei <[email protected]>:
mm/page_alloc: mark some symbols with static keyword
David Hildenbrand <[email protected]>:
mm/page_alloc: clear all pages in post_alloc_hook() with init_on_alloc=1
Lin Feng <[email protected]>:
init/main: fix broken buffer_init when DEFERRED_STRUCT_PAGE_INIT set
Lorenzo Stoakes <[email protected]>:
mm: page_alloc: refactor setup_per_zone_lowmem_reserve()
Muchun Song <[email protected]>:
mm/page_alloc: speed up the iteration of max_order
Subsystem: mm/memory-failure
Oscar Salvador <[email protected]>:
Patch series "HWpoison: further fixes and cleanups", v5:
mm,hwpoison: drain pcplists before bailing out for non-buddy zero-refcount page mm,hwpoison: take free pages off the buddy freelists
mm,hwpoison: drop unneeded pcplist draining
Patch series "HWPoison: Refactor get page interface", v2:
mm,hwpoison: refactor get_any_page
mm,hwpoison: disable pcplists before grabbing a refcount mm,hwpoison: remove drain_all_pages from shake_page mm,memory_failure: always pin the page in madvise_inject_error mm,hwpoison: return -EBUSY when migration fails
Subsystem: mm/hugetlb
Hui Su <[email protected]>:
mm/hugetlb.c: just use put_page_testzero() instead of page_count()
Ralph Campbell <[email protected]>:
include/linux/huge_mm.h: remove extern keyword
Alex Shi <[email protected]>:
khugepaged: add parameter explanations for kernel-doc markup
Liu Xiang <[email protected]>:
mm: hugetlb: fix type of delta parameter and related local variables in gather_surplus_pages()
Oscar Salvador <[email protected]>:
mm,hugetlb: remove unneeded initialization
Dan Carpenter <[email protected]>:
hugetlb: fix an error code in hugetlb_reserve_pages()
Subsystem: mm/vmscan
Johannes Weiner <[email protected]>:
mm: don't wake kswapd prematurely when watermark boosting is disabled
Lukas Bulwahn <[email protected]>:
mm/vmscan: drop unneeded assignment in kswapd()
"logic.yu" <[email protected]>:
mm/vmscan.c: remove the filename in the top of file comment
Muchun Song <[email protected]>:
mm/page_isolation: do not isolate the max order page
Subsystem: mm/z3fold
Vitaly Wool <[email protected]>:
Patch series "z3fold: stability / rt fixes":
z3fold: simplify freeing slots
z3fold: stricter locking and more careful reclaim
z3fold: remove preempt disabled sections for RT
Subsystem: mm/compaction
Yanfei Xu <[email protected]>:
mm/compaction: rename 'start_pfn' to 'iteration_start_pfn' in compact_zone()
Hui Su <[email protected]>:
mm/compaction: move compaction_suitable's comment to right place mm/compaction: make defer_compaction and compaction_deferred static
Subsystem: mm/oom-kill
Hui Su <[email protected]>:
mm/oom_kill: change comment and rename is_dump_unreclaim_slabs()
Subsystem: mm/migration
Long Li <[email protected]>:
mm/migrate.c: fix comment spelling
Ralph Campbell <[email protected]>:
mm/migrate.c: optimize migrate_vma_pages() mmu notifier
"Matthew Wilcox (Oracle)" <[email protected]>:
mm: support THPs in zero_user_segments
Yang Shi <[email protected]>:
Patch series "mm: misc migrate cleanup and improvement", v3:
mm: truncate_complete_page() does not exist any more
mm: migrate: simplify the logic for handling permanent failure
mm: migrate: skip shared exec THP for NUMA balancing
mm: migrate: clean up migrate_prep{_local}
mm: migrate: return -ENOSYS if THP migration is unsupported
Stephen Zhang <[email protected]>:
mm: migrate: remove unused parameter in migrate_vma_insert_page()
Subsystem: mm/cma
Lecopzer Chen <[email protected]>:
mm/cma.c: remove redundant cma_mutex lock
Charan Teja Reddy <[email protected]>:
mm: cma: improve pr_debug log in cma_release()
Subsystem: mm/page-poison
Vlastimil Babka <[email protected]>:
Patch series "cleanup page poisoning", v3:
mm, page_alloc: do not rely on the order of page_poison and init_on_alloc/free parameters mm, page_poison: use static key more efficiently
kernel/power: allow hibernation with page_poison sanity checking
mm, page_poison: remove CONFIG_PAGE_POISONING_NO_SANITY
mm, page_poison: remove CONFIG_PAGE_POISONING_ZERO
Subsystem: mm/userfaultfd
Lokesh Gidra <[email protected]>:
Patch series "Control over userfaultfd kernel-fault handling", v6:
userfaultfd: add UFFD_USER_MODE_ONLY
userfaultfd: add user-mode only option to unprivileged_userfaultfd sysctl knob
Axel Rasmussen <[email protected]>:
userfaultfd: selftests: make __{s,u}64 format specifiers portable
Peter Xu <[email protected]>:
Patch series "userfaultfd: selftests: Small fixes":
userfaultfd/selftests: always dump something in modes userfaultfd/selftests: fix retval check for userfaultfd_open() userfaultfd/selftests: hint the test runner on required privilege
Subsystem: mm/zswap
Joe Perches <[email protected]>:
mm/zswap: make struct kernel_param_ops definitions const
YueHaibing <[email protected]>:
mm/zswap: fix passing zero to 'PTR_ERR' warning
Barry Song <[email protected]>:
mm/zswap: move to use crypto_acomp API for hardware acceleration
Subsystem: mm/zsmalloc
Miaohe Lin <[email protected]>:
mm/zsmalloc.c: rework the list_add code in insert_zspage()
Subsystem: mm/uaccess
Colin Ian King <[email protected]>:
mm/process_vm_access: remove redundant initialization of iov_r
Subsystem: mm/zram
Minchan Kim <[email protected]>:
zram: support page writeback
zram: add stat to gather incompressible pages since zram set up
Rui Salvaterra <[email protected]>:
zram: break the strict dependency from lzo
Subsystem: mm/cleanups
Mauro Carvalho Chehab <[email protected]>:
mm: fix kernel-doc markups
Joe Perches <[email protected]>:
Patch series "mm: Convert sysfs sprintf family to sysfs_emit", v2:
mm: use sysfs_emit for struct kobject * uses
mm: huge_memory: convert remaining use of sprintf to sysfs_emit and neatening mm:backing-dev: use sysfs_emit in macro defining functions
mm: shmem: convert shmem_enabled_show to use sysfs_emit_at
mm: slub: convert sysfs sprintf family to sysfs_emit/sysfs_emit_at
"Gustavo A. R. Silva" <[email protected]>:
mm: fix fall-through warnings for Clang
Alexey Dobriyan <[email protected]>:
mm: cleanup kstrto*() usage
/mmap_lock.h | 107 ++ a/Documentation/admin-guide/blockdev/zram.rst | 6 a/Documentation/admin-guide/cgroup-v1/memcg_test.rst | 8 a/Documentation/admin-guide/cgroup-v1/memory.rst | 42 a/Documentation/admin-guide/cgroup-v2.rst | 11 a/Documentation/admin-guide/mm/transhuge.rst | 15 a/Documentation/admin-guide/sysctl/vm.rst | 15 a/Documentation/core-api/memory-allocation.rst | 4 a/Documentation/core-api/pin_user_pages.rst | 8 a/Documentation/dev-tools/kasan.rst | 5 a/Documentation/filesystems/tmpfs.rst | 8 a/Documentation/vm/memory-model.rst | 3 a/Documentation/vm/page_owner.rst | 12 a/arch/Kconfig | 21 a/arch/alpha/Kconfig | 8 a/arch/alpha/include/asm/mmzone.h | 14 a/arch/alpha/include/asm/page.h | 7 a/arch/alpha/include/asm/pgtable.h | 12 a/arch/alpha/include/asm/sparsemem.h | 18 a/arch/alpha/kernel/setup.c | 1 a/arch/arc/Kconfig | 3 a/arch/arc/include/asm/page.h | 20 a/arch/arc/mm/init.c | 29 a/arch/arm/Kconfig | 12 a/arch/arm/kernel/vdso.c | 9 a/arch/arm/mach-bcm/Kconfig | 1 a/arch/arm/mach-davinci/Kconfig | 1 a/arch/arm/mach-exynos/Kconfig | 1 a/arch/arm/mach-highbank/Kconfig | 1 a/arch/arm/mach-omap2/Kconfig | 1 a/arch/arm/mach-s5pv210/Kconfig | 1 a/arch/arm/mach-tango/Kconfig | 1 a/arch/arm/mm/init.c | 78 - a/arch/arm64/Kconfig | 9 a/arch/arm64/include/asm/cacheflush.h | 1 a/arch/arm64/include/asm/pgtable.h | 1 a/arch/arm64/kernel/vdso.c | 41 a/arch/arm64/mm/init.c | 68 - a/arch/arm64/mm/pageattr.c | 12 a/arch/ia64/Kconfig | 11 a/arch/ia64/include/asm/meminit.h | 2 a/arch/ia64/mm/contig.c | 88 -- a/arch/ia64/mm/discontig.c | 44 - a/arch/ia64/mm/init.c | 14 a/arch/ia64/mm/numa.c | 30 a/arch/m68k/Kconfig.cpu | 31 a/arch/m68k/include/asm/page.h | 2 a/arch/m68k/include/asm/page_mm.h | 7 a/arch/m68k/include/asm/virtconvert.h | 7 a/arch/m68k/mm/init.c | 10 a/arch/mips/vdso/genvdso.c | 4 a/arch/nds32/mm/mm-nds32.c | 6 a/arch/powerpc/Kconfig | 5 a/arch/riscv/Kconfig | 4 a/arch/riscv/include/asm/pgtable.h | 2 a/arch/riscv/include/asm/set_memory.h | 1 a/arch/riscv/mm/pageattr.c | 31 a/arch/s390/Kconfig | 4 a/arch/s390/configs/debug_defconfig | 2 a/arch/s390/configs/defconfig | 2 a/arch/s390/kernel/vdso.c | 11 a/arch/sparc/Kconfig | 4 a/arch/sparc/mm/init_64.c | 2 a/arch/x86/Kconfig | 5 a/arch/x86/entry/vdso/vma.c | 17 a/arch/x86/include/asm/set_memory.h | 1 a/arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 2 a/arch/x86/kernel/tboot.c | 1 a/arch/x86/mm/pat/set_memory.c | 6 a/drivers/base/node.c | 2 a/drivers/block/zram/Kconfig | 42 a/drivers/block/zram/zcomp.c | 2 a/drivers/block/zram/zram_drv.c | 29 a/drivers/block/zram/zram_drv.h | 1 a/drivers/dax/device.c | 4 a/drivers/dax/kmem.c | 2 a/drivers/dma-buf/sync_file.c | 3 a/drivers/edac/ghes_edac.c | 4 a/drivers/firmware/efi/efi.c | 1 a/drivers/gpu/drm/drm_atomic.c | 3 a/drivers/hwtracing/intel_th/msu.c | 2 a/drivers/ide/falconide.c | 2 a/drivers/ide/ide-probe.c | 3 a/drivers/misc/lkdtm/Makefile | 1 a/drivers/pinctrl/pinctrl-utils.c | 2 a/drivers/vhost/vringh.c | 3 a/drivers/virtio/virtio_balloon.c | 6 a/drivers/xen/unpopulated-alloc.c | 14 a/fs/aio.c | 5 a/fs/ntfs/file.c | 5 a/fs/ntfs/inode.c | 2 a/fs/ntfs/logfile.c | 3 a/fs/ocfs2/cluster/tcp.c | 1 a/fs/ocfs2/namei.c | 4 a/fs/proc/kcore.c | 2 a/fs/proc/meminfo.c | 2 a/fs/userfaultfd.c | 20 a/include/linux/cgroup-defs.h | 15 a/include/linux/compaction.h | 12 a/include/linux/fs.h | 2 a/include/linux/gfp.h | 2 a/include/linux/highmem.h | 19 a/include/linux/huge_mm.h | 93 -- a/include/linux/memcontrol.h | 148 --- a/include/linux/migrate.h | 4 a/include/linux/mm.h | 118 +- a/include/linux/mm_types.h | 8 a/include/linux/mmap_lock.h | 94 ++ a/include/linux/mmzone.h | 50 - a/include/linux/page-flags.h | 6 a/include/linux/page_ext.h | 8 a/include/linux/pagevec.h | 3 a/include/linux/poison.h | 4 a/include/linux/rmap.h | 1 a/include/linux/sched/mm.h | 16 a/include/linux/set_memory.h | 5 a/include/linux/shmem_fs.h | 6 a/include/linux/slab.h | 18 a/include/linux/vmalloc.h | 8 a/include/linux/vmstat.h | 104 ++ a/include/trace/events/sched.h | 84 + a/include/uapi/linux/const.h | 5 a/include/uapi/linux/ethtool.h | 2 a/include/uapi/linux/kernel.h | 9 a/include/uapi/linux/lightnvm.h | 2 a/include/uapi/linux/mroute6.h | 2 a/include/uapi/linux/netfilter/x_tables.h | 2 a/include/uapi/linux/netlink.h | 2 a/include/uapi/linux/sysctl.h | 2 a/include/uapi/linux/userfaultfd.h | 9 a/init/main.c | 6 a/ipc/shm.c | 8 a/kernel/cgroup/cgroup.c | 12 a/kernel/fork.c | 3 a/kernel/kthread.c | 29 a/kernel/power/hibernate.c | 2 a/kernel/power/power.h | 2 a/kernel/power/snapshot.c | 52 + a/kernel/ptrace.c | 2 a/kernel/workqueue.c | 3 a/lib/locking-selftest.c | 47 + a/lib/test_kasan_module.c | 29 a/mm/Kconfig | 25 a/mm/Kconfig.debug | 28 a/mm/Makefile | 4 a/mm/backing-dev.c | 8 a/mm/cma.c | 6 a/mm/compaction.c | 29 a/mm/filemap.c | 823 ++++++++++--------- a/mm/gup.c | 329 ++----- a/mm/gup_benchmark.c | 210 ---- a/mm/gup_test.c | 299 ++++++ a/mm/gup_test.h | 40 a/mm/highmem.c | 52 + a/mm/huge_memory.c | 86 + a/mm/hugetlb.c | 28 a/mm/init-mm.c | 1 a/mm/internal.h | 5 a/mm/kasan/generic.c | 3 a/mm/kasan/report.c | 4 a/mm/khugepaged.c | 58 - a/mm/ksm.c | 50 - a/mm/madvise.c | 14 a/mm/mapping_dirty_helpers.c | 6 a/mm/memblock.c | 80 + a/mm/memcontrol.c | 170 +-- a/mm/memory-failure.c | 322 +++---- a/mm/memory.c | 24 a/mm/memory_hotplug.c | 44 - a/mm/mempolicy.c | 8 a/mm/migrate.c | 183 ++-- a/mm/mm_init.c | 1 a/mm/mmap.c | 22 a/mm/mmap_lock.c | 230 +++++ a/mm/mmu_notifier.c | 7 a/mm/mmzone.c | 14 a/mm/mremap.c | 282 ++++-- a/mm/nommu.c | 8 a/mm/oom_kill.c | 14 a/mm/page_alloc.c | 517 ++++++----- a/mm/page_counter.c | 4 a/mm/page_ext.c | 10 a/mm/page_isolation.c | 18 a/mm/page_owner.c | 17 a/mm/page_poison.c | 56 - a/mm/page_vma_mapped.c | 9 a/mm/process_vm_access.c | 2 a/mm/rmap.c | 9 a/mm/shmem.c | 39 a/mm/slab.c | 10 a/mm/slab.h | 9 a/mm/slab_common.c | 10 a/mm/slob.c | 6 a/mm/slub.c | 156 +-- a/mm/swap.c | 12 a/mm/swap_state.c | 7 a/mm/swapfile.c | 14 a/mm/truncate.c | 18 a/mm/vmalloc.c | 105 +- a/mm/vmscan.c | 21 a/mm/vmstat.c | 6 a/mm/workingset.c | 8 a/mm/z3fold.c | 215 ++-- a/mm/zsmalloc.c | 11 a/mm/zswap.c | 193 +++- a/sound/core/pcm_lib.c | 4 a/tools/include/linux/poison.h | 6 a/tools/testing/selftests/vm/.gitignore | 4 a/tools/testing/selftests/vm/Makefile | 41 a/tools/testing/selftests/vm/check_config.sh | 31 a/tools/testing/selftests/vm/config | 2 a/tools/testing/selftests/vm/gup_benchmark.c | 143 --- a/tools/testing/selftests/vm/gup_test.c | 258 +++++ a/tools/testing/selftests/vm/hmm-tests.c | 10 a/tools/testing/selftests/vm/mremap_test.c | 344 +++++++ a/tools/testing/selftests/vm/run_vmtests | 51 - a/tools/testing/selftests/vm/userfaultfd.c | 94 -- 217 files changed, 4817 insertions(+), 3369 deletions(-)
Andrew Morton
maintainerPATCH 1/200 kthread: add kthread_work tracepoints
From: Rob Clark <[email protected]>
Subject: kthread: add kthread_work tracepoints
While migrating some code from wq to kthread_worker, I found that I missed the execute_start/end tracepoints. So add similar tracepoints for kthread_work. And for completeness, queue_work tracepoint (although this one differs slightly from the matching workqueue tracepoint).
---
include/trace/events/sched.h | 84 +++++++++++++++++++++++++++++++++ kernel/kthread.c | 9 +++ 2 files changed, 93 insertions(+)
include/trace/events/sched.h renamed from include/trace/events/sched.h~kthread-add-kthread_work-tracepoints +84 -0
@@ -5,6 +5,7 @@#if !defined(_TRACE_SCHED_H) || defined(TRACE_HEADER_MULTI_READ )#define _TRACE_SCHED_H +#include <linux/kthread.h> #include <linux/sched/numa_balancing.h> #include <linux/tracepoint.h> #include <linux/binfmts.h>
@@ -51,6 +52,89 @@ TRACE_EVENT(sched_kthread_stop_ret,TP_printk ("ret=%d" , __entry->ret) ); +/** +* sched_kthread_work_queue_work - called when a work gets queued +* @worker: pointer to the kthread_worker +* @work: pointer to struct kthread_work +* +* This event occurs when a work is queued immediately or once a +* delayed work is actually queued (ie: once the delay has been +* reached). +*/ +TRACE_EVENT (sched_kthread_work_queue_work, + + TP_PROTO(struct kthread_worker *worker, + struct kthread_work *work), + +TP_ARGS (worker, work), + +TP_STRUCT__entry ( + __field( void *, work ) + __field( void *, function) + __field( void *, worker) + ), + +TP_fast_assign ( + __entry->work = work; + __entry->function = work->func; + __entry->worker = worker; + ), + +TP_printk ("work struct=%p function=%ps worker=%p" , + __entry->work, __entry->function, __entry->worker) +); + +/** +* sched_kthread_work_execute_start - called immediately before the work callback +* @work: pointer to struct kthread_work +* +* Allows to track kthread work execution. +*/ +TRACE_EVENT (sched_kthread_work_execute_start, + + TP_PROTO(struct kthread_work *work), + +TP_ARGS (work), + +TP_STRUCT__entry ( + __field( void *, work ) + __field( void *, function) + ), + +TP_fast_assign ( + __entry->work = work; + __entry->function = work->func; + ), + +TP_printk ("work struct %p: function %ps" , __entry->work, __entry->function) +); + +/** +* sched_kthread_work_execute_end - called immediately after the work callback +* @work: pointer to struct work_struct +* @function: pointer to worker function +* +* Allows to track workqueue execution. +*/ +TRACE_EVENT (sched_kthread_work_execute_end, + + TP_PROTO(struct kthread_work *work, kthread_work_func_t function), + +TP_ARGS (work, function), + +TP_STRUCT__entry ( + __field( void *, work ) + __field( void *, function) + ), + +TP_fast_assign ( + __entry->work = work; + __entry->function = function; + ), + +TP_printk ("work struct %p: function %ps" , __entry->work, __entry->function) +); +/* * Tracepoint for waking up a task: */
kernel/kthread.c renamed from kernel/kthread.c~kthread-add-kthread_work-tracepoints +9 -0
@@ -704,8 +704,15 @@ repeat:raw_spin_unlock_irq (&worker->lock);if (work) { +kthread_work_func_t func = work->func;__set_current_state (TASK_RUNNING ); +trace_sched_kthread_work_execute_start (work); work->func (work); +/* +* Avoid dereferencing work after this point. The trace +* event only cares about the address. +*/ +trace_sched_kthread_work_execute_end (work, func); }else if (!freezing (current))schedule ();
@@ -834,6 +841,8 @@ static void kthread_insert_work(struct k {kthread_insert_work_sanity_check (worker, work); +trace_sched_kthread_work_queue_work (worker, work); +list_add_tail (&work->node, pos); work->worker = worker;if (!worker->current_work &&likely (worker->task))
_
Andrew Morton
maintainerPATCH 2/200 kthread_worker: document CPU hotplug handling
In reply to Andrew MortonFrom: Petr Mladek <[email protected]>
Subject: kthread_worker: document CPU hotplug handling
The kthread worker API is simple. In short, it allows to create, use, and destroy workers. kthread_create_worker_on_cpu() just allows to bind a newly created worker to a given CPU.
It is up to the API user how to handle CPU hotplug. They have to decide how to handle pending work items, prevent queuing new ones, and restore the functionality when the CPU goes off and on. There are few catches:
+ The CPU affinity gets lost when it is scheduled on an offline CPU.
+ The worker might not exist when the CPU was off when the user created the workers.
A good practice is to implement two CPU hotplug callbacks and destroy/create the worker when CPU goes down/up.
Mention this in the function description.
---
kernel/kthread.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-)
kernel/kthread.c renamed from kernel/kthread.c~kthread_worker-document-cpu-hotplug-handling +19 -1
@@ -793,7 +793,25 @@ EXPORT_SYMBOL(kthread_create_worker);* A good practice is to add the cpu number also into the worker name. * For example, use kthread_create_worker_on_cpu(cpu, "helper/%d", cpu). * -* Returns a pointer to the allocated worker on success, ERR_PTR(-ENOMEM) +* CPU hotplug: +* The kthread worker API is simple and generic. It just provides a way +* to create, use, and destroy workers. +* +* It is up to the API user how to handle CPU hotplug. They have to decide +* how to handle pending work items, prevent queuing new ones, and +* restore the functionality when the CPU goes off and on. There are a +* few catches: +* +* - CPU affinity gets lost when it is scheduled on an offline CPU. +* +* - The worker might not exist when the CPU was off when the user +* created the workers. +* +* Good practice is to implement two CPU hotplug callbacks and to +* destroy/create the worker when the CPU goes down/up. +* +* Return: +* The pointer to the allocated worker on success, ERR_PTR(-ENOMEM) * when the needed structures could not get allocated, and ERR_PTR(-EINTR) * when the worker was SIGKILLed. */
_
Andrew Morton
maintainerPATCH 3/200 uapi: move constants from <linux/kernel.h> to <linux/const.h>
In reply to Andrew MortonFrom: Petr Vorel <[email protected]>
Subject: uapi: move constants from <linux/kernel.h> to <linux/const.h>
and include <linux/const.h> in UAPI headers instead of <linux/kernel.h>.
The reason is to avoid indirect <linux/sysinfo.h> include when using some network headers: <linux/netlink.h> or others -> <linux/kernel.h> -> <linux/sysinfo.h>.
This indirect include causes on MUSL redefinition of struct sysinfo when included both <sys/sysinfo.h> and some of UAPI headers:
In file included from x86_64-buildroot-linux-musl/sysroot/usr/include/linux/kernel.h:5,
from x86_64-buildroot-linux-musl/sysroot/usr/include/linux/netlink.h:5,
from ../include/tst_netlink.h:14,
from tst_crypto.c:13:
x86_64-buildroot-linux-musl/sysroot/usr/include/linux/sysinfo.h:8:8: error: redefinition of `struct sysinfo'
struct sysinfo {
^~~~~~~
In file included from ../include/tst_safe_macros.h:15,
from ../include/tst_test.h:93,
from tst_crypto.c:11:x86_64-buildroot-linux-musl/sysroot/usr/include/sys/sysinfo.h:10:8: note: originally defined here
---
include/uapi/linux/const.h | 5 +++++ include/uapi/linux/ethtool.h | 2 +- include/uapi/linux/kernel.h | 9 +-------- include/uapi/linux/lightnvm.h | 2 +- include/uapi/linux/mroute6.h | 2 +- include/uapi/linux/netfilter/x_tables.h | 2 +- include/uapi/linux/netlink.h | 2 +- include/uapi/linux/sysctl.h | 2 +- 8 files changed, 12 insertions(+), 14 deletions(-)
include/uapi/linux/const.h renamed from include/uapi/linux/const.h~uapi-move-constants-from-linux-kernelh-to-linux-consth +5 -0
@@ -28,4 +28,9 @@#define _BITUL (x) (_UL(1) << (x))#define _BITULL (x) (_ULL(1) << (x)) +#define __ALIGN_KERNEL (x, a) __ALIGN_KERNEL_MASK(x, (typeof(x))(a) - 1) +#define __ALIGN_KERNEL_MASK (x, mask) (((x) + (mask)) & ~(mask)) + +#define __KERNEL_DIV_ROUND_UP (n, d) (((n) + (d) - 1) / (d)) +#endif /* _UAPI_LINUX_CONST_H */
include/uapi/linux/ethtool.h renamed from include/uapi/linux/ethtool.h~uapi-move-constants-from-linux-kernelh-to-linux-consth +1 -1
@@ -14,7 +14,7 @@#ifndef _UAPI_LINUX_ETHTOOL_H#define _UAPI_LINUX_ETHTOOL_H -#include <linux/kernel.h> +#include <linux/const.h> #include <linux/types.h> #include <linux/if_ether.h>
include/uapi/linux/kernel.h renamed from include/uapi/linux/kernel.h~uapi-move-constants-from-linux-kernelh-to-linux-consth +1 -8
@@ -3,13 +3,6 @@#define _UAPI_LINUX_KERNEL_H#include <linux/sysinfo.h> - -/* -* 'kernel.h' contains some often-used function prototypes etc -*/ -#define __ALIGN_KERNEL (x, a) __ALIGN_KERNEL_MASK(x, (typeof(x))(a) - 1) -#define __ALIGN_KERNEL_MASK (x, mask) (((x) + (mask)) & ~(mask)) - -#define __KERNEL_DIV_ROUND_UP (n, d) (((n) + (d) - 1) / (d)) +#include <linux/const.h> #endif /* _UAPI_LINUX_KERNEL_H */
include/uapi/linux/lightnvm.h renamed from include/uapi/linux/lightnvm.h~uapi-move-constants-from-linux-kernelh-to-linux-consth +1 -1
@@ -21,7 +21,7 @@#define _UAPI_LINUX_LIGHTNVM_H#ifdef __KERNEL__ -#include <linux/kernel.h> +#include <linux/const.h> #include <linux/ioctl.h> #else /* __KERNEL__ */ #include <stdio.h>
include/uapi/linux/mroute6.h renamed from include/uapi/linux/mroute6.h~uapi-move-constants-from-linux-kernelh-to-linux-consth +1 -1
@@ -2,7 +2,7 @@#ifndef _UAPI__LINUX_MROUTE6_H#define _UAPI__LINUX_MROUTE6_H -#include <linux/kernel.h> +#include <linux/const.h> #include <linux/types.h> #include <linux/sockios.h> #include <linux/in6.h> /* For struct sockaddr_in6. */
include/uapi/linux/netfilter/x_tables.h renamed from include/uapi/linux/netfilter/x_tables.h~uapi-move-constants-from-linux-kernelh-to-linux-consth +1 -1
@@ -1,7 +1,7 @@/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ #ifndef _UAPI_X_TABLES_H#define _UAPI_X_TABLES_H -#include <linux/kernel.h> +#include <linux/const.h> #include <linux/types.h> #define XT_FUNCTION_MAXNAMELEN 30
include/uapi/linux/netlink.h renamed from include/uapi/linux/netlink.h~uapi-move-constants-from-linux-kernelh-to-linux-consth +1 -1
@@ -2,7 +2,7 @@#ifndef _UAPI__LINUX_NETLINK_H#define _UAPI__LINUX_NETLINK_H -#include <linux/kernel.h> +#include <linux/const.h> #include <linux/socket.h> /* for __kernel_sa_family_t */ #include <linux/types.h>
include/uapi/linux/sysctl.h renamed from include/uapi/linux/sysctl.h~uapi-move-constants-from-linux-kernelh-to-linux-consth +1 -1
@@ -23,7 +23,7 @@#ifndef _UAPI_LINUX_SYSCTL_H#define _UAPI_LINUX_SYSCTL_H -#include <linux/kernel.h> +#include <linux/const.h> #include <linux/types.h> #include <linux/compiler.h>
_
Andrew Morton
maintainerPATCH 4/200 ide/falcon: remove in_interrupt() usage
In reply to Andrew MortonFrom: Sebastian Andrzej Siewior <[email protected]>
Subject: ide/falcon: remove in_interrupt() usage
falconide_get_lock() is called by ide_lock_host() and its caller (ide_issue_rq()) has already a might_sleep() check.
stdma_lock() has wait_event() which also has a might_sleep() check.
Remove the in_interrupt() check.
---
drivers/ide/falconide.c | 2 -- 1 file changed, 2 deletions(-)
drivers/ide/falconide.c renamed from drivers/ide/falconide.c~ide-falcon-remove-in_interrupt-usage +0 -2
@@ -51,8 +51,6 @@ static void falconide_release_lock(void)static void falconide_get_lock (irq_handler_t handler,void *data) {if (falconide_intr_lock ==0 ) { -if (in_interrupt () >0 ) -panic ("Falcon IDE hasn't ST-DMA lock in interrupt" );stdma_lock (handler, data); falconide_intr_lock =1 ; }
_
Andrew Morton
maintainerPATCH 5/200 ide: remove BUG_ON(in_interrupt() || irqs_disabled()) from ide_unregister()
In reply to Andrew MortonFrom: Sebastian Andrzej Siewior <[email protected]>
Subject: ide: remove BUG_ON(in_interrupt() || irqs_disabled()) from ide_unregister()
In the discussion about preempt count consistency across kernel configurations:
https://lore.kernel.org/r/[email protected]/
it was concluded that the usage of in_interrupt() and related context checks should be removed from non-core code.
Both BUG_ON()s in ide-probe.c were introduced in commit
4015c949fb465 ("[PATCH] update ide core")
when ide_unregister() was extended with semaphore based locking. Both checks won't complain about disabled preemption which is also wrong.
The might_sleep() in today's mutex_lock() will complain about the missuses.
Remove the BUG_ON() statements.
---
drivers/ide/ide-probe.c | 3 --- 1 file changed, 3 deletions(-)
drivers/ide/ide-probe.c renamed from drivers/ide/ide-probe.c~ide-remove-bug_onin_interrupt-irqs_disabled-from-ide_unregister +0 -3
@@ -1592,9 +1592,6 @@ EXPORT_SYMBOL_GPL(ide_port_unregister_destatic void ide_unregister (ide_hwif_t *hwif) { -BUG_ON (in_interrupt ()); -BUG_ON (irqs_disabled ()); -mutex_lock (&ide_cfg_mtx);if (hwif->present) {
_
Andrew Morton
maintainerPATCH 6/200 fs/ntfs: remove unused varibles
In reply to Andrew MortonFrom: Alex Shi <[email protected]>
Subject: fs/ntfs: remove unused varibles
We actually don't use these varibles, so remove them to avoid gcc warning:fs/ntfs/file.c:326:14: warning: variable `base_ni' set but not used [-Wunused-but-set-variable]fs/ntfs/logfile.c:481:21: warning: variable `log_page_mask' set but not used [-Wunused-but-set-variable]
---
fs/ntfs/file.c | 5 +---- fs/ntfs/logfile.c | 3 +-- 2 files changed, 2 insertions(+), 6 deletions(-)
fs/ntfs/file.c renamed from fs/ntfs/file.c~fs-ntfs-remove-unused-varibles +1 -4
@@ -323,7 +323,7 @@ static ssize_t ntfs_prepare_file_for_wriunsigned long flags;struct file *file = iocb->ki_filp;struct inode *vi =file_inode (file); -ntfs_inode *base_ni, *ni =NTFS_I (vi); +ntfs_inode *ni =NTFS_I (vi);ntfs_volume *vol = ni->vol; ntfs_debug("Entering for i_ino 0x%lx, attribute type 0x%x, pos "
@@ -365,9 +365,6 @@ static ssize_t ntfs_prepare_file_for_wri err = -EOPNOTSUPP ; goto out; } - base_ni = ni; -if (NInoAttr (ni)) - base_ni = ni->ext.base_ntfs_ino; err =file_remove_privs (file);if (unlikely (err)) goto out;
fs/ntfs/logfile.c renamed from fs/ntfs/logfile.c~fs-ntfs-remove-unused-varibles +1 -2
@@ -478,7 +478,7 @@ bool ntfs_check_logfile(struct inode *lou8 *kaddr =NULL ;RESTART_PAGE_HEADER *rstr1_ph =NULL ;RESTART_PAGE_HEADER *rstr2_ph =NULL ; -int log_page_size, log_page_mask, err; +int log_page_size, err;bool logfile_is_empty = true;u8 log_page_bits;
@@ -501,7 +501,6 @@ bool ntfs_check_logfile(struct inode *lo log_page_size = DefaultLogPageSize; else log_page_size =PAGE_SIZE ; - log_page_mask = log_page_size -1 ;/* * Use ntfs_ffs() instead of ffs() to enable the compiler to * optimize log_page_size and log_page_bits into constants.
_
Andrew Morton
maintainerPATCH 7/200 fs/ntfs: remove unused variable attr_len
In reply to Andrew MortonFrom: Alex Shi <[email protected]>
Subject: fs/ntfs: remove unused variable attr_len
This variable isn't used anymore, remove it to skip W=1 warning:fs/ntfs/inode.c:2350:6: warning: variable `attr_len' set but not used [-Wunused-but-set-variable]
---
fs/ntfs/inode.c | 2 -- 1 file changed, 2 deletions(-)
fs/ntfs/inode.c renamed from fs/ntfs/inode.c~fs-ntfs-remove-unused-varible-attr_len +0 -2
@@ -2347,7 +2347,6 @@ int ntfs_truncate(struct inode *vi)ATTR_RECORD *a;const char *te =" Leaving file length out of sync with i_size." ;int err, mp_size, size_change, alloc_change; -u32 attr_len;ntfs_debug ("Entering for inode 0x%lx." , vi->i_ino);BUG_ON (NInoAttr (ni));
@@ -2721,7 +2720,6 @@ do_non_resident_truncate:* this cannot fail since we are making the attribute smaller thus by * definition there is enough space to do so. */ - attr_len =le32_to_cpu (a->length); err =ntfs_attr_record_resize (m, a, mp_size +le16_to_cpu (a->data.non_resident.mapping_pairs_offset));BUG_ON (err);
_
Andrew Morton
maintainerPATCH 8/200 fs/ocfs2/cluster/tcp.c: remove unneeded break
In reply to Andrew MortonFrom: Tom Rix <[email protected]>
Subject: fs/ocfs2/cluster/tcp.c: remove unneeded break
A break is not needed if it is preceded by a goto
---
fs/ocfs2/cluster/tcp.c | 1 - 1 file changed, 1 deletion(-)
fs/ocfs2/cluster/tcp.c renamed from fs/ocfs2/cluster/tcp.c~fs-ocfs2-remove-unneeded-break +0 -1
@@ -1198,7 +1198,6 @@ static int o2net_process_message(structmsglog (hdr,"bad magic\n" ); ret = -EINVAL ; goto out; -break ; }/* find a handler for it */
_
Andrew Morton
maintainerPATCH 9/200 ocfs2: ratelimit the 'max lookup times reached' notice
In reply to Andrew MortonFrom: Mauricio Faria de Oliveira <[email protected]>
Subject: ocfs2: ratelimit the 'max lookup times reached' notice
Running stress-ng on ocfs2 completely fills the kernel log with 'max lookup times reached, filesystem may have nested directories.'
Let's ratelimit this message as done with others in the code.
Test-case:
# mkfs.ocfs2 --mount local $DEV # mount $DEV $MNT # cd $MNT
# dmesg -C # stress-ng --dirdeep 1 --dirdeep-ops 1000 # dmesg | grep -c 'max lookup times reached'
Before:
# dmesg -C # stress-ng --dirdeep 1 --dirdeep-ops 1000 ... stress-ng: info: [11116] successful run completed in 3.03s
# dmesg | grep -c 'max lookup times reached' 967
After:
# dmesg -C # stress-ng --dirdeep 1 --dirdeep-ops 1000 ... stress-ng: info: [739] successful run completed in 0.96s
# dmesg | grep -c 'max lookup times reached' 10
# dmesg [ 259.086086] ocfs2_check_if_ancestor: 1990 callbacks suppressed [ 259.086092] (stress-ng-dirde,740,1):ocfs2_check_if_ancestor:1091 max lookup times reached, filesystem may have nested directories, src inode: 18007, dest inode: 17940. ...
---
fs/ocfs2/namei.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/ocfs2/namei.c renamed from fs/ocfs2/namei.c~ocfs2-ratelimit-the-max-lookup-times-reached-notice +2 -2
@@ -1088,8 +1088,8 @@ static int ocfs2_check_if_ancestor(struc child_inode_no = parent_inode_no;if (++i >=MAX_LOOKUP_TIMES ) { -mlog (ML_NOTICE ,"max lookup times reached, filesystem " -"may have nested directories, " +mlog_ratelimited (ML_NOTICE ,"max lookup times reached, " +"filesystem may have nested directories, " "src inode: %llu, dest inode: %llu.\n" , (unsigned long long )src_inode_no, (unsigned long long )dest_inode_no);
_
Andrew Morton
maintainerPATCH 10/200 arch/Kconfig: fix spelling mistakes
In reply to Andrew MortonFrom: Colin Ian King <[email protected]>
Subject: arch/Kconfig: fix spelling mistakes
There are a few spelling mistakes in the Kconfig comments and help text. Fix these.
---
arch/Kconfig | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
arch/Kconfig renamed from arch/Kconfig~arch-fix-spelling-mistakes-in-kconfig +4 -4
@@ -261,7 +261,7 @@ config ARCH_HAS_SET_DIRECT_MAP # # Select if the architecture provides the arch_dma_set_uncached symbol to -# either provide an uncached segement alias for a DMA allocation, or +# either provide an uncached segment alias for a DMA allocation, or # to remap the page tables in place. # config ARCH_HAS_DMA_SET_UNCACHED
@@ -314,14 +314,14 @@ config ARCH_32BIT_OFF_T config HAVE_ASM_MODVERSIONS bool help - This symbol should be selected by an architecure if it provides + This symbol should be selected by an architecture if it provides <asm/asm-prototypes.h> to support the module versioning for symbols exported from assembly code. config HAVE_REGS_AND_STACK_ACCESS_API bool help - This symbol should be selected by an architecure if it supports + This symbol should be selected by an architecture if it supports the API needed to access registers and stack entries from pt_regs, declared in asm/ptrace.h For example the kprobes-based event tracer needs this API.
@@ -336,7 +336,7 @@ config HAVE_RSEQ config HAVE_FUNCTION_ARG_ACCESS_API bool help - This symbol should be selected by an architecure if it supports + This symbol should be selected by an architecture if it supports the API needed to access function arguments from pt_regs, declared in asm/ptrace.h
_
Andrew Morton
maintainerPATCH 11/200 mm/slab_common.c: use list_for_each_entry in dump_unreclaimable_slab()
In reply to Andrew MortonFrom: Hui Su <[email protected]>
Subject: mm/slab_common.c: use list_for_each_entry in dump_unreclaimable_slab()
dump_unreclaimable_slab() acquires the slab_mutex first, and it won't remove any slab_caches list entry when itering the slab_caches lists.
Thus we do not need list_for_each_entry_safe here, which is against removal of list entry.
---
mm/slab_common.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
mm/slab_common.c renamed from mm/slab_common.c~mmslab_common-use-list_for_each_entry-in-dump_unreclaimable_slab +2 -2
@@ -978,7 +978,7 @@ static int slab_show(struct seq_file *m,void dump_unreclaimable_slab (void ) { -struct kmem_cache *s, *s2; +struct kmem_cache *s;struct slabinfo sinfo;/*
@@ -996,7 +996,7 @@ void dump_unreclaimable_slab(void)pr_info ("Unreclaimable slab info:\n" );pr_info ("Name Used Total\n" ); -list_for_each_entry_safe (s, s2, &slab_caches, list) { +list_for_each_entry (s, &slab_caches, list) {if (s->flags &SLAB_RECLAIM_ACCOUNT )continue ;
_
Andrew Morton
maintainerPATCH 12/200 mm: slab: clarify krealloc()'s behavior with __GFP_ZERO
In reply to Andrew MortonFrom: Bartosz Golaszewski <[email protected]>
Subject: mm: slab: clarify krealloc()'s behavior with __GFP_ZERO
Patch series "slab: provide and use krealloc_array()", v3.
Andy brought to my attention the fact that users allocating an array of equally sized elements should check if the size multiplication doesn't overflow. This is why we have helpers like kmalloc_array().
However we don't have krealloc_array() equivalent and there are many users who do their own multiplication when calling krealloc() for arrays.
This series provides krealloc_array() and uses it in a couple places.
A separate series will follow adding devm_krealloc_array() which is needed in the xilinx adc driver.
This patch (of 9):
__GFP_ZERO is ignored by krealloc() (unless we fall-back to kmalloc() path, in which case it's honored). Point that out in the kerneldoc.
---
mm/slab_common.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
mm/slab_common.c renamed from mm/slab_common.c~mm-slab-clarify-kreallocs-behavior-with-__gfp_zero +3 -3
@@ -1091,9 +1091,9 @@ static __always_inline void *__do_kreall* @flags: the type of memory to allocate. * * The contents of the object pointed to are preserved up to the -* lesser of the new and old sizes. If @p is %NULL, krealloc() -* behaves exactly like kmalloc(). If @new_size is 0 and @p is not a -* %NULL pointer, the object pointed to is freed. +* lesser of the new and old sizes (__GFP_ZERO flag is effectively ignored). +* If @p is %NULL, krealloc() behaves exactly like kmalloc(). If @new_size +* is 0 and @p is not a %NULL pointer, the object pointed to is freed. * * Return: pointer to the allocated memory or %NULL in case of error */
_
Christian König
maintainerRe: [patch 012/200] mm: slab: clarify krealloc()'s behavior with __GFP_ZERO
Am 15.12.20 um 04:03 schrieb Andrew Morton:
Quoted 63 lines
From: Bartosz Golaszewski <[email protected]>
Subject: mm: slab: clarify krealloc()'s behavior with__GFP_ZEROPatch series "slab: provide and use
krealloc_array()", v3.Andy brought to my attention the fact that users allocating an array of equally sized elements should check if the size multiplication doesn't overflow. This is why we have helpers like
kmalloc_array().However we don't have
krealloc_array()equivalent and there are many users who do their own multiplication when callingkrealloc()for arrays.This series provides
krealloc_array()and uses it in a couple places.A separate series will follow adding
devm_krealloc_array()which is needed in the xilinx adc driver.This patch (of 9):
__GFP_ZEROis ignored bykrealloc()(unless we fall-back tokmalloc()path, in which case it's honored). Point that out in the kerneldoc.Signed-off-by Bartosz Golaszewski <[email protected]>Cc Andy Shevchenko <[email protected]>Cc Sumit Semwal <[email protected]>Cc Gustavo Padovan <[email protected]>Cc Christian Knig <[email protected]>Cc Mauro Carvalho Chehab <[email protected]>Cc Borislav Petkov <[email protected]>Cc Tony Luck <[email protected]>Cc James Morse <[email protected]>Cc Robert Richter <[email protected]>Cc Maarten Lankhorst <[email protected]>Cc Maxime Ripard <[email protected]>Cc Thomas Zimmermann <[email protected]>Cc David Airlie <[email protected]>Cc Daniel Vetter <[email protected]>Cc Alexander Shishkin <[email protected]>Cc Linus Walleij <[email protected]>Cc "Michael S . Tsirkin" <[email protected]>Cc Jason Wang <[email protected]>Cc Christoph Lameter <[email protected]>Cc Pekka Enberg <[email protected]>Cc David Rientjes <[email protected]>Cc Joonsoo Kim <[email protected]>Cc Jaroslav Kysela <[email protected]>Cc Takashi Iwai <[email protected]>Cc Borislav Petkov <[email protected]>Cc Daniel Vetter <[email protected]>Cc Takashi Iwai <[email protected]>Cc Vlastimil Babka <[email protected]>Signed-off-by Andrew Morton <[email protected]>---
mm/slab_common.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
mm/slab_common.c static __always_inline void *__do_kreall · line 1096
Quoted 9 lines
mm/slab_common.c renamed from mm/slab_common.c~mm-slab-clarify-kreallocs-behavior-with-__gfp_zero +3
-3@@ -1091,9 +1091,9 @@ static __always_inline void *__do_kreall* @flags: the type of memory to allocate. * * The contents of the object pointed to are preserved up to the -* lesser of the new and old sizes. If @p is %NULL, krealloc() -* behaves exactly like kmalloc(). If @new_size is 0 and @p is not a -* %NULL pointer, the object pointed to is freed. +* lesser of the new and old sizes (__GFP_ZERO flag is effectively ignored). +* If @p is %NULL, krealloc() behaves exactly like kmalloc(). If @new_size +* is 0 and @p is not a %NULL pointer, the object pointed to is freed.
Question: Can the fact that __GFP_ZERO is effectively ignored cause an information leak if new size is larger than old size and the array is somehow copied to user space?
I think the answer is no, but just wanted to double check. Maybe we should note that here.
Thanks,
Christian.
Quoted 4 lines
mm/slab_common.c renamed from mm/slab_common.c~mm-slab-clarify-kreallocs-behavior-with-__gfp_zero +0
-0* * Return: pointer to the allocated memory or %NULL in case of error */ _
Re: [patch 012/200] mm: slab: clarify krealloc()'s behavior with __GFP_ZERO
Quoted 1 line · Christian König
Am 15.12.20 um 04:03 schrieb Andrew Morton:
...
Quoted 6 lines
Question: Can the fact that
__GFP_ZEROis effectively ignored cause an information leak if new size is larger than old size and the array is somehow copied to user space?I think the answer is no, but just wanted to double check. Maybe we should note that here.
kmalloc()/kmalloc_array()/etc has the same. Should it be mentioned there as well?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Christian König
maintainerRe: [patch 012/200] mm: slab: clarify krealloc()'s behavior with __GFP_ZERO
Am 15.12.20 um 20:08 schrieb Andy Shevchenko:
Quoted 11 lines · Christian König
Quoted 1 line
Am 15.12.20 um 04:03 schrieb Andrew Morton:
...
Quoted 6 lines
Question: Can the fact that
__GFP_ZEROis effectively ignored cause an information leak if new size is larger than old size and the array is somehow copied to user space?I think the answer is no, but just wanted to double check. Maybe we should note that here.
kmalloc()/kmalloc_array()/etc has the same. Should it be mentioned there as well?
No, they don't. If kmalloc()/kmalloc_array() would ignore __GFP_ZERO we would have quite a problem.
It is only krealloc()/krealloc_array() which ignore __GFP_ZERO when they don't reallocate memory because newsize is smaller than oldsize. In other words the freed up space is not cleared in any way.
Christian.
Re: [patch 012/200] mm: slab: clarify krealloc()'s behavior with __GFP_ZERO
Quoted 11 lines · Christian König
Am 15.12.20 um 20:08 schrieb Andy Shevchenko:
Quoted 10 lines · Christian König
Quoted 1 line
Am 15.12.20 um 04:03 schrieb Andrew Morton:
...
Quoted 6 lines
Question: Can the fact that
__GFP_ZEROis effectively ignored cause an information leak if new size is larger than old size and the array is somehow copied to user space?I think the answer is no, but just wanted to double check. Maybe we should note that here.
Quoted 8 lines
Quoted 1 line
kmalloc()/kmalloc_array()/etc has the same. Should it be mentioned there as well?
No, they don't. If kmalloc()/kmalloc_array() would ignore
__GFP_ZEROwe would have quite a problem.It is only krealloc()/krealloc_array() which ignore
__GFP_ZEROwhen they don't reallocate memory because newsize is smaller than oldsize. In other words the freed up space is not cleared in any way.
Yes, true. So, you meant that comment now a bit misleading. I agree.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Andrew Morton
maintainerPATCH 13/200 mm: slab: provide krealloc_array()
In reply to Andrew MortonFrom: Bartosz Golaszewski <[email protected]>
Subject: mm: slab: provide krealloc_array()
When allocating an array of elements, users should check for multiplication overflow or preferably use one of the provided helpers
like: kmalloc_array().
There's no krealloc_array() counterpart but there are many users who use regular krealloc() to reallocate arrays. Let's provide an actual krealloc_array() implementation.
While at it: add some documentation regarding krealloc.
---
Documentation/core-api/memory-allocation.rst | 4 +++ include/linux/slab.h | 18 +++++++++++++++++ 2 files changed, 22 insertions(+)
Documentation/core-api/memory-allocation.rst renamed from Documentation/core-api/memory-allocation.rst~mm-slab-provide-krealloc_array +4 -0
@@ -147,6 +147,10 @@ The address of a chunk allocated with `k ARCH_KMALLOC_MINALIGN bytes. For sizes which are a power of two, the alignment is also guaranteed to be at least the respective size. +Chunks allocated with kmalloc() can be resized with krealloc(). Similarly +to kmalloc_array(): a helper for resizing arrays is provided in the form of +krealloc_array(). + For large allocations you can use vmalloc() and vzalloc(), or directly request pages from the page allocator. The memory allocated by `vmalloc` and related functions is not physically contiguous.
include/linux/slab.h renamed from include/linux/slab.h~mm-slab-provide-krealloc_array +18 -0
@@ -593,6 +593,24 @@ static inline void *kmalloc_array(size_t }/** +* krealloc_array - reallocate memory for an array. +* @p: pointer to the memory chunk to reallocate +* @new_n: new number of elements to alloc +* @new_size: new size of a single member of the array +* @flags: the type of memory to allocate (see kmalloc) +*/ +static __must_check inline void * +krealloc_array (void *p,size_t new_n,size_t new_size,gfp_t flags) +{ +size_t bytes; + +if (unlikely (check_mul_overflow (new_n, new_size, &bytes))) +return NULL ; + +return krealloc (p, bytes, flags); +} + +/** * kcalloc - allocate memory for an array. The memory is set to zero. * @n: number of elements. * @size: element size.
_
Andrew Morton
maintainerPATCH 14/200 ALSA: pcm: use krealloc_array()
In reply to Andrew MortonFrom: Bartosz Golaszewski <[email protected]>
Subject: ALSA: pcm: use krealloc_array()
Use the helper that checks for overflows internally instead of manually calculating the size of the new array.
---
sound/core/pcm_lib.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
sound/core/pcm_lib.c renamed from sound/core/pcm_lib.c~alsa-pcm-use-krealloc_array +2 -2
@@ -1129,8 +1129,8 @@ int snd_pcm_hw_rule_add(struct snd_pcm_rif (constrs->rules_num >= constrs->rules_all) {struct snd_pcm_hw_rule *new;unsigned int new_rules = constrs->rules_all +16 ; - new =krealloc (constrs->rules, new_rules *sizeof (*c), -GFP_KERNEL ); + new =krealloc_array (constrs->rules, new_rules, +sizeof (*c),GFP_KERNEL );if (!new) {va_end (args);return -ENOMEM ;
_
Andrew Morton
maintainerPATCH 15/200 vhost: vringh: use krealloc_array()
In reply to Andrew MortonFrom: Bartosz Golaszewski <[email protected]>
Subject: vhost: vringh: use krealloc_array()
Use the helper that checks for overflows internally instead of manually calculating the size of the new array.
---
drivers/vhost/vringh.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/vhost/vringh.c renamed from drivers/vhost/vringh.c~vhost-vringh-use-krealloc_array +2 -1
@@ -198,7 +198,8 @@ static int resize_iovec(struct vringh_ki flag = (iov->max_num &VRINGH_IOV_ALLOCATED );if (flag) - new =krealloc (iov->iov, new_num *sizeof (struct iovec ), gfp); + new =krealloc_array (iov->iov, new_num, +sizeof (struct iovec ), gfp);else { new =kmalloc_array (new_num,sizeof (struct iovec ), gfp);if (new) {
_
Andrew Morton
maintainerPATCH 16/200 pinctrl: use krealloc_array()
In reply to Andrew MortonFrom: Bartosz Golaszewski <[email protected]>
Subject: pinctrl: use krealloc_array()
Use the helper that checks for overflows internally instead of manually calculating the size of the new array.
---
drivers/pinctrl/pinctrl-utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/pinctrl-utils.c renamed from drivers/pinctrl/pinctrl-utils.c~pinctrl-use-krealloc_array +1 -1
@@ -39,7 +39,7 @@ int pinctrl_utils_reserve_map(struct pinif (old_num >= new_num)return 0 ; - new_map =krealloc (*map,sizeof (*new_map) * new_num,GFP_KERNEL ); + new_map =krealloc_array (*map, new_num,sizeof (*new_map),GFP_KERNEL );if (!new_map) {dev_err (pctldev->dev,"krealloc(map) failed\n" );return -ENOMEM ;
_
Andrew Morton
maintainerPATCH 17/200 edac: ghes: use krealloc_array()
In reply to Andrew MortonFrom: Bartosz Golaszewski <[email protected]>
Subject: edac: ghes: use krealloc_array()
Use the helper that checks for overflows internally instead of manually calculating the size of the new array.
---
drivers/edac/ghes_edac.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/edac/ghes_edac.c renamed from drivers/edac/ghes_edac.c~edac-ghes-use-krealloc_array +2 -2
@@ -207,8 +207,8 @@ static void enumerate_dimms(const structif (!hw->num_dimms || !(hw->num_dimms %16 )) {struct dimm_info *new; - new =krealloc (hw->dimms, (hw->num_dimms +16 ) *sizeof (struct dimm_info ), -GFP_KERNEL ); + new =krealloc_array (hw->dimms, hw->num_dimms +16 , +sizeof (struct dimm_info ),GFP_KERNEL );if (!new) {WARN_ON_ONCE (1 );return ;
_
Andrew Morton
maintainerPATCH 18/200 drm: atomic: use krealloc_array()
In reply to Andrew MortonFrom: Bartosz Golaszewski <[email protected]>
Subject: drm: atomic: use krealloc_array()
Use the helper that checks for overflows internally instead of manually calculating the size of the new array.
---
drivers/gpu/drm/drm_atomic.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_atomic.c renamed from drivers/gpu/drm/drm_atomic.c~drm-atomic-use-krealloc_array +2 -1
@@ -960,7 +960,8 @@ drm_atomic_get_connector_state(struct drstruct __drm_connnectors_state *c;int alloc =max (index +1 , config->num_connector); - c =krealloc (state->connectors, alloc *sizeof (*state->connectors),GFP_KERNEL ); + c =krealloc_array (state->connectors, alloc, +sizeof (*state->connectors),GFP_KERNEL );if (!c)return ERR_PTR (-ENOMEM );
_
Andrew Morton
maintainerPATCH 19/200 hwtracing: intel: use krealloc_array()
In reply to Andrew MortonFrom: Bartosz Golaszewski <[email protected]>
Subject: hwtracing: intel: use krealloc_array()
Use the helper that checks for overflows internally instead of manually calculating the size of the new array.
---
drivers/hwtracing/intel_th/msu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwtracing/intel_th/msu.c renamed from drivers/hwtracing/intel_th/msu.c~hwtracing-intel-use-krealloc_array +1 -1
@@ -2002,7 +2002,7 @@ nr_pages_store(struct device *dev, struc } nr_wins++; - rewin =krealloc (win,sizeof (*win) * nr_wins,GFP_KERNEL ); + rewin =krealloc_array (win, nr_wins,sizeof (*win),GFP_KERNEL );if (!rewin) {kfree (win);return -ENOMEM ;
_
Andrew Morton
maintainerPATCH 20/200 dma-buf: use krealloc_array()
In reply to Andrew MortonFrom: Bartosz Golaszewski <[email protected]>
Subject: dma-buf: use krealloc_array()
Use the helper that checks for overflows internally instead of manually calculating the size of the new array.
---
drivers/dma-buf/sync_file.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/dma-buf/sync_file.c renamed from drivers/dma-buf/sync_file.c~dma-buf-use-krealloc_array +1 -2
@@ -270,8 +270,7 @@ static struct sync_file *sync_file_merge fences[i++] =dma_fence_get (a_fences[0 ]);if (num_fences > i) { - nfences =krealloc (fences, i *sizeof (*fences), -GFP_KERNEL ); + nfences =krealloc_array (fences, i,sizeof (*fences),GFP_KERNEL );if (!nfences) goto err;
_
Re: [patch 020/200] dma-buf: use krealloc_array()
Am 15.12.20 um 04:04 schrieb Andrew Morton:
Quoted 29 lines
From: Bartosz Golaszewski <[email protected]>
Subject: dma-buf: usekrealloc_array()Use the helper that checks for overflows internally instead of manually calculating the size of the new array.
Signed-off-by Bartosz Golaszewski <[email protected]>Acked-by Christian König <[email protected]>Cc Alexander Shishkin <[email protected]>Cc Andy Shevchenko <[email protected]>Cc Borislav Petkov <[email protected]>Cc Borislav Petkov <[email protected]>Cc Christoph Lameter <[email protected]>Cc Daniel Vetter <[email protected]>Cc Daniel Vetter <[email protected]>Cc David Airlie <[email protected]>Cc David Rientjes <[email protected]>Cc Gustavo Padovan <[email protected]>Cc James Morse <[email protected]>Cc Jaroslav Kysela <[email protected]>Cc Jason Wang <[email protected]>Cc Joonsoo Kim <[email protected]>Cc Linus Walleij <[email protected]>Cc Maarten Lankhorst <[email protected]>Cc Mauro Carvalho Chehab <[email protected]>Cc Maxime Ripard <[email protected]>Cc "Michael S . Tsirkin" <[email protected]>Cc Pekka Enberg <[email protected]>
Quoted 8 lines
Cc Robert Richter <[email protected]>Cc Sumit Semwal <[email protected]>Cc Takashi Iwai <[email protected]>Cc Takashi Iwai <[email protected]>Cc Thomas Zimmermann <[email protected]>Cc Tony Luck <[email protected]>Cc Vlastimil Babka <[email protected]>Signed-off-by Andrew Morton <[email protected]>
Quoted 18 lines
---
drivers/dma-buf/sync_file.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/dma-buf/sync_file.c renamed from drivers/dma-buf/sync_file.c~dma-buf-use-krealloc_array +1
-2@@ -270,8 +270,7 @@ static struct sync_file *sync_file_merge fences[i++] =dma_fence_get (a_fences[0 ]);if (num_fences > i) { - nfences =krealloc (fences, i *sizeof (*fences), -GFP_KERNEL ); + nfences =krealloc_array (fences, i,sizeof (*fences),GFP_KERNEL );if (!nfences) goto err;_
Andrew Morton
maintainerPATCH 21/200 mm, slab, slub: clear the slab_cache field when freeing page
In reply to Andrew MortonFrom: Vlastimil Babka <[email protected]>
Subject: mm, slab, slub: clear the slab_cache field when freeing page
The page allocator expects that page->mapping is NULL for a page being freed. SLAB and SLUB use the slab_cache field which is in union with mapping, but before freeing the page, the field is referenced with the "mapping" name when set to NULL.
It's IMHO more correct (albeit functionally the same) to use the slab_cache name as that's the field we use in SL*B, and document why we clear it in a comment (we don't clear fields such as s_mem or freelist, as page allocator doesn't care about those). While using the 'mapping' name would automagically keep the code correct if the unions in struct page changed, such changes should be done consciously and needed changes evaluated - the comment should help with that.
---
mm/slab.c | 3 ++- mm/slub.c | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-)
mm/slab.c renamed from mm/slab.c~mm-slab-slub-clear-the-slab_cache-field-when-freeing-page +2 -1
@@ -1399,7 +1399,8 @@ static void kmem_freepages(struct kmem_c__ClearPageSlabPfmemalloc (page);__ClearPageSlab (page);page_mapcount_reset (page); - page->mapping =NULL ; +/* In union with page->mapping where page allocator expects NULL */ + page->slab_cache =NULL ;if (current->reclaim_state) current->reclaim_state->reclaimed_slab +=1 << order;
mm/slub.c renamed from mm/slub.c~mm-slab-slub-clear-the-slab_cache-field-when-freeing-page +2 -2
@@ -1836,8 +1836,8 @@ static void __free_slab(struct kmem_cach__ClearPageSlabPfmemalloc (page);__ClearPageSlab (page); - - page->mapping =NULL ; +/* In union with page->mapping where page allocator expects NULL */ + page->slab_cache =NULL ;if (current->reclaim_state) current->reclaim_state->reclaimed_slab += pages;unaccount_slab_page (page, order, s);
_
Andrew Morton
maintainerPATCH 22/200 mm/slab: rerform init_on_free earlier
In reply to Andrew MortonFrom: Alexander Popov <[email protected]>
Subject: mm/slab: rerform init_on_free earlier
Currently in CONFIG_SLAB init_on_free happens too late, and heap objects go to the heap quarantine not being erased.
Lets move init_on_free clearing before calling kasan_slab_free(). In that case heap quarantine will store erased objects, similarly to CONFIG_SLUB=y behavior.
---
mm/slab.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
mm/slab.c renamed from mm/slab.c~mm-slab-perform-init_on_free-earlier +3 -2
@@ -3417,6 +3417,9 @@ free_done: static __always_inline void __cache_free(struct kmem_cache *cachep, void *objp,unsigned long caller) { +if (unlikely (slab_want_init_on_free (cachep))) +memset (objp,0 , cachep->object_size); +/* Put the object into the quarantine, don't touch it for now. */ if (kasan_slab_free (cachep, objp, _RET_IP_))return ;
@@ -3435,8 +3438,6 @@ void ___cache_free(struct kmem_cache *castruct array_cache *ac =cpu_cache_get (cachep);check_irq_off (); -if (unlikely (slab_want_init_on_free (cachep))) -memset (objp,0 , cachep->object_size);kmemleak_free_recursive (objp, cachep->flags); objp =cache_free_debugcheck (cachep, objp, caller);memcg_slab_free_hook (cachep, &objp,1 );
_
Alexander Potapenko
reviewerRe: [patch 022/200] mm/slab: rerform init_on_free earlier
Quoted 3 lines · Andrew Morton
From: Alexander Popov <[email protected]>
Subject: mm/slab: rerforminit_on_freeearlier
Nit: s/rerform/perform
Quoted 43 lines
Currently in
CONFIG_SLABinit_on_freehappens too late, and heap objects go to the heap quarantine not being erased.Lets move
init_on_freeclearing before callingkasan_slab_free(). In that case heap quarantine will store erased objects, similarly toCONFIG_SLUB=ybehavior.Signed-off-by Alexander Popov <[email protected]>Reviewed-by Alexander Potapenko <[email protected]>Acked-by David Rientjes <[email protected]>Acked-by Joonsoo Kim <[email protected]>Cc Christoph Lameter <[email protected]>Cc Pekka Enberg <[email protected]>Signed-off-by Andrew Morton <[email protected]>---
mm/slab.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)mm/slab.c renamed from mm/slab.c~mm-slab-perform-init_on_free-earlier +3
-2@@ -3417,6 +3417,9 @@ free_done: static __always_inline void __cache_free(struct kmem_cache *cachep, void *objp,unsigned long caller) { +if (unlikely (slab_want_init_on_free (cachep))) +memset (objp,0 , cachep->object_size); +/* Put the object into the quarantine, don't touch it for now. */ if (kasan_slab_free (cachep, objp, _RET_IP_))return ;@@ -3435,8 +3438,6 @@ void ___cache_free(struct kmem_cache *castruct array_cache *ac =cpu_cache_get (cachep);check_irq_off (); -if (unlikely (slab_want_init_on_free (cachep))) -memset (objp,0 , cachep->object_size);kmemleak_free_recursive (objp, cachep->flags); objp =cache_free_debugcheck (cachep, objp, caller);memcg_slab_free_hook (cachep, &objp,1 );_
Signature · 10 lines
Alexander Potapenko Software Engineer Google Germany GmbH Erika-Mann-Straße, 33 80636 München Geschäftsführer: Paul Manicle, Halimah DeLaine Prado Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg
Re: [patch 022/200] mm/slab: rerform init_on_free earlier
Quoted 6 lines · Alexander Potapenko
Quoted 3 lines · Andrew Morton
From: Alexander Popov <[email protected]>
Subject: mm/slab: rerforminit_on_freeearlierNit: s/rerform/perform
Right, thanks, Alexander!
Andrew, should I resend the patch?
Re: [patch 022/200] mm/slab: rerform init_on_free earlier
Quoted 11 lines · Alexander Popov
Quoted 6 lines · Alexander Potapenko
Quoted 3 lines · Andrew Morton
From: Alexander Popov <[email protected]>
Subject: mm/slab: rerforminit_on_freeearlierNit: s/rerform/perform
Right, thanks, Alexander!
Andrew, should I resend the patch?
Hm, this typo is not from my patch.
I guess my resending is not needed.
Best regards,
Alexander
Andrew Morton
maintainerPATCH 23/200 mm, slub: use kmem_cache_debug_flags() in deactivate_slab()
In reply to Andrew MortonFrom: Vlastimil Babka <[email protected]>
Subject: mm, slub: use kmem_cache_debug_flags() in deactivate_slab()
Commit 9cf7a1118365 ("mm/slub: make add_full() condition more explicit") replaced an unnecessarily generic kmem_cache_debug(s) check with an explicit check of SLAB_STORE_USER and #ifdef CONFIG_SLUB_DEBUG.
We can achieve the same specific check with the recently added kmem_cache_debug_flags() which removes the #ifdef and restores the no-branch-overhead benefit of static key check when slub debugging is not enabled.
---
mm/slub.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
mm/slub.c renamed from mm/slub.c~mm-slub-use-kmem_cache_debug_flags-in-deactivate_slab +1 -3
@@ -2245,8 +2245,7 @@ redo: } }else { m =M_FULL ; -#ifdef CONFIG_SLUB_DEBUG -if ((s->flags &SLAB_STORE_USER ) && !lock) { +if (kmem_cache_debug_flags (s,SLAB_STORE_USER ) && !lock) { lock =1 ;/* * This also ensures that the scanning of full
@@ -2255,7 +2254,6 @@ redo:*/ spin_lock (&n->list_lock); } -#endif }if (l != m) {
_
Andrew Morton
maintainerPATCH 24/200 mm/slub: let number of online CPUs determine the slub page order
In reply to Andrew MortonFrom: Bharata B Rao <[email protected]>
Subject: mm/slub: let number of online CPUs determine the slub page order
The page order of the slab that gets chosen for a given slab cache depends on the number of objects that can be fit in the slab while meeting other requirements. We start with a value of minimum objects based on nr_cpu_ids that is driven by possible number of CPUs and hence could be higher than the actual number of CPUs present in the system. This leads to calculate_order() chosing a page order that is on the higher side leading to increased slab memory consumption on systems that have bigger page sizes.
Hence rely on the number of online CPUs when determining the mininum objects, thereby increasing the chances of chosing a lower conservative page order for the slab.
Vlastimil:
: Ideally, we would react to hotplug events and update existing caches : accordingly. But for that, recalculation of order for existing caches : would have to be made safe, while not affecting hot paths. We have : removed the sysfs interface with 32a6f409b693 ("mm, slub: remove runtime : allocation order changes") as it didn't seem easy and worth the trouble. :
: In case somebody wants to start with a large order right from the boot : because they know they will hotplug lots of cpus later, they can use : slub_min_objects= boot param to override this heuristic. So in case this : change regresses somebody's performance, there's a way around it and : thus the risk is low IMHO.
---
mm/slub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/slub.c renamed from mm/slub.c~mm-slub-let-number-of-online-cpus-determine-the-slub-page-order +1 -1
@@ -3431,7 +3431,7 @@ static inline int calculate_order(unsign*/ min_objects = slub_min_objects;if (!min_objects) - min_objects =4 * (fls (nr_cpu_ids) +1 ); + min_objects =4 * (fls (num_online_cpus ()) +1 ); max_objects =order_objects (slub_max_order, size); min_objects =min (min_objects, max_objects);
_
Andrew Morton
maintainerPATCH 25/200 device-dax/kmem: use struct_size()
In reply to Andrew MortonFrom: Dan Williams <[email protected]>
Subject: device-dax/kmem: use struct_size()
Linus notes the kernel has had a nice helper for the 'size of struct with variable array member at the end' operation for a couple years now, use it.
---
drivers/dax/kmem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dax/kmem.c renamed from drivers/dax/kmem.c~device-dax-kmem-use-struct_size +1 -1
@@ -61,7 +61,7 @@ static int dev_dax_kmem_probe(struct devreturn -EINVAL ; } - data =kzalloc (sizeof (*data) +sizeof (struct resource *) * dev_dax->nr_range,GFP_KERNEL ); + data =kzalloc (struct_size (data, res, dev_dax->nr_range),GFP_KERNEL );if (!data)return -ENOMEM ;
_
Andrew Morton
maintainerPATCH 26/200 mm: fix page_owner initializing issue for arm32
In reply to Andrew MortonFrom: Zhenhua Huang <[email protected]>
Subject: mm: fix page_owner initializing issue for arm32
Page owner of pages used by page owner itself used is missing on arm32 targets. The reason is dummy_handle and failure_handle is not initialized correctly. Buddy allocator is used to initialize these two handles. However, buddy allocator is not ready when page owner calls it. This change fixed that by initializing page owner after buddy initialization.
The working flow before and after this change are:
original logic:
1. allocated memory for page_ext(using memblock).
2. invoke the init callback of page_ext_ops like page_owner(using buddy allocator).
3. initialize buddy.
after this change:
1. allocated memory for page_ext(using memblock).
2. initialize buddy.
3. invoke the init callback of page_ext_ops likepage_owner(using buddy allocator).
with the change, failure/dummy_handle can get its correct value and page owner output for example has the one for page owner itself:
Page allocated via order 2, mask 0x6202c0(GFP_USER|__GFP_NOWARN), pid 1006, ts 67278156558 ns
PFN 543776 type Unmovable Block 531 type Unmovable Flags 0x0()
init_page_owner+0x28/0x2f8 invoke_init_callbacks_flatmem+0x24/0x34 start_kernel+0x33c/0x5d8 (null)
---
include/linux/page_ext.h | 8 ++++++++ init/main.c | 2 ++ mm/page_ext.c | 10 ++++++++-- 3 files changed, 18 insertions(+), 2 deletions(-)
include/linux/page_ext.h renamed from include/linux/page_ext.h~mm-fix-page_owner-initializing-issue-for-arm32 +8 -0
@@ -44,8 +44,12 @@ static inline void page_ext_init_flatmem { }extern void page_ext_init (void ); +static inline void page_ext_init_flatmem_late (void ) +{ +}#else extern void page_ext_init_flatmem (void ); +extern void page_ext_init_flatmem_late (void );static inline void page_ext_init (void ) { }
@@ -76,6 +80,10 @@ static inline void page_ext_init(void) { } +static inline void page_ext_init_flatmem_late (void ) +{ +} +static inline void page_ext_init_flatmem (void ) { }
init/main.c renamed from init/main.c~mm-fix-page_owner-initializing-issue-for-arm32 +2 -0
@@ -828,6 +828,8 @@ static void __init mm_init(void)init_debug_pagealloc ();report_meminit ();mem_init (); +/* page_owner must be initialized after buddy is ready */ +page_ext_init_flatmem_late ();kmem_cache_init ();kmemleak_init ();pgtable_init ();
mm/page_ext.c renamed from mm/page_ext.c~mm-fix-page_owner-initializing-issue-for-arm32 +8 -2
@@ -99,12 +99,19 @@ static void __init invoke_init_callbacks } } +#ifndef CONFIG_SPARSEMEM +void __init page_ext_init_flatmem_late (void ) +{ +invoke_init_callbacks (); +} +#endif +static inline struct page_ext *get_entry (void *base,unsigned long index) {return base + page_ext_size * index; } -#if !defined(CONFIG_SPARSEMEM ) +#ifndef CONFIG_SPARSEMEM void __meminit pgdat_page_ext_init (struct pglist_data *pgdat)
@@ -177,7 +184,6 @@ void __init page_ext_init_flatmem(void) goto fail; }pr_info ("allocated %ld bytes of page_ext\n" , total_usage); -invoke_init_callbacks ();return ; fail:
_
Andrew Morton
maintainerPATCH 27/200 mm/page_owner: record timestamp and pid
In reply to Andrew MortonFrom: Liam Mark <[email protected]>
Subject: mm/page_owner: record timestamp and pid
Collect the time for each allocation recorded in page owner so that allocation "surges" can be measured.
Record the pid for each allocation recorded in page owner so that the source of allocation "surges" can be better identified.
The above is very useful when doing memory analysis. On a crash for example, we can get this information from kdump (or ramdump) and parse it to figure out memory allocation problems.
Please note that on x86_64 this increases the size of struct page_owner from 16 bytes to 32.
Vlastimil: it's not a functionality intended for production, so unless somebody says they need to enable page_owner for debugging and this increase prevents them from fitting into available memory, let's not complicate things with making this optional.
---
Documentation/vm/page_owner.rst | 12 ++++++------ mm/page_owner.c | 17 +++++++++++++---- 2 files changed, 19 insertions(+), 10 deletions(-)
Documentation/vm/page_owner.rst renamed from Documentation/vm/page_owner.rst~mm-page_owner-record-timestamp-and-pid +6 -6
@@ -41,17 +41,17 @@ size change due to this facility. - Without page owner:: text data bss dec hex filename - 40662 1493 644 42799 a72f mm/page_alloc.o + 48392 2333 644 51369 c8a9 mm/page_alloc.o - With page owner:: text data bss dec hex filename - 40892 1493 644 43029 a815 mm/page_alloc.o - 1427 24 8 1459 5b3 mm/page_ext.o - 2722 50 0 2772 ad4 mm/page_owner.o + 48800 2445 644 51889 cab1 mm/page_alloc.o + 6574 108 29 6711 1a37 mm/page_owner.o + 1025 8 8 1041 411 mm/page_ext.o -Although, roughly, 4 KB code is added in total, page_alloc.o increase by -230 bytes and only half of it is in hotpath. Building the kernel with +Although, roughly, 8 KB code is added in total, page_alloc.o increase by +520 bytes and less than half of it is in hotpath. Building the kernel with page owner and turning it on if needed would be great option to debug kernel memory problem.
mm/page_owner.c renamed from mm/page_owner.c~mm-page_owner-record-timestamp-and-pid +13 -4
@@ -10,6 +10,7 @@#include <linux/migrate.h> #include <linux/stackdepot.h> #include <linux/seq_file.h> +#include <linux/sched/clock.h> #include "internal.h"
@@ -25,6 +26,8 @@ struct page_owner {gfp_t gfp_mask;depot_stack_handle_t handle;depot_stack_handle_t free_handle; +u64 ts_nsec; +pid_t pid; };static bool page_owner_enabled = false;
@@ -172,6 +175,8 @@ static inline void __set_page_owner_hand page_owner->order = order; page_owner->gfp_mask = gfp_mask; page_owner->last_migrate_reason =-1 ; + page_owner->pid = current->pid; + page_owner->ts_nsec =local_clock ();__set_bit (PAGE_EXT_OWNER , &page_ext->flags);__set_bit (PAGE_EXT_OWNER_ALLOCATED , &page_ext->flags);
@@ -236,6 +241,8 @@ void __copy_page_owner(struct page *oldp new_page_owner->last_migrate_reason = old_page_owner->last_migrate_reason; new_page_owner->handle = old_page_owner->handle; + new_page_owner->pid = old_page_owner->pid; + new_page_owner->ts_nsec = old_page_owner->ts_nsec;/* * We don't clear the bit on the oldpage as it's going to be freed
@@ -349,9 +356,10 @@ print_page_owner(char __user *buf, size_return -ENOMEM ; ret =snprintf (kbuf, count, -"Page allocated via order %u, mask %#x(%pGg)\n" , +"Page allocated via order %u, mask %#x(%pGg), pid %d, ts %llu ns\n" , page_owner->order, page_owner->gfp_mask, - &page_owner->gfp_mask); + &page_owner->gfp_mask, page_owner->pid, + page_owner->ts_nsec);if (ret >= count) goto err;
@@ -427,8 +435,9 @@ void __dump_page_owner(struct page *pageelse pr_alert ("page_owner tracks the page as freed\n" ); -pr_alert ("page last allocated via order %u, migratetype %s, gfp_mask %#x(%pGg)\n" , - page_owner->order, migratetype_names[mt], gfp_mask, &gfp_mask); +pr_alert ("page last allocated via order %u, migratetype %s, gfp_mask %#x(%pGg), pid %d, ts %llu\n" , + page_owner->order, migratetype_names[mt], gfp_mask, &gfp_mask, + page_owner->pid, page_owner->ts_nsec); handle =READ_ONCE (page_owner->handle);if (!handle) {
_
Andrew Morton
maintainerPATCH 28/200 mm/filemap/c: break generic_file_buffered_read up into multiple functions
In reply to Andrew MortonFrom: Kent Overstreet <[email protected]>
Subject: mm/filemap/c: break generic_file_buffered_read up into multiple functions
Patch series "generic_file_buffered_read() improvements", v2.
generic_file_buffered_read() has turned into a real monstrosity to work with. And it's a major performance improvement, for both small random and large sequential reads. On my test box, 4k buffered random reads go from ~150k to ~250k iops, and the improvements to big sequential reads are even bigger.
This incorporates the fix for IOCB_WAITQ handling that Jens just posted as well, also factors out lock_page_for_iocb() to improve handling of the various iocb flags.
This patch (of 2):
This is prep work for changing generic_file_buffered_read() to use find_get_pages_contig() to batch up all the pagecache lookups.
This patch should be functionally identical to the existing code and changes as little as of the flow control as possible. More refactoring could be done, this patch is intended to be relatively minimal.
---
mm/filemap.c | 483 ++++++++++++++++++++++++++----------------------- 1 file changed, 261 insertions(+), 222 deletions(-)
mm/filemap.c renamed from mm/filemap.c~fs-break-generic_file_buffered_read-up-into-multiple-functions +261 -222
@@ -2166,6 +2166,234 @@ static void shrink_readahead_size_eio(st ra->ra_pages /=4 ; } +static int lock_page_for_iocb (struct kiocb *iocb,struct page *page) +{ +if (iocb->ki_flags &IOCB_WAITQ ) +return lock_page_async (page, iocb->ki_waitq); +else if (iocb->ki_flags &IOCB_NOWAIT ) +return trylock_page (page) ?0 : -EAGAIN ; +else +return lock_page_killable (page); +} + +static int generic_file_buffered_read_page_ok (struct kiocb *iocb, +struct iov_iter *iter, +struct page *page) +{ +struct address_space *mapping = iocb->ki_filp->f_mapping; +struct inode *inode = mapping->host; +struct file_ra_state *ra = &iocb->ki_filp->f_ra; +unsigned int offset = iocb->ki_pos & ~PAGE_MASK ; +unsigned int bytes, copied; +loff_t isize, end_offset; + +BUG_ON (iocb->ki_pos >>PAGE_SHIFT != page->index); + +/* +* i_size must be checked after we know the page is Uptodate. +* +* Checking i_size after the check allows us to calculate +* the correct value for "bytes", which means the zero-filled +* part of the page is not copied back to userspace (unless +* another truncate extends the file - this is desired though). +*/ + + isize =i_size_read (inode); +if (unlikely (iocb->ki_pos >= isize)) +return 1 ; + + end_offset =min_t (loff_t, isize, iocb->ki_pos + iter->count); + + bytes =min_t (loff_t, end_offset - iocb->ki_pos,PAGE_SIZE - offset); + +/* If users can be writing to this page using arbitrary +* virtual addresses, take care about potential aliasing +* before reading the page on the kernel side. +*/ +if (mapping_writably_mapped (mapping)) +flush_dcache_page (page); + +/* +* Ok, we have the page, and it's up-to-date, so +* now we can copy it to user space... +*/ + + copied =copy_page_to_iter (page, offset, bytes, iter); + + iocb->ki_pos += copied; + +/* +* When a sequential read accesses a page several times, +* only mark it as accessed the first time. +*/ +if (iocb->ki_pos >>PAGE_SHIFT != ra->prev_pos >>PAGE_SHIFT ) +mark_page_accessed (page); + + ra->prev_pos = iocb->ki_pos; + +if (copied < bytes) +return -EFAULT ; + +return !iov_iter_count (iter) || iocb->ki_pos == isize; +} + +static struct page * +generic_file_buffered_read_readpage (struct kiocb *iocb, +struct file *filp, +struct address_space *mapping, +struct page *page) +{ +struct file_ra_state *ra = &filp->f_ra; +int error; + +if (iocb->ki_flags & (IOCB_NOIO |IOCB_NOWAIT )) { +unlock_page (page); +put_page (page); +return ERR_PTR (-EAGAIN ); + } + +/* +* A previous I/O error may have been due to temporary +* failures, eg. multipath errors. +* PG_error will be set again if readpage fails. +*/ +ClearPageError (page); +/* Start the actual read. The read will unlock the page. */ + error = mapping->a_ops->readpage (filp, page); + +if (unlikely (error)) { +put_page (page); +return error !=AOP_TRUNCATED_PAGE ?ERR_PTR (error) :NULL ; + } + +if (!PageUptodate (page)) { + error =lock_page_for_iocb (iocb, page); +if (unlikely (error)) { +put_page (page); +return ERR_PTR (error); + } +if (!PageUptodate (page)) { +if (page->mapping ==NULL ) { +/* +* invalidate_mapping_pages got it +*/ +unlock_page (page); +put_page (page); +return NULL ; + } +unlock_page (page); +shrink_readahead_size_eio (ra); +put_page (page); +return ERR_PTR (-EIO ); + } +unlock_page (page); + } + +return page; +} + +static struct page * +generic_file_buffered_read_pagenotuptodate (struct kiocb *iocb, +struct file *filp, +struct iov_iter *iter, +struct page *page, +loff_t pos,loff_t count) +{ +struct address_space *mapping = filp->f_mapping; +struct inode *inode = mapping->host; +int error; + +/* +* See comment in do_read_cache_page on why +* wait_on_page_locked is used to avoid unnecessarily +* serialisations and why it's safe. +*/ +if (iocb->ki_flags &IOCB_WAITQ ) { + error =wait_on_page_locked_async (page, + iocb->ki_waitq); + }else { + error =wait_on_page_locked_killable (page); + } +if (unlikely (error)) { +put_page (page); +return ERR_PTR (error); + } +if (PageUptodate (page)) +return page; + +if (inode->i_blkbits ==PAGE_SHIFT || + !mapping->a_ops->is_partially_uptodate) + goto page_not_up_to_date; +/* pipes can't handle partially uptodate pages */ +if (unlikely (iov_iter_is_pipe (iter))) + goto page_not_up_to_date; +if (!trylock_page (page)) + goto page_not_up_to_date; +/* Did it get truncated before we got the lock? */ +if (!page->mapping) + goto page_not_up_to_date_locked; +if (!mapping->a_ops->is_partially_uptodate (page, + pos & ~PAGE_MASK , count)) + goto page_not_up_to_date_locked; +unlock_page (page); +return page; + +page_not_up_to_date: +/* Get exclusive access to the page ... */ + error =lock_page_for_iocb (iocb, page); +if (unlikely (error)) { +put_page (page); +return ERR_PTR (error); + } + +page_not_up_to_date_locked: +/* Did it get truncated before we got the lock? */ +if (!page->mapping) { +unlock_page (page); +put_page (page); +return NULL ; + } + +/* Did somebody else fill it already? */ +if (PageUptodate (page)) { +unlock_page (page); +return page; + } + +return generic_file_buffered_read_readpage (iocb, filp, mapping, page); +} + +static struct page * +generic_file_buffered_read_no_cached_page (struct kiocb *iocb, +struct iov_iter *iter) +{ +struct file *filp = iocb->ki_filp; +struct address_space *mapping = filp->f_mapping; +pgoff_t index = iocb->ki_pos >>PAGE_SHIFT ; +struct page *page; +int error; + +if (iocb->ki_flags &IOCB_NOIO ) +return ERR_PTR (-EAGAIN ); + +/* +* Ok, it wasn't cached, so we need to create a new +* page.. +*/ + page =page_cache_alloc (mapping); +if (!page) +return ERR_PTR (-ENOMEM ); + + error =add_to_page_cache_lru (page, mapping, index, +mapping_gfp_constraint (mapping,GFP_KERNEL )); +if (error) { +put_page (page); +return error != -EEXIST ?ERR_PTR (error) :NULL ; + } + +return generic_file_buffered_read_readpage (iocb, filp, mapping, page); +} +/** * generic_file_buffered_read - generic file read routine * @iocb: the iocb to read
@@ -2189,23 +2417,15 @@ ssize_t generic_file_buffered_read(strucstruct address_space *mapping = filp->f_mapping;struct inode *inode = mapping->host;struct file_ra_state *ra = &filp->f_ra; -loff_t *ppos = &iocb->ki_pos; -pgoff_t index; +size_t orig_count =iov_iter_count (iter);pgoff_t last_index; -pgoff_t prev_index; -unsigned long offset;/* offset into pagecache page */ -unsigned int prev_offset;int error =0 ; -if (unlikely (*ppos >= inode->i_sb->s_maxbytes)) +if (unlikely (iocb->ki_pos >= inode->i_sb->s_maxbytes))return 0 ;iov_iter_truncate (iter, inode->i_sb->s_maxbytes); - index = *ppos >>PAGE_SHIFT ; - prev_index = ra->prev_pos >>PAGE_SHIFT ; - prev_offset = ra->prev_pos & (PAGE_SIZE -1 ); - last_index = (*ppos + iter->count +PAGE_SIZE -1 ) >>PAGE_SHIFT ; - offset = *ppos & ~PAGE_MASK ; + last_index = (iocb->ki_pos + iter->count +PAGE_SIZE -1 ) >>PAGE_SHIFT ;/* * If we've already successfully copied some data, then we
@@ -2216,10 +2436,8 @@ ssize_t generic_file_buffered_read(struc iocb->ki_flags |=IOCB_NOWAIT ;for (;;) { +pgoff_t index = iocb->ki_pos >>PAGE_SHIFT ;struct page *page; -pgoff_t end_index; -loff_t isize; -unsigned long nr, ret;cond_resched (); find_page:
@@ -2228,6 +2446,14 @@ find_page: goto out; } +/* +* We can't return -EIOCBQUEUED once we've done some work, so +* ensure we don't block: +*/ +if ((iocb->ki_flags &IOCB_WAITQ ) && + (written + orig_count -iov_iter_count (iter))) + iocb->ki_flags |=IOCB_NOWAIT ; + page =find_get_page (mapping, index);if (!page) {if (iocb->ki_flags &IOCB_NOIO )
@@ -2236,8 +2462,15 @@ find_page: ra, filp, index, last_index - index); page =find_get_page (mapping, index); -if (unlikely (page ==NULL )) - goto no_cached_page; +if (unlikely (page ==NULL )) { + page =generic_file_buffered_read_no_cached_page (iocb, iter); +if (!page) + goto find_page; +if (IS_ERR (page)) { + error =PTR_ERR (page); + goto out; + } + } }if (PageReadahead (page)) {if (iocb->ki_flags &IOCB_NOIO ) {
@@ -2249,231 +2482,37 @@ find_page: index, last_index - index); }if (!PageUptodate (page)) { -/* -* See comment in do_read_cache_page on why -* wait_on_page_locked is used to avoid unnecessarily -* serialisations and why it's safe. -*/ -if (iocb->ki_flags &IOCB_WAITQ ) { -if (written) { -put_page (page); - goto out; - } - error =wait_on_page_locked_async (page, - iocb->ki_waitq); - }else { -if (iocb->ki_flags &IOCB_NOWAIT ) { -put_page (page); - goto would_block; - } - error =wait_on_page_locked_killable (page); - } -if (unlikely (error)) - goto readpage_error; -if (PageUptodate (page)) - goto page_ok; - -if (inode->i_blkbits ==PAGE_SHIFT || - !mapping->a_ops->is_partially_uptodate) - goto page_not_up_to_date; -/* pipes can't handle partially uptodate pages */ -if (unlikely (iov_iter_is_pipe (iter))) - goto page_not_up_to_date; -if (!trylock_page (page)) - goto page_not_up_to_date; -/* Did it get truncated before we got the lock? */ -if (!page->mapping) - goto page_not_up_to_date_locked; -if (!mapping->a_ops->is_partially_uptodate (page, - offset, iter->count)) - goto page_not_up_to_date_locked; -unlock_page (page); - } -page_ok: -/* -* i_size must be checked after we know the page is Uptodate. -* -* Checking i_size after the check allows us to calculate -* the correct value for "nr", which means the zero-filled -* part of the page is not copied back to userspace (unless -* another truncate extends the file - this is desired though). -*/ - - isize =i_size_read (inode); - end_index = (isize -1 ) >>PAGE_SHIFT ; -if (unlikely (!isize || index > end_index)) { -put_page (page); - goto out; - } - -/* nr is the maximum number of bytes to copy from this page */ - nr =PAGE_SIZE ; -if (index == end_index) { - nr = ((isize -1 ) & ~PAGE_MASK ) +1 ; -if (nr <= offset) { +if (iocb->ki_flags &IOCB_NOWAIT ) {put_page (page); + error = -EAGAIN ; goto out; } - } - nr = nr - offset; - -/* If users can be writing to this page using arbitrary -* virtual addresses, take care about potential aliasing -* before reading the page on the kernel side. -*/ -if (mapping_writably_mapped (mapping)) -flush_dcache_page (page); - -/* -* When a sequential read accesses a page several times, -* only mark it as accessed the first time. -*/ -if (prev_index != index || offset != prev_offset) -mark_page_accessed (page); - prev_index = index; - -/* -* Ok, we have the page, and it's up-to-date, so -* now we can copy it to user space... -*/ - - ret =copy_page_to_iter (page, offset, nr, iter); - offset += ret; - index += offset >>PAGE_SHIFT ; - offset &= ~PAGE_MASK ; - prev_offset = offset; - -put_page (page); - written += ret; -if (!iov_iter_count (iter)) - goto out; -if (ret < nr) { - error = -EFAULT ; - goto out; - } -continue ; - -page_not_up_to_date: -/* Get exclusive access to the page ... */ -if (iocb->ki_flags &IOCB_WAITQ ) { -if (written) { -put_page (page); - goto out; - } - error =lock_page_async (page, iocb->ki_waitq); - }else { - error =lock_page_killable (page); - } -if (unlikely (error)) - goto readpage_error; - -page_not_up_to_date_locked: -/* Did it get truncated before we got the lock? */ -if (!page->mapping) { -unlock_page (page); -put_page (page); -continue ; - } - -/* Did somebody else fill it already? */ -if (PageUptodate (page)) { -unlock_page (page); - goto page_ok; - } - -readpage: -if (iocb->ki_flags & (IOCB_NOIO |IOCB_NOWAIT )) { -unlock_page (page); -put_page (page); - goto would_block; - } -/* -* A previous I/O error may have been due to temporary -* failures, eg. multipath errors. -* PG_error will be set again if readpage fails. -*/ -ClearPageError (page); -/* Start the actual read. The read will unlock the page. */ - error = mapping->a_ops->readpage (filp, page); - -if (unlikely (error)) { -if (error ==AOP_TRUNCATED_PAGE ) { -put_page (page); - error =0 ; + page =generic_file_buffered_read_pagenotuptodate (iocb, + filp, iter, page, iocb->ki_pos, iter->count); +if (!page) goto find_page; +if (IS_ERR (page)) { + error =PTR_ERR (page); + goto out; } - goto readpage_error; - } - -if (!PageUptodate (page)) { -if (iocb->ki_flags &IOCB_WAITQ ) { -if (written) { -put_page (page); - goto out; - } - error =lock_page_async (page, iocb->ki_waitq); - }else { - error =lock_page_killable (page); - } - -if (unlikely (error)) - goto readpage_error; -if (!PageUptodate (page)) { -if (page->mapping ==NULL ) { -/* -* invalidate_mapping_pages got it -*/ -unlock_page (page); -put_page (page); - goto find_page; - } -unlock_page (page); -shrink_readahead_size_eio (ra); - error = -EIO ; - goto readpage_error; - } -unlock_page (page); } - goto page_ok; - -readpage_error: -/* UHHUH! A synchronous read error occurred. Report it */ + error =generic_file_buffered_read_page_ok (iocb, iter, page);put_page (page); - goto out; -no_cached_page: -/* -* Ok, it wasn't cached, so we need to create a new -* page.. -*/ - page =page_cache_alloc (mapping); -if (!page) { - error = -ENOMEM ; - goto out; - } - error =add_to_page_cache_lru (page, mapping, index, -mapping_gfp_constraint (mapping,GFP_KERNEL ));if (error) { -put_page (page); -if (error == -EEXIST ) { +if (error >0 ) error =0 ; - goto find_page; - } goto out; } - goto readpage; } would_block: error = -EAGAIN ; out: - ra->prev_pos = prev_index; - ra->prev_pos <<=PAGE_SHIFT ; - ra->prev_pos |= prev_offset; - - *ppos = ((loff_t )index <<PAGE_SHIFT ) + offset;file_accessed (filp); + written += orig_count -iov_iter_count (iter); +return written ? written : error; }EXPORT_SYMBOL_GPL (generic_file_buffered_read);
_
Andrew Morton
maintainerPATCH 29/200 mm/filemap.c: generic_file_buffered_read() now uses find_get_pages_contig
In reply to Andrew MortonFrom: Kent Overstreet <[email protected]>
Subject: mm/filemap.c: generic_file_buffered_read() now uses find_get_pages_contig
Convert generic_file_buffered_read() to get pages to read from in batches, and then copy data to userspace from many pages at once - in particular, we now don't touch any cachelines that might be contended while we're in the loop to copy data to userspace.
This is is a performance improvement on workloads that do buffered reads with large blocksizes, and a very large performance improvement if that file is also being accessed concurrently by different threads.
On smaller reads (512 bytes), there's a very small performance improvement (1%, within the margin of error).
akpm: kernel test robot found a 32% speedup on one test:
https://lkml.kernel.org/r/20201030081456.GY31092@shao2-debian
---
mm/filemap.c | 313 +++++++++++++++++++++++++++---------------------- 1 file changed, 175 insertions(+), 138 deletions(-)
mm/filemap.c renamed from mm/filemap.c~fs-generic_file_buffered_read-now-uses-find_get_pages_contig +175 -138
@@ -2176,67 +2176,6 @@ static int lock_page_for_iocb(struct kioreturn lock_page_killable (page); } -static int generic_file_buffered_read_page_ok (struct kiocb *iocb, -struct iov_iter *iter, -struct page *page) -{ -struct address_space *mapping = iocb->ki_filp->f_mapping; -struct inode *inode = mapping->host; -struct file_ra_state *ra = &iocb->ki_filp->f_ra; -unsigned int offset = iocb->ki_pos & ~PAGE_MASK ; -unsigned int bytes, copied; -loff_t isize, end_offset; - -BUG_ON (iocb->ki_pos >>PAGE_SHIFT != page->index); - -/* -* i_size must be checked after we know the page is Uptodate. -* -* Checking i_size after the check allows us to calculate -* the correct value for "bytes", which means the zero-filled -* part of the page is not copied back to userspace (unless -* another truncate extends the file - this is desired though). -*/ - - isize =i_size_read (inode); -if (unlikely (iocb->ki_pos >= isize)) -return 1 ; - - end_offset =min_t (loff_t, isize, iocb->ki_pos + iter->count); - - bytes =min_t (loff_t, end_offset - iocb->ki_pos,PAGE_SIZE - offset); - -/* If users can be writing to this page using arbitrary -* virtual addresses, take care about potential aliasing -* before reading the page on the kernel side. -*/ -if (mapping_writably_mapped (mapping)) -flush_dcache_page (page); - -/* -* Ok, we have the page, and it's up-to-date, so -* now we can copy it to user space... -*/ - - copied =copy_page_to_iter (page, offset, bytes, iter); - - iocb->ki_pos += copied; - -/* -* When a sequential read accesses a page several times, -* only mark it as accessed the first time. -*/ -if (iocb->ki_pos >>PAGE_SHIFT != ra->prev_pos >>PAGE_SHIFT ) -mark_page_accessed (page); - - ra->prev_pos = iocb->ki_pos; - -if (copied < bytes) -return -EFAULT ; - -return !iov_iter_count (iter) || iocb->ki_pos == isize; -} -static struct page * generic_file_buffered_read_readpage(struct kiocb *iocb, struct file *filp,
@@ -2394,6 +2333,92 @@ generic_file_buffered_read_no_cached_pagreturn generic_file_buffered_read_readpage (iocb, filp, mapping, page); } +static int generic_file_buffered_read_get_pages (struct kiocb *iocb, +struct iov_iter *iter, +struct page **pages, +unsigned int nr) +{ +struct file *filp = iocb->ki_filp; +struct address_space *mapping = filp->f_mapping; +struct file_ra_state *ra = &filp->f_ra; +pgoff_t index = iocb->ki_pos >>PAGE_SHIFT ; +pgoff_t last_index = (iocb->ki_pos + iter->count +PAGE_SIZE -1 ) >>PAGE_SHIFT ; +int i, j, nr_got, err =0 ; + + nr = min_t(unsigned long, last_index - index, nr); +find_page: +if (fatal_signal_pending (current)) +return -EINTR ; + + nr_got =find_get_pages_contig (mapping, index, nr, pages); +if (nr_got) + goto got_pages; + +if (iocb->ki_flags &IOCB_NOIO ) +return -EAGAIN ; + +page_cache_sync_readahead (mapping, ra, filp, index, last_index - index); + + nr_got =find_get_pages_contig (mapping, index, nr, pages); +if (nr_got) + goto got_pages; + + pages[0 ] =generic_file_buffered_read_no_cached_page (iocb, iter); + err =PTR_ERR_OR_ZERO (pages[0 ]); +if (!IS_ERR_OR_NULL (pages[0 ])) + nr_got =1 ; +got_pages: +for (i =0 ; i < nr_got; i++) { +struct page *page = pages[i]; +pgoff_t pg_index = index + i; +loff_t pg_pos =max (iocb->ki_pos, + (loff_t ) pg_index <<PAGE_SHIFT ); +loff_t pg_count = iocb->ki_pos + iter->count - pg_pos; + +if (PageReadahead (page)) { +if (iocb->ki_flags &IOCB_NOIO ) { +for (j = i; j < nr_got; j++) +put_page (pages[j]); + nr_got = i; + err = -EAGAIN ; +break ; + } +page_cache_async_readahead (mapping, ra, filp, page, + pg_index, last_index - pg_index); + } + +if (!PageUptodate (page)) { +if ((iocb->ki_flags &IOCB_NOWAIT ) || + ((iocb->ki_flags &IOCB_WAITQ ) && i)) { +for (j = i; j < nr_got; j++) +put_page (pages[j]); + nr_got = i; + err = -EAGAIN ; +break ; + } + + page =generic_file_buffered_read_pagenotuptodate (iocb, + filp, iter, page, pg_pos, pg_count); +if (IS_ERR_OR_NULL (page)) { +for (j = i +1 ; j < nr_got; j++) +put_page (pages[j]); + nr_got = i; + err =PTR_ERR_OR_ZERO (page); +break ; + } + } + } + +if (likely (nr_got)) +return nr_got; +if (err) +return err; +/* +* No pages and no error means we raced and should retry: +*/ + goto find_page; +} +/** * generic_file_buffered_read - generic file read routine * @iocb: the iocb to read
@@ -2414,104 +2439,116 @@ ssize_t generic_file_buffered_read(struc struct iov_iter *iter, ssize_t written) {struct file *filp = iocb->ki_filp; +struct file_ra_state *ra = &filp->f_ra;struct address_space *mapping = filp->f_mapping;struct inode *inode = mapping->host; -struct file_ra_state *ra = &filp->f_ra; -size_t orig_count =iov_iter_count (iter); -pgoff_t last_index; -int error =0 ; +struct page *pages_onstack[PAGEVEC_SIZE ], **pages =NULL ; + unsigned int nr_pages = min_t(unsigned int, 512, + ((iocb->ki_pos + iter->count +PAGE_SIZE -1 ) >>PAGE_SHIFT ) - + (iocb->ki_pos >>PAGE_SHIFT )); +int i, pg_nr, error =0 ; +bool writably_mapped; +loff_t isize, end_offset;if (unlikely (iocb->ki_pos >= inode->i_sb->s_maxbytes))return 0 ;iov_iter_truncate (iter, inode->i_sb->s_maxbytes); - last_index = (iocb->ki_pos + iter->count +PAGE_SIZE -1 ) >>PAGE_SHIFT ; - -/* -* If we've already successfully copied some data, then we -* can no longer safely return -EIOCBQUEUED. Hence mark -* an async read NOWAIT at that point. -*/ -if (written && (iocb->ki_flags &IOCB_WAITQ )) - iocb->ki_flags |=IOCB_NOWAIT ; +if (nr_pages >ARRAY_SIZE (pages_onstack)) + pages =kmalloc_array (nr_pages,sizeof (void *),GFP_KERNEL ); -for (;;) { -pgoff_t index = iocb->ki_pos >>PAGE_SHIFT ; -struct page *page; +if (!pages) { + pages = pages_onstack; + nr_pages = min_t(unsigned int, nr_pages, ARRAY_SIZE(pages_onstack)); + } +do {cond_resched (); -find_page: -if (fatal_signal_pending (current)) { - error = -EINTR ; - goto out; - }/* -* We can't return -EIOCBQUEUED once we've done some work, so -* ensure we don't block: +* If we've already successfully copied some data, then we +* can no longer safely return -EIOCBQUEUED. Hence mark +* an async read NOWAIT at that point. */ -if ((iocb->ki_flags &IOCB_WAITQ ) && - (written + orig_count -iov_iter_count (iter))) +if ((iocb->ki_flags &IOCB_WAITQ ) && written) iocb->ki_flags |=IOCB_NOWAIT ; - page =find_get_page (mapping, index); -if (!page) { -if (iocb->ki_flags &IOCB_NOIO ) - goto would_block; -page_cache_sync_readahead (mapping, - ra, filp, - index, last_index - index); - page =find_get_page (mapping, index); -if (unlikely (page ==NULL )) { - page =generic_file_buffered_read_no_cached_page (iocb, iter); -if (!page) - goto find_page; -if (IS_ERR (page)) { - error =PTR_ERR (page); - goto out; - } - } - } -if (PageReadahead (page)) { -if (iocb->ki_flags &IOCB_NOIO ) { -put_page (page); - goto out; - } -page_cache_async_readahead (mapping, - ra, filp, page, - index, last_index - index); - } -if (!PageUptodate (page)) { -if (iocb->ki_flags &IOCB_NOWAIT ) { -put_page (page); - error = -EAGAIN ; - goto out; - } - page =generic_file_buffered_read_pagenotuptodate (iocb, - filp, iter, page, iocb->ki_pos, iter->count); -if (!page) - goto find_page; -if (IS_ERR (page)) { - error =PTR_ERR (page); - goto out; - } + i =0 ; + pg_nr =generic_file_buffered_read_get_pages (iocb, iter, + pages, nr_pages); +if (pg_nr <0 ) { + error = pg_nr; +break ; } - error =generic_file_buffered_read_page_ok (iocb, iter, page); -put_page (page); +/* +* i_size must be checked after we know the pages are Uptodate. +* +* Checking i_size after the check allows us to calculate +* the correct value for "nr", which means the zero-filled +* part of the page is not copied back to userspace (unless +* another truncate extends the file - this is desired though). +*/ + isize =i_size_read (inode); +if (unlikely (iocb->ki_pos >= isize)) + goto put_pages; + + end_offset =min_t (loff_t, isize, iocb->ki_pos + iter->count); + +while ((iocb->ki_pos >>PAGE_SHIFT ) + pg_nr > + (end_offset +PAGE_SIZE -1 ) >>PAGE_SHIFT ) +put_page (pages[--pg_nr]); + +/* +* Once we start copying data, we don't want to be touching any +* cachelines that might be contended: +*/ + writably_mapped =mapping_writably_mapped (mapping); -if (error) { -if (error >0 ) - error =0 ; - goto out; +/* +* When a sequential read accesses a page several times, only +* mark it as accessed the first time. +*/ +if (iocb->ki_pos >>PAGE_SHIFT != + ra->prev_pos >>PAGE_SHIFT ) +mark_page_accessed (pages[0 ]); +for (i =1 ; i < pg_nr; i++) +mark_page_accessed (pages[i]); + +for (i =0 ; i < pg_nr; i++) { +unsigned int offset = iocb->ki_pos & ~PAGE_MASK ; +unsigned int bytes =min_t (loff_t, end_offset - iocb->ki_pos, +PAGE_SIZE - offset); +unsigned int copied; + +/* +* If users can be writing to this page using arbitrary +* virtual addresses, take care about potential aliasing +* before reading the page on the kernel side. +*/ +if (writably_mapped) +flush_dcache_page (pages[i]); + + copied =copy_page_to_iter (pages[i], offset, bytes, iter); + + written += copied; + iocb->ki_pos += copied; + ra->prev_pos = iocb->ki_pos; + +if (copied < bytes) { + error = -EFAULT ; +break ; + } } - } +put_pages: +for (i =0 ; i < pg_nr; i++) +put_page (pages[i]); + }while (iov_iter_count (iter) && iocb->ki_pos < isize && !error); -would_block: - error = -EAGAIN ; -out:file_accessed (filp); - written += orig_count -iov_iter_count (iter); + +if (pages != pages_onstack) +kfree (pages);return written ? written : error; }
_
Andrew Morton
maintainerPATCH 30/200 mm/truncate: add parameter explanation for invalidate_mapping_pagevec
In reply to Andrew MortonFrom: Alex Shi <[email protected]>
Subject: mm/truncate: add parameter explanation for invalidate_mapping_pagevec
To fix a kernel-doc markups issue:mm/truncate.c:646: warning: Function parameter or member 'mapping' not described in 'invalidate_mapping_pagevec' mm/truncate.c:646: warning: Function parameter or member 'start' not described in 'invalidate_mapping_pagevec' mm/truncate.c:646: warning: Function parameter or member 'end' not described in 'invalidate_mapping_pagevec' mm/truncate.c:646: warning: Function parameter or member 'nr_pagevec' not described in 'invalidate_mapping_pagevec'
---
mm/truncate.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
mm/truncate.c renamed from mm/truncate.c~mm-truncate-add-parameter-explanation-for-invalidate_mapping_pagevec +9 -3
@@ -637,9 +637,15 @@ unsigned long invalidate_mapping_pages(sEXPORT_SYMBOL (invalidate_mapping_pages);/** -* This helper is similar with the above one, except that it accounts for pages -* that are likely on a pagevec and count them in @nr_pagevec, which will used by -* the caller. +* invalidate_mapping_pagevec - Invalidate all the unlocked pages of one inode +* @mapping: the address_space which holds the pages to invalidate +* @start: the offset 'from' which to invalidate +* @end: the offset 'to' which to invalidate (inclusive) +* @nr_pagevec: invalidate failed page number for caller +* +* This helper is similar with invalidate_mapping_pages, except that it accounts +* for pages that failed to invalidate on a pagevec and count them in +* @nr_pagevec, which will used by the caller. */ void invalidate_mapping_pagevec (struct address_space *mapping,pgoff_t start,pgoff_t end,unsigned long *nr_pagevec)
_
Andrew Morton
maintainerPATCH 31/200 mm/filemap.c: remove else after a return
In reply to Andrew MortonFrom: Hailong Liu <[email protected]>
Subject: mm/filemap.c: remove else after a return
The else' is not useful after a return' in __lock_page_or_retry().
---
mm/filemap.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-)
mm/filemap.c renamed from mm/filemap.c~mm-remove-the-unuseful-else-after-a-return +12 -11
@@ -1583,19 +1583,20 @@ int __lock_page_or_retry(struct page *paelse wait_on_page_locked (page);return 0 ; - }else { -if (flags &FAULT_FLAG_KILLABLE ) { -int ret; + } +if (flags &FAULT_FLAG_KILLABLE ) { +int ret; - ret =__lock_page_killable (page); -if (ret) { -mmap_read_unlock (mm); -return 0 ; - } - }else -__lock_page (page); -return 1 ; + ret =__lock_page_killable (page); +if (ret) { +mmap_read_unlock (mm); +return 0 ; + } + }else { +__lock_page (page); } +return 1 ; + }/**
_
Andrew Morton
maintainerPATCH 32/200 mm/gup_benchmark: rename to mm/gup_test
In reply to Andrew MortonFrom: John Hubbard <[email protected]>
Subject: mm/gup_benchmark: rename to mm/gup_test
Patch series "selftests/vm: gup_test, hmm-tests, assorted improvements", v3.
Summary: This series provides two main things, and a number of smaller supporting goodies. The two main points are:
1) Add a new sub-test to gup_test, which in turn is a renamed version of gup_benchmark. This sub-test allows nicer testing of dump_pages(), at least on user-space pages.
For quite a while, I was doing a quick hack to gup_test.c whenever I wanted to try out changes to dump_page(). Then Matthew Wilcox asked me what I meant when I said "I used my dump_page() unit test", and I realized that it might be nice to check in a polished up version of that.
Details about how it works and how to use it are in the commit description for patch #6 ("selftests/vm: gup_test: introduce the dump_pages() sub-test").
2) Fixes a limitation of hmm-tests: these tests are incredibly useful, but only if people actually build and run them. And it turns out that libhugetlbfs is a little too effective at throwing a wrench in the works, there. So I've added a little configuration check that removes just two of the 21 hmm-tests, if libhugetlbfs is not available.
Further details in the commit description of patch #8 ("selftests/vm: hmm-tests: remove the libhugetlbfs dependency").
Other smaller things that this series does:
a) Remove code duplication by creating gup_test.h.
b) Clear up the sub-test organization, and their invocation within run_vmtests.sh.
c) Other minor assorted improvements.
[1] v2 is here:
https://lore.kernel.org/linux-doc/[email protected]/
[2] https://lore.kernel.org/r/CAHk-=wgh-TMPHLY3jueHX7Y2fWh3D+nMBqVS__AZm6-oorquWA@mail.gmail.com
This patch (of 9):
Rename nearly every "gup_benchmark" reference and file name to "gup_test". The one exception is for the actual gup benchmark test itself.
The current code already does a *little* bit more than benchmarking, and definitely covers more than get_user_pages_fast(). More importantly, however, subsequent patches are about to add some functionality that is non-benchmark related.
Closely related changes:
* Kconfig: in addition to renaming the options from GUP_BENCHMARK to GUP_TEST, update the help text to reflect that it's no longer a benchmark-only test.
---
Documentation/core-api/pin_user_pages.rst | 6 arch/s390/configs/debug_defconfig | 2 arch/s390/configs/defconfig | 2 mm/Kconfig | 15 - mm/Makefile | 2 mm/gup_benchmark.c | 210 ------------------- mm/gup_test.c | 210 +++++++++++++++++++ tools/testing/selftests/vm/.gitignore | 2 tools/testing/selftests/vm/Makefile | 2 tools/testing/selftests/vm/config | 2 tools/testing/selftests/vm/gup_benchmark.c | 143 ------------ tools/testing/selftests/vm/gup_test.c | 143 ++++++++++++ tools/testing/selftests/vm/run_vmtests | 8 13 files changed, 376 insertions(+), 371 deletions(-)
arch/s390/configs/debug_defconfig renamed from arch/s390/configs/debug_defconfig~mm-gup_benchmark-rename-to-mm-gup_test +1 -1
@@ -102,7 +102,7 @@ CONFIG_ZSMALLOC_STAT=y CONFIG_DEFERRED_STRUCT_PAGE_INIT=y CONFIG_IDLE_PAGE_TRACKING=y CONFIG_PERCPU_STATS=y -CONFIG_GUP_BENCHMARK=y +CONFIG_GUP_TEST=y CONFIG_NET=y CONFIG_PACKET=y CONFIG_PACKET_DIAG=m
arch/s390/configs/defconfig renamed from arch/s390/configs/defconfig~mm-gup_benchmark-rename-to-mm-gup_test +1 -1
@@ -95,7 +95,7 @@ CONFIG_ZSMALLOC_STAT=y CONFIG_DEFERRED_STRUCT_PAGE_INIT=y CONFIG_IDLE_PAGE_TRACKING=y CONFIG_PERCPU_STATS=y -CONFIG_GUP_BENCHMARK=y +CONFIG_GUP_TEST=y CONFIG_NET=y CONFIG_PACKET=y CONFIG_PACKET_DIAG=m
Documentation/core-api/pin_user_pages.rst renamed from Documentation/core-api/pin_user_pages.rst~mm-gup_benchmark-rename-to-mm-gup_test +3 -3
@@ -221,12 +221,12 @@ Unit testing ============ This file:: - tools/testing/selftests/vm/gup_benchmark.c + tools/testing/selftests/vm/gup_test.c has the following new calls to exercise the new pin*() wrapper functions: -* PIN_FAST_BENCHMARK (./gup_benchmark -a) -* PIN_BENCHMARK (./gup_benchmark -b) +* PIN_FAST_BENCHMARK (./gup_test -a) +* PIN_BENCHMARK (./gup_test -b) You can monitor how many total dma-pinned pages have been acquired and released since the system was booted, via two new /proc/vmstat entries: ::
mm/gup_benchmark.c deleted +0 -210
210 lines not on this page · raw message
mm/gup_test.c new file +210 -0
210 lines not on this page · raw message
mm/Kconfig renamed from mm/Kconfig~mm-gup_benchmark-rename-to-mm-gup_test +10 -5
@@ -821,13 +821,18 @@ config PERCPU_STATS information includes global and per chunk statistics, which can be used to help understand percpu memory usage. -config GUP_BENCHMARK - bool "Enable infrastructure for get_user_pages() and related calls benchmarking" +config GUP_TEST + bool "Enable infrastructure for get_user_pages()-related unit tests" help - Provides /sys/kernel/debug/gup_benchmark that helps with testing - performance of get_user_pages() and related calls. + Provides /sys/kernel/debug/gup_test, which in turn provides a way + to make ioctl calls that can launch kernel-based unit tests for + the get_user_pages*() and pin_user_pages*() family of API calls. - See tools/testing/selftests/vm/gup_benchmark.c + These tests include benchmark testing of the _fast variants of + get_user_pages*() and pin_user_pages*(), as well as smoke tests of + the non-_fast variants. + + See tools/testing/selftests/vm/gup_test.c config GUP_GET_PTE_LOW_HIGH bool
mm/Makefile renamed from mm/Makefile~mm-gup_benchmark-rename-to-mm-gup_test +1 -1
@@ -90,7 +90,7 @@ obj-$(CONFIG_PAGE_COUNTER) += page_count obj-$(CONFIG_MEMCG) += memcontrol.o vmpressure.o obj-$(CONFIG_MEMCG_SWAP) += swap_cgroup.o obj-$(CONFIG_CGROUP_HUGETLB) += hugetlb_cgroup.o -obj-$(CONFIG_GUP_BENCHMARK) += gup_benchmark.o +obj-$(CONFIG_GUP_TEST) += gup_test.o obj-$(CONFIG_MEMORY_FAILURE) += memory-failure.o obj-$(CONFIG_HWPOISON_INJECT) += hwpoison-inject.o obj-$(CONFIG_DEBUG_KMEMLEAK) += kmemleak.o
tools/testing/selftests/vm/config renamed from tools/testing/selftests/vm/config~mm-gup_benchmark-rename-to-mm-gup_test +1 -1
@@ -3,4 +3,4 @@ CONFIG_USERFAULTFD=y CONFIG_TEST_VMALLOC=m CONFIG_DEVICE_PRIVATE=y CONFIG_TEST_HMM=m -CONFIG_GUP_BENCHMARK=y +CONFIG_GUP_TEST=y
tools/testing/selftests/vm/.gitignore renamed from tools/testing/selftests/vm/.gitignore~mm-gup_benchmark-rename-to-mm-gup_test +1 -1
@@ -15,7 +15,7 @@ userfaultfd mlock-intersect-test mlock-random-test virtual_address_range -gup_benchmark +gup_test va_128TBswitch map_fixed_noreplace write_to_hugetlbfs
tools/testing/selftests/vm/gup_benchmark.c deleted +0 -143
143 lines not on this page · raw message
tools/testing/selftests/vm/gup_test.c new file +143 -0
143 lines not on this page · raw message
tools/testing/selftests/vm/Makefile renamed from tools/testing/selftests/vm/Makefile~mm-gup_benchmark-rename-to-mm-gup_test +1 -1
@@ -23,7 +23,7 @@ MAKEFLAGS += --no-builtin-rules CFLAGS = -Wall -I ../../../../usr/include $(EXTRA_CFLAGS) LDLIBS = -lrt TEST_GEN_FILES = compaction_test -TEST_GEN_FILES += gup_benchmark +TEST_GEN_FILES += gup_test TEST_GEN_FILES += hmm-tests TEST_GEN_FILES += hugepage-mmap TEST_GEN_FILES += hugepage-shm
tools/testing/selftests/vm/run_vmtests renamed from tools/testing/selftests/vm/run_vmtests~mm-gup_benchmark-rename-to-mm-gup_test +4 -4
@@ -124,9 +124,9 @@ else fi echo "--------------------------------------------" -echo "running 'gup_benchmark -U' (normal/slow gup)" +echo "running 'gup_test -U' (normal/slow gup)" echo "--------------------------------------------" -./gup_benchmark -U +./gup_test -U if [ $? -ne 0 ]; then echo "[FAIL]" exitcode=1
@@ -135,9 +135,9 @@ else fi echo "------------------------------------------" -echo "running gup_benchmark -b (pin_user_pages)" +echo "running gup_test -b (pin_user_pages)" echo "------------------------------------------" -./gup_benchmark -b +./gup_test -b if [ $? -ne 0 ]; then echo "[FAIL]" exitcode=1
_
Andrew Morton
maintainerPATCH 33/200 selftests/vm: use a common gup_test.h
In reply to Andrew MortonFrom: John Hubbard <[email protected]>
Subject: selftests/vm: use a common gup_test.h
Avoid the need to copy-paste the gup_test ioctl commands and the struct gup_test definition, between the kernel and the user space application, by providing a new header file for these. This allows easier and safer adding of new ioctl calls, as well as reducing the overall line count.
Details: The header file has to be able to compile independently, because of the arguably unfortunate way that the Makefile is written: the Makefile tries to build all of its prerequisites, when really it should be only building the .c files, and leaving the other prerequisites (LOCAL_HDRS) as pure dependencies.
That Makefile limitation is probably not worth fixing, but it explains why one of the includes had to be moved into the new header file.
Also: simplify the ioctl struct (struct gup_test), by deleting the unused __expansion[10] field. This sort of thing is what you might see in a stable ABI, but this low-level, kernel-developer-oriented selftests/vm system is very much not subject to ABI stability. So "expansion" and "reserved" fields are unnecessary here.
---
mm/gup_test.c | 17 +---------------- mm/gup_test.h | 22 ++++++++++++++++++++++ tools/testing/selftests/vm/Makefile | 2 ++ tools/testing/selftests/vm/gup_test.c | 22 +--------------------- 4 files changed, 26 insertions(+), 37 deletions(-)
mm/gup_test.c renamed from mm/gup_test.c~selftests-vm-use-a-common-gup_testh +1 -16
@@ -4,22 +4,7 @@#include <linux/uaccess.h> #include <linux/ktime.h> #include <linux/debugfs.h> - -#define GUP_FAST_BENCHMARK _IOWR('g', 1, struct gup_test) -#define GUP_BENCHMARK _IOWR('g', 2, struct gup_test) -#define PIN_FAST_BENCHMARK _IOWR('g', 3, struct gup_test) -#define PIN_BENCHMARK _IOWR('g', 4, struct gup_test) -#define PIN_LONGTERM_BENCHMARK _IOWR('g', 5, struct gup_test) - -struct gup_test { -__u64 get_delta_usec; -__u64 put_delta_usec; -__u64 addr; -__u64 size; -__u32 nr_pages_per_call; -__u32 flags; -__u64 expansion[10 ];/* For future use */ -}; +#include "gup_test.h" static void put_back_pages (unsigned int cmd,struct page **pages,unsigned long nr_pages)
mm/gup_test.h new file +22 -0
@@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#ifndef __GUP_TEST_H +#define __GUP_TEST_H + +#include <linux/types.h> + +#define GUP_FAST_BENCHMARK _IOWR('g', 1, struct gup_test) +#define GUP_BENCHMARK _IOWR('g', 2, struct gup_test) +#define PIN_FAST_BENCHMARK _IOWR('g', 3, struct gup_test) +#define PIN_BENCHMARK _IOWR('g', 4, struct gup_test) +#define PIN_LONGTERM_BENCHMARK _IOWR('g', 5, struct gup_test) + +struct gup_test { +__u64 get_delta_usec; +__u64 put_delta_usec; +__u64 addr; +__u64 size; +__u32 nr_pages_per_call; +__u32 flags; +}; + +#endif /* __GUP_TEST_H */
tools/testing/selftests/vm/gup_test.c renamed from tools/testing/selftests/vm/gup_test.c~selftests-vm-use-a-common-gup_testh +1 -21
@@ -2,39 +2,19 @@#include <stdio.h> #include <stdlib.h> #include <unistd.h> -#include <sys/ioctl.h> #include <sys/mman.h> #include <sys/prctl.h> #include <sys/stat.h> #include <sys/types.h> - -#include <linux/types.h> +#include "../../../../mm/gup_test.h" #define MB (1UL << 20)#define PAGE_SIZE sysconf(_SC_PAGESIZE) -#define GUP_FAST_BENCHMARK _IOWR('g', 1, struct gup_test) -#define GUP_BENCHMARK _IOWR('g', 2, struct gup_test) - -/* Similar to above, but use FOLL_PIN instead of FOLL_GET. */ -#define PIN_FAST_BENCHMARK _IOWR('g', 3, struct gup_test) -#define PIN_BENCHMARK _IOWR('g', 4, struct gup_test) -#define PIN_LONGTERM_BENCHMARK _IOWR('g', 5, struct gup_test) -/* Just the flags we need, copied from mm.h: */ #define FOLL_WRITE 0x01/* check pte is writable */ -struct gup_test { -__u64 get_delta_usec; -__u64 put_delta_usec; -__u64 addr; -__u64 size; -__u32 nr_pages_per_call; -__u32 flags; -__u64 expansion[10 ];/* For future use */ -}; -int main (int argc,char **argv) {struct gup_test gup;
tools/testing/selftests/vm/Makefile renamed from tools/testing/selftests/vm/Makefile~selftests-vm-use-a-common-gup_testh +2 -0
@@ -134,3 +134,5 @@ endif $(OUTPUT)/userfaultfd: LDLIBS += -lpthread $(OUTPUT)/mlock-random-test: LDLIBS += -lcap + +$(OUTPUT)/gup_test: ../../../../mm/gup_test.h
_
Andrew Morton
maintainerPATCH 34/200 selftests/vm: rename run_vmtests --> run_vmtests.sh
In reply to Andrew MortonFrom: John Hubbard <[email protected]>
Subject: selftests/vm: rename run_vmtests --> run_vmtests.sh
Rename to *.sh, in order to match the conventions of all of the other items in selftest/vm.
The only reason not to use a .sh suffix a shell script like this, might be to make it look more like a normal program, but that's not an issue here.
---
tools/testing/selftests/vm/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/vm/Makefile renamed from tools/testing/selftests/vm/Makefile~selftests-vm-rename-run_vmtests-run_vmtestssh +1 -1
@@ -73,7 +73,7 @@ TEST_GEN_FILES += virtual_address_range TEST_GEN_FILES += write_to_hugetlbfs endif -TEST_PROGS := run_vmtests +TEST_PROGS := run_vmtests.sh TEST_FILES := test_vmalloc.sh
_
Andrew Morton
maintainerPATCH 35/200 selftests/vm: minor cleanup: Makefile and gup_test.c
In reply to Andrew MortonFrom: John Hubbard <[email protected]>
Subject: selftests/vm: minor cleanup: Makefile and gup_test.c
A few cleanups that don't deserve separate patches, but that also should not clutter up other functional changes:
1. Remove an unnecessary #include <prctl.h>
2. Restore the sorted order of TEST_GEN_FILES.
3. Add -lpthread to the common LDLIBS, as it is harmless and several tests use it. This gets rid of one special rule already.
---
tools/testing/selftests/vm/Makefile | 10 ++++------ tools/testing/selftests/vm/gup_test.c | 1 - 2 files changed, 4 insertions(+), 7 deletions(-)
tools/testing/selftests/vm/gup_test.c renamed from tools/testing/selftests/vm/gup_test.c~selftests-vm-minor-cleanup-makefile-and-gup_testc +0 -1
@@ -4,7 +4,6 @@#include <unistd.h> #include <sys/ioctl.h> #include <sys/mman.h> -#include <sys/prctl.h> #include <sys/stat.h> #include <sys/types.h> #include "../../../../mm/gup_test.h"
tools/testing/selftests/vm/Makefile renamed from tools/testing/selftests/vm/Makefile~selftests-vm-minor-cleanup-makefile-and-gup_testc +4 -6
@@ -21,14 +21,15 @@ MACHINE ?= $(shell echo $(uname_M) | sed MAKEFLAGS += --no-builtin-rules CFLAGS = -Wall -I ../../../../usr/include $(EXTRA_CFLAGS) -LDLIBS = -lrt +LDLIBS = -lrt -lpthread TEST_GEN_FILES = compaction_test TEST_GEN_FILES += gup_test TEST_GEN_FILES += hmm-tests TEST_GEN_FILES += hugepage-mmap TEST_GEN_FILES += hugepage-shm -TEST_GEN_FILES += map_hugetlb +TEST_GEN_FILES += khugepaged TEST_GEN_FILES += map_fixed_noreplace +TEST_GEN_FILES += map_hugetlb TEST_GEN_FILES += map_populate TEST_GEN_FILES += mlock-random-test TEST_GEN_FILES += mlock2-tests
@@ -37,7 +38,6 @@ TEST_GEN_FILES += on-fault-limit TEST_GEN_FILES += thuge-gen TEST_GEN_FILES += transhuge-stress TEST_GEN_FILES += userfaultfd -TEST_GEN_FILES += khugepaged ifeq ($(ARCH),x86_64) CAN_BUILD_I386 := $(shell ./../x86/check_cc.sh $(CC) ../x86/trivial_32bit_program.c -m32)
@@ -80,7 +80,7 @@ TEST_FILES := test_vmalloc.sh KSFT_KHDR_INSTALL := 1 include ../lib.mk -$(OUTPUT)/hmm-tests: LDLIBS += -lhugetlbfs -lpthread +$(OUTPUT)/hmm-tests: LDLIBS += -lhugetlbfs ifeq ($(ARCH),x86_64) BINARIES_32 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_32))
@@ -131,8 +131,6 @@ warn_32bit_failure: endif endif -$(OUTPUT)/userfaultfd: LDLIBS += -lpthread - $(OUTPUT)/mlock-random-test: LDLIBS += -lcap $(OUTPUT)/gup_test: ../../../../mm/gup_test.h
_
Andrew Morton
maintainerPATCH 36/200 selftests/vm: only some gup_test items are really benchmarks
In reply to Andrew MortonFrom: John Hubbard <[email protected]>
Subject: selftests/vm: only some gup_test items are really benchmarks
Therefore, some minor cleanup and improvements are in order:
1. Rename the other items appropriately.
2. Stop reporting timing information on the non-benchmark items. It's still being recorded and is available, but there's no point in cluttering up the report with data that no one reasonably needs to check.
3. Don't do iterations, for non-benchmark items.
4. Print out a shorter, more appropriate report for the non-benchmark tests.
5. Add the command that was run, to the report. This really helps, as there are quite a lot of options now.
6. Use a larger integer type for cmd, now that it's being compared Otherwise it doesn't work, because in this case cmd is about 3 billion, which is the perfect size for problems with signed vs unsigned int.
---
Documentation/core-api/pin_user_pages.rst | 2 mm/gup_test.c | 14 ++--- mm/gup_test.h | 8 +-- tools/testing/selftests/vm/gup_test.c | 47 ++++++++++++++++---- 4 files changed, 51 insertions(+), 20 deletions(-)
Documentation/core-api/pin_user_pages.rst renamed from Documentation/core-api/pin_user_pages.rst~selftests-vm-only-some-gup_test-items-are-really-benchmarks +1 -1
@@ -226,7 +226,7 @@ This file:: has the following new calls to exercise the new pin*() wrapper functions: * PIN_FAST_BENCHMARK (./gup_test -a) -* PIN_BENCHMARK (./gup_test -b) +* PIN_BASIC_TEST (./gup_test -b) You can monitor how many total dma-pinned pages have been acquired and released since the system was booted, via two new /proc/vmstat entries: ::
mm/gup_test.c renamed from mm/gup_test.c~selftests-vm-only-some-gup_test-items-are-really-benchmarks +7 -7
@@ -13,13 +13,13 @@ static void put_back_pages(unsigned intswitch (cmd) {case GUP_FAST_BENCHMARK : -case GUP_BENCHMARK : +case GUP_BASIC_TEST :for (i =0 ; i < nr_pages; i++)put_page (pages[i]);break ;case PIN_FAST_BENCHMARK : -case PIN_BENCHMARK : +case PIN_BASIC_TEST :case PIN_LONGTERM_BENCHMARK :unpin_user_pages (pages, nr_pages);break ;
@@ -34,7 +34,7 @@ static void verify_dma_pinned(unsigned iswitch (cmd) {case PIN_FAST_BENCHMARK : -case PIN_BENCHMARK : +case PIN_BASIC_TEST :case PIN_LONGTERM_BENCHMARK :for (i =0 ; i < nr_pages; i++) { page = pages[i];
@@ -94,7 +94,7 @@ static int __gup_test_ioctl(unsigned int nr =get_user_pages_fast (addr, nr, gup->flags, pages + i);break ; -case GUP_BENCHMARK : +case GUP_BASIC_TEST : nr =get_user_pages (addr, nr, gup->flags, pages + i,NULL );break ;
@@ -102,7 +102,7 @@ static int __gup_test_ioctl(unsigned int nr =pin_user_pages_fast (addr, nr, gup->flags, pages + i);break ; -case PIN_BENCHMARK : +case PIN_BASIC_TEST : nr =pin_user_pages (addr, nr, gup->flags, pages + i,NULL );break ;
@@ -157,10 +157,10 @@ static long gup_test_ioctl(struct file *switch (cmd) {case GUP_FAST_BENCHMARK : -case GUP_BENCHMARK :case PIN_FAST_BENCHMARK : -case PIN_BENCHMARK :case PIN_LONGTERM_BENCHMARK : +case GUP_BASIC_TEST : +case PIN_BASIC_TEST :break ;default :return -EINVAL ;
mm/gup_test.h renamed from mm/gup_test.h~selftests-vm-only-some-gup_test-items-are-really-benchmarks +4 -4
@@ -5,10 +5,10 @@#include <linux/types.h> #define GUP_FAST_BENCHMARK _IOWR('g', 1, struct gup_test) -#define GUP_BENCHMARK _IOWR('g', 2, struct gup_test) -#define PIN_FAST_BENCHMARK _IOWR('g', 3, struct gup_test) -#define PIN_BENCHMARK _IOWR('g', 4, struct gup_test) -#define PIN_LONGTERM_BENCHMARK _IOWR('g', 5, struct gup_test) +#define PIN_FAST_BENCHMARK _IOWR('g', 2, struct gup_test) +#define PIN_LONGTERM_BENCHMARK _IOWR('g', 3, struct gup_test) +#define GUP_BASIC_TEST _IOWR('g', 4, struct gup_test) +#define PIN_BASIC_TEST _IOWR('g', 5, struct gup_test)struct gup_test {__u64 get_delta_usec;
tools/testing/selftests/vm/gup_test.c renamed from tools/testing/selftests/vm/gup_test.c~selftests-vm-only-some-gup_test-items-are-really-benchmarks +39 -8
83 lines not on this page · raw message
_
Andrew Morton
maintainerPATCH 37/200 selftests/vm: gup_test: introduce the dump_pages() sub-test
In reply to Andrew MortonFrom: John Hubbard <[email protected]>
Subject: selftests/vm: gup_test: introduce the dump_pages() sub-test
For quite a while, I was doing a quick hack to gup_test.c (previously, gup_benchmark.c) whenever I wanted to try out my changes to dump_page(). This makes that hack unnecessary, and instead allows anyone to easily get the same coverage from a user space program. That saves a lot of time because you don't have to change the kernel, in order to test different pages and options.
The new sub-test takes advantage of the existing gup_test infrastructure, which already provides a simple user space program, some allocated user space pages, an ioctl call, pinning of those pages (via either get_user_pages or pin_user_pages) and a corresponding kernel-side test invocation. There's not much more required, mainly just a couple of inputs from the user.
In fact, the new test re-uses the existing command line options in order to get various helpful combinations (THP or normal, _fast or slow gup, gup vs. pup, and more).
New command line options are: which pages to dump, and what type of "get/pin" to use.
In order to figure out which pages to dump, the logic is:
* If the user doesn't specify anything, the page 0 (the first page in the address range that the program sets up for testing) is dumped.
* Or, the user can type up to 8 page indices anywhere on the command line. If you type more than 8, then it uses the first 8 and ignores the remaining items.
For example:
./gup_test -ct -F 1 0 19 0x1000
Meaning:
-c: dump pages sub-test
-t: use THP pages
-F 1: use pin_user_pages() instead of get_user_pages()
0 19 0x1000: dump pages 0, 19, and 4096---
mm/Kconfig | 6 ++ mm/gup_test.c | 56 +++++++++++++++++++++++- mm/gup_test.h | 10 ++++ tools/testing/selftests/vm/gup_test.c | 45 ++++++++++++++++++- 4 files changed, 113 insertions(+), 4 deletions(-)
mm/gup_test.c renamed from mm/gup_test.c~selftests-vm-gup_test-introduce-the-dump_pages-sub-test +54 -2
@@ -7,7 +7,7 @@#include "gup_test.h" static void put_back_pages (unsigned int cmd,struct page **pages, -unsigned long nr_pages) +unsigned long nr_pages,unsigned int gup_test_flags) {unsigned long i;
@@ -23,6 +23,15 @@ static void put_back_pages(unsigned intcase PIN_LONGTERM_BENCHMARK :unpin_user_pages (pages, nr_pages);break ; +case DUMP_USER_PAGES_TEST : +if (gup_test_flags &GUP_TEST_FLAG_DUMP_PAGES_USE_PIN ) { +unpin_user_pages (pages, nr_pages); + }else { +for (i =0 ; i < nr_pages; i++) +put_page (pages[i]); + + } +break ; } }
@@ -49,6 +58,37 @@ static void verify_dma_pinned(unsigned i } } +static void dump_pages_test (struct gup_test *gup,struct page **pages, +unsigned long nr_pages) +{ +unsigned int index_to_dump; +unsigned int i; + +/* +* Zero out any user-supplied page index that is out of range. Remember: +* .which_pages[] contains a 1-based set of page indices. +*/ +for (i =0 ; i <GUP_TEST_MAX_PAGES_TO_DUMP ; i++) { +if (gup->which_pages[i] > nr_pages) { +pr_warn ("ZEROING due to out of range: .which_pages[%u]: %u\n" , + i, gup->which_pages[i]); + gup->which_pages[i] =0 ; + } + } + +for (i =0 ; i <GUP_TEST_MAX_PAGES_TO_DUMP ; i++) { + index_to_dump = gup->which_pages[i]; + +if (index_to_dump) { + index_to_dump--;// Decode from 1-based, to 0-based +pr_info ("---- page #%u, starting from user virt addr: 0x%llx\n" , + index_to_dump, gup->addr); +dump_page (pages[index_to_dump], +"gup_test: dump_pages() test" ); + } + } +} +static int __gup_test_ioctl (unsigned int cmd,struct gup_test *gup) {
@@ -111,6 +151,14 @@ static int __gup_test_ioctl(unsigned int gup->flags |FOLL_LONGTERM , pages + i, NULL);break ; +case DUMP_USER_PAGES_TEST : +if (gup->flags &GUP_TEST_FLAG_DUMP_PAGES_USE_PIN ) + nr =pin_user_pages (addr, nr, gup->flags, + pages + i,NULL ); +else + nr =get_user_pages (addr, nr, gup->flags, + pages + i,NULL ); +break ;default : ret = -EINVAL ; goto unlock;
@@ -134,9 +182,12 @@ static int __gup_test_ioctl(unsigned int*/ verify_dma_pinned (cmd, pages, nr_pages); +if (cmd ==DUMP_USER_PAGES_TEST ) +dump_pages_test (gup, pages, nr_pages); + start_time =ktime_get (); -put_back_pages (cmd, pages, nr_pages); +put_back_pages (cmd, pages, nr_pages, gup->flags); end_time =ktime_get (); gup->put_delta_usec =ktime_us_delta (end_time, start_time);
@@ -161,6 +212,7 @@ static long gup_test_ioctl(struct file *case PIN_LONGTERM_BENCHMARK :case GUP_BASIC_TEST :case PIN_BASIC_TEST : +case DUMP_USER_PAGES_TEST :break ;default :return -EINVAL ;
mm/gup_test.h renamed from mm/gup_test.h~selftests-vm-gup_test-introduce-the-dump_pages-sub-test +10 -0
@@ -9,6 +9,11 @@#define PIN_LONGTERM_BENCHMARK _IOWR('g', 3, struct gup_test)#define GUP_BASIC_TEST _IOWR('g', 4, struct gup_test)#define PIN_BASIC_TEST _IOWR('g', 5, struct gup_test) +#define DUMP_USER_PAGES_TEST _IOWR('g', 6, struct gup_test) + +#define GUP_TEST_MAX_PAGES_TO_DUMP 8 + +#define GUP_TEST_FLAG_DUMP_PAGES_USE_PIN 0x1struct gup_test {__u64 get_delta_usec;
@@ -17,6 +22,11 @@ struct gup_test {__u64 size;__u32 nr_pages_per_call;__u32 flags; +/* +* Each non-zero entry is the number of the page (1-based: first page is +* page 1, so that zero entries mean "do nothing") from the .addr base. +*/ + __u32 which_pages[GUP_TEST_MAX_PAGES_TO_DUMP]; };#endif /* __GUP_TEST_H */
mm/Kconfig renamed from mm/Kconfig~selftests-vm-gup_test-introduce-the-dump_pages-sub-test +6 -0
@@ -832,6 +832,12 @@ config GUP_TEST get_user_pages*() and pin_user_pages*(), as well as smoke tests of the non-_fast variants. + There is also a sub-test that allows running dump_page() on any + of up to eight pages (selected by command line args) within the + range of user-space addresses. These pages are either pinned via + pin_user_pages*(), or pinned via get_user_pages*(), as specified + by other command line arguments. + See tools/testing/selftests/vm/gup_test.c config GUP_GET_PTE_LOW_HIGH
tools/testing/selftests/vm/gup_test.c renamed from tools/testing/selftests/vm/gup_test.c~selftests-vm-gup_test-introduce-the-dump_pages-sub-test +43 -2
75 lines not on this page · raw message
_
Andrew Morton
maintainerPATCH 38/200 selftests/vm: run_vmtests.sh: update and clean up gup_test invocation
In reply to Andrew MortonFrom: John Hubbard <[email protected]>
Subject: selftests/vm: run_vmtests.sh: update and clean up gup_test invocation
Run benchmarks on the _fast variants of gup and pup, as originally intended.
Run the new gup_test sub-test: dump pages. In addition to exercising the dump_page() call, it also demonstrates the various options you can use to specify which pages to dump, and how.
---
tools/testing/selftests/vm/run_vmtests | 28 ++++++++++++++++------- 1 file changed, 20 insertions(+), 8 deletions(-)
tools/testing/selftests/vm/run_vmtests renamed from tools/testing/selftests/vm/run_vmtests~selftests-vm-run_vmtestssh-update-and-clean-up-gup_test-invocation +20 -8
@@ -123,10 +123,10 @@ else echo "[PASS]" fi -echo "--------------------------------------------" -echo "running 'gup_test -U' (normal/slow gup)" -echo "--------------------------------------------" -./gup_test -U +echo "------------------------------------------------------" +echo "running: gup_test -u # get_user_pages_fast() benchmark" +echo "------------------------------------------------------" +./gup_test -u if [ $? -ne 0 ]; then echo "[FAIL]" exitcode=1
@@ -134,10 +134,22 @@ else echo "[PASS]" fi -echo "------------------------------------------" -echo "running gup_test -b (pin_user_pages)" -echo "------------------------------------------" -./gup_test -b +echo "------------------------------------------------------" +echo "running: gup_test -a # pin_user_pages_fast() benchmark" +echo "------------------------------------------------------" +./gup_test -a +if [ $? -ne 0 ]; then + echo "[FAIL]" + exitcode=1 +else + echo "[PASS]" +fi + +echo "------------------------------------------------------------" +echo "# Dump pages 0, 19, and 4096, using pin_user_pages:" +echo "running: gup_test -ct -F 0x1 0 19 0x1000 # dump_page() test" +echo "------------------------------------------------------------" +./gup_test -ct -F 0x1 0 19 0x1000 if [ $? -ne 0 ]; then echo "[FAIL]" exitcode=1
_
Andrew Morton
maintainerPATCH 39/200 selftests/vm: hmm-tests: remove the libhugetlbfs dependency
In reply to Andrew MortonFrom: John Hubbard <[email protected]>
Subject: selftests/vm: hmm-tests: remove the libhugetlbfs dependency
HMM selftests are incredibly useful, but they are only effective if people actually build and run them. All the other tests in selftests/vm can be built with very standard, always-available libraries: libpthread, librt. The hmm-tests.c program, on the other hand, requires something that is (much) less readily available: libhugetlbfs. And so the build will typically fail for many developers.
A simple attempt to install libhugetlbfs will also run into complications on some common distros these days: Fedora and Arch Linux (yes, Arch AUR has it, but that's fragile, as always with AUR). The library is not maintained actively enough at the moment, for distros to deal with it. I had to build it from source, for Fedora, and that didn't go too smoothly either.
It turns out that, out of 21 tests in hmm-tests.c, only 2 actually require functionality from libhugetlbfs. Therefore, if libhugetlbfs is missing, simply ifdef those two tests out and allow the developer to at least have the other 19 tests, if they don't want to pause to work through the above issues. Also issue a warning, so that it's clear that there is an imperfection in the build.
In order to do that, a tiny shell script (check_config.sh) runs a quick compile (not link, that's too prone to false failures with library paths), and basically, if the compiler doesn't find hugetlbfs.h in its standard locations, then the script concludes that libhugetlbfs is not available. The output is in two files, one for inclusion in hmm-test.c (local_config.h), and one for inclusion in the Makefile (local_config.mk).
---
tools/testing/selftests/vm/.gitignore | 1 tools/testing/selftests/vm/Makefile | 24 +++++++++++++- tools/testing/selftests/vm/check_config.sh | 31 +++++++++++++++++++ tools/testing/selftests/vm/hmm-tests.c | 10 +++++- 4 files changed, 63 insertions(+), 3 deletions(-)
tools/testing/selftests/vm/check_config.sh new file +31 -0
@@ -0,0 +1,31 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 +# +# Probe for libraries and create header files to record the results. Both C +# header files and Makefile include fragments are created. + +OUTPUT_H_FILE=local_config.h +OUTPUT_MKFILE=local_config.mk + +# libhugetlbfs +tmpname=$(mktemp) +tmpfile_c=${tmpname}.c +tmpfile_o=${tmpname}.o + +echo "#include <sys/types.h>" > $tmpfile_c +echo "#include <hugetlbfs.h>" >> $tmpfile_c +echo "int func(void) { return 0; }" >> $tmpfile_c + +CC=${1:?"Usage: $0 <compiler> # example compiler: gcc"} +$CC -c $tmpfile_c -o $tmpfile_o >/dev/null 2>&1 + +if [ -f $tmpfile_o ]; then + echo "#define LOCAL_CONFIG_HAVE_LIBHUGETLBFS 1" > $OUTPUT_H_FILE + echo "HMM_EXTRA_LIBS = -lhugetlbfs" > $OUTPUT_MKFILE +else + echo "// No libhugetlbfs support found" > $OUTPUT_H_FILE + echo "# No libhugetlbfs support found, so:" > $OUTPUT_MKFILE + echo "HMM_EXTRA_LIBS = " >> $OUTPUT_MKFILE +fi + +rm ${tmpname}.*
tools/testing/selftests/vm/.gitignore renamed from tools/testing/selftests/vm/.gitignore~selftests-vm-hmm-tests-remove-the-libhugetlbfs-dependency +1 -0
@@ -20,3 +20,4 @@ va_128TBswitch map_fixed_noreplace write_to_hugetlbfs hmm-tests +local_config.*
tools/testing/selftests/vm/hmm-tests.c renamed from tools/testing/selftests/vm/hmm-tests.c~selftests-vm-hmm-tests-remove-the-libhugetlbfs-dependency +9 -1
@@ -21,12 +21,16 @@#include <strings.h> #include <time.h> #include <pthread.h> -#include <hugetlbfs.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/mman.h> #include <sys/ioctl.h> +#include "./local_config.h" +#ifdef LOCAL_CONFIG_HAVE_LIBHUGETLBFS +#include <hugetlbfs.h> +#endif +/* * This is a private UAPI to the kernel test module so it isn't exported * in the usual include/uapi/... directory.
@@ -662,6 +666,7 @@ TEST_F(hmm, anon_write_huge)hmm_buffer_free (buffer); } +#ifdef LOCAL_CONFIG_HAVE_LIBHUGETLBFS /* * Write huge TLBFS page. */
@@ -720,6 +725,7 @@ TEST_F(hmm, anon_write_hugetlbfs) buffer->ptr =NULL ; hmm_buffer_free(buffer); } +#endif /* LOCAL_CONFIG_HAVE_LIBHUGETLBFS */ /* * Read mmap'ed file memory.
@@ -1336,6 +1342,7 @@ TEST_F(hmm2, snapshot)hmm_buffer_free (buffer); } +#ifdef LOCAL_CONFIG_HAVE_LIBHUGETLBFS /* * Test the hmm_range_fault() HMM_PFN_PMD flag for large pages that * should be mapped by a large page table entry.
@@ -1411,6 +1418,7 @@ TEST_F(hmm, compound) buffer->ptr =NULL ; hmm_buffer_free(buffer); } +#endif /* LOCAL_CONFIG_HAVE_LIBHUGETLBFS */ /* * Test two devices reading the same memory (double mapped).
tools/testing/selftests/vm/Makefile renamed from tools/testing/selftests/vm/Makefile~selftests-vm-hmm-tests-remove-the-libhugetlbfs-dependency +22 -2
@@ -1,5 +1,8 @@ # SPDX-License-Identifier: GPL-2.0 # Makefile for vm selftests + +include local_config.mk + uname_M := $(shell uname -m 2>/dev/null || echo not) MACHINE ?= $(shell echo $(uname_M) | sed -e 's/aarch64.*/arm64/')
@@ -80,8 +83,6 @@ TEST_FILES := test_vmalloc.sh KSFT_KHDR_INSTALL := 1 include ../lib.mk -$(OUTPUT)/hmm-tests: LDLIBS += -lhugetlbfs - ifeq ($(ARCH),x86_64) BINARIES_32 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_32)) BINARIES_64 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_64))
@@ -134,3 +135,22 @@ endif $(OUTPUT)/mlock-random-test: LDLIBS += -lcap $(OUTPUT)/gup_test: ../../../../mm/gup_test.h + +$(OUTPUT)/hmm-tests: local_config.h + +# HMM_EXTRA_LIBS may get set in local_config.mk, or it may be left empty. +$(OUTPUT)/hmm-tests: LDLIBS += $(HMM_EXTRA_LIBS) + +local_config.mk local_config.h: check_config.sh + /bin/sh ./check_config.sh $(CC) + +EXTRA_CLEAN += local_config.mk local_config.h + +ifeq ($(HMM_EXTRA_LIBS),) +all: warn_missing_hugelibs + +warn_missing_hugelibs: + @echo ; \ + echo "Warning: missing libhugetlbfs support. Some HMM tests will be skipped." ; \ + echo +endif
_
Andrew Morton
maintainerPATCH 40/200 selftests/vm: 2x speedup for run_vmtests.sh
In reply to Andrew MortonFrom: John Hubbard <[email protected]>
Subject: selftests/vm: 2x speedup for run_vmtests.sh
Each invocation of userfaultfd for "anon" and "shmem" was taking about 6.5 sec to run, contributing to an overall run time of about 22 sec for run_vmtests.sh.
Reduce the size and bounce input values to the userfaultfd invocation within run_vmtests.sh, enough to get each invocation down to about 1.0 sec. This should still provide a reasonable smoke test, while staying within a nominal time budget of around 1 second or so per test. And this brings the overall running time of run_vmtests.sh down to 11 second.
---
tools/testing/selftests/vm/run_vmtests | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/vm/run_vmtests renamed from tools/testing/selftests/vm/run_vmtests~selftests-vm-2x-speedup-for-run_vmtestssh +2 -2
@@ -160,7 +160,7 @@ fi echo "-------------------" echo "running userfaultfd" echo "-------------------" -./userfaultfd anon 128 32 +./userfaultfd anon 20 16 if [ $? -ne 0 ]; then echo "[FAIL]" exitcode=1
@@ -185,7 +185,7 @@ rm -f $mnt/ufd_test_file echo "-------------------------" echo "running userfaultfd_shmem" echo "-------------------------" -./userfaultfd shmem 128 32 +./userfaultfd shmem 20 16 if [ $? -ne 0 ]; then echo "[FAIL]" exitcode=1
_
Andrew Morton
maintainerPATCH 41/200 mm/gup_test.c: mark gup_test_init as __init function
In reply to Andrew MortonFrom: Barry Song <[email protected]>
Subject: mm/gup_test.c: mark gup_test_init as __init function
gup_test_init() is only called during initialization, mark it as __init to save some memory.
---
mm/gup_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/gup_test.c renamed from mm/gup_test.c~mm-gup_benchmark-mark-gup_benchmark_init-as-__init-function +1 -1
@@ -236,7 +236,7 @@ static const struct file_operations gup_ .unlocked_ioctl = gup_test_ioctl, }; -static int gup_test_init (void ) +static int __init gup_test_init (void ) {debugfs_create_file_unsafe ("gup_test" ,0600 ,NULL ,NULL , &gup_test_fops);
_
Andrew Morton
maintainerPATCH 42/200 mm/gup_test: GUP_TEST depends on DEBUG_FS
In reply to Andrew MortonFrom: Barry Song <[email protected]>
Subject: mm/gup_test: GUP_TEST depends on DEBUG_FS
Without DEBUG_FS, all the code in gup_benchmark becomes meaningless. For sure kernel provides debugfs stub while DEBUG_FS is disabled, but the point here is that GUP_TEST can do nothing without DEBUG_FS.
---
mm/Kconfig | 4 ++++ 1 file changed, 4 insertions(+)
mm/Kconfig renamed from mm/Kconfig~mm-gup_benchmark-gup_benchmark-depends-on-debug_fs +4 -0
@@ -823,6 +823,7 @@ config PERCPU_STATS config GUP_TEST bool "Enable infrastructure for get_user_pages()-related unit tests" + depends on DEBUG_FS help Provides /sys/kernel/debug/gup_test, which in turn provides a way to make ioctl calls that can launch kernel-based unit tests for
@@ -840,6 +841,9 @@ config GUP_TEST See tools/testing/selftests/vm/gup_test.c +comment "GUP_TEST needs to have DEBUG_FS enabled" + depends on !GUP_TEST && !DEBUG_FS + config GUP_GET_PTE_LOW_HIGH bool
_
Andrew Morton
maintainerPATCH 43/200 mm/gup: reorganize internal_get_user_pages_fast()
In reply to Andrew MortonFrom: Jason Gunthorpe <[email protected]>
Subject: mm/gup: reorganize internal_get_user_pages_fast()
Patch series "Add a seqcount between gup_fast and copy_page_range()", v4.
As discussed and suggested by Linus use a seqcount to close the small race between gup_fast and copy_page_range().
Ahmed confirms that raw_write_seqcount_begin() is the correct API to use in this case and it doesn't trigger any lockdeps.
I was able to test it using two threads, one forking and the other using ibv_reg_mr() to trigger GUP fast. Modifying copy_page_range() to sleep made the window large enough to reliably hit to test the logic.
This patch (of 2):
The next patch in this series makes the lockless flow a little more complex, so move the entire block into a new function and remove a level of indention. Tidy a bit of cruft:
- addr is always the same as start, so use start
- Use the modern check_add_overflow() for computing end = start + len
- nr_pinned/pages << PAGE_SHIFT needs the LHS to be unsigned long to avoid shift overflow, make the variables unsigned long to avoid coding casts in both places. nr_pinned was missing its cast
- The handling of ret and nr_pinned can be streamlined a bit
No functional change.
---
mm/gup.c | 101 ++++++++++++++++++++++++++++------------------------- 1 file changed, 55 insertions(+), 46 deletions(-)
mm/gup.c renamed from mm/gup.c~mm-reorganize-internal_get_user_pages_fast +55 -46
@@ -2677,13 +2677,43 @@ static int __gup_longterm_unlocked(unsigreturn ret; } -static int internal_get_user_pages_fast (unsigned long start,int nr_pages, +static unsigned long lockless_pages_from_mm (unsigned long start, +unsigned long end, +unsigned int gup_flags, +struct page **pages) +{ +unsigned long flags; +int nr_pinned =0 ; + +if (!IS_ENABLED (CONFIG_HAVE_FAST_GUP ) || + !gup_fast_permitted (start, end)) +return 0 ; + +/* +* Disable interrupts. The nested form is used, in order to allow full, +* general purpose use of this routine. +* +* With interrupts disabled, we block page table pages from being freed +* from under us. See struct mmu_table_batch comments in +* include/asm-generic/tlb.h for more details. +* +* We do not adopt an rcu_read_lock() here as we also want to block IPIs +* that come from THPs splitting. +*/ +local_irq_save (flags); +gup_pgd_range (start, end, gup_flags, pages, &nr_pinned); +local_irq_restore (flags); +return nr_pinned; +} + +static int internal_get_user_pages_fast (unsigned long start, +unsigned long nr_pages,unsigned int gup_flags,struct page **pages) { -unsigned long addr, len, end; -unsigned long flags; -int nr_pinned =0 , ret =0 ; +unsigned long len, end; +unsigned long nr_pinned; +int ret; if (WARN_ON_ONCE(gup_flags & ~(FOLL_WRITE | FOLL_LONGTERM | FOLL_FORCE | FOLL_PIN | FOLL_GET |
@@ -2697,54 +2727,33 @@ static int internal_get_user_pages_fast(might_lock_read (¤t->mm->mmap_lock); start =untagged_addr (start) &PAGE_MASK ; - addr = start; - len = (unsigned long ) nr_pages <<PAGE_SHIFT ; - end = start + len; - -if (end <= start) + len = nr_pages <<PAGE_SHIFT ; +if (check_add_overflow (start, len, &end))return 0 ;if (unlikely (!access_ok ((void __user *)start, len)))return -EFAULT ; -/* -* Disable interrupts. The nested form is used, in order to allow -* full, general purpose use of this routine. -* -* With interrupts disabled, we block page table pages from being -* freed from under us. See struct mmu_table_batch comments in -* include/asm-generic/tlb.h for more details. -* -* We do not adopt an rcu_read_lock(.) here as we also want to -* block IPIs that come from THPs splitting. -*/ -if (IS_ENABLED (CONFIG_HAVE_FAST_GUP ) &&gup_fast_permitted (start, end)) { -unsigned long fast_flags = gup_flags; - -local_irq_save (flags); -gup_pgd_range (addr, end, fast_flags, pages, &nr_pinned); -local_irq_restore (flags); - ret = nr_pinned; - } - -if (nr_pinned < nr_pages && !(gup_flags &FOLL_FAST_ONLY )) { -/* Try to get the remaining pages with get_user_pages */ - start += nr_pinned <<PAGE_SHIFT ; - pages += nr_pinned; - - ret =__gup_longterm_unlocked (start, nr_pages - nr_pinned, - gup_flags, pages); - -/* Have to be a bit careful with return values */ -if (nr_pinned >0 ) { -if (ret <0 ) - ret = nr_pinned; -else - ret += nr_pinned; - } + nr_pinned =lockless_pages_from_mm (start, end, gup_flags, pages); +if (nr_pinned == nr_pages || gup_flags &FOLL_FAST_ONLY ) +return nr_pinned; + +/* Slow path: try to get the remaining pages with get_user_pages */ + start += nr_pinned <<PAGE_SHIFT ; + pages += nr_pinned; + ret =__gup_longterm_unlocked (start, nr_pages - nr_pinned, gup_flags, + pages); +if (ret <0 ) { +/* +* The caller has to unpin the pages we already pinned so +* returning -errno is not an option +*/ +if (nr_pinned) +return nr_pinned; +return ret; } - -return ret; +return ret + nr_pinned; } +/** * get_user_pages_fast_only() - pin user pages in memory * @start: starting user address
_
Andrew Morton
maintainerPATCH 44/200 mm/gup: prevent gup_fast from racing with COW during fork
In reply to Andrew MortonFrom: Jason Gunthorpe <[email protected]>
Subject: mm/gup: prevent gup_fast from racing with COW during fork
Since commit 70e806e4e645 ("mm: Do early cow for pinned pages during fork() for ptes") pages under a FOLL_PIN will not be write protected during COW for fork. This means that pages returned from pin_user_pages(FOLL_WRITE) should not become write protected while the pin is active.
However, there is a small race where get_user_pages_fast(FOLL_PIN) can establish a FOLL_PIN at the same time copy_present_page() is write protecting it:
CPU 0 CPU 1
get_user_pages_fast()
internal_get_user_pages_fast()
copy_page_range()
pte_alloc_map_lock()
copy_present_page()
atomic_read(has_pinned) == 0
page_maybe_dma_pinned() == false
atomic_set(has_pinned, 1);
gup_pgd_range()
gup_pte_range()
pte_t pte = gup_get_pte(ptep)
pte_access_permitted(pte)
try_grab_compound_head()
pte = pte_wrprotect(pte)
set_pte_at();
pte_unmap_unlock()
// GUP now returns with a write protected pageThe first attempt to resolve this by using the write protect caused problems (and was missing a barrrier), see commit f3c64eda3e50 ("mm: avoid early COW write protect games during fork()")
Instead wrap copy_p4d_range() with the write side of a seqcount and check the read side around gup_pgd_range(). If there is a collision then get_user_pages_fast() fails and falls back to slow GUP.
Slow GUP is safe against this race because copy_page_range() is only called while holding the exclusive side of the mmap_lock on the src mm_struct.
---
arch/x86/kernel/tboot.c | 1 + drivers/firmware/efi/efi.c | 1 + include/linux/mm_types.h | 8 ++++++++ kernel/fork.c | 1 + mm/gup.c | 18 ++++++++++++++++++ mm/init-mm.c | 1 + mm/memory.c | 13 ++++++++++++- 7 files changed, 42 insertions(+), 1 deletion(-)
arch/x86/kernel/tboot.c renamed from arch/x86/kernel/tboot.c~mm-prevent-gup_fast-from-racing-with-cow-during-fork +1 -0
@@ -93,6 +93,7 @@ static struct mm_struct tboot_mm = { .pgd = swapper_pg_dir, .mm_users = ATOMIC_INIT(2), .mm_count = ATOMIC_INIT(1), + .write_protect_seq =SEQCNT_ZERO (tboot_mm.write_protect_seq),MMAP_LOCK_INITIALIZER (init_mm) .page_table_lock =__SPIN_LOCK_UNLOCKED (init_mm.page_table_lock), .mmlist = LIST_HEAD_INIT(init_mm.mmlist),
drivers/firmware/efi/efi.c renamed from drivers/firmware/efi/efi.c~mm-prevent-gup_fast-from-racing-with-cow-during-fork +1 -0
@@ -57,6 +57,7 @@ struct mm_struct efi_mm = { .mm_rb = RB_ROOT, .mm_users = ATOMIC_INIT(2), .mm_count = ATOMIC_INIT(1), + .write_protect_seq =SEQCNT_ZERO (efi_mm.write_protect_seq),MMAP_LOCK_INITIALIZER (efi_mm) .page_table_lock =__SPIN_LOCK_UNLOCKED (efi_mm.page_table_lock), .mmlist = LIST_HEAD_INIT(efi_mm.mmlist),
include/linux/mm_types.h renamed from include/linux/mm_types.h~mm-prevent-gup_fast-from-racing-with-cow-during-fork +8 -0
@@ -14,6 +14,7 @@#include <linux/uprobes.h> #include <linux/page-flags-layout.h> #include <linux/workqueue.h> +#include <linux/seqlock.h> #include <asm/mmu.h>
@@ -446,6 +447,13 @@ struct mm_struct {*/ atomic_t has_pinned; +/** +* @write_protect_seq: Locked when any thread is write +* protecting pages mapped by this mm to enforce a later COW, +* for instance during page table copying for fork(). +*/ +seqcount_t write_protect_seq; +#ifdef CONFIG_MMU atomic_long_t pgtables_bytes;/* PTE page table pages */ #endif
kernel/fork.c renamed from kernel/fork.c~mm-prevent-gup_fast-from-racing-with-cow-during-fork +1 -0
@@ -1007,6 +1007,7 @@ static struct mm_struct *mm_init(struct mm->vmacache_seqnum =0 ;atomic_set (&mm->mm_users,1 );atomic_set (&mm->mm_count,1 ); +seqcount_init (&mm->write_protect_seq);mmap_init_lock (mm);INIT_LIST_HEAD (&mm->mmlist); mm->core_state =NULL ;
mm/gup.c renamed from mm/gup.c~mm-prevent-gup_fast-from-racing-with-cow-during-fork +18 -0
@@ -2684,11 +2684,18 @@ static unsigned long lockless_pages_from {unsigned long flags;int nr_pinned =0 ; +unsigned seq;if (!IS_ENABLED (CONFIG_HAVE_FAST_GUP ) || !gup_fast_permitted (start, end))return 0 ; +if (gup_flags &FOLL_PIN ) { + seq =raw_read_seqcount (¤t->mm->write_protect_seq); +if (seq &1 ) +return 0 ; + } +/* * Disable interrupts. The nested form is used, in order to allow full, * general purpose use of this routine.
@@ -2703,6 +2710,17 @@ static unsigned long lockless_pages_fromlocal_irq_save (flags);gup_pgd_range (start, end, gup_flags, pages, &nr_pinned);local_irq_restore (flags); + +/* +* When pinning pages for DMA there could be a concurrent write protect +* from fork() via copy_page_range(), in this case always fail fast GUP. +*/ +if (gup_flags &FOLL_PIN ) { +if (read_seqcount_retry (¤t->mm->write_protect_seq, seq)) { +unpin_user_pages (pages, nr_pinned); +return 0 ; + } + }return nr_pinned; }
mm/init-mm.c renamed from mm/init-mm.c~mm-prevent-gup_fast-from-racing-with-cow-during-fork +1 -0
@@ -31,6 +31,7 @@ struct mm_struct init_mm = { .pgd = swapper_pg_dir, .mm_users = ATOMIC_INIT(2), .mm_count = ATOMIC_INIT(1), + .write_protect_seq =SEQCNT_ZERO (init_mm.write_protect_seq),MMAP_LOCK_INITIALIZER (init_mm) .page_table_lock =__SPIN_LOCK_UNLOCKED (init_mm.page_table_lock), .arg_lock = __SPIN_LOCK_UNLOCKED(init_mm.arg_lock),
mm/memory.c renamed from mm/memory.c~mm-prevent-gup_fast-from-racing-with-cow-during-fork +12 -1
@@ -1171,6 +1171,15 @@ copy_page_range(struct vm_area_struct *dmmu_notifier_range_init (&range,MMU_NOTIFY_PROTECTION_PAGE ,0 , src_vma, src_mm, addr, end);mmu_notifier_invalidate_range_start (&range); +/* +* Disabling preemption is not needed for the write side, as +* the read side doesn't spin, but goes to the mmap_lock. +* +* Use the raw variant of the seqcount_t write API to avoid +* lockdep complaining about preemptibility. +*/ +mmap_assert_write_locked (src_mm); +raw_write_seqcount_begin (&src_mm->write_protect_seq); } ret =0 ;
@@ -1187,8 +1196,10 @@ copy_page_range(struct vm_area_struct *d } }while (dst_pgd++, src_pgd++, addr = next, addr != end); -if (is_cow) +if (is_cow) { +raw_write_seqcount_end (&src_mm->write_protect_seq);mmu_notifier_invalidate_range_end (&range); + }return ret; }
_
Andrew Morton
maintainerPATCH 45/200 mm/gup: remove the vma allocation from gup_longterm_locked()
In reply to Andrew MortonFrom: Jason Gunthorpe <[email protected]>
Subject: mm/gup: remove the vma allocation from gup_longterm_locked()
Long ago there wasn't a FOLL_LONGTERM flag so this DAX check was done by post-processing the VMA list.
These days it is trivial to just check each VMA to see if it is DAX before processing it inside __get_user_pages() and return failure if a DAX VMA is encountered with FOLL_LONGTERM.
Removing the allocation of the VMA list is a significant speed up for many call sites.
Add an IS_ENABLED to vma_is_fsdax so that code generation is unchanged when DAX is compiled out.
Remove the dummy version of __gup_longterm_locked() as !CONFIG_CMA already makes memalloc_nocma_save(), check_and_migrate_cma_pages(), and memalloc_nocma_restore() into a NOP.
---
include/linux/fs.h | 2 - mm/gup.c | 83 +++++++------------------------------------ 2 files changed, 16 insertions(+), 69 deletions(-)
include/linux/fs.h renamed from include/linux/fs.h~mm-gup-remove-the-vma-allocation-from-gup_longterm_locked +1 -1
@@ -3230,7 +3230,7 @@ static inline bool vma_is_fsdax(struct v {struct inode *inode; -if (!vma->vm_file) +if (!IS_ENABLED (CONFIG_FS_DAX ) || !vma->vm_file)return false;if (!vma_is_dax (vma))return false;
mm/gup.c renamed from mm/gup.c~mm-gup-remove-the-vma-allocation-from-gup_longterm_locked +15 -68
120 lines not on this page · raw message
_
Andrew Morton
maintainerPATCH 46/200 mm/gup: combine put_compound_head() and unpin_user_page()
In reply to Andrew MortonFrom: Jason Gunthorpe <[email protected]>
Subject: mm/gup: combine put_compound_head() and unpin_user_page()
These functions accomplish the same thing but have different implementations.
unpin_user_page() has a bug where it calls mod_node_page_state() after calling put_page() which creates a risk that the page could have been hot-uplugged from the system.
Fix this by using put_compound_head() as the only implementation.
__unpin_devmap_managed_user_page() and related can be deleted as well in favour of the simpler, but slower, version in put_compound_head() that has an extra atomic page_ref_sub, but always calls put_page() which internally contains the special devmap code.
Move put_compound_head() to be directly after try_grab_compound_head() so people can find it in future.
---
mm/gup.c | 103 +++++++++++------------------------------------------ 1 file changed, 23 insertions(+), 80 deletions(-)
mm/gup.c renamed from mm/gup.c~mm-up-combine-put_compound_head-and-unpin_user_page +23 -80
@@ -123,6 +123,28 @@ static __maybe_unused struct page *try_greturn NULL ; } +static void put_compound_head (struct page *page,int refs,unsigned int flags) +{ +if (flags &FOLL_PIN ) { +mod_node_page_state (page_pgdat (page),NR_FOLL_PIN_RELEASED , + refs); + +if (hpage_pincount_available (page)) +hpage_pincount_sub (page, refs); +else + refs *=GUP_PIN_COUNTING_BIAS ; + } + +VM_BUG_ON_PAGE (page_ref_count (page) < refs, page); +/* +* Calling put_page() for each ref is unnecessarily slow. Only the last +* ref needs a put_page(). +*/ +if (refs >1 ) +page_ref_sub (page, refs -1 ); +put_page (page); +} +/** * try_grab_page() - elevate a page's refcount by a flag-dependent amount *
@@ -177,41 +199,6 @@ bool __must_check try_grab_page(struct preturn true; } -#ifdef CONFIG_DEV_PAGEMAP_OPS -static bool __unpin_devmap_managed_user_page (struct page *page) -{ -int count, refs =1 ; - -if (!page_is_devmap_managed (page)) -return false; - -if (hpage_pincount_available (page)) -hpage_pincount_sub (page,1 ); -else - refs =GUP_PIN_COUNTING_BIAS ; - - count =page_ref_sub_return (page, refs); - -mod_node_page_state (page_pgdat (page),NR_FOLL_PIN_RELEASED ,1 ); -/* -* devmap page refcounts are 1-based, rather than 0-based: if -* refcount is 1, then the page is free and the refcount is -* stable because nobody holds a reference on the page. -*/ -if (count ==1 ) -free_devmap_managed_page (page); -else if (!count) -__put_page (page); - -return true; -} -#else -static bool __unpin_devmap_managed_user_page (struct page *page) -{ -return false; -} -#endif /* CONFIG_DEV_PAGEMAP_OPS */ -/** * unpin_user_page() - release a dma-pinned page * @page: pointer to page to be released
@@ -223,28 +210,7 @@ static bool __unpin_devmap_managed_user_*/ void unpin_user_page (struct page *page) { -int refs =1 ; - - page =compound_head (page); - -/* -* For devmap managed pages we need to catch refcount transition from -* GUP_PIN_COUNTING_BIAS to 1, when refcount reach one it means the -* page is free and we need to inform the device driver through -* callback. See include/linux/memremap.h and HMM for details. -*/ -if (__unpin_devmap_managed_user_page (page)) -return ; - -if (hpage_pincount_available (page)) -hpage_pincount_sub (page,1 ); -else - refs =GUP_PIN_COUNTING_BIAS ; - -if (page_ref_sub_and_test (page, refs)) -__put_page (page); - -mod_node_page_state (page_pgdat (page),NR_FOLL_PIN_RELEASED ,1 ); +put_compound_head (compound_head (page),1 ,FOLL_PIN ); }EXPORT_SYMBOL (unpin_user_page);
@@ -2009,29 +1975,6 @@ EXPORT_SYMBOL(get_user_pages_unlocked);* This code is based heavily on the PowerPC implementation by Nick Piggin. */ #ifdef CONFIG_HAVE_FAST_GUP - -static void put_compound_head (struct page *page,int refs,unsigned int flags) -{ -if (flags &FOLL_PIN ) { -mod_node_page_state (page_pgdat (page),NR_FOLL_PIN_RELEASED , - refs); - -if (hpage_pincount_available (page)) -hpage_pincount_sub (page, refs); -else - refs *=GUP_PIN_COUNTING_BIAS ; - } - -VM_BUG_ON_PAGE (page_ref_count (page) < refs, page); -/* -* Calling put_page() for each ref is unnecessarily slow. Only the last -* ref needs a put_page(). -*/ -if (refs >1 ) -page_ref_sub (page, refs -1 ); -put_page (page); -} -#ifdef CONFIG_GUP_GET_PTE_LOW_HIGH /*
_
Andrew Morton
maintainerPATCH 47/200 mm: handle zone device pages in release_pages()
In reply to Andrew MortonFrom: Ralph Campbell <[email protected]>
Subject: mm: handle zone device pages in release_pages()
release_pages() is an optimized, inlined version of __put_pages() except that zone device struct pages that are not page_is_devmap_managed() (i.e., memory_type MEMORY_DEVICE_GENERIC and MEMORY_DEVICE_PCI_P2PDMA), fall through to the code that could return the zone device page to the page allocator instead of adjusting the pgmap reference count.
Clearly these type of pages are not having the reference count decremented to zero via release_pages() or page allocation problems would be seen. Just to be safe, handle the 1 to zero case in release_pages() like __put_page() does.
---
mm/swap.c | 3 +++ 1 file changed, 3 insertions(+)
mm/swap.c renamed from mm/swap.c~mm-handle-zone-device-pages-in-release_pages +3 -0
@@ -909,6 +909,9 @@ void release_pages(struct page **pages,put_devmap_managed_page (page);continue ; } +if (put_page_testzero (page)) +put_dev_pagemap (page->pgmap); +continue ; }if (!put_page_testzero (page))
_
Andrew Morton
maintainerPATCH 48/200 mm/swapfile.c: use helper function swap_count() in add_swap_count_continuation()
In reply to Andrew MortonFrom: Miaohe Lin <[email protected]>
Subject: mm/swapfile.c: use helper function swap_count() in add_swap_count_continuation()
Commit 570a335b8e22 ("swap_info: swap count continuations") introduced the func add_swap_count_continuation() but forgot to use the helper function swap_count() introduced by commit 355cfa73ddff ("mm: modify swap_map and add SWAP_HAS_CACHE flag").
---
mm/swapfile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/swapfile.c renamed from mm/swapfile.c~mm-swapfilec-use-helper-function-swap_count-in-add_swap_count_continuation +1 -1
@@ -3613,7 +3613,7 @@ int add_swap_count_continuation(swp_entr ci =lock_cluster (si, offset); - count = si->swap_map[offset] & ~SWAP_HAS_CACHE ; + count =swap_count (si->swap_map[offset]);if ((count & ~COUNT_CONTINUED ) !=SWAP_MAP_MAX ) {/*
_
Andrew Morton
maintainerPATCH 49/200 mm/swap_state: skip meaningless swap cache readahead when ra_info.win == 0
In reply to Andrew MortonFrom: Miaohe Lin <[email protected]>
Subject: mm/swap_state: skip meaningless swap cache readahead when ra_info.win == 0
swap_ra_info() may leave ra_info untouched in non_swap_entry() case as page table lock is not held. In this case, we have ra_info.nr_pte == 0 and it is meaningless to continue with swap cache readahead. Skip such ops by init ra_info.win = 1.
---
mm/swap_state.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
mm/swap_state.c renamed from mm/swap_state.c~mm-swap_state-skip-meaningless-swap-cache-readahead-when-ra_infowin-==-0 +3 -1
@@ -839,7 +839,9 @@ static struct page *swap_vma_readahead(sswp_entry_t entry;unsigned int i;bool page_allocated; -struct vma_swap_readahead ra_info = {0 ,}; +struct vma_swap_readahead ra_info = { + .win =1 , + };swap_ra_info (vmf, &ra_info);if (ra_info.win ==1 )
_
Andrew Morton
maintainerPATCH 50/200 mm/swapfile.c: remove unnecessary out label in __swap_duplicate()
In reply to Andrew MortonFrom: Miaohe Lin <[email protected]>
Subject: mm/swapfile.c: remove unnecessary out label in __swap_duplicate()
When the code went to the out label, it must have p == NULL. So what out label really does is redundant if check and return err. We should Remove this unnecessary out label because it does not handle resource free and so on.
---
mm/swapfile.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
mm/swapfile.c renamed from mm/swapfile.c~mm-swapfilec-remove-unnecessary-out-label-in-__swap_duplicate +2 -3
@@ -3445,11 +3445,11 @@ static int __swap_duplicate(swp_entry_tunsigned long offset;unsigned char count;unsigned char has_cache; -int err = -EINVAL ; +int err; p =get_swap_device (entry);if (!p) - goto out; +return -EINVAL ; offset =swp_offset (entry); ci =lock_cluster_or_swap_info (p, offset);
@@ -3496,7 +3496,6 @@ static int __swap_duplicate(swp_entry_t unlock_out:unlock_cluster_or_swap_info (p, ci); -out:if (p)put_swap_device (p);return err;
_
Andrew Morton
maintainerPATCH 51/200 mm/swapfile.c: use memset to fill the swap_map with SWAP_HAS_CACHE
In reply to Andrew MortonFrom: Miaohe Lin <[email protected]>
Subject: mm/swapfile.c: use memset to fill the swap_map with SWAP_HAS_CACHE
We could use helper memset to fill the swap_map with SWAP_HAS_CACHE instead of a direct loop here to simplify the code. Also we can remove the local variable i and map this way.
---
mm/swapfile.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
mm/swapfile.c renamed from mm/swapfile.c~mm-swap-use-memset-to-fill-the-swap_map-with-swap_has_cache +2 -5
@@ -975,8 +975,7 @@ static int swap_alloc_cluster(struct swa {unsigned long idx;struct swap_cluster_info *ci; -unsigned long offset, i; -unsigned char *map; +unsigned long offset;/* * Should not even be attempting cluster allocations when huge
@@ -996,9 +995,7 @@ static int swap_alloc_cluster(struct swaalloc_cluster (si, idx);cluster_set_count_flag (ci,SWAPFILE_CLUSTER ,CLUSTER_FLAG_HUGE ); - map = si->swap_map + offset; -for (i =0 ; i <SWAPFILE_CLUSTER ; i++) - map[i] =SWAP_HAS_CACHE ; +memset (si->swap_map + offset,SWAP_HAS_CACHE ,SWAPFILE_CLUSTER );unlock_cluster (ci);swap_range_alloc (si, offset,SWAPFILE_CLUSTER ); *slot =swp_entry (si->type, offset);
_
Andrew Morton
maintainerPATCH 52/200 mm: remove pagevec_lookup_range_nr_tag()
In reply to Andrew MortonFrom: Jeff Layton <[email protected]>
Subject: mm: remove pagevec_lookup_range_nr_tag()
With the merge of 2e1692966034 ("ceph: have ceph_writepages_start call pagevec_lookup_range_tag"), nothing calls this anymore.
---
include/linux/pagevec.h | 3 --- mm/swap.c | 9 --------- 2 files changed, 12 deletions(-)
include/linux/pagevec.h renamed from include/linux/pagevec.h~mm-remove-pagevec_lookup_range_nr_tag +0 -3
@@ -43,9 +43,6 @@ static inline unsigned pagevec_lookup(stunsigned pagevec_lookup_range_tag (struct pagevec *pvec,struct address_space *mapping,pgoff_t *index,pgoff_t end,xa_mark_t tag); -unsigned pagevec_lookup_range_nr_tag (struct pagevec *pvec, -struct address_space *mapping,pgoff_t *index,pgoff_t end, -xa_mark_t tag,unsigned max_pages);static inline unsigned pagevec_lookup_tag (struct pagevec *pvec,struct address_space *mapping,pgoff_t *index,xa_mark_t tag) {
mm/swap.c renamed from mm/swap.c~mm-remove-pagevec_lookup_range_nr_tag +0 -9
@@ -1167,15 +1167,6 @@ unsigned pagevec_lookup_range_tag(struct }EXPORT_SYMBOL (pagevec_lookup_range_tag); -unsigned pagevec_lookup_range_nr_tag (struct pagevec *pvec, -struct address_space *mapping,pgoff_t *index,pgoff_t end, -xa_mark_t tag,unsigned max_pages) -{ - pvec->nr =find_get_pages_range_tag (mapping, index, end, tag, - min_t(unsigned int, max_pages, PAGEVEC_SIZE), pvec->pages); -return pagevec_count (pvec); -} -EXPORT_SYMBOL (pagevec_lookup_range_nr_tag);/* * Perform any setup for the swap system */
_
Andrew Morton
maintainerPATCH 53/200 mm/shmem.c: make shmem_mapping() inline
In reply to Andrew MortonFrom: Hui Su <[email protected]>
Subject: mm/shmem.c: make shmem_mapping() inline
shmem_mapping() isn't worth an out-of-line call from any callsite.
So make it inline by
- make shmem_aops global
- export shmem_aops
- inline the shmem_mapping()
and replace the direct call 'shmem_aops' with shmem_mapping() in shmem.c.
---
include/linux/shmem_fs.h | 6 +++++- mm/shmem.c | 16 ++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-)
include/linux/shmem_fs.h renamed from include/linux/shmem_fs.h~mm-shmemc-make-shmem_mapping-inline +5 -1
@@ -67,7 +67,11 @@ extern unsigned long shmem_get_unmapped_ unsigned long len, unsigned long pgoff, unsigned long flags);extern int shmem_lock (struct file *file,int lock,struct user_struct *user);#ifdef CONFIG_SHMEM -extern bool shmem_mapping (struct address_space *mapping); +extern const struct address_space_operations shmem_aops; +static inline bool shmem_mapping (struct address_space *mapping) +{ +return mapping->a_ops == &shmem_aops; +}#else static inline bool shmem_mapping (struct address_space *mapping) {
mm/shmem.c renamed from mm/shmem.c~mm-shmemc-make-shmem_mapping-inline +6 -10
@@ -246,7 +246,7 @@ static inline void shmem_inode_unacct_bl }static const struct super_operations shmem_ops; -static const struct address_space_operations shmem_aops; +const struct address_space_operations shmem_aops;static const struct file_operations shmem_file_operations;static const struct inode_operations shmem_inode_operations;static const struct inode_operations shmem_dir_inode_operations;
@@ -1152,7 +1152,7 @@ static void shmem_evict_inode(struct inostruct shmem_inode_info *info =SHMEM_I (inode);struct shmem_sb_info *sbinfo =SHMEM_SB (inode->i_sb); -if (inode->i_mapping->a_ops == &shmem_aops) { +if (shmem_mapping (inode->i_mapping)) {shmem_unacct_size (info->flags, inode->i_size); inode->i_size =0 ;shmem_truncate_range (inode,0 , (loff_t)-1 );
@@ -1858,7 +1858,7 @@ repeat: }/* shmem_symlink() */ -if (mapping->a_ops != &shmem_aops) +if (!shmem_mapping (mapping)) goto alloc_nohuge;if (shmem_huge ==SHMEM_HUGE_DENY || sgp_huge ==SGP_NOHUGE ) goto alloc_nohuge;
@@ -2352,11 +2352,6 @@ static struct inode *shmem_get_inode(strreturn inode; } -bool shmem_mapping (struct address_space *mapping) -{ -return mapping->a_ops == &shmem_aops; -} - static int shmem_mfill_atomic_pte(struct mm_struct *dst_mm, pmd_t *dst_pmd, struct vm_area_struct *dst_vma,
@@ -3865,7 +3860,7 @@ static void shmem_destroy_inodecache(voikmem_cache_destroy (shmem_inode_cachep); } -static const struct address_space_operations shmem_aops = { +const struct address_space_operations shmem_aops = { .writepage = shmem_writepage, .set_page_dirty = __set_page_dirty_no_writeback, #ifdef CONFIG_TMPFS
@@ -3877,6 +3872,7 @@ static const struct address_space_operat#endif .error_remove_page = generic_error_remove_page, }; +EXPORT_SYMBOL (shmem_aops);static const struct file_operations shmem_file_operations = { .mmap = shmem_mmap,
@@ -4312,7 +4308,7 @@ struct page *shmem_read_mapping_page_gfpstruct page *page;int error; -BUG_ON (mapping->a_ops != &shmem_aops); +BUG_ON (!shmem_mapping (mapping)); error =shmem_getpage_gfp (inode, index, &page,SGP_CACHE , gfp,NULL ,NULL ,NULL );if (error)
_
Andrew Morton
maintainerPATCH 54/200 tmpfs: fix Documentation nits
In reply to Andrew MortonFrom: Randy Dunlap <[email protected]>
Subject: tmpfs: fix Documentation nits
Fix a typo, punctuation, use uppercase for CPUs, and limit tmpfs to keeping only its files in virtual memory (phrasing).
---
Documentation/filesystems/tmpfs.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
Documentation/filesystems/tmpfs.rst renamed from Documentation/filesystems/tmpfs.rst~tmpfs-fix-documentation-nits +4 -4
@@ -4,7 +4,7 @@ Tmpfs ===== -Tmpfs is a file system which keeps all files in virtual memory. +Tmpfs is a file system which keeps all of its files in virtual memory. Everything in tmpfs is temporary in the sense that no files will be
@@ -35,7 +35,7 @@ tmpfs has the following uses: memory. This mount does not depend on CONFIG_TMPFS. If CONFIG_TMPFS is not - set, the user visible part of tmpfs is not build. But the internal + set, the user visible part of tmpfs is not built. But the internal mechanisms are always present. 2) glibc 2.2 and above expects tmpfs to be mounted at /dev/shm for
@@ -50,7 +50,7 @@ tmpfs has the following uses: This mount is _not_ needed for SYSV shared memory. The internal mount is used for that. (In the 2.3 kernel versions it was necessary to mount the predecessor of tmpfs (shm fs) to use SYSV - shared memory) + shared memory.) 3) Some people (including me) find it very convenient to mount it e.g. on /tmp and /var/tmp and have a big swap partition. And now
@@ -83,7 +83,7 @@ If nr_blocks=0 (or size=0), blocks will if nr_inodes=0, inodes will not be limited. It is generally unwise to mount with such options, since it allows any user with write access to use up all the memory on the machine; but enhances the scalability of -that instance in a system with many cpus making intensive use of it. +that instance in a system with many CPUs making intensive use of it. tmpfs has a mount option to set the NUMA memory allocation policy for
_
Andrew Morton
maintainerPATCH 55/200 mm: memcontrol: add file_thp, shmem_thp to memory.stat
In reply to Andrew MortonFrom: Johannes Weiner <[email protected]>
Subject: mm: memcontrol: add file_thp, shmem_thp to memory.stat
As huge page usage in the page cache and for shmem files proliferates in our production environment, the performance monitoring team has asked for per-cgroup stats on those pages.
We already track and export anon_thp per cgroup. We already track file THP and shmem THP per node, so making them per-cgroup is only a matter of switching from node to lruvec counters. All callsites are in places where the pages are charged and locked, so page->memcg is stable.
---
Documentation/admin-guide/cgroup-v2.rst | 8 ++++++++ mm/filemap.c | 4 ++-- mm/huge_memory.c | 4 ++-- mm/khugepaged.c | 4 ++-- mm/memcontrol.c | 6 +++++- mm/shmem.c | 2 +- 6 files changed, 20 insertions(+), 8 deletions(-)
Documentation/admin-guide/cgroup-v2.rst renamed from Documentation/admin-guide/cgroup-v2.rst~mm-memcontrol-add-file_thp-shmem_thp-to-memorystat +8 -0
@@ -1300,6 +1300,14 @@ PAGE_SIZE multiple when read back. Amount of memory used in anonymous mappings backed by transparent hugepages + file_thp + Amount of cached filesystem data backed by transparent + hugepages + + shmem_thp + Amount of shm, tmpfs, shared anonymous mmap()s backed by + transparent hugepages + inactive_anon, active_anon, inactive_file, active_file, unevictable Amount of memory, swap-backed and filesystem-backed, on the internal memory management lists used by the
mm/filemap.c renamed from mm/filemap.c~mm-memcontrol-add-file_thp-shmem_thp-to-memorystat +2 -2
@@ -204,9 +204,9 @@ static void unaccount_page_cache_page(stif (PageSwapBacked (page)) {__mod_lruvec_page_state (page,NR_SHMEM , -nr);if (PageTransHuge (page)) -__dec_node_page_state (page,NR_SHMEM_THPS ); +__dec_lruvec_page_state (page,NR_SHMEM_THPS ); }else if (PageTransHuge (page)) { -__dec_node_page_state (page,NR_FILE_THPS ); +__dec_lruvec_page_state (page,NR_FILE_THPS );filemap_nr_thps_dec (mapping); }
mm/huge_memory.c renamed from mm/huge_memory.c~mm-memcontrol-add-file_thp-shmem_thp-to-memorystat +2 -2
@@ -2710,9 +2710,9 @@ int split_huge_page_to_list(struct pagespin_unlock (&ds_queue->split_queue_lock);if (mapping) {if (PageSwapBacked (head)) -__dec_node_page_state (head,NR_SHMEM_THPS ); +__dec_lruvec_page_state (head,NR_SHMEM_THPS );else -__dec_node_page_state (head,NR_FILE_THPS ); +__dec_lruvec_page_state (head,NR_FILE_THPS ); }__split_huge_page (page, list, end, flags);
mm/khugepaged.c renamed from mm/khugepaged.c~mm-memcontrol-add-file_thp-shmem_thp-to-memorystat +2 -2
@@ -1845,9 +1845,9 @@ out_unlock: }if (is_shmem) -__inc_node_page_state (new_page,NR_SHMEM_THPS ); +__inc_lruvec_page_state (new_page,NR_SHMEM_THPS );else { -__inc_node_page_state (new_page,NR_FILE_THPS ); +__inc_lruvec_page_state (new_page,NR_FILE_THPS );filemap_nr_thps_inc (mapping); }
mm/memcontrol.c renamed from mm/memcontrol.c~mm-memcontrol-add-file_thp-shmem_thp-to-memorystat +5 -1
@@ -1512,6 +1512,8 @@ static struct memory_stat memory_stats[] * constant(e.g. powerpc). */ { "anon_thp", 0, NR_ANON_THPS }, + { "file_thp", 0, NR_FILE_THPS }, + { "shmem_thp", 0, NR_SHMEM_THPS }, #endif { "inactive_anon", PAGE_SIZE, NR_INACTIVE_ANON }, { "active_anon", PAGE_SIZE, NR_ACTIVE_ANON },
@@ -1542,7 +1544,9 @@ static int __init memory_stats_init(voidfor (i =0 ; i <ARRAY_SIZE (memory_stats); i++) {#ifdef CONFIG_TRANSPARENT_HUGEPAGE -if (memory_stats[i].idx ==NR_ANON_THPS ) +if (memory_stats[i].idx ==NR_ANON_THPS || + memory_stats[i].idx ==NR_FILE_THPS || + memory_stats[i].idx ==NR_SHMEM_THPS ) memory_stats[i].ratio =HPAGE_PMD_SIZE ;#endif VM_BUG_ON (!memory_stats[i].ratio);
mm/shmem.c renamed from mm/shmem.c~mm-memcontrol-add-file_thp-shmem_thp-to-memorystat +1 -1
@@ -713,7 +713,7 @@ next: }if (PageTransHuge (page)) {count_vm_event (THP_FILE_ALLOC ); -__inc_node_page_state (page,NR_SHMEM_THPS ); +__inc_lruvec_page_state (page,NR_SHMEM_THPS ); } mapping->nrpages += nr;__mod_lruvec_page_state (page,NR_FILE_PAGES , nr);
_
Andrew Morton
maintainerPATCH 56/200 mm: memcontrol: remove unused mod_memcg_obj_state()
In reply to Andrew MortonFrom: Muchun Song <[email protected]>
Subject: mm: memcontrol: remove unused mod_memcg_obj_state()
Since commit:
991e7673859e ("mm: memcontrol: account kernel stack per node")
There is no user of the mod_memcg_obj_state(). This patch just remove it. Also rework type of the idx parameter of the mod_objcg_state() from int to enum node_stat_item.
---
include/linux/memcontrol.h | 6 ------ mm/memcontrol.c | 11 ----------- mm/slab.h | 4 ++-- 3 files changed, 2 insertions(+), 19 deletions(-)
include/linux/memcontrol.h renamed from include/linux/memcontrol.h~mm-memcontrol-remove-unused-mod_memcg_obj_state +0 -6
@@ -798,8 +798,6 @@ void __mod_lruvec_state(struct lruvec *l int val);void __mod_lruvec_slab_state (void *p,enum node_stat_item idx,int val); -void mod_memcg_obj_state (void *p,int idx,int val); -static inline void mod_lruvec_slab_state (void *p,enum node_stat_item idx,int val) {
@@ -1255,10 +1253,6 @@ static inline void mod_lruvec_slab_statemod_node_page_state (page_pgdat (page), idx, val); } -static inline void mod_memcg_obj_state (void *p,int idx,int val) -{ -} - static inline unsigned long mem_cgroup_soft_limit_reclaim(pg_data_t *pgdat, int order, gfp_t gfp_mask,
mm/memcontrol.c renamed from mm/memcontrol.c~mm-memcontrol-remove-unused-mod_memcg_obj_state +0 -11
@@ -882,17 +882,6 @@ void __mod_lruvec_slab_state(void *p, enrcu_read_unlock (); } -void mod_memcg_obj_state (void *p,int idx,int val) -{ -struct mem_cgroup *memcg; - -rcu_read_lock (); - memcg =mem_cgroup_from_obj (p); -if (memcg) -mod_memcg_state (memcg, idx, val); -rcu_read_unlock (); -} -/** * __count_memcg_events - account VM events in a cgroup * @memcg: the memory cgroup
mm/slab.h renamed from mm/slab.h~mm-memcontrol-remove-unused-mod_memcg_obj_state +2 -2
@@ -204,7 +204,7 @@ ssize_t slabinfo_write(struct file *filevoid __kmem_cache_free_bulk (struct kmem_cache *,size_t ,void **);int __kmem_cache_alloc_bulk (struct kmem_cache *,gfp_t ,size_t ,void **); -static inline int cache_vmstat_idx (struct kmem_cache *s) +static inline enum node_stat_item cache_vmstat_idx (struct kmem_cache *s) {return (s->flags &SLAB_RECLAIM_ACCOUNT ) ?NR_SLAB_RECLAIMABLE_B :NR_SLAB_UNRECLAIMABLE_B ;
@@ -304,7 +304,7 @@ static inline bool memcg_slab_pre_alloc_static inline void mod_objcg_state (struct obj_cgroup *objcg,struct pglist_data *pgdat, -int idx,int nr) +enum node_stat_item idx,int nr) {struct mem_cgroup *memcg;struct lruvec *lruvec;
_
Andrew Morton
maintainerPATCH 57/200 mm: memcontrol: eliminate redundant check in __mem_cgroup_insert_exceeded()
In reply to Andrew MortonFrom: Miaohe Lin <[email protected]>
Subject: mm: memcontrol: eliminate redundant check in __mem_cgroup_insert_exceeded()
The mz->usage_in_excess >= mz_node->usage_in_excess check is exactly the else case of mz->usage_in_excess < mz_node->usage_in_excess. So we could replace else if (mz->usage_in_excess >= mz_node->usage_in_excess) with else equally. Also drop the comment which doesn't really explain much.
---
mm/memcontrol.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
mm/memcontrol.c renamed from mm/memcontrol.c~mm-memcontrol-eliminate-redundant-check-in-__mem_cgroup_insert_exceeded +2 -7
@@ -623,14 +623,9 @@ static void __mem_cgroup_insert_exceededif (mz->usage_in_excess < mz_node->usage_in_excess) { p = &(*p)->rb_left; rightmost = false; - } - -/* -* We can't avoid mem cgroups that are over their soft -* limit by the same amount -*/ -else if (mz->usage_in_excess >= mz_node->usage_in_excess) + }else { p = &(*p)->rb_right; + } }if (rightmost)
_
Andrew Morton
maintainerPATCH 58/200 mm: memcg/slab: fix return of child memcg objcg for root memcg
In reply to Andrew MortonFrom: Muchun Song <[email protected]>
Subject: mm: memcg/slab: fix return of child memcg objcg for root memcg
Consider the following memcg hierarchy.
root
/ \
A BIf we failed to get the reference on objcg of memcg A, the get_obj_cgroup_from_current can return the wrong objcg for the root memcg.
---
mm/memcontrol.c | 1 + 1 file changed, 1 insertion(+)
mm/memcontrol.c renamed from mm/memcontrol.c~mm-memcg-slab-fix-return-child-memcg-objcg-for-root-memcg +1 -0
@@ -2975,6 +2975,7 @@ __always_inline struct obj_cgroup *get_o objcg =rcu_dereference (memcg->objcg);if (objcg &&obj_cgroup_tryget (objcg))break ; + objcg =NULL ; }rcu_read_unlock ();
_
Andrew Morton
maintainerPATCH 59/200 mm: memcg/slab: fix use after free in obj_cgroup_charge
In reply to Andrew MortonFrom: Muchun Song <[email protected]>
Subject: mm: memcg/slab: fix use after free in obj_cgroup_charge
The rcu_read_lock/unlock only can guarantee that the memcg will not be freed, but it cannot guarantee the success of css_get to memcg.
If the whole process of a cgroup offlining is completed between reading a objcg->memcg pointer and bumping the css reference on another CPU, and there are exactly 0 external references to this memory cgroup (how we get to the obj_cgroup_charge() then?), css_get() can change the ref counter from 0 back to 1.
---
mm/memcontrol.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
mm/memcontrol.c renamed from mm/memcontrol.c~mm-memcg-slab-fix-use-after-free-in-obj_cgroup_charge +3 -1
@@ -3235,8 +3235,10 @@ int obj_cgroup_charge(struct obj_cgroup* independently later. */ rcu_read_lock (); +retry: memcg =obj_cgroup_memcg (objcg); -css_get (&memcg->css); +if (unlikely (!css_tryget (&memcg->css))) + goto retry;rcu_read_unlock (); nr_pages = size >>PAGE_SHIFT ;
_
Andrew Morton
maintainerPATCH 60/200 mm/rmap: always do TTU_IGNORE_ACCESS
In reply to Andrew MortonFrom: Shakeel Butt <[email protected]>
Subject: mm/rmap: always do TTU_IGNORE_ACCESS
Since commit 369ea8242c0f ("mm/rmap: update to new mmu_notifier semantic v2"), the code to check the secondary MMU's page table access bit is broken for !(TTU_IGNORE_ACCESS) because the page is unmapped from the secondary MMU's page table before the check. More specifically for those secondary MMUs which unmap the memory in mmu_notifier_invalidate_range_start() like kvm.
However memory reclaim is the only user of !(TTU_IGNORE_ACCESS) or the absence of TTU_IGNORE_ACCESS and it explicitly performs the page table access check before trying to unmap the page. So, at worst the reclaim will miss accesses in a very short window if we remove page table access check in unmapping code.
There is an unintented consequence of !(TTU_IGNORE_ACCESS) for the memcg reclaim. From memcg reclaim the page_referenced() only account the accesses from the processes which are in the same memcg of the target page but the unmapping code is considering accesses from all the processes, so, decreasing the effectiveness of memcg reclaim.
The simplest solution is to always assume TTU_IGNORE_ACCESS in unmapping code.
---
include/linux/rmap.h | 1 - mm/huge_memory.c | 2 +- mm/memory-failure.c | 2 +- mm/memory_hotplug.c | 2 +- mm/migrate.c | 8 +++----- mm/rmap.c | 9 --------- mm/vmscan.c | 14 +++++--------- 7 files changed, 11 insertions(+), 27 deletions(-)
include/linux/rmap.h renamed from include/linux/rmap.h~mm-rmap-always-do-ttu_ignore_access +0 -1
@@ -91,7 +91,6 @@ enum ttu_flags {TTU_SPLIT_HUGE_PMD =0x4 ,/* split huge PMD if any */ TTU_IGNORE_MLOCK =0x8 ,/* ignore mlock */ -TTU_IGNORE_ACCESS =0x10 ,/* don't age */ TTU_IGNORE_HWPOISON =0x20 ,/* corrupted page is recoverable */ TTU_BATCH_FLUSH = 0x40, /* Batch TLB flushes where possible* and caller guarantees they will
mm/huge_memory.c renamed from mm/huge_memory.c~mm-rmap-always-do-ttu_ignore_access +1 -1
@@ -2321,7 +2321,7 @@ void vma_adjust_trans_huge(struct vm_arestatic void unmap_page (struct page *page) { -enum ttu_flags ttu_flags =TTU_IGNORE_MLOCK |TTU_IGNORE_ACCESS | +enum ttu_flags ttu_flags =TTU_IGNORE_MLOCK |TTU_RMAP_LOCKED |TTU_SPLIT_HUGE_PMD ;bool unmap_success;
mm/memory-failure.c renamed from mm/memory-failure.c~mm-rmap-always-do-ttu_ignore_access +1 -1
@@ -989,7 +989,7 @@ static int get_hwpoison_page(struct pagestatic bool hwpoison_user_mappings (struct page *p,unsigned long pfn,int flags,struct page **hpagep) { -enum ttu_flags ttu =TTU_IGNORE_MLOCK |TTU_IGNORE_ACCESS ; +enum ttu_flags ttu =TTU_IGNORE_MLOCK ;struct address_space *mapping;LIST_HEAD (tokill);bool unmap_success = true;
mm/memory_hotplug.c renamed from mm/memory_hotplug.c~mm-rmap-always-do-ttu_ignore_access +1 -1
@@ -1304,7 +1304,7 @@ do_migrate_range(unsigned long start_pfnif (WARN_ON (PageLRU (page)))isolate_lru_page (page);if (page_mapped (page)) -try_to_unmap (page,TTU_IGNORE_MLOCK |TTU_IGNORE_ACCESS ); +try_to_unmap (page,TTU_IGNORE_MLOCK );continue ; }
mm/migrate.c renamed from mm/migrate.c~mm-rmap-always-do-ttu_ignore_access +3 -5
@@ -1122,8 +1122,7 @@ static int __unmap_and_move(struct page/* Establish migration ptes */ VM_BUG_ON_PAGE (PageAnon (page) && !PageKsm (page) && !anon_vma, page); -try_to_unmap (page, -TTU_MIGRATION |TTU_IGNORE_MLOCK |TTU_IGNORE_ACCESS ); +try_to_unmap (page,TTU_MIGRATION |TTU_IGNORE_MLOCK ); page_was_mapped =1 ; }
@@ -1329,8 +1328,7 @@ static int unmap_and_move_huge_page(new_if (page_mapped (hpage)) {bool mapping_locked = false; -enum ttu_flags ttu =TTU_MIGRATION |TTU_IGNORE_MLOCK | -TTU_IGNORE_ACCESS ; +enum ttu_flags ttu =TTU_MIGRATION |TTU_IGNORE_MLOCK ;if (!PageAnon (hpage)) {/*
@@ -2688,7 +2686,7 @@ static void migrate_vma_prepare(struct m*/ static void migrate_vma_unmap (struct migrate_vma *migrate) { -int flags =TTU_MIGRATION |TTU_IGNORE_MLOCK |TTU_IGNORE_ACCESS ; +int flags =TTU_MIGRATION |TTU_IGNORE_MLOCK ;const unsigned long npages = migrate->npages;const unsigned long start = migrate->start;unsigned long addr, i, restore =0 ;
mm/rmap.c renamed from mm/rmap.c~mm-rmap-always-do-ttu_ignore_access +0 -9
@@ -1533,15 +1533,6 @@ static bool try_to_unmap_one(struct page goto discard; } -if (!(flags &TTU_IGNORE_ACCESS )) { -if (ptep_clear_flush_young_notify (vma, address, - pvmw.pte)) { - ret = false; -page_vma_mapped_walk_done (&pvmw); -break ; - } - } -/* Nuke the page table entry. */ flush_cache_page (vma, address,pte_pfn (*pvmw.pte));if (should_defer_flush (mm, flags)) {
mm/vmscan.c renamed from mm/vmscan.c~mm-rmap-always-do-ttu_ignore_access +5 -9
@@ -1072,7 +1072,6 @@ static void page_check_dirty_writeback(sstatic unsigned int shrink_page_list (struct list_head *page_list,struct pglist_data *pgdat,struct scan_control *sc, -enum ttu_flags ttu_flags,struct reclaim_stat *stat,bool ignore_references) {
@@ -1297,7 +1296,7 @@ static unsigned int shrink_page_list(str* processes. Try to unmap it here. */ if (page_mapped (page)) { -enum ttu_flags flags = ttu_flags |TTU_BATCH_FLUSH ; +enum ttu_flags flags =TTU_BATCH_FLUSH ;bool was_swapbacked =PageSwapBacked (page);if (unlikely (PageTransHuge (page)))
@@ -1514,7 +1513,7 @@ unsigned int reclaim_clean_pages_from_li } nr_reclaimed =shrink_page_list (&clean_pages, zone->zone_pgdat, &sc, -TTU_IGNORE_ACCESS , &stat, true); + &stat, true);list_splice (&clean_pages, page_list);mod_node_page_state (zone->zone_pgdat,NR_ISOLATED_FILE , -(long )nr_reclaimed);
@@ -1958,8 +1957,7 @@ shrink_inactive_list(unsigned long nr_toif (nr_taken ==0 )return 0 ; - nr_reclaimed =shrink_page_list (&page_list, pgdat, sc,0 , - &stat, false); + nr_reclaimed =shrink_page_list (&page_list, pgdat, sc, &stat, false);spin_lock_irq (&pgdat->lru_lock);
@@ -2131,8 +2129,7 @@ unsigned long reclaim_pages(struct list_ nr_reclaimed +=shrink_page_list (&node_page_list,NODE_DATA (nid), - &sc,0 , - &dummy_stat, false); + &sc, &dummy_stat, false);while (!list_empty (&node_page_list)) { page =lru_to_page (&node_page_list);list_del (&page->lru);
@@ -2145,8 +2142,7 @@ unsigned long reclaim_pages(struct list_if (!list_empty (&node_page_list)) { nr_reclaimed +=shrink_page_list (&node_page_list,NODE_DATA (nid), - &sc,0 , - &dummy_stat, false); + &sc, &dummy_stat, false);while (!list_empty (&node_page_list)) { page =lru_to_page (&node_page_list);list_del (&page->lru);
_
Andrew Morton
maintainerPATCH 61/200 mm/memcg: update page struct member in comments
In reply to Andrew MortonFrom: Alex Shi <[email protected]>
Subject: mm/memcg: update page struct member in comments
The page->mem_cgroup member is replaced by memcg_data, and add a helper page_memcg() for it. Need to update comments to avoid confusing.
---
mm/memcontrol.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
mm/memcontrol.c renamed from mm/memcontrol.c~mm-memcg-update-page-struct-member-in-comments +2 -2
@@ -1324,7 +1324,7 @@ int mem_cgroup_scan_tasks(struct mem_cgr* @page: the page * @pgdat: pgdat of the page * -* This function relies on page->mem_cgroup being stable - see the +* This function relies on page's memcg being stable - see the * access rules in commit_charge(). */ struct lruvec *mem_cgroup_page_lruvec (struct page *page,struct pglist_data *pgdat)
@@ -2879,7 +2879,7 @@ static void commit_charge(struct page *p {VM_BUG_ON_PAGE (page->mem_cgroup, page);/* -* Any of the following ensures page->mem_cgroup stability: +* Any of the following ensures page's memcg stability: * * - the page lock * - LRU isolation
_
Andrew Morton
maintainerPATCH 62/200 mm: memcg: fix obsolete code comments
In reply to Andrew MortonFrom: Roman Gushchin <[email protected]>
Subject: mm: memcg: fix obsolete code comments
This patch fixes/removes some obsolete comments in the code related to the kernel memory accounting:
- kmem_cache->memcg_params.memcg_caches has been removed by commit 9855609bde03 ("mm: memcg/slab: use a single set of kmem_caches for all accounted allocations")
- memcg->kmemcg_id is not used as a gate for kmem accounting since commit 0b8f73e10428 ("mm: memcontrol: clean up alloc, online, offline, free functions")
---
include/linux/memcontrol.h | 6 ++---- mm/memcontrol.c | 6 ------ 2 files changed, 2 insertions(+), 10 deletions(-)
include/linux/memcontrol.h renamed from include/linux/memcontrol.h~mm-memcg-fix-obsolete-code-comments +2 -4
@@ -296,7 +296,6 @@ struct mem_cgroup {int tcpmem_pressure;#ifdef CONFIG_MEMCG_KMEM -/* Index in the kmem_cache->memcg_params.memcg_caches array */ int kmemcg_id;enum memcg_kmem_state kmem_state;struct obj_cgroup __rcu *objcg;
@@ -1562,9 +1561,8 @@ static inline void memcg_kmem_uncharge(s }/* -* helper for accessing a memcg's index. It will be used as an index in the -* child cache array in kmem_cache, and also to derive its name. This function -* will return -1 when this is not a kmem-limited memcg. +* A helper for accessing memcg's kmem_id, used for getting +* corresponding LRU lists. */ static inline int memcg_cache_id (struct mem_cgroup *memcg) {
mm/memcontrol.c renamed from mm/memcontrol.c~mm-memcg-fix-obsolete-code-comments +0 -6
@@ -3703,12 +3703,6 @@ static int memcg_online_kmem(struct mem_static_branch_enable (&memcg_kmem_enabled_key); -/* -* A memory cgroup is considered kmem-online as soon as it gets -* kmemcg_id. Setting the id after enabling static branching will -* guarantee no one starts accounting before all call sites are -* patched. -*/ memcg->kmemcg_id = memcg_id; memcg->kmem_state =KMEM_ONLINE ;
_
Andrew Morton
maintainerPATCH 63/200 mm: memcg: deprecate the non-hierarchical mode
In reply to Andrew MortonFrom: Roman Gushchin <[email protected]>
Subject: mm: memcg: deprecate the non-hierarchical mode
Patch series "mm: memcg: deprecate cgroup v1 non-hierarchical mode", v1.
The non-hierarchical cgroup v1 mode is a legacy of early days of the memory controller and doesn't bring any value today. However, it complicates the code and creates many edge cases all over the memory controller code.
It's a good time to deprecate it completely. This patchset removes the internal logic, adjusts the user interface and updates the documentation. The alt patch removes some bits of the cgroup core code, which become obsolete.
Michal Hocko said:
: All that we know today is that we have a warning in place to complain : loudly when somebody relies on use_hierarchy=0 with a deeper hierarchy. : For all those years we have seen _zero_ reports that would describe a : sensible usecase.
:
: Moreover we (SUSE) have backported this warning into old distribution : kernels (since 3.0 based kernels) to extend the coverage and didn't hear : even for users who adopt new kernels only very slowly. The only report we : have seen so far was a LTP test suite which doesn't really reflect any : real life usecase.
This patch (of 3):
The non-hierarchical cgroup v1 mode is a legacy of early days of the memory controller and doesn't bring any value today. However, it complicates the code and creates many edge cases all over the memory controller code.
It's a good time to deprecate it completely.
Functionally this patch enabled is by default for all cgroups and forbids switching it off. Nothing changes if cgroup v2 is used: hierarchical mode was enforced from scratch.
To protect the ABI memory.use_hierarchy interface is preserved with a limited functionality: reading always returns "1", writing of "1" passes silently, writing of any other value fails with -EINVAL and a warning to dmesg (on the first occasion).
---
include/linux/memcontrol.h | 7 -- kernel/cgroup/cgroup.c | 5 - mm/memcontrol.c | 90 +++++------------------------------ 3 files changed, 13 insertions(+), 89 deletions(-)
include/linux/memcontrol.h renamed from include/linux/memcontrol.h~mm-memcg-deprecate-the-non-hierarchical-mode +0 -7
@@ -235,11 +235,6 @@ struct mem_cgroup {struct vmpressure vmpressure;/* -* Should the accounting and control be hierarchical, per subtree? -*/ -bool use_hierarchy; - -/* * Should the OOM killer kill all belonging tasks, had it kill one? */ bool oom_group;
@@ -588,8 +583,6 @@ static inline bool mem_cgroup_is_descend {if (root == memcg)return true; -if (!root->use_hierarchy) -return false;return cgroup_is_descendant (memcg->css.cgroup, root->css.cgroup); }
kernel/cgroup/cgroup.c renamed from kernel/cgroup/cgroup.c~mm-memcg-deprecate-the-non-hierarchical-mode +0 -5
@@ -281,9 +281,6 @@ bool cgroup_ssid_enabled(int ssid)* - cpuset: a task can be moved into an empty cpuset, and again it takes * masks of ancestors. * -* - memcg: use_hierarchy is on by default and the cgroup file for the flag -* is not created. -* * - blkcg: blk-throttle becomes properly hierarchical. * * - debug: disallowed on the default hierarchy.
@@ -5156,8 +5153,6 @@ static struct cgroup_subsys_state *css_c cgroup_parent(parent)) {pr_warn ("%s (%d) created nested cgroup for controller \"%s\" which has incomplete hierarchy support. Nested cgroups may change behavior in the future.\n" , current->comm, current->pid, ss->name); -if (!strcmp (ss->name,"memory" )) -pr_warn ("\"memory\" requires setting use_hierarchy to 1 on the root\n" ); ss->warned_broken_hierarchy = true; }
mm/memcontrol.c renamed from mm/memcontrol.c~mm-memcg-deprecate-the-non-hierarchical-mode +13 -77
156 lines not on this page · raw message
_
Andrew Morton
maintainerPATCH 64/200 docs: cgroup-v1: reflect the deprecation of the non-hierarchical mode
In reply to Andrew MortonFrom: Roman Gushchin <[email protected]>
Subject: docs: cgroup-v1: reflect the deprecation of the non-hierarchical mode
Update cgroup v1 docs after the deprecation of the non-hierarchical mode of the memory controller.
---
Documentation/admin-guide/cgroup-v1/memcg_test.rst | 8 -- Documentation/admin-guide/cgroup-v1/memory.rst | 42 +++-------- 2 files changed, 17 insertions(+), 33 deletions(-)
Documentation/admin-guide/cgroup-v1/memcg_test.rst renamed from Documentation/admin-guide/cgroup-v1/memcg_test.rst~docs-cgroup-v1-reflect-the-deprecation-of-the-non-hierarchical-mode +3 -5
@@ -219,13 +219,11 @@ Under below explanation, we assume CONFI This is an easy way to test page migration, too. -9.5 mkdir/rmdir ---------------- +9.5 nested cgroups +------------------ - When using hierarchy, mkdir/rmdir test should be done. - Use tests like the following:: + Use tests like the following for testing nested cgroups:: - echo 1 >/opt/cgroup/01/memory/use_hierarchy mkdir /opt/cgroup/01/child_a mkdir /opt/cgroup/01/child_b
Documentation/admin-guide/cgroup-v1/memory.rst renamed from Documentation/admin-guide/cgroup-v1/memory.rst~docs-cgroup-v1-reflect-the-deprecation-of-the-non-hierarchical-mode +14 -28
76 lines not on this page · raw message
_
Andrew Morton
maintainerPATCH 65/200 cgroup: remove obsoleted broken_hierarchy and warned_broken_hierarchy
In reply to Andrew MortonFrom: Roman Gushchin <[email protected]>
Subject: cgroup: remove obsoleted broken_hierarchy and warned_broken_hierarchy
With the deprecation of the non-hierarchical mode of the memory controller there are no more examples of broken hierarchies left.
Let's remove the cgroup core code which was supposed to print warnings about creating of broken hierarchies.
---
include/linux/cgroup-defs.h | 15 --------------- kernel/cgroup/cgroup.c | 7 ------- 2 files changed, 22 deletions(-)
include/linux/cgroup-defs.h renamed from include/linux/cgroup-defs.h~cgroup-remove-obsoleted-broken_hierarchy-and-warned_broken_hierarchy +0 -15
@@ -668,21 +668,6 @@ struct cgroup_subsys {*/ bool threaded:1; -/* -* If %false, this subsystem is properly hierarchical - -* configuration, resource accounting and restriction on a parent -* cgroup cover those of its children. If %true, hierarchy support -* is broken in some ways - some subsystems ignore hierarchy -* completely while others are only implemented half-way. -* -* It's now disallowed to create nested cgroups if the subsystem is -* broken and cgroup core will emit a warning message on such -* cases. Eventually, all subsystems will be made properly -* hierarchical and this will go away. -*/ - bool broken_hierarchy:1; - bool warned_broken_hierarchy:1; -/* the following two fields are initialized automtically during boot */ int id;const char *name;
kernel/cgroup/cgroup.c renamed from kernel/cgroup/cgroup.c~cgroup-remove-obsoleted-broken_hierarchy-and-warned_broken_hierarchy +0 -7
@@ -5149,13 +5149,6 @@ static struct cgroup_subsys_state *css_cif (err) goto err_list_del; -if (ss->broken_hierarchy && !ss->warned_broken_hierarchy && -cgroup_parent (parent)) { -pr_warn ("%s (%d) created nested cgroup for controller \"%s\" which has incomplete hierarchy support. Nested cgroups may change behavior in the future.\n" , - current->comm, current->pid, ss->name); - ss->warned_broken_hierarchy = true; - } -return css; err_list_del:
_
Andrew Morton
maintainerPATCH 66/200 mm/page_counter: use page_counter_read in page_counter_set_max
In reply to Andrew MortonFrom: Hui Su <[email protected]>
Subject: mm/page_counter: use page_counter_read in page_counter_set_max
Use page_counter_read() in page_counter_set_max().
---
mm/page_counter.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
mm/page_counter.c renamed from mm/page_counter.c~mm-page_counter-use-page_counter_read-in-page_counter_set_max +2 -2
@@ -183,14 +183,14 @@ int page_counter_set_max(struct page_cou* the limit, so if it sees the old limit, we see the * modified counter and retry. */ - usage =atomic_long_read (&counter->usage); + usage =page_counter_read (counter);if (usage > nr_pages)return -EBUSY ; old =xchg (&counter->max, nr_pages); -if (atomic_long_read (&counter->usage) <= usage) +if (page_counter_read (counter) <= usage)return 0 ; counter->max = old;
_
Andrew Morton
maintainerPATCH 67/200 mm: memcg: remove obsolete memcg_has_children()
In reply to Andrew MortonFrom: Lukas Bulwahn <[email protected]>
Subject: mm: memcg: remove obsolete memcg_has_children()
Commit 2ef1bf118c40 ("mm: memcg: deprecate the non-hierarchical mode") removed the only use of memcg_has_children() in mem_cgroup_hierarchy_write() as part of the feature deprecation.
Hence, since then, make CC=clang W=1 warns:
mm/memcontrol.c:3421:20:
warning: unused function 'memcg_has_children' [-Wunused-function]
Simply remove this obsolete unused function.
---
mm/memcontrol.c | 13 ------------- 1 file changed, 13 deletions(-)
mm/memcontrol.c renamed from mm/memcontrol.c~mm-memcg-remove-obsolete-memcg_has_children +0 -13
@@ -3454,19 +3454,6 @@ unsigned long mem_cgroup_soft_limit_recl }/* -* Test whether @memcg has children, dead or alive. -*/ -static inline bool memcg_has_children (struct mem_cgroup *memcg) -{ -bool ret; - -rcu_read_lock (); - ret =css_next_child (NULL , &memcg->css); -rcu_read_unlock (); -return ret; -} - -/* * Reclaims as many pages from the given memcg as possible. * * Caller is responsible for holding css reference for memcg.
_
Andrew Morton
maintainerPATCH 68/200 mm: memcg/slab: rename *_lruvec_slab_state to *_lruvec_kmem_state
In reply to Andrew MortonFrom: Muchun Song <[email protected]>
Subject: mm: memcg/slab: rename *_lruvec_slab_state to *_lruvec_kmem_state
The *_lruvec_slab_state is also suitable for pages allocated from buddy, not just for the slab objects. But the function name seems to tell us that only slab object is applicable. So we can rename the keyword of slab to kmem.
---
include/linux/memcontrol.h | 18 +++++++++--------- kernel/fork.c | 2 +- mm/memcontrol.c | 2 +- mm/workingset.c | 8 ++++---- 4 files changed, 15 insertions(+), 15 deletions(-)
include/linux/memcontrol.h renamed from include/linux/memcontrol.h~mm-memcg-slab-rename-_lruvec_slab_state-to-_lruvec_kmem_state +9 -9
@@ -788,15 +788,15 @@ void __mod_memcg_lruvec_state(struct lru int val);void __mod_lruvec_state (struct lruvec *lruvec,enum node_stat_item idx,int val); -void __mod_lruvec_slab_state (void *p,enum node_stat_item idx,int val); +void __mod_lruvec_kmem_state (void *p,enum node_stat_item idx,int val); -static inline void mod_lruvec_slab_state (void *p,enum node_stat_item idx, +static inline void mod_lruvec_kmem_state (void *p,enum node_stat_item idx,int val) {unsigned long flags;local_irq_save (flags); -__mod_lruvec_slab_state (p, idx, val); +__mod_lruvec_kmem_state (p, idx, val);local_irq_restore (flags); }
@@ -1229,7 +1229,7 @@ static inline void mod_lruvec_page_statemod_node_page_state (page_pgdat (page), idx, val); } -static inline void __mod_lruvec_slab_state (void *p,enum node_stat_item idx, +static inline void __mod_lruvec_kmem_state (void *p,enum node_stat_item idx,int val) {struct page *page =virt_to_head_page (p);
@@ -1237,7 +1237,7 @@ static inline void __mod_lruvec_slab_sta__mod_node_page_state (page_pgdat (page), idx, val); } -static inline void mod_lruvec_slab_state (void *p,enum node_stat_item idx, +static inline void mod_lruvec_kmem_state (void *p,enum node_stat_item idx,int val) {struct page *page =virt_to_head_page (p);
@@ -1332,14 +1332,14 @@ static inline void __dec_lruvec_page_sta__mod_lruvec_page_state (page, idx,-1 ); } -static inline void __inc_lruvec_slab_state (void *p,enum node_stat_item idx) +static inline void __inc_lruvec_kmem_state (void *p,enum node_stat_item idx) { -__mod_lruvec_slab_state (p, idx,1 ); +__mod_lruvec_kmem_state (p, idx,1 ); } -static inline void __dec_lruvec_slab_state (void *p,enum node_stat_item idx) +static inline void __dec_lruvec_kmem_state (void *p,enum node_stat_item idx) { -__mod_lruvec_slab_state (p, idx,-1 ); +__mod_lruvec_kmem_state (p, idx,-1 ); }/* idx can be of type enum memcg_stat_item or node_stat_item */
kernel/fork.c renamed from kernel/fork.c~mm-memcg-slab-rename-_lruvec_slab_state-to-_lruvec_kmem_state +1 -1
@@ -385,7 +385,7 @@ static void account_kernel_stack(structmod_lruvec_page_state (vm->pages[0 ],NR_KERNEL_STACK_KB , account * (THREAD_SIZE /1024 )); else -mod_lruvec_slab_state (stack ,NR_KERNEL_STACK_KB , +mod_lruvec_kmem_state (stack ,NR_KERNEL_STACK_KB , account * (THREAD_SIZE / 1024)); }
mm/memcontrol.c renamed from mm/memcontrol.c~mm-memcg-slab-rename-_lruvec_slab_state-to-_lruvec_kmem_state +1 -1
@@ -853,7 +853,7 @@ void __mod_lruvec_state(struct lruvec *l__mod_memcg_lruvec_state (lruvec, idx, val); } -void __mod_lruvec_slab_state (void *p,enum node_stat_item idx,int val) +void __mod_lruvec_kmem_state (void *p,enum node_stat_item idx,int val) {pg_data_t *pgdat =page_pgdat (virt_to_page (p));struct mem_cgroup *memcg;
mm/workingset.c renamed from mm/workingset.c~mm-memcg-slab-rename-_lruvec_slab_state-to-_lruvec_kmem_state +4 -4
@@ -445,12 +445,12 @@ void workingset_update_node(struct xa_noif (node->count && node->count == node->nr_values) {if (list_empty (&node->private_list)) {list_lru_add (&shadow_nodes, &node->private_list); -__inc_lruvec_slab_state (node,WORKINGSET_NODES ); +__inc_lruvec_kmem_state (node,WORKINGSET_NODES ); } }else {if (!list_empty (&node->private_list)) {list_lru_del (&shadow_nodes, &node->private_list); -__dec_lruvec_slab_state (node,WORKINGSET_NODES ); +__dec_lruvec_kmem_state (node,WORKINGSET_NODES ); } } }
@@ -544,7 +544,7 @@ static enum lru_status shadow_lru_isolat }list_lru_isolate (lru, item); -__dec_lruvec_slab_state (node,WORKINGSET_NODES ); +__dec_lruvec_kmem_state (node,WORKINGSET_NODES );spin_unlock (lru_lock);
@@ -559,7 +559,7 @@ static enum lru_status shadow_lru_isolat goto out_invalid; mapping->nrexceptional -= node->nr_values;xa_delete_node (node, workingset_update_node); -__inc_lruvec_slab_state (node,WORKINGSET_NODERECLAIM ); +__inc_lruvec_kmem_state (node,WORKINGSET_NODERECLAIM ); out_invalid:xa_unlock_irq (&mapping->i_pages);
_
Andrew Morton
maintainerPATCH 69/200 mm: memcontrol: sssign boolean values to a bool variable
In reply to Andrew MortonFrom: Kaixu Xia <[email protected]>
Subject: mm: memcontrol: sssign boolean values to a bool variable
Fix the following coccinelle warnings:
./mm/memcontrol.c:7341:2-22: WARNING: Assignment of 0/1 to bool variable ./mm/memcontrol.c:7343:2-22: WARNING: Assignment of 0/1 to bool variable
---
mm/memcontrol.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
mm/memcontrol.c renamed from mm/memcontrol.c~mm-memcontrol-assign-boolean-values-to-a-bool-variable +2 -2
@@ -7262,9 +7262,9 @@ bool mem_cgroup_swap_full(struct page *pstatic int __init setup_swap_account (char *s) {if (!strcmp (s,"1" )) - cgroup_memory_noswap =0 ; + cgroup_memory_noswap = false;else if (!strcmp (s,"0" )) - cgroup_memory_noswap =1 ; + cgroup_memory_noswap = true;return 1 ; }__setup ("swapaccount=" , setup_swap_account);
_
Andrew Morton
maintainerPATCH 70/200 mm/memcg: remove incorrect comment
In reply to Andrew MortonFrom: Alex Shi <[email protected]>
Subject: mm/memcg: remove incorrect comment
Swapcache readahead pages are charged before being used, so it is unlikely that they will be migrated before charging. Remove the incorrect comment.
---
mm/memcontrol.c | 1 - 1 file changed, 1 deletion(-)
mm/memcontrol.c renamed from mm/memcontrol.c~mm-memcg-remove-incorrect-comments +0 -1
@@ -6903,7 +6903,6 @@ void mem_cgroup_migrate(struct page *oldif (newpage->mem_cgroup)return ; -/* Swapcache readahead pages can get replaced before being charged */ memcg = oldpage->mem_cgroup;if (!memcg)return ;
_
Andrew Morton
maintainerPATCH 71/200 mm: move lruvec stats update functions to vmstat.h
In reply to Andrew MortonFrom: Shakeel Butt <[email protected]>
Subject: mm: move lruvec stats update functions to vmstat.h
Patch series "memcg: add pagetable comsumption to memory.stat", v2.
Many workloads consumes significant amount of memory in pagetables. One specific use-case is the user space network driver which mmaps the application memory to provide zero copy transfer. This driver can consume a large amount memory in page tables. This patch series exposes the pagetable comsumption for each memory cgroup.
This patch (of 2):
This does not change any functionality and only move the functions which update the lruvec stats to vmstat.h from memcontrol.h. The main reason for this patch is to be able to use these functions in the page table contructor function which is defined in mm.h and we can not include the memcontrol.h in that file. Also this is a better place for this interface in general. The lruvec abstraction, while invented for memcg, isn't specific to memcg at all.
---
include/linux/memcontrol.h | 111 ----------------------------------- include/linux/vmstat.h | 104 ++++++++++++++++++++++++++++++++ mm/memcontrol.c | 17 +++++ 3 files changed, 121 insertions(+), 111 deletions(-)
include/linux/memcontrol.h renamed from include/linux/memcontrol.h~mm-move-lruvec-stats-update-functions-to-vmstath +0 -111
@@ -786,8 +786,6 @@ static inline unsigned long lruvec_page_void __mod_memcg_lruvec_state (struct lruvec *lruvec,enum node_stat_item idx,int val); -void __mod_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); static inline void mod_lruvec_kmem_state(void *p, enum node_stat_item idx,
@@ -810,43 +808,6 @@ static inline void mod_memcg_lruvec_statlocal_irq_restore (flags); } -static inline void mod_lruvec_state (struct lruvec *lruvec, -enum node_stat_item idx,int val) -{ -unsigned long flags; - -local_irq_save (flags); -__mod_lruvec_state (lruvec, idx, val); -local_irq_restore (flags); -} - -static inline void __mod_lruvec_page_state (struct page *page, -enum node_stat_item idx,int val) -{ -struct page *head =compound_head (page);/* rmap on tail pages */ -pg_data_t *pgdat =page_pgdat (page); -struct lruvec *lruvec; - -/* Untracked pages have no memcg, no lruvec. Update only the node */ -if (!head->mem_cgroup) { -__mod_node_page_state (pgdat, idx, val); -return ; - } - - lruvec =mem_cgroup_lruvec (head->mem_cgroup, pgdat); -__mod_lruvec_state (lruvec, idx, val); -} - -static inline void mod_lruvec_page_state (struct page *page, -enum node_stat_item idx,int val) -{ -unsigned long flags; - -local_irq_save (flags); -__mod_lruvec_page_state (page, idx, val); -local_irq_restore (flags); -} -unsigned long mem_cgroup_soft_limit_reclaim (pg_data_t *pgdat,int order,gfp_t gfp_mask,unsigned long *total_scanned);
@@ -1205,30 +1166,6 @@ static inline void __mod_memcg_lruvec_st { } -static inline void __mod_lruvec_state (struct lruvec *lruvec, -enum node_stat_item idx,int val) -{ -__mod_node_page_state (lruvec_pgdat (lruvec), idx, val); -} - -static inline void mod_lruvec_state (struct lruvec *lruvec, -enum node_stat_item idx,int val) -{ -mod_node_page_state (lruvec_pgdat (lruvec), idx, val); -} - -static inline void __mod_lruvec_page_state (struct page *page, -enum node_stat_item idx,int val) -{ -__mod_node_page_state (page_pgdat (page), idx, val); -} - -static inline void mod_lruvec_page_state (struct page *page, -enum node_stat_item idx,int val) -{ -mod_node_page_state (page_pgdat (page), idx, val); -} -static inline void __mod_lruvec_kmem_state (void *p,enum node_stat_item idx,int val) {
@@ -1308,30 +1245,6 @@ static inline void __dec_memcg_page_stat__mod_memcg_page_state (page, idx,-1 ); } -static inline void __inc_lruvec_state (struct lruvec *lruvec, -enum node_stat_item idx) -{ -__mod_lruvec_state (lruvec, idx,1 ); -} - -static inline void __dec_lruvec_state (struct lruvec *lruvec, -enum node_stat_item idx) -{ -__mod_lruvec_state (lruvec, idx,-1 ); -} - -static inline void __inc_lruvec_page_state (struct page *page, -enum node_stat_item idx) -{ -__mod_lruvec_page_state (page, idx,1 ); -} - -static inline void __dec_lruvec_page_state (struct page *page, -enum node_stat_item idx) -{ -__mod_lruvec_page_state (page, idx,-1 ); -} -static inline void __inc_lruvec_kmem_state (void *p,enum node_stat_item idx) {__mod_lruvec_kmem_state (p, idx,1 );
@@ -1370,30 +1283,6 @@ static inline void dec_memcg_page_state(mod_memcg_page_state (page, idx,-1 ); } -static inline void inc_lruvec_state (struct lruvec *lruvec, -enum node_stat_item idx) -{ -mod_lruvec_state (lruvec, idx,1 ); -} - -static inline void dec_lruvec_state (struct lruvec *lruvec, -enum node_stat_item idx) -{ -mod_lruvec_state (lruvec, idx,-1 ); -} - -static inline void inc_lruvec_page_state (struct page *page, -enum node_stat_item idx) -{ -mod_lruvec_page_state (page, idx,1 ); -} - -static inline void dec_lruvec_page_state (struct page *page, -enum node_stat_item idx) -{ -mod_lruvec_page_state (page, idx,-1 ); -} -static inline struct lruvec *parent_lruvec (struct lruvec *lruvec) {struct mem_cgroup *memcg;
include/linux/vmstat.h renamed from include/linux/vmstat.h~mm-move-lruvec-stats-update-functions-to-vmstath +104 -0
108 lines not on this page · raw message
mm/memcontrol.c renamed from mm/memcontrol.c~mm-move-lruvec-stats-update-functions-to-vmstath +17 -0
@@ -853,6 +853,23 @@ void __mod_lruvec_state(struct lruvec *l__mod_memcg_lruvec_state (lruvec, idx, val); } +void __mod_lruvec_page_state (struct page *page,enum node_stat_item idx, +int val) +{ +struct page *head =compound_head (page);/* rmap on tail pages */ +pg_data_t *pgdat =page_pgdat (page); +struct lruvec *lruvec; + +/* Untracked pages have no memcg, no lruvec. Update only the node */ +if (!head->mem_cgroup) { +__mod_node_page_state (pgdat, idx, val); +return ; + } + + lruvec =mem_cgroup_lruvec (head->mem_cgroup, pgdat); +__mod_lruvec_state (lruvec, idx, val); +} +void __mod_lruvec_kmem_state (void *p,enum node_stat_item idx,int val) {pg_data_t *pgdat =page_pgdat (virt_to_page (p));
_
Andrew Morton
maintainerPATCH 72/200 mm: memcontrol: account pagetables per node
In reply to Andrew MortonFrom: Shakeel Butt <[email protected]>
Subject: mm: memcontrol: account pagetables per node
For many workloads, pagetable consumption is significant and it makes sense to expose it in the memory.stat for the memory cgroups. However at the moment, the pagetables are accounted per-zone. Converting them to per-node and using the right interface will correctly account for the memory cgroups as well.
---
Documentation/admin-guide/cgroup-v2.rst | 3 +++ arch/nds32/mm/mm-nds32.c | 6 +++--- drivers/base/node.c | 2 +- fs/proc/meminfo.c | 2 +- include/linux/mm.h | 8 ++++---- include/linux/mmzone.h | 2 +- mm/memcontrol.c | 2 ++ mm/page_alloc.c | 6 +++--- mm/vmstat.c | 2 +- 9 files changed, 19 insertions(+), 14 deletions(-)
arch/nds32/mm/mm-nds32.c renamed from arch/nds32/mm/mm-nds32.c~mm-memcontrol-account-pagetables-per-node +3 -3
@@ -34,8 +34,8 @@ pgd_t *pgd_alloc(struct mm_struct *mm)cpu_dcache_wb_range ((unsigned long )new_pgd, (unsigned long )new_pgd +PTRS_PER_PGD *sizeof (pgd_t)); -inc_zone_page_state (virt_to_page ((unsigned long *)new_pgd), -NR_PAGETABLE ); +inc_lruvec_page_state (virt_to_page ((unsigned long *)new_pgd), +NR_PAGETABLE );return new_pgd; }
@@ -59,7 +59,7 @@ void pgd_free(struct mm_struct *mm, pgd_ pte =pmd_page (*pmd);pmd_clear (pmd); -dec_zone_page_state (virt_to_page ((unsigned long *)pgd),NR_PAGETABLE ); +dec_lruvec_page_state (virt_to_page ((unsigned long *)pgd),NR_PAGETABLE );pte_free (mm, pte);mm_dec_nr_ptes (mm);pmd_free (mm, pmd);
Documentation/admin-guide/cgroup-v2.rst renamed from Documentation/admin-guide/cgroup-v2.rst~mm-memcontrol-account-pagetables-per-node +3 -0
@@ -1274,6 +1274,9 @@ PAGE_SIZE multiple when read back. kernel_stack Amount of memory allocated to kernel stacks. + pagetables + Amount of memory allocated for page tables. + percpu(npn) Amount of memory used for storing per-cpu kernel data structures.
drivers/base/node.c renamed from drivers/base/node.c~mm-memcontrol-account-pagetables-per-node +1 -1
@@ -450,7 +450,7 @@ static ssize_t node_read_meminfo(struct#ifdef CONFIG_SHADOW_CALL_STACK nid,node_page_state (pgdat,NR_KERNEL_SCS_KB ), #endif - nid,K (sum_zone_node_page_state (nid,NR_PAGETABLE )), + nid,K (node_page_state (pgdat,NR_PAGETABLE )), nid,0UL , nid,K (sum_zone_node_page_state (nid,NR_BOUNCE )), nid, K(node_page_state(pgdat, NR_WRITEBACK_TEMP)),
fs/proc/meminfo.c renamed from fs/proc/meminfo.c~mm-memcontrol-account-pagetables-per-node +1 -1
@@ -107,7 +107,7 @@ static int meminfo_proc_show(struct seq_ global_node_page_state(NR_KERNEL_SCS_KB));#endif show_val_kb (m,"PageTables: " , -global_zone_page_state (NR_PAGETABLE )); +global_node_page_state (NR_PAGETABLE ));show_val_kb (m,"NFS_Unstable: " ,0 ); show_val_kb(m, "Bounce: ",
include/linux/mm.h renamed from include/linux/mm.h~mm-memcontrol-account-pagetables-per-node +4 -4
@@ -2203,7 +2203,7 @@ static inline bool pgtable_pte_page_ctorif (!ptlock_init (page))return false;__SetPageTable (page); -inc_zone_page_state (page,NR_PAGETABLE ); +inc_lruvec_page_state (page,NR_PAGETABLE );return true; }
@@ -2211,7 +2211,7 @@ static inline void pgtable_pte_page_dtor {ptlock_free (page);__ClearPageTable (page); -dec_zone_page_state (page,NR_PAGETABLE ); +dec_lruvec_page_state (page,NR_PAGETABLE ); }#define pte_offset_map_lock (mm, pmd, address, ptlp) \
@@ -2298,7 +2298,7 @@ static inline bool pgtable_pmd_page_ctorif (!pmd_ptlock_init (page))return false;__SetPageTable (page); -inc_zone_page_state (page,NR_PAGETABLE ); +inc_lruvec_page_state (page,NR_PAGETABLE );return true; }
@@ -2306,7 +2306,7 @@ static inline void pgtable_pmd_page_dtor {pmd_ptlock_free (page);__ClearPageTable (page); -dec_zone_page_state (page,NR_PAGETABLE ); +dec_lruvec_page_state (page,NR_PAGETABLE ); }/*
include/linux/mmzone.h renamed from include/linux/mmzone.h~mm-memcontrol-account-pagetables-per-node +1 -1
@@ -152,7 +152,6 @@ enum zone_stat_item {NR_ZONE_UNEVICTABLE ,NR_ZONE_WRITE_PENDING ,/* Count of dirty, writeback and unstable pages */ NR_MLOCK ,/* mlock()ed pages found and moved off LRU */ -NR_PAGETABLE ,/* used for pagetables */ /* Second 128 byte cacheline */ NR_BOUNCE , #if IS_ENABLED(CONFIG_ZSMALLOC)
@@ -207,6 +206,7 @@ enum node_stat_item {#if IS_ENABLED (CONFIG_SHADOW_CALL_STACK )NR_KERNEL_SCS_KB ,/* measured in KiB */ #endif +NR_PAGETABLE ,/* used for pagetables */ NR_VM_NODE_STAT_ITEMS };
mm/memcontrol.c renamed from mm/memcontrol.c~mm-memcontrol-account-pagetables-per-node +2 -0
@@ -869,6 +869,7 @@ void __mod_lruvec_page_state(struct page lruvec =mem_cgroup_lruvec (head->mem_cgroup, pgdat);__mod_lruvec_state (lruvec, idx, val); } +EXPORT_SYMBOL (__mod_lruvec_page_state);void __mod_lruvec_kmem_state (void *p,enum node_stat_item idx,int val) {
@@ -1493,6 +1494,7 @@ static struct memory_stat memory_stats[] { "anon", PAGE_SIZE, NR_ANON_MAPPED }, { "file", PAGE_SIZE, NR_FILE_PAGES }, { "kernel_stack", 1024, NR_KERNEL_STACK_KB }, + { "pagetables", PAGE_SIZE, NR_PAGETABLE }, { "percpu", 1, MEMCG_PERCPU_B }, { "sock", PAGE_SIZE, MEMCG_SOCK }, { "shmem", PAGE_SIZE, NR_SHMEM },
mm/page_alloc.c renamed from mm/page_alloc.c~mm-memcontrol-account-pagetables-per-node +3 -3
@@ -5465,7 +5465,7 @@ void show_free_areas(unsigned int filterglobal_node_page_state_pages (NR_SLAB_UNRECLAIMABLE_B ),global_node_page_state (NR_FILE_MAPPED ),global_node_page_state (NR_SHMEM ), -global_zone_page_state (NR_PAGETABLE ), +global_node_page_state (NR_PAGETABLE ),global_zone_page_state (NR_BOUNCE ),global_zone_page_state (NR_FREE_PAGES ), free_pcp,
@@ -5497,6 +5497,7 @@ void show_free_areas(unsigned int filter#ifdef CONFIG_SHADOW_CALL_STACK " shadow_call_stack:%lukB" #endif +" pagetables:%lukB" " all_unreclaimable? %s" "\n" , pgdat->node_id,
@@ -5522,6 +5523,7 @@ void show_free_areas(unsigned int filter#ifdef CONFIG_SHADOW_CALL_STACK node_page_state (pgdat,NR_KERNEL_SCS_KB ), #endif +K (node_page_state (pgdat,NR_PAGETABLE )), pgdat->kswapd_failures >=MAX_RECLAIM_RETRIES ? "yes" : "no"); }
@@ -5553,7 +5555,6 @@ void show_free_areas(unsigned int filter" present:%lukB" " managed:%lukB" " mlocked:%lukB" -" pagetables:%lukB" " bounce:%lukB" " free_pcp:%lukB" " local_pcp:%ukB"
@@ -5574,7 +5575,6 @@ void show_free_areas(unsigned int filterK (zone->present_pages),K (zone_managed_pages (zone)),K (zone_page_state (zone,NR_MLOCK )), -K (zone_page_state (zone,NR_PAGETABLE )),K (zone_page_state (zone,NR_BOUNCE )),K (free_pcp), K(this_cpu_read(zone->pageset->pcp.count)),
mm/vmstat.c renamed from mm/vmstat.c~mm-memcontrol-account-pagetables-per-node +1 -1
@@ -1157,7 +1157,6 @@ const char * const vmstat_text[] = {"nr_zone_unevictable" ,"nr_zone_write_pending" ,"nr_mlock" , -"nr_page_table_pages" ,"nr_bounce" , #if IS_ENABLED(CONFIG_ZSMALLOC) "nr_zspages",
@@ -1215,6 +1214,7 @@ const char * const vmstat_text[] = {#if IS_ENABLED (CONFIG_SHADOW_CALL_STACK )"nr_shadow_call_stack" , #endif +"nr_page_table_pages" ,/* enum writeback_stat_item counters */ "nr_dirty_threshold",
_
Andrew Morton
maintainerPATCH 73/200 xen/unpopulated-alloc: consolidate pgmap manipulation
In reply to Andrew MortonFrom: Dan Williams <[email protected]>
Subject: xen/unpopulated-alloc: consolidate pgmap manipulation
Cleanup fill_list() to keep all the pgmap manipulations in a single location of the function. Update the exit unwind path accordingly.
---
drivers/xen/unpopulated-alloc.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/xen/unpopulated-alloc.c renamed from drivers/xen/unpopulated-alloc.c~xen-unpopulated-alloc-consolidate-pgmap-manipulation +7 -7
@@ -27,11 +27,6 @@ static int fill_list(unsigned int nr_pagif (!res)return -ENOMEM ; - pgmap =kzalloc (sizeof (*pgmap),GFP_KERNEL ); -if (!pgmap) - goto err_pgmap; - - pgmap->type =MEMORY_DEVICE_GENERIC ; res->name ="Xen scratch" ; res->flags =IORESOURCE_MEM |IORESOURCE_BUSY ;
@@ -43,6 +38,11 @@ static int fill_list(unsigned int nr_pag goto err_resource; } + pgmap =kzalloc (sizeof (*pgmap),GFP_KERNEL ); +if (!pgmap) + goto err_pgmap; + + pgmap->type =MEMORY_DEVICE_GENERIC ; pgmap->range = (struct range ) { .start = res->start, .end = res->end,
@@ -92,10 +92,10 @@ static int fill_list(unsigned int nr_pagreturn 0 ; err_memremap: -release_resource (res); -err_resource:kfree (pgmap); err_pgmap: +release_resource (res); +err_resource:kfree (res);return ret; }
_
Andrew Morton
maintainerPATCH 74/200 kselftests: vm: add mremap tests
In reply to Andrew MortonFrom: Kalesh Singh <[email protected]>
Subject: kselftests: vm: add mremap tests
Patch series "Speed up mremap on large regions", v4.
mremap time can be optimized by moving entries at the PMD/PUD level if the source and destination addresses are PMD/PUD-aligned and PMD/PUD-sized. Enable moving at the PMD and PUD levels on arm64 and x86. Other architectures where this type of move is supported and known to be safe can also opt-in to these optimizations by enabling HAVE_MOVE_PMD and HAVE_MOVE_PUD.
Observed Performance Improvements for remapping a PUD-aligned 1GB-sized region on x86 and arm64:
- HAVE_MOVE_PMD is already enabled on x86 : N/A
- Enabling HAVE_MOVE_PUD on x86 : ~13x speed up
- Enabling HAVE_MOVE_PMD on arm64 : ~ 8x speed up
- Enabling HAVE_MOVE_PUD on arm64 : ~19x speed up
Altogether, HAVE_MOVE_PMD and HAVE_MOVE_PUD give a total of ~150x speed up on arm64.
This patch (of 4):
Test mremap on regions of various sizes and alignments and validate data after remapping. Also provide total time for remapping the region which is useful for performance comparison of the mremap optimizations that move pages at the PMD/PUD levels if HAVE_MOVE_PMD and/or HAVE_MOVE_PUD are enabled.
---
tools/testing/selftests/vm/.gitignore | 1 tools/testing/selftests/vm/Makefile | 1 tools/testing/selftests/vm/mremap_test.c | 344 +++++++++++++++++++++ tools/testing/selftests/vm/run_vmtests | 11 4 files changed, 357 insertions(+)
tools/testing/selftests/vm/.gitignore renamed from tools/testing/selftests/vm/.gitignore~kselftests-vm-add-mremap-tests +1 -0
@@ -8,6 +8,7 @@ thuge-gen compaction_test mlock2-tests mremap_dontunmap +mremap_test on-fault-limit transhuge-stress protection_keys
tools/testing/selftests/vm/Makefile renamed from tools/testing/selftests/vm/Makefile~kselftests-vm-add-mremap-tests +1 -0
@@ -37,6 +37,7 @@ TEST_GEN_FILES += map_populate TEST_GEN_FILES += mlock-random-test TEST_GEN_FILES += mlock2-tests TEST_GEN_FILES += mremap_dontunmap +TEST_GEN_FILES += mremap_test TEST_GEN_FILES += on-fault-limit TEST_GEN_FILES += thuge-gen TEST_GEN_FILES += transhuge-stress
tools/testing/selftests/vm/mremap_test.c new file +344 -0
344 lines not on this page · raw message
tools/testing/selftests/vm/run_vmtests renamed from tools/testing/selftests/vm/run_vmtests~kselftests-vm-add-mremap-tests +11 -0
@@ -253,6 +253,17 @@ else echo "[PASS]" fi +echo "-------------------" +echo "running mremap_test" +echo "-------------------" +./mremap_test +if [ $? -ne 0 ]; then + echo "[FAIL]" + exitcode=1 +else + echo "[PASS]" +fi + echo "-----------------" echo "running thuge-gen" echo "-----------------"
_
Andrew Morton
maintainerPATCH 75/200 mm: speedup mremap on 1GB or larger regions
In reply to Andrew MortonFrom: Kalesh Singh <[email protected]>
Subject: mm: speedup mremap on 1GB or larger regions
Android needs to move large memory regions for garbage collection. The GC requires moving physical pages of multi-gigabyte heap using mremap. During this move, the application threads have to be paused for correctness. It is critical to keep this pause as short as possible to avoid jitters during user interaction.
Optimize mremap for >= 1GB-sized regions by moving at the PUD/PGD level if the source and destination addresses are PUD-aligned. For CONFIG_PGTABLE_LEVELS == 3, moving at the PUD level in effect moves PGD entries, since the PUD entry is “folded back” onto the PGD entry. Add HAVE_MOVE_PUD so that architectures where moving at the PUD level isn't supported/tested can turn this off by not selecting the config.
---
arch/Kconfig | 7 + mm/mremap.c | 230 ++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 197 insertions(+), 40 deletions(-)
arch/Kconfig renamed from arch/Kconfig~mm-speedup-mremap-on-1gb-or-larger-regions +7 -0
@@ -648,6 +648,13 @@ config HAVE_IRQ_TIME_ACCOUNTING Archs need to ensure they use a high enough resolution clock to support irq time accounting and then call enable_sched_clock_irqtime(). +config HAVE_MOVE_PUD + bool + help + Architectures that select this are able to move page tables at the + PUD level. If there are only 3 page table levels, the move effectively + happens at the PGD level. + config HAVE_MOVE_PMD bool help
mm/mremap.c renamed from mm/mremap.c~mm-speedup-mremap-on-1gb-or-larger-regions +190 -40
294 lines not on this page · raw message
_
Re: [patch 075/200] mm: speedup mremap on 1GB or larger regions
Quoted 9 lines · Andrew Morton
From: Kalesh Singh <[email protected]>
Subject: mm: speedup mremap on 1GB or larger regionsAndroid needs to move large memory regions for garbage collection. The GC requires moving physical pages of multi-gigabyte heap using mremap. During this move, the application threads have to be paused for correctness. It is critical to keep this pause as short as possible to avoid jitters during user interaction.
It would have been good to add a pointer to the PMD case we did earlier..
Also, a few comments on the actual performance in practice would be nice. Does this actually *trigger* on Android in practice?
I can well imagine the PMD case triggering easily, but are there real-life Android loads that really do gigabyte heaps? That sounds a bit odd to me.
So I don't have any complaints about the patch, but I just wonder how _realistic_ this actually is, particularly the alleged 13x improvement in timing...
Linus
Re: [patch 075/200] mm: speedup mremap on 1GB or larger regions
Quoted 17 lines · Linus Torvalds
Quoted 9 lines · Andrew Morton
From: Kalesh Singh <[email protected]>
Subject: mm: speedup mremap on 1GB or larger regionsAndroid needs to move large memory regions for garbage collection. The GC requires moving physical pages of multi-gigabyte heap using mremap. During this move, the application threads have to be paused for correctness. It is critical to keep this pause as short as possible to avoid jitters during user interaction.
It would have been good to add a pointer to the PMD case we did earlier..
Also, a few comments on the actual performance in practice would be nice. Does this actually *trigger* on Android in practice?
Quoted 8 lines
I can well imagine the PMD case triggering easily, but are there real-life Android loads that really do gigabyte heaps? That sounds a bit odd to me.
So I don't have any complaints about the patch, but I just wonder how _realistic_ this actually is, particularly the alleged 13x improvement in timing...
Hi Linus,
The new GC for Android requires moving the Java heap pages to a separate location during a stop-the-world pause (when application threads are paused). Once this is done, with the help of userfaultfd, the heap can be concurrently compacted while application threads are making progress.
Given that Android apps are highly susceptible to response time, we need this pause to be as small as possible (not more than a few microseconds). The dominating factor during this pause is the mremap operation and therefore this optimization is essential.
As of today, the Java heaps on Android are up to 1GB in virtual memory size. However, the new GC algorithm makes it multi-gigabyte. Even though the heap consumption in terms of physical memory is not going to be more than a few hundred MBs, the physical pages will be scattered across the entire virtual memory range. Therefore, this optimization will reduce the number of iterations required to finish the mremap operation.
Example scenario:
Let's say that our heap is 8GB in virtual memory size and 128MB (a realistic heap occupancy) in physical memory size at the time of a mremap operation. That means we have 32K 4KB physical pages in there.
A) Worst case scenario: every 4KB physical page is mapped to a unique PMD entry
1) With only the PMD optimization the loop will make 32K iterations.
2) With the PUD optimization the loop will make 8 iterations.
B) Best case scenario: all pages are compacted in one corner of the heap, then
1) With only the PMD optimization the loop will make 64 iterations.
2) With the PUD optimization the loop will make only 1 iteration.
Even in the best case we are reducing the number of iterations by 64x. The optimization will be useful even if not all of the virtual address range is mapped.
Thanks,
Kalesh
Quoted 1 line
Linus
Andrew Morton
maintainerPATCH 76/200 arm64: mremap speedup - enable HAVE_MOVE_PUD
In reply to Andrew MortonFrom: Kalesh Singh <[email protected]>
Subject: arm64: mremap speedup - enable HAVE_MOVE_PUD
HAVE_MOVE_PUD enables remapping pages at the PUD level if both the source and destination addresses are PUD-aligned.
With HAVE_MOVE_PUD enabled it can be inferred that there is approximately a 19x improvement in performance on arm64. (See data below).
------- Test Results ---------
The following results were obtained using a 5.4 kernel, by remapping a PUD-aligned, 1GB sized region to a PUD-aligned destination. The results from 10 iterations of the test are given below:
Total mremap times for 1GB data on arm64. All times are in nanoseconds.
Control HAVE_MOVE_PUD
1247761 74271 1219896 46771 1094792 59687 1227760 48385 1043698 76666 1101771 50365 1159896 52500 1143594 75261 1025833 61354 1078125 48697
1134312.6 59395.7 <-- Mean time in nanoseconds
A 1GB mremap completion time drops from ~1.1 milliseconds to ~59 microseconds on arm64. (~19x speed up).
---
arch/arm64/Kconfig | 1 + arch/arm64/include/asm/pgtable.h | 1 + 2 files changed, 2 insertions(+)
arch/arm64/include/asm/pgtable.h renamed from arch/arm64/include/asm/pgtable.h~arm64-mremap-speedup-enable-have_move_pud +1 -0
@@ -462,6 +462,7 @@ static inline pmd_t pmd_mkdevmap(pmd_t p#define pfn_pud (pfn,prot) __pud(__phys_to_pud_val((phys_addr_t)(pfn) << PAGE_SHIFT) | pgprot_val(prot))#define set_pmd_at (mm, addr, pmdp, pmd) set_pte_at(mm, addr, (pte_t *)pmdp, pmd_pte(pmd)) +#define set_pud_at (mm, addr, pudp, pud) set_pte_at(mm, addr, (pte_t *)pudp, pud_pte(pud))#define __p4d_to_phys (p4d) __pte_to_phys(p4d_pte(p4d))#define __phys_to_p4d_val (phys) __phys_to_pte_val(phys)
arch/arm64/Kconfig renamed from arch/arm64/Kconfig~arm64-mremap-speedup-enable-have_move_pud +1 -0
@@ -125,6 +125,7 @@ config ARM64 select HANDLE_DOMAIN_IRQ select HARDIRQS_SW_RESEND select HAVE_MOVE_PMD + select HAVE_MOVE_PUD select HAVE_PCI select HAVE_ACPI_APEI if (ACPI && EFI) select HAVE_ALIGNED_STRUCT_PAGE if SLUB
_
Andrew Morton
maintainerPATCH 77/200 x86: mremap speedup - Enable HAVE_MOVE_PUD
In reply to Andrew MortonFrom: Kalesh Singh <[email protected]>
Subject: x86: mremap speedup - Enable HAVE_MOVE_PUD
HAVE_MOVE_PUD enables remapping pages at the PUD level if both the source and destination addresses are PUD-aligned.
With HAVE_MOVE_PUD enabled it can be inferred that there is approximately a 13x improvement in performance on x86. (See data below).
------- Test Results ---------
The following results were obtained using a 5.4 kernel, by remapping a PUD-aligned, 1GB sized region to a PUD-aligned destination. The results from 10 iterations of the test are given below:
Total mremap times for 1GB data on x86. All times are in nanoseconds.
Control HAVE_MOVE_PUD
180394 15089 235728 14056 238931 25741 187330 13838 241742 14187 177925 14778 182758 14728 160872 14418 205813 15107 245722 13998
205721.5 15594 <-- Mean time in nanoseconds
A 1GB mremap completion time drops from ~205 microseconds to ~15 microseconds on x86. (~13x speed up).
---
arch/x86/Kconfig | 1 + 1 file changed, 1 insertion(+)
arch/x86/Kconfig renamed from arch/x86/Kconfig~x86-mremap-speedup-enable-have_move_pud +1 -0
@@ -199,6 +199,7 @@ config X86 select HAVE_MIXED_BREAKPOINTS_REGS select HAVE_MOD_ARCH_SPECIFIC select HAVE_MOVE_PMD + select HAVE_MOVE_PUD select HAVE_NMI select HAVE_OPROFILE select HAVE_OPTPROBES
_
Andrew Morton
maintainerPATCH 78/200 mm: cleanup: remove unused tsk arg from __access_remote_vm
In reply to Andrew MortonFrom: John Hubbard <[email protected]>
Subject: mm: cleanup: remove unused tsk arg from __access_remote_vm
Despite a comment that said that page fault accounting would be charged to whatever task_struct* was passed into __access_remote_vm(), the tsk argument was actually unused.
Making page fault accounting actually use this task struct is quite a project, so there is no point in keeping the tsk argument.
Delete both the comment, and the argument.
---
include/linux/mm.h | 4 ++-- kernel/ptrace.c | 2 +- mm/memory.c | 11 +++++------ mm/nommu.c | 8 ++++---- 4 files changed, 12 insertions(+), 13 deletions(-)
include/linux/mm.h renamed from include/linux/mm.h~mm-cleanup-remove-unused-tsk-arg-from-__access_remote_vm +2 -2
@@ -1716,8 +1716,8 @@ extern int access_process_vm(struct task void *buf, int len, unsigned int gup_flags);extern int access_remote_vm (struct mm_struct *mm,unsigned long addr,void *buf,int len,unsigned int gup_flags); -extern int __access_remote_vm (struct task_struct *tsk,struct mm_struct *mm, -unsigned long addr,void *buf,int len,unsigned int gup_flags); +extern int __access_remote_vm (struct mm_struct *mm,unsigned long addr, +void *buf,int len,unsigned int gup_flags); long get_user_pages_remote(struct mm_struct *mm, unsigned long start, unsigned long nr_pages,
kernel/ptrace.c renamed from kernel/ptrace.c~mm-cleanup-remove-unused-tsk-arg-from-__access_remote_vm +1 -1
@@ -57,7 +57,7 @@ int ptrace_access_vm(struct task_structreturn 0 ; } - ret =__access_remote_vm (tsk, mm, addr, buf, len, gup_flags); + ret =__access_remote_vm (mm, addr, buf, len, gup_flags);mmput (mm);return ret;
mm/memory.c renamed from mm/memory.c~mm-cleanup-remove-unused-tsk-arg-from-__access_remote_vm +5 -6
@@ -4885,11 +4885,10 @@ EXPORT_SYMBOL_GPL(generic_access_phys);#endif /* -* Access another process' address space as given in mm. If non-NULL, use the -* given task for page fault accounting. +* Access another process' address space as given in mm. */ -int __access_remote_vm (struct task_struct *tsk,struct mm_struct *mm, -unsigned long addr,void *buf,int len,unsigned int gup_flags) +int __access_remote_vm (struct mm_struct *mm,unsigned long addr,void *buf, +int len,unsigned int gup_flags) {struct vm_area_struct *vma;void *old_buf = buf;
@@ -4966,7 +4965,7 @@ int __access_remote_vm(struct task_strucint access_remote_vm (struct mm_struct *mm,unsigned long addr,void *buf,int len,unsigned int gup_flags) { -return __access_remote_vm (NULL , mm, addr, buf, len, gup_flags); +return __access_remote_vm (mm, addr, buf, len, gup_flags); }/*
@@ -4984,7 +4983,7 @@ int access_process_vm(struct task_structif (!mm)return 0 ; - ret =__access_remote_vm (tsk, mm, addr, buf, len, gup_flags); + ret =__access_remote_vm (mm, addr, buf, len, gup_flags);mmput (mm);
mm/nommu.c renamed from mm/nommu.c~mm-cleanup-remove-unused-tsk-arg-from-__access_remote_vm +4 -4
@@ -1675,8 +1675,8 @@ void filemap_map_pages(struct vm_fault * }EXPORT_SYMBOL (filemap_map_pages); -int __access_remote_vm (struct task_struct *tsk,struct mm_struct *mm, -unsigned long addr,void *buf,int len,unsigned int gup_flags) +int __access_remote_vm (struct mm_struct *mm,unsigned long addr,void *buf, +int len,unsigned int gup_flags) {struct vm_area_struct *vma;int write = gup_flags &FOLL_WRITE ;
@@ -1722,7 +1722,7 @@ int __access_remote_vm(struct task_strucint access_remote_vm (struct mm_struct *mm,unsigned long addr,void *buf,int len,unsigned int gup_flags) { -return __access_remote_vm (NULL , mm, addr, buf, len, gup_flags); +return __access_remote_vm (mm, addr, buf, len, gup_flags); }/*
@@ -1741,7 +1741,7 @@ int access_process_vm(struct task_structif (!mm)return 0 ; - len =__access_remote_vm (tsk, mm, addr, buf, len, gup_flags); + len =__access_remote_vm (mm, addr, buf, len, gup_flags);mmput (mm);return len;
_
Andrew Morton
maintainerPATCH 79/200 mm/mapping_dirty_helpers: enhance the kernel-doc markups
In reply to Andrew MortonFrom: Alex Shi <[email protected]>
Subject: mm/mapping_dirty_helpers: enhance the kernel-doc markups
Add and change parameter explanation for wp_pte and clean_record_pte, to avoid W1 warning:mm/mapping_dirty_helpers.c:34: warning: Function parameter or member 'end' not described in 'wp_pte' mm/mapping_dirty_helpers.c:88: warning: Function parameter or member 'end' not described in 'clean_record_pte'
---
mm/mapping_dirty_helpers.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
mm/mapping_dirty_helpers.c renamed from mm/mapping_dirty_helpers.c~mm-mapping_dirty_helpers-enhance-the-kernel-doc-markups +4 -2
@@ -23,7 +23,8 @@ struct wp_walk {/** * wp_pte - Write-protect a pte * @pte: Pointer to the pte -* @addr: The virtual page address +* @addr: The start of protecting virtual address +* @end: The end of protecting virtual address * @walk: pagetable walk callback argument * * The function write-protects a pte and records the range in
@@ -74,7 +75,8 @@ struct clean_walk {* clean_record_pte - Clean a pte and record its address space offset in a * bitmap * @pte: Pointer to the pte -* @addr: The virtual page address +* @addr: The start of virtual address to be clean +* @end: The end of virtual address to be clean * @walk: pagetable walk callback argument * * The function cleans a pte and records the range in
_
Andrew Morton
maintainerPATCH 80/200 mm/page_vma_mapped.c: add colon to fix kernel-doc markups error for check_pte
In reply to Andrew MortonFrom: Alex Shi <[email protected]>
Subject: mm/page_vma_mapped.c: add colon to fix kernel-doc markups error for check_pte
check_pte() needs a correct colon for kernel-doc markup, otherwise, gcc has the following warning for W=1, mm/page_vma_mapped.c:86: warning:
Function parameter or member 'pvmw' not described in 'check_pte'
---
mm/page_vma_mapped.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
mm/page_vma_mapped.c renamed from mm/page_vma_mapped.c~mm-add-colon-to-fix-kernel-doc-markups-error-for-check_pte +5 -4
@@ -66,18 +66,19 @@ static inline bool pfn_is_match(struct p/** * check_pte - check if @pvmw->page is mapped at the @pvmw->pte +* @pvmw: page_vma_mapped_walk struct, includes a pair pte and page for checking * * page_vma_mapped_walk() found a place where @pvmw->page is *potentially* * mapped. check_pte() has to validate this. * -* @pvmw->pte may point to empty PTE, swap PTE or PTE pointing to arbitrary -* page. +* pvmw->pte may point to empty PTE, swap PTE or PTE pointing to +* arbitrary page. * * If PVMW_MIGRATION flag is set, returns true if @pvmw->pte contains migration * entry that points to @pvmw->page or any subpage in case of THP. * -* If PVMW_MIGRATION flag is not set, returns true if @pvmw->pte points to -* @pvmw->page or any subpage in case of THP. +* If PVMW_MIGRATION flag is not set, returns true if pvmw->pte points to +* pvmw->page or any subpage in case of THP. * * Otherwise, return false. *
_
Andrew Morton
maintainerPATCH 81/200 mm: mmap_lock: add tracepoints around lock acquisition
In reply to Andrew MortonFrom: Axel Rasmussen <[email protected]>
Subject: mm: mmap_lock: add tracepoints around lock acquisition
The goal of these tracepoints is to be able to debug lock contention issues. This lock is acquired on most (all?) mmap / munmap / page fault operations, so a multi-threaded process which does a lot of these can experience significant contention.
We trace just before we start acquisition, when the acquisition returns (whether it succeeded or not), and when the lock is released (or downgraded). The events are broken out by lock type (read / write).
The events are also broken out by memcg path. For container-based workloads, users often think of several processes in a memcg as a single logical "task", so collecting statistics at this level is useful.
The end goal is to get latency information. This isn't directly included in the trace events. Instead, users are expected to compute the time between "start locking" and "acquire returned", using e.g. synthetic events or BPF. The benefit we get from this is simpler code.
Because we use tracepoint_enabled() to decide whether or not to trace, this patch has effectively no overhead unless tracepoints are enabled at runtime. If tracepoints are enabled, there is a performance impact, but how much depends on exactly what e.g. the BPF program does.
---
include/linux/mmap_lock.h | 94 +++++++++++ include/trace/events/mmap_lock.h | 107 +++++++++++++ mm/Makefile | 2 mm/mmap_lock.c | 230 +++++++++++++++++++++++++++++ 4 files changed, 427 insertions(+), 6 deletions(-)
include/linux/mmap_lock.h renamed from include/linux/mmap_lock.h~mmap_lock-add-tracepoints-around-lock-acquisition +89 -5
@@ -1,11 +1,65 @@#ifndef _LINUX_MMAP_LOCK_H#define _LINUX_MMAP_LOCK_H +#include <linux/lockdep.h> +#include <linux/mm_types.h> #include <linux/mmdebug.h> +#include <linux/rwsem.h> +#include <linux/tracepoint-defs.h> +#include <linux/types.h> #define MMAP_LOCK_INITIALIZER (name) \ .mmap_lock = __RWSEM_INITIALIZER((name).mmap_lock), +DECLARE_TRACEPOINT (mmap_lock_start_locking); +DECLARE_TRACEPOINT (mmap_lock_acquire_returned); +DECLARE_TRACEPOINT (mmap_lock_released); + +#ifdef CONFIG_TRACING + +void __mmap_lock_do_trace_start_locking (struct mm_struct *mm,bool write); +void __mmap_lock_do_trace_acquire_returned (struct mm_struct *mm,bool write, +bool success); +void __mmap_lock_do_trace_released (struct mm_struct *mm,bool write); + +static inline void __mmap_lock_trace_start_locking (struct mm_struct *mm, +bool write) +{ +if (tracepoint_enabled (mmap_lock_start_locking)) +__mmap_lock_do_trace_start_locking (mm, write); +} + +static inline void __mmap_lock_trace_acquire_returned (struct mm_struct *mm, +bool write,bool success) +{ +if (tracepoint_enabled (mmap_lock_acquire_returned)) +__mmap_lock_do_trace_acquire_returned (mm, write, success); +} + +static inline void __mmap_lock_trace_released (struct mm_struct *mm,bool write) +{ +if (tracepoint_enabled (mmap_lock_released)) +__mmap_lock_do_trace_released (mm, write); +} + +#else /* !CONFIG_TRACING */ + +static inline void __mmap_lock_trace_start_locking (struct mm_struct *mm, +bool write) +{ +} + +static inline void __mmap_lock_trace_acquire_returned (struct mm_struct *mm, +bool write,bool success) +{ +} + +static inline void __mmap_lock_trace_released (struct mm_struct *mm,bool write) +{ +} + +#endif /* CONFIG_TRACING */ +static inline void mmap_init_lock (struct mm_struct *mm) {init_rwsem (&mm->mmap_lock);
@@ -13,57 +67,86 @@ static inline void mmap_init_lock(structstatic inline void mmap_write_lock (struct mm_struct *mm) { +__mmap_lock_trace_start_locking (mm, true);down_write (&mm->mmap_lock); +__mmap_lock_trace_acquire_returned (mm, true, true); }static inline void mmap_write_lock_nested (struct mm_struct *mm,int subclass) { +__mmap_lock_trace_start_locking (mm, true);down_write_nested (&mm->mmap_lock, subclass); +__mmap_lock_trace_acquire_returned (mm, true, true); }static inline int mmap_write_lock_killable (struct mm_struct *mm) { -return down_write_killable (&mm->mmap_lock); +int ret; + +__mmap_lock_trace_start_locking (mm, true); + ret =down_write_killable (&mm->mmap_lock); +__mmap_lock_trace_acquire_returned (mm, true, ret ==0 ); +return ret; }static inline bool mmap_write_trylock (struct mm_struct *mm) { -return down_write_trylock (&mm->mmap_lock) !=0 ; +bool ret; + +__mmap_lock_trace_start_locking (mm, true); + ret =down_write_trylock (&mm->mmap_lock) !=0 ; +__mmap_lock_trace_acquire_returned (mm, true, ret); +return ret; }static inline void mmap_write_unlock (struct mm_struct *mm) {up_write (&mm->mmap_lock); +__mmap_lock_trace_released (mm, true); }static inline void mmap_write_downgrade (struct mm_struct *mm) {downgrade_write (&mm->mmap_lock); +__mmap_lock_trace_acquire_returned (mm, false, true); }static inline void mmap_read_lock (struct mm_struct *mm) { +__mmap_lock_trace_start_locking (mm, false);down_read (&mm->mmap_lock); +__mmap_lock_trace_acquire_returned (mm, false, true); }static inline int mmap_read_lock_killable (struct mm_struct *mm) { -return down_read_killable (&mm->mmap_lock); +int ret; + +__mmap_lock_trace_start_locking (mm, false); + ret =down_read_killable (&mm->mmap_lock); +__mmap_lock_trace_acquire_returned (mm, false, ret ==0 ); +return ret; }static inline bool mmap_read_trylock (struct mm_struct *mm) { -return down_read_trylock (&mm->mmap_lock) !=0 ; +bool ret; + +__mmap_lock_trace_start_locking (mm, false); + ret =down_read_trylock (&mm->mmap_lock) !=0 ; +__mmap_lock_trace_acquire_returned (mm, false, ret); +return ret; }static inline void mmap_read_unlock (struct mm_struct *mm) {up_read (&mm->mmap_lock); +__mmap_lock_trace_released (mm, false); }static inline bool mmap_read_trylock_non_owner (struct mm_struct *mm) { -if (down_read_trylock (&mm->mmap_lock)) { +if (mmap_read_trylock (mm)) {rwsem_release (&mm->mmap_lock.dep_map, _RET_IP_);return true; }
@@ -73,6 +156,7 @@ static inline bool mmap_read_trylock_nonstatic inline void mmap_read_unlock_non_owner (struct mm_struct *mm) {up_read_non_owner (&mm->mmap_lock); +__mmap_lock_trace_released (mm, false); }static inline void mmap_assert_locked (struct mm_struct *mm)
include/trace/events/mmap_lock.h new file +107 -0
107 lines not on this page · raw message
mm/Makefile renamed from mm/Makefile~mmap_lock-add-tracepoints-around-lock-acquisition +1 -1
@@ -52,7 +52,7 @@ obj-y := filemap.o mempool.o oom_kill. mm_init.o percpu.o slab_common.o \ compaction.o vmacache.o \ interval_tree.o list_lru.o workingset.o \ - debug.o gup.o $(mmu-y) + debug.o gup.o mmap_lock.o $(mmu-y) # Give 'page_alloc' its own module-parameter namespace page-alloc-y := page_alloc.o
mm/mmap_lock.c new file +230 -0
230 lines not on this page · raw message
_
Andrew Morton
maintainerPATCH 82/200 sparc: fix handling of page table constructor failure
In reply to Andrew MortonFrom: "Matthew Wilcox (Oracle)" <[email protected]>
Subject: sparc: fix handling of page table constructor failure
The page has just been allocated, so its refcount is 1. free_unref_page() is for use on pages which have a zero refcount. Use __free_page() like the other implementations of pte_alloc_one().
---
arch/sparc/mm/init_64.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/sparc/mm/init_64.c renamed from arch/sparc/mm/init_64.c~sparc-fix-handling-of-page-table-constructor-failure +1 -1
@@ -2894,7 +2894,7 @@ pgtable_t pte_alloc_one(struct mm_structif (!page)return NULL ;if (!pgtable_pte_page_ctor (page)) { -free_unref_page (page); +__free_page (page);return NULL ; }return (pte_t *)page_address (page);
_
Andrew Morton
maintainerPATCH 83/200 mm: move free_unref_page to mm/internal.h
In reply to Andrew MortonFrom: "Matthew Wilcox (Oracle)" <[email protected]>
Subject: mm: move free_unref_page to mm/internal.h
Code outside mm/ should not be calling free_unref_page(). Also move free_unref_page_list().
---
include/linux/gfp.h | 2 -- mm/internal.h | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-)
include/linux/gfp.h renamed from include/linux/gfp.h~mm-move-free_unref_page-to-mm-internalh +0 -2
@@ -580,8 +580,6 @@ void * __meminit alloc_pages_exact_nid(iextern void __free_pages (struct page *page,unsigned int order);extern void free_pages (unsigned long addr,unsigned int order); -extern void free_unref_page (struct page *page); -extern void free_unref_page_list (struct list_head *list);struct page_frag_cache ;extern void __page_frag_cache_drain (struct page *page,unsigned int count);
mm/internal.h renamed from mm/internal.h~mm-move-free_unref_page-to-mm-internalh +3 -0
@@ -199,6 +199,9 @@ extern void post_alloc_hook(struct page gfp_t gfp_flags);extern int user_min_free_kbytes; +extern void free_unref_page (struct page *page); +extern void free_unref_page_list (struct list_head *list); +extern void zone_pcp_update (struct zone *zone);extern void zone_pcp_reset (struct zone *zone);
_
Andrew Morton
maintainerPATCH 84/200 mm/mremap: account memory on do_munmap() failure
In reply to Andrew MortonFrom: Dmitry Safonov <[email protected]>
Subject: mm/mremap: account memory on do_munmap() failure
Patch series "mremap: move_vma() fixes".
This patch (of 6):
move_vma() copies VMA without adding it to account, then unmaps old part of VMA. On failure it unmaps the new VMA. With hacks accounting in munmap is disabled as it's a copy of existing VMA.
Account the memory on munmap() failure which was previously copied into a new VMA.
---
mm/mremap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
mm/mremap.c renamed from mm/mremap.c~mm-mremap-account-memory-on-do_munmap-failure +2 -1
@@ -600,7 +600,8 @@ static unsigned long move_vma(struct vm_if (do_munmap (mm, old_addr, old_len, uf_unmap) <0 ) {/* OOM: unable to split vma, just get accounts right */ -vm_unacct_memory (excess >>PAGE_SHIFT ); +if (vm_flags &VM_ACCOUNT ) +vm_acct_memory (new_len >>PAGE_SHIFT ); excess =0 ; }
_
Andrew Morton
maintainerPATCH 85/200 mm/mremap: for MREMAP_DONTUNMAP check security_vm_enough_memory_mm()
In reply to Andrew MortonFrom: Dmitry Safonov <[email protected]>
Subject: mm/mremap: for MREMAP_DONTUNMAP check security_vm_enough_memory_mm()
Currently memory is accounted post-mremap() with MREMAP_DONTUNMAP, which may break overcommit policy. So, check if there's enough memory before doing actual VMA copy.
Don't unset VM_ACCOUNT on MREMAP_DONTUNMAP. By semantics, such mremap() is actually a memory allocation. That also simplifies the error-path a little.
Also, as it's memory allocation on success don't reset hiwater_vm value.
---
mm/mremap.c | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-)
mm/mremap.c renamed from mm/mremap.c~mm-mremap-for-mremap_dontunmap-check-security_vm_enough_memory_mm +13 -23
@@ -515,11 +515,19 @@ static unsigned long move_vma(struct vm_if (err)return err; +if (unlikely (flags &MREMAP_DONTUNMAP && vm_flags &VM_ACCOUNT )) { +if (security_vm_enough_memory_mm (mm, new_len >>PAGE_SHIFT )) +return -ENOMEM ; + } + new_pgoff = vma->vm_pgoff + ((old_addr - vma->vm_start) >>PAGE_SHIFT ); new_vma =copy_vma (&vma, new_addr, new_len, new_pgoff, &need_rmap_locks); -if (!new_vma) +if (!new_vma) { +if (unlikely (flags &MREMAP_DONTUNMAP && vm_flags &VM_ACCOUNT )) +vm_unacct_memory (new_len >>PAGE_SHIFT );return -ENOMEM ; + } moved_len =move_page_tables (vma, old_addr, new_vma, new_addr, old_len, need_rmap_locks);
@@ -548,7 +556,7 @@ static unsigned long move_vma(struct vm_ }/* Conceal VM_ACCOUNT so old reservation is not undone */ -if (vm_flags &VM_ACCOUNT ) { +if (vm_flags &VM_ACCOUNT && !(flags &MREMAP_DONTUNMAP )) { vma->vm_flags &= ~VM_ACCOUNT ; excess = vma->vm_end - vma->vm_start - old_len; if (old_addr > vma->vm_start &&
@@ -573,34 +581,16 @@ static unsigned long move_vma(struct vm_untrack_pfn_moved (vma);if (unlikely (!err && (flags &MREMAP_DONTUNMAP ))) { -if (vm_flags &VM_ACCOUNT ) { -/* Always put back VM_ACCOUNT since we won't unmap */ - vma->vm_flags |=VM_ACCOUNT ; - -vm_acct_memory (new_len >>PAGE_SHIFT ); - } - -/* -* VMAs can actually be merged back together in copy_vma -* calling merge_vma. This can happen with anonymous vmas -* which have not yet been faulted, so if we were to consider -* this VMA split we'll end up adding VM_ACCOUNT on the -* next VMA, which is completely unrelated if this VMA -* was re-merged. -*/ -if (split && new_vma == vma) - split =0 ; -/* We always clear VM_LOCKED[ONFAULT] on the old vma */ vma->vm_flags &=VM_LOCKED_CLEAR_MASK ;/* Because we won't unmap we don't need to touch locked_vm */ - goto out; +return new_addr; }if (do_munmap (mm, old_addr, old_len, uf_unmap) <0 ) {/* OOM: unable to split vma, just get accounts right */ -if (vm_flags &VM_ACCOUNT ) +if (vm_flags &VM_ACCOUNT && !(flags &MREMAP_DONTUNMAP ))vm_acct_memory (new_len >>PAGE_SHIFT ); excess =0 ; }
@@ -609,7 +599,7 @@ static unsigned long move_vma(struct vm_ mm->locked_vm += new_len >>PAGE_SHIFT ; *locked = true; } -out: + mm->hiwater_vm = hiwater_vm;/* Restore VM_ACCOUNT if one or two pieces of vma left */
_
Andrew Morton
maintainerPATCH 86/200 mremap: don't allow MREMAP_DONTUNMAP on special_mappings and aio
In reply to Andrew MortonFrom: Dmitry Safonov <[email protected]>
Subject: mremap: don't allow MREMAP_DONTUNMAP on special_mappings and aio
As kernel expect to see only one of such mappings, any further operations on the VMA-copy may be unexpected by the kernel. Maybe it's being on the safe side, but there doesn't seem to be any expected use-case for this, so restrict it now.
---
arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 2 +- fs/aio.c | 5 ++++- include/linux/mm.h | 2 +- mm/mmap.c | 6 +++++- mm/mremap.c | 2 +- 5 files changed, 12 insertions(+), 5 deletions(-)
arch/x86/kernel/cpu/resctrl/pseudo_lock.c renamed from arch/x86/kernel/cpu/resctrl/pseudo_lock.c~mremap-dont-allow-mremap_dontunmap-on-special_mappings-and-aio +1 -1
@@ -1458,7 +1458,7 @@ static int pseudo_lock_dev_release(strucreturn 0 ; } -static int pseudo_lock_dev_mremap (struct vm_area_struct *area) +static int pseudo_lock_dev_mremap (struct vm_area_struct *area,unsigned long flags) {/* Not supported */ return -EINVAL ;
fs/aio.c renamed from fs/aio.c~mremap-dont-allow-mremap_dontunmap-on-special_mappings-and-aio +4 -1
@@ -324,13 +324,16 @@ static void aio_free_ring(struct kioctx } } -static int aio_ring_mremap (struct vm_area_struct *vma) +static int aio_ring_mremap (struct vm_area_struct *vma,unsigned long flags) {struct file *file = vma->vm_file;struct mm_struct *mm = vma->vm_mm;struct kioctx_table *table;int i, res = -EINVAL ; +if (flags &MREMAP_DONTUNMAP ) +return -EINVAL ; +spin_lock (&mm->ioctx_lock);rcu_read_lock (); table =rcu_dereference (mm->ioctx_table);
include/linux/mm.h renamed from include/linux/mm.h~mremap-dont-allow-mremap_dontunmap-on-special_mappings-and-aio +1 -1
@@ -558,7 +558,7 @@ struct vm_operations_struct {void (*open)(struct vm_area_struct * area);void (*close)(struct vm_area_struct * area);int (*split)(struct vm_area_struct * area,unsigned long addr); -int (*mremap)(struct vm_area_struct * area); +int (*mremap)(struct vm_area_struct *area,unsigned long flags);vm_fault_t (*fault)(struct vm_fault *vmf);vm_fault_t (*huge_fault)(struct vm_fault *vmf,enum page_entry_size pe_size);
mm/mmap.c renamed from mm/mmap.c~mremap-dont-allow-mremap_dontunmap-on-special_mappings-and-aio +5 -1
@@ -3405,10 +3405,14 @@ static const char *special_mapping_name(return ((struct vm_special_mapping *)vma->vm_private_data)->name; } -static int special_mapping_mremap (struct vm_area_struct *new_vma) +static int special_mapping_mremap (struct vm_area_struct *new_vma, +unsigned long flags) {struct vm_special_mapping *sm = new_vma->vm_private_data; +if (flags &MREMAP_DONTUNMAP ) +return -EINVAL ; +if (WARN_ON_ONCE (current->mm != new_vma->vm_mm))return -EFAULT ;
mm/mremap.c renamed from mm/mremap.c~mremap-dont-allow-mremap_dontunmap-on-special_mappings-and-aio +1 -1
@@ -534,7 +534,7 @@ static unsigned long move_vma(struct vm_if (moved_len < old_len) { err = -ENOMEM ; }else if (vma->vm_ops && vma->vm_ops->mremap) { - err = vma->vm_ops->mremap (new_vma); + err = vma->vm_ops->mremap (new_vma, flags); }if (unlikely (err)) {
_
Re: [patch 086/200] mremap: don't allow MREMAP_DONTUNMAP on special_mappings and aio
I don't think this situation can ever happen MREMAP_DONTUNMAP is already restricted to anonymous mappings (defined as not having vm_ops) and vma_to_resize checks that the mapping is anonymous before move_vma is called.
Quoted 115 lines · Andrew Morton
From: Dmitry Safonov <[email protected]>
Subject: mremap: don't allowMREMAP_DONTUNMAPonspecial_mappingsand aioAs kernel expect to see only one of such mappings, any further operations on the VMA-copy may be unexpected by the kernel. Maybe it's being on the safe side, but there doesn't seem to be any expected use-case for this, so restrict it now.
Fixes commit e346b3813067 ("mm/mremap: add MREMAP_DONTUNMAP to mremap()")Signed-off-by Dmitry Safonov <[email protected]>Cc Alexander Viro <[email protected]>Cc Andy Lutomirski <[email protected]>Cc Brian Geffon <[email protected]>Cc Catalin Marinas <[email protected]>Cc Dan Carpenter <[email protected]>Cc Dan Williams <[email protected]>Cc Dave Jiang <[email protected]>Cc Hugh Dickins <[email protected]>Cc Ingo Molnar <[email protected]>Cc Jason Gunthorpe <[email protected]>Cc John Hubbard <[email protected]>Cc "Kirill A. Shutemov" <[email protected]>Cc Mike Kravetz <[email protected]>Cc Minchan Kim <[email protected]>Cc Ralph Campbell <[email protected]>Cc Russell King <[email protected]>Cc Thomas Bogendoerfer <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Vishal Verma <[email protected]>Cc Vlastimil Babka <[email protected]>Cc Will Deacon <[email protected]>Signed-off-by Andrew Morton <[email protected]>---
arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 2 +- fs/aio.c | 5 ++++- include/linux/mm.h | 2 +- mm/mmap.c | 6 +++++- mm/mremap.c | 2 +- 5 files changed, 12 insertions(+), 5 deletions(-)arch/x86/kernel/cpu/resctrl/pseudo_lock.c renamed from arch/x86/kernel/cpu/resctrl/pseudo_lock.c~mremap-dont-allow-mremap_dontunmap-on-special_mappings-and-aio +1
-1@@ -1458,7 +1458,7 @@ static int pseudo_lock_dev_release(strucreturn 0 ; } -static int pseudo_lock_dev_mremap (struct vm_area_struct *area) +static int pseudo_lock_dev_mremap (struct vm_area_struct *area,unsigned long flags) {/* Not supported */ return -EINVAL ;fs/aio.c renamed from fs/aio.c~mremap-dont-allow-mremap_dontunmap-on-special_mappings-and-aio +4
-1@@ -324,13 +324,16 @@ static void aio_free_ring(struct kioctx } } -static int aio_ring_mremap (struct vm_area_struct *vma) +static int aio_ring_mremap (struct vm_area_struct *vma,unsigned long flags) {struct file *file = vma->vm_file;struct mm_struct *mm = vma->vm_mm;struct kioctx_table *table;int i, res = -EINVAL ; +if (flags &MREMAP_DONTUNMAP ) +return -EINVAL ; +spin_lock (&mm->ioctx_lock);rcu_read_lock (); table =rcu_dereference (mm->ioctx_table);include/linux/mm.h renamed from include/linux/mm.h~mremap-dont-allow-mremap_dontunmap-on-special_mappings-and-aio +1
-1@@ -558,7 +558,7 @@ struct vm_operations_struct {void (*open)(struct vm_area_struct * area);void (*close)(struct vm_area_struct * area);int (*split)(struct vm_area_struct * area,unsigned long addr); -int (*mremap)(struct vm_area_struct * area); +int (*mremap)(struct vm_area_struct *area,unsigned long flags);vm_fault_t (*fault)(struct vm_fault *vmf);vm_fault_t (*huge_fault)(struct vm_fault *vmf,enum page_entry_size pe_size);mm/mmap.c renamed from mm/mmap.c~mremap-dont-allow-mremap_dontunmap-on-special_mappings-and-aio +5
-1@@ -3405,10 +3405,14 @@ static const char *special_mapping_name(return ((struct vm_special_mapping *)vma->vm_private_data)->name; } -static int special_mapping_mremap (struct vm_area_struct *new_vma) +static int special_mapping_mremap (struct vm_area_struct *new_vma, +unsigned long flags) {struct vm_special_mapping *sm = new_vma->vm_private_data; +if (flags &MREMAP_DONTUNMAP ) +return -EINVAL ; +if (WARN_ON_ONCE (current->mm != new_vma->vm_mm))return -EFAULT ;mm/mremap.c renamed from mm/mremap.c~mremap-dont-allow-mremap_dontunmap-on-special_mappings-and-aio +1
-1@@ -534,7 +534,7 @@ static unsigned long move_vma(struct vm_if (moved_len < old_len) { err = -ENOMEM ; }else if (vma->vm_ops && vma->vm_ops->mremap) { - err = vma->vm_ops->mremap (new_vma); + err = vma->vm_ops->mremap (new_vma, flags); }if (unlikely (err)) {_
Andrew Morton
maintainerPATCH 87/200 vm_ops: rename .split() callback to .may_split()
In reply to Andrew MortonFrom: Dmitry Safonov <[email protected]>
Subject: vm_ops: rename .split() callback to .may_split()
Rename the callback to reflect that it's not called *on* or *after* split, but rather some time before the splitting to check if it's possible.
---
drivers/dax/device.c | 4 ++-- include/linux/mm.h | 3 ++- ipc/shm.c | 8 ++++---- mm/hugetlb.c | 2 +- mm/mmap.c | 4 ++-- 5 files changed, 11 insertions(+), 10 deletions(-)
drivers/dax/device.c renamed from drivers/dax/device.c~vm_ops-rename-split-callback-to-may_split +2 -2
@@ -256,7 +256,7 @@ static vm_fault_t dev_dax_fault(struct vreturn dev_dax_huge_fault (vmf,PE_SIZE_PTE ); } -static int dev_dax_split (struct vm_area_struct *vma,unsigned long addr) +static int dev_dax_may_split (struct vm_area_struct *vma,unsigned long addr) {struct file *filp = vma->vm_file;struct dev_dax *dev_dax = filp->private_data;
@@ -277,7 +277,7 @@ static unsigned long dev_dax_pagesize(ststatic const struct vm_operations_struct dax_vm_ops = { .fault = dev_dax_fault, .huge_fault = dev_dax_huge_fault, - .split = dev_dax_split, + .may_split = dev_dax_may_split, .pagesize = dev_dax_pagesize, };
include/linux/mm.h renamed from include/linux/mm.h~vm_ops-rename-split-callback-to-may_split +2 -1
@@ -557,7 +557,8 @@ enum page_entry_size {struct vm_operations_struct {void (*open)(struct vm_area_struct * area);void (*close)(struct vm_area_struct * area); -int (*split)(struct vm_area_struct * area,unsigned long addr); +/* Called any time before splitting to check if it's allowed */ +int (*may_split)(struct vm_area_struct *area,unsigned long addr);int (*mremap)(struct vm_area_struct *area,unsigned long flags);vm_fault_t (*fault)(struct vm_fault *vmf); vm_fault_t (*huge_fault)(struct vm_fault *vmf,
ipc/shm.c renamed from ipc/shm.c~vm_ops-rename-split-callback-to-may_split +4 -4
@@ -434,13 +434,13 @@ static vm_fault_t shm_fault(struct vm_fareturn sfd->vm_ops->fault (vmf); } -static int shm_split (struct vm_area_struct *vma,unsigned long addr) +static int shm_may_split (struct vm_area_struct *vma,unsigned long addr) {struct file *file = vma->vm_file;struct shm_file_data *sfd =shm_file_data (file); -if (sfd->vm_ops->split) -return sfd->vm_ops->split (vma, addr); +if (sfd->vm_ops->may_split) +return sfd->vm_ops->may_split (vma, addr);return 0 ; }
@@ -582,7 +582,7 @@ static const struct vm_operations_struct .open = shm_open, /* callback for a new vm-area open */ .close = shm_close, /* callback for when the vm-area is released */ .fault = shm_fault, - .split = shm_split, + .may_split = shm_may_split, .pagesize = shm_pagesize,#if defined(CONFIG_NUMA ) .set_policy = shm_set_policy,
mm/hugetlb.c renamed from mm/hugetlb.c~vm_ops-rename-split-callback-to-may_split +1 -1
@@ -3673,7 +3673,7 @@ const struct vm_operations_struct hugetl .fault = hugetlb_vm_op_fault, .open = hugetlb_vm_op_open, .close = hugetlb_vm_op_close, - .split = hugetlb_vm_op_split, + .may_split = hugetlb_vm_op_split, .pagesize = hugetlb_vm_op_pagesize, };
mm/mmap.c renamed from mm/mmap.c~vm_ops-rename-split-callback-to-may_split +2 -2
@@ -2731,8 +2731,8 @@ int __split_vma(struct mm_struct *mm, ststruct vm_area_struct *new;int err; -if (vma->vm_ops && vma->vm_ops->split) { - err = vma->vm_ops->split (vma, addr); +if (vma->vm_ops && vma->vm_ops->may_split) { + err = vma->vm_ops->may_split (vma, addr);if (err)return err; }
_
Andrew Morton
maintainerPATCH 88/200 mremap: check if it's possible to split original vma
In reply to Andrew MortonFrom: Dmitry Safonov <[email protected]>
Subject: mremap: check if it's possible to split original vma
If original VMA can't be split at the desired address, do_munmap() will fail and leave both new-copied VMA and old VMA. De-facto it's MREMAP_DONTUNMAP behaviour, which is unexpected.
Currently, it may fail such way for hugetlbfs and dax device mappings.
Minimize such unpleasant situations to OOM by checking .may_split() before attempting to create a VMA copy.
---
mm/mremap.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
mm/mremap.c renamed from mm/mremap.c~mremap-check-if-its-possible-to-split-original-vma +10 -1
@@ -493,7 +493,7 @@ static unsigned long move_vma(struct vm_unsigned long excess =0 ;unsigned long hiwater_vm;int split =0 ; -int err; +int err =0 ;bool need_rmap_locks;/*
@@ -503,6 +503,15 @@ static unsigned long move_vma(struct vm_if (mm->map_count >= sysctl_max_map_count -3 )return -ENOMEM ; +if (vma->vm_ops && vma->vm_ops->may_split) { +if (vma->vm_start != old_addr) + err = vma->vm_ops->may_split (vma, old_addr); +if (!err && vma->vm_end != old_addr + old_len) + err = vma->vm_ops->may_split (vma, old_addr + old_len); +if (err) +return err; + } +/* * Advise KSM to break any KSM pages in the area to be moved: * it would be confusing if they were to turn up at the new
_
Andrew Morton
maintainerPATCH 89/200 mm: forbid splitting special mappings
In reply to Andrew MortonFrom: Dmitry Safonov <[email protected]>
Subject: mm: forbid splitting special mappings
Don't allow splitting of vm_special_mapping's. It affects vdso/vvar areas. Uprobes have only one page in xol_area so they aren't affected.
Those restrictions were enforced by checks in .mremap() callbacks. Restrict resizing with generic .split() callback.
---
arch/arm/kernel/vdso.c | 9 ------- arch/arm64/kernel/vdso.c | 41 +++--------------------------------- arch/mips/vdso/genvdso.c | 4 --- arch/s390/kernel/vdso.c | 11 --------- arch/x86/entry/vdso/vma.c | 17 -------------- mm/mmap.c | 12 ++++++++++ 6 files changed, 17 insertions(+), 77 deletions(-)
arch/arm64/kernel/vdso.c renamed from arch/arm64/kernel/vdso.c~mm-forbid-splitting-special-mappings +4 -37
@@ -78,17 +78,9 @@ static union { }vdso_data_store __page_aligned_data;struct vdso_data *vdso_data = vdso_data_store.data; -static int __vdso_remap (enum vdso_abi abi, -const struct vm_special_mapping *sm, -struct vm_area_struct *new_vma) -{ -unsigned long new_size = new_vma->vm_end - new_vma->vm_start; -unsigned long vdso_size = vdso_info[abi].vdso_code_end - - vdso_info[abi].vdso_code_start; - -if (vdso_size != new_size) -return -EINVAL ; - +static int vdso_mremap (const struct vm_special_mapping *sm, +struct vm_area_struct *new_vma) +{ current->mm->context.vdso = (void *)new_vma->vm_start;return 0 ;
@@ -219,17 +211,6 @@ static vm_fault_t vvar_fault(const strucreturn vmf_insert_pfn (vma, vmf->address, pfn); } -static int vvar_mremap (const struct vm_special_mapping *sm, -struct vm_area_struct *new_vma) -{ -unsigned long new_size = new_vma->vm_end - new_vma->vm_start; - -if (new_size !=VVAR_NR_PAGES *PAGE_SIZE ) -return -EINVAL ; - -return 0 ; -} - static int __setup_additional_pages(enum vdso_abi abi, struct mm_struct *mm, struct linux_binprm *bprm,
@@ -280,12 +261,6 @@ up_fail:/* * Create and map the vectors page for AArch32 tasks. */ -static int aarch32_vdso_mremap (const struct vm_special_mapping *sm, -struct vm_area_struct *new_vma) -{ -return __vdso_remap (VDSO_ABI_AA32 , sm, new_vma); -} -enum aarch32_map {AA32_MAP_VECTORS ,/* kuser helpers */ AA32_MAP_SIGPAGE ,
@@ -308,11 +283,10 @@ static struct vm_special_mapping aarch32 [AA32_MAP_VVAR ] = { .name ="[vvar]" , .fault = vvar_fault, - .mremap = vvar_mremap, }, [AA32_MAP_VDSO ] = { .name ="[vdso]" , - .mremap = aarch32_vdso_mremap, + .mremap = vdso_mremap, }, };
@@ -453,12 +427,6 @@ out: }#endif /* CONFIG_COMPAT */ -static int vdso_mremap (const struct vm_special_mapping *sm, -struct vm_area_struct *new_vma) -{ -return __vdso_remap (VDSO_ABI_AA64 , sm, new_vma); -} -enum aarch64_map {AA64_MAP_VVAR ,AA64_MAP_VDSO ,
@@ -468,7 +436,6 @@ static struct vm_special_mapping aarch64 [AA64_MAP_VVAR] = { .name = "[vvar]", .fault = vvar_fault, - .mremap = vvar_mremap, }, [AA64_MAP_VDSO] = { .name = "[vdso]",
arch/arm/kernel/vdso.c renamed from arch/arm/kernel/vdso.c~mm-forbid-splitting-special-mappings +0 -9
@@ -50,15 +50,6 @@ static const struct vm_special_mapping vstatic int vdso_mremap (const struct vm_special_mapping *sm,struct vm_area_struct *new_vma) { -unsigned long new_size = new_vma->vm_end - new_vma->vm_start; -unsigned long vdso_size; - -/* without VVAR page */ - vdso_size = (vdso_total_pages -1 ) <<PAGE_SHIFT ; - -if (vdso_size != new_size) -return -EINVAL ; - current->mm->context.vdso = new_vma->vm_start;return 0 ;
arch/mips/vdso/genvdso.c renamed from arch/mips/vdso/genvdso.c~mm-forbid-splitting-special-mappings +0 -4
@@ -263,10 +263,6 @@ int main(int argc, char **argv)fprintf (out_file," const struct vm_special_mapping *sm,\n" );fprintf (out_file," struct vm_area_struct *new_vma)\n" );fprintf (out_file,"{\n" ); -fprintf (out_file," unsigned long new_size =\n" ); -fprintf (out_file," new_vma->vm_end - new_vma->vm_start;\n" ); -fprintf (out_file," if (vdso_image.size != new_size)\n" ); -fprintf (out_file," return -EINVAL;\n" );fprintf (out_file," current->mm->context.vdso =\n" );fprintf (out_file," (void *)(new_vma->vm_start);\n" );fprintf (out_file," return 0;\n" );
arch/s390/kernel/vdso.c renamed from arch/s390/kernel/vdso.c~mm-forbid-splitting-special-mappings +1 -10
@@ -61,17 +61,8 @@ static vm_fault_t vdso_fault(const strucstatic int vdso_mremap (const struct vm_special_mapping *sm,struct vm_area_struct *vma) { -unsigned long vdso_pages; - - vdso_pages = vdso64_pages; - -if ((vdso_pages <<PAGE_SHIFT ) != vma->vm_end - vma->vm_start) -return -EINVAL ; - -if (WARN_ON_ONCE (current->mm != vma->vm_mm)) -return -EFAULT ; - current->mm->context.vdso_base = vma->vm_start; +return 0 ; }
arch/x86/entry/vdso/vma.c renamed from arch/x86/entry/vdso/vma.c~mm-forbid-splitting-special-mappings +0 -17
@@ -89,30 +89,14 @@ static void vdso_fix_landing(const strucstatic int vdso_mremap (const struct vm_special_mapping *sm,struct vm_area_struct *new_vma) { -unsigned long new_size = new_vma->vm_end - new_vma->vm_start;const struct vdso_image *image = current->mm->context.vdso_image; -if (image->size != new_size) -return -EINVAL ; -vdso_fix_landing (image, new_vma); current->mm->context.vdso = (void __user *)new_vma->vm_start;return 0 ; } -static int vvar_mremap (const struct vm_special_mapping *sm, -struct vm_area_struct *new_vma) -{ -const struct vdso_image *image = new_vma->vm_mm->context.vdso_image; -unsigned long new_size = new_vma->vm_end - new_vma->vm_start; - -if (new_size != -image->sym_vvar_start) -return -EINVAL ; - -return 0 ; -} -#ifdef CONFIG_TIME_NS static struct page *find_timens_vvar_page (struct vm_area_struct *vma) {
@@ -252,7 +236,6 @@ static const struct vm_special_mapping vstatic const struct vm_special_mapping vvar_mapping = { .name ="[vvar]" , .fault = vvar_fault, - .mremap = vvar_mremap, };/*
mm/mmap.c renamed from mm/mmap.c~mm-forbid-splitting-special-mappings +12 -0
@@ -3422,6 +3422,17 @@ static int special_mapping_mremap(structreturn 0 ; } +static int special_mapping_split (struct vm_area_struct *vma,unsigned long addr) +{ +/* +* Forbid splitting special mappings - kernel has expectations over +* the number of pages in mapping. Together with VM_DONTEXPAND +* the size of vma should stay the same over the special mapping's +* lifetime. +*/ +return -EINVAL ; +} +static const struct vm_operations_struct special_mapping_vmops = { .close = special_mapping_close, .fault = special_mapping_fault,
@@ -3429,6 +3440,7 @@ static const struct vm_operations_struct .name = special_mapping_name, /* vDSO code relies that VVAR can't be accessed remotely */ .access = NULL, + .may_split = special_mapping_split, };static const struct vm_operations_struct legacy_special_mapping_vmops = {
_
Andrew Morton
maintainerPATCH 90/200 mm: track mmu notifiers in fs_reclaim_acquire/release
In reply to Andrew MortonFrom: Daniel Vetter <[email protected]>
Subject: mm: track mmu notifiers in fs_reclaim_acquire/release
fs_reclaim_acquire/release nicely catch recursion issues when allocating GFP_KERNEL memory against shrinkers (which gpu drivers tend to use to keep the excessive caches in check). For mmu notifier recursions we do have lockdep annotations since 23b68395c7c7 ("mm/mmu_notifiers: add a lockdep map for invalidate_range_start/end").
But these only fire if a path actually results in some pte invalidation - for most small allocations that's very rarely the case. The other trouble is that pte invalidation can happen any time when __GFP_RECLAIM is set. Which means only really GFP_ATOMIC is a safe choice, GFP_NOIO isn't good enough to avoid potential mmu notifier recursion.
I was pondering whether we should just do the general annotation, but there's always the risk for false positives. Plus I'm assuming that the core fs and io code is a lot better reviewed and tested than random mmu notifier code in drivers. Hence why I decide to only annotate for that specific case.
Furthermore even if we'd create a lockdep map for direct reclaim, we'd still need to explicit pull in the mmu notifier map - there's a lot more places that do pte invalidation than just direct reclaim, these two contexts arent the same.
Note that the mmu notifiers needing their own independent lockdep map is also the reason we can't hold them from fs_reclaim_acquire to fs_reclaim_release - it would nest with the acquistion in the pte invalidation code, causing a lockdep splat. And we can't remove the annotations from pte invalidation and all the other places since they're called from many other places than page reclaim. Hence we can only do the equivalent of might_lock, but on the raw lockdep map.
With this we can also remove the lockdep priming added in 66204f1d2d1b ("mm/mmu_notifiers: prime lockdep") since the new annotations are strictly more powerful.
---
mm/mmu_notifier.c | 7 ------- mm/page_alloc.c | 31 ++++++++++++++++++++----------- 2 files changed, 20 insertions(+), 18 deletions(-)
mm/mmu_notifier.c renamed from mm/mmu_notifier.c~mm-track-mmu-notifiers-in-fs_reclaim_acquire-release +0 -7
@@ -612,13 +612,6 @@ int __mmu_notifier_register(struct mmu_nmmap_assert_write_locked (mm);BUG_ON (atomic_read (&mm->mm_users) <=0 ); -if (IS_ENABLED (CONFIG_LOCKDEP )) { -fs_reclaim_acquire (GFP_KERNEL ); -lock_map_acquire (&__mmu_notifier_invalidate_range_start_map); -lock_map_release (&__mmu_notifier_invalidate_range_start_map); -fs_reclaim_release (GFP_KERNEL ); - } -if (!mm->notifier_subscriptions) {/* * kmalloc cannot be called under mm_take_all_locks(), but we
mm/page_alloc.c renamed from mm/page_alloc.c~mm-track-mmu-notifiers-in-fs_reclaim_acquire-release +20 -11
@@ -57,6 +57,7 @@#include <trace/events/oom.h> #include <linux/prefetch.h> #include <linux/mm_inline.h> +#include <linux/mmu_notifier.h> #include <linux/migrate.h> #include <linux/hugetlb.h> #include <linux/sched/rt.h>
@@ -4264,10 +4265,8 @@ should_compact_retry(struct alloc_contexstatic struct lockdep_map __fs_reclaim_map =STATIC_LOCKDEP_MAP_INIT ("fs_reclaim" , &__fs_reclaim_map); -static bool __need_fs_reclaim (gfp_t gfp_mask) +static bool __need_reclaim (gfp_t gfp_mask) { - gfp_mask =current_gfp_context (gfp_mask); -/* no reclaim without waiting on it */ if (!(gfp_mask & __GFP_DIRECT_RECLAIM))return false;
@@ -4276,10 +4275,6 @@ static bool __need_fs_reclaim(gfp_t gfp_if (current->flags &PF_MEMALLOC )return false; -/* We're only interested __GFP_FS allocations for now */ -if (!(gfp_mask & __GFP_FS)) -return false; -if (gfp_mask & __GFP_NOLOCKDEP)return false;
@@ -4298,15 +4293,29 @@ void __fs_reclaim_release(void)void fs_reclaim_acquire (gfp_t gfp_mask) { -if (__need_fs_reclaim (gfp_mask)) -__fs_reclaim_acquire (); + gfp_mask =current_gfp_context (gfp_mask); + +if (__need_reclaim (gfp_mask)) { +if (gfp_mask & __GFP_FS) +__fs_reclaim_acquire (); + +#ifdef CONFIG_MMU_NOTIFIER +lock_map_acquire (&__mmu_notifier_invalidate_range_start_map); +lock_map_release (&__mmu_notifier_invalidate_range_start_map); +#endif + + } }EXPORT_SYMBOL_GPL (fs_reclaim_acquire);void fs_reclaim_release (gfp_t gfp_mask) { -if (__need_fs_reclaim (gfp_mask)) -__fs_reclaim_release (); + gfp_mask =current_gfp_context (gfp_mask); + +if (__need_reclaim (gfp_mask)) { +if (gfp_mask & __GFP_FS) +__fs_reclaim_release (); + } }EXPORT_SYMBOL_GPL (fs_reclaim_release);#endif
_
Andrew Morton
maintainerPATCH 91/200 mm: extract might_alloc() debug check
In reply to Andrew MortonFrom: Daniel Vetter <[email protected]>
Subject: mm: extract might_alloc() debug check
Extracted from slab.h, which seems to have the most complete version including the correct might_sleep() check. Roll it out to slob.c.
Motivated by a discussion with Paul about possibly changing call_rcu behaviour to allocate memory, but only roughly every 500th call.
There are a lot fewer places in the kernel that care about whether allocating memory is allowed or not (due to deadlocks with reclaim code) than places that care whether sleeping is allowed. But debugging these also tends to be a lot harder, so nice descriptive checks could come in handy. I might have some use eventually for annotations in drivers/gpu.
Note that unlike fs_reclaim_acquire/release gfpflags_allow_blocking does not consult the PF_MEMALLOC flags. But there is no flag equivalent for GFP_NOWAIT, hence this check can't go wrong due to memalloc_no*_save/restore contexts. Willy is working on a patch series which might change this:
https://lore.kernel.org/linux-mm/[email protected]/
I think best would be if that updates gfpflags_allow_blocking(), since there's a ton of callers all over the place for that already.
Cc. Randy Dunlap <[email protected]>
---
include/linux/sched/mm.h | 16 ++++++++++++++++ mm/slab.h | 5 +---- mm/slob.c | 6 ++---- 3 files changed, 19 insertions(+), 8 deletions(-)
include/linux/sched/mm.h renamed from include/linux/sched/mm.h~mm-extract-might_alloc-debug-check +16 -0
@@ -181,6 +181,22 @@ static inline void fs_reclaim_release(gf#endif /** +* might_alloc - Mark possible allocation sites +* @gfp_mask: gfp_t flags that would be used to allocate +* +* Similar to might_sleep() and other annotations, this can be used in functions +* that might allocate, but often don't. Compiles to nothing without +* CONFIG_LOCKDEP. Includes a conditional might_sleep() if @gfp allows blocking. +*/ +static inline void might_alloc (gfp_t gfp_mask) +{ +fs_reclaim_acquire (gfp_mask); +fs_reclaim_release (gfp_mask); + +might_sleep_if (gfpflags_allow_blocking (gfp_mask)); +} + +/** * memalloc_noio_save - Marks implicit GFP_NOIO allocation scope. * * This functions marks the beginning of the GFP_NOIO allocation scope.
mm/slab.h renamed from mm/slab.h~mm-extract-might_alloc-debug-check +1 -4
@@ -510,10 +510,7 @@ static inline struct kmem_cache *slab_pr { flags &= gfp_allowed_mask; -fs_reclaim_acquire (flags); -fs_reclaim_release (flags); - -might_sleep_if (gfpflags_allow_blocking (flags)); +might_alloc (flags);if (should_failslab (s, flags))return NULL ;
mm/slob.c renamed from mm/slob.c~mm-extract-might_alloc-debug-check +2 -4
@@ -474,8 +474,7 @@ __do_kmalloc_node(size_t size, gfp_t gfp gfp &= gfp_allowed_mask; -fs_reclaim_acquire (gfp); -fs_reclaim_release (gfp); +might_alloc (gfp);if (size <PAGE_SIZE - minalign) {int align = minalign;
@@ -597,8 +596,7 @@ static void *slob_alloc_node(struct kmem flags &= gfp_allowed_mask; -fs_reclaim_acquire (flags); -fs_reclaim_release (flags); +might_alloc (flags);if (c->size <PAGE_SIZE ) { b =slob_alloc (c->size, flags, c->align, node,0 );
_
Andrew Morton
maintainerPATCH 92/200 locking/selftests: add testcases for fs_reclaim
In reply to Andrew MortonFrom: Daniel Vetter <[email protected]>
Subject: locking/selftests: add testcases for fs_reclaim
Since I butchered this I figured better to make sure we have testcases for this now. Since we only have a locking context for __GFP_FS that's the only thing we're testing right now.
---
lib/locking-selftest.c | 47 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+)
lib/locking-selftest.c renamed from lib/locking-selftest.c~locking-selftests-add-testcases-for-fs_reclaim +47 -0
@@ -15,6 +15,7 @@#include <linux/mutex.h> #include <linux/ww_mutex.h> #include <linux/sched.h> +#include <linux/sched/mm.h> #include <linux/delay.h> #include <linux/lockdep.h> #include <linux/spinlock.h>
@@ -2357,6 +2358,50 @@ static void queued_read_lock_tests(void)pr_cont ("\n" ); } +static void fs_reclaim_correct_nesting (void ) +{ +fs_reclaim_acquire (GFP_KERNEL ); +might_alloc (GFP_NOFS ); +fs_reclaim_release (GFP_KERNEL ); +} + +static void fs_reclaim_wrong_nesting (void ) +{ +fs_reclaim_acquire (GFP_KERNEL ); +might_alloc (GFP_KERNEL ); +fs_reclaim_release (GFP_KERNEL ); +} + +static void fs_reclaim_protected_nesting (void ) +{ +unsigned int flags; + +fs_reclaim_acquire (GFP_KERNEL ); + flags =memalloc_nofs_save (); +might_alloc (GFP_KERNEL ); +memalloc_nofs_restore (flags); +fs_reclaim_release (GFP_KERNEL ); +} + +static void fs_reclaim_tests (void ) +{ +printk (" --------------------\n" ); +printk (" | fs_reclaim tests |\n" ); +printk (" --------------------\n" ); + +print_testname ("correct nesting" ); +dotest (fs_reclaim_correct_nesting,SUCCESS ,0 ); +pr_cont ("\n" ); + +print_testname ("wrong nesting" ); +dotest (fs_reclaim_wrong_nesting,FAILURE ,0 ); +pr_cont ("\n" ); + +print_testname ("protected nesting" ); +dotest (fs_reclaim_protected_nesting,SUCCESS ,0 ); +pr_cont ("\n" ); +} +void locking_selftest (void ) {/*
@@ -2478,6 +2523,8 @@ void locking_selftest(void)if (IS_ENABLED (CONFIG_QUEUED_RWLOCKS ))queued_read_lock_tests (); +fs_reclaim_tests (); +if (unexpected_testcase_failures) {printk ("-----------------------------------------------------------------\n" ); debug_locks =0 ;
_
Andrew Morton
maintainerPATCH 93/200 mm/vmalloc.c:__vmalloc_area_node(): avoid 32-bit overflow
In reply to Andrew MortonFrom: Andrew Morton <[email protected]>
Subject: mm/vmalloc.c:__vmalloc_area_node(): avoid 32-bit overflow
With a machine with 3 TB (more than 2 TB memory). If you use vmalloc to allocate > 2 TB memory, the array_size below will be overflowed.
The array_size is an unsigned int and can only be used to allocate less than 2 TB memory. If you pass 2*1028*1028*1024*1024 = 2 * 2^40 in the argument of vmalloc. The array_size will become 2*2^31 = 2^32. The 2^32 cannot be store with a 32 bit integer.
The fix is to change the type of array_size to unsigned long.
---
mm/vmalloc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
mm/vmalloc.c renamed from mm/vmalloc.c~mm-vmallocc-__vmalloc_area_node-avoid-32-bit-overflow +3 -1
@@ -2461,9 +2461,11 @@ static void *__vmalloc_area_node(struct {const gfp_t nested_gfp = (gfp_mask &GFP_RECLAIM_MASK ) | __GFP_ZERO;unsigned int nr_pages =get_vm_area_size (area) >>PAGE_SHIFT ; -unsigned int array_size = nr_pages *sizeof (struct page *), i; +unsigned long array_size; +unsigned int i;struct page **pages; + array_size = (unsigned long )nr_pages *sizeof (struct page *); gfp_mask |= __GFP_NOWARN;if (!(gfp_mask & (GFP_DMA |GFP_DMA32 ))) gfp_mask |= __GFP_HIGHMEM;
_
Andrew Morton
maintainerPATCH 94/200 mm/vmalloc: use free_vm_area() if an allocation fails
In reply to Andrew MortonFrom: "Uladzislau Rezki (Sony)" <[email protected]>
Subject: mm/vmalloc: use free_vm_area() if an allocation fails
There is a dedicated and separate function that finds and removes a continuous kernel virtual area. As a final step it also releases the "area", a descriptor of corresponding vm_struct.
Use free_vmap_area() in the __vmalloc_node_range() instead of open coded steps which are exactly the same, to perform a cleanup.
---
mm/vmalloc.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
mm/vmalloc.c renamed from mm/vmalloc.c~mm-vmalloc-use-free_vm_area-if-an-allocation-fails +1 -2
@@ -2479,8 +2479,7 @@ static void *__vmalloc_area_node(struct }if (!pages) { -remove_vm_area (area->addr); -kfree (area); +free_vm_area (area);return NULL ; }
_
Andrew Morton
maintainerPATCH 95/200 mm/vmalloc: rework the drain logic
In reply to Andrew MortonFrom: "Uladzislau Rezki (Sony)" <[email protected]>
Subject: mm/vmalloc: rework the drain logic
A current "lazy drain" model suffers from at least two issues.
First one is related to the unsorted list of vmap areas, thus in order to identify the [min:max] range of areas to be drained, it requires a full list scan. What is a time consuming if the list is too long.
Second one and as a next step is about merging all fragments with a free space. What is also a time consuming because it has to iterate over entire list which holds outstanding lazy areas.
See below the "preemptirqsoff" tracer that illustrates a high latency. It is ~24676us. Our workloads like audio and video are effected by such long latency:
<snip>
tracer: preemptirqsoff
preemptirqsoff latency trace v1.1.5 on 4.9.186-perf+
--------------------------------------------------------------------
latency: 24676 us, #4/4, CPU#1 | (M:preempt VP:0, KP:0, SP:0 HP:0 P:8)
-----------------
| task: crtc_commit:112-261 (uid:0 nice:0 policy:1 rt_prio:16)
----------------- => started at: __purge_vmap_area_lazy
=> ended at: __purge_vmap_area_lazy
_------=> CPU#
/ _-----=> irqs-off
| / _----=> need-resched
|| / _---=> hardirq/softirq
||| / _--=> preempt-depth
|||| / delay
cmd pid ||||| time | caller
\ / ||||| \ | /
crtc_com-261 1...1 1us*: _raw_spin_lock <-__purge_vmap_area_lazy[...]
crtc_com-261 1...1 24675us : _raw_spin_unlock <-__purge_vmap_area_lazy
crtc_com-261 1...1 24677us : trace_preempt_on <-__purge_vmap_area_lazy
crtc_com-261 1...1 24683us : <stack trace>
=> free_vmap_area_noflush
=> remove_vm_area
=> __vunmap
=> vfree
=> drm_property_free_blob
=> drm_mode_object_unreference
=> drm_property_unreference_blob
=> __drm_atomic_helper_crtc_destroy_state
=> sde_crtc_destroy_state
=> drm_atomic_state_default_clear
=> drm_atomic_state_clear
=> drm_atomic_state_free
=> complete_commit
=> _msm_drm_commit_work_cb
=> kthread_worker_fn
=> kthread
=> ret_from_fork
<snip>
To address those two issues we can redesign a purging of the outstanding lazy areas. Instead of queuing vmap areas to the list, we replace it by the separate rb-tree. In hat case an area is located in the tree/list in ascending order. It will give us below advantages:
a) Outstanding vmap areas are merged creating bigger coalesced blocks, thus it becomes less fragmented.
b) It is possible to calculate a flush range [min:max] without scanning all elements. It is O(1) access time or complexity;
c) The final merge of areas with the rb-tree that represents a free space is faster because of (a). As a result the lock contention is also reduced.
---
include/linux/vmalloc.h | 8 +-- mm/vmalloc.c | 90 +++++++++++++++++++++----------------- 2 files changed, 53 insertions(+), 45 deletions(-)
include/linux/vmalloc.h renamed from include/linux/vmalloc.h~mm-vmalloc-rework-the-drain-logic +3 -5
@@ -72,16 +72,14 @@ struct vmap_area {struct list_head list;/* address sorted list */ /* -* The following three variables can be packed, because -* a vmap_area object is always one of the three states: +* The following two variables can be packed, because +* a vmap_area object can be either: * 1) in "free" tree (root is vmap_area_root) -* 2) in "busy" tree (root is free_vmap_area_root) -* 3) in purge list (head is vmap_purge_list) +* 2) or "busy" tree (root is free_vmap_area_root) */ union {unsigned long subtree_max_size;/* in "free" tree */ struct vm_struct *vm;/* in "busy" tree */ -struct llist_node purge_list;/* in purge list */ }; };
mm/vmalloc.c renamed from mm/vmalloc.c~mm-vmalloc-rework-the-drain-logic +50 -40
170 lines not on this page · raw message
_
Andrew Morton
maintainerPATCH 96/200 mm/vmalloc: add 'align' parameter explanation for pvm_determine_end_from_reverse
In reply to Andrew MortonFrom: Alex Shi <[email protected]>
Subject: mm/vmalloc: add 'align' parameter explanation for pvm_determine_end_from_reverse
Kernel-doc markup has a issue on pvm_determine_end_from_reverse:mm/vmalloc.c:3145: warning: Function parameter or member 'align' not described in 'pvm_determine_end_from_reverse'
Add a explanation for it to remove the warning.
---
mm/vmalloc.c | 1 + 1 file changed, 1 insertion(+)
mm/vmalloc.c renamed from mm/vmalloc.c~mm-vmalloc-add-align-parameter-explanation-for-pvm_determine_end_from_reverse +1 -0
@@ -3151,6 +3151,7 @@ pvm_find_va_enclose_addr(unsigned long a* @va: * in - the VA we start the search(reverse order); * out - the VA with the highest aligned end address. +* @align: alignment for required highest address * * Returns: determined end address within vmap_area */
_
Andrew Morton
maintainerPATCH 97/200 mm/vmalloc.c: remove unnecessary return statement
In reply to Andrew MortonFrom: Baolin Wang <[email protected]>
Subject: mm/vmalloc.c: remove unnecessary return statement
Remove unnecessary return statement for void function.
---
mm/vmalloc.c | 1 - 1 file changed, 1 deletion(-)
mm/vmalloc.c renamed from mm/vmalloc.c~mm-vmalloc-remove-unnecessary-return-statement +0 -1
@@ -2291,7 +2291,6 @@ static void __vunmap(const void *addr, i }kfree (area); -return ; }static inline void __vfree_deferred (const void *addr)
_
Andrew Morton
maintainerPATCH 98/200 mm/vmalloc: Fix unlock order in s_stop()
In reply to Andrew MortonFrom: Waiman Long <[email protected]>
Subject: mm/vmalloc: Fix unlock order in s_stop()
When multiple locks are acquired, they should be released in reverse order. For s_start() and s_stop() in mm/vmalloc.c, that is not the case.
s_start: mutex_lock(&vmap_purge_lock); spin_lock(&vmap_area_lock); s_stop : mutex_unlock(&vmap_purge_lock); spin_unlock(&vmap_area_lock);
This unlock sequence, though allowed, is not optimal. If a waiter is present, mutex_unlock() will need to go through the slowpath of waking up the waiter with preemption disabled. Fix that by releasing the spinlock first before the mutex.
---
mm/vmalloc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
mm/vmalloc.c renamed from mm/vmalloc.c~mm-vmalloc-fix-unlock-order-in-s_stop +2 -2
@@ -3465,11 +3465,11 @@ static void *s_next(struct seq_file *m, }static void s_stop (struct seq_file *m,void *p) - __releases(&vmap_purge_lock) __releases(&vmap_area_lock) + __releases(&vmap_purge_lock) { -mutex_unlock (&vmap_purge_lock);spin_unlock (&vmap_area_lock); +mutex_unlock (&vmap_purge_lock); }static void show_numa_info (struct seq_file *m,struct vm_struct *v)
_
Andrew Morton
maintainerPATCH 99/200 docs/vm: remove unused 3 items explanation for /proc/vmstat
In reply to Andrew MortonFrom: Alex Shi <[email protected]>
Subject: docs/vm: remove unused 3 items explanation for /proc/vmstat
Commit 5647bc293ab1 ("mm: compaction: Move migration fail/success stats to migrate.c"), removed 3 items in /proc/vmstat. but the docs still has their explanation. let's remove them.
"compact_blocks_moved",
"compact_pages_moved",
"compact_pagemigrate_failed",
---
Documentation/admin-guide/mm/transhuge.rst | 15 --------------- 1 file changed, 15 deletions(-)
Documentation/admin-guide/mm/transhuge.rst renamed from Documentation/admin-guide/mm/transhuge.rst~docs-vm-remove-unused-3-items-explanation-for-proc-vmstat +0 -15
@@ -401,21 +401,6 @@ compact_fail is incremented if the system tries to compact memory but failed. -compact_pages_moved - is incremented each time a page is moved. If - this value is increasing rapidly, it implies that the system - is copying a lot of data to satisfy the huge page allocation. - It is possible that the cost of copying exceeds any savings - from reduced TLB misses. - -compact_pagemigrate_failed - is incremented when the underlying mechanism - for moving a page failed. - -compact_blocks_moved - is incremented each time memory compaction examines - a huge page aligned range of pages. - It is possible to establish how long the stalls were using the function tracer to record how long was spent in __alloc_pages_nodemask and using the mm_page_alloc tracepoint to identify which allocations were
_
Andrew Morton
maintainerPATCH 100/200 mm/vmalloc.c: fix kasan shadow poisoning size
In reply to Andrew MortonFrom: Vincenzo Frascino <[email protected]>
Subject: mm/vmalloc.c: fix kasan shadow poisoning size
The size of vm area can be affected by the presence or not of the guard page. In particular when VM_NO_GUARD is present, the actual accessible size has to be considered like the real size minus the guard page.
Currently kasan does not keep into account this information during the poison operation and in particular tries to poison the guard page as well.
This approach, even if incorrect, does not cause an issue because the tags for the guard page are written in the shadow memory. With the future introduction of the Tag-Based KASAN, being the guard page inaccessible by nature, the write tag operation on this page triggers a fault.
Fix kasan shadow poisoning size invoking get_vm_area_size() instead of accessing directly the field in the data structure to detect the correct value.
---
mm/vmalloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/vmalloc.c renamed from mm/vmalloc.c~mm-vmalloc-fix-kasan-shadow-poisoning-size +1 -1
@@ -2272,7 +2272,7 @@ static void __vunmap(const void *addr, idebug_check_no_locks_freed (area->addr,get_vm_area_size (area));debug_check_no_obj_freed (area->addr,get_vm_area_size (area)); -kasan_poison_vmalloc (area->addr, area->size); +kasan_poison_vmalloc (area->addr,get_vm_area_size (area));vm_remove_mappings (area, deallocate_pages);
_
Andrew Morton
maintainerPATCH 101/200 workqueue: kasan: record workqueue stack
In reply to Andrew MortonFrom: Walter Wu <[email protected]>
Subject: workqueue: kasan: record workqueue stack
Patch series "kasan: add workqueue stack for generic KASAN", v5.
Syzbot reports many UAF issues for workqueue, see [1]. In some of these access/allocation happened in process_one_work(), we see the free stack is useless in KASAN report, it doesn't help programmers to solve UAF for workqueue issue.
This patchset improves KASAN reports by making them to have workqueue queueing stack. It is useful for programmers to solve use-after-free or double-free memory issue.
Generic KASAN also records the last two workqueue stacks and prints them in KASAN report. It is only suitable for generic KASAN.
[1]https://groups.google.com/g/syzkaller-bugs/search?q=%22use-after-free%22+process_one_work [2]https://bugzilla.kernel.org/show_bug.cgi?id=198437
This patch (of 4):
When analyzing use-after-free or double-free issue, recording the enqueuing work stacks is helpful to preserve usage history which potentially gives a hint about the affected code.
For workqueue it has turned out to be useful to record the enqueuing work call stacks. Because user can see KASAN report to determine whether it is root cause. They don't need to enable debugobjects, but they have a chance to find out the root cause.
---
kernel/workqueue.c | 3 +++ 1 file changed, 3 insertions(+)
kernel/workqueue.c renamed from kernel/workqueue.c~workqueue-kasan-record-workqueue-stack +3 -0
@@ -1327,6 +1327,9 @@ static void insert_work(struct pool_work {struct worker_pool *pool = pwq->pool; +/* record the work call stack in order to print it in KASAN reports */ +kasan_record_aux_stack (work); +/* we own @work, set data and link */ set_work_pwq (work, pwq, extra_flags);list_add_tail (&work->entry, head);
_
Andrew Morton
maintainerPATCH 102/200 kasan: print workqueue stack
In reply to Andrew MortonFrom: Walter Wu <[email protected]>
Subject: kasan: print workqueue stack
The aux_stack[2] is reused to record the call_rcu() call stack and enqueuing work call stacks. So that we need to change the auxiliary stack title for common title, print them in KASAN report.
---
mm/kasan/generic.c | 3 --- mm/kasan/report.c | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-)
mm/kasan/generic.c renamed from mm/kasan/generic.c~kasan-print-workqueue-stack +0 -3
@@ -339,9 +339,6 @@ void kasan_record_aux_stack(void *addr) object =nearest_obj (cache, page, addr); alloc_info =get_alloc_info (cache, object); -/* -* record the last two call_rcu() call stacks. -*/ alloc_info->aux_stack[1 ] = alloc_info->aux_stack[0 ]; alloc_info->aux_stack[0 ] =kasan_save_stack (GFP_NOWAIT ); }
mm/kasan/report.c renamed from mm/kasan/report.c~kasan-print-workqueue-stack +2 -2
@@ -185,12 +185,12 @@ static void describe_object(struct kmem_#ifdef CONFIG_KASAN_GENERIC if (alloc_info->aux_stack[0 ]) { -pr_err ("Last call_rcu():\n" ); +pr_err ("Last potentially related work creation:\n" );print_stack (alloc_info->aux_stack[0 ]);pr_err ("\n" ); }if (alloc_info->aux_stack[1 ]) { -pr_err ("Second to last call_rcu():\n" ); +pr_err ("Second to last potentially related work creation:\n" );print_stack (alloc_info->aux_stack[1 ]);pr_err ("\n" ); }
_
Andrew Morton
maintainerPATCH 103/200 lib/test_kasan.c: add workqueue test case
In reply to Andrew MortonFrom: Walter Wu <[email protected]>
Subject: lib/test_kasan.c: add workqueue test case
Adds a test to verify workqueue stack recording and print it in KASAN report.
The KASAN report was as follows(cleaned up slightly):
BUG: KASAN: use-after-free in kasan_workqueue_uaf Freed by task 54: kasan_save_stack+0x24/0x50 kasan_set_track+0x24/0x38 kasan_set_free_info+0x20/0x40 __kasan_slab_free+0x10c/0x170 kasan_slab_free+0x10/0x18 kfree+0x98/0x270 kasan_workqueue_work+0xc/0x18 Last potentially related work creation: kasan_save_stack+0x24/0x50 kasan_record_wq_stack+0xa8/0xb8 insert_work+0x48/0x288 __queue_work+0x3e8/0xc40 queue_work_on+0xf4/0x118 kasan_workqueue_uaf+0xfc/0x190
---
lib/test_kasan_module.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
lib/test_kasan_module.c renamed from lib/test_kasan_module.c~lib-test_kasanc-add-workqueue-test-case +29 -0
@@ -91,6 +91,34 @@ static noinline void __init kasan_rcu_uacall_rcu (&global_rcu_ptr->rcu, kasan_rcu_reclaim); } +static noinline void __init kasan_workqueue_work(struct work_struct *work) +{ +kfree (work); +} + +static noinline void __init kasan_workqueue_uaf(void) +{ +struct workqueue_struct *workqueue; +struct work_struct *work; + + workqueue =create_workqueue ("kasan_wq_test" ); +if (!workqueue) { +pr_err ("Allocation failed\n" ); +return ; + } + work =kmalloc (sizeof (struct work_struct ),GFP_KERNEL ); +if (!work) { +pr_err ("Allocation failed\n" ); +return ; + } + +INIT_WORK (work, kasan_workqueue_work); +queue_work (workqueue, work); +destroy_workqueue (workqueue); + +pr_info ("use-after-free on workqueue\n" ); + ((volatile struct work_struct *)work)->data; +}static int __init test_kasan_module_init (void ) {
@@ -102,6 +130,7 @@ static int __init test_kasan_module_initcopy_user_test ();kasan_rcu_uaf (); +kasan_workqueue_uaf ();kasan_restore_multi_shot (multishot);return -EAGAIN ;
_
Andrew Morton
maintainerPATCH 104/200 kasan: update documentation for generic kasan
In reply to Andrew MortonFrom: Walter Wu <[email protected]>
Subject: kasan: update documentation for generic kasan
Generic KASAN also supports to record the last two workqueue stacks and print them in KASAN report. So that need to update documentation.
---
Documentation/dev-tools/kasan.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
Documentation/dev-tools/kasan.rst renamed from Documentation/dev-tools/kasan.rst~kasan-update-documentation-for-generic-kasan +3 -2
@@ -190,8 +190,9 @@ function calls GCC directly inserts the This option significantly enlarges kernel but it gives x1.1-x2 performance boost over outline instrumented kernel. -Generic KASAN prints up to 2 call_rcu() call stacks in reports, the last one -and the second to last. +Generic KASAN also reports the last 2 call stacks to creation of work that +potentially has access to an object. Call stacks for the following are shown: +call_rcu() and workqueue queuing. Software tag-based KASAN ~~~~~~~~~~~~~~~~~~~~~~~~
_
Andrew Morton
maintainerPATCH 105/200 lkdtm: disable KASAN for rodata.o
In reply to Andrew MortonFrom: Marco Elver <[email protected]>
Subject: lkdtm: disable KASAN for rodata.o
Building lkdtm with KASAN and Clang 11 or later results in the following error when attempting to load the module:
kernel tried to execute NX-protected page - exploit attempt? (uid: 0)
BUG: unable to handle page fault for address: ffffffffc019cd70 #PF: supervisor instruction fetch in kernel mode #PF: error_code(0x0011) - permissions violation ... RIP: 0010:asan.module_ctor+0x0/0xffffffffffffa290 [lkdtm] ... Call Trace: do_init_module+0x17c/0x570 load_module+0xadee/0xd0b0 __x64_sys_finit_module+0x16c/0x1a0 do_syscall_64+0x34/0x50 entry_SYSCALL_64_after_hwframe+0x44/0xa9
The reason is that rodata.o generates a dummy function that lives in .rodata to validate that .rodata can't be executed; however, Clang 11 adds KASAN globals support by generating module constructors to initialize globals redzones. When Clang 11 adds a module constructor to rodata.o, it is also added to .rodata: any attempt to call it on initialization results in the above error.
Therefore, disable KASAN instrumentation for rodata.o.
---
drivers/misc/lkdtm/Makefile | 1 + 1 file changed, 1 insertion(+)
drivers/misc/lkdtm/Makefile renamed from drivers/misc/lkdtm/Makefile~lkdtm-disable-kasan-for-rodatao +1 -0
@@ -11,6 +11,7 @@ lkdtm-$(CONFIG_LKDTM) += usercopy.o lkdtm-$(CONFIG_LKDTM) += stackleak.o lkdtm-$(CONFIG_LKDTM) += cfi.o +KASAN_SANITIZE_rodata.o := n KASAN_SANITIZE_stackleak.o := n KCOV_INSTRUMENT_rodata.o := n
_
Andrew Morton
maintainerPATCH 106/200 alpha: switch from DISCONTIGMEM to SPARSEMEM
In reply to Andrew MortonFrom: Mike Rapoport <[email protected]>
Subject: alpha: switch from DISCONTIGMEM to SPARSEMEM
Patch series "arch, mm: deprecate DISCONTIGMEM", v2.
It's been a while since DISCONTIGMEM is generally considered deprecated, but it is still used by four architectures. This set replaces DISCONTIGMEM with a different way to handle holes in the memory map and marks DISCONTIGMEM configuration as BROKEN in Kconfigs of these architectures with the intention to completely remove it in several releases.
While for 64-bit alpha and ia64 the switch to SPARSEMEM is quite obvious and was a matter of moving some bits around, for smaller 32-bit arc and m68k SPARSEMEM is not necessarily the best thing to do.
On 32-bit machines SPARSEMEM would require large sections to make section index fit in the page flags, but larger sections mean that more memory is wasted for unused memory map.
Besides, pfn_to_page() and page_to_pfn() become less efficient, at least on arc.
So I've decided to generalize arm's approach for freeing of unused parts of the memory map with FLATMEM and enable it for both arc and m68k. The details are in the description of patches 10 (arc) and 13 (m68k).
This patch (of 13):
Enable SPARSEMEM support on alpha and deprecate DISCONTIGMEM.
The required changes are mostly around moving duplicated definitions of page access and address conversion macros to a common place and making sure they are available for all memory models.
The DISCONTINGMEM support is marked as BROKEN an will be removed in a couple of releases.
---
arch/alpha/Kconfig | 8 ++++++++ arch/alpha/include/asm/mmzone.h | 14 ++------------ arch/alpha/include/asm/page.h | 7 ++++--- arch/alpha/include/asm/pgtable.h | 12 +++++------- arch/alpha/include/asm/sparsemem.h | 18 ++++++++++++++++++ arch/alpha/kernel/setup.c | 1 + 6 files changed, 38 insertions(+), 22 deletions(-)
arch/alpha/include/asm/mmzone.h renamed from arch/alpha/include/asm/mmzone.h~alpha-switch-from-discontigmem-to-sparsemem +2 -12
@@ -6,6 +6,8 @@#ifndef _ASM_MMZONE_H_#define _ASM_MMZONE_H_ +#ifdef CONFIG_DISCONTIGMEM +#include <asm/smp.h> /*
@@ -45,8 +47,6 @@ PLAT_NODE_DATA_LOCALNR(unsigned long p, }#endif -#ifdef CONFIG_DISCONTIGMEM -/* * Following are macros that each numa implementation must define. */
@@ -68,11 +68,6 @@ PLAT_NODE_DATA_LOCALNR(unsigned long p,/* XXX: FIXME -- nyc */ #define kern_addr_valid (kaddr) (0) -#define virt_to_page (kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT) - -#define pmd_page (pmd) (pfn_to_page(pmd_val(pmd) >> 32)) -#define pte_pfn (pte) (pte_val(pte) >> 32) -#define mk_pte (page, pgprot) \ ({ \ pte_t pte; \
@@ -95,16 +90,11 @@ PLAT_NODE_DATA_LOCALNR(unsigned long p, __xx; \ }) -#define page_to_pa (page) \ - (page_to_pfn(page) << PAGE_SHIFT) -#define pfn_to_nid (pfn) pa_to_nid(((u64)(pfn) << PAGE_SHIFT))#define pfn_valid (pfn) \ (((pfn) - node_start_pfn(pfn_to_nid(pfn))) < \ node_spanned_pages(pfn_to_nid(pfn))) \ -#define virt_addr_valid (kaddr) pfn_valid((__pa(kaddr) >> PAGE_SHIFT)) -#endif /* CONFIG_DISCONTIGMEM */ #endif /* _ASM_MMZONE_H_ */
arch/alpha/include/asm/page.h renamed from arch/alpha/include/asm/page.h~alpha-switch-from-discontigmem-to-sparsemem +4 -3
@@ -83,12 +83,13 @@ typedef struct page *pgtable_t;#define __pa (x) ((unsigned long) (x) - PAGE_OFFSET)#define __va (x) ((void *)((unsigned long) (x) + PAGE_OFFSET)) -#ifndef CONFIG_DISCONTIGMEM +#define virt_to_page (kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT) +#define virt_addr_valid (kaddr) pfn_valid((__pa(kaddr) >> PAGE_SHIFT)) +#ifdef CONFIG_FLATMEM #define pfn_valid (pfn) ((pfn) < max_mapnr) -#define virt_addr_valid (kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT) -#endif /* CONFIG_DISCONTIGMEM */ +#endif /* CONFIG_FLATMEM */ #include <asm-generic/memory_model.h> #include <asm-generic/getorder.h>
arch/alpha/include/asm/pgtable.h renamed from arch/alpha/include/asm/pgtable.h~alpha-switch-from-discontigmem-to-sparsemem +5 -7
@@ -203,10 +203,10 @@ extern unsigned long __zero_page(void);* Conversion functions: convert a page and protection to a page entry, * and a page entry and page directory to the page they refer to. */ -#ifndef CONFIG_DISCONTIGMEM -#define page_to_pa (page) (((page) - mem_map) << PAGE_SHIFT) - +#define page_to_pa (page) (page_to_pfn(page) << PAGE_SHIFT)#define pte_pfn (pte) (pte_val(pte) >> 32) + +#ifndef CONFIG_DISCONTIGMEM #define pte_page (pte) pfn_to_page(pte_pfn(pte))#define mk_pte (page, pgprot) \ ({ \
@@ -236,10 +236,8 @@ pmd_page_vaddr(pmd_t pmd)return ((pmd_val (pmd) & _PFN_MASK) >> (32 -PAGE_SHIFT )) +PAGE_OFFSET ; } -#ifndef CONFIG_DISCONTIGMEM -#define pmd_page (pmd) (mem_map + ((pmd_val(pmd) & _PFN_MASK) >> 32)) -#define pud_page (pud) (mem_map + ((pud_val(pud) & _PFN_MASK) >> 32)) -#endif +#define pmd_page (pmd) (pfn_to_page(pmd_val(pmd) >> 32)) +#define pud_page (pud) (pfn_to_page(pud_val(pud) >> 32))extern inline unsigned long pud_page_vaddr (pud_t pgd) {return PAGE_OFFSET + ((pud_val (pgd) & _PFN_MASK) >> (32 -PAGE_SHIFT )); }
arch/alpha/include/asm/sparsemem.h new file +18 -0
@@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_ALPHA_SPARSEMEM_H +#define _ASM_ALPHA_SPARSEMEM_H + +#ifdef CONFIG_SPARSEMEM + +#define SECTION_SIZE_BITS 27 + +/* +* According to "Alpha Architecture Reference Manual" physical +* addresses are at most 48 bits. +* https://download.majix.org/dec/alpha_arch_ref.pdf +*/ +#define MAX_PHYSMEM_BITS 48 + +#endif /* CONFIG_SPARSEMEM */ + +#endif /* _ASM_ALPHA_SPARSEMEM_H */
arch/alpha/Kconfig renamed from arch/alpha/Kconfig~alpha-switch-from-discontigmem-to-sparsemem +8 -0
@@ -40,6 +40,7 @@ config ALPHA select CPU_NO_EFFICIENT_FFS if !ALPHA_EV67 select MMU_GATHER_NO_RANGE select SET_FS + select SPARSEMEM_EXTREME if SPARSEMEM help The Alpha is a 64-bit general-purpose processor designed and marketed by the Digital Equipment Corporation of blessed memory,
@@ -551,12 +552,19 @@ config NR_CPUS config ARCH_DISCONTIGMEM_ENABLE bool "Discontiguous Memory Support" + depends on BROKEN help Say Y to support efficient handling of discontiguous physical memory, for architectures which are either NUMA (Non-Uniform Memory Access) or have huge holes in the physical address space for other reasons. See <file:Documentation/vm/numa.rst> for more. +config ARCH_SPARSEMEM_ENABLE + bool "Sparse Memory Support" + help + Say Y to support efficient handling of discontiguous physical memory, + for systems that have huge holes in the physical address space. + config NUMA bool "NUMA Support (EXPERIMENTAL)" depends on DISCONTIGMEM && BROKEN
arch/alpha/kernel/setup.c renamed from arch/alpha/kernel/setup.c~alpha-switch-from-discontigmem-to-sparsemem +1 -0
@@ -648,6 +648,7 @@ setup_arch(char **cmdline_p)/* Find our memory. */ setup_memory (kernel_end);memblock_set_bottom_up (true); +sparse_init ();/* First guess at cpu cache sizes. Do this before init_arch. */ determine_cpu_caches (cpu->type);
_
Andrew Morton
maintainerPATCH 107/200 ia64: remove custom __early_pfn_to_nid()
In reply to Andrew MortonFrom: Mike Rapoport <[email protected]>
Subject: ia64: remove custom __early_pfn_to_nid()
The ia64 implementation of __early_pfn_to_nid() essentially relies on the same data as the generic implementation.
The correspondence between memory ranges and nodes is set in memblock during early memory initialization in register_active_ranges() function.
The initialization of sparsemem that requires early_pfn_to_nid() happens later and it can use the memblock information like the other architectures.
---
arch/ia64/Kconfig | 3 --- arch/ia64/mm/numa.c | 30 ------------------------------ include/linux/mm.h | 3 --- include/linux/mmzone.h | 11 ----------- mm/page_alloc.c | 16 ++++++++++++---- 5 files changed, 12 insertions(+), 51 deletions(-)
arch/ia64/Kconfig renamed from arch/ia64/Kconfig~ia64-remove-custom-__early_pfn_to_nid +0 -3
@@ -342,9 +342,6 @@ config HOLES_IN_ZONE bool default y if VIRTUAL_MEM_MAP -config HAVE_ARCH_EARLY_PFN_TO_NID - def_bool NUMA && SPARSEMEM - config HAVE_ARCH_NODEDATA_EXTENSION def_bool y depends on NUMA
arch/ia64/mm/numa.c renamed from arch/ia64/mm/numa.c~ia64-remove-custom-__early_pfn_to_nid +0 -30
@@ -58,36 +58,6 @@ paddr_to_nid(unsigned long paddr)EXPORT_SYMBOL (paddr_to_nid);#if defined(CONFIG_SPARSEMEM ) && defined(CONFIG_NUMA ) -/* -* Because of holes evaluate on section limits. -* If the section of memory exists, then return the node where the section -* resides. Otherwise return node 0 as the default. This is used by -* SPARSEMEM to allocate the SPARSEMEM sectionmap on the NUMA node where -* the section resides. -*/ -int __meminit __early_pfn_to_nid (unsigned long pfn, -struct mminit_pfnnid_cache *state) -{ -int i, section = pfn >>PFN_SECTION_SHIFT , ssec, esec; - -if (section >= state->last_start && section < state->last_end) -return state->last_nid; - -for (i =0 ; i < num_node_memblks; i++) { - ssec = node_memblk[i].start_paddr >>PA_SECTION_SHIFT ; - esec = (node_memblk[i].start_paddr + node_memblk[i].size + - ((1L <<PA_SECTION_SHIFT ) -1 )) >>PA_SECTION_SHIFT ; -if (section >= ssec && section < esec) { - state->last_start = ssec; - state->last_end = esec; - state->last_nid = node_memblk[i].nid; -return node_memblk[i].nid; - } - } - -return -1 ; -} -void numa_clear_node (int cpu) {unmap_cpu_from_node (cpu,NUMA_NO_NODE );
include/linux/mm.h renamed from include/linux/mm.h~ia64-remove-custom-__early_pfn_to_nid +0 -3
@@ -2434,9 +2434,6 @@ static inline int early_pfn_to_nid(unsig#else /* please see mm/page_alloc.c */ extern int __meminit early_pfn_to_nid (unsigned long pfn); -/* there is a per-arch backend function. */ -extern int __meminit __early_pfn_to_nid (unsigned long pfn, -struct mminit_pfnnid_cache *state);#endif extern void set_dma_reserve (unsigned long new_dma_reserve);
include/linux/mmzone.h renamed from include/linux/mmzone.h~ia64-remove-custom-__early_pfn_to_nid +0 -11
@@ -1429,17 +1429,6 @@ void sparse_init(void);#endif /* CONFIG_SPARSEMEM */ /* -* During memory init memblocks map pfns to nids. The search is expensive and -* this caches recent lookups. The implementation of __early_pfn_to_nid -* may treat start/end as pfns or sections. -*/ -struct mminit_pfnnid_cache { -unsigned long last_start; -unsigned long last_end; -int last_nid; -}; - -/* * If it is possible to have holes within a MAX_ORDER_NR_PAGES, then we * need to check pfn validity within that MAX_ORDER_NR_PAGES block. * pfn_valid_within() should be used in this case; we optimise this away
mm/page_alloc.c renamed from mm/page_alloc.c~ia64-remove-custom-__early_pfn_to_nid +12 -4
@@ -1559,14 +1559,23 @@ void __free_pages_core(struct page *page#ifdef CONFIG_NEED_MULTIPLE_NODES -static struct mminit_pfnnid_cache early_pfnnid_cache __meminitdata; +/* +* During memory init memblocks map pfns to nids. The search is expensive and +* this caches recent lookups. The implementation of __early_pfn_to_nid +* treats start/end as pfns. +*/ +struct mminit_pfnnid_cache { +unsigned long last_start; +unsigned long last_end; +int last_nid; +}; -#ifndef CONFIG_HAVE_ARCH_EARLY_PFN_TO_NID +static struct mminit_pfnnid_cache early_pfnnid_cache__meminitdata ;/* * Required by SPARSEMEM. Given a PFN, return what node the PFN is on. */ -int __meminit __early_pfn_to_nid(unsigned long pfn, +static int __meminit __early_pfn_to_nid (unsigned long pfn,struct mminit_pfnnid_cache *state) {unsigned long start_pfn, end_pfn;
@@ -1584,7 +1593,6 @@ int __meminit __early_pfn_to_nid(unsignereturn nid; } -#endif /* CONFIG_HAVE_ARCH_EARLY_PFN_TO_NID */ int __meminit early_pfn_to_nid (unsigned long pfn) {
_
Andrew Morton
maintainerPATCH 108/200 ia64: remove 'ifdef CONFIG_ZONE_DMA32' statements
In reply to Andrew MortonFrom: Mike Rapoport <[email protected]>
Subject: ia64: remove 'ifdef CONFIG_ZONE_DMA32' statements
After the removal of SN2 platform (commit cf07cb1ff4ea ("ia64: remove support for the SGI SN2 platform") IA-64 always has ZONE_DMA32 and there is no point to guard code with this configuration option.
Remove ifdefery associated with CONFIG_ZONE_DMA32
---
arch/ia64/mm/contig.c | 2 -- arch/ia64/mm/discontig.c | 2 -- 2 files changed, 4 deletions(-)
arch/ia64/mm/contig.c renamed from arch/ia64/mm/contig.c~ia64-remove-ifdef-config_zone_dma32-statements +0 -2
@@ -177,10 +177,8 @@ paging_init (void)unsigned long max_zone_pfns[MAX_NR_ZONES ];memset (max_zone_pfns,0 ,sizeof (max_zone_pfns)); -#ifdef CONFIG_ZONE_DMA32 max_dma =virt_to_phys ((void *)MAX_DMA_ADDRESS ) >>PAGE_SHIFT ; max_zone_pfns[ZONE_DMA32 ] = max_dma; -#endif max_zone_pfns[ZONE_NORMAL ] = max_low_pfn;#ifdef CONFIG_VIRTUAL_MEM_MAP
arch/ia64/mm/discontig.c renamed from arch/ia64/mm/discontig.c~ia64-remove-ifdef-config_zone_dma32-statements +0 -2
@@ -621,9 +621,7 @@ void __init paging_init(void) }memset (max_zone_pfns,0 ,sizeof (max_zone_pfns)); -#ifdef CONFIG_ZONE_DMA32 max_zone_pfns[ZONE_DMA32 ] = max_dma; -#endif max_zone_pfns[ZONE_NORMAL ] = max_pfn;free_area_init (max_zone_pfns);
_
Andrew Morton
maintainerPATCH 109/200 ia64: discontig: paging_init(): remove local max_pfn calculation
In reply to Andrew MortonFrom: Mike Rapoport <[email protected]>
Subject: ia64: discontig: paging_init(): remove local max_pfn calculation
The maximal PFN in the system is calculated during find_memory() time and it is stored at max_low_pfn then.
Use this value in paging_init() and remove the redundant detection of max_pfn in that function.
---
arch/ia64/mm/discontig.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
arch/ia64/mm/discontig.c renamed from arch/ia64/mm/discontig.c~ia64-discontig-paging_init-remove-local-max_pfn-calculation +1 -4
@@ -594,7 +594,6 @@ void __init paging_init(void) {unsigned long max_dma;unsigned long pfn_offset =0 ; -unsigned long max_pfn =0 ;int node;unsigned long max_zone_pfns[MAX_NR_ZONES ];
@@ -616,13 +615,11 @@ void __init paging_init(void)#ifdef CONFIG_VIRTUAL_MEM_MAP NODE_DATA (node)->node_mem_map = vmem_map + pfn_offset;#endif -if (mem_data[node].max_pfn > max_pfn) - max_pfn = mem_data[node].max_pfn; }memset (max_zone_pfns,0 ,sizeof (max_zone_pfns)); max_zone_pfns[ZONE_DMA32 ] = max_dma; - max_zone_pfns[ZONE_NORMAL ] = max_pfn; + max_zone_pfns[ZONE_NORMAL ] = max_low_pfn;free_area_init (max_zone_pfns); zero_page_memmap_ptr =virt_to_page (ia64_imva (empty_zero_page));
_