From patchwork Tue Jul 3 14:52:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 10504239 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1D6526035E for ; Tue, 3 Jul 2018 14:53:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0AD4B28C5D for ; Tue, 3 Jul 2018 14:53:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F29D928C6C; Tue, 3 Jul 2018 14:53:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6AA4628C5E for ; Tue, 3 Jul 2018 14:53:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 65C526B000E; Tue, 3 Jul 2018 10:52:57 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 5E2E66B0010; Tue, 3 Jul 2018 10:52:57 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 45C316B0266; Tue, 3 Jul 2018 10:52:57 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wm0-f71.google.com (mail-wm0-f71.google.com [74.125.82.71]) by kanga.kvack.org (Postfix) with ESMTP id E08886B000E for ; Tue, 3 Jul 2018 10:52:56 -0400 (EDT) Received: by mail-wm0-f71.google.com with SMTP id w21-v6so960324wmc.4 for ; Tue, 03 Jul 2018 07:52:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=+nVyWDtdKp2iA7nOKST8Mqi+lf6yi6YgDsFZX7IhpSo=; b=Y7xjjTAIblr1SPxtcOIR9ymVbWoEiJfsnsrEuf0mrwuZAEIednJNlOHFsZq6/cZ5+8 m6DdYv1+t0tRz651r9L4YCO3SW+/zVKFMsyKbNKaSz0tY2aFC1BW8Iuc1qOdh4qt28XX OlxAiSYKC4U0yWJx/9km5qVKS+AE9xmz/4Cvbjq8QQoz+4bFhjcOK6v7U9DtJK7PIVVN 7jGvW/FlSFaMABgUb85iuuaku65nA/lDHODenZwU9o0IqdjM+jR3Ecw5TSVNVwWcNfRG 3qCOuetldQSti7fi6p5Gku4vX7HDmeeIUYdFklei+9TUSNcrxtj3538AnIhth0U3teTO zvIg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bigeasy@linutronix.de designates 2a01:7a0:2:106d:700::1 as permitted sender) smtp.mailfrom=bigeasy@linutronix.de X-Gm-Message-State: APt69E2NoS+q240gK+omuvlKU4pb8HJuoAXStrVv0yP+QkCcmdtjH4NM rSQ16r7pYpoB1pSOOKkaPZfC+kpCTlm4eEa78V9w7bcg9eRLW51TrsirzFcjXoTC2f1Fj7W0F4y cX/ROTZzKE99a8aIkS2Px8ehCjY/vLbzWZgF5eh8UHXdhYtIw7yzkCpvnAOH5IrxieQ== X-Received: by 2002:a1c:1c52:: with SMTP id c79-v6mr4357328wmc.147.1530629576413; Tue, 03 Jul 2018 07:52:56 -0700 (PDT) X-Google-Smtp-Source: AAOMgpegs0Xq8yuWcJcLh1wpLadYtmnSqDumTJapwHo/ReJKychoAIdYfz3dMviC1v2Gi+qXCfGN X-Received: by 2002:a1c:1c52:: with SMTP id c79-v6mr4357251wmc.147.1530629574432; Tue, 03 Jul 2018 07:52:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530629574; cv=none; d=google.com; s=arc-20160816; b=P1sfqIF8lBtSVcK2qd+vDgXBl88PaCciN0HNNvxmaMfn4JLEO8caxf0/1zTUZgfTbl aeKx7Y7M1QnQ3WWzNWnWO9KCKWFVtP6NgJ/aqc9NlPeH0/BeG3HegMBhGlqdZayT5o0K p95AFbaRuXAHYGxj8WD/PlP04cWgbPHg2/q79CA8xB5gTkT5yuQbXGF3ncJ7CPPTKmL0 0nldEZJE6AAeFIr/UM5MfVwyeAs8qqk9pKsceF5heKLN1BHe4gG5mnWux6Oc3yD1yQkU cHCDbrzOjU6Aoebe3IYzqRDDcfTnVF3We4RCzpIf/L/Eug3uWzsDmXWQfrhJr3dU3aAy QqNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=+nVyWDtdKp2iA7nOKST8Mqi+lf6yi6YgDsFZX7IhpSo=; b=pfngLUVJjKa4R2ULRDGu+wLcvubjMlm9LbiTSEcBVnYyRxvcC1677jfYM/zFImjqU0 2e9XIHOtcmtV9dA+0Mjmgm7txnRE7HK+aEOOrR0Wj8VB+1nTSlehV67Gz3jTCXyjlFwa FOWMgxSkR3vk4aXrsRxMnbg6qy5QfNb2MG/TxU76/9Qo1oMGgoNV6pK7D6BVo3lcsSUY BFWQH02SxdOMxngOPiPWQi1Uga5JkEIl4b/ap+Yc7UcsjmEBoO5cuFQH6TbpA766pQBt kWWlYyvORxUI1czfYD6X+FQIzoCau71ihoWqmOXFZtPX0HH4vhKUEMFEEmmXcT7A+/aa Iq7Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of bigeasy@linutronix.de designates 2a01:7a0:2:106d:700::1 as permitted sender) smtp.mailfrom=bigeasy@linutronix.de Received: from Galois.linutronix.de (Galois.linutronix.de. [2a01:7a0:2:106d:700::1]) by mx.google.com with ESMTPS id n18-v6si1123241wrh.315.2018.07.03.07.52.54 for (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 03 Jul 2018 07:52:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of bigeasy@linutronix.de designates 2a01:7a0:2:106d:700::1 as permitted sender) client-ip=2a01:7a0:2:106d:700::1; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bigeasy@linutronix.de designates 2a01:7a0:2:106d:700::1 as permitted sender) smtp.mailfrom=bigeasy@linutronix.de Received: from localhost ([127.0.0.1] helo=bazinga.breakpoint.cc) by Galois.linutronix.de with esmtp (Exim 4.80) (envelope-from ) id 1faMfk-000384-Vq; Tue, 03 Jul 2018 16:52:53 +0200 From: Sebastian Andrzej Siewior To: Vladimir Davydov Cc: linux-mm@kvack.org, tglx@linutronix.de, Andrew Morton , Sebastian Andrzej Siewior Subject: [PATCH 4/4] mm/list_lru: Introduce list_lru_shrink_walk_irq() Date: Tue, 3 Jul 2018 16:52:35 +0200 Message-Id: <20180703145235.28050-5-bigeasy@linutronix.de> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180703145235.28050-1-bigeasy@linutronix.de> References: <20180624200907.ufjxk6l2biz6xcm2@esperanza> <20180703145235.28050-1-bigeasy@linutronix.de> Reply-To: "[PATCH 0/4]"@kvack.org, "mm/list_lru:add"@kvack.org, list_lru_shrink_walk_irq@kvack.org, and@kvack.org (), use@kvack.org, it@kvack.org MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Provide list_lru_shrink_walk_irq() and let it behave like list_lru_walk_one() except that it locks the spinlock with spin_lock_irq(). This is used by scan_shadow_nodes() because its lock nests within the i_pages lock which is acquired with IRQ. This change allows to use proper locking promitives instead hand crafted lock_irq_disable() plus spin_lock(). There is no EXPORT_SYMBOL provided because the current user is in-KERNEL only. Add list_lru_shrink_walk_irq() which acquires the spinlock with the proper locking primitives. Signed-off-by: Sebastian Andrzej Siewior --- include/linux/list_lru.h | 25 +++++++++++++++++++++++++ mm/list_lru.c | 15 +++++++++++++++ mm/workingset.c | 8 ++------ 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/include/linux/list_lru.h b/include/linux/list_lru.h index 96def9d15b1b..798c41743657 100644 --- a/include/linux/list_lru.h +++ b/include/linux/list_lru.h @@ -162,6 +162,23 @@ unsigned long list_lru_walk_one(struct list_lru *lru, int nid, struct mem_cgroup *memcg, list_lru_walk_cb isolate, void *cb_arg, unsigned long *nr_to_walk); +/** + * list_lru_walk_one_irq: walk a list_lru, isolating and disposing freeable items. + * @lru: the lru pointer. + * @nid: the node id to scan from. + * @memcg: the cgroup to scan from. + * @isolate: callback function that is resposible for deciding what to do with + * the item currently being scanned + * @cb_arg: opaque type that will be passed to @isolate + * @nr_to_walk: how many items to scan. + * + * Same as @list_lru_walk_one except that the spinlock is acquired with + * spin_lock_irq(). + */ +unsigned long list_lru_walk_one_irq(struct list_lru *lru, + int nid, struct mem_cgroup *memcg, + list_lru_walk_cb isolate, void *cb_arg, + unsigned long *nr_to_walk); 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); @@ -174,6 +191,14 @@ list_lru_shrink_walk(struct list_lru *lru, struct shrink_control *sc, &sc->nr_to_scan); } +static inline unsigned long +list_lru_shrink_walk_irq(struct list_lru *lru, struct shrink_control *sc, + list_lru_walk_cb isolate, void *cb_arg) +{ + return list_lru_walk_one_irq(lru, sc->nid, sc->memcg, isolate, cb_arg, + &sc->nr_to_scan); +} + static inline 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/mm/list_lru.c b/mm/list_lru.c index 4d7f981e6144..1bf53a08cda8 100644 --- a/mm/list_lru.c +++ b/mm/list_lru.c @@ -267,6 +267,21 @@ list_lru_walk_one(struct list_lru *lru, int nid, struct mem_cgroup *memcg, } EXPORT_SYMBOL_GPL(list_lru_walk_one); +unsigned long +list_lru_walk_one_irq(struct list_lru *lru, int nid, struct mem_cgroup *memcg, + list_lru_walk_cb isolate, void *cb_arg, + unsigned long *nr_to_walk) +{ + struct list_lru_node *nlru = &lru->node[nid]; + unsigned long ret; + + spin_lock_irq(&nlru->lock); + ret = __list_lru_walk_one(nlru, memcg_cache_id(memcg), isolate, cb_arg, + nr_to_walk); + spin_unlock_irq(&nlru->lock); + return ret; +} + 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) diff --git a/mm/workingset.c b/mm/workingset.c index 529480c21f93..aa75c0027079 100644 --- a/mm/workingset.c +++ b/mm/workingset.c @@ -480,13 +480,9 @@ static enum lru_status shadow_lru_isolate(struct list_head *item, static unsigned long scan_shadow_nodes(struct shrinker *shrinker, struct shrink_control *sc) { - unsigned long ret; - /* list_lru lock nests inside the IRQ-safe i_pages lock */ - local_irq_disable(); - ret = list_lru_shrink_walk(&shadow_nodes, sc, shadow_lru_isolate, NULL); - local_irq_enable(); - return ret; + return list_lru_shrink_walk_irq(&shadow_nodes, sc, shadow_lru_isolate, + NULL); } static struct shrinker workingset_shadow_shrinker = {