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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4CB5AC433F5 for ; Wed, 25 May 2022 11:39:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234546AbiEYLjA (ORCPT ); Wed, 25 May 2022 07:39:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230476AbiEYLi5 (ORCPT ); Wed, 25 May 2022 07:38:57 -0400 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 147EC9EB5F for ; Wed, 25 May 2022 04:38:55 -0700 (PDT) Received: by mail-pg1-x534.google.com with SMTP id s68so2385836pgs.10 for ; Wed, 25 May 2022 04:38:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=+XvTKuREjiScrS3Wh3we/csDNgvvsNrhuVBevDa5cpg=; b=fVm+KR5uG2kq3XNouhS2R/L94OvDDTU5coc7ipX7iW9rngv/ZEpY3fR7NHUagopxnq NOwZb9CkIdXE0nJjQCctq7BtxhLQ5RH5UDgwn7ez4SWe2+R/yap0p0jr7yj17acjt5hw G2PZoTAJr6pA91fcCSfWMXpeVKvzq6Pj2WOXEWXqJDxveE9fTloLLW0HvKPKCRpfOOvj kTsCQO3/q12cvQi9bx61yDyTEow8FG97UUPM/VzTxV7mxBmQY4NlM1Qjv6zJQds3Twro mlhbxszL5yozEO+IH9fK94imsjOF7jy+Dv2HjJPKoYorkW96w95P6s8sUB0SsP3o98AX 0syw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=+XvTKuREjiScrS3Wh3we/csDNgvvsNrhuVBevDa5cpg=; b=LeihjnmNTkYE0fJ5k0TZFkIEuqqkia0e6M3BT1FN8aa+zBS+rWXXkEuzxke/cTGc5E BKPAmACGxQ9xP18aSEbN2+i2gizCRPQYq5eVvMcaANZ0os9gsQUrv/bB+uda2o3L2sFN LvuUCYAk1A8rRI05bYipTlBXlYST+FZgjkoyrV5dSJpru9WmCepla7SBdODg03TTtFNr JwXqqzQTl3FhqVCSodcwFHo3//ap8ITYaYZw1sZrMCV2JSJrranJsgYtpsgT3Fkwcx6e d7mTYxOix9Pv3oWVvqvZjkt181tP9s4tVOBomHuIxMDg7xQLXv8/gN1tWKnto9O24ife 8zAA== X-Gm-Message-State: AOAM531mlyCArcwuTgqMXv6oAKC4YhxPqK3+b9awXZAwjvjxL5ALiTps ri0lnwqTmw5KpkTBjndncNv0nw== X-Google-Smtp-Source: ABdhPJywMg+/gvLv6CGzubqG5U05Br0QQh9ssP+pJgA5WkDyf0g/dnqlzvymmRS4/K2osf4odF5nUw== X-Received: by 2002:a63:9142:0:b0:3fa:dc58:8726 with SMTP id l63-20020a639142000000b003fadc588726mr2648562pge.349.1653478734613; Wed, 25 May 2022 04:38:54 -0700 (PDT) Received: from localhost ([2408:8207:18da:2310:c40f:7b5:4fa8:df3f]) by smtp.gmail.com with ESMTPSA id c27-20020aa7953b000000b0050dc762814fsm11277985pfp.41.2022.05.25.04.38.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 May 2022 04:38:53 -0700 (PDT) Date: Wed, 25 May 2022 19:38:49 +0800 From: Muchun Song To: Johannes Weiner Cc: mhocko@kernel.org, roman.gushchin@linux.dev, shakeelb@google.com, cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, duanxiongchun@bytedance.com, longman@redhat.com Subject: Re: [PATCH v4 04/11] mm: vmscan: rework move_pages_to_lru() Message-ID: References: <20220524060551.80037-1-songmuchun@bytedance.com> <20220524060551.80037-5-songmuchun@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 24, 2022 at 03:38:50PM -0400, Johannes Weiner wrote: > On Tue, May 24, 2022 at 02:05:44PM +0800, Muchun Song wrote: > > In the later patch, we will reparent the LRU pages. The pages moved to > > appropriate LRU list can be reparented during the process of the > > move_pages_to_lru(). So holding a lruvec lock by the caller is wrong, we > > should use the more general interface of folio_lruvec_relock_irq() to > > acquire the correct lruvec lock. > > > > Signed-off-by: Muchun Song > > --- > > mm/vmscan.c | 49 +++++++++++++++++++++++++------------------------ > > 1 file changed, 25 insertions(+), 24 deletions(-) > > > > diff --git a/mm/vmscan.c b/mm/vmscan.c > > index 1678802e03e7..761d5e0dd78d 100644 > > --- a/mm/vmscan.c > > +++ b/mm/vmscan.c > > @@ -2230,23 +2230,28 @@ static int too_many_isolated(struct pglist_data *pgdat, int file, > > * move_pages_to_lru() moves pages from private @list to appropriate LRU list. > > * On return, @list is reused as a list of pages to be freed by the caller. > > * > > - * Returns the number of pages moved to the given lruvec. > > + * Returns the number of pages moved to the appropriate LRU list. > > + * > > + * Note: The caller must not hold any lruvec lock. > > */ > > -static unsigned int move_pages_to_lru(struct lruvec *lruvec, > > - struct list_head *list) > > +static unsigned int move_pages_to_lru(struct list_head *list) > > { > > - int nr_pages, nr_moved = 0; > > + int nr_moved = 0; > > + struct lruvec *lruvec = NULL; > > LIST_HEAD(pages_to_free); > > - struct page *page; > > > > while (!list_empty(list)) { > > - page = lru_to_page(list); > > + int nr_pages; > > + struct folio *folio = lru_to_folio(list); > > + struct page *page = &folio->page; > > + > > + lruvec = folio_lruvec_relock_irq(folio, lruvec); > > VM_BUG_ON_PAGE(PageLRU(page), page); > > list_del(&page->lru); > > if (unlikely(!page_evictable(page))) { > > - spin_unlock_irq(&lruvec->lru_lock); > > + unlock_page_lruvec_irq(lruvec); > > Better to stick with the opencoded unlock. It matches a bit better > with the locking function, compared to locking folio and unlocking > page... > Seems like we are missing folio unlock variants. How about intriducing folio_lruvec_unlock() variants? There are a lot of places where locking folio and unlocking page. Thanks. > Aside from that, this looks good: > > Acked-by: Johannes Weiner > Thanks. From mboxrd@z Thu Jan 1 00:00:00 1970 From: Muchun Song Subject: Re: [PATCH v4 04/11] mm: vmscan: rework move_pages_to_lru() Date: Wed, 25 May 2022 19:38:49 +0800 Message-ID: References: <20220524060551.80037-1-songmuchun@bytedance.com> <20220524060551.80037-5-songmuchun@bytedance.com> Mime-Version: 1.0 Return-path: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=+XvTKuREjiScrS3Wh3we/csDNgvvsNrhuVBevDa5cpg=; b=fVm+KR5uG2kq3XNouhS2R/L94OvDDTU5coc7ipX7iW9rngv/ZEpY3fR7NHUagopxnq NOwZb9CkIdXE0nJjQCctq7BtxhLQ5RH5UDgwn7ez4SWe2+R/yap0p0jr7yj17acjt5hw G2PZoTAJr6pA91fcCSfWMXpeVKvzq6Pj2WOXEWXqJDxveE9fTloLLW0HvKPKCRpfOOvj kTsCQO3/q12cvQi9bx61yDyTEow8FG97UUPM/VzTxV7mxBmQY4NlM1Qjv6zJQds3Twro mlhbxszL5yozEO+IH9fK94imsjOF7jy+Dv2HjJPKoYorkW96w95P6s8sUB0SsP3o98AX 0syw== Content-Disposition: inline In-Reply-To: List-ID: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Johannes Weiner Cc: mhocko-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org, roman.gushchin-fxUVXftIFDnyG1zEObXtfA@public.gmane.org, shakeelb-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org, cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org, linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, duanxiongchun-EC8Uxl6Npydl57MIdRCFDg@public.gmane.org, longman-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org On Tue, May 24, 2022 at 03:38:50PM -0400, Johannes Weiner wrote: > On Tue, May 24, 2022 at 02:05:44PM +0800, Muchun Song wrote: > > In the later patch, we will reparent the LRU pages. The pages moved to > > appropriate LRU list can be reparented during the process of the > > move_pages_to_lru(). So holding a lruvec lock by the caller is wrong, we > > should use the more general interface of folio_lruvec_relock_irq() to > > acquire the correct lruvec lock. > > > > Signed-off-by: Muchun Song > > --- > > mm/vmscan.c | 49 +++++++++++++++++++++++++------------------------ > > 1 file changed, 25 insertions(+), 24 deletions(-) > > > > diff --git a/mm/vmscan.c b/mm/vmscan.c > > index 1678802e03e7..761d5e0dd78d 100644 > > --- a/mm/vmscan.c > > +++ b/mm/vmscan.c > > @@ -2230,23 +2230,28 @@ static int too_many_isolated(struct pglist_data *pgdat, int file, > > * move_pages_to_lru() moves pages from private @list to appropriate LRU list. > > * On return, @list is reused as a list of pages to be freed by the caller. > > * > > - * Returns the number of pages moved to the given lruvec. > > + * Returns the number of pages moved to the appropriate LRU list. > > + * > > + * Note: The caller must not hold any lruvec lock. > > */ > > -static unsigned int move_pages_to_lru(struct lruvec *lruvec, > > - struct list_head *list) > > +static unsigned int move_pages_to_lru(struct list_head *list) > > { > > - int nr_pages, nr_moved = 0; > > + int nr_moved = 0; > > + struct lruvec *lruvec = NULL; > > LIST_HEAD(pages_to_free); > > - struct page *page; > > > > while (!list_empty(list)) { > > - page = lru_to_page(list); > > + int nr_pages; > > + struct folio *folio = lru_to_folio(list); > > + struct page *page = &folio->page; > > + > > + lruvec = folio_lruvec_relock_irq(folio, lruvec); > > VM_BUG_ON_PAGE(PageLRU(page), page); > > list_del(&page->lru); > > if (unlikely(!page_evictable(page))) { > > - spin_unlock_irq(&lruvec->lru_lock); > > + unlock_page_lruvec_irq(lruvec); > > Better to stick with the opencoded unlock. It matches a bit better > with the locking function, compared to locking folio and unlocking > page... > Seems like we are missing folio unlock variants. How about intriducing folio_lruvec_unlock() variants? There are a lot of places where locking folio and unlocking page. Thanks. > Aside from that, this looks good: > > Acked-by: Johannes Weiner > Thanks.