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 C77CCC27C4F for ; Sun, 30 Jun 2024 19:17:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 38B9D6B0085; Sun, 30 Jun 2024 15:17:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 33B1B6B008C; Sun, 30 Jun 2024 15:17:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 202886B0092; Sun, 30 Jun 2024 15:17:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 03CC26B0085 for ; Sun, 30 Jun 2024 15:17:46 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 41A21140AD1 for ; Sun, 30 Jun 2024 19:17:46 +0000 (UTC) X-FDA: 82288514532.26.1C45897 Received: from mail-yw1-f169.google.com (mail-yw1-f169.google.com [209.85.128.169]) by imf02.hostedemail.com (Postfix) with ESMTP id 762AB8000B for ; Sun, 30 Jun 2024 19:17:44 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=Q4R4XER1; spf=pass (imf02.hostedemail.com: domain of surenb@google.com designates 209.85.128.169 as permitted sender) smtp.mailfrom=surenb@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719775043; 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=LiM1pX68adOinY1Ba8HhJGroraZqmuLSBXlSTDfxtcw=; b=u0GK4WBSxyZmCpSa0O9GYJCe4O+jATfRxlalFR1AGlaQf/r7csaBXf0gCG2Jkc+HbOIRCc mSmDEIYFMjIo4sZqLtlyqEshTPuuGg84ucM7AFnZqPzN+oKcp9e+e9MB6A+z92cPY1xbQD wiY+ZCw42JM4SNRQWulXC1aWDawPgZ4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719775043; a=rsa-sha256; cv=none; b=y8VGRwSxDhSWnc97j99hL5xLDTEWtBHJxvtJE+jL3pN8AXt5K+t9NELEBqDEIknLMlxYpQ A5aMYzgjrsADm2e2Xu1G07iM3eqelNZXHMwvlMOnfGoIXs106Fs23h1Sk2yALZ0esnRbTi EF0ZHq2GobsuWgOnWKoSwVD23BR5tN4= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=Q4R4XER1; spf=pass (imf02.hostedemail.com: domain of surenb@google.com designates 209.85.128.169 as permitted sender) smtp.mailfrom=surenb@google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yw1-f169.google.com with SMTP id 00721157ae682-64b5617ba47so16098897b3.3 for ; Sun, 30 Jun 2024 12:17:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1719775063; x=1720379863; 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=LiM1pX68adOinY1Ba8HhJGroraZqmuLSBXlSTDfxtcw=; b=Q4R4XER1WBXyr7kyJ9dM8o5633TuoYGRXrzf2QFKuglPys4qstoWsLGkhxRjFtzrpj A6Xh4uywn1JQWiduPQ5Wu6LKO1KBcFEhajvfcpEhIPc7u4wd0itUYpjCASFvH8kYOlto W40Hn2sfSS5YaRbn3iD5ONY3f2O0eiF0ZNusREnIor7WqIrutD/7F0+ydsomNFkcb1Ji giZJrnXKbmDbQw0jOT6U9yOWbPBlXbbJg9XdIwAkEb457d4s/u8VTe3196HPOHzpb7CZ JeTM9tvK/RP7NhtrXIFvGQuOJIWdD0D/ae94F22LFNWFJu1E+MoibBJVqJiokj3y++0C tHuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719775063; x=1720379863; 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=LiM1pX68adOinY1Ba8HhJGroraZqmuLSBXlSTDfxtcw=; b=RbRZj82mn7ceLTrDpwgS/jh/21IAKra1PlzXxC7SkcDpv+gEJ9wxeaCUC5NHhsL/uu UqRlfjZLAxCQfYxe1AG1Ebdwqfb+ojg8unyZdqWUDVWIxNLILSvRCZc4C2WBJ7RbJe0c nkH9ecexzdsRY/vt99iWSyF2hDfoU0NHB+yamCOipStQC61yJWV60EgakpZ477KjUkYU Vg9OP+uQrRUOq5pK7zHM1I7sExEilHQYZXuiYEI1MXJBk0/3GK1E3Nrchh++vViMhM0B j0meERvjQDypdqZsDK7mBhyrjHse15xfmeMog6CKazpWxA7dwnvMgU9unYV6OmPhBK2U i45w== X-Forwarded-Encrypted: i=1; AJvYcCW+GYif+J8glt51HcbCD1PQmHaf/JZMhXVHDvNdEE40gp/wPvKxLG3nsxmMlGqs44dYJO1bBCgTUBQrYlnGigEYZMg= X-Gm-Message-State: AOJu0Yzc62vyEwKnRn4//U+h8/xVG8eWgWZQyAkc5HAJza4gnmiZLxzv GF/gy5cYPoKhYpRLHrC3Y/+ZATi/tKaXiJDI/cT37Y6PisKjlPYGtqlFQRrrNhdTzlJx3VPZe3A 5+4xhCfZull8YlbNH4AsLwdSUe9ExGDGAKINY X-Google-Smtp-Source: AGHT+IHtbfYXamlGFEAiXUeTmfE7JAmJyT9hNWLW1R+8Hx2Kd9pGyd56H2rm7Z0f9UaPctOiJ68pR3Gqf60xKWnHlMk= X-Received: by 2002:a81:4c50:0:b0:64a:62f4:2a79 with SMTP id 00721157ae682-64c71aebe40mr28201327b3.21.1719775063121; Sun, 30 Jun 2024 12:17:43 -0700 (PDT) MIME-Version: 1.0 References: <20240614230504.3849136-1-surenb@google.com> <2a0ee369-12f9-401a-9179-82bd659ae201@suse.cz> In-Reply-To: <2a0ee369-12f9-401a-9179-82bd659ae201@suse.cz> From: Suren Baghdasaryan Date: Sun, 30 Jun 2024 12:17:32 -0700 Message-ID: Subject: Re: [PATCH 1/1] mm: handle profiling for fake memory allocations during compaction To: Vlastimil Babka Cc: akpm@linux-foundation.org, kent.overstreet@linux.dev, pasha.tatashin@soleen.com, souravpanda@google.com, keescook@chromium.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 762AB8000B X-Stat-Signature: nqokhfyakmwjauz6o7a8r6mqep63rbwo X-HE-Tag: 1719775064-817083 X-HE-Meta: U2FsdGVkX19pgRyR81ERrjRkHSIDTYQ0U6yWgn6u9XFjJZGrSFlx6kW2xfsaod3FJZkvwQ6F7+3JAlOd75Ds1WDIf/tGVq4+TkvSRZ3j9SwFhhry6hd7EERvAy+uBi2Nyrvw/bm7kAI0EPAP7zfEx6+3TSslJxdHxT/pbixGCh0PfLFicBf+EUkv1wxK8W8OBwrWhPzKQiWeKoK4Xn8URUvHaX1gs6gPToRLnXZw2RfFL/UDKls8UWX5TQOmjsA46Hs8WEUjmf4wf+QqnCZFpr8jNSqXUzde/khniu2bbpHLJbp0S5P4tri5xtTZk685789SadB+a+ou2kVvKtYmBCovBPeR84mn1GPpu4UB0+OAaF8Aq1ibs1P0KzHHWUgUQZ6t/DyCx/w/sATQrzOu4M4vwW3M9uCJslrD2ZNDhWGwD2f0YyxAElNlT0d7IMEdU347dE+eoM8xpB3FyHaYpLWZNXr1LPmuO3cDvEn2PKrItmMJMpWo1BbYoa4SpPZ+b2qyHp1HNsKwF8RJwcOLMhnQJN30TzvrImeh6TUpvfi/9gdUBMu3/2ULBkbX7qFNHIFuVEuhghyUE8zzcxfTXZzlasyimkR5lhjy6pYdM/c//5j+6bCNG7JfMOJp2iSjos63qYAJ3zqfDFUOHStCgAWQuBoNs1p5A2wXdN3Ew9KTlqAEnc5hOg5f+SYvWgpWm4SYTPqLP6jLG4BUF25bltmINTEtxbyveui259SYPJOzqjw7tS+LIHW1wjxzSDbugLoUjC7FazbhlQQSUSMib7YyLxrZsEzZN3dz5o5SUL2WTLRfQknjcslixURzi100RCadOFexZLkPU3u97rxIUQQ1nJxD5QOnH+adsBjfK/rld2X44yrTiKoZxUyhxF5EYQq9K+hY/utBjNU4sUMAfpet8Ln6zcu1pgRx89Vesd5INW2lyQXNqooEUkTHBTxksnb3C6XOzLyc8CqGx8O gPYjEtxk tFERRE7kcII+tALEwF/zPS89igCIH+UqTD9wnHMunV0FUSPkffBuVDnCoQdJTy0QRruyiNG/YeWWHsLU0pkBBBJ5SN8qA+Rytomyvo/VUHzGe5NuGTwzIEoLIeRXldktw6/4I0QrfrgAbqi2Ny98kCc+hI8iFyYXtzjawI3CyqJZPfkkWU+lk84CigQhUppCIYpvQ 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 Mon, Jun 17, 2024 at 1:33=E2=80=AFAM Vlastimil Babka wr= ote: > > On 6/15/24 1:05 AM, Suren Baghdasaryan wrote: > > During compaction isolated free pages are marked allocated so that they > > can be split and/or freed. For that, post_alloc_hook() is used inside > > split_map_pages() and release_free_list(). split_map_pages() marks free > > pages allocated, splits the pages and then lets alloc_contig_range_nopr= of() > > free those pages. release_free_list() marks free pages and immediately > > Well in case of split_map_pages() only some of them end up freed, but mos= t > should be used as migration targets. But we move the tags from the source > page during migration and unaccount the ones from the target (i.e. from t= he > instrumented post_alloc_hook() after this patch), right? So it should be = ok, > just the description here is incomplete. Sorry for the delay with replying, Vlastimil. Yes, you are correct. Some of these pages are not immediately freed but migrated and during migration the destination gets charged for them. As a result these new counters should still read 0 most of the time except for some intermediate states. I can amend the description if this is considered important. Thanks, Suren. > > > frees them. This usage of post_alloc_hook() affect memory allocation > > profiling because these functions might not be called from an instrumen= ted > > allocator, therefore current->alloc_tag is NULL and when debugging is > > enabled (CONFIG_MEM_ALLOC_PROFILING_DEBUG=3Dy) that causes warnings. > > To avoid that, wrap such post_alloc_hook() calls into an instrumented > > function which acts as an allocator which will be charged for these > > fake allocations. Note that these allocations are very short lived unti= l > > they are freed, therefore the associated counters should usually read 0= . > > > > Signed-off-by: Suren Baghdasaryan > > Acked-by: Vlastimil Babka > > > --- > > mm/compaction.c | 11 +++++++++-- > > 1 file changed, 9 insertions(+), 2 deletions(-) > > > > diff --git a/mm/compaction.c b/mm/compaction.c > > index e731d45befc7..739b1bf3d637 100644 > > --- a/mm/compaction.c > > +++ b/mm/compaction.c > > @@ -79,6 +79,13 @@ static inline bool is_via_compact_memory(int order) = { return false; } > > #define COMPACTION_HPAGE_ORDER (PMD_SHIFT - PAGE_SHIFT) > > #endif > > > > +static struct page *mark_allocated_noprof(struct page *page, unsigned = int order, gfp_t gfp_flags) > > +{ > > + post_alloc_hook(page, order, __GFP_MOVABLE); > > + return page; > > +} > > +#define mark_allocated(...) alloc_hooks(mark_allocated_noprof(__VA_AR= GS__)) > > + > > static void split_map_pages(struct list_head *freepages) > > { > > unsigned int i, order; > > @@ -93,7 +100,7 @@ static void split_map_pages(struct list_head *freepa= ges) > > > > nr_pages =3D 1 << order; > > > > - post_alloc_hook(page, order, __GFP_MOVABLE); > > + mark_allocated(page, order, __GFP_MOVABLE); > > if (order) > > split_page(page, order); > > > > @@ -122,7 +129,7 @@ static unsigned long release_free_list(struct list_= head *freepages) > > * Convert free pages into post allocation pages,= so > > * that we can free them via __free_page. > > */ > > - post_alloc_hook(page, order, __GFP_MOVABLE); > > + mark_allocated(page, order, __GFP_MOVABLE); > > __free_pages(page, order); > > if (pfn > high_pfn) > > high_pfn =3D pfn; > > > > base-commit: c286c21ff94252f778515b21b6bebe749454a852 >