Skip to contentSkip to conversation

Per superblock shrinkers V2

PATCH In review Dave Chinner 6 participants 38 messages May 25, 2010 – Jul 12, 2010

Subsystems (15)
DRM drivers Memory management x86 VFS +11 more subsystems
lore
Share & tools
lore
#0 lore raw

cover Per superblock shrinkers V2

This series reworks the filesystem shrinkers. We currently have a set of issues with the current filesystem shrinkers:

1. There is an dependency between dentry and inode cache shrinking that is only implicitly defined by the order of shrinker registration.
2. The shrinkers need to walk the superblock list and pin the superblock to avoid unmount races with the sb going away.
3. The dentry cache uses per-superblock LRUs and proportions reclaim between all the superblocks which means we are doing breadth based reclaim. This means we touch every superblock for every shrinker call, and may only reclaim a single dentry at a time from a given superblock.
4. The inode cache has a global LRU, so it has different reclaim patterns to the dentry cache, despite the fact that the dentry cache is generally the only thing that pins inodes in memory.
5. Filesystems need to register their own shrinkers for caches and can't co-ordinate them with the dentry and inode cache shrinkers.

The series starts by converting the inode cache to per-superblock LRUs and changes the shrinker to match the dentry cache (#4).

It then adds a context to the shrinker callouts by passing the shrinker structure with the callout. With this, a shrinker structure is added to the superblock structure and a per-superblock shrinker is registered. Both the inode and dentry caches are modified to shrunk via the superblock shrinker, and this directly encodes the dcache/icache dependency inside the shrinker (#1).

This shrinker structure also avoids the need to pin the superblock inside the shrinker because the shrinker is unregistered before the superblock is freed (#2). Further, it pushes the proportioning of reclaim between superblocks back up into the shrinker and batches all the reclaim from a superblock into a tight call loop until the shrink cycle for that superblock is complete. This effectively converts reclaim to a depth-based reclaim mechanism which has a smaller CPU cache footprint than the current mechanism (#3).

Then a pair of superblock operations that can be used to implement filesystem specific cache reclaim is added. This is split into two operations we don't need to overload the number of objects to scan to indicate that a count should be returned.

Finally, the XFS inode cache shrinker is converted to use these superblock operations, removing the need to register a shrinker, keep a global list of XFS filesystems and locking to access the per-filesystem caches. This fixes several new lockdep warnings the XFS shrinker introduces because of the different contexts the shrinker is called in, and allows for correct proportioning of reclaim between the dentry, inode and XFS inode caches on the filesystem to be executed (#5).

Version 2:
- rebase on new superblock iterator code in 2.6.35
- move sb shrinker registration to sget() and unregister to deactivate_super() to avoid unregister_shrinker() being called inside a spinlock.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#1 lore raw

PATCH 1/5 inode: Make unused inode LRU per superblock

From: Dave Chinner <[email protected]>

The inode unused list is currently a global LRU. This does not match the other global filesystem cache - the dentry cache - which uses per-superblock LRU lists. Hence we have related filesystem object types using different LRU reclaimatin schemes.

To enable a per-superblock filesystem cache shrinker, both of these caches need to have per-sb unused object LRU lists. Hence this patch converts the global inode LRU to per-sb LRUs.

The patch only does rudimentary per-sb propotioning in the shrinker infrastructure, as this gets removed when the per-sb shrinker callouts are introduced later on.

---
 fs/fs-writeback.c         |    2 +-
 fs/inode.c                |   87 +++++++++++++++++++++++++++++++++++++++-----
 fs/super.c                |    1 +
 include/linux/fs.h        |    4 ++
 include/linux/writeback.h |    1 -
 5 files changed, 83 insertions(+), 12 deletions(-)
fs/fs-writeback.c +1 -1
index 5c4161f..b1e76ef 100644
@@ -565,7 +565,7 @@ select_queue:
 			/*
 			 * The inode is clean, unused
 			 */
-			list_move(&inode->i_list, &inode_unused);
+			list_move(&inode->i_list, &inode->i_sb->s_inode_lru);
 		}
 	}
 	inode_sync_complete(inode);
fs/inode.c +77 -10

168 lines not on this page · raw message

fs/super.c +1 -0
index 69688b1..c554c53 100644
@@ -60,6 +60,7 @@ static struct super_block *alloc_super(struct file_system_type *type)
 		INIT_HLIST_HEAD(&s->s_anon);
 		INIT_LIST_HEAD(&s->s_inodes);
 		INIT_LIST_HEAD(&s->s_dentry_lru);
+		INIT_LIST_HEAD(&s->s_inode_lru);
 		init_rwsem(&s->s_umount);
 		mutex_init(&s->s_lock);
 		lockdep_set_class(&s->s_umount, &type->s_umount_key);
include/linux/fs.h +4 -0
index b336cb9..7b90c43 100644
@@ -1346,6 +1346,10 @@ struct super_block {
 	struct list_head	s_dentry_lru;	/* unused dentry lru */
 	int			s_nr_dentry_unused;	/* # of dentry on lru */
 
+	/* s_inode_lru and s_nr_inodes_unused are protected by inode_lock */
+	struct list_head	s_inode_lru;	/* unused inode lru */
+	int			s_nr_inodes_unused;	/* # of inodes on lru */
+
 	struct block_device	*s_bdev;
 	struct backing_dev_info *s_bdi;
 	struct mtd_info		*s_mtd;
include/linux/writeback.h +0 -1
index cc97d6c..a74837e 100644
@@ -11,7 +11,6 @@ struct backing_dev_info;
 
 extern spinlock_t inode_lock;
 extern struct list_head inode_in_use;
-extern struct list_head inode_unused;
 
 /*
  * fs/fs-writeback.c
Signature · 6 lines
1.5.6.5

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#2 lore raw

Re: [PATCH 1/5] inode: Make unused inode LRU per superblock

Quoted 6 lines · Dave Chinner

From: Dave Chinner <[email protected]>

The inode unused list is currently a global LRU. This does not match the other global filesystem cache - the dentry cache - which uses per-superblock LRU lists. Hence we have related filesystem object types using different LRU reclaimatin schemes.

Is this an improvement I wonder? The dcache is using per sb lists because it specifically requires sb traversal.

What allocation/reclaim really wants (for good scalability and NUMA characteristics) is per-zone lists for these things. It's easy to convert a single list into per-zone lists.

It is much harder to convert per-sb lists into per-sb x per-zone lists.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#3 lore raw

Re: [PATCH 1/5] inode: Make unused inode LRU per superblock

Quoted 10 lines · Nick Piggin
Quoted 6 lines · Dave Chinner

From: Dave Chinner <[email protected]>

The inode unused list is currently a global LRU. This does not match the other global filesystem cache - the dentry cache - which uses per-superblock LRU lists. Hence we have related filesystem object types using different LRU reclaimatin schemes.

Is this an improvement I wonder? The dcache is using per sb lists because it specifically requires sb traversal.

Right - I originally implemented the per-sb dentry lists for scalability purposes. i.e. to avoid monopolising the dentry_lock during unmount looking for dentries on a specific sb and hanging the system for several minutes.

However, the reason for doing this to the inode cache is not for scalability, it's because we have a tight relationship between the dentry and inode cacheѕ. That is, reclaim from the dentry LRU grows the inode LRU. Like the registration of the shrinkers, this is kind of an implicit, undocumented behavour of the current shrinker implemenation.

What this patch series does is take that implicit relationship and make it explicit. It also allows other filesystem caches to tie into the relationship if they need to (e.g. the XFS inode cache). What it _doesn't do_ is change the macro level behaviour of the shrinkers...

Quoted 5 lines

What allocation/reclaim really wants (for good scalability and NUMA characteristics) is per-zone lists for these things. It's easy to convert a single list into per-zone lists.

It is much harder to convert per-sb lists into per-sb x per-zone lists.

No it's not. Just convert the s_{dentry,inode}_lru lists on each superblock and call the shrinker with a new zone mask field to pick the correct LRU. That's no harder than converting a global LRU. Anyway, you'd still have to do per-sb x per-zone lists for the dentry LRUs, so changing the inode cache to per-sb makes no difference.

However, this is a moot point because we don't have per-zone shrinker interfaces. That's an entirely separate discussion because of the macro-level behavioural changes it implies....

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#4 lore raw

Re: [PATCH 1/5] inode: Make unused inode LRU per superblock

Quoted 17 lines · Dave Chinner
Quoted 10 lines · Nick Piggin
Quoted 6 lines · Dave Chinner

From: Dave Chinner <[email protected]>

The inode unused list is currently a global LRU. This does not match the other global filesystem cache - the dentry cache - which uses per-superblock LRU lists. Hence we have related filesystem object types using different LRU reclaimatin schemes.

Is this an improvement I wonder? The dcache is using per sb lists because it specifically requires sb traversal.

Right - I originally implemented the per-sb dentry lists for scalability purposes. i.e. to avoid monopolising the dentry_lock during unmount looking for dentries on a specific sb and hanging the system for several minutes.

Quoted 6 lines

However, the reason for doing this to the inode cache is not for scalability, it's because we have a tight relationship between the dentry and inode cacheѕ. That is, reclaim from the dentry LRU grows the inode LRU. Like the registration of the shrinkers, this is kind of an implicit, undocumented behavour of the current shrinker implemenation.

Right, that's why I wonder whether it is an improvement. It would be interesting to see some tests (showing at least parity).

Quoted 10 lines

What this patch series does is take that implicit relationship and make it explicit. It also allows other filesystem caches to tie into the relationship if they need to (e.g. the XFS inode cache). What it _doesn't do_ is change the macro level behaviour of the shrinkers...

Quoted 4 lines

What allocation/reclaim really wants (for good scalability and NUMA characteristics) is per-zone lists for these things. It's easy to convert a single list into per-zone lists.

Quoted 7 lines
Quoted 1 line

It is much harder to convert per-sb lists into per-sb x per-zone lists.

No it's not. Just convert the s_{dentry,inode}_lru lists on each superblock and call the shrinker with a new zone mask field to pick the correct LRU. That's no harder than converting a global LRU. Anyway, you'd still have to do per-sb x per-zone lists for the dentry LRUs, so changing the inode cache to per-sb makes no difference.

Right, it just makes it harder to do. By much harder, I did mostly mean the extra memory overhead. If there is *no* benefit from doing per-sb icache then I would question whether we should.

Quoted 3 lines

However, this is a moot point because we don't have per-zone shrinker interfaces. That's an entirely separate discussion because of the macro-level behavioural changes it implies....

Yep. I have some patches for it, but they're currently behind the other fine grained locking stuff. But it's something that really needs to be implemented, IMO.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#5 lore raw

Re: [PATCH 1/5] inode: Make unused inode LRU per superblock

Quoted 25 lines · Nick Piggin
Quoted 17 lines · Dave Chinner
Quoted 10 lines · Nick Piggin
Quoted 6 lines · Dave Chinner

From: Dave Chinner <[email protected]>

The inode unused list is currently a global LRU. This does not match the other global filesystem cache - the dentry cache - which uses per-superblock LRU lists. Hence we have related filesystem object types using different LRU reclaimatin schemes.

Is this an improvement I wonder? The dcache is using per sb lists because it specifically requires sb traversal.

Right - I originally implemented the per-sb dentry lists for scalability purposes. i.e. to avoid monopolising the dentry_lock during unmount looking for dentries on a specific sb and hanging the system for several minutes.

Quoted 6 lines

However, the reason for doing this to the inode cache is not for scalability, it's because we have a tight relationship between the dentry and inode cacheѕ. That is, reclaim from the dentry LRU grows the inode LRU. Like the registration of the shrinkers, this is kind of an implicit, undocumented behavour of the current shrinker implemenation.

Quoted 2 lines

Right, that's why I wonder whether it is an improvement. It would be interesting to see some tests (showing at least parity).

I've done some testing showing parity. They've been along the lines of:
- populate cache with 1m dentries + inodes
- run 'time echo 2 > /proc/sys/vm/drop_caches'

I've used different methods of populating the caches to have them non-sequential in the LRU (i.e. trigger fragmentation), have dirty backing inodes (e.g. the VFS inode clean, the xfs inode dirty because transactions haven't completed), etc.

The variation on the test is around +-10%, with the per-sb shrinkers averaging about 5% lower time to reclaim. This is within the error margin of the test, so it's not really a conclusive win, but it is certainly shows that it does not slow anything down. If you've got a better way to test it, then I'm all ears....

Quoted 12 lines
Quoted 12 lines

What this patch series does is take that implicit relationship and make it explicit. It also allows other filesystem caches to tie into the relationship if they need to (e.g. the XFS inode cache). What it _doesn't do_ is change the macro level behaviour of the shrinkers...

Quoted 5 lines

What allocation/reclaim really wants (for good scalability and NUMA characteristics) is per-zone lists for these things. It's easy to convert a single list into per-zone lists.

It is much harder to convert per-sb lists into per-sb x per-zone lists.

Quoted 8 lines
Quoted 5 lines

No it's not. Just convert the s_{dentry,inode}_lru lists on each superblock and call the shrinker with a new zone mask field to pick the correct LRU. That's no harder than converting a global LRU. Anyway, you'd still have to do per-sb x per-zone lists for the dentry LRUs, so changing the inode cache to per-sb makes no difference.

Right, it just makes it harder to do. By much harder, I did mostly mean the extra memory overhead.

You've still got to allocate that extra memory on the per-sb dentry LRUs so it's not really a valid argument. IOWs, if it's too much memory for per-sb inode LRUs, then it's too much memory for the per-sb dentry LRUs as well...

Quoted 2 lines

If there is *no* benefit from doing per-sb
icache then I would question whether we should.

The same vague questions wondering about the benefit of per-sb dentry LRUs were raised when I first proposed them years ago, and look where we are now. Besides, focussing on whether this one patch is a benefit or not is really missing the point because it's the benefits of this patchset as a whole that need to be considered....

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#6 lore raw

Re: [PATCH 1/5] inode: Make unused inode LRU per superblock

Quoted 39 lines · Dave Chinner
Quoted 25 lines · Nick Piggin
Quoted 17 lines · Dave Chinner
Quoted 10 lines · Nick Piggin
Quoted 6 lines · Dave Chinner

From: Dave Chinner <[email protected]>

The inode unused list is currently a global LRU. This does not match the other global filesystem cache - the dentry cache - which uses per-superblock LRU lists. Hence we have related filesystem object types using different LRU reclaimatin schemes.

Is this an improvement I wonder? The dcache is using per sb lists because it specifically requires sb traversal.

Right - I originally implemented the per-sb dentry lists for scalability purposes. i.e. to avoid monopolising the dentry_lock during unmount looking for dentries on a specific sb and hanging the system for several minutes.

Quoted 6 lines

However, the reason for doing this to the inode cache is not for scalability, it's because we have a tight relationship between the dentry and inode cacheѕ. That is, reclaim from the dentry LRU grows the inode LRU. Like the registration of the shrinkers, this is kind of an implicit, undocumented behavour of the current shrinker implemenation.

Quoted 2 lines

Right, that's why I wonder whether it is an improvement. It would be interesting to see some tests (showing at least parity).

I've done some testing showing parity. They've been along the lines of:
- populate cache with 1m dentries + inodes
- run 'time echo 2 > /proc/sys/vm/drop_caches'

I've used different methods of populating the caches to have them non-sequential in the LRU (i.e. trigger fragmentation), have dirty backing inodes (e.g. the VFS inode clean, the xfs inode dirty because transactions haven't completed), etc.

Quoted 5 lines

The variation on the test is around +-10%, with the per-sb shrinkers averaging about 5% lower time to reclaim. This is within the error margin of the test, so it's not really a conclusive win, but it is certainly shows that it does not slow anything down. If you've got a better way to test it, then I'm all ears....

I guess the problem is that inode LRU cache isn't very useful as long as there are dentries in the way (which is most of the time, isn't it?). I think nfsd will exercise them better? Dont know of any other cases.

Quoted 5 lines
Quoted 2 lines

Right, it just makes it harder to do. By much harder, I did mostly mean the extra memory overhead.

You've still got to allocate that extra memory on the per-sb dentry LRUs so it's not really a valid argument.

Well it would be per-zone, per-sb list, but I don't think that makes it an ivalid point.

Quoted 3 lines

IOWs, if it's too much
memory for per-sb inode LRUs, then it's too much memory for the per-sb dentry LRUs as well...

Not about how much is too much, it's about more cost or memory usage for what benefit? I guess it isn't a lot more memory though.

Quoted 6 lines
Quoted 2 lines

If there is *no* benefit from doing per-sb
icache then I would question whether we should.

The same vague questions wondering about the benefit of per-sb dentry LRUs were raised when I first proposed them years ago, and look where we are now.

To be fair that is because there were specific needs to do per-sb pruning. This isn't the case with icache.

Quoted 3 lines

Besides, focussing on whether this one patch
is a benefit or not is really missing the point because it's the benefits of this patchset as a whole that need to be considered....

I would indeed like to focus on the benefits of the patchset as a whole. Leaving aside the xfs changes, it would be interesting to have at least a few numbers for dcache/icache heavy workloads.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

maintainer
#7 lore raw

Re: [PATCH 1/5] inode: Make unused inode LRU per superblock

In reply to Dave Chinner
Quoted 17 lines · On Tue, 25 May 2010 18:53:04 +1000 Dave Chinner <[email protected]> wrote:

From: Dave Chinner <[email protected]>

The inode unused list is currently a global LRU. This does not match the other global filesystem cache - the dentry cache - which uses per-superblock LRU lists. Hence we have related filesystem object types using different LRU reclaimatin schemes.

To enable a per-superblock filesystem cache shrinker, both of these caches need to have per-sb unused object LRU lists. Hence this patch converts the global inode LRU to per-sb LRUs.

The patch only does rudimentary per-sb propotioning in the shrinker infrastructure, as this gets removed when the per-sb shrinker callouts are introduced later on.

...

fs/fs-writeback.c select_queue: · line 568

Quoted 1 line
fs/fs-writeback.c +1 -0
+			list_move(&inode->i_list, &inode->i_sb->s_inode_lru);

It's a shape that s_inode_lru is still protected by inode_lock. One day we're going to get in trouble over that lock. Migrating to a per-sb lock would be logical and might help.

Did you look into this? I expect we'd end up taking both inode_lock and the new sb->lru_lock in several places, which wouldn't be of any help, at least in the interim. Long-term, the locking for fs-writeback.c should move to the per-superblock one also, at which time this problem largely goes away I think. Unfortunately the writeback inode lists got moved into the backing_dev_info, whcih messes things up a bit.

fs/inode.c void __iget(struct inode *inode) · line 295

Quoted 2 lines
fs/inode.c +1 -0
 	inodes_stat.nr_unused--;
+	inode->i_sb->s_nr_inodes_unused--;

It's regrettable to be counting the same thing twice. Did you look into removing (or no longer using) inodes_stat.nr_unused?

fs/inode.c static void prune_icache(int nr_to_scan) · line 530

Quoted 1 line
fs/inode.c +1 -0
+		/* Now, we reclaim unused dentrins with fairness.

May as well fix the typo while we're there.

Please review all these comments to ensure that they are still accurate and complete.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#8 lore raw

Re: [PATCH 1/5] inode: Make unused inode LRU per superblock

Quoted 20 lines · Andrew Morton
Quoted 17 lines · On Tue, 25 May 2010 18:53:04 +1000 Dave Chinner <[email protected]> wrote:

From: Dave Chinner <[email protected]>

The inode unused list is currently a global LRU. This does not match the other global filesystem cache - the dentry cache - which uses per-superblock LRU lists. Hence we have related filesystem object types using different LRU reclaimatin schemes.

To enable a per-superblock filesystem cache shrinker, both of these caches need to have per-sb unused object LRU lists. Hence this patch converts the global inode LRU to per-sb LRUs.

The patch only does rudimentary per-sb propotioning in the shrinker infrastructure, as this gets removed when the per-sb shrinker callouts are introduced later on.

...

Quoted 7 lines

fs/fs-writeback.c select_queue: · line 568

Quoted 1 line
fs/fs-writeback.c +1 -0
+			list_move(&inode->i_list, &inode->i_sb->s_inode_lru);

It's a shape that s_inode_lru is still protected by inode_lock. One day we're going to get in trouble over that lock. Migrating to a per-sb lock would be logical and might help.

Did you look into this?

Yes, I have. Yes, it's possible. It's solving a different problem, so I figured it can be done in a different patch set.

Quoted 7 lines

I expect we'd end up taking both inode_lock
and the new sb->lru_lock in several places, which wouldn't be of any help, at least in the interim. Long-term, the locking for fs-writeback.c should move to the per-superblock one also, at which time this problem largely goes away I think. Unfortunately the writeback inode lists got moved into the backing_dev_info, whcih messes things up a bit.

*nod*

Quoted 6 lines

fs/inode.c void __iget(struct inode *inode) · line 295

Quoted 3 lines
fs/inode.c +1 -0
 	inodes_stat.nr_unused--;
+	inode->i_sb->s_nr_inodes_unused--;

It's regrettable to be counting the same thing twice. Did you look into removing (or no longer using) inodes_stat.nr_unused?

Sort of. The complexity is the stats are userspace visible, so they can't just be removed. Replacing the current stats means that when they are read from /proc we would need to walk all the superblocks to aggregate them. The bit I haven't looked at yet is whether walking superblocks is allowed in a proc handler.

So in the mean time, I just copied what was done for the dentry_stats. If it's ok to do this walk, then we can change both the dentry and inode stats at the same time.

Quoted 6 lines

fs/inode.c static void prune_icache(int nr_to_scan) · line 530

Quoted 1 line
fs/inode.c +1 -0
+		/* Now, we reclaim unused dentrins with fairness.

May as well fix the typo while we're there.

Please review all these comments to ensure that they are still accurate and complete.

Will do.

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#9 lore raw

Re: [PATCH 1/5] inode: Make unused inode LRU per superblock

Quoted 27 lines · Dave Chinner
Quoted 26 lines · Andrew Morton
Quoted 17 lines · On Tue, 25 May 2010 18:53:04 +1000 Dave Chinner <[email protected]> wrote:

From: Dave Chinner <[email protected]>

The inode unused list is currently a global LRU. This does not match the other global filesystem cache - the dentry cache - which uses per-superblock LRU lists. Hence we have related filesystem object types using different LRU reclaimatin schemes.

To enable a per-superblock filesystem cache shrinker, both of these caches need to have per-sb unused object LRU lists. Hence this patch converts the global inode LRU to per-sb LRUs.

The patch only does rudimentary per-sb propotioning in the shrinker infrastructure, as this gets removed when the per-sb shrinker callouts are introduced later on.

...

fs/fs-writeback.c select_queue: · line 568

Quoted 1 line
fs/fs-writeback.c +1 -0
+			list_move(&inode->i_list, &inode->i_sb->s_inode_lru);

It's a shape that s_inode_lru is still protected by inode_lock. One day we're going to get in trouble over that lock. Migrating to a per-sb lock would be logical and might help.

Quoted 4 lines
Quoted 1 line

Did you look into this?

Yes, I have. Yes, it's possible. It's solving a different problem, so I figured it can be done in a different patch set.

It almost all goes away in my inode lock splitup patches. Inode lru and dirty lists were the last things protected by the global lock there.

I am actually going to do per-zone lrus for these guys and per-zone locks (which is actually better than per-sb because it gives NUMA scalability within a single sb).

The dirty/writeback lists should probably be per-bdi locked.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#10 lore raw

PATCH 2/5 mm: add context argument to shrinker callback

In reply to Dave Chinner

From: Dave Chinner <[email protected]>

The current shrinker implementation requires the registered callback to have global state to work from. This makes it difficult to shrink caches that are not global (e.g. per-filesystem caches). Pass the shrinker structure to the callback so that users can embed the shrinker structure in the context the shrinker needs to operate on and get back to it in the callback via container_of().

---
 arch/x86/kvm/mmu.c              |    2 +-
 drivers/gpu/drm/i915/i915_gem.c |    2 +-
 fs/dcache.c                     |    2 +-
 fs/gfs2/glock.c                 |    2 +-
 fs/gfs2/quota.c                 |    2 +-
 fs/gfs2/quota.h                 |    2 +-
 fs/inode.c                      |    2 +-
 fs/mbcache.c                    |    5 +++--
 fs/nfs/dir.c                    |    2 +-
 fs/nfs/internal.h               |    3 ++-
 fs/quota/dquot.c                |    2 +-
 fs/ubifs/shrinker.c             |    2 +-
 fs/ubifs/ubifs.h                |    2 +-
 fs/xfs/linux-2.6/xfs_buf.c      |    5 +++--
 fs/xfs/linux-2.6/xfs_sync.c     |    1 +
 fs/xfs/quota/xfs_qm.c           |    7 +++++--
 include/linux/mm.h              |    2 +-
 mm/vmscan.c                     |    8 +++++---
 18 files changed, 31 insertions(+), 22 deletions(-)
arch/x86/kvm/mmu.c +1 -1
index 81563e7..ac3d107 100644
@@ -2919,7 +2919,7 @@ static int kvm_mmu_remove_some_alloc_mmu_pages(struct kvm *kvm)
 	return kvm_mmu_zap_page(kvm, page) + 1;
 }
 
-static int mmu_shrink(int nr_to_scan, gfp_t gfp_mask)
+static int mmu_shrink(struct shrinker *shrink, int nr_to_scan, gfp_t gfp_mask)
 {
 	struct kvm *kvm;
 	struct kvm *kvm_freed = NULL;
drivers/gpu/drm/i915/i915_gem.c +1 -1
index 112699f..6cd2e7a 100644
@@ -5216,7 +5216,7 @@ i915_gpu_is_active(struct drm_device *dev)
 }
 
 static int
-i915_gem_shrink(int nr_to_scan, gfp_t gfp_mask)
+i915_gem_shrink(struct shrinker *shrink, int nr_to_scan, gfp_t gfp_mask)
 {
 	drm_i915_private_t *dev_priv, *next_dev;
 	struct drm_i915_gem_object *obj_priv, *next_obj;
fs/dcache.c +1 -1
index d96047b..dba6b6d 100644
@@ -894,7 +894,7 @@ EXPORT_SYMBOL(shrink_dcache_parent);
  *
  * In this case we return -1 to tell the caller that we baled.
  */
-static int shrink_dcache_memory(int nr, gfp_t gfp_mask)
+static int shrink_dcache_memory(struct shrinker *shrink, int nr, gfp_t gfp_mask)
 {
 	if (nr) {
 		if (!(gfp_mask & __GFP_FS))
fs/gfs2/glock.c +1 -1
index ddcdbf4..04b540c 100644
@@ -1348,7 +1348,7 @@ void gfs2_glock_complete(struct gfs2_glock *gl, int ret)
 }
 
 
-static int gfs2_shrink_glock_memory(int nr, gfp_t gfp_mask)
+static int gfs2_shrink_glock_memory(struct shrinker *shrink, int nr, gfp_t gfp_mask)
 {
 	struct gfs2_glock *gl;
 	int may_demote;
fs/gfs2/quota.c +1 -1
index 49667d6..4ea548f 100644
@@ -77,7 +77,7 @@ static LIST_HEAD(qd_lru_list);
 static atomic_t qd_lru_count = ATOMIC_INIT(0);
 static DEFINE_SPINLOCK(qd_lru_lock);
 
-int gfs2_shrink_qd_memory(int nr, gfp_t gfp_mask)
+int gfs2_shrink_qd_memory(struct shrinker *shrink, int nr, gfp_t gfp_mask)
 {
 	struct gfs2_quota_data *qd;
 	struct gfs2_sbd *sdp;
fs/gfs2/quota.h +1 -1
index 195f60c..e7d236c 100644
@@ -51,7 +51,7 @@ static inline int gfs2_quota_lock_check(struct gfs2_inode *ip)
 	return ret;
 }
 
-extern int gfs2_shrink_qd_memory(int nr, gfp_t gfp_mask);
+extern int gfs2_shrink_qd_memory(struct shrinker *shrink, int nr, gfp_t gfp_mask);
 extern const struct quotactl_ops gfs2_quotactl_ops;
 
 #endif /* __QUOTA_DOT_H__ */
fs/inode.c +1 -1
index 3caa758..1e44ec5 100644
@@ -577,7 +577,7 @@ static void prune_icache(int count)
  * This function is passed the number of inodes to scan, and it returns the
  * total number of remaining possibly-reclaimable inodes.
  */
-static int shrink_icache_memory(int nr, gfp_t gfp_mask)
+static int shrink_icache_memory(struct shrinker *shrink, int nr, gfp_t gfp_mask)
 {
 	if (nr) {
 		/*
fs/mbcache.c +3 -2
index ec88ff3..e28f21b 100644
@@ -115,7 +115,7 @@ mb_cache_indexes(struct mb_cache *cache)
  * What the mbcache registers as to get shrunk dynamically.
  */
 
-static int mb_cache_shrink_fn(int nr_to_scan, gfp_t gfp_mask);
+static int mb_cache_shrink_fn(struct shrinker *shrink, int nr_to_scan, gfp_t gfp_mask);
 
 static struct shrinker mb_cache_shrinker = {
 	.shrink = mb_cache_shrink_fn,
@@ -191,13 +191,14 @@ forget:
  * This function is called by the kernel memory management when memory
  * gets low.
  *
+ * @shrink: (ignored)
  * @nr_to_scan: Number of objects to scan
  * @gfp_mask: (ignored)
  *
  * Returns the number of objects which are present in the cache.
  */
 static int
-mb_cache_shrink_fn(int nr_to_scan, gfp_t gfp_mask)
+mb_cache_shrink_fn(struct shrinker *shrink, int nr_to_scan, gfp_t gfp_mask)
 {
 	LIST_HEAD(free_list);
 	struct list_head *l, *ltmp;
fs/nfs/dir.c +1 -1
index ee9a179..3f33bc0 100644
@@ -1708,7 +1708,7 @@ static void nfs_access_free_list(struct list_head *head)
 	}
 }
 
-int nfs_access_cache_shrinker(int nr_to_scan, gfp_t gfp_mask)
+int nfs_access_cache_shrinker(struct shrinker *shrink, int nr_to_scan, gfp_t gfp_mask)
 {
 	LIST_HEAD(head);
 	struct nfs_inode *nfsi;
fs/nfs/internal.h +2 -1
index d8bd619..e70f44b 100644
@@ -205,7 +205,8 @@ extern struct rpc_procinfo nfs4_procedures[];
 void nfs_close_context(struct nfs_open_context *ctx, int is_sync);
 
 /* dir.c */
-extern int nfs_access_cache_shrinker(int nr_to_scan, gfp_t gfp_mask);
+extern int nfs_access_cache_shrinker(struct shrinker *shrink,
+					int nr_to_scan, gfp_t gfp_mask);
 
 /* inode.c */
 extern struct workqueue_struct *nfsiod_workqueue;
fs/quota/dquot.c +1 -1
index 655a4c5..cfd5437 100644
@@ -697,7 +697,7 @@ static int dqstats_read(unsigned int type)
  * more memory
  */
 
-static int shrink_dqcache_memory(int nr, gfp_t gfp_mask)
+static int shrink_dqcache_memory(struct shrinker *shrink, int nr, gfp_t gfp_mask)
 {
 	if (nr) {
 		spin_lock(&dq_list_lock);
fs/ubifs/shrinker.c +1 -1
index 02feb59..0b20111 100644
@@ -277,7 +277,7 @@ static int kick_a_thread(void)
 	return 0;
 }
 
-int ubifs_shrinker(int nr, gfp_t gfp_mask)
+int ubifs_shrinker(struct shrinker *shrink, int nr, gfp_t gfp_mask)
 {
 	int freed, contention = 0;
 	long clean_zn_cnt = atomic_long_read(&ubifs_clean_zn_cnt);
fs/ubifs/ubifs.h +1 -1
index bd2542d..5a92345 100644
@@ -1575,7 +1575,7 @@ int ubifs_tnc_start_commit(struct ubifs_info *c, struct ubifs_zbranch *zroot);
 int ubifs_tnc_end_commit(struct ubifs_info *c);
 
 /* shrinker.c */
-int ubifs_shrinker(int nr_to_scan, gfp_t gfp_mask);
+int ubifs_shrinker(struct shrinker *shrink, int nr_to_scan, gfp_t gfp_mask);
 
 /* commit.c */
 int ubifs_bg_thread(void *info);
fs/xfs/linux-2.6/xfs_buf.c +3 -2
index f01de3c..fe8bf82 100644
@@ -44,7 +44,7 @@
 
 static kmem_zone_t *xfs_buf_zone;
 STATIC int xfsbufd(void *);
-STATIC int xfsbufd_wakeup(int, gfp_t);
+STATIC int xfsbufd_wakeup(struct shrinker *, int, gfp_t);
 STATIC void xfs_buf_delwri_queue(xfs_buf_t *, int);
 static struct shrinker xfs_buf_shake = {
 	.shrink = xfsbufd_wakeup,
@@ -339,7 +339,7 @@ _xfs_buf_lookup_pages(
 					__func__, gfp_mask);
 
 			XFS_STATS_INC(xb_page_retries);
-			xfsbufd_wakeup(0, gfp_mask);
+			xfsbufd_wakeup(NULL, 0, gfp_mask);
 			congestion_wait(BLK_RW_ASYNC, HZ/50);
 			goto retry;
 		}
@@ -1753,6 +1753,7 @@ xfs_buf_runall_queues(
 
 STATIC int
 xfsbufd_wakeup(
+	struct shrinker		*shrink,
 	int			priority,
 	gfp_t			mask)
 {
fs/xfs/linux-2.6/xfs_sync.c +1 -0
index 3884e20..c881a0c 100644
@@ -842,6 +842,7 @@ static struct rw_semaphore xfs_mount_list_lock;
 
 static int
 xfs_reclaim_inode_shrink(
+	struct shrinker	*shrink,
 	int		nr_to_scan,
 	gfp_t		gfp_mask)
 {
fs/xfs/quota/xfs_qm.c +5 -2
index 38e7641..b8051aa 100644
@@ -69,7 +69,7 @@ STATIC void	xfs_qm_list_destroy(xfs_dqlist_t *);
 
 STATIC int	xfs_qm_init_quotainos(xfs_mount_t *);
 STATIC int	xfs_qm_init_quotainfo(xfs_mount_t *);
-STATIC int	xfs_qm_shake(int, gfp_t);
+STATIC int	xfs_qm_shake(struct shrinker *, int, gfp_t);
 
 static struct shrinker xfs_qm_shaker = {
 	.shrink = xfs_qm_shake,
@@ -2117,7 +2117,10 @@ xfs_qm_shake_freelist(
  */
 /* ARGSUSED */
 STATIC int
-xfs_qm_shake(int nr_to_scan, gfp_t gfp_mask)
+xfs_qm_shake(
+	struct shrinker	*shrink,
+	int		nr_to_scan,
+	gfp_t		gfp_mask)
 {
 	int	ndqused, nfree, n;
 
include/linux/mm.h +1 -1
index fb19bb9..3d7eedc 100644
@@ -994,7 +994,7 @@ static inline void sync_mm_rss(struct task_struct *task, struct mm_struct *mm)
  * querying the cache size, so a fastpath for that case is appropriate.
  */
 struct shrinker {
-	int (*shrink)(int nr_to_scan, gfp_t gfp_mask);
+	int (*shrink)(struct shrinker *, int nr_to_scan, gfp_t gfp_mask);
 	int seeks;	/* seeks to recreate an obj */
 
 	/* These are for internal use */
mm/vmscan.c +5 -3
index 3ff3311..9d56aaf 100644
@@ -215,8 +215,9 @@ unsigned long shrink_slab(unsigned long scanned, gfp_t gfp_mask,
 	list_for_each_entry(shrinker, &shrinker_list, list) {
 		unsigned long long delta;
 		unsigned long total_scan;
-		unsigned long max_pass = (*shrinker->shrink)(0, gfp_mask);
+		unsigned long max_pass;
 
+		max_pass = (*shrinker->shrink)(shrinker, 0, gfp_mask);
 		delta = (4 * scanned) / shrinker->seeks;
 		delta *= max_pass;
 		do_div(delta, lru_pages + 1);
@@ -244,8 +245,9 @@ unsigned long shrink_slab(unsigned long scanned, gfp_t gfp_mask,
 			int shrink_ret;
 			int nr_before;
 
-			nr_before = (*shrinker->shrink)(0, gfp_mask);
-			shrink_ret = (*shrinker->shrink)(this_scan, gfp_mask);
+			nr_before = (*shrinker->shrink)(shrinker, 0, gfp_mask);
+			shrink_ret = (*shrinker->shrink)(shrinker, this_scan,
+								gfp_mask);
 			if (shrink_ret == -1)
 				break;
 			if (shrink_ret < nr_before)
Signature · 6 lines
1.5.6.5

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#11 lore raw

PATCH 3/5 superblock: introduce per-sb cache shrinker infrastructure

In reply to Dave Chinner

From: Dave Chinner <[email protected]>

With context based shrinkers, we can implement a per-superblock shrinker that shrinks the caches attached to the superblock. We currently have global shrinkers for the inode and dentry caches that split up into per-superblock operations via a coarse proportioning method that does not batch very well. The global shrinkers also have a dependency - dentries pin inodes - so we have to be very careful about how we register the global shrinkers so that the implicit call order is always correct.

With a per-sb shrinker callout, we can encode this dependency directly into the per-sb shrinker, hence avoiding the need for strictly ordering shrinker registrations. We also have no need for any proportioning code for the shrinker subsystem already provides this functionality across all shrinkers. Allowing the shrinker to operate on a single superblock at a time means that we do less superblock list traversals and locking and reclaim should batch more effectively. This should result in less CPU overhead for reclaim and potentially faster reclaim of items from each filesystem.

---
 fs/dcache.c        |  133 ++++++++--------------------------------------------
 fs/inode.c         |  109 +++---------------------------------------
 fs/super.c         |   53 +++++++++++++++++++++
 include/linux/fs.h |    7 +++
 4 files changed, 88 insertions(+), 214 deletions(-)
fs/dcache.c +20 -113
index dba6b6d..d7bd781 100644
@@ -456,21 +456,16 @@ static void prune_one_dentry(struct dentry * dentry)
  * which flags are set. This means we don't need to maintain multiple
  * similar copies of this loop.
  */
-static void __shrink_dcache_sb(struct super_block *sb, int *count, int flags)
+static void __shrink_dcache_sb(struct super_block *sb, int count, int flags)
 {
 	LIST_HEAD(referenced);
 	LIST_HEAD(tmp);
 	struct dentry *dentry;
-	int cnt = 0;
 
 	BUG_ON(!sb);
-	BUG_ON((flags & DCACHE_REFERENCED) && count == NULL);
+	BUG_ON((flags & DCACHE_REFERENCED) && count == -1);
 	spin_lock(&dcache_lock);
-	if (count != NULL)
-		/* called from prune_dcache() and shrink_dcache_parent() */
-		cnt = *count;
-restart:
-	if (count == NULL)
+	if (count == -1)
 		list_splice_init(&sb->s_dentry_lru, &tmp);
 	else {
 		while (!list_empty(&sb->s_dentry_lru)) {
@@ -492,13 +487,13 @@ restart:
 			} else {
 				list_move_tail(&dentry->d_lru, &tmp);
 				spin_unlock(&dentry->d_lock);
-				cnt--;
-				if (!cnt)
+				if (--count == 0)
 					break;
 			}
 			cond_resched_lock(&dcache_lock);
 		}
 	}
+prune_more:
 	while (!list_empty(&tmp)) {
 		dentry = list_entry(tmp.prev, struct dentry, d_lru);
 		dentry_lru_del_init(dentry);
@@ -516,88 +511,29 @@ restart:
 		/* dentry->d_lock was dropped in prune_one_dentry() */
 		cond_resched_lock(&dcache_lock);
 	}
-	if (count == NULL && !list_empty(&sb->s_dentry_lru))
-		goto restart;
-	if (count != NULL)
-		*count = cnt;
+	if (count == -1 && !list_empty(&sb->s_dentry_lru)) {
+		list_splice_init(&sb->s_dentry_lru, &tmp);
+		goto prune_more;
+	}
 	if (!list_empty(&referenced))
 		list_splice(&referenced, &sb->s_dentry_lru);
 	spin_unlock(&dcache_lock);
 }
 
 /**
- * prune_dcache - shrink the dcache
- * @count: number of entries to try to free
+ * prune_dcache_sb - shrink the dcache
+ * @nr_to_scan: number of entries to try to free
  *
- * Shrink the dcache. This is done when we need more memory, or simply when we
- * need to unmount something (at which point we need to unuse all dentries).
+ * Attempt to shrink the superblock dcache LRU by @nr_to_scan entries. This is
+ * done when we need more memory an called from the superblock shrinker
+ * function.
  *
- * This function may fail to free any resources if all the dentries are in use.
+ * This function may fail to free any resources if all the dentries are in
+ * use.
  */
-static void prune_dcache(int count)
+void prune_dcache_sb(struct super_block *sb, int nr_to_scan)
 {
-	struct super_block *sb, *n;
-	int w_count;
-	int unused = dentry_stat.nr_unused;
-	int prune_ratio;
-	int pruned;
-
-	if (unused == 0 || count == 0)
-		return;
-	spin_lock(&dcache_lock);
-	if (count >= unused)
-		prune_ratio = 1;
-	else
-		prune_ratio = unused / count;
-	spin_lock(&sb_lock);
-	list_for_each_entry_safe(sb, n, &super_blocks, s_list) {
-		if (list_empty(&sb->s_instances))
-			continue;
-		if (sb->s_nr_dentry_unused == 0)
-			continue;
-		sb->s_count++;
-		/* Now, we reclaim unused dentrins with fairness.
-		 * We reclaim them same percentage from each superblock.
-		 * We calculate number of dentries to scan on this sb
-		 * as follows, but the implementation is arranged to avoid
-		 * overflows:
-		 * number of dentries to scan on this sb =
-		 * count * (number of dentries on this sb /
-		 * number of dentries in the machine)
-		 */
-		spin_unlock(&sb_lock);
-		if (prune_ratio != 1)
-			w_count = (sb->s_nr_dentry_unused / prune_ratio) + 1;
-		else
-			w_count = sb->s_nr_dentry_unused;
-		pruned = w_count;
-		/*
-		 * We need to be sure this filesystem isn't being unmounted,
-		 * otherwise we could race with generic_shutdown_super(), and
-		 * end up holding a reference to an inode while the filesystem
-		 * is unmounted.  So we try to get s_umount, and make sure
-		 * s_root isn't NULL.
-		 */
-		if (down_read_trylock(&sb->s_umount)) {
-			if ((sb->s_root != NULL) &&
-			    (!list_empty(&sb->s_dentry_lru))) {
-				spin_unlock(&dcache_lock);
-				__shrink_dcache_sb(sb, &w_count,
-						DCACHE_REFERENCED);
-				pruned -= w_count;
-				spin_lock(&dcache_lock);
-			}
-			up_read(&sb->s_umount);
-		}
-		spin_lock(&sb_lock);
-		count -= pruned;
-		__put_super(sb);
-		/* more work left to do? */
-		if (count <= 0)
-			break;
-	}
-	spin_unlock(&sb_lock);
-	spin_unlock(&dcache_lock);
+	__shrink_dcache_sb(sb, nr_to_scan, DCACHE_REFERENCED);
 }
 
 /**
@@ -610,7 +546,7 @@ static void prune_dcache(int count)
  */
 void shrink_dcache_sb(struct super_block * sb)
 {
-	__shrink_dcache_sb(sb, NULL, 0);
+	__shrink_dcache_sb(sb, -1, 0);
 }
 EXPORT_SYMBOL(shrink_dcache_sb);
 
@@ -878,37 +814,10 @@ void shrink_dcache_parent(struct dentry * parent)
 	int found;
 
 	while ((found = select_parent(parent)) != 0)
-		__shrink_dcache_sb(sb, &found, 0);
+		__shrink_dcache_sb(sb, found, 0);
 }
 EXPORT_SYMBOL(shrink_dcache_parent);
 
-/*
- * Scan `nr' dentries and return the number which remain.
- *
- * We need to avoid reentering the filesystem if the caller is performing a
- * GFP_NOFS allocation attempt.  One example deadlock is:
- *
- * ext2_new_block->getblk->GFP->shrink_dcache_memory->prune_dcache->
- * prune_one_dentry->dput->dentry_iput->iput->inode->i_sb->s_op->put_inode->
- * ext2_discard_prealloc->ext2_free_blocks->lock_super->DEADLOCK.
- *
- * In this case we return -1 to tell the caller that we baled.
- */
-static int shrink_dcache_memory(struct shrinker *shrink, int nr, gfp_t gfp_mask)
-{
-	if (nr) {
-		if (!(gfp_mask & __GFP_FS))
-			return -1;
-		prune_dcache(nr);
-	}
-	return (dentry_stat.nr_unused / 100) * sysctl_vfs_cache_pressure;
-}
-
-static struct shrinker dcache_shrinker = {
-	.shrink = shrink_dcache_memory,
-	.seeks = DEFAULT_SEEKS,
-};
-
 /**
  * d_alloc	-	allocate a dcache entry
  * @parent: parent of entry to allocate
@@ -2316,8 +2225,6 @@ static void __init dcache_init(void)
 	 */
 	dentry_cache = KMEM_CACHE(dentry,
 		SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|SLAB_MEM_SPREAD);
-	
-	register_shrinker(&dcache_shrinker);
 
 	/* Hash may have been set up in dcache_init_early */
 	if (!hashdist)
fs/inode.c +8 -101

150 lines not on this page · raw message

fs/super.c +53 -0

77 lines not on this page · raw message

include/linux/fs.h +7 -0
index 7b90c43..5bff2dc 100644
@@ -382,6 +382,7 @@ struct inodes_stat_t {
 #include <linux/capability.h>
 #include <linux/semaphore.h>
 #include <linux/fiemap.h>
+#include <linux/mm.h>
 
 #include <asm/atomic.h>
 #include <asm/byteorder.h>
@@ -1385,8 +1386,14 @@ struct super_block {
 	 * generic_show_options()
 	 */
 	char *s_options;
+
+	struct shrinker s_shrink;	/* per-sb shrinker handle */
 };
 
+/* superblock cache pruning functions */
+void prune_icache_sb(struct super_block *sb, int nr_to_scan);
+void prune_dcache_sb(struct super_block *sb, int nr_to_scan);
+
 extern struct timespec current_fs_time(struct super_block *sb);
 
 /*
Signature · 1 line
1.5.6.5

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#12 lore raw

Re: [PATCH 3/5] superblock: introduce per-sb cache shrinker infrastructure

Quoted 43 lines · Dave Chinner
fs/dcache.c +5 -10
@@ -456,21 +456,16 @@ static void prune_one_dentry(struct dentry * dentry)
  * which flags are set. This means we don't need to maintain multiple
  * similar copies of this loop.
  */
-static void __shrink_dcache_sb(struct super_block *sb, int *count, int flags)
+static void __shrink_dcache_sb(struct super_block *sb, int count, int flags)
 {
 	LIST_HEAD(referenced);
 	LIST_HEAD(tmp);
 	struct dentry *dentry;
-	int cnt = 0;
 
 	BUG_ON(!sb);
-	BUG_ON((flags & DCACHE_REFERENCED) && count == NULL);
+	BUG_ON((flags & DCACHE_REFERENCED) && count == -1);
 	spin_lock(&dcache_lock);
-	if (count != NULL)
-		/* called from prune_dcache() and shrink_dcache_parent() */
-		cnt = *count;
-restart:
-	if (count == NULL)
+	if (count == -1)
 		list_splice_init(&sb->s_dentry_lru, &tmp);
 	else {
 		while (!list_empty(&sb->s_dentry_lru)) {
@@ -492,13 +487,13 @@ restart:
 			} else {
 				list_move_tail(&dentry->d_lru, &tmp);
 				spin_unlock(&dentry->d_lock);
-				cnt--;
-				if (!cnt)
+				if (--count == 0)
 					break;
 			}
 			cond_resched_lock(&dcache_lock);
 		}
 	}
+prune_more:
 	while (!list_empty(&tmp)) {
 		dentry = list_entry(tmp.prev, struct dentry, d_lru);
 		dentry_lru_del_init(dentry);
@@ -516,88 +511,29 @@ restart:
 		/* dentry->d_lock was dropped in prune_one_dentry() */

fs/dcache.c restart: · line 517

Quoted 10 lines
fs/dcache.c +4 -4
 		cond_resched_lock(&dcache_lock);
 	}
-	if (count == NULL && !list_empty(&sb->s_dentry_lru))
-		goto restart;
-	if (count != NULL)
-		*count = cnt;
+	if (count == -1 && !list_empty(&sb->s_dentry_lru)) {
+		list_splice_init(&sb->s_dentry_lru, &tmp);
+		goto prune_more;
+	}

Nitpick but I prefer just the restart label wher it is previously. This is moving setup for the next iteration into the "error" case.

Quoted 10 lines
fs/super.c +10 -0
+static int prune_super(struct shrinker *shrink, int nr_to_scan, gfp_t gfp_mask)
+{
+	struct super_block *sb;
+	int count;
+
+	sb = container_of(shrink, struct super_block, s_shrink);
+
+	/*
+	 * Deadlock avoidance.  We may hold various FS locks, and we don't want
+	 * to recurse into the FS that called us in clear_inode() and friends..

fs/super.c line 59

Quoted 10 lines
fs/super.c +10 -0
+	 */
+	if (!(gfp_mask & __GFP_FS))
+		return -1;
+
+	/*
+	 * if we can't get the umount lock, then there's no point having the
+	 * shrinker try again because the sb is being torn down.
+	 */
+	if (!down_read_trylock(&sb->s_umount))
+		return -1;

Would you just elaborate on the lock order problem somewhere? (the comment makes it look like we *could* take the mutex if we wanted to).

Quoted 10 lines
fs/super.c +10 -0
+
+	if (!sb->s_root) {
+		up_read(&sb->s_umount);
+		return -1;
+	}
+
+	if (nr_to_scan) {
+		/* proportion the scan between the two cacheѕ */
+		int total;
+

fs/super.c line 79

Quoted 10 lines
fs/super.c +10 -0
+		total = sb->s_nr_dentry_unused + sb->s_nr_inodes_unused + 1;
+		count = (nr_to_scan * sb->s_nr_dentry_unused) / total;
+
+		/* prune dcache first as icache is pinned by it */
+		prune_dcache_sb(sb, count);
+		prune_icache_sb(sb, nr_to_scan - count);
+	}
+
+	count = ((sb->s_nr_dentry_unused + sb->s_nr_inodes_unused) / 100)
+						* sysctl_vfs_cache_pressure;

Do you think truncating in the divisions is at all a problem? It probably doesn't matter much I suppose.

Quoted 29 lines
fs/super.c +2 -0
@@ -162,6 +213,7 @@ void deactivate_locked_super(struct super_block *s)
 	struct file_system_type *fs = s->s_type;
 	if (atomic_dec_and_test(&s->s_active)) {
 		vfs_dq_off(s, 0);
+		unregister_shrinker(&s->s_shrink);
 		fs->kill_sb(s);
 		put_filesystem(fs);
 		put_super(s);
@@ -335,6 +387,7 @@ retry:
 	list_add_tail(&s->s_list, &super_blocks);
 	list_add(&s->s_instances, &type->fs_supers);
 	spin_unlock(&sb_lock);
+	register_shrinker(&s->s_shrink);
 	get_filesystem(type);
 	return s;
 }
include/linux/fs.h +1 -0
index 7b90c43..5bff2dc 100644
@@ -382,6 +382,7 @@ struct inodes_stat_t {
 #include <linux/capability.h>
 #include <linux/semaphore.h>
 #include <linux/fiemap.h>
+#include <linux/mm.h>
 
 #include <asm/atomic.h>
 #include <asm/byteorder.h>

include/linux/fs.h struct super_block { · line 1391

Quoted 6 lines
include/linux/fs.h +2 -0
@@ -1385,8 +1386,14 @@ struct super_block {
 	 * generic_show_options()
 	 */
 	char *s_options;
+
+	struct shrinker s_shrink;	/* per-sb shrinker handle */
 };

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#13 lore raw

Re: [PATCH 3/5] superblock: introduce per-sb cache shrinker infrastructure

Quoted 49 lines · Nick Piggin
Quoted 48 lines · Dave Chinner
fs/dcache.c +5 -13
@@ -456,21 +456,16 @@ static void prune_one_dentry(struct dentry * dentry)
  * which flags are set. This means we don't need to maintain multiple
  * similar copies of this loop.
  */
-static void __shrink_dcache_sb(struct super_block *sb, int *count, int flags)
+static void __shrink_dcache_sb(struct super_block *sb, int count, int flags)
 {
 	LIST_HEAD(referenced);
 	LIST_HEAD(tmp);
 	struct dentry *dentry;
-	int cnt = 0;
 
 	BUG_ON(!sb);
-	BUG_ON((flags & DCACHE_REFERENCED) && count == NULL);
+	BUG_ON((flags & DCACHE_REFERENCED) && count == -1);
 	spin_lock(&dcache_lock);
-	if (count != NULL)
-		/* called from prune_dcache() and shrink_dcache_parent() */
-		cnt = *count;
-restart:
-	if (count == NULL)
+	if (count == -1)
 		list_splice_init(&sb->s_dentry_lru, &tmp);
 	else {
 		while (!list_empty(&sb->s_dentry_lru)) {
@@ -492,13 +487,13 @@ restart:
 			} else {
 				list_move_tail(&dentry->d_lru, &tmp);
 				spin_unlock(&dentry->d_lock);
-				cnt--;
-				if (!cnt)
+				if (--count == 0)
 					break;
 			}
 			cond_resched_lock(&dcache_lock);
 		}
 	}
+prune_more:
 	while (!list_empty(&tmp)) {
 		dentry = list_entry(tmp.prev, struct dentry, d_lru);
 		dentry_lru_del_init(dentry);
@@ -516,88 +511,29 @@ restart:
 		/* dentry->d_lock was dropped in prune_one_dentry() */
 		cond_resched_lock(&dcache_lock);
 	}
-	if (count == NULL && !list_empty(&sb->s_dentry_lru))
-		goto restart;
-	if (count != NULL)
Quoted 8 lines

fs/dcache.c restart: · line 517

Quoted 5 lines
fs/dcache.c +4 -1
-		*count = cnt;
+	if (count == -1 && !list_empty(&sb->s_dentry_lru)) {
+		list_splice_init(&sb->s_dentry_lru, &tmp);
+		goto prune_more;
+	}

Nitpick but I prefer just the restart label wher it is previously. This is moving setup for the next iteration into the "error" case.

Ok, will fix.

Quoted 16 lines
Quoted 16 lines
fs/super.c +16 -0
+static int prune_super(struct shrinker *shrink, int nr_to_scan, gfp_t gfp_mask)
+{
+	struct super_block *sb;
+	int count;
+
+	sb = container_of(shrink, struct super_block, s_shrink);
+
+	/*
+	 * Deadlock avoidance.  We may hold various FS locks, and we don't want
+	 * to recurse into the FS that called us in clear_inode() and friends..
+	 */
+	if (!(gfp_mask & __GFP_FS))
+		return -1;
+
+	/*
+	 * if we can't get the umount lock, then there's no point having the
Quoted 8 lines

fs/super.c line 59

Quoted 4 lines
fs/super.c +4 -0
+	 * shrinker try again because the sb is being torn down.
+	 */
+	if (!down_read_trylock(&sb->s_umount))
+		return -1;

Would you just elaborate on the lock order problem somewhere? (the comment makes it look like we *could* take the mutex if we wanted to).

The shrinker is unregistered in deactivate_locked_super() which is just before ->kill_sb is called. The sb->s_umount lock is held at this point. hence is the shrinker is operating, we will deadlock if we try to lock it like this:

	unmount:			shrinker:
					down_read(&shrinker_lock);
	down_write(&sb->s_umount)
	unregister_shrinker()
	down_write(&shrinker_lock)
					prune_super()
					  down_read(&sb->s_umount);
					  (deadlock)

hence if we can't get the sb->s_umount lock in prune_super(), then the superblock must be being unmounted and the shrinker should abort as the ->kill_sb method will clean up everything after the shrinker is unregistered. Hence the down_read_trylock().

Quoted 14 lines
Quoted 14 lines
fs/super.c +14 -0
+	if (!sb->s_root) {
+		up_read(&sb->s_umount);
+		return -1;
+	}
+
+	if (nr_to_scan) {
+		/* proportion the scan between the two cacheѕ */
+		int total;
+
+		total = sb->s_nr_dentry_unused + sb->s_nr_inodes_unused + 1;
+		count = (nr_to_scan * sb->s_nr_dentry_unused) / total;
+
+		/* prune dcache first as icache is pinned by it */
+		prune_dcache_sb(sb, count);
Quoted 8 lines

fs/super.c line 79

Quoted 5 lines
fs/super.c +5 -0
+		prune_icache_sb(sb, nr_to_scan - count);
+	}
+
+	count = ((sb->s_nr_dentry_unused + sb->s_nr_inodes_unused) / 100)
+						* sysctl_vfs_cache_pressure;

Do you think truncating in the divisions is at all a problem? It probably doesn't matter much I suppose.

Same code as currently exists. IIRC, the reasoning is that if we've got less that 100 objects to reclaim, then we're unlikely to be able to free up any memory from the caches, anyway.

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#14 lore raw

PATCH v2 3/5 superblock: introduce per-sb cache shrinker infrastructure

Quoted 1 line · Dave Chinner

On Thu, May 27, 2010 at 02:41:16AM +1000, Nick Piggin wrote:

....

Quoted 4 lines
Quoted 2 lines

Nitpick but I prefer just the restart label wher it is previously. This is moving setup for the next iteration into the "error" case.

Ok, will fix.

....

Quoted 18 lines
Quoted 3 lines

Would you just elaborate on the lock order problem somewhere? (the comment makes it look like we *could* take the mutex if we wanted to).

The shrinker is unregistered in deactivate_locked_super() which is just before ->kill_sb is called. The sb->s_umount lock is held at this point. hence is the shrinker is operating, we will deadlock if we try to lock it like this:

	unmount:			shrinker:
					down_read(&shrinker_lock);
	down_write(&sb->s_umount)
	unregister_shrinker()
	down_write(&shrinker_lock)
					prune_super()
					  down_read(&sb->s_umount);
					  (deadlock)
Quoted 4 lines

hence if we can't get the sb->s_umount lock in prune_super(), then the superblock must be being unmounted and the shrinker should abort as the ->kill_sb method will clean up everything after the shrinker is unregistered. Hence the down_read_trylock().

Updated patch below with these issues fixed.

Cheers,

Dave.

Signature · 40 lines
Dave Chinner
[email protected]

superblock: introduce per-sb cache shrinker infrastructure

From: Dave Chinner <[email protected]>

With context based shrinkers, we can implement a per-superblock
shrinker that shrinks the caches attached to the superblock. We
currently have global shrinkers for the inode and dentry caches that
split up into per-superblock operations via a coarse proportioning
method that does not batch very well.  The global shrinkers also
have a dependency - dentries pin inodes - so we have to be very
careful about how we register the global shrinkers so that the
implicit call order is always correct.

With a per-sb shrinker callout, we can encode this dependency
directly into the per-sb shrinker, hence avoiding the need for
strictly ordering shrinker registrations. We also have no need for
any proportioning code for the shrinker subsystem already provides
this functionality across all shrinkers. Allowing the shrinker to
operate on a single superblock at a time means that we do less
superblock list traversals and locking and reclaim should batch more
effectively. This should result in less CPU overhead for reclaim and
potentially faster reclaim of items from each filesystem.

Signed-off-by: Dave Chinner <[email protected]>
---
Version 2:
- change loop restart in __shrink_dcache_sb() to match previous
  restart semantics
- add a better comment in prune_super() to explain the deadlock we
  are avoiding by using down_read_trylock(&sb->s_umount) before
  starting any shrinking.

 fs/dcache.c        |  127 +++++++---------------------------------------------
 fs/inode.c         |  109 +++-----------------------------------------
 fs/super.c         |   58 ++++++++++++++++++++++++
 include/linux/fs.h |    7 +++
 4 files changed, 89 insertions(+), 212 deletions(-)
fs/dcache.c +16 -111
index dba6b6d..a7cd335 100644
@@ -456,21 +456,17 @@ static void prune_one_dentry(struct dentry * dentry)
  * which flags are set. This means we don't need to maintain multiple
  * similar copies of this loop.
  */
-static void __shrink_dcache_sb(struct super_block *sb, int *count, int flags)
+static void __shrink_dcache_sb(struct super_block *sb, int count, int flags)
 {
 	LIST_HEAD(referenced);
 	LIST_HEAD(tmp);
 	struct dentry *dentry;
-	int cnt = 0;
 
 	BUG_ON(!sb);
-	BUG_ON((flags & DCACHE_REFERENCED) && count == NULL);
+	BUG_ON((flags & DCACHE_REFERENCED) && count == -1);
 	spin_lock(&dcache_lock);
-	if (count != NULL)
-		/* called from prune_dcache() and shrink_dcache_parent() */
-		cnt = *count;
 restart:
-	if (count == NULL)
+	if (count == -1)
 		list_splice_init(&sb->s_dentry_lru, &tmp);
 	else {
 		while (!list_empty(&sb->s_dentry_lru)) {
@@ -492,8 +488,7 @@ restart:
 			} else {
 				list_move_tail(&dentry->d_lru, &tmp);
 				spin_unlock(&dentry->d_lock);
-				cnt--;
-				if (!cnt)
+				if (--count == 0)
 					break;
 			}
 			cond_resched_lock(&dcache_lock);
@@ -516,88 +511,27 @@ restart:
 		/* dentry->d_lock was dropped in prune_one_dentry() */
 		cond_resched_lock(&dcache_lock);
 	}
-	if (count == NULL && !list_empty(&sb->s_dentry_lru))
+	if (count == -1 && !list_empty(&sb->s_dentry_lru))
 		goto restart;
-	if (count != NULL)
-		*count = cnt;
 	if (!list_empty(&referenced))
 		list_splice(&referenced, &sb->s_dentry_lru);
 	spin_unlock(&dcache_lock);
 }
 
 /**
- * prune_dcache - shrink the dcache
- * @count: number of entries to try to free
+ * prune_dcache_sb - shrink the dcache
+ * @nr_to_scan: number of entries to try to free
  *
- * Shrink the dcache. This is done when we need more memory, or simply when we
- * need to unmount something (at which point we need to unuse all dentries).
+ * Attempt to shrink the superblock dcache LRU by @nr_to_scan entries. This is
+ * done when we need more memory an called from the superblock shrinker
+ * function.
  *
- * This function may fail to free any resources if all the dentries are in use.
+ * This function may fail to free any resources if all the dentries are in
+ * use.
  */
-static void prune_dcache(int count)
+void prune_dcache_sb(struct super_block *sb, int nr_to_scan)
 {
-	struct super_block *sb, *n;
-	int w_count;
-	int unused = dentry_stat.nr_unused;
-	int prune_ratio;
-	int pruned;
-
-	if (unused == 0 || count == 0)
-		return;
-	spin_lock(&dcache_lock);
-	if (count >= unused)
-		prune_ratio = 1;
-	else
-		prune_ratio = unused / count;
-	spin_lock(&sb_lock);
-	list_for_each_entry_safe(sb, n, &super_blocks, s_list) {
-		if (list_empty(&sb->s_instances))
-			continue;
-		if (sb->s_nr_dentry_unused == 0)
-			continue;
-		sb->s_count++;
-		/* Now, we reclaim unused dentrins with fairness.
-		 * We reclaim them same percentage from each superblock.
-		 * We calculate number of dentries to scan on this sb
-		 * as follows, but the implementation is arranged to avoid
-		 * overflows:
-		 * number of dentries to scan on this sb =
-		 * count * (number of dentries on this sb /
-		 * number of dentries in the machine)
-		 */
-		spin_unlock(&sb_lock);
-		if (prune_ratio != 1)
-			w_count = (sb->s_nr_dentry_unused / prune_ratio) + 1;
-		else
-			w_count = sb->s_nr_dentry_unused;
-		pruned = w_count;
-		/*
-		 * We need to be sure this filesystem isn't being unmounted,
-		 * otherwise we could race with generic_shutdown_super(), and
-		 * end up holding a reference to an inode while the filesystem
-		 * is unmounted.  So we try to get s_umount, and make sure
-		 * s_root isn't NULL.
-		 */
-		if (down_read_trylock(&sb->s_umount)) {
-			if ((sb->s_root != NULL) &&
-			    (!list_empty(&sb->s_dentry_lru))) {
-				spin_unlock(&dcache_lock);
-				__shrink_dcache_sb(sb, &w_count,
-						DCACHE_REFERENCED);
-				pruned -= w_count;
-				spin_lock(&dcache_lock);
-			}
-			up_read(&sb->s_umount);
-		}
-		spin_lock(&sb_lock);
-		count -= pruned;
-		__put_super(sb);
-		/* more work left to do? */
-		if (count <= 0)
-			break;
-	}
-	spin_unlock(&sb_lock);
-	spin_unlock(&dcache_lock);
+	__shrink_dcache_sb(sb, nr_to_scan, DCACHE_REFERENCED);
 }
 
 /**
@@ -610,7 +544,7 @@ static void prune_dcache(int count)
  */
 void shrink_dcache_sb(struct super_block * sb)
 {
-	__shrink_dcache_sb(sb, NULL, 0);
+	__shrink_dcache_sb(sb, -1, 0);
 }
 EXPORT_SYMBOL(shrink_dcache_sb);
 
@@ -878,37 +812,10 @@ void shrink_dcache_parent(struct dentry * parent)
 	int found;
 
 	while ((found = select_parent(parent)) != 0)
-		__shrink_dcache_sb(sb, &found, 0);
+		__shrink_dcache_sb(sb, found, 0);
 }
 EXPORT_SYMBOL(shrink_dcache_parent);
 
-/*
- * Scan `nr' dentries and return the number which remain.
- *
- * We need to avoid reentering the filesystem if the caller is performing a
- * GFP_NOFS allocation attempt.  One example deadlock is:
- *
- * ext2_new_block->getblk->GFP->shrink_dcache_memory->prune_dcache->
- * prune_one_dentry->dput->dentry_iput->iput->inode->i_sb->s_op->put_inode->
- * ext2_discard_prealloc->ext2_free_blocks->lock_super->DEADLOCK.
- *
- * In this case we return -1 to tell the caller that we baled.
- */
-static int shrink_dcache_memory(struct shrinker *shrink, int nr, gfp_t gfp_mask)
-{
-	if (nr) {
-		if (!(gfp_mask & __GFP_FS))
-			return -1;
-		prune_dcache(nr);
-	}
-	return (dentry_stat.nr_unused / 100) * sysctl_vfs_cache_pressure;
-}
-
-static struct shrinker dcache_shrinker = {
-	.shrink = shrink_dcache_memory,
-	.seeks = DEFAULT_SEEKS,
-};
-
 /**
  * d_alloc	-	allocate a dcache entry
  * @parent: parent of entry to allocate
@@ -2316,8 +2223,6 @@ static void __init dcache_init(void)
 	 */
 	dentry_cache = KMEM_CACHE(dentry,
 		SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|SLAB_MEM_SPREAD);
-	
-	register_shrinker(&dcache_shrinker);
 
 	/* Hash may have been set up in dcache_init_early */
 	if (!hashdist)
fs/inode.c +8 -101

150 lines not on this page · raw message

fs/super.c +58 -0

82 lines not on this page · raw message

include/linux/fs.h +7 -0
index 7b90c43..5bff2dc 100644
@@ -382,6 +382,7 @@ struct inodes_stat_t {
 #include <linux/capability.h>
 #include <linux/semaphore.h>
 #include <linux/fiemap.h>
+#include <linux/mm.h>
 
 #include <asm/atomic.h>
 #include <asm/byteorder.h>
@@ -1385,8 +1386,14 @@ struct super_block {
 	 * generic_show_options()
 	 */
 	char *s_options;
+
+	struct shrinker s_shrink;	/* per-sb shrinker handle */
 };
 
+/* superblock cache pruning functions */
+void prune_icache_sb(struct super_block *sb, int nr_to_scan);
+void prune_dcache_sb(struct super_block *sb, int nr_to_scan);
+
 extern struct timespec current_fs_time(struct super_block *sb);
 
 /*

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

maintainer
#15 lore raw

Re: [PATCH 3/5 v2] superblock: introduce per-sb cache shrinker infrastructure

Quoted 26 lines · Dave Chinner
Quoted 1 line · Dave Chinner

On Thu, May 27, 2010 at 02:41:16AM +1000, Nick Piggin wrote:

....

Quoted 4 lines
Quoted 2 lines

Nitpick but I prefer just the restart label wher it is previously. This is moving setup for the next iteration into the "error" case.

Ok, will fix.

....

Quoted 18 lines
Quoted 3 lines

Would you just elaborate on the lock order problem somewhere? (the comment makes it look like we *could* take the mutex if we wanted to).

The shrinker is unregistered in deactivate_locked_super() which is just before ->kill_sb is called. The sb->s_umount lock is held at this point. hence is the shrinker is operating, we will deadlock if we try to lock it like this:

	unmount:			shrinker:
					down_read(&shrinker_lock);
	down_write(&sb->s_umount)
	unregister_shrinker()
	down_write(&shrinker_lock)
					prune_super()
					  down_read(&sb->s_umount);
					  (deadlock)
Quoted 4 lines
Quoted 4 lines

hence if we can't get the sb->s_umount lock in prune_super(), then the superblock must be being unmounted and the shrinker should abort as the ->kill_sb method will clean up everything after the shrinker is unregistered. Hence the down_read_trylock().

Um... Maybe I'm dumb, but what's wrong with doing unregistration from deactivate_locked_super(), right after the call of ->kill_sb()? At that point ->s_umount is already dropped, so we won't deadlock at all. Shrinker rwsem will make sure that all shrinkers-in-progress will run to completion, so we won't get a superblock freed under prune_super(). I don't particulary mind down_try_read() in prune_super(), but why not make life obviously safer?

Am I missing something here?

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#16 lore raw

Re: [PATCH 3/5 v2] superblock: introduce per-sb cache shrinker infrastructure

Quoted 40 lines · Al Viro
Quoted 26 lines · Dave Chinner
Quoted 1 line · Dave Chinner

On Thu, May 27, 2010 at 02:41:16AM +1000, Nick Piggin wrote:

....

Quoted 4 lines
Quoted 2 lines

Nitpick but I prefer just the restart label wher it is previously. This is moving setup for the next iteration into the "error" case.

Ok, will fix.

....

Quoted 18 lines
Quoted 3 lines

Would you just elaborate on the lock order problem somewhere? (the comment makes it look like we *could* take the mutex if we wanted to).

The shrinker is unregistered in deactivate_locked_super() which is just before ->kill_sb is called. The sb->s_umount lock is held at this point. hence is the shrinker is operating, we will deadlock if we try to lock it like this:

	unmount:			shrinker:
					down_read(&shrinker_lock);
	down_write(&sb->s_umount)
	unregister_shrinker()
	down_write(&shrinker_lock)
					prune_super()
					  down_read(&sb->s_umount);
					  (deadlock)
Quoted 4 lines
Quoted 4 lines

hence if we can't get the sb->s_umount lock in prune_super(), then the superblock must be being unmounted and the shrinker should abort as the ->kill_sb method will clean up everything after the shrinker is unregistered. Hence the down_read_trylock().

Um... Maybe I'm dumb, but what's wrong with doing unregistration from deactivate_locked_super(), right after the call of ->kill_sb()? At that point ->s_umount is already dropped, so we won't deadlock at all. Shrinker rwsem will make sure that all shrinkers-in-progress will run to completion, so we won't get a superblock freed under prune_super(). I don't particulary mind down_try_read() in prune_super(), but why not make life obviously safer?

Quoted 1 line

Am I missing something here?

I was worried about memory allocation in the ->kill_sb path deadlocking on the s_umount lock if it enters reclaim. e.g. XFS inodes can still be dirty even after the VFS has disposed of them, and writing them back can require page cache allocation for the backing buffers. If allocation recurses back into the shrinker, we can deadlock on the s_umount lock. This doesn't seem like an XFS specific problem, so I used a trylock to avoid that whole class of problems (same way the current shrinkers do).

Quoted 1 line

From there, we can unregister the shrinker before calling ->kill_sb

as per above. That, in turn, means that the unmount invalidate_inodes() vs shrinker race goes away and the iprune_sem is not needed in the new prune_icache_sb() function. I'm pretty sure that I can now remove the iprune_sem, but I haven't written the patch to do that yet.

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#17 lore raw

Re: [PATCH 3/5 v2] superblock: introduce per-sb cache shrinker infrastructure

Quoted 11 lines · Dave Chinner
Quoted 9 lines · Al Viro

Um... Maybe I'm dumb, but what's wrong with doing unregistration from deactivate_locked_super(), right after the call of ->kill_sb()? At that point ->s_umount is already dropped, so we won't deadlock at all. Shrinker rwsem will make sure that all shrinkers-in-progress will run to completion, so we won't get a superblock freed under prune_super(). I don't particulary mind down_try_read() in prune_super(), but why not make life obviously safer?

Am I missing something here?

Quoted 8 lines

I was worried about memory allocation in the ->kill_sb path deadlocking on the s_umount lock if it enters reclaim. e.g. XFS inodes can still be dirty even after the VFS has disposed of them, and writing them back can require page cache allocation for the backing buffers. If allocation recurses back into the shrinker, we can deadlock on the s_umount lock. This doesn't seem like an XFS specific problem, so I used a trylock to avoid that whole class of problems (same way the current shrinkers do).

If GFP_FS is set, we wouldn't touch the locks. It is a concern though, if __GFP_FS allocations were previously permitted under the exclusive lock.

Quoted 6 lines
Quoted 1 line

From there, we can unregister the shrinker before calling ->kill_sb

as per above. That, in turn, means that the unmount invalidate_inodes() vs shrinker race goes away and the iprune_sem is not needed in the new prune_icache_sb() function. I'm pretty sure that I can now remove the iprune_sem, but I haven't written the patch to do that yet.

I do really like that aspect of your patch. It's nice to have the shrinker always only operating against active supers. So I would be in favour of your current scheme.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#18 lore raw

Re: [PATCH 3/5] superblock: introduce per-sb cache shrinker infrastructure

In reply to Dave Chinner
Quoted 28 lines · Dave Chinner
Quoted 12 lines · Nick Piggin

fs/super.c static void prune_one_dentry(struct dentry * dentry) · line 461

Quoted 7 lines · Dave Chinner
fs/super.c +6 -0
@@ -456,21 +456,16 @@ static void prune_one_dentry(struct dentry * dentry)
+	/*
+	 * if we can't get the umount lock, then there's no point having the
+	 * shrinker try again because the sb is being torn down.
+	 */
+	if (!down_read_trylock(&sb->s_umount))
+		return -1;

Would you just elaborate on the lock order problem somewhere? (the comment makes it look like we *could* take the mutex if we wanted to).

The shrinker is unregistered in deactivate_locked_super() which is just before ->kill_sb is called. The sb->s_umount lock is held at this point. hence is the shrinker is operating, we will deadlock if we try to lock it like this:

	unmount:			shrinker:
					down_read(&shrinker_lock);
	down_write(&sb->s_umount)
	unregister_shrinker()
	down_write(&shrinker_lock)
					prune_super()
					  down_read(&sb->s_umount);
					  (deadlock)
Quoted 4 lines

hence if we can't get the sb->s_umount lock in prune_super(), then the superblock must be being unmounted and the shrinker should abort as the ->kill_sb method will clean up everything after the shrinker is unregistered. Hence the down_read_trylock().

You added it to the comment in your updated patch, that was the main thing I wanted. Thanks.

Quoted 23 lines
Quoted 14 lines
Quoted 14 lines
fs/super.c +14 -0
+	if (!sb->s_root) {
+		up_read(&sb->s_umount);
+		return -1;
+	}
+
+	if (nr_to_scan) {
+		/* proportion the scan between the two cacheѕ */
+		int total;
+
+		total = sb->s_nr_dentry_unused + sb->s_nr_inodes_unused + 1;
+		count = (nr_to_scan * sb->s_nr_dentry_unused) / total;
+
+		/* prune dcache first as icache is pinned by it */
+		prune_dcache_sb(sb, count);
Quoted 8 lines

fs/super.c line 79

Quoted 5 lines
fs/super.c +5 -0
+		prune_icache_sb(sb, nr_to_scan - count);
+	}
+
+	count = ((sb->s_nr_dentry_unused + sb->s_nr_inodes_unused) / 100)
+						* sysctl_vfs_cache_pressure;

Do you think truncating in the divisions is at all a problem? It probably doesn't matter much I suppose.

Quoted 3 lines

Same code as currently exists. IIRC, the reasoning is that if we've got less that 100 objects to reclaim, then we're unlikely to be able to free up any memory from the caches, anyway.

Yeah, which is why I stop short of saying you should change it in this patch.

But I think we should ensure things can get reclaimed eventually. 100 objects could be 100 slabs, which could be anything from half a meg to half a dozen. Multiplied by each of the caches. Could be significant in small systems.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#19 lore raw

Re: [PATCH 3/5] superblock: introduce per-sb cache shrinker infrastructure

Quoted 12 lines · Nick Piggin
Quoted 10 lines · Dave Chinner
Quoted 5 lines · Nick Piggin

fs/super.c line 79

Quoted 2 lines
fs/super.c +2 -0
+	count = ((sb->s_nr_dentry_unused + sb->s_nr_inodes_unused) / 100)
+						* sysctl_vfs_cache_pressure;

Do you think truncating in the divisions is at all a problem? It probably doesn't matter much I suppose.

Same code as currently exists. IIRC, the reasoning is that if we've got less that 100 objects to reclaim, then we're unlikely to be able to free up any memory from the caches, anyway.

Quoted 7 lines

Yeah, which is why I stop short of saying you should change it in this patch.

But I think we should ensure things can get reclaimed eventually. 100 objects could be 100 slabs, which could be anything from half a meg to half a dozen. Multiplied by each of the caches. Could be significant in small systems.

True, but usually there are busy objects in the dentry and inode slabs, so it shouldn't be a significant issue. We can probably address such problems if they can be demonstrated to be an issue in a separate patch set....

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#20 lore raw

Re: [PATCH 3/5] superblock: introduce per-sb cache shrinker infrastructure

Quoted 21 lines · Dave Chinner
Quoted 12 lines · Nick Piggin
Quoted 10 lines · Dave Chinner
Quoted 5 lines · Nick Piggin

fs/super.c line 79

Quoted 2 lines
fs/super.c +2 -0
+	count = ((sb->s_nr_dentry_unused + sb->s_nr_inodes_unused) / 100)
+						* sysctl_vfs_cache_pressure;

Do you think truncating in the divisions is at all a problem? It probably doesn't matter much I suppose.

Same code as currently exists. IIRC, the reasoning is that if we've got less that 100 objects to reclaim, then we're unlikely to be able to free up any memory from the caches, anyway.

Quoted 7 lines

Yeah, which is why I stop short of saying you should change it in this patch.

But I think we should ensure things can get reclaimed eventually. 100 objects could be 100 slabs, which could be anything from half a meg to half a dozen. Multiplied by each of the caches. Could be significant in small systems.

Quoted 4 lines

True, but usually there are busy objects in the dentry and inode slabs, so it shouldn't be a significant issue. We can probably address such problems if they can be demonstrated to be an issue in a separate patch set....

I didn't want to say it is a problem with your patchset, I just thought of it when reviewing.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#21 lore raw

Re: [PATCH 3/5] superblock: introduce per-sb cache shrinker infrastructure

In reply to Dave Chinner
Quoted 32 lines · Dave Chinner
fs/super.c +26 -0
@@ -37,6 +37,50 @@
 LIST_HEAD(super_blocks);
 DEFINE_SPINLOCK(sb_lock);
 
+static int prune_super(struct shrinker *shrink, int nr_to_scan, gfp_t gfp_mask)
+{
+	struct super_block *sb;
+	int count;
+
+	sb = container_of(shrink, struct super_block, s_shrink);
+
+	/*
+	 * Deadlock avoidance.  We may hold various FS locks, and we don't want
+	 * to recurse into the FS that called us in clear_inode() and friends..
+	 */
+	if (!(gfp_mask & __GFP_FS))
+		return -1;
+
+	/*
+	 * if we can't get the umount lock, then there's no point having the
+	 * shrinker try again because the sb is being torn down.
+	 */
+	if (!down_read_trylock(&sb->s_umount))
+		return -1;
+
+	if (!sb->s_root) {
+		up_read(&sb->s_umount);
+		return -1;
+	}
+

fs/super.c line 75

Quoted 10 lines
fs/super.c +10 -0
+	if (nr_to_scan) {
+		/* proportion the scan between the two cacheѕ */
+		int total;
+
+		total = sb->s_nr_dentry_unused + sb->s_nr_inodes_unused + 1;
+		count = (nr_to_scan * sb->s_nr_dentry_unused) / total;
+
+		/* prune dcache first as icache is pinned by it */
+		prune_dcache_sb(sb, count);
+		prune_icache_sb(sb, nr_to_scan - count);

Hmm, an interesting dynamic that you've changed is that previously we'd scan dcache LRU proportionately to pagecache, and then scan inode LRU in proportion to the current number of unused inodes.

But we can think of inodes that are only in use by unused (and aged) dentries as effectively unused themselves. So this sequence under estimates how many inodes to scan. This could bias pressure against dcache I'd think, especially considering inodes are far larger than dentries. Maybe require 2 passes to get the inodes unused inthe first pass.

Part of the problem is the funny shrinker API.

The right way to do it is to change the shrinker API so that it passes down the lru_pages and scanned into the callback. From there, the shrinkers can calculate the appropriate ratio of objects to scan. No need for 2-call scheme, no need for shrinker->seeks, and the ability to calculate an appropriate ratio first for dcache, and *then* for icache.

A helper of course can do the calculation (considering that every driver and their dog will do the wrong thing if we let them :)).

unsigned long shrinker_scan(unsigned long lru_pages,
unsigned long lru_scanned, unsigned long nr_objects, unsigned long scan_ratio)

{
	unsigned long long tmp = nr_objects;

	tmp *= lru_scanned * 100;
	do_div(tmp, (lru_pages * scan_ratio) + 1);

	return (unsigned long)tmp;
}

Then the shrinker callback will go:

	sb->s_nr_dentry_scan += shrinker_scan(lru_pages, lru_scanned,
				sb->s_nr_dentry_unused,
				vfs_cache_pressure * SEEKS_PER_DENTRY);
	if (sb->s_nr_dentry_scan > SHRINK_BATCH)
		prune_dcache()

	sb->s_nr_inode_scan += shrinker_scan(lru_pages, lru_scanned,
				sb->s_nr_inodes_unused,
				vfs_cache_pressure * SEEKS_PER_INODE);
	...

What do you think of that? Seeing as we're changing the shrinker API anyway, I'd think it is high time to do somthing like this.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#22 lore raw

Re: [PATCH 3/5] superblock: introduce per-sb cache shrinker infrastructure

Quoted 48 lines · Nick Piggin
Quoted 32 lines · Dave Chinner
fs/super.c +26 -0
@@ -37,6 +37,50 @@
 LIST_HEAD(super_blocks);
 DEFINE_SPINLOCK(sb_lock);
 
+static int prune_super(struct shrinker *shrink, int nr_to_scan, gfp_t gfp_mask)
+{
+	struct super_block *sb;
+	int count;
+
+	sb = container_of(shrink, struct super_block, s_shrink);
+
+	/*
+	 * Deadlock avoidance.  We may hold various FS locks, and we don't want
+	 * to recurse into the FS that called us in clear_inode() and friends..
+	 */
+	if (!(gfp_mask & __GFP_FS))
+		return -1;
+
+	/*
+	 * if we can't get the umount lock, then there's no point having the
+	 * shrinker try again because the sb is being torn down.
+	 */
+	if (!down_read_trylock(&sb->s_umount))
+		return -1;
+
+	if (!sb->s_root) {
+		up_read(&sb->s_umount);
+		return -1;
+	}
+

fs/super.c line 75

Quoted 10 lines
fs/super.c +10 -0
+	if (nr_to_scan) {
+		/* proportion the scan between the two cacheѕ */
+		int total;
+
+		total = sb->s_nr_dentry_unused + sb->s_nr_inodes_unused + 1;
+		count = (nr_to_scan * sb->s_nr_dentry_unused) / total;
+
+		/* prune dcache first as icache is pinned by it */
+		prune_dcache_sb(sb, count);
+		prune_icache_sb(sb, nr_to_scan - count);

Hmm, an interesting dynamic that you've changed is that previously we'd scan dcache LRU proportionately to pagecache, and then scan inode LRU in proportion to the current number of unused inodes.

Quoted 6 lines

But we can think of inodes that are only in use by unused (and aged) dentries as effectively unused themselves. So this sequence under estimates how many inodes to scan. This could bias pressure against dcache I'd think, especially considering inodes are far larger than dentries. Maybe require 2 passes to get the inodes unused inthe first pass.

It's self-balancing - it trends towards an equal number of unused dentries and inodes in the caches. Yes, it will tear down more dentries at first, but we need to do that to be able to reclaim inodes. Ås reclaim progresses the propotion of inodes increases, so the amount of inodes reclaimed increases.

Basically this is a recognition that the important cache for avoiding IO is the inode cache, not he dentry cache. Once the inode cache is freed that we need to do IO to repopulate it, but rebuilding dentries fromteh inode cache only costs CPU time. Hence under light reclaim, inodes are mostly left in cache but we free up memory that only costs CPU to rebuild. Under heavy, sustained reclaim, we trend towards freeing equal amounts of objects from both caches.

This is pretty much what the current code attempts to do - free a lot of dentries, then free a smaller amount of the inodes that were used by the freed dentries. Once again it is a direct encoding of what is currently an implicit design feature - it makes it *obvious* how we are trying to balance the caches.

Another reason for this is that the calculation changes again to allow filesystem caches to modiy this proportioning in the next patch....

FWIW, this also makes workloads that generate hundreds of thousands of never-to-be-used again negative dentries free dcache memory really quickly on memory pressure...

Quoted 8 lines

Part of the problem is the funny shrinker API.

The right way to do it is to change the shrinker API so that it passes down the lru_pages and scanned into the callback. From there, the shrinkers can calculate the appropriate ratio of objects to scan. No need for 2-call scheme, no need for shrinker->seeks, and the ability to calculate an appropriate ratio first for dcache, and *then* for icache.

My only concern about this is that exposes the inner workings of the shrinker and mm subsystem to code that simply doesn't need to know about it.

Quoted 28 lines

A helper of course can do the calculation (considering that every driver and their dog will do the wrong thing if we let them :)).

unsigned long shrinker_scan(unsigned long lru_pages,
unsigned long lru_scanned, unsigned long nr_objects, unsigned long scan_ratio)

{
	unsigned long long tmp = nr_objects;

	tmp *= lru_scanned * 100;
	do_div(tmp, (lru_pages * scan_ratio) + 1);

	return (unsigned long)tmp;
}

Then the shrinker callback will go:

	sb->s_nr_dentry_scan += shrinker_scan(lru_pages, lru_scanned,
				sb->s_nr_dentry_unused,
				vfs_cache_pressure * SEEKS_PER_DENTRY);
	if (sb->s_nr_dentry_scan > SHRINK_BATCH)
		prune_dcache()

	sb->s_nr_inode_scan += shrinker_scan(lru_pages, lru_scanned,
				sb->s_nr_inodes_unused,
				vfs_cache_pressure * SEEKS_PER_INODE);
	...
Quoted 2 lines

What do you think of that? Seeing as we're changing the shrinker API anyway, I'd think it is high time to do somthing like this.

Ignoring the dcache/icache reclaim ratio issues, I'd prefer a two call API that matches the current behaviour, leaving the caclulation of how much to reclaim in shrink_slab(). Encoding it this way makes it more difficult to change the high level behaviour e.g. if we want to modify the amount of slab reclaim based on reclaim priority, we'd have to cahnge every shrinker instead of just shrink_slab().

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#23 lore raw

Re: [PATCH 3/5] superblock: introduce per-sb cache shrinker infrastructure

Quoted 8 lines · Dave Chinner
Quoted 6 lines · Nick Piggin

But we can think of inodes that are only in use by unused (and aged) dentries as effectively unused themselves. So this sequence under estimates how many inodes to scan. This could bias pressure against dcache I'd think, especially considering inodes are far larger than dentries. Maybe require 2 passes to get the inodes unused inthe first pass.

Quoted 4 lines

It's self-balancing - it trends towards an equal number of unused dentries and inodes in the caches. Yes, it will tear down more dentries at first, but we need to do that to be able to reclaim inodes.

But then it doesn't scan enough inodes on the inode pass.

Quoted 5 lines

Ås reclaim progresses the propotion of inodes increases, so the amount of inodes reclaimed increases.

Basically this is a recognition that the important cache for avoiding IO is the inode cache, not he dentry cache. Once the inode

You can bias against the dcache using multipliers.

Quoted 6 lines

cache is freed that we need to do IO to repopulate it, but rebuilding dentries fromteh inode cache only costs CPU time. Hence under light reclaim, inodes are mostly left in cache but we free up memory that only costs CPU to rebuild. Under heavy, sustained reclaim, we trend towards freeing equal amounts of objects from both caches.

I don't know if you've got numbers or patterns to justify that. My point is that things should stay as close to the old code as possible without good reason.

Quoted 5 lines

This is pretty much what the current code attempts to do - free a lot of dentries, then free a smaller amount of the inodes that were used by the freed dentries. Once again it is a direct encoding of what is currently an implicit design feature - it makes it *obvious* how we are trying to balance the caches.

With your patches, if there are no inodes free you would need to take 2 passes at freeing the dentry cache. My suggestion is closer to the current code.

Quoted 7 lines

Another reason for this is that the calculation changes again to allow filesystem caches to modiy this proportioning in the next patch....

FWIW, this also makes workloads that generate hundreds of thousands of never-to-be-used again negative dentries free dcache memory really quickly on memory pressure...

That would still be the case because used inodes aren't getting their dentries freed so little inode scanning will occur.

Quoted 10 lines
Quoted 9 lines

Part of the problem is the funny shrinker API.

The right way to do it is to change the shrinker API so that it passes down the lru_pages and scanned into the callback. From there, the shrinkers can calculate the appropriate ratio of objects to scan. No need for 2-call scheme, no need for shrinker->seeks, and the ability to calculate an appropriate ratio first for dcache, and *then* for icache.

Quoted 3 lines

My only concern about this is that exposes the inner workings of the shrinker and mm subsystem to code that simply doesn't need to know about it.

It's just providing a ratio. The shrinkers allready know they are scanning based on a ratio of pagecache scanned.

Quoted 28 lines
Quoted 28 lines

A helper of course can do the calculation (considering that every driver and their dog will do the wrong thing if we let them :)).

unsigned long shrinker_scan(unsigned long lru_pages,
unsigned long lru_scanned, unsigned long nr_objects, unsigned long scan_ratio)

{
	unsigned long long tmp = nr_objects;

	tmp *= lru_scanned * 100;
	do_div(tmp, (lru_pages * scan_ratio) + 1);

	return (unsigned long)tmp;
}

Then the shrinker callback will go:

	sb->s_nr_dentry_scan += shrinker_scan(lru_pages, lru_scanned,
				sb->s_nr_dentry_unused,
				vfs_cache_pressure * SEEKS_PER_DENTRY);
	if (sb->s_nr_dentry_scan > SHRINK_BATCH)
		prune_dcache()

	sb->s_nr_inode_scan += shrinker_scan(lru_pages, lru_scanned,
				sb->s_nr_inodes_unused,
				vfs_cache_pressure * SEEKS_PER_INODE);
	...
Quoted 4 lines
Quoted 2 lines

What do you think of that? Seeing as we're changing the shrinker API anyway, I'd think it is high time to do somthing like this.

Ignoring the dcache/icache reclaim ratio issues, I'd prefer a two

Well if it is an issue, it should be changed in a different patch I think (with numbers).

Quoted 5 lines

call API that matches the current behaviour, leaving the caclulation of how much to reclaim in shrink_slab(). Encoding it this way makes it more difficult to change the high level behaviour e.g. if we want to modify the amount of slab reclaim based on reclaim priority, we'd have to cahnge every shrinker instead of just shrink_slab().

We can modifiy the ratios before calling if needed, or have a default ratio define to multiply with as well.

But shrinkers are very subsystem specific.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#24 lore raw

Re: [PATCH 3/5] superblock: introduce per-sb cache shrinker infrastructure

Quoted 9 lines · Nick Piggin
Quoted 8 lines · Dave Chinner
Quoted 6 lines · Nick Piggin

But we can think of inodes that are only in use by unused (and aged) dentries as effectively unused themselves. So this sequence under estimates how many inodes to scan. This could bias pressure against dcache I'd think, especially considering inodes are far larger than dentries. Maybe require 2 passes to get the inodes unused inthe first pass.

Quoted 6 lines
Quoted 4 lines

It's self-balancing - it trends towards an equal number of unused dentries and inodes in the caches. Yes, it will tear down more dentries at first, but we need to do that to be able to reclaim inodes.

But then it doesn't scan enough inodes on the inode pass.

We don't get a single shrinker call - we get batches of them fo each shrinker. The shrinker determines how many objects to scan in the cache, and that only changes for each shrinker to call based on the the shrinker->seeks and the number of objects in the cache. Once the number is decided, then the shrinker gets batches of reclaim to operate on.

Fundamentally, the current shrinker will ask for the same percentage of each cache to be scanned - if it decides to scan 20% of the dentry cache, it will also decide to scan 20% of the inode cache Hence what the inode shrinker is doing is scanning 20% of the inodes freed by the dcache shrinker.

In rough numbers, say we have 100k dentries, and the shrinker calculates it needs to scan 20% of the caches to reclaim them, the current code will end up with:

unused dentries unused inodes
before 100k 0
after dentry 80k 20k
after inode 80k 16k

So we get 20k dentries freed and 4k inodes freed on that shrink_slab pass.

To contrast this against the code I proposed, I'll make a couple of simplicfications to avoid hurting my brain. That is, I'll assume SHRINK_BATCH=100 (rather than 128) and forgetting about rounding errors. With this, the algorithm I encoded gives roughly the following for a 20% object reclaim:

number of batches = 20k / 100 = 200

Unused
dentries+inodes dentries inodes

before		  100k			100k		    0
batch 1		  100k			99900		  100
batch 2		  100k			99800		  200
....
batch 10	  100k			99000		 1000
batch 20	  99990			98010		 1990
batch 30	  99980			97030		 2950
batch 50	  99910			95100		 4810
batch 60	  99860			94150		 5710

.....
batch 200 98100 81900 16200

And so (roughly) we see that the number of inodes being reclaim per set of 10 batches roughly equals the (batch number - 10). Hence over 200 batches, we can expect to see roughly 190 + 180 + ... + 10 inodes reclaimed. That is 1900 inodes. Similarly for dentries, we get roughly 1000 + 990 + 980 + ... 810 dentries reclaimed - 18,100 in total.

In other words, we have roughly 18k dentries and 1.9k inodes reclaimed for the code I wrote new algorithm. That does mean it initially attempts to reclaim dentries faster than the current code, but as the number of unused inodes increases, this comes back to parity with the current code and we end up with a 1:1 reclaim ratio.

This is good behaviour - dentries are cheap to reconstruct from the inode cache, and we should hold onto the inode cache as much as possible. i.e. we should reclaim them more aggressively only if there is sustained pressure on the superblock and that is what the above algorithm does.

Quoted 7 lines
Quoted 5 lines

Ås reclaim progresses the propotion of inodes increases, so the amount of inodes reclaimed increases.

Basically this is a recognition that the important cache for avoiding IO is the inode cache, not he dentry cache. Once the inode

You can bias against the dcache using multipliers.

Multipliers are not self-balancing, and generally just amplify any imbalance an algorithm tends towards. The vfs_cache_pressure multiplier is a shining example of this kind of utterly useless knob...

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines

Part of the problem is the funny shrinker API.

The right way to do it is to change the shrinker API so that it passes down the lru_pages and scanned into the callback. From there, the shrinkers can calculate the appropriate ratio of objects to scan. No need for 2-call scheme, no need for shrinker->seeks, and the ability to calculate an appropriate ratio first for dcache, and *then* for icache.

Quoted 6 lines
Quoted 3 lines

My only concern about this is that exposes the inner workings of the shrinker and mm subsystem to code that simply doesn't need to know about it.

It's just providing a ratio. The shrinkers allready know they are scanning based on a ratio of pagecache scanned.

Sure, but the shrinkers are just a simple mechanism for implementing VM policy decisions. IMO reclaim policy decisions should not be pushed down and replicated in every one of these reclaim mechanisms.

Quoted 1 line

But shrinkers are very subsystem specific.

And as such should concentrate on getting their subsystem reclaim correct, not have to worry about implementing VM policy calculations...

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#25 lore raw

Re: [PATCH 3/5] superblock: introduce per-sb cache shrinker infrastructure

Quoted 15 lines · Dave Chinner
Quoted 14 lines · Nick Piggin
Quoted 12 lines · Dave Chinner
Quoted 6 lines · Nick Piggin

But we can think of inodes that are only in use by unused (and aged) dentries as effectively unused themselves. So this sequence under estimates how many inodes to scan. This could bias pressure against dcache I'd think, especially considering inodes are far larger than dentries. Maybe require 2 passes to get the inodes unused inthe first pass.

It's self-balancing - it trends towards an equal number of unused dentries and inodes in the caches. Yes, it will tear down more dentries at first, but we need to do that to be able to reclaim inodes.

Quoted 4 lines
Quoted 1 line

But then it doesn't scan enough inodes on the inode pass.

We don't get a single shrinker call - we get batches of them fo each shrinker.

OK fair point. However

[...]

Quoted 11 lines

In other words, we have roughly 18k dentries and 1.9k inodes reclaimed for the code I wrote new algorithm. That does mean it initially attempts to reclaim dentries faster than the current code, but as the number of unused inodes increases, this comes back to parity with the current code and we end up with a 1:1 reclaim ratio.

This is good behaviour - dentries are cheap to reconstruct from the inode cache, and we should hold onto the inode cache as much as possible. i.e. we should reclaim them more aggressively only if there is sustained pressure on the superblock and that is what the above algorithm does.

I prefer just to keep changes to a minimum and split into seperate patches (each with at least basic test or two showing no regression).

As-is you're already changing global inode/dentry passes into per sb inode and dentry passes. I think it can only be a good thing for that changeset if other changes are minimised.

Then if it is so obviously good behaviour to reduce dcache pressure, it should be easy to justify that too.

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

Ås reclaim progresses the propotion of inodes increases, so the amount of inodes reclaimed increases.

Basically this is a recognition that the important cache for avoiding IO is the inode cache, not he dentry cache. Once the inode

Quoted 6 lines
Quoted 1 line

You can bias against the dcache using multipliers.

Multipliers are not self-balancing, and generally just amplify any imbalance an algorithm tends towards. The vfs_cache_pressure multiplier is a shining example of this kind of utterly useless knob...

Well you can also bias against the dcache with any other means, including the change you've made here. My main point I guess is that it should not be in the same as this patchset (or at least an individual patch).

Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Quoted 8 lines

Part of the problem is the funny shrinker API.

The right way to do it is to change the shrinker API so that it passes down the lru_pages and scanned into the callback. From there, the shrinkers can calculate the appropriate ratio of objects to scan. No need for 2-call scheme, no need for shrinker->seeks, and the ability to calculate an appropriate ratio first for dcache, and *then* for icache.

My only concern about this is that exposes the inner workings of the shrinker and mm subsystem to code that simply doesn't need to know about it.

Quoted 6 lines
Quoted 2 lines

It's just providing a ratio. The shrinkers allready know they are scanning based on a ratio of pagecache scanned.

Sure, but the shrinkers are just a simple mechanism for implementing VM policy decisions. IMO reclaim policy decisions should not be pushed down and replicated in every one of these reclaim mechanisms.

Not really. The VM doesn't know about any of those. They are just told to provide a ratio and some scanning based on some abstract cost.

The VM doesn't know anything about usage patterns, inuse vs unused objects, exactly how their LRU algorithms are supposed to work, etc.

There is very little policy decision by the VM in the shrinkers.

Quoted 5 lines
Quoted 1 line

But shrinkers are very subsystem specific.

And as such should concentrate on getting their subsystem reclaim correct, not have to worry about implementing VM policy calculations...

Clearly they wouldn't with what I was proposing. And the result would be much more flexible and also gives the shrinkers more information.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

maintainer
#26 lore raw

Re: [PATCH 3/5] superblock: introduce per-sb cache shrinker infrastructure

In reply to Dave Chinner
Quoted 11 lines · On Tue, 25 May 2010 18:53:06 +1000 Dave Chinner <[email protected]> wrote:

From: Dave Chinner <[email protected]>

With context based shrinkers, we can implement a per-superblock shrinker that shrinks the caches attached to the superblock. We currently have global shrinkers for the inode and dentry caches that split up into per-superblock operations via a coarse proportioning method that does not batch very well. The global shrinkers also have a dependency - dentries pin inodes - so we have to be very careful about how we register the global shrinkers so that the implicit call order is always correct.

Quoted 10 lines

With a per-sb shrinker callout, we can encode this dependency directly into the per-sb shrinker, hence avoiding the need for strictly ordering shrinker registrations. We also have no need for any proportioning code for the shrinker subsystem already provides this functionality across all shrinkers. Allowing the shrinker to operate on a single superblock at a time means that we do less superblock list traversals and locking and reclaim should batch more effectively. This should result in less CPU overhead for reclaim and potentially faster reclaim of items from each filesystem.

I go all tingly when a changelog contains the word "should".

OK, it _should_ do X. But _does_ it actually do X?

Quoted 9 lines
 fs/super.c         |   53 +++++++++++++++++++++
 include/linux/fs.h |    7 +++
 4 files changed, 88 insertions(+), 214 deletions(-)
fs/dcache.c +0 -0
index dba6b6d..d7bd781 100644

fs/dcache.c static void prune_one_dentry(struct dentry * dentry) · line 459

Quoted 5 lines
fs/dcache.c +1 -1
@@ -456,21 +456,16 @@ static void prune_one_dentry(struct dentry * dentry)
  * which flags are set. This means we don't need to maintain multiple
  * similar copies of this loop.
  */
-static void __shrink_dcache_sb(struct super_block *sb, int *count, int flags)
+static void __shrink_dcache_sb(struct super_block *sb, int count, int flags)

Forgot to update the kerneldoc description of `count'.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#27 lore raw

Re: [PATCH 3/5] superblock: introduce per-sb cache shrinker infrastructure

Quoted 25 lines · Andrew Morton
Quoted 11 lines · On Tue, 25 May 2010 18:53:06 +1000 Dave Chinner <[email protected]> wrote:

From: Dave Chinner <[email protected]>

With context based shrinkers, we can implement a per-superblock shrinker that shrinks the caches attached to the superblock. We currently have global shrinkers for the inode and dentry caches that split up into per-superblock operations via a coarse proportioning method that does not batch very well. The global shrinkers also have a dependency - dentries pin inodes - so we have to be very careful about how we register the global shrinkers so that the implicit call order is always correct.

Quoted 10 lines

With a per-sb shrinker callout, we can encode this dependency directly into the per-sb shrinker, hence avoiding the need for strictly ordering shrinker registrations. We also have no need for any proportioning code for the shrinker subsystem already provides this functionality across all shrinkers. Allowing the shrinker to operate on a single superblock at a time means that we do less superblock list traversals and locking and reclaim should batch more effectively. This should result in less CPU overhead for reclaim and potentially faster reclaim of items from each filesystem.

Quoted 3 lines

I go all tingly when a changelog contains the word "should".

OK, it _should_ do X. But _does_ it actually do X?

As i said to Nick - the tests I ran showed an average improvement of 5% but the accuracy of the benchmark was +/-10%. Hence it's hard to draw any conclusive results from that. It appears to be slightly faster on an otherwise idle system, but...

As it is, the XFS shrinker that gets integrated into this structure in a later patch peaks at a higher rate - 150k inodes/s vs 90k inodes/s with the current shrinker - but still it's hard to quantify qualitatively. I'm going to run more benchmarks to try to get better numbers.

Quoted 4 lines
Quoted 4 lines
 fs/super.c         |   53 +++++++++++++++++++++
 include/linux/fs.h |    7 +++
 4 files changed, 88 insertions(+), 214 deletions(-)
Quoted 12 lines

fs/dcache.c static void prune_one_dentry(struct dentry * dentry) · line 459

Quoted 10 lines
fs/dcache.c +1 -1
index dba6b6d..d7bd781 100644
@@ -456,21 +456,16 @@ static void prune_one_dentry(struct dentry * dentry)
  * which flags are set. This means we don't need to maintain multiple
  * similar copies of this loop.
  */
-static void __shrink_dcache_sb(struct super_block *sb, int *count, int flags)
+static void __shrink_dcache_sb(struct super_block *sb, int count, int flags)

Forgot to update the kerneldoc description of `count'.

Will fix.

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#28 lore raw

PATCH 4/5 superblock: add filesystem shrinker operations

In reply to Dave Chinner

From: Dave Chinner <[email protected]>

Now we have a per-superblock shrinker implementation, we can add a filesystem specific callout to it to allow filesystem internal caches to be shrunk by the superblock shrinker.

Rather than perpetuate the multipurpose shrinker callback API (i.e. nr_to_scan == 0 meaning "tell me how many objects freeable in the cache), two operations will be added. The first will return the number of objects that are freeable, the second is the actual shrinker call.

---
 fs/super.c         |   43 +++++++++++++++++++++++++++++++------------
 include/linux/fs.h |   11 +++++++++++
 2 files changed, 42 insertions(+), 12 deletions(-)
fs/super.c +32 -13
index 07e22e3..9410218 100644
@@ -40,7 +40,8 @@ DEFINE_SPINLOCK(sb_lock);
 static int prune_super(struct shrinker *shrink, int nr_to_scan, gfp_t gfp_mask)
 {
 	struct super_block *sb;
-	int count;
+	int	fs_objects = 0;
+	int	total_objects;
 
 	sb = container_of(shrink, struct super_block, s_shrink);
 
@@ -63,22 +64,40 @@ static int prune_super(struct shrinker *shrink, int nr_to_scan, gfp_t gfp_mask)
 		return -1;
 	}
 
-	if (nr_to_scan) {
-		/* proportion the scan between the two cacheѕ */
-		int total;
-
-		total = sb->s_nr_dentry_unused + sb->s_nr_inodes_unused + 1;
-		count = (nr_to_scan * sb->s_nr_dentry_unused) / total;
+	if (sb->s_op && sb->s_op->nr_cached_objects)
+		fs_objects = sb->s_op->nr_cached_objects(sb);
 
-		/* prune dcache first as icache is pinned by it */
-		prune_dcache_sb(sb, count);
-		prune_icache_sb(sb, nr_to_scan - count);
+	total_objects = sb->s_nr_dentry_unused +
+			sb->s_nr_inodes_unused + fs_objects + 1;
+	if (nr_to_scan) {
+		int	dentries;
+		int	inodes;
+
+		/* proportion the scan between the cacheѕ */
+		dentries = (nr_to_scan * sb->s_nr_dentry_unused) /
+							total_objects;
+		inodes = (nr_to_scan * sb->s_nr_inodes_unused) /
+							total_objects;
+		if (fs_objects)
+			fs_objects = (nr_to_scan * fs_objects) /
+							total_objects;
+		/*
+		 * prune the dcache first as the icache is pinned by it, then
+		 * prune the icache, followed by the filesystem specific caches
+		 */
+		prune_dcache_sb(sb, dentries);
+		prune_icache_sb(sb, inodes);
+		if (sb->s_op && sb->s_op->free_cached_objects) {
+			sb->s_op->free_cached_objects(sb, fs_objects);
+			fs_objects = sb->s_op->nr_cached_objects(sb);
+		}
+		total_objects = sb->s_nr_dentry_unused +
+				sb->s_nr_inodes_unused + fs_objects;
 	}
 
-	count = ((sb->s_nr_dentry_unused + sb->s_nr_inodes_unused) / 100)
-						* sysctl_vfs_cache_pressure;
+	total_objects = (total_objects / 100) * sysctl_vfs_cache_pressure;
 	up_read(&sb->s_umount);
-	return count;
+	return total_objects;
 }
 
 /**
include/linux/fs.h +11 -0
index 5bff2dc..efcdcc6 100644
@@ -1590,6 +1590,17 @@ struct super_operations {
 	ssize_t (*quota_write)(struct super_block *, int, const char *, size_t, loff_t);
 #endif
 	int (*bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t);
+
+	/*
+	 * memory shrinker operations.
+	 * ->nr_cached_objects() should return the number of freeable cached
+	 * objects the filesystem holds.
+	 * ->free_cache_objects() should attempt to free the number of cached
+	 * objects indicated. It should return how many objects it attempted to
+	 * free.
+	 */
+	int (*nr_cached_objects)(struct super_block *);
+	int (*free_cached_objects)(struct super_block *, int);
 };
 
 /*
Signature · 1 line
1.5.6.5

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

maintainer
#29 lore raw

Re: [PATCH 4/5] superblock: add filesystem shrinker operations

Quoted 51 lines · On Tue, 25 May 2010 18:53:07 +1000 Dave Chinner <[email protected]> wrote:

From: Dave Chinner <[email protected]>

Now we have a per-superblock shrinker implementation, we can add a filesystem specific callout to it to allow filesystem internal caches to be shrunk by the superblock shrinker.

Rather than perpetuate the multipurpose shrinker callback API (i.e. nr_to_scan == 0 meaning "tell me how many objects freeable in the cache), two operations will be added. The first will return the number of objects that are freeable, the second is the actual shrinker call.

...

static int prune_super(struct shrinker *shrink, int nr_to_scan, gfp_t gfp_mask) {

fs/super.c +15 -10
 	struct super_block *sb;
-	int count;
+	int	fs_objects = 0;
+	int	total_objects;
 
 	sb = container_of(shrink, struct super_block, s_shrink);
@@ -63,22 +64,40 @@ static int prune_super(struct shrinker *shrink, int nr_to_scan, gfp_t gfp_mask)
 		return -1;
 	}
 
-	if (nr_to_scan) {
-		/* proportion the scan between the two cache__ */
-		int total;
-
-		total = sb->s_nr_dentry_unused + sb->s_nr_inodes_unused + 1;
-		count = (nr_to_scan * sb->s_nr_dentry_unused) / total;
+	if (sb->s_op && sb->s_op->nr_cached_objects)
+		fs_objects = sb->s_op->nr_cached_objects(sb);
 
-		/* prune dcache first as icache is pinned by it */
-		prune_dcache_sb(sb, count);
-		prune_icache_sb(sb, nr_to_scan - count);
+	total_objects = sb->s_nr_dentry_unused +
+			sb->s_nr_inodes_unused + fs_objects + 1;
+	if (nr_to_scan) {
+		int	dentries;
+		int	inodes;
+
+		/* proportion the scan between the cache__ */
+		dentries = (nr_to_scan * sb->s_nr_dentry_unused) /
+							total_objects;
+		inodes = (nr_to_scan * sb->s_nr_inodes_unused) /
+							total_objects;

fs/super.c static int prune_super(struct shrinker *shrink, int nr_to_scan, gfp_t gfp_mask) · line 90

Quoted 10 lines
fs/super.c +10 -0
+		if (fs_objects)
+			fs_objects = (nr_to_scan * fs_objects) /
+							total_objects;
+		/*
+		 * prune the dcache first as the icache is pinned by it, then
+		 * prune the icache, followed by the filesystem specific caches
+		 */
+		prune_dcache_sb(sb, dentries);
+		prune_icache_sb(sb, inodes);
+		if (sb->s_op && sb->s_op->free_cached_objects) {

Under which circumstances is a NULL ->free_cached_objects valid?

fs/super.c static int prune_super(struct shrinker *shrink, int nr_to_scan, gfp_t gfp_mask) · line 96

Quoted 6 lines
fs/super.c +5 -0
+			sb->s_op->free_cached_objects(sb, fs_objects);
+			fs_objects = sb->s_op->nr_cached_objects(sb);
+		}
+		total_objects = sb->s_nr_dentry_unused +
+				sb->s_nr_inodes_unused + fs_objects;
 	}

The return value from ->free_cached_objects() doesn't actually get used. Instead the code calls ->nr_cached_objects() twice.

Quoted 16 lines
fs/super.c +2 -3
-	count = ((sb->s_nr_dentry_unused + sb->s_nr_inodes_unused) / 100)
-						* sysctl_vfs_cache_pressure;
+	total_objects = (total_objects / 100) * sysctl_vfs_cache_pressure;
 	up_read(&sb->s_umount);
-	return count;
+	return total_objects;
 }
 
 /**
include/linux/fs.h +0 -0
index 5bff2dc..efcdcc6 100644
@@ -1590,6 +1590,17 @@ struct super_operations {
 	ssize_t (*quota_write)(struct super_block *, int, const char *, size_t, loff_t);
 #endif

include/linux/fs.h struct super_operations { · line 1601

Quoted 10 lines
include/linux/fs.h +9 -0
 	int (*bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t);
+
+	/*
+	 * memory shrinker operations.
+	 * ->nr_cached_objects() should return the number of freeable cached
+	 * objects the filesystem holds.
+	 * ->free_cache_objects() should attempt to free the number of cached
+	 * objects indicated. It should return how many objects it attempted to
+	 * free.
+	 */

I'd have thought that ->free_cache_objects() would always return the number which it was passed. Unless someone asked it to scan more objects than exist, perhaps.

include/linux/fs.h struct super_operations { · line 1604

Quoted 3 lines
include/linux/fs.h +2 -0
+	int (*nr_cached_objects)(struct super_block *);
+	int (*free_cached_objects)(struct super_block *, int);
 };

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#30 lore raw

PATCH 5/5 xfs: make use of new shrinker callout

In reply to Dave Chinner

From: Dave Chinner <[email protected]>

Convert the inode reclaim shrinker to use the new per-sb shrinker operations. This fixes a bunch of lockdep warnings about the xfs_mount_list_lock being taken in different reclaim contexts by removing it, and allows the reclaim to be proportioned across filesystems with no extra code.

---
 fs/xfs/linux-2.6/xfs_super.c   |   23 ++++++--
 fs/xfs/linux-2.6/xfs_sync.c    |  124 +++++++++++-----------------------------
 fs/xfs/linux-2.6/xfs_sync.h    |   16 +++--
 fs/xfs/quota/xfs_qm_syscalls.c |    2 +-
 fs/xfs/xfs_mount.h             |    1 -
 5 files changed, 61 insertions(+), 105 deletions(-)
fs/xfs/linux-2.6/xfs_super.c +18 -5
index f24dbe5..b59886a 100644
@@ -1212,7 +1212,6 @@ xfs_fs_put_super(
 
 	xfs_unmountfs(mp);
 	xfs_freesb(mp);
-	xfs_inode_shrinker_unregister(mp);
 	xfs_icsb_destroy_counters(mp);
 	xfs_close_devices(mp);
 	xfs_dmops_put(mp);
@@ -1626,8 +1625,6 @@ xfs_fs_fill_super(
 	if (error)
 		goto fail_vnrele;
 
-	xfs_inode_shrinker_register(mp);
-
 	kfree(mtpt);
 	return 0;
 
@@ -1681,6 +1678,22 @@ xfs_fs_get_sb(
 			   mnt);
 }
 
+static int
+xfs_fs_nr_cached_objects(
+	struct super_block	*sb)
+{
+	return xfs_reclaim_inodes_count(XFS_M(sb));
+}
+
+static int
+xfs_fs_free_cached_objects(
+	struct super_block	*sb,
+	int			nr_to_scan)
+{
+	xfs_reclaim_inodes_nr(XFS_M(sb), 0, nr_to_scan);
+	return 0;
+}
+
 static const struct super_operations xfs_super_operations = {
 	.alloc_inode		= xfs_fs_alloc_inode,
 	.destroy_inode		= xfs_fs_destroy_inode,
@@ -1694,6 +1707,8 @@ static const struct super_operations xfs_super_operations = {
 	.statfs			= xfs_fs_statfs,
 	.remount_fs		= xfs_fs_remount,
 	.show_options		= xfs_fs_show_options,
+	.nr_cached_objects	= xfs_fs_nr_cached_objects,
+	.free_cached_objects	= xfs_fs_free_cached_objects,
 };
 
 static struct file_system_type xfs_fs_type = {
@@ -1873,7 +1888,6 @@ init_xfs_fs(void)
 		goto out_cleanup_procfs;
 
 	vfs_initquota();
-	xfs_inode_shrinker_init();
 
 	error = register_filesystem(&xfs_fs_type);
 	if (error)
@@ -1901,7 +1915,6 @@ exit_xfs_fs(void)
 {
 	vfs_exitquota();
 	unregister_filesystem(&xfs_fs_type);
-	xfs_inode_shrinker_destroy();
 	xfs_sysctl_unregister();
 	xfs_cleanup_procfs();
 	xfs_buf_terminate();
fs/xfs/linux-2.6/xfs_sync.c +33 -91

186 lines not on this page · raw message

fs/xfs/linux-2.6/xfs_sync.h +9 -7
index cdcbaac..c55f645 100644
@@ -43,7 +43,14 @@ void xfs_quiesce_attr(struct xfs_mount *mp);
 
 void xfs_flush_inodes(struct xfs_inode *ip);
 
-int xfs_reclaim_inodes(struct xfs_mount *mp, int mode);
+int xfs_reclaim_inodes_count(struct xfs_mount *mp);
+int xfs_reclaim_inodes_nr(struct xfs_mount *mp, int mode, int nr_to_scan);
+
+static inline int
+xfs_reclaim_inodes(struct xfs_mount *mp, int mode)
+{
+	return xfs_reclaim_inodes_nr(mp, mode, 0);
+}
 
 void xfs_inode_set_reclaim_tag(struct xfs_inode *ip);
 void __xfs_inode_set_reclaim_tag(struct xfs_perag *pag, struct xfs_inode *ip);
@@ -53,11 +60,6 @@ void __xfs_inode_clear_reclaim_tag(struct xfs_mount *mp, struct xfs_perag *pag,
 int xfs_sync_inode_valid(struct xfs_inode *ip, struct xfs_perag *pag);
 int xfs_inode_ag_iterator(struct xfs_mount *mp,
 	int (*execute)(struct xfs_inode *ip, struct xfs_perag *pag, int flags),
-	int flags, int tag, int write_lock, int *nr_to_scan);
-
-void xfs_inode_shrinker_init(void);
-void xfs_inode_shrinker_destroy(void);
-void xfs_inode_shrinker_register(struct xfs_mount *mp);
-void xfs_inode_shrinker_unregister(struct xfs_mount *mp);
+	int flags, int tag, int write_lock, int nr_to_scan);
 
 #endif
fs/xfs/quota/xfs_qm_syscalls.c +1 -1
index 92b002f..f5b0e4e 100644
@@ -894,7 +894,7 @@ xfs_qm_dqrele_all_inodes(
 {
 	ASSERT(mp->m_quotainfo);
 	xfs_inode_ag_iterator(mp, xfs_dqrele_inode, flags,
-				XFS_ICI_NO_TAG, 0, NULL);
+				XFS_ICI_NO_TAG, 0, 0);
 }
 
 /*------------------------------------------------------------------------*/
fs/xfs/xfs_mount.h +0 -1
index 9ff48a1..4fa0bc7 100644
@@ -259,7 +259,6 @@ typedef struct xfs_mount {
 	wait_queue_head_t	m_wait_single_sync_task;
 	__int64_t		m_update_flags;	/* sb flags we need to update
 						   on the next remount,rw */
-	struct list_head	m_mplist;	/* inode shrinker mount list */
 } xfs_mount_t;
 
 /*
Signature · 6 lines
1.5.6.5

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#31 lore raw
In reply to Dave Chinner
Quoted 14 lines · Dave Chinner

This series reworks the filesystem shrinkers. We currently have a set of issues with the current filesystem shrinkers:

1. There is an dependency between dentry and inode cache shrinking that is only implicitly defined by the order of shrinker registration.
2. The shrinkers need to walk the superblock list and pin the superblock to avoid unmount races with the sb going away.
3. The dentry cache uses per-superblock LRUs and proportions reclaim between all the superblocks which means we are doing breadth based reclaim. This means we touch every superblock for every shrinker call, and may only reclaim

Quoted 8 lines

a single dentry at a time from a given superblock.
4. The inode cache has a global LRU, so it has different reclaim patterns to the dentry cache, despite the fact that the dentry cache is generally the only thing that pins inodes in memory.
5. Filesystems need to register their own shrinkers for caches and can't co-ordinate them with the dentry and inode cache shrinkers.

Seems like a fairly good approach overall. Thanks.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

maintainer
#32 lore raw
In reply to Dave Chinner
Quoted 13 lines · On Tue, 25 May 2010 18:53:03 +1000 Dave Chinner <[email protected]> wrote:

This series reworks the filesystem shrinkers. We currently have a set of issues with the current filesystem shrinkers:

1. There is an dependency between dentry and inode cache shrinking that is only implicitly defined by the order of shrinker registration.
2. The shrinkers need to walk the superblock list and pin the superblock to avoid unmount races with the sb going away.
3. The dentry cache uses per-superblock LRUs and proportions reclaim between all the superblocks which means we are doing breadth based reclaim. This means we touch every superblock for every shrinker call, and may only reclaim

Quoted 8 lines

a single dentry at a time from a given superblock.
4. The inode cache has a global LRU, so it has different reclaim patterns to the dentry cache, despite the fact that the dentry cache is generally the only thing that pins inodes in memory.
5. Filesystems need to register their own shrinkers for caches and can't co-ordinate them with the dentry and inode cache shrinkers.

Nice description, but... it never actually told us what the benefit of the changes are. Presumably some undescribed workload had some undescribed user-visible problem. But what was that workload, and what was the user-visible problem, and how does the patch affect all this?

Stuff like that.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#33 lore raw
Quoted 25 lines · Andrew Morton
Quoted 13 lines · On Tue, 25 May 2010 18:53:03 +1000 Dave Chinner <[email protected]> wrote:

This series reworks the filesystem shrinkers. We currently have a set of issues with the current filesystem shrinkers:

1. There is an dependency between dentry and inode cache shrinking that is only implicitly defined by the order of shrinker registration.
2. The shrinkers need to walk the superblock list and pin the superblock to avoid unmount races with the sb going away.
3. The dentry cache uses per-superblock LRUs and proportions reclaim between all the superblocks which means we are doing breadth based reclaim. This means we touch every superblock for every shrinker call, and may only reclaim

Quoted 8 lines

a single dentry at a time from a given superblock.
4. The inode cache has a global LRU, so it has different reclaim patterns to the dentry cache, despite the fact that the dentry cache is generally the only thing that pins inodes in memory.
5. Filesystems need to register their own shrinkers for caches and can't co-ordinate them with the dentry and inode cache shrinkers.

Quoted 2 lines

Nice description, but... it never actually told us what the benefit of the changes are.

The first patch I wrote was a small patch to introduce context to the shrinker callback and a per­XFS filesystem shrinker to solve OOM probelms introduced by background reclaim of XFS inodes. It was simple, it worked but Nick refused to allow it because of #1 listed above. He wanted some <handwaves> guarantee that context based shrinkers would not break the implicit registration dependency between the dentry and inode cache shrinkers.

We needed a fix for 2.6.34 for XFS, so I was forced to write a global shrinker which is what introduced all the lockdep problems. XFS does not have global inode caches, and the lock required to manage the list of XFs mounts were what caused all the new lockdep problems. There's also other lockdep false positive problems w/ XFS and shrinkers (e.g. iprune_sem and the unmount path) that need to be fixed.

That's what this patchset tries to address. It results in simpler code, less code, removal of implicit, undocumented dependencies, less locking shenanegans, no superblock list traversals, provides filesystems with hooks for cache reclaim without needing shrinker registration and fixes all the all the false positive lockdep problems XFS has with the current shrinker infrastructure.

If this is all too much, then I'm quite happy to go back to just the context based shrinker patch and leave everything else alone - the context based shrinkers are the change we *really* need. Everything else in this set of changes is just trying to address objections raised (that I still don't really understand) against that simple change.

Quoted 2 lines

Presumably some undescribed workload had some
undescribed user-visible problem.

$ find . -inum 11111

on a filesystem with more inodes in it than can be held in memory caused OOM panics.

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#34 lore raw
In reply to Andrew Morton
Quoted 25 lines · Andrew Morton
Quoted 13 lines · On Tue, 25 May 2010 18:53:03 +1000 Dave Chinner <[email protected]> wrote:

This series reworks the filesystem shrinkers. We currently have a set of issues with the current filesystem shrinkers:

1. There is an dependency between dentry and inode cache shrinking that is only implicitly defined by the order of shrinker registration.
2. The shrinkers need to walk the superblock list and pin the superblock to avoid unmount races with the sb going away.
3. The dentry cache uses per-superblock LRUs and proportions reclaim between all the superblocks which means we are doing breadth based reclaim. This means we touch every superblock for every shrinker call, and may only reclaim

Quoted 8 lines

a single dentry at a time from a given superblock.
4. The inode cache has a global LRU, so it has different reclaim patterns to the dentry cache, despite the fact that the dentry cache is generally the only thing that pins inodes in memory.
5. Filesystems need to register their own shrinkers for caches and can't co-ordinate them with the dentry and inode cache shrinkers.

Quoted 4 lines

Nice description, but... it never actually told us what the benefit of the changes are. Presumably some undescribed workload had some undescribed user-visible problem. But what was that workload, and what was the user-visible problem, and how does the patch affect all this?

For UBIFS it wwill give a benefit in terms of simpler UBIFS code - we now have to keep our own list of UBIFS superblocks, provide locking for it, and maintain. This is just extra burden. So the item 2 above will be useful for UBIFS.

Signature · 8 lines
Best Regards,
Artem Bityutskiy (Артём Битюцкий)

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#36 lore raw
Quoted 2 lines · Christoph Hellwig

Did you plan to resubmit this with the few review comments addressed? I'd really hate to not see this in 2.6.36.

I've been doing some more testing on it, and while I can get a 25% reduction in the time to create and remove 10 million inodes with per-sb shrinker, I can't get the reclaim pattern stable enough for my liking.

At this point in the cycle, I'd much prefer just to go with adding a context to the shrinker API to fix the XFS locking issues (i.e. the original patches I sent) and spend a bit more time working out which combination of Nick's and my bits that improves reclaim speed whilst retaining the stability of the courrent code....

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#37 lore raw
Quoted 5 lines · Dave Chinner

At this point in the cycle, I'd much prefer just to go with adding a context to the shrinker API to fix the XFS locking issues (i.e. the original patches I sent) and spend a bit more time working out which combination of Nick's and my bits that improves reclaim speed whilst retaining the stability of the courrent code....

That approach sounds good to me.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs