mm/hugetlb: add hugetlb_folio_subpool() helpers
authorSidhartha Kumar <sidhartha.kumar@oracle.com>
Thu, 22 Sep 2022 15:42:05 +0000 (10:42 -0500)
committerAndrew Morton <akpm@linux-foundation.org>
Wed, 9 Nov 2022 01:37:12 +0000 (17:37 -0800)
Allow hugetlbfs_migrate_folio to check and read subpool information by
passing in a folio.

Link: https://lkml.kernel.org/r/20220922154207.1575343-4-sidhartha.kumar@oracle.com
Signed-off-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
Reviewed-by: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Colin Cross <ccross@google.com>
Cc: David Howells <dhowells@redhat.com>
Cc: "Eric W . Biederman" <ebiederm@xmission.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: kernel test robot <lkp@intel.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Muchun Song <songmuchun@bytedance.com>
Cc: Peter Xu <peterx@redhat.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: William Kucharski <william.kucharski@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
fs/hugetlbfs/inode.c
include/linux/hugetlb.h

index dd54f67e47fdf145ab602571f821daee713eaf9c..c5137607e523c9ac74ee70d14ee07471e4b682bc 100644 (file)
@@ -1091,10 +1091,10 @@ static int hugetlbfs_migrate_folio(struct address_space *mapping,
        if (rc != MIGRATEPAGE_SUCCESS)
                return rc;
 
-       if (hugetlb_page_subpool(&src->page)) {
-               hugetlb_set_page_subpool(&dst->page,
-                                       hugetlb_page_subpool(&src->page));
-               hugetlb_set_page_subpool(&src->page, NULL);
+       if (hugetlb_folio_subpool(src)) {
+               hugetlb_set_folio_subpool(dst,
+                                       hugetlb_folio_subpool(src));
+               hugetlb_set_folio_subpool(src, NULL);
        }
 
        if (mode != MIGRATE_SYNC_NO_COPY)
index 3ff5d2dd3ca3d2989213288e43fa3f91991c27da..496d02bdb997e335a29fbdb23670b70a6139fdfc 100644 (file)
@@ -718,18 +718,29 @@ extern unsigned int default_hstate_idx;
 
 #define default_hstate (hstates[default_hstate_idx])
 
+static inline struct hugepage_subpool *hugetlb_folio_subpool(struct folio *folio)
+{
+       return (void *)folio_get_private_1(folio);
+}
+
 /*
  * hugetlb page subpool pointer located in hpage[1].private
  */
 static inline struct hugepage_subpool *hugetlb_page_subpool(struct page *hpage)
 {
-       return (void *)page_private(hpage + SUBPAGE_INDEX_SUBPOOL);
+       return hugetlb_folio_subpool(page_folio(hpage));
+}
+
+static inline void hugetlb_set_folio_subpool(struct folio *folio,
+                                       struct hugepage_subpool *subpool)
+{
+       folio_set_private_1(folio, (unsigned long)subpool);
 }
 
 static inline void hugetlb_set_page_subpool(struct page *hpage,
                                        struct hugepage_subpool *subpool)
 {
-       set_page_private(hpage + SUBPAGE_INDEX_SUBPOOL, (unsigned long)subpool);
+       hugetlb_set_folio_subpool(page_folio(hpage), subpool);
 }
 
 static inline struct hstate *hstate_file(struct file *f)