Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp2929044ybh; Sat, 25 Jul 2020 06:03:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz7iOrwCEmwcXcJ3YpVBbbLTSVb4DmqdRD6sAX3xPSwTBGpPhSn9Fx4pBYn+4o8uMuAJ4pt X-Received: by 2002:a05:6402:3058:: with SMTP id bu24mr13149216edb.242.1595682183810; Sat, 25 Jul 2020 06:03:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595682183; cv=none; d=google.com; s=arc-20160816; b=QUEHHEa/OOkXKex5g6aFmhOY0tRcNJsKe0KwffP8CSezCZ1Fi0M/xPUM5BjtPd6iHY pGupEF4UF23BpNeobDD3RbSLQble8mvZSAjrS1p7kmEbypx5zkMW7yQ8HkSTaUAdDOFx zh1/LOKIxGS0B4HiYN/2Z3NyyUTtcdVMHwGvMA3k9E5Od3OSJi85hse0d91XLPjKJNm0 eu0vQCuUc8hCTjSlWb8Esq2/HnPp8FeBfGFDOvNF8BNo4JFAoy4h+UUPw9HONP18Gjhn MpLmaI+qWCN9UIJsRcCOce5Y+fkDbTyo1TS3ywI7nrGVpkWeXIohfBxctBdtCDEddGX1 jg5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:to:from; bh=f+Xqzz/KcISm75BPDh12sKqLz528/7+GQVCh/Y/ul80=; b=KKOSNMLN8dmJ3I/EUd4/2n8x/CjicV/0pVwOeAYMbpyesQnYS+u3KUlcRLTUcbk2Ql JvdRK62GCs2ZtaMzHwFCyZ0zZjidPSoguV94tL5EaStn2WbU5jrHQSTR9OTkf97lhh5j yBj5sLZX4kwPxyHEyPFqfJUSmutLBPaQnbL+ZXaCZlybSAnjpQyxpwSe88Ef/+NSWWF+ qllQYsGCX69jZ3hsPW2IE3mjBQbpAxEAoFyOXfYoEcDP+Le4myL8kOhrnFvX+3VQJ9+B oqsp34jrKKkGSSxGBLhxe7hmzFmTYl06U/4FTV0cEjHWwSBd7gi8t8yctsQqAjPwatvQ CHBA== 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 dn12si2962733ejc.24.2020.07.25.06.02.41; Sat, 25 Jul 2020 06:03:03 -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; 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 S1727097AbgGYNA3 (ORCPT + 99 others); Sat, 25 Jul 2020 09:00:29 -0400 Received: from out30-132.freemail.mail.aliyun.com ([115.124.30.132]:46146 "EHLO out30-132.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726618AbgGYNA1 (ORCPT ); Sat, 25 Jul 2020 09:00:27 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R161e4;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=19;SR=0;TI=SMTPD_---0U3l6fmD_1595682015; Received: from aliy8.localdomain(mailfrom:alex.shi@linux.alibaba.com fp:SMTPD_---0U3l6fmD_1595682015) by smtp.aliyun-inc.com(127.0.0.1); Sat, 25 Jul 2020 21:00:20 +0800 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, yang.shi@linux.alibaba.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 Subject: [PATCH v17 01/21] mm/vmscan: remove unnecessary lruvec adding Date: Sat, 25 Jul 2020 20:59:38 +0800 Message-Id: <1595681998-19193-2-git-send-email-alex.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1595681998-19193-1-git-send-email-alex.shi@linux.alibaba.com> References: <1595681998-19193-1-git-send-email-alex.shi@linux.alibaba.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We don't have to add a freeable page into lru and then remove from it. This change saves a couple of actions and makes the moving more clear. The SetPageLRU needs to be kept here for list intergrity. Otherwise: #0 mave_pages_to_lru #1 release_pages if (put_page_testzero()) if !put_page_testzero !PageLRU //skip lru_lock list_add(&page->lru,) list_add(&page->lru,) //corrupt [akpm@linux-foundation.org: coding style fixes] Signed-off-by: Alex Shi Cc: Andrew Morton Cc: Johannes Weiner Cc: Tejun Heo Cc: Matthew Wilcox Cc: Hugh Dickins Cc: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org --- mm/vmscan.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 749d239c62b2..ddb29d813d77 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1856,26 +1856,29 @@ static unsigned noinline_for_stack move_pages_to_lru(struct lruvec *lruvec, while (!list_empty(list)) { page = lru_to_page(list); VM_BUG_ON_PAGE(PageLRU(page), page); + list_del(&page->lru); if (unlikely(!page_evictable(page))) { - list_del(&page->lru); spin_unlock_irq(&pgdat->lru_lock); putback_lru_page(page); spin_lock_irq(&pgdat->lru_lock); continue; } - lruvec = mem_cgroup_page_lruvec(page, pgdat); + /* + * The SetPageLRU needs to be kept here for list intergrity. + * Otherwise: + * #0 mave_pages_to_lru #1 release_pages + * if (put_page_testzero()) + * if !put_page_testzero + * !PageLRU //skip lru_lock + * list_add(&page->lru,) + * list_add(&page->lru,) //corrupt + */ SetPageLRU(page); - lru = page_lru(page); - nr_pages = hpage_nr_pages(page); - update_lru_size(lruvec, lru, page_zonenum(page), nr_pages); - list_move(&page->lru, &lruvec->lists[lru]); - - if (put_page_testzero(page)) { + if (unlikely(put_page_testzero(page))) { __ClearPageLRU(page); __ClearPageActive(page); - del_page_from_lru_list(page, lruvec, lru); if (unlikely(PageCompound(page))) { spin_unlock_irq(&pgdat->lru_lock); @@ -1883,11 +1886,19 @@ static unsigned noinline_for_stack move_pages_to_lru(struct lruvec *lruvec, spin_lock_irq(&pgdat->lru_lock); } else list_add(&page->lru, &pages_to_free); - } else { - nr_moved += nr_pages; - if (PageActive(page)) - workingset_age_nonresident(lruvec, nr_pages); + + continue; } + + lruvec = mem_cgroup_page_lruvec(page, pgdat); + lru = page_lru(page); + nr_pages = hpage_nr_pages(page); + + update_lru_size(lruvec, lru, page_zonenum(page), nr_pages); + list_add(&page->lru, &lruvec->lists[lru]); + nr_moved += nr_pages; + if (PageActive(page)) + workingset_age_nonresident(lruvec, nr_pages); } /* -- 1.8.3.1