From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5DA72C3DA4A for ; Fri, 9 Aug 2024 18:10:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BE42F6B0082; Fri, 9 Aug 2024 14:10:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B93A46B0089; Fri, 9 Aug 2024 14:10:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A5AD56B0098; Fri, 9 Aug 2024 14:10:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 87BDB6B0082 for ; Fri, 9 Aug 2024 14:10:34 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 3C9BD41396 for ; Fri, 9 Aug 2024 18:10:34 +0000 (UTC) X-FDA: 82433497188.20.C999D22 Received: from mail-qt1-f175.google.com (mail-qt1-f175.google.com [209.85.160.175]) by imf06.hostedemail.com (Postfix) with ESMTP id 22F96180028 for ; Fri, 9 Aug 2024 18:10:30 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=AI2IKHlJ; spf=pass (imf06.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.160.175 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=pass (policy=none) header.from=soleen.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723226979; h=from:from:sender: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:dkim-signature; bh=AHqMJlIkWWEgQwJvsxhrebiNG2gW3dBZk5UEyqRtZXk=; b=38vXZd7OUXd0JRfGSHYGjNtFrlImbRg1SBRhWSyGCGoXWDD9TqPfjCp8hascCSFgF3IZXd 38UnRqiXNbI0GMNxAp6gPVGdQAV8Skdm4Qx2ekCoC1ApKTiQwnOjPH+Qrv00iRUfJti1hy ti9m/WUGK4npT8eA/Jt752YJKjZsTKg= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=AI2IKHlJ; spf=pass (imf06.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.160.175 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=pass (policy=none) header.from=soleen.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723226979; a=rsa-sha256; cv=none; b=bBx2/gfaUFpNQrX8gw125ZFa/Lxf43f2SjC5CsKE80+fyl82hKfIeViyksWFScj3R7/hiL /m8dLHEvFaOJ434er3tVvEEW++mQO+PikXxRGMMb3ue9nXo5+v84qNlgPyOAgxSkWA7ybx x+oc768G55eK0+wWScm6x5aCtO1zpxQ= Received: by mail-qt1-f175.google.com with SMTP id d75a77b69052e-44ff7bdb5a6so14252241cf.3 for ; Fri, 09 Aug 2024 11:10:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1723227030; x=1723831830; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=AHqMJlIkWWEgQwJvsxhrebiNG2gW3dBZk5UEyqRtZXk=; b=AI2IKHlJzv7KxMw2KG1eus2H6KmoRgHB+H5KgEM6A0rqKz0Yb+FWmICvNvb0NrdJx9 kCQjfCiiBdFaasRCpiBKXMermJymguGL4nIUtNFJRafqUnk4OB4dEhukM04j2tY4Lx4E xk/ySfOsc/wX0wDsZN7TK5vhvXLPeOpGap9kDvjrBmkFVSmaLU3iWYauFPntPJx/0WZB eb5IdUSIFgCdhubTfchWS0RFQiw7PGxJGcndzDlvClBUsrOpyeQkML/BzPjp1ZPt6Gw7 DYo27vjthrF7Bc2hiZYp9ot9YckxjDHwONXXu8aXnjcvt6QYztHOSZ0hcvfowjZQgIh2 XhBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723227030; x=1723831830; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AHqMJlIkWWEgQwJvsxhrebiNG2gW3dBZk5UEyqRtZXk=; b=F9GzGq0KZ0Bb8jc/JYg+JNSYPspc7/lhziYfKhDWbMdgW3pTPumr6zD6A86OK+clnt H0GFaXC+5eZ4zf7hwlIAS+iSHLg5yOKmKg1A4RBVP4DDvWsxtR8nEdHPhVuduvbKHYb6 UCl2f+TWVZ8u2wU2W9er1+dcT2I18dG7wCkhyx8fy+gUf+rSIdR7mOprYyflHL8uSPqK Pv6FpYhOGabLE22ZocYVaUsE9ksaX/bipNbtRJ0xFicPYjl+iNdGCKI/iyl1XiIOs90Q Qw+Cmvk/tG4brRRO/EU2gJyRZuEMwEmtFMsp8jj6bxFqH1qUTiX+DXrI+Se5EUVmEiQP sSxQ== X-Forwarded-Encrypted: i=1; AJvYcCUIvzHDJz6wb/XmrJLN5j8dm+NWEgPaC9IzjzmfYmXpViq5wnwcPALh4Q4q36BEUrfu9AHLpsOhiwtVGsBk3uLGo40= X-Gm-Message-State: AOJu0YwK5GDPc1KsyY012nG1tAkUIILlx+yMR5hxjzWOqIcLDqeChM4g 6rEgl0GWaJiOL0D7uT8JvtTQVg8YijCcLVbTt6LyMyRiwVGtS4pO2IwLpeJVhE+iR5mau5VpNXw p/9fjINK42vXv9IEFWfGhMKAzCBT8gtmhG4hKZw== X-Google-Smtp-Source: AGHT+IHrNlz+ta25fI4t3VA0/EEbsr27aU89/bZMIE48EJr0+K917c8yN5Fy0ywTD7GNlhd6voyk2Z4+WfWnBsJ9Ua0= X-Received: by 2002:a05:622a:4113:b0:451:d70a:80b4 with SMTP id d75a77b69052e-4531251ba01mr31251511cf.4.1723227030003; Fri, 09 Aug 2024 11:10:30 -0700 (PDT) MIME-Version: 1.0 References: <20240808213437.682006-1-pasha.tatashin@soleen.com> <20240808213437.682006-4-pasha.tatashin@soleen.com> In-Reply-To: From: Pasha Tatashin Date: Fri, 9 Aug 2024 14:09:53 -0400 Message-ID: Subject: Re: [PATCH v4 3/3] mm: don't account memmap per-node To: David Hildenbrand Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-cxl@vger.kernel.org, cerasuolodomenico@gmail.com, hannes@cmpxchg.org, j.granados@samsung.com, lizhijian@fujitsu.com, muchun.song@linux.dev, nphamcs@gmail.com, rientjes@google.com, rppt@kernel.org, souravpanda@google.com, vbabka@suse.cz, willy@infradead.org, dan.j.williams@intel.com, yi.zhang@redhat.com, alison.schofield@intel.com, yosryahmed@google.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Stat-Signature: acu9czfqmp5opmcwgedxnx384y7tmfyu X-Rspam-User: X-Rspamd-Queue-Id: 22F96180028 X-Rspamd-Server: rspam02 X-HE-Tag: 1723227030-531529 X-HE-Meta: U2FsdGVkX19P8CSpDdSemYFEym1AVnrBsRhjcoZcjbk9oYYhvB3G7mQG1DhVcLnHFdcys4gc3Q7Vouzx2TrQMVjUxTjud8rbdTtostuQOOtfwhf5VEnKWzudcySrpgo3Qm5Fs+DTVheH2C61mG3JiA40MfGlvfbdtVqQQ7qvsMTpieDN5jSKvQugQ3KAzyz55Q0BmQI3uuJ+RvZKdjMvUQ08sfxvFGBfYFmaaDJhe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hynlM8jSnLq3o6/26qBBx6htvccAWzdu4qWDzkzyj8P5T2jybeJg09uxJr9osiWEl3zX0ZVdLGrVTktC1 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Fri, Aug 9, 2024 at 3:31=E2=80=AFAM David Hildenbrand = wrote: > > On 08.08.24 23:34, Pasha Tatashin wrote: > > Fix invalid access to pgdat during hot-remove operation: > > ndctl users reported a GPF when trying to destroy a namespace: > > $ ndctl destroy-namespace all -r all -f > > Segmentation fault > > dmesg: > > Oops: general protection fault, probably for > > non-canonical address 0xdffffc0000005650: 0000 [#1] PREEMPT SMP KASAN > > PTI > > KASAN: probably user-memory-access in range > > [0x000000000002b280-0x000000000002b287] > > CPU: 26 UID: 0 PID: 1868 Comm: ndctl Not tainted 6.11.0-rc1 #1 > > Hardware name: Dell Inc. PowerEdge R640/08HT8T, BIOS > > 2.20.1 09/13/2023 > > RIP: 0010:mod_node_page_state+0x2a/0x110 > > > > cxl-test users report a GPF when trying to unload the test module: > > $ modrpobe -r cxl-test > > dmesg > > BUG: unable to handle page fault for address: 0000000000004200 > > #PF: supervisor read access in kernel mode > > #PF: error_code(0x0000) - not-present page > > PGD 0 P4D 0 > > Oops: Oops: 0000 [#1] PREEMPT SMP PTI > > CPU: 0 UID: 0 PID: 1076 Comm: modprobe Tainted: G O N 6.11.0-rc1 #197 > > Tainted: [O]=3DOOT_MODULE, [N]=3DTEST > > Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 0.0.0 02/06/= 15 > > RIP: 0010:mod_node_page_state+0x6/0x90 > > > > Currently, when memory is hot-plugged or hot-removed the accounting is > > done based on the assumption that memmap is allocated from the same nod= e > > as the hot-plugged/hot-removed memory, which is not always the case. > > > > In addition, there are challenges with keeping the node id of the memor= y > > that is being remove to the time when memmap accounting is actually > > performed: since this is done after remove_pfn_range_from_zone(), and > > also after remove_memory_block_devices(). Meaning that we cannot use > > pgdat nor walking though memblocks to get the nid. > > > > Given all of that, account the memmap overhead system wide instead. > > > > For this we are going to be using global atomic counters, but given tha= t > > memmap size is rarely modified, and normally is only modified either > > during early boot when there is only one CPU, or under a hotplug global > > mutex lock, therefore there is no need for per-cpu optimizations. > > > > Also, while we are here rename nr_memmap to nr_memmap_pages, and > > nr_memmap_boot to nr_memmap_boot_pages to be self explanatory that the > > units are in page count. > > > > Reported-by: Yi Zhang > > Closes: https://lore.kernel.org/linux-cxl/CAHj4cs9Ax1=3DCoJkgBGP_+sNu6-= 6=3D6v=3D_L-ZBZY0bVLD3wUWZQg@mail.gmail.com > > Reported-by: Alison Schofield > > Closes: https://lore.kernel.org/linux-mm/Zq0tPd2h6alFz8XF@aschofie-mobl= 2/#t > > > > Fixes: 15995a352474 ("mm: report per-page metadata information") > > Signed-off-by: Pasha Tatashin > > Tested-by: Dan Williams > > --- > > [...] > > In general > > Acked-by: David Hildenbrand > > Two nits below: > > > > static void free_map_bootmem(struct page *memmap) > > diff --git a/mm/vmstat.c b/mm/vmstat.c > > index 6f8aa4766f16..ad82c1bf0e63 100644 > > --- a/mm/vmstat.c > > +++ b/mm/vmstat.c > > @@ -1033,6 +1033,23 @@ unsigned long node_page_state(struct pglist_data= *pgdat, > > } > > #endif > > > > +/* > > + * Count number of pages "struct page" and "struct page_ext" consume. > > + * nr_memmap_boot: # of pages allocated by boot allocator & not part o= f MemTotal > > + * nr_memmap: # of pages that were allocated by buddy allocator > > + */ > > +static atomic_long_t nr_memmap_boot, nr_memmap; > > I *think* the clean and portable way to do it is use ATOMIC_INIT(0) for > both. [even though what you have likely works on all archs] Yeah, it is not necessary, but I will add ATOMIC_LONG_INIT(0), > > > + > > +void mod_memmap_boot(long delta) > > +{ > > + atomic_long_add(delta, &nr_memmap_boot); > > +} > > + > > +void mod_memmap(long delta) > > +{ > > + atomic_long_add(delta, &nr_memmap); > > +} > > + > > Nit picking: (up to you) > > I'd do it similar to totalram_pages_add(): > > memmap_pages_add() > memmap_boot_pages_add() > > And call the variables something like > > static atomic_long_t memmap_pages_boot, memmap_pages; Sure, I will rename them. Pasha