linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [patch] hugetlb: fix i_blocks accounting
@ 2007-10-20 18:18 Ken Chen
  2007-10-23 14:52 ` Adam Litke
  0 siblings, 1 reply; 10+ messages in thread
From: Ken Chen @ 2007-10-20 18:18 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-mm

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/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index 12aca8e..ed6def0 100644
--- a/fs/hugetlbfs/inode.c
+++ b/fs/hugetlbfs/inode.c
@@ -862,7 +862,8 @@ out_free:
 int hugetlb_get_quota(struct address_space *mapping)
 {
 	int ret = 0;
-	struct hugetlbfs_sb_info *sbinfo = HUGETLBFS_SB(mapping->host->i_sb);
+	struct inode *inode = mapping->host;
+	struct hugetlbfs_sb_info *sbinfo = HUGETLBFS_SB(inode->i_sb);

 	if (sbinfo->free_blocks > -1) {
 		spin_lock(&sbinfo->stat_lock);
@@ -873,13 +874,17 @@ int hugetlb_get_quota(struct address_space *mapping)
 		spin_unlock(&sbinfo->stat_lock);
 	}

+	if (!ret)
+		inode->i_blocks += BLOCKS_PER_HUGEPAGE;
 	return ret;
 }

 void hugetlb_put_quota(struct address_space *mapping)
 {
-	struct hugetlbfs_sb_info *sbinfo = HUGETLBFS_SB(mapping->host->i_sb);
+	struct inode *inode = mapping->host;
+	struct hugetlbfs_sb_info *sbinfo = HUGETLBFS_SB(inode->i_sb);

+	inode->i_blocks -= BLOCKS_PER_HUGEPAGE;
 	if (sbinfo->free_blocks > -1) {
 		spin_lock(&sbinfo->stat_lock);
 		sbinfo->free_blocks++;
diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
index ea0f50b..694cf8b 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);
 void hugetlb_put_quota(struct address_space *mapping);

+#define BLOCKS_PER_HUGEPAGE	(HPAGE_SIZE / 512)
+
 static inline int is_file_hugepages(struct file *file)
 {
 	if (file->f_op == &hugetlbfs_file_operations)

--
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>

^ permalink raw reply related	[flat|nested] 10+ messages in thread
[parent not found: <b040c32a0711082343t2b94b495r1608d99ec0e28a4c@mail.gmail.com>]

end of thread, other threads:[~2007-11-12 14:52 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-20 18:18 [patch] hugetlb: fix i_blocks accounting Ken Chen
2007-10-23 14:52 ` Adam Litke
2007-10-24  0:34   ` Ken Chen
2007-10-24 13:06     ` Adam Litke
     [not found] <b040c32a0711082343t2b94b495r1608d99ec0e28a4c@mail.gmail.com>
2007-11-09 17:31 ` Ken Chen
     [not found] ` <1194617837.14675.45.camel@localhost.localdomain>
2007-11-09 17:42   ` 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

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).