public inbox for linux-ia64@vger.kernel.org
 help / color / mirror / Atom feed
From: "Chen, Kenneth W" <kenneth.w.chen@intel.com>
To: 'Andi Kleen' <ak@suse.de>
Cc: 'William Lee Irwin III' <wli@holomorphy.com>,
	linux-kernel@vger.kernel.org, linux-ia64@vger.kernel.org, "Seth,
	Rohit" <rohit.seth@intel.com>
Subject: RE: Hugetlb demanding paging for -mm tree
Date: Fri, 06 Aug 2004 21:06:03 +0000	[thread overview]
Message-ID: <200408062106.i76L63Y08492@unix-os.sc.intel.com> (raw)
In-Reply-To: <20040805140455.GE16763@wotan.suse.de>
In-Reply-To: <200408051329.i75DT3Y26431@unix-os.sc.intel.com>

Andi Kleen wrote on Thursday, August 05, 2004 7:05 AM
> On Thu, Aug 05, 2004 at 06:42:15AM -0700, Chen, Kenneth W wrote:
> > +int hugetlb_acct_memory(long delta)
> > +{
> > +	atomic_add(delta, &hugetlbzone_resv);
> > +	if (delta > 0 && atomic_read(&hugetlbzone_resv) >
> > +			VMACCTPG(hugetlb_total_pages())) {
> > +		atomic_add(-delta, &hugetlbzone_resv);
> > +		return -ENOMEM;
> > +	}
> > +	return 0;
>
> Wouldn't this be safer with a bit of locking?
> Even if the current code works lockless it would be more safer
> for long term mainteance.

Patch at the end of the mail.  Is it better?


> > +}
> > +
> > +struct file_region {
> > +	struct list_head link;
> > +	int from;
> > +	int to;
>
> Shouldn't these be long instead of int?

Yes, it should be long.  Thank you.

>
> I remember writing very similar, but simpler code for NUMA API
> regions. The PAT patches also have similar code.
> It's also tricky to get right.
>
> Maybe it would be time to move variable length region list handling
> into a nice library in lib/, so that it can be used by other users.

Let me roll that up in the next couple of days along with the above struct
type change. For now I guess we can let it sit in hugetlbfs for a few days.


diff -Nurp linux-2.6.7/fs/hugetlbfs/inode.c linux-2.6.7.hugetlb/fs/hugetlbfs/inode.c
--- linux-2.6.7/fs/hugetlbfs/inode.c	2004-08-06 11:45:04.000000000 -0700
+++ linux-2.6.7.hugetlb/fs/hugetlbfs/inode.c	2004-08-06 13:46:11.000000000 -0700
@@ -36,17 +36,21 @@
 #define VMACCT(x) ((x) >> (HPAGE_SHIFT))
 #define VMACCTPG(x) ((x) >> (HPAGE_SHIFT - PAGE_SHIFT))

-atomic_t hugetlbzone_resv = ATOMIC_INIT(0);
+static long hugetlbzone_resv;
+static spinlock_t hugetlbfs_lock = SPIN_LOCK_UNLOCKED;

 int hugetlb_acct_memory(long delta)
 {
-	atomic_add(delta, &hugetlbzone_resv);
-	if (delta > 0 && atomic_read(&hugetlbzone_resv) >
-			VMACCTPG(hugetlb_total_pages())) {
-		atomic_add(-delta, &hugetlbzone_resv);
-		return -ENOMEM;
-	}
-	return 0;
+	int ret = 0;
+
+	spin_lock(&hugetlbfs_lock);
+	if (delta > 0 && (hugetlbzone_resv + delta) >
+			VMACCTPG(hugetlb_total_pages()))
+		ret = -ENOMEM;
+	else
+		hugetlbzone_resv += delta;
+	spin_unlock(&hugetlbfs_lock);
+	return ret;
 }

 struct file_region {
@@ -225,8 +229,7 @@ static void hugetlb_acct_release(struct

 int hugetlbfs_report_meminfo(char *buf)
 {
-	long htlb = atomic_read(&hugetlbzone_resv);
-	return sprintf(buf, "HugePages_Reserved: %5lu\n", htlb);
+	return sprintf(buf, "HugePages_Reserved: %5lu\n", hugetlbzone_resv);
 }

 static struct super_operations hugetlbfs_ops;



  parent reply	other threads:[~2004-08-06 21:06 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-08-05 13:29 Hugetlb demanding paging for -mm tree Chen, Kenneth W
2004-08-05 13:36 ` William Lee Irwin III
2004-08-05 13:39 ` Chen, Kenneth W
2004-08-05 16:35   ` Hirokazu Takahashi
2004-08-07  8:36   ` William Lee Irwin III
2004-08-05 13:42 ` Chen, Kenneth W
2004-08-05 14:04   ` Andi Kleen
2004-08-05 13:43 ` Andi Kleen
2004-08-06 20:55 ` Chen, Kenneth W
2004-08-06 21:07   ` William Lee Irwin III
2004-08-07  8:13     ` William Lee Irwin III
2004-08-06 21:06 ` Chen, Kenneth W [this message]
2004-08-09 18:19 ` Chen, Kenneth W
2004-08-09 19:12   ` William Lee Irwin III
2004-08-09 18:43 ` Seth, Rohit
2004-08-09 18:59   ` William Lee Irwin III
2004-08-09 18:54 ` Chen, Kenneth W
2004-08-09 19:12   ` William Lee Irwin III
2004-08-10  8:52 ` Seth, Rohit
2004-08-10  8:55   ` William Lee Irwin III
2004-08-11  0:28 ` Seth, Rohit
2004-08-11  0:45   ` William Lee Irwin III
2004-08-11  6:36 ` Seth, Rohit
2004-08-11  6:38   ` William Lee Irwin III

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=200408062106.i76L63Y08492@unix-os.sc.intel.com \
    --to=kenneth.w.chen@intel.com \
    --cc=ak@suse.de \
    --cc=linux-ia64@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rohit.seth@intel.com \
    --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