From patchwork Mon Jul 16 11:19:21 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: 10526491 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 F38C0601D2 for ; Mon, 16 Jul 2018 11:19:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E5F9C28A52 for ; Mon, 16 Jul 2018 11:19:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D9E2428A56; Mon, 16 Jul 2018 11:19:44 +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 61A3A28A52 for ; Mon, 16 Jul 2018 11:19:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 71BD46B026C; Mon, 16 Jul 2018 07:19:36 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 69FDD6B026E; Mon, 16 Jul 2018 07:19:36 -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 42C556B026D; Mon, 16 Jul 2018 07:19:36 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by kanga.kvack.org (Postfix) with ESMTP id DAAC76B026A for ; Mon, 16 Jul 2018 07:19:35 -0400 (EDT) Received: by mail-wr1-f72.google.com with SMTP id r4-v6so8593744wrt.2 for ; Mon, 16 Jul 2018 04:19:35 -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:mime-version :content-transfer-encoding; bh=Oy+G1blhWbckcv+5TcRJrE82mCBBv7OgGLBoYCdDc2s=; b=bH2wtjCnlEUq7ScfHlfmdgpXUN5D+4EY0k9UUHt63Thg1eEwHLYUgeWMVTZoKz0JOq ry1DTwFIHVadta8LGjLUg0ldKVXLLOfA6QIYqyul/EdZK/z2ewV37TyCFLzm4eD9ehPu 9j3Hm/i8A1hO0wHd6M3b2Veqc7UZPjKNJoAsIzfpfCBmKRlSbhBjCA0MhniEjQBBCuLe hpilbkWISYYzQ69N+A7ieI+E62+b8jMvXU5dMK7cD4V02+J8R9f96RzvZFhG9qYBH+2/ bv7TJEC204Nny0cENzR6SFOMkUqOIb8ujRyRfWOBTdXVPnVqKLovJ0JMQTTpb5+3rkXO I5GA== 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: AOUpUlGFM/tyURLfLZCGcf66b6lk4OTQLyMg1Xz9/iTy5tuvwEnUmq0/ bEVX0YABHC1k/rdEi/LO+MCG1I3rdAVqrgaEnkK1lz0qnUO4Iv18kR0nwJeWRAdAN/TCg2U+PyF bio6g2LwluxbVffCDN81EnMMfpkltq7KWdikL7NCDIjFc3pkAJ/u75Uaqfl1h0Xha9Q== X-Received: by 2002:adf:ad45:: with SMTP id p63-v6mr11406737wrc.222.1531739975464; Mon, 16 Jul 2018 04:19:35 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcjm5zFFoJkE/z25+2apmrKFApmbuMAXyjmJMzfqNO5pKH65ojZE4hsVB2FUcNxTKfE40HK X-Received: by 2002:adf:ad45:: with SMTP id p63-v6mr11406703wrc.222.1531739974707; Mon, 16 Jul 2018 04:19:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531739974; cv=none; d=google.com; s=arc-20160816; b=DcC0WbJ34LuVe4D9b2UghxNORyd6mKTJ86l7+mZrEisT+ZI3h3JYmyxJq0f59CCpgv yugrtYJS6DQTajG6aqimNsNcY2VdGLpd3mayZDsTmaGLGiCjBs8otc1PdvEcYYiMcB0e uNHIEBnxwiG3rxPRyBh7NwSGUaiqMOJFnS6RsJIO7/70tNKUMBFJcYsh89HWpSBYEHot EInYqOZ7I+rd4YJQ5ADMIwvzNraS2nUNle2ED+SgM7UQXBTQBTqbbH4A6yqRLn2WAWBP 5QR09paoCcF8IsX7RhyEijkSuTlTWEC1rjekXz7nKZsdxSBrs6O9nJeHpHaPhWCMTy35 OOqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=Oy+G1blhWbckcv+5TcRJrE82mCBBv7OgGLBoYCdDc2s=; b=AlgCQ5zl6hUDcWt/chtHtl7fqRMl88EB/GXYM4Lbd+rnyF9AakFgGeOrWLLGqKFqy5 RToo2iK9a2lbMMqZWpaYggzb/2wgRH8ZBLOy/7sSIBebgQyiCgpJ7LUemEU9hDFHDt1e S7pmv4yhnAakVyNP32OKKgdyzKI32vnZ8x9++ydKRR/tiY+/QySKXZL0MqRAxNhMnTIM doA3A+qSM/GyWgCaeoK76P96o7Pqda8kh9TGB7BB/6whDwmQyi0BUqq7ZqPSedET3O11 bkWbM4CpobMzp9Xj11/QQ+TsBY/8+FlaItzQSb1kj+dPJo/6Dpz/gDKwt0GvDtfvGMQe eqLw== 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 m10-v6si27929387wrm.287.2018.07.16.04.19.34 for (version=TLS1_2 cipher=AES128-SHA bits=128/128); Mon, 16 Jul 2018 04:19:34 -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 1ff1XQ-0003CQ-AK; Mon, 16 Jul 2018 13:19:32 +0200 From: Sebastian Andrzej Siewior To: linux-mm@kvack.org Cc: tglx@linutronix.de, Vladimir Davydov , Andrew Morton , Sebastian Andrzej Siewior Subject: [PATCH 4/4] mm/list_lru: Introduce list_lru_shrink_walk_irq() Date: Mon, 16 Jul 2018 13:19:21 +0200 Message-Id: <20180716111921.5365-5-bigeasy@linutronix.de> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180716111921.5365-1-bigeasy@linutronix.de> References: <20180716111921.5365-1-bigeasy@linutronix.de> 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. Reviewed-by: Vladimir Davydov 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 d9c16f2f2f00..aa5efd9351eb 100644 --- a/include/linux/list_lru.h +++ b/include/linux/list_lru.h @@ -166,6 +166,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); @@ -178,6 +195,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 7b7a737f0963..89349a0276de 100644 --- a/mm/list_lru.c +++ b/mm/list_lru.c @@ -289,6 +289,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 06b45147e892..0b4f471d07ba 100644 --- a/mm/workingset.c +++ b/mm/workingset.c @@ -501,13 +501,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 = {