Received: by 2002:a89:288:0:b0:1f7:eeee:6653 with SMTP id j8csp108134lqh; Mon, 6 May 2024 12:50:31 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUW9DULAZ6ESH1ZCnWvEYkgxvshE6zY5dfbDP9M7ecgW8lqPP6vDqrm6Re539ur3olHgYbWGRDuKAz+LqZ4hy5qwYWLatv0lwiau8++Qg== X-Google-Smtp-Source: AGHT+IGY5BSkQbIUcoC4RCrd8RVjK66ITOWqFNcMGzQY0pR1Cy0XeNbP7hnsWq/gAQ003UwNbLkH X-Received: by 2002:a05:6358:9394:b0:186:1046:14e4 with SMTP id h20-20020a056358939400b00186104614e4mr13623479rwb.18.1715025030513; Mon, 06 May 2024 12:50:30 -0700 (PDT) Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id ca19-20020a056a02069300b005dbe2220330si10004559pgb.171.2024.05.06.12.50.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 12:50:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-170372-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@redhat.com header.s=mimecast20190719 header.b=Pb15iywg; arc=fail (body hash mismatch); spf=pass (google.com: domain of linux-kernel+bounces-170372-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170372-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 1E44B2816C9 for ; Mon, 6 May 2024 19:50:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 657F115B0E1; Mon, 6 May 2024 19:50:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Pb15iywg" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 8ACDE155A25 for ; Mon, 6 May 2024 19:50:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715025018; cv=none; b=clnJy/lgGmy/YrgBzrAE/PEtrAPwgEARs8b35BTRHCsKRKDYLxNrjUaX+V/BUo35vqPS+k7On7fySffQ8/agbzQajJFeSTaRjJhPksGT3bQSdnAkIAfshU5TinjIH6AxZnXMSYiyhS7KM3MwCg6a+Lepz2JflHZnj7LMis/CAlY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715025018; c=relaxed/simple; bh=UC6Ki0pIiVbiy3okjMnHafK7vvm5E/aH/pr4q15tdlc=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=a74AxQ8TP0uLs5NlIWwa30WNvp+riYNJ6PXkapUjp0LOfEu1vH8MFzPKx4AoKsVy+jrHYyddV7ubyupZWyGN+q8MUYcLbCda+QqzOASRfKsu7PySxlLucHtxCiiKaUO/NJgGdKvJIj2kaNIj7NqoYP6TzPXG5mTjKSDny9YxAqQ= 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=Pb15iywg; arc=none smtp.client-ip=170.10.129.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=1715025015; 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=43neyGYicA9em02DzDluHTB7rZaBqEtPcJZfV5lNzv4=; b=Pb15iywgaiFDh8Ev5bCbacxL/Z4PHLJYeatmDo3IHwhVQTVLbwstZYmyfxHnUwGf/aTpgW NT2C/ApGV5vhOoGggHKrc2hjPrOGzHiIAKu+7z4PUiP3sggx9cyorCAFPAdXJ0QCJ5gbOI jwrnhQdBPKqNu8p9g7caLNmaA9OEn4U= 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-655-QoNQ5uTfMHWFHp2HYC5Q7g-1; Mon, 06 May 2024 15:50:14 -0400 X-MC-Unique: QoNQ5uTfMHWFHp2HYC5Q7g-1 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-41d9e2b4743so12946095e9.1 for ; Mon, 06 May 2024 12:50:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715025013; x=1715629813; 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=43neyGYicA9em02DzDluHTB7rZaBqEtPcJZfV5lNzv4=; b=QEMp7TlnpCOtCUtSbE+Ky3kR7G4xcKZb5mHyuKGfKx0ix/Gvz1b11AYQqNdn1Qo3+y U7QnrXON4u+j4wiARXAtJL7icRMqZnh+r3EYOVovs39YxRKLAbrZOJPSRixqNL56n1U1 9VvXLbSFgv875bNwNc9ghMW0Lnk5eYqaAGdBjoxGkm0XEga2Bx8Kd3OqvaYrKcTUgY0/ 1Nvc3pEQJo+Qii4/oczxQ/lageqW/eN1oeg+Dg2yCQtf7zZhsJqqpcRYoSry0BX59W/r Pw0u6qzn3wsxeJ9eANcURGzGdgMNW4aonwXvlM/2alp1WclpEBO/1KMkBv6KxJHlFz6X 7CFw== X-Forwarded-Encrypted: i=1; AJvYcCUx49JS05SvihF7J8gdiJdvtkEvbBALDV/1E8QoEe7VUJbmm9Hek/DQEnMGNCWL3eqWDrEznb8VeDrIGD+YnfzcJlMQ+X+OZ7BEbUV8 X-Gm-Message-State: AOJu0YwjVrf7mbHuQzKHVRl3ecvbqkySVnTAmlsLBvqBnzpv/JjCRmhl SvwEwB2hoqmLKFEOp2CpmhsdZ9OXigO+Xx0/Zu5iRyxM5bx2NkUahx58+4p9rjYdyQC8lk1ecky GoVy+Bo0sP+p97bs02oP2WO7ctcfQhfrHo3hhYIChc7NZe3J0U6mnmMwtowwB0Q== X-Received: by 2002:a05:600c:1e0b:b0:41a:f936:5326 with SMTP id ay11-20020a05600c1e0b00b0041af9365326mr9691247wmb.15.1715025013220; Mon, 06 May 2024 12:50:13 -0700 (PDT) X-Received: by 2002:a05:600c:1e0b:b0:41a:f936:5326 with SMTP id ay11-20020a05600c1e0b00b0041af9365326mr9691228wmb.15.1715025012753; Mon, 06 May 2024 12:50:12 -0700 (PDT) Received: from [192.168.3.108] (p5b0c6c2e.dip0.t-ipconnect.de. [91.12.108.46]) by smtp.gmail.com with ESMTPSA id gb30-20020a056000459e00b0034e0346317dsm11349632wrb.13.2024.05.06.12.50.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 06 May 2024 12:50:12 -0700 (PDT) Message-ID: Date: Mon, 6 May 2024 21:50:10 +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 , Andrew Morton Cc: 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/E8M7TEwuCZQArqqTCmkG6HGcXFT0V9 PXFNNgV5jXMQRwU0O/ztJIQqsE5LsUomE//bLwzj9IVsaQpKDqW6TAPjcdBDPLHvriq7kGjt WhVhdl0qEYB8lkBEU7V2Yb+SYhmhpDrti9Fq1EsmhiHSkxJcGREoMK/63r9WLZYI3+4W2rAc UucZa4OT27U5ZISjNg3Ev0rxU5UH2/pT4wJCfxwocmqaRr6UYmrtZmND89X0KigoFD/XSeVv jwBRNjPAubK9/k5NoRrYqztM9W6sJqrH8+UWZ1Idd/DdmogJh0gNC0+N42Za9yBRURfIdKSb B3JfpUqcWwE7vUaYrHG1nw54pLUoPG6sA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X9S4g/8 kC4HRcclk8hpyhY2jKGluZO0awwTIMgVEzmTyBphDg/Gx7dZU1Xf8HFuE+UZ5UDHDTnwgv7E th6RC9+WrhDNspZ9fJjKWRbveQgUFCpe1sa77LAw+XFrKmBHXp9ZVIe90RMe2tRL06BGiRZr jPrnvUsUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat In-Reply-To: <20240506192924.271999-1-yosryahmed@google.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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 static void __folio_mod_node_file_state(folio, int nr_pages) { enum node_stat_item idx = NR_FILE_PMDMAPPED; if (folio_test_swapbacked(folio)) idx = NR_SHMEM_PMDMAPPED; __mod_node_page_state(folio_pgdat(folio), idx, nr_pages); } And then simply calling here __folio_mod_node_file_state(folio, -nr_pmdmapped); And likewise in __folio_add_file_rmap() .. will be cleaner. In any case Acked-by: David Hildenbrand -- Cheers, David / dhildenb