Received: by 2002:a89:288:0:b0:1f7:eeee:6653 with SMTP id j8csp126763lqh; Mon, 6 May 2024 13:31:53 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUEKHL+jgb29WwkmLPEWgpb/G29X1ESxCSb3AVp0wVsJCtXUOoT235WZbeuLeQLtrKH5OL/dVXZ0CL5V6IJtIvnhhzybG0iFgJYtxhnTw== X-Google-Smtp-Source: AGHT+IG/fMSa14SiBuYu0UBGlAEGMzrDZ+OfYlKL+GG2iR0bZK6zRJm150JeCS0b71jwzjkDCoU1 X-Received: by 2002:a05:6830:916:b0:6ee:4081:2e7 with SMTP id v22-20020a056830091600b006ee408102e7mr14949639ott.0.1715027512803; Mon, 06 May 2024 13:31:52 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715027512; cv=pass; d=google.com; s=arc-20160816; b=1K6eR98qWgaHzTijZQxmB+g80AFhQNJIx0otJYtJsZrqGZRQeux4YuEoAiJWx3GC3+ Rb9uf9oN/dMBCqVCTvUaIgmnvKSOzR5OqQmYJ7legXMfyjjhsBmGu8lIXUdSKejvagxc ZF22D50CfGVqyAU4/+jSCb/ujidVibNpifi/vQ71u6eVUJamNM3U3UK9s0OXuvh8b4dH Q7J9t52lztWK30FOXHGZ6GtOHbvgTNzTZqAcjtrnw7ZZWHHxlNF1RyESrFRSKYXItx7X gWKp1vU7j3HLThE1g33xr0V24GUqBajarNzeNzo2lRjPi21PjJhR+EOs4TXgE1yMiJqg 4dyg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:organization:autocrypt :content-language:from:references:cc:to:subject:user-agent :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :date:message-id:dkim-signature; bh=Ufdh+EVuNbhhg/Fs9LCV9pYz2tN7lfjT8/BykYZkopE=; fh=RCVygDTfjdFv+UEJgQ4ZiCoLaga8sjrjLnUlOPfnAUU=; b=qe+dsbiyqCbs3UzpKKIUzQT+5/5V9yDu3hs+m/PXSyk4mdyTwpNBE+n4iOx7KiQpFV tBiJFoMVNjShuJshJ31aJhLgIBj3Hh3bMpKseSth/y0EguEUOidTjW8eG91i6s07WZeu 63aKwScDqdd3AqS42ajd2OZDs8YxE5Y+XQIe+mcZLOUgj1nbDYXJa0fU/CRfGG1JbHKN jMpfnpcpQRARggdasq6gjS8BR20Oq7ChNyYt1NVDLWiowD4jlxdHjgSvb6qKGR5k5hHZ l3HggV8mdrYirHO3PnJ8ckDLrMaDEUvQJsXY24LABIvGtzFYdqN+x/aEfaSPb4l0hjCB FnJA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=eMELAxaz; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-170397-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170397-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id p25-20020a05620a113900b0079291d3a25esi4676102qkk.522.2024.05.06.13.31.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 13:31:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-170397-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=eMELAxaz; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-170397-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170397-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com 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 742EE1C20923 for ; Mon, 6 May 2024 20:31:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C06C515B137; Mon, 6 May 2024 20:31:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="eMELAxaz" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 9935F15250A for ; Mon, 6 May 2024 20:31:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715027505; cv=none; b=iOzg4D/wFK9ykFsXxat8oKbGPDzBUC5og3/evWqxKgAGC5frN8ZHSS8b6WPmdumWb7zjXCGXZoDEY8N/drsiZGjtPdm54MY0UvGvQLvMl1CZtOF+SK1CvnaHw2YpQVM4nEmeepRl4+aVqOOx76wYjKQ+BRRUCVi0lfuqFLvu7cA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715027505; c=relaxed/simple; bh=8J9HCTMFlsb3siLQBsDJafo+aPcJo4k9kbndliCU/5w=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=bV4+jruDMt3F7KfMHgzKSpxPLSIsXFaWUbD3Q+Rd4sNSdztPVeqWWXD6CSnPX1ZJ7vkyu4snp+uF5+n/9Al9RhZPdj7lM8kKcQnQPpbdB75o25w+rKUG93ZUTFAh6rq8cfZKLZSxRDXs4C5Rmkct9oyBqbugrRqyF0Hf2SLwF7s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=eMELAxaz; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715027501; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=Ufdh+EVuNbhhg/Fs9LCV9pYz2tN7lfjT8/BykYZkopE=; b=eMELAxazqj/nN+EFK4vv8h0A/AstxCtGv1HCewAt7qhdTlHtIzcCsbGaIfhRca3uk4iR20 tX7kasL6QSsj5+k7tb2rYoepfAtw3HlNY4800j91JIZ/kxR1EdxMhnXUWSRtFtAI2YSu2n 1cT2l3W2dWRyVXKaYZRLwrnxhbeSrIo= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-688-5hFldUTWPOe3vXJryv-MUA-1; Mon, 06 May 2024 16:31:40 -0400 X-MC-Unique: 5hFldUTWPOe3vXJryv-MUA-1 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-41dc9f97c7eso23516945e9.1 for ; Mon, 06 May 2024 13:31:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715027499; x=1715632299; h=content-transfer-encoding:in-reply-to:organization:autocrypt :content-language:from:references:cc:to:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=Ufdh+EVuNbhhg/Fs9LCV9pYz2tN7lfjT8/BykYZkopE=; b=deqoDFrZbTJ7jaPkW5Mr1zowCkRhflcy0s4JNOqMln45AGbcSaZWkgUCc7QBaNkZ2x bdHzbHKrQcP3jr03ETtTs3CEWcM2JbkMXNhlMnVl9Iz0m628KUaT4XX83qg0KHFV0iV6 8+LdfxSWtM2/FezvuEWzacv/B1g+hdr3LnNAzkwBTemIoluhZ2lBVoN5B33bDgGqCU2F 1OQi8ecO7VH4NRJa9o3zM0gA1xl8m3JiZQxWStfUkdgpmnChGzK0pzsUoQguPfxmON71 y8qxC7QwrWGBDys9ycKEkkuADzqpc+Ts5BH+p5FGaR1PytzvB+DgOK/eOJUrrwnvaG4U IDVQ== X-Forwarded-Encrypted: i=1; AJvYcCXromaZyMd2DN/wS3/FYyOe00WQFXRZLyaUz97BLcxsg2gZa9NL47RN52JNIRqhzrUlDJ55fdqUDGeOqKGM3lgUC4cJLiHVTH7FvtrY X-Gm-Message-State: AOJu0Yy5bpnTYsBQSIuUtRMKLWtNIKMFztvsSmTL00ieyc8FgU7jQjJe Qo3eNfUR3SACt6t/0aWrC76YG2iDXrzS70u1BEAhbxlAJiZfSF83wM5mz0CPvaZCw4up4rR3tyR N5xH8LgJztRhXo/zzfwWEwNlJbkUkJLd54GkRya9NyXnAHSDJ/X8PysjlUZjPcA== X-Received: by 2002:a05:600c:458f:b0:418:2ab6:7123 with SMTP id r15-20020a05600c458f00b004182ab67123mr640866wmo.10.1715027498757; Mon, 06 May 2024 13:31:38 -0700 (PDT) X-Received: by 2002:a05:600c:458f:b0:418:2ab6:7123 with SMTP id r15-20020a05600c458f00b004182ab67123mr640827wmo.10.1715027498275; Mon, 06 May 2024 13:31:38 -0700 (PDT) Received: from ?IPV6:2003:cb:c74b:bf00:182c:d606:87cf:6fea? (p200300cbc74bbf00182cd60687cf6fea.dip0.t-ipconnect.de. [2003:cb:c74b:bf00:182c:d606:87cf:6fea]) by smtp.gmail.com with ESMTPSA id v23-20020a5d5917000000b00346ceb9e060sm11412293wrd.103.2024.05.06.13.31.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 06 May 2024 13:31:37 -0700 (PDT) Message-ID: <42b09dc5-cfb1-4bd7-b5e3-8b631498d08f@redhat.com> Date: Mon, 6 May 2024 22:31:36 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] mm: do not update memcg stats for NR_{FILE/SHMEM}_PMDMAPPED To: Yosry Ahmed Cc: Andrew Morton , Shakeel Butt , 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 References: <20240506192924.271999-1-yosryahmed@google.com> From: David Hildenbrand Content-Language: en-US Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qaSr0ID2sz5jtBLRb15RMre27E1ImpaIv2Jw8NJgW0k/D1RyKCwaTsgRdwuK Kx/Y91XuSBdz0uOyU/S8kM1+ag0wvsGlpBVxRR/xw/E8M7TEwuCZQArqqTCmkG6HGc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e0uo06XMaY7UHS341ozXUUI7wC7iKfoUTv03iO9El5f XpNMx/YrIMduZ2+nd9Di7o5+KIwlb2mAB9sTNHdMrXesX8eBL6T9b+MZJk+mZuPxKNVfEQMQ a5SxUEADIPQTPNvBewdeI80yeOCrN+Zzwy/Mrx9EPeu59Y5vSJOx/z6OUImD/GhX7Xvkt3kq Er5KTrJz3++B6SH9pum9PuoE/k+nntJkNMmQpR4MCBaV/J9gIOPGodDKnjdng+mXliF3Ptu6 3oxc2RCyGzTlxyMwuc2U5Q7KtUNTdDe8T0uE+9b8BLMVQDDfJjqY0VVqSUwImzTDLX9S4g/8 kC4HRcclk8hpyhY2jKGluZO0awwTIMgVEzmTyBphDg/Gx7dZU1Xf8HFuE+UZ5UDHDTnwgv7E th6RC9+WrhDNspZ9fJjKWRbveQgUFCpe1sa77LAw+XFrKmBHXp9ZVIe90RMe2tRL06BGiRZr jPrnvUsUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 06.05.24 22:18, Yosry Ahmed wrote: > On Mon, May 06, 2024 at 09:50:10PM +0200, David Hildenbrand wrote: >> On 06.05.24 21:29, Yosry Ahmed wrote: >>> Previously, all NR_VM_EVENT_ITEMS stats were maintained per-memcg, >>> although some of those fields are not exposed anywhere. Commit >>> 14e0f6c957e39 ("memcg: reduce memory for the lruvec and memcg stats") >>> changed this such that we only maintain the stats we actually expose >>> per-memcg via a translation table. >>> >>> Additionally, commit 514462bbe927b ("memcg: warn for unexpected events >>> and stats") added a warning if a per-memcg stat update is attempted for >>> a stat that is not in the translation table. The warning started firing >>> for the NR_{FILE/SHMEM}_PMDMAPPED stat updates in the rmap code. These >>> stats are not maintained per-memcg, and hence are not in the translation >>> table. >>> >>> Do not use __lruvec_stat_mod_folio() when updating NR_FILE_PMDMAPPED and >>> NR_SHMEM_PMDMAPPED. 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 >>> Fixes: 514462bbe927 ("memcg: warn for unexpected events and stats") >>> Acked-by: Shakeel Butt >>> Signed-off-by: Yosry Ahmed >>> --- >>> mm/rmap.c | 15 +++++++++------ >>> 1 file changed, 9 insertions(+), 6 deletions(-) >>> >>> diff --git a/mm/rmap.c b/mm/rmap.c >>> index 12be4241474ab..ed7f820369864 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_pgdat(folio) should fit here easily. :) >> >> But I would actually suggest something like the following in mm/rmap.c > > I am not a big fan of this. Not because I don't like the abstraction, > but because I think it doesn't go all the way. It abstracts a very > certain case: updating nr_pmdmapped for file folios. > Right. It only removes some of the ugliness ;) > I think if we opt for abstracting the stats updates in mm/rmap.c, we > should go all the way with something like the following (probably split > as two patches: refactoring then bug fix). WDYT about the below? > > diff --git a/mm/rmap.c b/mm/rmap.c > index 12be4241474ab..70d6f6309da01 100644 > --- a/mm/rmap.c > +++ b/mm/rmap.c > @@ -1269,6 +1269,28 @@ static void __page_check_anon_rmap(struct folio *folio, struct page *page, > page); > } > > +static void __foio_mod_stat(struct folio *folio, int nr, int nr_pmdmapped) > +{ > + int idx; > + > + if (nr) { > + idx = folio_test_anon(folio) ? NR_ANON_MAPPED : NR_FILE_MAPPED; > + __lruvec_stat_mod_folio(folio, idx, nr); > + } > + if (nr_pmdmapped) { > + if (folio_test_anon(folio)) { > + idx = NR_ANON_THPS; > + __lruvec_stat_mod_folio(folio, idx, nr_pmdmapped); > + } else { > + /* NR_*_PMDMAPPED are not maintained per-memcg */ > + idx = folio_test_swapbacked(folio) ? > + NR_SHMEM_PMDMAPPED : NR_FILE_PMDMAPPED; > + __mod_node_page_state(folio_pgdat(folio), idx, > + nr_pmdmapped); > + } > + } > +} > + I didn't suggest that, because in the _anon and _file functions we'll end up introducing unnecessary folio_test_anon() checks that the compiler cannot optimize out. But at least in the removal path it's a clear win. -- Cheers, David / dhildenb