From patchwork Fri Sep 11 10:54:28 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 7159671 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B22879F380 for ; Fri, 11 Sep 2015 10:56:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DBE7E204CF for ; Fri, 11 Sep 2015 10:56:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F414A2056D for ; Fri, 11 Sep 2015 10:56:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752130AbbIKKz4 (ORCPT ); Fri, 11 Sep 2015 06:55:56 -0400 Received: from mail-yk0-f172.google.com ([209.85.160.172]:32836 "EHLO mail-yk0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752766AbbIKKyz (ORCPT ); Fri, 11 Sep 2015 06:54:55 -0400 Received: by ykei199 with SMTP id i199so86956117yke.0 for ; Fri, 11 Sep 2015 03:54:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=pI1/NlbeyVaGCqVmmlvWIYXJ506LwzlJVEtFZ5o9pTY=; b=Udg8nDll+1Sd5cgD6KhqaJXQfmSqYUbXks8OBqLiNWhciiq8dLo0PtGyWHmrRRWcR6 6zSqmm+xMrX4pByMN8eJEsrRy8UK+SoVkUteLIDfW7+N953WL5sk5tt4AZV6qp9pHunn QpgHXoqsClJLkNgxvNxoDZzQnFQBF9lQfKjpf/LUYwrbLNt47x9+QiVjDSiwM0Ox89FO /idMUVwsHeV74NHGS4IlG0J3WRDTYJsUfhmpLsdTTYmE50RSRJzxlqgvwPW2PRtEQODR cD/yHrSoPP+BvhEz1ZJa0ZEnUOn/lbxVF66eWC/5wyC9N9v7BTN7fiQlQ1V6mWdMapYf TjGg== X-Gm-Message-State: ALoCoQkE/cBOFYMTXpF3Og9Z/hzAkVpt8hp63gI2CNKz5G4Mpq1Ruv9g4bLFg92eleFuc3k66KEi X-Received: by 10.13.207.65 with SMTP id r62mr53833645ywd.18.1441968894879; Fri, 11 Sep 2015 03:54:54 -0700 (PDT) Received: from tlielax.poochiereds.net ([2606:a000:1105:8e:3a60:77ff:fe93:a95d]) by smtp.googlemail.com with ESMTPSA id u8sm489915ywe.17.2015.09.11.03.54.53 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Sep 2015 03:54:54 -0700 (PDT) From: Jeff Layton X-Google-Original-From: Jeff Layton To: bfields@fieldses.org Cc: linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, Andrew Morton , linux-mm@kvack.org Subject: [PATCH v4 02/16] list_lru: add list_lru_rotate Date: Fri, 11 Sep 2015 06:54:28 -0400 Message-Id: <1441968882-7851-3-git-send-email-jeff.layton@primarydata.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1441968882-7851-1-git-send-email-jeff.layton@primarydata.com> References: <1441968882-7851-1-git-send-email-jeff.layton@primarydata.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add a function that can move an entry to the MRU end of the list. Cc: Andrew Morton Cc: linux-mm@kvack.org Reviewed-by: Vladimir Davydov Signed-off-by: Jeff Layton --- include/linux/list_lru.h | 13 +++++++++++++ mm/list_lru.c | 15 +++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/include/linux/list_lru.h b/include/linux/list_lru.h index 2a6b9947aaa3..4534b1b34d2d 100644 --- a/include/linux/list_lru.h +++ b/include/linux/list_lru.h @@ -96,6 +96,19 @@ bool list_lru_add(struct list_lru *lru, struct list_head *item); bool list_lru_del(struct list_lru *lru, struct list_head *item); /** + * list_lru_rotate: rotate an element to the end of an lru list + * @list_lru: the lru pointer + * @item: the item to be rotated + * + * This function moves an entry to the end of an LRU list. Should be used when + * an entry that is on the LRU is used, and should be moved to the MRU end of + * the list. If the item is not on a list, then this function has no effect. + * The comments about an element already pertaining to a list are also valid + * for list_lru_rotate. + */ +void list_lru_rotate(struct list_lru *lru, struct list_head *item); + +/** * list_lru_count_one: return the number of objects currently held by @lru * @lru: the lru pointer. * @nid: the node id to count from. diff --git a/mm/list_lru.c b/mm/list_lru.c index e1da19fac1b3..66718c2a9a7b 100644 --- a/mm/list_lru.c +++ b/mm/list_lru.c @@ -130,6 +130,21 @@ bool list_lru_del(struct list_lru *lru, struct list_head *item) } EXPORT_SYMBOL_GPL(list_lru_del); +void list_lru_rotate(struct list_lru *lru, struct list_head *item) +{ + int nid = page_to_nid(virt_to_page(item)); + struct list_lru_node *nlru = &lru->node[nid]; + struct list_lru_one *l; + + spin_lock(&nlru->lock); + if (!list_empty(item)) { + l = list_lru_from_kmem(nlru, item); + list_move_tail(item, &l->list); + } + spin_unlock(&nlru->lock); +} +EXPORT_SYMBOL_GPL(list_lru_rotate); + void list_lru_isolate(struct list_lru_one *list, struct list_head *item) { list_del_init(item);