linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] swap: Avoid scanning invalidated region for cheap seek
@ 2014-05-26  2:00 Chen Yucong
  2014-05-28  3:53 ` Hugh Dickins
  0 siblings, 1 reply; 3+ messages in thread
From: Chen Yucong @ 2014-05-26  2:00 UTC (permalink / raw)
  To: akpm
  Cc: ddstreet, mgorman, hughd, shli, k.kozlowski, linux-mm,
	linux-kernel, Chen Yucong

For cheap seek, when we scan the region between si->lowset_bit
and scan_base, if san_base is greater than si->highest_bit, the
scan operation between si->highest_bit and scan_base is not
unnecessary.

This patch can be used to avoid scanning invalidated region for
cheap seek.

Signed-off-by: Chen Yucong <slaoub@gmail.com>
---
 mm/swapfile.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/mm/swapfile.c b/mm/swapfile.c
index beeeef8..7f0f27e 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -489,6 +489,7 @@ static unsigned long scan_swap_map(struct swap_info_struct *si,
 {
 	unsigned long offset;
 	unsigned long scan_base;
+	unsigned long upper_bound;
 	unsigned long last_in_cluster = 0;
 	int latency_ration = LATENCY_LIMIT;
 
@@ -551,9 +552,11 @@ static unsigned long scan_swap_map(struct swap_info_struct *si,
 
 		offset = si->lowest_bit;
 		last_in_cluster = offset + SWAPFILE_CLUSTER - 1;
+		upper_bound = (scan_base <= si->highest_bit) ?
+				scan_base : (si->highest_bit + 1);
 
 		/* Locate the first empty (unaligned) cluster */
-		for (; last_in_cluster < scan_base; offset++) {
+		for (; last_in_cluster < upper_bound; offset++) {
 			if (si->swap_map[offset])
 				last_in_cluster = offset + SWAPFILE_CLUSTER;
 			else if (offset == last_in_cluster) {
-- 
1.7.10.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>

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] swap: Avoid scanning invalidated region for cheap seek
  2014-05-26  2:00 [PATCH] swap: Avoid scanning invalidated region for cheap seek Chen Yucong
@ 2014-05-28  3:53 ` Hugh Dickins
  2014-05-30  7:41   ` Shaohua Li
  0 siblings, 1 reply; 3+ messages in thread
From: Hugh Dickins @ 2014-05-28  3:53 UTC (permalink / raw)
  To: Chen Yucong
  Cc: Shaohua Li, akpm, ddstreet, mgorman, k.kozlowski, linux-mm,
	linux-kernel

On Mon, 26 May 2014, Chen Yucong wrote:

> For cheap seek, when we scan the region between si->lowset_bit
> and scan_base, if san_base is greater than si->highest_bit, the
> scan operation between si->highest_bit and scan_base is not
> unnecessary.
> 
> This patch can be used to avoid scanning invalidated region for
> cheap seek.
> 
> Signed-off-by: Chen Yucong <slaoub@gmail.com>

I was going to suggest that you are adding a little code to a common
path, in order to optimize a very unlikely case: which does not seem
worthwhile to me.

But digging a little deeper, I think you have hit upon something more
interesting (though still in no need of your patch): it looks to me
like that is not even a common path, but dead code.

Shaohua, am I missing something, or does all SWP_SOLIDSTATE "seek is
cheap" now go your si->cluster_info scan_swap_map_try_ssd_cluster()
route?  So that the "last_in_cluster < scan_base" loop in the body
of scan_swap_map() is just redundant, and should have been deleted?

Hugh

> ---
>  mm/swapfile.c |    5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/mm/swapfile.c b/mm/swapfile.c
> index beeeef8..7f0f27e 100644
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
> @@ -489,6 +489,7 @@ static unsigned long scan_swap_map(struct swap_info_struct *si,
>  {
>  	unsigned long offset;
>  	unsigned long scan_base;
> +	unsigned long upper_bound;
>  	unsigned long last_in_cluster = 0;
>  	int latency_ration = LATENCY_LIMIT;
>  
> @@ -551,9 +552,11 @@ static unsigned long scan_swap_map(struct swap_info_struct *si,
>  
>  		offset = si->lowest_bit;
>  		last_in_cluster = offset + SWAPFILE_CLUSTER - 1;
> +		upper_bound = (scan_base <= si->highest_bit) ?
> +				scan_base : (si->highest_bit + 1);
>  
>  		/* Locate the first empty (unaligned) cluster */
> -		for (; last_in_cluster < scan_base; offset++) {
> +		for (; last_in_cluster < upper_bound; offset++) {
>  			if (si->swap_map[offset])
>  				last_in_cluster = offset + SWAPFILE_CLUSTER;
>  			else if (offset == last_in_cluster) {
> -- 
> 1.7.10.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>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] swap: Avoid scanning invalidated region for cheap seek
  2014-05-28  3:53 ` Hugh Dickins
@ 2014-05-30  7:41   ` Shaohua Li
  0 siblings, 0 replies; 3+ messages in thread
From: Shaohua Li @ 2014-05-30  7:41 UTC (permalink / raw)
  To: Hugh Dickins
  Cc: Chen Yucong, akpm, ddstreet, mgorman, k.kozlowski, linux-mm,
	linux-kernel

On Tue, May 27, 2014 at 08:53:00PM -0700, Hugh Dickins wrote:
> On Mon, 26 May 2014, Chen Yucong wrote:
> 
> > For cheap seek, when we scan the region between si->lowset_bit
> > and scan_base, if san_base is greater than si->highest_bit, the
> > scan operation between si->highest_bit and scan_base is not
> > unnecessary.
> > 
> > This patch can be used to avoid scanning invalidated region for
> > cheap seek.
> > 
> > Signed-off-by: Chen Yucong <slaoub@gmail.com>
> 
> I was going to suggest that you are adding a little code to a common
> path, in order to optimize a very unlikely case: which does not seem
> worthwhile to me.
> 
> But digging a little deeper, I think you have hit upon something more
> interesting (though still in no need of your patch): it looks to me
> like that is not even a common path, but dead code.
> 
> Shaohua, am I missing something, or does all SWP_SOLIDSTATE "seek is
> cheap" now go your si->cluster_info scan_swap_map_try_ssd_cluster()
> route?  So that the "last_in_cluster < scan_base" loop in the body
> of scan_swap_map() is just redundant, and should have been deleted?

Sorry for the delay, you are right. SSD case always goes
scan_swap_map_try_ssd_cluster, otherwise we just scan from lowest_bit to
highest_bit, so the "last_in_cluster < scan_base" loop is dead.

Yucong, can you resent a patch to delete it as Hugh suggested?

Thanks,
Shaohua

--
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>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-05-30  7:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-26  2:00 [PATCH] swap: Avoid scanning invalidated region for cheap seek Chen Yucong
2014-05-28  3:53 ` Hugh Dickins
2014-05-30  7:41   ` Shaohua Li

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).