Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp2593591ybz; Mon, 27 Apr 2020 00:06:36 -0700 (PDT) X-Google-Smtp-Source: APiQypKWypgnue4+R870rMn0fTcBXnerZAAX05zua1UbEWkJe2E1e/0irRNkhj0GIMYC3R8df0Nj X-Received: by 2002:aa7:c3d3:: with SMTP id l19mr17032236edr.14.1587971196787; Mon, 27 Apr 2020 00:06:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587971196; cv=none; d=google.com; s=arc-20160816; b=YeGZTdsc5EozD0/+ApsJFjDuBPrPuBd/VvRWPVJxZsRmXMAFlUDEbTp8rZKfGHJ5mF wObhPXQ/DbAiiuIYGla/IM8LM5ExKVVEf/RlhvsPF8fTdA1xpCBWpAwR9vrbDxtC0VFq 4Dp2idDt97go4K14QgRuqx1h3EcFhPuocqWaUYfwYgQUViS8HEDiVuauap4SloInEekB NDtJB3IXFkgLoF9iQHZk89I3LbF9J5VTm7EPgo/8uVk4dPxOnKkk6mb+UQ8/FlCafGOu 32rIeC0YhnOmDhg4QD65dmi/e39y0+zx44s7n498DyTpi8W68s6Px5Pzmd5F3alh5sT9 ugEA== 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=/kNBWq5RcCEi7KVvX1gtCnmuHlyl9EQEhtVxKBSI9ns=; b=rnER8/3axcoVo9ojAeCxmHNOw3v9Jay5yj2Aen433D1DiiY71ocdCHM/SpfXD05H5H gUYWmMnHAMy/KICVy8xCP73JLXp/3lNaqPKlrB5ky2Bfq1Jnu4hWBZn7DrWfPPZFlHti asQJpyhgr0EladjeXqtzWs+fFZECpwnluEFeOJ0RLLaWSPkYOKVPQV7iiNI3t9P2ZAY8 K2jY+nypQFPjMo+X9cvlL2MFeWJ39myN/QYhR3LoRCXASDgf4Za3iBC19b+TsMmt9+c/ 36s0UZncIlbCDAixnEcpw4xwEreOgRzXxB7Mwv9JgE4wypjQpDHSfZp9cvChYB/YNmza lDNQ== 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 e8si7562340ejr.462.2020.04.27.00.06.13; Mon, 27 Apr 2020 00:06:36 -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 S1726729AbgD0HDn (ORCPT + 99 others); Mon, 27 Apr 2020 03:03:43 -0400 Received: from out30-54.freemail.mail.aliyun.com ([115.124.30.54]:54947 "EHLO out30-54.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726676AbgD0HDk (ORCPT ); Mon, 27 Apr 2020 03:03:40 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R541e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04394;MF=alex.shi@linux.alibaba.com;NM=1;PH=DS;RN=17;SR=0;TI=SMTPD_---0Twm2W3x_1587971013; Received: from localhost(mailfrom:alex.shi@linux.alibaba.com fp:SMTPD_---0Twm2W3x_1587971013) by smtp.aliyun-inc.com(127.0.0.1); Mon, 27 Apr 2020 15:03:33 +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 Cc: Alex Shi Subject: [PATCH v10 02/15] mm/vmscan: remove unnecessary lruvec adding Date: Mon, 27 Apr 2020 15:02:51 +0800 Message-Id: <1587970985-21629-3-git-send-email-alex.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1587970985-21629-1-git-send-email-alex.shi@linux.alibaba.com> References: <1587970985-21629-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 | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index b06868fc4926..3910277da39e 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1837,26 +1837,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); @@ -1864,9 +1867,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