linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "Ken Chen" <kenchen@google.com>
To: linux-mm <linux-mm@kvack.org>
Subject: [patch] hugetlb: fix i_blocks accounting
Date: Fri, 9 Nov 2007 09:31:12 -0800	[thread overview]
Message-ID: <b040c32a0711090931v76c3c230k886639b14574f978@mail.gmail.com> (raw)
In-Reply-To: <b040c32a0711082343t2b94b495r1608d99ec0e28a4c@mail.gmail.com>

resent as I mistakenly bcc'ed linux-mm mailing list, where I really meant to cc.

---------- Forwarded message ----------
From: Ken Chen <kenchen@google.com>
Date: Nov 8, 2007 11:43 PM
Subject: [patch] hugetlb: fix i_blocks accounting
To: Andrew Morton <akpm@linux-foundation.org>, Adam Litke <agl@us.ibm.com>


rebase i_blocks bug fix on top of Adam's recent fs quota work.

------
For administrative purpose, we want to query actual block usage for
hugetlbfs file via fstat.  Currently, hugetlbfs always return 0.  Fix
that up since kernel already has all the information to track it
properly.


Signed-off-by: Ken Chen <kenchen@google.com>

diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
index 770dbed..65371bd 100644
--- a/include/linux/hugetlb.h
+++ b/include/linux/hugetlb.h
@@ -168,6 +168,8 @@ struct file *hugetlb_file_setup(const char *name, size_t);
 int hugetlb_get_quota(struct address_space *mapping, long delta);
 void hugetlb_put_quota(struct address_space *mapping, long delta);

+#define BLOCKS_PER_HUGEPAGE	(HPAGE_SIZE / 512)
+
 static inline int is_file_hugepages(struct file *file)
 {
 	if (file->f_op == &hugetlbfs_file_operations)
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index b58edd0..0d54370 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -801,6 +801,7 @@ retry:

 		if (vma->vm_flags & VM_SHARED) {
 			int err;
+			struct inode *inode = mapping->host;

 			err = add_to_page_cache(page, mapping, idx, GFP_KERNEL);
 			if (err) {
@@ -809,6 +810,10 @@ retry:
 					goto retry;
 				goto out;
 			}
+
+			spin_lock(&inode->i_lock);
+			inode->i_blocks += BLOCKS_PER_HUGEPAGE;
+			spin_unlock(&inode->i_lock);
 		} else
 			lock_page(page);
 	}
@@ -1159,6 +1164,11 @@ int hugetlb_reserve_pages(struct inode *inode,
long from, long to)
 void hugetlb_unreserve_pages(struct inode *inode, long offset, long freed)
 {
 	long chg = region_truncate(&inode->i_mapping->private_list, offset);
+
+	spin_lock(&inode->i_lock);
+	inode->i_blocks -= BLOCKS_PER_HUGEPAGE * freed;
+	spin_unlock(&inode->i_lock);
+
 	hugetlb_put_quota(inode->i_mapping, (chg - freed));
 	hugetlb_acct_memory(-(chg - freed));
 }

--
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:[~2007-11-09 17:31 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <b040c32a0711082343t2b94b495r1608d99ec0e28a4c@mail.gmail.com>
2007-11-09 17:31 ` Ken Chen [this message]
     [not found] ` <1194617837.14675.45.camel@localhost.localdomain>
2007-11-09 17:42   ` [patch] hugetlb: fix i_blocks accounting Ken Chen
2007-11-09 18:09     ` aglitke
2007-11-10  1:16       ` Andrew Morton
2007-11-10  1:34         ` Ken Chen
2007-11-12 14:53           ` aglitke
2007-10-20 18:18 Ken Chen
2007-10-23 14:52 ` Adam Litke
2007-10-24  0:34   ` Ken Chen
2007-10-24 13:06     ` Adam Litke

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=b040c32a0711090931v76c3c230k886639b14574f978@mail.gmail.com \
    --to=kenchen@google.com \
    --cc=linux-mm@kvack.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).