* [PATCH] iommu/iova: Optimize iova_magazine_alloc()
@ 2023-04-18 6:25 Zhen Lei
2023-04-20 10:38 ` Robin Murphy
0 siblings, 1 reply; 4+ messages in thread
From: Zhen Lei @ 2023-04-18 6:25 UTC (permalink / raw)
To: Robin Murphy, Joerg Roedel, Will Deacon, iommu, linux-kernel; +Cc: Zhen Lei
Only the member 'size' needs to be initialized to 0. Clearing the array
pfns[], which is about 1 KiB in size, not only wastes time, but also
causes cache pollution.
Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
---
drivers/iommu/iova.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c
index fe452ce466429a7..c970b9a2819d7bb 100644
--- a/drivers/iommu/iova.c
+++ b/drivers/iommu/iova.c
@@ -647,7 +647,13 @@ struct iova_rcache {
static struct iova_magazine *iova_magazine_alloc(gfp_t flags)
{
- return kzalloc(sizeof(struct iova_magazine), flags);
+ struct iova_magazine *mag;
+
+ mag = kmalloc(sizeof(struct iova_magazine), flags);
+ if (mag)
+ mag->size = 0;
+
+ return mag;
}
static void iova_magazine_free(struct iova_magazine *mag)
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] iommu/iova: Optimize iova_magazine_alloc()
2023-04-18 6:25 [PATCH] iommu/iova: Optimize iova_magazine_alloc() Zhen Lei
@ 2023-04-20 10:38 ` Robin Murphy
2023-04-20 11:52 ` Leizhen (ThunderTown)
0 siblings, 1 reply; 4+ messages in thread
From: Robin Murphy @ 2023-04-20 10:38 UTC (permalink / raw)
To: Zhen Lei, Joerg Roedel, Will Deacon, iommu, linux-kernel
On 2023-04-18 07:25, Zhen Lei wrote:
> Only the member 'size' needs to be initialized to 0. Clearing the array
> pfns[], which is about 1 KiB in size, not only wastes time, but also
> causes cache pollution.
Makes sense to me.
Acked-by: Robin Murphy <robin.murphy@arm.com>
> Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
> ---
> drivers/iommu/iova.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c
> index fe452ce466429a7..c970b9a2819d7bb 100644
> --- a/drivers/iommu/iova.c
> +++ b/drivers/iommu/iova.c
> @@ -647,7 +647,13 @@ struct iova_rcache {
>
> static struct iova_magazine *iova_magazine_alloc(gfp_t flags)
> {
> - return kzalloc(sizeof(struct iova_magazine), flags);
> + struct iova_magazine *mag;
> +
> + mag = kmalloc(sizeof(struct iova_magazine), flags);
Nit: maybe sizeof(*mag) is preferable?
> + if (mag)
> + mag->size = 0;
> +
> + return mag;
> }
>
> static void iova_magazine_free(struct iova_magazine *mag)
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] iommu/iova: Optimize iova_magazine_alloc()
2023-04-20 10:38 ` Robin Murphy
@ 2023-04-20 11:52 ` Leizhen (ThunderTown)
2023-05-22 15:10 ` Joerg Roedel
0 siblings, 1 reply; 4+ messages in thread
From: Leizhen (ThunderTown) @ 2023-04-20 11:52 UTC (permalink / raw)
To: Robin Murphy, Joerg Roedel, Will Deacon, iommu, linux-kernel
On 2023/4/20 18:38, Robin Murphy wrote:
> On 2023-04-18 07:25, Zhen Lei wrote:
>> Only the member 'size' needs to be initialized to 0. Clearing the array
>> pfns[], which is about 1 KiB in size, not only wastes time, but also
>> causes cache pollution.
>
> Makes sense to me.
>
> Acked-by: Robin Murphy <robin.murphy@arm.com>
>
>> Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
>> ---
>> drivers/iommu/iova.c | 8 +++++++-
>> 1 file changed, 7 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c
>> index fe452ce466429a7..c970b9a2819d7bb 100644
>> --- a/drivers/iommu/iova.c
>> +++ b/drivers/iommu/iova.c
>> @@ -647,7 +647,13 @@ struct iova_rcache {
>> static struct iova_magazine *iova_magazine_alloc(gfp_t flags)
>> {
>> - return kzalloc(sizeof(struct iova_magazine), flags);
>> + struct iova_magazine *mag;
>> +
>> + mag = kmalloc(sizeof(struct iova_magazine), flags);
>
> Nit: maybe sizeof(*mag) is preferable?
Yes, sizeof(*mag) is the more recommended usage, I will post v2 tomorrow.
>
>> + if (mag)
>> + mag->size = 0;
>> +
>> + return mag;
>> }
>> static void iova_magazine_free(struct iova_magazine *mag)
>
> .
>
--
Regards,
Zhen Lei
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] iommu/iova: Optimize iova_magazine_alloc()
2023-04-20 11:52 ` Leizhen (ThunderTown)
@ 2023-05-22 15:10 ` Joerg Roedel
0 siblings, 0 replies; 4+ messages in thread
From: Joerg Roedel @ 2023-05-22 15:10 UTC (permalink / raw)
To: Leizhen (ThunderTown); +Cc: Robin Murphy, Will Deacon, iommu, linux-kernel
On Thu, Apr 20, 2023 at 07:52:14PM +0800, Leizhen (ThunderTown) wrote:
> Yes, sizeof(*mag) is the more recommended usage, I will post v2 tomorrow.
Somehow v2 didn't make it to my inbox, but I found it on lore. This is
applied now, thanks.
Regards,
Joerg
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-05-22 15:11 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-18 6:25 [PATCH] iommu/iova: Optimize iova_magazine_alloc() Zhen Lei
2023-04-20 10:38 ` Robin Murphy
2023-04-20 11:52 ` Leizhen (ThunderTown)
2023-05-22 15:10 ` Joerg Roedel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox