From patchwork Fri Jun 14 23:05:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13699162 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 74D86C27C7B for ; Fri, 14 Jun 2024 23:12:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 340B16B0189; Fri, 14 Jun 2024 19:05:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2EFC56B018A; Fri, 14 Jun 2024 19:05:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1B74E6B018B; Fri, 14 Jun 2024 19:05:11 -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 E57CF6B0189 for ; Fri, 14 Jun 2024 19:05:10 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 8C673140974 for ; Fri, 14 Jun 2024 23:05:10 +0000 (UTC) X-FDA: 82231026780.01.7597699 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf11.hostedemail.com (Postfix) with ESMTP id E520640011 for ; Fri, 14 Jun 2024 23:05:08 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=gwTI5tvv; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf11.hostedemail.com: domain of 3o8xsZgYKCCoYaXKTHMUUMRK.IUSROTad-SSQbGIQ.UXM@flex--surenb.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3o8xsZgYKCCoYaXKTHMUUMRK.IUSROTad-SSQbGIQ.UXM@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718406305; 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:in-reply-to: references:dkim-signature; bh=Yn2hFXhX79WK1EuGevpcsoabHDFdbQfZxb2v8U67kDg=; b=WrcOCroUE9fTCFPRzDwDAaG0Pzk/u1RZOB4E7W4773ZF49+KIcNykpSYHzoUt/VDtfMi33 C5or5P2rePa+Zf81z6nYksuLTsgJuj1qAwk3bH+F7CHFBmxLfkqZFlT8i/4xjUHHqz9Sl5 BbGOIoOO46gKT41XiFb8RprMu83oCXs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718406305; a=rsa-sha256; cv=none; b=65yxnKxV6YXVKTDGKkV47011C2wJ0TAS9oeDTOJclOxrEUT6UvcyTKo1/LFXSyS4FNx+/H dMcVptjwHl7yEY+nYlm3jLb6cUs8n18/75IbPzWdihp72noHdilPMdHv0xA6zAcatnui6v 9ibySHns/k1EENCxccgSCg0rCWbQIco= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=gwTI5tvv; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf11.hostedemail.com: domain of 3o8xsZgYKCCoYaXKTHMUUMRK.IUSROTad-SSQbGIQ.UXM@flex--surenb.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3o8xsZgYKCCoYaXKTHMUUMRK.IUSROTad-SSQbGIQ.UXM@flex--surenb.bounces.google.com Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-631b498f981so31755087b3.0 for ; Fri, 14 Jun 2024 16:05:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1718406308; x=1719011108; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=Yn2hFXhX79WK1EuGevpcsoabHDFdbQfZxb2v8U67kDg=; b=gwTI5tvvjbfHl0fQL5sN4TPh8InnQv0zCJKAS9wi3FyCQI29xahs0yR3J2H1G2VI/F F3uCFIaWP0B9Xntx49nTttyphZa9P1tmMfMCxXDlA8ApJRyfp0MisnrEBm0+VjX8pKuB CnmVe41kdnj3VQhxI1HHCDWMQcz/QvSQJ5qzZy1dtZTyozvcEeKjGP85Ls4GqP72U3xX kpze5P7UeorbXzyWtxKpg0JpGG4WXxDHZfE5ERDOE+aoU2BErF75oVQztV311SMXlw5P ydE8stmeQqnAAXfPY4+uq4ntrJIlDEkW1vsb1Cm7cCXGaAX6zsrMwIEi+3cxiSrrpTyi hSXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718406308; x=1719011108; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Yn2hFXhX79WK1EuGevpcsoabHDFdbQfZxb2v8U67kDg=; b=jW2CgURgMzgwZTGJE+7PQFNfop9wtQ0dGDKgbMpJO12pQi1PO0ejjfKuvFREFxiW4u wlgwMYqNK04H0s0DGmav2PVVIRaM2RCEZBxncDrTZWrVsf5XKVRwF7of8fabfhKPIn1O +RG9LehT2NVYdL1HiWGzu8FMuH5jDJXIsQtrMHavN/2XSZ9nbGJdkqxqXCQDX94OVq/r 8uwxEdiACd8HjpDF2ApBtL6Nj/AHC1w8FEp82YHurzBWUWYTT8YXP6i1wmBGeINphqx9 8KUBa94TNBTuiByutMbavFOIeH1h2aS35blUX1ibRclzVL4w26wXjJBBfpqnKSMn9pvs 2isw== X-Forwarded-Encrypted: i=1; AJvYcCWdLFWFkGHbC29AyvR3p3uwa7MOoJe9Uh0gXGeaRWS2eGVWcH9myKgSzpasUuxvbfKpftOdOxTPerddulnYCzHPGr4= X-Gm-Message-State: AOJu0YwUhI2+QzvWEzyhcImtvrueOu/5wYrHeaPrqWiIYI8Sfak1XIiY tnISsovbXY3loRLLylIlgv2X63qo6SttCiFoaT0Yx6uscOz6rjrgQhtYVfumU05At5+rUAB8Uah 3HQ== X-Google-Smtp-Source: AGHT+IG+ZloUhmtk/dvF1n0BAyilcNB3L2cfA9Zfr3ld5hq7p6cOMW9TVxQTjZ6Wg9M3YIfspZKx34kVKi8= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:92f9:5432:a95e:d0e8]) (user=surenb job=sendgmr) by 2002:a25:938b:0:b0:dda:d7cf:5c2c with SMTP id 3f1490d57ef6-dff154676camr253369276.13.1718406307948; Fri, 14 Jun 2024 16:05:07 -0700 (PDT) Date: Fri, 14 Jun 2024 16:05:04 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.45.2.627.g7a2c4fd464-goog Message-ID: <20240614230504.3849136-1-surenb@google.com> Subject: [PATCH 1/1] mm: handle profiling for fake memory allocations during compaction From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: kent.overstreet@linux.dev, vbabka@suse.cz, pasha.tatashin@soleen.com, souravpanda@google.com, keescook@chromium.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Suren Baghdasaryan X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: E520640011 X-Stat-Signature: bmtjwzqwx73rmc6jwnyozm3x883ahrum X-Rspam-User: X-HE-Tag: 1718406308-494338 X-HE-Meta: U2FsdGVkX195AdFt4bQdaLy5K1S4Jul+JHC40jXAVp7V1AOyHf28MP2rRWAC+m9CeEH5xltU9G058+AXih0EGRngncLvg/YLeYVWsbhhtvey28upi8GQAezqAMUa9zMice39EXVh2IbiFTL1qX6iPAp9srrHV1TcSiP9KMJF8s9IfxZO/Z/4LBxDmSw5DZZuVjWws58kA2vhXRswTRsNMwFLyK/ffDy4+j5cXEFC+wA4urZy+wvlE2rUgq8Vx+IMTyY3BlqEEQwMW6x15f+dCCQ0/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/xGMaa4hqVA1c7I2YlFOEU8fRqRyKbchFAUV1uwd9ZY7uRXC0YbcIbaRzqo3X/qjr3w96ar0RVBJVb6YF5ZLn3wveoPKsN1sGTvdh0cX13SpADubB+XLaCIdpMt473A3lfC9EHeI9UYDvoj4GBoD9 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000017, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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_noprof() free those pages. release_free_list() marks free pages and immediately frees them. This usage of post_alloc_hook() affect memory allocation profiling because these functions might not be called from an instrumented allocator, therefore current->alloc_tag is NULL and when debugging is enabled (CONFIG_MEM_ALLOC_PROFILING_DEBUG=y) 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 until they are freed, therefore the associated counters should usually read 0. Signed-off-by: Suren Baghdasaryan Reported-by:/Closes: if appropriate. Acked-by: Vlastimil Babka --- mm/compaction.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) base-commit: c286c21ff94252f778515b21b6bebe749454a852 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_ARGS__)) + 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 *freepages) nr_pages = 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 = pfn;