iommu/iova: use named kmem_cache for iova magazines
Subsystems (3)
Robin Murphy
maintainerv3 cover iommu/iova: use named kmem_cache for iova magazines
Hi all,
I decided that Pasha's patch[1] was a good excuse to tackle a bit more cleanup of the existing IOVA code, so it can fit in more neatly. Thus to save time and effort I've taken the liberty of putting together this mini-series as the version I'd like to merge.
Cheers,
Robin.
[1] https://lore.kernel.org/linux-iommu/[email protected]/
Pasha Tatashin (1):
iommu/iova: use named kmem_cache for iova magazines
Robin Murphy (2):
iommu/iova: Tidy up iova_cache_get() failure
iommu/iova: Reorganise some code
drivers/iommu/iova.c | 143 +++++++++++++++++++++++-------------------- 1 file changed, 76 insertions(+), 67 deletions(-)
Signature · 1 line
2.39.2.101.g768bb238c484.dirty
Robin Murphy
maintainerPATCH v3 1/3 iommu/iova: Tidy up iova_cache_get() failure
Failure handling in iova_cache_get() is a little messy, and we'd like to add some more to it, so let's tidy up a bit first. By leaving the hotplug handler until last we can take advantage of kmem_cache_destroy() being NULL-safe to have a single cleanup label. We can also improve the error reporting, noting that kmem_cache_create() already screams if it fails, so that one is redundant.
--- drivers/iommu/iova.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-)
drivers/iommu/iova.c +16 -17
@@ -254,26 +254,20 @@ static void free_iova_mem(struct iova *iova)int iova_cache_get (void ) { +int err = -ENOMEM ; +mutex_lock (&iova_cache_mutex);if (!iova_cache_users) { -int ret; + iova_cache =kmem_cache_create ("iommu_iova" ,sizeof (struct iova ),0 , +SLAB_HWCACHE_ALIGN ,NULL ); +if (!iova_cache) + goto out_err; - ret =cpuhp_setup_state_multi (CPUHP_IOMMU_IOVA_DEAD ,"iommu/iova:dead" ,NULL , - iova_cpuhp_dead); -if (ret) { -mutex_unlock (&iova_cache_mutex); -pr_err ("Couldn't register cpuhp handler\n" ); -return ret; - } - - iova_cache =kmem_cache_create ( -"iommu_iova" ,sizeof (struct iova ),0 , -SLAB_HWCACHE_ALIGN ,NULL ); -if (!iova_cache) { -cpuhp_remove_multi_state (CPUHP_IOMMU_IOVA_DEAD ); -mutex_unlock (&iova_cache_mutex); -pr_err ("Couldn't create iova cache\n" ); -return -ENOMEM ; + err =cpuhp_setup_state_multi (CPUHP_IOMMU_IOVA_DEAD ,"iommu/iova:dead" , +NULL , iova_cpuhp_dead); +if (err) { +pr_err ("IOVA: Couldn't register cpuhp handler: %pe\n" ,ERR_PTR (err)); + goto out_err; } }
@@ -281,6 +275,11 @@ int iova_cache_get(void)mutex_unlock (&iova_cache_mutex);return 0 ; + +out_err: +kmem_cache_destroy (iova_cache); +mutex_unlock (&iova_cache_mutex); +return err; }EXPORT_SYMBOL_GPL (iova_cache_get);
Signature · 1 line
2.39.2.101.g768bb238c484.dirty
Robin Murphy
maintainerPATCH v3 2/3 iommu/iova: Reorganise some code
In reply to Robin MurphyThe iova_cache_{get,put}() calls really represent top-level lifecycle management for the whole IOVA library, so it's long been rather confusing to have them buried right in the middle of the allocator implementation details. Move them to a more expected position at the end of the file, where it will then also be easier to expand them. With this, we can also move the rcache hotplug handler (plus another stray function) into the rcache portion of the file.
--- drivers/iommu/iova.c | 128 +++++++++++++++++++++---------------------- 1 file changed, 64 insertions(+), 64 deletions(-)
drivers/iommu/iova.c +64 -64
@@ -24,24 +24,8 @@ static bool iova_rcache_insert(struct iova_domain *iovad,static unsigned long iova_rcache_get (struct iova_domain *iovad,unsigned long size,unsigned long limit_pfn); -static void free_cpu_cached_iovas (unsigned int cpu,struct iova_domain *iovad);static void free_iova_rcaches (struct iova_domain *iovad); - -unsigned long iova_rcache_range (void ) -{ -return PAGE_SIZE << (IOVA_RANGE_CACHE_MAX_SIZE -1 ); -} - -static int iova_cpuhp_dead (unsigned int cpu,struct hlist_node *node) -{ -struct iova_domain *iovad; - - iovad = hlist_entry_safe(node, struct iova_domain, cpuhp_dead); - -free_cpu_cached_iovas (cpu, iovad); -return 0 ; -} - +static void free_cpu_cached_iovas (unsigned int cpu,struct iova_domain *iovad);static void free_global_cached_iovas (struct iova_domain *iovad);static struct iova *to_iova (struct rb_node *node)
@@ -252,53 +236,6 @@ static void free_iova_mem(struct iova *iova)kmem_cache_free (iova_cache, iova); } -int iova_cache_get (void ) -{ -int err = -ENOMEM ; - -mutex_lock (&iova_cache_mutex); -if (!iova_cache_users) { - iova_cache =kmem_cache_create ("iommu_iova" ,sizeof (struct iova ),0 , -SLAB_HWCACHE_ALIGN ,NULL ); -if (!iova_cache) - goto out_err; - - err =cpuhp_setup_state_multi (CPUHP_IOMMU_IOVA_DEAD ,"iommu/iova:dead" , -NULL , iova_cpuhp_dead); -if (err) { -pr_err ("IOVA: Couldn't register cpuhp handler: %pe\n" ,ERR_PTR (err)); - goto out_err; - } - } - - iova_cache_users++; -mutex_unlock (&iova_cache_mutex); - -return 0 ; - -out_err: -kmem_cache_destroy (iova_cache); -mutex_unlock (&iova_cache_mutex); -return err; -} -EXPORT_SYMBOL_GPL (iova_cache_get); - -void iova_cache_put (void ) -{ -mutex_lock (&iova_cache_mutex); -if (WARN_ON (!iova_cache_users)) { -mutex_unlock (&iova_cache_mutex); -return ; - } - iova_cache_users--; -if (!iova_cache_users) { -cpuhp_remove_multi_state (CPUHP_IOMMU_IOVA_DEAD ); -kmem_cache_destroy (iova_cache); - } -mutex_unlock (&iova_cache_mutex); -} -EXPORT_SYMBOL_GPL (iova_cache_put); -/** * alloc_iova - allocates an iova * @iovad: - iova domain in question
@@ -653,6 +590,11 @@ struct iova_rcache {struct delayed_work work; }; +unsigned long iova_rcache_range (void ) +{ +return PAGE_SIZE << (IOVA_RANGE_CACHE_MAX_SIZE -1 ); +} +static struct iova_magazine *iova_magazine_alloc (gfp_t flags) {struct iova_magazine *mag;
@@ -989,5 +931,63 @@ static void free_global_cached_iovas(struct iova_domain *iovad)spin_unlock_irqrestore (&rcache->lock, flags); } } + +static int iova_cpuhp_dead (unsigned int cpu,struct hlist_node *node) +{ +struct iova_domain *iovad; + + iovad = hlist_entry_safe(node, struct iova_domain, cpuhp_dead); + +free_cpu_cached_iovas (cpu, iovad); +return 0 ; +} + +int iova_cache_get (void ) +{ +int err = -ENOMEM ; + +mutex_lock (&iova_cache_mutex); +if (!iova_cache_users) { + iova_cache =kmem_cache_create ("iommu_iova" ,sizeof (struct iova ),0 , +SLAB_HWCACHE_ALIGN ,NULL ); +if (!iova_cache) + goto out_err; + + err =cpuhp_setup_state_multi (CPUHP_IOMMU_IOVA_DEAD ,"iommu/iova:dead" , +NULL , iova_cpuhp_dead); +if (err) { +pr_err ("IOVA: Couldn't register cpuhp handler: %pe\n" ,ERR_PTR (err)); + goto out_err; + } + } + + iova_cache_users++; +mutex_unlock (&iova_cache_mutex); + +return 0 ; + +out_err: +kmem_cache_destroy (iova_cache); +mutex_unlock (&iova_cache_mutex); +return err; +} +EXPORT_SYMBOL_GPL (iova_cache_get); + +void iova_cache_put (void ) +{ +mutex_lock (&iova_cache_mutex); +if (WARN_ON (!iova_cache_users)) { +mutex_unlock (&iova_cache_mutex); +return ; + } + iova_cache_users--; +if (!iova_cache_users) { +cpuhp_remove_multi_state (CPUHP_IOMMU_IOVA_DEAD ); +kmem_cache_destroy (iova_cache); + } +mutex_unlock (&iova_cache_mutex); +} +EXPORT_SYMBOL_GPL (iova_cache_put); +MODULE_AUTHOR ("Anil S Keshavamurthy <[email protected]>" );MODULE_LICENSE ("GPL" );
Signature · 1 line
2.39.2.101.g768bb238c484.dirty
Robin Murphy
maintainerPATCH v3 3/3 iommu/iova: use named kmem_cache for iova magazines
In reply to Robin MurphyFrom: Pasha Tatashin <[email protected]>
The magazine buffers can take gigabytes of kmem memory, dominating all other allocations. For observability purpose create named slab cache so the iova magazine memory overhead can be clearly observed.
With this change:
Quoted 1 line
slabtop -o | head
Active / Total Objects (% used) : 869731 / 952904 (91.3%) Active / Total Slabs (% used) : 103411 / 103974 (99.5%) Active / Total Caches (% used) : 135 / 211 (64.0%) Active / Total Size (% used) : 395389.68K / 411430.20K (96.1%)
Minimum / Average / Maximum Object : 0.02K / 0.43K / 8.00K
OBJS ACTIVE USE OBJ SIZE SLABS OBJ/SLAB CACHE SIZE NAME
244412 244239 99% 1.00K 61103 4 244412K iommu_iova_magazine 91636 88343 96% 0.03K 739 124 2956K kmalloc-32 75744 74844 98% 0.12K 2367 32 9468K kernfs_node_cache
On this machine it is now clear that magazine use 242M of kmem memory.
--- drivers/iommu/iova.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
drivers/iommu/iova.c +12 -2
@@ -590,6 +590,8 @@ struct iova_rcache {struct delayed_work work; }; +static struct kmem_cache *iova_magazine_cache; +unsigned long iova_rcache_range (void ) {return PAGE_SIZE << (IOVA_RANGE_CACHE_MAX_SIZE -1 );
@@ -599,7 +601,7 @@ static struct iova_magazine *iova_magazine_alloc(gfp_t flags) {struct iova_magazine *mag; - mag =kmalloc (sizeof (*mag), flags); + mag =kmem_cache_alloc (iova_magazine_cache, flags);if (mag) mag->size =0 ;
@@ -608,7 +610,7 @@ static struct iova_magazine *iova_magazine_alloc(gfp_t flags)static void iova_magazine_free (struct iova_magazine *mag) { -kfree (mag); +kmem_cache_free (iova_magazine_cache, mag); } static void
@@ -953,6 +955,12 @@ int iova_cache_get(void)if (!iova_cache) goto out_err; + iova_magazine_cache =kmem_cache_create ("iommu_iova_magazine" , +sizeof (struct iova_magazine ), +0 ,SLAB_HWCACHE_ALIGN ,NULL ); +if (!iova_magazine_cache) + goto out_err; + err =cpuhp_setup_state_multi (CPUHP_IOMMU_IOVA_DEAD ,"iommu/iova:dead" ,NULL , iova_cpuhp_dead);if (err) {
@@ -968,6 +976,7 @@ int iova_cache_get(void) out_err:kmem_cache_destroy (iova_cache); +kmem_cache_destroy (iova_magazine_cache);mutex_unlock (&iova_cache_mutex);return err; }
@@ -984,6 +993,7 @@ void iova_cache_put(void)if (!iova_cache_users) {cpuhp_remove_multi_state (CPUHP_IOMMU_IOVA_DEAD );kmem_cache_destroy (iova_cache); +kmem_cache_destroy (iova_magazine_cache); }mutex_unlock (&iova_cache_mutex); }
Signature · 1 line
2.39.2.101.g768bb238c484.dirty
Re: [PATCH v3 1/3] iommu/iova: Tidy up iova_cache_get() failure
In reply to Robin MurphyQuoted 8 lines · Robin Murphy
Failure handling in
iova_cache_get()is a little messy, and we'd like to add some more to it, so let's tidy up a bit first. By leaving the hotplug handler until last we can take advantage ofkmem_cache_destroy()being NULL-safe to have a single cleanup label. We can also improve the error reporting, noting thatkmem_cache_create()already screams if it fails, so that one is redundant.Signed-off-by Robin Murphy <[email protected]>
Much easier to follow :)
Re: [PATCH v3 2/3] iommu/iova: Reorganise some code
In reply to Robin MurphyQuoted 9 lines · Robin Murphy
The iova_cache_{get,put}() calls really represent top-level lifecycle management for the whole IOVA library, so it's long been rather confusing to have them buried right in the middle of the allocator implementation details. Move them to a more expected position at the end of the file, where it will then also be easier to expand them. With this, we can also move the rcache hotplug handler (plus another stray function) into the rcache portion of the file.
Signed-off-by Robin Murphy <[email protected]>
Re: [PATCH v3 1/3] iommu/iova: Tidy up iova_cache_get() failure
In reply to Robin MurphyQuoted 9 lines · Robin Murphy
Failure handling in
iova_cache_get()is a little messy, and we'd like to add some more to it, so let's tidy up a bit first. By leaving the hotplug handler until last we can take advantage ofkmem_cache_destroy()being NULL-safe to have a single cleanup label. We can also improve the error reporting, noting thatkmem_cache_create()already screams if it fails, so that one is redundant.Signed-off-by Robin Murphy <[email protected]>
Thank you,
Pasha
Re: [PATCH v3 2/3] iommu/iova: Reorganise some code
In reply to Robin MurphyQuoted 10 lines · Robin Murphy
The iova_cache_{get,put}() calls really represent top-level lifecycle management for the whole IOVA library, so it's long been rather confusing to have them buried right in the middle of the allocator implementation details. Move them to a more expected position at the end of the file, where it will then also be easier to expand them. With this, we can also move the rcache hotplug handler (plus another stray function) into the rcache portion of the file.
Signed-off-by Robin Murphy <[email protected]>
Re: [PATCH v3 1/3] iommu/iova: Tidy up iova_cache_get() failure
In reply to Robin MurphyQuoted 8 lines · Robin Murphy
Failure handling in
iova_cache_get()is a little messy, and we'd like to add some more to it, so let's tidy up a bit first. By leaving the hotplug handler until last we can take advantage ofkmem_cache_destroy()being NULL-safe to have a single cleanup label. We can also improve the error reporting, noting thatkmem_cache_create()already screams if it fails, so that one is redundant.Signed-off-by Robin Murphy <[email protected]>
Regardless of a couple of minor comments, below, FWIW:
Quoted 9 lines
--- drivers/iommu/iova.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-)drivers/iommu/iova.c +0
-0
drivers/iommu/iova.c static void free_iova_mem(struct iova *iova) · line 262
Quoted 10 lines
drivers/iommu/iova.c +4
-1@@ -254,26 +254,20 @@ static void free_iova_mem(struct iova *iova)int iova_cache_get (void ) { +int err = -ENOMEM ; +mutex_lock (&iova_cache_mutex);if (!iova_cache_users) { -int ret; + iova_cache =kmem_cache_create ("iommu_iova" ,sizeof (struct iova ),0 , +SLAB_HWCACHE_ALIGN ,NULL );
Maybe can use KMEM_CACHE(), but it would mean that the name would change.
Quoted 13 lines
drivers/iommu/iova.c +2
-10+if (!iova_cache) + goto out_err; - ret =cpuhp_setup_state_multi (CPUHP_IOMMU_IOVA_DEAD ,"iommu/iova:dead" ,NULL , - iova_cpuhp_dead); -if (ret) { -mutex_unlock (&iova_cache_mutex); -pr_err ("Couldn't register cpuhp handler\n" ); -return ret; - } - - iova_cache = kmem_cache_create( - "iommu_iova", sizeof(struct iova), 0,
drivers/iommu/iova.c static void free_iova_mem(struct iova *iova) · line 269
Quoted 10 lines
drivers/iommu/iova.c +4
-6- SLAB_HWCACHE_ALIGN, NULL); -if (!iova_cache) { -cpuhp_remove_multi_state (CPUHP_IOMMU_IOVA_DEAD ); -mutex_unlock (&iova_cache_mutex); -pr_err ("Couldn't create iova cache\n" ); -return -ENOMEM ; + err =cpuhp_setup_state_multi (CPUHP_IOMMU_IOVA_DEAD ,"iommu/iova:dead" , +NULL , iova_cpuhp_dead); +if (err) { +pr_err ("IOVA: Couldn't register cpuhp handler: %pe\n" ,ERR_PTR (err));
Maybe can use pr_fmt with "iova".
Quoted 16 lines
drivers/iommu/iova.c +6
-0+ goto out_err; } }@@ -281,6 +275,11 @@ int iova_cache_get(void)mutex_unlock (&iova_cache_mutex);return 0 ; + +out_err: +kmem_cache_destroy (iova_cache); +mutex_unlock (&iova_cache_mutex); +return err; }EXPORT_SYMBOL_GPL (iova_cache_get);
Re: [PATCH v3 2/3] iommu/iova: Reorganise some code
In reply to Robin MurphyQuoted 10 lines · Robin Murphy
The iova_cache_{get,put}() calls really represent top-level lifecycle management for the whole IOVA library, so it's long been rather confusing to have them buried right in the middle of the allocator implementation details. Move them to a more expected position at the end of the file, where it will then also be easier to expand them. With this, we can also move the rcache hotplug handler (plus another stray function) into the rcache portion of the file.
Signed-off-by Robin Murphy<[email protected]>---
FWIW:
Quoted 13 lines · Robin Murphy
From: Pasha Tatashin <[email protected]>
The magazine buffers can take gigabytes of kmem memory, dominating all other allocations. For observability purpose create named slab cache so the iova magazine memory overhead can be clearly observed.
With this change:
Quoted 1 line
slabtop -o | head
Active / Total Objects (% used) : 869731 / 952904 (91.3%) Active / Total Slabs (% used) : 103411 / 103974 (99.5%) Active / Total Caches (% used) : 135 / 211 (64.0%) Active / Total Size (% used) : 395389.68K / 411430.20K (96.1%)
Quoted 8 lines
Minimum / Average / Maximum Object : 0.02K / 0.43K / 8.00K
OBJS ACTIVE USE OBJ SIZE SLABS OBJ/SLAB CACHE SIZE NAME
244412 244239 99% 1.00K 61103 4 244412Kiommu_iova_magazine91636 88343 96% 0.03K 739 124 2956K kmalloc-32 75744 74844 98% 0.12K 2367 32 9468K kernfs_node_cacheOn this machine it is now clear that magazine use 242M of kmem memory.
Those caches could do with a trimming ...
Quoted 6 lines
Acked-by David Rientjes <[email protected]>Signed-off-by Pasha Tatashin <[email protected]>[ rm: adjust to rework of iova_cache_{get,put} ]Signed-off-by Robin Murphy <[email protected]>---
FWIW:
Robin Murphy
maintainerRe: [PATCH v3 1/3] iommu/iova: Tidy up iova_cache_get() failure
In reply to John GarryQuoted 8 lines · John Garry
Quoted 7 lines · Robin Murphy
Failure handling in
iova_cache_get()is a little messy, and we'd like to add some more to it, so let's tidy up a bit first. By leaving the hotplug handler until last we can take advantage ofkmem_cache_destroy()being NULL-safe to have a single cleanup label. We can also improve the error reporting, noting thatkmem_cache_create()already screams if it fails, so that one is redundant.
Quoted 4 lines
Quoted 1 line
Signed-off-by Robin Murphy <[email protected]>Regardless of a couple of minor comments, below, FWIW:
Reviewed-by John Garry <[email protected]>
Thanks!
Quoted 13 lines
Quoted 13 lines
---
drivers/iommu/iova.c| 33 ++++++++++++++++-----------------1 file changed, 16 insertions(+), 17 deletions(-)drivers/iommu/iova.c +2
-0@@ -254,26 +254,20 @@ static void free_iova_mem(struct iova *iova) int iova_cache_get(void) { + int err = -ENOMEM; +
Quoted 8 lines
drivers/iommu/iova.c static void free_iova_mem(struct iova *iova) · line 262
Quoted 6 lines
drivers/iommu/iova.c +2
-1mutex_lock(&iova_cache_mutex); if (!iova_cache_users) { - int ret; + iova_cache = kmem_cache_create("iommu_iova", sizeof(structiova ),0 , + SLAB_HWCACHE_ALIGN, NULL);Maybe can use
KMEM_CACHE(), but it would mean that the name would change.
Oh, I never came across that before. On reflection, I am inclined to think that the "iommu_" names are usefully informative to userspace, and it's not worth churning the structure names themselves just to save a couple of lines here.
Quoted 26 lines
Quoted 15 lines
drivers/iommu/iova.c +2
-12+ if (!iova_cache) + goto out_err; - ret = cpuhp_setup_state_multi(CPUHP_IOMMU_IOVA_DEAD, "iommu/iova:dead", NULL, - iova_cpuhp_dead); - if (ret) { - mutex_unlock(&iova_cache_mutex); - pr_err("Couldn't register cpuhp handler\n"); - return ret; - } - - iova_cache = kmem_cache_create( - "iommu_iova", sizeof(struct iova), 0, - SLAB_HWCACHE_ALIGN, NULL); - if (!iova_cache) {drivers/iommu/iova.c static void free_iova_mem(struct iova *iova)
Quoted 10 lines
drivers/iommu/iova.c +4
-4- cpuhp_remove_multi_state(CPUHP_IOMMU_IOVA_DEAD); - mutex_unlock(&iova_cache_mutex); - pr_err("Couldn't create iova cache\n"); - return -ENOMEM; + err = cpuhp_setup_state_multi(CPUHP_IOMMU_IOVA_DEAD,"iommu/iova:dead" , + NULL, iova_cpuhp_dead); + if (err) { + pr_err("IOVA: Couldn't register cpuhp handler: %pe\n",ERR_PTR (err));
Quoted 1 line
Maybe can use
pr_fmtwith "iova".
That one I did consider, but since we now have just this one print and no imminent reason to add more, I figured I'd just stick it inline, and we can factor out a pr_fmt in future if we ever have cause to.
Cheers,
Robin.
Quoted 15 lines
Quoted 14 lines
drivers/iommu/iova.c +1
-0+ goto out_err; }}
drivers/iommu/iova.c +5
-0@@ -281,6 +275,11 @@ int iova_cache_get(void) mutex_unlock(&iova_cache_mutex); return 0; + +out_err: + kmem_cache_destroy(iova_cache); + mutex_unlock(&iova_cache_mutex); + return err; } EXPORT_SYMBOL_GPL(iova_cache_get);
Robin Murphy
maintainerQuoted 16 lines · John Garry
Quoted 15 lines · Robin Murphy
From: Pasha Tatashin <[email protected]>
The magazine buffers can take gigabytes of kmem memory, dominating all other allocations. For observability purpose create named slab cache so the iova magazine memory overhead can be clearly observed.
With this change:
Quoted 1 line
slabtop -o | head
Active / Total Objects (% used) : 869731 / 952904 (91.3%) Active / Total Slabs (% used) : 103411 / 103974 (99.5%) Active / Total Caches (% used) : 135 / 211 (64.0%) Active / Total Size (% used) : 395389.68K / 411430.20K (96.1%) Minimum / Average / Maximum Object : 0.02K / 0.43K / 8.00K
Quoted 8 lines
Quoted 6 lines
OBJS ACTIVE USE OBJ SIZE SLABS OBJ/SLAB CACHE SIZE NAME 244412 244239 99% 1.00K 61103 4 244412K
iommu_iova_magazine91636 88343 96% 0.03K 739 124 2956K kmalloc-32 75744 74844 98% 0.12K 2367 32 9468Kkernfs_node_cacheOn this machine it is now clear that magazine use 242M of kmem memory.
Those caches could do with a trimming ...
See the discussion on v1 for more details:
https://lore.kernel.org/linux-iommu/[email protected]/
but it seems this really is the idle baseline for lots of CPUs * lots of domains - if all those devices get going in anger it's likely that combined iova + iova_magazine usage truly will blow up into gigabytes.
Cheers,
Robin.
Quoted 10 lines
Quoted 7 lines
Acked-by David Rientjes <[email protected]>Signed-off-by Pasha Tatashin <[email protected]>[ rm: adjust to rework of iova_cache_{get,put} ]Signed-off-by Robin Murphy <[email protected]>---
FWIW:
Reviewed-by John Garry <[email protected]>
Re: [PATCH v3 1/3] iommu/iova: Tidy up iova_cache_get() failure
In reply to Robin MurphyQuoted 7 lines · Robin Murphy
Failure handling in
iova_cache_get()is a little messy, and we'd like to add some more to it, so let's tidy up a bit first. By leaving the hotplug handler until last we can take advantage ofkmem_cache_destroy()being NULL-safe to have a single cleanup label. We can also improve the error reporting, noting thatkmem_cache_create()already screams if it fails, so that one is redundant.
Quoted 5 lines
Signed-off-by Robin Murphy <[email protected]>--- drivers/iommu/iova.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-)
Re: [PATCH v3 2/3] iommu/iova: Reorganise some code
In reply to Robin MurphyQuoted 8 lines · Robin Murphy
The iova_cache_{get,put}() calls really represent top-level lifecycle management for the whole IOVA library, so it's long been rather confusing to have them buried right in the middle of the allocator implementation details. Move them to a more expected position at the end of the file, where it will then also be easier to expand them. With this, we can also move the rcache hotplug handler (plus another stray function) into the rcache portion of the file.
Quoted 5 lines
Signed-off-by Robin Murphy <[email protected]>--- drivers/iommu/iova.c | 128 +++++++++++++++++++++---------------------- 1 file changed, 64 insertions(+), 64 deletions(-)
Quoted 20 lines · Robin Murphy
From: Pasha Tatashin <[email protected]>
The magazine buffers can take gigabytes of kmem memory, dominating all other allocations. For observability purpose create named slab cache so the iova magazine memory overhead can be clearly observed.
With this change:
Quoted 1 line
slabtop -o | head
Active / Total Objects (% used) : 869731 / 952904 (91.3%) Active / Total Slabs (% used) : 103411 / 103974 (99.5%) Active / Total Caches (% used) : 135 / 211 (64.0%) Active / Total Size (% used) : 395389.68K / 411430.20K (96.1%)Minimum / Average / Maximum Object : 0.02K / 0.43K / 8.00K
OBJS ACTIVE USE OBJ SIZE SLABS OBJ/SLAB CACHE SIZE NAME
244412 244239 99% 1.00K 61103 4 244412K iommu_iova_magazine 91636 88343 96% 0.03K 739 124 2956K kmalloc-32 75744 74844 98% 0.12K 2367 32 9468K kernfs_node_cache
Quoted 7 lines
On this machine it is now clear that magazine use 242M of kmem memory.
Acked-by David Rientjes <[email protected]>Signed-off-by Pasha Tatashin <[email protected]>[ rm: adjust to rework of iova_cache_{get,put} ]Signed-off-by Robin Murphy <[email protected]>---
Quoted 9 lines · Robin Murphy
Pasha Tatashin (1):
iommu/iova: use namedkmem_cachefor iova magazinesRobin Murphy (2):
iommu/iova: Tidy upiova_cache_get()failure
iommu/iova: Reorganise some codedrivers/iommu/iova.c | 143 +++++++++++++++++++++++-------------------- 1 file changed, 76 insertions(+), 67 deletions(-)
Applied, thanks Robin.