linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Tejun Heo <tj@kernel.org>
To: Wang YanQing <udknight@gmail.com>,
	akpm@linux-foundation.org, yinghai@kernel.org,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	liwanp@linux.vnet.ibm.com, tangchen@cn.fujitsu.com
Subject: Re: [PATCH]memblock: do double array and add merge directly path in memblock_insert_region
Date: Sun, 9 Jun 2013 14:37:18 -0700	[thread overview]
Message-ID: <20130609213718.GA8045@mtj.dyndns.org> (raw)
In-Reply-To: <20130609173430.GA2592@udknight>

Hello,

On Mon, Jun 10, 2013 at 01:34:30AM +0800, Wang YanQing wrote:
> If we allow do merge directly when insertion, we can get better performance,
> this patch add support to do merge directly in memblock_insert_region.

Do you have actual case where performance in this patch is
problematic?

> -static void __init_memblock memblock_insert_region(struct memblock_type *type,
> +static int __init_memblock memblock_insert_region(struct memblock_type *type,
>  						   int idx, phys_addr_t base,
> -						   phys_addr_t size, int nid)
> +						   phys_addr_t size, int nid, int merge)

bool merge and you need to update comment accordingly.

>  {
>  	struct memblock_region *rgn = &type->regions[idx];
>  
> -	BUG_ON(type->cnt >= type->max);
> +	if (merge && (base + size) == rgn->base &&
> +	        nid == memblock_get_region_node(rgn)) {
> +		rgn->base = base;
> +		rgn->size += size;
> +		type->total_size += size;
> +		return 0;
> +	}

What if merge is from upside down or this connects two disjoint
regions?

>  static int __init_memblock memblock_add_region(struct memblock_type *type,
>  				phys_addr_t base, phys_addr_t size, int nid)
...
>  		if (rbase > base) {
> -			nr_new++;
> -			if (insert)
> -				memblock_insert_region(type, i++, base,
> -						       rbase - base, nid);
> +			ret = memblock_insert_region(type, i++, base,
> +					rbase - base, nid, 1);
> +			if (ret) {
> +				return ret;
> +			}

Superflous { } and you need roll back what you've done upto this point
before returning.  That's the reason why the function is structured
the way it is.  If insertion fails due to array expansion failure, the
previous code doesn't change the memblock tables at all.  Your new
code leaves it half-updated.

> @@ -498,8 +488,11 @@ static int __init_memblock memblock_isolate_range(struct memblock_type *type,
>  			rgn->base = base;
>  			rgn->size -= base - rbase;
>  			type->total_size -= base - rbase;
> -			memblock_insert_region(type, i, rbase, base - rbase,
> -					       memblock_get_region_node(rgn));
> +			ret = memblock_insert_region(type, i, rbase, base - rbase,
> +					memblock_get_region_node(rgn), 0);
> +			if (ret) {
> +				return ret;
> +			}

Ditto, you need to roll back on failure.

> @@ -533,6 +529,7 @@ static int __init_memblock __memblock_remove(struct memblock_type *type,
>  
>  	for (i = end_rgn - 1; i >= start_rgn; i--)
>  		memblock_remove_region(type, i);
> +	memblock_merge_regions(type);

Why is this added?

Thanks.

-- 
tejun

--
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-06-09 21:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-09 17:34 [PATCH]memblock: do double array and add merge directly path in memblock_insert_region Wang YanQing
2013-06-09 21:37 ` Tejun Heo [this message]

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=20130609213718.GA8045@mtj.dyndns.org \
    --to=tj@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=liwanp@linux.vnet.ibm.com \
    --cc=tangchen@cn.fujitsu.com \
    --cc=udknight@gmail.com \
    --cc=yinghai@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).