@@ -1449,7 +1449,7 @@ static __always_inline void update_lru_sizes(struct lruvec *lruvec,
1449
1449
*
1450
1450
* Appropriate locks must be held before calling this function.
1451
1451
*
1452
- * @nr_to_scan: The number of pages to look through on the list.
1452
+ * @nr_to_scan: The number of eligible pages to look through on the list.
1453
1453
* @lruvec: The LRU vector to pull pages from.
1454
1454
* @dst: The temp list to put pages on to.
1455
1455
* @nr_scanned: The number of pages that were scanned.
@@ -1469,11 +1469,13 @@ static unsigned long isolate_lru_pages(unsigned long nr_to_scan,
1469
1469
unsigned long nr_zone_taken [MAX_NR_ZONES ] = { 0 };
1470
1470
unsigned long nr_skipped [MAX_NR_ZONES ] = { 0 , };
1471
1471
unsigned long skipped = 0 ;
1472
- unsigned long scan , nr_pages ;
1472
+ unsigned long scan , total_scan , nr_pages ;
1473
1473
LIST_HEAD (pages_skipped );
1474
1474
1475
- for (scan = 0 ; scan < nr_to_scan && nr_taken < nr_to_scan &&
1476
- !list_empty (src ); scan ++ ) {
1475
+ scan = 0 ;
1476
+ for (total_scan = 0 ;
1477
+ scan < nr_to_scan && nr_taken < nr_to_scan && !list_empty (src );
1478
+ total_scan ++ ) {
1477
1479
struct page * page ;
1478
1480
1479
1481
page = lru_to_page (src );
@@ -1487,6 +1489,13 @@ static unsigned long isolate_lru_pages(unsigned long nr_to_scan,
1487
1489
continue ;
1488
1490
}
1489
1491
1492
+ /*
1493
+ * Do not count skipped pages because that makes the function
1494
+ * return with no isolated pages if the LRU mostly contains
1495
+ * ineligible pages. This causes the VM to not reclaim any
1496
+ * pages, triggering a premature OOM.
1497
+ */
1498
+ scan ++ ;
1490
1499
switch (__isolate_lru_page (page , mode )) {
1491
1500
case 0 :
1492
1501
nr_pages = hpage_nr_pages (page );
@@ -1524,9 +1533,9 @@ static unsigned long isolate_lru_pages(unsigned long nr_to_scan,
1524
1533
skipped += nr_skipped [zid ];
1525
1534
}
1526
1535
}
1527
- * nr_scanned = scan ;
1536
+ * nr_scanned = total_scan ;
1528
1537
trace_mm_vmscan_lru_isolate (sc -> reclaim_idx , sc -> order , nr_to_scan ,
1529
- scan , skipped , nr_taken , mode , lru );
1538
+ total_scan , skipped , nr_taken , mode , lru );
1530
1539
update_lru_sizes (lruvec , lru , nr_zone_taken );
1531
1540
return nr_taken ;
1532
1541
}
0 commit comments