From patchwork Wed Feb 16 11:51:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 12748468 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C1E22C433FE for ; Wed, 16 Feb 2022 11:53:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5ACE16B0071; Wed, 16 Feb 2022 06:53:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 535E36B0087; Wed, 16 Feb 2022 06:53:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3AFD96B0088; Wed, 16 Feb 2022 06:53:10 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0129.hostedemail.com [216.40.44.129]) by kanga.kvack.org (Postfix) with ESMTP id 2BDFC6B0071 for ; Wed, 16 Feb 2022 06:53:10 -0500 (EST) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id DE6578249980 for ; Wed, 16 Feb 2022 11:53:09 +0000 (UTC) X-FDA: 79148482098.06.27FD5EA Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) by imf24.hostedemail.com (Postfix) with ESMTP id 4EC60180003 for ; Wed, 16 Feb 2022 11:53:09 +0000 (UTC) Received: by mail-pj1-f53.google.com with SMTP id t14-20020a17090a3e4e00b001b8f6032d96so2154273pjm.2 for ; Wed, 16 Feb 2022 03:53:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hb4Gc01XylgUCngtxENOJFpbWICvKI3FBnXtbBe6mQw=; b=Hv/yV6E/bbCMqR7MM5iHb7bJyd4OPBm0sjIJ3Agnh7p/RUA72ZSwnSAYh6ui3TwcUb FyU50MF38ZlbkCpNny0kgYoGRV0KOuhYait9vzWyUZr7CRuPa6MgqauOfkcV7/tYZ0pU KL39IVOcG7nWuUyj2AXQjciC6hGq/Opoy8kqlQQQNGut9FKkUhMITh7zSDosRc3yLOsu klrE8gpCZ6vATDgd6TC+mpJgnN+XJ/HXQzrOknh73rDR5fVyse2le763zkJXHp599GVG gmy4vKNyMGXp4GqgaslCshQs1MFD3lOHii364ySCYulCbkvKHu7EzK86WBprQsgNKyhD 7u2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hb4Gc01XylgUCngtxENOJFpbWICvKI3FBnXtbBe6mQw=; b=tUqz4lsrL3LkwTS6vhqFd+TfQXGmbP5J8gKedK4HVKDTPGsJZfK8D/cbt0LuOus1bF y+MddyhZ/HZyTGupUIp2d8WzPFaimlYEmVUTsBhoLW6y98AhJb7pqjPvcaeSqjqadsQk 8S4fLzxhwxN1b30VQ911O3PJX2LW0/HIBtEx95pPU5tlCzfuXS4QFnI10J8HE70ZZ5e/ 2a3+BZ6bq79D93Q9FYL08jP5DTYXAs0ByL10sNInD5Vm2PuVImddLUmxwASKZ2znpDTL DpFMoWpg2gTRShmELr/0/SZ3ZeCSxAXnfwp1DPOmWqTmeVIRq9bPFDk8+GsQBHJ6ZEzu hKWQ== X-Gm-Message-State: AOAM533OfVKI5ZsesNK3bA02jTGYtH88bC4QYm7UE/T5DDwCjbg7+1QG 6IZ8w0dnhIV4VcTiuRodZva2Ag== X-Google-Smtp-Source: ABdhPJyXZS3mMwShvFS3X7uagm3iGHbU4H2oEm2bloQpabZs8Juq19OdY6sNgEvStD7wOLFso2+Zdg== X-Received: by 2002:a17:90b:3607:b0:1b8:efe5:9008 with SMTP id ml7-20020a17090b360700b001b8efe59008mr1272889pjb.163.1645012388467; Wed, 16 Feb 2022 03:53:08 -0800 (PST) Received: from FVFYT0MHHV2J.tiktokcdn.com ([139.177.225.249]) by smtp.gmail.com with ESMTPSA id m16sm14790221pfc.156.2022.02.16.03.53.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Feb 2022 03:53:08 -0800 (PST) From: Muchun Song To: guro@fb.com, hannes@cmpxchg.org, mhocko@kernel.org, akpm@linux-foundation.org, shakeelb@google.com, vdavydov.dev@gmail.com Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, duanxiongchun@bytedance.com, fam.zheng@bytedance.com, bsingharora@gmail.com, shy828301@gmail.com, alexs@kernel.org, smuchun@gmail.com, zhengqi.arch@bytedance.com, Muchun Song Subject: [PATCH v3 11/12] mm: lru: add VM_BUG_ON_FOLIO to lru maintenance function Date: Wed, 16 Feb 2022 19:51:31 +0800 Message-Id: <20220216115132.52602-12-songmuchun@bytedance.com> X-Mailer: git-send-email 2.32.0 (Apple Git-132) In-Reply-To: <20220216115132.52602-1-songmuchun@bytedance.com> References: <20220216115132.52602-1-songmuchun@bytedance.com> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 4EC60180003 X-Rspam-User: Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b="Hv/yV6E/"; spf=pass (imf24.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.216.53 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com; dmarc=pass (policy=none) header.from=bytedance.com X-Stat-Signature: mm6pndn4a7b9sk5xcydnmqxycg5mwgbw X-HE-Tag: 1645012389-472624 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: We need to make sure that the page is deleted from or added to the correct lruvec list. So add a VM_BUG_ON_FOLIO() to catch invalid users. Signed-off-by: Muchun Song --- include/linux/mm_inline.h | 15 ++++++++++++--- mm/vmscan.c | 1 - 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/include/linux/mm_inline.h b/include/linux/mm_inline.h index b725839dfe71..8cc134fd3f0b 100644 --- a/include/linux/mm_inline.h +++ b/include/linux/mm_inline.h @@ -105,7 +105,10 @@ void lruvec_add_folio(struct lruvec *lruvec, struct folio *folio) static __always_inline void add_page_to_lru_list(struct page *page, struct lruvec *lruvec) { - lruvec_add_folio(lruvec, page_folio(page)); + struct folio *folio = page_folio(page); + + VM_BUG_ON_FOLIO(!folio_matches_lruvec(folio, lruvec), folio); + lruvec_add_folio(lruvec, folio); } static __always_inline @@ -121,7 +124,10 @@ void lruvec_add_folio_tail(struct lruvec *lruvec, struct folio *folio) static __always_inline void add_page_to_lru_list_tail(struct page *page, struct lruvec *lruvec) { - lruvec_add_folio_tail(lruvec, page_folio(page)); + struct folio *folio = page_folio(page); + + VM_BUG_ON_FOLIO(!folio_matches_lruvec(folio, lruvec), folio); + lruvec_add_folio_tail(lruvec, folio); } static __always_inline @@ -135,7 +141,10 @@ void lruvec_del_folio(struct lruvec *lruvec, struct folio *folio) static __always_inline void del_page_from_lru_list(struct page *page, struct lruvec *lruvec) { - lruvec_del_folio(lruvec, page_folio(page)); + struct folio *folio = page_folio(page); + + VM_BUG_ON_FOLIO(!folio_matches_lruvec(folio, lruvec), folio); + lruvec_del_folio(lruvec, folio); } #ifdef CONFIG_ANON_VMA_NAME diff --git a/mm/vmscan.c b/mm/vmscan.c index 7beed9041e0a..00207553c419 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -2356,7 +2356,6 @@ static unsigned int move_pages_to_lru(struct list_head *list) continue; } - VM_BUG_ON_PAGE(!folio_matches_lruvec(folio, lruvec), page); add_page_to_lru_list(page, lruvec); nr_pages = thp_nr_pages(page); nr_moved += nr_pages;