Re: [PATCH v2] mm: make folio_pte_batch available outside of mm/memory.c

From: Barry Song
Date: Tue Feb 27 2024 - 19:10:24 EST


On Wed, Feb 28, 2024 at 10:54 AM SeongJae Park <sj@xxxxxxxxxx> wrote:
>
> On Tue, 27 Feb 2024 23:42:01 +1300 Barry Song <21cnbao@xxxxxxxxx> wrote:
>
> > From: Barry Song <v-songbaohua@xxxxxxxx>
> >
> > madvise, mprotect and some others might need folio_pte_batch to check if
> > a range of PTEs are completely mapped to a large folio with contiguous
> > physical addresses. Let's make it available in mm/internal.h.
>
> Hi Barry,
>
>
> I found this patch makes some of my build test that not setting CONFIG_MMU
> fails with multiple errors including below:
>
> In file included from .../mm/nommu.c:43:
> .../mm/internal.h: In function '__pte_batch_clear_ignored':
> .../mm/internal.h:98:23: error: implicit declaration of function 'pte_mkclean'; did you mean 'page_mkclean'? [-Werror=implicit-function-declaration]
> 98 | pte = pte_mkclean(pte);
> | ^~~~~~~~~~~
> | page_mkclean
>
> Enabling CONFIG_MMU made the build success. I haven't had a time to look into
> the code yet. May I ask your opinion?

i guess it is because we have moved some func from memory.c to
headfile. and this headfile is included by lots of
files in mm. memory.c, for itself, will only be compiled with enabled
CONFIG_MMU:
mmu-$(CONFIG_MMU) := highmem.o memory.o mincore.o \
mlock.o mmap.o mmu_gather.o mprotect.o mremap.o \
msync.o page_vma_mapped.o pagewalk.o \
pgtable-generic.o rmap.o vmalloc.o

Does the below fix your build?

diff --git a/mm/internal.h b/mm/internal.h
index fa9e2f7db506..4e57680b74e1 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -83,6 +83,8 @@ static inline void *folio_raw_mapping(struct folio *folio)
return (void *)(mapping & ~PAGE_MAPPING_FLAGS);
}

+#ifdef CONFIG_MMU
+
/* Flags for folio_pte_batch(). */
typedef int __bitwise fpb_t;

@@ -172,6 +174,7 @@ static inline int folio_pte_batch(struct folio
*folio, unsigned long addr,

return min(ptep - start_ptep, max_nr);
}
+#endif /* CONFIG_MMU */

void __acct_reclaim_writeback(pg_data_t *pgdat, struct folio *folio,
int nr_throttled);


> Thanks,
> SJ

Thanks
Barry