mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: NeilBrown <neilb@suse.com>
To: Oleg Drokin <oleg.drokin@intel.com>,
	James Simmons <jsimmons@infradead.org>,
	Andreas Dilger <andreas.dilger@intel.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-kernel@vger.kernel.org, lustre-devel@lists.lustre.org
Subject: Re: [PATCH 07/12] staging: lustre: libcfs: simplify memory allocation.
Date: Thu, 14 Dec 2017 11:00:45 +1100	[thread overview]
Message-ID: <87d13inpoy.fsf@notabene.neil.brown.name> (raw)
In-Reply-To: <151313495497.27582.5451400666802627086.stgit@noble>

[-- Attachment #1: Type: text/plain, Size: 3989 bytes --]

On Wed, Dec 13 2017, NeilBrown wrote:

> 1/ Use kvmalloc() instead of kmalloc or vmalloc
> 2/ Discard the _GFP() interfaces that are never used.
>   We only ever do GFP_NOFS and GFP_ATOMIC allocations,
>   so support each of those explicitly.

Hi,
 I just remembered that posting this patch was, maybe, a little premature.
vmalloc() doesn't support GFP_NOFS, so kvmalloc() warns about an attempt
to use GFP_NOFS.
lustre potentially used vmalloc in GFP_NOFS context, and so now calls
kvmalloc() with GFP_NOFS, which triggers a warning.

I haven't yet looking into how to remove the warning.  Maybe all
GFP_NOFS usages should use kmalloc(), not kvmalloc(), and accept the
increased chance of failure.
I'll dig deeper and hope to have a clearer opinion soon.

As it is only a warning, it is probably OK to keep the patch in
staging-next, but I wouldn't object if it was dropped.

Thanks,
NeilBrown

 

>
> Signed-off-by: NeilBrown <neilb@suse.com>
> ---
>  .../lustre/include/linux/libcfs/libcfs_private.h   |   42 ++++++--------------
>  1 file changed, 12 insertions(+), 30 deletions(-)
>
> diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_private.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_private.h
> index 2f4ff595fac9..c874f9d15c72 100644
> --- a/drivers/staging/lustre/include/linux/libcfs/libcfs_private.h
> +++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_private.h
> @@ -84,14 +84,6 @@ do {								    \
>  	lbug_with_loc(&msgdata);					\
>  } while (0)
>  
> -#ifndef LIBCFS_VMALLOC_SIZE
> -#define LIBCFS_VMALLOC_SIZE	(2 << PAGE_SHIFT) /* 2 pages */
> -#endif
> -
> -#define LIBCFS_ALLOC_PRE(size, mask)					\
> -	LASSERT(!in_interrupt() || ((size) <= LIBCFS_VMALLOC_SIZE &&	\
> -				    !gfpflags_allow_blocking(mask)))
> -
>  #define LIBCFS_ALLOC_POST(ptr, size)					    \
>  do {									    \
>  	if (unlikely(!(ptr))) {						    \
> @@ -103,46 +95,36 @@ do {									    \
>  } while (0)
>  
>  /**
> - * allocate memory with GFP flags @mask
> + * default allocator
>   */
> -#define LIBCFS_ALLOC_GFP(ptr, size, mask)				    \
> +#define LIBCFS_ALLOC(ptr, size)						    \
>  do {									    \
> -	LIBCFS_ALLOC_PRE((size), (mask));				    \
> -	(ptr) = (size) <= LIBCFS_VMALLOC_SIZE ?				    \
> -		kmalloc((size), (mask)) : vmalloc(size);	    \
> +	LASSERT(!in_interrupt());					    \
> +	(ptr) = kvmalloc((size), GFP_NOFS);				    \
>  	LIBCFS_ALLOC_POST((ptr), (size));				    \
>  } while (0)
>  
> -/**
> - * default allocator
> - */
> -#define LIBCFS_ALLOC(ptr, size) \
> -	LIBCFS_ALLOC_GFP(ptr, size, GFP_NOFS)
> -
>  /**
>   * non-sleeping allocator
>   */
> -#define LIBCFS_ALLOC_ATOMIC(ptr, size) \
> -	LIBCFS_ALLOC_GFP(ptr, size, GFP_ATOMIC)
> +#define LIBCFS_ALLOC_ATOMIC(ptr, size)					\
> +do {									\
> +	(ptr) = kmalloc((size), GFP_ATOMIC);				\
> +	LIBCFS_ALLOC_POST(ptr, size);					\
> +} while (0)
>  
>  /**
>   * allocate memory for specified CPU partition
>   *   \a cptab != NULL, \a cpt is CPU partition id of \a cptab
>   *   \a cptab == NULL, \a cpt is HW NUMA node id
>   */
> -#define LIBCFS_CPT_ALLOC_GFP(ptr, cptab, cpt, size, mask)		    \
> +#define LIBCFS_CPT_ALLOC(ptr, cptab, cpt, size)				    \
>  do {									    \
> -	LIBCFS_ALLOC_PRE((size), (mask));				    \
> -	(ptr) = (size) <= LIBCFS_VMALLOC_SIZE ?				    \
> -		kmalloc_node((size), (mask), cfs_cpt_spread_node(cptab, cpt)) :\
> -		vmalloc_node(size, cfs_cpt_spread_node(cptab, cpt));	    \
> +	LASSERT(!in_interrupt());					    \
> +	(ptr) = kvmalloc_node((size), GFP_NOFS, cfs_cpt_spread_node(cptab, cpt)); \
>  	LIBCFS_ALLOC_POST((ptr), (size));				    \
>  } while (0)
>  
> -/** default numa allocator */
> -#define LIBCFS_CPT_ALLOC(ptr, cptab, cpt, size)				    \
> -	LIBCFS_CPT_ALLOC_GFP(ptr, cptab, cpt, size, GFP_NOFS)
> -
>  #define LIBCFS_FREE(ptr, size)					  \
>  do {								    \
>  	if (unlikely(!(ptr))) {						\

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

  reply	other threads:[~2017-12-14  0:01 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-13  3:15 [PATCH 00/13] Assorted lustre clean-ups NeilBrown
2017-12-13  3:15 ` [PATCH 06/12] staging: lustre: lov: use list_for_each_entry in lov_obd.c NeilBrown
2017-12-13  3:15 ` [PATCH 04/12] staging: lustre: ldlm: minor list_entry improvements in ldlm_request.c NeilBrown
2017-12-13  3:15 ` [PATCH 05/12] staging: lustre: ldlm: use list_for_each_entry in ldlm_resource.c NeilBrown
2017-12-13  3:15 ` [PATCH 03/12] staging: lustre: ldlm: use list_first_entry in ldlm_lockd.c NeilBrown
2017-12-13  3:15 ` [PATCH 01/12] staging: lustre: use list_last_entry to simplify fld_cache_shrink NeilBrown
2017-12-13  3:15 ` [PATCH 02/12] staging: lustre: ldlm: use list_for_each_entry in ldlm_extent_shift_kms() NeilBrown
2017-12-13  3:15 ` [PATCH 11/12] staging: lustre: libcfs: discard KLASSERT() NeilBrown
2017-12-13  3:15 ` [PATCH 08/12] staging: lustre: libcfs: remove unused rounding functions NeilBrown
2017-12-13  3:15 ` [PATCH 09/12] staging: lustre: libcfs: discard MKSTR() macro NeilBrown
2017-12-13  3:15 ` [PATCH 07/12] staging: lustre: libcfs: simplify memory allocation NeilBrown
2017-12-14  0:00   ` NeilBrown [this message]
2017-12-13  3:15 ` [PATCH 12/12] staging: lustre: libcfs: discard LASSERT_CHECKED NeilBrown
     [not found]   ` <BN6PR1101MB21324C5DC6B6CF85ACD8EF00CB350@BN6PR1101MB2132.namprd11.prod.outlook.com>
2017-12-13 10:22     ` [lustre-devel] " Luis de Bethencourt
2017-12-13  3:15 ` [PATCH 10/12] staging: lustre: libcfs: discard MAX_NUMERIC_VALUE NeilBrown

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=87d13inpoy.fsf@notabene.neil.brown.name \
    --to=neilb@suse.com \
    --cc=andreas.dilger@intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jsimmons@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lustre-devel@lists.lustre.org \
    --cc=oleg.drokin@intel.com \
    /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 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®