migrate.h 4.2 KB
Newer Older
C
Christoph Lameter 已提交
1 2 3 4
#ifndef _LINUX_MIGRATE_H
#define _LINUX_MIGRATE_H

#include <linux/mm.h>
5
#include <linux/mempolicy.h>
6
#include <linux/migrate_mode.h>
7
#include <linux/hugetlb.h>
C
Christoph Lameter 已提交
8

9 10 11
typedef struct page *new_page_t(struct page *page, unsigned long private,
				int **reason);
typedef void free_page_t(struct page *page, unsigned long private);
12

13 14 15 16 17 18
/*
 * Return values from addresss_space_operations.migratepage():
 * - negative errno on page migration failure;
 * - zero on page migration success;
 */
#define MIGRATEPAGE_SUCCESS		0
19

20 21 22 23 24 25
enum migrate_reason {
	MR_COMPACTION,
	MR_MEMORY_FAILURE,
	MR_MEMORY_HOTPLUG,
	MR_SYSCALL,		/* also applies to cpusets */
	MR_MEMPOLICY_MBIND,
26
	MR_NUMA_MISPLACED,
27 28
	MR_CMA,
	MR_TYPES
29
};
30

31 32 33
/* In mm/debug.c; also keep sync with include/trace/events/migrate.h */
extern char *migrate_reason_names[MR_TYPES];

34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
static inline struct page *new_page_nodemask(struct page *page,
				int preferred_nid, nodemask_t *nodemask)
{
	gfp_t gfp_mask = GFP_USER | __GFP_MOVABLE;

	if (PageHuge(page))
		return alloc_huge_page_nodemask(page_hstate(compound_head(page)),
				nodemask);

	if (PageHighMem(page) || (zone_idx(page_zone(page)) == ZONE_MOVABLE))
		gfp_mask |= __GFP_HIGHMEM;

	return __alloc_pages_nodemask(gfp_mask, 0, preferred_nid, nodemask);
}

49
#ifdef CONFIG_MIGRATION
50

51
extern void putback_movable_pages(struct list_head *l);
52 53 54
extern int migrate_page(struct address_space *mapping,
			struct page *newpage, struct page *page,
			enum migrate_mode mode);
55
extern int migrate_pages(struct list_head *l, new_page_t new, free_page_t free,
56
		unsigned long private, enum migrate_mode mode, int reason);
57
extern int isolate_movable_page(struct page *page, isolate_mode_t mode);
58
extern void putback_movable_page(struct page *page);
59

C
Christoph Lameter 已提交
60
extern int migrate_prep(void);
61
extern int migrate_prep_local(void);
N
Naoya Horiguchi 已提交
62 63 64
extern void migrate_page_copy(struct page *newpage, struct page *page);
extern int migrate_huge_page_move_mapping(struct address_space *mapping,
				  struct page *newpage, struct page *page);
65 66
extern int migrate_page_move_mapping(struct address_space *mapping,
		struct page *newpage, struct page *page,
67 68
		struct buffer_head *head, enum migrate_mode mode,
		int extra_count);
C
Christoph Lameter 已提交
69
#else
70

71
static inline void putback_movable_pages(struct list_head *l) {}
72 73 74
static inline int migrate_pages(struct list_head *l, new_page_t new,
		free_page_t free, unsigned long private, enum migrate_mode mode,
		int reason)
75
	{ return -ENOSYS; }
76 77
static inline int isolate_movable_page(struct page *page, isolate_mode_t mode)
	{ return -EBUSY; }
78

C
Christoph Lameter 已提交
79
static inline int migrate_prep(void) { return -ENOSYS; }
80
static inline int migrate_prep_local(void) { return -ENOSYS; }
C
Christoph Lameter 已提交
81

N
Naoya Horiguchi 已提交
82 83 84
static inline void migrate_page_copy(struct page *newpage,
				     struct page *page) {}

85
static inline int migrate_huge_page_move_mapping(struct address_space *mapping,
N
Naoya Horiguchi 已提交
86 87 88 89 90
				  struct page *newpage, struct page *page)
{
	return -ENOSYS;
}

C
Christoph Lameter 已提交
91
#endif /* CONFIG_MIGRATION */
92

93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
#ifdef CONFIG_COMPACTION
extern int PageMovable(struct page *page);
extern void __SetPageMovable(struct page *page, struct address_space *mapping);
extern void __ClearPageMovable(struct page *page);
#else
static inline int PageMovable(struct page *page) { return 0; };
static inline void __SetPageMovable(struct page *page,
				struct address_space *mapping)
{
}
static inline void __ClearPageMovable(struct page *page)
{
}
#endif

108
#ifdef CONFIG_NUMA_BALANCING
109
extern bool pmd_trans_migrating(pmd_t pmd);
110 111
extern int migrate_misplaced_page(struct page *page,
				  struct vm_area_struct *vma, int node);
112
#else
113 114 115 116
static inline bool pmd_trans_migrating(pmd_t pmd)
{
	return false;
}
117 118
static inline int migrate_misplaced_page(struct page *page,
					 struct vm_area_struct *vma, int node)
119 120 121
{
	return -EAGAIN; /* can't migrate now */
}
122
#endif /* CONFIG_NUMA_BALANCING */
123

124 125 126 127 128 129 130
#if defined(CONFIG_NUMA_BALANCING) && defined(CONFIG_TRANSPARENT_HUGEPAGE)
extern int migrate_misplaced_transhuge_page(struct mm_struct *mm,
			struct vm_area_struct *vma,
			pmd_t *pmd, pmd_t entry,
			unsigned long address,
			struct page *page, int node);
#else
131 132 133 134 135 136 137 138
static inline int migrate_misplaced_transhuge_page(struct mm_struct *mm,
			struct vm_area_struct *vma,
			pmd_t *pmd, pmd_t entry,
			unsigned long address,
			struct page *page, int node)
{
	return -EAGAIN;
}
139
#endif /* CONFIG_NUMA_BALANCING && CONFIG_TRANSPARENT_HUGEPAGE*/
140

C
Christoph Lameter 已提交
141
#endif /* _LINUX_MIGRATE_H */