Received: by 2002:a89:288:0:b0:1f7:eeee:6653 with SMTP id j8csp97041lqh; Mon, 6 May 2024 12:25:40 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUGbFt7lPzRHRJgrH/LYVzWNzq/WFKg+7KvYU9uwb2tOmxZa+7FFFZ942VmtLWhC2H5QIuiBfrk9xD7sQcPk0/6GSvmhmtwNMkjR6QbVg== X-Google-Smtp-Source: AGHT+IG5ff8vLrYdmCuruMtH5QB7dsrg1NILawgJ0m8l8djhnMWipmvDs6ksXT0QzP/t2LBvt6aM X-Received: by 2002:a05:620a:1984:b0:792:9c83:dbc7 with SMTP id bm4-20020a05620a198400b007929c83dbc7mr1371617qkb.31.1715023539810; Mon, 06 May 2024 12:25:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715023539; cv=pass; d=google.com; s=arc-20160816; b=IoEY7o1h7h//985E4epGp5W2iR5JNQiRk3PLsMtlXVhFYk9znl6B8NLU6xhUJOB8AD XGgTUcVZNA+sSvXijghks8wmUeRRZVl7gU7MJoF5m1/oUGbjpJqO8bLfKare40NSASOT 8H7fI2PwJ+kLYkqiqDAb4O7kG5THyziiLMsQMWZ5GXvTxN1p3PgJuNxl4kYq7Lve7GsW Ky4t012CTCGGJjBmStTT0cobuuK2Dbc2+AMP8ADm5xInR+6/bGBvMwKZvng7mmNstktP gCrfHN/Tn1GMtZgxhYiNNevkmoTuke82pNnf1vaZj8ZU4nAxo3xxRA+EauGMM//22hjJ M+sA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:dkim-signature:date; bh=gxbtAlVeF1/sUOU5uEW9t+ZyL4fh7ysXOylZq3pXva4=; fh=vYLnwnogfBKzPOl4NoKPopZBWqbFr8xrWgAe4TCdeos=; b=f2m7ADRE7eOLqglDM4wIWNjcvgTxzpG8yqT0YSRBB+pPO1vMnIwWBAgpg0QSgCwgu2 PjSwuaXBfHeoW2enUjYjdaMBqI9/4AAeTCOrOqtjSAXnlLff7vHfBG4xQGu8g5duy7d/ I1YQQPKmYfaYsANPVo5e2F01anhsRBfA78Tws8HBdMb5pNZ22u8hT2dMcEvX6ja0l4lB kAFXS+UrfnErQKQM9FaMGjIoFfBHT1D0viRZ+sEMKc9/Uq2CHKZfV1X5UDDZbfzdC7cc EwJ1Nxx5Gwg/pC2DYeZxqNZg4NyiHWRegamBWTK0tM6wepq5DLBWuAxPpNrUkjQU/PdA aa1A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=T9cbPrAc; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-170338-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170338-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id qr10-20020a05620a390a00b0078edf8b7ec7si10812422qkn.747.2024.05.06.12.25.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 12:25:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-170338-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=T9cbPrAc; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-170338-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170338-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 8A9A61C21D40 for ; Mon, 6 May 2024 19:25:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A490D15956D; Mon, 6 May 2024 19:25:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="T9cbPrAc" Received: from out-184.mta0.migadu.com (out-184.mta0.migadu.com [91.218.175.184]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 59E6515921C for ; Mon, 6 May 2024 19:25:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.184 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715023525; cv=none; b=G1GU9HpMxwlZNBAxUyT3W1iiyfSDiLEBnfFolQOU7TjQCvfNTcmcuCI9i/YlRgBhoszweg6kv+2PNJpPz1hZVAD3uXPcRqj8lXFndwzYcN9faZME7Afvswj9EdlSnOxrrWR9i3v92YAkRxM5IBe05QdWCSfGH/9rgEwKSfrnPyo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715023525; c=relaxed/simple; bh=262GQmeTYIr1CgyTlhpiy51LdD2LjO0oEukrAEOG+OY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=IkS5kPlG42sl2RdmgjEWoJLx38nGLDh7lzKt/K5acpliKGz3CutSC48OuKlCudRvS/MI9e6QjL3Q1IAj6JN65FcQ4FR8wQ919LD6M4qKShhUcr39SyYZiQGZ9fgrSM+nWUWqfUgEStnmfvd5093NrdykZSKOvBNr78jU/VHVqMI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=T9cbPrAc; arc=none smtp.client-ip=91.218.175.184 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Date: Mon, 6 May 2024 12:25:15 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1715023521; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=gxbtAlVeF1/sUOU5uEW9t+ZyL4fh7ysXOylZq3pXva4=; b=T9cbPrAcYBtaXsosnsqLQXaQuAZ+LPyXYpdVTa780mNBy7ZSsC/zltH2S8h0boDI8LfmXy sYcDHXn7NMzZ/dlEFAT3/vWtFvdyybg5Lm7dAwyNVsC+0AncWVvtNaY/QUEVU4t9kiA8TM QIlxXVrydo0sNa2WAvWZF0Z6pIfVM0M= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Shakeel Butt To: Yosry Ahmed Cc: Andrew Morton , Johannes Weiner , Michal Hocko , Roman Gushchin , Muchun Song , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, syzbot+9319a4268a640e26b72b@syzkaller.appspotmail.com Subject: Re: [PATCH] mm: do not update memcg stats for NR_{FILE/SHMEM}_PMDMAPPED Message-ID: References: <20240506170024.202111-1-yosryahmed@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240506170024.202111-1-yosryahmed@google.com> X-Migadu-Flow: FLOW_OUT On Mon, May 06, 2024 at 05:00:24PM +0000, Yosry Ahmed wrote: > Do not use __lruvec_stat_mod_folio() when updating NR_FILE_PMDMAPPED and > NR_SHMEM_PMDMAPPED as these stats are not maintained per-memcg. Use > __mod_node_page_state() instead, which updates the global per-node stats > only. > > Reported-by: syzbot+9319a4268a640e26b72b@syzkaller.appspotmail.com > Closes: https://lore.kernel.org/lkml/0000000000001b9d500617c8b23c@google.com > Signed-off-by: Yosry Ahmed I think we can put Fixes either for 443c077dc2ec ("memcg: cleanup __mod_memcg_lruvec_state") or ad86c0f0e089 ("memcg: warn for unexpected events and stats"). > --- > mm/rmap.c | 15 +++++++++------ > 1 file changed, 9 insertions(+), 6 deletions(-) > > diff --git a/mm/rmap.c b/mm/rmap.c > index 12be4241474ab..c2cfb750d2535 100644 > --- a/mm/rmap.c > +++ b/mm/rmap.c > @@ -1435,13 +1435,14 @@ static __always_inline void __folio_add_file_rmap(struct folio *folio, > struct page *page, int nr_pages, struct vm_area_struct *vma, > enum rmap_level level) > { > + pg_data_t *pgdat = folio_pgdat(folio); > int nr, nr_pmdmapped = 0; > > VM_WARN_ON_FOLIO(folio_test_anon(folio), folio); > > nr = __folio_add_rmap(folio, page, nr_pages, level, &nr_pmdmapped); > if (nr_pmdmapped) > - __lruvec_stat_mod_folio(folio, folio_test_swapbacked(folio) ? > + __mod_node_page_state(pgdat, folio_test_swapbacked(folio) ? > NR_SHMEM_PMDMAPPED : NR_FILE_PMDMAPPED, nr_pmdmapped); > if (nr) > __lruvec_stat_mod_folio(folio, NR_FILE_MAPPED, nr); > @@ -1493,6 +1494,7 @@ static __always_inline void __folio_remove_rmap(struct folio *folio, > enum rmap_level level) > { > atomic_t *mapped = &folio->_nr_pages_mapped; > + pg_data_t *pgdat = folio_pgdat(folio); > int last, nr = 0, nr_pmdmapped = 0; > bool partially_mapped = false; > enum node_stat_item idx; > @@ -1540,13 +1542,14 @@ static __always_inline void __folio_remove_rmap(struct folio *folio, > } > > if (nr_pmdmapped) { > + /* NR_{FILE/SHMEM}_PMDMAPPED are not maintained per-memcg */ > if (folio_test_anon(folio)) > - idx = NR_ANON_THPS; > - else if (folio_test_swapbacked(folio)) > - idx = NR_SHMEM_PMDMAPPED; > + __lruvec_stat_mod_folio(folio, NR_ANON_THPS, -nr_pmdmapped); > else > - idx = NR_FILE_PMDMAPPED; > - __lruvec_stat_mod_folio(folio, idx, -nr_pmdmapped); > + __mod_node_page_state(pgdat, > + folio_test_swapbacked(folio) ? > + NR_SHMEM_PMDMAPPED : NR_FILE_PMDMAPPED, > + nr_pmdmapped); After the above fixed, you can add: Acked-by: Shakeel Butt