linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Toshi Kani <toshi.kani@hp.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: David Rientjes <rientjes@google.com>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	linuxram@us.ibm.com, guz.fnst@cn.fujitsu.com, tmac@hp.com,
	isimatu.yasuaki@jp.fujitsu.com, wency@cn.fujitsu.com,
	tangchen@cn.fujitsu.com, jiang.liu@huawei.com
Subject: Re: [PATCH v3 2/3] resource: Add release_mem_region_adjustable()
Date: Thu, 11 Apr 2013 10:30:02 -0600	[thread overview]
Message-ID: <1365697802.32127.117.camel@misato.fc.hp.com> (raw)
In-Reply-To: <20130410152404.e0836af597ba3545b9846672@linux-foundation.org>

On Wed, 2013-04-10 at 15:24 -0700, Andrew Morton wrote:
> On Wed, 10 Apr 2013 15:08:29 -0700 (PDT) David Rientjes <rientjes@google.com> wrote:
> 
> > On Wed, 10 Apr 2013, Toshi Kani wrote:
> > 
> > > > I'll switch it to GFP_ATOMIC.  Which is horridly lame but the
> > > > allocation is small and alternatives are unobvious.
> > > 
> > > Great!  Again, thanks for the update!
> > 
> > release_mem_region_adjustable() allocates at most one struct resource, so 
> > why not do kmalloc(sizeof(struct resource), GFP_KERNEL) before taking 
> > resource_lock and then testing whether it's NULL or not when splitting?  
> > It unnecessarily allocates memory when there's no split, but 
> > __remove_pages() shouldn't be a hotpath.
> 
> yup.
> 
> --- a/kernel/resource.c~resource-add-release_mem_region_adjustable-fix-fix
> +++ a/kernel/resource.c
> @@ -1046,7 +1046,8 @@ int release_mem_region_adjustable(struct
>  			resource_size_t start, resource_size_t size)
>  {
>  	struct resource **p;
> -	struct resource *res, *new;
> +	struct resource *res;
> +	struct resource *new_res;
>  	resource_size_t end;
>  	int ret = -EINVAL;
>  
> @@ -1054,6 +1055,9 @@ int release_mem_region_adjustable(struct
>  	if ((start < parent->start) || (end > parent->end))
>  		return ret;
>  
> +	/* The kzalloc() result gets checked later */
> +	new_res = kzalloc(sizeof(struct resource), GFP_KERNEL);
> +
>  	p = &parent->child;
>  	write_lock(&resource_lock);
>  
> @@ -1091,32 +1095,33 @@ int release_mem_region_adjustable(struct
>  						start - res->start);
>  		} else {
>  			/* split into two entries */
> -			new = kzalloc(sizeof(struct resource), GFP_ATOMIC);
> -			if (!new) {
> +			if (!new_res) {
>  				ret = -ENOMEM;
>  				break;
>  			}
> -			new->name = res->name;
> -			new->start = end + 1;
> -			new->end = res->end;
> -			new->flags = res->flags;
> -			new->parent = res->parent;
> -			new->sibling = res->sibling;
> -			new->child = NULL;
> +			new_res->name = res->name;
> +			new_res->start = end + 1;
> +			new_res->end = res->end;
> +			new_res->flags = res->flags;
> +			new_res->parent = res->parent;
> +			new_res->sibling = res->sibling;
> +			new_res->child = NULL;
>  
>  			ret = __adjust_resource(res, res->start,
>  						start - res->start);
>  			if (ret) {
> -				kfree(new);
> +				kfree(new_res);
>  				break;
>  			}

The kfree() in the if-statement above is not necessary since kfree() is
called before the return at the end.  That is, the if-statement needs to
be:
	if (ret)
		break;

With this change, I confirmed that all my test cases passed (with all
the config debug options this time :).  With the change:

Reviewed-by: Toshi Kani <toshi.kani@hp.com>
Tested-by: Toshi Kani <toshi.kani@hp.com>

Thanks!
-Toshi


> -			res->sibling = new;
> +			res->sibling = new_res;
> +			new_res = NULL;
>  		}
>  
>  		break;
>  	}
>  
>  	write_unlock(&resource_lock);
> +	kfree(new_res);
>  	return ret;
>  }
>  #endif	/* CONFIG_MEMORY_HOTPLUG */
> _
> 


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

  reply	other threads:[~2013-04-11 16:42 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-10 17:16 [PATCH v3 0/3] Support memory hot-delete to boot memory Toshi Kani
2013-04-10 17:16 ` [PATCH v3 1/3] resource: Add __adjust_resource() for internal use Toshi Kani
2013-04-10 17:17 ` [PATCH v3 2/3] resource: Add release_mem_region_adjustable() Toshi Kani
2013-04-10 21:44   ` Andrew Morton
2013-04-10 21:49     ` Toshi Kani
2013-04-10 22:08       ` David Rientjes
2013-04-10 22:24         ` Andrew Morton
2013-04-11 16:30           ` Toshi Kani [this message]
2013-04-24  8:42             ` Ram Pai
2013-04-24 14:43               ` Toshi Kani
2013-04-10 17:17 ` [PATCH v3 3/3] mm: Change __remove_pages() to call release_mem_region_adjustable() Toshi Kani
2013-04-10 22:13   ` David Rientjes
2013-04-11 20:30     ` Toshi Kani

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=1365697802.32127.117.camel@misato.fc.hp.com \
    --to=toshi.kani@hp.com \
    --cc=akpm@linux-foundation.org \
    --cc=guz.fnst@cn.fujitsu.com \
    --cc=isimatu.yasuaki@jp.fujitsu.com \
    --cc=jiang.liu@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linuxram@us.ibm.com \
    --cc=rientjes@google.com \
    --cc=tangchen@cn.fujitsu.com \
    --cc=tmac@hp.com \
    --cc=wency@cn.fujitsu.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