From mboxrd@z Thu Jan 1 00:00:00 1970 From: Glauber Costa Subject: [PATCH v7 14/34] list_lru: per-node API Date: Mon, 20 May 2013 00:07:07 +0400 Message-ID: <1368994047-5997-15-git-send-email-glommer@openvz.org> References: <1368994047-5997-1-git-send-email-glommer@openvz.org> Cc: , Andrew Morton , Greg Thelen , , Michal Hocko , Johannes Weiner , , Dave Chinner , hughd@google.com, Glauber Costa , Dave Chinner , Mel Gorman To: Return-path: Received: from mailhub.sw.ru ([195.214.232.25]:28582 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754541Ab3ESUHc (ORCPT ); Sun, 19 May 2013 16:07:32 -0400 In-Reply-To: <1368994047-5997-1-git-send-email-glommer@openvz.org> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: This patch adapts the list_lru API to accept an optional node argument, to be used by NUMA aware shrinking functions. Code that does not care about the NUMA placement of objects can still call into the very same functions as before. They will simply iterate over all nodes. Signed-off-by: Glauber Costa Cc: Dave Chinner Cc: Mel Gorman --- include/linux/list_lru.h | 34 +++++++++++++++++++++++++++++++++- lib/list_lru.c | 41 +++++++++-------------------------------- 2 files changed, 42 insertions(+), 33 deletions(-) diff --git a/include/linux/list_lru.h b/include/linux/list_lru.h index 668f1f1..4ff148c 100644 --- a/include/linux/list_lru.h +++ b/include/linux/list_lru.h @@ -42,13 +42,45 @@ struct list_lru { int list_lru_init(struct list_lru *lru); int list_lru_add(struct list_lru *lru, struct list_head *item); int list_lru_del(struct list_lru *lru, struct list_head *item); -unsigned long list_lru_count(struct list_lru *lru); + +unsigned long list_lru_count_node(struct list_lru *lru, int nid); +static unsigned long list_lru_count(struct list_lru *lru) +{ + long count = 0; + int nid; + + for_each_node_mask(nid, lru->active_nodes) + count += list_lru_count_node(lru, nid); + + return count; +} typedef enum lru_status (*list_lru_walk_cb)(struct list_head *item, spinlock_t *lock, void *cb_arg); typedef void (*list_lru_dispose_cb)(struct list_head *dispose_list); + +unsigned long list_lru_walk_node(struct list_lru *lru, int nid, + list_lru_walk_cb isolate, void *cb_arg, + unsigned long *nr_to_walk); + +static unsigned long +list_lru_walk(struct list_lru *lru, list_lru_walk_cb isolate, + void *cb_arg, unsigned long nr_to_walk) +{ + long isolated = 0; + int nid; + + for_each_node_mask(nid, lru->active_nodes) { + isolated += list_lru_walk_node(lru, nid, isolate, + cb_arg, &nr_to_walk); + if (nr_to_walk <= 0) + break; + } + return isolated; +} + unsigned long list_lru_walk(struct list_lru *lru, list_lru_walk_cb isolate, void *cb_arg, unsigned long nr_to_walk); diff --git a/lib/list_lru.c b/lib/list_lru.c index 7611df7..dae13d6 100644 --- a/lib/list_lru.c +++ b/lib/list_lru.c @@ -54,25 +54,21 @@ list_lru_del( EXPORT_SYMBOL_GPL(list_lru_del); unsigned long -list_lru_count(struct list_lru *lru) +list_lru_count_node(struct list_lru *lru, int nid) { long count = 0; - int nid; - - for_each_node_mask(nid, lru->active_nodes) { - struct list_lru_node *nlru = &lru->node[nid]; + struct list_lru_node *nlru = &lru->node[nid]; - spin_lock(&nlru->lock); - BUG_ON(nlru->nr_items < 0); - count += nlru->nr_items; - spin_unlock(&nlru->lock); - } + spin_lock(&nlru->lock); + BUG_ON(nlru->nr_items < 0); + count += nlru->nr_items; + spin_unlock(&nlru->lock); return count; } -EXPORT_SYMBOL_GPL(list_lru_count); +EXPORT_SYMBOL_GPL(list_lru_count_node); -static unsigned long +unsigned long list_lru_walk_node( struct list_lru *lru, int nid, @@ -118,26 +114,7 @@ restart: spin_unlock(&nlru->lock); return isolated; } - -unsigned long -list_lru_walk( - struct list_lru *lru, - list_lru_walk_cb isolate, - void *cb_arg, - unsigned long nr_to_walk) -{ - long isolated = 0; - int nid; - - for_each_node_mask(nid, lru->active_nodes) { - isolated += list_lru_walk_node(lru, nid, isolate, - cb_arg, &nr_to_walk); - if (nr_to_walk <= 0) - break; - } - return isolated; -} -EXPORT_SYMBOL_GPL(list_lru_walk); +EXPORT_SYMBOL_GPL(list_lru_walk_node); static unsigned long list_lru_dispose_all_node( -- 1.8.1.4