mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [RFC] ashmem: Fix ashmem shrinker nr_to_scan
@ 2020-03-06  1:19 Joel Fernandes (Google)
  2020-03-10 10:46 ` Dan Carpenter
  0 siblings, 1 reply; 2+ messages in thread
From: Joel Fernandes (Google) @ 2020-03-06  1:19 UTC (permalink / raw)
  To: linux-kernel
  Cc: Joel Fernandes (Google),
	surenb, Arve Hjønnevåg, Christian Brauner, devel,
	Greg Kroah-Hartman, Martijn Coenen, Todd Kjos

nr_to_scan is the number of pages to be freed however ashmem doesn't
discount nr_to_scan correctly as it frees ranges. It should be
discounting them by pages than by ranges. Correct the issue.

Cc: surenb@google.com
Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org>
---
 drivers/staging/android/ashmem.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/android/ashmem.c b/drivers/staging/android/ashmem.c
index 5891d0744a760..cb525ea6db98a 100644
--- a/drivers/staging/android/ashmem.c
+++ b/drivers/staging/android/ashmem.c
@@ -458,6 +458,8 @@ ashmem_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
 		lru_del(range);
 
 		freed += range_size(range);
+		sc->nr_to_scan -=  range_size(range);
+
 		mutex_unlock(&ashmem_mutex);
 		f->f_op->fallocate(f,
 				   FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
@@ -467,7 +469,7 @@ ashmem_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
 			wake_up_all(&ashmem_shrink_wait);
 		if (!mutex_trylock(&ashmem_mutex))
 			goto out;
-		if (--sc->nr_to_scan <= 0)
+		if (sc->nr_to_scan <= 0)
 			break;
 	}
 	mutex_unlock(&ashmem_mutex);
-- 
2.25.0.265.gbab2e86ba0-goog


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

* Re: [RFC] ashmem: Fix ashmem shrinker nr_to_scan
  2020-03-06  1:19 [RFC] ashmem: Fix ashmem shrinker nr_to_scan Joel Fernandes (Google)
@ 2020-03-10 10:46 ` Dan Carpenter
  0 siblings, 0 replies; 2+ messages in thread
From: Dan Carpenter @ 2020-03-10 10:46 UTC (permalink / raw)
  To: Joel Fernandes (Google)
  Cc: linux-kernel, devel, Todd Kjos, Greg Kroah-Hartman,
	Arve Hjønnevåg, Martijn Coenen, surenb,
	Christian Brauner

On Thu, Mar 05, 2020 at 08:19:30PM -0500, Joel Fernandes (Google) wrote:
> nr_to_scan is the number of pages to be freed however ashmem doesn't
> discount nr_to_scan correctly as it frees ranges. It should be
> discounting them by pages than by ranges. Correct the issue.
> 
> Cc: surenb@google.com
> Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org>
> ---
>  drivers/staging/android/ashmem.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/android/ashmem.c b/drivers/staging/android/ashmem.c
> index 5891d0744a760..cb525ea6db98a 100644
> --- a/drivers/staging/android/ashmem.c
> +++ b/drivers/staging/android/ashmem.c
> @@ -458,6 +458,8 @@ ashmem_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
>  		lru_del(range);
>  
>  		freed += range_size(range);
> +		sc->nr_to_scan -=  range_size(range);
                                 ^^
Two space characters.

In the old code we didn't *really* have to worry about sc->nr_to_scan
dropping to negative, but now we do.  ->nr_to_scan is unsigned so it
would be a high positive value now so it's maybe a forever loop?  I'm
too lazy to verify...

regards,
dan carpenter

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

end of thread, other threads:[~2020-03-10 10:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-06  1:19 [RFC] ashmem: Fix ashmem shrinker nr_to_scan Joel Fernandes (Google)
2020-03-10 10:46 ` Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®