linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] fs: Add a filesystem flag for THPs
@ 2020-09-16  3:27 Matthew Wilcox (Oracle)
  2020-09-16  3:27 ` [PATCH 2/2] fs: Do not update nr_thps for mappings which support THPs Matthew Wilcox (Oracle)
  0 siblings, 1 reply; 4+ messages in thread
From: Matthew Wilcox (Oracle) @ 2020-09-16  3:27 UTC (permalink / raw)
  To: Alexander Viro
  Cc: Matthew Wilcox (Oracle),
	linux-fsdevel, Hugh Dickins, Andrew Morton, linux-mm,
	linux-kernel, Song Liu, Rik van Riel, Kirill A . Shutemov,
	Johannes Weiner, Dave Chinner

The page cache needs to know whether the filesystem supports THPs so that
it doesn't send THPs to filesystems which can't handle them.  Dave Chinner
points out that getting from the page mapping to the filesystem type
is too many steps (mapping->host->i_sb->s_type->fs_flags) so cache that
information in the address space flags.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 fs/inode.c              | 2 ++
 include/linux/fs.h      | 1 +
 include/linux/pagemap.h | 6 ++++++
 mm/shmem.c              | 2 +-
 4 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/fs/inode.c b/fs/inode.c
index 13d8c0a44e23..4531358ae97b 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -181,6 +181,8 @@ int inode_init_always(struct super_block *sb, struct inode *inode)
 	mapping->a_ops = &empty_aops;
 	mapping->host = inode;
 	mapping->flags = 0;
+	if (sb->s_type->fs_flags & FS_THP_SUPPORT)
+		__set_bit(AS_THP_SUPPORT, &mapping->flags);
 	mapping->wb_err = 0;
 	atomic_set(&mapping->i_mmap_writable, 0);
 #ifdef CONFIG_READ_ONLY_THP_FOR_FS
diff --git a/include/linux/fs.h b/include/linux/fs.h
index f8d75e4ad9d7..f10190b22d5a 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2217,6 +2217,7 @@ struct file_system_type {
 #define FS_HAS_SUBTYPE		4
 #define FS_USERNS_MOUNT		8	/* Can be mounted by userns root */
 #define FS_DISALLOW_NOTIFY_PERM	16	/* Disable fanotify permission events */
+#define FS_THP_SUPPORT		8192	/* Remove once all fs converted */
 #define FS_RENAME_DOES_D_MOVE	32768	/* FS will handle d_move() during rename() internally. */
 	int (*init_fs_context)(struct fs_context *);
 	const struct fs_parameter_spec *parameters;
diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index 09738075e478..ecb03e1b3555 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -34,6 +34,7 @@ enum mapping_flags {
 	AS_EXITING	= 4, 	/* final truncate in progress */
 	/* writeback related tags are not used */
 	AS_NO_WRITEBACK_TAGS = 5,
+	AS_THP_SUPPORT = 6,	/* THPs supported */
 };
 
 /**
@@ -124,6 +125,11 @@ static inline void mapping_set_gfp_mask(struct address_space *m, gfp_t mask)
 	m->gfp_mask = mask;
 }
 
+static inline bool mapping_thp_support(struct address_space *mapping)
+{
+	return test_bit(AS_THP_SUPPORT, &mapping->flags);
+}
+
 void release_pages(struct page **pages, int nr);
 
 /*
diff --git a/mm/shmem.c b/mm/shmem.c
index bb0ebb52fcbe..c763a340ea86 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -3844,7 +3844,7 @@ static struct file_system_type shmem_fs_type = {
 	.parameters	= shmem_fs_parameters,
 #endif
 	.kill_sb	= kill_litter_super,
-	.fs_flags	= FS_USERNS_MOUNT,
+	.fs_flags	= FS_USERNS_MOUNT | FS_THP_SUPPORT,
 };
 
 int __init shmem_init(void)
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] fs: Do not update nr_thps for mappings which support THPs
  2020-09-16  3:27 [PATCH 1/2] fs: Add a filesystem flag for THPs Matthew Wilcox (Oracle)
@ 2020-09-16  3:27 ` Matthew Wilcox (Oracle)
  2020-09-16  5:21   ` Christoph Hellwig
  0 siblings, 1 reply; 4+ messages in thread
From: Matthew Wilcox (Oracle) @ 2020-09-16  3:27 UTC (permalink / raw)
  To: Alexander Viro
  Cc: Matthew Wilcox (Oracle),
	linux-fsdevel, Hugh Dickins, Andrew Morton, linux-mm,
	linux-kernel, Song Liu, Rik van Riel, Kirill A . Shutemov,
	Johannes Weiner, Dave Chinner

The nr_thps counter is to support THPs in the page cache when the
filesystem doesn't understand THPs.  Eventually it will be removed, but
we should still support filesystems which do not understand THPs yet.
Move the nr_thp manipulation functions to filemap.h since they're
page-cache specific.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 include/linux/fs.h      | 27 ---------------------------
 include/linux/pagemap.h | 29 +++++++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 27 deletions(-)

diff --git a/include/linux/fs.h b/include/linux/fs.h
index f10190b22d5a..83d8f3ba17a5 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2701,33 +2701,6 @@ static inline errseq_t file_sample_sb_err(struct file *file)
 	return errseq_sample(&file->f_path.dentry->d_sb->s_wb_err);
 }
 
-static inline int filemap_nr_thps(struct address_space *mapping)
-{
-#ifdef CONFIG_READ_ONLY_THP_FOR_FS
-	return atomic_read(&mapping->nr_thps);
-#else
-	return 0;
-#endif
-}
-
-static inline void filemap_nr_thps_inc(struct address_space *mapping)
-{
-#ifdef CONFIG_READ_ONLY_THP_FOR_FS
-	atomic_inc(&mapping->nr_thps);
-#else
-	WARN_ON_ONCE(1);
-#endif
-}
-
-static inline void filemap_nr_thps_dec(struct address_space *mapping)
-{
-#ifdef CONFIG_READ_ONLY_THP_FOR_FS
-	atomic_dec(&mapping->nr_thps);
-#else
-	WARN_ON_ONCE(1);
-#endif
-}
-
 extern int vfs_fsync_range(struct file *file, loff_t start, loff_t end,
 			   int datasync);
 extern int vfs_fsync(struct file *file, int datasync);
diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index ecb03e1b3555..2b637960be3a 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -130,6 +130,35 @@ static inline bool mapping_thp_support(struct address_space *mapping)
 	return test_bit(AS_THP_SUPPORT, &mapping->flags);
 }
 
+static inline int filemap_nr_thps(struct address_space *mapping)
+{
+#ifdef CONFIG_READ_ONLY_THP_FOR_FS
+	return atomic_read(&mapping->nr_thps);
+#else
+	return 0;
+#endif
+}
+
+static inline void filemap_nr_thps_inc(struct address_space *mapping)
+{
+#ifdef CONFIG_READ_ONLY_THP_FOR_FS
+	if (!mapping_thp_support(mapping))
+		atomic_inc(&mapping->nr_thps);
+#else
+	WARN_ON_ONCE(1);
+#endif
+}
+
+static inline void filemap_nr_thps_dec(struct address_space *mapping)
+{
+#ifdef CONFIG_READ_ONLY_THP_FOR_FS
+	if (!mapping_thp_support(mapping))
+		atomic_dec(&mapping->nr_thps);
+#else
+	WARN_ON_ONCE(1);
+#endif
+}
+
 void release_pages(struct page **pages, int nr);
 
 /*
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] fs: Do not update nr_thps for mappings which support THPs
  2020-09-16  3:27 ` [PATCH 2/2] fs: Do not update nr_thps for mappings which support THPs Matthew Wilcox (Oracle)
@ 2020-09-16  5:21   ` Christoph Hellwig
  2020-09-16 11:46     ` Matthew Wilcox
  0 siblings, 1 reply; 4+ messages in thread
From: Christoph Hellwig @ 2020-09-16  5:21 UTC (permalink / raw)
  To: Matthew Wilcox (Oracle)
  Cc: Alexander Viro, linux-fsdevel, Hugh Dickins, Andrew Morton,
	linux-mm, linux-kernel, Song Liu, Rik van Riel,
	Kirill A . Shutemov, Johannes Weiner, Dave Chinner

On Wed, Sep 16, 2020 at 04:27:17AM +0100, Matthew Wilcox (Oracle) wrote:
> The nr_thps counter is to support THPs in the page cache when the
> filesystem doesn't understand THPs.  Eventually it will be removed, but
> we should still support filesystems which do not understand THPs yet.
> Move the nr_thp manipulation functions to filemap.h since they're
> page-cache specific.

Honestly I don't think we should support the read-only THP crap.  We
should in fact never have merged that bandaid to start with given that
you did good progress on the real thing.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] fs: Do not update nr_thps for mappings which support THPs
  2020-09-16  5:21   ` Christoph Hellwig
@ 2020-09-16 11:46     ` Matthew Wilcox
  0 siblings, 0 replies; 4+ messages in thread
From: Matthew Wilcox @ 2020-09-16 11:46 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Alexander Viro, linux-fsdevel, Hugh Dickins, Andrew Morton,
	linux-mm, linux-kernel, Song Liu, Rik van Riel,
	Kirill A . Shutemov, Johannes Weiner, Dave Chinner

On Wed, Sep 16, 2020 at 06:21:26AM +0100, Christoph Hellwig wrote:
> On Wed, Sep 16, 2020 at 04:27:17AM +0100, Matthew Wilcox (Oracle) wrote:
> > The nr_thps counter is to support THPs in the page cache when the
> > filesystem doesn't understand THPs.  Eventually it will be removed, but
> > we should still support filesystems which do not understand THPs yet.
> > Move the nr_thp manipulation functions to filemap.h since they're
> > page-cache specific.
> 
> Honestly I don't think we should support the read-only THP crap.  We
> should in fact never have merged that bandaid to start with given that
> you did good progress on the real thing.

I'd like to see the feature ripped out again, yes.  Once we have a few more
filesystems converted, I think that'll be a reasonable thing to do.

It was a good step along the way; Song fixed a number of problems,
and worked on other things that I never had to learn anything about
(like uprobes and khugepaged).  I wouldn't go so far as to say we should
never have merged it, but I think we can remove it in about six months.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-09-16 20:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-16  3:27 [PATCH 1/2] fs: Add a filesystem flag for THPs Matthew Wilcox (Oracle)
2020-09-16  3:27 ` [PATCH 2/2] fs: Do not update nr_thps for mappings which support THPs Matthew Wilcox (Oracle)
2020-09-16  5:21   ` Christoph Hellwig
2020-09-16 11:46     ` Matthew Wilcox

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