linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Jiang Biao <jiang.biao2@zte.com.cn>
To: akpm@linux-foundation.org, mhocko@suse.com, hannes@cmpxchg.org,
	hillf.zj@alibaba-inc.com, minchan@kernel.org,
	ying.huang@intel.com, mgorman@techsingularity.net
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	jiang.biao2@zte.com.cn, zhong.weidong@zte.com.cn
Subject: [PATCH] mm/vmscan: try to optimize branch procedures.
Date: Tue, 28 Nov 2017 09:49:45 +0800	[thread overview]
Message-ID: <1511833785-55392-1-git-send-email-jiang.biao2@zte.com.cn> (raw)

1. Use unlikely to try to improve branch prediction. The
*total_scan < 0* branch is unlikely to reach, so use unlikely.

2. Optimize *next_deferred >= scanned* condition.
*next_deferred >= scanned* condition could be optimized into
*next_deferred > scanned*, because when *next_deferred == scanned*,
next_deferred shoud be 0, which is covered by the else branch.

3. Merge two branch blocks into one. The *next_deferred > 0* branch
could be merged into *next_deferred > scanned* to simplify the code.

Signed-off-by: Jiang Biao <jiang.biao2@zte.com.cn>
---
 mm/vmscan.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/mm/vmscan.c b/mm/vmscan.c
index eb2f031..5f5d4ab 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -338,7 +338,7 @@ static unsigned long do_shrink_slab(struct shrink_control *shrinkctl,
 	delta *= freeable;
 	do_div(delta, nr_eligible + 1);
 	total_scan += delta;
-	if (total_scan < 0) {
+	if (unlikely(total_scan < 0)) {
 		pr_err("shrink_slab: %pF negative objects to delete nr=%ld\n",
 		       shrinker->scan_objects, total_scan);
 		total_scan = freeable;
@@ -407,18 +407,16 @@ static unsigned long do_shrink_slab(struct shrink_control *shrinkctl,
 		cond_resched();
 	}
 
-	if (next_deferred >= scanned)
-		next_deferred -= scanned;
-	else
-		next_deferred = 0;
 	/*
 	 * move the unused scan count back into the shrinker in a
 	 * manner that handles concurrent updates. If we exhausted the
 	 * scan, there is no need to do an update.
 	 */
-	if (next_deferred > 0)
+	if (next_deferred > scanned) {
+		next_deferred -= scanned;
 		new_nr = atomic_long_add_return(next_deferred,
 						&shrinker->nr_deferred[nid]);
+	}
 	else
 		new_nr = atomic_long_read(&shrinker->nr_deferred[nid]);
 
-- 
2.7.4

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

             reply	other threads:[~2017-11-28  1:53 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-28  1:49 Jiang Biao [this message]
2017-11-28  8:03 ` Michal Hocko
2017-11-28  9:19   ` jiang.biao2
2017-11-28  9:31     ` Michal Hocko
2017-11-28  9:46     ` Mel Gorman
2017-11-28  9:40 ` Mel Gorman

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=1511833785-55392-1-git-send-email-jiang.biao2@zte.com.cn \
    --to=jiang.biao2@zte.com.cn \
    --cc=akpm@linux-foundation.org \
    --cc=hannes@cmpxchg.org \
    --cc=hillf.zj@alibaba-inc.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mgorman@techsingularity.net \
    --cc=mhocko@suse.com \
    --cc=minchan@kernel.org \
    --cc=ying.huang@intel.com \
    --cc=zhong.weidong@zte.com.cn \
    /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