Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1311956pxf; Fri, 9 Apr 2021 05:34:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzEEkeJCT3YqTWRm92NUntewriB1cpdI6Z7Nn54lwV/FiQV06u1u5GjuYw5lxHss0dhyCcf X-Received: by 2002:a63:f959:: with SMTP id q25mr13445682pgk.104.1617971654847; Fri, 09 Apr 2021 05:34:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617971654; cv=none; d=google.com; s=arc-20160816; b=jWlaMgoEuwdVwICEy1j6vc1DImRhgfwMwAT/8YlvMKIIoLp2VIuOMvagBSRByt5EQ4 NgmFKEuwAwHcC7pp9mPi4msMfD4U4b3xpByTUnqIctQeFOLQhmbIbFfFVQ0hKTapRiP+ +jwzedcZ3eYbiT0heQCc6mG5F1CjASqf1OFZiZgobfaYvGCs1o0LtiSFRvqobzNJf5e+ Jz536wEz8qr6jU5TXKf2log2UHPRA0nLZfXKGHfJlfvjOAx7lobtJIw/VdZAes7zS8KQ 8TWKrGjUzkV/ywjgS4nBirP+6gZp0YfQ9ufe8RuKXAwn7M9v2AWqD+hX+9Qu+e/skFvY Z42Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1fMqyM142M/rLjd886U1IMp5j4aF6dHNuuaPr8ObPdI=; b=WruHu+AxzvnzefMmm0VocgNw00TAfroPINLU+6Z47n6kZFfjxF0aID9XGd3gkkjbFV jbUpDVESBvt69FkARSATFCcc2iiFJp2F3pA5A6jiOuh8JRn3w4mRT6F1tR9rXoVHEkij l1fJVPOKx56taJUA1m2i7HZe5Ng/kxE5pFPw5cTWS+nbdrIEFyCn73+9JQmUOQHiwaDN QcqLH/1WukF3wNiByaNC5HM7m1e2bvxk/1QyXAAxCwCzHfGEXQOGzxhNGGB4LDEN5yvA ljWm8hAXo3xvkFqXGB6ZsDZsOjyNk8m53cXmnam/UORvqM983y1y62febnmWh1KZ3R98 9dVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=cQRyKiiK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d2si2868546pll.397.2021.04.09.05.34.03; Fri, 09 Apr 2021 05:34:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=cQRyKiiK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233774AbhDIMdJ (ORCPT + 99 others); Fri, 9 Apr 2021 08:33:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233706AbhDIMdE (ORCPT ); Fri, 9 Apr 2021 08:33:04 -0400 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2C42C061760 for ; Fri, 9 Apr 2021 05:32:50 -0700 (PDT) Received: by mail-pf1-x434.google.com with SMTP id y16so4138164pfc.5 for ; Fri, 09 Apr 2021 05:32:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1fMqyM142M/rLjd886U1IMp5j4aF6dHNuuaPr8ObPdI=; b=cQRyKiiKv4re6AmVdBzMfeckX6oHDJ8D7744bldCAKrRVgwddNhkYd9AeIdoDh06vy YrxFGz36GyHjdH740eUq03OlBfnWXq7wXGu0nWVNwpoFZc/DPH5v105jBfVtezgeA76i 2k6wx6pYY6tgLQwfzD3VUuyf9WRqjqtrjUhQhBfzZCX2XlUtbqD5SClktTezO2DguX5i FWgrLhA1CBlemaJk3Cu28VUfSvgfIezAuVUFwefwSXmLniEUhiaJ1DGYXmdnyjK3i0OM tqRXQ+tlp3fuzIllEyJ3srl9PO+cdXBS29bsYNiG0+uELvV7N+mfU6jTHVB5XiKeLTO+ H33w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1fMqyM142M/rLjd886U1IMp5j4aF6dHNuuaPr8ObPdI=; b=PiSnGczPwG/rQd6/P9FYaPo0jLd393I0SEcvuO7uiZSNLQaiwqmFLbng++At+r1Te0 G56QJETWpFEX412TjdUMyyF9GpoGSfbUXYCfVRYVpwWRl2F6dFiD/9mRnbxigUdtrWq8 kODaL4yF/iXeLbB6nrbU7Z8EyhAKNgXzGm4wPDN4efXZmgM3Eg7YhXrETPvoTgCixhF+ BhIkzdCN6ylctxywGOk7lcv5oUUj2bJtTtL0qwv812dEtJmA8BFKxzY6m8oCn7Xuixbq OXFO9F0EE3P+Ioe1wFqCZFigxnYHqAu4oJszskmqZShFaRf9hwMjMPW12JdiZk7a09ty EbJg== X-Gm-Message-State: AOAM5320zZjSqDoZ3wAtINAzm4P08sYIK0zwMyXvw66biEPVpYmWmFHj csHqxyEj9tXlnOeK+U2m+3bOrA== X-Received: by 2002:a62:7ccb:0:b029:247:2b6b:f42 with SMTP id x194-20020a627ccb0000b02902472b6b0f42mr2383323pfc.68.1617971570163; Fri, 09 Apr 2021 05:32:50 -0700 (PDT) Received: from localhost.localdomain ([139.177.225.243]) by smtp.gmail.com with ESMTPSA id t3sm2167785pfg.176.2021.04.09.05.32.45 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Apr 2021 05:32:49 -0700 (PDT) From: Muchun Song To: guro@fb.com, hannes@cmpxchg.org, mhocko@kernel.org, akpm@linux-foundation.org, shakeelb@google.com, vdavydov.dev@gmail.com Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, duanxiongchun@bytedance.com, fam.zheng@bytedance.com, bsingharora@gmail.com, shy828301@gmail.com, alex.shi@linux.alibaba.com, Muchun Song Subject: [RFC PATCH v2 10/18] mm: vmscan: rework move_pages_to_lru() Date: Fri, 9 Apr 2021 20:29:51 +0800 Message-Id: <20210409122959.82264-11-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20210409122959.82264-1-songmuchun@bytedance.com> References: <20210409122959.82264-1-songmuchun@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In the later patch, we will reparent the LRU pages. The pages which will move to appropriate LRU list can be reparented during the process of the move_pages_to_lru(). So holding a lruvec lock by the caller is wrong, we should use the more general interface of relock_page_lruvec_irq() to acquire the correct lruvec lock. Signed-off-by: Muchun Song --- mm/vmscan.c | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index e40b21298d77..4431007825ad 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -2013,23 +2013,27 @@ static int too_many_isolated(struct pglist_data *pgdat, int file, * move_pages_to_lru() moves pages from private @list to appropriate LRU list. * On return, @list is reused as a list of pages to be freed by the caller. * - * Returns the number of pages moved to the given lruvec. + * Returns the number of pages moved to the appropriate LRU list. + * + * Note: The caller must not hold any lruvec lock. */ -static unsigned int move_pages_to_lru(struct lruvec *lruvec, - struct list_head *list) +static unsigned int move_pages_to_lru(struct list_head *list) { - int nr_pages, nr_moved = 0; + int nr_moved = 0; + struct lruvec *lruvec = NULL; LIST_HEAD(pages_to_free); - struct page *page; while (!list_empty(list)) { - page = lru_to_page(list); + int nr_pages; + struct page *page = lru_to_page(list); + + lruvec = relock_page_lruvec_irq(page, lruvec); VM_BUG_ON_PAGE(PageLRU(page), page); list_del(&page->lru); if (unlikely(!page_evictable(page))) { - spin_unlock_irq(&lruvec->lru_lock); + unlock_page_lruvec_irq(lruvec); putback_lru_page(page); - spin_lock_irq(&lruvec->lru_lock); + lruvec = NULL; continue; } @@ -2050,19 +2054,15 @@ static unsigned int move_pages_to_lru(struct lruvec *lruvec, __clear_page_lru_flags(page); if (unlikely(PageCompound(page))) { - spin_unlock_irq(&lruvec->lru_lock); + unlock_page_lruvec_irq(lruvec); destroy_compound_page(page); - spin_lock_irq(&lruvec->lru_lock); + lruvec = NULL; } else list_add(&page->lru, &pages_to_free); continue; } - /* - * All pages were isolated from the same lruvec (and isolation - * inhibits memcg migration). - */ VM_BUG_ON_PAGE(!lruvec_holds_page_lru_lock(page, lruvec), page); add_page_to_lru_list(page, lruvec); nr_pages = thp_nr_pages(page); @@ -2071,6 +2071,8 @@ static unsigned int move_pages_to_lru(struct lruvec *lruvec, workingset_age_nonresident(lruvec, nr_pages); } + if (lruvec) + unlock_page_lruvec_irq(lruvec); /* * To save our caller's stack, now use input list for pages to free. */ @@ -2144,16 +2146,16 @@ shrink_inactive_list(unsigned long nr_to_scan, struct lruvec *lruvec, nr_reclaimed = shrink_page_list(&page_list, pgdat, sc, &stat, false); - spin_lock_irq(&lruvec->lru_lock); - move_pages_to_lru(lruvec, &page_list); + move_pages_to_lru(&page_list); + local_irq_disable(); __mod_node_page_state(pgdat, NR_ISOLATED_ANON + file, -nr_taken); item = current_is_kswapd() ? PGSTEAL_KSWAPD : PGSTEAL_DIRECT; if (!cgroup_reclaim(sc)) __count_vm_events(item, nr_reclaimed); __count_memcg_events(lruvec_memcg(lruvec), item, nr_reclaimed); __count_vm_events(PGSTEAL_ANON + file, nr_reclaimed); - spin_unlock_irq(&lruvec->lru_lock); + local_irq_enable(); lru_note_cost(lruvec, file, stat.nr_pageout); mem_cgroup_uncharge_list(&page_list); @@ -2280,18 +2282,16 @@ static void shrink_active_list(unsigned long nr_to_scan, /* * Move pages back to the lru list. */ - spin_lock_irq(&lruvec->lru_lock); - - nr_activate = move_pages_to_lru(lruvec, &l_active); - nr_deactivate = move_pages_to_lru(lruvec, &l_inactive); + nr_activate = move_pages_to_lru(&l_active); + nr_deactivate = move_pages_to_lru(&l_inactive); /* Keep all free pages in l_active list */ list_splice(&l_inactive, &l_active); + local_irq_disable(); __count_vm_events(PGDEACTIVATE, nr_deactivate); __count_memcg_events(lruvec_memcg(lruvec), PGDEACTIVATE, nr_deactivate); - __mod_node_page_state(pgdat, NR_ISOLATED_ANON + file, -nr_taken); - spin_unlock_irq(&lruvec->lru_lock); + local_irq_enable(); mem_cgroup_uncharge_list(&l_active); free_unref_page_list(&l_active); -- 2.11.0