linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Wei Wang <wei.w.wang@intel.com>
To: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	mhocko@kernel.org, akpm@linux-foundation.org,
	penguin-kernel@I-love.SAKURA.ne.jp, chris@chris-wilson.co.uk,
	mst@redhat.com
Cc: wei.w.wang@intel.com
Subject: [PATCH] mm/vmscan: adjust shrinkctl->nr_scanned after invoking scan_objects
Date: Fri,  3 Aug 2018 18:56:49 +0800	[thread overview]
Message-ID: <1533293809-34354-1-git-send-email-wei.w.wang@intel.com> (raw)

Some shrinkers may free more than the requested nr_to_scan of pages
in one invocation of scan_objects, and some may free less than that.

Currently shrinkers can either return the actual number of pages that
have been freed via the return value of scan_objects or track that
actual number in shrinkctl->nr_scanned. But do_shrink_slab works on an
assumption that the actual number is always tracked via
shrinkctl->nr_scanned, which is not true. Having checked the shrinkers
used in the kernel, they basically return the actual number of freed
pages via the return value of scan_objects, and most of them leave
shrinkctl->nr_scanned unchanged after scan_objects is called.

So this patch adjusts shrinkctl->nr_scanned to the actual freed number
after scan_objects is called.

Signed-off-by: Wei Wang <wei.w.wang@intel.com>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Michael S. Tsirkin <mst@redhat.com>
---
 mm/vmscan.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/mm/vmscan.c b/mm/vmscan.c
index 03822f8..78a75b9 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -447,9 +447,13 @@ static unsigned long do_shrink_slab(struct shrink_control *shrinkctl,
 		if (ret == SHRINK_STOP)
 			break;
 		freed += ret;
+		shrinkctl->nr_scanned = ret;
 
 		count_vm_events(SLABS_SCANNED, shrinkctl->nr_scanned);
-		total_scan -= shrinkctl->nr_scanned;
+		if (total_scan > shrinkctl->nr_scanned)
+			total_scan -= shrinkctl->nr_scanned;
+		else
+			total_scan = 0;
 		scanned += shrinkctl->nr_scanned;
 
 		cond_resched();
-- 
2.7.4


                 reply	other threads:[~2018-08-03 11:25 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1533293809-34354-1-git-send-email-wei.w.wang@intel.com \
    --to=wei.w.wang@intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=chris@chris-wilson.co.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@kernel.org \
    --cc=mst@redhat.com \
    --cc=penguin-kernel@I-love.SAKURA.ne.jp \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).