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
8383 extern nodemask_t cpuset_mems_allowed(struct task_struct *p);
8484 #define cpuset_current_mems_allowed (current->mems_allowed)
8585 void cpuset_init_current_mems_allowed(void);
86−int cpuset_nodemask_valid_mems_allowed(nodemask_t *nodemask);
86+int cpuset_nodemask_valid_mems_allowed(const nodemask_t *nodemask);
8787
8888 extern bool cpuset_current_node_allowed(int node, gfp_t gfp_mask);
8989
@@ -224,7 +224,7 @@ static inline nodemask_t cpuset_mems_allowed(struct task_struct *p) · 134 unmodified lines
224224 #define cpuset_current_mems_allowed (node_states[N_MEMORY])
225225 static inline void cpuset_init_current_mems_allowed(void) {}
226226
227−static inline int cpuset_nodemask_valid_mems_allowed(nodemask_t *nodemask)
227+static inline int cpuset_nodemask_valid_mems_allowed(const nodemask_t *nodemask)
228228 {
229229 return 1;
230230 }
include/linux/mm.h+2−2
@@ -4042,7 +4042,7 @@ extern int __meminit early_pfn_to_nid(unsigned long pfn); · 4041 unmodified lines
40424042 extern void mem_init(void);
40434043 extern void __init mmap_init(void);
40444044
4045−extern void __show_mem(unsigned int flags, nodemask_t *nodemask, int max_zone_idx);
4045+extern void __show_mem(unsigned int flags, const nodemask_t *nodemask, int max_zone_idx);
40464046 static inline void show_mem(void)
40474047 {
40484048 __show_mem(0, NULL, MAX_NR_ZONES - 1);
@@ -4052,7 +4052,7 @@ extern void si_meminfo(struct sysinfo * val); · 3 unmodified lines
40524052 extern void si_meminfo_node(struct sysinfo *val, int nid);
40534053
40544054 extern __printf(3, 4)
4055−void warn_alloc(gfp_t gfp_mask, nodemask_t *nodemask, const char *fmt, ...);
4055+void warn_alloc(gfp_t gfp_mask, const nodemask_t *nodemask, const char *fmt, ...);
40564056
40574057 extern void setup_per_cpu_pageset(void);
40584058
include/linux/mmzone.h+3−3
@@ -1815,7 +1815,7 @@ static inline int zonelist_node_idx(const struct zoneref *zoneref) · 1814 unmodified lines
18151815
18161816 struct zoneref *__next_zones_zonelist(struct zoneref *z,
18171817 enum zone_type highest_zoneidx,
1818− nodemask_t *nodes);
1818+ const nodemask_t *nodes);
18191819
18201820 /**
18211821 * 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
18341834 */
18351835 static __always_inline struct zoneref *next_zones_zonelist(struct zoneref *z,
18361836 enum zone_type highest_zoneidx,
1837− nodemask_t *nodes)
1837+ const nodemask_t *nodes)
18381838 {
18391839 if (likely(!nodes && zonelist_zone_idx(z) <= highest_zoneidx))
18401840 return z;
@@ -1860,7 +1860,7 @@ static __always_inline struct zoneref *next_zones_zonelist(struct zoneref *z, · 19 unmodified lines
18601860 */
18611861 static inline struct zoneref *first_zones_zonelist(struct zonelist *zonelist,
18621862 enum zone_type highest_zoneidx,
1863− nodemask_t *nodes)
1863+ const nodemask_t *nodes)
18641864 {
18651865 return next_zones_zonelist(zonelist->_zonerefs,
18661866 highest_zoneidx, nodes);
include/linux/oom.h+1−1
@@ -30,7 +30,7 @@ struct oom_control { · 29 unmodified lines
3030 struct zonelist *zonelist;
3131
3232 /* Used to determine mempolicy */
33− nodemask_t *nodemask;
33+ const nodemask_t *nodemask;
3434
3535 /* Memory cgroup in which oom is invoked, or NULL for global oom */
3636 struct mem_cgroup *memcg;
include/linux/swap.h+1−1
@@ -345,7 +345,7 @@ extern void swap_setup(void); · 344 unmodified lines
345345 /* linux/mm/vmscan.c */
346346 extern unsigned long zone_reclaimable_pages(struct zone *zone);
347347 extern 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);
349349 unsigned long lruvec_lru_size(struct lruvec *lruvec, enum lru_list lru, int zone_idx);
350350
351351 #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
41624162 *
41634163 * Are any of the nodes in the nodemask allowed in current->mems_allowed?
41644164 */
4165−int cpuset_nodemask_valid_mems_allowed(nodemask_t *nodemask)
4165+int cpuset_nodemask_valid_mems_allowed(const nodemask_t *nodemask)
41664166 {
41674167 return nodes_intersects(*nodemask, current->mems_allowed);
41684168 }
mm/internal.h+1−1
@@ -675,7 +675,7 @@ void page_alloc_sysctl_init(void); · 674 unmodified lines
675675 */
676676 struct alloc_context {
677677 struct zonelist *zonelist;
678− nodemask_t *nodemask;
678+ const nodemask_t *nodemask;
679679 struct zoneref *preferred_zoneref;
680680 int migratetype;
681681
mm/mmzone.c+3−2
@@ -43,7 +43,8 @@ struct zone *next_zone(struct zone *zone) · 42 unmodified lines
4343 return zone;
4444 }
4545
46−static inline int zref_in_nodemask(struct zoneref *zref, nodemask_t *nodes)
46+static inline int zref_in_nodemask(struct zoneref *zref,
47+ const nodemask_t *nodes)
4748 {
4849 #ifdef CONFIG_NUMA
4950 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
5556 /* Returns the next zone at or below highest_zoneidx in a zonelist */
5657 struct zoneref *__next_zones_zonelist(struct zoneref *z,
5758 enum zone_type highest_zoneidx,
58− nodemask_t *nodes)
59+ const nodemask_t *nodes)
5960 {
6061 /*
6162 * 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
39783978 return NULL;
39793979 }
39803980
3981−static void warn_alloc_show_mem(gfp_t gfp_mask, nodemask_t *nodemask)
3981+static void warn_alloc_show_mem(gfp_t gfp_mask, const nodemask_t *nodemask)
39823982 {
39833983 unsigned int filter = SHOW_MEM_FILTER_NODES;
39843984
@@ -3998,7 +3998,7 @@ static void warn_alloc_show_mem(gfp_t gfp_mask, nodemask_t *nodemask) · 13 unmodified lines
39983998 mem_cgroup_show_protected_memory(NULL);
39993999 }
40004000
4001−void warn_alloc(gfp_t gfp_mask, nodemask_t *nodemask, const char *fmt, ...)
4001+void warn_alloc(gfp_t gfp_mask, const nodemask_t *nodemask, const char *fmt, ...)
40024002 {
40034003 struct va_format vaf;
40044004 va_list args;
@@ -4680,7 +4680,7 @@ check_retry_cpuset(int cpuset_mems_cookie, struct alloc_context *ac) · 675 unmodified lines
46804680 return false;
46814681 }
46824682
4683−static void check_alloc_stall_warn(gfp_t gfp_mask, nodemask_t *nodemask,
4683+static void check_alloc_stall_warn(gfp_t gfp_mask, const nodemask_t *nodemask,
46844684 unsigned int order, unsigned long alloc_start_time)
46854685 {
46864686 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
116116 * Determine whether the node should be displayed or not, depending on whether
117117 * SHOW_MEM_FILTER_NODES was passed to show_free_areas().
118118 */
119−static bool show_mem_node_skip(unsigned int flags, int nid, nodemask_t *nodemask)
119+static bool show_mem_node_skip(unsigned int flags, int nid,
120+ const nodemask_t *nodemask)
120121 {
121122 if (!(flags & SHOW_MEM_FILTER_NODES))
122123 return false;
@@ -177,7 +178,8 @@ static bool node_has_managed_zones(pg_data_t *pgdat, int max_zone_idx) · 54 unmodified lines
177178 * SHOW_MEM_FILTER_NODES: suppress nodes that are not allowed by current's
178179 * cpuset.
179180 */
180−static void show_free_areas(unsigned int filter, nodemask_t *nodemask, int max_zone_idx)
181+static void show_free_areas(unsigned int filter, const nodemask_t *nodemask,
182+ int max_zone_idx)
181183 {
182184 unsigned long free_pcp = 0;
183185 int cpu, nid;
@@ -402,7 +404,8 @@ static void show_free_areas(unsigned int filter, nodemask_t *nodemask, int max_z · 218 unmodified lines
402404 show_swap_cache_info();
403405 }
404406
405−void __show_mem(unsigned int filter, nodemask_t *nodemask, int max_zone_idx)
407+void __show_mem(unsigned int filter, const nodemask_t *nodemask,
408+ int max_zone_idx)
406409 {
407410 unsigned long total = 0, reserved = 0, highmem = 0;
408411 struct zone *zone;
mm/vmscan.c+3−3
@@ -79,7 +79,7 @@ struct scan_control { · 78 unmodified lines
7979 * Nodemask of nodes allowed by the caller. If NULL, all nodes
8080 * are scanned.
8181 */
82− nodemask_t *nodemask;
82+ const nodemask_t *nodemask;
8383
8484 /*
8585 * 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
65916591 * happens, the page allocator should not consider triggering the OOM killer.
65926592 */
65936593 static bool throttle_direct_reclaim(gfp_t gfp_mask, struct zonelist *zonelist,
6594− nodemask_t *nodemask)
6594+ const nodemask_t *nodemask)
65956595 {
65966596 struct zoneref *z;
65976597 struct zone *zone;
@@ -6671,7 +6671,7 @@ out: · 73 unmodified lines
66716671 }
66726672
66736673 unsigned 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)
66756675 {
66766676 unsigned long nr_reclaimed;
66776677 struct scan_control sc = {