From patchwork Tue Jun 21 12:56:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 12889212 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 369C6C433EF for ; Tue, 21 Jun 2022 12:58:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C61B56B0072; Tue, 21 Jun 2022 08:58:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C13938E0002; Tue, 21 Jun 2022 08:58:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ADA2F6B0075; Tue, 21 Jun 2022 08:58:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 9FF3C6B0072 for ; Tue, 21 Jun 2022 08:58:32 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 672F7DAB for ; Tue, 21 Jun 2022 12:58:32 +0000 (UTC) X-FDA: 79602246864.12.43782B1 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) by imf05.hostedemail.com (Postfix) with ESMTP id 0DA1B10009C for ; Tue, 21 Jun 2022 12:58:31 +0000 (UTC) Received: by mail-pf1-f172.google.com with SMTP id a15so5838787pfv.13 for ; Tue, 21 Jun 2022 05:58:31 -0700 (PDT) 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=shtH7PIMf3J8dcya3xtagcl4W8V8R+/sKr+kfrLIY6Y=; b=pKDiUQIgj4YaZxnL6yCeczDMoqlNkY/fF9chdQFzHfGrTICA/YrcbElxeDDgKm++4f 6Cxu565+659Mbpd+/mE7x+gUVXxoISE/HC0AN/7bQGI7T2zC2G+4yGW6GKGsgGLiNSbf y7UEpRzdy/p0Tq93+aIN9Ik2CU7UNoB3XcKtE1bfePMgY7rTkTwwqscPFdMO3RNmhIfY 9QxdQEr3AcmrE33LiJxuDqt+aW0wit9ADGaAiEt4Kw2pPCT1u6q7cr38r7hY7aybgITy DvosnAH5V/sCJGZMM25qDYSkhP3+ATsBrPLgsuH6JxtYlZNQUeAcXTsUPlnNGDexLJCF QdIg== 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=shtH7PIMf3J8dcya3xtagcl4W8V8R+/sKr+kfrLIY6Y=; b=Lc1xK03ryCIsQUXtyl64YRBr7X9n9npkkISfFuh7d9Xxa3wjNI7TQE51b97YCO+x6Z FB977ANTd6Q9HT2kvrZiZoE27mSSxct4masr8P/qkh9LVuasBmA1eNmEwLnYuRmc6tq4 FyytYtZa9q184BtcM8MQ4i4LE/kImBfxb8jxZ03Hc1cli82TgMNsicsIHwbJ0jiFwVwo ZSgDINfUnqwJY/cHDGZG+EpM411veRpcMMnbKhw579VVG9usjBOIv01xJadXvYvMOAo5 5jKsOOTaxYRBDkSEiVjgmd9qb5pEz9P6OByMM1eGLdc6vKELvQ1GZLFRewIOeSvPHFaB /y/g== X-Gm-Message-State: AJIora94cfNVAe96OAUy3a5reymSLJIAeDN2V5Tt1qirwUMkJgAkK52L 3p37t8hDSxxRbbvxBAohmdWYtw== X-Google-Smtp-Source: AGRyM1u8ksQyZcIYOxcN0FytSUT2CO9PHE09w2KWxt2Sj0ZFsOL55NgBQbL9f4jw1sdjQKIB9ybP3Q== X-Received: by 2002:a05:6a00:430e:b0:525:26c1:973e with SMTP id cb14-20020a056a00430e00b0052526c1973emr9219577pfb.52.1655816311195; Tue, 21 Jun 2022 05:58:31 -0700 (PDT) Received: from FVFYT0MHHV2J.bytedance.net ([139.177.225.255]) by smtp.gmail.com with ESMTPSA id e3-20020a170903240300b0015ea3a491a1sm10643134plo.191.2022.06.21.05.58.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jun 2022 05:58:30 -0700 (PDT) From: Muchun Song To: akpm@linux-foundation.org, hannes@cmpxchg.org, longman@redhat.com, mhocko@kernel.org, roman.gushchin@linux.dev, shakeelb@google.com Cc: cgroups@vger.kernel.org, duanxiongchun@bytedance.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Muchun Song Subject: [PATCH v6 10/11] mm: lru: add VM_WARN_ON_ONCE_FOLIO to lru maintenance function Date: Tue, 21 Jun 2022 20:56:57 +0800 Message-Id: <20220621125658.64935-11-songmuchun@bytedance.com> X-Mailer: git-send-email 2.32.1 (Apple Git-133) In-Reply-To: <20220621125658.64935-1-songmuchun@bytedance.com> References: <20220621125658.64935-1-songmuchun@bytedance.com> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655816312; a=rsa-sha256; cv=none; b=QXeWpC/sf9QCTt9hXrxoarVZFW8wy6UYLMAnHvkmjGVFDVf/84lfNe3zl7coNPkQZXW9gU zp8AQlVdG+fSFXRBdpbw5y+xgqJNpfMIQosX4dfCkEGOd4tuY1393kr8KA2E1TDlesIXKE +NCQQxLSaomx0TqfCDUESkFxVhBFHSo= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=pKDiUQIg; dmarc=pass (policy=none) header.from=bytedance.com; spf=pass (imf05.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.210.172 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655816312; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=shtH7PIMf3J8dcya3xtagcl4W8V8R+/sKr+kfrLIY6Y=; b=cUNFVAlUibUPSVlVQAvF4BCnnsSKlRbeXzSDW0MI+aACm0tk/6+xGDUORBd7e3phSrQVtH QaKoQqHyYWbMFkiBwP4tuPtd51EQDpP2KxlMfs3fjlSBs11V9QGfCkr8AiTXMxEppOpAza 28cTgax3eCQo3HXjSdYZJ3zzKMMTowM= X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 0DA1B10009C X-Stat-Signature: 5cegf6ma4w6qf3158fjaygbctdq3sd3t X-Rspam-User: Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=pKDiUQIg; dmarc=pass (policy=none) header.from=bytedance.com; spf=pass (imf05.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.210.172 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com X-HE-Tag: 1655816311-808967 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_WARN_ON_ONCE_FOLIO() to catch invalid users. Then the VM_BUG_ON_PAGE() in move_pages_to_lru() could be removed since add_page_to_lru_list() will check that. Signed-off-by: Muchun Song Acked-by: Roman Gushchin --- include/linux/mm_inline.h | 6 ++++++ mm/vmscan.c | 1 - 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/include/linux/mm_inline.h b/include/linux/mm_inline.h index 7b25b53c474a..6585198b19e2 100644 --- a/include/linux/mm_inline.h +++ b/include/linux/mm_inline.h @@ -99,6 +99,8 @@ void lruvec_add_folio(struct lruvec *lruvec, struct folio *folio) { enum lru_list lru = folio_lru_list(folio); + VM_WARN_ON_ONCE_FOLIO(!folio_matches_lruvec(folio, lruvec), folio); + update_lru_size(lruvec, lru, folio_zonenum(folio), folio_nr_pages(folio)); if (lru != LRU_UNEVICTABLE) @@ -116,6 +118,8 @@ void lruvec_add_folio_tail(struct lruvec *lruvec, struct folio *folio) { enum lru_list lru = folio_lru_list(folio); + VM_WARN_ON_ONCE_FOLIO(!folio_matches_lruvec(folio, lruvec), folio); + update_lru_size(lruvec, lru, folio_zonenum(folio), folio_nr_pages(folio)); /* This is not expected to be used on LRU_UNEVICTABLE */ @@ -133,6 +137,8 @@ void lruvec_del_folio(struct lruvec *lruvec, struct folio *folio) { enum lru_list lru = folio_lru_list(folio); + VM_WARN_ON_ONCE_FOLIO(!folio_matches_lruvec(folio, lruvec), folio); + if (lru != LRU_UNEVICTABLE) list_del(&folio->lru); update_lru_size(lruvec, lru, folio_zonenum(folio), diff --git a/mm/vmscan.c b/mm/vmscan.c index 697656151431..51b1607c81e4 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -2361,7 +2361,6 @@ static unsigned int move_pages_to_lru(struct list_head *list) continue; } - VM_BUG_ON_FOLIO(!folio_matches_lruvec(folio, lruvec), folio); lruvec_add_folio(lruvec, folio); nr_pages = folio_nr_pages(folio); nr_moved += nr_pages;