lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1375582645-29274-19-git-send-email-kirill.shutemov@linux.intel.com>
Date:	Sun,  4 Aug 2013 05:17:20 +0300
From:	"Kirill A. Shutemov" <kirill.shutemov@...ux.intel.com>
To:	Andrea Arcangeli <aarcange@...hat.com>,
	Andrew Morton <akpm@...ux-foundation.org>
Cc:	Al Viro <viro@...iv.linux.org.uk>, Hugh Dickins <hughd@...gle.com>,
	Wu Fengguang <fengguang.wu@...el.com>, Jan Kara <jack@...e.cz>,
	Mel Gorman <mgorman@...e.de>, linux-mm@...ck.org,
	Andi Kleen <ak@...ux.intel.com>,
	Matthew Wilcox <willy@...ux.intel.com>,
	"Kirill A. Shutemov" <kirill@...temov.name>,
	Hillf Danton <dhillf@...il.com>, Dave Hansen <dave@...1.net>,
	Ning Qu <quning@...gle.com>, linux-fsdevel@...r.kernel.org,
	linux-kernel@...r.kernel.org,
	"Kirill A. Shutemov" <kirill.shutemov@...ux.intel.com>
Subject: [PATCH 18/23] thp: libfs: introduce simple_thp_release()

From: "Kirill A. Shutemov" <kirill.shutemov@...ux.intel.com>

simple_thp_release() is a dummy implementation of fops->release with
transparent huge page support. It's required to minimize memory overhead
of huge pages for small files.

It checks whether we should split the last page in the file to give
memory back to the system.

We split the page if it meets following criteria:
 - nobody has the file opened on write;
 - spliting will actually free any memory (at least one small page);
 - if it's a huge page ;)

Signed-off-by: Kirill A. Shutemov <kirill.shutemov@...ux.intel.com>
---
 fs/libfs.c         | 27 +++++++++++++++++++++++++++
 include/linux/fs.h |  2 ++
 2 files changed, 29 insertions(+)

diff --git a/fs/libfs.c b/fs/libfs.c
index 934778b..c43b055 100644
--- a/fs/libfs.c
+++ b/fs/libfs.c
@@ -488,6 +488,33 @@ int simple_thp_write_begin(struct file *file, struct address_space *mapping,
 	}
 	return 0;
 }
+
+int simple_thp_release(struct inode *inode, struct file *file)
+{
+	pgoff_t last_index;
+	struct page *page;
+
+	/* check if anybody still writes to file */
+	if (atomic_read(&inode->i_writecount) != !!(file->f_mode & FMODE_WRITE))
+		return 0;
+
+	last_index = i_size_read(inode) >> PAGE_CACHE_SHIFT;
+
+	/* check if splitting the page will free any memory */
+	if ((last_index & HPAGE_CACHE_INDEX_MASK) + 1 == HPAGE_CACHE_NR)
+		return 0;
+
+	page = find_get_page(file->f_mapping,
+			last_index & ~HPAGE_CACHE_INDEX_MASK);
+	if (!page)
+		return 0;
+
+	if (PageTransHuge(page))
+		split_huge_page(page);
+
+	page_cache_release(page);
+	return 0;
+}
 #endif
 
 /*
diff --git a/include/linux/fs.h b/include/linux/fs.h
index c1dbf43..b594f10 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2557,8 +2557,10 @@ extern int simple_write_end(struct file *file, struct address_space *mapping,
 extern int simple_thp_write_begin(struct file *file,
 		struct address_space *mapping, loff_t pos, unsigned len,
 		unsigned flags,	struct page **pagep, void **fsdata);
+extern int simple_thp_release(struct inode *inode, struct file *file);
 #else
 #define simple_thp_write_begin simple_write_begin
+#define simple_thp_release NULL
 #endif
 
 extern struct dentry *simple_lookup(struct inode *, struct dentry *, unsigned int flags);
-- 
1.8.3.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ