From patchwork Tue Aug 13 15:07:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13762199 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 693D2C52D7B for ; Tue, 13 Aug 2024 15:08:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AB1D56B009E; Tue, 13 Aug 2024 11:08:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A62366B009F; Tue, 13 Aug 2024 11:08:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8DB666B00A0; Tue, 13 Aug 2024 11:08:05 -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 701306B009E for ; Tue, 13 Aug 2024 11:08:05 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 1CCF71A0975 for ; Tue, 13 Aug 2024 15:08:05 +0000 (UTC) X-FDA: 82447552530.18.CAC86CA Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf24.hostedemail.com (Postfix) with ESMTP id 447A4180013 for ; Tue, 13 Aug 2024 15:08:02 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=4XZ9PoZp; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf24.hostedemail.com: domain of 30Xa7ZgYKCOgcebOXLQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=30Xa7ZgYKCOgcebOXLQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723561624; a=rsa-sha256; cv=none; b=N4jWFo7Pj0sZEBzbGOEJp5bnfHXhMSrpzxOX3T7mcGd27k8SS5EDZj71gk0QdorrnW3opr e1qxTB64fqjzs8ZDsG4WLXS4k6hmikYAZGdBFufQrrR0IeiNwRfgRzwpb7l6hbOPqNrX9N 6kAodPNXC2+FMEbrBHvRuRsLCqdqd4o= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=4XZ9PoZp; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf24.hostedemail.com: domain of 30Xa7ZgYKCOgcebOXLQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=30Xa7ZgYKCOgcebOXLQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723561624; 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=1x8HY6pqVTVF5kQzcpH4Ucp1zz0s1gAq4xU9MqMd/wE=; b=bBFQ0/v3P8ZsK0WxnjAwvoeDNV2n7MDPGHPZRaqNcuEr8vf6sNRzU+86st6gRBkS6FKA6S Zn0XiseXymY6kJPF3pfSp4/93dAuHu/GSNu/38zhXUEZJqo//3veDtymNZjOfDD9zQo6BX IaZx+T2jJs2AQoB2i+gnpWR+EMjQgA8= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e0b6584bbdcso8827277276.1 for ; Tue, 13 Aug 2024 08:08:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1723561681; x=1724166481; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=1x8HY6pqVTVF5kQzcpH4Ucp1zz0s1gAq4xU9MqMd/wE=; b=4XZ9PoZpFkiOtse445b4g66At+sG9GVDDT60nhr2Oal91+U5yc5caT5jVUbC+2BPEc rZCy7JvPzCpgLPZTFCmU5Yl9OJrqLIyWRUuJI/w5iLTe/TVTsCHp5X1AI24xbOjCY/EL onTtVh3w8RuGmexiA6Jmi6kBAurAh1B8ygUJglVts4Ox7hhn0a52YLCzT/T1FEIU0adR Pz3oVLz9ImOLJ0L5tgHULzIsY5TSUvyJdJ9oA4it780Jg5dgv2Y36khCoZsZ8YM/YzRY FxQS30yXHJoFImwRPOpFd9Z/9tICkva2uJb8zyCA4KpTurZ7QaPiRcgjeg0Wm7t74cOK v2qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723561681; x=1724166481; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=1x8HY6pqVTVF5kQzcpH4Ucp1zz0s1gAq4xU9MqMd/wE=; b=pN9YYLwL9G+NUQ6tkl8XIXb1wRJzdvmj/EZMS8p7Nt3Q5AhFEPYDICoYN7O1Kg1wpc zlkDpR6NpKX7kvlqikKeVyUlFgvC9Muc5WzKXlyBKpRh6jEsJc1tnfENMLlYFa1E0luC HmT7zQ6okHj83aCIr1O35IvJ9oSNb+HxxTyUBoH6LrSjrO61cHInRHIi7LFg60unACFj nFAGcX6qHGhJqGtwxX8eYEBBFWsYgF3nI3rq20rELVj4eoaoU/gUztSMNCLvdorCvyx8 adEIyE/7J67hRmPd95iQWDG9AVztJykhebnFUDeNfvCvjK7MeF6suwKx9q86IV5g19jI xxyQ== X-Forwarded-Encrypted: i=1; AJvYcCWClsdZVb/rQxyCmHdGU/fzUMVB1cQkUdHK1px5McqXpDtn2LT981E5Vl4PLFyhMD+ynhUkRNLwdE4f1YuQCogacho= X-Gm-Message-State: AOJu0Yy4XWfEdVlWl882ZsUfN5IFZeaW8FgUd5UC5m0vDvJF19nDQrz3 2cdwFB4Oh3+uvX1FxXiDF4zmlkoe6PUng6+cpmQiOIjLIphfMwodjpjInxvzuAw1rqwdzFU5k5o kbg== X-Google-Smtp-Source: AGHT+IEz36OwLmoBcnEL1WUUu6fUVYlI+FT85j7U+cB0aTgWoq2vINT4jdflqp8Za9uby33WBDXFm+7GRew= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:b416:2d8c:d850:78]) (user=surenb job=sendgmr) by 2002:a25:4844:0:b0:e05:eb99:5f84 with SMTP id 3f1490d57ef6-e113e9066d6mr4889276.4.1723561681199; Tue, 13 Aug 2024 08:08:01 -0700 (PDT) Date: Tue, 13 Aug 2024 08:07:56 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.46.0.76.ge559c4bf1a-goog Message-ID: <20240813150758.855881-1-surenb@google.com> Subject: [PATCH v3 1/2] alloc_tag: introduce clear_page_tag_ref() helper function From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: kent.overstreet@linux.dev, david@redhat.com, vbabka@suse.cz, pasha.tatashin@soleen.com, souravpanda@google.com, keescook@chromium.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, surenb@google.com, stable@vger.kernel.org X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 447A4180013 X-Stat-Signature: a7t7ttgjkwabkm9fcsy478sety84ahy1 X-Rspam-User: X-HE-Tag: 1723561682-272351 X-HE-Meta: U2FsdGVkX1+90s6g1IbY87FLWo0vrsvdF0oysdC3HroCbSXEQFLiMc2TgrS0p/CCU77xzijQIFGhCegc6Vn0NmHjaQTuiO0u1ENJTYCRnNFNxI+38FabIOIR831GelP3OGGDCEuV6i2snBDGjMXzpKRiTDTqlxT6o5C2dM1BaGB9xj1nRAFAMyXymY0fepV03eFZ0EuWfs5PeXq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4VqU/wZ4kK/HX9Gmx3d5fBf1hxa+de4Y1vk8ZXF0Ij5qeNEWpqd+4HHxhHH4FiV37URwLdGwUObgk/LTRRMJhsq/7i9k98gFamtrWgurk2IU++q5yZMC26hZTZxR3dYYhmdlY5T2FMLAJs2LFh53Z5x1upoImMf1m9cE3Wkd+CsaaxQxzAZNmIf1wjetOhQxXa7ErnCqp78AjOzPaSsQEfL9uCTtgXt33LtCEczz8wxNaCo+ovIK4Nif/GlFo0KN5DUWT+rF6USpUdS9o/H3Jfh9+oB68HeHb4SrA7LRWJyfOzOG30k7otAftdOz9lbAfKTFh6+pkiWh4H/mod2kSlN63oP8yF+BEttoA= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000140, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: In several cases we are freeing pages which were not allocated using common page allocators. For such cases, in order to keep allocation accounting correct, we should clear the page tag to indicate that the page being freed is expected to not have a valid allocation tag. Introduce clear_page_tag_ref() helper function to be used for this. Suggested-by: David Hildenbrand Signed-off-by: Suren Baghdasaryan Cc: stable@vger.kernel.org # v6.10 Acked-by: David Hildenbrand Reviewed-by: Pasha Tatashin --- include/linux/pgalloc_tag.h | 13 +++++++++++++ mm/mm_init.c | 10 +--------- mm/page_alloc.c | 9 +-------- 3 files changed, 15 insertions(+), 17 deletions(-) base-commit: d74da846046aeec9333e802f5918bd3261fb5509 diff --git a/include/linux/pgalloc_tag.h b/include/linux/pgalloc_tag.h index 18cd0c0c73d9..207f0c83c8e9 100644 --- a/include/linux/pgalloc_tag.h +++ b/include/linux/pgalloc_tag.h @@ -43,6 +43,18 @@ static inline void put_page_tag_ref(union codetag_ref *ref) page_ext_put(page_ext_from_codetag_ref(ref)); } +static inline void clear_page_tag_ref(struct page *page) +{ + if (mem_alloc_profiling_enabled()) { + union codetag_ref *ref = get_page_tag_ref(page); + + if (ref) { + set_codetag_empty(ref); + put_page_tag_ref(ref); + } + } +} + static inline void pgalloc_tag_add(struct page *page, struct task_struct *task, unsigned int nr) { @@ -126,6 +138,7 @@ static inline void pgalloc_tag_sub_pages(struct alloc_tag *tag, unsigned int nr) static inline union codetag_ref *get_page_tag_ref(struct page *page) { return NULL; } static inline void put_page_tag_ref(union codetag_ref *ref) {} +static inline void clear_page_tag_ref(struct page *page) {} static inline void pgalloc_tag_add(struct page *page, struct task_struct *task, unsigned int nr) {} static inline void pgalloc_tag_sub(struct page *page, unsigned int nr) {} diff --git a/mm/mm_init.c b/mm/mm_init.c index 75c3bd42799b..907c46b0773f 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -2460,15 +2460,7 @@ void __init memblock_free_pages(struct page *page, unsigned long pfn, } /* pages were reserved and not allocated */ - if (mem_alloc_profiling_enabled()) { - union codetag_ref *ref = get_page_tag_ref(page); - - if (ref) { - set_codetag_empty(ref); - put_page_tag_ref(ref); - } - } - + clear_page_tag_ref(page); __free_pages_core(page, order, MEMINIT_EARLY); } diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 28f80daf5c04..3f80e94a0b66 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -5821,14 +5821,7 @@ unsigned long free_reserved_area(void *start, void *end, int poison, const char void free_reserved_page(struct page *page) { - if (mem_alloc_profiling_enabled()) { - union codetag_ref *ref = get_page_tag_ref(page); - - if (ref) { - set_codetag_empty(ref); - put_page_tag_ref(ref); - } - } + clear_page_tag_ref(page); ClearPageReserved(page); init_page_count(page); __free_page(page);