Received: by 2002:a05:7208:13ca:b0:7f:395a:35b6 with SMTP id r10csp37936rbe; Wed, 28 Feb 2024 09:51:17 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVPalcn8zLukCC8Xuqij+LGd8HcP3bVhpRc/aXWQoeF+pCjKq41kO4GWoTCUMeRYBzSOfdDsrtE7XWeA6a7bCyBPKhduXICXMp0eK9ljw== X-Google-Smtp-Source: AGHT+IGo6UGnWTsxoCE7EhQvu/RSHzPwaLvoU74XibepYrwB33/vqryNTl3/b5iowmHB/NnZbMMY X-Received: by 2002:a17:906:4ed9:b0:a3e:526b:1bc2 with SMTP id i25-20020a1709064ed900b00a3e526b1bc2mr307350ejv.40.1709142676970; Wed, 28 Feb 2024 09:51:16 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709142676; cv=pass; d=google.com; s=arc-20160816; b=DAZ8jz3OJZDg97lwTcsKbsK2nq/X2cVC8fjHkM64xS0kXDS2r1dMpou8BNsJiEH5FV YNbtg6JHt2T9qOWzOXxKTqyBcnZgJcyQN14TkmOTkfUFIROpuL7HSoSBVDnS1uCohftQ 0OZcDUGeeN6WUEFnLd82XvD3psYydTxstCd7xAwIDJN4xmpwqIvN2OtOUczw4rxtf7UU p5uFm59wyBO5uq1oEbOGSrlhY/KIWvsNXQ+o/3u5GQARdS4KFcUpjFkEy1DVC73+khbZ JT2xossXjw5pvLVvMBGR2hjqHbKVh/qNCjdPH6JS1EN2P+6y4/aK1wJHbaBaj6CszNNy viog== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=VnQ/ab/JPnAloJ9klQyh8nICmNuzmA4WCeR9lmsJM4M=; fh=3xy6Vk3HhGZwDVzWk9AQnezLkTYHrRQi2VUCniD53qs=; b=fUf4cb+/n6LSX74/spu11TrlKzFcIbNBJ8C4OLDXGn6adK7WJVlZU2ffV55EvFc1kV FJPbXrh504AQkeA7IWX0XfpQCxa5YMCVMLCx+kOp7G3hi9Ps6SeMdUa1q/FnFrzkOCRe v+EbVaWlmHTcF/OfGqmO/qDtCf+OYZ5UeX8+dJ6hhIpI808ooVr2SN12oewITvJrST8q W1eRNBMVnjvhqaE9ZWxwp3l44E779uiZ+DRaBwbPf9DCMeZH/z89PdxR6H0IlLM4tBSm vfpl84Z/8enDZx1MBkQwx9joyjdD+eQjYdhzu43dE+nlgmv4fvljfdU6iAlrXogMtglO z8sw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=AGtlO26T; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-85464-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85464-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id h5-20020a1709062dc500b00a4415f923e6si396962eji.743.2024.02.28.09.51.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 09:51:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-85464-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=AGtlO26T; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-85464-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85464-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.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 am.mirrors.kernel.org (Postfix) with ESMTPS id 684031F26380 for ; Wed, 28 Feb 2024 17:51:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5F25815E5B6; Wed, 28 Feb 2024 17:51:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="AGtlO26T" Received: from mail-yw1-f174.google.com (mail-yw1-f174.google.com [209.85.128.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8419A15DBC1 for ; Wed, 28 Feb 2024 17:51:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709142665; cv=none; b=TexMYNaYWFDLHRq1PWFJs5PeNLj1lHS23v+lm89NYRr/5xAO0y+sKSL0MRnXbP/o8TlJfimBcIT+EwY5oM68TjvPIOtqnN4EQum6uRM4LhuDglXnSkCPGoTyKPmlqDQyynkKBKhACCNWOv8JpYnNi0AE76YWDh3wWGIYynHBMPE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709142665; c=relaxed/simple; bh=Kjp9e87qYUvuVJ7M2OXAg9wWZf/QwADaOftlAlqHnSs=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=Cr96pchn8cufAj+Fsbrv9AjVgj0fAuuk3fEOBL+60NdonNwgHAhGxV0pPJGADusUid+5zbPWgZoj2yuHHakGdvuPnywdX5Y1dFk6Y3NUxxwJ68XmdOwUWz33OY/vBF0UuFdYo9xjY5uG53Lq/AbmmbA67y5rEC3doyrHwG3y01I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=AGtlO26T; arc=none smtp.client-ip=209.85.128.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-yw1-f174.google.com with SMTP id 00721157ae682-60925c4235eso52217b3.3 for ; Wed, 28 Feb 2024 09:51:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709142662; x=1709747462; darn=vger.kernel.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=VnQ/ab/JPnAloJ9klQyh8nICmNuzmA4WCeR9lmsJM4M=; b=AGtlO26T+doUb5WQH6HpuNAonMJHI1VctQ6KnGaUDOiepgfP1rGunEp2EG/fAzIzgt 2jIqPjRYCt79wlj1VIm88MH5ngDdryRQHoOSIW2yXrvW1+SEYeglvKzZTlJ6Zf3g/NR7 uajrrj2JBMIzyvm4bcgTu6gTY4LlDUQLRpGFp6MlqBhwozTTw/lZe9bQDIwrGKZkUtgn hPfl50UdRGiSn7mkOc+n1IoWaEdBdeo8HszJPN0zZK0RacuYwh86fvoEl2VZa9Ghun5O Eyu7Yuo/iy5/V3RQoVduxsSei9kZcZMcu1t7C8S+2OXNwWpAE5Z+mfaF2ZnbZCtJATm6 590w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709142662; x=1709747462; 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=VnQ/ab/JPnAloJ9klQyh8nICmNuzmA4WCeR9lmsJM4M=; b=rYt4f2KwukaglxIt1Che8esyIFWTuOqGvS1+9uxez9NqXCxCl7Q6uS++bnC4zGDt1E oaBI5v4hOCR0pK1JDbYLqTQCz6jNK67yK+8ZDv7cBRbwpao2N+mKJrgVgtG0dvy7xBPt F1dPLGIfjuonADGzmH2hbaIdU1fDSQ+MZa7sQBr6lcio9t5+MDE38gOkBRGV+Dq9YmiO rb5y4GATM3Mf6GlThNOuWYgnbGMgCPWcxUo8VMV8rpEneWlklwEKL6E0iWasBiy3jndQ W3TwBXK+Zw72jY8y8CYaY+57LQMTrLz5a7EV7cobZAYMO1PbTW3qJ3nKfnTN0xKZRVto p4Ww== X-Forwarded-Encrypted: i=1; AJvYcCW5ws8l8oZwUu0buYkXalrWyiIKikA6g7hz4dnzGsopG5bGESbswqh6emNxTtVhnZM9oapFFDziRSVpYlxIL6Yaqq0KqN5vzA5JVLh4 X-Gm-Message-State: AOJu0YzGWthDmik/3zI5XnO2InJRKYbqrQrS/jdCpoAsURpXDgT73YVr 5R03cE0cUFELN5QC6In1JovSCkPplkdZJii9woSv/tAqs0Or5iE54zndth7IlNqpsaAyk0GbAuA 6u+IhsBZCjXjmC7JYOBtkfau/b2oaYbtSGyoM X-Received: by 2002:a25:9c08:0:b0:dcb:bff0:72b with SMTP id c8-20020a259c08000000b00dcbbff0072bmr3550ybo.31.1709142661963; Wed, 28 Feb 2024 09:51:01 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240221194052.927623-1-surenb@google.com> <20240221194052.927623-20-surenb@google.com> <2daf5f5a-401a-4ef7-8193-6dca4c064ea0@suse.cz> <6db0f0c8-81cb-4d04-9560-ba73d63db4b8@suse.cz> In-Reply-To: <6db0f0c8-81cb-4d04-9560-ba73d63db4b8@suse.cz> From: Suren Baghdasaryan Date: Wed, 28 Feb 2024 17:50:50 +0000 Message-ID: Subject: Re: [PATCH v4 19/36] mm: create new codetag references during page splitting To: Vlastimil Babka Cc: akpm@linux-foundation.org, kent.overstreet@linux.dev, mhocko@suse.com, hannes@cmpxchg.org, roman.gushchin@linux.dev, mgorman@suse.de, dave@stgolabs.net, willy@infradead.org, liam.howlett@oracle.com, penguin-kernel@i-love.sakura.ne.jp, corbet@lwn.net, void@manifault.com, peterz@infradead.org, juri.lelli@redhat.com, catalin.marinas@arm.com, will@kernel.org, arnd@arndb.de, tglx@linutronix.de, mingo@redhat.com, dave.hansen@linux.intel.com, x86@kernel.org, peterx@redhat.com, david@redhat.com, axboe@kernel.dk, mcgrof@kernel.org, masahiroy@kernel.org, nathan@kernel.org, dennis@kernel.org, tj@kernel.org, muchun.song@linux.dev, rppt@kernel.org, paulmck@kernel.org, pasha.tatashin@soleen.com, yosryahmed@google.com, yuzhao@google.com, dhowells@redhat.com, hughd@google.com, andreyknvl@gmail.com, keescook@chromium.org, ndesaulniers@google.com, vvvvvv@google.com, gregkh@linuxfoundation.org, ebiggers@google.com, ytcoode@gmail.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, bristot@redhat.com, vschneid@redhat.com, cl@linux.com, penberg@kernel.org, iamjoonsoo.kim@lge.com, 42.hyeyoo@gmail.com, glider@google.com, elver@google.com, dvyukov@google.com, shakeelb@google.com, songmuchun@bytedance.com, jbaron@akamai.com, rientjes@google.com, minchan@google.com, kaleshsingh@google.com, kernel-team@android.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, iommu@lists.linux.dev, linux-arch@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-modules@vger.kernel.org, kasan-dev@googlegroups.com, cgroups@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Feb 28, 2024 at 12:47=E2=80=AFAM Vlastimil Babka w= rote: > > On 2/27/24 17:38, Suren Baghdasaryan wrote: > > On Tue, Feb 27, 2024 at 2:10=E2=80=AFAM Vlastimil Babka wrote: > >> > >> On 2/21/24 20:40, Suren Baghdasaryan wrote: > >> > When a high-order page is split into smaller ones, each newly split > >> > page should get its codetag. The original codetag is reused for thes= e > >> > pages but it's recorded as 0-byte allocation because original codeta= g > >> > already accounts for the original high-order allocated page. > >> > >> This was v3 but then you refactored (for the better) so the commit log > >> could reflect it? > > > > Yes, technically mechnism didn't change but I should word it better. > > Smth like this: > > > > When a high-order page is split into smaller ones, each newly split > > page should get its codetag. After the split each split page will be > > referencing the original codetag. The codetag's "bytes" counter > > remains the same because the amount of allocated memory has not > > changed, however the "calls" counter gets increased to keep the > > counter correct when these individual pages get freed. > > Great, thanks. > The concern with __free_pages() is not really related to splitting, so fo= r > this patch: > > Reviewed-by: Vlastimil Babka > > > > >> > >> > Signed-off-by: Suren Baghdasaryan > >> > >> I was going to R-b, but now I recalled the trickiness of > >> __free_pages() for non-compound pages if it loses the race to a > >> speculative reference. Will the codetag handling work fine there? > > > > I think so. Each non-compoud page has its individual reference to its > > codetag and will decrement it whenever the page is freed. IIUC the > > logic in __free_pages(), when it loses race to a speculative > > reference it will free all pages except for the first one and the > > The "tail" pages of this non-compound high-order page will AFAICS not hav= e > code tags assigned, so alloc_tag_sub() will be a no-op (or a warning with > _DEBUG). Yes, that is correct. > > > first one will be freed when the last put_page() happens. If prior to > > this all these pages were split from one page then all of them will > > have their own reference which points to the same codetag. > > Yeah I'm assuming there's no split before the freeing. This patch about > splitting just reminded me of that tricky freeing scenario. Ah, I see. I thought you were talking about a page that was previously spli= t. > > So IIUC the "else if (!head)" path of __free_pages() will do nothing abou= t > the "tail" pages wrt code tags as there are no code tags. > Then whoever took the speculative "head" page reference will put_page() a= nd > free it, which will end up in alloc_tag_sub(). This will decrement calls > properly, but bytes will become imbalanced, because that put_page() will > pass order-0 worth of bytes - the original order is lost. Yeah, that's true. put_page() will end up calling free_unref_page(&folio->page, 0) even if the original order was more than 0. > > Now this might be rare enough that it's not worth fixing if that would be > too complicated, just FYI. Yeah. We can fix this by subtracting the "bytes" counter of the "head" page for all free_the_page(page + (1 << order), order) calls we do inside __free_pages(). But we can't simply use pgalloc_tag_sub() because the "calls" counter will get over-decremented (we allocated all of these pages with one call). I'll need to introduce a new pgalloc_tag_sub_bytes() API and use it here. I feel it's too targeted of a solution but OTOH this is a special situation, so maybe it's acceptable. WDYT? > > > > Every time > > one of these pages are freed that codetag's "bytes" and "calls" > > counters will be decremented. I think accounting will work correctly > > irrespective of where these pages are freed, in __free_pages() or by > > put_page(). > > >