gfs2: do not evict glocks with populated address spaces
PATCH RESEND 1/1 gfs2: do not evict glocks with populated address spaces
Metadata glocks may have associated address spaces used as caches. Avoid reclaiming such glocks under memory pressure while their mappings are still populated or their state is not unlocked, as this can lead to invalid page cache state and GLOCK_BUG_ON().
--- fs/gfs2/glock.h | 30 ++++++++++++++++++++++++++++++ fs/gfs2/super.c | 3 +++ 2 files changed, 33 insertions(+)
fs/gfs2/glock.h +30 -0
@@ -305,4 +305,34 @@ static inline bool glock_needs_demote(struct gfs2_glock *gl) test_bit(GLF_PENDING_DEMOTE, &gl->gl_flags)); } +/* +* gfs2_glock_not_evictable - check if a glock is not evictable +* @gl: The glock to check +* +* Glocks which do not represent normal filesystem inodes (e.g. statfs, quota, rindex) +* may have associated address spaces used as metadata caches. These glocks must not +* be reclaimed under memory pressure while their mappings are still populated or their +* state is not unlocked. +*/ + +static inline bool gfs2_glock_not_evictable (struct gfs2_glock *gl) +{ +if (gl->gl_name.ln_type ==LM_TYPE_INODE ) +return false; + +if (gl->gl_ops->go_flags &GLOF_ASPACE ) { +struct gfs2_glock_aspace *gla; + + gla = container_of(gl, struct gfs2_glock_aspace, glock); + +if (!mapping_empty (&gla->mapping)) +return true; + } + +if (gl->gl_state !=LM_ST_UNLOCKED ) +return true; + +return false; +} +#endif /* __GLOCK_DOT_H__ */
fs/gfs2/super.c +3 -0
@@ -1164,6 +1164,9 @@ static int gfs2_show_options(struct seq_file *s, struct dentry *root)static void gfs2_glock_put_eventually (struct gfs2_glock *gl) { +if (gfs2_glock_not_evictable (gl)) +return ; +if (current->flags &PF_MEMALLOC )gfs2_glock_put_async (gl);else
Signature · 1 line
2.34.1
Andreas Gruenbacher
maintainerGuilherme,
Quoted 4 lines · Guilherme Giacomo Simoes
Metadata glocks may have associated address spaces used as caches. Avoid reclaiming such glocks under memory pressure while their mappings are still populated or their state is not unlocked, as this can lead to invalid page cache state and
GLOCK_BUG_ON().
What invalid page cache state and GLOCK_BUG_ON() errors is this about, exactly?
Quoted 50 lines
Signed-off-by Guilherme Giacomo Simoes <[email protected]>--- fs/gfs2/glock.h | 30 ++++++++++++++++++++++++++++++ fs/gfs2/super.c | 3 +++ 2 files changed, 33 insertions(+)fs/gfs2/glock.h +30
-0@@ -305,4 +305,34 @@ static inline bool glock_needs_demote(struct gfs2_glock *gl) test_bit(GLF_PENDING_DEMOTE, &gl->gl_flags)); } +/* +* gfs2_glock_not_evictable - check if a glock is not evictable +* @gl: The glock to check +* +* Glocks which do not represent normal filesystem inodes (e.g. statfs, quota, rindex) +* may have associated address spaces used as metadata caches. These glocks must not +* be reclaimed under memory pressure while their mappings are still populated or their +* state is not unlocked. +*/ + +static inline bool gfs2_glock_not_evictable (struct gfs2_glock *gl) +{ +if (gl->gl_name.ln_type ==LM_TYPE_INODE ) +return false; + +if (gl->gl_ops->go_flags &GLOF_ASPACE ) { +struct gfs2_glock_aspace *gla; + + gla = container_of(gl, struct gfs2_glock_aspace, glock); + +if (!mapping_empty (&gla->mapping)) +return true; + } + +if (gl->gl_state !=LM_ST_UNLOCKED ) +return true; + +return false; +} +#endif /* __GLOCK_DOT_H__ */ fs/gfs2/super.c +0
-0
fs/gfs2/super.c static int gfs2_show_options(struct seq_file *s, struct dentry *root) · line 1169
Quoted 6 lines
fs/gfs2/super.c +3
-0@@ -1164,6 +1164,9 @@ static int gfs2_show_options(struct seq_file *s, struct dentry *root)static void gfs2_glock_put_eventually (struct gfs2_glock *gl) { +if (gfs2_glock_not_evictable (gl)) +return ; +
This leaks a glock reference, so it's definitely wrong.
Quoted 6 lines
fs/gfs2/super.c +0
-1if (current->flags &PF_MEMALLOC )gfs2_glock_put_async (gl);else --2.34.1
Thanks,
Andreas
Quoted 6 lines · Andreas Gruenbacher
Quoted 4 lines
Metadata glocks may have associated address spaces used as caches. Avoid reclaiming such glocks under memory pressure while their mappings are still populated or their state is not unlocked, as this can lead to invalid page cache state and
GLOCK_BUG_ON().What invalid page cache state and
GLOCK_BUG_ON()errors is this about, exactly?
On __gfs2_glock_put() (fs/gfs2/glock.c) the GLOCK_BUG_ON() is triggered under memory pressure while the glock is still locked or the glock is populated with metadata caches.
This happens because the __gfs2_glock_put() can't truncate pages with a private datas (truncate_inode_pages_final(mapping) is failed), how the metadata is a
private folio, the GLOCK_BUG_ON(gl, !mapping_empty(mapping)) is trigged.
Quoted 1 line
This leaks a glock reference, so it's definitely wrong.
But this glock is a private folio with metadata or is still locked. I think this can't be evictable
Andreas Gruenbacher
maintainerQuoted 11 lines · Guilherme Giacomo Simoes
Quoted 6 lines · Andreas Gruenbacher
Quoted 4 lines
Metadata glocks may have associated address spaces used as caches. Avoid reclaiming such glocks under memory pressure while their mappings are still populated or their state is not unlocked, as this can lead to invalid page cache state and
GLOCK_BUG_ON().What invalid page cache state and
GLOCK_BUG_ON()errors is this about, exactly?On
__gfs2_glock_put()(fs/gfs2/glock.c) theGLOCK_BUG_ON()is triggered under memory pressure while the glock is still locked or the glock is populated with metadata caches.
There are two GLOCK_BUG_ON() assertions in __gfs2_glock_put(). I assume you are talking about this one:
GLOCK_BUG_ON(gl, !list_empty(&gl->gl_holders));
This should never trigger because each holder has a glock reference (see the gfs2_glock_hold() in __gfs2_holder_init()), and so gl->gl_lockref should never reach zero while there are holders.
If none of the holders has the HIF_HOLDER flag set, we don't know if the glock is actually locked.
Quoted 3 lines
This happens because the
__gfs2_glock_put()can't truncate pages with a private datas (truncate_inode_pages_final(mapping)is failed), how the metadata is a private folio, theGLOCK_BUG_ON(gl, !mapping_empty(mapping))is trigged.
What are the actual messages you are getting?
Quoted 4 lines
Quoted 1 line
This leaks a glock reference, so it's definitely wrong.
But this glock is a private folio with metadata or is still locked. I think this can't be evictable
What even makes you think these glocks are evictable?
Thanks,
Andreas
Quoted 11 lines · Andreas Gruenbacher
There are two
GLOCK_BUG_ON()assertions in__gfs2_glock_put(). I assume you are talking about this one:
GLOCK_BUG_ON(gl, !list_empty(&gl->gl_holders));This should never trigger because each holder has a glock reference (see the
gfs2_glock_hold()in__gfs2_holder_init()), and sogl->gl_lockrefshould never reach zero while there are holders.If none of the holders has the
HIF_HOLDERflag set, we don't know if the glock is actually locked.
Sorry, yes has two GLOCK_BUG_ON() assertions. I talk about the second GLOCK_BUG_ON on __gfs2_glock_put():GLOCK_BUG_ON(gl, !mapping_empty(mapping)).
NOT ABOUT GLOCK_BUG_ON(gl, !list_empty(&gl->gl_holders)); (the first GLOCK_BUG_ON())
The dump_stack() indicates a memory pressure and the gfs2_glock_put_eventually() on fs/gfs2/super.c is called.
But when the __gfs2_glock_put() was called, the glock was has a private folios. I test by this way:
```
struct address_space *mapping = ...;
pgoff_t index;
struct folio *folio;
xa_for_each(&mapping->i_pages, index, folio) {
if (folio_test_private(folio))
pr_err("I have private folios")
}
```And, I can see the glock is about metadata:gl->gl_name.ln_type != LM_TYPE_INODE
the truncate_inode_pages_final() failed silently when the folio is private.
I guess maybe evict metadata (or locked) glock is not a good idea.
Thanks, Guilherme
Guilherme Giacomo Simoes wrotes:
Quoted 21 lines
Sorry, yes has two
GLOCK_BUG_ON()assertions. I talk about the secondGLOCK_BUG_ONon__gfs2_glock_put():GLOCK_BUG_ON(gl, !mapping_empty(mapping)).NOT ABOUT
GLOCK_BUG_ON(gl, !list_empty(&gl->gl_holders));(the firstGLOCK_BUG_ON())The
dump_stack()indicates a memory pressure and thegfs2_glock_put_eventually()onfs/gfs2/super.cis called.
But when the__gfs2_glock_put()was called, the glock was has a private folios. I test by this way:``` struct address_space *mapping = ...; pgoff_t index; struct folio *folio; xa_for_each(&mapping->i_pages, index, folio) { if (folio_test_private(folio)) pr_err("I have private folios") } ```
Quoted 6 lines
And, I can see the glock is about metadata:
gl->gl_name.ln_type != LM_TYPE_INODEthe
truncate_inode_pages_final()failed silently when the folio is private.I guess maybe evict metadata (or locked) glock is not a good idea.
Andreas, thoughs?