[vz7,2/2] relay: use kvzalloc for rchan structure allocation

Submitted by Oleg Babin on May 8, 2018, 12:30 p.m.

Details

Message ID 1525782633-61768-1-git-send-email-obabin@virtuozzo.com
State New
Series "Series without cover letter"
Headers show

Commit Message

Oleg Babin May 8, 2018, 12:30 p.m.
Size of rchan structure depends on NR_CPUS definition which can be
configured by the user and can become quite large.

E.g. if NR_CPUS equals to 5120 (real world scenario) then it makes
sizeof(struct rchan) == 41320 meaning the 4th memory order.

Use kvmalloc() for rchan structure allocation to fallback to vmalloc()
in case of high order page is not available at the moment.

https://jira.sw.ru/browse/HCI-53
Signed-off-by: Oleg Babin <obabin@virtuozzo.com>
---
 kernel/relay.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/kernel/relay.c b/kernel/relay.c
index 1b2a7dc4..6311d79 100644
--- a/kernel/relay.c
+++ b/kernel/relay.c
@@ -199,7 +199,7 @@  free_buf:
 static void relay_destroy_channel(struct kref *kref)
 {
 	struct rchan *chan = container_of(kref, struct rchan, kref);
-	kfree(chan);
+	kvfree(chan);
 }
 
 /**
@@ -592,7 +592,7 @@  struct rchan *relay_open(const char *base_filename,
 	if (subbuf_size > UINT_MAX / n_subbufs)
 		return NULL;
 
-	chan = kzalloc(sizeof(struct rchan), GFP_KERNEL);
+	chan = kvzalloc(sizeof(struct rchan), GFP_KERNEL);
 	if (!chan)
 		return NULL;
 

Comments

Andrey Ryabinin May 8, 2018, 12:50 p.m.
On 05/08/2018 03:30 PM, Oleg Babin wrote:
> Size of rchan structure depends on NR_CPUS definition which can be
> configured by the user and can become quite large.
> 
> E.g. if NR_CPUS equals to 5120 (real world scenario) then it makes
> sizeof(struct rchan) == 41320 meaning the 4th memory order.
> 
> Use kvmalloc() for rchan structure allocation to fallback to vmalloc()
> in case of high order page is not available at the moment.
> 
> https://jira.sw.ru/browse/HCI-53
> Signed-off-by: Oleg Babin <obabin@virtuozzo.com>
> ---


017c59c042d01fc84cae7a8ea475861e702c77ab
Author: Akash Goel <akash.goel@intel.com>
Date:   Fri Sep 2 21:47:38 2016 +0200

    relay: Use per CPU constructs for the relay channel buffer pointers
    
    relay essentially needs to maintain a per CPU array of channel buffer
    pointers but it manually creates that array.  Instead its better to use
    the per CPU constructs, provided by the kernel, to allocate & access the
    array of pointer to channel buffers.
    
    Signed-off-by: Akash Goel <akash.goel@intel.com>
    Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
    Link: http://lkml.kernel.org/r/1470909140-25919-1-git-send-email-akash.goel@intel.com
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>