incoming
Subsystems (42)
Andrew Morton
maintainer40 patches, based on 9d9af1007bc08971953ae915d88dc9bb21344b53.
Subsystems affected by this patch series:
ia64
mm/memcg
mm/migration
mm/pagemap
mm/gup
mm/madvise
mm/vmalloc
misc
Subsystem: ia64
Krzysztof Kozlowski <[email protected]>:
ia64: fix build error with !COREDUMP
Subsystem: mm/memcg
Roman Gushchin <[email protected]>:
mm, memcg: rework remote charging API to support nesting
Patch series "mm: kmem: kernel memory accounting in an interrupt context":
mm: kmem: move memcg_kmem_bypass() calls to get_mem/obj_cgroup_from_current()
mm: kmem: remove redundant checks from get_obj_cgroup_from_current()
mm: kmem: prepare remote memcg charging infra for interrupt contexts
mm: kmem: enable kernel memcg accounting from interrupt contexts
Subsystem: mm/migration
Joonsoo Kim <[email protected]>:
mm/memory-failure: remove a wrapper for alloc_migration_target() mm/memory_hotplug: remove a wrapper for alloc_migration_target()
Miaohe Lin <[email protected]>:
mm/migrate: avoid possible unnecessary process right check in kernel_move_pages()
Subsystem: mm/pagemap
"Liam R. Howlett" <[email protected]>:
mm/mmap: add inline vma_next() for readability of mmap code mm/mmap: add inline munmap_vma_range() for code readability
Subsystem: mm/gup
Jann Horn <[email protected]>:
mm/gup_benchmark: take the mmap lock around GUP
binfmt_elf: take the mmap lock around find_extend_vma() mm/gup: assert that the mmap lock is held in __get_user_pages()
John Hubbard <[email protected]>:
Patch series "selftests/vm: gup_test, hmm-tests, assorted improvements", v2:
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: 10x speedup for hmm-tests
Subsystem: mm/madvise
Minchan Kim <[email protected]>:
Patch series "introduce memory hinting API for external process", v9:
mm/madvise: pass mm to do_madvise
pid: move pidfd_get_pid() to pid.c
mm/madvise: introduce process_madvise() syscall: an external memory hinting API
Subsystem: mm/vmalloc
"Matthew Wilcox (Oracle)" <[email protected]>:
Patch series "remove alloc_vm_area", v4:
mm: update the documentation for vfree
Christoph Hellwig <[email protected]>:
mm: add a VM_MAP_PUT_PAGES flag for vmap
mm: add a vmap_pfn function
mm: allow a NULL fn callback in apply_to_page_range
zsmalloc: switch from alloc_vm_area to get_vm_area drm/i915: use vmap in shmem_pin_map
drm/i915: stop using kmap in i915_gem_object_map drm/i915: use vmap in i915_gem_object_map
xen/xenbus: use apply_to_page_range directly in xenbus_map_ring_pv x86/xen: open code alloc_vm_area in arch_gnttab_valloc
mm: remove alloc_vm_area
Patch series "two small vmalloc cleanups":
mm: cleanup the gfp_mask handling in __vmalloc_area_node
mm: remove the filename in the top of file comment in vmalloc.c
Subsystem: misc
Tian Tao <[email protected]>:
mm: remove duplicate include statement in mmu.c
Documentation/core-api/pin_user_pages.rst | 8 arch/alpha/kernel/syscalls/syscall.tbl | 1 arch/arm/mm/mmu.c | 1 arch/arm/tools/syscall.tbl | 1 arch/arm64/include/asm/unistd.h | 2 arch/arm64/include/asm/unistd32.h | 2 arch/ia64/kernel/Makefile | 2 arch/ia64/kernel/syscalls/syscall.tbl | 1 arch/m68k/kernel/syscalls/syscall.tbl | 1 arch/microblaze/kernel/syscalls/syscall.tbl | 1 arch/mips/kernel/syscalls/syscall_n32.tbl | 1 arch/mips/kernel/syscalls/syscall_n64.tbl | 1 arch/mips/kernel/syscalls/syscall_o32.tbl | 1 arch/parisc/kernel/syscalls/syscall.tbl | 1 arch/powerpc/kernel/syscalls/syscall.tbl | 1 arch/s390/configs/debug_defconfig | 2 arch/s390/configs/defconfig | 2 arch/s390/kernel/syscalls/syscall.tbl | 1 arch/sh/kernel/syscalls/syscall.tbl | 1 arch/sparc/kernel/syscalls/syscall.tbl | 1 arch/x86/entry/syscalls/syscall_32.tbl | 1 arch/x86/entry/syscalls/syscall_64.tbl | 1 arch/x86/xen/grant-table.c | 27 +- arch/xtensa/kernel/syscalls/syscall.tbl | 1 drivers/gpu/drm/i915/Kconfig | 1 drivers/gpu/drm/i915/gem/i915_gem_pages.c | 136 ++++------ drivers/gpu/drm/i915/gt/shmem_utils.c | 78 +----- drivers/xen/xenbus/xenbus_client.c | 30 +- fs/binfmt_elf.c | 3 fs/buffer.c | 6 fs/io_uring.c | 2 fs/notify/fanotify/fanotify.c | 5 fs/notify/inotify/inotify_fsnotify.c | 5 include/linux/memcontrol.h | 12 include/linux/mm.h | 2 include/linux/pid.h | 1 include/linux/sched/mm.h | 43 +-- include/linux/syscalls.h | 2 include/linux/vmalloc.h | 7 include/uapi/asm-generic/unistd.h | 4 kernel/exit.c | 19 - kernel/pid.c | 19 + kernel/sys_ni.c | 1 mm/Kconfig | 24 + mm/Makefile | 2 mm/gup.c | 2 mm/gup_benchmark.c | 225 ------------------ mm/gup_test.c | 295 +++++++++++++++++++++-- mm/gup_test.h | 40 ++- mm/madvise.c | 125 ++++++++-- mm/memcontrol.c | 83 ++++-- mm/memory-failure.c | 18 - mm/memory.c | 16 - mm/memory_hotplug.c | 46 +-- mm/migrate.c | 71 +++-- mm/mmap.c | 74 ++++- mm/nommu.c | 7 mm/percpu.c | 3 mm/slab.h | 3 mm/vmalloc.c | 147 +++++------ mm/zsmalloc.c | 10 tools/testing/selftests/vm/.gitignore | 3 tools/testing/selftests/vm/Makefile | 40 ++- tools/testing/selftests/vm/check_config.sh | 31 ++ tools/testing/selftests/vm/config | 2 tools/testing/selftests/vm/gup_benchmark.c | 143 ----------- tools/testing/selftests/vm/gup_test.c | 260 ++++++++++++++++++-- tools/testing/selftests/vm/hmm-tests.c | 12 tools/testing/selftests/vm/run_vmtests | 334 -------------------------- tools/testing/selftests/vm/run_vmtests.sh | 350 +++++++++++++++++++++++++++- 70 files changed, 1580 insertions(+), 1224 deletions(-)
Andrew Morton
maintainerPATCH 1/40 ia64: fix build error with !COREDUMP
From: Krzysztof Kozlowski <[email protected]>
Subject: ia64: fix build error with !COREDUMP
Fix linkage error when CONFIG_BINFMT_ELF is selected but CONFIG_COREDUMP is not:
ia64-linux-ld: arch/ia64/kernel/elfcore.o: in function `elf_core_write_extra_phdrs':
elfcore.c:(.text+0x172): undefined reference to `dump_emit'
ia64-linux-ld: arch/ia64/kernel/elfcore.o: in function `elf_core_write_extra_data':
elfcore.c:(.text+0x2b2): undefined reference to `dump_emit'
---
arch/ia64/kernel/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/ia64/kernel/Makefile renamed from arch/ia64/kernel/Makefile~ia64-fix-build-error-with-coredump +1 -1
@@ -40,7 +40,7 @@ obj-y += esi_stub.o # must be in kern endif obj-$(CONFIG_INTEL_IOMMU) += pci-dma.o -obj-$(CONFIG_BINFMT_ELF) += elfcore.o +obj-$(CONFIG_ELF_CORE) += elfcore.o # fp_emulate() expects f2-f5,f16-f31 to contain the user-level state. CFLAGS_traps.o += -mfixed-range=f2-f5,f16-f31
_
Andrew Morton
maintainerPATCH 2/40 mm, memcg: rework remote charging API to support nesting
In reply to Andrew MortonFrom: Roman Gushchin <[email protected]>
Subject: mm, memcg: rework remote charging API to support nesting
Currently the remote memcg charging API consists of two functions:memalloc_use_memcg() and memalloc_unuse_memcg(), which set and clear the memcg value, which overwrites the memcg of the current task.
memalloc_use_memcg(target_memcg); <...> memalloc_unuse_memcg();
It works perfectly for allocations performed from a normal context, however an attempt to call it from an interrupt context or just nest two remote charging blocks will lead to an incorrect accounting. On exit from the inner block the active memcg will be cleared instead of being restored.
memalloc_use_memcg(target_memcg);
memalloc_use_memcg(target_memcg_2);
<...>
memalloc_unuse_memcg(); Error: allocation here are charged to the memcg of the current process instead of target_memcg.
memalloc_unuse_memcg();
This patch extends the remote charging API by switching to a single
function: struct mem_cgroup *set_active_memcg(struct mem_cgroup *memcg), which sets the new value and returns the old one. So a remote charging block will look like:
old_memcg = set_active_memcg(target_memcg); <...> set_active_memcg(old_memcg);
This patch is heavily based on the patch by Johannes Weiner, which can be found here: https://lkml.org/lkml/2020/5/28/806 .
---
fs/buffer.c | 6 ++--- fs/notify/fanotify/fanotify.c | 5 ++-- fs/notify/inotify/inotify_fsnotify.c | 5 ++-- include/linux/sched/mm.h | 30 ++++++++----------------- mm/memcontrol.c | 6 ++--- 5 files changed, 22 insertions(+), 30 deletions(-)
fs/buffer.c renamed from fs/buffer.c~mm-rework-remote-memcg-charging-api-to-support-nesting +3 -3
@@ -842,13 +842,13 @@ struct buffer_head *alloc_page_buffers(sstruct buffer_head *bh, *head;gfp_t gfp =GFP_NOFS | __GFP_ACCOUNT;long offset; -struct mem_cgroup *memcg; +struct mem_cgroup *memcg, *old_memcg;if (retry) gfp |= __GFP_NOFAIL; memcg =get_mem_cgroup_from_page (page); -memalloc_use_memcg (memcg); + old_memcg =set_active_memcg (memcg); head =NULL ; offset =PAGE_SIZE ;
@@ -867,7 +867,7 @@ struct buffer_head *alloc_page_buffers(sset_bh_page (bh, page, offset); } out: -memalloc_unuse_memcg (); +set_active_memcg (old_memcg);mem_cgroup_put (memcg);return head;/*
fs/notify/fanotify/fanotify.c renamed from fs/notify/fanotify/fanotify.c~mm-rework-remote-memcg-charging-api-to-support-nesting +3 -2
@@ -531,6 +531,7 @@ static struct fanotify_event *fanotify_astruct inode *dirid =fanotify_dfid_inode (mask, data, data_type, dir);const struct path *path =fsnotify_data_path (data, data_type);unsigned int fid_mode =FAN_GROUP_FLAG (group,FANOTIFY_FID_BITS ); +struct mem_cgroup *old_memcg;struct inode *child =NULL ;bool name_event = false;
@@ -580,7 +581,7 @@ static struct fanotify_event *fanotify_a gfp |= __GFP_RETRY_MAYFAIL;/* Whoever is interested in the event, pays for the allocation. */ -memalloc_use_memcg (group->memcg); + old_memcg =set_active_memcg (group->memcg);if (fanotify_is_perm_event (mask)) { event =fanotify_alloc_perm_event (path, gfp);
@@ -608,7 +609,7 @@ static struct fanotify_event *fanotify_a event->pid =get_pid (task_tgid (current)); out: -memalloc_unuse_memcg (); +set_active_memcg (old_memcg);return event; }
fs/notify/inotify/inotify_fsnotify.c renamed from fs/notify/inotify/inotify_fsnotify.c~mm-rework-remote-memcg-charging-api-to-support-nesting +3 -2
@@ -66,6 +66,7 @@ static int inotify_one_event(struct fsnoint ret;int len =0 ;int alloc_len =sizeof (struct inotify_event_info ); +struct mem_cgroup *old_memcg;if ((inode_mark->mask &FS_EXCL_UNLINK ) && path &&d_unlinked (path->dentry))
@@ -87,9 +88,9 @@ static int inotify_one_event(struct fsno* trigger OOM killer in the target monitoring memcg as it may have * security repercussion. */ -memalloc_use_memcg (group->memcg); + old_memcg =set_active_memcg (group->memcg); event =kmalloc (alloc_len,GFP_KERNEL_ACCOUNT | __GFP_RETRY_MAYFAIL); -memalloc_unuse_memcg (); +set_active_memcg (old_memcg);if (unlikely (!event)) {/*
include/linux/sched/mm.h renamed from include/linux/sched/mm.h~mm-rework-remote-memcg-charging-api-to-support-nesting +10 -20
@@ -280,38 +280,28 @@ static inline void memalloc_nocma_restor#ifdef CONFIG_MEMCG /** -* memalloc_use_memcg - Starts the remote memcg charging scope. +* set_active_memcg - Starts the remote memcg charging scope. * @memcg: memcg to charge. * * This function marks the beginning of the remote memcg charging scope. All the * __GFP_ACCOUNT allocations till the end of the scope will be charged to the * given memcg. * -* NOTE: This function is not nesting safe. +* NOTE: This function can nest. Users must save the return value and +* reset the previous value after their own charging scope is over. */ -static inline void memalloc_use_memcg (struct mem_cgroup *memcg) +static inline struct mem_cgroup * +set_active_memcg (struct mem_cgroup *memcg) { -WARN_ON_ONCE (current->active_memcg); +struct mem_cgroup *old = current->active_memcg; current->active_memcg = memcg; -} - -/** -* memalloc_unuse_memcg - Ends the remote memcg charging scope. -* -* This function marks the end of the remote memcg charging scope started by -* memalloc_use_memcg(). -*/ -static inline void memalloc_unuse_memcg (void ) -{ - current->active_memcg =NULL ; +return old; }#else -static inline void memalloc_use_memcg (struct mem_cgroup *memcg) -{ -} - -static inline void memalloc_unuse_memcg (void ) +static inline struct mem_cgroup * +set_active_memcg (struct mem_cgroup *memcg) { +return NULL ; }#endif
mm/memcontrol.c renamed from mm/memcontrol.c~mm-rework-remote-memcg-charging-api-to-support-nesting +3 -3
@@ -5290,12 +5290,12 @@ static struct cgroup_subsys_state * __re mem_cgroup_css_alloc(struct cgroup_subsys_state *parent_css) {struct mem_cgroup *parent =mem_cgroup_from_css (parent_css); -struct mem_cgroup *memcg; +struct mem_cgroup *memcg, *old_memcg;long error = -ENOMEM ; -memalloc_use_memcg (parent); + old_memcg =set_active_memcg (parent); memcg =mem_cgroup_alloc (); -memalloc_unuse_memcg (); +set_active_memcg (old_memcg);if (IS_ERR (memcg))return ERR_CAST (memcg);
_
Andrew Morton
maintainerPATCH 3/40 mm: kmem: move memcg_kmem_bypass() calls to get_mem/obj_cgroup_from_current()
In reply to Andrew MortonFrom: Roman Gushchin <[email protected]>
Subject: mm: kmem: move memcg_kmem_bypass() calls to get_mem/obj_cgroup_from_current()
Patch series "mm: kmem: kernel memory accounting in an interrupt context".
This patchset implements memcg-based memory accounting of allocations made from an interrupt context.
Historically, such allocations were passed unaccounted mostly because charging the memory cgroup of the current process wasn't an option. Also performance reasons were likely a reason too.
The remote charging API allows to temporarily overwrite the currently active memory cgroup, so that all memory allocations are accounted towards some specified memory cgroup instead of the memory cgroup of the current process.
This patchset extends the remote charging API so that it can be used from an interrupt context. Then it removes the fence that prevented the accounting of allocations made from an interrupt context. It also contains a couple of optimizations/code refactorings.
This patchset doesn't directly enable accounting for any specific allocations, but prepares the code base for it. The bpf memory accounting will likely be the first user of it: a typical example is a bpf program parsing an incoming network packet, which allocates an entry in hashmap map to store some information.
This patch (of 4):
Currently memcg_kmem_bypass() is called before obtaining the current memory/obj cgroup using get_mem/obj_cgroup_from_current(). Moving memcg_kmem_bypass() into get_mem/obj_cgroup_from_current() reduces the number of call sites and allows further code simplifications.
---
mm/memcontrol.c | 13 ++++++++----- mm/percpu.c | 3 +-- mm/slab.h | 3 --- 3 files changed, 9 insertions(+), 10 deletions(-)
mm/memcontrol.c renamed from mm/memcontrol.c~mm-kmem-move-memcg_kmem_bypass-calls-to-get_mem-obj_cgroup_from_current +8 -5
@@ -1066,6 +1066,9 @@ EXPORT_SYMBOL(get_mem_cgroup_from_page);*/ static __always_inline struct mem_cgroup *get_mem_cgroup_from_current(void) { +if (memcg_kmem_bypass ()) +return NULL ; +if (unlikely (current->active_memcg)) {struct mem_cgroup *memcg;
@@ -2933,6 +2936,9 @@ __always_inline struct obj_cgroup *get_ostruct obj_cgroup *objcg =NULL ;struct mem_cgroup *memcg; +if (memcg_kmem_bypass ()) +return NULL ; +if (unlikely (!current->mm && !current->active_memcg))return NULL ;
@@ -3059,19 +3065,16 @@ int __memcg_kmem_charge_page(struct pagestruct mem_cgroup *memcg;int ret =0 ; -if (memcg_kmem_bypass ()) -return 0 ; - memcg =get_mem_cgroup_from_current (); -if (!mem_cgroup_is_root (memcg)) { +if (memcg && !mem_cgroup_is_root (memcg)) { ret =__memcg_kmem_charge (memcg, gfp,1 << order);if (!ret) { page->mem_cgroup = memcg;__SetPageKmemcg (page);return 0 ; } +css_put (&memcg->css); } -css_put (&memcg->css);return ret; }
mm/percpu.c renamed from mm/percpu.c~mm-kmem-move-memcg_kmem_bypass-calls-to-get_mem-obj_cgroup_from_current +1 -2
@@ -1584,8 +1584,7 @@ static enum pcpu_chunk_type pcpu_memcg_p {struct obj_cgroup *objcg; -if (!memcg_kmem_enabled () || !(gfp & __GFP_ACCOUNT) || -memcg_kmem_bypass ()) +if (!memcg_kmem_enabled () || !(gfp & __GFP_ACCOUNT))return PCPU_CHUNK_ROOT ; objcg =get_obj_cgroup_from_current ();
mm/slab.h renamed from mm/slab.h~mm-kmem-move-memcg_kmem_bypass-calls-to-get_mem-obj_cgroup_from_current +0 -3
@@ -280,9 +280,6 @@ static inline struct obj_cgroup *memcg_s {struct obj_cgroup *objcg; -if (memcg_kmem_bypass ()) -return NULL ; - objcg =get_obj_cgroup_from_current ();if (!objcg)return NULL ;
_
Andrew Morton
maintainerPATCH 4/40 mm: kmem: remove redundant checks from get_obj_cgroup_from_current()
In reply to Andrew MortonFrom: Roman Gushchin <[email protected]>
Subject: mm: kmem: remove redundant checks from get_obj_cgroup_from_current()
There are checks for current->mm and current->active_memcg in get_obj_cgroup_from_current(), but these checks are redundant:memcg_kmem_bypass() called just above performs same checks.
---
mm/memcontrol.c | 3 --- 1 file changed, 3 deletions(-)
mm/memcontrol.c renamed from mm/memcontrol.c~mm-kmem-remove-redundant-checks-from-get_obj_cgroup_from_current +0 -3
@@ -2939,9 +2939,6 @@ __always_inline struct obj_cgroup *get_oif (memcg_kmem_bypass ())return NULL ; -if (unlikely (!current->mm && !current->active_memcg)) -return NULL ; -rcu_read_lock ();if (unlikely (current->active_memcg)) memcg =rcu_dereference (current->active_memcg);
_
Andrew Morton
maintainerPATCH 5/40 mm: kmem: prepare remote memcg charging infra for interrupt contexts
In reply to Andrew MortonFrom: Roman Gushchin <[email protected]>
Subject: mm: kmem: prepare remote memcg charging infra for interrupt contexts
Remote memcg charging API uses current->active_memcg to store the currently active memory cgroup, which overwrites the memory cgroup of the current process. It works well for normal contexts, but doesn't work for interrupt contexts: indeed, if an interrupt occurs during the execution of a section with an active memcg set, all allocations inside the interrupt will be charged to the active memcg set (given that we'll enable accounting for allocations from an interrupt context). But because the interrupt might have no relation to the active memcg set outside, it's obviously wrong from the accounting prospective.
To resolve this problem, let's add a global percpu int_active_memcg variable, which will be used to store an active memory cgroup which will be used from interrupt contexts. set_active_memcg() will transparently use current->active_memcg or int_active_memcg depending on the context.
To make the read part simple and transparent for the caller, let's introduce two new functions:
- struct mem_cgroup *active_memcg(void),
- struct mem_cgroup *get_active_memcg(void).
They are returning the active memcg if it's set, hiding all implementation
details: where to get it depending on the current context.
---
include/linux/sched/mm.h | 13 ++++++++-- mm/memcontrol.c | 48 ++++++++++++++++++++++++++----------- 2 files changed, 45 insertions(+), 16 deletions(-)
include/linux/sched/mm.h renamed from include/linux/sched/mm.h~mm-kmem-prepare-remote-memcg-charging-infra-for-interrupt-contexts +11 -2
@@ -279,6 +279,7 @@ static inline void memalloc_nocma_restor#endif #ifdef CONFIG_MEMCG +DECLARE_PER_CPU(struct mem_cgroup *, int_active_memcg);/** * set_active_memcg - Starts the remote memcg charging scope. * @memcg: memcg to charge.
@@ -293,8 +294,16 @@ static inline void memalloc_nocma_restorstatic inline struct mem_cgroup *set_active_memcg (struct mem_cgroup *memcg) { -struct mem_cgroup *old = current->active_memcg; - current->active_memcg = memcg; +struct mem_cgroup *old; + +if (in_interrupt ()) { + old =this_cpu_read (int_active_memcg); +this_cpu_write (int_active_memcg, memcg); + }else { + old = current->active_memcg; + current->active_memcg = memcg; + } +return old; }#else
mm/memcontrol.c renamed from mm/memcontrol.c~mm-kmem-prepare-remote-memcg-charging-infra-for-interrupt-contexts +34 -14
74 lines not on this page · raw message
_
Andrew Morton
maintainerPATCH 6/40 mm: kmem: enable kernel memcg accounting from interrupt contexts
In reply to Andrew MortonFrom: Roman Gushchin <[email protected]>
Subject: mm: kmem: enable kernel memcg accounting from interrupt contexts
If a memcg to charge can be determined (using remote charging API), there are no reasons to exclude allocations made from an interrupt context from the accounting.
Such allocations will pass even if the resulting memcg size will exceed the hard limit, but it will affect the application of the memory pressure and an inability to put the workload under the limit will eventually trigger the OOM.
To use active_memcg() helper, memcg_kmem_bypass() is moved back to memcontrol.c.
---
include/linux/memcontrol.h | 12 ------------ mm/memcontrol.c | 13 +++++++++++++ 2 files changed, 13 insertions(+), 12 deletions(-)
include/linux/memcontrol.h renamed from include/linux/memcontrol.h~mm-kmem-enable-kernel-memcg-accounting-from-interrupt-contexts +0 -12
@@ -1531,18 +1531,6 @@ static inline bool memcg_kmem_enabled(voreturn static_branch_likely (&memcg_kmem_enabled_key); } -static inline bool memcg_kmem_bypass (void ) -{ -if (in_interrupt ()) -return true; - -/* Allow remote memcg charging in kthread contexts. */ -if ((!current->mm || (current->flags &PF_KTHREAD )) && - !current->active_memcg) -return true; -return false; -} -static inline int memcg_kmem_charge_page (struct page *page,gfp_t gfp,int order) {
mm/memcontrol.c renamed from mm/memcontrol.c~mm-kmem-enable-kernel-memcg-accounting-from-interrupt-contexts +13 -0
@@ -1090,6 +1090,19 @@ static __always_inline struct mem_cgroupreturn memcg; } +static __always_inline bool memcg_kmem_bypass(void) +{ +/* Allow remote memcg charging from any context. */ +if (unlikely (active_memcg ())) +return false; + +/* Memcg to charge can't be determined. */ +if (in_interrupt () || !current->mm || (current->flags &PF_KTHREAD )) +return true; + +return false; +} +/** * If active memcg is set, do not fallback to current->mm->memcg. */
_
Andrew Morton
maintainerPATCH 7/40 mm/memory-failure: remove a wrapper for alloc_migration_target()
In reply to Andrew MortonFrom: Joonsoo Kim <[email protected]>
Subject: mm/memory-failure: remove a wrapper for alloc_migration_target()
There is a well-defined standard migration target callback. Use it directly.
---
mm/memory-failure.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-)
mm/memory-failure.c renamed from mm/memory-failure.c~mm-memory-failure-remove-a-wrapper-for-alloc_migration_target +6 -12
@@ -1673,16 +1673,6 @@ int unpoison_memory(unsigned long pfn) }EXPORT_SYMBOL (unpoison_memory); -static struct page *new_page (struct page *p,unsigned long private) -{ -struct migration_target_control mtc = { - .nid =page_to_nid (p), - .gfp_mask =GFP_USER | __GFP_MOVABLE | __GFP_RETRY_MAYFAIL, - }; - -return alloc_migration_target (p, (unsigned long )&mtc); -} -/* * Safely get reference count of an arbitrary page. * Returns 0 for a free page, -EIO for a zero refcount page
@@ -1797,6 +1787,10 @@ static int __soft_offline_page(struct pachar const *msg_page[] = {"page" ,"hugepage" };bool huge =PageHuge (page);LIST_HEAD (pagelist); +struct migration_target_control mtc = { + .nid =NUMA_NO_NODE , + .gfp_mask =GFP_USER | __GFP_MOVABLE | __GFP_RETRY_MAYFAIL, + };/* * Check PageHWPoison again inside page lock because PageHWPoison
@@ -1833,8 +1827,8 @@ static int __soft_offline_page(struct pa }if (isolate_page (hpage, &pagelist)) { - ret =migrate_pages (&pagelist, new_page,NULL ,MPOL_MF_MOVE_ALL , -MIGRATE_SYNC ,MR_MEMORY_FAILURE ); + ret =migrate_pages (&pagelist, alloc_migration_target,NULL , + (unsigned long )&mtc,MIGRATE_SYNC ,MR_MEMORY_FAILURE );if (!ret) {bool release = !huge;
_
Andrew Morton
maintainerPATCH 8/40 mm/memory_hotplug: remove a wrapper for alloc_migration_target()
In reply to Andrew MortonFrom: Joonsoo Kim <[email protected]>
Subject: mm/memory_hotplug: remove a wrapper for alloc_migration_target()
To calculate the correct node to migrate the page for hotplug, we need to check node id of the page. Wrapper for alloc_migration_target() exists for this purpose.
However, Vlastimil informs that all migration source pages come from a single node. In this case, we don't need to check the node id for each page and we don't need to re-set the target nodemask for each page by using the wrapper. Set up the migration_target_control once and use it for all pages.
---
mm/memory_hotplug.c | 46 ++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 24 deletions(-)
mm/memory_hotplug.c renamed from mm/memory_hotplug.c~mm-memory_hotplug-remove-a-wrapper-for-alloc_migration_target +22 -24
@@ -1290,27 +1290,6 @@ found:return 0 ; } -static struct page *new_node_page (struct page *page,unsigned long private) -{ -nodemask_t nmask = node_states[N_MEMORY ]; -struct migration_target_control mtc = { - .nid =page_to_nid (page), - .nmask = &nmask, - .gfp_mask =GFP_USER | __GFP_MOVABLE | __GFP_RETRY_MAYFAIL, - }; - -/* -* try to allocate from a different node but reuse this node if there -* are no other online nodes to be used (e.g. we are offlining a part -* of the only existing node) -*/ -node_clear (mtc.nid, nmask); -if (nodes_empty (nmask)) -node_set (mtc.nid, nmask); - -return alloc_migration_target (page, (unsigned long )&mtc); -} -static int do_migrate_range (unsigned long start_pfn,unsigned long end_pfn) {
@@ -1370,9 +1349,28 @@ do_migrate_range(unsigned long start_pfnput_page (page); }if (!list_empty (&source)) { -/* Allocate a new page from the nearest neighbor node */ - ret =migrate_pages (&source, new_node_page,NULL ,0 , -MIGRATE_SYNC ,MR_MEMORY_HOTPLUG ); +nodemask_t nmask = node_states[N_MEMORY ]; +struct migration_target_control mtc = { + .nmask = &nmask, + .gfp_mask =GFP_USER | __GFP_MOVABLE | __GFP_RETRY_MAYFAIL, + }; + +/* +* We have checked that migration range is on a single zone so +* we can use the nid of the first page to all the others. +*/ + mtc.nid = page_to_nid(list_first_entry(&source, struct page, lru)); + +/* +* try to allocate from a different node but reuse this node +* if there are no other online nodes to be used (e.g. we are +* offlining a part of the only existing node) +*/ +node_clear (mtc.nid, nmask); +if (nodes_empty (nmask)) +node_set (mtc.nid, nmask); + ret =migrate_pages (&source, alloc_migration_target,NULL , + (unsigned long )&mtc,MIGRATE_SYNC ,MR_MEMORY_HOTPLUG );if (ret) {list_for_each_entry (page, &source, lru) { pr_warn("migrating pfn %lx failed ret:%d ",
_
Andrew Morton
maintainerPATCH 9/40 mm/migrate: avoid possible unnecessary process right check in kernel_move_pages()
In reply to Andrew MortonFrom: Miaohe Lin <[email protected]>
Subject: mm/migrate: avoid possible unnecessary process right check in kernel_move_pages()
There is no need to check if this process has the right to modify the specified process when they are same. And we could also skip the security hook call if a process is modifying its own pages. Add helper function to handle these.
---
mm/migrate.c | 71 +++++++++++++++++++++++++++++-------------------- 1 file changed, 43 insertions(+), 28 deletions(-)
mm/migrate.c renamed from mm/migrate.c~mm-migrate-avoid-possible-unnecessary-process-right-check-in-kernel_move_pages +43 -28
@@ -1864,33 +1864,27 @@ static int do_pages_stat(struct mm_strucreturn nr_pages ? -EFAULT :0 ; } -/* -* Move a list of pages in the address space of the currently executing -* process. -*/ -static int kernel_move_pages (pid_t pid,unsigned long nr_pages, -const void __user *__user *pages, -const int __user *nodes, -int __user *status,int flags) +static struct mm_struct *find_mm_struct (pid_t pid,nodemask_t *mem_nodes) {struct task_struct *task;struct mm_struct *mm; -int err; -nodemask_t task_nodes; - -/* Check flags */ -if (flags & ~(MPOL_MF_MOVE |MPOL_MF_MOVE_ALL )) -return -EINVAL ; -if ((flags &MPOL_MF_MOVE_ALL ) && !capable (CAP_SYS_NICE )) -return -EPERM ; +/* +* There is no need to check if current process has the right to modify +* the specified process when they are same. +*/ +if (!pid) { +mmget (current->mm); + *mem_nodes =cpuset_mems_allowed (current); +return current->mm; + }/* Find the mm_struct */ rcu_read_lock (); - task = pid ?find_task_by_vpid (pid) : current; + task =find_task_by_vpid (pid);if (!task) {rcu_read_unlock (); -return -ESRCH ; +return ERR_PTR (-ESRCH ); }get_task_struct (task);
@@ -1900,22 +1894,47 @@ static int kernel_move_pages(pid_t pid,*/ if (!ptrace_may_access (task,PTRACE_MODE_READ_REALCREDS )) {rcu_read_unlock (); - err = -EPERM ; + mm =ERR_PTR (-EPERM ); goto out; }rcu_read_unlock (); - err =security_task_movememory (task); -if (err) + mm =ERR_PTR (security_task_movememory (task)); +if (IS_ERR (mm)) goto out; - - task_nodes =cpuset_mems_allowed (task); + *mem_nodes =cpuset_mems_allowed (task); mm =get_task_mm (task); +out:put_task_struct (task); -if (!mm) + mm =ERR_PTR (-EINVAL ); +return mm; +} + +/* +* Move a list of pages in the address space of the currently executing +* process. +*/ +static int kernel_move_pages (pid_t pid,unsigned long nr_pages, +const void __user *__user *pages, +const int __user *nodes, +int __user *status,int flags) +{ +struct mm_struct *mm; +int err; +nodemask_t task_nodes; + +/* Check flags */ +if (flags & ~(MPOL_MF_MOVE |MPOL_MF_MOVE_ALL ))return -EINVAL ; +if ((flags &MPOL_MF_MOVE_ALL ) && !capable (CAP_SYS_NICE )) +return -EPERM ; + + mm =find_mm_struct (pid, &task_nodes); +if (IS_ERR (mm)) +return PTR_ERR (mm); +if (nodes) err =do_pages_move (mm, task_nodes, nr_pages, pages, nodes, status, flags);
@@ -1924,10 +1943,6 @@ static int kernel_move_pages(pid_t pid,mmput (mm);return err; - -out: -put_task_struct (task); -return err; } SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
_
Andrew Morton
maintainerPATCH 10/40 mm/mmap: add inline vma_next() for readability of mmap code
In reply to Andrew MortonFrom: "Liam R. Howlett" <[email protected]>
Subject: mm/mmap: add inline vma_next() for readability of mmap code
There are three places that the next vma is required which uses the same block of code. Replace the block with a function and add comments on what happens in the case where NULL is encountered.
---
mm/mmap.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-)
mm/mmap.c renamed from mm/mmap.c~mm-mmap-add-inline-vma_next-for-readability-of-mmap-code +20 -6
@@ -558,6 +558,23 @@ static int find_vma_links(struct mm_strureturn 0 ; } +/* +* vma_next() - Get the next VMA. +* @mm: The mm_struct. +* @vma: The current vma. +* +* If @vma is NULL, return the first vma in the mm. +* +* Returns: The next VMA after @vma. +*/ +static inline struct vm_area_struct *vma_next (struct mm_struct *mm, +struct vm_area_struct *vma) +{ +if (!vma) +return mm->mmap; + +return vma->vm_next; +}static unsigned long count_vma_pages_range (struct mm_struct *mm,unsigned long addr,unsigned long end) {
@@ -1128,10 +1145,7 @@ struct vm_area_struct *vma_merge(structif (vm_flags &VM_SPECIAL )return NULL ; -if (prev) - next = prev->vm_next; -else - next = mm->mmap; + next =vma_next (mm, prev); area = next;if (area && area->vm_end == end)/* cases 6, 7, 8 */ next = next->vm_next;
@@ -2632,7 +2646,7 @@ static void unmap_region(struct mm_struc struct vm_area_struct *vma, struct vm_area_struct *prev, unsigned long start, unsigned long end) { - struct vm_area_struct *next = prev ? prev->vm_next : mm->mmap; + struct vm_area_struct *next = vma_next(mm, prev);struct mmu_gather tlb;lru_add_drain ();
@@ -2831,7 +2845,7 @@ int __do_munmap(struct mm_struct *mm, unif (error)return error; } - vma = prev ? prev->vm_next : mm->mmap; + vma =vma_next (mm, prev);if (unlikely (uf)) {/*
_
Andrew Morton
maintainerPATCH 11/40 mm/mmap: add inline munmap_vma_range() for code readability
In reply to Andrew MortonFrom: "Liam R. Howlett" <[email protected]>
Subject: mm/mmap: add inline munmap_vma_range() for code readability
There are two locations that have a block of code for munmapping a vma range. Change those two locations to use a function and add meaningful comments about what happens to the arguments, which was unclear in the previous code.
---
mm/mmap.c | 48 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 15 deletions(-)
mm/mmap.c renamed from mm/mmap.c~mm-mmap-add-inline-munmap_vma_range-for-code-readability +33 -15
@@ -575,6 +575,33 @@ static inline struct vm_area_struct *vmareturn vma->vm_next; } + +/* +* munmap_vma_range() - munmap VMAs that overlap a range. +* @mm: The mm struct +* @start: The start of the range. +* @len: The length of the range. +* @pprev: pointer to the pointer that will be set to previous vm_area_struct +* @rb_link: the rb_node +* @rb_parent: the parent rb_node +* +* Find all the vm_area_struct that overlap from @start to +* @end and munmap them. Set @pprev to the previous vm_area_struct. +* +* Returns: -ENOMEM on munmap failure or 0 on success. +*/ +static inline int +munmap_vma_range (struct mm_struct *mm,unsigned long start,unsigned long len, +struct vm_area_struct **pprev,struct rb_node ***link, +struct rb_node **parent,struct list_head *uf) +{ + +while (find_vma_links (mm, start, start + len, pprev, link, parent)) +if (do_munmap (mm, start, len, uf)) +return -ENOMEM ; + +return 0 ; +}static unsigned long count_vma_pages_range (struct mm_struct *mm,unsigned long addr,unsigned long end) {
@@ -1721,13 +1748,9 @@ unsigned long mmap_region(struct file *freturn -ENOMEM ; } -/* Clear old maps */ -while (find_vma_links (mm, addr, addr + len, &prev, &rb_link, - &rb_parent)) { -if (do_munmap (mm, addr, len, uf)) -return -ENOMEM ; - } - +/* Clear old maps, set up prev, rb_link, rb_parent, and uf */ +if (munmap_vma_range (mm, addr, len, &prev, &rb_link, &rb_parent, uf)) +return -ENOMEM ;/* * Private writable mapping: check memory availability */
@@ -3063,14 +3086,9 @@ static int do_brk_flags(unsigned long adif (error)return error; -/* -* Clear old maps. this also does some error checking for us -*/ -while (find_vma_links (mm, addr, addr + len, &prev, &rb_link, - &rb_parent)) { -if (do_munmap (mm, addr, len, uf)) -return -ENOMEM ; - } +/* Clear old maps, set up prev, rb_link, rb_parent, and uf */ +if (munmap_vma_range (mm, addr, len, &prev, &rb_link, &rb_parent, uf)) +return -ENOMEM ;/* Check against address space limits *after* clearing old maps... */ if (!may_expand_vm (mm, flags, len >>PAGE_SHIFT ))
_
Andrew Morton
maintainerPATCH 12/40 mm/gup_benchmark: take the mmap lock around GUP
In reply to Andrew MortonFrom: Jann Horn <[email protected]>
Subject: mm/gup_benchmark: take the mmap lock around GUP
To be safe against concurrent changes to the VMA tree, we must take the mmap lock around GUP operations (excluding the GUP-fast family of operations, which will take the mmap lock by themselves if necessary).
This code is only for testing, and it's only reachable by root through debugfs, so this doesn't really have any impact; however, if we want to add lockdep asserts into the GUP path, we need to have clean locking here.
---
mm/gup_benchmark.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
mm/gup_benchmark.c renamed from mm/gup_benchmark.c~mm-gup_benchmark-take-the-mmap-lock-around-gup +12 -3
@@ -72,6 +72,8 @@ static int __gup_benchmark_ioctl(unsigneint nr;struct page **pages;int ret =0 ; +bool needs_mmap_lock = + cmd !=GUP_FAST_BENCHMARK && cmd !=PIN_FAST_BENCHMARK ;if (gup->size >ULONG_MAX )return -EINVAL ;
@@ -81,6 +83,11 @@ static int __gup_benchmark_ioctl(unsigneif (!pages)return -ENOMEM ; +if (needs_mmap_lock &&mmap_read_lock_killable (current->mm)) { + ret = -EINTR ; + goto free_pages; + } + i =0 ; nr = gup->nr_pages_per_call; start_time =ktime_get ();
@@ -120,9 +127,8 @@ static int __gup_benchmark_ioctl(unsigne pages + i, NULL);break ;default : -kvfree (pages); ret = -EINVAL ; - goto out; + goto unlock; }if (nr <=0 )
@@ -150,8 +156,11 @@ static int __gup_benchmark_ioctl(unsigne end_time =ktime_get (); gup->put_delta_usec =ktime_us_delta (end_time, start_time); +unlock: +if (needs_mmap_lock) +mmap_read_unlock (current->mm); +free_pages:kvfree (pages); -out:return ret; }
_
Andrew Morton
maintainerPATCH 13/40 binfmt_elf: take the mmap lock around find_extend_vma()
In reply to Andrew MortonFrom: Jann Horn <[email protected]>
Subject: binfmt_elf: take the mmap lock around find_extend_vma()
create_elf_tables() runs after setup_new_exec(), so other tasks can already access our new mm and do things like process_madvise() on it. (At the time I'm writing this commit, process_madvise() is not in mainline yet, but has been in akpm's tree for some time.)
While I believe that there are currently no APIs that would actually allow another process to mess up our VMA tree (process_madvise() is limited to MADV_COLD and MADV_PAGEOUT, and uring and userfaultfd cannot reach an mm under which no syscalls have been executed yet), this seems like an accident waiting to happen.
Let's make sure that we always take the mmap lock around GUP paths as long as another process might be able to see the mm.
(Yes, this diff looks suspicious because we drop the lock before doing anything with vma, but that's because we actually don't do anything with it apart from the NULL check.)
---
fs/binfmt_elf.c | 3 +++ 1 file changed, 3 insertions(+)
fs/binfmt_elf.c renamed from fs/binfmt_elf.c~binfmt_elf-take-the-mmap-lock-around-find_extend_vma +3 -0
@@ -310,7 +310,10 @@ create_elf_tables(struct linux_binprm *b* Grow the stack manually; some architectures have a limit on how * far ahead a user-space access may be in order to grow the stack. */ +if (mmap_read_lock_killable (mm)) +return -EINTR ; vma =find_extend_vma (mm, bprm->p); +mmap_read_unlock (mm);if (!vma)return -EFAULT ;
_
Andrew Morton
maintainerPATCH 14/40 mm/gup: assert that the mmap lock is held in __get_user_pages()
In reply to Andrew MortonFrom: Jann Horn <[email protected]>
Subject: mm/gup: assert that the mmap lock is held in __get_user_pages()
After having cleaned up all GUP callers (except for the atomisp staging driver, which currently gets mmap locking completely wrong [1]) to always ensure that they hold the mmap lock when calling into GUP (unless the mm is not yet globally visible), add an assertion to make sure it stays that way going forward.
[1] https://lore.kernel.org/lkml/CAG48ez3tZAb9JVhw4T5e-i=h2_DUZxfNRTDsagSRCVazNXx5qA@mail.gmail.com/
---
mm/gup.c | 2 ++ 1 file changed, 2 insertions(+)
mm/gup.c renamed from mm/gup.c~mm-gup-assert-that-the-mmap-lock-is-held-in-__get_user_pages +2 -0
@@ -1027,6 +1027,8 @@ static long __get_user_pages(struct mm_sstruct vm_area_struct *vma =NULL ;struct follow_page_context ctx = {NULL }; +mmap_assert_locked (mm); +if (!nr_pages)return 0 ;
_
Jann Horn
reviewerRe: [patch 14/40] mm/gup: assert that the mmap lock is held in __get_user_pages()
Quoted 8 lines · Andrew Morton
From: Jann Horn <[email protected]>
Subject: mm/gup: assert that the mmap lock is held in__get_user_pages()After having cleaned up all GUP callers (except for the atomisp staging driver, which currently gets mmap locking completely wrong [1]) to always ensure that they hold the mmap lock when calling into GUP (unless the mm is not yet globally visible), add an assertion to make sure it stays that way going forward.
Please hold this patch until the replacement for the previous patch in the series (original patch mmap-locking-api-dont-check-locking-if-the-mm-isnt-live-yet, which you are already holding back, and which is replaced by the series
https://lore.kernel.org/linux-mm/[email protected]/
"Broad write-locking of nascent mm in execve") has gone into the mm tree.
Otherwise I believe that this mmap_assert_lock() will cause new lockdep warnings in places like copy_strings().
(Going forward, is there something I should do differently if a similar issue happens again with a series of patches that has already landed in the mm tree but where, after further discussion, parts should be replaced?)
Quoted 28 lines
[1] https://lore.kernel.org/lkml/CAG48ez3tZAb9JVhw4T5e-i=h2_DUZxfNRTDsagSRCVazNXx5qA@mail.gmail.com/
Link https://lkml.kernel.org/r/CAG48ez1GM==OnHpS=ghqZNJPn02FCDUEHc7GQmGRMXUD_aKudg@mail.gmail.com open hereSigned-off-by Jann Horn <[email protected]>Reviewed-by Jason Gunthorpe <[email protected]>Cc "Eric W . Biederman" <[email protected]>Cc John Hubbard <[email protected]>Cc Mauro Carvalho Chehab <[email protected]>Cc Sakari Ailus <[email protected]>Signed-off-by Andrew Morton <[email protected]>---
mm/gup.c | 2 ++ 1 file changed, 2 insertions(+)mm/gup.c renamed from mm/gup.c~mm-gup-assert-that-the-mmap-lock-is-held-in-__get_user_pages +2
-0@@ -1027,6 +1027,8 @@ static long __get_user_pages(struct mm_sstruct vm_area_struct *vma =NULL ;struct follow_page_context ctx = {NULL }; +mmap_assert_locked (mm); +if (!nr_pages)return 0 ;_
Andrew Morton
maintainerPATCH 15/40 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", v2.
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.
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.
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.
This patch (of 8):
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
@@ -100,7 +100,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
@@ -94,7 +94,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
@@ -831,13 +831,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 16/40 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 "../../../../mm/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_benchmark) -#define GUP_BENCHMARK _IOWR('g', 2, struct gup_benchmark) - -/* Similar to above, but use FOLL_PIN instead of FOLL_GET. */ -#define PIN_FAST_BENCHMARK _IOWR('g', 3, struct gup_benchmark) -#define PIN_BENCHMARK _IOWR('g', 4, struct gup_benchmark) -#define PIN_LONGTERM_BENCHMARK _IOWR('g', 5, struct gup_benchmark) -/* Just the flags we need, copied from mm.h: */ #define FOLL_WRITE 0x01/* check pte is writable */ -struct gup_benchmark { -__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_benchmark gup;
tools/testing/selftests/vm/Makefile renamed from tools/testing/selftests/vm/Makefile~selftests-vm-use-a-common-gup_testh +2 -0
@@ -130,3 +130,5 @@ endif $(OUTPUT)/userfaultfd: LDLIBS += -lpthread $(OUTPUT)/mlock-random-test: LDLIBS += -lcap + +$(OUTPUT)/gup_test: ../../../../mm/gup_test.h
_
Re: [patch 16/40] selftests/vm: use a common gup_test.h
mm/gup_test.c line 5
Quoted 6 lines · Andrew Morton
mm/gup_test.c renamed from mm/gup_test.c~selftests-vm-use-a-common-gup_testh +2
-0@@ -4,22 +4,7 @@ +#include "../../../../mm/gup_test.h" +++ a/mm/gup_test.h
There is no way I'm applying a crazy patch like this.
That can't be right.
And even if it works, it *still* isn't right.
Linus
Re: [patch 16/40] selftests/vm: use a common gup_test.h
Quoted 11 lines · Linus Torvalds
mm/gup_test.c line 5
Quoted 6 lines · Andrew Morton
mm/gup_test.c renamed from mm/gup_test.c~selftests-vm-use-a-common-gup_testh +2
-0@@ -4,22 +4,7 @@ +#include "../../../../mm/gup_test.h" +++ a/mm/gup_test.hThere is no way I'm applying a crazy patch like this.
Quoted 3 lines
That can't be right.
And even if it works, it *still* isn't right.
.. and it looks like I'll have to drop all the other gup-test patches too because this one is broken.
Linus
John Hubbard
reviewerRe: [patch 16/40] selftests/vm: use a common gup_test.h
In reply to Linus TorvaldsQuoted 10 lines · Linus Torvalds
mm/gup_test.c line 5
Quoted 6 lines · Andrew Morton
mm/gup_test.c renamed from mm/gup_test.c~selftests-vm-use-a-common-gup_testh +2
-0@@ -4,22 +4,7 @@ +#include "../../../../mm/gup_test.h" +++ a/mm/gup_test.hThere is no way I'm applying a crazy patch like this.
Quoted 6 lines
That can't be right.
And even if it works, it *still* isn't right.
Linus
I feel the same way about the ridiculous ../..'s in the include path. But that seemed to be the accepted way (I even have an email that I'm trying to find, in which someone confirmed that...ah here, it is [1], and I'm adding Jason to CC) for the odd situation of sharing a header file between kernel and user space, for the kselftest world.
If there's a different acceptable way, I'd be delighted to use that.
[1] https://lore.kernel.org/r/[email protected]
thanks,
Signature · 2 lines
John Hubbard NVIDIA
Re: [patch 16/40] selftests/vm: use a common gup_test.h
Quoted 18 lines · John Hubbard
Quoted 10 lines · Linus Torvalds
mm/gup_test.c line 5
Quoted 6 lines · Andrew Morton
mm/gup_test.c renamed from mm/gup_test.c~selftests-vm-use-a-common-gup_testh +2
-0@@ -4,22 +4,7 @@ +#include "../../../../mm/gup_test.h" +++ a/mm/gup_test.hThere is no way I'm applying a crazy patch like this.
Quoted 6 lines
That can't be right.
And even if it works, it *still* isn't right.
Linus
Quoted 7 lines
I feel the same way about the ridiculous ../..'s in the include path. But that seemed to be the accepted way (I even have an email that I'm trying to find, in which someone confirmed that...ah here, it is [1], and I'm adding Jason to CC) for the odd situation of sharing a header file between kernel and user space, for the kselftest world.
If there's a different acceptable way, I'd be delighted to use that.
See where it says:
CFLAGS = -Wall -I ../../../../usr/include $(EXTRA_CFLAGS)
Does adding an extra -I../../../../mm to that line not do the trick?
John Hubbard
reviewerRe: [patch 16/40] selftests/vm: use a common gup_test.h
Quoted 25 lines · Matthew Wilcox
Quoted 24 lines · John Hubbard
Quoted 10 lines · Linus Torvalds
mm/gup_test.c line 5
Quoted 6 lines · Andrew Morton
mm/gup_test.c renamed from mm/gup_test.c~selftests-vm-use-a-common-gup_testh +2
-0@@ -4,22 +4,7 @@ +#include "../../../../mm/gup_test.h" +++ a/mm/gup_test.hThere is no way I'm applying a crazy patch like this.
Quoted 6 lines
That can't be right.
And even if it works, it *still* isn't right.
Linus
I feel the same way about the ridiculous ../..'s in the include path. But that seemed to be the accepted way (I even have an email that I'm trying to find, in which someone confirmed that...ah here, it is [1], and I'm adding Jason to CC) for the odd situation of sharing a header file between kernel and user space, for the kselftest world.
Quoted 8 lines
Quoted 1 line
If there's a different acceptable way, I'd be delighted to use that.
See where it says:
CFLAGS = -Wall -I ../../../../usr/include $(EXTRA_CFLAGS)
Does adding an extra -I../../../../mm to that line not do the trick?
Yes, that works. Here's a differential patch on top of the series to change it over:
tools/testing/selftests/vm/Makefile +1 -1
@@ -23,7 +23,7 @@ MACHINE ?= $(shell echo $(uname_M) | sed -e 's/aarch64.*/arm64/') # LDLIBS. MAKEFLAGS += --no-builtin-rules -CFLAGS = -Wall -I ../../../../usr/include $(EXTRA_CFLAGS) +CFLAGS = -Wall -I ../../../../usr/include -I ../../../../mm $(EXTRA_CFLAGS) LDLIBS = -lrt -lpthread TEST_GEN_FILES = compaction_test TEST_GEN_FILES += gup_test
tools/testing/selftests/vm/gup_test.c +1 -1
@@ -6,7 +6,7 @@#include <sys/mman.h> #include <sys/stat.h> #include <sys/types.h> -#include "../../../../mm/gup_test.h" +#include "gup_test.h" #define MB (1UL << 20)#define PAGE_SIZE sysconf(_SC_PAGESIZE)
thanks,
Signature · 2 lines
John Hubbard NVIDIA
Re: [patch 16/40] selftests/vm: use a common gup_test.h
Quoted 7 lines · John Hubbard
Quoted 4 lines
Does adding an extra -I../../../../mm to that line not do the trick?
Yes, that works. Here's a differential patch on top of the series to change it over:
Guys, you're looking at the wrong thing.
Inside the *tools* subdirectory, that "../../.." thing makes sense. You're in tools/testing/selftests/vm, and those crazy ".." paths are ok. Ugly, but ok.
But the thing I objected to wasn't that tools directory ugliness.
Let me repeat what I found completely and utterly unacceptable, and what you don't seem to have noticed, and what your patch didn't fix or touch:
+++ a/mm/gup_test.c
+#include "../../../../mm/gup_test.h"
Notice what directory it is in? Notice how "../../.." etc is COMPLETELY UNACCEPTABLE GARBAGE.
Linus
John Hubbard
reviewerRe: [patch 16/40] selftests/vm: use a common gup_test.h
Quoted 1 line · Linus Torvalds
On Sun, Oct 18, 2020 at 12:13 PM John Hubbard <[email protected]> wrote:
...
Quoted 12 lines
Guys, you're looking at the wrong thing.
Inside the *tools* subdirectory, that "../../.." thing makes sense. You're in
tools/testing/selftests/vm, and those crazy ".." paths are ok. Ugly, but ok.But the thing I objected to wasn't that tools directory ugliness.
Let me repeat what I found completely and utterly unacceptable, and what you don't seem to have noticed, and what your patch didn't fix or touch:
Quoted 8 lines
+++
a/mm/gup_test.c
+#include "../../../../mm/gup_test.h"Notice what directory it is in? Notice how "../../.." etc is COMPLETELY UNACCEPTABLE GARBAGE.
Linus
aha, yes. yuck. So can we please just fix it up like this? A quick compile test shows that it does build as expected:
mm/gup_test.c +1 -1
@@ -4,7 +4,7 @@#include <linux/uaccess.h> #include <linux/ktime.h> #include <linux/debugfs.h> -#include "../../../../mm/gup_test.h" +#include "gup_test.h" static void put_back_pages (unsigned int cmd,struct page **pages,unsigned long nr_pages,unsigned int gup_test_flags)
Meanwhile, I'll work on coming up with a rationalization for how I let that mistake slip past me. I've got a teenager living under the same roof with me here, so I'm routinely exposed to some truly inspirational ideas for excuses. :)
thanks,
Signature · 2 lines
John Hubbard NVIDIA
John Hubbard
reviewerRe: [patch 16/40] selftests/vm: use a common gup_test.h
Quoted 35 lines · John Hubbard
Quoted 1 line · Linus Torvalds
On Sun, Oct 18, 2020 at 12:13 PM John Hubbard <[email protected]> wrote:
...
Quoted 12 lines
Guys, you're looking at the wrong thing.
Inside the *tools* subdirectory, that "../../.." thing makes sense. You're in
tools/testing/selftests/vm, and those crazy ".." paths are ok. Ugly, but ok.But the thing I objected to wasn't that tools directory ugliness.
Let me repeat what I found completely and utterly unacceptable, and what you don't seem to have noticed, and what your patch didn't fix or touch:
Quoted 8 lines
+++
a/mm/gup_test.c
+#include "../../../../mm/gup_test.h"Notice what directory it is in? Notice how "../../.." etc is COMPLETELY UNACCEPTABLE GARBAGE.
Linus
aha, yes. yuck. So can we please just fix it up like this? A quick compile test shows that it does build as expected:
mm/gup_test.c +0
-0
mm/gup_test.c line 10
Quoted 8 lines
mm/gup_test.c +1
-1@@ -4,7 +4,7 @@ #include <linux/uaccess.h> #include <linux/ktime.h> #include <linux/debugfs.h> -#include "../../../../mm/gup_test.h" +#include "gup_test.h" static void put_back_pages(unsigned int cmd, struct page **pages, unsigned long nr_pages, unsigned int gup_test_flags)
Also, if there is anything I can do to unblock this, such as sending a formal patch, or an updated patch or patchset, please let me know. I realize that this is a low-priority area, but it would still be nice to get it merged and behind us.
thanks,
Signature · 2 lines
John Hubbard NVIDIA
Re: [patch 16/40] selftests/vm: use a common gup_test.h
Quoted 5 lines · John Hubbard
Also, if there is anything I can do to unblock this, such as sending a formal patch, or an updated patch or patchset, please let me know. I realize that this is a low-priority area, but it would still be nice to get it merged and behind us.
So what happens when I notice something like this, I just drop it from my queue, the policy being "this was clearly not ready to be sent to Linus".
That doesn't mean that it's blacklisted, but it does mean that I don't want to see it returned immediately with the superficial thing fixed that I noticed.
That's partly because I feel that people need to take another look and see if there was perhaps something else going on (if I found one small thing, maybe there are others lurking).
But admittedly it's probably mostly because I really don't want to feel like I'm the wall that people throw spaghetti at to see if it sticks. By the time it came to me, it was supposed to be ready (unless I'm actively part of the development of said feature of course - which still happens occasionally, but on the whole is a vanishingly small part of the stuff I merge).
So I do expect to see it again later in some patch submission, just not right now.
Linus
John Hubbard
reviewerRe: [patch 16/40] selftests/vm: use a common gup_test.h
Quoted 26 lines · Linus Torvalds
Quoted 5 lines · John Hubbard
Also, if there is anything I can do to unblock this, such as sending a formal patch, or an updated patch or patchset, please let me know. I realize that this is a low-priority area, but it would still be nice to get it merged and behind us.
So what happens when I notice something like this, I just drop it from my queue, the policy being "this was clearly not ready to be sent to Linus".
That doesn't mean that it's blacklisted, but it does mean that I don't want to see it returned immediately with the superficial thing fixed that I noticed.
That's partly because I feel that people need to take another look and see if there was perhaps something else going on (if I found one small thing, maybe there are others lurking).
But admittedly it's probably mostly because I really don't want to feel like I'm the wall that people throw spaghetti at to see if it sticks. By the time it came to me, it was supposed to be ready (unless I'm actively part of the development of said feature of course - which still happens occasionally, but on the whole is a vanishingly small part of the stuff I merge).
Quoted 4 lines
So I do expect to see it again later in some patch submission, just not right now.
Linus
Makes perfect sense. I was wondering if it was blacklisted or in purgatory or what, but now I get it. Thanks for explaining that part of the flow.
I'll see if I can pick up some more reviews, during this next cycle.
thanks,
Signature · 2 lines
John Hubbard NVIDIA
Andrew Morton
maintainerPATCH 17/40 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 tools/testing/selftests/vm/run_vmtests | 326 -------------------- tools/testing/selftests/vm/run_vmtests.sh | 326 ++++++++++++++++++++ 3 files changed, 327 insertions(+), 327 deletions(-)
tools/testing/selftests/vm/Makefile renamed from tools/testing/selftests/vm/Makefile~selftests-vm-rename-run_vmtests-run_vmtestssh +1 -1
@@ -69,7 +69,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
tools/testing/selftests/vm/run_vmtests deleted +0 -326
326 lines not on this page · raw message
tools/testing/selftests/vm/run_vmtests.sh new file +326 -0
326 lines not on this page · raw message
_
Andrew Morton
maintainerPATCH 18/40 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)
@@ -76,7 +76,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))
@@ -127,8 +127,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 19/40 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.
---
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 20/40 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 | 54 +++++++++++++++++++++++- mm/gup_test.h | 10 ++++ tools/testing/selftests/vm/gup_test.c | 47 +++++++++++++++++++- 4 files changed, 112 insertions(+), 5 deletions(-)
mm/gup_test.c renamed from mm/gup_test.c~selftests-vm-gup_test-introduce-the-dump_pages-sub-test +52 -2
@@ -7,7 +7,7 @@#include "../../../../mm/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;
@@ -133,10 +181,11 @@ static int __gup_test_ioctl(unsigned int* state: print a warning if any non-dma-pinned pages are found: */ verify_dma_pinned (cmd, pages, nr_pages); +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 +210,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
@@ -842,6 +842,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 +44 -3
77 lines not on this page · raw message
_
Andrew Morton
maintainerPATCH 21/40 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.sh | 24 +++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-)
tools/testing/selftests/vm/run_vmtests.sh renamed from tools/testing/selftests/vm/run_vmtests.sh~selftests-vm-run_vmtestsh-update-and-clean-up-gup_test-invocation +18 -6
@@ -124,9 +124,9 @@ else fi echo "--------------------------------------------" -echo "running 'gup_test -U' (normal/slow gup)" +echo "running 'gup_test -u' (fast gup benchmark)" echo "--------------------------------------------" -./gup_test -U +./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 "running gup_test -ct -F 0x1 0 19 0x1000" +echo " Dumps pages 0, 19, and 4096, using pin_user_pages (-F 0x1)" +echo "--------------------------------------------------------------" +./gup_test -ct -F 0x1 0 19 0x1000 if [ $? -ne 0 ]; then echo "[FAIL]" exitcode=1
_
Andrew Morton
maintainerPATCH 22/40 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/')
@@ -76,8 +79,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))
@@ -130,3 +131,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 23/40 selftests/vm: 10x speedup for hmm-tests
In reply to Andrew MortonFrom: John Hubbard <[email protected]>
Subject: selftests/vm: 10x speedup for hmm-tests
This patch reduces the running time for hmm-tests from about 10+ seconds, to just under 1.0 second, for an approximately 10x speedup. That brings it in line with most of the other tests in selftests/vm, which mostly run in < 1 sec.
This is done with a one-line change that simply reduces the number of iterations of several tests, from 256, to 10. Thanks to Ralph Campbell for suggesting changing NTIMES as a way to get the speedup.
---
tools/testing/selftests/vm/hmm-tests.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/vm/hmm-tests.c renamed from tools/testing/selftests/vm/hmm-tests.c~selftests-vm-10x-speedup-for-hmm-tests +1 -1
@@ -49,7 +49,7 @@ struct hmm_buffer {#define TWOMEG (1 << 21)#define HMM_BUFFER_SIZE (1024 << 12)#define HMM_PATH_MAX 64 -#define NTIMES 256 +#define NTIMES 10#define ALIGN (x, a) (((x) + (a - 1)) & (~((a) - 1)))
_
Andrew Morton
maintainerPATCH 24/40 mm/madvise: pass mm to do_madvise
In reply to Andrew MortonFrom: Minchan Kim <[email protected]>
Subject: mm/madvise: pass mm to do_madvise
Patch series "introduce memory hinting API for external process", v9.
Now, we have MADV_PAGEOUT and MADV_COLD as madvise hinting API. With that, application could give hints to kernel what memory range are preferred to be reclaimed. However, in some platform(e.g., Android), the information required to make the hinting decision is not known to the app. Instead, it is known to a centralized userspace daemon(e.g., ActivityManagerService), and that daemon must be able to initiate reclaim on its own without any app involvement.
To solve the concern, this patch introduces new syscall - process_madvise(2). Bascially, it's same with madvise(2) syscall but it has some differences.
1. It needs pidfd of target process to provide the hint
2. It supports only MADV_{COLD|PAGEOUT|MERGEABLE|UNMEREABLE} at this moment. Other hints in madvise will be opened when there are explicit requests from community to prevent unexpected bugs we couldn't support.
3. Only privileged processes can do something for other process's address space.
For more detail of the new API, please see "mm: introduce external memory hinting API" description in this patchset.
This patch (of 3):
In upcoming patches, do_madvise will be called from external process context so we shouldn't asssume "current" is always hinted process's task_struct.
Furthermore, we must not access mm_struct via task->mm, but obtain it via access_mm() once (in the following patch) and only use that pointer [1], so pass it to do_madvise() as well. Note the vma->vm_mm pointers are safe, so we can use them further down the call stack.
And let's pass current->mm as arguments of do_madvise so it shouldn't change existing behavior but prepare next patch to make review easy.
---
fs/io_uring.c | 2 +- include/linux/mm.h | 2 +- mm/madvise.c | 32 ++++++++++++++++++-------------- 3 files changed, 20 insertions(+), 16 deletions(-)
fs/io_uring.c renamed from fs/io_uring.c~mm-madvise-pass-mm-to-do_madvise +1 -1
@@ -3989,7 +3989,7 @@ static int io_madvise(struct io_kiocb *rif (force_nonblock)return -EAGAIN ; - ret =do_madvise (ma->addr, ma->len, ma->advice); + ret =do_madvise (current->mm, ma->addr, ma->len, ma->advice);if (ret <0 )req_set_fail_links (req);io_req_complete (req, ret);
include/linux/mm.h renamed from include/linux/mm.h~mm-madvise-pass-mm-to-do_madvise +1 -1
@@ -2579,7 +2579,7 @@ extern int __do_munmap(struct mm_struct struct list_head *uf, bool downgrade);extern int do_munmap (struct mm_struct *,unsigned long ,size_t ,struct list_head *uf); -extern int do_madvise (unsigned long start,size_t len_in,int behavior); +extern int do_madvise (struct mm_struct *mm,unsigned long start,size_t len_in,int behavior);#ifdef CONFIG_MMU extern int __mm_populate(unsigned long addr, unsigned long len,
mm/madvise.c renamed from mm/madvise.c~mm-madvise-pass-mm-to-do_madvise +18 -14
@@ -258,6 +258,7 @@ static long madvise_willneed(struct vm_astruct vm_area_struct **prev, unsigned long start, unsigned long end) { + struct mm_struct *mm = vma->vm_mm;struct file *file = vma->vm_file;loff_t offset;
@@ -294,10 +295,10 @@ static long madvise_willneed(struct vm_aget_file (file); offset = (loff_t)(start - vma->vm_start) + ((loff_t )vma->vm_pgoff <<PAGE_SHIFT ); -mmap_read_unlock (current->mm); +mmap_read_unlock (mm);vfs_fadvise (file, offset, end - start,POSIX_FADV_WILLNEED );fput (file); -mmap_read_lock (current->mm); +mmap_read_lock (mm);return 0 ; }
@@ -766,6 +767,8 @@ static long madvise_dontneed_free(struct unsigned long start, unsigned long end, int behavior) { + struct mm_struct *mm = vma->vm_mm; + *prev = vma;if (!can_madv_lru_vma (vma))return -EINVAL ;
@@ -773,8 +776,8 @@ static long madvise_dontneed_free(structif (!userfaultfd_remove (vma, start, end)) { *prev =NULL ;/* mmap_lock has been dropped, prev is stale */ -mmap_read_lock (current->mm); - vma =find_vma (current->mm, start); +mmap_read_lock (mm); + vma =find_vma (mm, start);if (!vma)return -ENOMEM ;if (start < vma->vm_start) {
@@ -828,6 +831,7 @@ static long madvise_remove(struct vm_areloff_t offset;int error;struct file *f; +struct mm_struct *mm = vma->vm_mm; *prev =NULL ;/* tell sys_madvise we drop mmap_lock */
@@ -855,13 +859,13 @@ static long madvise_remove(struct vm_areget_file (f);if (userfaultfd_remove (vma, start, end)) {/* mmap_lock was not released by userfaultfd_remove() */ -mmap_read_unlock (current->mm); +mmap_read_unlock (mm); } error =vfs_fallocate (f,FALLOC_FL_PUNCH_HOLE |FALLOC_FL_KEEP_SIZE , offset, end - start);fput (f); -mmap_read_lock (current->mm); +mmap_read_lock (mm);return error; }
@@ -1045,7 +1049,7 @@ madvise_behavior_valid(int behavior)* -EBADF - map exists, but area maps something that isn't a file. * -EAGAIN - a kernel resource was temporarily unavailable. */ -int do_madvise (unsigned long start,size_t len_in,int behavior) +int do_madvise (struct mm_struct *mm,unsigned long start,size_t len_in,int behavior) {unsigned long end, tmp;struct vm_area_struct *vma, *prev;
@@ -1083,10 +1087,10 @@ int do_madvise(unsigned long start, size write =madvise_need_mmap_write (behavior);if (write) { -if (mmap_write_lock_killable (current->mm)) +if (mmap_write_lock_killable (mm))return -EINTR ; }else { -mmap_read_lock (current->mm); +mmap_read_lock (mm); }/*
@@ -1094,7 +1098,7 @@ int do_madvise(unsigned long start, size* ranges, just ignore them, but return -ENOMEM at the end. * - different from the way of handling in mlock etc. */ - vma =find_vma_prev (current->mm, start, &prev); + vma =find_vma_prev (mm, start, &prev);if (vma && start > vma->vm_start) prev = vma;
@@ -1131,19 +1135,19 @@ int do_madvise(unsigned long start, sizeif (prev) vma = prev->vm_next;else /* madvise_remove dropped mmap_lock */ - vma =find_vma (current->mm, start); + vma =find_vma (mm, start); } out:blk_finish_plug (&plug);if (write) -mmap_write_unlock (current->mm); +mmap_write_unlock (mm);else -mmap_read_unlock (current->mm); +mmap_read_unlock (mm);return error; } SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior) { -return do_madvise (start, len_in, behavior); +return do_madvise (current->mm, start, len_in, behavior); }
_
Andrew Morton
maintainerPATCH 25/40 pid: move pidfd_get_pid() to pid.c
In reply to Andrew MortonFrom: Minchan Kim <[email protected]>
Subject: pid: move pidfd_get_pid() to pid.c
process_madvise syscall needs pidfd_get_pid function to translate pidfd to pid so this patch move the function to kernel/pid.c.
---
include/linux/pid.h | 1 + kernel/exit.c | 19 ------------------- kernel/pid.c | 19 +++++++++++++++++++ 3 files changed, 20 insertions(+), 19 deletions(-)
include/linux/pid.h renamed from include/linux/pid.h~pid-move-pidfd_get_pid-to-pidc +1 -0
@@ -77,6 +77,7 @@ extern const struct file_operations pidfstruct file ;extern struct pid *pidfd_pid (const struct file *file); +struct pid *pidfd_get_pid (unsigned int fd,unsigned int *flags);static inline struct pid *get_pid (struct pid *pid) {
kernel/exit.c renamed from kernel/exit.c~pid-move-pidfd_get_pid-to-pidc +0 -19
@@ -1474,25 +1474,6 @@ end:return retval; } -static struct pid *pidfd_get_pid (unsigned int fd,unsigned int *flags) -{ -struct fd f; -struct pid *pid; - - f =fdget (fd); -if (!f.file) -return ERR_PTR (-EBADF ); - - pid =pidfd_pid (f.file); -if (!IS_ERR (pid)) { -get_pid (pid); - *flags = f.file->f_flags; - } - -fdput (f); -return pid; -} -static long kernel_waitid (int which,pid_t upid,struct waitid_info *infop,int options,struct rusage *ru) {
kernel/pid.c renamed from kernel/pid.c~pid-move-pidfd_get_pid-to-pidc +19 -0
@@ -520,6 +520,25 @@ struct pid *find_ge_pid(int nr, struct preturn idr_get_next (&ns->idr, &nr); } +struct pid *pidfd_get_pid (unsigned int fd,unsigned int *flags) +{ +struct fd f; +struct pid *pid; + + f =fdget (fd); +if (!f.file) +return ERR_PTR (-EBADF ); + + pid =pidfd_pid (f.file); +if (!IS_ERR (pid)) { +get_pid (pid); + *flags = f.file->f_flags; + } + +fdput (f); +return pid; +} +/** * pidfd_create() - Create a new pid file descriptor. *
_
Andrew Morton
maintainerPATCH 26/40 mm/madvise: introduce process_madvise() syscall: an external memory hinting API
In reply to Andrew MortonFrom: Minchan Kim <[email protected]>
Subject: mm/madvise: introduce process_madvise() syscall: an external memory hinting API
There is usecase that System Management Software(SMS) want to give a memory hint like MADV_[COLD|PAGEEOUT] to other processes and in the case of Android, it is the ActivityManagerService.
The information required to make the reclaim decision is not known to the app. Instead, it is known to the centralized userspace daemon(ActivityManagerService), and that daemon must be able to initiate reclaim on its own without any app involvement.
To solve the issue, this patch introduces a new syscall process_madvise(2). It uses pidfd of an external process to give the hint. It also supports vector address range because Android app has thousands of vmas due to zygote so it's totally waste of CPU and power if we should call the syscall one by one for each vma.(With testing 2000-vma syscall vs 1-vector syscall, it showed 15% performance improvement. I think it would be bigger in real practice because the testing ran very cache friendly environment).
Another potential use case for the vector range is to amortize the cost ofTLB shootdowns for multiple ranges when using MADV_DONTNEED; this could benefit users like TCP receive zerocopy and malloc implementations. In future, we could find more usecases for other advises so let's make it happens as API since we introduce a new syscall at this moment. With that, existing madvise(2) user could replace it with process_madvise(2) with their own pid if they want to have batch address ranges support feature.
ince it could affect other process's address range, only privileged process(PTRACE_MODE_ATTACH_FSCREDS) or something else(e.g., being the same UID) gives it the right to ptrace the process could use it successfully. The flag argument is reserved for future use if we need to extend the API.
I think supporting all hints madvise has/will supported/support to process_madvise is rather risky. Because we are not sure all hints make sense from external process and implementation for the hint may rely on the caller being in the current context so it could be error-prone. Thus, I just limited hints as MADV_[COLD|PAGEOUT] in this patch.
If someone want to add other hints, we could hear the usecase and review it for each hint. It's safer for maintenance rather than introducing a buggy syscall but hard to fix it later.
So finally, the API is as follows,
ssize_t process_madvise(int pidfd, const struct iovec *iovec,
unsigned long vlen, int advice, unsigned int flags);
DESCRIPTION
The process_madvise() system call is used to give advice or directions to the kernel about the address ranges from external process as well as local process. It provides the advice to address ranges of process described by iovec and vlen. The goal of such advice is to improve system or application performance.
The pidfd selects the process referred to by the PID file descriptor specified in pidfd. (See pidofd_open(2) for further information)
The pointer iovec points to an array of iovec structures, defined in <sys/uio.h> as:
struct iovec {
void *iov_base; /* starting address */
size_t iov_len; /* number of bytes to be advised */
};
The iovec describes address ranges beginning at address(iov_base) and with size length of bytes(iov_len).
The vlen represents the number of elements in iovec.
The advice is indicated in the advice argument, which is one of the following at this moment if the target process specified by pidfd is external.
MADV_COLD
MADV_PAGEOUT
Permission to provide a hint to external process is governed by a ptrace access mode PTRACE_MODE_ATTACH_FSCREDS check; see ptrace(2).
The process_madvise supports every advice madvise(2) has if target process is in same thread group with calling process so user could use process_madvise(2) to extend existing madvise(2) to support vector address ranges.
RETURN VALUE
On success, process_madvise() returns the number of bytes advised. This return value may be less than the total number of requested bytes, if an error occurred. The caller should check return value to determine whether a partial advice occurred.
FAQ:
Q.1 - Why does any external entity have better knowledge?
Quote from Sandeep
"For Android, every application (including the special SystemServer) are forked from Zygote. The reason of course is to share as many libraries and classes between the two as possible to benefit from the preloading during boot.
After applications start, (almost) all of the APIs end up calling into this SystemServer process over IPC (binder) and back to the application.
In a fully running system, the SystemServer monitors every single process periodically to calculate their PSS / RSS and also decides which process is "important" to the user for interactivity.
So, because of how these processes start _and_ the fact that the SystemServer is looping to monitor each process, it does tend to *know* which address range of the application is not used / useful.
Besides, we can never rely on applications to clean things up themselves. We've had the "hey app1, the system is low on memory, please trim your memory usage down" notifications for a long time[1]. They rely on applications honoring the broadcasts and very few do.
So, if we want to avoid the inevitable killing of the application and restarting it, some way to be able to tell the OS about unimportant memory in these applications will be useful.
- ssp
Q.2 - How to guarantee the race(i.e., object validation) between when giving a hint from an external process and get the hint from the target process?
process_madvise operates on the target process's address space as it exists at the instant that process_madvise is called. If the space target process can run between the time the process_madvise process inspects the target process address space and the time that process_madvise is actually called, process_madvise may operate on memory regions that the calling process does not expect. It's the responsibility of the process calling process_madvise to close this race condition. For example, the calling process can suspend the target process with ptrace, SIGSTOP, or the freezer cgroup so that it doesn't have an opportunity to change its own address space before process_madvise is called. Another option is to operate on memory regions that the caller knows a priori will be unchanged in the target process. Yet another option is to accept the race for certain process_madvise calls after reasoning that mistargeting will do no harm. The suggested API itself does not provide synchronization. It also apply other APIs like move_pages, process_vm_write.
The race isn't really a problem though. Why is it so wrong to require that callers do their own synchronization in some manner? Nobody objects to write(2) merely because it's possible for two processes to open the same file and clobber each other's writes --- instead, we tell people to use flock or something. Think about mmap. It never guarantees newly allocated address space is still valid when the user tries to access it because other threads could unmap the memory right before. That's where we need synchronization by using other API or design from userside. It shouldn't be part of API itself. If someone needs more fine-grained synchronization rather than process level, there were two ideas suggested - cookie[2] and anon-fd[3]. Both are applicable via using last reserved argument of the API but I don't think it's necessary right now since we have already ways to prevent the race so don't want to add additional complexity with more fine-grained optimization model.
To make the API extend, it reserved an unsigned long as last argument so we could support it in future if someone really needs it.
Q.3 - Why doesn't ptrace work?
Injecting an madvise in the target process using ptrace would not work for us because such injected madvise would have to be executed by the target process, which means that process would have to be runnable and that creates the risk of the abovementioned race and hinting a wrong VMA. Furthermore, we want to act the hint in caller's context, not the callee's, because the callee is usually limited in cpuset/cgroups or even freezed state so they can't act by themselves quick enough, which causes more thrashing/kill. It doesn't work if the target process are ptraced(e.g., strace, debugger, minidump) because a process can have at most one ptracer.
[1] https://developer.android.com/topic/performance/memory"
[2] process_getinfo for getting the cookie which is updated whenever vma of process address layout are changed - Daniel Colascione -
https://lore.kernel.org/lkml/[email protected]/T/#m7694416fd179b2066a2c62b5b139b14e3894e224
[3] anonymous fd which is used for the object(i.e., address range) validation - Michal Hocko -
https://lore.kernel.org/lkml/[email protected]/
---
arch/alpha/kernel/syscalls/syscall.tbl | 1 arch/arm/tools/syscall.tbl | 1 arch/arm64/include/asm/unistd.h | 2 arch/arm64/include/asm/unistd32.h | 2 arch/ia64/kernel/syscalls/syscall.tbl | 1 arch/m68k/kernel/syscalls/syscall.tbl | 1 arch/microblaze/kernel/syscalls/syscall.tbl | 1 arch/mips/kernel/syscalls/syscall_n32.tbl | 1 arch/mips/kernel/syscalls/syscall_n64.tbl | 1 arch/mips/kernel/syscalls/syscall_o32.tbl | 1 arch/parisc/kernel/syscalls/syscall.tbl | 1 arch/powerpc/kernel/syscalls/syscall.tbl | 1 arch/s390/kernel/syscalls/syscall.tbl | 1 arch/sh/kernel/syscalls/syscall.tbl | 1 arch/sparc/kernel/syscalls/syscall.tbl | 1 arch/x86/entry/syscalls/syscall_32.tbl | 1 arch/x86/entry/syscalls/syscall_64.tbl | 1 arch/xtensa/kernel/syscalls/syscall.tbl | 1 include/linux/syscalls.h | 2 include/uapi/asm-generic/unistd.h | 4 kernel/sys_ni.c | 1 mm/madvise.c | 93 +++++++++++++++++- 22 files changed, 117 insertions(+), 3 deletions(-)
arch/alpha/kernel/syscalls/syscall.tbl renamed from arch/alpha/kernel/syscalls/syscall.tbl~mm-madvise-introduce-process_madvise-syscall-an-external-memory-hinting-api +1 -0
@@ -479,3 +479,4 @@ 547 common openat2 sys_openat2 548 common pidfd_getfd sys_pidfd_getfd 549 common faccessat2 sys_faccessat2 +550 common process_madvise sys_process_madvise
arch/arm64/include/asm/unistd32.h renamed from arch/arm64/include/asm/unistd32.h~mm-madvise-introduce-process_madvise-syscall-an-external-memory-hinting-api +2 -0
@@ -887,6 +887,8 @@ __SYSCALL(__NR_openat2, sys_openat2) __SYSCALL(__NR_pidfd_getfd, sys_pidfd_getfd)#define __NR_faccessat2 439 __SYSCALL(__NR_faccessat2, sys_faccessat2) +#define __NR_process_madvise 440 +__SYSCALL (__NR_process_madvise, sys_process_madvise)/* * Please add new compat syscalls above this comment and update
arch/arm64/include/asm/unistd.h renamed from arch/arm64/include/asm/unistd.h~mm-madvise-introduce-process_madvise-syscall-an-external-memory-hinting-api +1 -1
@@ -38,7 +38,7 @@#define __ARM_NR_compat_set_tls (__ARM_NR_COMPAT_BASE + 5)#define __ARM_NR_COMPAT_END (__ARM_NR_COMPAT_BASE + 0x800) -#define __NR_compat_syscalls 440 +#define __NR_compat_syscalls 441#endif #define __ARCH_WANT_SYS_CLONE
arch/arm/tools/syscall.tbl renamed from arch/arm/tools/syscall.tbl~mm-madvise-introduce-process_madvise-syscall-an-external-memory-hinting-api +1 -0
@@ -453,3 +453,4 @@ 437 common openat2 sys_openat2 438 common pidfd_getfd sys_pidfd_getfd 439 common faccessat2 sys_faccessat2 +440 common process_madvise sys_process_madvise
arch/ia64/kernel/syscalls/syscall.tbl renamed from arch/ia64/kernel/syscalls/syscall.tbl~mm-madvise-introduce-process_madvise-syscall-an-external-memory-hinting-api +1 -0
@@ -360,3 +360,4 @@ 437 common openat2 sys_openat2 438 common pidfd_getfd sys_pidfd_getfd 439 common faccessat2 sys_faccessat2 +440 common process_madvise sys_process_madvise
arch/m68k/kernel/syscalls/syscall.tbl renamed from arch/m68k/kernel/syscalls/syscall.tbl~mm-madvise-introduce-process_madvise-syscall-an-external-memory-hinting-api +1 -0
@@ -439,3 +439,4 @@ 437 common openat2 sys_openat2 438 common pidfd_getfd sys_pidfd_getfd 439 common faccessat2 sys_faccessat2 +440 common process_madvise sys_process_madvise
arch/microblaze/kernel/syscalls/syscall.tbl renamed from arch/microblaze/kernel/syscalls/syscall.tbl~mm-madvise-introduce-process_madvise-syscall-an-external-memory-hinting-api +1 -0
@@ -445,3 +445,4 @@ 437 common openat2 sys_openat2 438 common pidfd_getfd sys_pidfd_getfd 439 common faccessat2 sys_faccessat2 +440 common process_madvise sys_process_madvise
arch/mips/kernel/syscalls/syscall_n32.tbl renamed from arch/mips/kernel/syscalls/syscall_n32.tbl~mm-madvise-introduce-process_madvise-syscall-an-external-memory-hinting-api +1 -0
@@ -378,3 +378,4 @@ 437 n32 openat2 sys_openat2 438 n32 pidfd_getfd sys_pidfd_getfd 439 n32 faccessat2 sys_faccessat2 +440 n32 process_madvise sys_process_madvise
arch/mips/kernel/syscalls/syscall_n64.tbl renamed from arch/mips/kernel/syscalls/syscall_n64.tbl~mm-madvise-introduce-process_madvise-syscall-an-external-memory-hinting-api +1 -0
@@ -354,3 +354,4 @@ 437 n64 openat2 sys_openat2 438 n64 pidfd_getfd sys_pidfd_getfd 439 n64 faccessat2 sys_faccessat2 +440 n64 process_madvise sys_process_madvise
arch/mips/kernel/syscalls/syscall_o32.tbl renamed from arch/mips/kernel/syscalls/syscall_o32.tbl~mm-madvise-introduce-process_madvise-syscall-an-external-memory-hinting-api +1 -0
@@ -427,3 +427,4 @@ 437 o32 openat2 sys_openat2 438 o32 pidfd_getfd sys_pidfd_getfd 439 o32 faccessat2 sys_faccessat2 +440 o32 process_madvise sys_process_madvise
arch/parisc/kernel/syscalls/syscall.tbl renamed from arch/parisc/kernel/syscalls/syscall.tbl~mm-madvise-introduce-process_madvise-syscall-an-external-memory-hinting-api +1 -0
@@ -437,3 +437,4 @@ 437 common openat2 sys_openat2 438 common pidfd_getfd sys_pidfd_getfd 439 common faccessat2 sys_faccessat2 +440 common process_madvise sys_process_madvise
arch/powerpc/kernel/syscalls/syscall.tbl renamed from arch/powerpc/kernel/syscalls/syscall.tbl~mm-madvise-introduce-process_madvise-syscall-an-external-memory-hinting-api +1 -0
@@ -529,3 +529,4 @@ 437 common openat2 sys_openat2 438 common pidfd_getfd sys_pidfd_getfd 439 common faccessat2 sys_faccessat2 +440 common process_madvise sys_process_madvise
arch/s390/kernel/syscalls/syscall.tbl renamed from arch/s390/kernel/syscalls/syscall.tbl~mm-madvise-introduce-process_madvise-syscall-an-external-memory-hinting-api +1 -0
@@ -442,3 +442,4 @@ 437 common openat2 sys_openat2 sys_openat2 438 common pidfd_getfd sys_pidfd_getfd sys_pidfd_getfd 439 common faccessat2 sys_faccessat2 sys_faccessat2 +440 common process_madvise sys_process_madvise sys_process_madvise
arch/sh/kernel/syscalls/syscall.tbl renamed from arch/sh/kernel/syscalls/syscall.tbl~mm-madvise-introduce-process_madvise-syscall-an-external-memory-hinting-api +1 -0
@@ -442,3 +442,4 @@ 437 common openat2 sys_openat2 438 common pidfd_getfd sys_pidfd_getfd 439 common faccessat2 sys_faccessat2 +440 common process_madvise sys_process_madvise
arch/sparc/kernel/syscalls/syscall.tbl renamed from arch/sparc/kernel/syscalls/syscall.tbl~mm-madvise-introduce-process_madvise-syscall-an-external-memory-hinting-api +1 -0
@@ -485,3 +485,4 @@ 437 common openat2 sys_openat2 438 common pidfd_getfd sys_pidfd_getfd 439 common faccessat2 sys_faccessat2 +440 common process_madvise sys_process_madvise
arch/x86/entry/syscalls/syscall_32.tbl renamed from arch/x86/entry/syscalls/syscall_32.tbl~mm-madvise-introduce-process_madvise-syscall-an-external-memory-hinting-api +1 -0
@@ -444,3 +444,4 @@ 437 i386 openat2 sys_openat2 438 i386 pidfd_getfd sys_pidfd_getfd 439 i386 faccessat2 sys_faccessat2 +440 i386 process_madvise sys_process_madvise
arch/x86/entry/syscalls/syscall_64.tbl renamed from arch/x86/entry/syscalls/syscall_64.tbl~mm-madvise-introduce-process_madvise-syscall-an-external-memory-hinting-api +1 -0
@@ -361,6 +361,7 @@ 437 common openat2 sys_openat2 438 common pidfd_getfd sys_pidfd_getfd 439 common faccessat2 sys_faccessat2 +440 common process_madvise sys_process_madvise # # x32-specific system call numbers start at 512 to avoid cache impact
arch/xtensa/kernel/syscalls/syscall.tbl renamed from arch/xtensa/kernel/syscalls/syscall.tbl~mm-madvise-introduce-process_madvise-syscall-an-external-memory-hinting-api +1 -0
@@ -410,3 +410,4 @@ 437 common openat2 sys_openat2 438 common pidfd_getfd sys_pidfd_getfd 439 common faccessat2 sys_faccessat2 +440 common process_madvise sys_process_madvise
include/linux/syscalls.h renamed from include/linux/syscalls.h~mm-madvise-introduce-process_madvise-syscall-an-external-memory-hinting-api +2 -0
@@ -879,6 +879,8 @@ asmlinkage long sys_munlockall(void);asmlinkage long sys_mincore (unsigned long start,size_t len,unsigned char __user * vec);asmlinkage long sys_madvise (unsigned long start,size_t len,int behavior); +asmlinkage long sys_process_madvise (int pidfd,const struct iovec __user *vec, +size_t vlen,int behavior,unsigned int flags);asmlinkage long sys_remap_file_pages (unsigned long start,unsigned long size,unsigned long prot,unsigned long pgoff,unsigned long flags);
include/uapi/asm-generic/unistd.h renamed from include/uapi/asm-generic/unistd.h~mm-madvise-introduce-process_madvise-syscall-an-external-memory-hinting-api +3 -1
@@ -857,9 +857,11 @@ __SYSCALL(__NR_openat2, sys_openat2) __SYSCALL(__NR_pidfd_getfd, sys_pidfd_getfd)#define __NR_faccessat2 439 __SYSCALL(__NR_faccessat2, sys_faccessat2) +#define __NR_process_madvise 440 +__SYSCALL(__NR_process_madvise, sys_process_madvise)#undef __NR_syscalls -#define __NR_syscalls 440 +#define __NR_syscalls 441/* * 32 bit systems traditionally used different
kernel/sys_ni.c renamed from kernel/sys_ni.c~mm-madvise-introduce-process_madvise-syscall-an-external-memory-hinting-api +1 -0
@@ -280,6 +280,7 @@ COND_SYSCALL(mlockall);COND_SYSCALL (munlockall);COND_SYSCALL (mincore);COND_SYSCALL (madvise); +COND_SYSCALL (process_madvise);COND_SYSCALL (remap_file_pages);COND_SYSCALL (mbind);COND_SYSCALL_COMPAT (mbind);
mm/madvise.c renamed from mm/madvise.c~mm-madvise-introduce-process_madvise-syscall-an-external-memory-hinting-api +92 -1
120 lines not on this page · raw message
_
Andrew Morton
maintainerPATCH 27/40 mm: update the documentation for vfree
In reply to Andrew MortonFrom: "Matthew Wilcox (Oracle)" <[email protected]>
Subject: mm: update the documentation for vfree
Patch series "remove alloc_vm_area", v4.
This series removes alloc_vm_area, which was left over from the big vmalloc interface rework. It is a rather arkane interface, basicaly the equivalent of get_vm_area + actually faulting in all PTEs in the allocated area. It was originally addeds for Xen (which isn't modular to start with), and then grew users in zsmalloc and i915 which seems to mostly qualify as abuses of the interface, especially for i915 as a random driver should not set up PTE bits directly.
This patch (of 11):
* Document that you can call vfree() on an address returned from vmap()
* Remove the note about the minimum size -- the minimum size of a vmalloc allocation is one page
* Add a Context: section
* Fix capitalisation
* Reword the prohibition on calling from NMI context to avoid a double negative
---
mm/vmalloc.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)
mm/vmalloc.c renamed from mm/vmalloc.c~mm-update-the-documentation-for-vfree +11 -10
@@ -2321,20 +2321,21 @@ static void __vfree(const void *addr) }/** -* vfree - release memory allocated by vmalloc() -* @addr: memory base address +* vfree - Release memory allocated by vmalloc() +* @addr: Memory base address * -* Free the virtually continuous memory area starting at @addr, as -* obtained from vmalloc(), vmalloc_32() or __vmalloc(). If @addr is -* NULL, no operation is performed. +* Free the virtually continuous memory area starting at @addr, as obtained +* from one of the vmalloc() family of APIs. This will usually also free the +* physical memory underlying the virtual allocation, but that memory is +* reference counted, so it will not be freed until the last user goes away. * -* Must not be called in NMI context (strictly speaking, only if we don't -* have CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG, but making the calling -* conventions for vfree() arch-depenedent would be a really bad idea) +* If @addr is NULL, no operation is performed. * +* Context: * May sleep if called *not* from interrupt context. -* -* NOTE: assumes that the object at @addr has a size >= sizeof(llist_node) +* Must not be called in NMI context (strictly speaking, it could be +* if we have CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG, but making the calling +* conventions for vfree() arch-depenedent would be a really bad idea). */ void vfree (const void *addr) {
_
Andrew Morton
maintainerPATCH 28/40 mm: add a VM_MAP_PUT_PAGES flag for vmap
In reply to Andrew MortonFrom: Christoph Hellwig <[email protected]>
Subject: mm: add a VM_MAP_PUT_PAGES flag for vmap
Add a flag so that vmap takes ownership of the passed in page array. When vfree is called on such an allocation it will put one reference on each page, and free the page array itself.
---
include/linux/vmalloc.h | 1 + mm/vmalloc.c | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-)
include/linux/vmalloc.h renamed from include/linux/vmalloc.h~mm-add-a-vm_map_put_pages-flag-for-vmap +1 -0
@@ -24,6 +24,7 @@ struct notifier_block; /* in notifier.h#define VM_UNINITIALIZED 0x00000020/* vm_struct is not fully initialized */ #define VM_NO_GUARD 0x00000040/* don't add guard page */ #define VM_KASAN 0x00000080/* has allocated kasan shadow memory */ +#define VM_MAP_PUT_PAGES 0x00000100/* put pages and free array in vfree */ /* * VM_KASAN is used slighly differently depending on CONFIG_KASAN_VMALLOC.
mm/vmalloc.c renamed from mm/vmalloc.c~mm-add-a-vm_map_put_pages-flag-for-vmap +7 -2
@@ -2377,8 +2377,11 @@ EXPORT_SYMBOL(vunmap);* @flags: vm_area->flags * @prot: page protection for the mapping * -* Maps @count pages from @pages into contiguous kernel virtual -* space. +* Maps @count pages from @pages into contiguous kernel virtual space. +* If @flags contains %VM_MAP_PUT_PAGES the ownership of the pages array itself +* (which must be kmalloc or vmalloc memory) and one reference per pages in it +* are transferred from the caller to vmap(), and will be freed / dropped when +* vfree() is called on the return value. * * Return: the address of the area or %NULL on failure */
@@ -2404,6 +2407,8 @@ void *vmap(struct page **pages, unsignedreturn NULL ; } +if (flags &VM_MAP_PUT_PAGES ) + area->pages = pages;return area->addr; }EXPORT_SYMBOL (vmap);
_
Andrew Morton
maintainerPATCH 29/40 mm: add a vmap_pfn function
In reply to Andrew MortonFrom: Christoph Hellwig <[email protected]>
Subject: mm: add a vmap_pfn function
Add a proper helper to remap PFNs into kernel virtual space so that drivers don't have to abuse alloc_vm_area and open coded PTE manipulation for it.
---
include/linux/vmalloc.h | 1 mm/Kconfig | 3 ++ mm/vmalloc.c | 45 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+)
include/linux/vmalloc.h renamed from include/linux/vmalloc.h~mm-add-a-vmap_pfn-function +1 -0
@@ -122,6 +122,7 @@ extern void vfree_atomic(const void *addextern void *vmap (struct page **pages,unsigned int count,unsigned long flags,pgprot_t prot); +void *vmap_pfn (unsigned long *pfns,unsigned int count,pgprot_t prot);extern void vunmap (const void *addr); extern int remap_vmalloc_range_partial(struct vm_area_struct *vma,
mm/Kconfig renamed from mm/Kconfig~mm-add-a-vmap_pfn-function +3 -0
@@ -816,6 +816,9 @@ config DEVICE_PRIVATE memory; i.e., memory that is only accessible from the device (or group of devices). You likely also want to select HMM_MIRROR. +config VMAP_PFN + bool + config FRAME_VECTOR bool
mm/vmalloc.c renamed from mm/vmalloc.c~mm-add-a-vmap_pfn-function +45 -0
51 lines not on this page · raw message
_
Andrew Morton
maintainerPATCH 30/40 mm: allow a NULL fn callback in apply_to_page_range
In reply to Andrew MortonFrom: Christoph Hellwig <[email protected]>
Subject: mm: allow a NULL fn callback in apply_to_page_range
Besides calling the callback on each page, apply_to_page_range also has the effect of pre-faulting all PTEs for the range. To support callers that only need the pre-faulting, make the callback optional.
Based on a patch from Minchan Kim <[email protected]>.
---
mm/memory.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
mm/memory.c renamed from mm/memory.c~mm-allow-a-null-fn-callback-in-apply_to_page_range +9 -7
@@ -2391,13 +2391,15 @@ static int apply_to_pte_range(struct mm_arch_enter_lazy_mmu_mode (); -do { -if (create || !pte_none (*pte)) { - err =fn (pte++, addr, data); -if (err) -break ; - } - }while (addr +=PAGE_SIZE , addr != end); +if (fn) { +do { +if (create || !pte_none (*pte)) { + err =fn (pte++, addr, data); +if (err) +break ; + } + }while (addr +=PAGE_SIZE , addr != end); + } *mask |=PGTBL_PTE_MODIFIED ;arch_leave_lazy_mmu_mode ();
_
Andrew Morton
maintainerPATCH 31/40 zsmalloc: switch from alloc_vm_area to get_vm_area
In reply to Andrew MortonFrom: Christoph Hellwig <[email protected]>
Subject: zsmalloc: switch from alloc_vm_area to get_vm_area
Just manually pre-fault the PTEs using apply_to_page_range.
---
mm/zsmalloc.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
mm/zsmalloc.c renamed from mm/zsmalloc.c~zsmalloc-switch-from-alloc_vm_area-to-get_vm_area +8 -2
@@ -1122,10 +1122,16 @@ static inline int __zs_cpu_up(struct map*/ if (area->vm)return 0 ; - area->vm =alloc_vm_area (PAGE_SIZE *2 ,NULL ); + area->vm =get_vm_area (PAGE_SIZE *2 ,0 );if (!area->vm)return -ENOMEM ; -return 0 ; + +/* +* Populate ptes in advance to avoid pte allocation with GFP_KERNEL +* in non-preemtible context of zs_map_object. +*/ +return apply_to_page_range (&init_mm, (unsigned long )area->vm->addr, +PAGE_SIZE *2 ,NULL ,NULL ); }static inline void __zs_cpu_down (struct mapping_area *area)
_
Andrew Morton
maintainerPATCH 32/40 drm/i915: use vmap in shmem_pin_map
In reply to Andrew MortonFrom: Christoph Hellwig <[email protected]>
Subject: drm/i915: use vmap in shmem_pin_map
shmem_pin_map somewhat awkwardly reimplements vmap using alloc_vm_area and manual pte setup. The only practical difference is that alloc_vm_area prefeaults the vmalloc area PTEs, which doesn't seem to be required here (and could be added to vmap using a flag if actually required). Switch to use vmap, and use vfree to free both the vmalloc mapping and the page array, as well as dropping the references to each page.
---
drivers/gpu/drm/i915/gt/shmem_utils.c | 78 +++++------------------- 1 file changed, 19 insertions(+), 59 deletions(-)
drivers/gpu/drm/i915/gt/shmem_utils.c renamed from drivers/gpu/drm/i915/gt/shmem_utils.c~drm-i915-use-vmap-in-shmem_pin_map +19 -59
@@ -49,80 +49,40 @@ struct file *shmem_create_from_object(streturn file; } -static size_t shmem_npte (struct file *file) -{ -return file->f_mapping->host->i_size >>PAGE_SHIFT ; -} - -static void __shmem_unpin_map (struct file *file,void *ptr,size_t n_pte) -{ -unsigned long pfn; - -vunmap (ptr); - -for (pfn =0 ; pfn < n_pte; pfn++) { -struct page *page; - - page =shmem_read_mapping_page_gfp (file->f_mapping, pfn, -GFP_KERNEL ); -if (!WARN_ON (IS_ERR (page))) { -put_page (page); -put_page (page); - } - } -} -void *shmem_pin_map (struct file *file) { -const size_t n_pte =shmem_npte (file); -pte_t *stack[32 ], **ptes, **mem; -struct vm_struct *area; -unsigned long pfn; - - mem = stack; -if (n_pte >ARRAY_SIZE (stack)) { - mem =kvmalloc_array (n_pte,sizeof (*mem),GFP_KERNEL ); -if (!mem) -return NULL ; - } - - area =alloc_vm_area (n_pte <<PAGE_SHIFT , mem); -if (!area) { -if (mem != stack) -kvfree (mem); +struct page **pages; +size_t n_pages, i; +void *vaddr; + + n_pages = file->f_mapping->host->i_size >>PAGE_SHIFT ; + pages =kvmalloc_array (n_pages,sizeof (*pages),GFP_KERNEL ); +if (!pages)return NULL ; - } - ptes = mem; -for (pfn =0 ; pfn < n_pte; pfn++) { -struct page *page; - - page =shmem_read_mapping_page_gfp (file->f_mapping, pfn, -GFP_KERNEL ); -if (IS_ERR (page)) +for (i =0 ; i < n_pages; i++) { + pages[i] =shmem_read_mapping_page_gfp (file->f_mapping, i, +GFP_KERNEL ); +if (IS_ERR (pages[i])) goto err_page; - - **ptes++ =mk_pte (page,PAGE_KERNEL ); } -if (mem != stack) -kvfree (mem); - + vaddr =vmap (pages, n_pages,VM_MAP_PUT_PAGES ,PAGE_KERNEL ); +if (!vaddr) + goto err_page;mapping_set_unevictable (file->f_mapping); -return area->addr; - +return vaddr; err_page: -if (mem != stack) -kvfree (mem); - -__shmem_unpin_map (file, area->addr, pfn); +while (--i >=0 ) +put_page (pages[i]); +kvfree (pages);return NULL ; }void shmem_unpin_map (struct file *file,void *ptr) {mapping_clear_unevictable (file->f_mapping); -__shmem_unpin_map (file, ptr,shmem_npte (file)); +vfree (ptr); } static int __shmem_rw(struct file *file, loff_t off,
_
Andrew Morton
maintainerPATCH 33/40 drm/i915: stop using kmap in i915_gem_object_map
In reply to Andrew MortonFrom: Christoph Hellwig <[email protected]>
Subject: drm/i915: stop using kmap in i915_gem_object_map
kmap for !PageHighmem is just a convoluted way to say page_address, and kunmap is a no-op in that case.
---
drivers/gpu/drm/i915/gem/i915_gem_pages.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_pages.c renamed from drivers/gpu/drm/i915/gem/i915_gem_pages.c~drm-i915-stop-using-kmap-in-i915_gem_object_map +2 -5
@@ -162,8 +162,6 @@ static void unmap_object(struct drm_i915 {if (is_vmalloc_addr (ptr))vunmap (ptr); -else -kunmap (kmap_to_page (ptr)); } struct sg_table *
@@ -277,11 +275,10 @@ static void *i915_gem_object_map(struct* forever. * * So if the page is beyond the 32b boundary, make an explicit -* vmap. On 64b, this check will be optimised away as we can -* directly kmap any page on the system. +* vmap. */ if (!PageHighMem (page)) -return kmap (page); +return page_address (page); } mem = stack;
_
Andrew Morton
maintainerPATCH 34/40 drm/i915: use vmap in i915_gem_object_map
In reply to Andrew MortonFrom: Christoph Hellwig <[email protected]>
Subject: drm/i915: use vmap in i915_gem_object_map
i915_gem_object_map implements fairly low-level vmap functionality in a driver. Split it into two helpers, one for remapping kernel memory which can use vmap, and one for I/O memory that uses vmap_pfn.
The only practical difference is that alloc_vm_area prefeaults the vmalloc area PTEs, which doesn't seem to be required here for the kernel memory case (and could be added to vmap using a flag if actually required).
---
drivers/gpu/drm/i915/Kconfig | 1 drivers/gpu/drm/i915/gem/i915_gem_pages.c | 129 +++++++++----------- 2 files changed, 61 insertions(+), 69 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_pages.c renamed from drivers/gpu/drm/i915/gem/i915_gem_pages.c~drm-i915-use-vmap-in-i915_gem_object_map +60 -69
@@ -232,34 +232,21 @@ unlock:return err; } -static inline pte_t iomap_pte (resource_size_t base, -dma_addr_t offset, -pgprot_t prot) -{ -return pte_mkspecial (pfn_pte ((base + offset) >>PAGE_SHIFT , prot)); -} -/* The 'mapping' part of i915_gem_object_pin_map() below */ -static void *i915_gem_object_map (struct drm_i915_gem_object *obj, -enum i915_map_type type) +static void *i915_gem_object_map_page (struct drm_i915_gem_object *obj, +enum i915_map_type type) { -unsigned long n_pte = obj->base.size >>PAGE_SHIFT ; -struct sg_table *sgt = obj->mm.pages; -pte_t *stack[32 ], **mem; -struct vm_struct *area; +unsigned long n_pages = obj->base.size >>PAGE_SHIFT , i; +struct page *stack[32 ], **pages = stack, *page; +struct sgt_iter iter;pgprot_t pgprot; +void *vaddr; -if (!i915_gem_object_has_struct_page (obj) && type !=I915_MAP_WC ) -return NULL ; - -if (GEM_WARN_ON (type ==I915_MAP_WC && - !static_cpu_has (X86_FEATURE_PAT ))) -return NULL ; - -/* A single page can always be kmapped */ -if (n_pte ==1 && type ==I915_MAP_WB ) { -struct page *page =sg_page (sgt->sgl); - +switch (type) { +default : +MISSING_CASE (type); + fallthrough;/* to use PAGE_KERNEL anyway */ +case I915_MAP_WB :/* * On 32b, highmem using a finite set of indirect PTE (i.e. * vmap) to provide virtual mappings of the high pages.
@@ -277,30 +264,8 @@ static void *i915_gem_object_map(struct* So if the page is beyond the 32b boundary, make an explicit * vmap. */ -if (!PageHighMem (page)) -return page_address (page); - } - - mem = stack; -if (n_pte >ARRAY_SIZE (stack)) { -/* Too big for stack -- allocate temporary array instead */ - mem =kvmalloc_array (n_pte,sizeof (*mem),GFP_KERNEL ); -if (!mem) -return NULL ; - } - - area =alloc_vm_area (obj->base.size, mem); -if (!area) { -if (mem != stack) -kvfree (mem); -return NULL ; - } - -switch (type) { -default : -MISSING_CASE (type); - fallthrough;/* to use PAGE_KERNEL anyway */ -case I915_MAP_WB : +if (n_pages ==1 && !PageHighMem (sg_page (obj->mm.pages->sgl))) +return page_address (sg_page (obj->mm.pages->sgl)); pgprot =PAGE_KERNEL ;break ;case I915_MAP_WC :
@@ -308,30 +273,50 @@ static void *i915_gem_object_map(structbreak ; } -if (i915_gem_object_has_struct_page (obj)) { -struct sgt_iter iter; -struct page *page; -pte_t **ptes = mem; - -for_each_sgt_page (page, iter, sgt) - **ptes++ =mk_pte (page, pgprot); - }else { -resource_size_t iomap; -struct sgt_iter iter; -pte_t **ptes = mem; -dma_addr_t addr; +if (n_pages >ARRAY_SIZE (stack)) { +/* Too big for stack -- allocate temporary array instead */ + pages =kvmalloc_array (n_pages,sizeof (*pages),GFP_KERNEL ); +if (!pages) +return NULL ; + } - iomap = obj->mm.region->iomap.base; - iomap -= obj->mm.region->region.start; + i =0 ; +for_each_sgt_page (page, iter, obj->mm.pages) + pages[i++] = page; + vaddr =vmap (pages, n_pages,0 , pgprot); +if (pages != stack) +kvfree (pages); +return vaddr; +} -for_each_sgt_daddr (addr, iter, sgt) - **ptes++ =iomap_pte (iomap, addr, pgprot); - } +static void *i915_gem_object_map_pfn (struct drm_i915_gem_object *obj, +enum i915_map_type type) +{ +resource_size_t iomap = obj->mm.region->iomap.base - + obj->mm.region->region.start; +unsigned long n_pfn = obj->base.size >>PAGE_SHIFT ; +unsigned long stack[32 ], *pfns = stack, i; +struct sgt_iter iter; +dma_addr_t addr; +void *vaddr; -if (mem != stack) -kvfree (mem); +if (type !=I915_MAP_WC ) +return NULL ; + +if (n_pfn >ARRAY_SIZE (stack)) { +/* Too big for stack -- allocate temporary array instead */ + pfns =kvmalloc_array (n_pfn,sizeof (*pfns),GFP_KERNEL ); +if (!pfns) +return NULL ; + } -return area->addr; + i =0 ; +for_each_sgt_daddr (addr, iter, obj->mm.pages) + pfns[i++] = (iomap + addr) >>PAGE_SHIFT ; + vaddr =vmap_pfn (pfns, n_pfn,pgprot_writecombine (PAGE_KERNEL_IO )); +if (pfns != stack) +kvfree (pfns); +return vaddr; }/* get, pin, and map the pages of the object into kernel space */
@@ -383,7 +368,13 @@ void *i915_gem_object_pin_map(struct drm }if (!ptr) { - ptr =i915_gem_object_map (obj, type); +if (GEM_WARN_ON (type ==I915_MAP_WC && + !static_cpu_has (X86_FEATURE_PAT ))) + ptr =NULL ; +else if (i915_gem_object_has_struct_page (obj)) + ptr =i915_gem_object_map_page (obj, type); +else + ptr =i915_gem_object_map_pfn (obj, type);if (!ptr) { err = -ENOMEM ; goto err_unpin;
drivers/gpu/drm/i915/Kconfig renamed from drivers/gpu/drm/i915/Kconfig~drm-i915-use-vmap-in-i915_gem_object_map +1 -0
@@ -25,6 +25,7 @@ config DRM_I915 select CRC32 select SND_HDA_I915 if SND_HDA_CORE select CEC_CORE if CEC_NOTIFIER + select VMAP_PFN help Choose this option if you have a system that has "Intel Graphics Media Accelerator" or "HD Graphics" integrated graphics,
_
Andrew Morton
maintainerPATCH 35/40 xen/xenbus: use apply_to_page_range directly in xenbus_map_ring_pv
In reply to Andrew MortonFrom: Christoph Hellwig <[email protected]>
Subject: xen/xenbus: use apply_to_page_range directly in xenbus_map_ring_pv
Replacing alloc_vm_area with get_vm_area_caller + apply_page_range allows to fill put the phys_addr values directly instead of doing another loop over all addresses.
---
drivers/xen/xenbus/xenbus_client.c | 30 ++++++++++++++------------- 1 file changed, 16 insertions(+), 14 deletions(-)
drivers/xen/xenbus/xenbus_client.c renamed from drivers/xen/xenbus/xenbus_client.c~xen-xenbus-use-apply_to_page_range-directly-in-xenbus_map_ring_pv +16 -14
@@ -73,16 +73,13 @@ struct map_ring_valloc {struct xenbus_map_node *node;/* Why do we need two arrays? See comment of __xenbus_map_ring */ -union { -unsigned long addrs[XENBUS_MAX_RING_GRANTS ]; -pte_t *ptes[XENBUS_MAX_RING_GRANTS ]; - }; +unsigned long addrs[XENBUS_MAX_RING_GRANTS ];phys_addr_t phys_addrs[XENBUS_MAX_RING_GRANTS ];struct gnttab_map_grant_ref map[XENBUS_MAX_RING_GRANTS ];struct gnttab_unmap_grant_ref unmap[XENBUS_MAX_RING_GRANTS ]; -unsigned int idx;/* HVM only. */ +unsigned int idx; };static DEFINE_SPINLOCK (xenbus_valloc_lock);
@@ -686,6 +683,14 @@ int xenbus_unmap_ring_vfree(struct xenbuEXPORT_SYMBOL_GPL (xenbus_unmap_ring_vfree);#ifdef CONFIG_XEN_PV +static int map_ring_apply (pte_t *pte,unsigned long addr,void *data) +{ +struct map_ring_valloc *info = data; + + info->phys_addrs[info->idx++] =arbitrary_virt_to_machine (pte).maddr; +return 0 ; +} + static int xenbus_map_ring_pv(struct xenbus_device *dev, struct map_ring_valloc *info, grant_ref_t *gnt_refs,
@@ -694,18 +699,15 @@ static int xenbus_map_ring_pv(struct xen {struct xenbus_map_node *node = info->node;struct vm_struct *area; -int err = GNTST_okay; -int i; -bool leaked; +bool leaked = false; +int err = -ENOMEM ; - area =alloc_vm_area (XEN_PAGE_SIZE * nr_grefs, info->ptes); + area =get_vm_area (XEN_PAGE_SIZE * nr_grefs,VM_IOREMAP );if (!area)return -ENOMEM ; - -for (i =0 ; i < nr_grefs; i++) - info->phys_addrs[i] = -arbitrary_virt_to_machine (info->ptes[i]).maddr; - +if (apply_to_page_range (&init_mm, (unsigned long )area->addr, +XEN_PAGE_SIZE * nr_grefs, map_ring_apply, info)) + goto failed; err =__xenbus_map_ring (dev, gnt_refs, nr_grefs, node->handles, info, GNTMAP_host_map | GNTMAP_contains_pte, &leaked);
_
Andrew Morton
maintainerPATCH 36/40 x86/xen: open code alloc_vm_area in arch_gnttab_valloc
In reply to Andrew MortonFrom: Christoph Hellwig <[email protected]>
Subject: x86/xen: open code alloc_vm_area in arch_gnttab_valloc
Replace the last call to alloc_vm_area with an open coded version using an iterator in struct gnttab_vm_area instead of the triple indirection magic in alloc_vm_area.
---
arch/x86/xen/grant-table.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-)
arch/x86/xen/grant-table.c renamed from arch/x86/xen/grant-table.c~x86-xen-open-code-alloc_vm_area-in-arch_gnttab_valloc +20 -7
@@ -25,6 +25,7 @@static struct gnttab_vm_area {struct vm_struct *area;pte_t **ptes; +int idx; } gnttab_shared_vm_area, gnttab_status_vm_area; int arch_gnttab_map_shared(unsigned long *frames, unsigned long nr_gframes,
@@ -90,19 +91,31 @@ void arch_gnttab_unmap(void *shared, uns } } +static int gnttab_apply (pte_t *pte,unsigned long addr,void *data) +{ +struct gnttab_vm_area *area = data; + + area->ptes[area->idx++] = pte; +return 0 ; +} +static int arch_gnttab_valloc (struct gnttab_vm_area *area,unsigned nr_frames) { area->ptes =kmalloc_array (nr_frames,sizeof (*area->ptes),GFP_KERNEL );if (area->ptes ==NULL )return -ENOMEM ; - - area->area =alloc_vm_area (PAGE_SIZE * nr_frames, area->ptes); -if (area->area ==NULL ) { -kfree (area->ptes); -return -ENOMEM ; - } - + area->area =get_vm_area (PAGE_SIZE * nr_frames,VM_IOREMAP ); +if (!area->area) + goto out_free_ptes; +if (apply_to_page_range (&init_mm, (unsigned long )area->area->addr, +PAGE_SIZE * nr_frames, gnttab_apply, area)) + goto out_free_vm_area;return 0 ; +out_free_vm_area: +free_vm_area (area->area); +out_free_ptes: +kfree (area->ptes); +return -ENOMEM ; }static void arch_gnttab_vfree (struct gnttab_vm_area *area)
_
Andrew Morton
maintainerPATCH 37/40 mm: remove alloc_vm_area
In reply to Andrew MortonFrom: Christoph Hellwig <[email protected]>
Subject: mm: remove alloc_vm_area
All users are gone now.
---
include/linux/vmalloc.h | 5 --- mm/nommu.c | 7 ----- mm/vmalloc.c | 48 -------------------------------------- 3 files changed, 1 insertion(+), 59 deletions(-)
include/linux/vmalloc.h renamed from include/linux/vmalloc.h~mm-remove-alloc_vm_area +1 -4
@@ -169,6 +169,7 @@ extern struct vm_struct *__get_vm_area_cunsigned long flags, unsigned long start, unsigned long end, const void *caller); +void free_vm_area (struct vm_struct *area);extern struct vm_struct *remove_vm_area (const void *addr);extern struct vm_struct *find_vm_area (const void *addr);
@@ -204,10 +205,6 @@ static inline void set_vm_flush_reset_pe }#endif -/* Allocate/destroy a 'vmalloc' VM area. */ -extern struct vm_struct *alloc_vm_area (size_t size,pte_t **ptes); -extern void free_vm_area (struct vm_struct *area); -/* for /dev/kmem */ extern long vread (char *buf,char *addr,unsigned long count);extern long vwrite (char *buf,char *addr,unsigned long count);
mm/nommu.c renamed from mm/nommu.c~mm-remove-alloc_vm_area +0 -7
@@ -354,13 +354,6 @@ void vm_unmap_aliases(void) }EXPORT_SYMBOL_GPL (vm_unmap_aliases); -struct vm_struct *alloc_vm_area (size_t size,pte_t **ptes) -{ -BUG (); -return NULL ; -} -EXPORT_SYMBOL_GPL (alloc_vm_area); -void free_vm_area (struct vm_struct *area) {BUG ();
mm/vmalloc.c renamed from mm/vmalloc.c~mm-remove-alloc_vm_area +0 -48
54 lines not on this page · raw message
_
Andrew Morton
maintainerPATCH 38/40 mm: cleanup the gfp_mask handling in __vmalloc_area_node
In reply to Andrew MortonFrom: Christoph Hellwig <[email protected]>
Subject: mm: cleanup the gfp_mask handling in __vmalloc_area_node
Patch series "two small vmalloc cleanups".
This patch (of 2):
__vmalloc_area_node currently has four different gfp_t variables to just express this simple logic:
- use the passed in mask, plus __GFP_NOWARN and __GFP_HIGHMEM (if suitable) for the underlying page allocation
- use just the reclaim flags from the passed in mask plus __GFP_ZERO for allocating the page array
Simplify this down to just use the pre-existing nested_gfp as-is for the page array allocation, and just the passed in gfp_mask for the page allocation, after conditionally ORing __GFP_HIGHMEM into it. This also makes the allocation warning a little more correct.
Also initialize two variables at the time of declaration while touching this area.
---
mm/vmalloc.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-)
mm/vmalloc.c renamed from mm/vmalloc.c~mm-cleanup-the-gfp_mask-handling-in-__vmalloc_area_node +10 -12
@@ -2461,21 +2461,19 @@ EXPORT_SYMBOL_GPL(vmap_pfn);static void *__vmalloc_area_node (struct vm_struct *area,gfp_t gfp_mask,pgprot_t prot,int node) { -struct page **pages; -unsigned int nr_pages, array_size, i;const gfp_t nested_gfp = (gfp_mask &GFP_RECLAIM_MASK ) | __GFP_ZERO; -const gfp_t alloc_mask = gfp_mask | __GFP_NOWARN; -const gfp_t highmem_mask = (gfp_mask & (GFP_DMA |GFP_DMA32 )) ? -0 : - __GFP_HIGHMEM; +unsigned int nr_pages =get_vm_area_size (area) >>PAGE_SHIFT ; +unsigned int array_size = nr_pages *sizeof (struct page *), i; +struct page **pages; - nr_pages =get_vm_area_size (area) >>PAGE_SHIFT ; - array_size = (nr_pages *sizeof (struct page *)); + gfp_mask |= __GFP_NOWARN; +if (!(gfp_mask & (GFP_DMA |GFP_DMA32 ))) + gfp_mask |= __GFP_HIGHMEM;/* Please note that the recursion is strictly bounded. */ if (array_size >PAGE_SIZE ) { - pages =__vmalloc_node (array_size,1 , nested_gfp|highmem_mask, - node, area->caller); + pages =__vmalloc_node (array_size,1 , nested_gfp, node, + area->caller); }else { pages =kmalloc_node (array_size, nested_gfp, node); }
@@ -2493,9 +2491,9 @@ static void *__vmalloc_area_node(structstruct page *page;if (node ==NUMA_NO_NODE ) - page =alloc_page (alloc_mask|highmem_mask); + page =alloc_page (gfp_mask);else - page =alloc_pages_node (node, alloc_mask|highmem_mask,0 ); + page =alloc_pages_node (node, gfp_mask,0 );if (unlikely (!page)) {/* Successfully allocated i pages, free them in __vfree() */
_
Andrew Morton
maintainerPATCH 39/40 mm: remove the filename in the top of file comment in vmalloc.c
In reply to Andrew MortonFrom: Christoph Hellwig <[email protected]>
Subject: mm: remove the filename in the top of file comment in vmalloc.c
No point in having the filename inside the file.
---
mm/vmalloc.c | 2 -- 1 file changed, 2 deletions(-)
mm/vmalloc.c renamed from mm/vmalloc.c~mm-remove-the-filename-in-the-top-of-file-comment-in-vmallocc +0 -2
@@ -1,7 +1,5 @@// SPDX-License-Identifier: GPL-2.0-only /* -* linux/mm/vmalloc.c -* * Copyright (C) 1993 Linus Torvalds * Support of BIGMEM added by Gerhard Wichert, Siemens AG, July 1999 * SMP-safe vmalloc/vfree/ioremap, Tigran Aivazian <[email protected]>, May 2000
_
Andrew Morton
maintainerPATCH 40/40 mm: remove duplicate include statement in mmu.c
In reply to Andrew MortonFrom: Tian Tao <[email protected]>
Subject: mm: remove duplicate include statement in mmu.c
asm/sections.h is included more than once, Remove the one that isn't necessary.
---
arch/arm/mm/mmu.c | 1 - 1 file changed, 1 deletion(-)
arch/arm/mm/mmu.c renamed from arch/arm/mm/mmu.c~mm-remove-duplicate-include-statement-in-mmuc +0 -1
@@ -17,7 +17,6 @@#include <asm/cp15.h> #include <asm/cputype.h> -#include <asm/sections.h> #include <asm/cachetype.h> #include <asm/fixmap.h> #include <asm/sections.h>
_