Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp1117346lqs; Fri, 14 Jun 2024 16:12:39 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWfmb3AZQpTtac84+/S4orCfBtCdjycXNvgIz39bxk3oSyVraT0uLUPj+H5QwElPoaqxUIgIYrrnXZTug8mSE4LjNqir9V1/Af2X22HXQ== X-Google-Smtp-Source: AGHT+IH2M81HA9eOwJ4nev6yaicz/bWZfgBn00WSwYeZEd1O+kLXu12xIxsN5sWRaShy5f/sJ3yP X-Received: by 2002:a17:906:2503:b0:a6e:feb5:148e with SMTP id a640c23a62f3a-a6f60d29902mr261211366b.27.1718406759173; Fri, 14 Jun 2024 16:12:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718406759; cv=pass; d=google.com; s=arc-20160816; b=DSjHHRvAWZbZn7rO4ayyTdSQHmUk69XSfcYblZRi2GigTz7egKHgftzBMhDlTKZqpQ rVRz+qYXYgML7jisZkKc6fuCRUoPZh+eYZlr9IfNnHqh1rfw6PtwnrBNTCiTVbPQaqBq 0SY0w7tV4MihArMMzwO4fx5bkbzgYbT0+tuA1/vn4PcMN+DTODRHn+xtM86K9Zp2tSu1 o3E66ogbIINj/MyhdltkIeJhgRFmG6pc5YXfcfY5DVOO1HFyYNw+ps96UVk7zO/X057c OAVfAj9Vtm0LWTL4haOTcisgueR1IoEZnci1dNn5R59X8peeUC2pAhFimS1CWUTaewer p2pg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature; bh=Yn2hFXhX79WK1EuGevpcsoabHDFdbQfZxb2v8U67kDg=; fh=21G1sw374sKbJRu2kZXZn6M3Tsz/euKwXhn1v04cYK0=; b=uNgeT/Fk2gngw1XIm6cfP66WojVlil8M1KL+aaBfKQHFsEoN0GDElAsOc5fC7Flaro 5MhPLQX+aGNeIvVsDyJ1SWhvoPOV6bQNwydfr6JAw5uwm5PxgLkDmosQ3U66yB2nb7K+ 80NLIDQQc111pYxS32nf9K1HytjkB7uAiPZHr4hqyKIjvYG2gMbPVv5GSgXlAV6az3M7 tTXAkufmY5mBCk21vjbczZl4nmcZDy0GX4nmyYh+06oPpCaErRI+eB+a8Ctevb4nd9zG HKb/4oGkVXGCi7yFnjTTwjljjoBDz9C9bxXmTWUM9hfZlSNiwRDjDCqq606HvxYWEZYU BU5g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=2g5MBss+; arc=pass (i=1 spf=pass spfdomain=flex--surenb.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-215580-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-215580-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 a640c23a62f3a-a6f56e26485si213214566b.722.2024.06.14.16.12.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jun 2024 16:12:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-215580-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=2g5MBss+; arc=pass (i=1 spf=pass spfdomain=flex--surenb.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-215580-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-215580-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 AA55E1F23D13 for ; Fri, 14 Jun 2024 23:12:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8A89C1AB525; Fri, 14 Jun 2024 23:07:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="2g5MBss+" Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (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 3618519049A for ; Fri, 14 Jun 2024 23:05:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718406328; cv=none; b=EOQmkphqzeNIHT+ptHzJOrQVGaVMjtk2Vb+DBDse6+Covk3npNPvSej9cV5xKP8gPXuU9tT6/QWU0MBq8bpjK+nryd6/zTGHu6kBlp4VRgfo7ce7MebSae5XDNsD4dbp8pWf3LUdV+cWcygqTOvolZpzkLsuWhbVgDyKxOXkqkM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718406328; c=relaxed/simple; bh=JON1NdPgYPoWrnE0rBETijaw+SbmqmxVotV1RuOXvoc=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=mquHc5cPak5ZAg3Txyp0HDiMoFD2+gjK7i9+dNpr19gSIrxifwjuBwhjChEjIjBvLUNPq5CPkQLw7rpnc3BDA7eZeujnXDZvgsG1sNm8YAyK9AAHZH0RhQCJ4T+guyQvtvS4OetLcuOoQY6wano4MJG3daFjf8rm4Er2cuEXWRI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--surenb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=2g5MBss+; arc=none smtp.client-ip=209.85.219.201 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=flex--surenb.bounces.google.com Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dfe25446483so3888586276.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=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=Yn2hFXhX79WK1EuGevpcsoabHDFdbQfZxb2v8U67kDg=; b=2g5MBss+jYosVE+e4oF7hJvrL97VmnkItlxRQJ45oN24nTZ+v3HPEKyJOfFFYr4eoZ QvFxsZOGfpPauTswkh+KM/ryd2wYNW87P0fQZNCBT9unPqhSA4WvDWMNBHOJIz6S7k4V QmV6uFMjIEjcBxeSySj4E46SJHFa2TF30F9HLm9pdZ55SeDcivbNDhuJhMwJw01Mm3IH 52ZRJ4GzC+OHGDXRYvYCGfNByZcUiYpLpJyWgtbMfQgKcMEQ4QJpvpyvVeXsl1bU839I d6jcuhyGz9zUWf5vrcNS+0/FKfnukFtgary7QxNyQqlBrxT64r0pjnxFuHkQkDLjMoxh 91WQ== 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=LW50nH9dmYs68abHrltWmhcckMRBLl6/r77Z4G+j01tIuXquYXOiQ2x67fjA8pQ9CG EDKV10aT3m8ampp12XMQD3ZlCqcvFC3yEP5hnPxdbQ0iXv3vO1TvWaZh+2zauYjB8pCO 3R0ll3GnB887oZc8vDfVsI0yPPsWn4dd/o5oaLxpJK/QCvyIyGrDFEvJP4LfJIcHwngQ l5humFnx1heUfQWXT7egoi4/iYnmd4NBDVtyJVfBlCBaUl7t6V1/IAQoju1P9sIkn/vs S8nyUwwuzXvLqwTv0LZycH6Rl8eQXjz8vKIq2P3gFBO/BJhKdYXepZGFOB6CA4tNSziq 2vJA== X-Forwarded-Encrypted: i=1; AJvYcCWTqRc+1pV46U1GiDVVsu72SrEq0woMcMEQ8Ib0QDzlrN1jN/1doB5By63FQl+WQT8AVivul1FpRduRfyP6vRu9a44ntTnb8HEw8qy3 X-Gm-Message-State: AOJu0YyWYJE0/Il0QfJErH2Q4aXthHD36rATF3TsUNubuqKWGRZlgZIi FQ68yTuLilrrAjaq7SqnYGmfMZYCzHYyBTR4xoDtFS3QqhZX/uemm326bNJ5oAx5mSFCtcE93I+ Qvw== 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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 Content-Type: text/plain; charset="UTF-8" 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 --- 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_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; base-commit: c286c21ff94252f778515b21b6bebe749454a852 -- 2.45.2.627.g7a2c4fd464-goog