Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1243006pxb; Wed, 4 Nov 2020 03:59:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJzBiCGkvrwK3HD6mIvk2Au8zS7UR8aftjyLUt4660kMz3v0yX3clLuQwYVXR8+jL6pz9ZfY X-Received: by 2002:a17:906:f186:: with SMTP id gs6mr1950687ejb.171.1604491155160; Wed, 04 Nov 2020 03:59:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604491155; cv=none; d=google.com; s=arc-20160816; b=CZSOpgUvokPr336wS3+yQ8tGOdafCOtcTiwaY6Ew9a5SBrB16CZYF2X8+vXCb6t1oc vLhLHbr4WGexeTQCyar6Wa3bp/5HAA2tBsNaAtXZirAT5exxIrxOtPgae1RLlMSxjPxg vXlEruj/Xc+BOzDTI/j0Pa8uUmqhpzzQ3wJgbCLfc3ywjUl+U3oQaDqUfP77cwuVC03L vIzgbfXxwv5E5UnaDFv2LXy3ocCffwmMj8YvoTJ35o/hTNkXd4YJWfrBe1UPZ/EkYvmA /JtHuYPS+hBUl7ajBXzJOtaztzvaMFJPJVc3EFy2WhMGVNYE7gDi7aLB6XsYR1it9CPM Ob3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:references:to:from:subject; bh=lfXA2s9KoJQ01Ng+SvQ1o7+jlnGzcTKeTsDuU+m4xWQ=; b=YQu3G6hpjPNa2nuMUj4i4xGU9hy3dQ4ghWySTi+qWsCEQYKL7ubpXgmhM4Yli3ackn aREqkmuATgihf9NY3FFV7zJo0T/G3Cpn5q6ep9TdxXM5V6io06lTy0skIBiyrZRjJ7+S ZdjVJwMwTEmGnIga55Mxabn/SQAfc/ip8t7q05OPPAH+d+Gabn+6uBGpXrm32tU3UNKq R42t9QHAXskgPdU8vDhHnNwxc3aaEeWrExnQmrSIYx7jkehQVNDQlNbTPUmF8Wn15tVR 0e0blM3tCryZLJDir3l3fJM+xly15gqyBBHUrtdY2jIkQglGy+SJ55sR+/crexpPgYl0 jHeQ== ARC-Authentication-Results: i=1; mx.google.com; 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=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z19si1104570edx.461.2020.11.04.03.58.52; Wed, 04 Nov 2020 03:59:15 -0800 (PST) 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; 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=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729438AbgKDL5e (ORCPT + 99 others); Wed, 4 Nov 2020 06:57:34 -0500 Received: from out30-44.freemail.mail.aliyun.com ([115.124.30.44]:40491 "EHLO out30-44.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728841AbgKDLzq (ORCPT ); Wed, 4 Nov 2020 06:55:46 -0500 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R141e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04407;MF=alex.shi@linux.alibaba.com;NM=1;PH=DS;RN=21;SR=0;TI=SMTPD_---0UED0xNV_1604490939; Received: from IT-FVFX43SYHV2H.local(mailfrom:alex.shi@linux.alibaba.com fp:SMTPD_---0UED0xNV_1604490939) by smtp.aliyun-inc.com(127.0.0.1); Wed, 04 Nov 2020 19:55:39 +0800 Subject: Re: [PATCH v20 00/20] per memcg lru lock From: Alex Shi To: akpm@linux-foundation.org, mgorman@techsingularity.net, tj@kernel.org, hughd@google.com, khlebnikov@yandex-team.ru, daniel.m.jordan@oracle.com, willy@infradead.org, hannes@cmpxchg.org, lkp@intel.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, shakeelb@google.com, iamjoonsoo.kim@lge.com, richard.weiyang@gmail.com, kirill@shutemov.name, alexander.duyck@gmail.com, rong.a.chen@intel.com, mhocko@suse.com, vdavydov.dev@gmail.com, shy828301@gmail.com References: <1603968305-8026-1-git-send-email-alex.shi@linux.alibaba.com> Message-ID: <811216d4-4972-4721-d6b9-1028c02f4290@linux.alibaba.com> Date: Wed, 4 Nov 2020 19:55:39 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: <1603968305-8026-1-git-send-email-alex.shi@linux.alibaba.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Johannes & all, Thanks for all comments and suggestions, here is a patch base on v20, as a summary for all you suggested: Is this ok? Many thanks! Alex diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 0c97292834fa..0fe4172c8c14 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -20,6 +20,9 @@ * Lockless page tracking & accounting * Unified hierarchy configuration model * Copyright (C) 2015 Red Hat, Inc., Johannes Weiner + * + * Per memcg lru locking + * Copyright (C) 2020 Alibaba, Inc, Alex Shi */ #include @@ -1380,6 +1383,14 @@ struct lruvec *mem_cgroup_page_lruvec(struct page *page, struct pglist_data *pgd return lruvec; } +/** + * lock_page_lruvec - return lruvec for the locked page. + * @page: the page + * + * This series functions should be used in either conditions: + * PageLRU is cleared or unset + * or, page->_refcount is zero + */ struct lruvec *lock_page_lruvec(struct page *page) { struct lruvec *lruvec; diff --git a/mm/swap.c b/mm/swap.c index 9fe5ff9a8111..bcc814de35c4 100644 --- a/mm/swap.c +++ b/mm/swap.c @@ -264,6 +264,13 @@ void lru_note_cost(struct lruvec *lruvec, bool file, unsigned int nr_pages) do { unsigned long lrusize; + /* + * Hold lruvec->lru_lock is safe here, since + * 1) The pinned lruvec in reclaim, or + * 2) From a pre-LRU page during refault (which also holds the + * rcu lock, so would be safe even if the page was on the LRU + * and could move simultaneously to a new lruvec). + */ spin_lock_irq(&lruvec->lru_lock); /* Record cost event */ if (file) @@ -355,10 +362,12 @@ static void activate_page(struct page *page) struct lruvec *lruvec; page = compound_head(page); - lruvec = lock_page_lruvec_irq(page); - if (PageLRU(page)) + if (TestClearPageLRU(page)) { + lruvec = lock_page_lruvec_irq(page); __activate_page(page, lruvec); - unlock_page_lruvec_irq(lruvec); + unlock_page_lruvec_irq(lruvec); + SetPageLRU(page); + } } #endif diff --git a/mm/vmscan.c b/mm/vmscan.c index 7ed10ade548d..af03a7f2e1b8 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1868,6 +1868,10 @@ static unsigned noinline_for_stack move_pages_to_lru(struct lruvec *lruvec, 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); lru = page_lru(page); nr_pages = thp_nr_pages(page);