From patchwork Wed Jul 3 17:42:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13722628 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 DB40CC2BD09 for ; Wed, 3 Jul 2024 17:42:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0D39D6B0083; Wed, 3 Jul 2024 13:42:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 083356B0088; Wed, 3 Jul 2024 13:42:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E65D76B0089; Wed, 3 Jul 2024 13:42:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id C793F6B0083 for ; Wed, 3 Jul 2024 13:42:32 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 654AE12063B for ; Wed, 3 Jul 2024 17:42:32 +0000 (UTC) X-FDA: 82299160944.11.7472F06 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf17.hostedemail.com (Postfix) with ESMTP id 9515B4000F for ; Wed, 3 Jul 2024 17:42:30 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=fL7BGmbY; spf=pass (imf17.hostedemail.com: domain of 3hY2FZgYKCPAkmjWfTYggYdW.Ugedafmp-eecnSUc.gjY@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3hY2FZgYKCPAkmjWfTYggYdW.Ugedafmp-eecnSUc.gjY@flex--surenb.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=1720028527; 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=cHmmenAJD4Xuv33/PGus2uArSA74vyhiLTN2TNueFk0=; b=BXIekGXPEj4NuVeJgvY8++CZCwTGJ3BNCzlg0QgbB/QtrgZFhTDEWW0po6VHyA5h0r2Z3/ kfrEDsbUNbyY6CeS/pQkrTEdVclBKDi+s+ZcZqmgEYoJWymYdhDfm5mUlqQK5kIjPZyL0e 4AmQKAqzly9tkfdzTxXGb2Dc518XeMY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720028527; a=rsa-sha256; cv=none; b=px/Ys8ugMWLCJ0PyGqVgs+/8JG97aLVhV+GHXHcZoe/bCCo1Hh7MQnJLvq2VoIhfWKj0N0 i9BZMWRKEos2o6V2ucDdWE+dBqEY5UHiL8z72k8Fdr7tBhg74+zCCX+4Y0WAG43FY8T+2j 4GZ34mgrs/7jCCl/bX826RsZj/dMzD0= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=fL7BGmbY; spf=pass (imf17.hostedemail.com: domain of 3hY2FZgYKCPAkmjWfTYggYdW.Ugedafmp-eecnSUc.gjY@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3hY2FZgYKCPAkmjWfTYggYdW.Ugedafmp-eecnSUc.gjY@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-650f5b28822so22543557b3.2 for ; Wed, 03 Jul 2024 10:42:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1720028549; x=1720633349; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=cHmmenAJD4Xuv33/PGus2uArSA74vyhiLTN2TNueFk0=; b=fL7BGmbYFvRD/aenDisWE/xOVGq/aMmoWUM8Bz3UPR2kaV3/NEXKrSdSbauYa+nBGE agr0jDXYBckt4R1kU1TpMuEvI7vq6JOKjiFikSdXmBgUhB9MJXVtJ4iPvz3ezAzxIc2o gjAZ/8JaacBtwywwwHCXoy1LwGCYOXl3bO9OpOHo3PM7LKnFvT4/tqpAfJn5wxWWNI75 THMIBBfwdv12rNnu7eq5P+F2fiIYynFIvJNIBhQ8ryUjHzuaQKFhz1ryC7G7B+Fx5c1e Mo1+/KmOA1acAVEvipfS98aZQUoGCtozmE1txtlE0Qq+fV1+svJuXWyo1C57PHp2haCP jbLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720028549; x=1720633349; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=cHmmenAJD4Xuv33/PGus2uArSA74vyhiLTN2TNueFk0=; b=b0o/AqJWyDlum0yC8Sojaej9qv6CDe9CS970wjaLPt6guT5m5hrCZ2XmR9M7vv1CnN 3qfpWheGg2AcHG4yRnT5BUviM+OmJd/YPKEvbIuGcc2fLwctT1utNmECZhZn2GJKZV2B PEc8c/UPilwNu3bqPWCfD89Gxzasn0lkzgZvlmBWLWoykGZxdwfusQwKOnZdf6zC4lnQ HURc6ZeZT2soOi5EY6thjGKa22+TrjgkG5TWLfdHEG7KqcfksQfp8rvd0z6yaFmQbFTP 8Hce/0z5RIRVLeFI2orjqs/UcOIeooCE5eqo7OBWnkhmVEIgmpDIkaNTO/wNi0ULuTZi qKwQ== X-Forwarded-Encrypted: i=1; AJvYcCVRR4HhhN/eaayeboz7oJTDE2UIGkNQ9cRl1jpZ+6Bddz/wFseQk/+R5HUuWaC3hi5J6eccCS+qhUqlAMp2Am980o8= X-Gm-Message-State: AOJu0YyFcwgaeGznb/nlYjy87sA9ITVaRsjlkjzhOw6rcsnjidB8ijza qCmxn2yRoxiSg5AJgVz2sOBwCewSq9yFzo+vpAp/PC0s7iMmXwS3OBKWErr01fQpRUIJHrfsgeS X8A== X-Google-Smtp-Source: AGHT+IFqhs8YAXy71fS/OG8wb/RazDJEP/UmJcIZGBEuKGVV5zkwlO2Qnshi5IQglkMDLXF+R6xYdSLhDko= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:7049:5206:eaa8:8edd]) (user=surenb job=sendgmr) by 2002:a25:dd46:0:b0:dfa:b328:475d with SMTP id 3f1490d57ef6-e036ec80d10mr192889276.12.1720028549451; Wed, 03 Jul 2024 10:42:29 -0700 (PDT) Date: Wed, 3 Jul 2024 10:42:25 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.45.2.803.g4e1b14247a-goog Message-ID: <20240703174225.3891393-1-surenb@google.com> Subject: [PATCH 1/1] mm: add comments for allocation helpers explaining why they are macros From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: kent.overstreet@linux.dev, jack@suse.cz, thorsten.blum@toblux.com, christian.koenig@amd.com, hch@lst.de, linux-mm@kvack.org, linux-kernel@vger.kernel.org, surenb@google.com X-Rspamd-Queue-Id: 9515B4000F X-Stat-Signature: si8sche6qrsjap667bcft84j1jcqesjy X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1720028550-848975 X-HE-Meta: U2FsdGVkX1/FNBu2RqyUAOeLv7t49tCt4efL2XfNQpl1zBFkOE4nBsIiLAu1Vcro+TwPxcsE2d303RsUviybGIA7iBOFqYJ/otYIqpUeUtV6bKua97tm77rK4rnmTbsW6b1/UABpKjffXQMFb6Oq9bWw0EpInN4vYnTXthy18keIfpypSw+lJfb+pKxFybxS4IBd3cMIPqBVlAQNX4SfA0Ygn26AmJqPQesfjIpKeNjeBPU953/QM8wB5vtqAjk9cfxK8cOKpAzQWVz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izS39HHl8pEO+wrDuFRAjiE3F4ZvoXlNFXyGsX8dpbdM2Vci4Y3yIp0hYq/FntD56s+Dt3Lr9ezLgTGySfirSnLWqmPg65SF9cuMoZt1PRngV7OWYJqUNjwYkuS0M9fB948xdcPYywo/CigMRByUB5kUBfFbSL4TW9oC9ELPHwmicNKtosSpC6PaA0aHl8x4nrhImVqF1qzByVvQVsGv8iE0lYyq93jXRKA= 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: A number of allocation helper functions were converted into macros to account them at the call sites. Add a comment for each converted allocation helper explaining why it has to be a macro and why we typecast the return value wherever required. The patch also moves acpi_os_acquire_object() closer to other allocation helpers to group them together under the same comment. The patch has no functional changes. Fixes: 2c321f3f70bc ("mm: change inlined allocation helpers to account at the call site") Suggested-by: Andrew Morton Signed-off-by: Suren Baghdasaryan --- fs/nfs/iostat.h | 4 ++++ include/acpi/platform/aclinuxex.h | 9 ++++++--- include/linux/bpf.h | 4 ++++ include/linux/dma-fence-chain.h | 4 ++++ include/linux/hid_bpf.h | 5 +++++ include/linux/jbd2.h | 10 ++++++++++ include/linux/skbuff.h | 8 ++++++++ include/linux/skmsg.h | 5 +++++ 8 files changed, 46 insertions(+), 3 deletions(-) base-commit: 8a9c6c40432e265600232b864f97d7c675e8be52 diff --git a/fs/nfs/iostat.h b/fs/nfs/iostat.h index b17a9eb9b148..49862c95b224 100644 --- a/fs/nfs/iostat.h +++ b/fs/nfs/iostat.h @@ -46,6 +46,10 @@ static inline void nfs_add_stats(const struct inode *inode, nfs_add_server_stats(NFS_SERVER(inode), stat, addend); } +/* + * This specialized allocator has to be a macro for its allocations to be + * accounted separately (to have a separate alloc_tag). + */ #define nfs_alloc_iostats() alloc_percpu(struct nfs_iostats) static inline void nfs_free_iostats(struct nfs_iostats __percpu *stats) diff --git a/include/acpi/platform/aclinuxex.h b/include/acpi/platform/aclinuxex.h index 62cac266a1c8..eeff40295b4b 100644 --- a/include/acpi/platform/aclinuxex.h +++ b/include/acpi/platform/aclinuxex.h @@ -46,6 +46,9 @@ acpi_status acpi_os_terminate(void); * Interrupts are off during resume, just like they are for boot. * However, boot has (system_state != SYSTEM_RUNNING) * to quiet __might_sleep() in kmalloc() and resume does not. + * + * These specialized allocators have to be macros for their allocations to be + * accounted separately (to have separate alloc_tag). */ #define acpi_os_allocate(_size) \ kmalloc(_size, irqs_disabled() ? GFP_ATOMIC : GFP_KERNEL) @@ -53,14 +56,14 @@ acpi_status acpi_os_terminate(void); #define acpi_os_allocate_zeroed(_size) \ kzalloc(_size, irqs_disabled() ? GFP_ATOMIC : GFP_KERNEL) +#define acpi_os_acquire_object(_cache) \ + kmem_cache_zalloc(_cache, irqs_disabled() ? GFP_ATOMIC : GFP_KERNEL) + static inline void acpi_os_free(void *memory) { kfree(memory); } -#define acpi_os_acquire_object(_cache) \ - kmem_cache_zalloc(_cache, irqs_disabled() ? GFP_ATOMIC : GFP_KERNEL) - static inline acpi_thread_id acpi_os_get_thread_id(void) { return (acpi_thread_id) (unsigned long)current; diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 5e694a308081..4cef340737c4 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -2261,6 +2261,10 @@ void *bpf_map_kvcalloc(struct bpf_map *map, size_t n, size_t size, void __percpu *bpf_map_alloc_percpu(const struct bpf_map *map, size_t size, size_t align, gfp_t flags); #else +/* + * These specialized allocators have to be macros for their allocations to be + * accounted separately (to have separate alloc_tag). + */ #define bpf_map_kmalloc_node(_map, _size, _flags, _node) \ kmalloc_node(_size, _flags, _node) #define bpf_map_kzalloc(_map, _size, _flags) \ diff --git a/include/linux/dma-fence-chain.h b/include/linux/dma-fence-chain.h index ad9e2506c2f4..68c3c1e41014 100644 --- a/include/linux/dma-fence-chain.h +++ b/include/linux/dma-fence-chain.h @@ -85,6 +85,10 @@ dma_fence_chain_contained(struct dma_fence *fence) * dma_fence_chain_alloc * * Returns a new struct dma_fence_chain object or NULL on failure. + * + * This specialized allocator has to be a macro for its allocations to be + * accounted separately (to have a separate alloc_tag). The typecast is + * intentional to enforce typesafety. */ #define dma_fence_chain_alloc() \ ((struct dma_fence_chain *)kmalloc(sizeof(struct dma_fence_chain), GFP_KERNEL)) diff --git a/include/linux/hid_bpf.h b/include/linux/hid_bpf.h index eec2592dec12..99a3edb6cf07 100644 --- a/include/linux/hid_bpf.h +++ b/include/linux/hid_bpf.h @@ -152,6 +152,11 @@ static inline int hid_bpf_connect_device(struct hid_device *hdev) { return 0; } static inline void hid_bpf_disconnect_device(struct hid_device *hdev) {} static inline void hid_bpf_destroy_device(struct hid_device *hid) {} static inline void hid_bpf_device_init(struct hid_device *hid) {} +/* + * This specialized allocator has to be a macro for its allocations to be + * accounted separately (to have a separate alloc_tag). The typecast is + * intentional to enforce typesafety. + */ #define call_hid_bpf_rdesc_fixup(_hdev, _rdesc, _size) \ ((u8 *)kmemdup(_rdesc, *(_size), GFP_KERNEL)) diff --git a/include/linux/jbd2.h b/include/linux/jbd2.h index ab04c1c27fae..a280f42c8c76 100644 --- a/include/linux/jbd2.h +++ b/include/linux/jbd2.h @@ -1588,6 +1588,11 @@ void jbd2_journal_put_journal_head(struct journal_head *jh); */ extern struct kmem_cache *jbd2_handle_cache; +/* + * This specialized allocator has to be a macro for its allocations to be + * accounted separately (to have a separate alloc_tag). The typecast is + * intentional to enforce typesafety. + */ #define jbd2_alloc_handle(_gfp_flags) \ ((handle_t *)kmem_cache_zalloc(jbd2_handle_cache, _gfp_flags)) @@ -1602,6 +1607,11 @@ static inline void jbd2_free_handle(handle_t *handle) */ extern struct kmem_cache *jbd2_inode_cache; +/* + * This specialized allocator has to be a macro for its allocations to be + * accounted separately (to have a separate alloc_tag). The typecast is + * intentional to enforce typesafety. + */ #define jbd2_alloc_inode(_gfp_flags) \ ((struct jbd2_inode *)kmem_cache_alloc(jbd2_inode_cache, _gfp_flags)) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 1c2902eaebd3..fd51f2de51da 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -3400,6 +3400,10 @@ static inline struct page *__dev_alloc_pages_noprof(gfp_t gfp_mask, } #define __dev_alloc_pages(...) alloc_hooks(__dev_alloc_pages_noprof(__VA_ARGS__)) +/* + * This specialized allocator has to be a macro for its allocations to be + * accounted separately (to have a separate alloc_tag). + */ #define dev_alloc_pages(_order) __dev_alloc_pages(GFP_ATOMIC | __GFP_NOWARN, _order) /** @@ -3416,6 +3420,10 @@ static inline struct page *__dev_alloc_page_noprof(gfp_t gfp_mask) } #define __dev_alloc_page(...) alloc_hooks(__dev_alloc_page_noprof(__VA_ARGS__)) +/* + * This specialized allocator has to be a macro for its allocations to be + * accounted separately (to have a separate alloc_tag). + */ #define dev_alloc_page() dev_alloc_pages(0) /** diff --git a/include/linux/skmsg.h b/include/linux/skmsg.h index c9efda9df285..d9b03e0746e7 100644 --- a/include/linux/skmsg.h +++ b/include/linux/skmsg.h @@ -414,6 +414,11 @@ void sk_psock_stop_verdict(struct sock *sk, struct sk_psock *psock); int sk_psock_msg_verdict(struct sock *sk, struct sk_psock *psock, struct sk_msg *msg); +/* + * This specialized allocator has to be a macro for its allocations to be + * accounted separately (to have a separate alloc_tag). The typecast is + * intentional to enforce typesafety. + */ #define sk_psock_init_link() \ ((struct sk_psock_link *)kzalloc(sizeof(struct sk_psock_link), \ GFP_ATOMIC | __GFP_NOWARN))