Skip to content

Commit 3b0ba54

Browse files
surenbaghdasaryanakpm00
authored andcommitted
mm: add comments for allocation helpers explaining why they are macros
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. Link: https://lkml.kernel.org/r/[email protected] Fixes: 2c321f3 ("mm: change inlined allocation helpers to account at the call site") Signed-off-by: Suren Baghdasaryan <[email protected]> Suggested-by: Andrew Morton <[email protected]> Cc: Christian König <[email protected]> Cc: Christoph Hellwig <[email protected]> Cc: Jan Kara <[email protected]> Cc: Kent Overstreet <[email protected]> Cc: Thorsten Blum <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent cd1e0da commit 3b0ba54

File tree

8 files changed

+46
-3
lines changed

8 files changed

+46
-3
lines changed

fs/nfs/iostat.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ static inline void nfs_add_stats(const struct inode *inode,
4646
nfs_add_server_stats(NFS_SERVER(inode), stat, addend);
4747
}
4848

49+
/*
50+
* This specialized allocator has to be a macro for its allocations to be
51+
* accounted separately (to have a separate alloc_tag).
52+
*/
4953
#define nfs_alloc_iostats() alloc_percpu(struct nfs_iostats)
5054

5155
static inline void nfs_free_iostats(struct nfs_iostats __percpu *stats)

include/acpi/platform/aclinuxex.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,24 @@ acpi_status acpi_os_terminate(void);
4646
* Interrupts are off during resume, just like they are for boot.
4747
* However, boot has (system_state != SYSTEM_RUNNING)
4848
* to quiet __might_sleep() in kmalloc() and resume does not.
49+
*
50+
* These specialized allocators have to be macros for their allocations to be
51+
* accounted separately (to have separate alloc_tag).
4952
*/
5053
#define acpi_os_allocate(_size) \
5154
kmalloc(_size, irqs_disabled() ? GFP_ATOMIC : GFP_KERNEL)
5255

5356
#define acpi_os_allocate_zeroed(_size) \
5457
kzalloc(_size, irqs_disabled() ? GFP_ATOMIC : GFP_KERNEL)
5558

59+
#define acpi_os_acquire_object(_cache) \
60+
kmem_cache_zalloc(_cache, irqs_disabled() ? GFP_ATOMIC : GFP_KERNEL)
61+
5662
static inline void acpi_os_free(void *memory)
5763
{
5864
kfree(memory);
5965
}
6066

61-
#define acpi_os_acquire_object(_cache) \
62-
kmem_cache_zalloc(_cache, irqs_disabled() ? GFP_ATOMIC : GFP_KERNEL)
63-
6467
static inline acpi_thread_id acpi_os_get_thread_id(void)
6568
{
6669
return (acpi_thread_id) (unsigned long)current;

include/linux/bpf.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2261,6 +2261,10 @@ void *bpf_map_kvcalloc(struct bpf_map *map, size_t n, size_t size,
22612261
void __percpu *bpf_map_alloc_percpu(const struct bpf_map *map, size_t size,
22622262
size_t align, gfp_t flags);
22632263
#else
2264+
/*
2265+
* These specialized allocators have to be macros for their allocations to be
2266+
* accounted separately (to have separate alloc_tag).
2267+
*/
22642268
#define bpf_map_kmalloc_node(_map, _size, _flags, _node) \
22652269
kmalloc_node(_size, _flags, _node)
22662270
#define bpf_map_kzalloc(_map, _size, _flags) \

include/linux/dma-fence-chain.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ dma_fence_chain_contained(struct dma_fence *fence)
8585
* dma_fence_chain_alloc
8686
*
8787
* Returns a new struct dma_fence_chain object or NULL on failure.
88+
*
89+
* This specialized allocator has to be a macro for its allocations to be
90+
* accounted separately (to have a separate alloc_tag). The typecast is
91+
* intentional to enforce typesafety.
8892
*/
8993
#define dma_fence_chain_alloc() \
9094
((struct dma_fence_chain *)kmalloc(sizeof(struct dma_fence_chain), GFP_KERNEL))

include/linux/hid_bpf.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ static inline int hid_bpf_connect_device(struct hid_device *hdev) { return 0; }
152152
static inline void hid_bpf_disconnect_device(struct hid_device *hdev) {}
153153
static inline void hid_bpf_destroy_device(struct hid_device *hid) {}
154154
static inline void hid_bpf_device_init(struct hid_device *hid) {}
155+
/*
156+
* This specialized allocator has to be a macro for its allocations to be
157+
* accounted separately (to have a separate alloc_tag). The typecast is
158+
* intentional to enforce typesafety.
159+
*/
155160
#define call_hid_bpf_rdesc_fixup(_hdev, _rdesc, _size) \
156161
((u8 *)kmemdup(_rdesc, *(_size), GFP_KERNEL))
157162

include/linux/jbd2.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,6 +1588,11 @@ void jbd2_journal_put_journal_head(struct journal_head *jh);
15881588
*/
15891589
extern struct kmem_cache *jbd2_handle_cache;
15901590

1591+
/*
1592+
* This specialized allocator has to be a macro for its allocations to be
1593+
* accounted separately (to have a separate alloc_tag). The typecast is
1594+
* intentional to enforce typesafety.
1595+
*/
15911596
#define jbd2_alloc_handle(_gfp_flags) \
15921597
((handle_t *)kmem_cache_zalloc(jbd2_handle_cache, _gfp_flags))
15931598

@@ -1602,6 +1607,11 @@ static inline void jbd2_free_handle(handle_t *handle)
16021607
*/
16031608
extern struct kmem_cache *jbd2_inode_cache;
16041609

1610+
/*
1611+
* This specialized allocator has to be a macro for its allocations to be
1612+
* accounted separately (to have a separate alloc_tag). The typecast is
1613+
* intentional to enforce typesafety.
1614+
*/
16051615
#define jbd2_alloc_inode(_gfp_flags) \
16061616
((struct jbd2_inode *)kmem_cache_alloc(jbd2_inode_cache, _gfp_flags))
16071617

include/linux/skbuff.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3400,6 +3400,10 @@ static inline struct page *__dev_alloc_pages_noprof(gfp_t gfp_mask,
34003400
}
34013401
#define __dev_alloc_pages(...) alloc_hooks(__dev_alloc_pages_noprof(__VA_ARGS__))
34023402

3403+
/*
3404+
* This specialized allocator has to be a macro for its allocations to be
3405+
* accounted separately (to have a separate alloc_tag).
3406+
*/
34033407
#define dev_alloc_pages(_order) __dev_alloc_pages(GFP_ATOMIC | __GFP_NOWARN, _order)
34043408

34053409
/**
@@ -3416,6 +3420,10 @@ static inline struct page *__dev_alloc_page_noprof(gfp_t gfp_mask)
34163420
}
34173421
#define __dev_alloc_page(...) alloc_hooks(__dev_alloc_page_noprof(__VA_ARGS__))
34183422

3423+
/*
3424+
* This specialized allocator has to be a macro for its allocations to be
3425+
* accounted separately (to have a separate alloc_tag).
3426+
*/
34193427
#define dev_alloc_page() dev_alloc_pages(0)
34203428

34213429
/**

include/linux/skmsg.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,11 @@ void sk_psock_stop_verdict(struct sock *sk, struct sk_psock *psock);
414414
int sk_psock_msg_verdict(struct sock *sk, struct sk_psock *psock,
415415
struct sk_msg *msg);
416416

417+
/*
418+
* This specialized allocator has to be a macro for its allocations to be
419+
* accounted separately (to have a separate alloc_tag). The typecast is
420+
* intentional to enforce typesafety.
421+
*/
417422
#define sk_psock_init_link() \
418423
((struct sk_psock_link *)kzalloc(sizeof(struct sk_psock_link), \
419424
GFP_ATOMIC | __GFP_NOWARN))

0 commit comments

Comments
 (0)