Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp526247pxa; Wed, 19 Aug 2020 07:58:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy7VeMHf+zcj609Le41N97lOZbH5vLs/sHJxLfTYaU7K6u2s83454OZBKazCWdQEvkHcsUW X-Received: by 2002:a17:906:6d91:: with SMTP id h17mr24326552ejt.531.1597849111566; Wed, 19 Aug 2020 07:58:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597849111; cv=none; d=google.com; s=arc-20160816; b=LwV6/yVmBSTUO9c9AeOrjv/Mgsz8TSkQVcb8+GYQjujQ+UIVmHjKw+JGuakGNaG/WV Y838PK3Z2aZ6EB1iPqlp2vBv9SHrF3YLjfrZJ/IuPOxmuEzU9QUw/ZkGPdIqBwJpICm5 cOcbodw0gusd0pblwixxNLfIDNtnkfZ+zZ2JpdIeIT07AmpIay9R8OK8wxRwod2DqtZ5 TmfKc7qYp5kvgTDtwh1i8PIA9f6HVvn3N7ERuiDb2RoLtr8HvZwOQtZVNwy+YbBopz+J jrCdnmn73SJ4HtIY1Fe9dIQ7PDr6VdSXipTUb/GG23D6xpFgW/qTizGmtR/dvT0OzMFb lC4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=VDgt+NfpwH6U6r2hvHr0dBMMv6qNBbALooemz8NFh5U=; b=CFkcLiXC9YcAXndmohubVzsYsrBwU1gftpHVOJBlCOiBRQIEwxkcUDrsnZ5snb9Y66 zGb+3mMnnuskO6iNwv5bIYnYQTCAlIQGBKT2ifptD34dByrYsx2tQR3N/uLhF3V1PrTv dzakc/8k0sVC0IXKzQUat008AeJjnOkYSiPqT7r8i2RGTficmgRyWjdtpY1MGDM5Vn2Q kKMzQ0UmN8+v/Iejax3QuEAt1pY2npS5w/KrBKLC6gewMd8GdWrITYxQYIZ1UQJR+9DX 3OhwqC0ni1U0ipyyzI5OHyW69RE2OBwEFYpKFm1pVD0HI4OlQJ/3i79XFsAFHHd5x98+ i3wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=f+ZY76s5; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o9si15269402edq.412.2020.08.19.07.58.07; Wed, 19 Aug 2020 07:58:31 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=f+ZY76s5; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727854AbgHSO5i (ORCPT + 99 others); Wed, 19 Aug 2020 10:57:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727018AbgHSO53 (ORCPT ); Wed, 19 Aug 2020 10:57:29 -0400 Received: from mail-io1-xd42.google.com (mail-io1-xd42.google.com [IPv6:2607:f8b0:4864:20::d42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BD58C061757; Wed, 19 Aug 2020 07:57:28 -0700 (PDT) Received: by mail-io1-xd42.google.com with SMTP id u126so24896361iod.12; Wed, 19 Aug 2020 07:57:28 -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=VDgt+NfpwH6U6r2hvHr0dBMMv6qNBbALooemz8NFh5U=; b=f+ZY76s5TRKLUXDOUW1UKWMOshJmecMeQftVcBsCsWkWr4125JZu9WJtY2mpOhQoPG qsJ/dGsIR4iuWMWEBeaCXI22z2X+muEGh5TnoFmIDerzN/VXAPAsbPN/7xR8Dk2eGWx4 w4VaCqCZAoGVIR1bl2Smo3+3TxHihbXBwp9Ciz1699llS6GM6yAvU/XbPjS9Q72K3Pge qtxmOF26p1U8NUaDlBngBuqZz1LHwJQqQGV9gjb/PYz4tx7Z16p/BVOLCP4Bur07EFLS R2gYxBW87NUAFuNuUQubaJdFH84qd2+y7N8LItneA+hKUh1pddYAeHTHUiPrPqKxB4ke G4dA== 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=VDgt+NfpwH6U6r2hvHr0dBMMv6qNBbALooemz8NFh5U=; b=s1HM1JTef5VBiZZw5DRtF5oI42gJnYDzy4p5bBrOo8gZnbGRJAd+ddEnuVqqUynxgq 9/7CyLrzjyONjYER+3aqDoiiyoLJVzDtNj3ruSF7/cVUA9xHvZHwN/HIGqQe4rOuAd5g 4MAjB9If+wizhRavZsb/Ga6HCMejevtATotLEERLsaboJRimQGsvrWc/D1uVm02Lo991 Rwrgrrw9UBrrfkwhtP+pA3/idpi+ErLOrdh0SAlBPZ0iBKSGqFRQXnXUqhocxXPgFvQN Q0vNLtnVcM4t/5ULnhK/YtCOgqmtjPbI2kJaJFuEJB81SGteTk6WyZn4NrAVI+KyTeX4 4gWA== X-Gm-Message-State: AOAM5333xd6kOtPVhiPA3gJ7v415LXpyBfaRN3Xo/VSRIHGMitQX//z1 nemz9XHqISz/bk4a8jLptV4GDXmmdjnBJbRkDQs= X-Received: by 2002:a05:6602:2e83:: with SMTP id m3mr21190548iow.38.1597849047807; Wed, 19 Aug 2020 07:57:27 -0700 (PDT) MIME-Version: 1.0 References: <20200819041852.23414.95939.stgit@localhost.localdomain> <20200819042730.23414.41309.stgit@localhost.localdomain> <15edf807-ce03-83f7-407d-5929341b2b4e@linux.alibaba.com> In-Reply-To: <15edf807-ce03-83f7-407d-5929341b2b4e@linux.alibaba.com> From: Alexander Duyck Date: Wed, 19 Aug 2020 07:57:16 -0700 Message-ID: Subject: Re: [RFC PATCH v2 4/5] mm: Split release_pages work into 3 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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 19, 2020 at 12:54 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 release_pages function has a number of paths that end up with the > > LRU lock having to be released and reacquired. Such an example would be= the > > freeing of THP pages as it requires releasing the LRU lock so that it c= an > > be potentially reacquired by __put_compound_page. > > > > In order to avoid that we can split the work into 3 passes, the first > > without the LRU lock to go through and sort out those pages that are no= t in > > the LRU so they can be freed immediately from those that can't. The sec= ond > > pass will then go through removing those pages from the LRU in batches = as > > large as a pagevec can hold before freeing the LRU lock. Once the pages= have > > been removed from the LRU we can then proceed to free the remaining pag= es > > without needing to worry about if they are in the LRU any further. > > > > The general idea is to avoid bouncing the LRU lock between pages and to > > hopefully aggregate the lock for up to the full page vector worth of pa= ges. > > > > Signed-off-by: Alexander Duyck > > --- > > mm/swap.c | 109 +++++++++++++++++++++++++++++++++++++----------------= -------- > > 1 file changed, 67 insertions(+), 42 deletions(-) > > > > diff --git a/mm/swap.c b/mm/swap.c > > index fe53449fa1b8..b405f81b2c60 100644 > > --- a/mm/swap.c > > +++ b/mm/swap.c > > @@ -795,6 +795,54 @@ void lru_add_drain_all(void) > > } > > #endif > > > > +static void __release_page(struct page *page, struct list_head *pages_= to_free) > > +{ > > + if (PageCompound(page)) { > > + __put_compound_page(page); > > + } else { > > + /* Clear Active bit in case of parallel mark_page_accesse= d */ > > + __ClearPageActive(page); > > + __ClearPageWaiters(page); > > + > > + list_add(&page->lru, pages_to_free); > > + } > > +} > > + > > +static void __release_lru_pages(struct pagevec *pvec, > > + struct list_head *pages_to_free) > > +{ > > + struct lruvec *lruvec =3D NULL; > > + unsigned long flags =3D 0; > > + int i; > > + > > + /* > > + * The pagevec at this point should contain a set of pages with > > + * their reference count at 0 and the LRU flag set. We will now > > + * need to pull the pages from their LRU lists. > > + * > > + * We walk the list backwards here since that way we are starting= at > > + * the pages that should be warmest in the cache. > > + */ > > + for (i =3D pagevec_count(pvec); i--;) { > > + struct page *page =3D pvec->pages[i]; > > + > > + lruvec =3D relock_page_lruvec_irqsave(page, lruvec, &flag= s); > > the lock bounce is better with the patch, would you like to do further > like using add_lruvecs to reduce bounce more? > > Thanks > Alex I'm not sure how much doing something like that would add. In my case I had a very specific issue that this is addressing which is the fact that every compound page was taking the LRU lock and zone lock separately. With this patch that is reduced to one LRU lock per 15 pages and then the zone lock per page. By adding or sorting pages by lruvec I am not sure there will be much benefit as I am not certain how often we will end up with pages being interleaved between multiple lruvecs. In addition as I am limiting the quantity to a pagevec which limits the pages to 15 I am not sure there will be much benefit to be seen for sorting the pages beforehand. Thanks. - Alex