History

mm: constify oom_control, scan_control, and alloc_context nodemask

The nodemasks in these structures may come from a variety of sources, including tasks and cpusets - and should never be modified by any code when being passed around inside another context.

Gregory Price committed 5 months ago

Commit baff6d21 parent 567c26a11 files · +26 −22Browse files

Unified · Split

11 files
  1. include/linux/cpuset.h +2 −2
  2. include/linux/mm.h +2 −2
  3. include/linux/mmzone.h +3 −3
  4. include/linux/oom.h +1 −1
  5. include/linux/swap.h +1 −1
  6. kernel/cgroup/cpuset.c +1 −1
  7. mm/internal.h +1 −1
  8. mm/mmzone.c +3 −2
  9. mm/page_alloc.c +3 −3
  10. mm/show_mem.c +6 −3
  11. mm/vmscan.c +3 −3
include/linux/cpuset.h+2−2
@@ -83,7 +83,7 @@ extern bool cpuset_cpus_allowed_fallback(struct task_struct *p); · 82 unmodified lines
83extern nodemask_t cpuset_mems_allowed(struct task_struct *p);83extern nodemask_t cpuset_mems_allowed(struct task_struct *p);
84#define cpuset_current_mems_allowed (current->mems_allowed)84#define cpuset_current_mems_allowed (current->mems_allowed)
85void cpuset_init_current_mems_allowed(void);85void cpuset_init_current_mems_allowed(void);
86int cpuset_nodemask_valid_mems_allowed(nodemask_t *nodemask);86int cpuset_nodemask_valid_mems_allowed(const nodemask_t *nodemask);
87 87
88extern bool cpuset_current_node_allowed(int node, gfp_t gfp_mask);88extern bool cpuset_current_node_allowed(int node, gfp_t gfp_mask);
89 89
@@ -224,7 +224,7 @@ static inline nodemask_t cpuset_mems_allowed(struct task_struct *p) · 134 unmodified lines
224#define cpuset_current_mems_allowed (node_states[N_MEMORY])224#define cpuset_current_mems_allowed (node_states[N_MEMORY])
225static inline void cpuset_init_current_mems_allowed(void) {}225static inline void cpuset_init_current_mems_allowed(void) {}
226 226
227static inline int cpuset_nodemask_valid_mems_allowed(nodemask_t *nodemask)227static inline int cpuset_nodemask_valid_mems_allowed(const nodemask_t *nodemask)
228{228{
229 return 1;229 return 1;
230}230}
include/linux/mm.h+2−2
@@ -4042,7 +4042,7 @@ extern int __meminit early_pfn_to_nid(unsigned long pfn); · 4041 unmodified lines
4042extern void mem_init(void);4042extern void mem_init(void);
4043extern void __init mmap_init(void);4043extern void __init mmap_init(void);
4044 4044
4045extern void __show_mem(unsigned int flags, nodemask_t *nodemask, int max_zone_idx);4045extern void __show_mem(unsigned int flags, const nodemask_t *nodemask, int max_zone_idx);
4046static inline void show_mem(void)4046static inline void show_mem(void)
4047{4047{
4048 __show_mem(0, NULL, MAX_NR_ZONES - 1);4048 __show_mem(0, NULL, MAX_NR_ZONES - 1);
@@ -4052,7 +4052,7 @@ extern void si_meminfo(struct sysinfo * val); · 3 unmodified lines
4052extern void si_meminfo_node(struct sysinfo *val, int nid);4052extern void si_meminfo_node(struct sysinfo *val, int nid);
4053 4053
4054extern __printf(3, 4)4054extern __printf(3, 4)
4055void warn_alloc(gfp_t gfp_mask, nodemask_t *nodemask, const char *fmt, ...);4055void warn_alloc(gfp_t gfp_mask, const nodemask_t *nodemask, const char *fmt, ...);
4056 4056
4057extern void setup_per_cpu_pageset(void);4057extern void setup_per_cpu_pageset(void);
4058 4058
include/linux/mmzone.h+3−3
@@ -1815,7 +1815,7 @@ static inline int zonelist_node_idx(const struct zoneref *zoneref) · 1814 unmodified lines
1815 1815
1816struct zoneref *__next_zones_zonelist(struct zoneref *z,1816struct zoneref *__next_zones_zonelist(struct zoneref *z,
1817 enum zone_type highest_zoneidx,1817 enum zone_type highest_zoneidx,
1818 nodemask_t *nodes);1818 const nodemask_t *nodes);
1819 1819
1820/**1820/**
1821 * next_zones_zonelist - Returns the next zone at or below highest_zoneidx within the allowed nodemask using a cursor within a zonelist as a starting point1821 * next_zones_zonelist - Returns the next zone at or below highest_zoneidx within the allowed nodemask using a cursor within a zonelist as a starting point
@@ -1834,7 +1834,7 @@ struct zoneref *__next_zones_zonelist(struct zoneref *z, · 12 unmodified lines
1834 */1834 */
1835static __always_inline struct zoneref *next_zones_zonelist(struct zoneref *z,1835static __always_inline struct zoneref *next_zones_zonelist(struct zoneref *z,
1836 enum zone_type highest_zoneidx,1836 enum zone_type highest_zoneidx,
1837 nodemask_t *nodes)1837 const nodemask_t *nodes)
1838{1838{
1839 if (likely(!nodes && zonelist_zone_idx(z) <= highest_zoneidx))1839 if (likely(!nodes && zonelist_zone_idx(z) <= highest_zoneidx))
1840 return z;1840 return z;
@@ -1860,7 +1860,7 @@ static __always_inline struct zoneref *next_zones_zonelist(struct zoneref *z, · 19 unmodified lines
1860 */1860 */
1861static inline struct zoneref *first_zones_zonelist(struct zonelist *zonelist,1861static inline struct zoneref *first_zones_zonelist(struct zonelist *zonelist,
1862 enum zone_type highest_zoneidx,1862 enum zone_type highest_zoneidx,
1863 nodemask_t *nodes)1863 const nodemask_t *nodes)
1864{1864{
1865 return next_zones_zonelist(zonelist->_zonerefs,1865 return next_zones_zonelist(zonelist->_zonerefs,
1866 highest_zoneidx, nodes);1866 highest_zoneidx, nodes);
include/linux/oom.h+1−1
@@ -30,7 +30,7 @@ struct oom_control { · 29 unmodified lines
30 struct zonelist *zonelist;30 struct zonelist *zonelist;
31 31
32 /* Used to determine mempolicy */32 /* Used to determine mempolicy */
33 nodemask_t *nodemask;33 const nodemask_t *nodemask;
34 34
35 /* Memory cgroup in which oom is invoked, or NULL for global oom */35 /* Memory cgroup in which oom is invoked, or NULL for global oom */
36 struct mem_cgroup *memcg;36 struct mem_cgroup *memcg;
include/linux/swap.h+1−1
@@ -345,7 +345,7 @@ extern void swap_setup(void); · 344 unmodified lines
345/* linux/mm/vmscan.c */345/* linux/mm/vmscan.c */
346extern unsigned long zone_reclaimable_pages(struct zone *zone);346extern unsigned long zone_reclaimable_pages(struct zone *zone);
347extern unsigned long try_to_free_pages(struct zonelist *zonelist, int order,347extern unsigned long try_to_free_pages(struct zonelist *zonelist, int order,
348 gfp_t gfp_mask, nodemask_t *mask);348 gfp_t gfp_mask, const nodemask_t *mask);
349unsigned long lruvec_lru_size(struct lruvec *lruvec, enum lru_list lru, int zone_idx);349unsigned long lruvec_lru_size(struct lruvec *lruvec, enum lru_list lru, int zone_idx);
350 350
351#define MEMCG_RECLAIM_MAY_SWAP (1 << 1)351#define MEMCG_RECLAIM_MAY_SWAP (1 << 1)
kernel/cgroup/cpuset.c+1−1
@@ -4162,7 +4162,7 @@ nodemask_t cpuset_mems_allowed(struct task_struct *tsk) · 4161 unmodified lines
4162 *4162 *
4163 * Are any of the nodes in the nodemask allowed in current->mems_allowed?4163 * Are any of the nodes in the nodemask allowed in current->mems_allowed?
4164 */4164 */
4165int cpuset_nodemask_valid_mems_allowed(nodemask_t *nodemask)4165int cpuset_nodemask_valid_mems_allowed(const nodemask_t *nodemask)
4166{4166{
4167 return nodes_intersects(*nodemask, current->mems_allowed);4167 return nodes_intersects(*nodemask, current->mems_allowed);
4168}4168}
mm/internal.h+1−1
@@ -675,7 +675,7 @@ void page_alloc_sysctl_init(void); · 674 unmodified lines
675 */675 */
676struct alloc_context {676struct alloc_context {
677 struct zonelist *zonelist;677 struct zonelist *zonelist;
678 nodemask_t *nodemask;678 const nodemask_t *nodemask;
679 struct zoneref *preferred_zoneref;679 struct zoneref *preferred_zoneref;
680 int migratetype;680 int migratetype;
681 681
mm/mmzone.c+3−2
@@ -43,7 +43,8 @@ struct zone *next_zone(struct zone *zone) · 42 unmodified lines
43 return zone;43 return zone;
44}44}
45 45
46static inline int zref_in_nodemask(struct zoneref *zref, nodemask_t *nodes)46static inline int zref_in_nodemask(struct zoneref *zref,
47 const nodemask_t *nodes)
47{48{
48#ifdef CONFIG_NUMA49#ifdef CONFIG_NUMA
49 return node_isset(zonelist_node_idx(zref), *nodes);50 return node_isset(zonelist_node_idx(zref), *nodes);
@@ -55,7 +56,7 @@ static inline int zref_in_nodemask(struct zoneref *zref, nodemask_t *nodes) · 5 unmodified lines
55/* Returns the next zone at or below highest_zoneidx in a zonelist */56/* Returns the next zone at or below highest_zoneidx in a zonelist */
56struct zoneref *__next_zones_zonelist(struct zoneref *z,57struct zoneref *__next_zones_zonelist(struct zoneref *z,
57 enum zone_type highest_zoneidx,58 enum zone_type highest_zoneidx,
58 nodemask_t *nodes)59 const nodemask_t *nodes)
59{60{
60 /*61 /*
61 * Find the next suitable zone to use for the allocation.62 * Find the next suitable zone to use for the allocation.
mm/page_alloc.c+3−3
@@ -3978,7 +3978,7 @@ try_this_zone: · 3977 unmodified lines
3978 return NULL;3978 return NULL;
3979}3979}
3980 3980
3981static void warn_alloc_show_mem(gfp_t gfp_mask, nodemask_t *nodemask)3981static void warn_alloc_show_mem(gfp_t gfp_mask, const nodemask_t *nodemask)
3982{3982{
3983 unsigned int filter = SHOW_MEM_FILTER_NODES;3983 unsigned int filter = SHOW_MEM_FILTER_NODES;
3984 3984
@@ -3998,7 +3998,7 @@ static void warn_alloc_show_mem(gfp_t gfp_mask, nodemask_t *nodemask) · 13 unmodified lines
3998 mem_cgroup_show_protected_memory(NULL);3998 mem_cgroup_show_protected_memory(NULL);
3999}3999}
4000 4000
4001void warn_alloc(gfp_t gfp_mask, nodemask_t *nodemask, const char *fmt, ...)4001void warn_alloc(gfp_t gfp_mask, const nodemask_t *nodemask, const char *fmt, ...)
4002{4002{
4003 struct va_format vaf;4003 struct va_format vaf;
4004 va_list args;4004 va_list args;
@@ -4680,7 +4680,7 @@ check_retry_cpuset(int cpuset_mems_cookie, struct alloc_context *ac) · 675 unmodified lines
4680 return false;4680 return false;
4681}4681}
4682 4682
4683static void check_alloc_stall_warn(gfp_t gfp_mask, nodemask_t *nodemask,4683static void check_alloc_stall_warn(gfp_t gfp_mask, const nodemask_t *nodemask,
4684 unsigned int order, unsigned long alloc_start_time)4684 unsigned int order, unsigned long alloc_start_time)
4685{4685{
4686 static DEFINE_SPINLOCK(alloc_stall_lock);4686 static DEFINE_SPINLOCK(alloc_stall_lock);
mm/show_mem.c+6−3
@@ -116,7 +116,8 @@ void si_meminfo_node(struct sysinfo *val, int nid) · 115 unmodified lines
116 * Determine whether the node should be displayed or not, depending on whether116 * Determine whether the node should be displayed or not, depending on whether
117 * SHOW_MEM_FILTER_NODES was passed to show_free_areas().117 * SHOW_MEM_FILTER_NODES was passed to show_free_areas().
118 */118 */
119static bool show_mem_node_skip(unsigned int flags, int nid, nodemask_t *nodemask)119static bool show_mem_node_skip(unsigned int flags, int nid,
120 const nodemask_t *nodemask)
120{121{
121 if (!(flags & SHOW_MEM_FILTER_NODES))122 if (!(flags & SHOW_MEM_FILTER_NODES))
122 return false;123 return false;
@@ -177,7 +178,8 @@ static bool node_has_managed_zones(pg_data_t *pgdat, int max_zone_idx) · 54 unmodified lines
177 * SHOW_MEM_FILTER_NODES: suppress nodes that are not allowed by current's178 * SHOW_MEM_FILTER_NODES: suppress nodes that are not allowed by current's
178 * cpuset.179 * cpuset.
179 */180 */
180static void show_free_areas(unsigned int filter, nodemask_t *nodemask, int max_zone_idx)181static void show_free_areas(unsigned int filter, const nodemask_t *nodemask,
182 int max_zone_idx)
181{183{
182 unsigned long free_pcp = 0;184 unsigned long free_pcp = 0;
183 int cpu, nid;185 int cpu, nid;
@@ -402,7 +404,8 @@ static void show_free_areas(unsigned int filter, nodemask_t *nodemask, int max_z · 218 unmodified lines
402 show_swap_cache_info();404 show_swap_cache_info();
403}405}
404 406
405void __show_mem(unsigned int filter, nodemask_t *nodemask, int max_zone_idx)407void __show_mem(unsigned int filter, const nodemask_t *nodemask,
408 int max_zone_idx)
406{409{
407 unsigned long total = 0, reserved = 0, highmem = 0;410 unsigned long total = 0, reserved = 0, highmem = 0;
408 struct zone *zone;411 struct zone *zone;
mm/vmscan.c+3−3
@@ -79,7 +79,7 @@ struct scan_control { · 78 unmodified lines
79 * Nodemask of nodes allowed by the caller. If NULL, all nodes79 * Nodemask of nodes allowed by the caller. If NULL, all nodes
80 * are scanned.80 * are scanned.
81 */81 */
82 nodemask_t *nodemask;82 const nodemask_t *nodemask;
83 83
84 /*84 /*
85 * The memory cgroup that hit its limit and as a result is the85 * The memory cgroup that hit its limit and as a result is the
@@ -6591,7 +6591,7 @@ static bool allow_direct_reclaim(pg_data_t *pgdat) · 6505 unmodified lines
6591 * happens, the page allocator should not consider triggering the OOM killer.6591 * happens, the page allocator should not consider triggering the OOM killer.
6592 */6592 */
6593static bool throttle_direct_reclaim(gfp_t gfp_mask, struct zonelist *zonelist,6593static bool throttle_direct_reclaim(gfp_t gfp_mask, struct zonelist *zonelist,
6594 nodemask_t *nodemask)6594 const nodemask_t *nodemask)
6595{6595{
6596 struct zoneref *z;6596 struct zoneref *z;
6597 struct zone *zone;6597 struct zone *zone;
@@ -6671,7 +6671,7 @@ out: · 73 unmodified lines
6671}6671}
6672 6672
6673unsigned long try_to_free_pages(struct zonelist *zonelist, int order,6673unsigned long try_to_free_pages(struct zonelist *zonelist, int order,
6674 gfp_t gfp_mask, nodemask_t *nodemask)6674 gfp_t gfp_mask, const nodemask_t *nodemask)
6675{6675{
6676 unsigned long nr_reclaimed;6676 unsigned long nr_reclaimed;
6677 struct scan_control sc = {6677 struct scan_control sc = {