From patchwork Mon Aug 19 15:15:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13768490 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 BBFFDC5320E for ; Mon, 19 Aug 2024 15:15:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3EBDE6B008C; Mon, 19 Aug 2024 11:15:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 39BAC6B0092; Mon, 19 Aug 2024 11:15:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1EE276B0093; Mon, 19 Aug 2024 11:15:24 -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 F3DE96B008C for ; Mon, 19 Aug 2024 11:15:23 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id BA0A5A13A1 for ; Mon, 19 Aug 2024 15:15:23 +0000 (UTC) X-FDA: 82469343726.16.B6C2FCC Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf04.hostedemail.com (Postfix) with ESMTP id DC6C440006 for ; Mon, 19 Aug 2024 15:15:21 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="h/H9P7l/"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf04.hostedemail.com: domain of 3iGHDZgYKCJUHJG3C05DD5A3.1DBA7CJM-BB9Kz19.DG5@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3iGHDZgYKCJUHJG3C05DD5A3.1DBA7CJM-BB9Kz19.DG5@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724080435; 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=JgTjJwDNOOBGmN3SYEoTtFKEJl/MBoFNsUNbiHHZqOc=; b=48RMXEHtTofDekt7vsvEO3xUwkuhw+Bqgo2nRzbjqC7lgNweoL4YHF8X7c1GiabcGiezhh wtp1nFtkVfZJ/1jYaBA/wgSfP6tQZeiV/8MkuHSlv2nVYAOQWMe/zad/NRS1mSbDnEa8D5 7O7l7k8wcqeUOEwEuG9Yw3MS0plX8S4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724080435; a=rsa-sha256; cv=none; b=X6xL3bY+AgrxLOkWCzJnr12V3izPZXYwuaIsd5FbYfiS8Fm57UFfZYh408GFS4SSkNAB7l TO6+P+8VwZOKKZ01iLIzkXbk2fNDn+8109l0vznEOT2gB53axVf0gUAYx5S/mBC67H/MXQ ln5Wa+SoxYOiGCjyj+KIne1eoLAgNV4= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="h/H9P7l/"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf04.hostedemail.com: domain of 3iGHDZgYKCJUHJG3C05DD5A3.1DBA7CJM-BB9Kz19.DG5@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3iGHDZgYKCJUHJG3C05DD5A3.1DBA7CJM-BB9Kz19.DG5@flex--surenb.bounces.google.com Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6adcb88da08so88462947b3.3 for ; Mon, 19 Aug 2024 08:15:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1724080521; x=1724685321; 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=JgTjJwDNOOBGmN3SYEoTtFKEJl/MBoFNsUNbiHHZqOc=; b=h/H9P7l/ze4L1ylPdOLHnqMnWxWfwefgcfcOnHMXHYI6qRHgDQ8mxRC2o5PbDNTB92 pjOkGJcauj57iqFYT30Hvl1dmcDpzH4Ztm7p59AhttIYkX9W2LUtIUKxubGjWMtWg0JO mTv0AOWtaD6YQQlLzxrCUDRwWweGXBnn97UpUgtX4A8ZQ3KV2RWkes1OpY1kRyQbsxbC rhGPE2Exi8ZKKsx75IG6zGJlmuAhobPFcrN1FBL0W5HDptDr4Cba8OSd2dXunNJNFLdw +13ZCWalR8WWzPQ4lup9fVMz69QWHSRwv14PAmcaE3pBW3lWbk/CRvnCfVeAFSQD6TEt fWzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724080521; x=1724685321; 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=JgTjJwDNOOBGmN3SYEoTtFKEJl/MBoFNsUNbiHHZqOc=; b=QDuI5Y+EqDVn8g6uI8c+71MMZ4gdkfa3YuRmsEArjfrZjFldDYYEKWJvulL9VKa30U V+pKgg1za3p8wnJ5oeNX8P/Lszd/nbG/JixDc5hJJzW8m4mZOO1cSTbePKw2z2Y+qvaE rwRzD8v6XLPKocgqE11K5FeBnIyuW5u+4gCZdOOFdGHr7tbNgM8hiN6rao5+rydt6Mhw Z45ikryr9ul+Ud1MBfAaKpYrdMs/lHTT5winCBSXDm0aQF1GgSFM5PL8hc/WMyjKlM9M Sm1DsVxRxoa3CNkkwXTHZ5KHD0pesyEd3an/sPyE9hV0TzzzKpm3uklVYRkjjTz3iCIb QUew== X-Forwarded-Encrypted: i=1; AJvYcCUkO/jZvkssVCSE81uOUEqf13WZnmNUodlbaFp3Q72tuW0eWwRnm2CFIn63dQXfutPBx4tArtSP6W7B/+dJtP8cLPM= X-Gm-Message-State: AOJu0Ywgw6hILtg3bwJE0Mxz+U11QJonZ97836Fq256nDH7x8m95pxS+ 7Dgcm5F5wM/rgy5aRYPRnIBlQo3cSE/p2Yfv5KTNgTvbNclolaxakGniJLI2UlrhiV/l0/wi0x6 QAw== X-Google-Smtp-Source: AGHT+IF6wQq4hojn2WvBl6Ky3Y5Ec+1miO/ZVJTIsvzHPNXwtXX0T5qfBPLHg5VMXezc7PRztRYvs2+xsUs= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:5aea:cf26:50f4:76db]) (user=surenb job=sendgmr) by 2002:a05:690c:4e0e:b0:64a:d1b0:4f24 with SMTP id 00721157ae682-6b1bba55dd5mr2194777b3.7.1724080520869; Mon, 19 Aug 2024 08:15:20 -0700 (PDT) Date: Mon, 19 Aug 2024 08:15:09 -0700 In-Reply-To: <20240819151512.2363698-1-surenb@google.com> Mime-Version: 1.0 References: <20240819151512.2363698-1-surenb@google.com> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog Message-ID: <20240819151512.2363698-4-surenb@google.com> Subject: [PATCH 3/5] alloc_tag: introduce pgalloc_tag_ref to abstract page tag references From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: kent.overstreet@linux.dev, corbet@lwn.net, arnd@arndb.de, mcgrof@kernel.org, rppt@kernel.org, paulmck@kernel.org, thuth@redhat.com, tglx@linutronix.de, bp@alien8.de, xiongwei.song@windriver.com, ardb@kernel.org, david@redhat.com, vbabka@suse.cz, mhocko@suse.com, hannes@cmpxchg.org, roman.gushchin@linux.dev, dave@stgolabs.net, willy@infradead.org, liam.howlett@oracle.com, pasha.tatashin@soleen.com, souravpanda@google.com, keescook@chromium.org, dennis@kernel.org, jhubbard@nvidia.com, yuzhao@google.com, vvvvvv@google.com, rostedt@goodmis.org, iamjoonsoo.kim@lge.com, rientjes@google.com, minchan@google.com, kaleshsingh@google.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-modules@vger.kernel.org, kernel-team@android.com, surenb@google.com X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: DC6C440006 X-Stat-Signature: p4r16nt7je5xhid36ufewdot7j3pxzej X-Rspam-User: X-HE-Tag: 1724080521-921719 X-HE-Meta: U2FsdGVkX18Rao4SgnMPBm/1chzHy+UaO2qLtOrcvTTkXyv2VmkEBX7jLhogD7YM56C9oVEObB6C8AosJDQ6trq1FYaMQhG6DO7cEIp9Jt0lA2hW+K+pwj0VsnNzsOtpbr6EBi/58sEmXJE2CgWsjLLjKANXJiu6c0ADoezP4n4prxy20ltwo6z15DCyt74e7kHxaVw5r62gf8kegBDHKrH9yeGxTAXVxT0rrLxImc4EUlKpKZVk4kjUUfsF2ctZmQB2CzU3MiuJDmaQLQ8Dj7R/lOHmNgNbSrasKA9umD1VIafseJAK7IWdpw7RRNzzGm8lpgRT02sBUN09b0FcBqN1eVESo1tdId2Bjjwa2OwOnipv7zkDFNlSHL84HA7hGDwcZZn0w5R2pTqiSoHf9PYSJVRWF0cMo3zmaM5ityhkxH/FhBLL9EUJxGaMcQkcx7l0eK6LfHrbkMmUY1LvzutCfTcpdDTfW9DFO3ykZd4j/MRvNy2R9DYj0yNbgkO2f1gPCfihF6+YNo+3Xp0gJLT072lz4EvPqWsHSd4ojEDfn8r/AwafA2m7UE6AarWq1qZfG52u1yBDHszHSYLhhm++Lbt86/PbTiL+v18/jJVR3jRHEIqASW+Wec7644/6pb622JRmihdmCnWW6GWOSA95w2HJzilmK2A8sExTtxQF5rGgdVuBeUfWzl1YXllzPeigX8cX+DUNpHjnOArXCAl6Gy2uj/px2Ta/4JETP8LYtODAFTMkxCOB3s9H4H6ndhYTcNgaksNIP70MEzOLkXAapSD/5DSsqnNvLtEg/FMFPLzI/m5r0/+Ih21Rea/1yFVB8qJ3TVnWz20T3lc4TozJiDyVZDmAHQJBosEsXAP3Ul3TfyTtUAuEUnnmSOktKpGQ+JZmCGFGxyOu6q2A7wjyQmQ99mBBvnkDaNEY7iZWI37VAoM2TJ3mby3tV6GfkSUg7WkFi/zvatPHM7g e7quZFou 59rFf4fEeiTA6z7AdKWGF5p+ikeq22rBRNjoP07TaQGmFKALePa9B5M0JO37f5hEVHWNyuY7GJzlUjw/mIlIlW2OWsheBqwHzdnIriR/w/WX7m0L29dQgOlzzGv/GyKxwcDeoStcLxpLOQG+Iar2cDakVZ+X40sb6Q6yqoqMFGNes6sBMJFkF3e2y3BEzzrVQuob0GM9AhIz6oPwcJpCd3wraiLSNkIUBCoF4Sojr6AB1KQpod5vHpKNFmut/8ZO548lL2nKwXv6YC+IIsqwrUYeX0EfX2f2ygixOFeE6Z6yjKn9sLmVBPXgGZZpCH67kI9xKowiX1Zw6RsP2bMZnRWVSj7lQ5OiKFiuBF4Iu/fRIdEOObOvEUcqBrplQ5G/TKRxoo19QC0mO33jyJ1OOB8CVrdbPClmYKKUuBjWWDdCxFTEw+mxmqPVTgcUryy6WRgZCZ0N5m2pOhlwwGNYOYP+Y5aPgl2ikwAsoz9IFHgDjBnYWsEgwmrzHcMb1GnsU+Z+OjVGJ0nCGX07lgMGTEPgO2CYhIey7b1VgNgjS8nEZ3xlf9B4ktvaIivVboS4X3prG 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: To simplify later changes to page tag references, introduce new pgalloc_tag_ref and pgtag_ref_handle types. This allows easy replacement of page_ext as a storage of page allocation tags Signed-off-by: Suren Baghdasaryan --- include/linux/pgalloc_tag.h | 144 +++++++++++++++++++++++------------- lib/alloc_tag.c | 3 +- 2 files changed, 95 insertions(+), 52 deletions(-) diff --git a/include/linux/pgalloc_tag.h b/include/linux/pgalloc_tag.h index 244a328dff62..c76b629d0206 100644 --- a/include/linux/pgalloc_tag.h +++ b/include/linux/pgalloc_tag.h @@ -9,48 +9,76 @@ #ifdef CONFIG_MEM_ALLOC_PROFILING +typedef union codetag_ref pgalloc_tag_ref; + +static inline void read_pgref(pgalloc_tag_ref *pgref, union codetag_ref *ref) +{ + ref->ct = pgref->ct; +} + +static inline void write_pgref(pgalloc_tag_ref *pgref, union codetag_ref *ref) +{ + pgref->ct = ref->ct; +} #include extern struct page_ext_operations page_alloc_tagging_ops; -static inline union codetag_ref *codetag_ref_from_page_ext(struct page_ext *page_ext) +static inline pgalloc_tag_ref *pgref_from_page_ext(struct page_ext *page_ext) { - return (union codetag_ref *)page_ext_data(page_ext, &page_alloc_tagging_ops); + return (pgalloc_tag_ref *)page_ext_data(page_ext, &page_alloc_tagging_ops); } -static inline struct page_ext *page_ext_from_codetag_ref(union codetag_ref *ref) +static inline struct page_ext *page_ext_from_pgref(pgalloc_tag_ref *pgref) { - return (void *)ref - page_alloc_tagging_ops.offset; + return (void *)pgref - page_alloc_tagging_ops.offset; } +typedef pgalloc_tag_ref *pgtag_ref_handle; + /* Should be called only if mem_alloc_profiling_enabled() */ -static inline union codetag_ref *get_page_tag_ref(struct page *page) +static inline pgtag_ref_handle get_page_tag_ref(struct page *page, union codetag_ref *ref) { if (page) { struct page_ext *page_ext = page_ext_get(page); - if (page_ext) - return codetag_ref_from_page_ext(page_ext); + if (page_ext) { + pgalloc_tag_ref *pgref = pgref_from_page_ext(page_ext); + + read_pgref(pgref, ref); + return pgref; + } } return NULL; } -static inline void put_page_tag_ref(union codetag_ref *ref) +static inline void put_page_tag_ref(pgtag_ref_handle pgref) { - if (WARN_ON(!ref)) + if (WARN_ON(!pgref)) return; - page_ext_put(page_ext_from_codetag_ref(ref)); + page_ext_put(page_ext_from_pgref(pgref)); +} + +static inline void update_page_tag_ref(pgtag_ref_handle pgref, union codetag_ref *ref) +{ + if (WARN_ON(!pgref || !ref)) + return; + + write_pgref(pgref, 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); + pgtag_ref_handle handle; + union codetag_ref ref; + + handle = get_page_tag_ref(page, &ref); + if (handle) { + set_codetag_empty(&ref); + update_page_tag_ref(handle, &ref); + put_page_tag_ref(handle); } } } @@ -59,11 +87,14 @@ static inline void pgalloc_tag_add(struct page *page, struct task_struct *task, unsigned int nr) { if (mem_alloc_profiling_enabled()) { - union codetag_ref *ref = get_page_tag_ref(page); - - if (ref) { - alloc_tag_add(ref, task->alloc_tag, PAGE_SIZE * nr); - put_page_tag_ref(ref); + pgtag_ref_handle handle; + union codetag_ref ref; + + handle = get_page_tag_ref(page, &ref); + if (handle) { + alloc_tag_add(&ref, task->alloc_tag, PAGE_SIZE * nr); + update_page_tag_ref(handle, &ref); + put_page_tag_ref(handle); } } } @@ -71,53 +102,58 @@ static inline void pgalloc_tag_add(struct page *page, struct task_struct *task, static inline void pgalloc_tag_sub(struct page *page, unsigned int nr) { if (mem_alloc_profiling_enabled()) { - union codetag_ref *ref = get_page_tag_ref(page); - - if (ref) { - alloc_tag_sub(ref, PAGE_SIZE * nr); - put_page_tag_ref(ref); + pgtag_ref_handle handle; + union codetag_ref ref; + + handle = get_page_tag_ref(page, &ref); + if (handle) { + alloc_tag_sub(&ref, PAGE_SIZE * nr); + update_page_tag_ref(handle, &ref); + put_page_tag_ref(handle); } } } static inline void pgalloc_tag_split(struct page *page, unsigned int nr) { - int i; - struct page_ext *first_page_ext; - struct page_ext *page_ext; - union codetag_ref *ref; + pgtag_ref_handle first_pgref; + union codetag_ref first_ref; struct alloc_tag *tag; + int i; if (!mem_alloc_profiling_enabled()) return; - first_page_ext = page_ext = page_ext_get(page); - if (unlikely(!page_ext)) + first_pgref = get_page_tag_ref(page, &first_ref); + if (unlikely(!first_pgref)) return; - ref = codetag_ref_from_page_ext(page_ext); - if (!ref->ct) + if (!first_ref.ct) goto out; - tag = ct_to_alloc_tag(ref->ct); - page_ext = page_ext_next(page_ext); + tag = ct_to_alloc_tag(first_ref.ct); for (i = 1; i < nr; i++) { - /* Set new reference to point to the original tag */ - ref = codetag_ref_from_page_ext(page_ext); - alloc_tag_add_check(ref, tag); - if (ref) { - ref->ct = &tag->ct; + pgtag_ref_handle handle; + union codetag_ref ref; + + page++; + handle = get_page_tag_ref(page, &ref); + if (handle) { + /* Set new reference to point to the original tag */ + alloc_tag_add_check(&ref, tag); + ref.ct = &tag->ct; /* * We need in increment the call counter every time we split a * large allocation into smaller ones because when we free each * part the counter will be decremented. */ this_cpu_inc(tag->counters->calls); + update_page_tag_ref(handle, &ref); + put_page_tag_ref(handle); } - page_ext = page_ext_next(page_ext); } out: - page_ext_put(first_page_ext); + put_page_tag_ref(first_pgref); } static inline struct alloc_tag *pgalloc_tag_get(struct page *page) @@ -125,13 +161,15 @@ static inline struct alloc_tag *pgalloc_tag_get(struct page *page) struct alloc_tag *tag = NULL; if (mem_alloc_profiling_enabled()) { - union codetag_ref *ref = get_page_tag_ref(page); - - alloc_tag_sub_check(ref); - if (ref) { - if (ref->ct) - tag = ct_to_alloc_tag(ref->ct); - put_page_tag_ref(ref); + pgtag_ref_handle handle; + union codetag_ref ref; + + handle = get_page_tag_ref(page, &ref); + if (handle) { + alloc_tag_sub_check(&ref); + if (ref.ct) + tag = ct_to_alloc_tag(ref.ct); + put_page_tag_ref(handle); } } @@ -146,8 +184,12 @@ static inline void pgalloc_tag_sub_pages(struct alloc_tag *tag, unsigned int nr) #else /* CONFIG_MEM_ALLOC_PROFILING */ -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) {} +typedef void *pgtag_ref_handle; + +static inline pgtag_ref_handle +get_page_tag_ref(struct page *page, union codetag_ref *ref) { return NULL; } +static inline void put_page_tag_ref(pgtag_ref_handle handle) {} +static inline void update_page_tag_ref(pgtag_ref_handle handle, 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) {} diff --git a/lib/alloc_tag.c b/lib/alloc_tag.c index f33784f48dd2..a1d80d2ef512 100644 --- a/lib/alloc_tag.c +++ b/lib/alloc_tag.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -397,7 +398,7 @@ static __init void init_page_alloc_tagging(void) } struct page_ext_operations page_alloc_tagging_ops = { - .size = sizeof(union codetag_ref), + .size = sizeof(pgalloc_tag_ref), .need = need_page_alloc_tagging, .init = init_page_alloc_tagging, };