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=-10.1 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 autolearn=unavailable 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 A6536C433E8 for ; Tue, 28 Jul 2020 15:56:17 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2A62D2053B for ; Tue, 28 Jul 2020 15:56:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bZo5BpOK" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2A62D2053B 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 6FCB96B007E; Tue, 28 Jul 2020 11:56:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6D3266B0080; Tue, 28 Jul 2020 11:56:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5C1958D000B; Tue, 28 Jul 2020 11:56:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0084.hostedemail.com [216.40.44.84]) by kanga.kvack.org (Postfix) with ESMTP id 469076B007E for ; Tue, 28 Jul 2020 11:56:16 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id C9C51180AD83A for ; Tue, 28 Jul 2020 15:56:15 +0000 (UTC) X-FDA: 77087936310.27.head21_611039226f6b Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin27.hostedemail.com (Postfix) with ESMTP id A75C13D8EC for ; Tue, 28 Jul 2020 15:56:07 +0000 (UTC) X-HE-Tag: head21_611039226f6b X-Filterd-Recvd-Size: 13971 Received: from mail-io1-f68.google.com (mail-io1-f68.google.com [209.85.166.68]) by imf10.hostedemail.com (Postfix) with ESMTP for ; Tue, 28 Jul 2020 15:56:07 +0000 (UTC) Received: by mail-io1-f68.google.com with SMTP id l17so21260661iok.7 for ; Tue, 28 Jul 2020 08:56:06 -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=OTfwjc1FRQLZQNZD1/9bduGC1jve2EFF+bZqMItMbMI=; b=bZo5BpOKVA3FUbeHqes88E2XiqI+1pUiJvaI8Vg2qsZrJ8/WVytv13JK85YM7vRiW7 7SBoL0m2NQdE0iD7/0In30u7Kh9hnvXHifRNYJq8UfCDDi3139iNiU07/3wrfcA3mtBp LrqHVWdXB+qrAzaOUxZgpmJ+rKwBKZOpWvoVw8u/OvICCYBTr2x85Bf0m2v7BAHTwnNx vZAnymn3iMjjrDEt58wRcAuKEXhred52FDKC0JS/J/j8lN0FUHVJUAPZzJ/F1kAQVGQ1 WGlXXVxcOuVZXfPJjRLD6NcKUA0RzFELEfhnHwDlD5lO30mf8DtYbjTzcxfMliqaqxSx TuTg== 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=OTfwjc1FRQLZQNZD1/9bduGC1jve2EFF+bZqMItMbMI=; b=dMYXMZd2fizVZuW6x913cU97utkn+BQiF6B59EmJhsSg4Z51epymU0uptERHWndWFA 2M8j8BaRZB5IrHdiNwzQms3OOhCz7yy563saagXtDs99ZtpqWnUitbS6sjYYeWCxMfCu WgyLALqudFw97VyA7aqu02KApLFBzx4IRF9K8ekcQHQTSXIjFaJhIVhct6vgEs8LMeNv +xqQHkdJBcXXfEdU3o4geh9vxByW2w/IY/RSfGOwbVIhxRIAV9TjobzG2XLz2PJgCW5q ORKC5B+Yuul4sfnHyw03Em60dBntXCAXNwf1K36RcyyTxCU+9n+KVvrV1hchZzfF6nkp FiGA== X-Gm-Message-State: AOAM5322NUgejBEmECoacLtg9DUWH3nrtKYpoIf9xsO5kD59szVmWQOp 8J1KmtWjjakXPhUzxonB3Ck4ewpV5CIg7THBABs= X-Google-Smtp-Source: ABdhPJwCqe5IctwsE4VLRsK8Zi2PsslTmgFY725Rn4+dwHYPCAonPWWUshwTmD9995054HtivWtW4maSQJv8hdfw2iw= X-Received: by 2002:a6b:92d5:: with SMTP id u204mr17206025iod.38.1595951766280; Tue, 28 Jul 2020 08:56:06 -0700 (PDT) MIME-Version: 1.0 References: <1595681998-19193-1-git-send-email-alex.shi@linux.alibaba.com> <1595681998-19193-18-git-send-email-alex.shi@linux.alibaba.com> <1fd45e69-3a50-aae8-bcc4-47d891a5e263@linux.alibaba.com> In-Reply-To: <1fd45e69-3a50-aae8-bcc4-47d891a5e263@linux.alibaba.com> From: Alexander Duyck Date: Tue, 28 Jul 2020 08:55:55 -0700 Message-ID: Subject: Re: [PATCH v17 17/21] mm/lru: replace pgdat lru_lock with lruvec lock To: Alex Shi Cc: Andrew Morton , Mel Gorman , Tejun Heo , Hugh Dickins , Konstantin Khlebnikov , Daniel Jordan , Yang Shi , Matthew Wilcox , Johannes Weiner , kbuild test robot , linux-mm , LKML , cgroups@vger.kernel.org, Shakeel Butt , Joonsoo Kim , Wei Yang , "Kirill A. Shutemov" , Rong Chen , Michal Hocko , Vladimir Davydov Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: A75C13D8EC X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 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 Tue, Jul 28, 2020 at 8:40 AM Alex Shi wrote= : > > > > =E5=9C=A8 2020/7/28 =E4=B8=8A=E5=8D=887:34, Alexander Duyck =E5=86=99=E9= =81=93: > > It might make more sense to look at modifying > > compact_unlock_should_abort and compact_lock_irqsave (which always > > returns true so should probably be a void) to address the deficiencies > > they have that make them unusable for you. > > One of possible reuse for the func compact_unlock_should_abort, could be > like the following, the locked parameter reused different in 2 places. > but, it's seems no this style usage in kernel, isn't it? > > Thanks > Alex > > From 41d5ce6562f20f74bc6ac2db83e226ac28d56e90 Mon Sep 17 00:00:00 2001 > From: Alex Shi > Date: Tue, 28 Jul 2020 21:19:32 +0800 > Subject: [PATCH] compaction polishing > > Signed-off-by: Alex Shi > --- > mm/compaction.c | 71 ++++++++++++++++++++++++---------------------------= ------ > 1 file changed, 30 insertions(+), 41 deletions(-) > > diff --git a/mm/compaction.c b/mm/compaction.c > index c28a43481f01..36fce988de3e 100644 > --- a/mm/compaction.c > +++ b/mm/compaction.c > @@ -479,20 +479,20 @@ static bool test_and_set_skip(struct compact_contro= l *cc, struct page *page, > * > * Always returns true which makes it easier to track lock state in call= ers. > */ > -static bool compact_lock_irqsave(spinlock_t *lock, unsigned long *flags, > +static void compact_lock_irqsave(spinlock_t *lock, unsigned long *flags, > struct compact_control *c= c) > __acquires(lock) > { > /* Track if the lock is contended in async mode */ > if (cc->mode =3D=3D MIGRATE_ASYNC && !cc->contended) { > if (spin_trylock_irqsave(lock, *flags)) > - return true; > + return; > > cc->contended =3D true; > } > > spin_lock_irqsave(lock, *flags); > - return true; > + return; > } > > /* > @@ -511,11 +511,11 @@ static bool compact_lock_irqsave(spinlock_t *lock, = unsigned long *flags, > * scheduled) > */ > static bool compact_unlock_should_abort(spinlock_t *lock, > - unsigned long flags, bool *locked, struct compact_control= *cc) > + unsigned long flags, void **locked, struct compact_contro= l *cc) Instead of passing both a void pointer and the lock why not just pass the pointer to the lock pointer? You could combine lock and locked into a single argument and save yourself some extra effort. > { > if (*locked) { > spin_unlock_irqrestore(lock, flags); > - *locked =3D false; > + *locked =3D NULL; > } > > if (fatal_signal_pending(current)) { > @@ -543,7 +543,7 @@ static unsigned long isolate_freepages_block(struct c= ompact_control *cc, > int nr_scanned =3D 0, total_isolated =3D 0; > struct page *cursor; > unsigned long flags =3D 0; > - bool locked =3D false; > + struct compact_control *locked =3D NULL; > unsigned long blockpfn =3D *start_pfn; > unsigned int order; > > @@ -565,7 +565,7 @@ static unsigned long isolate_freepages_block(struct c= ompact_control *cc, > */ > if (!(blockpfn % SWAP_CLUSTER_MAX) > && compact_unlock_should_abort(&cc->zone->lock, flags= , > - &locked, = cc)) > + (void**)&locked, = cc)) > break; > > nr_scanned++; > @@ -599,8 +599,8 @@ static unsigned long isolate_freepages_block(struct c= ompact_control *cc, > * recheck as well. > */ > if (!locked) { > - locked =3D compact_lock_irqsave(&cc->zone->lock, > - &flags, c= c); > + compact_lock_irqsave(&cc->zone->lock, &flags, cc)= ; > + locked =3D cc; > > /* Recheck this is a buddy page under lock */ > if (!PageBuddy(page)) If you have to provide a pointer you might as well just provide a pointer to the zone lock since that is the thing that is actually holding the lock at this point and would be consistent with your other uses of the locked value. One possibility would be to change the return type so that you return a pointer to the lock you are using. Then the code would look closer to the lruvec code you are already using. > @@ -787,7 +787,7 @@ static bool too_many_isolated(pg_data_t *pgdat) > unsigned long nr_scanned =3D 0, nr_isolated =3D 0; > struct lruvec *lruvec; > unsigned long flags =3D 0; > - struct lruvec *locked_lruvec =3D NULL; > + struct lruvec *locked =3D NULL; > struct page *page =3D NULL, *valid_page =3D NULL; > unsigned long start_pfn =3D low_pfn; > bool skip_on_failure =3D false; > @@ -847,21 +847,11 @@ static bool too_many_isolated(pg_data_t *pgdat) > * contention, to give chance to IRQs. Abort completely i= f > * a fatal signal is pending. > */ > - if (!(low_pfn % SWAP_CLUSTER_MAX)) { > - if (locked_lruvec) { > - unlock_page_lruvec_irqrestore(locked_lruv= ec, > - f= lags); > - locked_lruvec =3D NULL; > - } > - > - if (fatal_signal_pending(current)) { > - cc->contended =3D true; > - > - low_pfn =3D 0; > - goto fatal_pending; > - } > - > - cond_resched(); > + if (!(low_pfn % SWAP_CLUSTER_MAX) > + && compact_unlock_should_abort(&locked->lru_lock, fla= gs, > + (void**)&locked, cc)) { An added advantage to making locked a pointer to a spinlock is that you could reduce the number of pointers you have to pass. Instead of messing with &locked->lru_lock you would just pass the pointer to locked resulting in fewer arguments being passed and if it is NULL you skip the whole unlock pass. > + low_pfn =3D 0; > + goto fatal_pending; > } > > if (!pfn_valid_within(low_pfn)) > @@ -932,9 +922,9 @@ static bool too_many_isolated(pg_data_t *pgdat) > */ > if (unlikely(__PageMovable(page)) && > !PageIsolated(page)) { > - if (locked_lruvec) { > - unlock_page_lruvec_irqrestore(loc= ked_lruvec, flags); > - locked_lruvec =3D NULL; > + if (locked) { > + unlock_page_lruvec_irqrestore(loc= ked, flags); > + locked =3D NULL; > } > > if (!isolate_movable_page(page, isolate_m= ode)) > @@ -979,13 +969,13 @@ static bool too_many_isolated(pg_data_t *pgdat) > lruvec =3D mem_cgroup_page_lruvec(page, pgdat); > > /* If we already hold the lock, we can skip some rechecki= ng */ > - if (lruvec !=3D locked_lruvec) { > - if (locked_lruvec) > - unlock_page_lruvec_irqrestore(locked_lruv= ec, > + if (lruvec !=3D locked) { > + if (locked) > + unlock_page_lruvec_irqrestore(locked, > f= lags); > > compact_lock_irqsave(&lruvec->lru_lock, &flags, c= c); > - locked_lruvec =3D lruvec; > + locked =3D lruvec; > rcu_read_unlock(); > > lruvec_memcg_debug(lruvec, page); > @@ -1041,9 +1031,9 @@ static bool too_many_isolated(pg_data_t *pgdat) > > isolate_fail_put: > /* Avoid potential deadlock in freeing page under lru_loc= k */ > - if (locked_lruvec) { > - unlock_page_lruvec_irqrestore(locked_lruvec, flag= s); > - locked_lruvec =3D NULL; > + if (locked) { > + unlock_page_lruvec_irqrestore(locked, flags); > + locked =3D NULL; > } > put_page(page); > > @@ -1057,10 +1047,9 @@ static bool too_many_isolated(pg_data_t *pgdat) > * page anyway. > */ > if (nr_isolated) { > - if (locked_lruvec) { > - unlock_page_lruvec_irqrestore(locked_lruv= ec, > - f= lags); > - locked_lruvec =3D NULL; > + if (locked) { > + unlock_page_lruvec_irqrestore(locked, fla= gs); > + locked =3D NULL; > } > putback_movable_pages(&cc->migratepages); > cc->nr_migratepages =3D 0; > @@ -1087,8 +1076,8 @@ static bool too_many_isolated(pg_data_t *pgdat) > page =3D NULL; > > isolate_abort: > - if (locked_lruvec) > - unlock_page_lruvec_irqrestore(locked_lruvec, flags); > + if (locked) > + unlock_page_lruvec_irqrestore(locked, flags); > if (page) { > SetPageLRU(page); > put_page(page); > -- > 1.8.3.1 >