Skip to contentSkip to conversation

mm/thp: allow dropping THP from page cache

PATCH In review [email protected] 1 participant 1 message Oct 19, 2019

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

PATCH 24/26 mm/thp: allow dropping THP from page cache

From: "Kirill A. Shutemov" <[email protected]>
Subject: mm/thp: allow dropping THP from page cache

Once a THP is added to the page cache, it cannot be dropped via /proc/sys/vm/drop_caches. Fix this issue with proper handling in invalidate_mapping_pages().

Fixes 99cb0dbd47a1 ("mm,thp: add read-only THP support for (non-shmem) FS")
Cc Matthew Wilcox (Oracle) <[email protected]>
Cc Oleg Nesterov <[email protected]>
Cc Srikar Dronamraju <[email protected]>
Cc William Kucharski <[email protected]>

---

 mm/truncate.c |   12 ++++++++++++
 1 file changed, 12 insertions(+)
mm/truncate.c renamed from mm/truncate.c~mm-thp-allow-drop-thp-from-page-cache +12 -0
@@ -592,6 +592,16 @@ unsigned long invalidate_mapping_pages(s
 					unlock_page(page);
 					continue;
 				}
+
+				/* Take a pin outside pagevec */
+				get_page(page);
+
+				/*
+				 * Drop extra pins before trying to invalidate
+				 * the huge page.
+				 */
+				pagevec_remove_exceptionals(&pvec);
+				pagevec_release(&pvec);
 			}
 
 			ret = invalidate_inode_page(page);
@@ -602,6 +612,8 @@ unsigned long invalidate_mapping_pages(s
 			 */
 			if (!ret)
 				deactivate_file_page(page);
+			if (PageTransHuge(page))
+				put_page(page);
 			count += ret;
 		}
 		pagevec_remove_exceptionals(&pvec);

_