History

Merge branch 'akpm' (patches from Andrew)

Merge updates from Andrew Morton: "Incoming: - a small number of updates to scripts/, ocfs2 and fs/buffer.c - most of MM I still have quite a lot of material (mostly not MM) staged after linux-next due to -next dependencies. I'll send those across next week as the preprequisites get merged up" * emailed patches from Andrew Morton <akpm@linux-foundation.org>: (135 commits) mm/page_io.c: annotate refault stalls from swap_readpage mm/Kconfig: fix trivial help text punctuation mm/Kconfig: fix indentation mm/memory_hotplug.c: remove __online_page_set_limits() mm: fix typos in comments when calling __SetPageUptodate() mm: fix struct member name in function comments mm/shmem.c: cast the type of unmap_start to u64 mm: shmem: use proper gfp flags for shmem_writepage() mm/shmem.c: make array 'values' static const, makes object smaller userfaultfd: require CAP_SYS_PTRACE for UFFD_FEATURE_EVENT_FORK fs/userfaultfd.c: wp: clear VM_UFFD_MISSING or VM_UFFD_WP during userfaultfd_register() userfaultfd: wrap the common dst_vma check into an inlined function userfaultfd: remove unnecessary WARN_ON() in __mcopy_atomic_hugetlb() userfaultfd: use vma_pagesize for all huge page size calculation mm/madvise.c: use PAGE_ALIGN[ED] for range checking mm/madvise.c: replace with page_size() in madvise_inject_error() mm/mmap.c: make vma_merge() comment more easy to understand mm/hwpoison-inject: use DEFINE_DEBUGFS_ATTRIBUTE to define debugfs fops autonuma: reduce cache footprint when scanning page tables autonuma: fix watermark checking in migrate_balanced_pgdat() ...

Linus Torvalds committed 6 years ago

Commit 596cf452 parents c3bfc5d 937790695 files · +2661 −1506Browse files

Unified · Split

95 files
  1. Documentation/admin-guide/cgroup-v2.rst +6 −1
  2. Documentation/dev-tools/kasan.rst +63 −0
  3. arch/Kconfig +5 −4
  4. arch/arc/include/asm/pgtable.h +0 −1
  5. arch/arc/mm/fault.c +8 −2
  6. arch/arc/mm/highmem.c +3 −1
  7. arch/powerpc/include/asm/book3s/64/pgtable-4k.h +0 −3
  8. arch/powerpc/include/asm/book3s/64/pgtable-64k.h +0 −3
  9. arch/powerpc/mm/book3s64/radix_pgtable.c +1 −0
  10. arch/x86/Kconfig +1 −0
  11. arch/x86/mm/kasan_init_64.c +61 −0
  12. drivers/base/memory.c +15 −25
  13. drivers/hv/hv_balloon.c +1 −3
  14. drivers/xen/balloon.c +0 −1
  15. fs/buffer.c +4 −2
  16. fs/direct-io.c +0 −21
  17. fs/hugetlbfs/inode.c +48 −15
  18. fs/ocfs2/acl.c +2 −2
  19. fs/userfaultfd.c +13 −8
  20. include/asm-generic/4level-fixup.h +0 −1
  21. include/asm-generic/5level-fixup.h +0 −1
  22. include/asm-generic/pgtable-nop4d.h +1 −1
  23. include/asm-generic/pgtable-nopmd.h +1 −1
  24. include/asm-generic/pgtable-nopud.h +1 −1
  25. include/asm-generic/pgtable.h +51 −0
  26. include/asm-generic/tlb.h +0 −4
  27. include/linux/fs.h +5 −1
  28. include/linux/gfp.h +2 −0
  29. include/linux/hugetlb.h +116 −24
  30. include/linux/kasan.h +31 −0
  31. include/linux/memblock.h +3 −0
  32. include/linux/memcontrol.h +22 −27
  33. include/linux/memory_hotplug.h +4 −7
  34. include/linux/mm.h +12 −22
  35. include/linux/mmzone.h +20 −14
  36. include/linux/moduleloader.h +1 −1
  37. include/linux/page-isolation.h +2 −2
  38. include/linux/slab.h +0 −20
  39. include/linux/string.h +2 −0
  40. include/linux/swap.h +1 −1
  41. include/linux/vmalloc.h +12 −0
  42. include/trace/events/kmem.h +47 −0
  43. kernel/events/uprobes.c +1 −1
  44. kernel/fork.c +4 −0
  45. kernel/sysctl.c +1 −1
  46. lib/Kconfig.kasan +16 −0
  47. lib/test_kasan.c +26 −0
  48. lib/vsprintf.c +29 −11
  49. mm/Kconfig +20 −20
  50. mm/cma.c +2 −4
  51. mm/cma_debug.c +5 −5
  52. mm/filemap.c +29 −25
  53. mm/gup.c +27 −13
  54. mm/huge_memory.c +1 −1
  55. mm/hugetlb.c +91 −197
  56. mm/hwpoison-inject.c +2 −2
  57. mm/internal.h +26 −1
  58. mm/kasan/common.c +233 −0
  59. mm/kasan/generic_report.c +3 −0
  60. mm/kasan/kasan.h +1 −0
  61. mm/khugepaged.c +18 −0
  62. mm/madvise.c +7 −7
  63. mm/memblock.c +75 −36
  64. mm/memcontrol.c +33 −134
  65. mm/memory-failure.c +23 −38
  66. mm/memory.c +40 −12
  67. mm/memory_hotplug.c +56 −30
  68. mm/mempolicy.c +31 −16
  69. mm/migrate.c +6 −10
  70. mm/mmap.c +21 −42
  71. mm/mprotect.c +4 −4
  72. mm/mremap.c +2 −2
  73. mm/nommu.c +2 −8
  74. mm/page_alloc.c +119 −18
  75. mm/page_io.c +13 −2
  76. mm/page_isolation.c +6 −6
  77. mm/pgtable-generic.c +9 −0
  78. mm/rmap.c +45 −20
  79. mm/shmem.c +17 −12
  80. mm/slab.c +4 −3
  81. mm/slab.h +3 −3
  82. mm/slab_common.c +53 −46
  83. mm/slub.c +16 −20
  84. mm/sparse.c +10 −8
  85. mm/swap.c +24 −5
  86. mm/swapfile.c +7 −0
  87. mm/userfaultfd.c +37 −36
  88. mm/util.c +16 −6
  89. mm/vmalloc.c +134 −58
  90. mm/vmscan.c +327 −335
  91. mm/workingset.c +53 −16
  92. mm/z3fold.c +303 −72
  93. scripts/spelling.txt +28 −0
  94. tools/testing/selftests/memfd/memfd_test.c +36 −0
  95. tools/testing/selftests/vm/config +1 −0
Documentation/admin-guide/cgroup-v2.rst+6−1
@@ -1288,7 +1288,12 @@ PAGE_SIZE multiple when read back. · 1287 unmodified lines
1288 inactive_anon, active_anon, inactive_file, active_file, unevictable1288 inactive_anon, active_anon, inactive_file, active_file, unevictable
1289 Amount of memory, swap-backed and filesystem-backed,1289 Amount of memory, swap-backed and filesystem-backed,
1290 on the internal memory management lists used by the1290 on the internal memory management lists used by the
1291 page reclaim algorithm1291 page reclaim algorithm.
1292
1293 As these represent internal list state (eg. shmem pages are on anon
1294 memory management lists), inactive_foo + active_foo may not be equal to
1295 the value for the foo counter, since the foo counter is type-based, not
1296 list-based.
1292 1297
1293 slab_reclaimable1298 slab_reclaimable
1294 Part of "slab" that might be reclaimed, such as1299 Part of "slab" that might be reclaimed, such as
Documentation/dev-tools/kasan.rst+63−0
@@ -218,3 +218,66 @@ brk handler is used to print bug reports. · 217 unmodified lines
218A potential expansion of this mode is a hardware tag-based mode, which would218A potential expansion of this mode is a hardware tag-based mode, which would
219use hardware memory tagging support instead of compiler instrumentation and219use hardware memory tagging support instead of compiler instrumentation and
220manual shadow memory manipulation.220manual shadow memory manipulation.
221
222What memory accesses are sanitised by KASAN?
223--------------------------------------------
224
225The kernel maps memory in a number of different parts of the address
226space. This poses something of a problem for KASAN, which requires
227that all addresses accessed by instrumented code have a valid shadow
228region.
229
230The range of kernel virtual addresses is large: there is not enough
231real memory to support a real shadow region for every address that
232could be accessed by the kernel.
233
234By default
235~~~~~~~~~~
236
237By default, architectures only map real memory over the shadow region
238for the linear mapping (and potentially other small areas). For all
239other areas - such as vmalloc and vmemmap space - a single read-only
240page is mapped over the shadow area. This read-only shadow page
241declares all memory accesses as permitted.
242
243This presents a problem for modules: they do not live in the linear
244mapping, but in a dedicated module space. By hooking in to the module
245allocator, KASAN can temporarily map real shadow memory to cover
246them. This allows detection of invalid accesses to module globals, for
247example.
248
249This also creates an incompatibility with ``VMAP_STACK``: if the stack
250lives in vmalloc space, it will be shadowed by the read-only page, and
251the kernel will fault when trying to set up the shadow data for stack
252variables.
253
254CONFIG_KASAN_VMALLOC
255~~~~~~~~~~~~~~~~~~~~
256
257With ``CONFIG_KASAN_VMALLOC``, KASAN can cover vmalloc space at the
258cost of greater memory usage. Currently this is only supported on x86.
259
260This works by hooking into vmalloc and vmap, and dynamically
261allocating real shadow memory to back the mappings.
262
263Most mappings in vmalloc space are small, requiring less than a full
264page of shadow space. Allocating a full shadow page per mapping would
265therefore be wasteful. Furthermore, to ensure that different mappings
266use different shadow pages, mappings would have to be aligned to
267``KASAN_SHADOW_SCALE_SIZE * PAGE_SIZE``.
268
269Instead, we share backing space across multiple mappings. We allocate
270a backing page when a mapping in vmalloc space uses a particular page
271of the shadow region. This page can be shared by other vmalloc
272mappings later on.
273
274We hook in to the vmap infrastructure to lazily clean up unused shadow
275memory.
276
277To avoid the difficulties around swapping mappings around, we expect
278that the part of the shadow region that covers the vmalloc space will
279not be covered by the early shadow page, but will be left
280unmapped. This will require changes in arch-specific code.
281
282This allows ``VMAP_STACK`` support on x86, and can simplify support of
283architectures that do not have a fixed module region.
arch/Kconfig+5−4
@@ -836,16 +836,17 @@ config HAVE_ARCH_VMAP_STACK · 835 unmodified lines
836config VMAP_STACK836config VMAP_STACK
837 default y837 default y
838 bool "Use a virtually-mapped stack"838 bool "Use a virtually-mapped stack"
839 depends on HAVE_ARCH_VMAP_STACK && !KASAN839 depends on HAVE_ARCH_VMAP_STACK
840 depends on !KASAN || KASAN_VMALLOC
840 ---help---841 ---help---
841 Enable this if you want the use virtually-mapped kernel stacks842 Enable this if you want the use virtually-mapped kernel stacks
842 with guard pages. This causes kernel stack overflows to be843 with guard pages. This causes kernel stack overflows to be
843 caught immediately rather than causing difficult-to-diagnose844 caught immediately rather than causing difficult-to-diagnose
844 corruption.845 corruption.
845 846
846 This is presently incompatible with KASAN because KASAN expects847 To use this with KASAN, the architecture must support backing
847 the stack to map directly to the KASAN shadow map using a formula848 virtual mappings with real shadow memory, and KASAN_VMALLOC must
848 that is incorrect if the stack is in vmalloc space.849 be enabled.
849 850
850config ARCH_OPTIONAL_KERNEL_RWX851config ARCH_OPTIONAL_KERNEL_RWX
851 def_bool n852 def_bool n
arch/arc/include/asm/pgtable.h+0−1
@@ -33,7 +33,6 @@ · 32 unmodified lines
33#define _ASM_ARC_PGTABLE_H33#define _ASM_ARC_PGTABLE_H
34 34
35#include <linux/bits.h>35#include <linux/bits.h>
36#define __ARCH_USE_5LEVEL_HACK
37#include <asm-generic/pgtable-nopmd.h>36#include <asm-generic/pgtable-nopmd.h>
38#include <asm/page.h>37#include <asm/page.h>
39#include <asm/mmu.h> /* to propagate CONFIG_ARC_MMU_VER <n> */38#include <asm/mmu.h> /* to propagate CONFIG_ARC_MMU_VER <n> */
arch/arc/mm/fault.c+8−2
@@ -30,6 +30,7 @@ noinline static int handle_kernel_vaddr_fault(unsigned long address) · 29 unmodified lines
30 * with the 'reference' page table.30 * with the 'reference' page table.
31 */31 */
32 pgd_t *pgd, *pgd_k;32 pgd_t *pgd, *pgd_k;
33 p4d_t *p4d, *p4d_k;
33 pud_t *pud, *pud_k;34 pud_t *pud, *pud_k;
34 pmd_t *pmd, *pmd_k;35 pmd_t *pmd, *pmd_k;
35 36
@@ -39,8 +40,13 @@ noinline static int handle_kernel_vaddr_fault(unsigned long address) · 3 unmodified lines
39 if (!pgd_present(*pgd_k))40 if (!pgd_present(*pgd_k))
40 goto bad_area;41 goto bad_area;
41 42
42 pud = pud_offset(pgd, address);43 p4d = p4d_offset(pgd, address);
43 pud_k = pud_offset(pgd_k, address);44 p4d_k = p4d_offset(pgd_k, address);
45 if (!p4d_present(*p4d_k))
46 goto bad_area;
47
48 pud = pud_offset(p4d, address);
49 pud_k = pud_offset(p4d_k, address);
44 if (!pud_present(*pud_k))50 if (!pud_present(*pud_k))
45 goto bad_area;51 goto bad_area;
46 52
arch/arc/mm/highmem.c+3−1
@@ -111,12 +111,14 @@ EXPORT_SYMBOL(__kunmap_atomic); · 110 unmodified lines
111static noinline pte_t * __init alloc_kmap_pgtable(unsigned long kvaddr)111static noinline pte_t * __init alloc_kmap_pgtable(unsigned long kvaddr)
112{112{
113 pgd_t *pgd_k;113 pgd_t *pgd_k;
114 p4d_t *p4d_k;
114 pud_t *pud_k;115 pud_t *pud_k;
115 pmd_t *pmd_k;116 pmd_t *pmd_k;
116 pte_t *pte_k;117 pte_t *pte_k;
117 118
118 pgd_k = pgd_offset_k(kvaddr);119 pgd_k = pgd_offset_k(kvaddr);
119 pud_k = pud_offset(pgd_k, kvaddr);120 p4d_k = p4d_offset(pgd_k, kvaddr);
121 pud_k = pud_offset(p4d_k, kvaddr);
120 pmd_k = pmd_offset(pud_k, kvaddr);122 pmd_k = pmd_offset(pud_k, kvaddr);
121 123
122 pte_k = (pte_t *)memblock_alloc_low(PAGE_SIZE, PAGE_SIZE);124 pte_k = (pte_t *)memblock_alloc_low(PAGE_SIZE, PAGE_SIZE);
arch/powerpc/include/asm/book3s/64/pgtable-4k.h+0−3
@@ -70,9 +70,6 @@ static inline int get_hugepd_cache_index(int index) · 69 unmodified lines
70 /* should not reach */70 /* should not reach */
71}71}
72 72
73#else /* !CONFIG_HUGETLB_PAGE */
74static inline int pmd_huge(pmd_t pmd) { return 0; }
75static inline int pud_huge(pud_t pud) { return 0; }
76#endif /* CONFIG_HUGETLB_PAGE */73#endif /* CONFIG_HUGETLB_PAGE */
77 74
78#endif /* __ASSEMBLY__ */75#endif /* __ASSEMBLY__ */
arch/powerpc/include/asm/book3s/64/pgtable-64k.h+0−3
@@ -59,9 +59,6 @@ static inline int get_hugepd_cache_index(int index) · 58 unmodified lines
59 BUG();59 BUG();
60}60}
61 61
62#else /* !CONFIG_HUGETLB_PAGE */
63static inline int pmd_huge(pmd_t pmd) { return 0; }
64static inline int pud_huge(pud_t pud) { return 0; }
65#endif /* CONFIG_HUGETLB_PAGE */62#endif /* CONFIG_HUGETLB_PAGE */
66 63
67static inline int remap_4k_pfn(struct vm_area_struct *vma, unsigned long addr,64static inline int remap_4k_pfn(struct vm_area_struct *vma, unsigned long addr,
arch/powerpc/mm/book3s64/radix_pgtable.c+1−0
@@ -13,6 +13,7 @@ · 12 unmodified lines
13#include <linux/memblock.h>13#include <linux/memblock.h>
14#include <linux/of_fdt.h>14#include <linux/of_fdt.h>
15#include <linux/mm.h>15#include <linux/mm.h>
16#include <linux/hugetlb.h>
16#include <linux/string_helpers.h>17#include <linux/string_helpers.h>
17#include <linux/stop_machine.h>18#include <linux/stop_machine.h>
18 19
arch/x86/Kconfig+1−0
@@ -134,6 +134,7 @@ config X86 · 133 unmodified lines
134 select HAVE_ARCH_JUMP_LABEL134 select HAVE_ARCH_JUMP_LABEL
135 select HAVE_ARCH_JUMP_LABEL_RELATIVE135 select HAVE_ARCH_JUMP_LABEL_RELATIVE
136 select HAVE_ARCH_KASAN if X86_64136 select HAVE_ARCH_KASAN if X86_64
137 select HAVE_ARCH_KASAN_VMALLOC if X86_64
137 select HAVE_ARCH_KGDB138 select HAVE_ARCH_KGDB
138 select HAVE_ARCH_MMAP_RND_BITS if MMU139 select HAVE_ARCH_MMAP_RND_BITS if MMU
139 select HAVE_ARCH_MMAP_RND_COMPAT_BITS if MMU && COMPAT140 select HAVE_ARCH_MMAP_RND_COMPAT_BITS if MMU && COMPAT
arch/x86/mm/kasan_init_64.c+61−0
@@ -245,6 +245,49 @@ static void __init kasan_map_early_shadow(pgd_t *pgd) · 244 unmodified lines
245 } while (pgd++, addr = next, addr != end);245 } while (pgd++, addr = next, addr != end);
246}246}
247 247
248static void __init kasan_shallow_populate_p4ds(pgd_t *pgd,
249 unsigned long addr,
250 unsigned long end)
251{
252 p4d_t *p4d;
253 unsigned long next;
254 void *p;
255
256 p4d = p4d_offset(pgd, addr);
257 do {
258 next = p4d_addr_end(addr, end);
259
260 if (p4d_none(*p4d)) {
261 p = early_alloc(PAGE_SIZE, NUMA_NO_NODE, true);
262 p4d_populate(&init_mm, p4d, p);
263 }
264 } while (p4d++, addr = next, addr != end);
265}
266
267static void __init kasan_shallow_populate_pgds(void *start, void *end)
268{
269 unsigned long addr, next;
270 pgd_t *pgd;
271 void *p;
272
273 addr = (unsigned long)start;
274 pgd = pgd_offset_k(addr);
275 do {
276 next = pgd_addr_end(addr, (unsigned long)end);
277
278 if (pgd_none(*pgd)) {
279 p = early_alloc(PAGE_SIZE, NUMA_NO_NODE, true);
280 pgd_populate(&init_mm, pgd, p);
281 }
282
283 /*
284 * we need to populate p4ds to be synced when running in
285 * four level mode - see sync_global_pgds_l4()
286 */
287 kasan_shallow_populate_p4ds(pgd, addr, next);
288 } while (pgd++, addr = next, addr != (unsigned long)end);
289}
290
248#ifdef CONFIG_KASAN_INLINE291#ifdef CONFIG_KASAN_INLINE
249static int kasan_die_handler(struct notifier_block *self,292static int kasan_die_handler(struct notifier_block *self,
250 unsigned long val,293 unsigned long val,
@@ -354,6 +397,24 @@ void __init kasan_init(void) · 103 unmodified lines
354 397
355 kasan_populate_early_shadow(398 kasan_populate_early_shadow(
356 kasan_mem_to_shadow((void *)PAGE_OFFSET + MAXMEM),399 kasan_mem_to_shadow((void *)PAGE_OFFSET + MAXMEM),
400 kasan_mem_to_shadow((void *)VMALLOC_START));
401
402 /*
403 * If we're in full vmalloc mode, don't back vmalloc space with early
404 * shadow pages. Instead, prepopulate pgds/p4ds so they are synced to
405 * the global table and we can populate the lower levels on demand.
406 */
407 if (IS_ENABLED(CONFIG_KASAN_VMALLOC))
408 kasan_shallow_populate_pgds(
409 kasan_mem_to_shadow((void *)VMALLOC_START),
410 kasan_mem_to_shadow((void *)VMALLOC_END));
411 else
412 kasan_populate_early_shadow(
413 kasan_mem_to_shadow((void *)VMALLOC_START),
414 kasan_mem_to_shadow((void *)VMALLOC_END));
415
416 kasan_populate_early_shadow(
417 kasan_mem_to_shadow((void *)VMALLOC_END + 1),
357 shadow_cpu_entry_begin);418 shadow_cpu_entry_begin);
358 419
359 kasan_populate_shadow((unsigned long)shadow_cpu_entry_begin,420 kasan_populate_shadow((unsigned long)shadow_cpu_entry_begin,
drivers/base/memory.c+15−25
@@ -19,15 +19,12 @@ · 18 unmodified lines
19#include <linux/memory.h>19#include <linux/memory.h>
20#include <linux/memory_hotplug.h>20#include <linux/memory_hotplug.h>
21#include <linux/mm.h>21#include <linux/mm.h>
22#include <linux/mutex.h>
23#include <linux/stat.h>22#include <linux/stat.h>
24#include <linux/slab.h>23#include <linux/slab.h>
25 24
26#include <linux/atomic.h>25#include <linux/atomic.h>
27#include <linux/uaccess.h>26#include <linux/uaccess.h>
28 27
29static DEFINE_MUTEX(mem_sysfs_mutex);
30
31#define MEMORY_CLASS_NAME "memory"28#define MEMORY_CLASS_NAME "memory"
32 29
33#define to_memory_block(dev) container_of(dev, struct memory_block, dev)30#define to_memory_block(dev) container_of(dev, struct memory_block, dev)
@@ -538,12 +535,7 @@ static ssize_t soft_offline_page_store(struct device *dev, · 504 unmodified lines
538 if (kstrtoull(buf, 0, &pfn) < 0)535 if (kstrtoull(buf, 0, &pfn) < 0)
539 return -EINVAL;536 return -EINVAL;
540 pfn >>= PAGE_SHIFT;537 pfn >>= PAGE_SHIFT;
541 if (!pfn_valid(pfn))538 ret = soft_offline_page(pfn, 0);
542 return -ENXIO;
543 /* Only online pages can be soft-offlined (esp., not ZONE_DEVICE). */
544 if (!pfn_to_online_page(pfn))
545 return -EIO;
546 ret = soft_offline_page(pfn_to_page(pfn), 0);
547 return ret == 0 ? count : ret;539 return ret == 0 ? count : ret;
548}540}
549 541
@@ -705,6 +697,8 @@ static void unregister_memory(struct memory_block *memory) · 155 unmodified lines
705 * Create memory block devices for the given memory area. Start and size697 * Create memory block devices for the given memory area. Start and size
706 * have to be aligned to memory block granularity. Memory block devices698 * have to be aligned to memory block granularity. Memory block devices
707 * will be initialized as offline.699 * will be initialized as offline.
700 *
701 * Called under device_hotplug_lock.
708 */702 */
709int create_memory_block_devices(unsigned long start, unsigned long size)703int create_memory_block_devices(unsigned long start, unsigned long size)
710{704{
@@ -718,7 +712,6 @@ int create_memory_block_devices(unsigned long start, unsigned long size) · 7 unmodified lines
718 !IS_ALIGNED(size, memory_block_size_bytes())))712 !IS_ALIGNED(size, memory_block_size_bytes())))
719 return -EINVAL;713 return -EINVAL;
720 714
721 mutex_lock(&mem_sysfs_mutex);
722 for (block_id = start_block_id; block_id != end_block_id; block_id++) {715 for (block_id = start_block_id; block_id != end_block_id; block_id++) {
723 ret = init_memory_block(&mem, block_id, MEM_OFFLINE);716 ret = init_memory_block(&mem, block_id, MEM_OFFLINE);
724 if (ret)717 if (ret)
@@ -730,11 +723,12 @@ int create_memory_block_devices(unsigned long start, unsigned long size) · 5 unmodified lines
730 for (block_id = start_block_id; block_id != end_block_id;723 for (block_id = start_block_id; block_id != end_block_id;
731 block_id++) {724 block_id++) {
732 mem = find_memory_block_by_id(block_id);725 mem = find_memory_block_by_id(block_id);
726 if (WARN_ON_ONCE(!mem))
727 continue;
733 mem->section_count = 0;728 mem->section_count = 0;
734 unregister_memory(mem);729 unregister_memory(mem);
735 }730 }
736 }731 }
737 mutex_unlock(&mem_sysfs_mutex);
738 return ret;732 return ret;
739}733}
740 734
@@ -742,6 +736,8 @@ int create_memory_block_devices(unsigned long start, unsigned long size) · 1 unmodified line
742 * Remove memory block devices for the given memory area. Start and size736 * Remove memory block devices for the given memory area. Start and size
743 * have to be aligned to memory block granularity. Memory block devices737 * have to be aligned to memory block granularity. Memory block devices
744 * have to be offline.738 * have to be offline.
739 *
740 * Called under device_hotplug_lock.
745 */741 */
746void remove_memory_block_devices(unsigned long start, unsigned long size)742void remove_memory_block_devices(unsigned long start, unsigned long size)
747{743{
@@ -754,7 +750,6 @@ void remove_memory_block_devices(unsigned long start, unsigned long size) · 6 unmodified lines
754 !IS_ALIGNED(size, memory_block_size_bytes())))750 !IS_ALIGNED(size, memory_block_size_bytes())))
755 return;751 return;
756 752
757 mutex_lock(&mem_sysfs_mutex);
758 for (block_id = start_block_id; block_id != end_block_id; block_id++) {753 for (block_id = start_block_id; block_id != end_block_id; block_id++) {
759 mem = find_memory_block_by_id(block_id);754 mem = find_memory_block_by_id(block_id);
760 if (WARN_ON_ONCE(!mem))755 if (WARN_ON_ONCE(!mem))
@@ -763,7 +758,6 @@ void remove_memory_block_devices(unsigned long start, unsigned long size) · 2 unmodified lines
763 unregister_memory_block_under_nodes(mem);758 unregister_memory_block_under_nodes(mem);
764 unregister_memory(mem);759 unregister_memory(mem);
765 }760 }
766 mutex_unlock(&mem_sysfs_mutex);
767}761}
768 762
769/* return true if the memory block is offlined, otherwise, return false */763/* return true if the memory block is offlined, otherwise, return false */
@@ -797,12 +791,13 @@ static const struct attribute_group *memory_root_attr_groups[] = { · 27 unmodified lines
797};791};
798 792
799/*793/*
800 * Initialize the sysfs support for memory devices...794 * Initialize the sysfs support for memory devices. At the time this function
795 * is called, we cannot have concurrent creation/deletion of memory block
796 * devices, the device_hotplug_lock is not needed.
801 */797 */
802void __init memory_dev_init(void)798void __init memory_dev_init(void)
803{799{
804 int ret;800 int ret;
805 int err;
806 unsigned long block_sz, nr;801 unsigned long block_sz, nr;
807 802
808 /* Validate the configured memory block size */803 /* Validate the configured memory block size */
@@ -813,24 +808,19 @@ void __init memory_dev_init(void) · 4 unmodified lines
813 808
814 ret = subsys_system_register(&memory_subsys, memory_root_attr_groups);809 ret = subsys_system_register(&memory_subsys, memory_root_attr_groups);
815 if (ret)810 if (ret)
816 goto out;811 panic("%s() failed to register subsystem: %d\n", __func__, ret);
817 812
818 /*813 /*
819 * Create entries for memory sections that were found814 * Create entries for memory sections that were found
820 * during boot and have been initialized815 * during boot and have been initialized
821 */816 */
822 mutex_lock(&mem_sysfs_mutex);
823 for (nr = 0; nr <= __highest_present_section_nr;817 for (nr = 0; nr <= __highest_present_section_nr;
824 nr += sections_per_block) {818 nr += sections_per_block) {
825 err = add_memory_block(nr);819 ret = add_memory_block(nr);
826 if (!ret)820 if (ret)
827 ret = err;821 panic("%s() failed to add memory block: %d\n", __func__,
822 ret);
828 }823 }
829 mutex_unlock(&mem_sysfs_mutex);
830
831out:
832 if (ret)
833 panic("%s() failed: %d\n", __func__, ret);
834}824}
835 825
836/**826/**
drivers/hv/hv_balloon.c+1−3
@@ -682,9 +682,7 @@ static void hv_page_online_one(struct hv_hotadd_state *has, struct page *pg) · 681 unmodified lines
682 __ClearPageOffline(pg);682 __ClearPageOffline(pg);
683 683
684 /* This frame is currently backed; online the page. */684 /* This frame is currently backed; online the page. */
685 __online_page_set_limits(pg);685 generic_online_page(pg, 0);
686 __online_page_increment_counters(pg);
687 __online_page_free(pg);
688 686
689 lockdep_assert_held(&dm_device.ha_lock);687 lockdep_assert_held(&dm_device.ha_lock);
690 dm_device.num_pages_onlined++;688 dm_device.num_pages_onlined++;
drivers/xen/balloon.c+0−1
@@ -374,7 +374,6 @@ static void xen_online_page(struct page *page, unsigned int order) · 373 unmodified lines
374 mutex_lock(&balloon_mutex);374 mutex_lock(&balloon_mutex);
375 for (i = 0; i < size; i++) {375 for (i = 0; i < size; i++) {
376 p = pfn_to_page(start_pfn + i);376 p = pfn_to_page(start_pfn + i);
377 __online_page_set_limits(p);
378 balloon_append(p);377 balloon_append(p);
379 }378 }
380 mutex_unlock(&balloon_mutex);379 mutex_unlock(&balloon_mutex);
fs/buffer.c+4−2
@@ -49,6 +49,8 @@ · 48 unmodified lines
49#include <trace/events/block.h>49#include <trace/events/block.h>
50#include <linux/fscrypt.h>50#include <linux/fscrypt.h>
51 51
52#include "internal.h"
53
52static int fsync_buffers_list(spinlock_t *lock, struct list_head *list);54static int fsync_buffers_list(spinlock_t *lock, struct list_head *list);
53static int submit_bh_wbc(int op, int op_flags, struct buffer_head *bh,55static int submit_bh_wbc(int op, int op_flags, struct buffer_head *bh,
54 enum rw_hint hint, struct writeback_control *wbc);56 enum rw_hint hint, struct writeback_control *wbc);
@@ -1423,10 +1425,10 @@ static bool has_bh_in_lru(int cpu, void *dummy) · 1368 unmodified lines
1423 1425
1424 for (i = 0; i < BH_LRU_SIZE; i++) {1426 for (i = 0; i < BH_LRU_SIZE; i++) {
1425 if (b->bhs[i])1427 if (b->bhs[i])
1426 return 1;1428 return true;
1427 }1429 }
1428 1430
1429 return 0;1431 return false;
1430}1432}
1431 1433
1432void invalidate_bh_lrus(void)1434void invalidate_bh_lrus(void)
fs/direct-io.c+0−21
@@ -220,27 +220,6 @@ static inline struct page *dio_get_page(struct dio *dio, · 219 unmodified lines
220 return dio->pages[sdio->head];220 return dio->pages[sdio->head];
221}221}
222 222
223/*
224 * Warn about a page cache invalidation failure during a direct io write.
225 */
226void dio_warn_stale_pagecache(struct file *filp)
227{
228 static DEFINE_RATELIMIT_STATE(_rs, 86400 * HZ, DEFAULT_RATELIMIT_BURST);
229 char pathname[128];
230 struct inode *inode = file_inode(filp);
231 char *path;
232
233 errseq_set(&inode->i_mapping->wb_err, -EIO);
234 if (__ratelimit(&_rs)) {
235 path = file_path(filp, pathname, sizeof(pathname));
236 if (IS_ERR(path))
237 path = "(unknown)";
238 pr_crit("Page cache invalidation failure on direct I/O. Possible data corruption due to collision with buffered I/O!\n");
239 pr_crit("File: %s PID: %d Comm: %.20s\n", path, current->pid,
240 current->comm);
241 }
242}
243
244/*223/*
245 * dio_complete() - called when all DIO BIO I/O has been completed224 * dio_complete() - called when all DIO BIO I/O has been completed
246 *225 *
fs/hugetlbfs/inode.c+48−15
@@ -440,7 +440,7 @@ static void remove_inode_hugepages(struct inode *inode, loff_t lstart, · 439 unmodified lines
440 u32 hash;440 u32 hash;
441 441
442 index = page->index;442 index = page->index;
443 hash = hugetlb_fault_mutex_hash(h, mapping, index, 0);443 hash = hugetlb_fault_mutex_hash(mapping, index);
444 mutex_lock(&hugetlb_fault_mutex_table[hash]);444 mutex_lock(&hugetlb_fault_mutex_table[hash]);
445 445
446 /*446 /*
@@ -644,7 +644,7 @@ static long hugetlbfs_fallocate(struct file *file, int mode, loff_t offset, · 197 unmodified lines
644 addr = index * hpage_size;644 addr = index * hpage_size;
645 645
646 /* mutex taken here, fault path and hole punch */646 /* mutex taken here, fault path and hole punch */
647 hash = hugetlb_fault_mutex_hash(h, mapping, index, addr);647 hash = hugetlb_fault_mutex_hash(mapping, index);
648 mutex_lock(&hugetlb_fault_mutex_table[hash]);648 mutex_lock(&hugetlb_fault_mutex_table[hash]);
649 649
650 /* See if already present in mapping to avoid alloc/free */650 /* See if already present in mapping to avoid alloc/free */
@@ -815,8 +815,11 @@ static struct inode *hugetlbfs_get_inode(struct super_block *sb, · 164 unmodified lines
815/*815/*
816 * File creation. Allocate an inode, and we're done..816 * File creation. Allocate an inode, and we're done..
817 */817 */
818static int hugetlbfs_mknod(struct inode *dir,818static int do_hugetlbfs_mknod(struct inode *dir,
819 struct dentry *dentry, umode_t mode, dev_t dev)819 struct dentry *dentry,
820 umode_t mode,
821 dev_t dev,
822 bool tmpfile)
820{823{
821 struct inode *inode;824 struct inode *inode;
822 int error = -ENOSPC;825 int error = -ENOSPC;
@@ -824,13 +827,23 @@ static int hugetlbfs_mknod(struct inode *dir, · 1 unmodified line
824 inode = hugetlbfs_get_inode(dir->i_sb, dir, mode, dev);827 inode = hugetlbfs_get_inode(dir->i_sb, dir, mode, dev);
825 if (inode) {828 if (inode) {
826 dir->i_ctime = dir->i_mtime = current_time(dir);829 dir->i_ctime = dir->i_mtime = current_time(dir);
827 d_instantiate(dentry, inode);830 if (tmpfile) {
828 dget(dentry); /* Extra count - pin the dentry in core */831 d_tmpfile(dentry, inode);
832 } else {
833 d_instantiate(dentry, inode);
834 dget(dentry);/* Extra count - pin the dentry in core */
835 }
829 error = 0;836 error = 0;
830 }837 }
831 return error;838 return error;
832}839}
833 840
841static int hugetlbfs_mknod(struct inode *dir,
842 struct dentry *dentry, umode_t mode, dev_t dev)
843{
844 return do_hugetlbfs_mknod(dir, dentry, mode, dev, false);
845}
846
834static int hugetlbfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)847static int hugetlbfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
835{848{
836 int retval = hugetlbfs_mknod(dir, dentry, mode | S_IFDIR, 0);849 int retval = hugetlbfs_mknod(dir, dentry, mode | S_IFDIR, 0);
@@ -844,6 +857,12 @@ static int hugetlbfs_create(struct inode *dir, struct dentry *dentry, umode_t mo · 7 unmodified lines
844 return hugetlbfs_mknod(dir, dentry, mode | S_IFREG, 0);857 return hugetlbfs_mknod(dir, dentry, mode | S_IFREG, 0);
845}858}
846 859
860static int hugetlbfs_tmpfile(struct inode *dir,
861 struct dentry *dentry, umode_t mode)
862{
863 return do_hugetlbfs_mknod(dir, dentry, mode | S_IFREG, 0, true);
864}
865
847static int hugetlbfs_symlink(struct inode *dir,866static int hugetlbfs_symlink(struct inode *dir,
848 struct dentry *dentry, const char *symname)867 struct dentry *dentry, const char *symname)
849{868{
@@ -1102,6 +1121,7 @@ static const struct inode_operations hugetlbfs_dir_inode_operations = { · 252 unmodified lines
1102 .mknod = hugetlbfs_mknod,1121 .mknod = hugetlbfs_mknod,
1103 .rename = simple_rename,1122 .rename = simple_rename,
1104 .setattr = hugetlbfs_setattr,1123 .setattr = hugetlbfs_setattr,
1124 .tmpfile = hugetlbfs_tmpfile,
1105};1125};
1106 1126
1107static const struct inode_operations hugetlbfs_inode_operations = {1127static const struct inode_operations hugetlbfs_inode_operations = {
@@ -1461,28 +1481,41 @@ static int __init init_hugetlbfs_fs(void) · 353 unmodified lines
1461 sizeof(struct hugetlbfs_inode_info),1481 sizeof(struct hugetlbfs_inode_info),
1462 0, SLAB_ACCOUNT, init_once);1482 0, SLAB_ACCOUNT, init_once);
1463 if (hugetlbfs_inode_cachep == NULL)1483 if (hugetlbfs_inode_cachep == NULL)
1464 goto out2;1484 goto out;
1465 1485
1466 error = register_filesystem(&hugetlbfs_fs_type);1486 error = register_filesystem(&hugetlbfs_fs_type);
1467 if (error)1487 if (error)
1468 goto out;1488 goto out_free;
1469 1489
1490 /* default hstate mount is required */
1491 mnt = mount_one_hugetlbfs(&hstates[default_hstate_idx]);
1492 if (IS_ERR(mnt)) {
1493 error = PTR_ERR(mnt);
1494 goto out_unreg;
1495 }
1496 hugetlbfs_vfsmount[default_hstate_idx] = mnt;
1497
1498 /* other hstates are optional */
1470 i = 0;1499 i = 0;
1471 for_each_hstate(h) {1500 for_each_hstate(h) {
1501 if (i == default_hstate_idx)
1502 continue;
1503
1472 mnt = mount_one_hugetlbfs(h);1504 mnt = mount_one_hugetlbfs(h);
1473 if (IS_ERR(mnt) && i == 0) {1505 if (IS_ERR(mnt))
1474 error = PTR_ERR(mnt);1506 hugetlbfs_vfsmount[i] = NULL;
1475 goto out;1507 else
1476 }1508 hugetlbfs_vfsmount[i] = mnt;
1477 hugetlbfs_vfsmount[i] = mnt;
1478 i++;1509 i++;
1479 }1510 }
1480 1511
1481 return 0;1512 return 0;
1482 1513
1483 out:1514 out_unreg:
1515 (void)unregister_filesystem(&hugetlbfs_fs_type);
1516 out_free:
1484 kmem_cache_destroy(hugetlbfs_inode_cachep);1517 kmem_cache_destroy(hugetlbfs_inode_cachep);
1485 out2:1518 out:
1486 return error;1519 return error;
1487}1520}
1488fs_initcall(init_hugetlbfs_fs)1521fs_initcall(init_hugetlbfs_fs)
fs/ocfs2/acl.c+2−2
@@ -327,8 +327,8 @@ int ocfs2_acl_chmod(struct inode *inode, struct buffer_head *bh) · 326 unmodified lines
327 down_read(&OCFS2_I(inode)->ip_xattr_sem);327 down_read(&OCFS2_I(inode)->ip_xattr_sem);
328 acl = ocfs2_get_acl_nolock(inode, ACL_TYPE_ACCESS, bh);328 acl = ocfs2_get_acl_nolock(inode, ACL_TYPE_ACCESS, bh);
329 up_read(&OCFS2_I(inode)->ip_xattr_sem);329 up_read(&OCFS2_I(inode)->ip_xattr_sem);
330 if (IS_ERR(acl) || !acl)330 if (IS_ERR_OR_NULL(acl))
331 return PTR_ERR(acl);331 return PTR_ERR_OR_ZERO(acl);
332 ret = __posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);332 ret = __posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
333 if (ret)333 if (ret)
334 return ret;334 return ret;
fs/userfaultfd.c+13−8
@@ -1460,7 +1460,8 @@ static int userfaultfd_register(struct userfaultfd_ctx *ctx, · 1459 unmodified lines
1460 start = vma->vm_start;1460 start = vma->vm_start;
1461 vma_end = min(end, vma->vm_end);1461 vma_end = min(end, vma->vm_end);
1462 1462
1463 new_flags = (vma->vm_flags & ~vm_flags) | vm_flags;1463 new_flags = (vma->vm_flags &
1464 ~(VM_UFFD_MISSING|VM_UFFD_WP)) | vm_flags;
1464 prev = vma_merge(mm, prev, start, vma_end, new_flags,1465 prev = vma_merge(mm, prev, start, vma_end, new_flags,
1465 vma->anon_vma, vma->vm_file, vma->vm_pgoff,1466 vma->anon_vma, vma->vm_file, vma->vm_pgoff,
1466 vma_policy(vma),1467 vma_policy(vma),
@@ -1834,13 +1835,12 @@ static int userfaultfd_api(struct userfaultfd_ctx *ctx, · 367 unmodified lines
1834 if (copy_from_user(&uffdio_api, buf, sizeof(uffdio_api)))1835 if (copy_from_user(&uffdio_api, buf, sizeof(uffdio_api)))
1835 goto out;1836 goto out;
1836 features = uffdio_api.features;1837 features = uffdio_api.features;
1837 if (uffdio_api.api != UFFD_API || (features & ~UFFD_API_FEATURES)) {1838 ret = -EINVAL;
1838 memset(&uffdio_api, 0, sizeof(uffdio_api));1839 if (uffdio_api.api != UFFD_API || (features & ~UFFD_API_FEATURES))
1839 if (copy_to_user(buf, &uffdio_api, sizeof(uffdio_api)))1840 goto err_out;
1840 goto out;1841 ret = -EPERM;
1841 ret = -EINVAL;1842 if ((features & UFFD_FEATURE_EVENT_FORK) && !capable(CAP_SYS_PTRACE))
1842 goto out;1843 goto err_out;
1843 }
1844 /* report all available features and ioctls to userland */1844 /* report all available features and ioctls to userland */
1845 uffdio_api.features = UFFD_API_FEATURES;1845 uffdio_api.features = UFFD_API_FEATURES;
1846 uffdio_api.ioctls = UFFD_API_IOCTLS;1846 uffdio_api.ioctls = UFFD_API_IOCTLS;
@@ -1853,6 +1853,11 @@ static int userfaultfd_api(struct userfaultfd_ctx *ctx, · 6 unmodified lines
1853 ret = 0;1853 ret = 0;
1854out:1854out:
1855 return ret;1855 return ret;
1856err_out:
1857 memset(&uffdio_api, 0, sizeof(uffdio_api));
1858 if (copy_to_user(buf, &uffdio_api, sizeof(uffdio_api)))
1859 ret = -EFAULT;
1860 goto out;
1856}1861}
1857 1862
1858static long userfaultfd_ioctl(struct file *file, unsigned cmd,1863static long userfaultfd_ioctl(struct file *file, unsigned cmd,
include/asm-generic/4level-fixup.h+0−1
@@ -30,7 +30,6 @@ · 29 unmodified lines
30#undef pud_free_tlb30#undef pud_free_tlb
31#define pud_free_tlb(tlb, x, addr) do { } while (0)31#define pud_free_tlb(tlb, x, addr) do { } while (0)
32#define pud_free(mm, x) do { } while (0)32#define pud_free(mm, x) do { } while (0)
33#define __pud_free_tlb(tlb, x, addr) do { } while (0)
34 33
35#undef pud_addr_end34#undef pud_addr_end
36#define pud_addr_end(addr, end) (end)35#define pud_addr_end(addr, end) (end)
include/asm-generic/5level-fixup.h+0−1
@@ -51,7 +51,6 @@ static inline int p4d_present(p4d_t p4d) · 50 unmodified lines
51#undef p4d_free_tlb51#undef p4d_free_tlb
52#define p4d_free_tlb(tlb, x, addr) do { } while (0)52#define p4d_free_tlb(tlb, x, addr) do { } while (0)
53#define p4d_free(mm, x) do { } while (0)53#define p4d_free(mm, x) do { } while (0)
54#define __p4d_free_tlb(tlb, x, addr) do { } while (0)
55 54
56#undef p4d_addr_end55#undef p4d_addr_end
57#define p4d_addr_end(addr, end) (end)56#define p4d_addr_end(addr, end) (end)
include/asm-generic/pgtable-nop4d.h+1−1
@@ -50,7 +50,7 @@ static inline p4d_t *p4d_offset(pgd_t *pgd, unsigned long address) · 49 unmodified lines
50 */50 */
51#define p4d_alloc_one(mm, address) NULL51#define p4d_alloc_one(mm, address) NULL
52#define p4d_free(mm, x) do { } while (0)52#define p4d_free(mm, x) do { } while (0)
53#define __p4d_free_tlb(tlb, x, a) do { } while (0)53#define p4d_free_tlb(tlb, x, a) do { } while (0)
54 54
55#undef p4d_addr_end55#undef p4d_addr_end
56#define p4d_addr_end(addr, end) (end)56#define p4d_addr_end(addr, end) (end)
include/asm-generic/pgtable-nopmd.h+1−1
@@ -60,7 +60,7 @@ static inline pmd_t * pmd_offset(pud_t * pud, unsigned long address) · 59 unmodified lines
60static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)60static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
61{61{
62}62}
63#define __pmd_free_tlb(tlb, x, a) do { } while (0)63#define pmd_free_tlb(tlb, x, a) do { } while (0)
64 64
65#undef pmd_addr_end65#undef pmd_addr_end
66#define pmd_addr_end(addr, end) (end)66#define pmd_addr_end(addr, end) (end)
include/asm-generic/pgtable-nopud.h+1−1
@@ -59,7 +59,7 @@ static inline pud_t *pud_offset(p4d_t *p4d, unsigned long address) · 58 unmodified lines
59 */59 */
60#define pud_alloc_one(mm, address) NULL60#define pud_alloc_one(mm, address) NULL
61#define pud_free(mm, x) do { } while (0)61#define pud_free(mm, x) do { } while (0)
62#define __pud_free_tlb(tlb, x, a) do { } while (0)62#define pud_free_tlb(tlb, x, a) do { } while (0)
63 63
64#undef pud_addr_end64#undef pud_addr_end
65#define pud_addr_end(addr, end) (end)65#define pud_addr_end(addr, end) (end)
include/asm-generic/pgtable.h+51−0
@@ -558,8 +558,19 @@ static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot) · 557 unmodified lines
558 * Do the tests inline, but report and clear the bad entry in mm/memory.c.558 * Do the tests inline, but report and clear the bad entry in mm/memory.c.
559 */559 */
560void pgd_clear_bad(pgd_t *);560void pgd_clear_bad(pgd_t *);
561
562#ifndef __PAGETABLE_P4D_FOLDED
561void p4d_clear_bad(p4d_t *);563void p4d_clear_bad(p4d_t *);
564#else
565#define p4d_clear_bad(p4d) do { } while (0)
566#endif
567
568#ifndef __PAGETABLE_PUD_FOLDED
562void pud_clear_bad(pud_t *);569void pud_clear_bad(pud_t *);
570#else
571#define pud_clear_bad(p4d) do { } while (0)
572#endif
573
563void pmd_clear_bad(pmd_t *);574void pmd_clear_bad(pmd_t *);
564 575
565static inline int pgd_none_or_clear_bad(pgd_t *pgd)576static inline int pgd_none_or_clear_bad(pgd_t *pgd)
@@ -903,6 +914,21 @@ static inline int pud_write(pud_t pud) · 337 unmodified lines
903}914}
904#endif /* pud_write */915#endif /* pud_write */
905 916
917#if !defined(CONFIG_ARCH_HAS_PTE_DEVMAP) || !defined(CONFIG_TRANSPARENT_HUGEPAGE)
918static inline int pmd_devmap(pmd_t pmd)
919{
920 return 0;
921}
922static inline int pud_devmap(pud_t pud)
923{
924 return 0;
925}
926static inline int pgd_devmap(pgd_t pgd)
927{
928 return 0;
929}
930#endif
931
906#if !defined(CONFIG_TRANSPARENT_HUGEPAGE) || \932#if !defined(CONFIG_TRANSPARENT_HUGEPAGE) || \
907 (defined(CONFIG_TRANSPARENT_HUGEPAGE) && \933 (defined(CONFIG_TRANSPARENT_HUGEPAGE) && \
908 !defined(CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD))934 !defined(CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD))
@@ -912,6 +938,31 @@ static inline int pud_trans_huge(pud_t pud) · 3 unmodified lines
912}938}
913#endif939#endif
914 940
941/* See pmd_none_or_trans_huge_or_clear_bad for discussion. */
942static inline int pud_none_or_trans_huge_or_dev_or_clear_bad(pud_t *pud)
943{
944 pud_t pudval = READ_ONCE(*pud);
945
946 if (pud_none(pudval) || pud_trans_huge(pudval) || pud_devmap(pudval))
947 return 1;
948 if (unlikely(pud_bad(pudval))) {
949 pud_clear_bad(pud);
950 return 1;
951 }
952 return 0;
953}
954
955/* See pmd_trans_unstable for discussion. */
956static inline int pud_trans_unstable(pud_t *pud)
957{
958#if defined(CONFIG_TRANSPARENT_HUGEPAGE) && \
959 defined(CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD)
960 return pud_none_or_trans_huge_or_dev_or_clear_bad(pud);
961#else
962 return 0;
963#endif
964}
965
915#ifndef pmd_read_atomic966#ifndef pmd_read_atomic
916static inline pmd_t pmd_read_atomic(pmd_t *pmdp)967static inline pmd_t pmd_read_atomic(pmd_t *pmdp)
917{968{
include/asm-generic/tlb.h+0−4
@@ -584,7 +584,6 @@ static inline void tlb_end_vma(struct mmu_gather *tlb, struct vm_area_struct *vm · 583 unmodified lines
584 } while (0)584 } while (0)
585#endif585#endif
586 586
587#ifndef __ARCH_HAS_4LEVEL_HACK
588#ifndef pud_free_tlb587#ifndef pud_free_tlb
589#define pud_free_tlb(tlb, pudp, address) \588#define pud_free_tlb(tlb, pudp, address) \
590 do { \589 do { \
@@ -594,9 +593,7 @@ static inline void tlb_end_vma(struct mmu_gather *tlb, struct vm_area_struct *vm · 3 unmodified lines
594 __pud_free_tlb(tlb, pudp, address); \593 __pud_free_tlb(tlb, pudp, address); \
595 } while (0)594 } while (0)
596#endif595#endif
597#endif
598 596
599#ifndef __ARCH_HAS_5LEVEL_HACK
600#ifndef p4d_free_tlb597#ifndef p4d_free_tlb
601#define p4d_free_tlb(tlb, pudp, address) \598#define p4d_free_tlb(tlb, pudp, address) \
602 do { \599 do { \
@@ -605,7 +602,6 @@ static inline void tlb_end_vma(struct mmu_gather *tlb, struct vm_area_struct *vm · 2 unmodified lines
605 __p4d_free_tlb(tlb, pudp, address); \602 __p4d_free_tlb(tlb, pudp, address); \
606 } while (0)603 } while (0)
607#endif604#endif
608#endif
609 605
610#endif /* CONFIG_MMU */606#endif /* CONFIG_MMU */
611 607
include/linux/fs.h+5−1
@@ -3156,7 +3156,6 @@ enum { · 3155 unmodified lines
3156};3156};
3157 3157
3158void dio_end_io(struct bio *bio);3158void dio_end_io(struct bio *bio);
3159void dio_warn_stale_pagecache(struct file *filp);
3160 3159
3161ssize_t __blockdev_direct_IO(struct kiocb *iocb, struct inode *inode,3160ssize_t __blockdev_direct_IO(struct kiocb *iocb, struct inode *inode,
3162 struct block_device *bdev, struct iov_iter *iter,3161 struct block_device *bdev, struct iov_iter *iter,
@@ -3201,6 +3200,11 @@ static inline void inode_dio_end(struct inode *inode) · 38 unmodified lines
3201 wake_up_bit(&inode->i_state, __I_DIO_WAKEUP);3200 wake_up_bit(&inode->i_state, __I_DIO_WAKEUP);
3202}3201}
3203 3202
3203/*
3204 * Warn about a page cache invalidation failure diring a direct I/O write.
3205 */
3206void dio_warn_stale_pagecache(struct file *filp);
3207
3204extern void inode_set_flags(struct inode *inode, unsigned int flags,3208extern void inode_set_flags(struct inode *inode, unsigned int flags,
3205 unsigned int mask);3209 unsigned int mask);
3206 3210
include/linux/gfp.h+2−0
@@ -612,6 +612,8 @@ static inline bool pm_suspended_storage(void) · 611 unmodified lines
612/* The below functions must be run on a range from a single zone. */612/* The below functions must be run on a range from a single zone. */
613extern int alloc_contig_range(unsigned long start, unsigned long end,613extern int alloc_contig_range(unsigned long start, unsigned long end,
614 unsigned migratetype, gfp_t gfp_mask);614 unsigned migratetype, gfp_t gfp_mask);
615extern struct page *alloc_contig_pages(unsigned long nr_pages, gfp_t gfp_mask,
616 int nid, nodemask_t *nodemask);
615#endif617#endif
616void free_contig_range(unsigned long pfn, unsigned int nr_pages);618void free_contig_range(unsigned long pfn, unsigned int nr_pages);
617 619
include/linux/hugetlb.h+116−24
@@ -105,8 +105,7 @@ void move_hugetlb_state(struct page *oldpage, struct page *newpage, int reason); · 104 unmodified lines
105void free_huge_page(struct page *page);105void free_huge_page(struct page *page);
106void hugetlb_fix_reserve_counts(struct inode *inode);106void hugetlb_fix_reserve_counts(struct inode *inode);
107extern struct mutex *hugetlb_fault_mutex_table;107extern struct mutex *hugetlb_fault_mutex_table;
108u32 hugetlb_fault_mutex_hash(struct hstate *h, struct address_space *mapping,108u32 hugetlb_fault_mutex_hash(struct address_space *mapping, pgoff_t idx);
109 pgoff_t idx, unsigned long address);
110 109
111pte_t *huge_pmd_share(struct mm_struct *mm, unsigned long addr, pud_t *pud);110pte_t *huge_pmd_share(struct mm_struct *mm, unsigned long addr, pud_t *pud);
112 111
@@ -164,38 +163,130 @@ static inline void adjust_range_if_pmd_sharing_possible( · 51 unmodified lines
164{163{
165}164}
166 165
167#define follow_hugetlb_page(m,v,p,vs,a,b,i,w,n) ({ BUG(); 0; })166static inline long follow_hugetlb_page(struct mm_struct *mm,
168#define follow_huge_addr(mm, addr, write) ERR_PTR(-EINVAL)167 struct vm_area_struct *vma, struct page **pages,
169#define copy_hugetlb_page_range(src, dst, vma) ({ BUG(); 0; })168 struct vm_area_struct **vmas, unsigned long *position,
169 unsigned long *nr_pages, long i, unsigned int flags,
170 int *nonblocking)
171{
172 BUG();
173 return 0;
174}
175
176static inline struct page *follow_huge_addr(struct mm_struct *mm,
177 unsigned long address, int write)
178{
179 return ERR_PTR(-EINVAL);
180}
181
182static inline int copy_hugetlb_page_range(struct mm_struct *dst,
183 struct mm_struct *src, struct vm_area_struct *vma)
184{
185 BUG();
186 return 0;
187}
188
170static inline void hugetlb_report_meminfo(struct seq_file *m)189static inline void hugetlb_report_meminfo(struct seq_file *m)
171{190{
172}191}
173#define hugetlb_report_node_meminfo(n, buf) 0192
193static inline int hugetlb_report_node_meminfo(int nid, char *buf)
194{
195 return 0;
196}
197
174static inline void hugetlb_show_meminfo(void)198static inline void hugetlb_show_meminfo(void)
175{199{
176}200}
177#define follow_huge_pd(vma, addr, hpd, flags, pdshift) NULL201
178#define follow_huge_pmd(mm, addr, pmd, flags) NULL202static inline struct page *follow_huge_pd(struct vm_area_struct *vma,
179#define follow_huge_pud(mm, addr, pud, flags) NULL203 unsigned long address, hugepd_t hpd, int flags,
180#define follow_huge_pgd(mm, addr, pgd, flags) NULL204 int pdshift)
181#define prepare_hugepage_range(file, addr, len) (-EINVAL)205{
182#define pmd_huge(x) 0206 return NULL;
183#define pud_huge(x) 0207}
184#define is_hugepage_only_range(mm, addr, len) 0208
185#define hugetlb_free_pgd_range(tlb, addr, end, floor, ceiling) ({BUG(); 0; })209static inline struct page *follow_huge_pmd(struct mm_struct *mm,
186#define hugetlb_mcopy_atomic_pte(dst_mm, dst_pte, dst_vma, dst_addr, \210 unsigned long address, pmd_t *pmd, int flags)
187 src_addr, pagep) ({ BUG(); 0; })211{
188#define huge_pte_offset(mm, address, sz) 0212 return NULL;
213}
214
215static inline struct page *follow_huge_pud(struct mm_struct *mm,
216 unsigned long address, pud_t *pud, int flags)
217{
218 return NULL;
219}
220
221static inline struct page *follow_huge_pgd(struct mm_struct *mm,
222 unsigned long address, pgd_t *pgd, int flags)
223{
224 return NULL;
225}
226
227static inline int prepare_hugepage_range(struct file *file,
228 unsigned long addr, unsigned long len)
229{
230 return -EINVAL;
231}
232
233static inline int pmd_huge(pmd_t pmd)
234{
235 return 0;
236}
237
238static inline int pud_huge(pud_t pud)
239{
240 return 0;
241}
242
243static inline int is_hugepage_only_range(struct mm_struct *mm,
244 unsigned long addr, unsigned long len)
245{
246 return 0;
247}
248
249static inline void hugetlb_free_pgd_range(struct mmu_gather *tlb,
250 unsigned long addr, unsigned long end,
251 unsigned long floor, unsigned long ceiling)
252{
253 BUG();
254}
255
256static inline int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm,
257 pte_t *dst_pte,
258 struct vm_area_struct *dst_vma,
259 unsigned long dst_addr,
260 unsigned long src_addr,
261 struct page **pagep)
262{
263 BUG();
264 return 0;
265}
266
267static inline pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr,
268 unsigned long sz)
269{
270 return NULL;
271}
189 272
190static inline bool isolate_huge_page(struct page *page, struct list_head *list)273static inline bool isolate_huge_page(struct page *page, struct list_head *list)
191{274{
192 return false;275 return false;
193}276}
194#define putback_active_hugepage(p) do {} while (0)
195#define move_hugetlb_state(old, new, reason) do {} while (0)
196 277
197static inline unsigned long hugetlb_change_protection(struct vm_area_struct *vma,278static inline void putback_active_hugepage(struct page *page)
198 unsigned long address, unsigned long end, pgprot_t newprot)279{
280}
281
282static inline void move_hugetlb_state(struct page *oldpage,
283 struct page *newpage, int reason)
284{
285}
286
287static inline unsigned long hugetlb_change_protection(
288 struct vm_area_struct *vma, unsigned long address,
289 unsigned long end, pgprot_t newprot)
199{290{
200 return 0;291 return 0;
201}292}
@@ -213,9 +304,10 @@ static inline void __unmap_hugepage_range(struct mmu_gather *tlb, · 11 unmodified lines
213{304{
214 BUG();305 BUG();
215}306}
307
216static inline vm_fault_t hugetlb_fault(struct mm_struct *mm,308static inline vm_fault_t hugetlb_fault(struct mm_struct *mm,
217 struct vm_area_struct *vma, unsigned long address,309 struct vm_area_struct *vma, unsigned long address,
218 unsigned int flags)310 unsigned int flags)
219{311{
220 BUG();312 BUG();
221 return 0;313 return 0;
include/linux/kasan.h+31−0
@@ -70,8 +70,18 @@ struct kasan_cache { · 69 unmodified lines
70 int free_meta_offset;70 int free_meta_offset;
71};71};
72 72
73/*
74 * These functions provide a special case to support backing module
75 * allocations with real shadow memory. With KASAN vmalloc, the special
76 * case is unnecessary, as the work is handled in the generic case.
77 */
78#ifndef CONFIG_KASAN_VMALLOC
73int kasan_module_alloc(void *addr, size_t size);79int kasan_module_alloc(void *addr, size_t size);
74void kasan_free_shadow(const struct vm_struct *vm);80void kasan_free_shadow(const struct vm_struct *vm);
81#else
82static inline int kasan_module_alloc(void *addr, size_t size) { return 0; }
83static inline void kasan_free_shadow(const struct vm_struct *vm) {}
84#endif
75 85
76int kasan_add_zero_shadow(void *start, unsigned long size);86int kasan_add_zero_shadow(void *start, unsigned long size);
77void kasan_remove_zero_shadow(void *start, unsigned long size);87void kasan_remove_zero_shadow(void *start, unsigned long size);
@@ -194,4 +204,25 @@ static inline void *kasan_reset_tag(const void *addr) · 116 unmodified lines
194 204
195#endif /* CONFIG_KASAN_SW_TAGS */205#endif /* CONFIG_KASAN_SW_TAGS */
196 206
207#ifdef CONFIG_KASAN_VMALLOC
208int kasan_populate_vmalloc(unsigned long requested_size,
209 struct vm_struct *area);
210void kasan_poison_vmalloc(void *start, unsigned long size);
211void kasan_release_vmalloc(unsigned long start, unsigned long end,
212 unsigned long free_region_start,
213 unsigned long free_region_end);
214#else
215static inline int kasan_populate_vmalloc(unsigned long requested_size,
216 struct vm_struct *area)
217{
218 return 0;
219}
220
221static inline void kasan_poison_vmalloc(void *start, unsigned long size) {}
222static inline void kasan_release_vmalloc(unsigned long start,
223 unsigned long end,
224 unsigned long free_region_start,
225 unsigned long free_region_end) {}
226#endif
227
197#endif /* LINUX_KASAN_H */228#endif /* LINUX_KASAN_H */
include/linux/memblock.h+3−0
@@ -358,6 +358,9 @@ static inline phys_addr_t memblock_phys_alloc(phys_addr_t size, · 357 unmodified lines
358 MEMBLOCK_ALLOC_ACCESSIBLE);358 MEMBLOCK_ALLOC_ACCESSIBLE);
359}359}
360 360
361void *memblock_alloc_exact_nid_raw(phys_addr_t size, phys_addr_t align,
362 phys_addr_t min_addr, phys_addr_t max_addr,
363 int nid);
361void *memblock_alloc_try_nid_raw(phys_addr_t size, phys_addr_t align,364void *memblock_alloc_try_nid_raw(phys_addr_t size, phys_addr_t align,
362 phys_addr_t min_addr, phys_addr_t max_addr,365 phys_addr_t min_addr, phys_addr_t max_addr,
363 int nid);366 int nid);
include/linux/memcontrol.h+22−27
@@ -58,7 +58,6 @@ enum mem_cgroup_protection { · 57 unmodified lines
58 58
59struct mem_cgroup_reclaim_cookie {59struct mem_cgroup_reclaim_cookie {
60 pg_data_t *pgdat;60 pg_data_t *pgdat;
61 int priority;
62 unsigned int generation;61 unsigned int generation;
63};62};
64 63
@@ -81,7 +80,6 @@ struct mem_cgroup_id { · 16 unmodified lines
81enum mem_cgroup_events_target {80enum mem_cgroup_events_target {
82 MEM_CGROUP_TARGET_THRESH,81 MEM_CGROUP_TARGET_THRESH,
83 MEM_CGROUP_TARGET_SOFTLIMIT,82 MEM_CGROUP_TARGET_SOFTLIMIT,
84 MEM_CGROUP_TARGET_NUMAINFO,
85 MEM_CGROUP_NTARGETS,83 MEM_CGROUP_NTARGETS,
86};84};
87 85
@@ -112,7 +110,7 @@ struct memcg_shrinker_map { · 24 unmodified lines
112};110};
113 111
114/*112/*
115 * per-zone information in memory controller.113 * per-node information in memory controller.
116 */114 */
117struct mem_cgroup_per_node {115struct mem_cgroup_per_node {
118 struct lruvec lruvec;116 struct lruvec lruvec;
@@ -126,7 +124,7 @@ struct mem_cgroup_per_node { · 7 unmodified lines
126 124
127 unsigned long lru_zone_size[MAX_NR_ZONES][NR_LRU_LISTS];125 unsigned long lru_zone_size[MAX_NR_ZONES][NR_LRU_LISTS];
128 126
129 struct mem_cgroup_reclaim_iter iter[DEF_PRIORITY + 1];127 struct mem_cgroup_reclaim_iter iter;
130 128
131 struct memcg_shrinker_map __rcu *shrinker_map;129 struct memcg_shrinker_map __rcu *shrinker_map;
132 130
@@ -134,9 +132,6 @@ struct mem_cgroup_per_node { · 1 unmodified line
134 unsigned long usage_in_excess;/* Set to the value by which */132 unsigned long usage_in_excess;/* Set to the value by which */
135 /* the soft limit is exceeded*/133 /* the soft limit is exceeded*/
136 bool on_tree;134 bool on_tree;
137 bool congested; /* memcg has many dirty pages */
138 /* backed by a congested BDI */
139
140 struct mem_cgroup *memcg; /* Back pointer, we cannot */135 struct mem_cgroup *memcg; /* Back pointer, we cannot */
141 /* use container_of */136 /* use container_of */
142};137};
@@ -313,13 +308,6 @@ struct mem_cgroup { · 170 unmodified lines
313 struct list_head kmem_caches;308 struct list_head kmem_caches;
314#endif309#endif
315 310
316 int last_scanned_node;
317#if MAX_NUMNODES > 1
318 nodemask_t scan_nodes;
319 atomic_t numainfo_events;
320 atomic_t numainfo_updating;
321#endif
322
323#ifdef CONFIG_CGROUP_WRITEBACK311#ifdef CONFIG_CGROUP_WRITEBACK
324 struct list_head cgwb_list;312 struct list_head cgwb_list;
325 struct wb_domain cgwb_domain;313 struct wb_domain cgwb_domain;
@@ -394,25 +382,27 @@ mem_cgroup_nodeinfo(struct mem_cgroup *memcg, int nid) · 68 unmodified lines
394}382}
395 383
396/**384/**
397 * mem_cgroup_lruvec - get the lru list vector for a node or a memcg zone385 * mem_cgroup_lruvec - get the lru list vector for a memcg & node
398 * @node: node of the wanted lruvec
399 * @memcg: memcg of the wanted lruvec386 * @memcg: memcg of the wanted lruvec
400 *387 *
401 * Returns the lru list vector holding pages for a given @node or a given388 * Returns the lru list vector holding pages for a given @memcg &
402 * @memcg and @zone. This can be the node lruvec, if the memory controller389 * @node combination. This can be the node lruvec, if the memory
403 * is disabled.390 * controller is disabled.
404 */391 */
405static inline struct lruvec *mem_cgroup_lruvec(struct pglist_data *pgdat,392static inline struct lruvec *mem_cgroup_lruvec(struct mem_cgroup *memcg,
406 struct mem_cgroup *memcg)393 struct pglist_data *pgdat)
407{394{
408 struct mem_cgroup_per_node *mz;395 struct mem_cgroup_per_node *mz;
409 struct lruvec *lruvec;396 struct lruvec *lruvec;
410 397
411 if (mem_cgroup_disabled()) {398 if (mem_cgroup_disabled()) {
412 lruvec = node_lruvec(pgdat);399 lruvec = &pgdat->__lruvec;
413 goto out;400 goto out;
414 }401 }
415 402
403 if (!memcg)
404 memcg = root_mem_cgroup;
405
416 mz = mem_cgroup_nodeinfo(memcg, pgdat->node_id);406 mz = mem_cgroup_nodeinfo(memcg, pgdat->node_id);
417 lruvec = &mz->lruvec;407 lruvec = &mz->lruvec;
418out:408out:
@@ -728,7 +718,7 @@ static inline void __mod_lruvec_page_state(struct page *page, · 309 unmodified lines
728 return;718 return;
729 }719 }
730 720
731 lruvec = mem_cgroup_lruvec(pgdat, page->mem_cgroup);721 lruvec = mem_cgroup_lruvec(page->mem_cgroup, pgdat);
732 __mod_lruvec_state(lruvec, idx, val);722 __mod_lruvec_state(lruvec, idx, val);
733}723}
734 724
@@ -899,16 +889,21 @@ static inline void mem_cgroup_migrate(struct page *old, struct page *new) · 164 unmodified lines
899{889{
900}890}
901 891
902static inline struct lruvec *mem_cgroup_lruvec(struct pglist_data *pgdat,892static inline struct lruvec *mem_cgroup_lruvec(struct mem_cgroup *memcg,
903 struct mem_cgroup *memcg)893 struct pglist_data *pgdat)
904{894{
905 return node_lruvec(pgdat);895 return &pgdat->__lruvec;
906}896}
907 897
908static inline struct lruvec *mem_cgroup_page_lruvec(struct page *page,898static inline struct lruvec *mem_cgroup_page_lruvec(struct page *page,
909 struct pglist_data *pgdat)899 struct pglist_data *pgdat)
910{900{
911 return &pgdat->lruvec;901 return &pgdat->__lruvec;
902}
903
904static inline struct mem_cgroup *parent_mem_cgroup(struct mem_cgroup *memcg)
905{
906 return NULL;
912}907}
913 908
914static inline bool mm_match_cgroup(struct mm_struct *mm,909static inline bool mm_match_cgroup(struct mm_struct *mm,
include/linux/memory_hotplug.h+4−7
@@ -102,13 +102,10 @@ extern unsigned long __offline_isolated_pages(unsigned long start_pfn, · 101 unmodified lines
102 102
103typedef void (*online_page_callback_t)(struct page *page, unsigned int order);103typedef void (*online_page_callback_t)(struct page *page, unsigned int order);
104 104
105extern void generic_online_page(struct page *page, unsigned int order);
105extern int set_online_page_callback(online_page_callback_t callback);106extern int set_online_page_callback(online_page_callback_t callback);
106extern int restore_online_page_callback(online_page_callback_t callback);107extern int restore_online_page_callback(online_page_callback_t callback);
107 108
108extern void __online_page_set_limits(struct page *page);
109extern void __online_page_increment_counters(struct page *page);
110extern void __online_page_free(struct page *page);
111
112extern int try_online_node(int nid);109extern int try_online_node(int nid);
113 110
114extern int arch_add_memory(int nid, u64 start, u64 size,111extern int arch_add_memory(int nid, u64 start, u64 size,
@@ -229,9 +226,6 @@ void put_online_mems(void); · 114 unmodified lines
229void mem_hotplug_begin(void);226void mem_hotplug_begin(void);
230void mem_hotplug_done(void);227void mem_hotplug_done(void);
231 228
232extern void set_zone_contiguous(struct zone *zone);
233extern void clear_zone_contiguous(struct zone *zone);
234
235#else /* ! CONFIG_MEMORY_HOTPLUG */229#else /* ! CONFIG_MEMORY_HOTPLUG */
236#define pfn_to_online_page(pfn) \230#define pfn_to_online_page(pfn) \
237({ \231({ \
@@ -339,6 +333,9 @@ static inline int remove_memory(int nid, u64 start, u64 size) · 101 unmodified lines
339static inline void __remove_memory(int nid, u64 start, u64 size) {}333static inline void __remove_memory(int nid, u64 start, u64 size) {}
340#endif /* CONFIG_MEMORY_HOTREMOVE */334#endif /* CONFIG_MEMORY_HOTREMOVE */
341 335
336extern void set_zone_contiguous(struct zone *zone);
337extern void clear_zone_contiguous(struct zone *zone);
338
342extern void __ref free_area_init_core_hotplug(int nid);339extern void __ref free_area_init_core_hotplug(int nid);
343extern int __add_memory(int nid, u64 start, u64 size);340extern int __add_memory(int nid, u64 start, u64 size);
344extern int add_memory(int nid, u64 start, u64 size);341extern int add_memory(int nid, u64 start, u64 size);
include/linux/mm.h+12−22
@@ -564,21 +564,6 @@ int vma_is_stack_for_current(struct vm_area_struct *vma); · 563 unmodified lines
564struct mmu_gather;564struct mmu_gather;
565struct inode;565struct inode;
566 566
567#if !defined(CONFIG_ARCH_HAS_PTE_DEVMAP) || !defined(CONFIG_TRANSPARENT_HUGEPAGE)
568static inline int pmd_devmap(pmd_t pmd)
569{
570 return 0;
571}
572static inline int pud_devmap(pud_t pud)
573{
574 return 0;
575}
576static inline int pgd_devmap(pgd_t pgd)
577{
578 return 0;
579}
580#endif
581
582/*567/*
583 * FIXME: take this include out, include page-flags.h in568 * FIXME: take this include out, include page-flags.h in
584 * files which need it (119 of them)569 * files which need it (119 of them)
@@ -1643,19 +1628,27 @@ static inline unsigned long get_mm_counter(struct mm_struct *mm, int member) · 1058 unmodified lines
1643 return (unsigned long)val;1628 return (unsigned long)val;
1644}1629}
1645 1630
1631void mm_trace_rss_stat(struct mm_struct *mm, int member, long count);
1632
1646static inline void add_mm_counter(struct mm_struct *mm, int member, long value)1633static inline void add_mm_counter(struct mm_struct *mm, int member, long value)
1647{1634{
1648 atomic_long_add(value, &mm->rss_stat.count[member]);1635 long count = atomic_long_add_return(value, &mm->rss_stat.count[member]);
1636
1637 mm_trace_rss_stat(mm, member, count);
1649}1638}
1650 1639
1651static inline void inc_mm_counter(struct mm_struct *mm, int member)1640static inline void inc_mm_counter(struct mm_struct *mm, int member)
1652{1641{
1653 atomic_long_inc(&mm->rss_stat.count[member]);1642 long count = atomic_long_inc_return(&mm->rss_stat.count[member]);
1643
1644 mm_trace_rss_stat(mm, member, count);
1654}1645}
1655 1646
1656static inline void dec_mm_counter(struct mm_struct *mm, int member)1647static inline void dec_mm_counter(struct mm_struct *mm, int member)
1657{1648{
1658 atomic_long_dec(&mm->rss_stat.count[member]);1649 long count = atomic_long_dec_return(&mm->rss_stat.count[member]);
1650
1651 mm_trace_rss_stat(mm, member, count);
1659}1652}
1660 1653
1661/* Optimized variant when page is already known not to be PageAnon */1654/* Optimized variant when page is already known not to be PageAnon */
@@ -2214,9 +2207,6 @@ void warn_alloc(gfp_t gfp_mask, nodemask_t *nodemask, const char *fmt, ...); · 552 unmodified lines
2214 2207
2215extern void setup_per_cpu_pageset(void);2208extern void setup_per_cpu_pageset(void);
2216 2209
2217extern void zone_pcp_update(struct zone *zone);
2218extern void zone_pcp_reset(struct zone *zone);
2219
2220/* page_alloc.c */2210/* page_alloc.c */
2221extern int min_free_kbytes;2211extern int min_free_kbytes;
2222extern int watermark_boost_factor;2212extern int watermark_boost_factor;
@@ -2780,7 +2770,7 @@ extern int sysctl_memory_failure_early_kill; · 557 unmodified lines
2780extern int sysctl_memory_failure_recovery;2770extern int sysctl_memory_failure_recovery;
2781extern void shake_page(struct page *p, int access);2771extern void shake_page(struct page *p, int access);
2782extern atomic_long_t num_poisoned_pages __read_mostly;2772extern atomic_long_t num_poisoned_pages __read_mostly;
2783extern int soft_offline_page(struct page *page, int flags);2773extern int soft_offline_page(unsigned long pfn, int flags);
2784 2774
2785 2775
2786/*2776/*
include/linux/mmzone.h+20−14
@@ -273,12 +273,12 @@ enum lru_list { · 272 unmodified lines
273 273
274#define for_each_evictable_lru(lru) for (lru = 0; lru <= LRU_ACTIVE_FILE; lru++)274#define for_each_evictable_lru(lru) for (lru = 0; lru <= LRU_ACTIVE_FILE; lru++)
275 275
276static inline int is_file_lru(enum lru_list lru)276static inline bool is_file_lru(enum lru_list lru)
277{277{
278 return (lru == LRU_INACTIVE_FILE || lru == LRU_ACTIVE_FILE);278 return (lru == LRU_INACTIVE_FILE || lru == LRU_ACTIVE_FILE);
279}279}
280 280
281static inline int is_active_lru(enum lru_list lru)281static inline bool is_active_lru(enum lru_list lru)
282{282{
283 return (lru == LRU_ACTIVE_ANON || lru == LRU_ACTIVE_FILE);283 return (lru == LRU_ACTIVE_ANON || lru == LRU_ACTIVE_FILE);
284}284}
@@ -296,6 +296,12 @@ struct zone_reclaim_stat { · 11 unmodified lines
296 unsigned long recent_scanned[2];296 unsigned long recent_scanned[2];
297};297};
298 298
299enum lruvec_flags {
300 LRUVEC_CONGESTED, /* lruvec has many dirty pages
301 * backed by a congested BDI
302 */
303};
304
299struct lruvec {305struct lruvec {
300 struct list_head lists[NR_LRU_LISTS];306 struct list_head lists[NR_LRU_LISTS];
301 struct zone_reclaim_stat reclaim_stat;307 struct zone_reclaim_stat reclaim_stat;
@@ -303,12 +309,14 @@ struct lruvec { · 1 unmodified line
303 atomic_long_t inactive_age;309 atomic_long_t inactive_age;
304 /* Refaults at the time of last reclaim cycle */310 /* Refaults at the time of last reclaim cycle */
305 unsigned long refaults;311 unsigned long refaults;
312 /* Various lruvec state flags (enum lruvec_flags) */
313 unsigned long flags;
306#ifdef CONFIG_MEMCG314#ifdef CONFIG_MEMCG
307 struct pglist_data *pgdat;315 struct pglist_data *pgdat;
308#endif316#endif
309};317};
310 318
311/* Isolate unmapped file */319/* Isolate unmapped pages */
312#define ISOLATE_UNMAPPED ((__force isolate_mode_t)0x2)320#define ISOLATE_UNMAPPED ((__force isolate_mode_t)0x2)
313/* Isolate for asynchronous migration */321/* Isolate for asynchronous migration */
314#define ISOLATE_ASYNC_MIGRATE ((__force isolate_mode_t)0x4)322#define ISOLATE_ASYNC_MIGRATE ((__force isolate_mode_t)0x4)
@@ -572,9 +580,6 @@ struct zone { · 257 unmodified lines
572} ____cacheline_internodealigned_in_smp;580} ____cacheline_internodealigned_in_smp;
573 581
574enum pgdat_flags {582enum pgdat_flags {
575 PGDAT_CONGESTED, /* pgdat has many dirty pages backed by
576 * a congested BDI
577 */
578 PGDAT_DIRTY, /* reclaim scanning has recently found583 PGDAT_DIRTY, /* reclaim scanning has recently found
579 * many dirty file pages at the tail584 * many dirty file pages at the tail
580 * of the LRU.585 * of the LRU.
@@ -777,7 +782,13 @@ typedef struct pglist_data { · 196 unmodified lines
777#endif782#endif
778 783
779 /* Fields commonly accessed by the page reclaim scanner */784 /* Fields commonly accessed by the page reclaim scanner */
780 struct lruvec lruvec;785
786 /*
787 * NOTE: THIS IS UNUSED IF MEMCG IS ENABLED.
788 *
789 * Use mem_cgroup_lruvec() to look up lruvecs.
790 */
791 struct lruvec __lruvec;
781 792
782 unsigned long flags;793 unsigned long flags;
783 794
@@ -800,11 +811,6 @@ typedef struct pglist_data { · 16 unmodified lines
800#define node_start_pfn(nid) (NODE_DATA(nid)->node_start_pfn)811#define node_start_pfn(nid) (NODE_DATA(nid)->node_start_pfn)
801#define node_end_pfn(nid) pgdat_end_pfn(NODE_DATA(nid))812#define node_end_pfn(nid) pgdat_end_pfn(NODE_DATA(nid))
802 813
803static inline struct lruvec *node_lruvec(struct pglist_data *pgdat)
804{
805 return &pgdat->lruvec;
806}
807
808static inline unsigned long pgdat_end_pfn(pg_data_t *pgdat)814static inline unsigned long pgdat_end_pfn(pg_data_t *pgdat)
809{815{
810 return pgdat->node_start_pfn + pgdat->node_spanned_pages;816 return pgdat->node_start_pfn + pgdat->node_spanned_pages;
@@ -842,7 +848,7 @@ static inline struct pglist_data *lruvec_pgdat(struct lruvec *lruvec) · 31 unmodified lines
842#ifdef CONFIG_MEMCG848#ifdef CONFIG_MEMCG
843 return lruvec->pgdat;849 return lruvec->pgdat;
844#else850#else
845 return container_of(lruvec, struct pglist_data, lruvec);851 return container_of(lruvec, struct pglist_data, __lruvec);
846#endif852#endif
847}853}
848 854
@@ -1079,7 +1085,7 @@ static inline struct zoneref *first_zones_zonelist(struct zonelist *zonelist, · 230 unmodified lines
1079/**1085/**
1080 * for_each_zone_zonelist_nodemask - helper macro to iterate over valid zones in a zonelist at or below a given zone index and within a nodemask1086 * for_each_zone_zonelist_nodemask - helper macro to iterate over valid zones in a zonelist at or below a given zone index and within a nodemask
1081 * @zone - The current zone in the iterator1087 * @zone - The current zone in the iterator
1082 * @z - The current pointer within zonelist->zones being iterated1088 * @z - The current pointer within zonelist->_zonerefs being iterated
1083 * @zlist - The zonelist being iterated1089 * @zlist - The zonelist being iterated
1084 * @highidx - The zone index of the highest zone to return1090 * @highidx - The zone index of the highest zone to return
1085 * @nodemask - Nodemask allowed by the allocator1091 * @nodemask - Nodemask allowed by the allocator
include/linux/moduleloader.h+1−1
@@ -91,7 +91,7 @@ void module_arch_cleanup(struct module *mod); · 90 unmodified lines
91/* Any cleanup before freeing mod->module_init */91/* Any cleanup before freeing mod->module_init */
92void module_arch_freeing_init(struct module *mod);92void module_arch_freeing_init(struct module *mod);
93 93
94#ifdef CONFIG_KASAN94#if defined(CONFIG_KASAN) && !defined(CONFIG_KASAN_VMALLOC)
95#include <linux/kasan.h>95#include <linux/kasan.h>
96#define MODULE_ALIGN (PAGE_SIZE << KASAN_SHADOW_SCALE_SHIFT)96#define MODULE_ALIGN (PAGE_SIZE << KASAN_SHADOW_SCALE_SHIFT)
97#else97#else
include/linux/page-isolation.h+2−2
@@ -30,7 +30,7 @@ static inline bool is_migrate_isolate(int migratetype) · 29 unmodified lines
30}30}
31#endif31#endif
32 32
33#define SKIP_HWPOISON 0x133#define MEMORY_OFFLINE 0x1
34#define REPORT_FAILURE 0x234#define REPORT_FAILURE 0x2
35 35
36bool has_unmovable_pages(struct zone *zone, struct page *page, int count,36bool has_unmovable_pages(struct zone *zone, struct page *page, int count,
@@ -58,7 +58,7 @@ undo_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn, · 21 unmodified lines
58 * Test all pages in [start_pfn, end_pfn) are isolated or not.58 * Test all pages in [start_pfn, end_pfn) are isolated or not.
59 */59 */
60int test_pages_isolated(unsigned long start_pfn, unsigned long end_pfn,60int test_pages_isolated(unsigned long start_pfn, unsigned long end_pfn,
61 bool skip_hwpoisoned_pages);61 int isol_flags);
62 62
63struct page *alloc_migrate_target(struct page *page, unsigned long private);63struct page *alloc_migrate_target(struct page *page, unsigned long private);
64 64
include/linux/slab.h+0−20
@@ -561,26 +561,6 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags) · 560 unmodified lines
561 return __kmalloc(size, flags);561 return __kmalloc(size, flags);
562}562}
563 563
564/*
565 * Determine size used for the nth kmalloc cache.
566 * return size or 0 if a kmalloc cache for that
567 * size does not exist
568 */
569static __always_inline unsigned int kmalloc_size(unsigned int n)
570{
571#ifndef CONFIG_SLOB
572 if (n > 2)
573 return 1U << n;
574
575 if (n == 1 && KMALLOC_MIN_SIZE <= 32)
576 return 96;
577
578 if (n == 2 && KMALLOC_MIN_SIZE <= 64)
579 return 192;
580#endif
581 return 0;
582}
583
584static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)564static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
585{565{
586#ifndef CONFIG_SLOB566#ifndef CONFIG_SLOB
include/linux/string.h+2−0
@@ -216,6 +216,8 @@ int bprintf(u32 *bin_buf, size_t size, const char *fmt, ...) __printf(3, 4); · 215 unmodified lines
216extern ssize_t memory_read_from_buffer(void *to, size_t count, loff_t *ppos,216extern ssize_t memory_read_from_buffer(void *to, size_t count, loff_t *ppos,
217 const void *from, size_t available);217 const void *from, size_t available);
218 218
219int ptr_to_hashval(const void *ptr, unsigned long *hashval_out);
220
219/**221/**
220 * strstarts - does @str start with @prefix?222 * strstarts - does @str start with @prefix?
221 * @str: string to examine223 * @str: string to examine
include/linux/swap.h+1−1
@@ -307,7 +307,7 @@ struct vma_swap_readahead { · 306 unmodified lines
307};307};
308 308
309/* linux/mm/workingset.c */309/* linux/mm/workingset.c */
310void *workingset_eviction(struct page *page);310void *workingset_eviction(struct page *page, struct mem_cgroup *target_memcg);
311void workingset_refault(struct page *page, void *shadow);311void workingset_refault(struct page *page, void *shadow);
312void workingset_activation(struct page *page);312void workingset_activation(struct page *page);
313 313
include/linux/vmalloc.h+12−0
@@ -22,6 +22,18 @@ struct notifier_block; /* in notifier.h */ · 21 unmodified lines
22#define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */22#define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
23#define VM_NO_GUARD 0x00000040 /* don't add guard page */23#define VM_NO_GUARD 0x00000040 /* don't add guard page */
24#define VM_KASAN 0x00000080 /* has allocated kasan shadow memory */24#define VM_KASAN 0x00000080 /* has allocated kasan shadow memory */
25
26/*
27 * VM_KASAN is used slighly differently depending on CONFIG_KASAN_VMALLOC.
28 *
29 * If IS_ENABLED(CONFIG_KASAN_VMALLOC), VM_KASAN is set on a vm_struct after
30 * shadow memory has been mapped. It's used to handle allocation errors so that
31 * we don't try to poision shadow on free if it was never allocated.
32 *
33 * Otherwise, VM_KASAN is set for kasan_module_alloc() allocations and used to
34 * determine which allocations need the module shadow freed.
35 */
36
25/*37/*
26 * Memory with VM_FLUSH_RESET_PERMS cannot be freed in an interrupt or with38 * Memory with VM_FLUSH_RESET_PERMS cannot be freed in an interrupt or with
27 * vfree_atomic().39 * vfree_atomic().
include/trace/events/kmem.h+47−0
@@ -316,6 +316,53 @@ TRACE_EVENT(mm_page_alloc_extfrag, · 315 unmodified lines
316 __entry->change_ownership)316 __entry->change_ownership)
317);317);
318 318
319/*
320 * Required for uniquely and securely identifying mm in rss_stat tracepoint.
321 */
322#ifndef __PTR_TO_HASHVAL
323static unsigned int __maybe_unused mm_ptr_to_hash(const void *ptr)
324{
325 int ret;
326 unsigned long hashval;
327
328 ret = ptr_to_hashval(ptr, &hashval);
329 if (ret)
330 return 0;
331
332 /* The hashed value is only 32-bit */
333 return (unsigned int)hashval;
334}
335#define __PTR_TO_HASHVAL
336#endif
337
338TRACE_EVENT(rss_stat,
339
340 TP_PROTO(struct mm_struct *mm,
341 int member,
342 long count),
343
344 TP_ARGS(mm, member, count),
345
346 TP_STRUCT__entry(
347 __field(unsigned int, mm_id)
348 __field(unsigned int, curr)
349 __field(int, member)
350 __field(long, size)
351 ),
352
353 TP_fast_assign(
354 __entry->mm_id = mm_ptr_to_hash(mm);
355 __entry->curr = !!(current->mm == mm);
356 __entry->member = member;
357 __entry->size = (count << PAGE_SHIFT);
358 ),
359
360 TP_printk("mm_id=%u curr=%d member=%d size=%ldB",
361 __entry->mm_id,
362 __entry->curr,
363 __entry->member,
364 __entry->size)
365 );
319#endif /* _TRACE_KMEM_H */366#endif /* _TRACE_KMEM_H */
320 367
321/* This part must be outside protection */368/* This part must be outside protection */
kernel/events/uprobes.c+1−1
@@ -1457,7 +1457,7 @@ static int xol_add_vma(struct mm_struct *mm, struct xol_area *area) · 1456 unmodified lines
1457 /* Try to map as high as possible, this is only a hint. */1457 /* Try to map as high as possible, this is only a hint. */
1458 area->vaddr = get_unmapped_area(NULL, TASK_SIZE - PAGE_SIZE,1458 area->vaddr = get_unmapped_area(NULL, TASK_SIZE - PAGE_SIZE,
1459 PAGE_SIZE, 0, 0);1459 PAGE_SIZE, 0, 0);
1460 if (area->vaddr & ~PAGE_MASK) {1460 if (IS_ERR_VALUE(area->vaddr)) {
1461 ret = area->vaddr;1461 ret = area->vaddr;
1462 goto fail;1462 goto fail;
1463 }1463 }
kernel/fork.c+4−0
@@ -93,6 +93,7 @@ · 92 unmodified lines
93#include <linux/livepatch.h>93#include <linux/livepatch.h>
94#include <linux/thread_info.h>94#include <linux/thread_info.h>
95#include <linux/stackleak.h>95#include <linux/stackleak.h>
96#include <linux/kasan.h>
96 97
97#include <asm/pgtable.h>98#include <asm/pgtable.h>
98#include <asm/pgalloc.h>99#include <asm/pgalloc.h>
@@ -223,6 +224,9 @@ static unsigned long *alloc_thread_stack_node(struct task_struct *tsk, int node) · 124 unmodified lines
223 if (!s)224 if (!s)
224 continue;225 continue;
225 226
227 /* Clear the KASAN shadow of the stack. */
228 kasan_unpoison_shadow(s->addr, THREAD_SIZE);
229
226 /* Clear stale pointers from reused stack. */230 /* Clear stale pointers from reused stack. */
227 memset(s->addr, 0, THREAD_SIZE);231 memset(s->addr, 0, THREAD_SIZE);
228 232
kernel/sysctl.c+1−1
@@ -1466,7 +1466,7 @@ static struct ctl_table vm_table[] = { · 1465 unmodified lines
1466 .procname = "drop_caches",1466 .procname = "drop_caches",
1467 .data = &sysctl_drop_caches,1467 .data = &sysctl_drop_caches,
1468 .maxlen = sizeof(int),1468 .maxlen = sizeof(int),
1469 .mode = 0644,1469 .mode = 0200,
1470 .proc_handler = drop_caches_sysctl_handler,1470 .proc_handler = drop_caches_sysctl_handler,
1471 .extra1 = SYSCTL_ONE,1471 .extra1 = SYSCTL_ONE,
1472 .extra2 = &four,1472 .extra2 = &four,
lib/Kconfig.kasan+16−0
@@ -6,6 +6,9 @@ config HAVE_ARCH_KASAN · 5 unmodified lines
6config HAVE_ARCH_KASAN_SW_TAGS6config HAVE_ARCH_KASAN_SW_TAGS
7 bool7 bool
8 8
9config HAVE_ARCH_KASAN_VMALLOC
10 bool
11
9config CC_HAS_KASAN_GENERIC12config CC_HAS_KASAN_GENERIC
10 def_bool $(cc-option, -fsanitize=kernel-address)13 def_bool $(cc-option, -fsanitize=kernel-address)
11 14
@@ -142,6 +145,19 @@ config KASAN_SW_TAGS_IDENTIFY · 130 unmodified lines
142 (use-after-free or out-of-bounds) at the cost of increased145 (use-after-free or out-of-bounds) at the cost of increased
143 memory consumption.146 memory consumption.
144 147
148config KASAN_VMALLOC
149 bool "Back mappings in vmalloc space with real shadow memory"
150 depends on KASAN && HAVE_ARCH_KASAN_VMALLOC
151 help
152 By default, the shadow region for vmalloc space is the read-only
153 zero page. This means that KASAN cannot detect errors involving
154 vmalloc space.
155
156 Enabling this option will hook in to vmap/vmalloc and back those
157 mappings with real shadow memory allocated on demand. This allows
158 for KASAN to detect more sorts of errors (and to support vmapped
159 stacks), but at the cost of higher memory usage.
160
145config TEST_KASAN161config TEST_KASAN
146 tristate "Module for testing KASAN for bug detection"162 tristate "Module for testing KASAN for bug detection"
147 depends on m && KASAN163 depends on m && KASAN
lib/test_kasan.c+26−0
@@ -19,6 +19,7 @@ · 18 unmodified lines
19#include <linux/string.h>19#include <linux/string.h>
20#include <linux/uaccess.h>20#include <linux/uaccess.h>
21#include <linux/io.h>21#include <linux/io.h>
22#include <linux/vmalloc.h>
22 23
23#include <asm/page.h>24#include <asm/page.h>
24 25
@@ -748,6 +749,30 @@ static noinline void __init kmalloc_double_kzfree(void) · 723 unmodified lines
748 kzfree(ptr);749 kzfree(ptr);
749}750}
750 751
752#ifdef CONFIG_KASAN_VMALLOC
753static noinline void __init vmalloc_oob(void)
754{
755 void *area;
756
757 pr_info("vmalloc out-of-bounds\n");
758
759 /*
760 * We have to be careful not to hit the guard page.
761 * The MMU will catch that and crash us.
762 */
763 area = vmalloc(3000);
764 if (!area) {
765 pr_err("Allocation failed\n");
766 return;
767 }
768
769 ((volatile char *)area)[3100];
770 vfree(area);
771}
772#else
773static void __init vmalloc_oob(void) {}
774#endif
775
751static int __init kmalloc_tests_init(void)776static int __init kmalloc_tests_init(void)
752{777{
753 /*778 /*
@@ -793,6 +818,7 @@ static int __init kmalloc_tests_init(void) · 39 unmodified lines
793 kasan_strings();818 kasan_strings();
794 kasan_bitops();819 kasan_bitops();
795 kmalloc_double_kzfree();820 kmalloc_double_kzfree();
821 vmalloc_oob();
796 822
797 kasan_restore_multi_shot(multishot);823 kasan_restore_multi_shot(multishot);
798 824
lib/vsprintf.c+29−11
@@ -761,11 +761,38 @@ static int __init initialize_ptr_random(void) · 760 unmodified lines
761early_initcall(initialize_ptr_random);761early_initcall(initialize_ptr_random);
762 762
763/* Maps a pointer to a 32 bit unique identifier. */763/* Maps a pointer to a 32 bit unique identifier. */
764static inline int __ptr_to_hashval(const void *ptr, unsigned long *hashval_out)
765{
766 unsigned long hashval;
767
768 if (static_branch_unlikely(&not_filled_random_ptr_key))
769 return -EAGAIN;
770
771#ifdef CONFIG_64BIT
772 hashval = (unsigned long)siphash_1u64((u64)ptr, &ptr_key);
773 /*
774 * Mask off the first 32 bits, this makes explicit that we have
775 * modified the address (and 32 bits is plenty for a unique ID).
776 */
777 hashval = hashval & 0xffffffff;
778#else
779 hashval = (unsigned long)siphash_1u32((u32)ptr, &ptr_key);
780#endif
781 *hashval_out = hashval;
782 return 0;
783}
784
785int ptr_to_hashval(const void *ptr, unsigned long *hashval_out)
786{
787 return __ptr_to_hashval(ptr, hashval_out);
788}
789
764static char *ptr_to_id(char *buf, char *end, const void *ptr,790static char *ptr_to_id(char *buf, char *end, const void *ptr,
765 struct printf_spec spec)791 struct printf_spec spec)
766{792{
767 const char *str = sizeof(ptr) == 8 ? "(____ptrval____)" : "(ptrval)";793 const char *str = sizeof(ptr) == 8 ? "(____ptrval____)" : "(ptrval)";
768 unsigned long hashval;794 unsigned long hashval;
795 int ret;
769 796
770 /* When debugging early boot use non-cryptographically secure hash. */797 /* When debugging early boot use non-cryptographically secure hash. */
771 if (unlikely(debug_boot_weak_hash)) {798 if (unlikely(debug_boot_weak_hash)) {
@@ -773,22 +800,13 @@ static char *ptr_to_id(char *buf, char *end, const void *ptr, · 1 unmodified line
773 return pointer_string(buf, end, (const void *)hashval, spec);800 return pointer_string(buf, end, (const void *)hashval, spec);
774 }801 }
775 802
776 if (static_branch_unlikely(&not_filled_random_ptr_key)) {803 ret = __ptr_to_hashval(ptr, &hashval);
804 if (ret) {
777 spec.field_width = 2 * sizeof(ptr);805 spec.field_width = 2 * sizeof(ptr);
778 /* string length must be less than default_width */806 /* string length must be less than default_width */
779 return error_string(buf, end, str, spec);807 return error_string(buf, end, str, spec);
780 }808 }
781 809
782#ifdef CONFIG_64BIT
783 hashval = (unsigned long)siphash_1u64((u64)ptr, &ptr_key);
784 /*
785 * Mask off the first 32 bits, this makes explicit that we have
786 * modified the address (and 32 bits is plenty for a unique ID).
787 */
788 hashval = hashval & 0xffffffff;
789#else
790 hashval = (unsigned long)siphash_1u32((u32)ptr, &ptr_key);
791#endif
792 return pointer_string(buf, end, (const void *)hashval, spec);810 return pointer_string(buf, end, (const void *)hashval, spec);
793}811}
794 812
mm/Kconfig+20−20
@@ -29,7 +29,7 @@ config FLATMEM_MANUAL · 28 unmodified lines
29 29
30 For systems that have holes in their physical address30 For systems that have holes in their physical address
31 spaces and for features like NUMA and memory hotplug,31 spaces and for features like NUMA and memory hotplug,
32 choose "Sparse Memory"32 choose "Sparse Memory".
33 33
34 If unsure, choose this option (Flat Memory) over any other.34 If unsure, choose this option (Flat Memory) over any other.
35 35
@@ -122,9 +122,9 @@ config SPARSEMEM_VMEMMAP · 86 unmodified lines
122 depends on SPARSEMEM && SPARSEMEM_VMEMMAP_ENABLE122 depends on SPARSEMEM && SPARSEMEM_VMEMMAP_ENABLE
123 default y123 default y
124 help124 help
125 SPARSEMEM_VMEMMAP uses a virtually mapped memmap to optimise125 SPARSEMEM_VMEMMAP uses a virtually mapped memmap to optimise
126 pfn_to_page and page_to_pfn operations. This is the most126 pfn_to_page and page_to_pfn operations. This is the most
127 efficient option when sufficient kernel resources are available.127 efficient option when sufficient kernel resources are available.
128 128
129config HAVE_MEMBLOCK_NODE_MAP129config HAVE_MEMBLOCK_NODE_MAP
130 bool130 bool
@@ -160,9 +160,9 @@ config MEMORY_HOTPLUG_SPARSE · 29 unmodified lines
160 depends on SPARSEMEM && MEMORY_HOTPLUG160 depends on SPARSEMEM && MEMORY_HOTPLUG
161 161
162config MEMORY_HOTPLUG_DEFAULT_ONLINE162config MEMORY_HOTPLUG_DEFAULT_ONLINE
163 bool "Online the newly added memory blocks by default"163 bool "Online the newly added memory blocks by default"
164 depends on MEMORY_HOTPLUG164 depends on MEMORY_HOTPLUG
165 help165 help
166 This option sets the default policy setting for memory hotplug166 This option sets the default policy setting for memory hotplug
167 onlining policy (/sys/devices/system/memory/auto_online_blocks) which167 onlining policy (/sys/devices/system/memory/auto_online_blocks) which
168 determines what happens to newly added memory regions. Policy setting168 determines what happens to newly added memory regions. Policy setting
@@ -227,14 +227,14 @@ config COMPACTION · 58 unmodified lines
227 select MIGRATION227 select MIGRATION
228 depends on MMU228 depends on MMU
229 help229 help
230 Compaction is the only memory management component to form230 Compaction is the only memory management component to form
231 high order (larger physically contiguous) memory blocks231 high order (larger physically contiguous) memory blocks
232 reliably. The page allocator relies on compaction heavily and232 reliably. The page allocator relies on compaction heavily and
233 the lack of the feature can lead to unexpected OOM killer233 the lack of the feature can lead to unexpected OOM killer
234 invocations for high order memory requests. You shouldn't234 invocations for high order memory requests. You shouldn't
235 disable this option unless there really is a strong reason for235 disable this option unless there really is a strong reason for
236 it and then we would be really interested to hear about that at236 it and then we would be really interested to hear about that at
237 linux-mm@kvack.org.237 linux-mm@kvack.org.
238 238
239#239#
240# support for page migration240# support for page migration
@@ -258,7 +258,7 @@ config ARCH_ENABLE_THP_MIGRATION · 17 unmodified lines
258 bool258 bool
259 259
260config CONTIG_ALLOC260config CONTIG_ALLOC
261 def_bool (MEMORY_ISOLATION && COMPACTION) || CMA261 def_bool (MEMORY_ISOLATION && COMPACTION) || CMA
262 262
263config PHYS_ADDR_T_64BIT263config PHYS_ADDR_T_64BIT
264 def_bool 64BIT264 def_bool 64BIT
@@ -302,10 +302,10 @@ config KSM · 37 unmodified lines
302 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).302 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
303 303
304config DEFAULT_MMAP_MIN_ADDR304config DEFAULT_MMAP_MIN_ADDR
305 int "Low address space to protect from user allocation"305 int "Low address space to protect from user allocation"
306 depends on MMU306 depends on MMU
307 default 4096307 default 4096
308 help308 help
309 This is the portion of low virtual memory which should be protected309 This is the portion of low virtual memory which should be protected
310 from userspace allocation. Keeping a user from writing to low pages310 from userspace allocation. Keeping a user from writing to low pages
311 can help reduce the impact of kernel NULL pointer bugs.311 can help reduce the impact of kernel NULL pointer bugs.
@@ -408,7 +408,7 @@ choice · 96 unmodified lines
408endchoice408endchoice
409 409
410config ARCH_WANTS_THP_SWAP410config ARCH_WANTS_THP_SWAP
411 def_bool n411 def_bool n
412 412
413config THP_SWAP413config THP_SWAP
414 def_bool y414 def_bool y
mm/cma.c+2−4
@@ -95,13 +95,11 @@ static void cma_clear_bitmap(struct cma *cma, unsigned long pfn, · 94 unmodified lines
95 95
96static int __init cma_activate_area(struct cma *cma)96static int __init cma_activate_area(struct cma *cma)
97{97{
98 int bitmap_size = BITS_TO_LONGS(cma_bitmap_maxno(cma)) * sizeof(long);
99 unsigned long base_pfn = cma->base_pfn, pfn = base_pfn;98 unsigned long base_pfn = cma->base_pfn, pfn = base_pfn;
100 unsigned i = cma->count >> pageblock_order;99 unsigned i = cma->count >> pageblock_order;
101 struct zone *zone;100 struct zone *zone;
102 101
103 cma->bitmap = kzalloc(bitmap_size, GFP_KERNEL);102 cma->bitmap = bitmap_zalloc(cma_bitmap_maxno(cma), GFP_KERNEL);
104
105 if (!cma->bitmap) {103 if (!cma->bitmap) {
106 cma->count = 0;104 cma->count = 0;
107 return -ENOMEM;105 return -ENOMEM;
@@ -139,7 +137,7 @@ static int __init cma_activate_area(struct cma *cma) · 31 unmodified lines
139 137
140not_in_zone:138not_in_zone:
141 pr_err("CMA area %s could not be activated\n", cma->name);139 pr_err("CMA area %s could not be activated\n", cma->name);
142 kfree(cma->bitmap);140 bitmap_free(cma->bitmap);
143 cma->count = 0;141 cma->count = 0;
144 return -EINVAL;142 return -EINVAL;
145}143}
mm/cma_debug.c+5−5
@@ -29,7 +29,7 @@ static int cma_debugfs_get(void *data, u64 *val) · 28 unmodified lines
29 29
30 return 0;30 return 0;
31}31}
32DEFINE_SIMPLE_ATTRIBUTE(cma_debugfs_fops, cma_debugfs_get, NULL, "%llu\n");32DEFINE_DEBUGFS_ATTRIBUTE(cma_debugfs_fops, cma_debugfs_get, NULL, "%llu\n");
33 33
34static int cma_used_get(void *data, u64 *val)34static int cma_used_get(void *data, u64 *val)
35{35{
@@ -44,7 +44,7 @@ static int cma_used_get(void *data, u64 *val) · 8 unmodified lines
44 44
45 return 0;45 return 0;
46}46}
47DEFINE_SIMPLE_ATTRIBUTE(cma_used_fops, cma_used_get, NULL, "%llu\n");47DEFINE_DEBUGFS_ATTRIBUTE(cma_used_fops, cma_used_get, NULL, "%llu\n");
48 48
49static int cma_maxchunk_get(void *data, u64 *val)49static int cma_maxchunk_get(void *data, u64 *val)
50{50{
@@ -66,7 +66,7 @@ static int cma_maxchunk_get(void *data, u64 *val) · 15 unmodified lines
66 66
67 return 0;67 return 0;
68}68}
69DEFINE_SIMPLE_ATTRIBUTE(cma_maxchunk_fops, cma_maxchunk_get, NULL, "%llu\n");69DEFINE_DEBUGFS_ATTRIBUTE(cma_maxchunk_fops, cma_maxchunk_get, NULL, "%llu\n");
70 70
71static void cma_add_to_cma_mem_list(struct cma *cma, struct cma_mem *mem)71static void cma_add_to_cma_mem_list(struct cma *cma, struct cma_mem *mem)
72{72{
@@ -126,7 +126,7 @@ static int cma_free_write(void *data, u64 val) · 53 unmodified lines
126 126
127 return cma_free_mem(cma, pages);127 return cma_free_mem(cma, pages);
128}128}
129DEFINE_SIMPLE_ATTRIBUTE(cma_free_fops, NULL, cma_free_write, "%llu\n");129DEFINE_DEBUGFS_ATTRIBUTE(cma_free_fops, NULL, cma_free_write, "%llu\n");
130 130
131static int cma_alloc_mem(struct cma *cma, int count)131static int cma_alloc_mem(struct cma *cma, int count)
132{132{
@@ -158,7 +158,7 @@ static int cma_alloc_write(void *data, u64 val) · 25 unmodified lines
158 158
159 return cma_alloc_mem(cma, pages);159 return cma_alloc_mem(cma, pages);
160}160}
161DEFINE_SIMPLE_ATTRIBUTE(cma_alloc_fops, NULL, cma_alloc_write, "%llu\n");161DEFINE_DEBUGFS_ATTRIBUTE(cma_alloc_fops, NULL, cma_alloc_write, "%llu\n");
162 162
163static void cma_debugfs_add_one(struct cma *cma, struct dentry *root_dentry)163static void cma_debugfs_add_one(struct cma *cma, struct dentry *root_dentry)
164{164{
mm/filemap.c+29−25
@@ -2329,27 +2329,6 @@ EXPORT_SYMBOL(generic_file_read_iter); · 2328 unmodified lines
2329 2329
2330#ifdef CONFIG_MMU2330#ifdef CONFIG_MMU
2331#define MMAP_LOTSAMISS (100)2331#define MMAP_LOTSAMISS (100)
2332static struct file *maybe_unlock_mmap_for_io(struct vm_fault *vmf,
2333 struct file *fpin)
2334{
2335 int flags = vmf->flags;
2336
2337 if (fpin)
2338 return fpin;
2339
2340 /*
2341 * FAULT_FLAG_RETRY_NOWAIT means we don't want to wait on page locks or
2342 * anything, so we only pin the file and drop the mmap_sem if only
2343 * FAULT_FLAG_ALLOW_RETRY is set.
2344 */
2345 if ((flags & (FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_RETRY_NOWAIT)) ==
2346 FAULT_FLAG_ALLOW_RETRY) {
2347 fpin = get_file(vmf->vma->vm_file);
2348 up_read(&vmf->vma->vm_mm->mmap_sem);
2349 }
2350 return fpin;
2351}
2352
2353/*2332/*
2354 * lock_page_maybe_drop_mmap - lock the page, possibly dropping the mmap_sem2333 * lock_page_maybe_drop_mmap - lock the page, possibly dropping the mmap_sem
2355 * @vmf - the vm_fault for this fault.2334 * @vmf - the vm_fault for this fault.
@@ -3161,6 +3140,27 @@ int pagecache_write_end(struct file *file, struct address_space *mapping, · 805 unmodified lines
3161}3140}
3162EXPORT_SYMBOL(pagecache_write_end);3141EXPORT_SYMBOL(pagecache_write_end);
3163 3142
3143/*
3144 * Warn about a page cache invalidation failure during a direct I/O write.
3145 */
3146void dio_warn_stale_pagecache(struct file *filp)
3147{
3148 static DEFINE_RATELIMIT_STATE(_rs, 86400 * HZ, DEFAULT_RATELIMIT_BURST);
3149 char pathname[128];
3150 struct inode *inode = file_inode(filp);
3151 char *path;
3152
3153 errseq_set(&inode->i_mapping->wb_err, -EIO);
3154 if (__ratelimit(&_rs)) {
3155 path = file_path(filp, pathname, sizeof(pathname));
3156 if (IS_ERR(path))
3157 path = "(unknown)";
3158 pr_crit("Page cache invalidation failure on direct I/O. Possible data corruption due to collision with buffered I/O!\n");
3159 pr_crit("File: %s PID: %d Comm: %.20s\n", path, current->pid,
3160 current->comm);
3161 }
3162}
3163
3164ssize_t3164ssize_t
3165generic_file_direct_write(struct kiocb *iocb, struct iov_iter *from)3165generic_file_direct_write(struct kiocb *iocb, struct iov_iter *from)
3166{3166{
@@ -3218,11 +3218,15 @@ generic_file_direct_write(struct kiocb *iocb, struct iov_iter *from) · 51 unmodified lines
3218 * Most of the time we do not need this since dio_complete() will do3218 * Most of the time we do not need this since dio_complete() will do
3219 * the invalidation for us. However there are some file systems that3219 * the invalidation for us. However there are some file systems that
3220 * do not end up with dio_complete() being called, so let's not break3220 * do not end up with dio_complete() being called, so let's not break
3221 * them by removing it completely3221 * them by removing it completely.
3222 *
3223 * Noticeable example is a blkdev_direct_IO().
3224 *
3225 * Skip invalidation for async writes or if mapping has no pages.
3222 */3226 */
3223 if (mapping->nrpages)3227 if (written > 0 && mapping->nrpages &&
3224 invalidate_inode_pages2_range(mapping,3228 invalidate_inode_pages2_range(mapping, pos >> PAGE_SHIFT, end))
3225 pos >> PAGE_SHIFT, end);3229 dio_warn_stale_pagecache(file);
3226 3230
3227 if (written > 0) {3231 if (written > 0) {
3228 pos += written;3232 pos += written;
mm/gup.c+27−13
@@ -734,11 +734,17 @@ static int check_vma_flags(struct vm_area_struct *vma, unsigned long gup_flags) · 733 unmodified lines
734 * Or NULL if the caller does not require them.734 * Or NULL if the caller does not require them.
735 * @nonblocking: whether waiting for disk IO or mmap_sem contention735 * @nonblocking: whether waiting for disk IO or mmap_sem contention
736 *736 *
737 * Returns number of pages pinned. This may be fewer than the number737 * Returns either number of pages pinned (which may be less than the
738 * requested. If nr_pages is 0 or negative, returns 0. If no pages738 * number requested), or an error. Details about the return value:
739 * were pinned, returns -errno. Each page returned must be released739 *
740 * with a put_page() call when it is finished with. vmas will only740 * -- If nr_pages is 0, returns 0.
741 * remain valid while mmap_sem is held.741 * -- If nr_pages is >0, but no pages were pinned, returns -errno.
742 * -- If nr_pages is >0, and some pages were pinned, returns the number of
743 * pages pinned. Again, this may be less than nr_pages.
744 *
745 * The caller is responsible for releasing returned @pages, via put_page().
746 *
747 * @vmas are valid only as long as mmap_sem is held.
742 *748 *
743 * Must be called with mmap_sem held. It may be released. See below.749 * Must be called with mmap_sem held. It may be released. See below.
744 *750 *
@@ -1107,11 +1113,17 @@ static __always_inline long __get_user_pages_locked(struct task_struct *tsk, · 362 unmodified lines
1107 * subsequently whether VM_FAULT_RETRY functionality can be1113 * subsequently whether VM_FAULT_RETRY functionality can be
1108 * utilised. Lock must initially be held.1114 * utilised. Lock must initially be held.
1109 *1115 *
1110 * Returns number of pages pinned. This may be fewer than the number1116 * Returns either number of pages pinned (which may be less than the
1111 * requested. If nr_pages is 0 or negative, returns 0. If no pages1117 * number requested), or an error. Details about the return value:
1112 * were pinned, returns -errno. Each page returned must be released1118 *
1113 * with a put_page() call when it is finished with. vmas will only1119 * -- If nr_pages is 0, returns 0.
1114 * remain valid while mmap_sem is held.1120 * -- If nr_pages is >0, but no pages were pinned, returns -errno.
1121 * -- If nr_pages is >0, and some pages were pinned, returns the number of
1122 * pages pinned. Again, this may be less than nr_pages.
1123 *
1124 * The caller is responsible for releasing returned @pages, via put_page().
1125 *
1126 * @vmas are valid only as long as mmap_sem is held.
1115 *1127 *
1116 * Must be called with mmap_sem held for read or write.1128 * Must be called with mmap_sem held for read or write.
1117 *1129 *
@@ -1443,6 +1455,7 @@ static long check_and_migrate_cma_pages(struct task_struct *tsk, · 325 unmodified lines
1443 bool drain_allow = true;1455 bool drain_allow = true;
1444 bool migrate_allow = true;1456 bool migrate_allow = true;
1445 LIST_HEAD(cma_page_list);1457 LIST_HEAD(cma_page_list);
1458 long ret = nr_pages;
1446 1459
1447check_again:1460check_again:
1448 for (i = 0; i < nr_pages;) {1461 for (i = 0; i < nr_pages;) {
@@ -1504,17 +1517,18 @@ check_again: · 55 unmodified lines
1504 * again migrating any new CMA pages which we failed to isolate1517 * again migrating any new CMA pages which we failed to isolate
1505 * earlier.1518 * earlier.
1506 */1519 */
1507 nr_pages = __get_user_pages_locked(tsk, mm, start, nr_pages,1520 ret = __get_user_pages_locked(tsk, mm, start, nr_pages,
1508 pages, vmas, NULL,1521 pages, vmas, NULL,
1509 gup_flags);1522 gup_flags);
1510 1523
1511 if ((nr_pages > 0) && migrate_allow) {1524 if ((ret > 0) && migrate_allow) {
1525 nr_pages = ret;
1512 drain_allow = true;1526 drain_allow = true;
1513 goto check_again;1527 goto check_again;
1514 }1528 }
1515 }1529 }
1516 1530
1517 return nr_pages;1531 return ret;
1518}1532}
1519#else1533#else
1520static long check_and_migrate_cma_pages(struct task_struct *tsk,1534static long check_and_migrate_cma_pages(struct task_struct *tsk,
mm/huge_memory.c+1−1
@@ -3003,7 +3003,7 @@ next: · 3002 unmodified lines
3003 3003
3004 return 0;3004 return 0;
3005}3005}
3006DEFINE_SIMPLE_ATTRIBUTE(split_huge_pages_fops, NULL, split_huge_pages_set,3006DEFINE_DEBUGFS_ATTRIBUTE(split_huge_pages_fops, NULL, split_huge_pages_set,
3007 "%llu\n");3007 "%llu\n");
3008 3008
3009static int __init split_huge_pages_debugfs(void)3009static int __init split_huge_pages_debugfs(void)
mm/hugetlb.c+91−197
@@ -244,16 +244,66 @@ struct file_region { · 243 unmodified lines
244 long to;244 long to;
245};245};
246 246
247/* Must be called with resv->lock held. Calling this with count_only == true
248 * will count the number of pages to be added but will not modify the linked
249 * list.
250 */
251static long add_reservation_in_range(struct resv_map *resv, long f, long t,
252 bool count_only)
253{
254 long chg = 0;
255 struct list_head *head = &resv->regions;
256 struct file_region *rg = NULL, *trg = NULL, *nrg = NULL;
257
258 /* Locate the region we are before or in. */
259 list_for_each_entry(rg, head, link)
260 if (f <= rg->to)
261 break;
262
263 /* Round our left edge to the current segment if it encloses us. */
264 if (f > rg->from)
265 f = rg->from;
266
267 chg = t - f;
268
269 /* Check for and consume any regions we now overlap with. */
270 nrg = rg;
271 list_for_each_entry_safe(rg, trg, rg->link.prev, link) {
272 if (&rg->link == head)
273 break;
274 if (rg->from > t)
275 break;
276
277 /* We overlap with this area, if it extends further than
278 * us then we must extend ourselves. Account for its
279 * existing reservation.
280 */
281 if (rg->to > t) {
282 chg += rg->to - t;
283 t = rg->to;
284 }
285 chg -= rg->to - rg->from;
286
287 if (!count_only && rg != nrg) {
288 list_del(&rg->link);
289 kfree(rg);
290 }
291 }
292
293 if (!count_only) {
294 nrg->from = f;
295 nrg->to = t;
296 }
297
298 return chg;
299}
300
247/*301/*
248 * Add the huge page range represented by [f, t) to the reserve302 * Add the huge page range represented by [f, t) to the reserve
249 * map. In the normal case, existing regions will be expanded303 * map. Existing regions will be expanded to accommodate the specified
250 * to accommodate the specified range. Sufficient regions should304 * range, or a region will be taken from the cache. Sufficient regions
251 * exist for expansion due to the previous call to region_chg305 * must exist in the cache due to the previous call to region_chg with
252 * with the same range. However, it is possible that region_del306 * the same range.
253 * could have been called after region_chg and modifed the map
254 * in such a way that no region exists to be expanded. In this
255 * case, pull a region descriptor from the cache associated with
256 * the map and use that for the new range.
257 *307 *
258 * Return the number of new huge pages added to the map. This308 * Return the number of new huge pages added to the map. This
259 * number is greater than or equal to zero.309 * number is greater than or equal to zero.
@@ -261,7 +311,7 @@ struct file_region { · 1 unmodified line
261static long region_add(struct resv_map *resv, long f, long t)311static long region_add(struct resv_map *resv, long f, long t)
262{312{
263 struct list_head *head = &resv->regions;313 struct list_head *head = &resv->regions;
264 struct file_region *rg, *nrg, *trg;314 struct file_region *rg, *nrg;
265 long add = 0;315 long add = 0;
266 316
267 spin_lock(&resv->lock);317 spin_lock(&resv->lock);
@@ -272,9 +322,8 @@ static long region_add(struct resv_map *resv, long f, long t) · 4 unmodified lines
272 322
273 /*323 /*
274 * If no region exists which can be expanded to include the324 * If no region exists which can be expanded to include the
275 * specified range, the list must have been modified by an325 * specified range, pull a region descriptor from the cache
276 * interleving call to region_del(). Pull a region descriptor326 * and use it for this range.
277 * from the cache and use it for this range.
278 */327 */
279 if (&rg->link == head || t < rg->from) {328 if (&rg->link == head || t < rg->from) {
280 VM_BUG_ON(resv->region_cache_count <= 0);329 VM_BUG_ON(resv->region_cache_count <= 0);
@@ -292,38 +341,7 @@ static long region_add(struct resv_map *resv, long f, long t) · 11 unmodified lines
292 goto out_locked;341 goto out_locked;
293 }342 }
294 343
295 /* Round our left edge to the current segment if it encloses us. */344 add = add_reservation_in_range(resv, f, t, false);
296 if (f > rg->from)
297 f = rg->from;
298
299 /* Check for and consume any regions we now overlap with. */
300 nrg = rg;
301 list_for_each_entry_safe(rg, trg, rg->link.prev, link) {
302 if (&rg->link == head)
303 break;
304 if (rg->from > t)
305 break;
306
307 /* If this area reaches higher then extend our area to
308 * include it completely. If this is not the first area
309 * which we intend to reuse, free it. */
310 if (rg->to > t)
311 t = rg->to;
312 if (rg != nrg) {
313 /* Decrement return value by the deleted range.
314 * Another range will span this area so that by
315 * end of routine add will be >= zero
316 */
317 add -= (rg->to - rg->from);
318 list_del(&rg->link);
319 kfree(rg);
320 }
321 }
322
323 add += (nrg->from - f); /* Added to beginning of region */
324 nrg->from = f;
325 add += t - nrg->to; /* Added to end of region */
326 nrg->to = t;
327 345
328out_locked:346out_locked:
329 resv->adds_in_progress--;347 resv->adds_in_progress--;
@@ -339,15 +357,9 @@ out_locked: · 9 unmodified lines
339 * call to region_add that will actually modify the reserve357 * call to region_add that will actually modify the reserve
340 * map to add the specified range [f, t). region_chg does358 * map to add the specified range [f, t). region_chg does
341 * not change the number of huge pages represented by the359 * not change the number of huge pages represented by the
342 * map. However, if the existing regions in the map can not360 * map. A new file_region structure is added to the cache
343 * be expanded to represent the new range, a new file_region361 * as a placeholder, so that the subsequent region_add
344 * structure is added to the map as a placeholder. This is362 * call will have all the regions it needs and will not fail.
345 * so that the subsequent region_add call will have all the
346 * regions it needs and will not fail.
347 *
348 * Upon entry, region_chg will also examine the cache of region descriptors
349 * associated with the map. If there are not enough descriptors cached, one
350 * will be allocated for the in progress add operation.
351 *363 *
352 * Returns the number of huge pages that need to be added to the existing364 * Returns the number of huge pages that need to be added to the existing
353 * reservation map for the range [f, t). This number is greater or equal to365 * reservation map for the range [f, t). This number is greater or equal to
@@ -356,11 +368,8 @@ out_locked: · 2 unmodified lines
356 */368 */
357static long region_chg(struct resv_map *resv, long f, long t)369static long region_chg(struct resv_map *resv, long f, long t)
358{370{
359 struct list_head *head = &resv->regions;
360 struct file_region *rg, *nrg = NULL;
361 long chg = 0;371 long chg = 0;
362 372
363retry:
364 spin_lock(&resv->lock);373 spin_lock(&resv->lock);
365retry_locked:374retry_locked:
366 resv->adds_in_progress++;375 resv->adds_in_progress++;
@@ -378,10 +387,8 @@ retry_locked: · 11 unmodified lines
378 spin_unlock(&resv->lock);387 spin_unlock(&resv->lock);
379 388
380 trg = kmalloc(sizeof(*trg), GFP_KERNEL);389 trg = kmalloc(sizeof(*trg), GFP_KERNEL);
381 if (!trg) {390 if (!trg)
382 kfree(nrg);
383 return -ENOMEM;391 return -ENOMEM;
384 }
385 392
386 spin_lock(&resv->lock);393 spin_lock(&resv->lock);
387 list_add(&trg->link, &resv->region_cache);394 list_add(&trg->link, &resv->region_cache);
@@ -389,61 +396,8 @@ retry_locked: · 1 unmodified line
389 goto retry_locked;396 goto retry_locked;
390 }397 }
391 398
392 /* Locate the region we are before or in. */399 chg = add_reservation_in_range(resv, f, t, true);
393 list_for_each_entry(rg, head, link)
394 if (f <= rg->to)
395 break;
396 400
397 /* If we are below the current region then a new region is required.
398 * Subtle, allocate a new region at the position but make it zero
399 * size such that we can guarantee to record the reservation. */
400 if (&rg->link == head || t < rg->from) {
401 if (!nrg) {
402 resv->adds_in_progress--;
403 spin_unlock(&resv->lock);
404 nrg = kmalloc(sizeof(*nrg), GFP_KERNEL);
405 if (!nrg)
406 return -ENOMEM;
407
408 nrg->from = f;
409 nrg->to = f;
410 INIT_LIST_HEAD(&nrg->link);
411 goto retry;
412 }
413
414 list_add(&nrg->link, rg->link.prev);
415 chg = t - f;
416 goto out_nrg;
417 }
418
419 /* Round our left edge to the current segment if it encloses us. */
420 if (f > rg->from)
421 f = rg->from;
422 chg = t - f;
423
424 /* Check for and consume any regions we now overlap with. */
425 list_for_each_entry(rg, rg->link.prev, link) {
426 if (&rg->link == head)
427 break;
428 if (rg->from > t)
429 goto out;
430
431 /* We overlap with this area, if it extends further than
432 * us then we must extend ourselves. Account for its
433 * existing reservation. */
434 if (rg->to > t) {
435 chg += rg->to - t;
436 t = rg->to;
437 }
438 chg -= rg->to - rg->from;
439 }
440
441out:
442 spin_unlock(&resv->lock);
443 /* We already know we raced and no longer need the new region */
444 kfree(nrg);
445 return chg;
446out_nrg:
447 spin_unlock(&resv->lock);401 spin_unlock(&resv->lock);
448 return chg;402 return chg;
449}403}
@@ -1069,85 +1023,12 @@ static void free_gigantic_page(struct page *page, unsigned int order) · 619 unmodified lines
1069}1023}
1070 1024
1071#ifdef CONFIG_CONTIG_ALLOC1025#ifdef CONFIG_CONTIG_ALLOC
1072static int __alloc_gigantic_page(unsigned long start_pfn,
1073 unsigned long nr_pages, gfp_t gfp_mask)
1074{
1075 unsigned long end_pfn = start_pfn + nr_pages;
1076 return alloc_contig_range(start_pfn, end_pfn, MIGRATE_MOVABLE,
1077 gfp_mask);
1078}
1079
1080static bool pfn_range_valid_gigantic(struct zone *z,
1081 unsigned long start_pfn, unsigned long nr_pages)
1082{
1083 unsigned long i, end_pfn = start_pfn + nr_pages;
1084 struct page *page;
1085
1086 for (i = start_pfn; i < end_pfn; i++) {
1087 page = pfn_to_online_page(i);
1088 if (!page)
1089 return false;
1090
1091 if (page_zone(page) != z)
1092 return false;
1093
1094 if (PageReserved(page))
1095 return false;
1096
1097 if (page_count(page) > 0)
1098 return false;
1099
1100 if (PageHuge(page))
1101 return false;
1102 }
1103
1104 return true;
1105}
1106
1107static bool zone_spans_last_pfn(const struct zone *zone,
1108 unsigned long start_pfn, unsigned long nr_pages)
1109{
1110 unsigned long last_pfn = start_pfn + nr_pages - 1;
1111 return zone_spans_pfn(zone, last_pfn);
1112}
1113
1114static struct page *alloc_gigantic_page(struct hstate *h, gfp_t gfp_mask,1026static struct page *alloc_gigantic_page(struct hstate *h, gfp_t gfp_mask,
1115 int nid, nodemask_t *nodemask)1027 int nid, nodemask_t *nodemask)
1116{1028{
1117 unsigned int order = huge_page_order(h);1029 unsigned long nr_pages = 1UL << huge_page_order(h);
1118 unsigned long nr_pages = 1 << order;
1119 unsigned long ret, pfn, flags;
1120 struct zonelist *zonelist;
1121 struct zone *zone;
1122 struct zoneref *z;
1123 1030
1124 zonelist = node_zonelist(nid, gfp_mask);1031 return alloc_contig_pages(nr_pages, gfp_mask, nid, nodemask);
1125 for_each_zone_zonelist_nodemask(zone, z, zonelist, gfp_zone(gfp_mask), nodemask) {
1126 spin_lock_irqsave(&zone->lock, flags);
1127
1128 pfn = ALIGN(zone->zone_start_pfn, nr_pages);
1129 while (zone_spans_last_pfn(zone, pfn, nr_pages)) {
1130 if (pfn_range_valid_gigantic(zone, pfn, nr_pages)) {
1131 /*
1132 * We release the zone lock here because
1133 * alloc_contig_range() will also lock the zone
1134 * at some point. If there's an allocation
1135 * spinning on this lock, it may win the race
1136 * and cause alloc_contig_range() to fail...
1137 */
1138 spin_unlock_irqrestore(&zone->lock, flags);
1139 ret = __alloc_gigantic_page(pfn, nr_pages, gfp_mask);
1140 if (!ret)
1141 return pfn_to_page(pfn);
1142 spin_lock_irqsave(&zone->lock, flags);
1143 }
1144 pfn += nr_pages;
1145 }
1146
1147 spin_unlock_irqrestore(&zone->lock, flags);
1148 }
1149
1150 return NULL;
1151}1032}
1152 1033
1153static void prep_new_huge_page(struct hstate *h, struct page *page, int nid);1034static void prep_new_huge_page(struct hstate *h, struct page *page, int nid);
@@ -3915,7 +3796,7 @@ retry: · 2761 unmodified lines
3915 * handling userfault. Reacquire after handling3796 * handling userfault. Reacquire after handling
3916 * fault to make calling code simpler.3797 * fault to make calling code simpler.
3917 */3798 */
3918 hash = hugetlb_fault_mutex_hash(h, mapping, idx, haddr);3799 hash = hugetlb_fault_mutex_hash(mapping, idx);
3919 mutex_unlock(&hugetlb_fault_mutex_table[hash]);3800 mutex_unlock(&hugetlb_fault_mutex_table[hash]);
3920 ret = handle_userfault(&vmf, VM_UFFD_MISSING);3801 ret = handle_userfault(&vmf, VM_UFFD_MISSING);
3921 mutex_lock(&hugetlb_fault_mutex_table[hash]);3802 mutex_lock(&hugetlb_fault_mutex_table[hash]);
@@ -4042,8 +3923,7 @@ backout_unlocked: · 120 unmodified lines
4042}3923}
4043 3924
4044#ifdef CONFIG_SMP3925#ifdef CONFIG_SMP
4045u32 hugetlb_fault_mutex_hash(struct hstate *h, struct address_space *mapping,3926u32 hugetlb_fault_mutex_hash(struct address_space *mapping, pgoff_t idx)
4046 pgoff_t idx, unsigned long address)
4047{3927{
4048 unsigned long key[2];3928 unsigned long key[2];
4049 u32 hash;3929 u32 hash;
@@ -4051,7 +3931,7 @@ u32 hugetlb_fault_mutex_hash(struct hstate *h, struct address_space *mapping, · 1 unmodified line
4051 key[0] = (unsigned long) mapping;3931 key[0] = (unsigned long) mapping;
4052 key[1] = idx;3932 key[1] = idx;
4053 3933
4054 hash = jhash2((u32 *)&key, sizeof(key)/sizeof(u32), 0);3934 hash = jhash2((u32 *)&key, sizeof(key)/(sizeof(u32)), 0);
4055 3935
4056 return hash & (num_fault_mutexes - 1);3936 return hash & (num_fault_mutexes - 1);
4057}3937}
@@ -4060,8 +3940,7 @@ u32 hugetlb_fault_mutex_hash(struct hstate *h, struct address_space *mapping, · 2 unmodified lines
4060 * For uniprocesor systems we always use a single mutex, so just3940 * For uniprocesor systems we always use a single mutex, so just
4061 * return 0 and avoid the hashing overhead.3941 * return 0 and avoid the hashing overhead.
4062 */3942 */
4063u32 hugetlb_fault_mutex_hash(struct hstate *h, struct address_space *mapping,3943u32 hugetlb_fault_mutex_hash(struct address_space *mapping, pgoff_t idx)
4064 pgoff_t idx, unsigned long address)
4065{3944{
4066 return 0;3945 return 0;
4067}3946}
@@ -4105,7 +3984,7 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma, · 37 unmodified lines
4105 * get spurious allocation failures if two CPUs race to instantiate3984 * get spurious allocation failures if two CPUs race to instantiate
4106 * the same page in the page cache.3985 * the same page in the page cache.
4107 */3986 */
4108 hash = hugetlb_fault_mutex_hash(h, mapping, idx, haddr);3987 hash = hugetlb_fault_mutex_hash(mapping, idx);
4109 mutex_lock(&hugetlb_fault_mutex_table[hash]);3988 mutex_lock(&hugetlb_fault_mutex_table[hash]);
4110 3989
4111 entry = huge_ptep_get(ptep);3990 entry = huge_ptep_get(ptep);
@@ -4459,6 +4338,21 @@ long follow_hugetlb_page(struct mm_struct *mm, struct vm_area_struct *vma, · 347 unmodified lines
4459 break;4338 break;
4460 }4339 }
4461 }4340 }
4341
4342 /*
4343 * If subpage information not requested, update counters
4344 * and skip the same_page loop below.
4345 */
4346 if (!pages && !vmas && !pfn_offset &&
4347 (vaddr + huge_page_size(h) < vma->vm_end) &&
4348 (remainder >= pages_per_huge_page(h))) {
4349 vaddr += huge_page_size(h);
4350 remainder -= pages_per_huge_page(h);
4351 i += pages_per_huge_page(h);
4352 spin_unlock(ptl);
4353 continue;
4354 }
4355
4462same_page:4356same_page:
4463 if (pages) {4357 if (pages) {
4464 pages[i] = mem_map_offset(page, pfn_offset);4358 pages[i] = mem_map_offset(page, pfn_offset);
@@ -4842,7 +4736,7 @@ pte_t *huge_pmd_share(struct mm_struct *mm, unsigned long addr, pud_t *pud) · 377 unmodified lines
4842 if (!vma_shareable(vma, addr))4736 if (!vma_shareable(vma, addr))
4843 return (pte_t *)pmd_alloc(mm, pud, addr);4737 return (pte_t *)pmd_alloc(mm, pud, addr);
4844 4738
4845 i_mmap_lock_write(mapping);4739 i_mmap_lock_read(mapping);
4846 vma_interval_tree_foreach(svma, &mapping->i_mmap, idx, idx) {4740 vma_interval_tree_foreach(svma, &mapping->i_mmap, idx, idx) {
4847 if (svma == vma)4741 if (svma == vma)
4848 continue;4742 continue;
@@ -4872,7 +4766,7 @@ pte_t *huge_pmd_share(struct mm_struct *mm, unsigned long addr, pud_t *pud) · 23 unmodified lines
4872 spin_unlock(ptl);4766 spin_unlock(ptl);
4873out:4767out:
4874 pte = (pte_t *)pmd_alloc(mm, pud, addr);4768 pte = (pte_t *)pmd_alloc(mm, pud, addr);
4875 i_mmap_unlock_write(mapping);4769 i_mmap_unlock_read(mapping);
4876 return pte;4770 return pte;
4877}4771}
4878 4772
mm/hwpoison-inject.c+2−2
@@ -67,8 +67,8 @@ static int hwpoison_unpoison(void *data, u64 val) · 66 unmodified lines
67 return unpoison_memory(val);67 return unpoison_memory(val);
68}68}
69 69
70DEFINE_SIMPLE_ATTRIBUTE(hwpoison_fops, NULL, hwpoison_inject, "%lli\n");70DEFINE_DEBUGFS_ATTRIBUTE(hwpoison_fops, NULL, hwpoison_inject, "%lli\n");
71DEFINE_SIMPLE_ATTRIBUTE(unpoison_fops, NULL, hwpoison_unpoison, "%lli\n");71DEFINE_DEBUGFS_ATTRIBUTE(unpoison_fops, NULL, hwpoison_unpoison, "%lli\n");
72 72
73static void pfn_inject_exit(void)73static void pfn_inject_exit(void)
74{74{
mm/internal.h+26−1
@@ -165,6 +165,9 @@ extern void post_alloc_hook(struct page *page, unsigned int order, · 164 unmodified lines
165 gfp_t gfp_flags);165 gfp_t gfp_flags);
166extern int user_min_free_kbytes;166extern int user_min_free_kbytes;
167 167
168extern void zone_pcp_update(struct zone *zone);
169extern void zone_pcp_reset(struct zone *zone);
170
168#if defined CONFIG_COMPACTION || defined CONFIG_CMA171#if defined CONFIG_COMPACTION || defined CONFIG_CMA
169 172
170/*173/*
@@ -290,7 +293,8 @@ static inline bool is_data_mapping(vm_flags_t flags) · 119 unmodified lines
290 293
291/* mm/util.c */294/* mm/util.c */
292void __vma_link_list(struct mm_struct *mm, struct vm_area_struct *vma,295void __vma_link_list(struct mm_struct *mm, struct vm_area_struct *vma,
293 struct vm_area_struct *prev, struct rb_node *rb_parent);296 struct vm_area_struct *prev);
297void __vma_unlink_list(struct mm_struct *mm, struct vm_area_struct *vma);
294 298
295#ifdef CONFIG_MMU299#ifdef CONFIG_MMU
296extern long populate_vma_page_range(struct vm_area_struct *vma,300extern long populate_vma_page_range(struct vm_area_struct *vma,
@@ -362,6 +366,27 @@ vma_address(struct page *page, struct vm_area_struct *vma) · 65 unmodified lines
362 return max(start, vma->vm_start);366 return max(start, vma->vm_start);
363}367}
364 368
369static inline struct file *maybe_unlock_mmap_for_io(struct vm_fault *vmf,
370 struct file *fpin)
371{
372 int flags = vmf->flags;
373
374 if (fpin)
375 return fpin;
376
377 /*
378 * FAULT_FLAG_RETRY_NOWAIT means we don't want to wait on page locks or
379 * anything, so we only pin the file and drop the mmap_sem if only
380 * FAULT_FLAG_ALLOW_RETRY is set.
381 */
382 if ((flags & (FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_RETRY_NOWAIT)) ==
383 FAULT_FLAG_ALLOW_RETRY) {
384 fpin = get_file(vmf->vma->vm_file);
385 up_read(&vmf->vma->vm_mm->mmap_sem);
386 }
387 return fpin;
388}
389
365#else /* !CONFIG_MMU */390#else /* !CONFIG_MMU */
366static inline void clear_page_mlock(struct page *page) { }391static inline void clear_page_mlock(struct page *page) { }
367static inline void mlock_vma_page(struct page *page) { }392static inline void mlock_vma_page(struct page *page) { }
mm/kasan/common.c+233−0
@@ -36,6 +36,8 @@ · 35 unmodified lines
36#include <linux/bug.h>36#include <linux/bug.h>
37#include <linux/uaccess.h>37#include <linux/uaccess.h>
38 38
39#include <asm/tlbflush.h>
40
39#include "kasan.h"41#include "kasan.h"
40#include "../slab.h"42#include "../slab.h"
41 43
@@ -590,6 +592,7 @@ void kasan_kfree_large(void *ptr, unsigned long ip) · 548 unmodified lines
590 /* The object will be poisoned by page_alloc. */592 /* The object will be poisoned by page_alloc. */
591}593}
592 594
595#ifndef CONFIG_KASAN_VMALLOC
593int kasan_module_alloc(void *addr, size_t size)596int kasan_module_alloc(void *addr, size_t size)
594{597{
595 void *ret;598 void *ret;
@@ -625,6 +628,7 @@ void kasan_free_shadow(const struct vm_struct *vm) · 29 unmodified lines
625 if (vm->flags & VM_KASAN)628 if (vm->flags & VM_KASAN)
626 vfree(kasan_mem_to_shadow(vm->addr));629 vfree(kasan_mem_to_shadow(vm->addr));
627}630}
631#endif
628 632
629extern void __kasan_report(unsigned long addr, size_t size, bool is_write, unsigned long ip);633extern void __kasan_report(unsigned long addr, size_t size, bool is_write, unsigned long ip);
630 634
@@ -744,3 +748,232 @@ static int __init kasan_memhotplug_init(void) · 113 unmodified lines
744 748
745core_initcall(kasan_memhotplug_init);749core_initcall(kasan_memhotplug_init);
746#endif750#endif
751
752#ifdef CONFIG_KASAN_VMALLOC
753static int kasan_populate_vmalloc_pte(pte_t *ptep, unsigned long addr,
754 void *unused)
755{
756 unsigned long page;
757 pte_t pte;
758
759 if (likely(!pte_none(*ptep)))
760 return 0;
761
762 page = __get_free_page(GFP_KERNEL);
763 if (!page)
764 return -ENOMEM;
765
766 memset((void *)page, KASAN_VMALLOC_INVALID, PAGE_SIZE);
767 pte = pfn_pte(PFN_DOWN(__pa(page)), PAGE_KERNEL);
768
769 spin_lock(&init_mm.page_table_lock);
770 if (likely(pte_none(*ptep))) {
771 set_pte_at(&init_mm, addr, ptep, pte);
772 page = 0;
773 }
774 spin_unlock(&init_mm.page_table_lock);
775 if (page)
776 free_page(page);
777 return 0;
778}
779
780int kasan_populate_vmalloc(unsigned long requested_size, struct vm_struct *area)
781{
782 unsigned long shadow_start, shadow_end;
783 int ret;
784
785 shadow_start = (unsigned long)kasan_mem_to_shadow(area->addr);
786 shadow_start = ALIGN_DOWN(shadow_start, PAGE_SIZE);
787 shadow_end = (unsigned long)kasan_mem_to_shadow(area->addr +
788 area->size);
789 shadow_end = ALIGN(shadow_end, PAGE_SIZE);
790
791 ret = apply_to_page_range(&init_mm, shadow_start,
792 shadow_end - shadow_start,
793 kasan_populate_vmalloc_pte, NULL);
794 if (ret)
795 return ret;
796
797 flush_cache_vmap(shadow_start, shadow_end);
798
799 kasan_unpoison_shadow(area->addr, requested_size);
800
801 area->flags |= VM_KASAN;
802
803 /*
804 * We need to be careful about inter-cpu effects here. Consider:
805 *
806 * CPU#0 CPU#1
807 * WRITE_ONCE(p, vmalloc(100)); while (x = READ_ONCE(p)) ;
808 * p[99] = 1;
809 *
810 * With compiler instrumentation, that ends up looking like this:
811 *
812 * CPU#0 CPU#1
813 * // vmalloc() allocates memory
814 * // let a = area->addr
815 * // we reach kasan_populate_vmalloc
816 * // and call kasan_unpoison_shadow:
817 * STORE shadow(a), unpoison_val
818 * ...
819 * STORE shadow(a+99), unpoison_val x = LOAD p
820 * // rest of vmalloc process <data dependency>
821 * STORE p, a LOAD shadow(x+99)
822 *
823 * If there is no barrier between the end of unpoisioning the shadow
824 * and the store of the result to p, the stores could be committed
825 * in a different order by CPU#0, and CPU#1 could erroneously observe
826 * poison in the shadow.
827 *
828 * We need some sort of barrier between the stores.
829 *
830 * In the vmalloc() case, this is provided by a smp_wmb() in
831 * clear_vm_uninitialized_flag(). In the per-cpu allocator and in
832 * get_vm_area() and friends, the caller gets shadow allocated but
833 * doesn't have any pages mapped into the virtual address space that
834 * has been reserved. Mapping those pages in will involve taking and
835 * releasing a page-table lock, which will provide the barrier.
836 */
837
838 return 0;
839}
840
841/*
842 * Poison the shadow for a vmalloc region. Called as part of the
843 * freeing process at the time the region is freed.
844 */
845void kasan_poison_vmalloc(void *start, unsigned long size)
846{
847 size = round_up(size, KASAN_SHADOW_SCALE_SIZE);
848 kasan_poison_shadow(start, size, KASAN_VMALLOC_INVALID);
849}
850
851static int kasan_depopulate_vmalloc_pte(pte_t *ptep, unsigned long addr,
852 void *unused)
853{
854 unsigned long page;
855
856 page = (unsigned long)__va(pte_pfn(*ptep) << PAGE_SHIFT);
857
858 spin_lock(&init_mm.page_table_lock);
859
860 if (likely(!pte_none(*ptep))) {
861 pte_clear(&init_mm, addr, ptep);
862 free_page(page);
863 }
864 spin_unlock(&init_mm.page_table_lock);
865
866 return 0;
867}
868
869/*
870 * Release the backing for the vmalloc region [start, end), which
871 * lies within the free region [free_region_start, free_region_end).
872 *
873 * This can be run lazily, long after the region was freed. It runs
874 * under vmap_area_lock, so it's not safe to interact with the vmalloc/vmap
875 * infrastructure.
876 *
877 * How does this work?
878 * -------------------
879 *
880 * We have a region that is page aligned, labelled as A.
881 * That might not map onto the shadow in a way that is page-aligned:
882 *
883 * start end
884 * v v
885 * |????????|????????|AAAAAAAA|AA....AA|AAAAAAAA|????????| < vmalloc
886 * -------- -------- -------- -------- --------
887 * | | | | |
888 * | | | /-------/ |
889 * \-------\|/------/ |/---------------/
890 * ||| ||
891 * |??AAAAAA|AAAAAAAA|AA??????| < shadow
892 * (1) (2) (3)
893 *
894 * First we align the start upwards and the end downwards, so that the
895 * shadow of the region aligns with shadow page boundaries. In the
896 * example, this gives us the shadow page (2). This is the shadow entirely
897 * covered by this allocation.
898 *
899 * Then we have the tricky bits. We want to know if we can free the
900 * partially covered shadow pages - (1) and (3) in the example. For this,
901 * we are given the start and end of the free region that contains this
902 * allocation. Extending our previous example, we could have:
903 *
904 * free_region_start free_region_end
905 * | start end |
906 * v v v v
907 * |FFFFFFFF|FFFFFFFF|AAAAAAAA|AA....AA|AAAAAAAA|FFFFFFFF| < vmalloc
908 * -------- -------- -------- -------- --------
909 * | | | | |
910 * | | | /-------/ |
911 * \-------\|/------/ |/---------------/
912 * ||| ||
913 * |FFAAAAAA|AAAAAAAA|AAF?????| < shadow
914 * (1) (2) (3)
915 *
916 * Once again, we align the start of the free region up, and the end of
917 * the free region down so that the shadow is page aligned. So we can free
918 * page (1) - we know no allocation currently uses anything in that page,
919 * because all of it is in the vmalloc free region. But we cannot free
920 * page (3), because we can't be sure that the rest of it is unused.
921 *
922 * We only consider pages that contain part of the original region for
923 * freeing: we don't try to free other pages from the free region or we'd
924 * end up trying to free huge chunks of virtual address space.
925 *
926 * Concurrency
927 * -----------
928 *
929 * How do we know that we're not freeing a page that is simultaneously
930 * being used for a fresh allocation in kasan_populate_vmalloc(_pte)?
931 *
932 * We _can_ have kasan_release_vmalloc and kasan_populate_vmalloc running
933 * at the same time. While we run under free_vmap_area_lock, the population
934 * code does not.
935 *
936 * free_vmap_area_lock instead operates to ensure that the larger range
937 * [free_region_start, free_region_end) is safe: because __alloc_vmap_area and
938 * the per-cpu region-finding algorithm both run under free_vmap_area_lock,
939 * no space identified as free will become used while we are running. This
940 * means that so long as we are careful with alignment and only free shadow
941 * pages entirely covered by the free region, we will not run in to any
942 * trouble - any simultaneous allocations will be for disjoint regions.
943 */
944void kasan_release_vmalloc(unsigned long start, unsigned long end,
945 unsigned long free_region_start,
946 unsigned long free_region_end)
947{
948 void *shadow_start, *shadow_end;
949 unsigned long region_start, region_end;
950
951 region_start = ALIGN(start, PAGE_SIZE * KASAN_SHADOW_SCALE_SIZE);
952 region_end = ALIGN_DOWN(end, PAGE_SIZE * KASAN_SHADOW_SCALE_SIZE);
953
954 free_region_start = ALIGN(free_region_start,
955 PAGE_SIZE * KASAN_SHADOW_SCALE_SIZE);
956
957 if (start != region_start &&
958 free_region_start < region_start)
959 region_start -= PAGE_SIZE * KASAN_SHADOW_SCALE_SIZE;
960
961 free_region_end = ALIGN_DOWN(free_region_end,
962 PAGE_SIZE * KASAN_SHADOW_SCALE_SIZE);
963
964 if (end != region_end &&
965 free_region_end > region_end)
966 region_end += PAGE_SIZE * KASAN_SHADOW_SCALE_SIZE;
967
968 shadow_start = kasan_mem_to_shadow((void *)region_start);
969 shadow_end = kasan_mem_to_shadow((void *)region_end);
970
971 if (shadow_end > shadow_start) {
972 apply_to_page_range(&init_mm, (unsigned long)shadow_start,
973 (unsigned long)(shadow_end - shadow_start),
974 kasan_depopulate_vmalloc_pte, NULL);
975 flush_tlb_kernel_range((unsigned long)shadow_start,
976 (unsigned long)shadow_end);
977 }
978}
979#endif
mm/kasan/generic_report.c+3−0
@@ -86,6 +86,9 @@ static const char *get_shadow_bug_type(struct kasan_access_info *info) · 85 unmodified lines
86 case KASAN_ALLOCA_RIGHT:86 case KASAN_ALLOCA_RIGHT:
87 bug_type = "alloca-out-of-bounds";87 bug_type = "alloca-out-of-bounds";
88 break;88 break;
89 case KASAN_VMALLOC_INVALID:
90 bug_type = "vmalloc-out-of-bounds";
91 break;
89 }92 }
90 93
91 return bug_type;94 return bug_type;
mm/kasan/kasan.h+1−0
@@ -25,6 +25,7 @@ · 24 unmodified lines
25#endif25#endif
26 26
27#define KASAN_GLOBAL_REDZONE 0xFA /* redzone for global variable */27#define KASAN_GLOBAL_REDZONE 0xFA /* redzone for global variable */
28#define KASAN_VMALLOC_INVALID 0xF9 /* unallocated space in vmapped page */
28 29
29/*30/*
30 * Stack redzone shadow values31 * Stack redzone shadow values
mm/khugepaged.c+18−0
@@ -1602,6 +1602,24 @@ static void collapse_file(struct mm_struct *mm, · 1601 unmodified lines
1602 result = SCAN_FAIL;1602 result = SCAN_FAIL;
1603 goto xa_unlocked;1603 goto xa_unlocked;
1604 }1604 }
1605 } else if (PageDirty(page)) {
1606 /*
1607 * khugepaged only works on read-only fd,
1608 * so this page is dirty because it hasn't
1609 * been flushed since first write. There
1610 * won't be new dirty pages.
1611 *
1612 * Trigger async flush here and hope the
1613 * writeback is done when khugepaged
1614 * revisits this page.
1615 *
1616 * This is a one-off situation. We are not
1617 * forcing writeback in loop.
1618 */
1619 xas_unlock_irq(&xas);
1620 filemap_flush(mapping);
1621 result = SCAN_FAIL;
1622 goto xa_unlocked;
1605 } else if (trylock_page(page)) {1623 } else if (trylock_page(page)) {
1606 get_page(page);1624 get_page(page);
1607 xas_unlock_irq(&xas);1625 xas_unlock_irq(&xas);
mm/madvise.c+7−7
@@ -864,13 +864,13 @@ static int madvise_inject_error(int behavior, · 863 unmodified lines
864{864{
865 struct page *page;865 struct page *page;
866 struct zone *zone;866 struct zone *zone;
867 unsigned int order;867 unsigned long size;
868 868
869 if (!capable(CAP_SYS_ADMIN))869 if (!capable(CAP_SYS_ADMIN))
870 return -EPERM;870 return -EPERM;
871 871
872 872
873 for (; start < end; start += PAGE_SIZE << order) {873 for (; start < end; start += size) {
874 unsigned long pfn;874 unsigned long pfn;
875 int ret;875 int ret;
876 876
@@ -882,9 +882,9 @@ static int madvise_inject_error(int behavior, · 5 unmodified lines
882 /*882 /*
883 * When soft offlining hugepages, after migrating the page883 * When soft offlining hugepages, after migrating the page
884 * we dissolve it, therefore in the second loop "page" will884 * we dissolve it, therefore in the second loop "page" will
885 * no longer be a compound page, and order will be 0.885 * no longer be a compound page.
886 */886 */
887 order = compound_order(compound_head(page));887 size = page_size(compound_head(page));
888 888
889 if (PageHWPoison(page)) {889 if (PageHWPoison(page)) {
890 put_page(page);890 put_page(page);
@@ -895,7 +895,7 @@ static int madvise_inject_error(int behavior, · 4 unmodified lines
895 pr_info("Soft offlining pfn %#lx at process virtual address %#lx\n",895 pr_info("Soft offlining pfn %#lx at process virtual address %#lx\n",
896 pfn, start);896 pfn, start);
897 897
898 ret = soft_offline_page(page, MF_COUNT_INCREASED);898 ret = soft_offline_page(pfn, MF_COUNT_INCREASED);
899 if (ret)899 if (ret)
900 return ret;900 return ret;
901 continue;901 continue;
@@ -1059,9 +1059,9 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior) · 157 unmodified lines
1059 if (!madvise_behavior_valid(behavior))1059 if (!madvise_behavior_valid(behavior))
1060 return error;1060 return error;
1061 1061
1062 if (start & ~PAGE_MASK)1062 if (!PAGE_ALIGNED(start))
1063 return error;1063 return error;
1064 len = (len_in + ~PAGE_MASK) & PAGE_MASK;1064 len = PAGE_ALIGN(len_in);
1065 1065
1066 /* Check to see whether len was rounded up from small -ve to zero */1066 /* Check to see whether len was rounded up from small -ve to zero */
1067 if (len_in && !len)1067 if (len_in && !len)
mm/memblock.c+75−36
@@ -57,42 +57,38 @@ · 56 unmodified lines
57 * at build time. The region arrays for the "memory" and "reserved"57 * at build time. The region arrays for the "memory" and "reserved"
58 * types are initially sized to %INIT_MEMBLOCK_REGIONS and for the58 * types are initially sized to %INIT_MEMBLOCK_REGIONS and for the
59 * "physmap" type to %INIT_PHYSMEM_REGIONS.59 * "physmap" type to %INIT_PHYSMEM_REGIONS.
60 * The :c:func:`memblock_allow_resize` enables automatic resizing of60 * The memblock_allow_resize() enables automatic resizing of the region
61 * the region arrays during addition of new regions. This feature61 * arrays during addition of new regions. This feature should be used
62 * should be used with care so that memory allocated for the region62 * with care so that memory allocated for the region array will not
63 * array will not overlap with areas that should be reserved, for63 * overlap with areas that should be reserved, for example initrd.
64 * example initrd.
65 *64 *
66 * The early architecture setup should tell memblock what the physical65 * The early architecture setup should tell memblock what the physical
67 * memory layout is by using :c:func:`memblock_add` or66 * memory layout is by using memblock_add() or memblock_add_node()
68 * :c:func:`memblock_add_node` functions. The first function does not67 * functions. The first function does not assign the region to a NUMA
69 * assign the region to a NUMA node and it is appropriate for UMA68 * node and it is appropriate for UMA systems. Yet, it is possible to
70 * systems. Yet, it is possible to use it on NUMA systems as well and69 * use it on NUMA systems as well and assign the region to a NUMA node
71 * assign the region to a NUMA node later in the setup process using70 * later in the setup process using memblock_set_node(). The
72 * :c:func:`memblock_set_node`. The :c:func:`memblock_add_node`71 * memblock_add_node() performs such an assignment directly.
73 * performs such an assignment directly.
74 *72 *
75 * Once memblock is setup the memory can be allocated using one of the73 * Once memblock is setup the memory can be allocated using one of the
76 * API variants:74 * API variants:
77 *75 *
78 * * :c:func:`memblock_phys_alloc*` - these functions return the76 * * memblock_phys_alloc*() - these functions return the **physical**
79 * **physical** address of the allocated memory77 * address of the allocated memory
80 * * :c:func:`memblock_alloc*` - these functions return the **virtual**78 * * memblock_alloc*() - these functions return the **virtual** address
81 * address of the allocated memory.79 * of the allocated memory.
82 *80 *
83 * Note, that both API variants use implict assumptions about allowed81 * Note, that both API variants use implict assumptions about allowed
84 * memory ranges and the fallback methods. Consult the documentation82 * memory ranges and the fallback methods. Consult the documentation
85 * of :c:func:`memblock_alloc_internal` and83 * of memblock_alloc_internal() and memblock_alloc_range_nid()
86 * :c:func:`memblock_alloc_range_nid` functions for more elaboarte84 * functions for more elaborate description.
87 * description.
88 *85 *
89 * As the system boot progresses, the architecture specific86 * As the system boot progresses, the architecture specific mem_init()
90 * :c:func:`mem_init` function frees all the memory to the buddy page87 * function frees all the memory to the buddy page allocator.
91 * allocator.
92 *88 *
93 * Unless an architecure enables %CONFIG_ARCH_KEEP_MEMBLOCK, the89 * Unless an architecture enables %CONFIG_ARCH_KEEP_MEMBLOCK, the
94 * memblock data structures will be discarded after the system90 * memblock data structures will be discarded after the system
95 * initialization compltes.91 * initialization completes.
96 */92 */
97 93
98#ifndef CONFIG_NEED_MULTIPLE_NODES94#ifndef CONFIG_NEED_MULTIPLE_NODES
@@ -1323,12 +1319,13 @@ __next_mem_pfn_range_in_zone(u64 *idx, struct zone *zone, · 1224 unmodified lines
1323 * @start: the lower bound of the memory region to allocate (phys address)1319 * @start: the lower bound of the memory region to allocate (phys address)
1324 * @end: the upper bound of the memory region to allocate (phys address)1320 * @end: the upper bound of the memory region to allocate (phys address)
1325 * @nid: nid of the free area to find, %NUMA_NO_NODE for any node1321 * @nid: nid of the free area to find, %NUMA_NO_NODE for any node
1322 * @exact_nid: control the allocation fall back to other nodes
1326 *1323 *
1327 * The allocation is performed from memory region limited by1324 * The allocation is performed from memory region limited by
1328 * memblock.current_limit if @max_addr == %MEMBLOCK_ALLOC_ACCESSIBLE.1325 * memblock.current_limit if @end == %MEMBLOCK_ALLOC_ACCESSIBLE.
1329 *1326 *
1330 * If the specified node can not hold the requested memory the1327 * If the specified node can not hold the requested memory and @exact_nid
1331 * allocation falls back to any node in the system1328 * is false, the allocation falls back to any node in the system.
1332 *1329 *
1333 * For systems with memory mirroring, the allocation is attempted first1330 * For systems with memory mirroring, the allocation is attempted first
1334 * from the regions with mirroring enabled and then retried from any1331 * from the regions with mirroring enabled and then retried from any
@@ -1342,7 +1339,8 @@ __next_mem_pfn_range_in_zone(u64 *idx, struct zone *zone, · 7 unmodified lines
1342 */1339 */
1343static phys_addr_t __init memblock_alloc_range_nid(phys_addr_t size,1340static phys_addr_t __init memblock_alloc_range_nid(phys_addr_t size,
1344 phys_addr_t align, phys_addr_t start,1341 phys_addr_t align, phys_addr_t start,
1345 phys_addr_t end, int nid)1342 phys_addr_t end, int nid,
1343 bool exact_nid)
1346{1344{
1347 enum memblock_flags flags = choose_memblock_flags();1345 enum memblock_flags flags = choose_memblock_flags();
1348 phys_addr_t found;1346 phys_addr_t found;
@@ -1362,7 +1360,7 @@ again: · 13 unmodified lines
1362 if (found && !memblock_reserve(found, size))1360 if (found && !memblock_reserve(found, size))
1363 goto done;1361 goto done;
1364 1362
1365 if (nid != NUMA_NO_NODE) {1363 if (nid != NUMA_NO_NODE && !exact_nid) {
1366 found = memblock_find_in_range_node(size, align, start,1364 found = memblock_find_in_range_node(size, align, start,
1367 end, NUMA_NO_NODE,1365 end, NUMA_NO_NODE,
1368 flags);1366 flags);
@@ -1410,7 +1408,8 @@ phys_addr_t __init memblock_phys_alloc_range(phys_addr_t size, · 41 unmodified lines
1410 phys_addr_t start,1408 phys_addr_t start,
1411 phys_addr_t end)1409 phys_addr_t end)
1412{1410{
1413 return memblock_alloc_range_nid(size, align, start, end, NUMA_NO_NODE);1411 return memblock_alloc_range_nid(size, align, start, end, NUMA_NO_NODE,
1412 false);
1414}1413}
1415 1414
1416/**1415/**
@@ -1429,7 +1428,7 @@ phys_addr_t __init memblock_phys_alloc_range(phys_addr_t size, · 12 unmodified lines
1429phys_addr_t __init memblock_phys_alloc_try_nid(phys_addr_t size, phys_addr_t align, int nid)1428phys_addr_t __init memblock_phys_alloc_try_nid(phys_addr_t size, phys_addr_t align, int nid)
1430{1429{
1431 return memblock_alloc_range_nid(size, align, 0,1430 return memblock_alloc_range_nid(size, align, 0,
1432 MEMBLOCK_ALLOC_ACCESSIBLE, nid);1431 MEMBLOCK_ALLOC_ACCESSIBLE, nid, false);
1433}1432}
1434 1433
1435/**1434/**
@@ -1439,6 +1438,7 @@ phys_addr_t __init memblock_phys_alloc_try_nid(phys_addr_t size, phys_addr_t ali · 3 unmodified lines
1439 * @min_addr: the lower bound of the memory region to allocate (phys address)1438 * @min_addr: the lower bound of the memory region to allocate (phys address)
1440 * @max_addr: the upper bound of the memory region to allocate (phys address)1439 * @max_addr: the upper bound of the memory region to allocate (phys address)
1441 * @nid: nid of the free area to find, %NUMA_NO_NODE for any node1440 * @nid: nid of the free area to find, %NUMA_NO_NODE for any node
1441 * @exact_nid: control the allocation fall back to other nodes
1442 *1442 *
1443 * Allocates memory block using memblock_alloc_range_nid() and1443 * Allocates memory block using memblock_alloc_range_nid() and
1444 * converts the returned physical address to virtual.1444 * converts the returned physical address to virtual.
@@ -1454,7 +1454,7 @@ phys_addr_t __init memblock_phys_alloc_try_nid(phys_addr_t size, phys_addr_t ali · 9 unmodified lines
1454static void * __init memblock_alloc_internal(1454static void * __init memblock_alloc_internal(
1455 phys_addr_t size, phys_addr_t align,1455 phys_addr_t size, phys_addr_t align,
1456 phys_addr_t min_addr, phys_addr_t max_addr,1456 phys_addr_t min_addr, phys_addr_t max_addr,
1457 int nid)1457 int nid, bool exact_nid)
1458{1458{
1459 phys_addr_t alloc;1459 phys_addr_t alloc;
1460 1460
@@ -1469,11 +1469,13 @@ static void * __init memblock_alloc_internal( · 8 unmodified lines
1469 if (max_addr > memblock.current_limit)1469 if (max_addr > memblock.current_limit)
1470 max_addr = memblock.current_limit;1470 max_addr = memblock.current_limit;
1471 1471
1472 alloc = memblock_alloc_range_nid(size, align, min_addr, max_addr, nid);1472 alloc = memblock_alloc_range_nid(size, align, min_addr, max_addr, nid,
1473 exact_nid);
1473 1474
1474 /* retry allocation without lower limit */1475 /* retry allocation without lower limit */
1475 if (!alloc && min_addr)1476 if (!alloc && min_addr)
1476 alloc = memblock_alloc_range_nid(size, align, 0, max_addr, nid);1477 alloc = memblock_alloc_range_nid(size, align, 0, max_addr, nid,
1478 exact_nid);
1477 1479
1478 if (!alloc)1480 if (!alloc)
1479 return NULL;1481 return NULL;
@@ -1481,6 +1483,43 @@ static void * __init memblock_alloc_internal( · 1 unmodified line
1481 return phys_to_virt(alloc);1483 return phys_to_virt(alloc);
1482}1484}
1483 1485
1486/**
1487 * memblock_alloc_exact_nid_raw - allocate boot memory block on the exact node
1488 * without zeroing memory
1489 * @size: size of memory block to be allocated in bytes
1490 * @align: alignment of the region and block's size
1491 * @min_addr: the lower bound of the memory region from where the allocation
1492 * is preferred (phys address)
1493 * @max_addr: the upper bound of the memory region from where the allocation
1494 * is preferred (phys address), or %MEMBLOCK_ALLOC_ACCESSIBLE to
1495 * allocate only from memory limited by memblock.current_limit value
1496 * @nid: nid of the free area to find, %NUMA_NO_NODE for any node
1497 *
1498 * Public function, provides additional debug information (including caller
1499 * info), if enabled. Does not zero allocated memory.
1500 *
1501 * Return:
1502 * Virtual address of allocated memory block on success, NULL on failure.
1503 */
1504void * __init memblock_alloc_exact_nid_raw(
1505 phys_addr_t size, phys_addr_t align,
1506 phys_addr_t min_addr, phys_addr_t max_addr,
1507 int nid)
1508{
1509 void *ptr;
1510
1511 memblock_dbg("%s: %llu bytes align=0x%llx nid=%d from=%pa max_addr=%pa %pS\n",
1512 __func__, (u64)size, (u64)align, nid, &min_addr,
1513 &max_addr, (void *)_RET_IP_);
1514
1515 ptr = memblock_alloc_internal(size, align,
1516 min_addr, max_addr, nid, true);
1517 if (ptr && size > 0)
1518 page_init_poison(ptr, size);
1519
1520 return ptr;
1521}
1522
1484/**1523/**
1485 * memblock_alloc_try_nid_raw - allocate boot memory block without zeroing1524 * memblock_alloc_try_nid_raw - allocate boot memory block without zeroing
1486 * memory and without panicking1525 * memory and without panicking
@@ -1512,7 +1551,7 @@ void * __init memblock_alloc_try_nid_raw( · 25 unmodified lines
1512 &max_addr, (void *)_RET_IP_);1551 &max_addr, (void *)_RET_IP_);
1513 1552
1514 ptr = memblock_alloc_internal(size, align,1553 ptr = memblock_alloc_internal(size, align,
1515 min_addr, max_addr, nid);1554 min_addr, max_addr, nid, false);
1516 if (ptr && size > 0)1555 if (ptr && size > 0)
1517 page_init_poison(ptr, size);1556 page_init_poison(ptr, size);
1518 1557
@@ -1547,7 +1586,7 @@ void * __init memblock_alloc_try_nid( · 28 unmodified lines
1547 __func__, (u64)size, (u64)align, nid, &min_addr,1586 __func__, (u64)size, (u64)align, nid, &min_addr,
1548 &max_addr, (void *)_RET_IP_);1587 &max_addr, (void *)_RET_IP_);
1549 ptr = memblock_alloc_internal(size, align,1588 ptr = memblock_alloc_internal(size, align,
1550 min_addr, max_addr, nid);1589 min_addr, max_addr, nid, false);
1551 if (ptr)1590 if (ptr)
1552 memset(ptr, 0, size);1591 memset(ptr, 0, size);
1553 1592
mm/memcontrol.c+33−134
@@ -108,7 +108,6 @@ static const char *const mem_cgroup_lru_names[] = { · 107 unmodified lines
108 108
109#define THRESHOLDS_EVENTS_TARGET 128109#define THRESHOLDS_EVENTS_TARGET 128
110#define SOFTLIMIT_EVENTS_TARGET 1024110#define SOFTLIMIT_EVENTS_TARGET 1024
111#define NUMAINFO_EVENTS_TARGET 1024
112 111
113/*112/*
114 * Cgroups above their limits are maintained in a RB-Tree, independent of113 * Cgroups above their limits are maintained in a RB-Tree, independent of
@@ -778,7 +777,7 @@ void __mod_lruvec_slab_state(void *p, enum node_stat_item idx, int val) · 663 unmodified lines
778 if (!memcg || memcg == root_mem_cgroup) {777 if (!memcg || memcg == root_mem_cgroup) {
779 __mod_node_page_state(pgdat, idx, val);778 __mod_node_page_state(pgdat, idx, val);
780 } else {779 } else {
781 lruvec = mem_cgroup_lruvec(pgdat, memcg);780 lruvec = mem_cgroup_lruvec(memcg, pgdat);
782 __mod_lruvec_state(lruvec, idx, val);781 __mod_lruvec_state(lruvec, idx, val);
783 }782 }
784 rcu_read_unlock();783 rcu_read_unlock();
@@ -877,9 +876,6 @@ static bool mem_cgroup_event_ratelimit(struct mem_cgroup *memcg, · 92 unmodified lines
877 case MEM_CGROUP_TARGET_SOFTLIMIT:876 case MEM_CGROUP_TARGET_SOFTLIMIT:
878 next = val + SOFTLIMIT_EVENTS_TARGET;877 next = val + SOFTLIMIT_EVENTS_TARGET;
879 break;878 break;
880 case MEM_CGROUP_TARGET_NUMAINFO:
881 next = val + NUMAINFO_EVENTS_TARGET;
882 break;
883 default:879 default:
884 break;880 break;
885 }881 }
@@ -899,21 +895,12 @@ static void memcg_check_events(struct mem_cgroup *memcg, struct page *page) · 13 unmodified lines
899 if (unlikely(mem_cgroup_event_ratelimit(memcg,895 if (unlikely(mem_cgroup_event_ratelimit(memcg,
900 MEM_CGROUP_TARGET_THRESH))) {896 MEM_CGROUP_TARGET_THRESH))) {
901 bool do_softlimit;897 bool do_softlimit;
902 bool do_numainfo __maybe_unused;
903 898
904 do_softlimit = mem_cgroup_event_ratelimit(memcg,899 do_softlimit = mem_cgroup_event_ratelimit(memcg,
905 MEM_CGROUP_TARGET_SOFTLIMIT);900 MEM_CGROUP_TARGET_SOFTLIMIT);
906#if MAX_NUMNODES > 1
907 do_numainfo = mem_cgroup_event_ratelimit(memcg,
908 MEM_CGROUP_TARGET_NUMAINFO);
909#endif
910 mem_cgroup_threshold(memcg);901 mem_cgroup_threshold(memcg);
911 if (unlikely(do_softlimit))902 if (unlikely(do_softlimit))
912 mem_cgroup_update_tree(memcg, page);903 mem_cgroup_update_tree(memcg, page);
913#if MAX_NUMNODES > 1
914 if (unlikely(do_numainfo))
915 atomic_inc(&memcg->numainfo_events);
916#endif
917 }904 }
918}905}
919 906
@@ -1052,7 +1039,7 @@ struct mem_cgroup *mem_cgroup_iter(struct mem_cgroup *root, · 132 unmodified lines
1052 struct mem_cgroup_per_node *mz;1039 struct mem_cgroup_per_node *mz;
1053 1040
1054 mz = mem_cgroup_nodeinfo(root, reclaim->pgdat->node_id);1041 mz = mem_cgroup_nodeinfo(root, reclaim->pgdat->node_id);
1055 iter = &mz->iter[reclaim->priority];1042 iter = &mz->iter;
1056 1043
1057 if (prev && reclaim->generation != iter->generation)1044 if (prev && reclaim->generation != iter->generation)
1058 goto out_unlock;1045 goto out_unlock;
@@ -1152,15 +1139,11 @@ static void __invalidate_reclaim_iterators(struct mem_cgroup *from, · 93 unmodified lines
1152 struct mem_cgroup_reclaim_iter *iter;1139 struct mem_cgroup_reclaim_iter *iter;
1153 struct mem_cgroup_per_node *mz;1140 struct mem_cgroup_per_node *mz;
1154 int nid;1141 int nid;
1155 int i;
1156 1142
1157 for_each_node(nid) {1143 for_each_node(nid) {
1158 mz = mem_cgroup_nodeinfo(from, nid);1144 mz = mem_cgroup_nodeinfo(from, nid);
1159 for (i = 0; i <= DEF_PRIORITY; i++) {1145 iter = &mz->iter;
1160 iter = &mz->iter[i];1146 cmpxchg(&iter->position, dead_memcg, NULL);
1161 cmpxchg(&iter->position,
1162 dead_memcg, NULL);
1163 }
1164 }1147 }
1165}1148}
1166 1149
@@ -1238,7 +1221,7 @@ struct lruvec *mem_cgroup_page_lruvec(struct page *page, struct pglist_data *pgd · 71 unmodified lines
1238 struct lruvec *lruvec;1221 struct lruvec *lruvec;
1239 1222
1240 if (mem_cgroup_disabled()) {1223 if (mem_cgroup_disabled()) {
1241 lruvec = &pgdat->lruvec;1224 lruvec = &pgdat->__lruvec;
1242 goto out;1225 goto out;
1243 }1226 }
1244 1227
@@ -1595,104 +1578,6 @@ static bool mem_cgroup_out_of_memory(struct mem_cgroup *memcg, gfp_t gfp_mask, · 350 unmodified lines
1595 return ret;1578 return ret;
1596}1579}
1597 1580
1598#if MAX_NUMNODES > 1
1599
1600/**
1601 * test_mem_cgroup_node_reclaimable
1602 * @memcg: the target memcg
1603 * @nid: the node ID to be checked.
1604 * @noswap : specify true here if the user wants flle only information.
1605 *
1606 * This function returns whether the specified memcg contains any
1607 * reclaimable pages on a node. Returns true if there are any reclaimable
1608 * pages in the node.
1609 */
1610static bool test_mem_cgroup_node_reclaimable(struct mem_cgroup *memcg,
1611 int nid, bool noswap)
1612{
1613 struct lruvec *lruvec = mem_cgroup_lruvec(NODE_DATA(nid), memcg);
1614
1615 if (lruvec_page_state(lruvec, NR_INACTIVE_FILE) ||
1616 lruvec_page_state(lruvec, NR_ACTIVE_FILE))
1617 return true;
1618 if (noswap || !total_swap_pages)
1619 return false;
1620 if (lruvec_page_state(lruvec, NR_INACTIVE_ANON) ||
1621 lruvec_page_state(lruvec, NR_ACTIVE_ANON))
1622 return true;
1623 return false;
1624
1625}
1626
1627/*
1628 * Always updating the nodemask is not very good - even if we have an empty
1629 * list or the wrong list here, we can start from some node and traverse all
1630 * nodes based on the zonelist. So update the list loosely once per 10 secs.
1631 *
1632 */
1633static void mem_cgroup_may_update_nodemask(struct mem_cgroup *memcg)
1634{
1635 int nid;
1636 /*
1637 * numainfo_events > 0 means there was at least NUMAINFO_EVENTS_TARGET
1638 * pagein/pageout changes since the last update.
1639 */
1640 if (!atomic_read(&memcg->numainfo_events))
1641 return;
1642 if (atomic_inc_return(&memcg->numainfo_updating) > 1)
1643 return;
1644
1645 /* make a nodemask where this memcg uses memory from */
1646 memcg->scan_nodes = node_states[N_MEMORY];
1647
1648 for_each_node_mask(nid, node_states[N_MEMORY]) {
1649
1650 if (!test_mem_cgroup_node_reclaimable(memcg, nid, false))
1651 node_clear(nid, memcg->scan_nodes);
1652 }
1653
1654 atomic_set(&memcg->numainfo_events, 0);
1655 atomic_set(&memcg->numainfo_updating, 0);
1656}
1657
1658/*
1659 * Selecting a node where we start reclaim from. Because what we need is just
1660 * reducing usage counter, start from anywhere is O,K. Considering
1661 * memory reclaim from current node, there are pros. and cons.
1662 *
1663 * Freeing memory from current node means freeing memory from a node which
1664 * we'll use or we've used. So, it may make LRU bad. And if several threads
1665 * hit limits, it will see a contention on a node. But freeing from remote
1666 * node means more costs for memory reclaim because of memory latency.
1667 *
1668 * Now, we use round-robin. Better algorithm is welcomed.
1669 */
1670int mem_cgroup_select_victim_node(struct mem_cgroup *memcg)
1671{
1672 int node;
1673
1674 mem_cgroup_may_update_nodemask(memcg);
1675 node = memcg->last_scanned_node;
1676
1677 node = next_node_in(node, memcg->scan_nodes);
1678 /*
1679 * mem_cgroup_may_update_nodemask might have seen no reclaimmable pages
1680 * last time it really checked all the LRUs due to rate limiting.
1681 * Fallback to the current node in that case for simplicity.
1682 */
1683 if (unlikely(node == MAX_NUMNODES))
1684 node = numa_node_id();
1685
1686 memcg->last_scanned_node = node;
1687 return node;
1688}
1689#else
1690int mem_cgroup_select_victim_node(struct mem_cgroup *memcg)
1691{
1692 return 0;
1693}
1694#endif
1695
1696static int mem_cgroup_soft_reclaim(struct mem_cgroup *root_memcg,1581static int mem_cgroup_soft_reclaim(struct mem_cgroup *root_memcg,
1697 pg_data_t *pgdat,1582 pg_data_t *pgdat,
1698 gfp_t gfp_mask,1583 gfp_t gfp_mask,
@@ -1705,7 +1590,6 @@ static int mem_cgroup_soft_reclaim(struct mem_cgroup *root_memcg, · 6 unmodified lines
1705 unsigned long nr_scanned;1590 unsigned long nr_scanned;
1706 struct mem_cgroup_reclaim_cookie reclaim = {1591 struct mem_cgroup_reclaim_cookie reclaim = {
1707 .pgdat = pgdat,1592 .pgdat = pgdat,
1708 .priority = 0,
1709 };1593 };
1710 1594
1711 excess = soft_limit_excess(root_memcg);1595 excess = soft_limit_excess(root_memcg);
@@ -3750,7 +3634,7 @@ static int mem_cgroup_move_charge_write(struct cgroup_subsys_state *css, · 2038 unmodified lines
3750static unsigned long mem_cgroup_node_nr_lru_pages(struct mem_cgroup *memcg,3634static unsigned long mem_cgroup_node_nr_lru_pages(struct mem_cgroup *memcg,
3751 int nid, unsigned int lru_mask)3635 int nid, unsigned int lru_mask)
3752{3636{
3753 struct lruvec *lruvec = mem_cgroup_lruvec(NODE_DATA(nid), memcg);3637 struct lruvec *lruvec = mem_cgroup_lruvec(memcg, NODE_DATA(nid));
3754 unsigned long nr = 0;3638 unsigned long nr = 0;
3755 enum lru_list lru;3639 enum lru_list lru;
3756 3640
@@ -5078,7 +4962,6 @@ static struct mem_cgroup *mem_cgroup_alloc(void) · 1321 unmodified lines
5078 goto fail;4962 goto fail;
5079 4963
5080 INIT_WORK(&memcg->high_work, high_work_func);4964 INIT_WORK(&memcg->high_work, high_work_func);
5081 memcg->last_scanned_node = MAX_NUMNODES;
5082 INIT_LIST_HEAD(&memcg->oom_notify);4965 INIT_LIST_HEAD(&memcg->oom_notify);
5083 mutex_init(&memcg->thresholds_lock);4966 mutex_init(&memcg->thresholds_lock);
5084 spin_lock_init(&memcg->move_lock);4967 spin_lock_init(&memcg->move_lock);
@@ -5455,8 +5338,8 @@ static int mem_cgroup_move_account(struct page *page, · 370 unmodified lines
5455 anon = PageAnon(page);5338 anon = PageAnon(page);
5456 5339
5457 pgdat = page_pgdat(page);5340 pgdat = page_pgdat(page);
5458 from_vec = mem_cgroup_lruvec(pgdat, from);5341 from_vec = mem_cgroup_lruvec(from, pgdat);
5459 to_vec = mem_cgroup_lruvec(pgdat, to);5342 to_vec = mem_cgroup_lruvec(to, pgdat);
5460 5343
5461 spin_lock_irqsave(&from->move_lock, flags);5344 spin_lock_irqsave(&from->move_lock, flags);
5462 5345
@@ -6096,7 +5979,8 @@ static ssize_t memory_high_write(struct kernfs_open_file *of, · 633 unmodified lines
6096 char *buf, size_t nbytes, loff_t off)5979 char *buf, size_t nbytes, loff_t off)
6097{5980{
6098 struct mem_cgroup *memcg = mem_cgroup_from_css(of_css(of));5981 struct mem_cgroup *memcg = mem_cgroup_from_css(of_css(of));
6099 unsigned long nr_pages;5982 unsigned int nr_retries = MEM_CGROUP_RECLAIM_RETRIES;
5983 bool drained = false;
6100 unsigned long high;5984 unsigned long high;
6101 int err;5985 int err;
6102 5986
@@ -6107,12 +5991,29 @@ static ssize_t memory_high_write(struct kernfs_open_file *of, · 4 unmodified lines
6107 5991
6108 memcg->high = high;5992 memcg->high = high;
6109 5993
6110 nr_pages = page_counter_read(&memcg->memory);5994 for (;;) {
6111 if (nr_pages > high)5995 unsigned long nr_pages = page_counter_read(&memcg->memory);
6112 try_to_free_mem_cgroup_pages(memcg, nr_pages - high,5996 unsigned long reclaimed;
6113 GFP_KERNEL, true);5997
5998 if (nr_pages <= high)
5999 break;
6000
6001 if (signal_pending(current))
6002 break;
6003
6004 if (!drained) {
6005 drain_all_stock(memcg);
6006 drained = true;
6007 continue;
6008 }
6009
6010 reclaimed = try_to_free_mem_cgroup_pages(memcg, nr_pages - high,
6011 GFP_KERNEL, true);
6012
6013 if (!reclaimed && !nr_retries--)
6014 break;
6015 }
6114 6016
6115 memcg_wb_domain_size_changed(memcg);
6116 return nbytes;6017 return nbytes;
6117}6018}
6118 6019
@@ -6144,10 +6045,8 @@ static ssize_t memory_max_write(struct kernfs_open_file *of, · 25 unmodified lines
6144 if (nr_pages <= max)6045 if (nr_pages <= max)
6145 break;6046 break;
6146 6047
6147 if (signal_pending(current)) {6048 if (signal_pending(current))
6148 err = -EINTR;
6149 break;6049 break;
6150 }
6151 6050
6152 if (!drained) {6051 if (!drained) {
6153 drain_all_stock(memcg);6052 drain_all_stock(memcg);
mm/memory-failure.c+23−38
@@ -303,30 +303,24 @@ static unsigned long dev_pagemap_mapping_shift(struct page *page, · 302 unmodified lines
303/*303/*
304 * Schedule a process for later kill.304 * Schedule a process for later kill.
305 * Uses GFP_ATOMIC allocations to avoid potential recursions in the VM.305 * Uses GFP_ATOMIC allocations to avoid potential recursions in the VM.
306 * TBD would GFP_NOIO be enough?
307 */306 */
308static void add_to_kill(struct task_struct *tsk, struct page *p,307static void add_to_kill(struct task_struct *tsk, struct page *p,
309 struct vm_area_struct *vma,308 struct vm_area_struct *vma,
310 struct list_head *to_kill,309 struct list_head *to_kill)
311 struct to_kill **tkc)
312{310{
313 struct to_kill *tk;311 struct to_kill *tk;
314 312
315 if (*tkc) {313 tk = kmalloc(sizeof(struct to_kill), GFP_ATOMIC);
316 tk = *tkc;314 if (!tk) {
317 *tkc = NULL;315 pr_err("Memory failure: Out of memory while machine check handling\n");
318 } else {316 return;
319 tk = kmalloc(sizeof(struct to_kill), GFP_ATOMIC);
320 if (!tk) {
321 pr_err("Memory failure: Out of memory while machine check handling\n");
322 return;
323 }
324 }317 }
318
325 tk->addr = page_address_in_vma(p, vma);319 tk->addr = page_address_in_vma(p, vma);
326 if (is_zone_device_page(p))320 if (is_zone_device_page(p))
327 tk->size_shift = dev_pagemap_mapping_shift(p, vma);321 tk->size_shift = dev_pagemap_mapping_shift(p, vma);
328 else322 else
329 tk->size_shift = compound_order(compound_head(p)) + PAGE_SHIFT;323 tk->size_shift = page_shift(compound_head(p));
330 324
331 /*325 /*
332 * Send SIGKILL if "tk->addr == -EFAULT". Also, as326 * Send SIGKILL if "tk->addr == -EFAULT". Also, as
@@ -345,6 +339,7 @@ static void add_to_kill(struct task_struct *tsk, struct page *p, · 12 unmodified lines
345 kfree(tk);339 kfree(tk);
346 return;340 return;
347 }341 }
342
348 get_task_struct(tsk);343 get_task_struct(tsk);
349 tk->tsk = tsk;344 tk->tsk = tsk;
350 list_add_tail(&tk->nd, to_kill);345 list_add_tail(&tk->nd, to_kill);
@@ -436,7 +431,7 @@ static struct task_struct *task_early_kill(struct task_struct *tsk, · 85 unmodified lines
436 * Collect processes when the error hit an anonymous page.431 * Collect processes when the error hit an anonymous page.
437 */432 */
438static void collect_procs_anon(struct page *page, struct list_head *to_kill,433static void collect_procs_anon(struct page *page, struct list_head *to_kill,
439 struct to_kill **tkc, int force_early)434 int force_early)
440{435{
441 struct vm_area_struct *vma;436 struct vm_area_struct *vma;
442 struct task_struct *tsk;437 struct task_struct *tsk;
@@ -461,7 +456,7 @@ static void collect_procs_anon(struct page *page, struct list_head *to_kill, · 18 unmodified lines
461 if (!page_mapped_in_vma(page, vma))456 if (!page_mapped_in_vma(page, vma))
462 continue;457 continue;
463 if (vma->vm_mm == t->mm)458 if (vma->vm_mm == t->mm)
464 add_to_kill(t, page, vma, to_kill, tkc);459 add_to_kill(t, page, vma, to_kill);
465 }460 }
466 }461 }
467 read_unlock(&tasklist_lock);462 read_unlock(&tasklist_lock);
@@ -472,7 +467,7 @@ static void collect_procs_anon(struct page *page, struct list_head *to_kill, · 4 unmodified lines
472 * Collect processes when the error hit a file mapped page.467 * Collect processes when the error hit a file mapped page.
473 */468 */
474static void collect_procs_file(struct page *page, struct list_head *to_kill,469static void collect_procs_file(struct page *page, struct list_head *to_kill,
475 struct to_kill **tkc, int force_early)470 int force_early)
476{471{
477 struct vm_area_struct *vma;472 struct vm_area_struct *vma;
478 struct task_struct *tsk;473 struct task_struct *tsk;
@@ -496,7 +491,7 @@ static void collect_procs_file(struct page *page, struct list_head *to_kill, · 17 unmodified lines
496 * to be informed of all such data corruptions.491 * to be informed of all such data corruptions.
497 */492 */
498 if (vma->vm_mm == t->mm)493 if (vma->vm_mm == t->mm)
499 add_to_kill(t, page, vma, to_kill, tkc);494 add_to_kill(t, page, vma, to_kill);
500 }495 }
501 }496 }
502 read_unlock(&tasklist_lock);497 read_unlock(&tasklist_lock);
@@ -505,26 +500,17 @@ static void collect_procs_file(struct page *page, struct list_head *to_kill, · 2 unmodified lines
505 500
506/*501/*
507 * Collect the processes who have the corrupted page mapped to kill.502 * Collect the processes who have the corrupted page mapped to kill.
508 * This is done in two steps for locking reasons.
509 * First preallocate one tokill structure outside the spin locks,
510 * so that we can kill at least one process reasonably reliable.
511 */503 */
512static void collect_procs(struct page *page, struct list_head *tokill,504static void collect_procs(struct page *page, struct list_head *tokill,
513 int force_early)505 int force_early)
514{506{
515 struct to_kill *tk;
516
517 if (!page->mapping)507 if (!page->mapping)
518 return;508 return;
519 509
520 tk = kmalloc(sizeof(struct to_kill), GFP_NOIO);
521 if (!tk)
522 return;
523 if (PageAnon(page))510 if (PageAnon(page))
524 collect_procs_anon(page, tokill, &tk, force_early);511 collect_procs_anon(page, tokill, force_early);
525 else512 else
526 collect_procs_file(page, tokill, &tk, force_early);513 collect_procs_file(page, tokill, force_early);
527 kfree(tk);
528}514}
529 515
530static const char *action_name[] = {516static const char *action_name[] = {
@@ -1490,7 +1476,7 @@ static void memory_failure_work_func(struct work_struct *work) · 959 unmodified lines
1490 if (!gotten)1476 if (!gotten)
1491 break;1477 break;
1492 if (entry.flags & MF_SOFT_OFFLINE)1478 if (entry.flags & MF_SOFT_OFFLINE)
1493 soft_offline_page(pfn_to_page(entry.pfn), entry.flags);1479 soft_offline_page(entry.pfn, entry.flags);
1494 else1480 else
1495 memory_failure(entry.pfn, entry.flags);1481 memory_failure(entry.pfn, entry.flags);
1496 }1482 }
@@ -1871,7 +1857,7 @@ static int soft_offline_free_page(struct page *page) · 374 unmodified lines
1871 1857
1872/**1858/**
1873 * soft_offline_page - Soft offline a page.1859 * soft_offline_page - Soft offline a page.
1874 * @page: page to offline1860 * @pfn: pfn to soft-offline
1875 * @flags: flags. Same as memory_failure().1861 * @flags: flags. Same as memory_failure().
1876 *1862 *
1877 * Returns 0 on success, otherwise negated errno.1863 * Returns 0 on success, otherwise negated errno.
@@ -1891,18 +1877,17 @@ static int soft_offline_free_page(struct page *page) · 13 unmodified lines
1891 * This is not a 100% solution for all memory, but tries to be1877 * This is not a 100% solution for all memory, but tries to be
1892 * ``good enough'' for the majority of memory.1878 * ``good enough'' for the majority of memory.
1893 */1879 */
1894int soft_offline_page(struct page *page, int flags)1880int soft_offline_page(unsigned long pfn, int flags)
1895{1881{
1896 int ret;1882 int ret;
1897 unsigned long pfn = page_to_pfn(page);1883 struct page *page;
1898 1884
1899 if (is_zone_device_page(page)) {1885 if (!pfn_valid(pfn))
1900 pr_debug_ratelimited("soft_offline: %#lx page is device page\n",1886 return -ENXIO;
1901 pfn);1887 /* Only online pages can be soft-offlined (esp., not ZONE_DEVICE). */
1902 if (flags & MF_COUNT_INCREASED)1888 page = pfn_to_online_page(pfn);
1903 put_page(page);1889 if (!page)
1904 return -EIO;1890 return -EIO;
1905 }
1906 1891
1907 if (PageHWPoison(page)) {1892 if (PageHWPoison(page)) {
1908 pr_info("soft offline: %#lx page already poisoned\n", pfn);1893 pr_info("soft offline: %#lx page already poisoned\n", pfn);
mm/memory.c+40−12
@@ -72,6 +72,8 @@ · 71 unmodified lines
72#include <linux/oom.h>72#include <linux/oom.h>
73#include <linux/numa.h>73#include <linux/numa.h>
74 74
75#include <trace/events/kmem.h>
76
75#include <asm/io.h>77#include <asm/io.h>
76#include <asm/mmu_context.h>78#include <asm/mmu_context.h>
77#include <asm/pgalloc.h>79#include <asm/pgalloc.h>
@@ -152,6 +154,10 @@ static int __init init_zero_pfn(void) · 74 unmodified lines
152}154}
153core_initcall(init_zero_pfn);155core_initcall(init_zero_pfn);
154 156
157void mm_trace_rss_stat(struct mm_struct *mm, int member, long count)
158{
159 trace_rss_stat(mm, member, count);
160}
155 161
156#if defined(SPLIT_RSS_COUNTING)162#if defined(SPLIT_RSS_COUNTING)
157 163
@@ -2289,10 +2295,11 @@ static vm_fault_t do_page_mkwrite(struct vm_fault *vmf) · 2131 unmodified lines
2289 *2295 *
2290 * The function expects the page to be locked and unlocks it.2296 * The function expects the page to be locked and unlocks it.
2291 */2297 */
2292static void fault_dirty_shared_page(struct vm_area_struct *vma,2298static vm_fault_t fault_dirty_shared_page(struct vm_fault *vmf)
2293 struct page *page)
2294{2299{
2300 struct vm_area_struct *vma = vmf->vma;
2295 struct address_space *mapping;2301 struct address_space *mapping;
2302 struct page *page = vmf->page;
2296 bool dirtied;2303 bool dirtied;
2297 bool page_mkwrite = vma->vm_ops && vma->vm_ops->page_mkwrite;2304 bool page_mkwrite = vma->vm_ops && vma->vm_ops->page_mkwrite;
2298 2305
@@ -2307,16 +2314,30 @@ static void fault_dirty_shared_page(struct vm_area_struct *vma, · 8 unmodified lines
2307 mapping = page_rmapping(page);2314 mapping = page_rmapping(page);
2308 unlock_page(page);2315 unlock_page(page);
2309 2316
2317 if (!page_mkwrite)
2318 file_update_time(vma->vm_file);
2319
2320 /*
2321 * Throttle page dirtying rate down to writeback speed.
2322 *
2323 * mapping may be NULL here because some device drivers do not
2324 * set page.mapping but still dirty their pages
2325 *
2326 * Drop the mmap_sem before waiting on IO, if we can. The file
2327 * is pinning the mapping, as per above.
2328 */
2310 if ((dirtied || page_mkwrite) && mapping) {2329 if ((dirtied || page_mkwrite) && mapping) {
2311 /*2330 struct file *fpin;
2312 * Some device drivers do not set page.mapping2331
2313 * but still dirty their pages2332 fpin = maybe_unlock_mmap_for_io(vmf, NULL);
2314 */
2315 balance_dirty_pages_ratelimited(mapping);2333 balance_dirty_pages_ratelimited(mapping);
2334 if (fpin) {
2335 fput(fpin);
2336 return VM_FAULT_RETRY;
2337 }
2316 }2338 }
2317 2339
2318 if (!page_mkwrite)2340 return 0;
2319 file_update_time(vma->vm_file);
2320}2341}
2321 2342
2322/*2343/*
@@ -2571,6 +2592,7 @@ static vm_fault_t wp_page_shared(struct vm_fault *vmf) · 248 unmodified lines
2571 __releases(vmf->ptl)2592 __releases(vmf->ptl)
2572{2593{
2573 struct vm_area_struct *vma = vmf->vma;2594 struct vm_area_struct *vma = vmf->vma;
2595 vm_fault_t ret = VM_FAULT_WRITE;
2574 2596
2575 get_page(vmf->page);2597 get_page(vmf->page);
2576 2598
@@ -2594,10 +2616,10 @@ static vm_fault_t wp_page_shared(struct vm_fault *vmf) · 17 unmodified lines
2594 wp_page_reuse(vmf);2616 wp_page_reuse(vmf);
2595 lock_page(vmf->page);2617 lock_page(vmf->page);
2596 }2618 }
2597 fault_dirty_shared_page(vma, vmf->page);2619 ret |= fault_dirty_shared_page(vmf);
2598 put_page(vmf->page);2620 put_page(vmf->page);
2599 2621
2600 return VM_FAULT_WRITE;2622 return ret;
2601}2623}
2602 2624
2603/*2625/*
@@ -3083,7 +3105,7 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf) · 479 unmodified lines
3083 3105
3084 /*3106 /*
3085 * The memory barrier inside __SetPageUptodate makes sure that3107 * The memory barrier inside __SetPageUptodate makes sure that
3086 * preceeding stores to the page contents become visible before3108 * preceding stores to the page contents become visible before
3087 * the set_pte_at() write.3109 * the set_pte_at() write.
3088 */3110 */
3089 __SetPageUptodate(page);3111 __SetPageUptodate(page);
@@ -3641,7 +3663,7 @@ static vm_fault_t do_shared_fault(struct vm_fault *vmf) · 551 unmodified lines
3641 return ret;3663 return ret;
3642 }3664 }
3643 3665
3644 fault_dirty_shared_page(vma, vmf->page);3666 ret |= fault_dirty_shared_page(vmf);
3645 return ret;3667 return ret;
3646}3668}
3647 3669
@@ -3988,6 +4010,7 @@ static vm_fault_t __handle_mm_fault(struct vm_area_struct *vma, · 340 unmodified lines
3988 vmf.pud = pud_alloc(mm, p4d, address);4010 vmf.pud = pud_alloc(mm, p4d, address);
3989 if (!vmf.pud)4011 if (!vmf.pud)
3990 return VM_FAULT_OOM;4012 return VM_FAULT_OOM;
4013retry_pud:
3991 if (pud_none(*vmf.pud) && __transparent_hugepage_enabled(vma)) {4014 if (pud_none(*vmf.pud) && __transparent_hugepage_enabled(vma)) {
3992 ret = create_huge_pud(&vmf);4015 ret = create_huge_pud(&vmf);
3993 if (!(ret & VM_FAULT_FALLBACK))4016 if (!(ret & VM_FAULT_FALLBACK))
@@ -4014,6 +4037,11 @@ static vm_fault_t __handle_mm_fault(struct vm_area_struct *vma, · 20 unmodified lines
4014 vmf.pmd = pmd_alloc(mm, vmf.pud, address);4037 vmf.pmd = pmd_alloc(mm, vmf.pud, address);
4015 if (!vmf.pmd)4038 if (!vmf.pmd)
4016 return VM_FAULT_OOM;4039 return VM_FAULT_OOM;
4040
4041 /* Huge pud page fault raced with pmd_alloc? */
4042 if (pud_trans_unstable(vmf.pud))
4043 goto retry_pud;
4044
4017 if (pmd_none(*vmf.pmd) && __transparent_hugepage_enabled(vma)) {4045 if (pmd_none(*vmf.pmd) && __transparent_hugepage_enabled(vma)) {
4018 ret = create_huge_pmd(&vmf);4046 ret = create_huge_pmd(&vmf);
4019 if (!(ret & VM_FAULT_FALLBACK))4047 if (!(ret & VM_FAULT_FALLBACK))
mm/memory_hotplug.c+56−30
@@ -49,8 +49,6 @@ · 48 unmodified lines
49 * and restore_online_page_callback() for generic callback restore.49 * and restore_online_page_callback() for generic callback restore.
50 */50 */
51 51
52static void generic_online_page(struct page *page, unsigned int order);
53
54static online_page_callback_t online_page_callback = generic_online_page;52static online_page_callback_t online_page_callback = generic_online_page;
55static DEFINE_MUTEX(online_page_callback_lock);53static DEFINE_MUTEX(online_page_callback_lock);
56 54
@@ -278,6 +276,22 @@ static int check_pfn_span(unsigned long pfn, unsigned long nr_pages, · 221 unmodified lines
278 return 0;276 return 0;
279}277}
280 278
279static int check_hotplug_memory_addressable(unsigned long pfn,
280 unsigned long nr_pages)
281{
282 const u64 max_addr = PFN_PHYS(pfn + nr_pages) - 1;
283
284 if (max_addr >> MAX_PHYSMEM_BITS) {
285 const u64 max_allowed = (1ull << (MAX_PHYSMEM_BITS + 1)) - 1;
286 WARN(1,
287 "Hotplugged memory exceeds maximum addressable address, range=%#llx-%#llx, maximum=%#llx\n",
288 (u64)PFN_PHYS(pfn), max_addr, max_allowed);
289 return -E2BIG;
290 }
291
292 return 0;
293}
294
281/*295/*
282 * Reasonably generic function for adding memory. It is296 * Reasonably generic function for adding memory. It is
283 * expected that archs that support memory hotplug will297 * expected that archs that support memory hotplug will
@@ -291,6 +305,10 @@ int __ref __add_pages(int nid, unsigned long pfn, unsigned long nr_pages, · 7 unmodified lines
291 unsigned long nr, start_sec, end_sec;305 unsigned long nr, start_sec, end_sec;
292 struct vmem_altmap *altmap = restrictions->altmap;306 struct vmem_altmap *altmap = restrictions->altmap;
293 307
308 err = check_hotplug_memory_addressable(pfn, nr_pages);
309 if (err)
310 return err;
311
294 if (altmap) {312 if (altmap) {
295 /*313 /*
296 * Validate altmap is within bounds of the total request314 * Validate altmap is within bounds of the total request
@@ -580,24 +598,7 @@ int restore_online_page_callback(online_page_callback_t callback) · 283 unmodified lines
580}598}
581EXPORT_SYMBOL_GPL(restore_online_page_callback);599EXPORT_SYMBOL_GPL(restore_online_page_callback);
582 600
583void __online_page_set_limits(struct page *page)601void generic_online_page(struct page *page, unsigned int order)
584{
585}
586EXPORT_SYMBOL_GPL(__online_page_set_limits);
587
588void __online_page_increment_counters(struct page *page)
589{
590 adjust_managed_page_count(page, 1);
591}
592EXPORT_SYMBOL_GPL(__online_page_increment_counters);
593
594void __online_page_free(struct page *page)
595{
596 __free_reserved_page(page);
597}
598EXPORT_SYMBOL_GPL(__online_page_free);
599
600static void generic_online_page(struct page *page, unsigned int order)
601{602{
602 kernel_map_pages(page, 1 << order, 1);603 kernel_map_pages(page, 1 << order, 1);
603 __free_pages_core(page, order);604 __free_pages_core(page, order);
@@ -607,6 +608,7 @@ static void generic_online_page(struct page *page, unsigned int order) · 3 unmodified lines
607 totalhigh_pages_add(1UL << order);608 totalhigh_pages_add(1UL << order);
608#endif609#endif
609}610}
611EXPORT_SYMBOL_GPL(generic_online_page);
610 612
611static int online_pages_range(unsigned long start_pfn, unsigned long nr_pages,613static int online_pages_range(unsigned long start_pfn, unsigned long nr_pages,
612 void *arg)614 void *arg)
@@ -1180,7 +1182,8 @@ static bool is_pageblock_removable_nolock(unsigned long pfn) · 567 unmodified lines
1180 if (!zone_spans_pfn(zone, pfn))1182 if (!zone_spans_pfn(zone, pfn))
1181 return false;1183 return false;
1182 1184
1183 return !has_unmovable_pages(zone, page, 0, MIGRATE_MOVABLE, SKIP_HWPOISON);1185 return !has_unmovable_pages(zone, page, 0, MIGRATE_MOVABLE,
1186 MEMORY_OFFLINE);
1184}1187}
1185 1188
1186/* Checks if this range of memory is likely to be hot-removable. */1189/* Checks if this range of memory is likely to be hot-removable. */
@@ -1377,9 +1380,7 @@ do_migrate_range(unsigned long start_pfn, unsigned long end_pfn) · 190 unmodified lines
1377 return ret;1380 return ret;
1378}1381}
1379 1382
1380/*1383/* Mark all sections offline and remove all free pages from the buddy. */
1381 * remove from free_area[] and mark all as Reserved.
1382 */
1383static int1384static int
1384offline_isolated_pages_cb(unsigned long start, unsigned long nr_pages,1385offline_isolated_pages_cb(unsigned long start, unsigned long nr_pages,
1385 void *data)1386 void *data)
@@ -1397,7 +1398,8 @@ static int · 11 unmodified lines
1397check_pages_isolated_cb(unsigned long start_pfn, unsigned long nr_pages,1398check_pages_isolated_cb(unsigned long start_pfn, unsigned long nr_pages,
1398 void *data)1399 void *data)
1399{1400{
1400 return test_pages_isolated(start_pfn, start_pfn + nr_pages, true);1401 return test_pages_isolated(start_pfn, start_pfn + nr_pages,
1402 MEMORY_OFFLINE);
1401}1403}
1402 1404
1403static int __init cmdline_parse_movable_node(char *p)1405static int __init cmdline_parse_movable_node(char *p)
@@ -1478,10 +1480,19 @@ static void node_states_clear_node(int node, struct memory_notify *arg) · 74 unmodified lines
1478 node_clear_state(node, N_MEMORY);1480 node_clear_state(node, N_MEMORY);
1479}1481}
1480 1482
1483static int count_system_ram_pages_cb(unsigned long start_pfn,
1484 unsigned long nr_pages, void *data)
1485{
1486 unsigned long *nr_system_ram_pages = data;
1487
1488 *nr_system_ram_pages += nr_pages;
1489 return 0;
1490}
1491
1481static int __ref __offline_pages(unsigned long start_pfn,1492static int __ref __offline_pages(unsigned long start_pfn,
1482 unsigned long end_pfn)1493 unsigned long end_pfn)
1483{1494{
1484 unsigned long pfn, nr_pages;1495 unsigned long pfn, nr_pages = 0;
1485 unsigned long offlined_pages = 0;1496 unsigned long offlined_pages = 0;
1486 int ret, node, nr_isolate_pageblock;1497 int ret, node, nr_isolate_pageblock;
1487 unsigned long flags;1498 unsigned long flags;
@@ -1492,6 +1503,22 @@ static int __ref __offline_pages(unsigned long start_pfn, · 4 unmodified lines
1492 1503
1493 mem_hotplug_begin();1504 mem_hotplug_begin();
1494 1505
1506 /*
1507 * Don't allow to offline memory blocks that contain holes.
1508 * Consequently, memory blocks with holes can never get onlined
1509 * via the hotplug path - online_pages() - as hotplugged memory has
1510 * no holes. This way, we e.g., don't have to worry about marking
1511 * memory holes PG_reserved, don't need pfn_valid() checks, and can
1512 * avoid using walk_system_ram_range() later.
1513 */
1514 walk_system_ram_range(start_pfn, end_pfn - start_pfn, &nr_pages,
1515 count_system_ram_pages_cb);
1516 if (nr_pages != end_pfn - start_pfn) {
1517 ret = -EINVAL;
1518 reason = "memory holes";
1519 goto failed_removal;
1520 }
1521
1495 /* This makes hotplug much easier...and readable.1522 /* This makes hotplug much easier...and readable.
1496 we assume this for now. .*/1523 we assume this for now. .*/
1497 if (!test_pages_in_a_zone(start_pfn, end_pfn, &valid_start,1524 if (!test_pages_in_a_zone(start_pfn, end_pfn, &valid_start,
@@ -1503,12 +1530,11 @@ static int __ref __offline_pages(unsigned long start_pfn, · 5 unmodified lines
1503 1530
1504 zone = page_zone(pfn_to_page(valid_start));1531 zone = page_zone(pfn_to_page(valid_start));
1505 node = zone_to_nid(zone);1532 node = zone_to_nid(zone);
1506 nr_pages = end_pfn - start_pfn;
1507 1533
1508 /* set above range as isolated */1534 /* set above range as isolated */
1509 ret = start_isolate_page_range(start_pfn, end_pfn,1535 ret = start_isolate_page_range(start_pfn, end_pfn,
1510 MIGRATE_MOVABLE,1536 MIGRATE_MOVABLE,
1511 SKIP_HWPOISON | REPORT_FAILURE);1537 MEMORY_OFFLINE | REPORT_FAILURE);
1512 if (ret < 0) {1538 if (ret < 0) {
1513 reason = "failure to isolate range";1539 reason = "failure to isolate range";
1514 goto failed_removal;1540 goto failed_removal;
@@ -1750,13 +1776,13 @@ static int __ref try_remove_memory(int nid, u64 start, u64 size) · 235 unmodified lines
1750 1776
1751 /* remove memmap entry */1777 /* remove memmap entry */
1752 firmware_map_remove(start, start + size, "System RAM");1778 firmware_map_remove(start, start + size, "System RAM");
1753 memblock_free(start, size);
1754 memblock_remove(start, size);
1755 1779
1756 /* remove memory block devices before removing memory */1780 /* remove memory block devices before removing memory */
1757 remove_memory_block_devices(start, size);1781 remove_memory_block_devices(start, size);
1758 1782
1759 arch_remove_memory(nid, start, size, NULL);1783 arch_remove_memory(nid, start, size, NULL);
1784 memblock_free(start, size);
1785 memblock_remove(start, size);
1760 __release_memory_resource(start, size);1786 __release_memory_resource(start, size);
1761 1787
1762 try_offline_node(nid);1788 try_offline_node(nid);
mm/mempolicy.c+31−16
@@ -410,7 +410,9 @@ struct queue_pages { · 409 unmodified lines
410 struct list_head *pagelist;410 struct list_head *pagelist;
411 unsigned long flags;411 unsigned long flags;
412 nodemask_t *nmask;412 nodemask_t *nmask;
413 struct vm_area_struct *prev;413 unsigned long start;
414 unsigned long end;
415 struct vm_area_struct *first;
414};416};
415 417
416/*418/*
@@ -618,6 +620,22 @@ static int queue_pages_test_walk(unsigned long start, unsigned long end, · 201 unmodified lines
618 unsigned long endvma = vma->vm_end;620 unsigned long endvma = vma->vm_end;
619 unsigned long flags = qp->flags;621 unsigned long flags = qp->flags;
620 622
623 /* range check first */
624 VM_BUG_ON((vma->vm_start > start) || (vma->vm_end < end));
625
626 if (!qp->first) {
627 qp->first = vma;
628 if (!(flags & MPOL_MF_DISCONTIG_OK) &&
629 (qp->start < vma->vm_start))
630 /* hole at head side of range */
631 return -EFAULT;
632 }
633 if (!(flags & MPOL_MF_DISCONTIG_OK) &&
634 ((vma->vm_end < qp->end) &&
635 (!vma->vm_next || vma->vm_end < vma->vm_next->vm_start)))
636 /* hole at middle or tail of range */
637 return -EFAULT;
638
621 /*639 /*
622 * Need check MPOL_MF_STRICT to return -EIO if possible640 * Need check MPOL_MF_STRICT to return -EIO if possible
623 * regardless of vma_migratable641 * regardless of vma_migratable
@@ -628,17 +646,6 @@ static int queue_pages_test_walk(unsigned long start, unsigned long end, · 4 unmodified lines
628 646
629 if (endvma > end)647 if (endvma > end)
630 endvma = end;648 endvma = end;
631 if (vma->vm_start > start)
632 start = vma->vm_start;
633
634 if (!(flags & MPOL_MF_DISCONTIG_OK)) {
635 if (!vma->vm_next && vma->vm_end < end)
636 return -EFAULT;
637 if (qp->prev && qp->prev->vm_end < vma->vm_start)
638 return -EFAULT;
639 }
640
641 qp->prev = vma;
642 649
643 if (flags & MPOL_MF_LAZY) {650 if (flags & MPOL_MF_LAZY) {
644 /* Similar to task_numa_work, skip inaccessible VMAs */651 /* Similar to task_numa_work, skip inaccessible VMAs */
@@ -681,14 +688,23 @@ queue_pages_range(struct mm_struct *mm, unsigned long start, unsigned long end, · 36 unmodified lines
681 nodemask_t *nodes, unsigned long flags,688 nodemask_t *nodes, unsigned long flags,
682 struct list_head *pagelist)689 struct list_head *pagelist)
683{690{
691 int err;
684 struct queue_pages qp = {692 struct queue_pages qp = {
685 .pagelist = pagelist,693 .pagelist = pagelist,
686 .flags = flags,694 .flags = flags,
687 .nmask = nodes,695 .nmask = nodes,
688 .prev = NULL,696 .start = start,
697 .end = end,
698 .first = NULL,
689 };699 };
690 700
691 return walk_page_range(mm, start, end, &queue_pages_walk_ops, &qp);701 err = walk_page_range(mm, start, end, &queue_pages_walk_ops, &qp);
702
703 if (!qp.first)
704 /* whole range in hole */
705 err = -EFAULT;
706
707 return err;
692}708}
693 709
694/*710/*
@@ -740,8 +756,7 @@ static int mbind_range(struct mm_struct *mm, unsigned long start, · 45 unmodified lines
740 unsigned long vmend;756 unsigned long vmend;
741 757
742 vma = find_vma(mm, start);758 vma = find_vma(mm, start);
743 if (!vma || vma->vm_start > start)759 VM_BUG_ON(!vma);
744 return -EFAULT;
745 760
746 prev = vma->vm_prev;761 prev = vma->vm_prev;
747 if (start > vma->vm_start)762 if (start > vma->vm_start)
mm/migrate.c+6−10
@@ -1168,15 +1168,11 @@ static ICE_noinline int unmap_and_move(new_page_t get_new_page, · 1167 unmodified lines
1168 enum migrate_reason reason)1168 enum migrate_reason reason)
1169{1169{
1170 int rc = MIGRATEPAGE_SUCCESS;1170 int rc = MIGRATEPAGE_SUCCESS;
1171 struct page *newpage;1171 struct page *newpage = NULL;
1172 1172
1173 if (!thp_migration_supported() && PageTransHuge(page))1173 if (!thp_migration_supported() && PageTransHuge(page))
1174 return -ENOMEM;1174 return -ENOMEM;
1175 1175
1176 newpage = get_new_page(page, private);
1177 if (!newpage)
1178 return -ENOMEM;
1179
1180 if (page_count(page) == 1) {1176 if (page_count(page) == 1) {
1181 /* page was freed from under us. So we are done. */1177 /* page was freed from under us. So we are done. */
1182 ClearPageActive(page);1178 ClearPageActive(page);
@@ -1187,13 +1183,13 @@ static ICE_noinline int unmap_and_move(new_page_t get_new_page, · 4 unmodified lines
1187 __ClearPageIsolated(page);1183 __ClearPageIsolated(page);
1188 unlock_page(page);1184 unlock_page(page);
1189 }1185 }
1190 if (put_new_page)
1191 put_new_page(newpage, private);
1192 else
1193 put_page(newpage);
1194 goto out;1186 goto out;
1195 }1187 }
1196 1188
1189 newpage = get_new_page(page, private);
1190 if (!newpage)
1191 return -ENOMEM;
1192
1197 rc = __unmap_and_move(page, newpage, force, mode);1193 rc = __unmap_and_move(page, newpage, force, mode);
1198 if (rc == MIGRATEPAGE_SUCCESS)1194 if (rc == MIGRATEPAGE_SUCCESS)
1199 set_page_owner_migrate_reason(newpage, reason);1195 set_page_owner_migrate_reason(newpage, reason);
@@ -1863,7 +1859,7 @@ static bool migrate_balanced_pgdat(struct pglist_data *pgdat, · 663 unmodified lines
1863 if (!zone_watermark_ok(zone, 0,1859 if (!zone_watermark_ok(zone, 0,
1864 high_wmark_pages(zone) +1860 high_wmark_pages(zone) +
1865 nr_migrate_pages,1861 nr_migrate_pages,
1866 0, 0))1862 ZONE_MOVABLE, 0))
1867 continue;1863 continue;
1868 return true;1864 return true;
1869 }1865 }
mm/mmap.c+21−42
@@ -641,7 +641,7 @@ __vma_link(struct mm_struct *mm, struct vm_area_struct *vma, · 640 unmodified lines
641 struct vm_area_struct *prev, struct rb_node **rb_link,641 struct vm_area_struct *prev, struct rb_node **rb_link,
642 struct rb_node *rb_parent)642 struct rb_node *rb_parent)
643{643{
644 __vma_link_list(mm, vma, prev, rb_parent);644 __vma_link_list(mm, vma, prev);
645 __vma_link_rb(mm, vma, rb_link, rb_parent);645 __vma_link_rb(mm, vma, rb_link, rb_parent);
646}646}
647 647
@@ -684,37 +684,14 @@ static void __insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma) · 36 unmodified lines
684 684
685static __always_inline void __vma_unlink_common(struct mm_struct *mm,685static __always_inline void __vma_unlink_common(struct mm_struct *mm,
686 struct vm_area_struct *vma,686 struct vm_area_struct *vma,
687 struct vm_area_struct *prev,
688 bool has_prev,
689 struct vm_area_struct *ignore)687 struct vm_area_struct *ignore)
690{688{
691 struct vm_area_struct *next;
692
693 vma_rb_erase_ignore(vma, &mm->mm_rb, ignore);689 vma_rb_erase_ignore(vma, &mm->mm_rb, ignore);
694 next = vma->vm_next;690 __vma_unlink_list(mm, vma);
695 if (has_prev)
696 prev->vm_next = next;
697 else {
698 prev = vma->vm_prev;
699 if (prev)
700 prev->vm_next = next;
701 else
702 mm->mmap = next;
703 }
704 if (next)
705 next->vm_prev = prev;
706
707 /* Kill the cache */691 /* Kill the cache */
708 vmacache_invalidate(mm);692 vmacache_invalidate(mm);
709}693}
710 694
711static inline void __vma_unlink_prev(struct mm_struct *mm,
712 struct vm_area_struct *vma,
713 struct vm_area_struct *prev)
714{
715 __vma_unlink_common(mm, vma, prev, true, vma);
716}
717
718/*695/*
719 * We cannot adjust vm_start, vm_end, vm_pgoff fields of a vma that696 * We cannot adjust vm_start, vm_end, vm_pgoff fields of a vma that
720 * is already present in an i_mmap tree without adjusting the tree.697 * is already present in an i_mmap tree without adjusting the tree.
@@ -769,8 +746,6 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start, · 48 unmodified lines
769 remove_next = 1 + (end > next->vm_end);746 remove_next = 1 + (end > next->vm_end);
770 VM_WARN_ON(remove_next == 2 &&747 VM_WARN_ON(remove_next == 2 &&
771 end != next->vm_next->vm_end);748 end != next->vm_next->vm_end);
772 VM_WARN_ON(remove_next == 1 &&
773 end != next->vm_end);
774 /* trim end to next, for case 6 first pass */749 /* trim end to next, for case 6 first pass */
775 end = next->vm_end;750 end = next->vm_end;
776 }751 }
@@ -889,7 +864,7 @@ again: · 112 unmodified lines
889 * us to remove next before dropping the locks.864 * us to remove next before dropping the locks.
890 */865 */
891 if (remove_next != 3)866 if (remove_next != 3)
892 __vma_unlink_prev(mm, next, vma);867 __vma_unlink_common(mm, next, next);
893 else868 else
894 /*869 /*
895 * vma is not before next if they've been870 * vma is not before next if they've been
@@ -900,7 +875,7 @@ again: · 4 unmodified lines
900 * "next" (which is stored in post-swap()875 * "next" (which is stored in post-swap()
901 * "vma").876 * "vma").
902 */877 */
903 __vma_unlink_common(mm, next, NULL, false, vma);878 __vma_unlink_common(mm, next, vma);
904 if (file)879 if (file)
905 __remove_shared_vm_struct(next, file, mapping);880 __remove_shared_vm_struct(next, file, mapping);
906 } else if (insert) {881 } else if (insert) {
@@ -1116,15 +1091,18 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags, · 209 unmodified lines
1116 * the area passed down from mprotect_fixup, never extending beyond one1091 * the area passed down from mprotect_fixup, never extending beyond one
1117 * vma, PPPPPP is the prev vma specified, and NNNNNN the next vma after:1092 * vma, PPPPPP is the prev vma specified, and NNNNNN the next vma after:
1118 *1093 *
1119 * AAAA AAAA AAAA AAAA1094 * AAAA AAAA AAAA
1120 * PPPPPPNNNNNN PPPPPPNNNNNN PPPPPPNNNNNN PPPPNNNNXXXX1095 * PPPPPPNNNNNN PPPPPPNNNNNN PPPPPPNNNNNN
1121 * cannot merge might become might become might become1096 * cannot merge might become might become
1122 * PPNNNNNNNNNN PPPPPPPPPPNN PPPPPPPPPPPP 6 or1097 * PPNNNNNNNNNN PPPPPPPPPPNN
1123 * mmap, brk or case 4 below case 5 below PPPPPPPPXXXX 7 or1098 * mmap, brk or case 4 below case 5 below
1124 * mremap move: PPPPXXXXXXXX 81099 * mremap move:
1125 * AAAA1100 * AAAA AAAA
1126 * PPPP NNNN PPPPPPPPPPPP PPPPPPPPNNNN PPPPNNNNNNNN1101 * PPPP NNNN PPPPNNNNXXXX
1127 * might become case 1 below case 2 below case 3 below1102 * might become might become
1103 * PPPPPPPPPPPP 1 or PPPPPPPPPPPP 6 or
1104 * PPPPPPPPNNNN 2 or PPPPPPPPXXXX 7 or
1105 * PPPPNNNNNNNN 3 PPPPXXXXXXXX 8
1128 *1106 *
1129 * It is important for case 8 that the vma NNNN overlapping the1107 * It is important for case 8 that the vma NNNN overlapping the
1130 * region AAAA is never going to extended over XXXX. Instead XXXX must1108 * region AAAA is never going to extended over XXXX. Instead XXXX must
@@ -1442,7 +1420,7 @@ unsigned long do_mmap(struct file *file, unsigned long addr, · 311 unmodified lines
1442 * that it represents a valid section of the address space.1420 * that it represents a valid section of the address space.
1443 */1421 */
1444 addr = get_unmapped_area(file, addr, len, pgoff, flags);1422 addr = get_unmapped_area(file, addr, len, pgoff, flags);
1445 if (offset_in_page(addr))1423 if (IS_ERR_VALUE(addr))
1446 return addr;1424 return addr;
1447 1425
1448 if (flags & MAP_FIXED_NOREPLACE) {1426 if (flags & MAP_FIXED_NOREPLACE) {
@@ -3006,15 +2984,16 @@ static int do_brk_flags(unsigned long addr, unsigned long len, unsigned long fla · 1557 unmodified lines
3006 struct rb_node **rb_link, *rb_parent;2984 struct rb_node **rb_link, *rb_parent;
3007 pgoff_t pgoff = addr >> PAGE_SHIFT;2985 pgoff_t pgoff = addr >> PAGE_SHIFT;
3008 int error;2986 int error;
2987 unsigned long mapped_addr;
3009 2988
3010 /* Until we need other flags, refuse anything except VM_EXEC. */2989 /* Until we need other flags, refuse anything except VM_EXEC. */
3011 if ((flags & (~VM_EXEC)) != 0)2990 if ((flags & (~VM_EXEC)) != 0)
3012 return -EINVAL;2991 return -EINVAL;
3013 flags |= VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;2992 flags |= VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
3014 2993
3015 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);2994 mapped_addr = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
3016 if (offset_in_page(error))2995 if (IS_ERR_VALUE(mapped_addr))
3017 return error;2996 return mapped_addr;
3018 2997
3019 error = mlock_future_check(mm, mm->def_flags, len);2998 error = mlock_future_check(mm, mm->def_flags, len);
3020 if (error)2999 if (error)
mm/mprotect.c+4−4
@@ -80,6 +80,10 @@ static unsigned long change_pte_range(struct vm_area_struct *vma, pmd_t *pmd, · 79 unmodified lines
80 if (prot_numa) {80 if (prot_numa) {
81 struct page *page;81 struct page *page;
82 82
83 /* Avoid TLB flush if possible */
84 if (pte_protnone(oldpte))
85 continue;
86
83 page = vm_normal_page(vma, addr, oldpte);87 page = vm_normal_page(vma, addr, oldpte);
84 if (!page || PageKsm(page))88 if (!page || PageKsm(page))
85 continue;89 continue;
@@ -97,10 +101,6 @@ static unsigned long change_pte_range(struct vm_area_struct *vma, pmd_t *pmd, · 11 unmodified lines
97 if (page_is_file_cache(page) && PageDirty(page))101 if (page_is_file_cache(page) && PageDirty(page))
98 continue;102 continue;
99 103
100 /* Avoid TLB flush if possible */
101 if (pte_protnone(oldpte))
102 continue;
103
104 /*104 /*
105 * Don't mess with PTEs if page is already on the node105 * Don't mess with PTEs if page is already on the node
106 * a single-threaded process is running on.106 * a single-threaded process is running on.
mm/mremap.c+2−2
@@ -558,7 +558,7 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len, · 557 unmodified lines
558 ret = get_unmapped_area(vma->vm_file, new_addr, new_len, vma->vm_pgoff +558 ret = get_unmapped_area(vma->vm_file, new_addr, new_len, vma->vm_pgoff +
559 ((addr - vma->vm_start) >> PAGE_SHIFT),559 ((addr - vma->vm_start) >> PAGE_SHIFT),
560 map_flags);560 map_flags);
561 if (offset_in_page(ret))561 if (IS_ERR_VALUE(ret))
562 goto out1;562 goto out1;
563 563
564 ret = move_vma(vma, addr, old_len, new_len, new_addr, locked, uf,564 ret = move_vma(vma, addr, old_len, new_len, new_addr, locked, uf,
@@ -706,7 +706,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len, · 141 unmodified lines
706 vma->vm_pgoff +706 vma->vm_pgoff +
707 ((addr - vma->vm_start) >> PAGE_SHIFT),707 ((addr - vma->vm_start) >> PAGE_SHIFT),
708 map_flags);708 map_flags);
709 if (offset_in_page(new_addr)) {709 if (IS_ERR_VALUE(new_addr)) {
710 ret = new_addr;710 ret = new_addr;
711 goto out;711 goto out;
712 }712 }
mm/nommu.c+2−8
@@ -648,7 +648,7 @@ static void add_vma_to_mm(struct mm_struct *mm, struct vm_area_struct *vma) · 647 unmodified lines
648 if (rb_prev)648 if (rb_prev)
649 prev = rb_entry(rb_prev, struct vm_area_struct, vm_rb);649 prev = rb_entry(rb_prev, struct vm_area_struct, vm_rb);
650 650
651 __vma_link_list(mm, vma, prev, parent);651 __vma_link_list(mm, vma, prev);
652}652}
653 653
654/*654/*
@@ -684,13 +684,7 @@ static void delete_vma_from_mm(struct vm_area_struct *vma) · 29 unmodified lines
684 /* remove from the MM's tree and list */684 /* remove from the MM's tree and list */
685 rb_erase(&vma->vm_rb, &mm->mm_rb);685 rb_erase(&vma->vm_rb, &mm->mm_rb);
686 686
687 if (vma->vm_prev)687 __vma_unlink_list(mm, vma);
688 vma->vm_prev->vm_next = vma->vm_next;
689 else
690 mm->mmap = vma->vm_next;
691
692 if (vma->vm_next)
693 vma->vm_next->vm_prev = vma->vm_prev;
694}688}
695 689
696/*690/*
mm/page_alloc.c+119−18
@@ -5354,6 +5354,7 @@ void show_free_areas(unsigned int filter, nodemask_t *nodemask) · 5353 unmodified lines
5354 " min:%lukB"5354 " min:%lukB"
5355 " low:%lukB"5355 " low:%lukB"
5356 " high:%lukB"5356 " high:%lukB"
5357 " reserved_highatomic:%luKB"
5357 " active_anon:%lukB"5358 " active_anon:%lukB"
5358 " inactive_anon:%lukB"5359 " inactive_anon:%lukB"
5359 " active_file:%lukB"5360 " active_file:%lukB"
@@ -5375,6 +5376,7 @@ void show_free_areas(unsigned int filter, nodemask_t *nodemask) · 15 unmodified lines
5375 K(min_wmark_pages(zone)),5376 K(min_wmark_pages(zone)),
5376 K(low_wmark_pages(zone)),5377 K(low_wmark_pages(zone)),
5377 K(high_wmark_pages(zone)),5378 K(high_wmark_pages(zone)),
5379 K(zone->nr_reserved_highatomic),
5378 K(zone_page_state(zone, NR_ZONE_ACTIVE_ANON)),5380 K(zone_page_state(zone, NR_ZONE_ACTIVE_ANON)),
5379 K(zone_page_state(zone, NR_ZONE_INACTIVE_ANON)),5381 K(zone_page_state(zone, NR_ZONE_INACTIVE_ANON)),
5380 K(zone_page_state(zone, NR_ZONE_ACTIVE_FILE)),5382 K(zone_page_state(zone, NR_ZONE_ACTIVE_FILE)),
@@ -6711,7 +6713,7 @@ static void __meminit pgdat_init_internals(struct pglist_data *pgdat) · 1330 unmodified lines
6711 6713
6712 pgdat_page_ext_init(pgdat);6714 pgdat_page_ext_init(pgdat);
6713 spin_lock_init(&pgdat->lru_lock);6715 spin_lock_init(&pgdat->lru_lock);
6714 lruvec_init(node_lruvec(pgdat));6716 lruvec_init(&pgdat->__lruvec);
6715}6717}
6716 6718
6717static void __meminit zone_init_internals(struct zone *zone, enum zone_type idx, int nid,6719static void __meminit zone_init_internals(struct zone *zone, enum zone_type idx, int nid,
@@ -7988,6 +7990,15 @@ int lowmem_reserve_ratio_sysctl_handler(struct ctl_table *table, int write, · 1270 unmodified lines
7988 return 0;7990 return 0;
7989}7991}
7990 7992
7993static void __zone_pcp_update(struct zone *zone)
7994{
7995 unsigned int cpu;
7996
7997 for_each_possible_cpu(cpu)
7998 pageset_set_high_and_batch(zone,
7999 per_cpu_ptr(zone->pageset, cpu));
8000}
8001
7991/*8002/*
7992 * percpu_pagelist_fraction - changes the pcp->high for each zone on each8003 * percpu_pagelist_fraction - changes the pcp->high for each zone on each
7993 * cpu. It is the fraction of total pages in each zone that a hot per cpu8004 * cpu. It is the fraction of total pages in each zone that a hot per cpu
@@ -8019,13 +8030,8 @@ int percpu_pagelist_fraction_sysctl_handler(struct ctl_table *table, int write, · 25 unmodified lines
8019 if (percpu_pagelist_fraction == old_percpu_pagelist_fraction)8030 if (percpu_pagelist_fraction == old_percpu_pagelist_fraction)
8020 goto out;8031 goto out;
8021 8032
8022 for_each_populated_zone(zone) {8033 for_each_populated_zone(zone)
8023 unsigned int cpu;8034 __zone_pcp_update(zone);
8024
8025 for_each_possible_cpu(cpu)
8026 pageset_set_high_and_batch(zone,
8027 per_cpu_ptr(zone->pageset, cpu));
8028 }
8029out:8035out:
8030 mutex_unlock(&pcp_batch_high_lock);8036 mutex_unlock(&pcp_batch_high_lock);
8031 return ret;8037 return ret;
@@ -8261,7 +8267,7 @@ bool has_unmovable_pages(struct zone *zone, struct page *page, int count, · 229 unmodified lines
8261 * The HWPoisoned page may be not in buddy system, and8267 * The HWPoisoned page may be not in buddy system, and
8262 * page_count() is not 0.8268 * page_count() is not 0.
8263 */8269 */
8264 if ((flags & SKIP_HWPOISON) && PageHWPoison(page))8270 if ((flags & MEMORY_OFFLINE) && PageHWPoison(page))
8265 continue;8271 continue;
8266 8272
8267 if (__PageMovable(page))8273 if (__PageMovable(page))
@@ -8477,7 +8483,7 @@ int alloc_contig_range(unsigned long start, unsigned long end, · 209 unmodified lines
8477 }8483 }
8478 8484
8479 /* Make sure the range is really isolated. */8485 /* Make sure the range is really isolated. */
8480 if (test_pages_isolated(outer_start, end, false)) {8486 if (test_pages_isolated(outer_start, end, 0)) {
8481 pr_info_ratelimited("%s: [%lx, %lx) PFNs busy\n",8487 pr_info_ratelimited("%s: [%lx, %lx) PFNs busy\n",
8482 __func__, outer_start, end);8488 __func__, outer_start, end);
8483 ret = -EBUSY;8489 ret = -EBUSY;
@@ -8502,6 +8508,107 @@ done: · 18 unmodified lines
8502 pfn_max_align_up(end), migratetype);8508 pfn_max_align_up(end), migratetype);
8503 return ret;8509 return ret;
8504}8510}
8511
8512static int __alloc_contig_pages(unsigned long start_pfn,
8513 unsigned long nr_pages, gfp_t gfp_mask)
8514{
8515 unsigned long end_pfn = start_pfn + nr_pages;
8516
8517 return alloc_contig_range(start_pfn, end_pfn, MIGRATE_MOVABLE,
8518 gfp_mask);
8519}
8520
8521static bool pfn_range_valid_contig(struct zone *z, unsigned long start_pfn,
8522 unsigned long nr_pages)
8523{
8524 unsigned long i, end_pfn = start_pfn + nr_pages;
8525 struct page *page;
8526
8527 for (i = start_pfn; i < end_pfn; i++) {
8528 page = pfn_to_online_page(i);
8529 if (!page)
8530 return false;
8531
8532 if (page_zone(page) != z)
8533 return false;
8534
8535 if (PageReserved(page))
8536 return false;
8537
8538 if (page_count(page) > 0)
8539 return false;
8540
8541 if (PageHuge(page))
8542 return false;
8543 }
8544 return true;
8545}
8546
8547static bool zone_spans_last_pfn(const struct zone *zone,
8548 unsigned long start_pfn, unsigned long nr_pages)
8549{
8550 unsigned long last_pfn = start_pfn + nr_pages - 1;
8551
8552 return zone_spans_pfn(zone, last_pfn);
8553}
8554
8555/**
8556 * alloc_contig_pages() -- tries to find and allocate contiguous range of pages
8557 * @nr_pages: Number of contiguous pages to allocate
8558 * @gfp_mask: GFP mask to limit search and used during compaction
8559 * @nid: Target node
8560 * @nodemask: Mask for other possible nodes
8561 *
8562 * This routine is a wrapper around alloc_contig_range(). It scans over zones
8563 * on an applicable zonelist to find a contiguous pfn range which can then be
8564 * tried for allocation with alloc_contig_range(). This routine is intended
8565 * for allocation requests which can not be fulfilled with the buddy allocator.
8566 *
8567 * The allocated memory is always aligned to a page boundary. If nr_pages is a
8568 * power of two then the alignment is guaranteed to be to the given nr_pages
8569 * (e.g. 1GB request would be aligned to 1GB).
8570 *
8571 * Allocated pages can be freed with free_contig_range() or by manually calling
8572 * __free_page() on each allocated page.
8573 *
8574 * Return: pointer to contiguous pages on success, or NULL if not successful.
8575 */
8576struct page *alloc_contig_pages(unsigned long nr_pages, gfp_t gfp_mask,
8577 int nid, nodemask_t *nodemask)
8578{
8579 unsigned long ret, pfn, flags;
8580 struct zonelist *zonelist;
8581 struct zone *zone;
8582 struct zoneref *z;
8583
8584 zonelist = node_zonelist(nid, gfp_mask);
8585 for_each_zone_zonelist_nodemask(zone, z, zonelist,
8586 gfp_zone(gfp_mask), nodemask) {
8587 spin_lock_irqsave(&zone->lock, flags);
8588
8589 pfn = ALIGN(zone->zone_start_pfn, nr_pages);
8590 while (zone_spans_last_pfn(zone, pfn, nr_pages)) {
8591 if (pfn_range_valid_contig(zone, pfn, nr_pages)) {
8592 /*
8593 * We release the zone lock here because
8594 * alloc_contig_range() will also lock the zone
8595 * at some point. If there's an allocation
8596 * spinning on this lock, it may win the race
8597 * and cause alloc_contig_range() to fail...
8598 */
8599 spin_unlock_irqrestore(&zone->lock, flags);
8600 ret = __alloc_contig_pages(pfn, nr_pages,
8601 gfp_mask);
8602 if (!ret)
8603 return pfn_to_page(pfn);
8604 spin_lock_irqsave(&zone->lock, flags);
8605 }
8606 pfn += nr_pages;
8607 }
8608 spin_unlock_irqrestore(&zone->lock, flags);
8609 }
8610 return NULL;
8611}
8505#endif /* CONFIG_CONTIG_ALLOC */8612#endif /* CONFIG_CONTIG_ALLOC */
8506 8613
8507void free_contig_range(unsigned long pfn, unsigned int nr_pages)8614void free_contig_range(unsigned long pfn, unsigned int nr_pages)
@@ -8523,11 +8630,8 @@ void free_contig_range(unsigned long pfn, unsigned int nr_pages) · 15 unmodified lines
8523 */8630 */
8524void __meminit zone_pcp_update(struct zone *zone)8631void __meminit zone_pcp_update(struct zone *zone)
8525{8632{
8526 unsigned cpu;
8527 mutex_lock(&pcp_batch_high_lock);8633 mutex_lock(&pcp_batch_high_lock);
8528 for_each_possible_cpu(cpu)8634 __zone_pcp_update(zone);
8529 pageset_set_high_and_batch(zone,
8530 per_cpu_ptr(zone->pageset, cpu));
8531 mutex_unlock(&pcp_batch_high_lock);8635 mutex_unlock(&pcp_batch_high_lock);
8532}8636}
8533 8637
@@ -8560,7 +8664,7 @@ __offline_isolated_pages(unsigned long start_pfn, unsigned long end_pfn) · 26 unmodified lines
8560{8664{
8561 struct page *page;8665 struct page *page;
8562 struct zone *zone;8666 struct zone *zone;
8563 unsigned int order, i;8667 unsigned int order;
8564 unsigned long pfn;8668 unsigned long pfn;
8565 unsigned long flags;8669 unsigned long flags;
8566 unsigned long offlined_pages = 0;8670 unsigned long offlined_pages = 0;
@@ -8588,7 +8692,6 @@ __offline_isolated_pages(unsigned long start_pfn, unsigned long end_pfn) · 21 unmodified lines
8588 */8692 */
8589 if (unlikely(!PageBuddy(page) && PageHWPoison(page))) {8693 if (unlikely(!PageBuddy(page) && PageHWPoison(page))) {
8590 pfn++;8694 pfn++;
8591 SetPageReserved(page);
8592 offlined_pages++;8695 offlined_pages++;
8593 continue;8696 continue;
8594 }8697 }
@@ -8602,8 +8705,6 @@ __offline_isolated_pages(unsigned long start_pfn, unsigned long end_pfn) · 7 unmodified lines
8602 pfn, 1 << order, end_pfn);8705 pfn, 1 << order, end_pfn);
8603#endif8706#endif
8604 del_page_from_free_area(page, &zone->free_area[order]);8707 del_page_from_free_area(page, &zone->free_area[order]);
8605 for (i = 0; i < (1 << order); i++)
8606 SetPageReserved((page+i));
8607 pfn += (1 << order);8708 pfn += (1 << order);
8608 }8709 }
8609 spin_unlock_irqrestore(&zone->lock, flags);8710 spin_unlock_irqrestore(&zone->lock, flags);
mm/page_io.c+13−2
@@ -22,6 +22,7 @@ · 21 unmodified lines
22#include <linux/writeback.h>22#include <linux/writeback.h>
23#include <linux/frontswap.h>23#include <linux/frontswap.h>
24#include <linux/blkdev.h>24#include <linux/blkdev.h>
25#include <linux/psi.h>
25#include <linux/uio.h>26#include <linux/uio.h>
26#include <linux/sched/task.h>27#include <linux/sched/task.h>
27#include <asm/pgtable.h>28#include <asm/pgtable.h>
@@ -354,10 +355,19 @@ int swap_readpage(struct page *page, bool synchronous) · 326 unmodified lines
354 struct swap_info_struct *sis = page_swap_info(page);355 struct swap_info_struct *sis = page_swap_info(page);
355 blk_qc_t qc;356 blk_qc_t qc;
356 struct gendisk *disk;357 struct gendisk *disk;
358 unsigned long pflags;
357 359
358 VM_BUG_ON_PAGE(!PageSwapCache(page) && !synchronous, page);360 VM_BUG_ON_PAGE(!PageSwapCache(page) && !synchronous, page);
359 VM_BUG_ON_PAGE(!PageLocked(page), page);361 VM_BUG_ON_PAGE(!PageLocked(page), page);
360 VM_BUG_ON_PAGE(PageUptodate(page), page);362 VM_BUG_ON_PAGE(PageUptodate(page), page);
363
364 /*
365 * Count submission time as memory stall. When the device is congested,
366 * or the submitting cgroup IO-throttled, submission can be a
367 * significant part of overall IO time.
368 */
369 psi_memstall_enter(&pflags);
370
361 if (frontswap_load(page) == 0) {371 if (frontswap_load(page) == 0) {
362 SetPageUptodate(page);372 SetPageUptodate(page);
363 unlock_page(page);373 unlock_page(page);
@@ -371,7 +381,7 @@ int swap_readpage(struct page *page, bool synchronous) · 7 unmodified lines
371 ret = mapping->a_ops->readpage(swap_file, page);381 ret = mapping->a_ops->readpage(swap_file, page);
372 if (!ret)382 if (!ret)
373 count_vm_event(PSWPIN);383 count_vm_event(PSWPIN);
374 return ret;384 goto out;
375 }385 }
376 386
377 ret = bdev_read_page(sis->bdev, swap_page_sector(page), page);387 ret = bdev_read_page(sis->bdev, swap_page_sector(page), page);
@@ -382,7 +392,7 @@ int swap_readpage(struct page *page, bool synchronous) · 4 unmodified lines
382 }392 }
383 393
384 count_vm_event(PSWPIN);394 count_vm_event(PSWPIN);
385 return 0;395 goto out;
386 }396 }
387 397
388 ret = 0;398 ret = 0;
@@ -418,6 +428,7 @@ int swap_readpage(struct page *page, bool synchronous) · 29 unmodified lines
418 bio_put(bio);428 bio_put(bio);
419 429
420out:430out:
431 psi_memstall_leave(&pflags);
421 return ret;432 return ret;
422}433}
423 434
mm/page_isolation.c+6−6
@@ -168,7 +168,8 @@ __first_valid_page(unsigned long pfn, unsigned long nr_pages) · 167 unmodified lines
168 * @migratetype: Migrate type to set in error recovery.168 * @migratetype: Migrate type to set in error recovery.
169 * @flags: The following flags are allowed (they can be combined in169 * @flags: The following flags are allowed (they can be combined in
170 * a bit mask)170 * a bit mask)
171 * SKIP_HWPOISON - ignore hwpoison pages171 * MEMORY_OFFLINE - isolate to offline (!allocate) memory
172 * e.g., skip over PageHWPoison() pages
172 * REPORT_FAILURE - report details about the failure to173 * REPORT_FAILURE - report details about the failure to
173 * isolate the range174 * isolate the range
174 *175 *
@@ -257,7 +258,7 @@ void undo_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn, · 82 unmodified lines
257 */258 */
258static unsigned long259static unsigned long
259__test_page_isolated_in_pageblock(unsigned long pfn, unsigned long end_pfn,260__test_page_isolated_in_pageblock(unsigned long pfn, unsigned long end_pfn,
260 bool skip_hwpoisoned_pages)261 int flags)
261{262{
262 struct page *page;263 struct page *page;
263 264
@@ -274,7 +275,7 @@ __test_page_isolated_in_pageblock(unsigned long pfn, unsigned long end_pfn, · 10 unmodified lines
274 * simple way to verify that as VM_BUG_ON(), though.275 * simple way to verify that as VM_BUG_ON(), though.
275 */276 */
276 pfn += 1 << page_order(page);277 pfn += 1 << page_order(page);
277 else if (skip_hwpoisoned_pages && PageHWPoison(page))278 else if ((flags & MEMORY_OFFLINE) && PageHWPoison(page))
278 /* A HWPoisoned page cannot be also PageBuddy */279 /* A HWPoisoned page cannot be also PageBuddy */
279 pfn++;280 pfn++;
280 else281 else
@@ -286,7 +287,7 @@ __test_page_isolated_in_pageblock(unsigned long pfn, unsigned long end_pfn, · 5 unmodified lines
286 287
287/* Caller should ensure that requested range is in a single zone */288/* Caller should ensure that requested range is in a single zone */
288int test_pages_isolated(unsigned long start_pfn, unsigned long end_pfn,289int test_pages_isolated(unsigned long start_pfn, unsigned long end_pfn,
289 bool skip_hwpoisoned_pages)290 int isol_flags)
290{291{
291 unsigned long pfn, flags;292 unsigned long pfn, flags;
292 struct page *page;293 struct page *page;
@@ -308,8 +309,7 @@ int test_pages_isolated(unsigned long start_pfn, unsigned long end_pfn, · 15 unmodified lines
308 /* Check all pages are free or marked as ISOLATED */309 /* Check all pages are free or marked as ISOLATED */
309 zone = page_zone(page);310 zone = page_zone(page);
310 spin_lock_irqsave(&zone->lock, flags);311 spin_lock_irqsave(&zone->lock, flags);
311 pfn = __test_page_isolated_in_pageblock(start_pfn, end_pfn,312 pfn = __test_page_isolated_in_pageblock(start_pfn, end_pfn, isol_flags);
312 skip_hwpoisoned_pages);
313 spin_unlock_irqrestore(&zone->lock, flags);313 spin_unlock_irqrestore(&zone->lock, flags);
314 314
315 trace_test_pages_isolated(start_pfn, end_pfn, pfn);315 trace_test_pages_isolated(start_pfn, end_pfn, pfn);
mm/pgtable-generic.c+9−0
@@ -24,18 +24,27 @@ void pgd_clear_bad(pgd_t *pgd) · 23 unmodified lines
24 pgd_clear(pgd);24 pgd_clear(pgd);
25}25}
26 26
27#ifndef __PAGETABLE_P4D_FOLDED
27void p4d_clear_bad(p4d_t *p4d)28void p4d_clear_bad(p4d_t *p4d)
28{29{
29 p4d_ERROR(*p4d);30 p4d_ERROR(*p4d);
30 p4d_clear(p4d);31 p4d_clear(p4d);
31}32}
33#endif
32 34
35#ifndef __PAGETABLE_PUD_FOLDED
33void pud_clear_bad(pud_t *pud)36void pud_clear_bad(pud_t *pud)
34{37{
35 pud_ERROR(*pud);38 pud_ERROR(*pud);
36 pud_clear(pud);39 pud_clear(pud);
37}40}
41#endif
38 42
43/*
44 * Note that the pmd variant below can't be stub'ed out just as for p4d/pud
45 * above. pmd folding is special and typically pmd_* macros refer to upper
46 * level even when folded
47 */
39void pmd_clear_bad(pmd_t *pmd)48void pmd_clear_bad(pmd_t *pmd)
40{49{
41 pmd_ERROR(*pmd);50 pmd_ERROR(*pmd);
mm/rmap.c+45−20
@@ -251,18 +251,37 @@ static inline void unlock_anon_vma_root(struct anon_vma *root) · 250 unmodified lines
251 * Attach the anon_vmas from src to dst.251 * Attach the anon_vmas from src to dst.
252 * Returns 0 on success, -ENOMEM on failure.252 * Returns 0 on success, -ENOMEM on failure.
253 *253 *
254 * If dst->anon_vma is NULL this function tries to find and reuse existing254 * anon_vma_clone() is called by __vma_split(), __split_vma(), copy_vma() and
255 * anon_vma which has no vmas and only one child anon_vma. This prevents255 * anon_vma_fork(). The first three want an exact copy of src, while the last
256 * degradation of anon_vma hierarchy to endless linear chain in case of256 * one, anon_vma_fork(), may try to reuse an existing anon_vma to prevent
257 * constantly forking task. On the other hand, an anon_vma with more than one257 * endless growth of anon_vma. Since dst->anon_vma is set to NULL before call,
258 * child isn't reused even if there was no alive vma, thus rmap walker has a258 * we can identify this case by checking (!dst->anon_vma && src->anon_vma).
259 * good chance of avoiding scanning the whole hierarchy when it searches where259 *
260 * page is mapped.260 * If (!dst->anon_vma && src->anon_vma) is true, this function tries to find
261 * and reuse existing anon_vma which has no vmas and only one child anon_vma.
262 * This prevents degradation of anon_vma hierarchy to endless linear chain in
263 * case of constantly forking task. On the other hand, an anon_vma with more
264 * than one child isn't reused even if there was no alive vma, thus rmap
265 * walker has a good chance of avoiding scanning the whole hierarchy when it
266 * searches where page is mapped.
261 */267 */
262int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)268int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
263{269{
264 struct anon_vma_chain *avc, *pavc;270 struct anon_vma_chain *avc, *pavc;
265 struct anon_vma *root = NULL;271 struct anon_vma *root = NULL;
272 struct vm_area_struct *prev = dst->vm_prev, *pprev = src->vm_prev;
273
274 /*
275 * If parent share anon_vma with its vm_prev, keep this sharing in in
276 * child.
277 *
278 * 1. Parent has vm_prev, which implies we have vm_prev.
279 * 2. Parent and its vm_prev have the same anon_vma.
280 */
281 if (!dst->anon_vma && src->anon_vma &&
282 pprev && pprev->anon_vma == src->anon_vma)
283 dst->anon_vma = prev->anon_vma;
284
266 285
267 list_for_each_entry_reverse(pavc, &src->anon_vma_chain, same_vma) {286 list_for_each_entry_reverse(pavc, &src->anon_vma_chain, same_vma) {
268 struct anon_vma *anon_vma;287 struct anon_vma *anon_vma;
@@ -287,8 +306,8 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src) · 18 unmodified lines
287 * will always reuse it. Root anon_vma is never reused:306 * will always reuse it. Root anon_vma is never reused:
288 * it has self-parent reference and at least one child.307 * it has self-parent reference and at least one child.
289 */308 */
290 if (!dst->anon_vma && anon_vma != src->anon_vma &&309 if (!dst->anon_vma && src->anon_vma &&
291 anon_vma->degree < 2)310 anon_vma != src->anon_vma && anon_vma->degree < 2)
292 dst->anon_vma = anon_vma;311 dst->anon_vma = anon_vma;
293 }312 }
294 if (dst->anon_vma)313 if (dst->anon_vma)
@@ -458,9 +477,10 @@ void __init anon_vma_init(void) · 163 unmodified lines
458 * chain and verify that the page in question is indeed mapped in it477 * chain and verify that the page in question is indeed mapped in it
459 * [ something equivalent to page_mapped_in_vma() ].478 * [ something equivalent to page_mapped_in_vma() ].
460 *479 *
461 * Since anon_vma's slab is DESTROY_BY_RCU and we know from page_remove_rmap()480 * Since anon_vma's slab is SLAB_TYPESAFE_BY_RCU and we know from
462 * that the anon_vma pointer from page->mapping is valid if there is a481 * page_remove_rmap() that the anon_vma pointer from page->mapping is valid
463 * mapcount, we can dereference the anon_vma after observing those.482 * if there is a mapcount, we can dereference the anon_vma after observing
483 * those.
464 */484 */
465struct anon_vma *page_get_anon_vma(struct page *page)485struct anon_vma *page_get_anon_vma(struct page *page)
466{486{
@@ -1055,7 +1075,6 @@ static void __page_set_anon_rmap(struct page *page, · 588 unmodified lines
1055static void __page_check_anon_rmap(struct page *page,1075static void __page_check_anon_rmap(struct page *page,
1056 struct vm_area_struct *vma, unsigned long address)1076 struct vm_area_struct *vma, unsigned long address)
1057{1077{
1058#ifdef CONFIG_DEBUG_VM
1059 /*1078 /*
1060 * The page's anon-rmap details (mapping and index) are guaranteed to1079 * The page's anon-rmap details (mapping and index) are guaranteed to
1061 * be set up correctly at this point.1080 * be set up correctly at this point.
@@ -1068,9 +1087,9 @@ static void __page_check_anon_rmap(struct page *page, · 6 unmodified lines
1068 * are initially only visible via the pagetables, and the pte is locked1087 * are initially only visible via the pagetables, and the pte is locked
1069 * over the call to page_add_new_anon_rmap.1088 * over the call to page_add_new_anon_rmap.
1070 */1089 */
1071 BUG_ON(page_anon_vma(page)->root != vma->anon_vma->root);1090 VM_BUG_ON_PAGE(page_anon_vma(page)->root != vma->anon_vma->root, page);
1072 BUG_ON(page_to_pgoff(page) != linear_page_index(vma, address));1091 VM_BUG_ON_PAGE(page_to_pgoff(page) != linear_page_index(vma, address),
1073#endif1092 page);
1074}1093}
1075 1094
1076/**1095/**
@@ -1273,12 +1292,20 @@ static void page_remove_anon_compound_rmap(struct page *page) · 196 unmodified lines
1273 if (TestClearPageDoubleMap(page)) {1292 if (TestClearPageDoubleMap(page)) {
1274 /*1293 /*
1275 * Subpages can be mapped with PTEs too. Check how many of1294 * Subpages can be mapped with PTEs too. Check how many of
1276 * themi are still mapped.1295 * them are still mapped.
1277 */1296 */
1278 for (i = 0, nr = 0; i < HPAGE_PMD_NR; i++) {1297 for (i = 0, nr = 0; i < HPAGE_PMD_NR; i++) {
1279 if (atomic_add_negative(-1, &page[i]._mapcount))1298 if (atomic_add_negative(-1, &page[i]._mapcount))
1280 nr++;1299 nr++;
1281 }1300 }
1301
1302 /*
1303 * Queue the page for deferred split if at least one small
1304 * page of the compound page is unmapped, but at least one
1305 * small page is still mapped.
1306 */
1307 if (nr && nr < HPAGE_PMD_NR)
1308 deferred_split_huge_page(page);
1282 } else {1309 } else {
1283 nr = HPAGE_PMD_NR;1310 nr = HPAGE_PMD_NR;
1284 }1311 }
@@ -1286,10 +1313,8 @@ static void page_remove_anon_compound_rmap(struct page *page) · 1 unmodified line
1286 if (unlikely(PageMlocked(page)))1313 if (unlikely(PageMlocked(page)))
1287 clear_page_mlock(page);1314 clear_page_mlock(page);
1288 1315
1289 if (nr) {1316 if (nr)
1290 __mod_node_page_state(page_pgdat(page), NR_ANON_MAPPED, -nr);1317 __mod_node_page_state(page_pgdat(page), NR_ANON_MAPPED, -nr);
1291 deferred_split_huge_page(page);
1292 }
1293}1318}
1294 1319
1295/**1320/**
mm/shmem.c+17−12
@@ -1369,7 +1369,8 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc) · 1368 unmodified lines
1369 if (list_empty(&info->swaplist))1369 if (list_empty(&info->swaplist))
1370 list_add(&info->swaplist, &shmem_swaplist);1370 list_add(&info->swaplist, &shmem_swaplist);
1371 1371
1372 if (add_to_swap_cache(page, swap, GFP_ATOMIC) == 0) {1372 if (add_to_swap_cache(page, swap,
1373 __GFP_HIGH | __GFP_NOMEMALLOC | __GFP_NOWARN) == 0) {
1373 spin_lock_irq(&info->lock);1374 spin_lock_irq(&info->lock);
1374 shmem_recalc_inode(inode);1375 shmem_recalc_inode(inode);
1375 info->swapped++;1376 info->swapped++;
@@ -2022,16 +2023,14 @@ static vm_fault_t shmem_fault(struct vm_fault *vmf) · 646 unmodified lines
2022 shmem_falloc->waitq &&2023 shmem_falloc->waitq &&
2023 vmf->pgoff >= shmem_falloc->start &&2024 vmf->pgoff >= shmem_falloc->start &&
2024 vmf->pgoff < shmem_falloc->next) {2025 vmf->pgoff < shmem_falloc->next) {
2026 struct file *fpin;
2025 wait_queue_head_t *shmem_falloc_waitq;2027 wait_queue_head_t *shmem_falloc_waitq;
2026 DEFINE_WAIT_FUNC(shmem_fault_wait, synchronous_wake_function);2028 DEFINE_WAIT_FUNC(shmem_fault_wait, synchronous_wake_function);
2027 2029
2028 ret = VM_FAULT_NOPAGE;2030 ret = VM_FAULT_NOPAGE;
2029 if ((vmf->flags & FAULT_FLAG_ALLOW_RETRY) &&2031 fpin = maybe_unlock_mmap_for_io(vmf, NULL);
2030 !(vmf->flags & FAULT_FLAG_RETRY_NOWAIT)) {2032 if (fpin)
2031 /* It's polite to up mmap_sem if we can */
2032 up_read(&vma->vm_mm->mmap_sem);
2033 ret = VM_FAULT_RETRY;2033 ret = VM_FAULT_RETRY;
2034 }
2035 2034
2036 shmem_falloc_waitq = shmem_falloc->waitq;2035 shmem_falloc_waitq = shmem_falloc->waitq;
2037 prepare_to_wait(shmem_falloc_waitq, &shmem_fault_wait,2036 prepare_to_wait(shmem_falloc_waitq, &shmem_fault_wait,
@@ -2049,6 +2048,9 @@ static vm_fault_t shmem_fault(struct vm_fault *vmf) · 11 unmodified lines
2049 spin_lock(&inode->i_lock);2048 spin_lock(&inode->i_lock);
2050 finish_wait(shmem_falloc_waitq, &shmem_fault_wait);2049 finish_wait(shmem_falloc_waitq, &shmem_fault_wait);
2051 spin_unlock(&inode->i_lock);2050 spin_unlock(&inode->i_lock);
2051
2052 if (fpin)
2053 fput(fpin);
2052 return ret;2054 return ret;
2053 }2055 }
2054 spin_unlock(&inode->i_lock);2056 spin_unlock(&inode->i_lock);
@@ -2213,11 +2215,14 @@ static int shmem_mmap(struct file *file, struct vm_area_struct *vma) · 158 unmodified lines
2213 return -EPERM;2215 return -EPERM;
2214 2216
2215 /*2217 /*
2216 * Since the F_SEAL_FUTURE_WRITE seals allow for a MAP_SHARED2218 * Since an F_SEAL_FUTURE_WRITE sealed memfd can be mapped as
2217 * read-only mapping, take care to not allow mprotect to revert2219 * MAP_SHARED and read-only, take care to not allow mprotect to
2218 * protections.2220 * revert protections on such mappings. Do this only for shared
2221 * mappings. For private mappings, don't need to mask
2222 * VM_MAYWRITE as we still want them to be COW-writable.
2219 */2223 */
2220 vma->vm_flags &= ~(VM_MAYWRITE);2224 if (vma->vm_flags & VM_SHARED)
2225 vma->vm_flags &= ~(VM_MAYWRITE);
2221 }2226 }
2222 2227
2223 file_accessed(file);2228 file_accessed(file);
@@ -2742,7 +2747,7 @@ static long shmem_fallocate(struct file *file, int mode, loff_t offset, · 518 unmodified lines
2742 }2747 }
2743 2748
2744 shmem_falloc.waitq = &shmem_falloc_waitq;2749 shmem_falloc.waitq = &shmem_falloc_waitq;
2745 shmem_falloc.start = unmap_start >> PAGE_SHIFT;2750 shmem_falloc.start = (u64)unmap_start >> PAGE_SHIFT;
2746 shmem_falloc.next = (unmap_end + 1) >> PAGE_SHIFT;2751 shmem_falloc.next = (unmap_end + 1) >> PAGE_SHIFT;
2747 spin_lock(&inode->i_lock);2752 spin_lock(&inode->i_lock);
2748 inode->i_private = &shmem_falloc;2753 inode->i_private = &shmem_falloc;
@@ -3928,7 +3933,7 @@ out2: · 1179 unmodified lines
3928static ssize_t shmem_enabled_show(struct kobject *kobj,3933static ssize_t shmem_enabled_show(struct kobject *kobj,
3929 struct kobj_attribute *attr, char *buf)3934 struct kobj_attribute *attr, char *buf)
3930{3935{
3931 int values[] = {3936 static const int values[] = {
3932 SHMEM_HUGE_ALWAYS,3937 SHMEM_HUGE_ALWAYS,
3933 SHMEM_HUGE_WITHIN_SIZE,3938 SHMEM_HUGE_WITHIN_SIZE,
3934 SHMEM_HUGE_ADVISE,3939 SHMEM_HUGE_ADVISE,
mm/slab.c+4−3
@@ -1247,9 +1247,10 @@ void __init kmem_cache_init(void) · 1246 unmodified lines
1247 * structures first. Without this, further allocations will bug.1247 * structures first. Without this, further allocations will bug.
1248 */1248 */
1249 kmalloc_caches[KMALLOC_NORMAL][INDEX_NODE] = create_kmalloc_cache(1249 kmalloc_caches[KMALLOC_NORMAL][INDEX_NODE] = create_kmalloc_cache(
1250 kmalloc_info[INDEX_NODE].name,1250 kmalloc_info[INDEX_NODE].name[KMALLOC_NORMAL],
1251 kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS,1251 kmalloc_info[INDEX_NODE].size,
1252 0, kmalloc_size(INDEX_NODE));1252 ARCH_KMALLOC_FLAGS, 0,
1253 kmalloc_info[INDEX_NODE].size);
1253 slab_state = PARTIAL_NODE;1254 slab_state = PARTIAL_NODE;
1254 setup_kmalloc_cache_index_table();1255 setup_kmalloc_cache_index_table();
1255 1256
mm/slab.h+3−3
@@ -139,7 +139,7 @@ extern struct kmem_cache *kmem_cache; · 138 unmodified lines
139 139
140/* A table of kmalloc cache names and sizes */140/* A table of kmalloc cache names and sizes */
141extern const struct kmalloc_info_struct {141extern const struct kmalloc_info_struct {
142 const char *name;142 const char *name[NR_KMALLOC_TYPES];
143 unsigned int size;143 unsigned int size;
144} kmalloc_info[];144} kmalloc_info[];
145 145
@@ -369,7 +369,7 @@ static __always_inline int memcg_charge_slab(struct page *page, · 223 unmodified lines
369 if (ret)369 if (ret)
370 goto out;370 goto out;
371 371
372 lruvec = mem_cgroup_lruvec(page_pgdat(page), memcg);372 lruvec = mem_cgroup_lruvec(memcg, page_pgdat(page));
373 mod_lruvec_state(lruvec, cache_vmstat_idx(s), 1 << order);373 mod_lruvec_state(lruvec, cache_vmstat_idx(s), 1 << order);
374 374
375 /* transer try_charge() page references to kmem_cache */375 /* transer try_charge() page references to kmem_cache */
@@ -393,7 +393,7 @@ static __always_inline void memcg_uncharge_slab(struct page *page, int order, · 17 unmodified lines
393 rcu_read_lock();393 rcu_read_lock();
394 memcg = READ_ONCE(s->memcg_params.memcg);394 memcg = READ_ONCE(s->memcg_params.memcg);
395 if (likely(!mem_cgroup_is_root(memcg))) {395 if (likely(!mem_cgroup_is_root(memcg))) {
396 lruvec = mem_cgroup_lruvec(page_pgdat(page), memcg);396 lruvec = mem_cgroup_lruvec(memcg, page_pgdat(page));
397 mod_lruvec_state(lruvec, cache_vmstat_idx(s), -(1 << order));397 mod_lruvec_state(lruvec, cache_vmstat_idx(s), -(1 << order));
398 memcg_kmem_uncharge_memcg(page, order, memcg);398 memcg_kmem_uncharge_memcg(page, order, memcg);
399 } else {399 } else {
mm/slab_common.c+53−46
@@ -1139,26 +1139,56 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags) · 1138 unmodified lines
1139 return kmalloc_caches[kmalloc_type(flags)][index];1139 return kmalloc_caches[kmalloc_type(flags)][index];
1140}1140}
1141 1141
1142#ifdef CONFIG_ZONE_DMA
1143#define INIT_KMALLOC_INFO(__size, __short_size) \
1144{ \
1145 .name[KMALLOC_NORMAL] = "kmalloc-" #__short_size, \
1146 .name[KMALLOC_RECLAIM] = "kmalloc-rcl-" #__short_size, \
1147 .name[KMALLOC_DMA] = "dma-kmalloc-" #__short_size, \
1148 .size = __size, \
1149}
1150#else
1151#define INIT_KMALLOC_INFO(__size, __short_size) \
1152{ \
1153 .name[KMALLOC_NORMAL] = "kmalloc-" #__short_size, \
1154 .name[KMALLOC_RECLAIM] = "kmalloc-rcl-" #__short_size, \
1155 .size = __size, \
1156}
1157#endif
1158
1142/*1159/*
1143 * kmalloc_info[] is to make slub_debug=,kmalloc-xx option work at boot time.1160 * kmalloc_info[] is to make slub_debug=,kmalloc-xx option work at boot time.
1144 * kmalloc_index() supports up to 2^26=64MB, so the final entry of the table is1161 * kmalloc_index() supports up to 2^26=64MB, so the final entry of the table is
1145 * kmalloc-67108864.1162 * kmalloc-67108864.
1146 */1163 */
1147const struct kmalloc_info_struct kmalloc_info[] __initconst = {1164const struct kmalloc_info_struct kmalloc_info[] __initconst = {
1148 {NULL, 0}, {"kmalloc-96", 96},1165 INIT_KMALLOC_INFO(0, 0),
1149 {"kmalloc-192", 192}, {"kmalloc-8", 8},1166 INIT_KMALLOC_INFO(96, 96),
1150 {"kmalloc-16", 16}, {"kmalloc-32", 32},1167 INIT_KMALLOC_INFO(192, 192),
1151 {"kmalloc-64", 64}, {"kmalloc-128", 128},1168 INIT_KMALLOC_INFO(8, 8),
1152 {"kmalloc-256", 256}, {"kmalloc-512", 512},1169 INIT_KMALLOC_INFO(16, 16),
1153 {"kmalloc-1k", 1024}, {"kmalloc-2k", 2048},1170 INIT_KMALLOC_INFO(32, 32),
1154 {"kmalloc-4k", 4096}, {"kmalloc-8k", 8192},1171 INIT_KMALLOC_INFO(64, 64),
1155 {"kmalloc-16k", 16384}, {"kmalloc-32k", 32768},1172 INIT_KMALLOC_INFO(128, 128),
1156 {"kmalloc-64k", 65536}, {"kmalloc-128k", 131072},1173 INIT_KMALLOC_INFO(256, 256),
1157 {"kmalloc-256k", 262144}, {"kmalloc-512k", 524288},1174 INIT_KMALLOC_INFO(512, 512),
1158 {"kmalloc-1M", 1048576}, {"kmalloc-2M", 2097152},1175 INIT_KMALLOC_INFO(1024, 1k),
1159 {"kmalloc-4M", 4194304}, {"kmalloc-8M", 8388608},1176 INIT_KMALLOC_INFO(2048, 2k),
1160 {"kmalloc-16M", 16777216}, {"kmalloc-32M", 33554432},1177 INIT_KMALLOC_INFO(4096, 4k),
1161 {"kmalloc-64M", 67108864}1178 INIT_KMALLOC_INFO(8192, 8k),
1179 INIT_KMALLOC_INFO(16384, 16k),
1180 INIT_KMALLOC_INFO(32768, 32k),
1181 INIT_KMALLOC_INFO(65536, 64k),
1182 INIT_KMALLOC_INFO(131072, 128k),
1183 INIT_KMALLOC_INFO(262144, 256k),
1184 INIT_KMALLOC_INFO(524288, 512k),
1185 INIT_KMALLOC_INFO(1048576, 1M),
1186 INIT_KMALLOC_INFO(2097152, 2M),
1187 INIT_KMALLOC_INFO(4194304, 4M),
1188 INIT_KMALLOC_INFO(8388608, 8M),
1189 INIT_KMALLOC_INFO(16777216, 16M),
1190 INIT_KMALLOC_INFO(33554432, 32M),
1191 INIT_KMALLOC_INFO(67108864, 64M)
1162};1192};
1163 1193
1164/*1194/*
@@ -1208,36 +1238,14 @@ void __init setup_kmalloc_cache_index_table(void) · 43 unmodified lines
1208 }1238 }
1209}1239}
1210 1240
1211static const char *
1212kmalloc_cache_name(const char *prefix, unsigned int size)
1213{
1214
1215 static const char units[3] = "\0kM";
1216 int idx = 0;
1217
1218 while (size >= 1024 && (size % 1024 == 0)) {
1219 size /= 1024;
1220 idx++;
1221 }
1222
1223 return kasprintf(GFP_NOWAIT, "%s-%u%c", prefix, size, units[idx]);
1224}
1225
1226static void __init1241static void __init
1227new_kmalloc_cache(int idx, int type, slab_flags_t flags)1242new_kmalloc_cache(int idx, enum kmalloc_cache_type type, slab_flags_t flags)
1228{1243{
1229 const char *name;1244 if (type == KMALLOC_RECLAIM)
1230
1231 if (type == KMALLOC_RECLAIM) {
1232 flags |= SLAB_RECLAIM_ACCOUNT;1245 flags |= SLAB_RECLAIM_ACCOUNT;
1233 name = kmalloc_cache_name("kmalloc-rcl",
1234 kmalloc_info[idx].size);
1235 BUG_ON(!name);
1236 } else {
1237 name = kmalloc_info[idx].name;
1238 }
1239 1246
1240 kmalloc_caches[type][idx] = create_kmalloc_cache(name,1247 kmalloc_caches[type][idx] = create_kmalloc_cache(
1248 kmalloc_info[idx].name[type],
1241 kmalloc_info[idx].size, flags, 0,1249 kmalloc_info[idx].size, flags, 0,
1242 kmalloc_info[idx].size);1250 kmalloc_info[idx].size);
1243}1251}
@@ -1249,7 +1257,8 @@ new_kmalloc_cache(int idx, int type, slab_flags_t flags) · 5 unmodified lines
1249 */1257 */
1250void __init create_kmalloc_caches(slab_flags_t flags)1258void __init create_kmalloc_caches(slab_flags_t flags)
1251{1259{
1252 int i, type;1260 int i;
1261 enum kmalloc_cache_type type;
1253 1262
1254 for (type = KMALLOC_NORMAL; type <= KMALLOC_RECLAIM; type++) {1263 for (type = KMALLOC_NORMAL; type <= KMALLOC_RECLAIM; type++) {
1255 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {1264 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
@@ -1278,12 +1287,10 @@ void __init create_kmalloc_caches(slab_flags_t flags) · 22 unmodified lines
1278 struct kmem_cache *s = kmalloc_caches[KMALLOC_NORMAL][i];1287 struct kmem_cache *s = kmalloc_caches[KMALLOC_NORMAL][i];
1279 1288
1280 if (s) {1289 if (s) {
1281 unsigned int size = kmalloc_size(i);
1282 const char *n = kmalloc_cache_name("dma-kmalloc", size);
1283
1284 BUG_ON(!n);
1285 kmalloc_caches[KMALLOC_DMA][i] = create_kmalloc_cache(1290 kmalloc_caches[KMALLOC_DMA][i] = create_kmalloc_cache(
1286 n, size, SLAB_CACHE_DMA | flags, 0, 0);1291 kmalloc_info[i].name[KMALLOC_DMA],
1292 kmalloc_info[i].size,
1293 SLAB_CACHE_DMA | flags, 0, 0);
1287 }1294 }
1288 }1295 }
1289#endif1296#endif
mm/slub.c+16−20
@@ -93,9 +93,7 @@ · 92 unmodified lines
93 * minimal so we rely on the page allocators per cpu caches for93 * minimal so we rely on the page allocators per cpu caches for
94 * fast frees and allocs.94 * fast frees and allocs.
95 *95 *
96 * Overloading of page flags that are otherwise used for LRU management.96 * page->frozen The slab is frozen and exempt from list processing.
97 *
98 * PageActive The slab is frozen and exempt from list processing.
99 * This means that the slab is dedicated to a purpose97 * This means that the slab is dedicated to a purpose
100 * such as satisfying allocations for a specific98 * such as satisfying allocations for a specific
101 * processor. Objects may be freed in the slab while99 * processor. Objects may be freed in the slab while
@@ -111,7 +109,7 @@ · 9 unmodified lines
111 * free objects in addition to the regular freelist109 * free objects in addition to the regular freelist
112 * that requires the slab lock.110 * that requires the slab lock.
113 *111 *
114 * PageError Slab requires special handling due to debug112 * SLAB_DEBUG_FLAGS Slab requires special handling due to debug
115 * options set. This moves slab handling out of113 * options set. This moves slab handling out of
116 * the fast path and disables lockless freelists.114 * the fast path and disables lockless freelists.
117 */115 */
@@ -736,6 +734,7 @@ static int check_bytes_and_report(struct kmem_cache *s, struct page *page, · 618 unmodified lines
736{734{
737 u8 *fault;735 u8 *fault;
738 u8 *end;736 u8 *end;
737 u8 *addr = page_address(page);
739 738
740 metadata_access_enable();739 metadata_access_enable();
741 fault = memchr_inv(start, value, bytes);740 fault = memchr_inv(start, value, bytes);
@@ -748,8 +747,9 @@ static int check_bytes_and_report(struct kmem_cache *s, struct page *page, · 6 unmodified lines
748 end--;747 end--;
749 748
750 slab_bug(s, "%s overwritten", what);749 slab_bug(s, "%s overwritten", what);
751 pr_err("INFO: 0x%p-0x%p. First byte 0x%x instead of 0x%x\n",750 pr_err("INFO: 0x%p-0x%p @offset=%tu. First byte 0x%x instead of 0x%x\n",
752 fault, end - 1, fault[0], value);751 fault, end - 1, fault - addr,
752 fault[0], value);
753 print_trailer(s, page, object);753 print_trailer(s, page, object);
754 754
755 restore_bytes(s, what, value, fault, end);755 restore_bytes(s, what, value, fault, end);
@@ -844,7 +844,8 @@ static int slab_pad_check(struct kmem_cache *s, struct page *page) · 88 unmodified lines
844 while (end > fault && end[-1] == POISON_INUSE)844 while (end > fault && end[-1] == POISON_INUSE)
845 end--;845 end--;
846 846
847 slab_err(s, page, "Padding overwritten. 0x%p-0x%p", fault, end - 1);847 slab_err(s, page, "Padding overwritten. 0x%p-0x%p @offset=%tu",
848 fault, end - 1, fault - start);
848 print_section(KERN_ERR, "Padding ", pad, remainder);849 print_section(KERN_ERR, "Padding ", pad, remainder);
849 850
850 restore_bytes(s, "slab padding", POISON_INUSE, fault, end);851 restore_bytes(s, "slab padding", POISON_INUSE, fault, end);
@@ -4383,31 +4384,26 @@ static int count_total(struct page *page) · 3532 unmodified lines
4383#endif4384#endif
4384 4385
4385#ifdef CONFIG_SLUB_DEBUG4386#ifdef CONFIG_SLUB_DEBUG
4386static int validate_slab(struct kmem_cache *s, struct page *page,4387static void validate_slab(struct kmem_cache *s, struct page *page,
4387 unsigned long *map)4388 unsigned long *map)
4388{4389{
4389 void *p;4390 void *p;
4390 void *addr = page_address(page);4391 void *addr = page_address(page);
4391 4392
4392 if (!check_slab(s, page) ||4393 if (!check_slab(s, page) || !on_freelist(s, page, NULL))
4393 !on_freelist(s, page, NULL))4394 return;
4394 return 0;
4395 4395
4396 /* Now we know that a valid freelist exists */4396 /* Now we know that a valid freelist exists */
4397 bitmap_zero(map, page->objects);4397 bitmap_zero(map, page->objects);
4398 4398
4399 get_map(s, page, map);4399 get_map(s, page, map);
4400 for_each_object(p, s, addr, page->objects) {4400 for_each_object(p, s, addr, page->objects) {
4401 if (test_bit(slab_index(p, s, addr), map))4401 u8 val = test_bit(slab_index(p, s, addr), map) ?
4402 if (!check_object(s, page, p, SLUB_RED_INACTIVE))4402 SLUB_RED_INACTIVE : SLUB_RED_ACTIVE;
4403 return 0;
4404 }
4405 4403
4406 for_each_object(p, s, addr, page->objects)4404 if (!check_object(s, page, p, val))
4407 if (!test_bit(slab_index(p, s, addr), map))4405 break;
4408 if (!check_object(s, page, p, SLUB_RED_ACTIVE))4406 }
4409 return 0;
4410 return 1;
4411}4407}
4412 4408
4413static void validate_slab_slab(struct kmem_cache *s, struct page *page,4409static void validate_slab_slab(struct kmem_cache *s, struct page *page,
mm/sparse.c+10−8
@@ -458,8 +458,7 @@ struct page __init *__populate_section_memmap(unsigned long pfn, · 457 unmodified lines
458 if (map)458 if (map)
459 return map;459 return map;
460 460
461 map = memblock_alloc_try_nid(size,461 map = memblock_alloc_try_nid_raw(size, size, addr,
462 PAGE_SIZE, addr,
463 MEMBLOCK_ALLOC_ACCESSIBLE, nid);462 MEMBLOCK_ALLOC_ACCESSIBLE, nid);
464 if (!map)463 if (!map)
465 panic("%s: Failed to allocate %lu bytes align=0x%lx nid=%d from=%pa\n",464 panic("%s: Failed to allocate %lu bytes align=0x%lx nid=%d from=%pa\n",
@@ -482,10 +481,13 @@ static void __init sparse_buffer_init(unsigned long size, int nid) · 16 unmodified lines
482{481{
483 phys_addr_t addr = __pa(MAX_DMA_ADDRESS);482 phys_addr_t addr = __pa(MAX_DMA_ADDRESS);
484 WARN_ON(sparsemap_buf); /* forgot to call sparse_buffer_fini()? */483 WARN_ON(sparsemap_buf); /* forgot to call sparse_buffer_fini()? */
485 sparsemap_buf =484 /*
486 memblock_alloc_try_nid_raw(size, PAGE_SIZE,485 * Pre-allocated buffer is mainly used by __populate_section_memmap
487 addr,486 * and we want it to be properly aligned to the section size - this is
488 MEMBLOCK_ALLOC_ACCESSIBLE, nid);487 * especially the case for VMEMMAP which maps memmap to PMDs
488 */
489 sparsemap_buf = memblock_alloc_exact_nid_raw(size, section_map_size(),
490 addr, MEMBLOCK_ALLOC_ACCESSIBLE, nid);
489 sparsemap_buf_end = sparsemap_buf + size;491 sparsemap_buf_end = sparsemap_buf + size;
490}492}
491 493
@@ -647,7 +649,7 @@ void offline_mem_sections(unsigned long start_pfn, unsigned long end_pfn) · 155 unmodified lines
647#endif649#endif
648 650
649#ifdef CONFIG_SPARSEMEM_VMEMMAP651#ifdef CONFIG_SPARSEMEM_VMEMMAP
650static struct page *populate_section_memmap(unsigned long pfn,652static struct page * __meminit populate_section_memmap(unsigned long pfn,
651 unsigned long nr_pages, int nid, struct vmem_altmap *altmap)653 unsigned long nr_pages, int nid, struct vmem_altmap *altmap)
652{654{
653 return __populate_section_memmap(pfn, nr_pages, nid, altmap);655 return __populate_section_memmap(pfn, nr_pages, nid, altmap);
@@ -669,7 +671,7 @@ static void free_map_bootmem(struct page *memmap) · 15 unmodified lines
669 vmemmap_free(start, end, NULL);671 vmemmap_free(start, end, NULL);
670}672}
671#else673#else
672struct page *populate_section_memmap(unsigned long pfn,674struct page * __meminit populate_section_memmap(unsigned long pfn,
673 unsigned long nr_pages, int nid, struct vmem_altmap *altmap)675 unsigned long nr_pages, int nid, struct vmem_altmap *altmap)
674{676{
675 struct page *page, *ret;677 struct page *page, *ret;
mm/swap.c+24−5
@@ -373,9 +373,16 @@ static void __lru_cache_activate_page(struct page *page) · 372 unmodified lines
373void mark_page_accessed(struct page *page)373void mark_page_accessed(struct page *page)
374{374{
375 page = compound_head(page);375 page = compound_head(page);
376 if (!PageActive(page) && !PageUnevictable(page) &&
377 PageReferenced(page)) {
378 376
377 if (!PageReferenced(page)) {
378 SetPageReferenced(page);
379 } else if (PageUnevictable(page)) {
380 /*
381 * Unevictable pages are on the "LRU_UNEVICTABLE" list. But,
382 * this list is never rotated or maintained, so marking an
383 * evictable page accessed has no effect.
384 */
385 } else if (!PageActive(page)) {
379 /*386 /*
380 * If the page is on the LRU, queue it for activation via387 * If the page is on the LRU, queue it for activation via
381 * activate_page_pvecs. Otherwise, assume the page is on a388 * activate_page_pvecs. Otherwise, assume the page is on a
@@ -389,8 +396,6 @@ void mark_page_accessed(struct page *page) · 7 unmodified lines
389 ClearPageReferenced(page);396 ClearPageReferenced(page);
390 if (page_is_file_cache(page))397 if (page_is_file_cache(page))
391 workingset_activation(page);398 workingset_activation(page);
392 } else if (!PageReferenced(page)) {
393 SetPageReferenced(page);
394 }399 }
395 if (page_is_idle(page))400 if (page_is_idle(page))
396 clear_page_idle(page);401 clear_page_idle(page);
@@ -708,9 +713,10 @@ static void lru_add_drain_per_cpu(struct work_struct *dummy) · 311 unmodified lines
708 */713 */
709void lru_add_drain_all(void)714void lru_add_drain_all(void)
710{715{
716 static seqcount_t seqcount = SEQCNT_ZERO(seqcount);
711 static DEFINE_MUTEX(lock);717 static DEFINE_MUTEX(lock);
712 static struct cpumask has_work;718 static struct cpumask has_work;
713 int cpu;719 int cpu, seq;
714 720
715 /*721 /*
716 * Make sure nobody triggers this path before mm_percpu_wq is fully722 * Make sure nobody triggers this path before mm_percpu_wq is fully
@@ -719,7 +725,19 @@ void lru_add_drain_all(void) · 2 unmodified lines
719 if (WARN_ON(!mm_percpu_wq))725 if (WARN_ON(!mm_percpu_wq))
720 return;726 return;
721 727
728 seq = raw_read_seqcount_latch(&seqcount);
729
722 mutex_lock(&lock);730 mutex_lock(&lock);
731
732 /*
733 * Piggyback on drain started and finished while we waited for lock:
734 * all pages pended at the time of our enter were drained from vectors.
735 */
736 if (__read_seqcount_retry(&seqcount, seq))
737 goto done;
738
739 raw_write_seqcount_latch(&seqcount);
740
723 cpumask_clear(&has_work);741 cpumask_clear(&has_work);
724 742
725 for_each_online_cpu(cpu) {743 for_each_online_cpu(cpu) {
@@ -740,6 +758,7 @@ void lru_add_drain_all(void) · 14 unmodified lines
740 for_each_cpu(cpu, &has_work)758 for_each_cpu(cpu, &has_work)
741 flush_work(&per_cpu(lru_add_drain_work, cpu));759 flush_work(&per_cpu(lru_add_drain_work, cpu));
742 760
761done:
743 mutex_unlock(&lock);762 mutex_unlock(&lock);
744}763}
745#else764#else
mm/swapfile.c+7−0
@@ -2887,6 +2887,13 @@ static int claim_swapfile(struct swap_info_struct *p, struct inode *inode) · 2886 unmodified lines
2887 error = set_blocksize(p->bdev, PAGE_SIZE);2887 error = set_blocksize(p->bdev, PAGE_SIZE);
2888 if (error < 0)2888 if (error < 0)
2889 return error;2889 return error;
2890 /*
2891 * Zoned block devices contain zones that have a sequential
2892 * write only restriction. Hence zoned block devices are not
2893 * suitable for swapping. Disallow them here.
2894 */
2895 if (blk_queue_is_zoned(p->bdev->bd_queue))
2896 return -EINVAL;
2890 p->flags |= SWP_BLKDEV;2897 p->flags |= SWP_BLKDEV;
2891 } else if (S_ISREG(inode->i_mode)) {2898 } else if (S_ISREG(inode->i_mode)) {
2892 p->bdev = inode->i_sb->s_bdev;2899 p->bdev = inode->i_sb->s_bdev;
mm/userfaultfd.c+37−36
@@ -18,6 +18,36 @@ · 17 unmodified lines
18#include <asm/tlbflush.h>18#include <asm/tlbflush.h>
19#include "internal.h"19#include "internal.h"
20 20
21static __always_inline
22struct vm_area_struct *find_dst_vma(struct mm_struct *dst_mm,
23 unsigned long dst_start,
24 unsigned long len)
25{
26 /*
27 * Make sure that the dst range is both valid and fully within a
28 * single existing vma.
29 */
30 struct vm_area_struct *dst_vma;
31
32 dst_vma = find_vma(dst_mm, dst_start);
33 if (!dst_vma)
34 return NULL;
35
36 if (dst_start < dst_vma->vm_start ||
37 dst_start + len > dst_vma->vm_end)
38 return NULL;
39
40 /*
41 * Check the vma is registered in uffd, this is required to
42 * enforce the VM_MAYWRITE check done at uffd registration
43 * time.
44 */
45 if (!dst_vma->vm_userfaultfd_ctx.ctx)
46 return NULL;
47
48 return dst_vma;
49}
50
21static int mcopy_atomic_pte(struct mm_struct *dst_mm,51static int mcopy_atomic_pte(struct mm_struct *dst_mm,
22 pmd_t *dst_pmd,52 pmd_t *dst_pmd,
23 struct vm_area_struct *dst_vma,53 struct vm_area_struct *dst_vma,
@@ -60,7 +90,7 @@ static int mcopy_atomic_pte(struct mm_struct *dst_mm, · 36 unmodified lines
60 90
61 /*91 /*
62 * The memory barrier inside __SetPageUptodate makes sure that92 * The memory barrier inside __SetPageUptodate makes sure that
63 * preceeding stores to the page contents become visible before93 * preceding stores to the page contents become visible before
64 * the set_pte_at() write.94 * the set_pte_at() write.
65 */95 */
66 __SetPageUptodate(page);96 __SetPageUptodate(page);
@@ -184,7 +214,6 @@ static __always_inline ssize_t __mcopy_atomic_hugetlb(struct mm_struct *dst_mm, · 117 unmodified lines
184 unsigned long src_addr, dst_addr;214 unsigned long src_addr, dst_addr;
185 long copied;215 long copied;
186 struct page *page;216 struct page *page;
187 struct hstate *h;
188 unsigned long vma_hpagesize;217 unsigned long vma_hpagesize;
189 pgoff_t idx;218 pgoff_t idx;
190 u32 hash;219 u32 hash;
@@ -221,20 +250,9 @@ retry: · 30 unmodified lines
221 */250 */
222 if (!dst_vma) {251 if (!dst_vma) {
223 err = -ENOENT;252 err = -ENOENT;
224 dst_vma = find_vma(dst_mm, dst_start);253 dst_vma = find_dst_vma(dst_mm, dst_start, len);
225 if (!dst_vma || !is_vm_hugetlb_page(dst_vma))254 if (!dst_vma || !is_vm_hugetlb_page(dst_vma))
226 goto out_unlock;255 goto out_unlock;
227 /*
228 * Check the vma is registered in uffd, this is
229 * required to enforce the VM_MAYWRITE check done at
230 * uffd registration time.
231 */
232 if (!dst_vma->vm_userfaultfd_ctx.ctx)
233 goto out_unlock;
234
235 if (dst_start < dst_vma->vm_start ||
236 dst_start + len > dst_vma->vm_end)
237 goto out_unlock;
238 256
239 err = -EINVAL;257 err = -EINVAL;
240 if (vma_hpagesize != vma_kernel_pagesize(dst_vma))258 if (vma_hpagesize != vma_kernel_pagesize(dst_vma))
@@ -243,10 +261,6 @@ retry: · 2 unmodified lines
243 vm_shared = dst_vma->vm_flags & VM_SHARED;261 vm_shared = dst_vma->vm_flags & VM_SHARED;
244 }262 }
245 263
246 if (WARN_ON(dst_addr & (vma_hpagesize - 1) ||
247 (len - copied) & (vma_hpagesize - 1)))
248 goto out_unlock;
249
250 /*264 /*
251 * If not shared, ensure the dst_vma has a anon_vma.265 * If not shared, ensure the dst_vma has a anon_vma.
252 */266 */
@@ -256,24 +270,21 @@ retry: · 3 unmodified lines
256 goto out_unlock;270 goto out_unlock;
257 }271 }
258 272
259 h = hstate_vma(dst_vma);
260
261 while (src_addr < src_start + len) {273 while (src_addr < src_start + len) {
262 pte_t dst_pteval;274 pte_t dst_pteval;
263 275
264 BUG_ON(dst_addr >= dst_start + len);276 BUG_ON(dst_addr >= dst_start + len);
265 VM_BUG_ON(dst_addr & ~huge_page_mask(h));
266 277
267 /*278 /*
268 * Serialize via hugetlb_fault_mutex279 * Serialize via hugetlb_fault_mutex
269 */280 */
270 idx = linear_page_index(dst_vma, dst_addr);281 idx = linear_page_index(dst_vma, dst_addr);
271 mapping = dst_vma->vm_file->f_mapping;282 mapping = dst_vma->vm_file->f_mapping;
272 hash = hugetlb_fault_mutex_hash(h, mapping, idx, dst_addr);283 hash = hugetlb_fault_mutex_hash(mapping, idx);
273 mutex_lock(&hugetlb_fault_mutex_table[hash]);284 mutex_lock(&hugetlb_fault_mutex_table[hash]);
274 285
275 err = -ENOMEM;286 err = -ENOMEM;
276 dst_pte = huge_pte_alloc(dst_mm, dst_addr, huge_page_size(h));287 dst_pte = huge_pte_alloc(dst_mm, dst_addr, vma_hpagesize);
277 if (!dst_pte) {288 if (!dst_pte) {
278 mutex_unlock(&hugetlb_fault_mutex_table[hash]);289 mutex_unlock(&hugetlb_fault_mutex_table[hash]);
279 goto out_unlock;290 goto out_unlock;
@@ -300,7 +311,8 @@ retry: · 20 unmodified lines
300 311
301 err = copy_huge_page_from_user(page,312 err = copy_huge_page_from_user(page,
302 (const void __user *)src_addr,313 (const void __user *)src_addr,
303 pages_per_huge_page(h), true);314 vma_hpagesize / PAGE_SIZE,
315 true);
304 if (unlikely(err)) {316 if (unlikely(err)) {
305 err = -EFAULT;317 err = -EFAULT;
306 goto out;318 goto out;
@@ -475,20 +487,9 @@ retry: · 168 unmodified lines
475 * both valid and fully within a single existing vma.487 * both valid and fully within a single existing vma.
476 */488 */
477 err = -ENOENT;489 err = -ENOENT;
478 dst_vma = find_vma(dst_mm, dst_start);490 dst_vma = find_dst_vma(dst_mm, dst_start, len);
479 if (!dst_vma)491 if (!dst_vma)
480 goto out_unlock;492 goto out_unlock;
481 /*
482 * Check the vma is registered in uffd, this is required to
483 * enforce the VM_MAYWRITE check done at uffd registration
484 * time.
485 */
486 if (!dst_vma->vm_userfaultfd_ctx.ctx)
487 goto out_unlock;
488
489 if (dst_start < dst_vma->vm_start ||
490 dst_start + len > dst_vma->vm_end)
491 goto out_unlock;
492 493
493 err = -EINVAL;494 err = -EINVAL;
494 /*495 /*
mm/util.c+16−6
@@ -271,7 +271,7 @@ void *memdup_user_nul(const void __user *src, size_t len) · 270 unmodified lines
271EXPORT_SYMBOL(memdup_user_nul);271EXPORT_SYMBOL(memdup_user_nul);
272 272
273void __vma_link_list(struct mm_struct *mm, struct vm_area_struct *vma,273void __vma_link_list(struct mm_struct *mm, struct vm_area_struct *vma,
274 struct vm_area_struct *prev, struct rb_node *rb_parent)274 struct vm_area_struct *prev)
275{275{
276 struct vm_area_struct *next;276 struct vm_area_struct *next;
277 277
@@ -280,18 +280,28 @@ void __vma_link_list(struct mm_struct *mm, struct vm_area_struct *vma, · 2 unmodified lines
280 next = prev->vm_next;280 next = prev->vm_next;
281 prev->vm_next = vma;281 prev->vm_next = vma;
282 } else {282 } else {
283 next = mm->mmap;
283 mm->mmap = vma;284 mm->mmap = vma;
284 if (rb_parent)
285 next = rb_entry(rb_parent,
286 struct vm_area_struct, vm_rb);
287 else
288 next = NULL;
289 }285 }
290 vma->vm_next = next;286 vma->vm_next = next;
291 if (next)287 if (next)
292 next->vm_prev = vma;288 next->vm_prev = vma;
293}289}
294 290
291void __vma_unlink_list(struct mm_struct *mm, struct vm_area_struct *vma)
292{
293 struct vm_area_struct *prev, *next;
294
295 next = vma->vm_next;
296 prev = vma->vm_prev;
297 if (prev)
298 prev->vm_next = next;
299 else
300 mm->mmap = next;
301 if (next)
302 next->vm_prev = prev;
303}
304
295/* Check if the vma is being used as a stack by this task */305/* Check if the vma is being used as a stack by this task */
296int vma_is_stack_for_current(struct vm_area_struct *vma)306int vma_is_stack_for_current(struct vm_area_struct *vma)
297{307{
mm/vmalloc.c+134−58
@@ -331,6 +331,7 @@ EXPORT_SYMBOL(vmalloc_to_pfn); · 330 unmodified lines
331 331
332 332
333static DEFINE_SPINLOCK(vmap_area_lock);333static DEFINE_SPINLOCK(vmap_area_lock);
334static DEFINE_SPINLOCK(free_vmap_area_lock);
334/* Export for kexec only */335/* Export for kexec only */
335LIST_HEAD(vmap_area_list);336LIST_HEAD(vmap_area_list);
336static LLIST_HEAD(vmap_purge_list);337static LLIST_HEAD(vmap_purge_list);
@@ -682,7 +683,7 @@ insert_vmap_area_augment(struct vmap_area *va, · 345 unmodified lines
682 * free area is inserted. If VA has been merged, it is683 * free area is inserted. If VA has been merged, it is
683 * freed.684 * freed.
684 */685 */
685static __always_inline void686static __always_inline struct vmap_area *
686merge_or_add_vmap_area(struct vmap_area *va,687merge_or_add_vmap_area(struct vmap_area *va,
687 struct rb_root *root, struct list_head *head)688 struct rb_root *root, struct list_head *head)
688{689{
@@ -749,7 +750,10 @@ merge_or_add_vmap_area(struct vmap_area *va, · 60 unmodified lines
749 750
750 /* Free vmap_area object. */751 /* Free vmap_area object. */
751 kmem_cache_free(vmap_area_cachep, va);752 kmem_cache_free(vmap_area_cachep, va);
752 return;753
754 /* Point to the new merged area. */
755 va = sibling;
756 merged = true;
753 }757 }
754 }758 }
755 759
@@ -758,6 +762,8 @@ insert: · 2 unmodified lines
758 link_va(va, root, parent, link, head);762 link_va(va, root, parent, link, head);
759 augment_tree_propagate_from(va);763 augment_tree_propagate_from(va);
760 }764 }
765
766 return va;
761}767}
762 768
763static __always_inline bool769static __always_inline bool
@@ -968,6 +974,19 @@ adjust_va_to_fit_type(struct vmap_area *va, · 204 unmodified lines
968 * There are a few exceptions though, as an example it is974 * There are a few exceptions though, as an example it is
969 * a first allocation (early boot up) when we have "one"975 * a first allocation (early boot up) when we have "one"
970 * big free space that has to be split.976 * big free space that has to be split.
977 *
978 * Also we can hit this path in case of regular "vmap"
979 * allocations, if "this" current CPU was not preloaded.
980 * See the comment in alloc_vmap_area() why. If so, then
981 * GFP_NOWAIT is used instead to get an extra object for
982 * split purpose. That is rare and most time does not
983 * occur.
984 *
985 * What happens if an allocation gets failed. Basically,
986 * an "overflow" path is triggered to purge lazily freed
987 * areas to free some memory, then, the "retry" path is
988 * triggered to repeat one more time. See more details
989 * in alloc_vmap_area() function.
971 */990 */
972 lva = kmem_cache_alloc(vmap_area_cachep, GFP_NOWAIT);991 lva = kmem_cache_alloc(vmap_area_cachep, GFP_NOWAIT);
973 if (!lva)992 if (!lva)
@@ -1063,9 +1082,9 @@ static struct vmap_area *alloc_vmap_area(unsigned long size, · 89 unmodified lines
1063 return ERR_PTR(-EBUSY);1082 return ERR_PTR(-EBUSY);
1064 1083
1065 might_sleep();1084 might_sleep();
1085 gfp_mask = gfp_mask & GFP_RECLAIM_MASK;
1066 1086
1067 va = kmem_cache_alloc_node(vmap_area_cachep,1087 va = kmem_cache_alloc_node(vmap_area_cachep, gfp_mask, node);
1068 gfp_mask & GFP_RECLAIM_MASK, node);
1069 if (unlikely(!va))1088 if (unlikely(!va))
1070 return ERR_PTR(-ENOMEM);1089 return ERR_PTR(-ENOMEM);
1071 1090
@@ -1073,49 +1092,55 @@ static struct vmap_area *alloc_vmap_area(unsigned long size, · 1 unmodified line
1073 * Only scan the relevant parts containing pointers to other objects1092 * Only scan the relevant parts containing pointers to other objects
1074 * to avoid false negatives.1093 * to avoid false negatives.
1075 */1094 */
1076 kmemleak_scan_area(&va->rb_node, SIZE_MAX, gfp_mask & GFP_RECLAIM_MASK);1095 kmemleak_scan_area(&va->rb_node, SIZE_MAX, gfp_mask);
1077 1096
1078retry:1097retry:
1079 /*1098 /*
1080 * Preload this CPU with one extra vmap_area object to ensure1099 * Preload this CPU with one extra vmap_area object. It is used
1081 * that we have it available when fit type of free area is1100 * when fit type of free area is NE_FIT_TYPE. Please note, it
1082 * NE_FIT_TYPE.1101 * does not guarantee that an allocation occurs on a CPU that
1102 * is preloaded, instead we minimize the case when it is not.
1103 * It can happen because of cpu migration, because there is a
1104 * race until the below spinlock is taken.
1083 *1105 *
1084 * The preload is done in non-atomic context, thus it allows us1106 * The preload is done in non-atomic context, thus it allows us
1085 * to use more permissive allocation masks to be more stable under1107 * to use more permissive allocation masks to be more stable under
1086 * low memory condition and high memory pressure.1108 * low memory condition and high memory pressure. In rare case,
1109 * if not preloaded, GFP_NOWAIT is used.
1087 *1110 *
1088 * Even if it fails we do not really care about that. Just proceed1111 * Set "pva" to NULL here, because of "retry" path.
1089 * as it is. "overflow" path will refill the cache we allocate from.
1090 */1112 */
1091 preempt_disable();1113 pva = NULL;
1092 if (!__this_cpu_read(ne_fit_preload_node)) {
1093 preempt_enable();
1094 pva = kmem_cache_alloc_node(vmap_area_cachep, GFP_KERNEL, node);
1095 preempt_disable();
1096
1097 if (__this_cpu_cmpxchg(ne_fit_preload_node, NULL, pva)) {
1098 if (pva)
1099 kmem_cache_free(vmap_area_cachep, pva);
1100 }
1101 }
1102 1114
1103 spin_lock(&vmap_area_lock);1115 if (!this_cpu_read(ne_fit_preload_node))
1104 preempt_enable();1116 /*
1117 * Even if it fails we do not really care about that.
1118 * Just proceed as it is. If needed "overflow" path
1119 * will refill the cache we allocate from.
1120 */
1121 pva = kmem_cache_alloc_node(vmap_area_cachep, gfp_mask, node);
1122
1123 spin_lock(&free_vmap_area_lock);
1124
1125 if (pva && __this_cpu_cmpxchg(ne_fit_preload_node, NULL, pva))
1126 kmem_cache_free(vmap_area_cachep, pva);
1105 1127
1106 /*1128 /*
1107 * If an allocation fails, the "vend" address is1129 * If an allocation fails, the "vend" address is
1108 * returned. Therefore trigger the overflow path.1130 * returned. Therefore trigger the overflow path.
1109 */1131 */
1110 addr = __alloc_vmap_area(size, align, vstart, vend);1132 addr = __alloc_vmap_area(size, align, vstart, vend);
1133 spin_unlock(&free_vmap_area_lock);
1134
1111 if (unlikely(addr == vend))1135 if (unlikely(addr == vend))
1112 goto overflow;1136 goto overflow;
1113 1137
1114 va->va_start = addr;1138 va->va_start = addr;
1115 va->va_end = addr + size;1139 va->va_end = addr + size;
1116 va->vm = NULL;1140 va->vm = NULL;
1117 insert_vmap_area(va, &vmap_area_root, &vmap_area_list);
1118 1141
1142 spin_lock(&vmap_area_lock);
1143 insert_vmap_area(va, &vmap_area_root, &vmap_area_list);
1119 spin_unlock(&vmap_area_lock);1144 spin_unlock(&vmap_area_lock);
1120 1145
1121 BUG_ON(!IS_ALIGNED(va->va_start, align));1146 BUG_ON(!IS_ALIGNED(va->va_start, align));
@@ -1125,7 +1150,6 @@ retry: · 3 unmodified lines
1125 return va;1150 return va;
1126 1151
1127overflow:1152overflow:
1128 spin_unlock(&vmap_area_lock);
1129 if (!purged) {1153 if (!purged) {
1130 purge_vmap_area_lazy();1154 purge_vmap_area_lazy();
1131 purged = 1;1155 purged = 1;
@@ -1161,28 +1185,24 @@ int unregister_vmap_purge_notifier(struct notifier_block *nb) · 29 unmodified lines
1161}1185}
1162EXPORT_SYMBOL_GPL(unregister_vmap_purge_notifier);1186EXPORT_SYMBOL_GPL(unregister_vmap_purge_notifier);
1163 1187
1164static void __free_vmap_area(struct vmap_area *va)1188/*
1189 * Free a region of KVA allocated by alloc_vmap_area
1190 */
1191static void free_vmap_area(struct vmap_area *va)
1165{1192{
1166 /*1193 /*
1167 * Remove from the busy tree/list.1194 * Remove from the busy tree/list.
1168 */1195 */
1196 spin_lock(&vmap_area_lock);
1169 unlink_va(va, &vmap_area_root);1197 unlink_va(va, &vmap_area_root);
1198 spin_unlock(&vmap_area_lock);
1170 1199
1171 /*1200 /*
1172 * Merge VA with its neighbors, otherwise just add it.1201 * Insert/Merge it back to the free tree/list.
1173 */1202 */
1174 merge_or_add_vmap_area(va,1203 spin_lock(&free_vmap_area_lock);
1175 &free_vmap_area_root, &free_vmap_area_list);1204 merge_or_add_vmap_area(va, &free_vmap_area_root, &free_vmap_area_list);
1176}1205 spin_unlock(&free_vmap_area_lock);
1177
1178/*
1179 * Free a region of KVA allocated by alloc_vmap_area
1180 */
1181static void free_vmap_area(struct vmap_area *va)
1182{
1183 spin_lock(&vmap_area_lock);
1184 __free_vmap_area(va);
1185 spin_unlock(&vmap_area_lock);
1186}1206}
1187 1207
1188/*1208/*
@@ -1275,24 +1295,30 @@ static bool __purge_vmap_area_lazy(unsigned long start, unsigned long end) · 86 unmodified lines
1275 flush_tlb_kernel_range(start, end);1295 flush_tlb_kernel_range(start, end);
1276 resched_threshold = lazy_max_pages() << 1;1296 resched_threshold = lazy_max_pages() << 1;
1277 1297
1278 spin_lock(&vmap_area_lock);1298 spin_lock(&free_vmap_area_lock);
1279 llist_for_each_entry_safe(va, n_va, valist, purge_list) {1299 llist_for_each_entry_safe(va, n_va, valist, purge_list) {
1280 unsigned long nr = (va->va_end - va->va_start) >> PAGE_SHIFT;1300 unsigned long nr = (va->va_end - va->va_start) >> PAGE_SHIFT;
1301 unsigned long orig_start = va->va_start;
1302 unsigned long orig_end = va->va_end;
1281 1303
1282 /*1304 /*
1283 * Finally insert or merge lazily-freed area. It is1305 * Finally insert or merge lazily-freed area. It is
1284 * detached and there is no need to "unlink" it from1306 * detached and there is no need to "unlink" it from
1285 * anything.1307 * anything.
1286 */1308 */
1287 merge_or_add_vmap_area(va,1309 va = merge_or_add_vmap_area(va, &free_vmap_area_root,
1288 &free_vmap_area_root, &free_vmap_area_list);1310 &free_vmap_area_list);
1311
1312 if (is_vmalloc_or_module_addr((void *)orig_start))
1313 kasan_release_vmalloc(orig_start, orig_end,
1314 va->va_start, va->va_end);
1289 1315
1290 atomic_long_sub(nr, &vmap_lazy_nr);1316 atomic_long_sub(nr, &vmap_lazy_nr);
1291 1317
1292 if (atomic_long_read(&vmap_lazy_nr) < resched_threshold)1318 if (atomic_long_read(&vmap_lazy_nr) < resched_threshold)
1293 cond_resched_lock(&vmap_area_lock);1319 cond_resched_lock(&free_vmap_area_lock);
1294 }1320 }
1295 spin_unlock(&vmap_area_lock);1321 spin_unlock(&free_vmap_area_lock);
1296 return true;1322 return true;
1297}1323}
1298 1324
@@ -2014,15 +2040,21 @@ int map_vm_area(struct vm_struct *area, pgprot_t prot, struct page **pages) · 715 unmodified lines
2014}2040}
2015EXPORT_SYMBOL_GPL(map_vm_area);2041EXPORT_SYMBOL_GPL(map_vm_area);
2016 2042
2017static void setup_vmalloc_vm(struct vm_struct *vm, struct vmap_area *va,2043static inline void setup_vmalloc_vm_locked(struct vm_struct *vm,
2018 unsigned long flags, const void *caller)2044 struct vmap_area *va, unsigned long flags, const void *caller)
2019{2045{
2020 spin_lock(&vmap_area_lock);
2021 vm->flags = flags;2046 vm->flags = flags;
2022 vm->addr = (void *)va->va_start;2047 vm->addr = (void *)va->va_start;
2023 vm->size = va->va_end - va->va_start;2048 vm->size = va->va_end - va->va_start;
2024 vm->caller = caller;2049 vm->caller = caller;
2025 va->vm = vm;2050 va->vm = vm;
2051}
2052
2053static void setup_vmalloc_vm(struct vm_struct *vm, struct vmap_area *va,
2054 unsigned long flags, const void *caller)
2055{
2056 spin_lock(&vmap_area_lock);
2057 setup_vmalloc_vm_locked(vm, va, flags, caller);
2026 spin_unlock(&vmap_area_lock);2058 spin_unlock(&vmap_area_lock);
2027}2059}
2028 2060
@@ -2068,6 +2100,22 @@ static struct vm_struct *__get_vm_area_node(unsigned long size, · 39 unmodified lines
2068 2100
2069 setup_vmalloc_vm(area, va, flags, caller);2101 setup_vmalloc_vm(area, va, flags, caller);
2070 2102
2103 /*
2104 * For KASAN, if we are in vmalloc space, we need to cover the shadow
2105 * area with real memory. If we come here through VM_ALLOC, this is
2106 * done by a higher level function that has access to the true size,
2107 * which might not be a full page.
2108 *
2109 * We assume module space comes via VM_ALLOC path.
2110 */
2111 if (is_vmalloc_addr(area->addr) && !(area->flags & VM_ALLOC)) {
2112 if (kasan_populate_vmalloc(area->size, area)) {
2113 unmap_vmap_area(va);
2114 kfree(area);
2115 return NULL;
2116 }
2117 }
2118
2071 return area;2119 return area;
2072}2120}
2073 2121
@@ -2245,6 +2293,9 @@ static void __vunmap(const void *addr, int deallocate_pages) · 171 unmodified lines
2245 debug_check_no_locks_freed(area->addr, get_vm_area_size(area));2293 debug_check_no_locks_freed(area->addr, get_vm_area_size(area));
2246 debug_check_no_obj_freed(area->addr, get_vm_area_size(area));2294 debug_check_no_obj_freed(area->addr, get_vm_area_size(area));
2247 2295
2296 if (area->flags & VM_KASAN)
2297 kasan_poison_vmalloc(area->addr, area->size);
2298
2248 vm_remove_mappings(area, deallocate_pages);2299 vm_remove_mappings(area, deallocate_pages);
2249 2300
2250 if (deallocate_pages) {2301 if (deallocate_pages) {
@@ -2440,7 +2491,7 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask, · 189 unmodified lines
2440 goto fail;2491 goto fail;
2441 }2492 }
2442 area->pages[i] = page;2493 area->pages[i] = page;
2443 if (gfpflags_allow_blocking(gfp_mask|highmem_mask))2494 if (gfpflags_allow_blocking(gfp_mask))
2444 cond_resched();2495 cond_resched();
2445 }2496 }
2446 atomic_long_add(area->nr_pages, &nr_vmalloc_pages);2497 atomic_long_add(area->nr_pages, &nr_vmalloc_pages);
@@ -2497,6 +2548,11 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align, · 50 unmodified lines
2497 if (!addr)2548 if (!addr)
2498 return NULL;2549 return NULL;
2499 2550
2551 if (is_vmalloc_or_module_addr(area->addr)) {
2552 if (kasan_populate_vmalloc(real_size, area))
2553 return NULL;
2554 }
2555
2500 /*2556 /*
2501 * In this function, newly allocated vm_struct has VM_UNINITIALIZED2557 * In this function, newly allocated vm_struct has VM_UNINITIALIZED
2502 * flag. It means that vm_struct is not fully initialized.2558 * flag. It means that vm_struct is not fully initialized.
@@ -3282,7 +3338,7 @@ struct vm_struct **pcpu_get_vm_areas(const unsigned long *offsets, · 779 unmodified lines
3282 goto err_free;3338 goto err_free;
3283 }3339 }
3284retry:3340retry:
3285 spin_lock(&vmap_area_lock);3341 spin_lock(&free_vmap_area_lock);
3286 3342
3287 /* start scanning - we scan from the top, begin with the last area */3343 /* start scanning - we scan from the top, begin with the last area */
3288 area = term_area = last_area;3344 area = term_area = last_area;
@@ -3364,29 +3420,44 @@ retry: · 75 unmodified lines
3364 va = vas[area];3420 va = vas[area];
3365 va->va_start = start;3421 va->va_start = start;
3366 va->va_end = start + size;3422 va->va_end = start + size;
3367
3368 insert_vmap_area(va, &vmap_area_root, &vmap_area_list);
3369 }3423 }
3370 3424
3371 spin_unlock(&vmap_area_lock);3425 spin_unlock(&free_vmap_area_lock);
3372 3426
3373 /* insert all vm's */3427 /* insert all vm's */
3374 for (area = 0; area < nr_vms; area++)3428 spin_lock(&vmap_area_lock);
3375 setup_vmalloc_vm(vms[area], vas[area], VM_ALLOC,3429 for (area = 0; area < nr_vms; area++) {
3430 insert_vmap_area(vas[area], &vmap_area_root, &vmap_area_list);
3431
3432 setup_vmalloc_vm_locked(vms[area], vas[area], VM_ALLOC,
3376 pcpu_get_vm_areas);3433 pcpu_get_vm_areas);
3434 }
3435 spin_unlock(&vmap_area_lock);
3436
3437 /* populate the shadow space outside of the lock */
3438 for (area = 0; area < nr_vms; area++) {
3439 /* assume success here */
3440 kasan_populate_vmalloc(sizes[area], vms[area]);
3441 }
3377 3442
3378 kfree(vas);3443 kfree(vas);
3379 return vms;3444 return vms;
3380 3445
3381recovery:3446recovery:
3382 /* Remove previously inserted areas. */3447 /*
3448 * Remove previously allocated areas. There is no
3449 * need in removing these areas from the busy tree,
3450 * because they are inserted only on the final step
3451 * and when pcpu_get_vm_areas() is success.
3452 */
3383 while (area--) {3453 while (area--) {
3384 __free_vmap_area(vas[area]);3454 merge_or_add_vmap_area(vas[area], &free_vmap_area_root,
3455 &free_vmap_area_list);
3385 vas[area] = NULL;3456 vas[area] = NULL;
3386 }3457 }
3387 3458
3388overflow:3459overflow:
3389 spin_unlock(&vmap_area_lock);3460 spin_unlock(&free_vmap_area_lock);
3390 if (!purged) {3461 if (!purged) {
3391 purge_vmap_area_lazy();3462 purge_vmap_area_lazy();
3392 purged = true;3463 purged = true;
@@ -3437,9 +3508,12 @@ void pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms) · 44 unmodified lines
3437 3508
3438#ifdef CONFIG_PROC_FS3509#ifdef CONFIG_PROC_FS
3439static void *s_start(struct seq_file *m, loff_t *pos)3510static void *s_start(struct seq_file *m, loff_t *pos)
3511 __acquires(&vmap_purge_lock)
3440 __acquires(&vmap_area_lock)3512 __acquires(&vmap_area_lock)
3441{3513{
3514 mutex_lock(&vmap_purge_lock);
3442 spin_lock(&vmap_area_lock);3515 spin_lock(&vmap_area_lock);
3516
3443 return seq_list_start(&vmap_area_list, *pos);3517 return seq_list_start(&vmap_area_list, *pos);
3444}3518}
3445 3519
@@ -3449,8 +3523,10 @@ static void *s_next(struct seq_file *m, void *p, loff_t *pos) · 3 unmodified lines
3449}3523}
3450 3524
3451static void s_stop(struct seq_file *m, void *p)3525static void s_stop(struct seq_file *m, void *p)
3526 __releases(&vmap_purge_lock)
3452 __releases(&vmap_area_lock)3527 __releases(&vmap_area_lock)
3453{3528{
3529 mutex_unlock(&vmap_purge_lock);
3454 spin_unlock(&vmap_area_lock);3530 spin_unlock(&vmap_area_lock);
3455}3531}
3456 3532
mm/vmscan.c+327−335
@@ -79,6 +79,13 @@ struct scan_control { · 78 unmodified lines
79 */79 */
80 struct mem_cgroup *target_mem_cgroup;80 struct mem_cgroup *target_mem_cgroup;
81 81
82 /* Can active pages be deactivated as part of reclaim? */
83#define DEACTIVATE_ANON 1
84#define DEACTIVATE_FILE 2
85 unsigned int may_deactivate:2;
86 unsigned int force_deactivate:1;
87 unsigned int skipped_deactivate:1;
88
82 /* Writepage batching in laptop mode; RECLAIM_WRITE */89 /* Writepage batching in laptop mode; RECLAIM_WRITE */
83 unsigned int may_writepage:1;90 unsigned int may_writepage:1;
84 91
@@ -101,6 +108,12 @@ struct scan_control { · 16 unmodified lines
101 /* One of the zones is ready for compaction */108 /* One of the zones is ready for compaction */
102 unsigned int compaction_ready:1;109 unsigned int compaction_ready:1;
103 110
111 /* There is easily reclaimable cold cache in the current node */
112 unsigned int cache_trim_mode:1;
113
114 /* The file pages on the current node are dangerously low */
115 unsigned int file_is_tiny:1;
116
104 /* Allocation order */117 /* Allocation order */
105 s8 order;118 s8 order;
106 119
@@ -239,13 +252,13 @@ static void unregister_memcg_shrinker(struct shrinker *shrinker) · 132 unmodified lines
239 up_write(&shrinker_rwsem);252 up_write(&shrinker_rwsem);
240}253}
241 254
242static bool global_reclaim(struct scan_control *sc)255static bool cgroup_reclaim(struct scan_control *sc)
243{256{
244 return !sc->target_mem_cgroup;257 return sc->target_mem_cgroup;
245}258}
246 259
247/**260/**
248 * sane_reclaim - is the usual dirty throttling mechanism operational?261 * writeback_throttling_sane - is the usual dirty throttling mechanism available?
249 * @sc: scan_control in question262 * @sc: scan_control in question
250 *263 *
251 * The normal page dirty throttling mechanism in balance_dirty_pages() is264 * The normal page dirty throttling mechanism in balance_dirty_pages() is
@@ -257,11 +270,9 @@ static bool global_reclaim(struct scan_control *sc) · 5 unmodified lines
257 * This function tests whether the vmscan currently in progress can assume270 * This function tests whether the vmscan currently in progress can assume
258 * that the normal dirty throttling mechanism is operational.271 * that the normal dirty throttling mechanism is operational.
259 */272 */
260static bool sane_reclaim(struct scan_control *sc)273static bool writeback_throttling_sane(struct scan_control *sc)
261{274{
262 struct mem_cgroup *memcg = sc->target_mem_cgroup;275 if (!cgroup_reclaim(sc))
263
264 if (!memcg)
265 return true;276 return true;
266#ifdef CONFIG_CGROUP_WRITEBACK277#ifdef CONFIG_CGROUP_WRITEBACK
267 if (cgroup_subsys_on_dfl(memory_cgrp_subsys))278 if (cgroup_subsys_on_dfl(memory_cgrp_subsys))
@@ -269,29 +280,6 @@ static bool sane_reclaim(struct scan_control *sc) · 1 unmodified line
269#endif280#endif
270 return false;281 return false;
271}282}
272
273static void set_memcg_congestion(pg_data_t *pgdat,
274 struct mem_cgroup *memcg,
275 bool congested)
276{
277 struct mem_cgroup_per_node *mn;
278
279 if (!memcg)
280 return;
281
282 mn = mem_cgroup_nodeinfo(memcg, pgdat->node_id);
283 WRITE_ONCE(mn->congested, congested);
284}
285
286static bool memcg_congested(pg_data_t *pgdat,
287 struct mem_cgroup *memcg)
288{
289 struct mem_cgroup_per_node *mn;
290
291 mn = mem_cgroup_nodeinfo(memcg, pgdat->node_id);
292 return READ_ONCE(mn->congested);
293
294}
295#else283#else
296static int prealloc_memcg_shrinker(struct shrinker *shrinker)284static int prealloc_memcg_shrinker(struct shrinker *shrinker)
297{285{
@@ -302,27 +290,15 @@ static void unregister_memcg_shrinker(struct shrinker *shrinker) · 4 unmodified lines
302{290{
303}291}
304 292
305static bool global_reclaim(struct scan_control *sc)293static bool cgroup_reclaim(struct scan_control *sc)
306{294{
307 return true;295 return false;
308}296}
309 297
310static bool sane_reclaim(struct scan_control *sc)298static bool writeback_throttling_sane(struct scan_control *sc)
311{299{
312 return true;300 return true;
313}301}
314
315static inline void set_memcg_congestion(struct pglist_data *pgdat,
316 struct mem_cgroup *memcg, bool congested)
317{
318}
319
320static inline bool memcg_congested(struct pglist_data *pgdat,
321 struct mem_cgroup *memcg)
322{
323 return false;
324
325}
326#endif302#endif
327 303
328/*304/*
@@ -351,32 +327,21 @@ unsigned long zone_reclaimable_pages(struct zone *zone) · 22 unmodified lines
351 */327 */
352unsigned long lruvec_lru_size(struct lruvec *lruvec, enum lru_list lru, int zone_idx)328unsigned long lruvec_lru_size(struct lruvec *lruvec, enum lru_list lru, int zone_idx)
353{329{
354 unsigned long lru_size = 0;330 unsigned long size = 0;
355 int zid;331 int zid;
356 332
357 if (!mem_cgroup_disabled()) {333 for (zid = 0; zid <= zone_idx && zid < MAX_NR_ZONES; zid++) {
358 for (zid = 0; zid < MAX_NR_ZONES; zid++)
359 lru_size += mem_cgroup_get_zone_lru_size(lruvec, lru, zid);
360 } else
361 lru_size = node_page_state(lruvec_pgdat(lruvec), NR_LRU_BASE + lru);
362
363 for (zid = zone_idx + 1; zid < MAX_NR_ZONES; zid++) {
364 struct zone *zone = &lruvec_pgdat(lruvec)->node_zones[zid];334 struct zone *zone = &lruvec_pgdat(lruvec)->node_zones[zid];
365 unsigned long size;
366 335
367 if (!managed_zone(zone))336 if (!managed_zone(zone))
368 continue;337 continue;
369 338
370 if (!mem_cgroup_disabled())339 if (!mem_cgroup_disabled())
371 size = mem_cgroup_get_zone_lru_size(lruvec, lru, zid);340 size += mem_cgroup_get_zone_lru_size(lruvec, lru, zid);
372 else341 else
373 size = zone_page_state(&lruvec_pgdat(lruvec)->node_zones[zid],342 size += zone_page_state(zone, NR_ZONE_LRU_BASE + lru);
374 NR_ZONE_LRU_BASE + lru);
375 lru_size -= min(size, lru_size);
376 }343 }
377 344 return size;
378 return lru_size;
379
380}345}
381 346
382/*347/*
@@ -775,7 +740,7 @@ static inline int is_page_cache_freeable(struct page *page) · 392 unmodified lines
775 return page_count(page) - page_has_private(page) == 1 + page_cache_pins;740 return page_count(page) - page_has_private(page) == 1 + page_cache_pins;
776}741}
777 742
778static int may_write_to_inode(struct inode *inode, struct scan_control *sc)743static int may_write_to_inode(struct inode *inode)
779{744{
780 if (current->flags & PF_SWAPWRITE)745 if (current->flags & PF_SWAPWRITE)
781 return 1;746 return 1;
@@ -823,8 +788,7 @@ typedef enum { · 41 unmodified lines
823 * pageout is called by shrink_page_list() for each dirty page.788 * pageout is called by shrink_page_list() for each dirty page.
824 * Calls ->writepage().789 * Calls ->writepage().
825 */790 */
826static pageout_t pageout(struct page *page, struct address_space *mapping,791static pageout_t pageout(struct page *page, struct address_space *mapping)
827 struct scan_control *sc)
828{792{
829 /*793 /*
830 * If the page is dirty, only perform writeback if that write794 * If the page is dirty, only perform writeback if that write
@@ -860,7 +824,7 @@ static pageout_t pageout(struct page *page, struct address_space *mapping, · 29 unmodified lines
860 }824 }
861 if (mapping->a_ops->writepage == NULL)825 if (mapping->a_ops->writepage == NULL)
862 return PAGE_ACTIVATE;826 return PAGE_ACTIVATE;
863 if (!may_write_to_inode(mapping->host, sc))827 if (!may_write_to_inode(mapping->host))
864 return PAGE_KEEP;828 return PAGE_KEEP;
865 829
866 if (clear_page_dirty_for_io(page)) {830 if (clear_page_dirty_for_io(page)) {
@@ -899,7 +863,7 @@ static pageout_t pageout(struct page *page, struct address_space *mapping, · 32 unmodified lines
899 * gets returned with a refcount of 0.863 * gets returned with a refcount of 0.
900 */864 */
901static int __remove_mapping(struct address_space *mapping, struct page *page,865static int __remove_mapping(struct address_space *mapping, struct page *page,
902 bool reclaimed)866 bool reclaimed, struct mem_cgroup *target_memcg)
903{867{
904 unsigned long flags;868 unsigned long flags;
905 int refcount;869 int refcount;
@@ -971,7 +935,7 @@ static int __remove_mapping(struct address_space *mapping, struct page *page, · 65 unmodified lines
971 */935 */
972 if (reclaimed && page_is_file_cache(page) &&936 if (reclaimed && page_is_file_cache(page) &&
973 !mapping_exiting(mapping) && !dax_mapping(mapping))937 !mapping_exiting(mapping) && !dax_mapping(mapping))
974 shadow = workingset_eviction(page);938 shadow = workingset_eviction(page, target_memcg);
975 __delete_from_page_cache(page, shadow);939 __delete_from_page_cache(page, shadow);
976 xa_unlock_irqrestore(&mapping->i_pages, flags);940 xa_unlock_irqrestore(&mapping->i_pages, flags);
977 941
@@ -994,7 +958,7 @@ cannot_free: · 16 unmodified lines
994 */958 */
995int remove_mapping(struct address_space *mapping, struct page *page)959int remove_mapping(struct address_space *mapping, struct page *page)
996{960{
997 if (__remove_mapping(mapping, page, false)) {961 if (__remove_mapping(mapping, page, false, NULL)) {
998 /*962 /*
999 * Unfreezing the refcount with 1 rather than 2 effectively963 * Unfreezing the refcount with 1 rather than 2 effectively
1000 * drops the pagecache ref for us without requiring another964 * drops the pagecache ref for us without requiring another
@@ -1239,7 +1203,7 @@ static unsigned long shrink_page_list(struct list_head *page_list, · 238 unmodified lines
1239 goto activate_locked;1203 goto activate_locked;
1240 1204
1241 /* Case 2 above */1205 /* Case 2 above */
1242 } else if (sane_reclaim(sc) ||1206 } else if (writeback_throttling_sane(sc) ||
1243 !PageReclaim(page) || !may_enter_fs) {1207 !PageReclaim(page) || !may_enter_fs) {
1244 /*1208 /*
1245 * This is slightly racy - end_page_writeback()1209 * This is slightly racy - end_page_writeback()
@@ -1394,7 +1358,7 @@ static unsigned long shrink_page_list(struct list_head *page_list, · 148 unmodified lines
1394 * starts and then write it out here.1358 * starts and then write it out here.
1395 */1359 */
1396 try_to_unmap_flush_dirty();1360 try_to_unmap_flush_dirty();
1397 switch (pageout(page, mapping, sc)) {1361 switch (pageout(page, mapping)) {
1398 case PAGE_KEEP:1362 case PAGE_KEEP:
1399 goto keep_locked;1363 goto keep_locked;
1400 case PAGE_ACTIVATE:1364 case PAGE_ACTIVATE:
@@ -1472,7 +1436,8 @@ static unsigned long shrink_page_list(struct list_head *page_list, · 71 unmodified lines
1472 1436
1473 count_vm_event(PGLAZYFREED);1437 count_vm_event(PGLAZYFREED);
1474 count_memcg_page_event(page, PGLAZYFREED);1438 count_memcg_page_event(page, PGLAZYFREED);
1475 } else if (!mapping || !__remove_mapping(mapping, page, true))1439 } else if (!mapping || !__remove_mapping(mapping, page, true,
1440 sc->target_mem_cgroup))
1476 goto keep_locked;1441 goto keep_locked;
1477 1442
1478 unlock_page(page);1443 unlock_page(page);
@@ -1820,7 +1785,7 @@ int isolate_lru_page(struct page *page) · 341 unmodified lines
1820 1785
1821/*1786/*
1822 * A direct reclaimer may isolate SWAP_CLUSTER_MAX pages from the LRU list and1787 * A direct reclaimer may isolate SWAP_CLUSTER_MAX pages from the LRU list and
1823 * then get resheduled. When there are massive number of tasks doing page1788 * then get rescheduled. When there are massive number of tasks doing page
1824 * allocation, such sleeping direct reclaimers may keep piling up on each CPU,1789 * allocation, such sleeping direct reclaimers may keep piling up on each CPU,
1825 * the LRU list will go small and be scanned faster than necessary, leading to1790 * the LRU list will go small and be scanned faster than necessary, leading to
1826 * unnecessary swapping, thrashing and OOM.1791 * unnecessary swapping, thrashing and OOM.
@@ -1833,7 +1798,7 @@ static int too_many_isolated(struct pglist_data *pgdat, int file, · 6 unmodified lines
1833 if (current_is_kswapd())1798 if (current_is_kswapd())
1834 return 0;1799 return 0;
1835 1800
1836 if (!sane_reclaim(sc))1801 if (!writeback_throttling_sane(sc))
1837 return 0;1802 return 0;
1838 1803
1839 if (file) {1804 if (file) {
@@ -1983,7 +1948,7 @@ shrink_inactive_list(unsigned long nr_to_scan, struct lruvec *lruvec, · 143 unmodified lines
1983 reclaim_stat->recent_scanned[file] += nr_taken;1948 reclaim_stat->recent_scanned[file] += nr_taken;
1984 1949
1985 item = current_is_kswapd() ? PGSCAN_KSWAPD : PGSCAN_DIRECT;1950 item = current_is_kswapd() ? PGSCAN_KSWAPD : PGSCAN_DIRECT;
1986 if (global_reclaim(sc))1951 if (!cgroup_reclaim(sc))
1987 __count_vm_events(item, nr_scanned);1952 __count_vm_events(item, nr_scanned);
1988 __count_memcg_events(lruvec_memcg(lruvec), item, nr_scanned);1953 __count_memcg_events(lruvec_memcg(lruvec), item, nr_scanned);
1989 spin_unlock_irq(&pgdat->lru_lock);1954 spin_unlock_irq(&pgdat->lru_lock);
@@ -1997,7 +1962,7 @@ shrink_inactive_list(unsigned long nr_to_scan, struct lruvec *lruvec, · 7 unmodified lines
1997 spin_lock_irq(&pgdat->lru_lock);1962 spin_lock_irq(&pgdat->lru_lock);
1998 1963
1999 item = current_is_kswapd() ? PGSTEAL_KSWAPD : PGSTEAL_DIRECT;1964 item = current_is_kswapd() ? PGSTEAL_KSWAPD : PGSTEAL_DIRECT;
2000 if (global_reclaim(sc))1965 if (!cgroup_reclaim(sc))
2001 __count_vm_events(item, nr_reclaimed);1966 __count_vm_events(item, nr_reclaimed);
2002 __count_memcg_events(lruvec_memcg(lruvec), item, nr_reclaimed);1967 __count_memcg_events(lruvec_memcg(lruvec), item, nr_reclaimed);
2003 reclaim_stat->recent_rotated[0] += stat.nr_activate[0];1968 reclaim_stat->recent_rotated[0] += stat.nr_activate[0];
@@ -2199,6 +2164,20 @@ unsigned long reclaim_pages(struct list_head *page_list) · 195 unmodified lines
2199 return nr_reclaimed;2164 return nr_reclaimed;
2200}2165}
2201 2166
2167static unsigned long shrink_list(enum lru_list lru, unsigned long nr_to_scan,
2168 struct lruvec *lruvec, struct scan_control *sc)
2169{
2170 if (is_active_lru(lru)) {
2171 if (sc->may_deactivate & (1 << is_file_lru(lru)))
2172 shrink_active_list(nr_to_scan, lruvec, sc, lru);
2173 else
2174 sc->skipped_deactivate = 1;
2175 return 0;
2176 }
2177
2178 return shrink_inactive_list(nr_to_scan, lruvec, sc, lru);
2179}
2180
2202/*2181/*
2203 * The inactive anon list should be small enough that the VM never has2182 * The inactive anon list should be small enough that the VM never has
2204 * to do too much work.2183 * to do too much work.
@@ -2227,64 +2206,25 @@ unsigned long reclaim_pages(struct list_head *page_list) · 22 unmodified lines
2227 * 1TB 101 10GB2206 * 1TB 101 10GB
2228 * 10TB 320 32GB2207 * 10TB 320 32GB
2229 */2208 */
2230static bool inactive_list_is_low(struct lruvec *lruvec, bool file,2209static bool inactive_is_low(struct lruvec *lruvec, enum lru_list inactive_lru)
2231 struct scan_control *sc, bool trace)
2232{2210{
2233 enum lru_list active_lru = file * LRU_FILE + LRU_ACTIVE;2211 enum lru_list active_lru = inactive_lru + LRU_ACTIVE;
2234 struct pglist_data *pgdat = lruvec_pgdat(lruvec);
2235 enum lru_list inactive_lru = file * LRU_FILE;
2236 unsigned long inactive, active;2212 unsigned long inactive, active;
2237 unsigned long inactive_ratio;2213 unsigned long inactive_ratio;
2238 unsigned long refaults;
2239 unsigned long gb;2214 unsigned long gb;
2240 2215
2241 /*2216 inactive = lruvec_page_state(lruvec, NR_LRU_BASE + inactive_lru);
2242 * If we don't have swap space, anonymous page deactivation2217 active = lruvec_page_state(lruvec, NR_LRU_BASE + active_lru);
2243 * is pointless.
2244 */
2245 if (!file && !total_swap_pages)
2246 return false;
2247
2248 inactive = lruvec_lru_size(lruvec, inactive_lru, sc->reclaim_idx);
2249 active = lruvec_lru_size(lruvec, active_lru, sc->reclaim_idx);
2250
2251 /*
2252 * When refaults are being observed, it means a new workingset
2253 * is being established. Disable active list protection to get
2254 * rid of the stale workingset quickly.
2255 */
2256 refaults = lruvec_page_state_local(lruvec, WORKINGSET_ACTIVATE);
2257 if (file && lruvec->refaults != refaults) {
2258 inactive_ratio = 0;
2259 } else {
2260 gb = (inactive + active) >> (30 - PAGE_SHIFT);
2261 if (gb)
2262 inactive_ratio = int_sqrt(10 * gb);
2263 else
2264 inactive_ratio = 1;
2265 }
2266 2218
2267 if (trace)2219 gb = (inactive + active) >> (30 - PAGE_SHIFT);
2268 trace_mm_vmscan_inactive_list_is_low(pgdat->node_id, sc->reclaim_idx,2220 if (gb)
2269 lruvec_lru_size(lruvec, inactive_lru, MAX_NR_ZONES), inactive,2221 inactive_ratio = int_sqrt(10 * gb);
2270 lruvec_lru_size(lruvec, active_lru, MAX_NR_ZONES), active,2222 else
2271 inactive_ratio, file);2223 inactive_ratio = 1;
2272 2224
2273 return inactive * inactive_ratio < active;2225 return inactive * inactive_ratio < active;
2274}2226}
2275 2227
2276static unsigned long shrink_list(enum lru_list lru, unsigned long nr_to_scan,
2277 struct lruvec *lruvec, struct scan_control *sc)
2278{
2279 if (is_active_lru(lru)) {
2280 if (inactive_list_is_low(lruvec, is_file_lru(lru), sc, true))
2281 shrink_active_list(nr_to_scan, lruvec, sc, lru);
2282 return 0;
2283 }
2284
2285 return shrink_inactive_list(nr_to_scan, lruvec, sc, lru);
2286}
2287
2288enum scan_balance {2228enum scan_balance {
2289 SCAN_EQUAL,2229 SCAN_EQUAL,
2290 SCAN_FRACT,2230 SCAN_FRACT,
@@ -2301,10 +2241,10 @@ enum scan_balance { · 10 unmodified lines
2301 * nr[0] = anon inactive pages to scan; nr[1] = anon active pages to scan2241 * nr[0] = anon inactive pages to scan; nr[1] = anon active pages to scan
2302 * nr[2] = file inactive pages to scan; nr[3] = file active pages to scan2242 * nr[2] = file inactive pages to scan; nr[3] = file active pages to scan
2303 */2243 */
2304static void get_scan_count(struct lruvec *lruvec, struct mem_cgroup *memcg,2244static void get_scan_count(struct lruvec *lruvec, struct scan_control *sc,
2305 struct scan_control *sc, unsigned long *nr,2245 unsigned long *nr)
2306 unsigned long *lru_pages)
2307{2246{
2247 struct mem_cgroup *memcg = lruvec_memcg(lruvec);
2308 int swappiness = mem_cgroup_swappiness(memcg);2248 int swappiness = mem_cgroup_swappiness(memcg);
2309 struct zone_reclaim_stat *reclaim_stat = &lruvec->reclaim_stat;2249 struct zone_reclaim_stat *reclaim_stat = &lruvec->reclaim_stat;
2310 u64 fraction[2];2250 u64 fraction[2];
@@ -2329,7 +2269,7 @@ static void get_scan_count(struct lruvec *lruvec, struct mem_cgroup *memcg, · 18 unmodified lines
2329 * using the memory controller's swap limit feature would be2269 * using the memory controller's swap limit feature would be
2330 * too expensive.2270 * too expensive.
2331 */2271 */
2332 if (!global_reclaim(sc) && !swappiness) {2272 if (cgroup_reclaim(sc) && !swappiness) {
2333 scan_balance = SCAN_FILE;2273 scan_balance = SCAN_FILE;
2334 goto out;2274 goto out;
2335 }2275 }
@@ -2345,58 +2285,18 @@ static void get_scan_count(struct lruvec *lruvec, struct mem_cgroup *memcg, · 9 unmodified lines
2345 }2285 }
2346 2286
2347 /*2287 /*
2348 * Prevent the reclaimer from falling into the cache trap: as2288 * If the system is almost out of file pages, force-scan anon.
2349 * cache pages start out inactive, every cache fault will tip
2350 * the scan balance towards the file LRU. And as the file LRU
2351 * shrinks, so does the window for rotation from references.
2352 * This means we have a runaway feedback loop where a tiny
2353 * thrashing file LRU becomes infinitely more attractive than
2354 * anon pages. Try to detect this based on file LRU size.
2355 */2289 */
2356 if (global_reclaim(sc)) {2290 if (sc->file_is_tiny) {
2357 unsigned long pgdatfile;2291 scan_balance = SCAN_ANON;
2358 unsigned long pgdatfree;2292 goto out;
2359 int z;
2360 unsigned long total_high_wmark = 0;
2361
2362 pgdatfree = sum_zone_node_page_state(pgdat->node_id, NR_FREE_PAGES);
2363 pgdatfile = node_page_state(pgdat, NR_ACTIVE_FILE) +
2364 node_page_state(pgdat, NR_INACTIVE_FILE);
2365
2366 for (z = 0; z < MAX_NR_ZONES; z++) {
2367 struct zone *zone = &pgdat->node_zones[z];
2368 if (!managed_zone(zone))
2369 continue;
2370
2371 total_high_wmark += high_wmark_pages(zone);
2372 }
2373
2374 if (unlikely(pgdatfile + pgdatfree <= total_high_wmark)) {
2375 /*
2376 * Force SCAN_ANON if there are enough inactive
2377 * anonymous pages on the LRU in eligible zones.
2378 * Otherwise, the small LRU gets thrashed.
2379 */
2380 if (!inactive_list_is_low(lruvec, false, sc, false) &&
2381 lruvec_lru_size(lruvec, LRU_INACTIVE_ANON, sc->reclaim_idx)
2382 >> sc->priority) {
2383 scan_balance = SCAN_ANON;
2384 goto out;
2385 }
2386 }
2387 }2293 }
2388 2294
2389 /*2295 /*
2390 * If there is enough inactive page cache, i.e. if the size of the2296 * If there is enough inactive page cache, we do not reclaim
2391 * inactive list is greater than that of the active list *and* the2297 * anything from the anonymous working right now.
2392 * inactive list actually has some pages to scan on this priority, we
2393 * do not reclaim anything from the anonymous working set right now.
2394 * Without the second condition we could end up never scanning an
2395 * lruvec even if it has plenty of old anonymous pages unless the
2396 * system is under heavy pressure.
2397 */2298 */
2398 if (!inactive_list_is_low(lruvec, true, sc, false) &&2299 if (sc->cache_trim_mode) {
2399 lruvec_lru_size(lruvec, LRU_INACTIVE_FILE, sc->reclaim_idx) >> sc->priority) {
2400 scan_balance = SCAN_FILE;2300 scan_balance = SCAN_FILE;
2401 goto out;2301 goto out;
2402 }2302 }
@@ -2454,7 +2354,6 @@ static void get_scan_count(struct lruvec *lruvec, struct mem_cgroup *memcg, · 51 unmodified lines
2454 fraction[1] = fp;2354 fraction[1] = fp;
2455 denominator = ap + fp + 1;2355 denominator = ap + fp + 1;
2456out:2356out:
2457 *lru_pages = 0;
2458 for_each_evictable_lru(lru) {2357 for_each_evictable_lru(lru) {
2459 int file = is_file_lru(lru);2358 int file = is_file_lru(lru);
2460 unsigned long lruvec_size;2359 unsigned long lruvec_size;
@@ -2549,18 +2448,12 @@ out: · 88 unmodified lines
2549 BUG();2448 BUG();
2550 }2449 }
2551 2450
2552 *lru_pages += lruvec_size;
2553 nr[lru] = scan;2451 nr[lru] = scan;
2554 }2452 }
2555}2453}
2556 2454
2557/*2455static void shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc)
2558 * This is a basic per-node page freer. Used by both kswapd and direct reclaim.
2559 */
2560static void shrink_node_memcg(struct pglist_data *pgdat, struct mem_cgroup *memcg,
2561 struct scan_control *sc, unsigned long *lru_pages)
2562{2456{
2563 struct lruvec *lruvec = mem_cgroup_lruvec(pgdat, memcg);
2564 unsigned long nr[NR_LRU_LISTS];2457 unsigned long nr[NR_LRU_LISTS];
2565 unsigned long targets[NR_LRU_LISTS];2458 unsigned long targets[NR_LRU_LISTS];
2566 unsigned long nr_to_scan;2459 unsigned long nr_to_scan;
@@ -2570,7 +2463,7 @@ static void shrink_node_memcg(struct pglist_data *pgdat, struct mem_cgroup *memc · 3 unmodified lines
2570 struct blk_plug plug;2463 struct blk_plug plug;
2571 bool scan_adjusted;2464 bool scan_adjusted;
2572 2465
2573 get_scan_count(lruvec, memcg, sc, nr, lru_pages);2466 get_scan_count(lruvec, sc, nr);
2574 2467
2575 /* Record the original scan target for proportional adjustments later */2468 /* Record the original scan target for proportional adjustments later */
2576 memcpy(targets, nr, sizeof(nr));2469 memcpy(targets, nr, sizeof(nr));
@@ -2586,7 +2479,7 @@ static void shrink_node_memcg(struct pglist_data *pgdat, struct mem_cgroup *memc · 9 unmodified lines
2586 * abort proportional reclaim if either the file or anon lru has already2479 * abort proportional reclaim if either the file or anon lru has already
2587 * dropped to zero at the first pass.2480 * dropped to zero at the first pass.
2588 */2481 */
2589 scan_adjusted = (global_reclaim(sc) && !current_is_kswapd() &&2482 scan_adjusted = (!cgroup_reclaim(sc) && !current_is_kswapd() &&
2590 sc->priority == DEF_PRIORITY);2483 sc->priority == DEF_PRIORITY);
2591 2484
2592 blk_start_plug(&plug);2485 blk_start_plug(&plug);
@@ -2668,7 +2561,7 @@ static void shrink_node_memcg(struct pglist_data *pgdat, struct mem_cgroup *memc · 75 unmodified lines
2668 * Even if we did not try to evict anon pages at all, we want to2561 * Even if we did not try to evict anon pages at all, we want to
2669 * rebalance the anon lru active/inactive ratio.2562 * rebalance the anon lru active/inactive ratio.
2670 */2563 */
2671 if (inactive_list_is_low(lruvec, false, sc, true))2564 if (total_swap_pages && inactive_is_low(lruvec, LRU_INACTIVE_ANON))
2672 shrink_active_list(SWAP_CLUSTER_MAX, lruvec,2565 shrink_active_list(SWAP_CLUSTER_MAX, lruvec,
2673 sc, LRU_ACTIVE_ANON);2566 sc, LRU_ACTIVE_ANON);
2674}2567}
@@ -2744,156 +2637,234 @@ static inline bool should_continue_reclaim(struct pglist_data *pgdat, · 69 unmodified lines
2744 return inactive_lru_pages > pages_for_compaction;2637 return inactive_lru_pages > pages_for_compaction;
2745}2638}
2746 2639
2747static bool pgdat_memcg_congested(pg_data_t *pgdat, struct mem_cgroup *memcg)2640static void shrink_node_memcgs(pg_data_t *pgdat, struct scan_control *sc)
2748{2641{
2749 return test_bit(PGDAT_CONGESTED, &pgdat->flags) ||2642 struct mem_cgroup *target_memcg = sc->target_mem_cgroup;
2750 (memcg && memcg_congested(pgdat, memcg));2643 struct mem_cgroup *memcg;
2644
2645 memcg = mem_cgroup_iter(target_memcg, NULL, NULL);
2646 do {
2647 struct lruvec *lruvec = mem_cgroup_lruvec(memcg, pgdat);
2648 unsigned long reclaimed;
2649 unsigned long scanned;
2650
2651 switch (mem_cgroup_protected(target_memcg, memcg)) {
2652 case MEMCG_PROT_MIN:
2653 /*
2654 * Hard protection.
2655 * If there is no reclaimable memory, OOM.
2656 */
2657 continue;
2658 case MEMCG_PROT_LOW:
2659 /*
2660 * Soft protection.
2661 * Respect the protection only as long as
2662 * there is an unprotected supply
2663 * of reclaimable memory from other cgroups.
2664 */
2665 if (!sc->memcg_low_reclaim) {
2666 sc->memcg_low_skipped = 1;
2667 continue;
2668 }
2669 memcg_memory_event(memcg, MEMCG_LOW);
2670 break;
2671 case MEMCG_PROT_NONE:
2672 /*
2673 * All protection thresholds breached. We may
2674 * still choose to vary the scan pressure
2675 * applied based on by how much the cgroup in
2676 * question has exceeded its protection
2677 * thresholds (see get_scan_count).
2678 */
2679 break;
2680 }
2681
2682 reclaimed = sc->nr_reclaimed;
2683 scanned = sc->nr_scanned;
2684
2685 shrink_lruvec(lruvec, sc);
2686
2687 shrink_slab(sc->gfp_mask, pgdat->node_id, memcg,
2688 sc->priority);
2689
2690 /* Record the group's reclaim efficiency */
2691 vmpressure(sc->gfp_mask, memcg, false,
2692 sc->nr_scanned - scanned,
2693 sc->nr_reclaimed - reclaimed);
2694
2695 } while ((memcg = mem_cgroup_iter(target_memcg, memcg, NULL)));
2751}2696}
2752 2697
2753static bool shrink_node(pg_data_t *pgdat, struct scan_control *sc)2698static bool shrink_node(pg_data_t *pgdat, struct scan_control *sc)
2754{2699{
2755 struct reclaim_state *reclaim_state = current->reclaim_state;2700 struct reclaim_state *reclaim_state = current->reclaim_state;
2756 unsigned long nr_reclaimed, nr_scanned;2701 unsigned long nr_reclaimed, nr_scanned;
2702 struct lruvec *target_lruvec;
2757 bool reclaimable = false;2703 bool reclaimable = false;
2704 unsigned long file;
2758 2705
2759 do {2706 target_lruvec = mem_cgroup_lruvec(sc->target_mem_cgroup, pgdat);
2760 struct mem_cgroup *root = sc->target_mem_cgroup;
2761 unsigned long node_lru_pages = 0;
2762 struct mem_cgroup *memcg;
2763 2707
2764 memset(&sc->nr, 0, sizeof(sc->nr));2708again:
2709 memset(&sc->nr, 0, sizeof(sc->nr));
2765 2710
2766 nr_reclaimed = sc->nr_reclaimed;2711 nr_reclaimed = sc->nr_reclaimed;
2767 nr_scanned = sc->nr_scanned;2712 nr_scanned = sc->nr_scanned;
2768 2713
2769 memcg = mem_cgroup_iter(root, NULL, NULL);2714 /*
2770 do {2715 * Target desirable inactive:active list ratios for the anon
2771 unsigned long lru_pages;2716 * and file LRU lists.
2772 unsigned long reclaimed;2717 */
2773 unsigned long scanned;2718 if (!sc->force_deactivate) {
2719 unsigned long refaults;
2774 2720
2775 switch (mem_cgroup_protected(root, memcg)) {2721 if (inactive_is_low(target_lruvec, LRU_INACTIVE_ANON))
2776 case MEMCG_PROT_MIN:2722 sc->may_deactivate |= DEACTIVATE_ANON;
2777 /*2723 else
2778 * Hard protection.2724 sc->may_deactivate &= ~DEACTIVATE_ANON;
2779 * If there is no reclaimable memory, OOM.
2780 */
2781 continue;
2782 case MEMCG_PROT_LOW:
2783 /*
2784 * Soft protection.
2785 * Respect the protection only as long as
2786 * there is an unprotected supply
2787 * of reclaimable memory from other cgroups.
2788 */
2789 if (!sc->memcg_low_reclaim) {
2790 sc->memcg_low_skipped = 1;
2791 continue;
2792 }
2793 memcg_memory_event(memcg, MEMCG_LOW);
2794 break;
2795 case MEMCG_PROT_NONE:
2796 /*
2797 * All protection thresholds breached. We may
2798 * still choose to vary the scan pressure
2799 * applied based on by how much the cgroup in
2800 * question has exceeded its protection
2801 * thresholds (see get_scan_count).
2802 */
2803 break;
2804 }
2805 2725
2806 reclaimed = sc->nr_reclaimed;2726 /*
2807 scanned = sc->nr_scanned;2727 * When refaults are being observed, it means a new
2808 shrink_node_memcg(pgdat, memcg, sc, &lru_pages);2728 * workingset is being established. Deactivate to get
2809 node_lru_pages += lru_pages;2729 * rid of any stale active pages quickly.
2730 */
2731 refaults = lruvec_page_state(target_lruvec,
2732 WORKINGSET_ACTIVATE);
2733 if (refaults != target_lruvec->refaults ||
2734 inactive_is_low(target_lruvec, LRU_INACTIVE_FILE))
2735 sc->may_deactivate |= DEACTIVATE_FILE;
2736 else
2737 sc->may_deactivate &= ~DEACTIVATE_FILE;
2738 } else
2739 sc->may_deactivate = DEACTIVATE_ANON | DEACTIVATE_FILE;
2810 2740
2811 shrink_slab(sc->gfp_mask, pgdat->node_id, memcg,2741 /*
2812 sc->priority);2742 * If we have plenty of inactive file pages that aren't
2743 * thrashing, try to reclaim those first before touching
2744 * anonymous pages.
2745 */
2746 file = lruvec_page_state(target_lruvec, NR_INACTIVE_FILE);
2747 if (file >> sc->priority && !(sc->may_deactivate & DEACTIVATE_FILE))
2748 sc->cache_trim_mode = 1;
2749 else
2750 sc->cache_trim_mode = 0;
2751
2752 /*
2753 * Prevent the reclaimer from falling into the cache trap: as
2754 * cache pages start out inactive, every cache fault will tip
2755 * the scan balance towards the file LRU. And as the file LRU
2756 * shrinks, so does the window for rotation from references.
2757 * This means we have a runaway feedback loop where a tiny
2758 * thrashing file LRU becomes infinitely more attractive than
2759 * anon pages. Try to detect this based on file LRU size.
2760 */
2761 if (!cgroup_reclaim(sc)) {
2762 unsigned long total_high_wmark = 0;
2763 unsigned long free, anon;
2764 int z;
2813 2765
2814 /* Record the group's reclaim efficiency */2766 free = sum_zone_node_page_state(pgdat->node_id, NR_FREE_PAGES);
2815 vmpressure(sc->gfp_mask, memcg, false,2767 file = node_page_state(pgdat, NR_ACTIVE_FILE) +
2816 sc->nr_scanned - scanned,2768 node_page_state(pgdat, NR_INACTIVE_FILE);
2817 sc->nr_reclaimed - reclaimed);
2818 2769
2819 } while ((memcg = mem_cgroup_iter(root, memcg, NULL)));2770 for (z = 0; z < MAX_NR_ZONES; z++) {
2771 struct zone *zone = &pgdat->node_zones[z];
2772 if (!managed_zone(zone))
2773 continue;
2820 2774
2821 if (reclaim_state) {2775 total_high_wmark += high_wmark_pages(zone);
2822 sc->nr_reclaimed += reclaim_state->reclaimed_slab;
2823 reclaim_state->reclaimed_slab = 0;
2824 }2776 }
2825 2777
2826 /* Record the subtree's reclaim efficiency */2778 /*
2827 vmpressure(sc->gfp_mask, sc->target_mem_cgroup, true,2779 * Consider anon: if that's low too, this isn't a
2828 sc->nr_scanned - nr_scanned,2780 * runaway file reclaim problem, but rather just
2829 sc->nr_reclaimed - nr_reclaimed);2781 * extreme pressure. Reclaim as per usual then.
2782 */
2783 anon = node_page_state(pgdat, NR_INACTIVE_ANON);
2830 2784
2831 if (sc->nr_reclaimed - nr_reclaimed)2785 sc->file_is_tiny =
2832 reclaimable = true;2786 file + free <= total_high_wmark &&
2787 !(sc->may_deactivate & DEACTIVATE_ANON) &&
2788 anon >> sc->priority;
2789 }
2833 2790
2834 if (current_is_kswapd()) {2791 shrink_node_memcgs(pgdat, sc);
2835 /*
2836 * If reclaim is isolating dirty pages under writeback,
2837 * it implies that the long-lived page allocation rate
2838 * is exceeding the page laundering rate. Either the
2839 * global limits are not being effective at throttling
2840 * processes due to the page distribution throughout
2841 * zones or there is heavy usage of a slow backing
2842 * device. The only option is to throttle from reclaim
2843 * context which is not ideal as there is no guarantee
2844 * the dirtying process is throttled in the same way
2845 * balance_dirty_pages() manages.
2846 *
2847 * Once a node is flagged PGDAT_WRITEBACK, kswapd will
2848 * count the number of pages under pages flagged for
2849 * immediate reclaim and stall if any are encountered
2850 * in the nr_immediate check below.
2851 */
2852 if (sc->nr.writeback && sc->nr.writeback == sc->nr.taken)
2853 set_bit(PGDAT_WRITEBACK, &pgdat->flags);
2854 2792
2855 /*2793 if (reclaim_state) {
2856 * Tag a node as congested if all the dirty pages2794 sc->nr_reclaimed += reclaim_state->reclaimed_slab;
2857 * scanned were backed by a congested BDI and2795 reclaim_state->reclaimed_slab = 0;
2858 * wait_iff_congested will stall.2796 }
2859 */
2860 if (sc->nr.dirty && sc->nr.dirty == sc->nr.congested)
2861 set_bit(PGDAT_CONGESTED, &pgdat->flags);
2862 2797
2863 /* Allow kswapd to start writing pages during reclaim.*/2798 /* Record the subtree's reclaim efficiency */
2864 if (sc->nr.unqueued_dirty == sc->nr.file_taken)2799 vmpressure(sc->gfp_mask, sc->target_mem_cgroup, true,
2865 set_bit(PGDAT_DIRTY, &pgdat->flags);2800 sc->nr_scanned - nr_scanned,
2801 sc->nr_reclaimed - nr_reclaimed);
2866 2802
2867 /*2803 if (sc->nr_reclaimed - nr_reclaimed)
2868 * If kswapd scans pages marked marked for immediate2804 reclaimable = true;
2869 * reclaim and under writeback (nr_immediate), it
2870 * implies that pages are cycling through the LRU
2871 * faster than they are written so also forcibly stall.
2872 */
2873 if (sc->nr.immediate)
2874 congestion_wait(BLK_RW_ASYNC, HZ/10);
2875 }
2876 2805
2806 if (current_is_kswapd()) {
2877 /*2807 /*
2878 * Legacy memcg will stall in page writeback so avoid forcibly2808 * If reclaim is isolating dirty pages under writeback,
2879 * stalling in wait_iff_congested().2809 * it implies that the long-lived page allocation rate
2810 * is exceeding the page laundering rate. Either the
2811 * global limits are not being effective at throttling
2812 * processes due to the page distribution throughout
2813 * zones or there is heavy usage of a slow backing
2814 * device. The only option is to throttle from reclaim
2815 * context which is not ideal as there is no guarantee
2816 * the dirtying process is throttled in the same way
2817 * balance_dirty_pages() manages.
2818 *
2819 * Once a node is flagged PGDAT_WRITEBACK, kswapd will
2820 * count the number of pages under pages flagged for
2821 * immediate reclaim and stall if any are encountered
2822 * in the nr_immediate check below.
2880 */2823 */
2881 if (!global_reclaim(sc) && sane_reclaim(sc) &&2824 if (sc->nr.writeback && sc->nr.writeback == sc->nr.taken)
2882 sc->nr.dirty && sc->nr.dirty == sc->nr.congested)2825 set_bit(PGDAT_WRITEBACK, &pgdat->flags);
2883 set_memcg_congestion(pgdat, root, true);2826
2827 /* Allow kswapd to start writing pages during reclaim.*/
2828 if (sc->nr.unqueued_dirty == sc->nr.file_taken)
2829 set_bit(PGDAT_DIRTY, &pgdat->flags);
2884 2830
2885 /*2831 /*
2886 * Stall direct reclaim for IO completions if underlying BDIs2832 * If kswapd scans pages marked marked for immediate
2887 * and node is congested. Allow kswapd to continue until it2833 * reclaim and under writeback (nr_immediate), it
2888 * starts encountering unqueued dirty pages or cycling through2834 * implies that pages are cycling through the LRU
2889 * the LRU too quickly.2835 * faster than they are written so also forcibly stall.
2890 */2836 */
2891 if (!sc->hibernation_mode && !current_is_kswapd() &&2837 if (sc->nr.immediate)
2892 current_may_throttle() && pgdat_memcg_congested(pgdat, root))2838 congestion_wait(BLK_RW_ASYNC, HZ/10);
2893 wait_iff_congested(BLK_RW_ASYNC, HZ/10);2839 }
2894 2840
2895 } while (should_continue_reclaim(pgdat, sc->nr_reclaimed - nr_reclaimed,2841 /*
2896 sc));2842 * Tag a node/memcg as congested if all the dirty pages
2843 * scanned were backed by a congested BDI and
2844 * wait_iff_congested will stall.
2845 *
2846 * Legacy memcg will stall in page writeback so avoid forcibly
2847 * stalling in wait_iff_congested().
2848 */
2849 if ((current_is_kswapd() ||
2850 (cgroup_reclaim(sc) && writeback_throttling_sane(sc))) &&
2851 sc->nr.dirty && sc->nr.dirty == sc->nr.congested)
2852 set_bit(LRUVEC_CONGESTED, &target_lruvec->flags);
2853
2854 /*
2855 * Stall direct reclaim for IO completions if underlying BDIs
2856 * and node is congested. Allow kswapd to continue until it
2857 * starts encountering unqueued dirty pages or cycling through
2858 * the LRU too quickly.
2859 */
2860 if (!current_is_kswapd() && current_may_throttle() &&
2861 !sc->hibernation_mode &&
2862 test_bit(LRUVEC_CONGESTED, &target_lruvec->flags))
2863 wait_iff_congested(BLK_RW_ASYNC, HZ/10);
2864
2865 if (should_continue_reclaim(pgdat, sc->nr_reclaimed - nr_reclaimed,
2866 sc))
2867 goto again;
2897 2868
2898 /*2869 /*
2899 * Kswapd gives up on balancing particular nodes after too2870 * Kswapd gives up on balancing particular nodes after too
@@ -2973,7 +2944,7 @@ static void shrink_zones(struct zonelist *zonelist, struct scan_control *sc) · 73 unmodified lines
2973 * Take care memory controller reclaiming has small influence2944 * Take care memory controller reclaiming has small influence
2974 * to global LRU.2945 * to global LRU.
2975 */2946 */
2976 if (global_reclaim(sc)) {2947 if (!cgroup_reclaim(sc)) {
2977 if (!cpuset_zone_allowed(zone,2948 if (!cpuset_zone_allowed(zone,
2978 GFP_KERNEL | __GFP_HARDWALL))2949 GFP_KERNEL | __GFP_HARDWALL))
2979 continue;2950 continue;
@@ -3032,19 +3003,14 @@ static void shrink_zones(struct zonelist *zonelist, struct scan_control *sc) · 52 unmodified lines
3032 sc->gfp_mask = orig_mask;3003 sc->gfp_mask = orig_mask;
3033}3004}
3034 3005
3035static void snapshot_refaults(struct mem_cgroup *root_memcg, pg_data_t *pgdat)3006static void snapshot_refaults(struct mem_cgroup *target_memcg, pg_data_t *pgdat)
3036{3007{
3037 struct mem_cgroup *memcg;3008 struct lruvec *target_lruvec;
3038 3009 unsigned long refaults;
3039 memcg = mem_cgroup_iter(root_memcg, NULL, NULL);
3040 do {
3041 unsigned long refaults;
3042 struct lruvec *lruvec;
3043 3010
3044 lruvec = mem_cgroup_lruvec(pgdat, memcg);3011 target_lruvec = mem_cgroup_lruvec(target_memcg, pgdat);
3045 refaults = lruvec_page_state_local(lruvec, WORKINGSET_ACTIVATE);3012 refaults = lruvec_page_state(target_lruvec, WORKINGSET_ACTIVATE);
3046 lruvec->refaults = refaults;3013 target_lruvec->refaults = refaults;
3047 } while ((memcg = mem_cgroup_iter(root_memcg, memcg, NULL)));
3048}3014}
3049 3015
3050/*3016/*
@@ -3073,7 +3039,7 @@ static unsigned long do_try_to_free_pages(struct zonelist *zonelist, · 22 unmodified lines
3073retry:3039retry:
3074 delayacct_freepages_start();3040 delayacct_freepages_start();
3075 3041
3076 if (global_reclaim(sc))3042 if (!cgroup_reclaim(sc))
3077 __count_zid_vm_events(ALLOCSTALL, sc->reclaim_idx, 1);3043 __count_zid_vm_events(ALLOCSTALL, sc->reclaim_idx, 1);
3078 3044
3079 do {3045 do {
@@ -3102,8 +3068,16 @@ retry: · 22 unmodified lines
3102 if (zone->zone_pgdat == last_pgdat)3068 if (zone->zone_pgdat == last_pgdat)
3103 continue;3069 continue;
3104 last_pgdat = zone->zone_pgdat;3070 last_pgdat = zone->zone_pgdat;
3071
3105 snapshot_refaults(sc->target_mem_cgroup, zone->zone_pgdat);3072 snapshot_refaults(sc->target_mem_cgroup, zone->zone_pgdat);
3106 set_memcg_congestion(last_pgdat, sc->target_mem_cgroup, false);3073
3074 if (cgroup_reclaim(sc)) {
3075 struct lruvec *lruvec;
3076
3077 lruvec = mem_cgroup_lruvec(sc->target_mem_cgroup,
3078 zone->zone_pgdat);
3079 clear_bit(LRUVEC_CONGESTED, &lruvec->flags);
3080 }
3107 }3081 }
3108 3082
3109 delayacct_freepages_end();3083 delayacct_freepages_end();
@@ -3115,9 +3089,27 @@ retry: · 5 unmodified lines
3115 if (sc->compaction_ready)3089 if (sc->compaction_ready)
3116 return 1;3090 return 1;
3117 3091
3092 /*
3093 * We make inactive:active ratio decisions based on the node's
3094 * composition of memory, but a restrictive reclaim_idx or a
3095 * memory.low cgroup setting can exempt large amounts of
3096 * memory from reclaim. Neither of which are very common, so
3097 * instead of doing costly eligibility calculations of the
3098 * entire cgroup subtree up front, we assume the estimates are
3099 * good, and retry with forcible deactivation if that fails.
3100 */
3101 if (sc->skipped_deactivate) {
3102 sc->priority = initial_priority;
3103 sc->force_deactivate = 1;
3104 sc->skipped_deactivate = 0;
3105 goto retry;
3106 }
3107
3118 /* Untapped cgroup reserves? Don't OOM, retry. */3108 /* Untapped cgroup reserves? Don't OOM, retry. */
3119 if (sc->memcg_low_skipped) {3109 if (sc->memcg_low_skipped) {
3120 sc->priority = initial_priority;3110 sc->priority = initial_priority;
3111 sc->force_deactivate = 0;
3112 sc->skipped_deactivate = 0;
3121 sc->memcg_low_reclaim = 1;3113 sc->memcg_low_reclaim = 1;
3122 sc->memcg_low_skipped = 0;3114 sc->memcg_low_skipped = 0;
3123 goto retry;3115 goto retry;
@@ -3309,6 +3301,7 @@ unsigned long mem_cgroup_shrink_node(struct mem_cgroup *memcg, · 185 unmodified lines
3309 pg_data_t *pgdat,3301 pg_data_t *pgdat,
3310 unsigned long *nr_scanned)3302 unsigned long *nr_scanned)
3311{3303{
3304 struct lruvec *lruvec = mem_cgroup_lruvec(memcg, pgdat);
3312 struct scan_control sc = {3305 struct scan_control sc = {
3313 .nr_to_reclaim = SWAP_CLUSTER_MAX,3306 .nr_to_reclaim = SWAP_CLUSTER_MAX,
3314 .target_mem_cgroup = memcg,3307 .target_mem_cgroup = memcg,
@@ -3317,7 +3310,6 @@ unsigned long mem_cgroup_shrink_node(struct mem_cgroup *memcg, · 2 unmodified lines
3317 .reclaim_idx = MAX_NR_ZONES - 1,3310 .reclaim_idx = MAX_NR_ZONES - 1,
3318 .may_swap = !noswap,3311 .may_swap = !noswap,
3319 };3312 };
3320 unsigned long lru_pages;
3321 3313
3322 WARN_ON_ONCE(!current->reclaim_state);3314 WARN_ON_ONCE(!current->reclaim_state);
3323 3315
@@ -3334,7 +3326,7 @@ unsigned long mem_cgroup_shrink_node(struct mem_cgroup *memcg, · 10 unmodified lines
3334 * will pick up pages from other mem cgroup's as well. We hack3326 * will pick up pages from other mem cgroup's as well. We hack
3335 * the priority and make it zero.3327 * the priority and make it zero.
3336 */3328 */
3337 shrink_node_memcg(pgdat, memcg, &sc, &lru_pages);3329 shrink_lruvec(lruvec, &sc);
3338 3330
3339 trace_mm_vmscan_memcg_softlimit_reclaim_end(sc.nr_reclaimed);3331 trace_mm_vmscan_memcg_softlimit_reclaim_end(sc.nr_reclaimed);
3340 3332
@@ -3348,10 +3340,8 @@ unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *memcg, · 7 unmodified lines
3348 gfp_t gfp_mask,3340 gfp_t gfp_mask,
3349 bool may_swap)3341 bool may_swap)
3350{3342{
3351 struct zonelist *zonelist;
3352 unsigned long nr_reclaimed;3343 unsigned long nr_reclaimed;
3353 unsigned long pflags;3344 unsigned long pflags;
3354 int nid;
3355 unsigned int noreclaim_flag;3345 unsigned int noreclaim_flag;
3356 struct scan_control sc = {3346 struct scan_control sc = {
3357 .nr_to_reclaim = max(nr_pages, SWAP_CLUSTER_MAX),3347 .nr_to_reclaim = max(nr_pages, SWAP_CLUSTER_MAX),
@@ -3364,16 +3354,14 @@ unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *memcg, · 6 unmodified lines
3364 .may_unmap = 1,3354 .may_unmap = 1,
3365 .may_swap = may_swap,3355 .may_swap = may_swap,
3366 };3356 };
3367
3368 set_task_reclaim_state(current, &sc.reclaim_state);
3369 /*3357 /*
3370 * Unlike direct reclaim via alloc_pages(), memcg's reclaim doesn't3358 * Traverse the ZONELIST_FALLBACK zonelist of the current node to put
3371 * take care of from where we get pages. So the node where we start the3359 * equal pressure on all the nodes. This is based on the assumption that
3372 * scan does not need to be the current node.3360 * the reclaim does not bail out early.
3373 */3361 */
3374 nid = mem_cgroup_select_victim_node(memcg);3362 struct zonelist *zonelist = node_zonelist(numa_node_id(), sc.gfp_mask);
3375 3363
3376 zonelist = &NODE_DATA(nid)->node_zonelists[ZONELIST_FALLBACK];3364 set_task_reclaim_state(current, &sc.reclaim_state);
3377 3365
3378 trace_mm_vmscan_memcg_reclaim_begin(0, sc.gfp_mask);3366 trace_mm_vmscan_memcg_reclaim_begin(0, sc.gfp_mask);
3379 3367
@@ -3396,18 +3384,20 @@ static void age_active_anon(struct pglist_data *pgdat, · 16 unmodified lines
3396 struct scan_control *sc)3384 struct scan_control *sc)
3397{3385{
3398 struct mem_cgroup *memcg;3386 struct mem_cgroup *memcg;
3387 struct lruvec *lruvec;
3399 3388
3400 if (!total_swap_pages)3389 if (!total_swap_pages)
3401 return;3390 return;
3402 3391
3392 lruvec = mem_cgroup_lruvec(NULL, pgdat);
3393 if (!inactive_is_low(lruvec, LRU_INACTIVE_ANON))
3394 return;
3395
3403 memcg = mem_cgroup_iter(NULL, NULL, NULL);3396 memcg = mem_cgroup_iter(NULL, NULL, NULL);
3404 do {3397 do {
3405 struct lruvec *lruvec = mem_cgroup_lruvec(pgdat, memcg);3398 lruvec = mem_cgroup_lruvec(memcg, pgdat);
3406 3399 shrink_active_list(SWAP_CLUSTER_MAX, lruvec,
3407 if (inactive_list_is_low(lruvec, false, sc, true))3400 sc, LRU_ACTIVE_ANON);
3408 shrink_active_list(SWAP_CLUSTER_MAX, lruvec,
3409 sc, LRU_ACTIVE_ANON);
3410
3411 memcg = mem_cgroup_iter(NULL, memcg, NULL);3401 memcg = mem_cgroup_iter(NULL, memcg, NULL);
3412 } while (memcg);3402 } while (memcg);
3413}3403}
@@ -3475,7 +3465,9 @@ static bool pgdat_balanced(pg_data_t *pgdat, int order, int classzone_idx) · 61 unmodified lines
3475/* Clear pgdat state for congested, dirty or under writeback. */3465/* Clear pgdat state for congested, dirty or under writeback. */
3476static void clear_pgdat_congested(pg_data_t *pgdat)3466static void clear_pgdat_congested(pg_data_t *pgdat)
3477{3467{
3478 clear_bit(PGDAT_CONGESTED, &pgdat->flags);3468 struct lruvec *lruvec = mem_cgroup_lruvec(NULL, pgdat);
3469
3470 clear_bit(LRUVEC_CONGESTED, &lruvec->flags);
3479 clear_bit(PGDAT_DIRTY, &pgdat->flags);3471 clear_bit(PGDAT_DIRTY, &pgdat->flags);
3480 clear_bit(PGDAT_WRITEBACK, &pgdat->flags);3472 clear_bit(PGDAT_WRITEBACK, &pgdat->flags);
3481}3473}
mm/workingset.c+53−16
@@ -213,28 +213,53 @@ static void unpack_shadow(void *shadow, int *memcgidp, pg_data_t **pgdat, · 212 unmodified lines
213 *workingsetp = workingset;213 *workingsetp = workingset;
214}214}
215 215
216static void advance_inactive_age(struct mem_cgroup *memcg, pg_data_t *pgdat)
217{
218 /*
219 * Reclaiming a cgroup means reclaiming all its children in a
220 * round-robin fashion. That means that each cgroup has an LRU
221 * order that is composed of the LRU orders of its child
222 * cgroups; and every page has an LRU position not just in the
223 * cgroup that owns it, but in all of that group's ancestors.
224 *
225 * So when the physical inactive list of a leaf cgroup ages,
226 * the virtual inactive lists of all its parents, including
227 * the root cgroup's, age as well.
228 */
229 do {
230 struct lruvec *lruvec;
231
232 lruvec = mem_cgroup_lruvec(memcg, pgdat);
233 atomic_long_inc(&lruvec->inactive_age);
234 } while (memcg && (memcg = parent_mem_cgroup(memcg)));
235}
236
216/**237/**
217 * workingset_eviction - note the eviction of a page from memory238 * workingset_eviction - note the eviction of a page from memory
239 * @target_memcg: the cgroup that is causing the reclaim
218 * @page: the page being evicted240 * @page: the page being evicted
219 *241 *
220 * Returns a shadow entry to be stored in @page->mapping->i_pages in place242 * Returns a shadow entry to be stored in @page->mapping->i_pages in place
221 * of the evicted @page so that a later refault can be detected.243 * of the evicted @page so that a later refault can be detected.
222 */244 */
223void *workingset_eviction(struct page *page)245void *workingset_eviction(struct page *page, struct mem_cgroup *target_memcg)
224{246{
225 struct pglist_data *pgdat = page_pgdat(page);247 struct pglist_data *pgdat = page_pgdat(page);
226 struct mem_cgroup *memcg = page_memcg(page);
227 int memcgid = mem_cgroup_id(memcg);
228 unsigned long eviction;248 unsigned long eviction;
229 struct lruvec *lruvec;249 struct lruvec *lruvec;
250 int memcgid;
230 251
231 /* Page is fully exclusive and pins page->mem_cgroup */252 /* Page is fully exclusive and pins page->mem_cgroup */
232 VM_BUG_ON_PAGE(PageLRU(page), page);253 VM_BUG_ON_PAGE(PageLRU(page), page);
233 VM_BUG_ON_PAGE(page_count(page), page);254 VM_BUG_ON_PAGE(page_count(page), page);
234 VM_BUG_ON_PAGE(!PageLocked(page), page);255 VM_BUG_ON_PAGE(!PageLocked(page), page);
235 256
236 lruvec = mem_cgroup_lruvec(pgdat, memcg);257 advance_inactive_age(page_memcg(page), pgdat);
237 eviction = atomic_long_inc_return(&lruvec->inactive_age);258
259 lruvec = mem_cgroup_lruvec(target_memcg, pgdat);
260 /* XXX: target_memcg can be NULL, go through lruvec */
261 memcgid = mem_cgroup_id(lruvec_memcg(lruvec));
262 eviction = atomic_long_read(&lruvec->inactive_age);
238 return pack_shadow(memcgid, pgdat, eviction, PageWorkingset(page));263 return pack_shadow(memcgid, pgdat, eviction, PageWorkingset(page));
239}264}
240 265
@@ -244,10 +269,13 @@ void *workingset_eviction(struct page *page) · 3 unmodified lines
244 * @shadow: shadow entry of the evicted page269 * @shadow: shadow entry of the evicted page
245 *270 *
246 * Calculates and evaluates the refault distance of the previously271 * Calculates and evaluates the refault distance of the previously
247 * evicted page in the context of the node it was allocated in.272 * evicted page in the context of the node and the memcg whose memory
273 * pressure caused the eviction.
248 */274 */
249void workingset_refault(struct page *page, void *shadow)275void workingset_refault(struct page *page, void *shadow)
250{276{
277 struct mem_cgroup *eviction_memcg;
278 struct lruvec *eviction_lruvec;
251 unsigned long refault_distance;279 unsigned long refault_distance;
252 struct pglist_data *pgdat;280 struct pglist_data *pgdat;
253 unsigned long active_file;281 unsigned long active_file;
@@ -277,12 +305,12 @@ void workingset_refault(struct page *page, void *shadow) · 23 unmodified lines
277 * would be better if the root_mem_cgroup existed in all305 * would be better if the root_mem_cgroup existed in all
278 * configurations instead.306 * configurations instead.
279 */307 */
280 memcg = mem_cgroup_from_id(memcgid);308 eviction_memcg = mem_cgroup_from_id(memcgid);
281 if (!mem_cgroup_disabled() && !memcg)309 if (!mem_cgroup_disabled() && !eviction_memcg)
282 goto out;310 goto out;
283 lruvec = mem_cgroup_lruvec(pgdat, memcg);311 eviction_lruvec = mem_cgroup_lruvec(eviction_memcg, pgdat);
284 refault = atomic_long_read(&lruvec->inactive_age);312 refault = atomic_long_read(&eviction_lruvec->inactive_age);
285 active_file = lruvec_lru_size(lruvec, LRU_ACTIVE_FILE, MAX_NR_ZONES);313 active_file = lruvec_page_state(eviction_lruvec, NR_ACTIVE_FILE);
286 314
287 /*315 /*
288 * Calculate the refault distance316 * Calculate the refault distance
@@ -302,6 +330,17 @@ void workingset_refault(struct page *page, void *shadow) · 13 unmodified lines
302 */330 */
303 refault_distance = (refault - eviction) & EVICTION_MASK;331 refault_distance = (refault - eviction) & EVICTION_MASK;
304 332
333 /*
334 * The activation decision for this page is made at the level
335 * where the eviction occurred, as that is where the LRU order
336 * during page reclaim is being determined.
337 *
338 * However, the cgroup that will own the page is the one that
339 * is actually experiencing the refault event.
340 */
341 memcg = page_memcg(page);
342 lruvec = mem_cgroup_lruvec(memcg, pgdat);
343
305 inc_lruvec_state(lruvec, WORKINGSET_REFAULT);344 inc_lruvec_state(lruvec, WORKINGSET_REFAULT);
306 345
307 /*346 /*
@@ -313,7 +352,7 @@ void workingset_refault(struct page *page, void *shadow) · 5 unmodified lines
313 goto out;352 goto out;
314 353
315 SetPageActive(page);354 SetPageActive(page);
316 atomic_long_inc(&lruvec->inactive_age);355 advance_inactive_age(memcg, pgdat);
317 inc_lruvec_state(lruvec, WORKINGSET_ACTIVATE);356 inc_lruvec_state(lruvec, WORKINGSET_ACTIVATE);
318 357
319 /* Page was active prior to eviction */358 /* Page was active prior to eviction */
@@ -332,7 +371,6 @@ out: · 12 unmodified lines
332void workingset_activation(struct page *page)371void workingset_activation(struct page *page)
333{372{
334 struct mem_cgroup *memcg;373 struct mem_cgroup *memcg;
335 struct lruvec *lruvec;
336 374
337 rcu_read_lock();375 rcu_read_lock();
338 /*376 /*
@@ -345,8 +383,7 @@ void workingset_activation(struct page *page) · 6 unmodified lines
345 memcg = page_memcg_rcu(page);383 memcg = page_memcg_rcu(page);
346 if (!mem_cgroup_disabled() && !memcg)384 if (!mem_cgroup_disabled() && !memcg)
347 goto out;385 goto out;
348 lruvec = mem_cgroup_lruvec(page_pgdat(page), memcg);386 advance_inactive_age(memcg, page_pgdat(page));
349 atomic_long_inc(&lruvec->inactive_age);
350out:387out:
351 rcu_read_unlock();388 rcu_read_unlock();
352}389}
@@ -426,7 +463,7 @@ static unsigned long count_shadow_nodes(struct shrinker *shrinker, · 73 unmodified lines
426 struct lruvec *lruvec;463 struct lruvec *lruvec;
427 int i;464 int i;
428 465
429 lruvec = mem_cgroup_lruvec(NODE_DATA(sc->nid), sc->memcg);466 lruvec = mem_cgroup_lruvec(sc->memcg, NODE_DATA(sc->nid));
430 for (pages = 0, i = 0; i < NR_LRU_LISTS; i++)467 for (pages = 0, i = 0; i < NR_LRU_LISTS; i++)
431 pages += lruvec_page_state_local(lruvec,468 pages += lruvec_page_state_local(lruvec,
432 NR_LRU_BASE + i);469 NR_LRU_BASE + i);
mm/z3fold.c+303−72
@@ -41,6 +41,7 @@ · 40 unmodified lines
41#include <linux/workqueue.h>41#include <linux/workqueue.h>
42#include <linux/slab.h>42#include <linux/slab.h>
43#include <linux/spinlock.h>43#include <linux/spinlock.h>
44#include <linux/rwlock.h>
44#include <linux/zpool.h>45#include <linux/zpool.h>
45#include <linux/magic.h>46#include <linux/magic.h>
46 47
@@ -90,6 +91,7 @@ struct z3fold_buddy_slots { · 43 unmodified lines
90 */91 */
91 unsigned long slot[BUDDY_MASK + 1];92 unsigned long slot[BUDDY_MASK + 1];
92 unsigned long pool; /* back link + flags */93 unsigned long pool; /* back link + flags */
94 rwlock_t lock;
93};95};
94#define HANDLE_FLAG_MASK (0x03)96#define HANDLE_FLAG_MASK (0x03)
95 97
@@ -124,6 +126,7 @@ struct z3fold_header { · 28 unmodified lines
124 unsigned short start_middle;126 unsigned short start_middle;
125 unsigned short first_num:2;127 unsigned short first_num:2;
126 unsigned short mapped_count:2;128 unsigned short mapped_count:2;
129 unsigned short foreign_handles:2;
127};130};
128 131
129/**132/**
@@ -178,6 +181,19 @@ enum z3fold_page_flags { · 48 unmodified lines
178 PAGE_CLAIMED, /* by either reclaim or free */181 PAGE_CLAIMED, /* by either reclaim or free */
179};182};
180 183
184/*
185 * handle flags, go under HANDLE_FLAG_MASK
186 */
187enum z3fold_handle_flags {
188 HANDLES_ORPHANED = 0,
189};
190
191/*
192 * Forward declarations
193 */
194static struct z3fold_header *__z3fold_alloc(struct z3fold_pool *, size_t, bool);
195static void compact_page_work(struct work_struct *w);
196
181/*****************197/*****************
182 * Helpers198 * Helpers
183*****************/199*****************/
@@ -191,8 +207,6 @@ static int size_to_chunks(size_t size) · 7 unmodified lines
191#define for_each_unbuddied_list(_iter, _begin) \207#define for_each_unbuddied_list(_iter, _begin) \
192 for ((_iter) = (_begin); (_iter) < NCHUNKS; (_iter)++)208 for ((_iter) = (_begin); (_iter) < NCHUNKS; (_iter)++)
193 209
194static void compact_page_work(struct work_struct *w);
195
196static inline struct z3fold_buddy_slots *alloc_slots(struct z3fold_pool *pool,210static inline struct z3fold_buddy_slots *alloc_slots(struct z3fold_pool *pool,
197 gfp_t gfp)211 gfp_t gfp)
198{212{
@@ -204,6 +218,7 @@ static inline struct z3fold_buddy_slots *alloc_slots(struct z3fold_pool *pool, · 5 unmodified lines
204 if (slots) {218 if (slots) {
205 memset(slots->slot, 0, sizeof(slots->slot));219 memset(slots->slot, 0, sizeof(slots->slot));
206 slots->pool = (unsigned long)pool;220 slots->pool = (unsigned long)pool;
221 rwlock_init(&slots->lock);
207 }222 }
208 223
209 return slots;224 return slots;
@@ -219,25 +234,110 @@ static inline struct z3fold_buddy_slots *handle_to_slots(unsigned long handle) · 9 unmodified lines
219 return (struct z3fold_buddy_slots *)(handle & ~(SLOTS_ALIGN - 1));234 return (struct z3fold_buddy_slots *)(handle & ~(SLOTS_ALIGN - 1));
220}235}
221 236
237/* Lock a z3fold page */
238static inline void z3fold_page_lock(struct z3fold_header *zhdr)
239{
240 spin_lock(&zhdr->page_lock);
241}
242
243/* Try to lock a z3fold page */
244static inline int z3fold_page_trylock(struct z3fold_header *zhdr)
245{
246 return spin_trylock(&zhdr->page_lock);
247}
248
249/* Unlock a z3fold page */
250static inline void z3fold_page_unlock(struct z3fold_header *zhdr)
251{
252 spin_unlock(&zhdr->page_lock);
253}
254
255
256static inline struct z3fold_header *__get_z3fold_header(unsigned long handle,
257 bool lock)
258{
259 struct z3fold_buddy_slots *slots;
260 struct z3fold_header *zhdr;
261 int locked = 0;
262
263 if (!(handle & (1 << PAGE_HEADLESS))) {
264 slots = handle_to_slots(handle);
265 do {
266 unsigned long addr;
267
268 read_lock(&slots->lock);
269 addr = *(unsigned long *)handle;
270 zhdr = (struct z3fold_header *)(addr & PAGE_MASK);
271 if (lock)
272 locked = z3fold_page_trylock(zhdr);
273 read_unlock(&slots->lock);
274 if (locked)
275 break;
276 cpu_relax();
277 } while (lock);
278 } else {
279 zhdr = (struct z3fold_header *)(handle & PAGE_MASK);
280 }
281
282 return zhdr;
283}
284
285/* Returns the z3fold page where a given handle is stored */
286static inline struct z3fold_header *handle_to_z3fold_header(unsigned long h)
287{
288 return __get_z3fold_header(h, false);
289}
290
291/* return locked z3fold page if it's not headless */
292static inline struct z3fold_header *get_z3fold_header(unsigned long h)
293{
294 return __get_z3fold_header(h, true);
295}
296
297static inline void put_z3fold_header(struct z3fold_header *zhdr)
298{
299 struct page *page = virt_to_page(zhdr);
300
301 if (!test_bit(PAGE_HEADLESS, &page->private))
302 z3fold_page_unlock(zhdr);
303}
304
222static inline void free_handle(unsigned long handle)305static inline void free_handle(unsigned long handle)
223{306{
224 struct z3fold_buddy_slots *slots;307 struct z3fold_buddy_slots *slots;
308 struct z3fold_header *zhdr;
225 int i;309 int i;
226 bool is_free;310 bool is_free;
227 311
228 if (handle & (1 << PAGE_HEADLESS))312 if (handle & (1 << PAGE_HEADLESS))
229 return;313 return;
230 314
231 WARN_ON(*(unsigned long *)handle == 0);315 if (WARN_ON(*(unsigned long *)handle == 0))
232 *(unsigned long *)handle = 0;316 return;
317
318 zhdr = handle_to_z3fold_header(handle);
233 slots = handle_to_slots(handle);319 slots = handle_to_slots(handle);
320 write_lock(&slots->lock);
321 *(unsigned long *)handle = 0;
322 write_unlock(&slots->lock);
323 if (zhdr->slots == slots)
324 return; /* simple case, nothing else to do */
325
326 /* we are freeing a foreign handle if we are here */
327 zhdr->foreign_handles--;
234 is_free = true;328 is_free = true;
329 read_lock(&slots->lock);
330 if (!test_bit(HANDLES_ORPHANED, &slots->pool)) {
331 read_unlock(&slots->lock);
332 return;
333 }
235 for (i = 0; i <= BUDDY_MASK; i++) {334 for (i = 0; i <= BUDDY_MASK; i++) {
236 if (slots->slot[i]) {335 if (slots->slot[i]) {
237 is_free = false;336 is_free = false;
238 break;337 break;
239 }338 }
240 }339 }
340 read_unlock(&slots->lock);
241 341
242 if (is_free) {342 if (is_free) {
243 struct z3fold_pool *pool = slots_to_pool(slots);343 struct z3fold_pool *pool = slots_to_pool(slots);
@@ -322,6 +422,7 @@ static struct z3fold_header *init_z3fold_page(struct page *page, bool headless, · 78 unmodified lines
322 zhdr->first_num = 0;422 zhdr->first_num = 0;
323 zhdr->start_middle = 0;423 zhdr->start_middle = 0;
324 zhdr->cpu = -1;424 zhdr->cpu = -1;
425 zhdr->foreign_handles = 0;
325 zhdr->slots = slots;426 zhdr->slots = slots;
326 zhdr->pool = pool;427 zhdr->pool = pool;
327 INIT_LIST_HEAD(&zhdr->buddy);428 INIT_LIST_HEAD(&zhdr->buddy);
@@ -341,24 +442,6 @@ static void free_z3fold_page(struct page *page, bool headless) · 13 unmodified lines
341 __free_page(page);442 __free_page(page);
342}443}
343 444
344/* Lock a z3fold page */
345static inline void z3fold_page_lock(struct z3fold_header *zhdr)
346{
347 spin_lock(&zhdr->page_lock);
348}
349
350/* Try to lock a z3fold page */
351static inline int z3fold_page_trylock(struct z3fold_header *zhdr)
352{
353 return spin_trylock(&zhdr->page_lock);
354}
355
356/* Unlock a z3fold page */
357static inline void z3fold_page_unlock(struct z3fold_header *zhdr)
358{
359 spin_unlock(&zhdr->page_lock);
360}
361
362/* Helper function to build the index */445/* Helper function to build the index */
363static inline int __idx(struct z3fold_header *zhdr, enum buddy bud)446static inline int __idx(struct z3fold_header *zhdr, enum buddy bud)
364{447{
@@ -389,7 +472,9 @@ static unsigned long __encode_handle(struct z3fold_header *zhdr, · 24 unmodified lines
389 if (bud == LAST)472 if (bud == LAST)
390 h |= (zhdr->last_chunks << BUDDY_SHIFT);473 h |= (zhdr->last_chunks << BUDDY_SHIFT);
391 474
475 write_lock(&slots->lock);
392 slots->slot[idx] = h;476 slots->slot[idx] = h;
477 write_unlock(&slots->lock);
393 return (unsigned long)&slots->slot[idx];478 return (unsigned long)&slots->slot[idx];
394}479}
395 480
@@ -398,22 +483,15 @@ static unsigned long encode_handle(struct z3fold_header *zhdr, enum buddy bud) · 2 unmodified lines
398 return __encode_handle(zhdr, zhdr->slots, bud);483 return __encode_handle(zhdr, zhdr->slots, bud);
399}484}
400 485
401/* Returns the z3fold page where a given handle is stored */
402static inline struct z3fold_header *handle_to_z3fold_header(unsigned long h)
403{
404 unsigned long addr = h;
405
406 if (!(addr & (1 << PAGE_HEADLESS)))
407 addr = *(unsigned long *)h;
408
409 return (struct z3fold_header *)(addr & PAGE_MASK);
410}
411
412/* only for LAST bud, returns zero otherwise */486/* only for LAST bud, returns zero otherwise */
413static unsigned short handle_to_chunks(unsigned long handle)487static unsigned short handle_to_chunks(unsigned long handle)
414{488{
415 unsigned long addr = *(unsigned long *)handle;489 struct z3fold_buddy_slots *slots = handle_to_slots(handle);
490 unsigned long addr;
416 491
492 read_lock(&slots->lock);
493 addr = *(unsigned long *)handle;
494 read_unlock(&slots->lock);
417 return (addr & ~PAGE_MASK) >> BUDDY_SHIFT;495 return (addr & ~PAGE_MASK) >> BUDDY_SHIFT;
418}496}
419 497
@@ -425,10 +503,13 @@ static unsigned short handle_to_chunks(unsigned long handle) · 5 unmodified lines
425static enum buddy handle_to_buddy(unsigned long handle)503static enum buddy handle_to_buddy(unsigned long handle)
426{504{
427 struct z3fold_header *zhdr;505 struct z3fold_header *zhdr;
506 struct z3fold_buddy_slots *slots = handle_to_slots(handle);
428 unsigned long addr;507 unsigned long addr;
429 508
509 read_lock(&slots->lock);
430 WARN_ON(handle & (1 << PAGE_HEADLESS));510 WARN_ON(handle & (1 << PAGE_HEADLESS));
431 addr = *(unsigned long *)handle;511 addr = *(unsigned long *)handle;
512 read_unlock(&slots->lock);
432 zhdr = (struct z3fold_header *)(addr & PAGE_MASK);513 zhdr = (struct z3fold_header *)(addr & PAGE_MASK);
433 return (addr - zhdr->first_num) & BUDDY_MASK;514 return (addr - zhdr->first_num) & BUDDY_MASK;
434}515}
@@ -442,6 +523,8 @@ static void __release_z3fold_page(struct z3fold_header *zhdr, bool locked) · 7 unmodified lines
442{523{
443 struct page *page = virt_to_page(zhdr);524 struct page *page = virt_to_page(zhdr);
444 struct z3fold_pool *pool = zhdr_to_pool(zhdr);525 struct z3fold_pool *pool = zhdr_to_pool(zhdr);
526 bool is_free = true;
527 int i;
445 528
446 WARN_ON(!list_empty(&zhdr->buddy));529 WARN_ON(!list_empty(&zhdr->buddy));
447 set_bit(PAGE_STALE, &page->private);530 set_bit(PAGE_STALE, &page->private);
@@ -450,8 +533,25 @@ static void __release_z3fold_page(struct z3fold_header *zhdr, bool locked) · 2 unmodified lines
450 if (!list_empty(&page->lru))533 if (!list_empty(&page->lru))
451 list_del_init(&page->lru);534 list_del_init(&page->lru);
452 spin_unlock(&pool->lock);535 spin_unlock(&pool->lock);
536
537 /* If there are no foreign handles, free the handles array */
538 read_lock(&zhdr->slots->lock);
539 for (i = 0; i <= BUDDY_MASK; i++) {
540 if (zhdr->slots->slot[i]) {
541 is_free = false;
542 break;
543 }
544 }
545 if (!is_free)
546 set_bit(HANDLES_ORPHANED, &zhdr->slots->pool);
547 read_unlock(&zhdr->slots->lock);
548
549 if (is_free)
550 kmem_cache_free(pool->c_handle, zhdr->slots);
551
453 if (locked)552 if (locked)
454 z3fold_page_unlock(zhdr);553 z3fold_page_unlock(zhdr);
554
455 spin_lock(&pool->stale_lock);555 spin_lock(&pool->stale_lock);
456 list_add(&zhdr->buddy, &pool->stale);556 list_add(&zhdr->buddy, &pool->stale);
457 queue_work(pool->release_wq, &pool->work);557 queue_work(pool->release_wq, &pool->work);
@@ -479,6 +579,7 @@ static void release_z3fold_page_locked_list(struct kref *ref) · 21 unmodified lines
479 struct z3fold_header *zhdr = container_of(ref, struct z3fold_header,579 struct z3fold_header *zhdr = container_of(ref, struct z3fold_header,
480 refcount);580 refcount);
481 struct z3fold_pool *pool = zhdr_to_pool(zhdr);581 struct z3fold_pool *pool = zhdr_to_pool(zhdr);
582
482 spin_lock(&pool->lock);583 spin_lock(&pool->lock);
483 list_del_init(&zhdr->buddy);584 list_del_init(&zhdr->buddy);
484 spin_unlock(&pool->lock);585 spin_unlock(&pool->lock);
@@ -559,6 +660,119 @@ static inline void *mchunk_memmove(struct z3fold_header *zhdr, · 74 unmodified lines
559 zhdr->middle_chunks << CHUNK_SHIFT);660 zhdr->middle_chunks << CHUNK_SHIFT);
560}661}
561 662
663static inline bool buddy_single(struct z3fold_header *zhdr)
664{
665 return !((zhdr->first_chunks && zhdr->middle_chunks) ||
666 (zhdr->first_chunks && zhdr->last_chunks) ||
667 (zhdr->middle_chunks && zhdr->last_chunks));
668}
669
670static struct z3fold_header *compact_single_buddy(struct z3fold_header *zhdr)
671{
672 struct z3fold_pool *pool = zhdr_to_pool(zhdr);
673 void *p = zhdr;
674 unsigned long old_handle = 0;
675 size_t sz = 0;
676 struct z3fold_header *new_zhdr = NULL;
677 int first_idx = __idx(zhdr, FIRST);
678 int middle_idx = __idx(zhdr, MIDDLE);
679 int last_idx = __idx(zhdr, LAST);
680 unsigned short *moved_chunks = NULL;
681
682 /*
683 * No need to protect slots here -- all the slots are "local" and
684 * the page lock is already taken
685 */
686 if (zhdr->first_chunks && zhdr->slots->slot[first_idx]) {
687 p += ZHDR_SIZE_ALIGNED;
688 sz = zhdr->first_chunks << CHUNK_SHIFT;
689 old_handle = (unsigned long)&zhdr->slots->slot[first_idx];
690 moved_chunks = &zhdr->first_chunks;
691 } else if (zhdr->middle_chunks && zhdr->slots->slot[middle_idx]) {
692 p += zhdr->start_middle << CHUNK_SHIFT;
693 sz = zhdr->middle_chunks << CHUNK_SHIFT;
694 old_handle = (unsigned long)&zhdr->slots->slot[middle_idx];
695 moved_chunks = &zhdr->middle_chunks;
696 } else if (zhdr->last_chunks && zhdr->slots->slot[last_idx]) {
697 p += PAGE_SIZE - (zhdr->last_chunks << CHUNK_SHIFT);
698 sz = zhdr->last_chunks << CHUNK_SHIFT;
699 old_handle = (unsigned long)&zhdr->slots->slot[last_idx];
700 moved_chunks = &zhdr->last_chunks;
701 }
702
703 if (sz > 0) {
704 enum buddy new_bud = HEADLESS;
705 short chunks = size_to_chunks(sz);
706 void *q;
707
708 new_zhdr = __z3fold_alloc(pool, sz, false);
709 if (!new_zhdr)
710 return NULL;
711
712 if (WARN_ON(new_zhdr == zhdr))
713 goto out_fail;
714
715 if (new_zhdr->first_chunks == 0) {
716 if (new_zhdr->middle_chunks != 0 &&
717 chunks >= new_zhdr->start_middle) {
718 new_bud = LAST;
719 } else {
720 new_bud = FIRST;
721 }
722 } else if (new_zhdr->last_chunks == 0) {
723 new_bud = LAST;
724 } else if (new_zhdr->middle_chunks == 0) {
725 new_bud = MIDDLE;
726 }
727 q = new_zhdr;
728 switch (new_bud) {
729 case FIRST:
730 new_zhdr->first_chunks = chunks;
731 q += ZHDR_SIZE_ALIGNED;
732 break;
733 case MIDDLE:
734 new_zhdr->middle_chunks = chunks;
735 new_zhdr->start_middle =
736 new_zhdr->first_chunks + ZHDR_CHUNKS;
737 q += new_zhdr->start_middle << CHUNK_SHIFT;
738 break;
739 case LAST:
740 new_zhdr->last_chunks = chunks;
741 q += PAGE_SIZE - (new_zhdr->last_chunks << CHUNK_SHIFT);
742 break;
743 default:
744 goto out_fail;
745 }
746 new_zhdr->foreign_handles++;
747 memcpy(q, p, sz);
748 write_lock(&zhdr->slots->lock);
749 *(unsigned long *)old_handle = (unsigned long)new_zhdr +
750 __idx(new_zhdr, new_bud);
751 if (new_bud == LAST)
752 *(unsigned long *)old_handle |=
753 (new_zhdr->last_chunks << BUDDY_SHIFT);
754 write_unlock(&zhdr->slots->lock);
755 add_to_unbuddied(pool, new_zhdr);
756 z3fold_page_unlock(new_zhdr);
757
758 *moved_chunks = 0;
759 }
760
761 return new_zhdr;
762
763out_fail:
764 if (new_zhdr) {
765 if (kref_put(&new_zhdr->refcount, release_z3fold_page_locked))
766 atomic64_dec(&pool->pages_nr);
767 else {
768 add_to_unbuddied(pool, new_zhdr);
769 z3fold_page_unlock(new_zhdr);
770 }
771 }
772 return NULL;
773
774}
775
562#define BIG_CHUNK_GAP 3776#define BIG_CHUNK_GAP 3
563/* Has to be called with lock held */777/* Has to be called with lock held */
564static int z3fold_compact_page(struct z3fold_header *zhdr)778static int z3fold_compact_page(struct z3fold_header *zhdr)
@@ -638,6 +852,15 @@ static void do_compact_page(struct z3fold_header *zhdr, bool locked) · 73 unmodified lines
638 return;852 return;
639 }853 }
640 854
855 if (!zhdr->foreign_handles && buddy_single(zhdr) &&
856 zhdr->mapped_count == 0 && compact_single_buddy(zhdr)) {
857 if (kref_put(&zhdr->refcount, release_z3fold_page_locked))
858 atomic64_dec(&pool->pages_nr);
859 else
860 z3fold_page_unlock(zhdr);
861 return;
862 }
863
641 z3fold_compact_page(zhdr);864 z3fold_compact_page(zhdr);
642 add_to_unbuddied(pool, zhdr);865 add_to_unbuddied(pool, zhdr);
643 z3fold_page_unlock(zhdr);866 z3fold_page_unlock(zhdr);
@@ -690,7 +913,8 @@ lookup: · 46 unmodified lines
690 spin_unlock(&pool->lock);913 spin_unlock(&pool->lock);
691 914
692 page = virt_to_page(zhdr);915 page = virt_to_page(zhdr);
693 if (test_bit(NEEDS_COMPACTING, &page->private)) {916 if (test_bit(NEEDS_COMPACTING, &page->private) ||
917 test_bit(PAGE_CLAIMED, &page->private)) {
694 z3fold_page_unlock(zhdr);918 z3fold_page_unlock(zhdr);
695 zhdr = NULL;919 zhdr = NULL;
696 put_cpu_ptr(pool->unbuddied);920 put_cpu_ptr(pool->unbuddied);
@@ -734,7 +958,8 @@ lookup: · 37 unmodified lines
734 spin_unlock(&pool->lock);958 spin_unlock(&pool->lock);
735 959
736 page = virt_to_page(zhdr);960 page = virt_to_page(zhdr);
737 if (test_bit(NEEDS_COMPACTING, &page->private)) {961 if (test_bit(NEEDS_COMPACTING, &page->private) ||
962 test_bit(PAGE_CLAIMED, &page->private)) {
738 z3fold_page_unlock(zhdr);963 z3fold_page_unlock(zhdr);
739 zhdr = NULL;964 zhdr = NULL;
740 if (can_sleep)965 if (can_sleep)
@@ -1000,7 +1225,7 @@ static void z3fold_free(struct z3fold_pool *pool, unsigned long handle) · 259 unmodified lines
1000 enum buddy bud;1225 enum buddy bud;
1001 bool page_claimed;1226 bool page_claimed;
1002 1227
1003 zhdr = handle_to_z3fold_header(handle);1228 zhdr = get_z3fold_header(handle);
1004 page = virt_to_page(zhdr);1229 page = virt_to_page(zhdr);
1005 page_claimed = test_and_set_bit(PAGE_CLAIMED, &page->private);1230 page_claimed = test_and_set_bit(PAGE_CLAIMED, &page->private);
1006 1231
@@ -1014,6 +1239,7 @@ static void z3fold_free(struct z3fold_pool *pool, unsigned long handle) · 7 unmodified lines
1014 spin_lock(&pool->lock);1239 spin_lock(&pool->lock);
1015 list_del(&page->lru);1240 list_del(&page->lru);
1016 spin_unlock(&pool->lock);1241 spin_unlock(&pool->lock);
1242 put_z3fold_header(zhdr);
1017 free_z3fold_page(page, true);1243 free_z3fold_page(page, true);
1018 atomic64_dec(&pool->pages_nr);1244 atomic64_dec(&pool->pages_nr);
1019 }1245 }
@@ -1021,7 +1247,6 @@ static void z3fold_free(struct z3fold_pool *pool, unsigned long handle) · 1 unmodified line
1021 }1247 }
1022 1248
1023 /* Non-headless case */1249 /* Non-headless case */
1024 z3fold_page_lock(zhdr);
1025 bud = handle_to_buddy(handle);1250 bud = handle_to_buddy(handle);
1026 1251
1027 switch (bud) {1252 switch (bud) {
@@ -1037,11 +1262,13 @@ static void z3fold_free(struct z3fold_pool *pool, unsigned long handle) · 9 unmodified lines
1037 default:1262 default:
1038 pr_err("%s: unknown bud %d\n", __func__, bud);1263 pr_err("%s: unknown bud %d\n", __func__, bud);
1039 WARN_ON(1);1264 WARN_ON(1);
1040 z3fold_page_unlock(zhdr);1265 put_z3fold_header(zhdr);
1266 clear_bit(PAGE_CLAIMED, &page->private);
1041 return;1267 return;
1042 }1268 }
1043 1269
1044 free_handle(handle);1270 if (!page_claimed)
1271 free_handle(handle);
1045 if (kref_put(&zhdr->refcount, release_z3fold_page_locked_list)) {1272 if (kref_put(&zhdr->refcount, release_z3fold_page_locked_list)) {
1046 atomic64_dec(&pool->pages_nr);1273 atomic64_dec(&pool->pages_nr);
1047 return;1274 return;
@@ -1053,7 +1280,7 @@ static void z3fold_free(struct z3fold_pool *pool, unsigned long handle) · 5 unmodified lines
1053 }1280 }
1054 if (unlikely(PageIsolated(page)) ||1281 if (unlikely(PageIsolated(page)) ||
1055 test_and_set_bit(NEEDS_COMPACTING, &page->private)) {1282 test_and_set_bit(NEEDS_COMPACTING, &page->private)) {
1056 z3fold_page_unlock(zhdr);1283 put_z3fold_header(zhdr);
1057 clear_bit(PAGE_CLAIMED, &page->private);1284 clear_bit(PAGE_CLAIMED, &page->private);
1058 return;1285 return;
1059 }1286 }
@@ -1063,14 +1290,14 @@ static void z3fold_free(struct z3fold_pool *pool, unsigned long handle) · 3 unmodified lines
1063 spin_unlock(&pool->lock);1290 spin_unlock(&pool->lock);
1064 zhdr->cpu = -1;1291 zhdr->cpu = -1;
1065 kref_get(&zhdr->refcount);1292 kref_get(&zhdr->refcount);
1066 do_compact_page(zhdr, true);
1067 clear_bit(PAGE_CLAIMED, &page->private);1293 clear_bit(PAGE_CLAIMED, &page->private);
1294 do_compact_page(zhdr, true);
1068 return;1295 return;
1069 }1296 }
1070 kref_get(&zhdr->refcount);1297 kref_get(&zhdr->refcount);
1071 queue_work_on(zhdr->cpu, pool->compact_wq, &zhdr->work);
1072 clear_bit(PAGE_CLAIMED, &page->private);1298 clear_bit(PAGE_CLAIMED, &page->private);
1073 z3fold_page_unlock(zhdr);1299 queue_work_on(zhdr->cpu, pool->compact_wq, &zhdr->work);
1300 put_z3fold_header(zhdr);
1074}1301}
1075 1302
1076/**1303/**
@@ -1111,11 +1338,10 @@ static void z3fold_free(struct z3fold_pool *pool, unsigned long handle) · 34 unmodified lines
1111 */1338 */
1112static int z3fold_reclaim_page(struct z3fold_pool *pool, unsigned int retries)1339static int z3fold_reclaim_page(struct z3fold_pool *pool, unsigned int retries)
1113{1340{
1114 int i, ret = 0;1341 int i, ret = -1;
1115 struct z3fold_header *zhdr = NULL;1342 struct z3fold_header *zhdr = NULL;
1116 struct page *page = NULL;1343 struct page *page = NULL;
1117 struct list_head *pos;1344 struct list_head *pos;
1118 struct z3fold_buddy_slots slots;
1119 unsigned long first_handle = 0, middle_handle = 0, last_handle = 0;1345 unsigned long first_handle = 0, middle_handle = 0, last_handle = 0;
1120 1346
1121 spin_lock(&pool->lock);1347 spin_lock(&pool->lock);
@@ -1153,6 +1379,12 @@ static int z3fold_reclaim_page(struct z3fold_pool *pool, unsigned int retries) · 31 unmodified lines
1153 zhdr = NULL;1379 zhdr = NULL;
1154 continue; /* can't evict at this point */1380 continue; /* can't evict at this point */
1155 }1381 }
1382 if (zhdr->foreign_handles) {
1383 clear_bit(PAGE_CLAIMED, &page->private);
1384 z3fold_page_unlock(zhdr);
1385 zhdr = NULL;
1386 continue; /* can't evict such page */
1387 }
1156 kref_get(&zhdr->refcount);1388 kref_get(&zhdr->refcount);
1157 list_del_init(&zhdr->buddy);1389 list_del_init(&zhdr->buddy);
1158 zhdr->cpu = -1;1390 zhdr->cpu = -1;
@@ -1176,39 +1408,38 @@ static int z3fold_reclaim_page(struct z3fold_pool *pool, unsigned int retries) · 17 unmodified lines
1176 last_handle = 0;1408 last_handle = 0;
1177 middle_handle = 0;1409 middle_handle = 0;
1178 if (zhdr->first_chunks)1410 if (zhdr->first_chunks)
1179 first_handle = __encode_handle(zhdr, &slots,1411 first_handle = encode_handle(zhdr, FIRST);
1180 FIRST);
1181 if (zhdr->middle_chunks)1412 if (zhdr->middle_chunks)
1182 middle_handle = __encode_handle(zhdr, &slots,1413 middle_handle = encode_handle(zhdr, MIDDLE);
1183 MIDDLE);
1184 if (zhdr->last_chunks)1414 if (zhdr->last_chunks)
1185 last_handle = __encode_handle(zhdr, &slots,1415 last_handle = encode_handle(zhdr, LAST);
1186 LAST);
1187 /*1416 /*
1188 * it's safe to unlock here because we hold a1417 * it's safe to unlock here because we hold a
1189 * reference to this page1418 * reference to this page
1190 */1419 */
1191 z3fold_page_unlock(zhdr);1420 z3fold_page_unlock(zhdr);
1192 } else {1421 } else {
1193 first_handle = __encode_handle(zhdr, &slots, HEADLESS);1422 first_handle = encode_handle(zhdr, HEADLESS);
1194 last_handle = middle_handle = 0;1423 last_handle = middle_handle = 0;
1195 }1424 }
1196
1197 /* Issue the eviction callback(s) */1425 /* Issue the eviction callback(s) */
1198 if (middle_handle) {1426 if (middle_handle) {
1199 ret = pool->ops->evict(pool, middle_handle);1427 ret = pool->ops->evict(pool, middle_handle);
1200 if (ret)1428 if (ret)
1201 goto next;1429 goto next;
1430 free_handle(middle_handle);
1202 }1431 }
1203 if (first_handle) {1432 if (first_handle) {
1204 ret = pool->ops->evict(pool, first_handle);1433 ret = pool->ops->evict(pool, first_handle);
1205 if (ret)1434 if (ret)
1206 goto next;1435 goto next;
1436 free_handle(first_handle);
1207 }1437 }
1208 if (last_handle) {1438 if (last_handle) {
1209 ret = pool->ops->evict(pool, last_handle);1439 ret = pool->ops->evict(pool, last_handle);
1210 if (ret)1440 if (ret)
1211 goto next;1441 goto next;
1442 free_handle(last_handle);
1212 }1443 }
1213next:1444next:
1214 if (test_bit(PAGE_HEADLESS, &page->private)) {1445 if (test_bit(PAGE_HEADLESS, &page->private)) {
@@ -1264,14 +1495,13 @@ static void *z3fold_map(struct z3fold_pool *pool, unsigned long handle) · 49 unmodified lines
1264 void *addr;1495 void *addr;
1265 enum buddy buddy;1496 enum buddy buddy;
1266 1497
1267 zhdr = handle_to_z3fold_header(handle);1498 zhdr = get_z3fold_header(handle);
1268 addr = zhdr;1499 addr = zhdr;
1269 page = virt_to_page(zhdr);1500 page = virt_to_page(zhdr);
1270 1501
1271 if (test_bit(PAGE_HEADLESS, &page->private))1502 if (test_bit(PAGE_HEADLESS, &page->private))
1272 goto out;1503 goto out;
1273 1504
1274 z3fold_page_lock(zhdr);
1275 buddy = handle_to_buddy(handle);1505 buddy = handle_to_buddy(handle);
1276 switch (buddy) {1506 switch (buddy) {
1277 case FIRST:1507 case FIRST:
@@ -1293,8 +1523,8 @@ static void *z3fold_map(struct z3fold_pool *pool, unsigned long handle) · 15 unmodified lines
1293 1523
1294 if (addr)1524 if (addr)
1295 zhdr->mapped_count++;1525 zhdr->mapped_count++;
1296 z3fold_page_unlock(zhdr);
1297out:1526out:
1527 put_z3fold_header(zhdr);
1298 return addr;1528 return addr;
1299}1529}
1300 1530
@@ -1309,18 +1539,17 @@ static void z3fold_unmap(struct z3fold_pool *pool, unsigned long handle) · 8 unmodified lines
1309 struct page *page;1539 struct page *page;
1310 enum buddy buddy;1540 enum buddy buddy;
1311 1541
1312 zhdr = handle_to_z3fold_header(handle);1542 zhdr = get_z3fold_header(handle);
1313 page = virt_to_page(zhdr);1543 page = virt_to_page(zhdr);
1314 1544
1315 if (test_bit(PAGE_HEADLESS, &page->private))1545 if (test_bit(PAGE_HEADLESS, &page->private))
1316 return;1546 return;
1317 1547
1318 z3fold_page_lock(zhdr);
1319 buddy = handle_to_buddy(handle);1548 buddy = handle_to_buddy(handle);
1320 if (buddy == MIDDLE)1549 if (buddy == MIDDLE)
1321 clear_bit(MIDDLE_CHUNK_MAPPED, &page->private);1550 clear_bit(MIDDLE_CHUNK_MAPPED, &page->private);
1322 zhdr->mapped_count--;1551 zhdr->mapped_count--;
1323 z3fold_page_unlock(zhdr);1552 put_z3fold_header(zhdr);
1324}1553}
1325 1554
1326/**1555/**
@@ -1352,19 +1581,21 @@ static bool z3fold_page_isolate(struct page *page, isolate_mode_t mode) · 25 unmodified lines
1352 test_bit(PAGE_STALE, &page->private))1581 test_bit(PAGE_STALE, &page->private))
1353 goto out;1582 goto out;
1354 1583
1584 if (zhdr->mapped_count != 0 || zhdr->foreign_handles != 0)
1585 goto out;
1586
1355 pool = zhdr_to_pool(zhdr);1587 pool = zhdr_to_pool(zhdr);
1588 spin_lock(&pool->lock);
1589 if (!list_empty(&zhdr->buddy))
1590 list_del_init(&zhdr->buddy);
1591 if (!list_empty(&page->lru))
1592 list_del_init(&page->lru);
1593 spin_unlock(&pool->lock);
1594
1595 kref_get(&zhdr->refcount);
1596 z3fold_page_unlock(zhdr);
1597 return true;
1356 1598
1357 if (zhdr->mapped_count == 0) {
1358 kref_get(&zhdr->refcount);
1359 if (!list_empty(&zhdr->buddy))
1360 list_del_init(&zhdr->buddy);
1361 spin_lock(&pool->lock);
1362 if (!list_empty(&page->lru))
1363 list_del(&page->lru);
1364 spin_unlock(&pool->lock);
1365 z3fold_page_unlock(zhdr);
1366 return true;
1367 }
1368out:1599out:
1369 z3fold_page_unlock(zhdr);1600 z3fold_page_unlock(zhdr);
1370 return false;1601 return false;
@@ -1387,7 +1618,7 @@ static int z3fold_page_migrate(struct address_space *mapping, struct page *newpa · 16 unmodified lines
1387 if (!z3fold_page_trylock(zhdr)) {1618 if (!z3fold_page_trylock(zhdr)) {
1388 return -EAGAIN;1619 return -EAGAIN;
1389 }1620 }
1390 if (zhdr->mapped_count != 0) {1621 if (zhdr->mapped_count != 0 || zhdr->foreign_handles != 0) {
1391 z3fold_page_unlock(zhdr);1622 z3fold_page_unlock(zhdr);
1392 return -EBUSY;1623 return -EBUSY;
1393 }1624 }
scripts/spelling.txt+28−0
@@ -87,6 +87,7 @@ algorith||algorithm · 86 unmodified lines
87algorithmical||algorithmically87algorithmical||algorithmically
88algoritm||algorithm88algoritm||algorithm
89algoritms||algorithms89algoritms||algorithms
90algorithmn||algorithm
90algorrithm||algorithm91algorrithm||algorithm
91algorritm||algorithm92algorritm||algorithm
92aligment||alignment93aligment||alignment
@@ -109,6 +110,7 @@ alredy||already · 16 unmodified lines
109altough||although110altough||although
110alue||value111alue||value
111ambigious||ambiguous112ambigious||ambiguous
113ambigous||ambiguous
112amoung||among114amoung||among
113amout||amount115amout||amount
114amplifer||amplifier116amplifer||amplifier
@@ -179,6 +181,7 @@ attepmpt||attempt · 64 unmodified lines
179attnetion||attention181attnetion||attention
180attruibutes||attributes182attruibutes||attributes
181authentification||authentication183authentification||authentication
184authenicated||authenticated
182automaticaly||automatically185automaticaly||automatically
183automaticly||automatically186automaticly||automatically
184automatize||automate187automatize||automate
@@ -286,6 +289,7 @@ claread||cleared · 101 unmodified lines
286clared||cleared289clared||cleared
287closeing||closing290closeing||closing
288clustred||clustered291clustred||clustered
292cnfiguration||configuration
289coexistance||coexistence293coexistance||coexistence
290colescing||coalescing294colescing||coalescing
291collapsable||collapsible295collapsable||collapsible
@@ -325,9 +329,11 @@ comression||compression · 33 unmodified lines
325comunication||communication329comunication||communication
326conbination||combination330conbination||combination
327conditionaly||conditionally331conditionaly||conditionally
332conditon||condition
328conected||connected333conected||connected
329conector||connector334conector||connector
330connecetd||connected335connecetd||connected
336configration||configuration
331configuartion||configuration337configuartion||configuration
332configuation||configuration338configuation||configuration
333configued||configured339configued||configured
@@ -347,6 +353,7 @@ containts||contains · 13 unmodified lines
347contaisn||contains353contaisn||contains
348contant||contact354contant||contact
349contence||contents355contence||contents
356contiguos||contiguous
350continious||continuous357continious||continuous
351continous||continuous358continous||continuous
352continously||continuously359continously||continuously
@@ -380,6 +387,7 @@ cylic||cyclic · 27 unmodified lines
380dafault||default387dafault||default
381deafult||default388deafult||default
382deamon||daemon389deamon||daemon
390debouce||debounce
383decompres||decompress391decompres||decompress
384decsribed||described392decsribed||described
385decription||description393decription||description
@@ -448,6 +456,7 @@ diffrent||different · 62 unmodified lines
448differenciate||differentiate456differenciate||differentiate
449diffrentiate||differentiate457diffrentiate||differentiate
450difinition||definition458difinition||definition
459digial||digital
451dimention||dimension460dimention||dimension
452dimesions||dimensions461dimesions||dimensions
453dispalying||displaying462dispalying||displaying
@@ -489,6 +498,7 @@ droput||dropout · 35 unmodified lines
489druing||during498druing||during
490dynmaic||dynamic499dynmaic||dynamic
491eanable||enable500eanable||enable
501eanble||enable
492easilly||easily502easilly||easily
493ecspecially||especially503ecspecially||especially
494edditable||editable504edditable||editable
@@ -502,6 +512,7 @@ elementry||elementary · 7 unmodified lines
502eletronic||electronic512eletronic||electronic
503embeded||embedded513embeded||embedded
504enabledi||enabled514enabledi||enabled
515enbale||enable
505enble||enable516enble||enable
506enchanced||enhanced517enchanced||enhanced
507encorporating||incorporating518encorporating||incorporating
@@ -536,6 +547,7 @@ excellant||excellent · 28 unmodified lines
536execeeded||exceeded547execeeded||exceeded
537execeeds||exceeds548execeeds||exceeds
538exeed||exceed549exeed||exceed
550exeuction||execution
539existance||existence551existance||existence
540existant||existent552existant||existent
541exixt||exist553exixt||exist
@@ -601,10 +613,12 @@ frambuffer||framebuffer · 59 unmodified lines
601framming||framing613framming||framing
602framwork||framework614framwork||framework
603frequncy||frequency615frequncy||frequency
616frequancy||frequency
604frome||from617frome||from
605fucntion||function618fucntion||function
606fuction||function619fuction||function
607fuctions||functions620fuctions||functions
621fullill||fulfill
608funcation||function622funcation||function
609funcion||function623funcion||function
610functionallity||functionality624functionallity||functionality
@@ -642,6 +656,7 @@ happend||happened · 31 unmodified lines
642harware||hardware656harware||hardware
643heirarchically||hierarchically657heirarchically||hierarchically
644helpfull||helpful658helpfull||helpful
659hexdecimal||hexadecimal
645hybernate||hibernate660hybernate||hibernate
646hierachy||hierarchy661hierachy||hierarchy
647hierarchie||hierarchy662hierarchie||hierarchy
@@ -709,12 +724,14 @@ initalize||initialize · 61 unmodified lines
709initation||initiation724initation||initiation
710initators||initiators725initators||initiators
711initialiazation||initialization726initialiazation||initialization
727initializationg||initialization
712initializiation||initialization728initializiation||initialization
713initialze||initialize729initialze||initialize
714initialzed||initialized730initialzed||initialized
715initialzing||initializing731initialzing||initializing
716initilization||initialization732initilization||initialization
717initilize||initialize733initilize||initialize
734initliaze||initialize
718inofficial||unofficial735inofficial||unofficial
719inrerface||interface736inrerface||interface
720insititute||institute737insititute||institute
@@ -779,6 +796,7 @@ itertation||iteration · 58 unmodified lines
779itslef||itself796itslef||itself
780jave||java797jave||java
781jeffies||jiffies798jeffies||jiffies
799jumpimng||jumping
782juse||just800juse||just
783jus||just801jus||just
784kown||known802kown||known
@@ -839,6 +857,7 @@ messags||messages · 54 unmodified lines
839messgaes||messages857messgaes||messages
840messsage||message858messsage||message
841messsages||messages859messsages||messages
860metdata||metadata
842micropone||microphone861micropone||microphone
843microprocesspr||microprocessor862microprocesspr||microprocessor
844migrateable||migratable863migrateable||migratable
@@ -857,6 +876,7 @@ mismactch||mismatch · 12 unmodified lines
857missign||missing876missign||missing
858missmanaged||mismanaged877missmanaged||mismanaged
859missmatch||mismatch878missmatch||mismatch
879misssing||missing
860miximum||maximum880miximum||maximum
861mmnemonic||mnemonic881mmnemonic||mnemonic
862mnay||many882mnay||many
@@ -912,6 +932,7 @@ occured||occurred · 49 unmodified lines
912occuring||occurring932occuring||occurring
913offser||offset933offser||offset
914offet||offset934offet||offset
935offlaod||offload
915offloded||offloaded936offloded||offloaded
916offseting||offsetting937offseting||offsetting
917omited||omitted938omited||omitted
@@ -993,6 +1014,7 @@ poiter||pointer · 75 unmodified lines
993posible||possible1014posible||possible
994positon||position1015positon||position
995possibilites||possibilities1016possibilites||possibilities
1017potocol||protocol
996powerfull||powerful1018powerfull||powerful
997pramater||parameter1019pramater||parameter
998preamle||preamble1020preamle||preamble
@@ -1061,11 +1083,13 @@ psychadelic||psychedelic · 62 unmodified lines
1061pwoer||power1083pwoer||power
1062queing||queuing1084queing||queuing
1063quering||querying1085quering||querying
1086queus||queues
1064randomally||randomly1087randomally||randomly
1065raoming||roaming1088raoming||roaming
1066reasearcher||researcher1089reasearcher||researcher
1067reasearchers||researchers1090reasearchers||researchers
1068reasearch||research1091reasearch||research
1092receieve||receive
1069recepient||recipient1093recepient||recipient
1070recevied||received1094recevied||received
1071receving||receiving1095receving||receiving
@@ -1166,6 +1190,7 @@ scaleing||scaling · 94 unmodified lines
1166scaned||scanned1190scaned||scanned
1167scaning||scanning1191scaning||scanning
1168scarch||search1192scarch||search
1193schdule||schedule
1169seach||search1194seach||search
1170searchs||searches1195searchs||searches
1171secquence||sequence1196secquence||sequence
@@ -1308,6 +1333,7 @@ taskelt||tasklet · 136 unmodified lines
1308teh||the1333teh||the
1309temorary||temporary1334temorary||temporary
1310temproarily||temporarily1335temproarily||temporarily
1336temperture||temperature
1311thead||thread1337thead||thread
1312therfore||therefore1338therfore||therefore
1313thier||their1339thier||their
@@ -1354,6 +1380,7 @@ uknown||unknown · 40 unmodified lines
1354usupported||unsupported1380usupported||unsupported
1355uncommited||uncommitted1381uncommited||uncommitted
1356unconditionaly||unconditionally1382unconditionaly||unconditionally
1383undeflow||underflow
1357underun||underrun1384underun||underrun
1358unecessary||unnecessary1385unecessary||unnecessary
1359unexecpted||unexpected1386unexecpted||unexpected
@@ -1414,6 +1441,7 @@ varible||variable · 54 unmodified lines
1414varient||variant1441varient||variant
1415vaule||value1442vaule||value
1416verbse||verbose1443verbse||verbose
1444veify||verify
1417verisons||versions1445verisons||versions
1418verison||version1446verison||version
1419verson||version1447verson||version
tools/testing/selftests/memfd/memfd_test.c+36−0
@@ -290,6 +290,40 @@ static void mfd_assert_read_shared(int fd) · 289 unmodified lines
290 munmap(p, mfd_def_size);290 munmap(p, mfd_def_size);
291}291}
292 292
293static void mfd_assert_fork_private_write(int fd)
294{
295 int *p;
296 pid_t pid;
297
298 p = mmap(NULL,
299 mfd_def_size,
300 PROT_READ | PROT_WRITE,
301 MAP_PRIVATE,
302 fd,
303 0);
304 if (p == MAP_FAILED) {
305 printf("mmap() failed: %m\n");
306 abort();
307 }
308
309 p[0] = 22;
310
311 pid = fork();
312 if (pid == 0) {
313 p[0] = 33;
314 exit(0);
315 } else {
316 waitpid(pid, NULL, 0);
317
318 if (p[0] != 22) {
319 printf("MAP_PRIVATE copy-on-write failed: %m\n");
320 abort();
321 }
322 }
323
324 munmap(p, mfd_def_size);
325}
326
293static void mfd_assert_write(int fd)327static void mfd_assert_write(int fd)
294{328{
295 ssize_t l;329 ssize_t l;
@@ -760,6 +794,8 @@ static void test_seal_future_write(void) · 464 unmodified lines
760 mfd_assert_read_shared(fd2);794 mfd_assert_read_shared(fd2);
761 mfd_fail_write(fd2);795 mfd_fail_write(fd2);
762 796
797 mfd_assert_fork_private_write(fd);
798
763 munmap(p, mfd_def_size);799 munmap(p, mfd_def_size);
764 close(fd2);800 close(fd2);
765 close(fd);801 close(fd);
tools/testing/selftests/vm/config+1−0
@@ -1,2 +1,3 @@
1CONFIG_SYSVIPC=y1CONFIG_SYSVIPC=y
2CONFIG_USERFAULTFD=y2CONFIG_USERFAULTFD=y
3CONFIG_TEST_VMALLOC=m

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t