aboutsummaryrefslogtreecommitdiffstats
path: root/mm
diff options
context:
space:
mode:
Diffstat (limited to 'mm')
-rw-r--r--mm/gup.c7
-rw-r--r--mm/hugetlb.c2
-rw-r--r--mm/memblock.c10
-rw-r--r--mm/mlock.c6
-rw-r--r--mm/page_alloc.c13
-rw-r--r--mm/swap.c84
-rw-r--r--mm/vmalloc.c10
-rw-r--r--mm/vmscan.c59
-rw-r--r--mm/zpool.c2
-rw-r--r--mm/zswap.c6
10 files changed, 91 insertions, 108 deletions
diff --git a/mm/gup.c b/mm/gup.c
index 1b46e6e74881..6afae32571ca 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -516,7 +516,7 @@ static int faultin_page(struct task_struct *tsk, struct vm_area_struct *vma,
516 } 516 }
517 517
518 if (ret & VM_FAULT_RETRY) { 518 if (ret & VM_FAULT_RETRY) {
519 if (nonblocking) 519 if (nonblocking && !(fault_flags & FAULT_FLAG_RETRY_NOWAIT))
520 *nonblocking = 0; 520 *nonblocking = 0;
521 return -EBUSY; 521 return -EBUSY;
522 } 522 }
@@ -890,7 +890,10 @@ static __always_inline long __get_user_pages_locked(struct task_struct *tsk,
890 break; 890 break;
891 } 891 }
892 if (*locked) { 892 if (*locked) {
893 /* VM_FAULT_RETRY didn't trigger */ 893 /*
894 * VM_FAULT_RETRY didn't trigger or it was a
895 * FOLL_NOWAIT.
896 */
894 if (!pages_done) 897 if (!pages_done)
895 pages_done = ret; 898 pages_done = ret;
896 break; 899 break;
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 7c204e3d132b..a963f2034dfc 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -1583,7 +1583,7 @@ static struct page *alloc_surplus_huge_page(struct hstate *h, gfp_t gfp_mask,
1583 page = NULL; 1583 page = NULL;
1584 } else { 1584 } else {
1585 h->surplus_huge_pages++; 1585 h->surplus_huge_pages++;
1586 h->nr_huge_pages_node[page_to_nid(page)]++; 1586 h->surplus_huge_pages_node[page_to_nid(page)]++;
1587 } 1587 }
1588 1588
1589out_unlock: 1589out_unlock:
diff --git a/mm/memblock.c b/mm/memblock.c
index 5a9ca2a1751b..b6ba6b7adadc 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -1107,7 +1107,7 @@ unsigned long __init_memblock memblock_next_valid_pfn(unsigned long pfn,
1107 struct memblock_type *type = &memblock.memory; 1107 struct memblock_type *type = &memblock.memory;
1108 unsigned int right = type->cnt; 1108 unsigned int right = type->cnt;
1109 unsigned int mid, left = 0; 1109 unsigned int mid, left = 0;
1110 phys_addr_t addr = PFN_PHYS(pfn + 1); 1110 phys_addr_t addr = PFN_PHYS(++pfn);
1111 1111
1112 do { 1112 do {
1113 mid = (right + left) / 2; 1113 mid = (right + left) / 2;
@@ -1118,15 +1118,15 @@ unsigned long __init_memblock memblock_next_valid_pfn(unsigned long pfn,
1118 type->regions[mid].size)) 1118 type->regions[mid].size))
1119 left = mid + 1; 1119 left = mid + 1;
1120 else { 1120 else {
1121 /* addr is within the region, so pfn + 1 is valid */ 1121 /* addr is within the region, so pfn is valid */
1122 return min(pfn + 1, max_pfn); 1122 return pfn;
1123 } 1123 }
1124 } while (left < right); 1124 } while (left < right);
1125 1125
1126 if (right == type->cnt) 1126 if (right == type->cnt)
1127 return max_pfn; 1127 return -1UL;
1128 else 1128 else
1129 return min(PHYS_PFN(type->regions[right].base), max_pfn); 1129 return PHYS_PFN(type->regions[right].base);
1130} 1130}
1131 1131
1132/** 1132/**
diff --git a/mm/mlock.c b/mm/mlock.c
index 79398200e423..74e5a6547c3d 100644
--- a/mm/mlock.c
+++ b/mm/mlock.c
@@ -64,6 +64,12 @@ void clear_page_mlock(struct page *page)
64 mod_zone_page_state(page_zone(page), NR_MLOCK, 64 mod_zone_page_state(page_zone(page), NR_MLOCK,
65 -hpage_nr_pages(page)); 65 -hpage_nr_pages(page));
66 count_vm_event(UNEVICTABLE_PGCLEARED); 66 count_vm_event(UNEVICTABLE_PGCLEARED);
67 /*
68 * The previous TestClearPageMlocked() corresponds to the smp_mb()
69 * in __pagevec_lru_add_fn().
70 *
71 * See __pagevec_lru_add_fn for more explanation.
72 */
67 if (!isolate_lru_page(page)) { 73 if (!isolate_lru_page(page)) {
68 putback_lru_page(page); 74 putback_lru_page(page);
69 } else { 75 } else {
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 81e18ceef579..3d974cb2a1a1 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -46,6 +46,7 @@
46#include <linux/stop_machine.h> 46#include <linux/stop_machine.h>
47#include <linux/sort.h> 47#include <linux/sort.h>
48#include <linux/pfn.h> 48#include <linux/pfn.h>
49#include <xen/xen.h>
49#include <linux/backing-dev.h> 50#include <linux/backing-dev.h>
50#include <linux/fault-inject.h> 51#include <linux/fault-inject.h>
51#include <linux/page-isolation.h> 52#include <linux/page-isolation.h>
@@ -347,6 +348,9 @@ static inline bool update_defer_init(pg_data_t *pgdat,
347 /* Always populate low zones for address-constrained allocations */ 348 /* Always populate low zones for address-constrained allocations */
348 if (zone_end < pgdat_end_pfn(pgdat)) 349 if (zone_end < pgdat_end_pfn(pgdat))
349 return true; 350 return true;
351 /* Xen PV domains need page structures early */
352 if (xen_pv_domain())
353 return true;
350 (*nr_initialised)++; 354 (*nr_initialised)++;
351 if ((*nr_initialised > pgdat->static_init_pgcnt) && 355 if ((*nr_initialised > pgdat->static_init_pgcnt) &&
352 (pfn & (PAGES_PER_SECTION - 1)) == 0) { 356 (pfn & (PAGES_PER_SECTION - 1)) == 0) {
@@ -5355,9 +5359,14 @@ void __meminit memmap_init_zone(unsigned long size, int nid, unsigned long zone,
5355 /* 5359 /*
5356 * Skip to the pfn preceding the next valid one (or 5360 * Skip to the pfn preceding the next valid one (or
5357 * end_pfn), such that we hit a valid pfn (or end_pfn) 5361 * end_pfn), such that we hit a valid pfn (or end_pfn)
5358 * on our next iteration of the loop. 5362 * on our next iteration of the loop. Note that it needs
5363 * to be pageblock aligned even when the region itself
5364 * is not. move_freepages_block() can shift ahead of
5365 * the valid region but still depends on correct page
5366 * metadata.
5359 */ 5367 */
5360 pfn = memblock_next_valid_pfn(pfn, end_pfn) - 1; 5368 pfn = (memblock_next_valid_pfn(pfn, end_pfn) &
5369 ~(pageblock_nr_pages-1)) - 1;
5361#endif 5370#endif
5362 continue; 5371 continue;
5363 } 5372 }
diff --git a/mm/swap.c b/mm/swap.c
index 567a7b96e41d..0f17330dd0e5 100644
--- a/mm/swap.c
+++ b/mm/swap.c
@@ -446,30 +446,6 @@ void lru_cache_add(struct page *page)
446} 446}
447 447
448/** 448/**
449 * add_page_to_unevictable_list - add a page to the unevictable list
450 * @page: the page to be added to the unevictable list
451 *
452 * Add page directly to its zone's unevictable list. To avoid races with
453 * tasks that might be making the page evictable, through eg. munlock,
454 * munmap or exit, while it's not on the lru, we want to add the page
455 * while it's locked or otherwise "invisible" to other tasks. This is
456 * difficult to do when using the pagevec cache, so bypass that.
457 */
458void add_page_to_unevictable_list(struct page *page)
459{
460 struct pglist_data *pgdat = page_pgdat(page);
461 struct lruvec *lruvec;
462
463 spin_lock_irq(&pgdat->lru_lock);
464 lruvec = mem_cgroup_page_lruvec(page, pgdat);
465 ClearPageActive(page);
466 SetPageUnevictable(page);
467 SetPageLRU(page);
468 add_page_to_lru_list(page, lruvec, LRU_UNEVICTABLE);
469 spin_unlock_irq(&pgdat->lru_lock);
470}
471
472/**
473 * lru_cache_add_active_or_unevictable 449 * lru_cache_add_active_or_unevictable
474 * @page: the page to be added to LRU 450 * @page: the page to be added to LRU
475 * @vma: vma in which page is mapped for determining reclaimability 451 * @vma: vma in which page is mapped for determining reclaimability
@@ -484,13 +460,9 @@ void lru_cache_add_active_or_unevictable(struct page *page,
484{ 460{
485 VM_BUG_ON_PAGE(PageLRU(page), page); 461 VM_BUG_ON_PAGE(PageLRU(page), page);
486 462
487 if (likely((vma->vm_flags & (VM_LOCKED | VM_SPECIAL)) != VM_LOCKED)) { 463 if (likely((vma->vm_flags & (VM_LOCKED | VM_SPECIAL)) != VM_LOCKED))
488 SetPageActive(page); 464 SetPageActive(page);
489 lru_cache_add(page); 465 else if (!TestSetPageMlocked(page)) {
490 return;
491 }
492
493 if (!TestSetPageMlocked(page)) {
494 /* 466 /*
495 * We use the irq-unsafe __mod_zone_page_stat because this 467 * We use the irq-unsafe __mod_zone_page_stat because this
496 * counter is not modified from interrupt context, and the pte 468 * counter is not modified from interrupt context, and the pte
@@ -500,7 +472,7 @@ void lru_cache_add_active_or_unevictable(struct page *page,
500 hpage_nr_pages(page)); 472 hpage_nr_pages(page));
501 count_vm_event(UNEVICTABLE_PGMLOCKED); 473 count_vm_event(UNEVICTABLE_PGMLOCKED);
502 } 474 }
503 add_page_to_unevictable_list(page); 475 lru_cache_add(page);
504} 476}
505 477
506/* 478/*
@@ -886,15 +858,55 @@ void lru_add_page_tail(struct page *page, struct page *page_tail,
886static void __pagevec_lru_add_fn(struct page *page, struct lruvec *lruvec, 858static void __pagevec_lru_add_fn(struct page *page, struct lruvec *lruvec,
887 void *arg) 859 void *arg)
888{ 860{
889 int file = page_is_file_cache(page); 861 enum lru_list lru;
890 int active = PageActive(page); 862 int was_unevictable = TestClearPageUnevictable(page);
891 enum lru_list lru = page_lru(page);
892 863
893 VM_BUG_ON_PAGE(PageLRU(page), page); 864 VM_BUG_ON_PAGE(PageLRU(page), page);
894 865
895 SetPageLRU(page); 866 SetPageLRU(page);
867 /*
868 * Page becomes evictable in two ways:
869 * 1) Within LRU lock [munlock_vma_pages() and __munlock_pagevec()].
870 * 2) Before acquiring LRU lock to put the page to correct LRU and then
871 * a) do PageLRU check with lock [check_move_unevictable_pages]
872 * b) do PageLRU check before lock [clear_page_mlock]
873 *
874 * (1) & (2a) are ok as LRU lock will serialize them. For (2b), we need
875 * following strict ordering:
876 *
877 * #0: __pagevec_lru_add_fn #1: clear_page_mlock
878 *
879 * SetPageLRU() TestClearPageMlocked()
880 * smp_mb() // explicit ordering // above provides strict
881 * // ordering
882 * PageMlocked() PageLRU()
883 *
884 *
885 * if '#1' does not observe setting of PG_lru by '#0' and fails
886 * isolation, the explicit barrier will make sure that page_evictable
887 * check will put the page in correct LRU. Without smp_mb(), SetPageLRU
888 * can be reordered after PageMlocked check and can make '#1' to fail
889 * the isolation of the page whose Mlocked bit is cleared (#0 is also
890 * looking at the same page) and the evictable page will be stranded
891 * in an unevictable LRU.
892 */
893 smp_mb();
894
895 if (page_evictable(page)) {
896 lru = page_lru(page);
897 update_page_reclaim_stat(lruvec, page_is_file_cache(page),
898 PageActive(page));
899 if (was_unevictable)
900 count_vm_event(UNEVICTABLE_PGRESCUED);
901 } else {
902 lru = LRU_UNEVICTABLE;
903 ClearPageActive(page);
904 SetPageUnevictable(page);
905 if (!was_unevictable)
906 count_vm_event(UNEVICTABLE_PGCULLED);
907 }
908
896 add_page_to_lru_list(page, lruvec, lru); 909 add_page_to_lru_list(page, lruvec, lru);
897 update_page_reclaim_stat(lruvec, file, active);
898 trace_mm_lru_insertion(page, lru); 910 trace_mm_lru_insertion(page, lru);
899} 911}
900 912
@@ -913,7 +925,7 @@ EXPORT_SYMBOL(__pagevec_lru_add);
913 * @pvec: Where the resulting entries are placed 925 * @pvec: Where the resulting entries are placed
914 * @mapping: The address_space to search 926 * @mapping: The address_space to search
915 * @start: The starting entry index 927 * @start: The starting entry index
916 * @nr_pages: The maximum number of pages 928 * @nr_entries: The maximum number of pages
917 * @indices: The cache indices corresponding to the entries in @pvec 929 * @indices: The cache indices corresponding to the entries in @pvec
918 * 930 *
919 * pagevec_lookup_entries() will search for and return a group of up 931 * pagevec_lookup_entries() will search for and return a group of up
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 673942094328..ebff729cc956 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -1943,11 +1943,15 @@ void *vmalloc_exec(unsigned long size)
1943} 1943}
1944 1944
1945#if defined(CONFIG_64BIT) && defined(CONFIG_ZONE_DMA32) 1945#if defined(CONFIG_64BIT) && defined(CONFIG_ZONE_DMA32)
1946#define GFP_VMALLOC32 GFP_DMA32 | GFP_KERNEL 1946#define GFP_VMALLOC32 (GFP_DMA32 | GFP_KERNEL)
1947#elif defined(CONFIG_64BIT) && defined(CONFIG_ZONE_DMA) 1947#elif defined(CONFIG_64BIT) && defined(CONFIG_ZONE_DMA)
1948#define GFP_VMALLOC32 GFP_DMA | GFP_KERNEL 1948#define GFP_VMALLOC32 (GFP_DMA | GFP_KERNEL)
1949#else 1949#else
1950#define GFP_VMALLOC32 GFP_KERNEL 1950/*
1951 * 64b systems should always have either DMA or DMA32 zones. For others
1952 * GFP_DMA32 should do the right thing and use the normal zone.
1953 */
1954#define GFP_VMALLOC32 GFP_DMA32 | GFP_KERNEL
1951#endif 1955#endif
1952 1956
1953/** 1957/**
diff --git a/mm/vmscan.c b/mm/vmscan.c
index 444749669187..bee53495a829 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -769,64 +769,7 @@ int remove_mapping(struct address_space *mapping, struct page *page)
769 */ 769 */
770void putback_lru_page(struct page *page) 770void putback_lru_page(struct page *page)
771{ 771{
772 bool is_unevictable; 772 lru_cache_add(page);
773 int was_unevictable = PageUnevictable(page);
774
775 VM_BUG_ON_PAGE(PageLRU(page), page);
776
777redo:
778 ClearPageUnevictable(page);
779
780 if (page_evictable(page)) {
781 /*
782 * For evictable pages, we can use the cache.
783 * In event of a race, worst case is we end up with an
784 * unevictable page on [in]active list.
785 * We know how to handle that.
786 */
787 is_unevictable = false;
788 lru_cache_add(page);
789 } else {
790 /*
791 * Put unevictable pages directly on zone's unevictable
792 * list.
793 */
794 is_unevictable = true;
795 add_page_to_unevictable_list(page);
796 /*
797 * When racing with an mlock or AS_UNEVICTABLE clearing
798 * (page is unlocked) make sure that if the other thread
799 * does not observe our setting of PG_lru and fails
800 * isolation/check_move_unevictable_pages,
801 * we see PG_mlocked/AS_UNEVICTABLE cleared below and move
802 * the page back to the evictable list.
803 *
804 * The other side is TestClearPageMlocked() or shmem_lock().
805 */
806 smp_mb();
807 }
808
809 /*
810 * page's status can change while we move it among lru. If an evictable
811 * page is on unevictable list, it never be freed. To avoid that,
812 * check after we added it to the list, again.
813 */
814 if (is_unevictable && page_evictable(page)) {
815 if (!isolate_lru_page(page)) {
816 put_page(page);
817 goto redo;
818 }
819 /* This means someone else dropped this page from LRU
820 * So, it will be freed or putback to LRU again. There is
821 * nothing to do here.
822 */
823 }
824
825 if (was_unevictable && !is_unevictable)
826 count_vm_event(UNEVICTABLE_PGRESCUED);
827 else if (!was_unevictable && is_unevictable)
828 count_vm_event(UNEVICTABLE_PGCULLED);
829
830 put_page(page); /* drop ref from isolate */ 773 put_page(page); /* drop ref from isolate */
831} 774}
832 775
diff --git a/mm/zpool.c b/mm/zpool.c
index f8cb83e7699b..01a771e304fa 100644
--- a/mm/zpool.c
+++ b/mm/zpool.c
@@ -360,7 +360,7 @@ u64 zpool_get_total_size(struct zpool *zpool)
360 360
361/** 361/**
362 * zpool_evictable() - Test if zpool is potentially evictable 362 * zpool_evictable() - Test if zpool is potentially evictable
363 * @pool The zpool to test 363 * @zpool: The zpool to test
364 * 364 *
365 * Zpool is only potentially evictable when it's created with struct 365 * Zpool is only potentially evictable when it's created with struct
366 * zpool_ops.evict and its driver implements struct zpool_driver.shrink. 366 * zpool_ops.evict and its driver implements struct zpool_driver.shrink.
diff --git a/mm/zswap.c b/mm/zswap.c
index c004aa4fd3f4..61a5c41972db 100644
--- a/mm/zswap.c
+++ b/mm/zswap.c
@@ -1007,6 +1007,12 @@ static int zswap_frontswap_store(unsigned type, pgoff_t offset,
1007 u8 *src, *dst; 1007 u8 *src, *dst;
1008 struct zswap_header zhdr = { .swpentry = swp_entry(type, offset) }; 1008 struct zswap_header zhdr = { .swpentry = swp_entry(type, offset) };
1009 1009
1010 /* THP isn't supported */
1011 if (PageTransHuge(page)) {
1012 ret = -EINVAL;
1013 goto reject;
1014 }
1015
1010 if (!zswap_enabled || !tree) { 1016 if (!zswap_enabled || !tree) {
1011 ret = -ENODEV; 1017 ret = -ENODEV;
1012 goto reject; 1018 goto reject;