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=-23.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_IN_DEF_DKIM_WL 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 2CC2BC433B4 for ; Thu, 13 May 2021 17:52:55 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9FA48611CE for ; Thu, 13 May 2021 17:52:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9FA48611CE Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 199126B0036; Thu, 13 May 2021 13:52:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1485A6B006E; Thu, 13 May 2021 13:52:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F03856B0070; Thu, 13 May 2021 13:52:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0200.hostedemail.com [216.40.44.200]) by kanga.kvack.org (Postfix) with ESMTP id BAB506B0036 for ; Thu, 13 May 2021 13:52:53 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 5A991180286CF for ; Thu, 13 May 2021 17:52:53 +0000 (UTC) X-FDA: 78136953426.19.628B972 Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) by imf20.hostedemail.com (Postfix) with ESMTP id 079DD3D9 for ; Thu, 13 May 2021 17:52:51 +0000 (UTC) Received: by mail-wr1-f51.google.com with SMTP id x5so27691240wrv.13 for ; Thu, 13 May 2021 10:52:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=f1A9LeFsvnKWnTM1tIiSlAgEcRbEeG0uXjKs5/7vqDI=; b=HWHH5yGTu4pZlNQMZuPZI9GnAwAi34d61rkoSkEqGQaLbN3PLllL+dV5F7MjsXDqy7 DOUnxJwHgX+ToDOBYH9vjMm5lFsk+3UXl7PQcwDRFql7TfJb/vEc+BERcL17o5IRo3Rc WJkq3b75YGvqqYJ+U0t578HdQF6dWw4HhlgQWwPUI0tDM3COoJaeXmlA472X8mbWb3ZN Pvup8Soe7PZZQjHl7zNtPHvZ6mG19fBAv3OTjLESgeWEVfyErrW6DyJcWn178Uf5hWm8 P87ArC9HAgpzN+24Naa0OFoSiwTYAU5tkVsgWxAtPFBMgEdMslWXKhlixeW7/UtE1cgQ OB2w== 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; bh=f1A9LeFsvnKWnTM1tIiSlAgEcRbEeG0uXjKs5/7vqDI=; b=kNLNJOepmRxKSqlOU+5jntDsgBIhu+vT8l38ekIANRmCTYf7GGm2TzdB9vrauD5JK3 qrIE5ZvzS8KO+x13RUaXVXM/9uL7HcfUh+rADSvw10+jhss2f4JXfd5gXjAk1WBvzNg3 Gl06IfOiShRSgz7qU7JgyRYIo6gc6iDI+CAGxzmGhizqGC9lsDztza3OXVckzD7WIY0G F8qmwmCL79pwtDTjlbPZKfK1LqAFAtZoZznTKsBTLQKHrubSPldnGcndwUy46zk2rSK2 eSCXH33ZzqsimCoLLVlpDev39BjEOSK46zAuB71eRBWnt1xG3daje59DTtgujCDB5fuv 23Gw== X-Gm-Message-State: AOAM530mHYZEDDsxZCYj1nUjy0JrIpCYqUhNk0/2fH1ZsbKkTl0RaAtV Yt+dQRKPRq5RjxE5nUJb5MJXEmQBWyo3a7V2GIxbvBgxkPdD1w== X-Google-Smtp-Source: ABdhPJzfB8+j5147yQZ5jkxNLHrIz85CCSRvZHjWyDpsVRxbz7uaGWDooTezFQdl9GKLBBFEwQLtgslzRRurpDa26tg= X-Received: by 2002:a5d:47a8:: with SMTP id 8mr54046668wrb.124.1620928371597; Thu, 13 May 2021 10:52:51 -0700 (PDT) MIME-Version: 1.0 References: <20210513122702.2245882-1-willy@infradead.org> In-Reply-To: <20210513122702.2245882-1-willy@infradead.org> From: Yu Zhao Date: Thu, 13 May 2021 11:52:39 -0600 Message-ID: Subject: Re: [PATCH] mm/lru: Add folio LRU functions To: "Matthew Wilcox (Oracle)" Cc: Andrew Morton , Linux-MM Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: 079DD3D9 Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20161025 header.b=HWHH5yGT; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf20.hostedemail.com: domain of yuzhao@google.com designates 209.85.221.51 as permitted sender) smtp.mailfrom=yuzhao@google.com X-Rspamd-Server: rspam03 X-Stat-Signature: nebttfqzw4wkdre9gba16woa68hgg7sc X-HE-Tag: 1620928371-778006 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 Thu, May 13, 2021 at 6:28 AM Matthew Wilcox (Oracle) wrote: > > Handle arbitrary-order folios being added to the LRU. By definition, > all pages being added to the LRU were already head or base pages, > so define page wrappers around folio functions where the original > page functions involved calling compound_head() to manipulate flags, > but define folio wrappers around page functions where there's no need to > call compound_head(). The one thing that does change for those functions > is calling compound_nr() instead of thp_nr_pages(), in order to handle > arbitrary-sized folios. > > Saves almost 800 bytes of kernel text; no functions grow. > > Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Yu Zhao > --- > include/linux/mm_inline.h | 85 +++++++++++++++++++++++++++------------ > 1 file changed, 59 insertions(+), 26 deletions(-) > > diff --git a/include/linux/mm_inline.h b/include/linux/mm_inline.h > index 355ea1ee32bd..c9e05631e565 100644 > --- a/include/linux/mm_inline.h > +++ b/include/linux/mm_inline.h > @@ -6,22 +6,27 @@ > #include > > /** > - * page_is_file_lru - should the page be on a file LRU or anon LRU? > - * @page: the page to test > + * folio_is_file_lru - should the folio be on a file LRU or anon LRU? > + * @folio: the folio to test > * > - * Returns 1 if @page is a regular filesystem backed page cache page or a lazily > - * freed anonymous page (e.g. via MADV_FREE). Returns 0 if @page is a normal > - * anonymous page, a tmpfs page or otherwise ram or swap backed page. Used by > - * functions that manipulate the LRU lists, to sort a page onto the right LRU > - * list. > + * Returns 1 if @folio is a regular filesystem backed page cache folio > + * or a lazily freed anonymous folio (e.g. via MADV_FREE). Returns 0 if > + * @folio is a normal anonymous folio, a tmpfs folio or otherwise ram or > + * swap backed folio. Used by functions that manipulate the LRU lists, > + * to sort a folio onto the right LRU list. > * > * We would like to get this info without a page flag, but the state > - * needs to survive until the page is last deleted from the LRU, which > + * needs to survive until the folio is last deleted from the LRU, which > * could be as far down as __page_cache_release. > */ > +static inline int folio_is_file_lru(struct folio *folio) > +{ > + return !folio_swapbacked(folio); > +} > + > static inline int page_is_file_lru(struct page *page) > { > - return !PageSwapBacked(page); > + return folio_is_file_lru(page_folio(page)); > } > > static __always_inline void update_lru_size(struct lruvec *lruvec, > @@ -42,66 +47,94 @@ static __always_inline void update_lru_size(struct lruvec *lruvec, > * __clear_page_lru_flags - clear page lru flags before releasing a page > * @page: the page that was on lru and now has a zero reference > */ > -static __always_inline void __clear_page_lru_flags(struct page *page) > +static __always_inline void __folio_clear_lru_flags(struct folio *folio) > { > - VM_BUG_ON_PAGE(!PageLRU(page), page); > + VM_BUG_ON_FOLIO(!folio_lru(folio), folio); > > - __ClearPageLRU(page); > + __folio_clear_lru_flag(folio); > > /* this shouldn't happen, so leave the flags to bad_page() */ > - if (PageActive(page) && PageUnevictable(page)) > + if (folio_active(folio) && folio_unevictable(folio)) > return; > > - __ClearPageActive(page); > - __ClearPageUnevictable(page); > + __folio_clear_active_flag(folio); > + __folio_clear_unevictable_flag(folio); > +} > + > +static __always_inline void __clear_page_lru_flags(struct page *page) > +{ > + __folio_clear_lru_flags(page_folio(page)); > } > > /** > - * page_lru - which LRU list should a page be on? > - * @page: the page to test > + * folio_lru_list - which LRU list should a folio be on? > + * @folio: the folio to test > * > - * Returns the LRU list a page should be on, as an index > + * Returns the LRU list a folio should be on, as an index > * into the array of LRU lists. > */ > -static __always_inline enum lru_list page_lru(struct page *page) > +static __always_inline enum lru_list folio_lru_list(struct folio *folio) > { > enum lru_list lru; > > - VM_BUG_ON_PAGE(PageActive(page) && PageUnevictable(page), page); > + VM_BUG_ON_FOLIO(folio_active(folio) && folio_unevictable(folio), folio); > > - if (PageUnevictable(page)) > + if (folio_unevictable(folio)) > return LRU_UNEVICTABLE; > > - lru = page_is_file_lru(page) ? LRU_INACTIVE_FILE : LRU_INACTIVE_ANON; > - if (PageActive(page)) > + lru = folio_is_file_lru(folio) ? LRU_INACTIVE_FILE : LRU_INACTIVE_ANON; > + if (folio_active(folio)) > lru += LRU_ACTIVE; > > return lru; > } > > +static __always_inline enum lru_list page_lru(struct page *page) > +{ > + return folio_lru_list(page_folio(page)); > +} > + > static __always_inline void add_page_to_lru_list(struct page *page, > struct lruvec *lruvec) > { > enum lru_list lru = page_lru(page); > > - update_lru_size(lruvec, lru, page_zonenum(page), thp_nr_pages(page)); > + update_lru_size(lruvec, lru, page_zonenum(page), compound_nr(page)); > list_add(&page->lru, &lruvec->lists[lru]); > } > > +static __always_inline void folio_add_to_lru_list(struct folio *folio, > + struct lruvec *lruvec) > +{ > + add_page_to_lru_list(&folio->page, lruvec); > +} > + > static __always_inline void add_page_to_lru_list_tail(struct page *page, > struct lruvec *lruvec) > { > enum lru_list lru = page_lru(page); > > - update_lru_size(lruvec, lru, page_zonenum(page), thp_nr_pages(page)); > + update_lru_size(lruvec, lru, page_zonenum(page), compound_nr(page)); > list_add_tail(&page->lru, &lruvec->lists[lru]); > } > > +static __always_inline void folio_add_to_lru_list_tail(struct folio *folio, > + struct lruvec *lruvec) > +{ > + add_page_to_lru_list_tail(&folio->page, lruvec); > +} > + > static __always_inline void del_page_from_lru_list(struct page *page, > struct lruvec *lruvec) > { > list_del(&page->lru); > update_lru_size(lruvec, page_lru(page), page_zonenum(page), > - -thp_nr_pages(page)); > + -compound_nr(page)); > +} > + > +static __always_inline void folio_del_from_lru_list(struct folio *folio, > + struct lruvec *lruvec) > +{ > + del_page_from_lru_list(&folio->page, lruvec); > } > #endif > -- > 2.30.2 >