Skip to contentSkip to conversation

mm/hugetlb: convert get_hwpoison_huge_page() to folios

PATCH Applied Sidhartha Kumar 3 participants 4 messages Jan 18, 2023 – Jan 19, 2023

Subsystems (3)

v2 of 3 Applied 1/1 Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 mm/hugetlb: convert get_hwpoison_huge_page() to folios

Straightforward conversion of get_hwpoison_huge_page() to get_hwpoison_hugetlb_folio(). Reduces two references to a head page in memory-failure.c

---
v1 -> v2
Change &folio->page == compound_head(page) to folio == page_folio(page) in __get_hwpoison_page() per Matthew

add a-b

 include/linux/hugetlb.h |  2 +-
 mm/hugetlb.c            | 10 +++++-----
 mm/memory-failure.c     | 22 +++++++++++-----------
 3 files changed, 17 insertions(+), 17 deletions(-)
include/linux/hugetlb.h +1 -1
index febc36f6c595..c6854fc50690 100644
@@ -171,7 +171,7 @@ bool hugetlb_reserve_pages(struct inode *inode, long from, long to,
 long hugetlb_unreserve_pages(struct inode *inode, long start, long end,
 						long freed);
 int isolate_hugetlb(struct folio *folio, struct list_head *list);
-int get_hwpoison_huge_page(struct page *page, bool *hugetlb, bool unpoison);
+int get_hwpoison_hugetlb_folio(struct folio *folio, bool *hugetlb, bool unpoison);
 int get_huge_page_for_hwpoison(unsigned long pfn, int flags,
 				bool *migratable_cleared);
 void putback_active_hugepage(struct page *page);
mm/hugetlb.c +5 -5
index 856d2fdffbb9..c37a26c8392c 100644
@@ -7272,18 +7272,18 @@ int isolate_hugetlb(struct folio *folio, struct list_head *list)
 	return ret;
 }
 
-int get_hwpoison_huge_page(struct page *page, bool *hugetlb, bool unpoison)
+int get_hwpoison_hugetlb_folio(struct folio *folio, bool *hugetlb, bool unpoison)
 {
 	int ret = 0;
 
 	*hugetlb = false;
 	spin_lock_irq(&hugetlb_lock);
-	if (PageHeadHuge(page)) {
+	if (folio_test_hugetlb(folio)) {
 		*hugetlb = true;
-		if (HPageFreed(page))
+		if (folio_test_hugetlb_freed(folio))
 			ret = 0;
-		else if (HPageMigratable(page) || unpoison)
-			ret = get_page_unless_zero(page);
+		else if (folio_test_hugetlb_migratable(folio) || unpoison)
+			ret = folio_try_get(folio);
 		else
 			ret = -EBUSY;
 	}
mm/memory-failure.c +11 -11
index 0b0a36afd79d..eb8c3cf2ca36 100644
@@ -1328,28 +1328,28 @@ static inline bool HWPoisonHandlable(struct page *page, unsigned long flags)
 
 static int __get_hwpoison_page(struct page *page, unsigned long flags)
 {
-	struct page *head = compound_head(page);
+	struct folio *folio = page_folio(page);
 	int ret = 0;
 	bool hugetlb = false;
 
-	ret = get_hwpoison_huge_page(head, &hugetlb, false);
+	ret = get_hwpoison_hugetlb_folio(folio, &hugetlb, false);
 	if (hugetlb)
 		return ret;
 
 	/*
-	 * This check prevents from calling get_page_unless_zero() for any
-	 * unsupported type of page in order to reduce the risk of unexpected
-	 * races caused by taking a page refcount.
+	 * This check prevents from calling folio_try_get() for any
+	 * unsupported type of folio in order to reduce the risk of unexpected
+	 * races caused by taking a folio refcount.
 	 */
-	if (!HWPoisonHandlable(head, flags))
+	if (!HWPoisonHandlable(&folio->page, flags))
 		return -EBUSY;
 
-	if (get_page_unless_zero(head)) {
-		if (head == compound_head(page))
+	if (folio_try_get(folio)) {
+		if (folio == page_folio(page))
 			return 1;
 
 		pr_info("%#lx cannot catch tail\n", page_to_pfn(page));
-		put_page(head);
+		folio_put(folio);
 	}
 
 	return 0;
@@ -1418,11 +1418,11 @@ static int get_any_page(struct page *p, unsigned long flags)
 
 static int __get_unpoison_page(struct page *page)
 {
-	struct page *head = compound_head(page);
+	struct folio *folio = page_folio(page);
 	int ret = 0;
 	bool hugetlb = false;
 
-	ret = get_hwpoison_huge_page(head, &hugetlb, true);
+	ret = get_hwpoison_hugetlb_folio(folio, &hugetlb, true);
 	if (hugetlb)
 		return ret;
 
Signature · 1 line
2.39.0
#2 lore raw
In reply to Sidhartha Kumar
Thank you for the patch! Yet something to improve:

Hi Sidhartha,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on akpm-mm/mm-everything]

url:    https://github.com/intel-lab-lkp/linux/commits/Sidhartha-Kumar/mm-hugetlb-convert-get_hwpoison_huge_page-to-folios/20230119-014337
base:   https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link:    https://lore.kernel.org/r/20230118174039.14247-1-sidhartha.kumar%40oracle.com
patch subject: [PATCH v2] mm/hugetlb: convert get_hwpoison_huge_page() to folios
config: arm64-buildonly-randconfig-r006-20230118 (https://download.01.org/0day-ci/archive/20230119/[email protected]/config)
compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project 4196ca3278f78c6e19246e54ab0ecb364e37d66a)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install arm64 cross compiling tool for clang build
# apt-get install binutils-aarch64-linux-gnu
# https://github.com/intel-lab-lkp/linux/commit/6704f4eff6775ce3ccc4156b41b9d1c4d091eb14
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Sidhartha-Kumar/mm-hugetlb-convert-get_hwpoison_huge_page-to-folios/20230119-014337 git checkout 6704f4eff6775ce3ccc4156b41b9d1c4d091eb14
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=arm64 olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=arm64 SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable | Reported-by: kernel test robot <[email protected]>

All errors (new ones prefixed by >>):

>> mm/memory-failure.c:1335:8: error: call to undeclared function 'get_hwpoison_hugetlb_folio'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
           ret = get_hwpoison_hugetlb_folio(folio, &hugetlb, false);
                 ^
   mm/memory-failure.c:1335:8: note: did you mean 'get_hwpoison_huge_page'?
   include/linux/hugetlb.h:420:19: note: 'get_hwpoison_huge_page' declared here
   static inline int get_hwpoison_huge_page(struct page *page, bool *hugetlb, bool unpoison)
                     ^
   mm/memory-failure.c:1425:8: error: call to undeclared function 'get_hwpoison_hugetlb_folio'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
           ret = get_hwpoison_hugetlb_folio(folio, &hugetlb, true);
                 ^

2 errors generated.

vim +/get_hwpoison_hugetlb_folio +1335 mm/memory-failure.c

1328
1329 static int __get_hwpoison_page(struct page *page, unsigned long flags)
1330 {
1331 struct folio *folio = page_folio(page);
1332 int ret = 0;
1333 bool hugetlb = false;
1334

> 1335		ret = get_hwpoison_hugetlb_folio(folio, &hugetlb, false);

1336 if (hugetlb)
1337 return ret;
1338
1339 /*
1340 * This check prevents from calling folio_try_get() for any
1341 * unsupported type of folio in order to reduce the risk of unexpected
1342 * races caused by taking a folio refcount.
1343 */
1344 if (!HWPoisonHandlable(&folio->page, flags))
1345 return -EBUSY;
1346
1347 if (folio_try_get(folio)) {
1348 if (folio == page_folio(page))
1349 return 1;
1350
1351 pr_info("%#lx cannot catch tail\n", page_to_pfn(page));
1352 folio_put(folio);
1353 }
1354
1355 return 0;
1356 }
1357

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests
#3 lore raw
In reply to Sidhartha Kumar
Thank you for the patch! Yet something to improve:

Hi Sidhartha,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on akpm-mm/mm-everything]

url:    https://github.com/intel-lab-lkp/linux/commits/Sidhartha-Kumar/mm-hugetlb-convert-get_hwpoison_huge_page-to-folios/20230119-014337
base:   https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link:    https://lore.kernel.org/r/20230118174039.14247-1-sidhartha.kumar%40oracle.com
patch subject: [PATCH v2] mm/hugetlb: convert get_hwpoison_huge_page() to folios
config: x86_64-randconfig-a012 (https://download.01.org/0day-ci/archive/20230119/[email protected]/config)
compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/6704f4eff6775ce3ccc4156b41b9d1c4d091eb14
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Sidhartha-Kumar/mm-hugetlb-convert-get_hwpoison_huge_page-to-folios/20230119-014337 git checkout 6704f4eff6775ce3ccc4156b41b9d1c4d091eb14
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable | Reported-by: kernel test robot <[email protected]>

All errors (new ones prefixed by >>):

>> mm/memory-failure.c:1335:8: error: implicit declaration of function 'get_hwpoison_hugetlb_folio' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
           ret = get_hwpoison_hugetlb_folio(folio, &hugetlb, false);
                 ^
   mm/memory-failure.c:1335:8: note: did you mean 'get_hwpoison_huge_page'?
   include/linux/hugetlb.h:420:19: note: 'get_hwpoison_huge_page' declared here
   static inline int get_hwpoison_huge_page(struct page *page, bool *hugetlb, bool unpoison)
                     ^
   mm/memory-failure.c:1425:8: error: implicit declaration of function 'get_hwpoison_hugetlb_folio' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
           ret = get_hwpoison_hugetlb_folio(folio, &hugetlb, true);
                 ^

2 errors generated.

vim +/get_hwpoison_hugetlb_folio +1335 mm/memory-failure.c

1328
1329 static int __get_hwpoison_page(struct page *page, unsigned long flags)
1330 {
1331 struct folio *folio = page_folio(page);
1332 int ret = 0;
1333 bool hugetlb = false;
1334

> 1335		ret = get_hwpoison_hugetlb_folio(folio, &hugetlb, false);

1336 if (hugetlb)
1337 return ret;
1338
1339 /*
1340 * This check prevents from calling folio_try_get() for any
1341 * unsupported type of folio in order to reduce the risk of unexpected
1342 * races caused by taking a folio refcount.
1343 */
1344 if (!HWPoisonHandlable(&folio->page, flags))
1345 return -EBUSY;
1346
1347 if (folio_try_get(folio)) {
1348 if (folio == page_folio(page))
1349 return 1;
1350
1351 pr_info("%#lx cannot catch tail\n", page_to_pfn(page));
1352 folio_put(folio);
1353 }
1354
1355 return 0;
1356 }
1357

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests