Re: [PATCH v4 14/36] lib: add allocation tagging support for memory allocation profiling
From: Suren Baghdasaryan <surenb@google.com>
Date: 2024-02-28 18:07:33
Also in:
cgroups, linux-arch, linux-doc, linux-fsdevel, linux-iommu, linux-mm, lkml
On Wed, Feb 28, 2024 at 8:41 AM Vlastimil Babka [off-list ref] wrote:
Another thing I noticed, dunno how critical On 2/21/24 20:40, Suren Baghdasaryan wrote:quoted
+static inline void __alloc_tag_sub(union codetag_ref *ref, size_t bytes) +{ + struct alloc_tag *tag; + +#ifdef CONFIG_MEM_ALLOC_PROFILING_DEBUG + WARN_ONCE(ref && !ref->ct, "alloc_tag was not set\n"); +#endif + if (!ref || !ref->ct) + return;This is quite careful.quoted
+ + tag = ct_to_alloc_tag(ref->ct); + + this_cpu_sub(tag->counters->bytes, bytes); + this_cpu_dec(tag->counters->calls); + + ref->ct = NULL; +} + +static inline void alloc_tag_sub(union codetag_ref *ref, size_t bytes) +{ + __alloc_tag_sub(ref, bytes); +} + +static inline void alloc_tag_sub_noalloc(union codetag_ref *ref, size_t bytes) +{ + __alloc_tag_sub(ref, bytes); +} + +static inline void alloc_tag_ref_set(union codetag_ref *ref, struct alloc_tag *tag) +{ +#ifdef CONFIG_MEM_ALLOC_PROFILING_DEBUG + WARN_ONCE(ref && ref->ct, + "alloc_tag was not cleared (got tag for %s:%u)\n",\ + ref->ct->filename, ref->ct->lineno); + + WARN_ONCE(!tag, "current->alloc_tag not set"); +#endif + if (!ref || !tag) + return;This too.quoted
+ + ref->ct = &tag->ct; + /* + * We need in increment the call counter every time we have a new + * allocation or when we split a large allocation into smaller ones. + * Each new reference for every sub-allocation needs to increment call + * counter because when we free each part the counter will be decremented. + */ + this_cpu_inc(tag->counters->calls); +} + +static inline void alloc_tag_add(union codetag_ref *ref, struct alloc_tag *tag, size_t bytes) +{ + alloc_tag_ref_set(ref, tag);We might have returned from alloc_tag_ref_set() due to !tagquoted
+ this_cpu_add(tag->counters->bytes, bytes);But here we still assume it's valid.
Yes, this is a blunder on my side after splitting alloc_tag_ref_set() into a separate function. I'll fix this in the next version. Thanks!
quoted
+} +-- To unsubscribe from this group and stop receiving emails from it, send an email to kernel-team+unsubscribe@android.com.