From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 86ED1C433E1 for ; Wed, 19 Aug 2020 14:42:55 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 31F2A207BB for ; Wed, 19 Aug 2020 14:42:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="We78s8ae" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 31F2A207BB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 932AC6B00B7; Wed, 19 Aug 2020 10:42:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8E4106B00B8; Wed, 19 Aug 2020 10:42:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7D19F6B00B9; Wed, 19 Aug 2020 10:42:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0129.hostedemail.com [216.40.44.129]) by kanga.kvack.org (Postfix) with ESMTP id 662D26B00B7 for ; Wed, 19 Aug 2020 10:42:54 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 29C572480 for ; Wed, 19 Aug 2020 14:42:54 +0000 (UTC) X-FDA: 77167585068.27.yard15_5409b0827028 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin27.hostedemail.com (Postfix) with ESMTP id EADBC3D663 for ; Wed, 19 Aug 2020 14:42:53 +0000 (UTC) X-HE-Tag: yard15_5409b0827028 X-Filterd-Recvd-Size: 8043 Received: from mail-io1-f67.google.com (mail-io1-f67.google.com [209.85.166.67]) by imf04.hostedemail.com (Postfix) with ESMTP for ; Wed, 19 Aug 2020 14:42:53 +0000 (UTC) Received: by mail-io1-f67.google.com with SMTP id v6so24834433iow.11 for ; Wed, 19 Aug 2020 07:42:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=mcVXNr/miBqBqBzPd9zMl9/P3yj0Py/DDVO/2K9/W8w=; b=We78s8aeZBHNS8HsXJOECFtjGX0yBLXCmD9JNUeoRZJB6mQznUcKYUARlp2d8bBHSj 3MYtOox2aoiTCMZJHQ0aLbKAufrXDvLthlw1SYtqfpmsKIMKJ2AKJcyGEV9+c8l1w3Z1 gCVfjavBkDJIkR3fUr3gg57fqGnCjcqa0v128cNDQur3H2RzKvtWNedO3MfQvg9dIMe3 FJzHgpcTQvnbz5Ng96Mgg/91NthBPq/wlMFrT2EQKdfpKbLD5aEGeARJ24zu4Vn9Jf2V ilqu/6IJiEUpeCdUs/PwxW30G3jBBEkpPghitItA81NmeiUXeGHVXCopiMY4J/OlNh08 ToMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=mcVXNr/miBqBqBzPd9zMl9/P3yj0Py/DDVO/2K9/W8w=; b=gemV2Lz1/XKJBuTEZYdcYS9Jnx4lnm5TWIY5Wyq6eo9VP8y9smqTwGay7BFB4+LWvS XCIyO57DND56Ay/nPWe0QXEOW+TDXg+oNvpFoPiJT/Xl97RcOXQM1+TMm54EUQYo/qHn b4mQnu+vPS4tR6evvs03Cj+mKDyTR9vrkRSkz+Tk1axJdGPoyf84iaPAgq7zfZ0Flamz n/bM9hJgbEwJ2HfKpKYGowIPXrZKM/BGtlhr5M6aZ/OM+fdskSP3H6lwRUwChpceJhOk /5xh5v8Omsi0LDCWlD4hBBrZ5ti14tYzme0fTjNw38htiCD8lNtij+VObGd/okjwmuq8 PQbA== X-Gm-Message-State: AOAM532Aix1KrwO+IpPKWYdWBXtzt8chIJPfaj3eUAdlWIrj6bhjrc0F l8FG+4Ley1U6uLKn6NUsRXIGlnu0WcGXw3metTM= X-Google-Smtp-Source: ABdhPJy0G9erP9ijJ2vX8Ai98AthvnT14z2zO5yP9aZ0guBPsZfdROzXXArHkB7NYbBxnMOHqKwUMXP/pKWqLBtWNUU= X-Received: by 2002:a6b:da0d:: with SMTP id x13mr20832998iob.138.1597848172300; Wed, 19 Aug 2020 07:42:52 -0700 (PDT) MIME-Version: 1.0 References: <20200819041852.23414.95939.stgit@localhost.localdomain> <20200819042738.23414.60815.stgit@localhost.localdomain> <084c58a7-7aac-820c-9606-19391c35b9b5@linux.alibaba.com> In-Reply-To: <084c58a7-7aac-820c-9606-19391c35b9b5@linux.alibaba.com> From: Alexander Duyck Date: Wed, 19 Aug 2020 07:42:41 -0700 Message-ID: Subject: Re: [RFC PATCH v2 5/5] mm: Split move_pages_to_lru into 3 separate passes To: Alex Shi Cc: Yang Shi , kbuild test robot , Rong Chen , Konstantin Khlebnikov , "Kirill A. Shutemov" , Hugh Dickins , LKML , Daniel Jordan , linux-mm , Shakeel Butt , Matthew Wilcox , Johannes Weiner , Tejun Heo , cgroups@vger.kernel.org, Andrew Morton , Wei Yang , Mel Gorman , Joonsoo Kim Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: EADBC3D663 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, Aug 19, 2020 at 12:58 AM Alex Shi wrot= e: > > > > =E5=9C=A8 2020/8/19 =E4=B8=8B=E5=8D=8812:27, Alexander Duyck =E5=86=99=E9= =81=93: > > From: Alexander Duyck > > > > The current code for move_pages_to_lru is meant to release the LRU lock > > every time it encounters an unevictable page or a compound page that mu= st > > be freed. This results in a fair amount of code bulk because the lruvec= has > > to be reacquired every time the lock is released and reacquired. > > > > Instead of doing this I believe we can break the code up into 3 passes.= The > > first pass will identify the pages we can move to LRU and move those. I= n > > addition it will sort the list out leaving the unevictable pages in the > > list and moving those pages that have dropped to a reference count of 0= to > > pages_to_free. The second pass will return the unevictable pages to the > > LRU. The final pass will free any compound pages we have in the > > pages_to_free list before we merge it back with the original list and > > return from the function. > > > > The advantage of doing it this way is that we only have to release the = lock > > between pass 1 and 2, and then we reacquire the lock after pass 3 after= we > > merge the pages_to_free back into the original list. As such we only ha= ve > > to release the lock at most once in an entire call instead of having to > > test to see if we need to relock with each page. > > > > Signed-off-by: Alexander Duyck > > --- > > mm/vmscan.c | 68 ++++++++++++++++++++++++++++++++++-----------------= -------- > > 1 file changed, 39 insertions(+), 29 deletions(-) > > > > diff --git a/mm/vmscan.c b/mm/vmscan.c > > index 3ebe3f9b653b..6a2bdbc1a9eb 100644 > > --- a/mm/vmscan.c > > +++ b/mm/vmscan.c > > @@ -1850,22 +1850,21 @@ static unsigned noinline_for_stack move_pages_t= o_lru(struct lruvec *lruvec, > > { > > int nr_pages, nr_moved =3D 0; > > LIST_HEAD(pages_to_free); > > - struct page *page; > > - struct lruvec *orig_lruvec =3D lruvec; > > + struct page *page, *next; > > enum lru_list lru; > > > > - while (!list_empty(list)) { > > - page =3D lru_to_page(list); > > + list_for_each_entry_safe(page, next, list, lru) { > > VM_BUG_ON_PAGE(PageLRU(page), page); > > - list_del(&page->lru); > > - if (unlikely(!page_evictable(page))) { > > - if (lruvec) { > > - spin_unlock_irq(&lruvec->lru_lock); > > - lruvec =3D NULL; > > - } > > - putback_lru_page(page); > > + > > + /* > > + * if page is unevictable leave it on the list to be retu= rned > > + * to the LRU after we have finished processing the other > > + * entries in the list. > > + */ > > + if (unlikely(!page_evictable(page))) > > continue; > > - } > > + > > + list_del(&page->lru); > > > > /* > > * The SetPageLRU needs to be kept here for list intergri= ty. > > @@ -1878,20 +1877,14 @@ static unsigned noinline_for_stack move_pages_t= o_lru(struct lruvec *lruvec, > > * list_add(&page->lru,) > > * list_add(&page-= >lru,) > > */ > > - lruvec =3D relock_page_lruvec_irq(page, lruvec); > > It's actually changed the meaning from current func. which I had seen a b= ug if no relock. > but after move to 5.9 kernel, I can not reprodce the bug any more. I am n= ot sure if 5.9 fixed > the problem, and we don't need relock here. So I am not sure what you mean here about "changed the meaning from the current func". Which function are you referring to and what changed? >From what I can tell the pages cannot change memcg because they were isolated and had the LRU flag stripped. They shouldn't be able to change destination LRU vector as a result. Assuming that, then they can all be processed under same LRU lock and we can avoid having to release it until we are forced to do so to call putback_lru_page or destroy the compound pages that were freed while we were shrinking the LRU lists. > For the rest of this patch. > Reviewed-by: Alex Shi Thanks for the review. - Alex