From patchwork Thu Nov 28 10:26:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wang <00107082@163.com> X-Patchwork-Id: 13895588 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 9B272E7716D for ; Thu, 5 Dec 2024 15:33:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 27C3D6B012F; Thu, 5 Dec 2024 10:19:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6B6316B0099; Thu, 5 Dec 2024 10:19:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6457A6B00F2; Thu, 5 Dec 2024 10:19:14 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 55B046B0088 for ; Thu, 28 Nov 2024 05:26:46 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id BBF491A0C67 for ; Thu, 28 Nov 2024 10:26:45 +0000 (UTC) X-FDA: 82835124792.27.DED6ACD Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.2]) by imf06.hostedemail.com (Postfix) with ESMTP id 96202180002 for ; Thu, 28 Nov 2024 10:26:38 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=163.com header.s=s110527 header.b=Md8ueVcS; spf=pass (imf06.hostedemail.com: domain of 00107082@163.com designates 117.135.210.2 as permitted sender) smtp.mailfrom=00107082@163.com; dmarc=pass (policy=none) header.from=163.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732789599; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=PlN/JwIS08XOn3UybnRLA84jTD+KAdku/dbRhzO6KGc=; b=vEaTv9kiYvcbOx3ozHlE0DRGKMLYPaTj5AeqDHVAjNIAG3Ludkyv6MxJs8RUQSadYFipXN YaVhclVdxp3JWEgkUbnLjLgOjNrZ8JyY7Ktf/jslFddWY3YhOKk+qoiGRpaVIHhLtLHmNV zuCAH34QdHIKDPET74Fux/8ddfYIQUg= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=163.com header.s=s110527 header.b=Md8ueVcS; spf=pass (imf06.hostedemail.com: domain of 00107082@163.com designates 117.135.210.2 as permitted sender) smtp.mailfrom=00107082@163.com; dmarc=pass (policy=none) header.from=163.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732789599; a=rsa-sha256; cv=none; b=feXzIh33wHtf16zYHkdI6HBircJkBBJ4t2fz5Yr5Q1c5Rj6Q8JoKD0IWX8TYT54NUAEWbl tMG3e3eiCotWEFphJ0cClE/TKL3GwuVa3amCsGG1ZgbjenM+TLRRlP47flzxRnqv4rp+uE k7R1l6GXEc3GiQsf4dhYi7f0f4b+KsQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=PlN/J wIS08XOn3UybnRLA84jTD+KAdku/dbRhzO6KGc=; b=Md8ueVcSicnAnQS4Kd45n BrIWQ3k6HvfYs4gXiqd1I2TEzXQqqUsfeV/HtvTiWw+li4Roq/D+vT45CM2RSqQG GzKZXJb7Fuzpce0lgbHavmEr2aft8nYNQNrYXZK/rpTMdD6ltMghhyh7fR57pg7F 7lhk8730PTrprlJt+Pglkc= Received: from localhost.localdomain (unknown [111.35.188.140]) by gzga-smtp-mtada-g1-3 (Coremail) with SMTP id _____wDXry1MRUhn8LrHAw--.22498S4; Thu, 28 Nov 2024 18:26:34 +0800 (CST) From: David Wang <00107082@163.com> To: surenb@google.com, kent.overstreet@linux.dev, yuzhao@google.com, akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, David Wang <00107082@163.com> Subject: [PATCH] mm/codetag: swap tags when migrate pages Date: Thu, 28 Nov 2024 18:26:19 +0800 Message-Id: <20241128102619.707071-1-00107082@163.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-CM-TRANSID: _____wDXry1MRUhn8LrHAw--.22498S4 X-Coremail-Antispam: 1Uf129KBjvJXoWxWr15JF1fKFWfWF4xXFy8AFb_yoW5KFy7pF Wj9wnxGa98GFy7WFWvvF4qvw13J397Kay7AFW2ga4fu3WYyr4kKryDt34jqF4UuFyUJFn2 vrsFqr1jgF1UJ37anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0pE8nYUUUUUU= X-Originating-IP: [111.35.188.140] X-CM-SenderInfo: qqqrilqqysqiywtou0bp/1tbiMxulqmdIPjvEigAAsD X-Rspamd-Server: rspam05 X-Stat-Signature: 1urmz74h9m1e4ncfyh6b9ewyimdn43u3 X-Rspamd-Queue-Id: 96202180002 X-Rspam-User: X-HE-Tag: 1732789598-586288 X-HE-Meta: U2FsdGVkX18oqU4b+SjJ1VM5PVgl9jddKn8ZBaeAaCRay7Ysx8EnwdTYe3hWTGttgbJy2sxr3rzcYNAOrFM+vQ5c79bt53V5DEW2+cR9NeLrkaeMp+HqW+RMSzcLS0zO+iwOlfihkc9B/GKoynsqbkDrGy8Lb0T241e4jCdGvOrba4uig9VaOAH9NvCM/UVC4x1jvOPDYhnbjLAzMk7kfmO4YVT30lCKq0oMFoswyaOPWJAZravsXs3vU3HC9Ue3YrvKmP2UsIHLwJCOuowRANv7tZprWjZhckElQ1PvylaJJaPOEw3xLIoyz10wVV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qsR3gK257kscl1jEoY/5xgC5iyW3oYHuyV54IhyHCBlHqOKmWcHS0xj3WqxrSOzs6dY4+CwhWPyIlSl443toisDYmYFbEOK3NfN 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: The initial solution for codetag adjustment during page migration uses three kinds of low level plumbings, those steps can be replaced by swapping tags, which only needs one kind of low level plumbing, and code is more clear. Signed-off-by: David Wang <00107082@163.com> Link: https://lore.kernel.org/lkml/20241124074318.399027-1-00107082@163.com/ --- include/linux/pgalloc_tag.h | 4 ++-- lib/alloc_tag.c | 35 +++++++++++++++++++---------------- mm/migrate.c | 2 +- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/include/linux/pgalloc_tag.h b/include/linux/pgalloc_tag.h index 0e43ab653ab6..3469c4b20105 100644 --- a/include/linux/pgalloc_tag.h +++ b/include/linux/pgalloc_tag.h @@ -231,7 +231,7 @@ static inline void pgalloc_tag_sub_pages(struct alloc_tag *tag, unsigned int nr) } void pgalloc_tag_split(struct folio *folio, int old_order, int new_order); -void pgalloc_tag_copy(struct folio *new, struct folio *old); +void pgalloc_tag_swap(struct folio *new, struct folio *old); void __init alloc_tag_sec_init(void); @@ -245,7 +245,7 @@ static inline struct alloc_tag *pgalloc_tag_get(struct page *page) { return NULL static inline void pgalloc_tag_sub_pages(struct alloc_tag *tag, unsigned int nr) {} static inline void alloc_tag_sec_init(void) {} 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) {} +static inline void pgalloc_tag_swap(struct folio *new, struct folio *old) {} #endif /* CONFIG_MEM_ALLOC_PROFILING */ diff --git a/lib/alloc_tag.c b/lib/alloc_tag.c index 2414a7ee7ec7..b45efde50c40 100644 --- a/lib/alloc_tag.c +++ b/lib/alloc_tag.c @@ -189,26 +189,29 @@ void pgalloc_tag_split(struct folio *folio, int old_order, int new_order) } } -void pgalloc_tag_copy(struct folio *new, struct folio *old) +void pgalloc_tag_swap(struct folio *new, struct folio *old) { - union pgtag_ref_handle handle; - union codetag_ref ref; - struct alloc_tag *tag; + union pgtag_ref_handle handles[2]; + union codetag_ref refs[2]; + struct alloc_tag *tags[2]; + struct folio *folios[2] = {new, old}; + int i; - tag = pgalloc_tag_get(&old->page); - if (!tag) - return; + for (i = 0; i < 2; i++) { + tags[i] = pgalloc_tag_get(&folios[i]->page); + if (!tags[i]) + return; + if (!get_page_tag_ref(&folios[i]->page, &refs[i], &handles[i])) + return; + } - if (!get_page_tag_ref(&new->page, &ref, &handle)) - return; + swap(tags[0], tags[1]); - /* 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_size(new)); - __alloc_tag_ref_set(&ref, tag); - update_page_tag_ref(handle, &ref); - put_page_tag_ref(handle); + for (i = 0; i < 2; i++) { + __alloc_tag_ref_set(&refs[i], tags[i]); + update_page_tag_ref(handles[i], &refs[i]); + put_page_tag_ref(handles[i]); + } } static void shutdown_mem_profiling(bool remove_file) diff --git a/mm/migrate.c b/mm/migrate.c index 2ce6b4b814df..cc68583c86f9 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -745,7 +745,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); + pgalloc_tag_swap(newfolio, folio); mem_cgroup_migrate(folio, newfolio); }