From patchwork Fri Jan 22 22:05:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Zhao X-Patchwork-Id: 12040731 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=-16.6 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT 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 3D872C433DB for ; Fri, 22 Jan 2021 22:06:18 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B7FE223B1B for ; Fri, 22 Jan 2021 22:06:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B7FE223B1B 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 750776B0023; Fri, 22 Jan 2021 17:06:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6FD636B0024; Fri, 22 Jan 2021 17:06:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 578746B0025; Fri, 22 Jan 2021 17:06:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0081.hostedemail.com [216.40.44.81]) by kanga.kvack.org (Postfix) with ESMTP id 356BC6B0023 for ; Fri, 22 Jan 2021 17:06:12 -0500 (EST) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id E9C8182D6B48 for ; Fri, 22 Jan 2021 22:06:11 +0000 (UTC) X-FDA: 77734794942.17.flesh18_13142752756f Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin17.hostedemail.com (Postfix) with ESMTP id CAE18181CCC92 for ; Fri, 22 Jan 2021 22:06:11 +0000 (UTC) X-HE-Tag: flesh18_13142752756f X-Filterd-Recvd-Size: 6373 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf39.hostedemail.com (Postfix) with ESMTP for ; Fri, 22 Jan 2021 22:06:11 +0000 (UTC) Received: by mail-yb1-f201.google.com with SMTP id b62so6898231ybg.1 for ; Fri, 22 Jan 2021 14:06:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=PuLjvynrg4RueR9MnPtl/IKEUZzMuvZcczIQVkHLPxA=; b=is0zDnNnmJbohTyX0ICyl2GWebWoGZO3LYZYq5StpLjdztxZxQ1x6D4pDVi2482Wcv PFiQPq9Z2rZsA1VViLZtfi5aqmmNjb8NfcWwbdbfPOzR6r3ufyMTfhi//kRU8PpSgReq D8YOCZyVonQdyZjCBXQOHqkt4Hfb2a6uj8o/M49WOfP68LB9wKtRqZU4hmV/GBAoiJY2 anDaAB3i+hlhzjqJ1wqYSVewzAfw9Z6/KOBuxmDLh8AdH9EIVPFfDPA1s5N1k/Ibw6Lj wnF5TB35lr9GtfGP3xAPhXb4UMlp9t+ZyEEf95Lgyon4Um8ohy1XJjFFRUSgR2IWRjeu Z9dA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=PuLjvynrg4RueR9MnPtl/IKEUZzMuvZcczIQVkHLPxA=; b=JKmKBKqwE2PcAoIxnskpIVcVSUcXcpKThNIxGkqPsfQ04y2aE8+FHuUDcshdestpez b0BPrIFNeLY7sIPx6rcOsNuw8fvDbFTd7dMu1Ym1IK2W8uPVLAGPQSUUbAl/LJ6iq7JE ecH76b6UTugD66DOGryf69iQm2OO/W8OdVhH6m98nTzR2lM9ci4xgoqKysac3n6FMD0K EmGvtoQplNcYQ1aoANU2NfDdgvRE+3hCJQ9wJ3Fwu3zT0FaMGH+4AvRqxZcTbyJyR5lU f18JtQg0aQEyXVkRaJ89ta9WapeB286Kt/LeRgGqsus2vtBU21Gnt4rQAULvJ0cUUYmJ 3CyQ== X-Gm-Message-State: AOAM530U4ZzGFGqLKTWyYaD9kqgKpgeVmKM+z0yj3C3wvltQmYp23qPs f87/G5WISlRNcdaYBny50NtGVVB4K6c= X-Google-Smtp-Source: ABdhPJyRTcSRQhsSHaqqODslMrw0qd1Ys4U9WBeBKQcEiersSME0lIFIEZYEZdLFapETlRej2mLSzFfviX0= X-Received: from yuzhao.bld.corp.google.com ([2620:15c:183:200:5129:9a91:ef0e:c1a9]) (user=yuzhao job=sendgmr) by 2002:a25:4296:: with SMTP id p144mr9927779yba.428.1611353170659; Fri, 22 Jan 2021 14:06:10 -0800 (PST) Date: Fri, 22 Jan 2021 15:05:56 -0700 In-Reply-To: <20210122220600.906146-1-yuzhao@google.com> Message-Id: <20210122220600.906146-7-yuzhao@google.com> Mime-Version: 1.0 References: <20210122220600.906146-1-yuzhao@google.com> X-Mailer: git-send-email 2.30.0.280.ga3ce27912f-goog Subject: [PATCH v2 06/10] mm: add __clear_page_lru_flags() to replace page_off_lru() From: Yu Zhao To: Andrew Morton , Hugh Dickins , Alex Shi Cc: Michal Hocko , Johannes Weiner , Vladimir Davydov , Roman Gushchin , Vlastimil Babka , Matthew Wilcox , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Yu Zhao 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: Similar to page_off_lru(), the new function does non-atomic clearing of PageLRU() in addition to PageActive() and PageUnevictable(), on a page that has no references left. If PageActive() and PageUnevictable() are both set, refuse to clear either and leave them to bad_page(). This is a behavior change that is meant to help debug. Link: https://lore.kernel.org/linux-mm/20201207220949.830352-7-yuzhao@google.com/ Signed-off-by: Yu Zhao --- include/linux/mm_inline.h | 28 ++++++++++------------------ mm/swap.c | 6 ++---- mm/vmscan.c | 3 +-- 3 files changed, 13 insertions(+), 24 deletions(-) diff --git a/include/linux/mm_inline.h b/include/linux/mm_inline.h index ffacc6273678..ef3fd79222e5 100644 --- a/include/linux/mm_inline.h +++ b/include/linux/mm_inline.h @@ -61,27 +61,19 @@ static inline enum lru_list page_lru_base_type(struct page *page) } /** - * page_off_lru - which LRU list was page on? clearing its lru flags. - * @page: the page to test - * - * Returns the LRU list a page was on, as an index into the array of LRU - * lists; and clears its Unevictable or Active flags, ready for freeing. + * __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 enum lru_list page_off_lru(struct page *page) +static __always_inline void __clear_page_lru_flags(struct page *page) { - enum lru_list lru; + __ClearPageLRU(page); - if (PageUnevictable(page)) { - __ClearPageUnevictable(page); - lru = LRU_UNEVICTABLE; - } else { - lru = page_lru_base_type(page); - if (PageActive(page)) { - __ClearPageActive(page); - lru += LRU_ACTIVE; - } - } - return lru; + /* this shouldn't happen, so leave the flags to bad_page() */ + if (PageActive(page) && PageUnevictable(page)) + return; + + __ClearPageActive(page); + __ClearPageUnevictable(page); } /** diff --git a/mm/swap.c b/mm/swap.c index 94532799ed82..38900d672051 100644 --- a/mm/swap.c +++ b/mm/swap.c @@ -84,9 +84,8 @@ static void __page_cache_release(struct page *page) lruvec = lock_page_lruvec_irqsave(page, &flags); VM_BUG_ON_PAGE(!PageLRU(page), page); - __ClearPageLRU(page); del_page_from_lru_list(page, lruvec); - page_off_lru(page); + __clear_page_lru_flags(page); unlock_page_lruvec_irqrestore(lruvec, flags); } __ClearPageWaiters(page); @@ -911,9 +910,8 @@ void release_pages(struct page **pages, int nr) lock_batch = 0; VM_BUG_ON_PAGE(!PageLRU(page), page); - __ClearPageLRU(page); del_page_from_lru_list(page, lruvec); - page_off_lru(page); + __clear_page_lru_flags(page); } __ClearPageWaiters(page); diff --git a/mm/vmscan.c b/mm/vmscan.c index 7c65d47e6612..452dd3818aa3 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1849,8 +1849,7 @@ static unsigned noinline_for_stack move_pages_to_lru(struct lruvec *lruvec, SetPageLRU(page); if (unlikely(put_page_testzero(page))) { - __ClearPageLRU(page); - __ClearPageActive(page); + __clear_page_lru_flags(page); if (unlikely(PageCompound(page))) { spin_unlock_irq(&lruvec->lru_lock);