public inbox for linux-ia64@vger.kernel.org
 help / color / mirror / Atom feed
From: Andy Whitcroft <apw@shadowen.org>
To: "Martin J. Bligh" <mbligh@aracnet.com>,
	Ray Bryant <raybry@sgi.com>, Andrew Morton <akpm@osdl.org>,
	linux-kernel@vger.kernel.org
Cc: anton@samba.org, sds@epoch.ncsc.mil, ak@suse.de,
	lse-tech@lists.sourceforge.net, linux-ia64@vger.kernel.org
Subject: Re: [PATCH] [0/6] HUGETLB memory commitment
Date: Mon, 29 Mar 2004 12:30:19 +0000	[thread overview]
Message-ID: <11580712.1080567019@42.150.104.212.access.eclipse.net.uk> (raw)
In-Reply-To: <98220000.1080501001@[10.10.2.4]>

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

--On 28 March 2004 11:10 -0800 "Martin J. Bligh" <mbligh@aracnet.com> wrote:

> 1. Stop hugepages using the existing overcommit pool for small pages, 
> which breaks small page allocations by prematurely the pool.
> 2. Give hugepages their own over-commit pool, instead of prefaulting.

Indeed.  The previous patches I submitted only address #1.  Attached is
another patch which should address #2, it supplies hugetlb commit
accounting.  This is checked and applied when the segment is created.  It
also supplements the meminfo information to display this new commitment.
The patch only implments strict commitment, but as has been stated here
often, it is not clear that overcommit of unswappable memory makes any
sense in the absence of demand allocation.  When that is implemented then
this will likely need a policy.

Patch applies on top of my previous patch and has been tested on i386.

-apw

[-- Attachment #2: 070-hugetlb_commit.txt --]
[-- Type: text/plain, Size: 4095 bytes --]

---
 file                    |    1 +
 fs/hugetlbfs/inode.c    |   32 ++++++++++++++++++++++++++++++--
 fs/proc/proc_misc.c     |    1 +
 include/linux/hugetlb.h |    3 +++
 4 files changed, 35 insertions(+), 2 deletions(-)

diff -X /home/apw/lib/vdiff.excl -rupN reference/file current/file
--- reference/file	1970-01-01 01:00:00.000000000 +0100
+++ current/file	2004-03-29 12:10:17.000000000 +0100
@@ -0,0 +1 @@
+this is more text
diff -X /home/apw/lib/vdiff.excl -rupN reference/fs/hugetlbfs/inode.c current/fs/hugetlbfs/inode.c
--- reference/fs/hugetlbfs/inode.c	2004-03-25 02:43:00.000000000 +0000
+++ current/fs/hugetlbfs/inode.c	2004-03-29 13:26:57.000000000 +0100
@@ -32,6 +32,25 @@
 /* some random number */
 #define HUGETLBFS_MAGIC	0x958458f6
 
+atomic_t hugetlb_committed_space = ATOMIC_INIT(0);
+
+int hugetlb_acct_memory(long delta)
+{
+	atomic_add(delta, &hugetlb_committed_space);
+	if (delta > 0 && atomic_read(&hugetlb_committed_space) >
+			hugetlb_total_pages()) {
+		atomic_add(-delta, &hugetlb_committed_space);
+		return -ENOMEM;
+	}
+	return 0;
+}
+
+int hugetlbfs_report_meminfo(char *buf)
+{
+	long htlb = atomic_read(&hugetlb_committed_space);
+	return sprintf(buf, "HugeCommited_AS: %5lu\n", htlb);
+}
+
 static struct super_operations hugetlbfs_ops;
 static struct address_space_operations hugetlbfs_aops;
 struct file_operations hugetlbfs_file_operations;
@@ -200,6 +219,7 @@ static void hugetlbfs_delete_inode(struc
 
 	if (inode->i_data.nrpages)
 		truncate_hugepages(&inode->i_data, 0);
+	hugetlb_acct_memory(-(inode->i_size / PAGE_SIZE));
 
 	security_inode_delete(inode);
 
@@ -231,6 +251,8 @@ static void hugetlbfs_forget_inode(struc
 		return;
 	}
 
+	hugetlb_acct_memory(-(inode->i_size / PAGE_SIZE));
+
 	/* write_inode_now() ? */
 	inodes_stat.nr_unused--;
 	hlist_del_init(&inode->i_hash);
@@ -241,6 +263,7 @@ out_truncate:
 	spin_unlock(&inode_lock);
 	if (inode->i_data.nrpages)
 		truncate_hugepages(&inode->i_data, 0);
+	hugetlb_acct_memory(-(inode->i_size / PAGE_SIZE));
 
 	if (sbinfo->free_inodes >= 0) {
 		spin_lock(&sbinfo->stat_lock);
@@ -350,6 +373,10 @@ static int hugetlbfs_setattr(struct dent
 			error = hugetlb_vmtruncate(inode, attr->ia_size);
 		if (error)
 			goto out;
+		/* We rely on the fact that the sizes are hugepage aligned,
+		 * and that hugetlb_vmtruncate prevents extend. */
+		hugetlb_acct_memory((attr->ia_size - i_size_read(inode)) /
+			PAGE_SIZE);
 		attr->ia_valid &= ~ATTR_SIZE;
 	}
 	error = inode_setattr(inode, attr);
@@ -710,8 +737,9 @@ struct file *hugetlb_zero_setup(size_t s
 	if (!capable(CAP_IPC_LOCK))
 		return ERR_PTR(-EPERM);
 
-	if (!is_hugepage_mem_enough(size))
-		return ERR_PTR(-ENOMEM);
+	error = hugetlb_acct_memory(size / PAGE_SIZE);
+	if (error)
+		return ERR_PTR(error);
 
 	root = hugetlbfs_vfsmount->mnt_root;
 	snprintf(buf, 16, "%lu", hugetlbfs_counter());
diff -X /home/apw/lib/vdiff.excl -rupN reference/fs/proc/proc_misc.c current/fs/proc/proc_misc.c
--- reference/fs/proc/proc_misc.c	2004-03-29 12:10:18.000000000 +0100
+++ current/fs/proc/proc_misc.c	2004-03-29 13:27:04.000000000 +0100
@@ -232,6 +232,7 @@ static int meminfo_read_proc(char *page,
 		);
 
 		len += hugetlb_report_meminfo(page + len);
+		len += hugetlbfs_report_meminfo(page + len);
 
 	return proc_calc_metrics(page, start, off, count, eof, len);
 #undef K
diff -X /home/apw/lib/vdiff.excl -rupN reference/include/linux/hugetlb.h current/include/linux/hugetlb.h
--- reference/include/linux/hugetlb.h	2004-03-29 12:10:22.000000000 +0100
+++ current/include/linux/hugetlb.h	2004-03-29 13:22:38.000000000 +0100
@@ -115,11 +115,14 @@ static inline void set_file_hugepages(st
 {
 	file->f_op = &hugetlbfs_file_operations;
 }
+int hugetlbfs_report_meminfo(char *);
+
 #else /* !CONFIG_HUGETLBFS */
 
 #define is_file_hugepages(file)		0
 #define set_file_hugepages(file)	BUG()
 #define hugetlb_zero_setup(size)	ERR_PTR(-ENOSYS)
+#define hugetlbfs_report_meminfo(buf)	0
 
 #endif /* !CONFIG_HUGETLBFS */
 

  parent reply	other threads:[~2004-03-29 12:30 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-03-25 16:54 [PATCH] [0/6] HUGETLB memory commitment Andy Whitcroft
2004-03-25 16:58 ` [PATCH] [1/6] " Andy Whitcroft
2004-03-25 16:59 ` [PATCH] [2/6] " Andy Whitcroft
2004-03-25 17:00 ` [PATCH] [3/6] " Andy Whitcroft
2004-03-25 17:01 ` [PATCH] [4/6] " Andy Whitcroft
2004-03-25 17:02 ` [PATCH] [5/6] " Andy Whitcroft
2004-03-25 17:03 ` [PATCH] [6/6] " Andy Whitcroft
2004-03-25 21:04 ` [PATCH] [0/6] " Andrew Morton
2004-03-25 23:27   ` Andy Whitcroft
2004-03-25 23:51     ` Andrew Morton
2004-03-25 23:59       ` Andy Whitcroft
2004-03-26  2:01         ` Andy Whitcroft
2004-03-26  0:18       ` Martin J. Bligh
2004-03-28 18:02     ` Ray Bryant
2004-03-28 19:10       ` Martin J. Bligh
2004-03-28 21:32         ` [Lse-tech] " Ray Bryant
2004-03-29 16:50           ` Martin J. Bligh
2004-03-29 12:30         ` Andy Whitcroft [this message]
2004-03-26  0:10 ` Keith Owens
2004-03-26  0:22   ` Andrew Morton
2004-03-26  3:41     ` [Lse-tech] " Suparna Bhattacharya
2004-03-26  3:39       ` Keith Owens
2004-03-26 11:45         ` Suparna Bhattacharya
2004-03-29 20:45 ` Chen, Kenneth W
2004-03-29 20:49 ` Chen, Kenneth W
2004-03-30 12:57   ` Andy Whitcroft
2004-03-30 20:04 ` Chen, Kenneth W
2004-03-30 21:48   ` Andy Whitcroft
2004-03-31  1:48     ` Andy Whitcroft
2004-03-31  8:51 ` Chen, Kenneth W
2004-03-31 16:20   ` Andy Whitcroft
2004-04-01 21:15   ` Andy Whitcroft
2004-04-01 22:50     ` Andy Whitcroft
2004-04-01 23:09 ` Chen, Kenneth W
2004-04-03  3:57   ` [PATCH] " Ray Bryant
2004-04-04  3:31     ` Chen, Kenneth W
2004-04-04 22:15       ` Ray Bryant
2004-04-05 15:26       ` [Lse-tech] " Ray Bryant
2004-04-05 17:01         ` Chen, Kenneth W
2004-04-05 18:22           ` Ray Bryant
2004-04-05 23:18         ` Chen, Kenneth W
2004-04-06  1:05           ` Ray Bryant
2004-04-06 16:14           ` Andy Whitcroft
2004-04-06 17:40         ` Chen, Kenneth W

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=11580712.1080567019@42.150.104.212.access.eclipse.net.uk \
    --to=apw@shadowen.org \
    --cc=ak@suse.de \
    --cc=akpm@osdl.org \
    --cc=anton@samba.org \
    --cc=linux-ia64@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lse-tech@lists.sourceforge.net \
    --cc=mbligh@aracnet.com \
    --cc=raybry@sgi.com \
    --cc=sds@epoch.ncsc.mil \
    /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