Skip to content

Commit

Permalink
mm: compaction: improve compaction_suitable() accuracy
Browse files Browse the repository at this point in the history
With the new per-mt free counts, compaction can check the watermarks
specifically against suitable migration targets. This ensures reclaim
keeps going when the free pages are in blocks that aren't actually
suitable migration targets: MIGRATE_FREE, UNMOVABLE, RECLAIMABLE.

Signed-off-by: Johannes Weiner <[email protected]>
  • Loading branch information
hnaz committed Mar 9, 2023
1 parent 7ddf44b commit ad60dfc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
21 changes: 13 additions & 8 deletions mm/compaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -2226,11 +2226,16 @@ enum compact_result compaction_suitable(struct zone *zone, int order,
unsigned int alloc_flags,
int highest_zoneidx)
{
unsigned long free_pages;
enum compact_result ret;
int fragindex;

ret = __compaction_suitable(zone, order, alloc_flags, highest_zoneidx,
zone_page_state(zone, NR_FREE_PAGES));
/* Suitable migration targets */
free_pages = zone_page_state(zone, NR_FREE_MOVABLE);
free_pages += zone_page_state(zone, NR_FREE_CMA_PAGES);

ret = __compaction_suitable(zone, order, highest_zoneidx, free_pages);

/*
* fragmentation index determines if allocation failures are due to
* low memory or external fragmentation
Expand Down Expand Up @@ -2273,19 +2278,19 @@ bool compaction_zonelist_suitable(struct alloc_context *ac, int order,
for_each_zone_zonelist_nodemask(zone, z, ac->zonelist,
ac->highest_zoneidx, ac->nodemask) {
unsigned long available;
enum compact_result compact_result;

available = zone_page_state_snapshot(zone, NR_FREE_MOVABLE);
available += zone_page_state_snapshot(zone, NR_FREE_CMA_PAGES);
/*
* Do not consider all the reclaimable memory because we do not
* want to trash just for a single high order allocation which
* is even not guaranteed to appear even if __compaction_suitable
* is happy about the watermark check.
*/
available = zone_reclaimable_pages(zone) / order;
available += zone_page_state_snapshot(zone, NR_FREE_PAGES);
compact_result = __compaction_suitable(zone, order, alloc_flags,
ac->highest_zoneidx, available);
if (compact_result == COMPACT_CONTINUE)
available += zone_reclaimable_pages(zone) / order;

if (__compaction_suitable(zone, order, ac->highest_zoneidx,
available) == COMPACT_CONTINUE)
return true;
}

Expand Down
7 changes: 5 additions & 2 deletions mm/vmscan.c
Original file line number Diff line number Diff line change
Expand Up @@ -6270,6 +6270,7 @@ static void shrink_node(pg_data_t *pgdat, struct scan_control *sc)
static inline bool compaction_ready(struct zone *zone, struct scan_control *sc)
{
unsigned long watermark;
unsigned long free_pages;
enum compact_result suitable;

suitable = compaction_suitable(zone, sc->order, 0, sc->reclaim_idx);
Expand All @@ -6290,8 +6291,10 @@ static inline bool compaction_ready(struct zone *zone, struct scan_control *sc)
* we are already above the high+gap watermark, don't reclaim at all.
*/
watermark = high_wmark_pages(zone) + compact_gap(sc->order);

return zone_watermark_ok_safe(zone, 0, watermark, sc->reclaim_idx);
free_pages = zone_page_state_snapshot(zone, NR_FREE_MOVABLE);
free_pages += zone_page_state_snapshot(zone, NR_FREE_CMA_PAGES);
return __zone_watermark_ok(zone, 0, watermark, sc->reclaim_idx,
ALLOC_CMA, free_pages);
}

static void consider_reclaim_throttle(pg_data_t *pgdat, struct scan_control *sc)
Expand Down

0 comments on commit ad60dfc

Please sign in to comment.