aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/mm.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/mm.h')
-rw-r--r--include/linux/mm.h178
1 files changed, 99 insertions, 79 deletions
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 9d9dcc35d6a1..e7c3f9a0111a 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -87,6 +87,7 @@ extern unsigned int kobjsize(const void *objp);
87#define VM_PFNMAP 0x00000400 /* Page-ranges managed without "struct page", just pure PFN */ 87#define VM_PFNMAP 0x00000400 /* Page-ranges managed without "struct page", just pure PFN */
88#define VM_DENYWRITE 0x00000800 /* ETXTBSY on write attempts.. */ 88#define VM_DENYWRITE 0x00000800 /* ETXTBSY on write attempts.. */
89 89
90#define VM_POPULATE 0x00001000
90#define VM_LOCKED 0x00002000 91#define VM_LOCKED 0x00002000
91#define VM_IO 0x00004000 /* Memory mapped I/O or similar */ 92#define VM_IO 0x00004000 /* Memory mapped I/O or similar */
92 93
@@ -366,7 +367,7 @@ static inline struct page *compound_head(struct page *page)
366 * both from it and to it can be tracked, using atomic_inc_and_test 367 * both from it and to it can be tracked, using atomic_inc_and_test
367 * and atomic_add_negative(-1). 368 * and atomic_add_negative(-1).
368 */ 369 */
369static inline void reset_page_mapcount(struct page *page) 370static inline void page_mapcount_reset(struct page *page)
370{ 371{
371 atomic_set(&(page)->_mapcount, -1); 372 atomic_set(&(page)->_mapcount, -1);
372} 373}
@@ -580,50 +581,11 @@ static inline pte_t maybe_mkwrite(pte_t pte, struct vm_area_struct *vma)
580 * sets it, so none of the operations on it need to be atomic. 581 * sets it, so none of the operations on it need to be atomic.
581 */ 582 */
582 583
583 584/* Page flags: | [SECTION] | [NODE] | ZONE | [LAST_NID] | ... | FLAGS | */
584/*
585 * page->flags layout:
586 *
587 * There are three possibilities for how page->flags get
588 * laid out. The first is for the normal case, without
589 * sparsemem. The second is for sparsemem when there is
590 * plenty of space for node and section. The last is when
591 * we have run out of space and have to fall back to an
592 * alternate (slower) way of determining the node.
593 *
594 * No sparsemem or sparsemem vmemmap: | NODE | ZONE | ... | FLAGS |
595 * classic sparse with space for node:| SECTION | NODE | ZONE | ... | FLAGS |
596 * classic sparse no space for node: | SECTION | ZONE | ... | FLAGS |
597 */
598#if defined(CONFIG_SPARSEMEM) && !defined(CONFIG_SPARSEMEM_VMEMMAP)
599#define SECTIONS_WIDTH SECTIONS_SHIFT
600#else
601#define SECTIONS_WIDTH 0
602#endif
603
604#define ZONES_WIDTH ZONES_SHIFT
605
606#if SECTIONS_WIDTH+ZONES_WIDTH+NODES_SHIFT <= BITS_PER_LONG - NR_PAGEFLAGS
607#define NODES_WIDTH NODES_SHIFT
608#else
609#ifdef CONFIG_SPARSEMEM_VMEMMAP
610#error "Vmemmap: No space for nodes field in page flags"
611#endif
612#define NODES_WIDTH 0
613#endif
614
615/* Page flags: | [SECTION] | [NODE] | ZONE | ... | FLAGS | */
616#define SECTIONS_PGOFF ((sizeof(unsigned long)*8) - SECTIONS_WIDTH) 585#define SECTIONS_PGOFF ((sizeof(unsigned long)*8) - SECTIONS_WIDTH)
617#define NODES_PGOFF (SECTIONS_PGOFF - NODES_WIDTH) 586#define NODES_PGOFF (SECTIONS_PGOFF - NODES_WIDTH)
618#define ZONES_PGOFF (NODES_PGOFF - ZONES_WIDTH) 587#define ZONES_PGOFF (NODES_PGOFF - ZONES_WIDTH)
619 588#define LAST_NID_PGOFF (ZONES_PGOFF - LAST_NID_WIDTH)
620/*
621 * We are going to use the flags for the page to node mapping if its in
622 * there. This includes the case where there is no node, so it is implicit.
623 */
624#if !(NODES_WIDTH > 0 || NODES_SHIFT == 0)
625#define NODE_NOT_IN_PAGE_FLAGS
626#endif
627 589
628/* 590/*
629 * Define the bit shifts to access each section. For non-existent 591 * Define the bit shifts to access each section. For non-existent
@@ -633,6 +595,7 @@ static inline pte_t maybe_mkwrite(pte_t pte, struct vm_area_struct *vma)
633#define SECTIONS_PGSHIFT (SECTIONS_PGOFF * (SECTIONS_WIDTH != 0)) 595#define SECTIONS_PGSHIFT (SECTIONS_PGOFF * (SECTIONS_WIDTH != 0))
634#define NODES_PGSHIFT (NODES_PGOFF * (NODES_WIDTH != 0)) 596#define NODES_PGSHIFT (NODES_PGOFF * (NODES_WIDTH != 0))
635#define ZONES_PGSHIFT (ZONES_PGOFF * (ZONES_WIDTH != 0)) 597#define ZONES_PGSHIFT (ZONES_PGOFF * (ZONES_WIDTH != 0))
598#define LAST_NID_PGSHIFT (LAST_NID_PGOFF * (LAST_NID_WIDTH != 0))
636 599
637/* NODE:ZONE or SECTION:ZONE is used to ID a zone for the buddy allocator */ 600/* NODE:ZONE or SECTION:ZONE is used to ID a zone for the buddy allocator */
638#ifdef NODE_NOT_IN_PAGE_FLAGS 601#ifdef NODE_NOT_IN_PAGE_FLAGS
@@ -654,6 +617,7 @@ static inline pte_t maybe_mkwrite(pte_t pte, struct vm_area_struct *vma)
654#define ZONES_MASK ((1UL << ZONES_WIDTH) - 1) 617#define ZONES_MASK ((1UL << ZONES_WIDTH) - 1)
655#define NODES_MASK ((1UL << NODES_WIDTH) - 1) 618#define NODES_MASK ((1UL << NODES_WIDTH) - 1)
656#define SECTIONS_MASK ((1UL << SECTIONS_WIDTH) - 1) 619#define SECTIONS_MASK ((1UL << SECTIONS_WIDTH) - 1)
620#define LAST_NID_MASK ((1UL << LAST_NID_WIDTH) - 1)
657#define ZONEID_MASK ((1UL << ZONEID_SHIFT) - 1) 621#define ZONEID_MASK ((1UL << ZONEID_SHIFT) - 1)
658 622
659static inline enum zone_type page_zonenum(const struct page *page) 623static inline enum zone_type page_zonenum(const struct page *page)
@@ -661,6 +625,10 @@ static inline enum zone_type page_zonenum(const struct page *page)
661 return (page->flags >> ZONES_PGSHIFT) & ZONES_MASK; 625 return (page->flags >> ZONES_PGSHIFT) & ZONES_MASK;
662} 626}
663 627
628#if defined(CONFIG_SPARSEMEM) && !defined(CONFIG_SPARSEMEM_VMEMMAP)
629#define SECTION_IN_PAGE_FLAGS
630#endif
631
664/* 632/*
665 * The identification function is only used by the buddy allocator for 633 * The identification function is only used by the buddy allocator for
666 * determining if two pages could be buddies. We are not really 634 * determining if two pages could be buddies. We are not really
@@ -693,31 +661,48 @@ static inline int page_to_nid(const struct page *page)
693#endif 661#endif
694 662
695#ifdef CONFIG_NUMA_BALANCING 663#ifdef CONFIG_NUMA_BALANCING
696static inline int page_xchg_last_nid(struct page *page, int nid) 664#ifdef LAST_NID_NOT_IN_PAGE_FLAGS
665static inline int page_nid_xchg_last(struct page *page, int nid)
697{ 666{
698 return xchg(&page->_last_nid, nid); 667 return xchg(&page->_last_nid, nid);
699} 668}
700 669
701static inline int page_last_nid(struct page *page) 670static inline int page_nid_last(struct page *page)
702{ 671{
703 return page->_last_nid; 672 return page->_last_nid;
704} 673}
705static inline void reset_page_last_nid(struct page *page) 674static inline void page_nid_reset_last(struct page *page)
706{ 675{
707 page->_last_nid = -1; 676 page->_last_nid = -1;
708} 677}
709#else 678#else
710static inline int page_xchg_last_nid(struct page *page, int nid) 679static inline int page_nid_last(struct page *page)
680{
681 return (page->flags >> LAST_NID_PGSHIFT) & LAST_NID_MASK;
682}
683
684extern int page_nid_xchg_last(struct page *page, int nid);
685
686static inline void page_nid_reset_last(struct page *page)
687{
688 int nid = (1 << LAST_NID_SHIFT) - 1;
689
690 page->flags &= ~(LAST_NID_MASK << LAST_NID_PGSHIFT);
691 page->flags |= (nid & LAST_NID_MASK) << LAST_NID_PGSHIFT;
692}
693#endif /* LAST_NID_NOT_IN_PAGE_FLAGS */
694#else
695static inline int page_nid_xchg_last(struct page *page, int nid)
711{ 696{
712 return page_to_nid(page); 697 return page_to_nid(page);
713} 698}
714 699
715static inline int page_last_nid(struct page *page) 700static inline int page_nid_last(struct page *page)
716{ 701{
717 return page_to_nid(page); 702 return page_to_nid(page);
718} 703}
719 704
720static inline void reset_page_last_nid(struct page *page) 705static inline void page_nid_reset_last(struct page *page)
721{ 706{
722} 707}
723#endif 708#endif
@@ -727,7 +712,7 @@ static inline struct zone *page_zone(const struct page *page)
727 return &NODE_DATA(page_to_nid(page))->node_zones[page_zonenum(page)]; 712 return &NODE_DATA(page_to_nid(page))->node_zones[page_zonenum(page)];
728} 713}
729 714
730#if defined(CONFIG_SPARSEMEM) && !defined(CONFIG_SPARSEMEM_VMEMMAP) 715#ifdef SECTION_IN_PAGE_FLAGS
731static inline void set_page_section(struct page *page, unsigned long section) 716static inline void set_page_section(struct page *page, unsigned long section)
732{ 717{
733 page->flags &= ~(SECTIONS_MASK << SECTIONS_PGSHIFT); 718 page->flags &= ~(SECTIONS_MASK << SECTIONS_PGSHIFT);
@@ -757,7 +742,7 @@ static inline void set_page_links(struct page *page, enum zone_type zone,
757{ 742{
758 set_page_zone(page, zone); 743 set_page_zone(page, zone);
759 set_page_node(page, node); 744 set_page_node(page, node);
760#if defined(CONFIG_SPARSEMEM) && !defined(CONFIG_SPARSEMEM_VMEMMAP) 745#ifdef SECTION_IN_PAGE_FLAGS
761 set_page_section(page, pfn_to_section_nr(pfn)); 746 set_page_section(page, pfn_to_section_nr(pfn));
762#endif 747#endif
763} 748}
@@ -817,18 +802,7 @@ void page_address_init(void);
817#define PAGE_MAPPING_KSM 2 802#define PAGE_MAPPING_KSM 2
818#define PAGE_MAPPING_FLAGS (PAGE_MAPPING_ANON | PAGE_MAPPING_KSM) 803#define PAGE_MAPPING_FLAGS (PAGE_MAPPING_ANON | PAGE_MAPPING_KSM)
819 804
820extern struct address_space swapper_space; 805extern struct address_space *page_mapping(struct page *page);
821static inline struct address_space *page_mapping(struct page *page)
822{
823 struct address_space *mapping = page->mapping;
824
825 VM_BUG_ON(PageSlab(page));
826 if (unlikely(PageSwapCache(page)))
827 mapping = &swapper_space;
828 else if ((unsigned long)mapping & PAGE_MAPPING_ANON)
829 mapping = NULL;
830 return mapping;
831}
832 806
833/* Neutral page->mapping pointer to address_space or anon_vma or other */ 807/* Neutral page->mapping pointer to address_space or anon_vma or other */
834static inline void *page_rmapping(struct page *page) 808static inline void *page_rmapping(struct page *page)
@@ -1035,18 +1009,18 @@ static inline int fixup_user_fault(struct task_struct *tsk,
1035} 1009}
1036#endif 1010#endif
1037 1011
1038extern int make_pages_present(unsigned long addr, unsigned long end);
1039extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write); 1012extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
1040extern int access_remote_vm(struct mm_struct *mm, unsigned long addr, 1013extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
1041 void *buf, int len, int write); 1014 void *buf, int len, int write);
1042 1015
1043int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm, 1016long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
1044 unsigned long start, int len, unsigned int foll_flags, 1017 unsigned long start, unsigned long nr_pages,
1045 struct page **pages, struct vm_area_struct **vmas, 1018 unsigned int foll_flags, struct page **pages,
1046 int *nonblocking); 1019 struct vm_area_struct **vmas, int *nonblocking);
1047int get_user_pages(struct task_struct *tsk, struct mm_struct *mm, 1020long get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
1048 unsigned long start, int nr_pages, int write, int force, 1021 unsigned long start, unsigned long nr_pages,
1049 struct page **pages, struct vm_area_struct **vmas); 1022 int write, int force, struct page **pages,
1023 struct vm_area_struct **vmas);
1050int get_user_pages_fast(unsigned long start, int nr_pages, int write, 1024int get_user_pages_fast(unsigned long start, int nr_pages, int write,
1051 struct page **pages); 1025 struct page **pages);
1052struct kvec; 1026struct kvec;
@@ -1359,6 +1333,24 @@ extern void free_bootmem_with_active_regions(int nid,
1359 unsigned long max_low_pfn); 1333 unsigned long max_low_pfn);
1360extern void sparse_memory_present_with_active_regions(int nid); 1334extern void sparse_memory_present_with_active_regions(int nid);
1361 1335
1336#define MOVABLEMEM_MAP_MAX MAX_NUMNODES
1337struct movablemem_entry {
1338 unsigned long start_pfn; /* start pfn of memory segment */
1339 unsigned long end_pfn; /* end pfn of memory segment (exclusive) */
1340};
1341
1342struct movablemem_map {
1343 bool acpi; /* true if using SRAT info */
1344 int nr_map;
1345 struct movablemem_entry map[MOVABLEMEM_MAP_MAX];
1346 nodemask_t numa_nodes_hotplug; /* on which nodes we specify memory */
1347 nodemask_t numa_nodes_kernel; /* on which nodes kernel resides in */
1348};
1349
1350extern void __init insert_movablemem_map(unsigned long start_pfn,
1351 unsigned long end_pfn);
1352extern int __init movablemem_map_overlap(unsigned long start_pfn,
1353 unsigned long end_pfn);
1362#endif /* CONFIG_HAVE_MEMBLOCK_NODE_MAP */ 1354#endif /* CONFIG_HAVE_MEMBLOCK_NODE_MAP */
1363 1355
1364#if !defined(CONFIG_HAVE_MEMBLOCK_NODE_MAP) && \ 1356#if !defined(CONFIG_HAVE_MEMBLOCK_NODE_MAP) && \
@@ -1395,6 +1387,9 @@ extern void setup_per_cpu_pageset(void);
1395extern void zone_pcp_update(struct zone *zone); 1387extern void zone_pcp_update(struct zone *zone);
1396extern void zone_pcp_reset(struct zone *zone); 1388extern void zone_pcp_reset(struct zone *zone);
1397 1389
1390/* page_alloc.c */
1391extern int min_free_kbytes;
1392
1398/* nommu.c */ 1393/* nommu.c */
1399extern atomic_long_t mmap_pages_allocated; 1394extern atomic_long_t mmap_pages_allocated;
1400extern int nommu_shrink_inode_mappings(struct inode *, size_t, size_t); 1395extern int nommu_shrink_inode_mappings(struct inode *, size_t, size_t);
@@ -1472,13 +1467,24 @@ extern int install_special_mapping(struct mm_struct *mm,
1472extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long); 1467extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
1473 1468
1474extern unsigned long mmap_region(struct file *file, unsigned long addr, 1469extern unsigned long mmap_region(struct file *file, unsigned long addr,
1475 unsigned long len, unsigned long flags, 1470 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
1476 vm_flags_t vm_flags, unsigned long pgoff); 1471extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
1477extern unsigned long do_mmap_pgoff(struct file *, unsigned long, 1472 unsigned long len, unsigned long prot, unsigned long flags,
1478 unsigned long, unsigned long, 1473 unsigned long pgoff, unsigned long *populate);
1479 unsigned long, unsigned long);
1480extern int do_munmap(struct mm_struct *, unsigned long, size_t); 1474extern int do_munmap(struct mm_struct *, unsigned long, size_t);
1481 1475
1476#ifdef CONFIG_MMU
1477extern int __mm_populate(unsigned long addr, unsigned long len,
1478 int ignore_errors);
1479static inline void mm_populate(unsigned long addr, unsigned long len)
1480{
1481 /* Ignore errors */
1482 (void) __mm_populate(addr, len, 1);
1483}
1484#else
1485static inline void mm_populate(unsigned long addr, unsigned long len) {}
1486#endif
1487
1482/* These take the mm semaphore themselves */ 1488/* These take the mm semaphore themselves */
1483extern unsigned long vm_brk(unsigned long, unsigned long); 1489extern unsigned long vm_brk(unsigned long, unsigned long);
1484extern int vm_munmap(unsigned long, size_t); 1490extern int vm_munmap(unsigned long, size_t);
@@ -1623,8 +1629,17 @@ int vm_insert_pfn(struct vm_area_struct *vma, unsigned long addr,
1623int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr, 1629int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
1624 unsigned long pfn); 1630 unsigned long pfn);
1625 1631
1626struct page *follow_page(struct vm_area_struct *, unsigned long address, 1632struct page *follow_page_mask(struct vm_area_struct *vma,
1627 unsigned int foll_flags); 1633 unsigned long address, unsigned int foll_flags,
1634 unsigned int *page_mask);
1635
1636static inline struct page *follow_page(struct vm_area_struct *vma,
1637 unsigned long address, unsigned int foll_flags)
1638{
1639 unsigned int unused_page_mask;
1640 return follow_page_mask(vma, address, foll_flags, &unused_page_mask);
1641}
1642
1628#define FOLL_WRITE 0x01 /* check pte is writable */ 1643#define FOLL_WRITE 0x01 /* check pte is writable */
1629#define FOLL_TOUCH 0x02 /* mark page accessed */ 1644#define FOLL_TOUCH 0x02 /* mark page accessed */
1630#define FOLL_GET 0x04 /* do get_page on page */ 1645#define FOLL_GET 0x04 /* do get_page on page */
@@ -1636,6 +1651,7 @@ struct page *follow_page(struct vm_area_struct *, unsigned long address,
1636#define FOLL_SPLIT 0x80 /* don't return transhuge pages, split them */ 1651#define FOLL_SPLIT 0x80 /* don't return transhuge pages, split them */
1637#define FOLL_HWPOISON 0x100 /* check page is hwpoisoned */ 1652#define FOLL_HWPOISON 0x100 /* check page is hwpoisoned */
1638#define FOLL_NUMA 0x200 /* force NUMA hinting page fault */ 1653#define FOLL_NUMA 0x200 /* force NUMA hinting page fault */
1654#define FOLL_MIGRATION 0x400 /* wait for page to replace migration entry */
1639 1655
1640typedef int (*pte_fn_t)(pte_t *pte, pgtable_t token, unsigned long addr, 1656typedef int (*pte_fn_t)(pte_t *pte, pgtable_t token, unsigned long addr,
1641 void *data); 1657 void *data);
@@ -1707,7 +1723,11 @@ int vmemmap_populate_basepages(struct page *start_page,
1707 unsigned long pages, int node); 1723 unsigned long pages, int node);
1708int vmemmap_populate(struct page *start_page, unsigned long pages, int node); 1724int vmemmap_populate(struct page *start_page, unsigned long pages, int node);
1709void vmemmap_populate_print_last(void); 1725void vmemmap_populate_print_last(void);
1710 1726#ifdef CONFIG_MEMORY_HOTPLUG
1727void vmemmap_free(struct page *memmap, unsigned long nr_pages);
1728#endif
1729void register_page_bootmem_memmap(unsigned long section_nr, struct page *map,
1730 unsigned long size);
1711 1731
1712enum mf_flags { 1732enum mf_flags {
1713 MF_COUNT_INCREASED = 1 << 0, 1733 MF_COUNT_INCREASED = 1 << 0,
@@ -1720,7 +1740,7 @@ extern int unpoison_memory(unsigned long pfn);
1720extern int sysctl_memory_failure_early_kill; 1740extern int sysctl_memory_failure_early_kill;
1721extern int sysctl_memory_failure_recovery; 1741extern int sysctl_memory_failure_recovery;
1722extern void shake_page(struct page *p, int access); 1742extern void shake_page(struct page *p, int access);
1723extern atomic_long_t mce_bad_pages; 1743extern atomic_long_t num_poisoned_pages;
1724extern int soft_offline_page(struct page *page, int flags); 1744extern int soft_offline_page(struct page *page, int flags);
1725 1745
1726extern void dump_page(struct page *page); 1746extern void dump_page(struct page *page);