The patch titled Subject: mm: don't miss the last page because of round-off error has been added to the -mm tree. Its filename is mm-dont-miss-the-last-page-because-of-round-off-error.patch This patch should soon appear at http://ozlabs.org/~akpm/mmots/broken-out/mm-dont-miss-the-last-page-because-of-round-off-error.patch and later at http://ozlabs.org/~akpm/mmotm/broken-out/mm-dont-miss-the-last-page-because-of-round-off-error.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Roman Gushchin <guro@xxxxxx> Subject: mm: don't miss the last page because of round-off error I've noticed, that dying memory cgroups are often pinned in memory by a single pagecache page. Even under moderate memory pressure they sometimes stayed in such state for a long time. That looked strange. My investigation showed that the problem is caused by applying the LRU pressure balancing math: scan = div64_u64(scan * fraction[lru], denominator), where denominator = fraction[anon] + fraction[file] + 1. Because fraction[lru] is always less than denominator, if the initial scan size is 1, the result is always 0. This means the last page is not scanned and has no chances to be reclaimed. Fix this by rounding up the result of the division. In practice this change significantly improves the speed of dying cgroups reclaim. Link: http://lkml.kernel.org/r/20180827162621.30187-3-guro@xxxxxx Signed-off-by: Roman Gushchin <guro@xxxxxx> Cc: Johannes Weiner <hannes@xxxxxxxxxxx> Cc: Michal Hocko <mhocko@xxxxxxxxxx> Cc: Tejun Heo <tj@xxxxxxxxxx> Cc: Rik van Riel <riel@xxxxxxxxxxx> Cc: Konstantin Khlebnikov <koct9i@xxxxxxxxx> Cc: Matthew Wilcox <willy@xxxxxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- include/linux/math64.h | 2 ++ mm/vmscan.c | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) --- a/include/linux/math64.h~mm-dont-miss-the-last-page-because-of-round-off-error +++ a/include/linux/math64.h @@ -281,4 +281,6 @@ static inline u64 mul_u64_u32_div(u64 a, } #endif /* mul_u64_u32_div */ +#define DIV64_U64_ROUND_UP(ll, d) div64_u64((ll) + (d) - 1, (d)) + #endif /* _LINUX_MATH64_H */ --- a/mm/vmscan.c~mm-dont-miss-the-last-page-because-of-round-off-error +++ a/mm/vmscan.c @@ -2446,9 +2446,11 @@ out: /* * Scan types proportional to swappiness and * their relative recent reclaim efficiency. + * Make sure we don't miss the last page + * because of a round-off error. */ - scan = div64_u64(scan * fraction[file], - denominator); + scan = DIV64_U64_ROUND_UP(scan * fraction[file], + denominator); break; case SCAN_FILE: case SCAN_ANON: _ Patches currently in -mm which might be from guro@xxxxxx are mm-rework-memcg-kernel-stack-accounting.patch mm-drain-memcg-stocks-on-css-offlining.patch mm-dont-miss-the-last-page-because-of-round-off-error.patch