GFS2: Use list_lru for quota lru list
Subsystems (3)
This patch is a first go (only compile tested so far) at what list_lru support should look like for GFS2's quota subsystem. I've done this one rather than the glock lru list first, since this is easier. There are still some unresolved issues on the glock side with how to use the new list_lru code.
The conversion is fairly straight forward in this case though, just requiring an extra function to conditionally add items to the lru list upon an atomic counter hitting zero. The other change is that the locking as split into two, one the internal lock in the lru code, and the other being a new quota spinlock, which is used for all the non-lru locking.
Let me know if you can spot any problems, and we'll move on to doing a bit of testing before we merge this. Once thats done, I'll start looking at the glock issues again to see if I can make some headway there too,
Steve.
fs/gfs2/main.c +9 -0
@@ -18,6 +18,7 @@#include <linux/rculist_bl.h> #include <linux/atomic.h> #include <linux/mempool.h> +#include <linux/list_lru.h> #include "gfs2.h" #include "incore.h"
@@ -35,6 +36,7 @@ static struct shrinker qd_shrinker = { .count_objects = gfs2_qd_shrink_count, .scan_objects = gfs2_qd_shrink_scan, .seeks = DEFAULT_SEEKS, + .flags = SHRINKER_NUMA_AWARE, };static void gfs2_init_inode_once (void *foo)
@@ -87,6 +89,10 @@ static int __init init_gfs2_fs(void)if (error)return error; + error =list_lru_init (&gfs2_qd_lru); +if (error) + goto fail_lru; + error =gfs2_glock_init ();if (error) goto fail;
@@ -179,6 +185,8 @@ fail_wq: fail_unregister:unregister_filesystem (&gfs2_fs_type); fail: +list_lru_destroy (&gfs2_qd_lru); +fail_lru:unregister_shrinker (&qd_shrinker);gfs2_glock_exit ();
@@ -221,6 +229,7 @@ static void __exit exit_gfs2_fs(void)unregister_filesystem (&gfs2meta_fs_type);destroy_workqueue (gfs_recovery_wq);destroy_workqueue (gfs2_control_wq); +list_lru_destroy (&gfs2_qd_lru);rcu_barrier ();
fs/gfs2/quota.c +68 -81
324 lines not on this page · raw message
fs/gfs2/quota.h +1 -0
@@ -58,5 +58,6 @@ extern unsigned long gfs2_qd_shrink_count(struct shrinker *shrink,extern unsigned long gfs2_qd_shrink_scan (struct shrinker *shrink,struct shrink_control *sc);extern const struct quotactl_ops gfs2_quotactl_ops; +extern struct list_lru gfs2_qd_lru;#endif /* __QUOTA_DOT_H__ */
include/linux/list_lru.h +16 -0
@@ -53,6 +53,22 @@ int list_lru_init(struct list_lru *lru);bool list_lru_add (struct list_lru *lru,struct list_head *item);/** +* list_lru_add_on_zero: decrement counter and atomically add to lru on zero +* @list_lru: the lru pointer +* @item: the item to potentially add to the lru +* @counter: the counter to decrement +* +* If the @counter is zero after decrementing, then the item will be +* atomically added to the lru, assuming that it is not already there. +* This is identical to list_lru_add, aside from the additional testing +* of an atomic counter. +* +* Return value: true if the list was updated, false otherwise +*/ +bool list_lru_add_on_zero (struct list_lru *lru,struct list_head *item,atomic_t + *count); + +/** * list_lru_del: delete an element to the lru list * @list_lru: the lru pointer * @item: the item to be deleted.
mm/list_lru.c +20 -0
@@ -29,6 +29,26 @@ bool list_lru_add(struct list_lru *lru, struct list_head *item) }EXPORT_SYMBOL_GPL (list_lru_add); +bool list_lru_add_on_zero (struct list_lru *lru,struct list_head *item,atomic_t *count) +{ +int nid =page_to_nid (virt_to_page (item)); +struct list_lru_node *nlru = &lru->node[nid]; + +if (atomic_dec_and_lock (count, &nlru->lock)) { +WARN_ON_ONCE (nlru->nr_items <0 ); +if (list_empty (item)) { +list_add_tail (item, &nlru->list); +if (nlru->nr_items++ ==0 ) +node_set (nid, lru->active_nodes); +spin_unlock (&nlru->lock); +return true; + } +spin_unlock (&nlru->lock); + } +return false; +} +EXPORT_SYMBOL_GPL (list_lru_add_on_zero); +bool list_lru_del (struct list_lru *lru,struct list_head *item) {int nid =page_to_nid (virt_to_page (item));
Quoted 7 lines · Steven Whitehouse
This patch is a first go (only compile tested so far) at what
list_lrusupport should look like for GFS2's quota subsystem. I've done this one rather than the glock lru list first, since this is easier. There are still some unresolved issues on the glock side with how to use the newlist_lrucode.
Quoted 6 lines
The conversion is fairly straight forward in this case though, just requiring an extra function to conditionally add items to the lru list upon an atomic counter hitting zero. The other change is that the locking as split into two, one the internal lock in the lru code, and the other being a new quota spinlock, which is used for all the non-lru locking.
I'm nmot sure I really like the concept of adding reference count futzing into the list_lru operations. The whole point of th einternal locking of the list_lru is that it is independent of the objects being placed on the LRUs. That is, objects cannot use the internal LRU list locks for serialisation in any manner as it is purely there for correctness of LRU list internals, not for external object lifecycle management.
More below.
<trimmed to jus tbe the new code block>
fs/gfs2/quota.c struct gfs2_quota_change_host { · line 90
Quoted 13 lines
fs/gfs2/quota.c +8
-0+static enum lru_status gfs2_qd_walk (struct list_head *item,spinlock_t *lock,void *arg) {struct gfs2_quota_data *qd;struct gfs2_sbd *sdp; + qd = list_entry(item, struct gfs2_quota_data, qd_reclaim); + sdp = qd->qd_gl->gl_sbd; +spin_lock (&qd_lock); +if (atomic_read (&qd->qd_count)) { +spin_unlock (&qd_lock); +return LRU_SKIP ; + }
The LRU locks are considered "innermost" so you cannot take other locks inside the lru locks like this. So that needs to be a spin_trylock()....
fs/gfs2/quota.c struct gfs2_quota_change_host { · line 93
Quoted 3 lines
fs/gfs2/quota.c +2
-0+/* Free from the filesystem-specific list */ +list_del (&qd->qd_list);
LRU lists require list_del_init()
Review
Quoted 2 lines
(quoted diff) +2
-0+ spin_unlock(&qd_lock); + spin_unlock(lock);
You dropped the LRU lock, and hence can only return LRU_RETRY at this point to indicate that the LRU traversal needs to be restarted.
fs/gfs2/quota.c struct gfs2_quota_change_host { · line 105
Quoted 9 lines
fs/gfs2/quota.c +7
-0+gfs2_assert_warn (sdp, !qd->qd_change); +gfs2_assert_warn (sdp, !qd->qd_slot_count); +gfs2_assert_warn (sdp, !qd->qd_bh_count); +gfs2_glock_put (qd->qd_gl); +atomic_dec (&sdp->sd_quota_count); +/* Delete it from the common reclaim list */ +kmem_cache_free (gfs2_quotad_cachep, qd);
This callback is intended not to be used directly for freeing objects. The idea is that you pass a dispose list to the callback and you mark items as "on the dispose list" when you move it to them so you don't need to drop the LRU lock. Then when the scan returns, you walk the dispose list and free all the objects...
fs/gfs2/quota.c struct gfs2_quota_change_host { · line 118
Quoted 13 lines
fs/gfs2/quota.c +13
-0+spin_lock (lock); + +return LRU_REMOVED ; +} + +unsigned long gfs2_qd_shrink_scan (struct shrinker *shrink, +struct shrink_control *sc) +{ +if (!(sc->gfp_mask & __GFP_FS)) +return SHRINK_STOP ; + +return list_lru_walk_node (&gfs2_qd_lru, sc->nid, gfs2_qd_walk,NULL , + &sc->nr_to_scan);
i.e. here is where you'd dispose of all the items isolated from the LRU in the isolation callback.
Quoted 23 lines
static u64
qd2index(struct gfs2_quota_data *qd)fs/gfs2/quota.c +3
-0@@ -177,15 +180,9 @@ static int qd_get(struct gfs2_sbd *sdp, struct kqid qid,for (;;) { found =0 ; +spin_lock (&qd_lock);list_for_each_entry (qd, &sdp->sd_quota_list, qd_list) {if (qid_eq (qd->qd_id, qid)) {atomic_inc (&qd->qd_count); found =1 ;break ;@@ -202,9 +199,10 @@ static int qd_get(struct gfs2_sbd *sdp, struct kqid qid, new_qd =NULL ; } +spin_unlock (&qd_lock);if (qd) { +list_lru_del (&gfs2_qd_lru, &qd->qd_reclaim);if (new_qd) {gfs2_glock_put (new_qd->qd_gl);kmem_cache_free (gfs2_quotad_cachep, new_qd);
fs/gfs2/quota.c static void qd_hold(struct gfs2_quota_data *qd) · line 229
Quoted 10 lines
fs/gfs2/quota.c +1
-6@@ -228,12 +226,7 @@ static void qd_hold(struct gfs2_quota_data *qd)static void qd_put (struct gfs2_quota_data *qd) { -if (atomic_dec_and_lock (&qd->qd_count, &qd_lru_lock)) { -/* Add to the reclaim list */ -list_add_tail (&qd->qd_reclaim, &qd_lru_list); -atomic_inc (&qd_lru_count); -spin_unlock (&qd_lru_lock); - } +list_lru_add_on_zero (&gfs2_qd_lru, &qd->qd_reclaim, &qd->qd_count);
Why do you need to take the LRU lock atomically here?
It appears to me that you have a situation where the reference count of zero means "on the LRU list", but there's nothing in qd_get() that enforces the LRU removal only occurs for the first reference that is taken. Indeed, why do you even need to remove the item from the LRU list when you get a reference to it? you skip referenced dquots in the isolation callback, so the only time it needs to be removed from the LRU is on reclaim. And that means you only need an atomic_dec_and_test() to determine if you need to add the dquot to the LRU....
So what it appears to me is that you need to do is:
a) separate the dq_lru_lock > dq_lock changes into a separate patch
b) separate the object reference counting from the LRU operations
c) make the LRU operations the innermost operations for locking purposes
d) convert to list_lru operations...
Cheers,
Dave.
Signature · 2 lines
Dave Chinner dchinner at redhat.com