mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dave Hansen <haveblue@us.ibm.com>
To: David Gibson <dwg@au1.ibm.com>
Cc: William Lee Irwin <wli@holomorphy.com>, linux-kernel@vger.kernel.org
Subject: Re: RFC: Block reservation for hugetlbfs
Date: Tue, 21 Feb 2006 11:25:36 -0800	[thread overview]
Message-ID: <1140549936.8693.41.camel@localhost.localdomain> (raw)
In-Reply-To: <20060221022124.GA18535@localhost.localdomain>

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

On Tue, 2006-02-21 at 13:21 +1100, David Gibson wrote:
> The patch below is a draft attempt to address this problem, by
> strictly reserving a number of physical hugepages for hugepages inodes
> which have been mapped, but not instatiated.  MAP_SHARED mappings are
> thus "safe" - they will fail on mmap(), not later with a SIGBUS.
> MAP_PRIVATE mappings can still SIGBUS.
...
> +	read_lock_irq(&inode->i_mapping->tree_lock);
> +	for (pg = inode->i_blocks; pg < npages; pg++) {
> +		page = radix_tree_lookup(&mapping->page_tree, pg);
> +		if (! page)
> +			change_in_reserve++;
> +	}
> +
> +	for (pg = npages; pg < inode->i_blocks; pg++) {
> +		page = radix_tree_lookup(&mapping->page_tree, pg);
> +		if (! page)
> +			change_in_reserve--;
> +	}
> +	spin_lock(&hugetlb_lock);

I'm a bit confused by this.  The for loops goes through and looks for
pages that have indexes greater than the current i_blocks, but less than
the number of pages requested by this reservation.  With demand
faulting, can there be holes in the file?  Will this code account for
them?

I think this would also be a bit more clear if the two for loops were a
bit more explicit in what they are doing.  The first is growing the
reservation when "npages > inode->i_blocks" and the second is shrinking
the reservation when "npages < inode->i_blocks", right?  Is this
completely clear from the code? ;)

Also, since the operation you are performing is actually counting pages
in the radix tree at certain indexes, would it be sane to have a patch
such as the (completely untested) attached one to do just that, but in
the radix code?

-- Dave


[-- Attachment #2: radix-tree-count.patch --]
[-- Type: text/x-patch, Size: 1821 bytes --]



---

 memhotplug-dave/lib/radix-tree.c |   19 +++++++++++++++++--
 1 files changed, 17 insertions(+), 2 deletions(-)

diff -puN lib/radix-tree.c~radix-tree-count lib/radix-tree.c
--- memhotplug/lib/radix-tree.c~radix-tree-count	2006-02-21 10:50:25.000000000 -0800
+++ memhotplug-dave/lib/radix-tree.c	2006-02-21 10:51:00.000000000 -0800
@@ -538,7 +538,9 @@ __lookup(struct radix_tree_root *root, v
 	for (i = index & RADIX_TREE_MAP_MASK; i < RADIX_TREE_MAP_SIZE; i++) {
 		index++;
 		if (slot->slots[i]) {
-			results[nr_found++] = slot->slots[i];
+			if (results)
+				results[nr_found] = slot->slots[i];
+			nr_found++;
 			if (nr_found == max_items)
 				goto out;
 		}
@@ -559,6 +561,9 @@ out:
  *	them at *@results and returns the number of items which were placed at
  *	*@results.
  *
+ *	If *@results is NULL, the function will return a count of pages found,
+ *	without any actual results.
+ *
  *	The implementation is naive.
  */
 unsigned int
@@ -572,10 +577,13 @@ radix_tree_gang_lookup(struct radix_tree
 	while (ret < max_items) {
 		unsigned int nr_found;
 		unsigned long next_index;	/* Index of next search */
+		void *cur_result = NULL;
 
 		if (cur_index > max_index)
 			break;
-		nr_found = __lookup(root, results + ret, cur_index,
+		if (results)
+			cur_result = results + ret;
+		nr_found = __lookup(root, cur_result, cur_index,
 					max_items - ret, &next_index);
 		ret += nr_found;
 		if (next_index == 0)
@@ -586,6 +594,13 @@ radix_tree_gang_lookup(struct radix_tree
 }
 EXPORT_SYMBOL(radix_tree_gang_lookup);
 
+unsigned int
+radix_tree_lookup_count(struct radix_tree_root *root
+			unsigned long first_index)
+{
+	return radix_tree_gang_lookup(root, NULL, first_index, ~0);
+}
+
 /*
  * FIXME: the two tag_get()s here should use find_next_bit() instead of
  * open-coding the search.
_

  parent reply	other threads:[~2006-02-21 19:25 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-02-21  2:21 David Gibson
2006-02-21  4:18 ` Nick Piggin
2006-02-21 23:39   ` David Gibson
2006-02-22  0:38     ` Nick Piggin
2006-02-22  2:11       ` David Gibson
2006-02-22  3:09         ` Nick Piggin
2006-02-24  4:11           ` David Gibson
2006-02-24  6:22             ` Nick Piggin
2006-02-27  0:18               ` David Gibson
2006-02-21 19:25 ` Dave Hansen [this message]
2006-02-21 23:46   ` David Gibson

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=1140549936.8693.41.camel@localhost.localdomain \
    --to=haveblue@us.ibm.com \
    --cc=dwg@au1.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=wli@holomorphy.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

Powered by JetHome