* [PATCH] scsi: libcxgbi: use kvzalloc instead of opencoded kzalloc/vzalloc @ 2020-07-31 21:55 Denis Efremov 2020-07-31 21:58 ` Joe Perches 2020-08-01 13:31 ` [PATCH v2] " Denis Efremov 0 siblings, 2 replies; 12+ messages in thread From: Denis Efremov @ 2020-07-31 21:55 UTC (permalink / raw) To: Martin K. Petersen, James E.J. Bottomley Cc: Denis Efremov, linux-scsi, linux-kernel Remove cxgbi_alloc_big_mem(), cxgbi_free_big_mem() functions and use kvzalloc/kvfree instead. Signed-off-by: Denis Efremov <efremov@linux.com> --- drivers/scsi/cxgbi/libcxgbi.c | 8 ++++---- drivers/scsi/cxgbi/libcxgbi.h | 16 ---------------- 2 files changed, 4 insertions(+), 20 deletions(-) diff --git a/drivers/scsi/cxgbi/libcxgbi.c b/drivers/scsi/cxgbi/libcxgbi.c index 4bc794d2f51c..a98b870eb1f3 100644 --- a/drivers/scsi/cxgbi/libcxgbi.c +++ b/drivers/scsi/cxgbi/libcxgbi.c @@ -77,9 +77,9 @@ int cxgbi_device_portmap_create(struct cxgbi_device *cdev, unsigned int base, { struct cxgbi_ports_map *pmap = &cdev->pmap; - pmap->port_csk = cxgbi_alloc_big_mem(max_conn * - sizeof(struct cxgbi_sock *), - GFP_KERNEL); + pmap->port_csk = kvzalloc(array_size(max_conn, + sizeof(struct cxgbi_sock *)), + GFP_KERNEL); if (!pmap->port_csk) { pr_warn("cdev 0x%p, portmap OOM %u.\n", cdev, max_conn); return -ENOMEM; @@ -124,7 +124,7 @@ static inline void cxgbi_device_destroy(struct cxgbi_device *cdev) if (cdev->cdev2ppm) cxgbi_ppm_release(cdev->cdev2ppm(cdev)); if (cdev->pmap.max_connect) - cxgbi_free_big_mem(cdev->pmap.port_csk); + kvfree(cdev->pmap.port_csk); kfree(cdev); } diff --git a/drivers/scsi/cxgbi/libcxgbi.h b/drivers/scsi/cxgbi/libcxgbi.h index 84b96af52655..321426242be4 100644 --- a/drivers/scsi/cxgbi/libcxgbi.h +++ b/drivers/scsi/cxgbi/libcxgbi.h @@ -537,22 +537,6 @@ struct cxgbi_task_data { #define iscsi_task_cxgbi_data(task) \ ((task)->dd_data + sizeof(struct iscsi_tcp_task)) -static inline void *cxgbi_alloc_big_mem(unsigned int size, - gfp_t gfp) -{ - void *p = kzalloc(size, gfp | __GFP_NOWARN); - - if (!p) - p = vzalloc(size); - - return p; -} - -static inline void cxgbi_free_big_mem(void *addr) -{ - kvfree(addr); -} - static inline void cxgbi_set_iscsi_ipv4(struct cxgbi_hba *chba, __be32 ipaddr) { if (chba->cdev->flags & CXGBI_FLAG_IPV4_SET) -- 2.26.2 ^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH] scsi: libcxgbi: use kvzalloc instead of opencoded kzalloc/vzalloc 2020-07-31 21:55 [PATCH] scsi: libcxgbi: use kvzalloc instead of opencoded kzalloc/vzalloc Denis Efremov @ 2020-07-31 21:58 ` Joe Perches 2020-07-31 22:10 ` Denis Efremov 2020-08-01 13:31 ` [PATCH v2] " Denis Efremov 1 sibling, 1 reply; 12+ messages in thread From: Joe Perches @ 2020-07-31 21:58 UTC (permalink / raw) To: Denis Efremov, Martin K. Petersen, James E.J. Bottomley Cc: linux-scsi, linux-kernel On Sat, 2020-08-01 at 00:55 +0300, Denis Efremov wrote: > Remove cxgbi_alloc_big_mem(), cxgbi_free_big_mem() functions > and use kvzalloc/kvfree instead. Sensible, thanks. > diff --git a/drivers/scsi/cxgbi/libcxgbi.c b/drivers/scsi/cxgbi/libcxgbi.c [] > @@ -77,9 +77,9 @@ int cxgbi_device_portmap_create(struct cxgbi_device *cdev, unsigned int base, > { > struct cxgbi_ports_map *pmap = &cdev->pmap; > > - pmap->port_csk = cxgbi_alloc_big_mem(max_conn * > - sizeof(struct cxgbi_sock *), > - GFP_KERNEL); > + pmap->port_csk = kvzalloc(array_size(max_conn, > + sizeof(struct cxgbi_sock *)), > + GFP_KERNEL); missing __GFP_NOWARN > diff --git a/drivers/scsi/cxgbi/libcxgbi.h b/drivers/scsi/cxgbi/libcxgbi.h [] > @@ -537,22 +537,6 @@ struct cxgbi_task_data { > #define iscsi_task_cxgbi_data(task) \ > ((task)->dd_data + sizeof(struct iscsi_tcp_task)) > > -static inline void *cxgbi_alloc_big_mem(unsigned int size, > - gfp_t gfp) > -{ > - void *p = kzalloc(size, gfp | __GFP_NOWARN); ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] scsi: libcxgbi: use kvzalloc instead of opencoded kzalloc/vzalloc 2020-07-31 21:58 ` Joe Perches @ 2020-07-31 22:10 ` Denis Efremov 2020-07-31 22:24 ` Joe Perches 0 siblings, 1 reply; 12+ messages in thread From: Denis Efremov @ 2020-07-31 22:10 UTC (permalink / raw) To: Joe Perches, Martin K. Petersen, James E.J. Bottomley Cc: linux-scsi, linux-kernel On 8/1/20 12:58 AM, Joe Perches wrote: > On Sat, 2020-08-01 at 00:55 +0300, Denis Efremov wrote: >> Remove cxgbi_alloc_big_mem(), cxgbi_free_big_mem() functions >> and use kvzalloc/kvfree instead. > > Sensible, thanks. > >> diff --git a/drivers/scsi/cxgbi/libcxgbi.c b/drivers/scsi/cxgbi/libcxgbi.c > [] >> @@ -77,9 +77,9 @@ int cxgbi_device_portmap_create(struct cxgbi_device *cdev, unsigned int base, >> { >> struct cxgbi_ports_map *pmap = &cdev->pmap; >> >> - pmap->port_csk = cxgbi_alloc_big_mem(max_conn * >> - sizeof(struct cxgbi_sock *), >> - GFP_KERNEL); >> + pmap->port_csk = kvzalloc(array_size(max_conn, >> + sizeof(struct cxgbi_sock *)), >> + GFP_KERNEL); > > missing __GFP_NOWARN > kvmalloc_node adds __GFP_NOWARN internally to kmalloc call https://elixir.bootlin.com/linux/v5.8-rc4/source/mm/util.c#L568 Thanks, Denis ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] scsi: libcxgbi: use kvzalloc instead of opencoded kzalloc/vzalloc 2020-07-31 22:10 ` Denis Efremov @ 2020-07-31 22:24 ` Joe Perches 2020-08-01 7:51 ` Denis Efremov 0 siblings, 1 reply; 12+ messages in thread From: Joe Perches @ 2020-07-31 22:24 UTC (permalink / raw) To: Denis Efremov, Martin K. Petersen, James E.J. Bottomley Cc: linux-scsi, linux-kernel On Sat, 2020-08-01 at 01:10 +0300, Denis Efremov wrote: > > On 8/1/20 12:58 AM, Joe Perches wrote: > > On Sat, 2020-08-01 at 00:55 +0300, Denis Efremov wrote: > > > Remove cxgbi_alloc_big_mem(), cxgbi_free_big_mem() functions > > > and use kvzalloc/kvfree instead. > > > > Sensible, thanks. > > > > > diff --git a/drivers/scsi/cxgbi/libcxgbi.c b/drivers/scsi/cxgbi/libcxgbi.c > > [] > > > @@ -77,9 +77,9 @@ int cxgbi_device_portmap_create(struct cxgbi_device *cdev, unsigned int base, > > > { > > > struct cxgbi_ports_map *pmap = &cdev->pmap; > > > > > > - pmap->port_csk = cxgbi_alloc_big_mem(max_conn * > > > - sizeof(struct cxgbi_sock *), > > > - GFP_KERNEL); > > > + pmap->port_csk = kvzalloc(array_size(max_conn, > > > + sizeof(struct cxgbi_sock *)), > > > + GFP_KERNEL); > > > > missing __GFP_NOWARN > > > > kvmalloc_node adds __GFP_NOWARN internally to kmalloc call > https://elixir.bootlin.com/linux/v5.8-rc4/source/mm/util.c#L568 Only when there's a fallback, and the fallback does not. ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] scsi: libcxgbi: use kvzalloc instead of opencoded kzalloc/vzalloc 2020-07-31 22:24 ` Joe Perches @ 2020-08-01 7:51 ` Denis Efremov 2020-08-01 7:58 ` Denis Efremov 2020-08-01 8:10 ` Joe Perches 0 siblings, 2 replies; 12+ messages in thread From: Denis Efremov @ 2020-08-01 7:51 UTC (permalink / raw) To: Joe Perches, Martin K. Petersen, James E.J. Bottomley Cc: linux-scsi, linux-kernel On 8/1/20 1:24 AM, Joe Perches wrote: > On Sat, 2020-08-01 at 01:10 +0300, Denis Efremov wrote: >> >> On 8/1/20 12:58 AM, Joe Perches wrote: >>> On Sat, 2020-08-01 at 00:55 +0300, Denis Efremov wrote: >>>> Remove cxgbi_alloc_big_mem(), cxgbi_free_big_mem() functions >>>> and use kvzalloc/kvfree instead. >>> >>> Sensible, thanks. >>> >>>> diff --git a/drivers/scsi/cxgbi/libcxgbi.c b/drivers/scsi/cxgbi/libcxgbi.c >>> [] >>>> @@ -77,9 +77,9 @@ int cxgbi_device_portmap_create(struct cxgbi_device *cdev, unsigned int base, >>>> { >>>> struct cxgbi_ports_map *pmap = &cdev->pmap; >>>> >>>> - pmap->port_csk = cxgbi_alloc_big_mem(max_conn * >>>> - sizeof(struct cxgbi_sock *), >>>> - GFP_KERNEL); >>>> + pmap->port_csk = kvzalloc(array_size(max_conn, >>>> + sizeof(struct cxgbi_sock *)), >>>> + GFP_KERNEL); >>> >>> missing __GFP_NOWARN >>> >> >> kvmalloc_node adds __GFP_NOWARN internally to kmalloc call >> https://elixir.bootlin.com/linux/v5.8-rc4/source/mm/util.c#L568 > > Only when there's a fallback, and the fallback does not. > Sorry, Joe, I don't understand why do we need to add __GFP_NOWARN here. We use GFP_KERNEL for allocation. cxgbi_alloc_big_mem adds __GFP_NOWARN only to kzalloc(). kvzalloc is: kvmalloc(size, flags | __GFP_ZERO) kvmalloc is: kvmalloc_node(size, flags, NUMA_NO_NODE) kvmalloc_node: if ((flags & GFP_KERNEL) != GFP_KERNEL) // false, flags == GFP_KERNEL|__GFP_ZERO return kmalloc_node(size, flags, node); if (size > PAGE_SIZE) { kmalloc_flags |= __GFP_NOWARN; // add __GFP_NOWARN for "big" allocations if (!(kmalloc_flags & __GFP_RETRY_MAYFAIL)) kmalloc_flags |= __GFP_NORETRY; } // kmalloc_flags == GFP_KERNEL|__GFP_ZERO|__GFP_NOWARN if size > PAGE_SIZE ret = kmalloc_node(size, kmalloc_flags, node); if (ret || size <= PAGE_SIZE) return ret; // flags == GFP_KERNEL|__GFP_ZERO return __vmalloc_node(size, 1, flags, node, __builtin_return_address(0)); So, to my understanding the difference is only that cxgbi_alloc_big_mem adds __GFP_NOWARN to kzalloc unconditionally, kvzalloc adds __GFP_NOWARN to kmalloc_node if size > PAGE_SIZE. We use: max_conn * sizeof(struct cxgbi_sock *) in allocation. max_conn can be either CXGBI_MAX_CONN or CXGB4I_MAX_CONN. CXGBI_MAX_CONN == 16384, CXGB4I_MAX_CONN == 16384. Thus the allocation is bigger than PAGE_SIZE and kvmalloc_node adds __GFP_NOWARN to the kmalloc_node call. Maybe I missed something? Thanks, Denis ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] scsi: libcxgbi: use kvzalloc instead of opencoded kzalloc/vzalloc 2020-08-01 7:51 ` Denis Efremov @ 2020-08-01 7:58 ` Denis Efremov 2020-08-01 8:10 ` Joe Perches 1 sibling, 0 replies; 12+ messages in thread From: Denis Efremov @ 2020-08-01 7:58 UTC (permalink / raw) To: Joe Perches, Martin K. Petersen, James E.J. Bottomley Cc: linux-scsi, linux-kernel On 8/1/20 10:51 AM, Denis Efremov wrote: > > > On 8/1/20 1:24 AM, Joe Perches wrote: >> On Sat, 2020-08-01 at 01:10 +0300, Denis Efremov wrote: >>> >>> On 8/1/20 12:58 AM, Joe Perches wrote: >>>> On Sat, 2020-08-01 at 00:55 +0300, Denis Efremov wrote: >>>>> Remove cxgbi_alloc_big_mem(), cxgbi_free_big_mem() functions >>>>> and use kvzalloc/kvfree instead. >>>> >>>> Sensible, thanks. >>>> >>>>> diff --git a/drivers/scsi/cxgbi/libcxgbi.c b/drivers/scsi/cxgbi/libcxgbi.c >>>> [] >>>>> @@ -77,9 +77,9 @@ int cxgbi_device_portmap_create(struct cxgbi_device *cdev, unsigned int base, >>>>> { >>>>> struct cxgbi_ports_map *pmap = &cdev->pmap; >>>>> >>>>> - pmap->port_csk = cxgbi_alloc_big_mem(max_conn * >>>>> - sizeof(struct cxgbi_sock *), >>>>> - GFP_KERNEL); >>>>> + pmap->port_csk = kvzalloc(array_size(max_conn, >>>>> + sizeof(struct cxgbi_sock *)), >>>>> + GFP_KERNEL); >>>> >>>> missing __GFP_NOWARN >>>> >>> >>> kvmalloc_node adds __GFP_NOWARN internally to kmalloc call >>> https://elixir.bootlin.com/linux/v5.8-rc4/source/mm/util.c#L568 >> >> Only when there's a fallback, and the fallback does not. >> > > Sorry, Joe, I don't understand why do we need to add __GFP_NOWARN here. > > We use GFP_KERNEL for allocation. cxgbi_alloc_big_mem adds __GFP_NOWARN only to kzalloc(). > kvzalloc is: kvmalloc(size, flags | __GFP_ZERO) > kvmalloc is: kvmalloc_node(size, flags, NUMA_NO_NODE) > kvmalloc_node: > if ((flags & GFP_KERNEL) != GFP_KERNEL) // false, flags == GFP_KERNEL|__GFP_ZERO > return kmalloc_node(size, flags, node); > > if (size > PAGE_SIZE) { > kmalloc_flags |= __GFP_NOWARN; // add __GFP_NOWARN for "big" allocations > > if (!(kmalloc_flags & __GFP_RETRY_MAYFAIL)) > kmalloc_flags |= __GFP_NORETRY; > } > > // kmalloc_flags == GFP_KERNEL|__GFP_ZERO|__GFP_NOWARN if size > PAGE_SIZE > ret = kmalloc_node(size, kmalloc_flags, node); > > if (ret || size <= PAGE_SIZE) > return ret; > > // flags == GFP_KERNEL|__GFP_ZERO > return __vmalloc_node(size, 1, flags, node, > __builtin_return_address(0)); > > So, to my understanding the difference is only that cxgbi_alloc_big_mem adds __GFP_NOWARN > to kzalloc unconditionally, kvzalloc adds __GFP_NOWARN to kmalloc_node if size > PAGE_SIZE. > We use: max_conn * sizeof(struct cxgbi_sock *) in allocation. max_conn can be either > CXGBI_MAX_CONN or CXGB4I_MAX_CONN. CXGBI_MAX_CONN == 16384, CXGB4I_MAX_CONN == 16384. > Thus the allocation is bigger than PAGE_SIZE and kvmalloc_node adds __GFP_NOWARN to the > kmalloc_node call. Maybe I missed something? > Of course max_conn can be smaller than CXGBI_MAX_CONN and CXGB4I_MAX_CONN and size < PAGE_SIZE. However, it's by design not to warn on "small" allocations in kvmalloc_node and it will not even try to call __vmalloc_node if "small" allocation will fail with kmalloc_node. I think that this behavior fits the cxgbi_device_portmap_create() context call. ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] scsi: libcxgbi: use kvzalloc instead of opencoded kzalloc/vzalloc 2020-08-01 7:51 ` Denis Efremov 2020-08-01 7:58 ` Denis Efremov @ 2020-08-01 8:10 ` Joe Perches 2020-08-01 13:28 ` Denis Efremov 1 sibling, 1 reply; 12+ messages in thread From: Joe Perches @ 2020-08-01 8:10 UTC (permalink / raw) To: Denis Efremov, Martin K. Petersen, James E.J. Bottomley Cc: linux-scsi, linux-kernel On Sat, 2020-08-01 at 10:51 +0300, Denis Efremov wrote: > On 8/1/20 1:24 AM, Joe Perches wrote: > > On Sat, 2020-08-01 at 01:10 +0300, Denis Efremov wrote: > > > On 8/1/20 12:58 AM, Joe Perches wrote: > > > > On Sat, 2020-08-01 at 00:55 +0300, Denis Efremov wrote: > > > > > Remove cxgbi_alloc_big_mem(), cxgbi_free_big_mem() functions > > > > > and use kvzalloc/kvfree instead. > > > > > > > > Sensible, thanks. > > > > > > > > > diff --git a/drivers/scsi/cxgbi/libcxgbi.c b/drivers/scsi/cxgbi/libcxgbi.c > > > > [] > > > > > @@ -77,9 +77,9 @@ int cxgbi_device_portmap_create(struct cxgbi_device *cdev, unsigned int base, > > > > > { > > > > > struct cxgbi_ports_map *pmap = &cdev->pmap; > > > > > > > > > > - pmap->port_csk = cxgbi_alloc_big_mem(max_conn * > > > > > - sizeof(struct cxgbi_sock *), > > > > > - GFP_KERNEL); > > > > > + pmap->port_csk = kvzalloc(array_size(max_conn, > > > > > + sizeof(struct cxgbi_sock *)), > > > > > + GFP_KERNEL); > > > > > > > > missing __GFP_NOWARN > > > > > > > > > > kvmalloc_node adds __GFP_NOWARN internally to kmalloc call > > > https://elixir.bootlin.com/linux/v5.8-rc4/source/mm/util.c#L568 > > > > Only when there's a fallback, and the fallback does not. > Sorry, Joe, I don't understand why do we need to add __GFP_NOWARN here. Hi. The reason to add __GFP_NOWARN is so you don't get a dump_stack() as there's an existing error message output below this when OOM. You should either remove the error message as it just effectively duplicates the dump_stack or add __GFP_NOWARN. Your choice. cheers, Joe ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] scsi: libcxgbi: use kvzalloc instead of opencoded kzalloc/vzalloc 2020-08-01 8:10 ` Joe Perches @ 2020-08-01 13:28 ` Denis Efremov 0 siblings, 0 replies; 12+ messages in thread From: Denis Efremov @ 2020-08-01 13:28 UTC (permalink / raw) To: Joe Perches, Martin K. Petersen, James E.J. Bottomley Cc: linux-scsi, linux-kernel On 8/1/20 11:10 AM, Joe Perches wrote: > On Sat, 2020-08-01 at 10:51 +0300, Denis Efremov wrote: >> On 8/1/20 1:24 AM, Joe Perches wrote: >>> On Sat, 2020-08-01 at 01:10 +0300, Denis Efremov wrote: >>>> On 8/1/20 12:58 AM, Joe Perches wrote: >>>>> On Sat, 2020-08-01 at 00:55 +0300, Denis Efremov wrote: >>>>>> Remove cxgbi_alloc_big_mem(), cxgbi_free_big_mem() functions >>>>>> and use kvzalloc/kvfree instead. >>>>> >>>>> Sensible, thanks. >>>>> >>>>>> diff --git a/drivers/scsi/cxgbi/libcxgbi.c b/drivers/scsi/cxgbi/libcxgbi.c >>>>> [] >>>>>> @@ -77,9 +77,9 @@ int cxgbi_device_portmap_create(struct cxgbi_device *cdev, unsigned int base, >>>>>> { >>>>>> struct cxgbi_ports_map *pmap = &cdev->pmap; >>>>>> >>>>>> - pmap->port_csk = cxgbi_alloc_big_mem(max_conn * >>>>>> - sizeof(struct cxgbi_sock *), >>>>>> - GFP_KERNEL); >>>>>> + pmap->port_csk = kvzalloc(array_size(max_conn, >>>>>> + sizeof(struct cxgbi_sock *)), >>>>>> + GFP_KERNEL); >>>>> >>>>> missing __GFP_NOWARN >>>>> >>>> >>>> kvmalloc_node adds __GFP_NOWARN internally to kmalloc call >>>> https://elixir.bootlin.com/linux/v5.8-rc4/source/mm/util.c#L568 >>> >>> Only when there's a fallback, and the fallback does not. >> Sorry, Joe, I don't understand why do we need to add __GFP_NOWARN here. > > Hi. > > The reason to add __GFP_NOWARN is so you don't get a > dump_stack() as there's an existing error message > output below this when OOM. > > You should either remove the error message as it just > effectively duplicates the dump_stack or add __GFP_NOWARN. Now I see, thanks! I will send v2. Regards, Denis ^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v2] scsi: libcxgbi: use kvzalloc instead of opencoded kzalloc/vzalloc 2020-07-31 21:55 [PATCH] scsi: libcxgbi: use kvzalloc instead of opencoded kzalloc/vzalloc Denis Efremov 2020-07-31 21:58 ` Joe Perches @ 2020-08-01 13:31 ` Denis Efremov 2020-08-27 15:13 ` Denis Efremov 2020-09-09 2:17 ` Martin K. Petersen 1 sibling, 2 replies; 12+ messages in thread From: Denis Efremov @ 2020-08-01 13:31 UTC (permalink / raw) To: Martin K. Petersen, James E.J. Bottomley Cc: Denis Efremov, linux-scsi, linux-kernel, Joe Perches Remove cxgbi_alloc_big_mem(), cxgbi_free_big_mem() functions and use kvzalloc/kvfree instead. __GFP_NOWARN added to kvzalloc() call because we already print a warning in case of allocation fail. Signed-off-by: Denis Efremov <efremov@linux.com> --- drivers/scsi/cxgbi/libcxgbi.c | 8 ++++---- drivers/scsi/cxgbi/libcxgbi.h | 16 ---------------- 2 files changed, 4 insertions(+), 20 deletions(-) diff --git a/drivers/scsi/cxgbi/libcxgbi.c b/drivers/scsi/cxgbi/libcxgbi.c index 4bc794d2f51c..51f4d34da73f 100644 --- a/drivers/scsi/cxgbi/libcxgbi.c +++ b/drivers/scsi/cxgbi/libcxgbi.c @@ -77,9 +77,9 @@ int cxgbi_device_portmap_create(struct cxgbi_device *cdev, unsigned int base, { struct cxgbi_ports_map *pmap = &cdev->pmap; - pmap->port_csk = cxgbi_alloc_big_mem(max_conn * - sizeof(struct cxgbi_sock *), - GFP_KERNEL); + pmap->port_csk = kvzalloc(array_size(max_conn, + sizeof(struct cxgbi_sock *)), + GFP_KERNEL | __GFP_NOWARN); if (!pmap->port_csk) { pr_warn("cdev 0x%p, portmap OOM %u.\n", cdev, max_conn); return -ENOMEM; @@ -124,7 +124,7 @@ static inline void cxgbi_device_destroy(struct cxgbi_device *cdev) if (cdev->cdev2ppm) cxgbi_ppm_release(cdev->cdev2ppm(cdev)); if (cdev->pmap.max_connect) - cxgbi_free_big_mem(cdev->pmap.port_csk); + kvfree(cdev->pmap.port_csk); kfree(cdev); } diff --git a/drivers/scsi/cxgbi/libcxgbi.h b/drivers/scsi/cxgbi/libcxgbi.h index 84b96af52655..321426242be4 100644 --- a/drivers/scsi/cxgbi/libcxgbi.h +++ b/drivers/scsi/cxgbi/libcxgbi.h @@ -537,22 +537,6 @@ struct cxgbi_task_data { #define iscsi_task_cxgbi_data(task) \ ((task)->dd_data + sizeof(struct iscsi_tcp_task)) -static inline void *cxgbi_alloc_big_mem(unsigned int size, - gfp_t gfp) -{ - void *p = kzalloc(size, gfp | __GFP_NOWARN); - - if (!p) - p = vzalloc(size); - - return p; -} - -static inline void cxgbi_free_big_mem(void *addr) -{ - kvfree(addr); -} - static inline void cxgbi_set_iscsi_ipv4(struct cxgbi_hba *chba, __be32 ipaddr) { if (chba->cdev->flags & CXGBI_FLAG_IPV4_SET) -- 2.26.2 ^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH v2] scsi: libcxgbi: use kvzalloc instead of opencoded kzalloc/vzalloc 2020-08-01 13:31 ` [PATCH v2] " Denis Efremov @ 2020-08-27 15:13 ` Denis Efremov 2020-08-27 15:17 ` Martin K. Petersen 2020-09-09 2:17 ` Martin K. Petersen 1 sibling, 1 reply; 12+ messages in thread From: Denis Efremov @ 2020-08-27 15:13 UTC (permalink / raw) To: Martin K. Petersen, James E.J. Bottomley Cc: linux-scsi, linux-kernel, Joe Perches Ping? On 8/1/20 4:31 PM, Denis Efremov wrote: > Remove cxgbi_alloc_big_mem(), cxgbi_free_big_mem() functions > and use kvzalloc/kvfree instead. __GFP_NOWARN added to kvzalloc() > call because we already print a warning in case of allocation fail. > > Signed-off-by: Denis Efremov <efremov@linux.com> > --- > drivers/scsi/cxgbi/libcxgbi.c | 8 ++++---- > drivers/scsi/cxgbi/libcxgbi.h | 16 ---------------- > 2 files changed, 4 insertions(+), 20 deletions(-) > > diff --git a/drivers/scsi/cxgbi/libcxgbi.c b/drivers/scsi/cxgbi/libcxgbi.c > index 4bc794d2f51c..51f4d34da73f 100644 > --- a/drivers/scsi/cxgbi/libcxgbi.c > +++ b/drivers/scsi/cxgbi/libcxgbi.c > @@ -77,9 +77,9 @@ int cxgbi_device_portmap_create(struct cxgbi_device *cdev, unsigned int base, > { > struct cxgbi_ports_map *pmap = &cdev->pmap; > > - pmap->port_csk = cxgbi_alloc_big_mem(max_conn * > - sizeof(struct cxgbi_sock *), > - GFP_KERNEL); > + pmap->port_csk = kvzalloc(array_size(max_conn, > + sizeof(struct cxgbi_sock *)), > + GFP_KERNEL | __GFP_NOWARN); > if (!pmap->port_csk) { > pr_warn("cdev 0x%p, portmap OOM %u.\n", cdev, max_conn); > return -ENOMEM; > @@ -124,7 +124,7 @@ static inline void cxgbi_device_destroy(struct cxgbi_device *cdev) > if (cdev->cdev2ppm) > cxgbi_ppm_release(cdev->cdev2ppm(cdev)); > if (cdev->pmap.max_connect) > - cxgbi_free_big_mem(cdev->pmap.port_csk); > + kvfree(cdev->pmap.port_csk); > kfree(cdev); > } > > diff --git a/drivers/scsi/cxgbi/libcxgbi.h b/drivers/scsi/cxgbi/libcxgbi.h > index 84b96af52655..321426242be4 100644 > --- a/drivers/scsi/cxgbi/libcxgbi.h > +++ b/drivers/scsi/cxgbi/libcxgbi.h > @@ -537,22 +537,6 @@ struct cxgbi_task_data { > #define iscsi_task_cxgbi_data(task) \ > ((task)->dd_data + sizeof(struct iscsi_tcp_task)) > > -static inline void *cxgbi_alloc_big_mem(unsigned int size, > - gfp_t gfp) > -{ > - void *p = kzalloc(size, gfp | __GFP_NOWARN); > - > - if (!p) > - p = vzalloc(size); > - > - return p; > -} > - > -static inline void cxgbi_free_big_mem(void *addr) > -{ > - kvfree(addr); > -} > - > static inline void cxgbi_set_iscsi_ipv4(struct cxgbi_hba *chba, __be32 ipaddr) > { > if (chba->cdev->flags & CXGBI_FLAG_IPV4_SET) > ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2] scsi: libcxgbi: use kvzalloc instead of opencoded kzalloc/vzalloc 2020-08-27 15:13 ` Denis Efremov @ 2020-08-27 15:17 ` Martin K. Petersen 0 siblings, 0 replies; 12+ messages in thread From: Martin K. Petersen @ 2020-08-27 15:17 UTC (permalink / raw) To: Denis Efremov Cc: Martin K. Petersen, James E.J. Bottomley, linux-scsi, linux-kernel, Joe Perches Denis, > Ping? It's in my staging branch. -- Martin K. Petersen Oracle Linux Engineering ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2] scsi: libcxgbi: use kvzalloc instead of opencoded kzalloc/vzalloc 2020-08-01 13:31 ` [PATCH v2] " Denis Efremov 2020-08-27 15:13 ` Denis Efremov @ 2020-09-09 2:17 ` Martin K. Petersen 1 sibling, 0 replies; 12+ messages in thread From: Martin K. Petersen @ 2020-09-09 2:17 UTC (permalink / raw) To: James E.J. Bottomley, Denis Efremov Cc: Martin K . Petersen, linux-kernel, linux-scsi, Joe Perches On Sat, 1 Aug 2020 16:31:23 +0300, Denis Efremov wrote: > Remove cxgbi_alloc_big_mem(), cxgbi_free_big_mem() functions > and use kvzalloc/kvfree instead. __GFP_NOWARN added to kvzalloc() > call because we already print a warning in case of allocation fail. Applied to 5.10/scsi-queue, thanks! [1/1] scsi: libcxgbi: Use kvzalloc instead of opencoded kzalloc/vzalloc https://git.kernel.org/mkp/scsi/c/ee9108fedf63 -- Martin K. Petersen Oracle Linux Engineering ^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2020-09-09 2:17 UTC | newest] Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2020-07-31 21:55 [PATCH] scsi: libcxgbi: use kvzalloc instead of opencoded kzalloc/vzalloc Denis Efremov 2020-07-31 21:58 ` Joe Perches 2020-07-31 22:10 ` Denis Efremov 2020-07-31 22:24 ` Joe Perches 2020-08-01 7:51 ` Denis Efremov 2020-08-01 7:58 ` Denis Efremov 2020-08-01 8:10 ` Joe Perches 2020-08-01 13:28 ` Denis Efremov 2020-08-01 13:31 ` [PATCH v2] " Denis Efremov 2020-08-27 15:13 ` Denis Efremov 2020-08-27 15:17 ` Martin K. Petersen 2020-09-09 2:17 ` Martin K. Petersen
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.