linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] crypto: lzo: try kmalloc() before vmalloc()
@ 2014-05-27 17:28 Eric Dumazet
  2014-05-27 17:30 ` Herbert Xu
  2014-06-20 18:40 ` Herbert Xu
  0 siblings, 2 replies; 8+ messages in thread
From: Eric Dumazet @ 2014-05-27 17:28 UTC (permalink / raw)
  To: Herbert Xu, David S. Miller
  Cc: linux-crypto, linux-kernel@vger.kernel.org, Seth Jennings

From: Eric Dumazet <edumazet@google.com>

zswap allocates one LZO context per online cpu.

Using vmalloc() for small (16KB) memory areas has drawback of slowing
down /proc/vmallocinfo and /proc/meminfo reads, TLB pressure and poor
NUMA locality, as default NUMA policy at boot time is to interleave
pages :

edumazet:~# grep lzo /proc/vmallocinfo | head -4
0xffffc90006062000-0xffffc90006067000   20480 lzo_init+0x1b/0x30 pages=4 vmalloc N0=2 N1=2
0xffffc90006067000-0xffffc9000606c000   20480 lzo_init+0x1b/0x30 pages=4 vmalloc N0=2 N1=2
0xffffc9000606c000-0xffffc90006071000   20480 lzo_init+0x1b/0x30 pages=4 vmalloc N0=2 N1=2
0xffffc90006071000-0xffffc90006076000   20480 lzo_init+0x1b/0x30 pages=4 vmalloc N0=2 N1=2

This patch tries a regular kmalloc() and fallback to vmalloc in case
memory is too fragmented.

Signed-off-by: Eric Dumazet <edumazet@google.com>
---
 crypto/lzo.c |   11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/crypto/lzo.c b/crypto/lzo.c
index 1c2aa69c54b8..252e791d0ccc 100644
--- a/crypto/lzo.c
+++ b/crypto/lzo.c
@@ -20,6 +20,7 @@
 #include <linux/module.h>
 #include <linux/crypto.h>
 #include <linux/vmalloc.h>
+#include <linux/mm.h>
 #include <linux/lzo.h>
 
 struct lzo_ctx {
@@ -30,7 +31,10 @@ static int lzo_init(struct crypto_tfm *tfm)
 {
 	struct lzo_ctx *ctx = crypto_tfm_ctx(tfm);
 
-	ctx->lzo_comp_mem = vmalloc(LZO1X_MEM_COMPRESS);
+	ctx->lzo_comp_mem = kmalloc(LZO1X_MEM_COMPRESS,
+				    GFP_KERNEL | __GFP_NOWARN | __GFP_REPEAT);
+	if (!ctx->lzo_comp_mem)
+		ctx->lzo_comp_mem = vmalloc(LZO1X_MEM_COMPRESS);
 	if (!ctx->lzo_comp_mem)
 		return -ENOMEM;
 
@@ -41,7 +45,10 @@ static void lzo_exit(struct crypto_tfm *tfm)
 {
 	struct lzo_ctx *ctx = crypto_tfm_ctx(tfm);
 
-	vfree(ctx->lzo_comp_mem);
+	if (is_vmalloc_addr(ctx->lzo_comp_mem))
+		vfree(ctx->lzo_comp_mem);
+	else
+		kfree(ctx->lzo_comp_mem);
 }
 
 static int lzo_compress(struct crypto_tfm *tfm, const u8 *src,

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

* Re: [PATCH] crypto: lzo: try kmalloc() before vmalloc()
  2014-05-27 17:28 [PATCH] crypto: lzo: try kmalloc() before vmalloc() Eric Dumazet
@ 2014-05-27 17:30 ` Herbert Xu
  2014-05-27 17:38   ` Eric Dumazet
  2014-05-28 17:41   ` Eric Dumazet
  2014-06-20 18:40 ` Herbert Xu
  1 sibling, 2 replies; 8+ messages in thread
From: Herbert Xu @ 2014-05-27 17:30 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: David S. Miller, linux-crypto, linux-kernel@vger.kernel.org,
	Seth Jennings

On Tue, May 27, 2014 at 10:28:55AM -0700, Eric Dumazet wrote:
> From: Eric Dumazet <edumazet@google.com>
> 
> zswap allocates one LZO context per online cpu.
> 
> Using vmalloc() for small (16KB) memory areas has drawback of slowing
> down /proc/vmallocinfo and /proc/meminfo reads, TLB pressure and poor
> NUMA locality, as default NUMA policy at boot time is to interleave
> pages :
> 
> edumazet:~# grep lzo /proc/vmallocinfo | head -4
> 0xffffc90006062000-0xffffc90006067000   20480 lzo_init+0x1b/0x30 pages=4 vmalloc N0=2 N1=2
> 0xffffc90006067000-0xffffc9000606c000   20480 lzo_init+0x1b/0x30 pages=4 vmalloc N0=2 N1=2
> 0xffffc9000606c000-0xffffc90006071000   20480 lzo_init+0x1b/0x30 pages=4 vmalloc N0=2 N1=2
> 0xffffc90006071000-0xffffc90006076000   20480 lzo_init+0x1b/0x30 pages=4 vmalloc N0=2 N1=2
> 
> This patch tries a regular kmalloc() and fallback to vmalloc in case
> memory is too fragmented.
> 
> Signed-off-by: Eric Dumazet <edumazet@google.com>

Looks good to me.  This would seem like something that could be
generalised to other vmalloc users, no?

Thanks,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

* Re: [PATCH] crypto: lzo: try kmalloc() before vmalloc()
  2014-05-27 17:30 ` Herbert Xu
@ 2014-05-27 17:38   ` Eric Dumazet
  2014-05-28 17:41   ` Eric Dumazet
  1 sibling, 0 replies; 8+ messages in thread
From: Eric Dumazet @ 2014-05-27 17:38 UTC (permalink / raw)
  To: Herbert Xu
  Cc: David S. Miller, linux-crypto, linux-kernel@vger.kernel.org,
	Seth Jennings

On Wed, 2014-05-28 at 01:30 +0800, Herbert Xu wrote:

> Looks good to me.  This would seem like something that could be
> generalised to other vmalloc users, no?
> 

Yep, we have some spots where this is done, and we had attempts in the
past to get a generic allocator / deallocator but this went nowhere,
after a lot of time trying to get this right.

I guess we need to reach some threshold to convince Andrew Morton ;)

$ git grep -n is_vmalloc_addr | wc -l
85

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

* Re: [PATCH] crypto: lzo: try kmalloc() before vmalloc()
  2014-05-27 17:30 ` Herbert Xu
  2014-05-27 17:38   ` Eric Dumazet
@ 2014-05-28 17:41   ` Eric Dumazet
  2014-05-29 12:35     ` Herbert Xu
  1 sibling, 1 reply; 8+ messages in thread
From: Eric Dumazet @ 2014-05-28 17:41 UTC (permalink / raw)
  To: Herbert Xu; +Cc: David S. Miller, linux-crypto

On Wed, 2014-05-28 at 01:30 +0800, Herbert Xu wrote:

> Looks good to me.  This would seem like something that could be
> generalised to other vmalloc users, no?

BTW, any objections if I send patches to add NUMA allocations into
crypto layer, or was it already considered ?

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

* Re: [PATCH] crypto: lzo: try kmalloc() before vmalloc()
  2014-05-28 17:41   ` Eric Dumazet
@ 2014-05-29 12:35     ` Herbert Xu
  0 siblings, 0 replies; 8+ messages in thread
From: Herbert Xu @ 2014-05-29 12:35 UTC (permalink / raw)
  To: Eric Dumazet; +Cc: David S. Miller, linux-crypto

On Wed, May 28, 2014 at 10:41:20AM -0700, Eric Dumazet wrote:
> On Wed, 2014-05-28 at 01:30 +0800, Herbert Xu wrote:
> 
> > Looks good to me.  This would seem like something that could be
> > generalised to other vmalloc users, no?
> 
> BTW, any objections if I send patches to add NUMA allocations into
> crypto layer, or was it already considered ?

No please go ahead.

Thanks,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

* Re: [PATCH] crypto: lzo: try kmalloc() before vmalloc()
  2014-05-27 17:28 [PATCH] crypto: lzo: try kmalloc() before vmalloc() Eric Dumazet
  2014-05-27 17:30 ` Herbert Xu
@ 2014-06-20 18:40 ` Herbert Xu
  2014-06-24  8:23   ` [PATCH] crypto: lzo: use kvfree() helper Eric Dumazet
  1 sibling, 1 reply; 8+ messages in thread
From: Herbert Xu @ 2014-06-20 18:40 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: David S. Miller, linux-crypto, linux-kernel@vger.kernel.org,
	Seth Jennings

On Tue, May 27, 2014 at 10:28:55AM -0700, Eric Dumazet wrote:
> From: Eric Dumazet <edumazet@google.com>
> 
> zswap allocates one LZO context per online cpu.
> 
> Using vmalloc() for small (16KB) memory areas has drawback of slowing
> down /proc/vmallocinfo and /proc/meminfo reads, TLB pressure and poor
> NUMA locality, as default NUMA policy at boot time is to interleave
> pages :
> 
> edumazet:~# grep lzo /proc/vmallocinfo | head -4
> 0xffffc90006062000-0xffffc90006067000   20480 lzo_init+0x1b/0x30 pages=4 vmalloc N0=2 N1=2
> 0xffffc90006067000-0xffffc9000606c000   20480 lzo_init+0x1b/0x30 pages=4 vmalloc N0=2 N1=2
> 0xffffc9000606c000-0xffffc90006071000   20480 lzo_init+0x1b/0x30 pages=4 vmalloc N0=2 N1=2
> 0xffffc90006071000-0xffffc90006076000   20480 lzo_init+0x1b/0x30 pages=4 vmalloc N0=2 N1=2
> 
> This patch tries a regular kmalloc() and fallback to vmalloc in case
> memory is too fragmented.
> 
> Signed-off-by: Eric Dumazet <edumazet@google.com>

Patch applied.
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

* [PATCH] crypto: lzo: use kvfree() helper
  2014-06-20 18:40 ` Herbert Xu
@ 2014-06-24  8:23   ` Eric Dumazet
  2014-06-25 13:56     ` Herbert Xu
  0 siblings, 1 reply; 8+ messages in thread
From: Eric Dumazet @ 2014-06-24  8:23 UTC (permalink / raw)
  To: Herbert Xu; +Cc: David S. Miller, linux-crypto, Seth Jennings

From: Eric Dumazet <edumazet@google.com>

kvfree() helper is now available, use it instead of open code it.

Signed-off-by: Eric Dumazet <edumazet@google.com>
---
 crypto/lzo.c |    5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/crypto/lzo.c b/crypto/lzo.c
index 252e791d..a8ff2f7 100644
--- a/crypto/lzo.c
+++ b/crypto/lzo.c
@@ -45,10 +45,7 @@ static void lzo_exit(struct crypto_tfm *tfm)
 {
 	struct lzo_ctx *ctx = crypto_tfm_ctx(tfm);
 
-	if (is_vmalloc_addr(ctx->lzo_comp_mem))
-		vfree(ctx->lzo_comp_mem);
-	else
-		kfree(ctx->lzo_comp_mem);
+	kvfree(ctx->lzo_comp_mem);
 }
 
 static int lzo_compress(struct crypto_tfm *tfm, const u8 *src,

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

* Re: [PATCH] crypto: lzo: use kvfree() helper
  2014-06-24  8:23   ` [PATCH] crypto: lzo: use kvfree() helper Eric Dumazet
@ 2014-06-25 13:56     ` Herbert Xu
  0 siblings, 0 replies; 8+ messages in thread
From: Herbert Xu @ 2014-06-25 13:56 UTC (permalink / raw)
  To: Eric Dumazet; +Cc: David S. Miller, linux-crypto, Seth Jennings

On Tue, Jun 24, 2014 at 01:23:45AM -0700, Eric Dumazet wrote:
> From: Eric Dumazet <edumazet@google.com>
> 
> kvfree() helper is now available, use it instead of open code it.
> 
> Signed-off-by: Eric Dumazet <edumazet@google.com>

Patch applied.
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

end of thread, other threads:[~2014-06-25 13:56 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-27 17:28 [PATCH] crypto: lzo: try kmalloc() before vmalloc() Eric Dumazet
2014-05-27 17:30 ` Herbert Xu
2014-05-27 17:38   ` Eric Dumazet
2014-05-28 17:41   ` Eric Dumazet
2014-05-29 12:35     ` Herbert Xu
2014-06-20 18:40 ` Herbert Xu
2014-06-24  8:23   ` [PATCH] crypto: lzo: use kvfree() helper Eric Dumazet
2014-06-25 13:56     ` Herbert Xu

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