All of lore.kernel.org
 help / color / mirror / Atom feed
From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
To: Akinobu Mita <akinobu.mita@gmail.com>
Cc: linux-kernel@vger.kernel.org, akpm@linux-foundation.org,
	linux-mm@kvack.org
Subject: Re: [PATCH] frontswap: fix incorrect zeroing and allocation size for frontswap_map
Date: Mon, 3 Jun 2013 08:36:34 -0400	[thread overview]
Message-ID: <20130603123634.GE6893@phenom.dumpdata.com> (raw)
In-Reply-To: <1370130777-6707-1-git-send-email-akinobu.mita@gmail.com>

On Sun, Jun 02, 2013 at 08:52:57AM +0900, Akinobu Mita wrote:
> The bitmap accessed by bitops must have enough size to hold the required
> numbers of bits rounded up to a multiple of BITS_PER_LONG.  And the bitmap
> must not be zeroed by memset() if the number of bits cleared is not
> a multiple of BITS_PER_LONG.
> 
> This fixes incorrect zeroing and allocation size for frontswap_map.
> The incorrect zeroing part doesn't cause any problem because
> frontswap_map is freed just after zeroing.  But the wrongly calculated
> allocation size may cause the problem.
> 
> For 32bit systems, the allocation size of frontswap_map is about twice as
> large as required size.  For 64bit systems, the allocation size is smaller
> than requeired if the number of bits is not a multiple of BITS_PER_LONG.
       ^^^^^^^^^
       required.

Looks OK to me. Thanks for catching this. I will test it out and if it
does not break any regression tests should go for the next rc.

Thanks!
> 
> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
> Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> ---
>  mm/frontswap.c | 2 +-
>  mm/swapfile.c  | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/mm/frontswap.c b/mm/frontswap.c
> index 538367e..1b24bdc 100644
> --- a/mm/frontswap.c
> +++ b/mm/frontswap.c
> @@ -319,7 +319,7 @@ void __frontswap_invalidate_area(unsigned type)
>  			return;
>  		frontswap_ops->invalidate_area(type);
>  		atomic_set(&sis->frontswap_pages, 0);
> -		memset(sis->frontswap_map, 0, sis->max / sizeof(long));
> +		bitmap_zero(sis->frontswap_map, sis->max);
>  	}
>  	clear_bit(type, need_init);
>  }
> diff --git a/mm/swapfile.c b/mm/swapfile.c
> index 6c340d9..746af55b 100644
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
> @@ -2116,7 +2116,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
>  	}
>  	/* frontswap enabled? set up bit-per-page map for frontswap */
>  	if (frontswap_enabled)
> -		frontswap_map = vzalloc(maxpages / sizeof(long));
> +		frontswap_map = vzalloc(BITS_TO_LONGS(maxpages) * sizeof(long));
>  
>  	if (p->bdev) {
>  		if (blk_queue_nonrot(bdev_get_queue(p->bdev))) {
> -- 
> 1.8.1.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>

WARNING: multiple messages have this Message-ID (diff)
From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
To: Akinobu Mita <akinobu.mita@gmail.com>
Cc: linux-kernel@vger.kernel.org, akpm@linux-foundation.org,
	linux-mm@kvack.org
Subject: Re: [PATCH] frontswap: fix incorrect zeroing and allocation size for frontswap_map
Date: Mon, 3 Jun 2013 08:36:34 -0400	[thread overview]
Message-ID: <20130603123634.GE6893@phenom.dumpdata.com> (raw)
In-Reply-To: <1370130777-6707-1-git-send-email-akinobu.mita@gmail.com>

On Sun, Jun 02, 2013 at 08:52:57AM +0900, Akinobu Mita wrote:
> The bitmap accessed by bitops must have enough size to hold the required
> numbers of bits rounded up to a multiple of BITS_PER_LONG.  And the bitmap
> must not be zeroed by memset() if the number of bits cleared is not
> a multiple of BITS_PER_LONG.
> 
> This fixes incorrect zeroing and allocation size for frontswap_map.
> The incorrect zeroing part doesn't cause any problem because
> frontswap_map is freed just after zeroing.  But the wrongly calculated
> allocation size may cause the problem.
> 
> For 32bit systems, the allocation size of frontswap_map is about twice as
> large as required size.  For 64bit systems, the allocation size is smaller
> than requeired if the number of bits is not a multiple of BITS_PER_LONG.
       ^^^^^^^^^
       required.

Looks OK to me. Thanks for catching this. I will test it out and if it
does not break any regression tests should go for the next rc.

Thanks!
> 
> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
> Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> ---
>  mm/frontswap.c | 2 +-
>  mm/swapfile.c  | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/mm/frontswap.c b/mm/frontswap.c
> index 538367e..1b24bdc 100644
> --- a/mm/frontswap.c
> +++ b/mm/frontswap.c
> @@ -319,7 +319,7 @@ void __frontswap_invalidate_area(unsigned type)
>  			return;
>  		frontswap_ops->invalidate_area(type);
>  		atomic_set(&sis->frontswap_pages, 0);
> -		memset(sis->frontswap_map, 0, sis->max / sizeof(long));
> +		bitmap_zero(sis->frontswap_map, sis->max);
>  	}
>  	clear_bit(type, need_init);
>  }
> diff --git a/mm/swapfile.c b/mm/swapfile.c
> index 6c340d9..746af55b 100644
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
> @@ -2116,7 +2116,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
>  	}
>  	/* frontswap enabled? set up bit-per-page map for frontswap */
>  	if (frontswap_enabled)
> -		frontswap_map = vzalloc(maxpages / sizeof(long));
> +		frontswap_map = vzalloc(BITS_TO_LONGS(maxpages) * sizeof(long));
>  
>  	if (p->bdev) {
>  		if (blk_queue_nonrot(bdev_get_queue(p->bdev))) {
> -- 
> 1.8.1.4
> 

  reply	other threads:[~2013-06-03 12:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-01 23:52 [PATCH] frontswap: fix incorrect zeroing and allocation size for frontswap_map Akinobu Mita
2013-06-01 23:52 ` Akinobu Mita
2013-06-03 12:36 ` Konrad Rzeszutek Wilk [this message]
2013-06-03 12:36   ` Konrad Rzeszutek Wilk

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=20130603123634.GE6893@phenom.dumpdata.com \
    --to=konrad.wilk@oracle.com \
    --cc=akinobu.mita@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.