From patchwork Fri Sep 6 04:21:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Zhao X-Patchwork-Id: 13793202 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 50BF1CE7AAE for ; Fri, 6 Sep 2024 04:21:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CC2C86B0089; Fri, 6 Sep 2024 00:21:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C71986B008C; Fri, 6 Sep 2024 00:21:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B12E46B008A; Fri, 6 Sep 2024 00:21:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 931CF6B0088 for ; Fri, 6 Sep 2024 00:21:21 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 1FD28160EC8 for ; Fri, 6 Sep 2024 04:21:21 +0000 (UTC) X-FDA: 82533013962.15.89D7FD8 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf20.hostedemail.com (Postfix) with ESMTP id 62DEC1C0009 for ; Fri, 6 Sep 2024 04:21:19 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=pW95mU8K; spf=pass (imf20.hostedemail.com: domain of 3PYPaZgYKCOokglTMaSaaSXQ.OaYXUZgj-YYWhMOW.adS@flex--yuzhao.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3PYPaZgYKCOokglTMaSaaSXQ.OaYXUZgj-YYWhMOW.adS@flex--yuzhao.bounces.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=1725596454; 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:in-reply-to:references:references:dkim-signature; bh=50wP6OBJW621Z1lTCrGAHD/paOiHcQB2J19sjWWdS44=; b=C2qvpUQqJsf5L6+PoKYfUoBVSAL8zTwbypkMibGrLDQNo6Ka9r73Z1vOwJsS9VCadOqlRM zIfzIUkVg77FuyTeel8zme88Smc4srDlG2Lb3KXNlMVdyrNbX3pxaA/OfQ1DOVzh0OjzMU ZMli0JCPpZx+0WKbJzf3GF4c4xkf6iQ= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=pW95mU8K; spf=pass (imf20.hostedemail.com: domain of 3PYPaZgYKCOokglTMaSaaSXQ.OaYXUZgj-YYWhMOW.adS@flex--yuzhao.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3PYPaZgYKCOokglTMaSaaSXQ.OaYXUZgj-YYWhMOW.adS@flex--yuzhao.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725596454; a=rsa-sha256; cv=none; b=rcxS6iqlCqsah9GP/LnMQ6aS5sCk14l+ASxDKDPNLCWi/q8jsBBuGZxH/QTFPTDoNGAkTQ cf7sQL6LruR6zWDttcKxXF7C5e17aEGGdOM/2SA9/Zx3e+dZZQO51oWlgL3a2ovfrgd9lU BdvvH62WEc1Y0JS926Q4pT8Rwv/WM1o= Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e03623b24ddso3881313276.1 for ; Thu, 05 Sep 2024 21:21:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1725596478; x=1726201278; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=50wP6OBJW621Z1lTCrGAHD/paOiHcQB2J19sjWWdS44=; b=pW95mU8KEFIHUoxNUkGfQFOfz0Fp1FGTIE45dnBxUQ50bCWFxxJsZZ25UMKAWrOYnZ OGbcThTEl8v5QkwcIDHSPYmElBGbVroUvaaHMPeBB9UDZDrztgWhibdibDPuki40NRUa S3BViweJYSJotOd2OBzlCR42QczfwlAOngha62L9Tbpuqzj3hyQaJPpsTvoWVEo5OQ9E XLSSZ9zB3+9dzAwgaG2Vw3+V+S8PKlEmtavJkqkeGG7BvVs/i5f5pDO2DZvLvOEjWZGD kyB/ap0LqNpa4sy08tjbVoRShXL+jqOHI/Y+gUOsnQ4Sz9LI4CK7c6mE5UPutIfm1uzn ZsFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725596478; x=1726201278; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=50wP6OBJW621Z1lTCrGAHD/paOiHcQB2J19sjWWdS44=; b=MJT7t7IJsCnaLNMVLuRjajdekHhnL4qCfAa80dsjsv+CKIbMK+bifsW7M3vuEUT5P2 geaKxwb0SyDTzGdGWkHEjXpHbEUb72ejGP1VPXiZSjxMAW7aDwlgbR1w9oY/4uq2heVu AmLay2xZBB1GdYOPgfDuq52qGGExFkTrr2t5XCM3L4nVnLs9ZKWHkrz3gx5I1ONm44Vu V8DLmiGqMtNM2rQ+ZMVuGHHy3gaVuH8sKykM2+DUDS+pXTm5H71IzfElMVKK6NXPO96q Odjx8Cd27C9mlNjaExlL6L3SkoQNsDkcYcbulwKzc0l05VAsx4ZQud/A+CbGseGDRgYA twSQ== X-Forwarded-Encrypted: i=1; AJvYcCXXEBVzPFeU1V0nNDUg78pciOgOJDZr3rn/5ypdDRcbPLn+xKt9rvqeaEzUnBjSHAY5YVsqsUqKng==@kvack.org X-Gm-Message-State: AOJu0YyeQbD8xLTUYyjnCD7tPaH+qMgqQUdzzbmVYgv/W3Ivtd6SM5CL fErpL2Rf1qbGPjZPkPOT5scdaV6Swb0FTO09b8+cUIiAmMDwE5R/eHu5msIUUHqNnVELkN2vpsM B9g== X-Google-Smtp-Source: AGHT+IF4EfUu9keMzscep5B8o/9Ylkdf8A/cgbCOdPnpDmV6X9nqkqfVEQVj/bbPL42JtNauX/vBJjc/UKI= X-Received: from yuzhao2.bld.corp.google.com ([2a00:79e0:2e28:6:5b7a:cdaf:9b3d:354a]) (user=yuzhao job=sendgmr) by 2002:a25:d84e:0:b0:e11:5da7:337 with SMTP id 3f1490d57ef6-e1d3487f694mr2558276.3.1725596477951; Thu, 05 Sep 2024 21:21:17 -0700 (PDT) Date: Thu, 5 Sep 2024 22:21:08 -0600 In-Reply-To: <20240906042108.1150526-1-yuzhao@google.com> Mime-Version: 1.0 References: <20240906042108.1150526-1-yuzhao@google.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog Message-ID: <20240906042108.1150526-3-yuzhao@google.com> Subject: [PATCH mm-unstable v2 3/3] mm/codetag: add pgalloc_tag_copy() From: Yu Zhao To: Andrew Morton , Kent Overstreet , Suren Baghdasaryan Cc: Muchun Song , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Yu Zhao , stable@vger.kernel.org X-Rspam-User: X-Stat-Signature: bbgufshobypi1to4qwx89qi6gzah86tz X-Rspamd-Queue-Id: 62DEC1C0009 X-Rspamd-Server: rspam11 X-HE-Tag: 1725596479-448835 X-HE-Meta: U2FsdGVkX1+rGBhpxQzNdwVP8ZV9jpybc6bD6YpXzfiUYJaae6A2JjvJIqgqfwqgps+jcL8fD/4OYVSFrxL3m23pKdQxWs9BbwHumDFucMxwSkxlJQarY1B8inXvubpRRGq6MYRnkgbesq7njt++bMK9L6uTfVdvH39/uFwI/0U3D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rYdup/02hZkjXxErzBkWd450w3dAf/w7u/NUQEnbAAXSks7B2Ja99m6a6GTz5aZhHrsuV6ACaOukuncI/aUS6vyFAHphLq/bSVHwNTGdCQWqOBm4E1JNsOtdyYP2v95NNSZNdx+XnJfW2bXXw/EMRZzY8VXrW5ZXXviYzWXFP8FNnSlV5ECx4SjBxyfxOmZLUv4yYOCeVUBIsb2uTodwDWYwTx5mD0dMyJaU/CX1PQ3cuyFvUXLPo96nyhHrlQxj4hgYFq0Pr7yncCcYpW9ln4gPK5oZ5w6CmjPhQuOmAdimrZPBbzVkp2zte7ux+nUhIDqwP0OfXdAZ8Nc0lP154yKrGJWvdotKrpnU= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000004, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Add pgalloc_tag_copy() to transfer the codetag from the old folio to the new one during migration. This makes original allocation sites persist cross migration rather than lump into the get_new_folio callbacks passed into migrate_pages(), e.g., compaction_alloc(): # echo 1 >/proc/sys/vm/compact_memory # grep compaction_alloc /proc/allocinfo Before this patch: 132968448 32463 mm/compaction.c:1880 func:compaction_alloc After this patch: 0 0 mm/compaction.c:1880 func:compaction_alloc Fixes: dcfe378c81f7 ("lib: introduce support for page allocation tagging") Signed-off-by: Yu Zhao Acked-by: Suren Baghdasaryan Cc: --- include/linux/alloc_tag.h | 24 ++++++++++-------------- include/linux/mm.h | 27 +++++++++++++++++++++++++++ mm/migrate.c | 1 + 3 files changed, 38 insertions(+), 14 deletions(-) diff --git a/include/linux/alloc_tag.h b/include/linux/alloc_tag.h index 896491d9ebe8..1f0a9ff23a2c 100644 --- a/include/linux/alloc_tag.h +++ b/include/linux/alloc_tag.h @@ -137,7 +137,16 @@ static inline void alloc_tag_sub_check(union codetag_ref *ref) {} /* Caller should verify both ref and tag to be valid */ static inline void __alloc_tag_ref_set(union codetag_ref *ref, struct alloc_tag *tag) { + alloc_tag_add_check(ref, tag); + if (!ref || !tag) + return; + ref->ct = &tag->ct; +} + +static inline void alloc_tag_ref_set(union codetag_ref *ref, struct alloc_tag *tag) +{ + __alloc_tag_ref_set(ref, tag); /* * We need in increment the call counter every time we have a new * allocation or when we split a large allocation into smaller ones. @@ -147,22 +156,9 @@ static inline void __alloc_tag_ref_set(union codetag_ref *ref, struct alloc_tag this_cpu_inc(tag->counters->calls); } -static inline void alloc_tag_ref_set(union codetag_ref *ref, struct alloc_tag *tag) -{ - alloc_tag_add_check(ref, tag); - if (!ref || !tag) - return; - - __alloc_tag_ref_set(ref, tag); -} - static inline void alloc_tag_add(union codetag_ref *ref, struct alloc_tag *tag, size_t bytes) { - alloc_tag_add_check(ref, tag); - if (!ref || !tag) - return; - - __alloc_tag_ref_set(ref, tag); + alloc_tag_ref_set(ref, tag); this_cpu_add(tag->counters->bytes, bytes); } diff --git a/include/linux/mm.h b/include/linux/mm.h index a07e93adb8ad..d750be768121 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -4161,10 +4161,37 @@ static inline void pgalloc_tag_split(struct folio *folio, int old_order, int new } } } + +static inline void pgalloc_tag_copy(struct folio *new, struct folio *old) +{ + struct alloc_tag *tag; + union codetag_ref *ref; + + tag = pgalloc_tag_get(&old->page); + if (!tag) + return; + + ref = get_page_tag_ref(&new->page); + if (!ref) + return; + + /* Clear the old ref to the original allocation tag. */ + clear_page_tag_ref(&old->page); + /* Decrement the counters of the tag on get_new_folio. */ + alloc_tag_sub(ref, folio_nr_pages(new)); + + __alloc_tag_ref_set(ref, tag); + + put_page_tag_ref(ref); +} #else /* !CONFIG_MEM_ALLOC_PROFILING */ static inline void pgalloc_tag_split(struct folio *folio, int old_order, int new_order) { } + +static inline void pgalloc_tag_copy(struct folio *new, struct folio *old) +{ +} #endif /* CONFIG_MEM_ALLOC_PROFILING */ #endif /* _LINUX_MM_H */ diff --git a/mm/migrate.c b/mm/migrate.c index 0f6b78fd73aa..dfdb3a136bf8 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -743,6 +743,7 @@ void folio_migrate_flags(struct folio *newfolio, struct folio *folio) folio_set_readahead(newfolio); folio_copy_owner(newfolio, folio); + pgalloc_tag_copy(newfolio, folio); mem_cgroup_migrate(folio, newfolio); }