Skip to content

Commit

Permalink
mm/vmscan.c: use DIV_ROUND_UP for calculation of zone's balance_gap a…
Browse files Browse the repository at this point in the history
…nd correct comments.

Currently, we use (zone->managed_pages + KSWAPD_ZONE_BALANCE_GAP_RATIO-1)
/ KSWAPD_ZONE_BALANCE_GAP_RATIO to avoid a zero gap value.  It's better to
use DIV_ROUND_UP macro for neater code and clear meaning.

Besides, the gap value is calculated against the per-zone "managed pages",
not "present pages".  This patch also corrects the comment and do some
rephrasing.

Signed-off-by: Jianyu Zhan <[email protected]>
Acked-by: Rik van Riel <[email protected]>
Acked-by: Rafael Aquini <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
JianyuZhan authored and torvalds committed Jun 4, 2014
1 parent b7596fb commit 4be89a3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
8 changes: 4 additions & 4 deletions include/linux/swap.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ enum {
#define COMPACT_CLUSTER_MAX SWAP_CLUSTER_MAX

/*
* Ratio between the present memory in the zone and the "gap" that
* we're allowing kswapd to shrink in addition to the per-zone high
* wmark, even for zones that already have the high wmark satisfied,
* in order to provide better per-zone lru behavior. We are ok to
* Ratio between zone->managed_pages and the "gap" that above the per-zone
* "high_wmark". While balancing nodes, We allow kswapd to shrink zones that
* do not meet the (high_wmark + gap) watermark, even which already met the
* high_wmark, in order to provide better per-zone lru behavior. We are ok to
* spend not more than 1% of the memory for this zone balancing "gap".
*/
#define KSWAPD_ZONE_BALANCE_GAP_RATIO 100
Expand Down
10 changes: 4 additions & 6 deletions mm/vmscan.c
Original file line number Diff line number Diff line change
Expand Up @@ -2295,9 +2295,8 @@ static inline bool compaction_ready(struct zone *zone, struct scan_control *sc)
* there is a buffer of free pages available to give compaction
* a reasonable chance of completing and allocating the page
*/
balance_gap = min(low_wmark_pages(zone),
(zone->managed_pages + KSWAPD_ZONE_BALANCE_GAP_RATIO-1) /
KSWAPD_ZONE_BALANCE_GAP_RATIO);
balance_gap = min(low_wmark_pages(zone), DIV_ROUND_UP(
zone->managed_pages, KSWAPD_ZONE_BALANCE_GAP_RATIO));
watermark = high_wmark_pages(zone) + balance_gap + (2UL << sc->order);
watermark_ok = zone_watermark_ok_safe(zone, 0, watermark, 0, 0);

Expand Down Expand Up @@ -2949,9 +2948,8 @@ static bool kswapd_shrink_zone(struct zone *zone,
* high wmark plus a "gap" where the gap is either the low
* watermark or 1% of the zone, whichever is smaller.
*/
balance_gap = min(low_wmark_pages(zone),
(zone->managed_pages + KSWAPD_ZONE_BALANCE_GAP_RATIO-1) /
KSWAPD_ZONE_BALANCE_GAP_RATIO);
balance_gap = min(low_wmark_pages(zone), DIV_ROUND_UP(
zone->managed_pages, KSWAPD_ZONE_BALANCE_GAP_RATIO));

/*
* If there is no low memory pressure or the zone is balanced then no
Expand Down

0 comments on commit 4be89a3

Please sign in to comment.