Skip to content

Commit

Permalink
mm: introduce and use mapping_empty()
Browse files Browse the repository at this point in the history
Patch series "Remove nrexceptional tracking", v2.

We actually use nrexceptional for very little these days.  It's a minor
pain to keep in sync with nrpages, but the pain becomes much bigger with
the THP patches because we don't know how many indices a shadow entry
occupies.  It's easier to just remove it than keep it accurate.

Also, we save 8 bytes per inode which is nothing to sneeze at; on my
laptop, it would improve shmem_inode_cache from 22 to 23 objects per
16kB, and inode_cache from 26 to 27 objects.  Combined, that saves
a megabyte of memory from a combined usage of 25MB for both caches.
Unfortunately, ext4 doesn't cross a magic boundary, so it doesn't save
any memory for ext4.

This patch (of 4):

Instead of checking the two counters (nrpages and nrexceptional), we can
just check whether i_pages is empty.

Link: https://lkml.kernel.org/r/[email protected]
Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Matthew Wilcox (Oracle) <[email protected]>
Tested-by: Vishal Verma <[email protected]>
Acked-by: Johannes Weiner <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Matthew Wilcox (Oracle) authored and torvalds committed May 5, 2021
1 parent 4d75136 commit 7716506
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 19 deletions.
2 changes: 1 addition & 1 deletion fs/block_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ static void kill_bdev(struct block_device *bdev)
{
struct address_space *mapping = bdev->bd_inode->i_mapping;

if (mapping->nrpages == 0 && mapping->nrexceptional == 0)
if (mapping_empty(mapping))
return;

invalidate_bh_lrus();
Expand Down
2 changes: 1 addition & 1 deletion fs/dax.c
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ int dax_writeback_mapping_range(struct address_space *mapping,
if (WARN_ON_ONCE(inode->i_blkbits != PAGE_SHIFT))
return -EIO;

if (!mapping->nrexceptional || wbc->sync_mode != WB_SYNC_ALL)
if (mapping_empty(mapping) || wbc->sync_mode != WB_SYNC_ALL)
return 0;

trace_dax_writeback_range(inode, xas.xa_index, end_index);
Expand Down
3 changes: 1 addition & 2 deletions fs/gfs2/glock.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,7 @@ static void __gfs2_glock_put(struct gfs2_glock *gl)
if (mapping) {
truncate_inode_pages_final(mapping);
if (!gfs2_withdrawn(sdp))
GLOCK_BUG_ON(gl, mapping->nrpages ||
mapping->nrexceptional);
GLOCK_BUG_ON(gl, !mapping_empty(mapping));
}
trace_gfs2_glock_put(gl);
sdp->sd_lockstruct.ls_ops->lm_put_lock(gl);
Expand Down
5 changes: 5 additions & 0 deletions include/linux/pagemap.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@

struct pagevec;

static inline bool mapping_empty(struct address_space *mapping)
{
return xa_empty(&mapping->i_pages);
}

/*
* Bits in mapping->flags.
*/
Expand Down
18 changes: 3 additions & 15 deletions mm/truncate.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ void truncate_inode_pages_range(struct address_space *mapping,
pgoff_t index;
int i;

if (mapping->nrpages == 0 && mapping->nrexceptional == 0)
if (mapping_empty(mapping))
goto out;

/* Offsets within partial pages */
Expand Down Expand Up @@ -440,9 +440,6 @@ EXPORT_SYMBOL(truncate_inode_pages);
*/
void truncate_inode_pages_final(struct address_space *mapping)
{
unsigned long nrexceptional;
unsigned long nrpages;

/*
* Page reclaim can not participate in regular inode lifetime
* management (can't call iput()) and thus can race with the
Expand All @@ -452,16 +449,7 @@ void truncate_inode_pages_final(struct address_space *mapping)
*/
mapping_set_exiting(mapping);

/*
* When reclaim installs eviction entries, it increases
* nrexceptional first, then decreases nrpages. Make sure we see
* this in the right order or we might miss an entry.
*/
nrpages = mapping->nrpages;
smp_rmb();
nrexceptional = mapping->nrexceptional;

if (nrpages || nrexceptional) {
if (!mapping_empty(mapping)) {
/*
* As truncation uses a lockless tree lookup, cycle
* the tree lock to make sure any ongoing tree
Expand Down Expand Up @@ -633,7 +621,7 @@ int invalidate_inode_pages2_range(struct address_space *mapping,
int ret2 = 0;
int did_range_unmap = 0;

if (mapping->nrpages == 0 && mapping->nrexceptional == 0)
if (mapping_empty(mapping))
goto out;

pagevec_init(&pvec);
Expand Down

0 comments on commit 7716506

Please sign in to comment.