Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp7277977ybl; Wed, 15 Jan 2020 19:23:47 -0800 (PST) X-Google-Smtp-Source: APXvYqxdP8zvCB1D6JFGbgZ9iO8iuq1AB5QxBFzB5GuWgIvXwML2hbgasBg3RTs3fR2e/Y6li18V X-Received: by 2002:a05:6830:1047:: with SMTP id b7mr418713otp.77.1579145026916; Wed, 15 Jan 2020 19:23:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579145026; cv=none; d=google.com; s=arc-20160816; b=aq6ToS4x/mzicI1Vj68kC0WQItzqIYIPIKBOv4jOc6fq96uWP7Z1/Fn1BJ5Q29meJ+ FBIANU+tvjsiy9X08s5WjI4n5tYVdpbxlTR/9A4GGFJlZ5kewasdCUW9Zcz2mJ0eLcEQ jPaAAJCuiCCG81O8+qKC0jqK5k0mofemrTBIMYzPcrigeKEVO6arm8AFVGWIDX2b7tpx tzZ1sHX1Dk+Fn5wZxxmfvPJgYamexCK6LAEN+dBA0B4LFYla9utOlk7z1/o+eFYoDsfp ztTX8CWtgXMOxsAXRM+O2nkWRcdPz3OY8uPR+317sXOKgBQJHKL0D3kFdao1XLbMBH4Y J/zA== 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:cc:to:from; bh=+RP43hHeBBeLBF/S/t3U27MlgKUlRmyp97Wp7vxBz0Y=; b=fH9rtNRamQNRGqCRYtcF4Zz4obOWLZW2o00MxpJ2SDfYPpjfwddzCNy5x3LXzS2laS q0RfnS84+6Hj5v0x3RImpvWoc1NniEjlY+pJgYshEjkDPT14KwNwEg513m/9m82GdQJ8 YIffVnymffZUF8ukWL9filsNeEZqxaCr66lYhObJ28UzN9K821DCjuqPhH3qGu/6zJhN NcGCC+LWvHXhuKI6cb+DkXMecJnTkenbhy1JKsNksUt1KfBFrLD4Mg6hMTsU47B/O/i3 TJEW9RrQdMsm7rvDhPXXhjNQYNrwJiLc32ZEL/ZZ1UYgfpMkuzTClW7FvhMEFCIyKb4R /NJA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id d17si10900867oib.174.2020.01.15.19.23.34; Wed, 15 Jan 2020 19:23:46 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1729224AbgAPDFx (ORCPT + 99 others); Wed, 15 Jan 2020 22:05:53 -0500 Received: from out30-54.freemail.mail.aliyun.com ([115.124.30.54]:39356 "EHLO out30-54.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730343AbgAPDFO (ORCPT ); Wed, 15 Jan 2020 22:05:14 -0500 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R111e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01f04446;MF=alex.shi@linux.alibaba.com;NM=1;PH=DS;RN=14;SR=0;TI=SMTPD_---0TnrJfUT_1579143911; Received: from localhost(mailfrom:alex.shi@linux.alibaba.com fp:SMTPD_---0TnrJfUT_1579143911) by smtp.aliyun-inc.com(127.0.0.1); Thu, 16 Jan 2020 11:05:11 +0800 From: Alex Shi To: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, 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, shakeelb@google.com, hannes@cmpxchg.org Cc: yun.wang@linux.alibaba.com Subject: [PATCH v8 01/10] mm/vmscan: remove unnecessary lruvec adding Date: Thu, 16 Jan 2020 11:05:00 +0800 Message-Id: <1579143909-156105-2-git-send-email-alex.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1579143909-156105-1-git-send-email-alex.shi@linux.alibaba.com> References: <1579143909-156105-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 Signed-off-by: Alex Shi Cc: Andrew Morton Cc: Johannes Weiner Cc: Hugh Dickins Cc: yun.wang@linux.alibaba.com Cc: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org --- mm/vmscan.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 572fb17c6273..a270d32bdb94 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1852,26 +1852,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); @@ -1879,9 +1882,16 @@ 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; + 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; } /* -- 1.8.3.1