Re: + mm-shmem-support-large-folio-allocation-for-shmem_replace_folio-fix.patch added to mm-unstable branch

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On 2024/8/28 17:28, SeongJae Park wrote:
Hello,

On Tue, 27 Aug 2024 19:13:21 -0700 Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> wrote:


The patch titled
      Subject: mm: shmem: fix the gfp flag for large folio allocation
has been added to the -mm mm-unstable branch.  Its filename is
      mm-shmem-support-large-folio-allocation-for-shmem_replace_folio-fix.patch

This patch will shortly appear at
      https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-shmem-support-large-folio-allocation-for-shmem_replace_folio-fix.patch

This patch will later appear in the mm-unstable branch at
     git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

Before you just go and hit "reply", please:
    a) Consider who else should be cc'ed
    b) Prefer to cc a suitable mailing list as well
    c) Ideally: find the original patch on the mailing list and do a
       reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***

The -mm tree is included into linux-next via the mm-everything
branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there every 2-3 working days

------------------------------------------------------
From: Baolin Wang <baolin.wang@xxxxxxxxxxxxxxxxx>
Subject: mm: shmem: fix the gfp flag for large folio allocation
Date: Tue, 27 Aug 2024 11:06:34 +0800

In shmem_replace_folio(), it may be necessary to allocate a large folio,
so we should update the gfp flags to ensure it is suitable for allocating
the large folio.

Link: https://lkml.kernel.org/r/5b1e9c5a-7f61-4d97-a8d7-41767ca04c77@xxxxxxxxxxxxxxxxx
Signed-off-by: Baolin Wang <baolin.wang@xxxxxxxxxxxxxxxxx>
Cc: Barry Song <baohua@xxxxxxxxxx>
Cc: Chris Li <chrisl@xxxxxxxxxx>
Cc: Daniel Gomez <da.gomez@xxxxxxxxxxx>
Cc: David Hildenbrand <david@xxxxxxxxxx>
Cc: "Huang, Ying" <ying.huang@xxxxxxxxx>
Cc: Hugh Dickins <hughd@xxxxxxxxxx>
Cc: Kefeng Wang <wangkefeng.wang@xxxxxxxxxx>
Cc: Lance Yang <ioworker0@xxxxxxxxx>
Cc: Matthew Wilcox <willy@xxxxxxxxxxxxx>
Cc: Pankaj Raghav <p.raghav@xxxxxxxxxxx>
Cc: Ryan Roberts <ryan.roberts@xxxxxxx>
Cc: Yang Shi <shy828301@xxxxxxxxx>
Cc: Zi Yan <ziy@xxxxxxxxxx>
Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
---

  mm/shmem.c |   18 +++++++++++++-----
  1 file changed, 13 insertions(+), 5 deletions(-)

--- a/mm/shmem.c~mm-shmem-support-large-folio-allocation-for-shmem_replace_folio-fix
+++ a/mm/shmem.c
@@ -155,7 +155,7 @@ static unsigned long shmem_default_max_i
static int shmem_swapin_folio(struct inode *inode, pgoff_t index,
  			struct folio **foliop, enum sgp_type sgp, gfp_t gfp,
-			struct mm_struct *fault_mm, vm_fault_t *fault_type);
+			struct vm_area_struct *vma, vm_fault_t *fault_type);
static inline struct shmem_sb_info *SHMEM_SB(struct super_block *sb)
  {
@@ -1883,7 +1883,8 @@ static bool shmem_should_replace_folio(s
  }
static int shmem_replace_folio(struct folio **foliop, gfp_t gfp,
-				struct shmem_inode_info *info, pgoff_t index)
+				struct shmem_inode_info *info, pgoff_t index,
+				struct vm_area_struct *vma)
  {
  	struct folio *new, *old = *foliop;
  	swp_entry_t entry = old->swap;
@@ -1898,6 +1899,12 @@ static int shmem_replace_folio(struct fo
  	 * limit chance of success by further cpuset and node constraints.
  	 */
  	gfp &= ~GFP_CONSTRAINT_MASK;
+	if (nr_pages > 1) {
+		gfp_t huge_gfp = vma_thp_gfp_mask(vma);
+
+		gfp = limit_gfp_mask(huge_gfp, gfp);
+	}
+

I just found the above change makes kernel build without
CONFIG_TRANSPARENT_HUGEPAGE fails like below.

     ERROR:root:/usr/bin/ld: mm/shmem.o: in function `shmem_swapin_folio':
     shmem.c:(.text+0x12d9): undefined reference to `vma_thp_gfp_mask'
     collect2: error: ld returned 1 exit status

Specifically, I reproduce the problem with kunit[1].

Maybe the above if statement need to take care of the case, e.g., wrap with
#ifdef CONFIG_TRANSPARENT_HUGEPAGE?

[1] https://github.com/damonitor/damon-tests/blob/master/corr/tests/kunit.sh

Thanks for reporting. Yes, the vma_thp_gfp_mask() should be wrapped with the CONFIG_TRANSPARENT_HUGEPAGE macro.

Andrew, please help to squash the following fix. Sorry for troubles.

diff --git a/mm/shmem.c b/mm/shmem.c
index 2b0209d6ac9c..553b99cb265e 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -1910,11 +1910,13 @@ static int shmem_replace_folio(struct folio **foliop, gfp_t gfp,
         * limit chance of success by further cpuset and node constraints.
         */
        gfp &= ~GFP_CONSTRAINT_MASK;
+#ifdef CONFIG_TRANSPARENT_HUGEPAGE
        if (nr_pages > 1) {
                gfp_t huge_gfp = vma_thp_gfp_mask(vma);

                gfp = limit_gfp_mask(huge_gfp, gfp);
        }
+#endif

        new = shmem_alloc_folio(gfp, folio_order(old), info, index);
        if (!new)




[Index of Archives]     [Kernel Archive]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]

  Powered by Linux