All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tracing: add ACCOUNT flag for allocations from marked slab caches
@ 2022-05-16 18:53 Vasily Averin
  2022-05-16 19:10 ` Shakeel Butt
  2022-05-17 11:53 ` Hyeonggon Yoo
  0 siblings, 2 replies; 8+ messages in thread
From: Vasily Averin @ 2022-05-16 18:53 UTC (permalink / raw)
  To: Roman Gushchin, Vlastimil Babka, Andrew Morton, Joonsoo Kim,
	David Rientjes, Pekka Enberg, Christoph Lameter
  Cc: kernel, linux-mm, linux-kernel, Shakeel Butt, Michal Hocko

Slab caches marked with SLAB_ACCOUNT force accounting for every
allocation from this cache even if __GFP_ACCOUNT flag is not passed.
Unfortunately, at the moment this flag is not visible in ftrace output,
and this makes it difficult to analyze the accounted allocations.

This patch adds the __GFP_ACCOUNT flag for allocations from slab caches
marked with SLAB_ACCOUNT to the ftrace output.

Signed-off-by: Vasily Averin <vvs@openvz.org>
---
 mm/slab.c | 3 +++
 mm/slub.c | 3 +++
 2 files changed, 6 insertions(+)

diff --git a/mm/slab.c b/mm/slab.c
index 0edb474edef1..4c3da8dfcbdb 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -3492,6 +3492,9 @@ void *__kmem_cache_alloc_lru(struct kmem_cache *cachep, struct list_lru *lru,
 {
 	void *ret = slab_alloc(cachep, lru, flags, cachep->object_size, _RET_IP_);
 
+	if (cachep->flags & SLAB_ACCOUNT)
+		flags |= __GFP_ACCOUNT;
+
 	trace_kmem_cache_alloc(_RET_IP_, ret,
 			       cachep->object_size, cachep->size, flags);
 
diff --git a/mm/slub.c b/mm/slub.c
index ed5c2c03a47a..670bbfef9e49 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -3231,6 +3231,9 @@ void *__kmem_cache_alloc_lru(struct kmem_cache *s, struct list_lru *lru,
 {
 	void *ret = slab_alloc(s, lru, gfpflags, _RET_IP_, s->object_size);
 
+	if (s->flags & SLAB_ACCOUNT)
+		gfpflags |= __GFP_ACCOUNT;
+
 	trace_kmem_cache_alloc(_RET_IP_, ret, s->object_size,
 				s->size, gfpflags);
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] tracing: add ACCOUNT flag for allocations from marked slab caches
  2022-05-16 18:53 [PATCH] tracing: add ACCOUNT flag for allocations from marked slab caches Vasily Averin
@ 2022-05-16 19:10 ` Shakeel Butt
  2022-05-16 21:41   ` Vlastimil Babka
  2022-05-17  3:32   ` Vasily Averin
  2022-05-17 11:53 ` Hyeonggon Yoo
  1 sibling, 2 replies; 8+ messages in thread
From: Shakeel Butt @ 2022-05-16 19:10 UTC (permalink / raw)
  To: Vasily Averin
  Cc: Roman Gushchin, Vlastimil Babka, Andrew Morton, Joonsoo Kim,
	David Rientjes, Pekka Enberg, Christoph Lameter, kernel,
	Linux MM, LKML, Michal Hocko

On Mon, May 16, 2022 at 11:53 AM Vasily Averin <vvs@openvz.org> wrote:
>
> Slab caches marked with SLAB_ACCOUNT force accounting for every
> allocation from this cache even if __GFP_ACCOUNT flag is not passed.
> Unfortunately, at the moment this flag is not visible in ftrace output,
> and this makes it difficult to analyze the accounted allocations.
>
> This patch adds the __GFP_ACCOUNT flag for allocations from slab caches
> marked with SLAB_ACCOUNT to the ftrace output.
>
> Signed-off-by: Vasily Averin <vvs@openvz.org>
> ---
>  mm/slab.c | 3 +++
>  mm/slub.c | 3 +++
>  2 files changed, 6 insertions(+)
>
> diff --git a/mm/slab.c b/mm/slab.c
> index 0edb474edef1..4c3da8dfcbdb 100644
> --- a/mm/slab.c
> +++ b/mm/slab.c
> @@ -3492,6 +3492,9 @@ void *__kmem_cache_alloc_lru(struct kmem_cache *cachep, struct list_lru *lru,

What about kmem_cache_alloc_node()?

>  {
>         void *ret = slab_alloc(cachep, lru, flags, cachep->object_size, _RET_IP_);
>
> +       if (cachep->flags & SLAB_ACCOUNT)

Should this 'if' be unlikely() or should we trace cachep->flags
explicitly to avoid this branch altogether?

> +               flags |= __GFP_ACCOUNT;
> +
>         trace_kmem_cache_alloc(_RET_IP_, ret,
>                                cachep->object_size, cachep->size, flags);
>
> diff --git a/mm/slub.c b/mm/slub.c
> index ed5c2c03a47a..670bbfef9e49 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -3231,6 +3231,9 @@ void *__kmem_cache_alloc_lru(struct kmem_cache *s, struct list_lru *lru,
>  {
>         void *ret = slab_alloc(s, lru, gfpflags, _RET_IP_, s->object_size);
>
> +       if (s->flags & SLAB_ACCOUNT)
> +               gfpflags |= __GFP_ACCOUNT;
> +
>         trace_kmem_cache_alloc(_RET_IP_, ret, s->object_size,
>                                 s->size, gfpflags);
>
> --
> 2.25.1
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] tracing: add ACCOUNT flag for allocations from marked slab caches
  2022-05-16 19:10 ` Shakeel Butt
@ 2022-05-16 21:41   ` Vlastimil Babka
  2022-05-16 22:08     ` Roman Gushchin
  2022-05-17  3:32   ` Vasily Averin
  1 sibling, 1 reply; 8+ messages in thread
From: Vlastimil Babka @ 2022-05-16 21:41 UTC (permalink / raw)
  To: Shakeel Butt, Vasily Averin
  Cc: Roman Gushchin, Andrew Morton, Joonsoo Kim, David Rientjes,
	Pekka Enberg, Christoph Lameter, kernel, Linux MM, LKML,
	Michal Hocko, Hyeonggon Yoo

On 5/16/22 21:10, Shakeel Butt wrote:
> On Mon, May 16, 2022 at 11:53 AM Vasily Averin <vvs@openvz.org> wrote:
>>
>> Slab caches marked with SLAB_ACCOUNT force accounting for every
>> allocation from this cache even if __GFP_ACCOUNT flag is not passed.
>> Unfortunately, at the moment this flag is not visible in ftrace output,
>> and this makes it difficult to analyze the accounted allocations.
>>
>> This patch adds the __GFP_ACCOUNT flag for allocations from slab caches
>> marked with SLAB_ACCOUNT to the ftrace output.
>>
>> Signed-off-by: Vasily Averin <vvs@openvz.org>
>> ---
>>  mm/slab.c | 3 +++
>>  mm/slub.c | 3 +++
>>  2 files changed, 6 insertions(+)
>>
>> diff --git a/mm/slab.c b/mm/slab.c
>> index 0edb474edef1..4c3da8dfcbdb 100644
>> --- a/mm/slab.c
>> +++ b/mm/slab.c
>> @@ -3492,6 +3492,9 @@ void *__kmem_cache_alloc_lru(struct kmem_cache *cachep, struct list_lru *lru,
> 
> What about kmem_cache_alloc_node()?
> 
>>  {
>>         void *ret = slab_alloc(cachep, lru, flags, cachep->object_size, _RET_IP_);
>>
>> +       if (cachep->flags & SLAB_ACCOUNT)
> 
> Should this 'if' be unlikely() or should we trace cachep->flags
> explicitly to avoid this branch altogether?

Hm I think ideally the tracepoint accepts cachep instead of current
cachep->*size parameters and does the necessary extraction and
modification in its fast_assign.

> 
>> +               flags |= __GFP_ACCOUNT;
>> +
>>         trace_kmem_cache_alloc(_RET_IP_, ret,
>>                                cachep->object_size, cachep->size, flags);
>>
>> diff --git a/mm/slub.c b/mm/slub.c
>> index ed5c2c03a47a..670bbfef9e49 100644
>> --- a/mm/slub.c
>> +++ b/mm/slub.c
>> @@ -3231,6 +3231,9 @@ void *__kmem_cache_alloc_lru(struct kmem_cache *s, struct list_lru *lru,
>>  {
>>         void *ret = slab_alloc(s, lru, gfpflags, _RET_IP_, s->object_size);
>>
>> +       if (s->flags & SLAB_ACCOUNT)
>> +               gfpflags |= __GFP_ACCOUNT;
>> +
>>         trace_kmem_cache_alloc(_RET_IP_, ret, s->object_size,
>>                                 s->size, gfpflags);
>>
>> --
>> 2.25.1
>>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] tracing: add ACCOUNT flag for allocations from marked slab caches
  2022-05-16 21:41   ` Vlastimil Babka
@ 2022-05-16 22:08     ` Roman Gushchin
  2022-05-17  3:49       ` Vasily Averin
  0 siblings, 1 reply; 8+ messages in thread
From: Roman Gushchin @ 2022-05-16 22:08 UTC (permalink / raw)
  To: Vlastimil Babka
  Cc: Shakeel Butt, Vasily Averin, Andrew Morton, Joonsoo Kim,
	David Rientjes, Pekka Enberg, Christoph Lameter, kernel,
	Linux MM, LKML, Michal Hocko, Hyeonggon Yoo

On Mon, May 16, 2022 at 11:41:27PM +0200, Vlastimil Babka wrote:
> On 5/16/22 21:10, Shakeel Butt wrote:
> > On Mon, May 16, 2022 at 11:53 AM Vasily Averin <vvs@openvz.org> wrote:
> >>
> >> Slab caches marked with SLAB_ACCOUNT force accounting for every
> >> allocation from this cache even if __GFP_ACCOUNT flag is not passed.
> >> Unfortunately, at the moment this flag is not visible in ftrace output,
> >> and this makes it difficult to analyze the accounted allocations.
> >>
> >> This patch adds the __GFP_ACCOUNT flag for allocations from slab caches
> >> marked with SLAB_ACCOUNT to the ftrace output.
> >>
> >> Signed-off-by: Vasily Averin <vvs@openvz.org>
> >> ---
> >>  mm/slab.c | 3 +++
> >>  mm/slub.c | 3 +++
> >>  2 files changed, 6 insertions(+)
> >>
> >> diff --git a/mm/slab.c b/mm/slab.c
> >> index 0edb474edef1..4c3da8dfcbdb 100644
> >> --- a/mm/slab.c
> >> +++ b/mm/slab.c
> >> @@ -3492,6 +3492,9 @@ void *__kmem_cache_alloc_lru(struct kmem_cache *cachep, struct list_lru *lru,
> > 
> > What about kmem_cache_alloc_node()?
> > 
> >>  {
> >>         void *ret = slab_alloc(cachep, lru, flags, cachep->object_size, _RET_IP_);
> >>
> >> +       if (cachep->flags & SLAB_ACCOUNT)
> > 
> > Should this 'if' be unlikely() or should we trace cachep->flags
> > explicitly to avoid this branch altogether?
> 
> Hm I think ideally the tracepoint accepts cachep instead of current
> cachep->*size parameters and does the necessary extraction and
> modification in its fast_assign.

+1 for fast_assign

Changing flags just for tracing looks a bit excessive.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] tracing: add ACCOUNT flag for allocations from marked slab caches
  2022-05-16 19:10 ` Shakeel Butt
  2022-05-16 21:41   ` Vlastimil Babka
@ 2022-05-17  3:32   ` Vasily Averin
  2022-05-17  3:54     ` Matthew Wilcox
  1 sibling, 1 reply; 8+ messages in thread
From: Vasily Averin @ 2022-05-17  3:32 UTC (permalink / raw)
  To: Shakeel Butt
  Cc: Roman Gushchin, Vlastimil Babka, Andrew Morton, Joonsoo Kim,
	David Rientjes, Pekka Enberg, Christoph Lameter, kernel,
	Linux MM, LKML, Michal Hocko

On 5/16/22 22:10, Shakeel Butt wrote:
> On Mon, May 16, 2022 at 11:53 AM Vasily Averin <vvs@openvz.org> wrote:

>> +++ b/mm/slab.c
>> @@ -3492,6 +3492,9 @@ void *__kmem_cache_alloc_lru(struct kmem_cache *cachep, struct list_lru *lru,
> 
> What about kmem_cache_alloc_node()?

Thank you for the hint, I was inaccurate and missed *_node.

>>  {
>>         void *ret = slab_alloc(cachep, lru, flags, cachep->object_size, _RET_IP_);
>>
>> +       if (cachep->flags & SLAB_ACCOUNT)
> 
> Should this 'if' be unlikely() or should we trace cachep->flags
> explicitly to avoid this branch altogether?

In general output of cachep->flags can be useful, but at the moment 
I am only interested in SLAB_ACCOUNT flag and in any case I would
prefer to translate it to GFP_ACCOUNT.
So I'm going to use unlikely() in v2 patch version.

>> +               flags |= __GFP_ACCOUNT;
>> +
>>         trace_kmem_cache_alloc(_RET_IP_, ret,
>>                                cachep->object_size, cachep->size, flags);
>>

Thank you,
	Vasily Averin

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] tracing: add ACCOUNT flag for allocations from marked slab caches
  2022-05-16 22:08     ` Roman Gushchin
@ 2022-05-17  3:49       ` Vasily Averin
  0 siblings, 0 replies; 8+ messages in thread
From: Vasily Averin @ 2022-05-17  3:49 UTC (permalink / raw)
  To: Roman Gushchin, Vlastimil Babka
  Cc: Shakeel Butt, Andrew Morton, Joonsoo Kim, David Rientjes,
	Pekka Enberg, Christoph Lameter, kernel, Linux MM, LKML,
	Michal Hocko, Hyeonggon Yoo

On 5/17/22 01:08, Roman Gushchin wrote:
> On Mon, May 16, 2022 at 11:41:27PM +0200, Vlastimil Babka wrote:
>> On 5/16/22 21:10, Shakeel Butt wrote:
>>> On Mon, May 16, 2022 at 11:53 AM Vasily Averin <vvs@openvz.org> wrote:
>>>>  {
>>>>         void *ret = slab_alloc(cachep, lru, flags, cachep->object_size, _RET_IP_);
>>>>
>>>> +       if (cachep->flags & SLAB_ACCOUNT)
>>>
>>> Should this 'if' be unlikely() or should we trace cachep->flags
>>> explicitly to avoid this branch altogether?
>>
>> Hm I think ideally the tracepoint accepts cachep instead of current
>> cachep->*size parameters and does the necessary extraction and
>> modification in its fast_assign.
> 
> +1 for fast_assign
> 
> Changing flags just for tracing looks a bit excessive.

At the kmem_cache_alloc and kmem_alloc use the same tracing template.
Ok, I'll try to redesign this.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] tracing: add ACCOUNT flag for allocations from marked slab caches
  2022-05-17  3:32   ` Vasily Averin
@ 2022-05-17  3:54     ` Matthew Wilcox
  0 siblings, 0 replies; 8+ messages in thread
From: Matthew Wilcox @ 2022-05-17  3:54 UTC (permalink / raw)
  To: Vasily Averin
  Cc: Shakeel Butt, Roman Gushchin, Vlastimil Babka, Andrew Morton,
	Joonsoo Kim, David Rientjes, Pekka Enberg, Christoph Lameter,
	kernel, Linux MM, LKML, Michal Hocko

On Tue, May 17, 2022 at 06:32:28AM +0300, Vasily Averin wrote:
> > Should this 'if' be unlikely() or should we trace cachep->flags
> > explicitly to avoid this branch altogether?
> 
> In general output of cachep->flags can be useful, but at the moment 
> I am only interested in SLAB_ACCOUNT flag and in any case I would
> prefer to translate it to GFP_ACCOUNT.
> So I'm going to use unlikely() in v2 patch version.

It's still going to be an extra test, and networking is extremely
sensitive to extra instructions if tracing is compiled out.  Passing
in 'cachep' to the trace call looked like the best suggestion to me.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] tracing: add ACCOUNT flag for allocations from marked slab caches
  2022-05-16 18:53 [PATCH] tracing: add ACCOUNT flag for allocations from marked slab caches Vasily Averin
  2022-05-16 19:10 ` Shakeel Butt
@ 2022-05-17 11:53 ` Hyeonggon Yoo
  1 sibling, 0 replies; 8+ messages in thread
From: Hyeonggon Yoo @ 2022-05-17 11:53 UTC (permalink / raw)
  To: Vasily Averin
  Cc: Roman Gushchin, Vlastimil Babka, Andrew Morton, Joonsoo Kim,
	David Rientjes, Pekka Enberg, Christoph Lameter, kernel,
	linux-mm, linux-kernel, Shakeel Butt, Michal Hocko

On Mon, May 16, 2022 at 09:53:32PM +0300, Vasily Averin wrote:
> Slab caches marked with SLAB_ACCOUNT force accounting for every
> allocation from this cache even if __GFP_ACCOUNT flag is not passed.
> Unfortunately, at the moment this flag is not visible in ftrace output,
> and this makes it difficult to analyze the accounted allocations.
> 
> This patch adds the __GFP_ACCOUNT flag for allocations from slab caches
> marked with SLAB_ACCOUNT to the ftrace output.
> 
> Signed-off-by: Vasily Averin <vvs@openvz.org>
> ---
>  mm/slab.c | 3 +++
>  mm/slub.c | 3 +++
>  2 files changed, 6 insertions(+)
> 
> diff --git a/mm/slab.c b/mm/slab.c
> index 0edb474edef1..4c3da8dfcbdb 100644
> --- a/mm/slab.c
> +++ b/mm/slab.c
> @@ -3492,6 +3492,9 @@ void *__kmem_cache_alloc_lru(struct kmem_cache *cachep, struct list_lru *lru,
>  {
>  	void *ret = slab_alloc(cachep, lru, flags, cachep->object_size, _RET_IP_);
>  
> +	if (cachep->flags & SLAB_ACCOUNT)
> +		flags |= __GFP_ACCOUNT;
> +
>  	trace_kmem_cache_alloc(_RET_IP_, ret,
>  			       cachep->object_size, cachep->size, flags);
>  
> diff --git a/mm/slub.c b/mm/slub.c
> index ed5c2c03a47a..670bbfef9e49 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -3231,6 +3231,9 @@ void *__kmem_cache_alloc_lru(struct kmem_cache *s, struct list_lru *lru,
>  {
>  	void *ret = slab_alloc(s, lru, gfpflags, _RET_IP_, s->object_size);
>  
> +	if (s->flags & SLAB_ACCOUNT)
> +		gfpflags |= __GFP_ACCOUNT;
> +
>  	trace_kmem_cache_alloc(_RET_IP_, ret, s->object_size,
>  				s->size, gfpflags);
>  
> -- 
> 2.25.1
> 
> 

To me it sounds like it would confuse memory cgroup because:
	1) For now objects are charged only in slab memcg hooks
	2) This patch makes buddy allocator charge the page too

-- 
Thanks,
Hyeonggon

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-05-17 11:53 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-16 18:53 [PATCH] tracing: add ACCOUNT flag for allocations from marked slab caches Vasily Averin
2022-05-16 19:10 ` Shakeel Butt
2022-05-16 21:41   ` Vlastimil Babka
2022-05-16 22:08     ` Roman Gushchin
2022-05-17  3:49       ` Vasily Averin
2022-05-17  3:32   ` Vasily Averin
2022-05-17  3:54     ` Matthew Wilcox
2022-05-17 11:53 ` Hyeonggon Yoo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.