Received: by 2002:a05:6a10:c7d3:0:0:0:0 with SMTP id h19csp14584pxy; Fri, 13 Aug 2021 22:27:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxVy8e2e7MmOikz3lb5j31Zwt82WiRoM5hMLFyEoQ8xlm/wDKZf7LpmeOZxEtwF4H+dPJz/ X-Received: by 2002:a05:6e02:1b0e:: with SMTP id i14mr3934057ilv.69.1628918872292; Fri, 13 Aug 2021 22:27:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628918872; cv=none; d=google.com; s=arc-20160816; b=UdREW2rDCH/037teQkGCu5EaiMgI/x5uWNPsz8TtZUgWSg8fUZd6kxJRnhtuNL3Uib ctCvzsbbyveTAT/aKYclupD+8ruJrgyUmF4RENw9MHyKNP47Mpx4AwbjWowvGs3Jg6j2 4RjV8rfCTxQpn1oX7jz/gUJojuoM9h1/f7aXPlbhJJ3IY4bRX4uurDixVgR57naW+oPn qKBi//3C4FwPxYAkT7Pp3aIeJGrOJw8u3EAWv0iwyvL3sv+xHVLNM5Cf/J/7G3JyYKQD qsbTC+UOMPA5CrvjaqtpppZp6o2vnfI/1qYBHrjwCexXn6+lmW0k8hjLkJbbmoHnelZe gwAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=QA9/p/h+KpQBCu0VXssIO4coGl6opMzNI5lAhcd+PlA=; b=JCE+bYAibDl4cu8Xwf+iohcJiGXIxcfr+tBZYMhJzOBPIfvukZFPED7ca+i1h5h8Ee ct53bNS9U0AFNigwijVemYS+0e6lD6C2B2wtqTUkmMoVowsgbuLhzuPr8WAWsLZl68LW YbKk4e8Vnlg0RUesctqd4eVGUviMsoBiPFB7JzkUo6O7lb8w9UvDmJyjsYhgoI62cM30 pCcs2mI6J3w+YXDg1W2Nve40ms2w74pOnRIZfA1WTWMssJAAQJRE2Zuldx3r+SF943ho C2C13F5O0+HhXXNi24/mox/4cK1UBaaQJUSxo3d0Z3y+6LmPx0nzWSB/g0eAoypSBRI3 3elQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=KDQ5YMhg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e16si3977433ilm.91.2021.08.13.22.27.41; Fri, 13 Aug 2021 22:27:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=KDQ5YMhg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236879AbhHNF1F (ORCPT + 99 others); Sat, 14 Aug 2021 01:27:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237307AbhHNF1F (ORCPT ); Sat, 14 Aug 2021 01:27:05 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53929C061575 for ; Fri, 13 Aug 2021 22:26:37 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id n13-20020a17090a4e0d00b0017946980d8dso4896773pjh.5 for ; Fri, 13 Aug 2021 22:26:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QA9/p/h+KpQBCu0VXssIO4coGl6opMzNI5lAhcd+PlA=; b=KDQ5YMhgkeEAvreorbhUVEHxzOIds006yyG7sFmzuFq31cEDc/SNg2TOFchU4xbqWa 1XBG/aepaxXn4ctwfkD+f/wOUrWBRIMwaiB/0STszbdDRmsudQEoxsiLYs+6OMrNMJmB lNnQy25bdCLe9AuL4d7jAWRz+ndeHYY94Nn9oZEZoNugTMW9s5H3sbODiyzgNZyUnu+R y5KbGSFShj/a7gotHGrE44xj0sl1YilJ1zP19RRFJhAZpTYnFgzpUTJG5HHTeNOY75vA ZCLc90EFBuIz3S94EHEGHwZZxcvZnVnCXiwTvgtNKIrH0DnSsXops3lWSlu3cQ7tjJNW tHqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QA9/p/h+KpQBCu0VXssIO4coGl6opMzNI5lAhcd+PlA=; b=CKhcPGOhrh36WltX15p6CuzT+kVDXyJKFgJ1A0V7bDTlAjgiY7LUSsp0XTyqgQS03m joylt6V15AgotlVsvcsS3RFKCwP41YnwA+GtbNLGmmLE+ntjmmizvNbINePUmFBwNCbo SoeAR9Z6ZiCNcklHloGvzBTAr26xr8GSoUJT7zrlkFCRnc9N3ba3hyCpYMLnWOw7pUa3 2DnZAOe7KUNhq8D3bI4fSrhlJUxdPa4vRltocA5OWTr1sj7emALVF4Tzepo0j35eROdN X3yIbFUqxTIhyJNvq48U58Ln6czsMIKyXgXnt2xkqkbQ6r5o2irRn6N7EN4Pe9P4sHVj VLpQ== X-Gm-Message-State: AOAM531D34IvAztL3KYA4aoWnmXwgfsyXIpREg1pXVRKMUmaVQ7gyGzG esojJqoaaGvgqDy34bwrxcK1iw== X-Received: by 2002:a65:62c1:: with SMTP id m1mr5447376pgv.339.1628918796923; Fri, 13 Aug 2021 22:26:36 -0700 (PDT) Received: from localhost.localdomain ([139.177.225.237]) by smtp.gmail.com with ESMTPSA id s5sm4783133pgp.81.2021.08.13.22.26.31 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Aug 2021 22:26:36 -0700 (PDT) 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 v1 11/12] mm: lru: add VM_BUG_ON_FOLIO to lru maintenance function Date: Sat, 14 Aug 2021 13:25:18 +0800 Message-Id: <20210814052519.86679-12-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20210814052519.86679-1-songmuchun@bytedance.com> References: <20210814052519.86679-1-songmuchun@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 e2ec68b0515c..60eb827a41fe 100644 --- a/include/linux/mm_inline.h +++ b/include/linux/mm_inline.h @@ -103,7 +103,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 @@ -119,7 +122,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 @@ -133,6 +139,9 @@ 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); } #endif diff --git a/mm/vmscan.c b/mm/vmscan.c index 8ce42858ad5d..902d36ec91a3 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -2204,7 +2204,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; -- 2.11.0