/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _LINUX_RMAP_H
#define _LINUX_RMAP_H


#include <linux/list.h>
#include <linux/slab.h>
#include <linux/mm.h>
#include <linux/rwsem.h>
#include <linux/memcontrol.h>
#include <linux/highmem.h>
#include <linux/pagemap.h>
#include <linux/memremap.h>
#include <linux/bit_spinlock.h>


struct anon_vma {
	struct anon_vma *root;		
	struct rw_semaphore rwsem;	
	
	atomic_t refcount;

	
	unsigned long num_children;
	
	unsigned long num_active_vmas;

	struct anon_vma *parent;	

	

	
	struct rb_root_cached rb_root;
};


struct anon_vma_chain {
	struct vm_area_struct *vma;
	struct anon_vma *anon_vma;
	struct list_head same_vma;   
	struct rb_node rb;			
	unsigned long rb_subtree_last;
#ifdef CONFIG_DEBUG_VM_RB
	unsigned long cached_vma_start, cached_vma_last;
#endif
};

enum ttu_flags {
	TTU_USE_SHARED_ZEROPAGE	= 0x2,	
	TTU_SPLIT_HUGE_PMD	= 0x4,	
	TTU_IGNORE_MLOCK	= 0x8,	
	TTU_SYNC		= 0x10,	
	TTU_HWPOISON		= 0x20,	
	TTU_BATCH_FLUSH		= 0x40,	
	TTU_RMAP_LOCKED		= 0x80,	
};

#ifdef CONFIG_MMU

void anon_vma_init(void);	

#ifdef CONFIG_MM_ID
static __always_inline void folio_lock_large_mapcount(struct folio *folio)
{
	bit_spin_lock(FOLIO_MM_IDS_LOCK_BITNUM, &folio->_mm_ids);
}

static __always_inline void folio_unlock_large_mapcount(struct folio *folio)
{
	__bit_spin_unlock(FOLIO_MM_IDS_LOCK_BITNUM, &folio->_mm_ids);
}

static inline unsigned int folio_mm_id(const struct folio *folio, int idx)
{
	VM_WARN_ON_ONCE(idx != 0 && idx != 1);
	return folio->_mm_id[idx] & MM_ID_MASK;
}

static inline void folio_set_mm_id(struct folio *folio, int idx, mm_id_t id)
{
	VM_WARN_ON_ONCE(idx != 0 && idx != 1);
	folio->_mm_id[idx] &= ~MM_ID_MASK;
	folio->_mm_id[idx] |= id;
}

static inline void __folio_large_mapcount_sanity_checks(const struct folio *folio,
		int diff, mm_id_t mm_id)
{
	VM_WARN_ON_ONCE(!folio_test_large(folio) || folio_test_hugetlb(folio));
	VM_WARN_ON_ONCE(diff <= 0);
	VM_WARN_ON_ONCE(mm_id < MM_ID_MIN || mm_id > MM_ID_MAX);

	
	VM_WARN_ON_ONCE(diff > folio_large_nr_pages(folio));
	VM_WARN_ON_ONCE(folio_large_nr_pages(folio) - 1 > MM_ID_MAPCOUNT_MAX);

	VM_WARN_ON_ONCE(folio_mm_id(folio, 0) == MM_ID_DUMMY &&
			folio->_mm_id_mapcount[0] != -1);
	VM_WARN_ON_ONCE(folio_mm_id(folio, 0) != MM_ID_DUMMY &&
			folio->_mm_id_mapcount[0] < 0);
	VM_WARN_ON_ONCE(folio_mm_id(folio, 1) == MM_ID_DUMMY &&
			folio->_mm_id_mapcount[1] != -1);
	VM_WARN_ON_ONCE(folio_mm_id(folio, 1) != MM_ID_DUMMY &&
			folio->_mm_id_mapcount[1] < 0);
	VM_WARN_ON_ONCE(!folio_mapped(folio) &&
			test_bit(FOLIO_MM_IDS_SHARED_BITNUM, &folio->_mm_ids));
}

static __always_inline void folio_set_large_mapcount(struct folio *folio,
		int mapcount, struct vm_area_struct *vma)
{
	__folio_large_mapcount_sanity_checks(folio, mapcount, vma->vm_mm->mm_id);

	VM_WARN_ON_ONCE(folio_mm_id(folio, 0) != MM_ID_DUMMY);
	VM_WARN_ON_ONCE(folio_mm_id(folio, 1) != MM_ID_DUMMY);

	
	atomic_set(&folio->_large_mapcount, mapcount - 1);
	folio->_mm_id_mapcount[0] = mapcount - 1;
	folio_set_mm_id(folio, 0, vma->vm_mm->mm_id);
}

static __always_inline int folio_add_return_large_mapcount(struct folio *folio,
		int diff, struct vm_area_struct *vma)
{
	const mm_id_t mm_id = vma->vm_mm->mm_id;
	int new_mapcount_val;

	folio_lock_large_mapcount(folio);
	__folio_large_mapcount_sanity_checks(folio, diff, mm_id);

	new_mapcount_val = atomic_read(&folio->_large_mapcount) + diff;
	atomic_set(&folio->_large_mapcount, new_mapcount_val);

	
	if (folio_mm_id(folio, 0) == mm_id) {
		folio->_mm_id_mapcount[0] += diff;
		if (!IS_ENABLED(CONFIG_64BIT) && unlikely(folio->_mm_id_mapcount[0] < 0)) {
			folio->_mm_id_mapcount[0] = -1;
			folio_set_mm_id(folio, 0, MM_ID_DUMMY);
			folio->_mm_ids |= FOLIO_MM_IDS_SHARED_BIT;
		}
	} else if (folio_mm_id(folio, 1) == mm_id) {
		folio->_mm_id_mapcount[1] += diff;
		if (!IS_ENABLED(CONFIG_64BIT) && unlikely(folio->_mm_id_mapcount[1] < 0)) {
			folio->_mm_id_mapcount[1] = -1;
			folio_set_mm_id(folio, 1, MM_ID_DUMMY);
			folio->_mm_ids |= FOLIO_MM_IDS_SHARED_BIT;
		}
	} else if (folio_mm_id(folio, 0) == MM_ID_DUMMY) {
		folio_set_mm_id(folio, 0, mm_id);
		folio->_mm_id_mapcount[0] = diff - 1;
		
		if (new_mapcount_val != diff - 1)
			folio->_mm_ids |= FOLIO_MM_IDS_SHARED_BIT;
	} else if (folio_mm_id(folio, 1) == MM_ID_DUMMY) {
		folio_set_mm_id(folio, 1, mm_id);
		folio->_mm_id_mapcount[1] = diff - 1;
		
		folio->_mm_ids |= FOLIO_MM_IDS_SHARED_BIT;
	}
	folio_unlock_large_mapcount(folio);
	return new_mapcount_val + 1;
}
#define folio_add_large_mapcount folio_add_return_large_mapcount

static __always_inline int folio_sub_return_large_mapcount(struct folio *folio,
		int diff, struct vm_area_struct *vma)
{
	const mm_id_t mm_id = vma->vm_mm->mm_id;
	int new_mapcount_val;

	folio_lock_large_mapcount(folio);
	__folio_large_mapcount_sanity_checks(folio, diff, mm_id);

	new_mapcount_val = atomic_read(&folio->_large_mapcount) - diff;
	atomic_set(&folio->_large_mapcount, new_mapcount_val);

	
	if (folio_mm_id(folio, 0) == mm_id) {
		folio->_mm_id_mapcount[0] -= diff;
		if (folio->_mm_id_mapcount[0] >= 0)
			goto out;
		folio->_mm_id_mapcount[0] = -1;
		folio_set_mm_id(folio, 0, MM_ID_DUMMY);
	} else if (folio_mm_id(folio, 1) == mm_id) {
		folio->_mm_id_mapcount[1] -= diff;
		if (folio->_mm_id_mapcount[1] >= 0)
			goto out;
		folio->_mm_id_mapcount[1] = -1;
		folio_set_mm_id(folio, 1, MM_ID_DUMMY);
	}

	
	if (folio->_mm_id_mapcount[0] == new_mapcount_val ||
	    folio->_mm_id_mapcount[1] == new_mapcount_val)
		folio->_mm_ids &= ~FOLIO_MM_IDS_SHARED_BIT;
out:
	folio_unlock_large_mapcount(folio);
	return new_mapcount_val + 1;
}
#define folio_sub_large_mapcount folio_sub_return_large_mapcount
#else 

static inline void folio_set_large_mapcount(struct folio *folio, int mapcount,
		struct vm_area_struct *vma)
{
	
	atomic_set(&folio->_large_mapcount, mapcount - 1);
}

static inline void folio_add_large_mapcount(struct folio *folio,
		int diff, struct vm_area_struct *vma)
{
	atomic_add(diff, &folio->_large_mapcount);
}

static inline int folio_add_return_large_mapcount(struct folio *folio,
		int diff, struct vm_area_struct *vma)
{
	BUILD_BUG();
}

static inline void folio_sub_large_mapcount(struct folio *folio,
		int diff, struct vm_area_struct *vma)
{
	atomic_sub(diff, &folio->_large_mapcount);
}

static inline int folio_sub_return_large_mapcount(struct folio *folio,
		int diff, struct vm_area_struct *vma)
{
	BUILD_BUG();
}
#endif 

#define folio_inc_large_mapcount(folio, vma) \
	folio_add_large_mapcount(folio, 1, vma)
#define folio_inc_return_large_mapcount(folio, vma) \
	folio_add_return_large_mapcount(folio, 1, vma)
#define folio_dec_large_mapcount(folio, vma) \
	folio_sub_large_mapcount(folio, 1, vma)
#define folio_dec_return_large_mapcount(folio, vma) \
	folio_sub_return_large_mapcount(folio, 1, vma)


typedef int __bitwise rmap_t;


#define RMAP_NONE		((__force rmap_t)0)


#define RMAP_EXCLUSIVE		((__force rmap_t)BIT(0))

static __always_inline void __folio_rmap_sanity_checks(const struct folio *folio,
		const struct page *page, int nr_pages, enum pgtable_level level)
{
	
	VM_WARN_ON_FOLIO(folio_test_hugetlb(folio), folio);

	
	VM_WARN_ON_FOLIO(is_zero_folio(folio), folio);

	

	VM_WARN_ON_ONCE(nr_pages <= 0);
	VM_WARN_ON_FOLIO(page_folio(page) != folio, folio);
	VM_WARN_ON_FOLIO(page_folio(page + nr_pages - 1) != folio, folio);

	switch (level) {
	case PGTABLE_LEVEL_PTE:
		break;
	case PGTABLE_LEVEL_PMD:
		
		VM_WARN_ON_FOLIO(folio_nr_pages(folio) != HPAGE_PMD_NR, folio);
		VM_WARN_ON_FOLIO(nr_pages != HPAGE_PMD_NR, folio);
		break;
	case PGTABLE_LEVEL_PUD:
		
		VM_WARN_ON_FOLIO(folio_nr_pages(folio) != HPAGE_PUD_NR, folio);
		VM_WARN_ON_FOLIO(nr_pages != HPAGE_PUD_NR, folio);
		break;
	default:
		BUILD_BUG();
	}

	
	if (folio_test_anon(folio) && !folio_test_ksm(folio)) {
		unsigned long mapping = (unsigned long)folio->mapping;
		struct anon_vma *anon_vma;

		anon_vma = (void *)(mapping - FOLIO_MAPPING_ANON);
		VM_WARN_ON_FOLIO(atomic_read(&anon_vma->refcount) == 0, folio);
	}
}


void folio_move_anon_rmap(struct folio *, struct vm_area_struct *);
void folio_add_anon_rmap_ptes(struct folio *, struct page *, int nr_pages,
		struct vm_area_struct *, unsigned long address, rmap_t flags);
#define folio_add_anon_rmap_pte(folio, page, vma, address, flags) \
	folio_add_anon_rmap_ptes(folio, page, 1, vma, address, flags)
void folio_add_anon_rmap_pmd(struct folio *, struct page *,
		struct vm_area_struct *, unsigned long address, rmap_t flags);
void folio_add_new_anon_rmap(struct folio *, struct vm_area_struct *,
		unsigned long address, rmap_t flags);
void folio_add_file_rmap_ptes(struct folio *, struct page *, int nr_pages,
		struct vm_area_struct *);
#define folio_add_file_rmap_pte(folio, page, vma) \
	folio_add_file_rmap_ptes(folio, page, 1, vma)
void folio_add_file_rmap_pmd(struct folio *, struct page *,
		struct vm_area_struct *);
void folio_add_file_rmap_pud(struct folio *, struct page *,
		struct vm_area_struct *);
void folio_remove_rmap_ptes(struct folio *, struct page *, int nr_pages,
		struct vm_area_struct *);
#define folio_remove_rmap_pte(folio, page, vma) \
	folio_remove_rmap_ptes(folio, page, 1, vma)
void folio_remove_rmap_pmd(struct folio *, struct page *,
		struct vm_area_struct *);
void folio_remove_rmap_pud(struct folio *, struct page *,
		struct vm_area_struct *);

void hugetlb_add_anon_rmap(struct folio *, struct vm_area_struct *,
		unsigned long address, rmap_t flags);
void hugetlb_add_new_anon_rmap(struct folio *, struct vm_area_struct *,
		unsigned long address);


static inline int hugetlb_try_dup_anon_rmap(struct folio *folio,
		struct vm_area_struct *vma)
{
	VM_WARN_ON_FOLIO(!folio_test_hugetlb(folio), folio);
	VM_WARN_ON_FOLIO(!folio_test_anon(folio), folio);

	if (PageAnonExclusive(&folio->page)) {
		if (unlikely(folio_needs_cow_for_dma(vma, folio)))
			return -EBUSY;
		ClearPageAnonExclusive(&folio->page);
	}
	atomic_inc(&folio->_entire_mapcount);
	atomic_inc(&folio->_large_mapcount);
	return 0;
}


static inline int hugetlb_try_share_anon_rmap(struct folio *folio)
{
	VM_WARN_ON_FOLIO(!folio_test_hugetlb(folio), folio);
	VM_WARN_ON_FOLIO(!folio_test_anon(folio), folio);
	VM_WARN_ON_FOLIO(!PageAnonExclusive(&folio->page), folio);

	
	if (IS_ENABLED(CONFIG_HAVE_GUP_FAST))
		smp_mb();

	if (unlikely(folio_maybe_dma_pinned(folio)))
		return -EBUSY;
	ClearPageAnonExclusive(&folio->page);

	
	if (IS_ENABLED(CONFIG_HAVE_GUP_FAST))
		smp_mb__after_atomic();
	return 0;
}

static inline void hugetlb_add_file_rmap(struct folio *folio)
{
	VM_WARN_ON_FOLIO(!folio_test_hugetlb(folio), folio);
	VM_WARN_ON_FOLIO(folio_test_anon(folio), folio);

	atomic_inc(&folio->_entire_mapcount);
	atomic_inc(&folio->_large_mapcount);
}

static inline void hugetlb_remove_rmap(struct folio *folio)
{
	VM_WARN_ON_FOLIO(!folio_test_hugetlb(folio), folio);

	atomic_dec(&folio->_entire_mapcount);
	atomic_dec(&folio->_large_mapcount);
}

static __always_inline void __folio_dup_file_rmap(struct folio *folio,
		struct page *page, int nr_pages, struct vm_area_struct *dst_vma,
		enum pgtable_level level)
{
	const int orig_nr_pages = nr_pages;

	__folio_rmap_sanity_checks(folio, page, nr_pages, level);

	switch (level) {
	case PGTABLE_LEVEL_PTE:
		if (!folio_test_large(folio)) {
			atomic_inc(&folio->_mapcount);
			break;
		}

		if (IS_ENABLED(CONFIG_PAGE_MAPCOUNT)) {
			do {
				atomic_inc(&page->_mapcount);
			} while (page++, --nr_pages > 0);
		}
		folio_add_large_mapcount(folio, orig_nr_pages, dst_vma);
		break;
	case PGTABLE_LEVEL_PMD:
	case PGTABLE_LEVEL_PUD:
		atomic_inc(&folio->_entire_mapcount);
		folio_inc_large_mapcount(folio, dst_vma);
		break;
	default:
		BUILD_BUG();
	}
}


static inline void folio_dup_file_rmap_ptes(struct folio *folio,
		struct page *page, int nr_pages, struct vm_area_struct *dst_vma)
{
	__folio_dup_file_rmap(folio, page, nr_pages, dst_vma, PGTABLE_LEVEL_PTE);
}

static __always_inline void folio_dup_file_rmap_pte(struct folio *folio,
		struct page *page, struct vm_area_struct *dst_vma)
{
	__folio_dup_file_rmap(folio, page, 1, dst_vma, PGTABLE_LEVEL_PTE);
}


static inline void folio_dup_file_rmap_pmd(struct folio *folio,
		struct page *page, struct vm_area_struct *dst_vma)
{
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
	__folio_dup_file_rmap(folio, page, HPAGE_PMD_NR, dst_vma, PGTABLE_LEVEL_PTE);
#else
	WARN_ON_ONCE(true);
#endif
}

static __always_inline int __folio_try_dup_anon_rmap(struct folio *folio,
		struct page *page, int nr_pages, struct vm_area_struct *dst_vma,
		struct vm_area_struct *src_vma, enum pgtable_level level)
{
	const int orig_nr_pages = nr_pages;
	bool maybe_pinned;
	int i;

	VM_WARN_ON_FOLIO(!folio_test_anon(folio), folio);
	__folio_rmap_sanity_checks(folio, page, nr_pages, level);

	
	maybe_pinned = likely(!folio_is_device_private(folio)) &&
		       unlikely(folio_needs_cow_for_dma(src_vma, folio));

	
	switch (level) {
	case PGTABLE_LEVEL_PTE:
		if (unlikely(maybe_pinned)) {
			for (i = 0; i < nr_pages; i++)
				if (PageAnonExclusive(page + i))
					return -EBUSY;
		}

		if (!folio_test_large(folio)) {
			if (PageAnonExclusive(page))
				ClearPageAnonExclusive(page);
			atomic_inc(&folio->_mapcount);
			break;
		}

		do {
			if (PageAnonExclusive(page))
				ClearPageAnonExclusive(page);
			if (IS_ENABLED(CONFIG_PAGE_MAPCOUNT))
				atomic_inc(&page->_mapcount);
		} while (page++, --nr_pages > 0);
		folio_add_large_mapcount(folio, orig_nr_pages, dst_vma);
		break;
	case PGTABLE_LEVEL_PMD:
	case PGTABLE_LEVEL_PUD:
		if (PageAnonExclusive(page)) {
			if (unlikely(maybe_pinned))
				return -EBUSY;
			ClearPageAnonExclusive(page);
		}
		atomic_inc(&folio->_entire_mapcount);
		folio_inc_large_mapcount(folio, dst_vma);
		break;
	default:
		BUILD_BUG();
	}
	return 0;
}


static inline int folio_try_dup_anon_rmap_ptes(struct folio *folio,
		struct page *page, int nr_pages, struct vm_area_struct *dst_vma,
		struct vm_area_struct *src_vma)
{
	return __folio_try_dup_anon_rmap(folio, page, nr_pages, dst_vma,
					 src_vma, PGTABLE_LEVEL_PTE);
}

static __always_inline int folio_try_dup_anon_rmap_pte(struct folio *folio,
		struct page *page, struct vm_area_struct *dst_vma,
		struct vm_area_struct *src_vma)
{
	return __folio_try_dup_anon_rmap(folio, page, 1, dst_vma, src_vma,
					 PGTABLE_LEVEL_PTE);
}


static inline int folio_try_dup_anon_rmap_pmd(struct folio *folio,
		struct page *page, struct vm_area_struct *dst_vma,
		struct vm_area_struct *src_vma)
{
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
	return __folio_try_dup_anon_rmap(folio, page, HPAGE_PMD_NR, dst_vma,
					 src_vma, PGTABLE_LEVEL_PMD);
#else
	WARN_ON_ONCE(true);
	return -EBUSY;
#endif
}

static __always_inline int __folio_try_share_anon_rmap(struct folio *folio,
		struct page *page, int nr_pages, enum pgtable_level level)
{
	VM_WARN_ON_FOLIO(!folio_test_anon(folio), folio);
	VM_WARN_ON_FOLIO(!PageAnonExclusive(page), folio);
	__folio_rmap_sanity_checks(folio, page, nr_pages, level);

	
	if (unlikely(folio_is_device_private(folio))) {
		ClearPageAnonExclusive(page);
		return 0;
	}

	

	
	if (IS_ENABLED(CONFIG_HAVE_GUP_FAST))
		smp_mb();

	if (unlikely(folio_maybe_dma_pinned(folio)))
		return -EBUSY;
	ClearPageAnonExclusive(page);

	
	if (IS_ENABLED(CONFIG_HAVE_GUP_FAST))
		smp_mb__after_atomic();
	return 0;
}


static inline int folio_try_share_anon_rmap_pte(struct folio *folio,
		struct page *page)
{
	return __folio_try_share_anon_rmap(folio, page, 1, PGTABLE_LEVEL_PTE);
}


static inline int folio_try_share_anon_rmap_pmd(struct folio *folio,
		struct page *page)
{
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
	return __folio_try_share_anon_rmap(folio, page, HPAGE_PMD_NR,
					   PGTABLE_LEVEL_PMD);
#else
	WARN_ON_ONCE(true);
	return -EBUSY;
#endif
}


int folio_referenced(struct folio *, int is_locked,
			struct mem_cgroup *memcg, vm_flags_t *vm_flags);

void try_to_migrate(struct folio *folio, enum ttu_flags flags);
void try_to_unmap(struct folio *, enum ttu_flags flags);

struct page *make_device_exclusive(struct mm_struct *mm, unsigned long addr,
		void *owner, struct folio **foliop);


#define PVMW_SYNC		(1 << 0)

#define PVMW_MIGRATION		(1 << 1)




#define PVMW_PGTABLE_CROSSED	(1 << 16)

struct page_vma_mapped_walk {
	unsigned long pfn;
	unsigned long nr_pages;
	pgoff_t pgoff;
	struct vm_area_struct *vma;
	unsigned long address;
	pmd_t *pmd;
	pte_t *pte;
	spinlock_t *ptl;
	unsigned int flags;
};

#define DEFINE_FOLIO_VMA_WALK(name, _folio, _vma, _address, _flags)	\
	struct page_vma_mapped_walk name = {				\
		.pfn = folio_pfn(_folio),				\
		.nr_pages = folio_nr_pages(_folio),			\
		.pgoff = folio_pgoff(_folio),				\
		.vma = _vma,						\
		.address = _address,					\
		.flags = _flags,					\
	}

static inline void page_vma_mapped_walk_done(struct page_vma_mapped_walk *pvmw)
{
	
	if (pvmw->pte && !is_vm_hugetlb_page(pvmw->vma))
		pte_unmap(pvmw->pte);
	if (pvmw->ptl)
		spin_unlock(pvmw->ptl);
}


static inline void
page_vma_mapped_walk_restart(struct page_vma_mapped_walk *pvmw)
{
	WARN_ON_ONCE(!pvmw->pmd && !pvmw->pte);

	if (likely(pvmw->ptl))
		spin_unlock(pvmw->ptl);
	else
		WARN_ON_ONCE(1);

	pvmw->ptl = NULL;
	pvmw->pmd = NULL;
	pvmw->pte = NULL;
}

bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw);
unsigned long page_address_in_vma(const struct folio *folio,
		const struct page *, const struct vm_area_struct *);


int folio_mkclean(struct folio *);

int mapping_wrprotect_range(struct address_space *mapping, pgoff_t pgoff,
		unsigned long pfn, unsigned long nr_pages);

int pfn_mkclean_range(unsigned long pfn, unsigned long nr_pages, pgoff_t pgoff,
		      struct vm_area_struct *vma);

void remove_migration_ptes(struct folio *src, struct folio *dst,
		enum ttu_flags flags);


struct rmap_walk_control {
	void *arg;
	bool try_lock;
	bool contended;
	
	bool (*rmap_one)(struct folio *folio, struct vm_area_struct *vma,
					unsigned long addr, void *arg);
	int (*done)(struct folio *folio);
	struct anon_vma *(*anon_lock)(const struct folio *folio,
				      struct rmap_walk_control *rwc);
	bool (*invalid_vma)(struct vm_area_struct *vma, void *arg);
};

void rmap_walk(struct folio *folio, struct rmap_walk_control *rwc);
void rmap_walk_locked(struct folio *folio, struct rmap_walk_control *rwc);
struct anon_vma *folio_lock_anon_vma_read(const struct folio *folio,
					  struct rmap_walk_control *rwc);

#else	

#define anon_vma_init()		do {} while (0)
#define anon_vma_prepare(vma)	(0)

static inline int folio_referenced(struct folio *folio, int is_locked,
				  struct mem_cgroup *memcg,
				  vm_flags_t *vm_flags)
{
	*vm_flags = 0;
	return 0;
}

static inline void try_to_unmap(struct folio *folio, enum ttu_flags flags)
{
}

static inline int folio_mkclean(struct folio *folio)
{
	return 0;
}
#endif	

#endif	
