netlink: use kvmalloc() in netlink_alloc_large_skb()
This is a followup of commit 234ec0b6034b ("netlink: fix potential sleeping issue in mqueue_flush_file"), because vfree_atomic() overhead is unfortunate for medium sized allocations. 1) If the allocation is smaller than PAGE_SIZE, do not bother with vmalloc() at all. Some arches have 64KB PAGE_SIZE, while NLMSG_GOODSIZE is smaller than 8KB. 2) Use kvmalloc(), which might allocate one high order page instead of vmalloc if memory is not too fragmented. Signed-off-by: Eric Dumazet <edumazet@google.com> Reviewed-by: Zhengchao Shao <shaozhengchao@huawei.com> Link: https://lore.kernel.org/r/20240224090630.605917-1-edumazet@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
parent
c4b04a802d
commit
f8cbf6bde4
@ -1202,23 +1202,21 @@ struct sock *netlink_getsockbyfilp(struct file *filp)
|
|||||||
|
|
||||||
struct sk_buff *netlink_alloc_large_skb(unsigned int size, int broadcast)
|
struct sk_buff *netlink_alloc_large_skb(unsigned int size, int broadcast)
|
||||||
{
|
{
|
||||||
|
size_t head_size = SKB_HEAD_ALIGN(size);
|
||||||
struct sk_buff *skb;
|
struct sk_buff *skb;
|
||||||
void *data;
|
void *data;
|
||||||
|
|
||||||
if (size <= NLMSG_GOODSIZE || broadcast)
|
if (head_size <= PAGE_SIZE || broadcast)
|
||||||
return alloc_skb(size, GFP_KERNEL);
|
return alloc_skb(size, GFP_KERNEL);
|
||||||
|
|
||||||
size = SKB_DATA_ALIGN(size) +
|
data = kvmalloc(head_size, GFP_KERNEL);
|
||||||
SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
|
if (!data)
|
||||||
|
|
||||||
data = vmalloc(size);
|
|
||||||
if (data == NULL)
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
skb = __build_skb(data, size);
|
skb = __build_skb(data, head_size);
|
||||||
if (skb == NULL)
|
if (!skb)
|
||||||
vfree(data);
|
kvfree(data);
|
||||||
else
|
else if (is_vmalloc_addr(data))
|
||||||
skb->destructor = netlink_skb_destructor;
|
skb->destructor = netlink_skb_destructor;
|
||||||
|
|
||||||
return skb;
|
return skb;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user