Received: by 2002:a89:288:0:b0:1f7:eeee:6653 with SMTP id j8csp135727lqh; Mon, 6 May 2024 13:53:51 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUf79QDiTktybVhBjsxVgRtP2iZqVEhw/Og9Ng6KlzV0Wq8L3mFLOGlZxndY6hrkZBmT4g1Wv2mcBtDF4PwUv6Xucy0iTjBxUqXpx03Eg== X-Google-Smtp-Source: AGHT+IGsEDk+Oo2tLbTzl+OTLO4Tp4HQUmrYBrb1ukI5II5mGn7nOs2eBNxGfWa3Jnu3fhBDSCSu X-Received: by 2002:a05:6a00:1306:b0:6e7:29dd:84db with SMTP id j6-20020a056a00130600b006e729dd84dbmr14226611pfu.31.1715028831297; Mon, 06 May 2024 13:53:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715028831; cv=pass; d=google.com; s=arc-20160816; b=SfsAtugCOqsm19kcr5ozw7JGNkX8Tz5B47kKKhA0ibL+ImGb4EXTrNQavhQoT6Upit iKtfv6h5nD22g15pVURyrQYtAQBEu81qHwpERgjRdQntWRNbtXV4P/5YArY+g7+oUQ4N DYMOD1+QSsx/AKSocXdhX0X3hOh1O/GvyZ/DK9ByO5NxFKQkzBElXMSX1e05L1fvQ+fw TaReDpBxYkHjVvkd6uFafjangi6nlbpLjKPsUSkJ6TFa2xN719we97mOOeN1GEl1cPeN 14mWEhOEjSWDe5Lz1pxtpl+yGNxDxc4oHHDCQQYHIXpxu5lqMjs8TuszYS0D9stQA+Rn 6qBg== 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=g6sZw134VQmMlIGhxEPVPz2EDdHDR3NFPzKEHXmWo0Q=; fh=8nASS3pHpokrUc6eV2jTtBojkMu/2Gb7AmloN2HvFEo=; b=YwfsZbHZEr7hqEZ+Hpyynod04MtyLBG4A0V6iluEaFHjMHZD4EgV4zEGEQ70XfWJo3 teUlEe79xP5xzihQQDhIwNAZk1BbNptSx5FC1xhZTdKD3RqZ/uSCfcd+MS1qistAsiX/ 5Qa1nHdKYUPeGmQ19/G5IIqy+qCbgpWBVTRzgi2DZCoqTIW3DIBAfxF9gRlqZT4X5U+C 07svkSXILQut06/Zt3IyybJQFyE5hQuEWYGEHjmw/UVoS10K/Esw9WCRFLUy5xKNVP/E xFyz25SLqZ62rezd2gGJKfBmASqanZ4+aQjR9xj/Iu4vFnVRHBSMWe4zW3CSRcDW1hyU zt6w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=U1upf4x4; 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-170416-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170416-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id h71-20020a63834a000000b0062c2edaa062si55685pge.54.2024.05.06.13.53.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 13:53:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-170416-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=U1upf4x4; 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-170416-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170416-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 32979B20C4C for ; Mon, 6 May 2024 20:53:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3561515B96B; Mon, 6 May 2024 20:53:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="U1upf4x4" 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 3B84015ADBA for ; Mon, 6 May 2024 20:53:33 +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=1715028815; cv=none; b=pK+loZYW7kM2QWX7yNDy1ebfGgs2eRLcWHfk6gIdeFy52+kQPA4vbWvjHhawDXNrkJ+RoE8gVQ9NshfsR4h70B0q71OC4Ev1+5XnMEtdVpMYbjHQFP6EYEBNZZxicwTy1bluLp7tWL7x02Tum/2BjnqesfmcZiC1JCWywuo6Wt0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715028815; c=relaxed/simple; bh=SOrr1nenzAriLe0GnDo7AsSNuockUJ6/CCRk2fh8qKE=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=UPKWEBdmg6LwzVPdRyaCmHQVWCNmhkY7mfBiIjamv+QBxVsl9pisuWRT7cpOqFxK0CXlR85UXF2ZHP9hmUCzQEBvt3cZZCa01ByP09vzKKECiCJtOgozjGFcDqmN5tpJRnsUMYeaE6PdeeIxCEfqt2jfmAkR5dKRsHQOWajMqOc= 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=U1upf4x4; 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=1715028813; 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=g6sZw134VQmMlIGhxEPVPz2EDdHDR3NFPzKEHXmWo0Q=; b=U1upf4x4Rcoz5AgVTMbApO7WDMYcs/qJUN7thQ7L4ftOoXhvbC8Fb5k543zaUaNyGrMgI3 GzXDrgVniDPq8T+uyRdb0d7k4/nqPSFh9Mss6vz7yhrshHkuDGHtbMCBqqxFoVjnQxzXij d5AetmQrHhrAXwT2Mvpsxv1SRXJEENE= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-631-ggJMnFKuPMWuAPGBLNimGA-1; Mon, 06 May 2024 16:53:31 -0400 X-MC-Unique: ggJMnFKuPMWuAPGBLNimGA-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-418f18458a0so13345145e9.0 for ; Mon, 06 May 2024 13:53:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715028811; x=1715633611; 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=g6sZw134VQmMlIGhxEPVPz2EDdHDR3NFPzKEHXmWo0Q=; b=GThn8xsym62XGKqFY3nkIECBJRk9DEfAcc08vB+izcQ6KMqxBM6Not6gmoTQnyXXLY yEURg383UAKE06g1DJtz7S5p46CbShvWDxv9XwS+enFtfrOcGNc3T+3IPUd7KDWJy6Qv HLmttv6qOe71zmJiF3/0ZLHsuEQilzZpSA5ATv9+ZiBIvain9d0xGHUZtmnZShKr0AcS 72OMIPu2pGg6oEQFyqQOz1jvY1W3DkrL3cZS5W5SdfXfCbVZ5wyZVy2Yy4Ee1ZMUeCh4 BznG/J/WaX/Tk253rg2ojwCiOs5e/Lj5e4PHRjeRvCHVZXum2Ii3kFD8TiCmqnjmeh5U pi8g== X-Forwarded-Encrypted: i=1; AJvYcCVpi7m71p9Fuvog9uGlH+lKB96UYtlpcDKS4qmgwlW4W4b8WaZP1ElfCZSUTxd8r3g9r/e4r3E2rmx3JYKHcnmo2gGbsOL75aIotQcC X-Gm-Message-State: AOJu0YwH6/XpNI7baK8NmQtH9ZExsgf9qsgDx1NAEWZbPIPFD0Pb9t+s xOWZerHmwD2bhpGKb1gXqeCL/9eyY1lTtHHwZh+yA3mlhlw3dC9ldzqKGDTaFbA81f0aZRNRJFH NnCVYL0hSyFioqzeZaoLO72yVB+do5hwvmr3/mHdkIXEVHJf0GvkWhDgJE3QlCF6ZGVi4xA== X-Received: by 2002:a05:600c:3148:b0:41a:bdaf:8c78 with SMTP id h8-20020a05600c314800b0041abdaf8c78mr9056659wmo.8.1715028810716; Mon, 06 May 2024 13:53:30 -0700 (PDT) X-Received: by 2002:a05:600c:3148:b0:41a:bdaf:8c78 with SMTP id h8-20020a05600c314800b0041abdaf8c78mr9056640wmo.8.1715028810231; Mon, 06 May 2024 13:53:30 -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 l27-20020a05600c1d1b00b0041c5151dc1csm20990620wms.29.2024.05.06.13.53.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 06 May 2024 13:53:29 -0700 (PDT) Message-ID: Date: Mon, 6 May 2024 22:53:28 +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> <42b09dc5-cfb1-4bd7-b5e3-8b631498d08f@redhat.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/D1RyKCwaTsg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32Ms6t1trDQmPx2iP5+7iDsb7OKAb5eOS8h+BEBDeq 3ecsQDv0fFJOA9ag5O3LLNk+3x3q7e0uo06XMaY7UHS341ozXUUI7wC7iKfoUTv03iO9El5f 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: 8bit On 06.05.24 22:41, Yosry Ahmed wrote: > On Mon, May 6, 2024 at 1:31 PM David Hildenbrand wrote: >> >> 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 do this we just add one unnecessary layer of indirection > to one case. If anything people will wonder why we have a helper only > for this case. Just my 2c :) > >> >>> 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. > > I convinced myself that the folio_test_anon() will be #free because > the struct folio should be already in the cache at this point, of > course I may be delusional :) Well, nothing is free :) But yes, likely it won't matter much. > > We can pass in an @anon boolean parameter, but it becomes an ugliness > tradeoff at this point :) Agreed. > > Anyway, I don't feel strongly either way. I am fine with keeping the > patch as-is, the diff I proposed above, or the diff I proposed with an > @anon parameter of folio_test_anon(). The only option I don't really > like is adding a helper just for the file pmdmapped case. Let's go with your cleanup here (could do as separate cleanup on top of v2, whatever you prefer). -- Cheers, David / dhildenb