Skip to content

Commit e972a07

Browse files
rientjestorvalds
authored andcommitted
mm, oom: rename zonelist locking functions
try_set_zonelist_oom() and clear_zonelist_oom() are not named properly to imply that they require locking semantics to avoid out_of_memory() being reordered. zone_scan_lock is required for both functions to ensure that there is proper locking synchronization. Rename try_set_zonelist_oom() to oom_zonelist_trylock() and rename clear_zonelist_oom() to oom_zonelist_unlock() to imply there is proper locking semantics. At the same time, convert oom_zonelist_trylock() to return bool instead of int since only success and failure are tested. Signed-off-by: David Rientjes <rientjes@google.com> Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Rik van Riel <riel@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 8d060bf commit e972a07

3 files changed

Lines changed: 18 additions & 22 deletions

File tree

‎include/linux/oom.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ extern void oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
5555
struct mem_cgroup *memcg, nodemask_t *nodemask,
5656
const char *message);
5757

58-
extern int try_set_zonelist_oom(struct zonelist *zonelist, gfp_t gfp_flags);
59-
extern void clear_zonelist_oom(struct zonelist *zonelist, gfp_t gfp_flags);
58+
extern bool oom_zonelist_trylock(struct zonelist *zonelist, gfp_t gfp_flags);
59+
extern void oom_zonelist_unlock(struct zonelist *zonelist, gfp_t gfp_flags);
6060

6161
extern void check_panic_on_oom(enum oom_constraint constraint, gfp_t gfp_mask,
6262
int order, const nodemask_t *nodemask);

‎mm/oom_kill.c‎

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -559,28 +559,25 @@ EXPORT_SYMBOL_GPL(unregister_oom_notifier);
559559
* if a parallel OOM killing is already taking place that includes a zone in
560560
* the zonelist. Otherwise, locks all zones in the zonelist and returns 1.
561561
*/
562-
int try_set_zonelist_oom(struct zonelist *zonelist, gfp_t gfp_mask)
562+
bool oom_zonelist_trylock(struct zonelist *zonelist, gfp_t gfp_mask)
563563
{
564564
struct zoneref *z;
565565
struct zone *zone;
566-
int ret = 1;
566+
bool ret = true;
567567

568568
spin_lock(&zone_scan_lock);
569-
for_each_zone_zonelist(zone, z, zonelist, gfp_zone(gfp_mask)) {
569+
for_each_zone_zonelist(zone, z, zonelist, gfp_zone(gfp_mask))
570570
if (zone_is_oom_locked(zone)) {
571-
ret = 0;
571+
ret = false;
572572
goto out;
573573
}
574-
}
575574

576-
for_each_zone_zonelist(zone, z, zonelist, gfp_zone(gfp_mask)) {
577-
/*
578-
* Lock each zone in the zonelist under zone_scan_lock so a
579-
* parallel invocation of try_set_zonelist_oom() doesn't succeed
580-
* when it shouldn't.
581-
*/
575+
/*
576+
* Lock each zone in the zonelist under zone_scan_lock so a parallel
577+
* call to oom_zonelist_trylock() doesn't succeed when it shouldn't.
578+
*/
579+
for_each_zone_zonelist(zone, z, zonelist, gfp_zone(gfp_mask))
582580
zone_set_flag(zone, ZONE_OOM_LOCKED);
583-
}
584581

585582
out:
586583
spin_unlock(&zone_scan_lock);
@@ -592,15 +589,14 @@ int try_set_zonelist_oom(struct zonelist *zonelist, gfp_t gfp_mask)
592589
* allocation attempts with zonelists containing them may now recall the OOM
593590
* killer, if necessary.
594591
*/
595-
void clear_zonelist_oom(struct zonelist *zonelist, gfp_t gfp_mask)
592+
void oom_zonelist_unlock(struct zonelist *zonelist, gfp_t gfp_mask)
596593
{
597594
struct zoneref *z;
598595
struct zone *zone;
599596

600597
spin_lock(&zone_scan_lock);
601-
for_each_zone_zonelist(zone, z, zonelist, gfp_zone(gfp_mask)) {
598+
for_each_zone_zonelist(zone, z, zonelist, gfp_zone(gfp_mask))
602599
zone_clear_flag(zone, ZONE_OOM_LOCKED);
603-
}
604600
spin_unlock(&zone_scan_lock);
605601
}
606602

@@ -695,8 +691,8 @@ void pagefault_out_of_memory(void)
695691
return;
696692

697693
zonelist = node_zonelist(first_memory_node, GFP_KERNEL);
698-
if (try_set_zonelist_oom(zonelist, GFP_KERNEL)) {
694+
if (oom_zonelist_trylock(zonelist, GFP_KERNEL)) {
699695
out_of_memory(NULL, 0, 0, NULL, false);
700-
clear_zonelist_oom(zonelist, GFP_KERNEL);
696+
oom_zonelist_unlock(zonelist, GFP_KERNEL);
701697
}
702698
}

‎mm/page_alloc.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2246,8 +2246,8 @@ __alloc_pages_may_oom(gfp_t gfp_mask, unsigned int order,
22462246
{
22472247
struct page *page;
22482248

2249-
/* Acquire the OOM killer lock for the zones in zonelist */
2250-
if (!try_set_zonelist_oom(zonelist, gfp_mask)) {
2249+
/* Acquire the per-zone oom lock for each zone */
2250+
if (!oom_zonelist_trylock(zonelist, gfp_mask)) {
22512251
schedule_timeout_uninterruptible(1);
22522252
return NULL;
22532253
}
@@ -2285,7 +2285,7 @@ __alloc_pages_may_oom(gfp_t gfp_mask, unsigned int order,
22852285
out_of_memory(zonelist, gfp_mask, order, nodemask, false);
22862286

22872287
out:
2288-
clear_zonelist_oom(zonelist, gfp_mask);
2288+
oom_zonelist_unlock(zonelist, gfp_mask);
22892289
return page;
22902290
}
22912291

0 commit comments

Comments
 (0)