Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp293581ybt; Fri, 19 Jun 2020 02:03:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxXDWTuUb0EwKu6Qg0XqMS5WQ2jYIY5PAv6sZfUECGxl8ara2nUi8uPwGgON9OPOH6MVoX9 X-Received: by 2002:a17:906:5e08:: with SMTP id n8mr2664305eju.132.1592557439717; Fri, 19 Jun 2020 02:03:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592557439; cv=none; d=google.com; s=arc-20160816; b=s82LaKsUqPjiiSdckXODbRraBxLqMElHlLq6P9PoQ7klm1JSbCR49QW3kNS9rzpyhO AF3pcRrO7HTVN4bYUFX9usKElIsaz4EF7s1piCwiuAND3cZ84fO2YRz9L9ZJ9TERy7ZY 52qqzyRFNVUGL7BcY09M8E6adA36TXrKAOLvpLpQgJ8+vq5JKnmRGhY26I8eAyyxkHJ1 Yre8JdqIgDCwM+/69bsQxi32EUmQ0suCwa+wGQxmT7DRBp33/s2sJ498yxCi2pNs0TzB JoXUtgk9L9ce3RA+Eii8XPzwy2sB3wilkC4LrqHk+Hk2tbnT6fcu6+MHLr74BXvEkf+A 293Q== 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=3LRJpnrNZuhIMjIZU6ZIaZWbP+WMKxa/Le9y81FoX2o=; b=rZN5pw1aJDNsjgJoTOGsHdy/RyF+C07ZPCb9jG2JyexXpGKBEQ9UCGwluKjVvnG4Si HA1VGC68sJKyFg/aP92DcfxV97lEXjZ4z5R1WdCFvz8vy8GhzsPSHtZ2yyqR0JHnAWRm Wrt6D6ZckKRU8us6JYdi1h8wO/tdPXkXK/kUK7w8TOggi8asOgAI/jzDY2Xc8ouvXvnj sel+Lt6XHS6R8mvxbNwnjgtl+jOzY+c0jwg8Uovp0Pir00NTR5OZvOlaYyRAMr2aDrEK hK0P+LxPKzMLUPh6VjGQLZf2IS3JAlzhwfGrRiI12a0safef8Ly2nLskhuZ1skSBlBAG nbdA== 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 b2si3489390ejk.469.2020.06.19.02.03.36; Fri, 19 Jun 2020 02:03:59 -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 S1731661AbgFSIej (ORCPT + 99 others); Fri, 19 Jun 2020 04:34:39 -0400 Received: from out30-130.freemail.mail.aliyun.com ([115.124.30.130]:43840 "EHLO out30-130.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731544AbgFSIeY (ORCPT ); Fri, 19 Jun 2020 04:34:24 -0400 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=e01f04397;MF=alex.shi@linux.alibaba.com;NM=1;PH=DS;RN=16;SR=0;TI=SMTPD_---0U01UeXJ_1592555658; Received: from localhost(mailfrom:alex.shi@linux.alibaba.com fp:SMTPD_---0U01UeXJ_1592555658) by smtp.aliyun-inc.com(127.0.0.1); Fri, 19 Jun 2020 16:34:18 +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 Subject: [PATCH v13 01/18] mm/vmscan: remove unnecessary lruvec adding Date: Fri, 19 Jun 2020 16:33:39 +0800 Message-Id: <1592555636-115095-2-git-send-email-alex.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1592555636-115095-1-git-send-email-alex.shi@linux.alibaba.com> References: <1592555636-115095-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 b6d84326bdf2..81228334f7d6 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1855,26 +1855,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); @@ -1882,9 +1885,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