diff mbox series

[v3,07/11] lib/ref_tracker: remove warnings in case of allocation failure

Message ID 20220221232542.1481315-8-andrzej.hajda@intel.com (mailing list archive)
State New, archived
Headers show
Series drm/i915: use ref_tracker library for tracking wakerefs | expand

Commit Message

Andrzej Hajda Feb. 21, 2022, 11:25 p.m. UTC
Library can handle allocation failures. To avoid allocation warnings
__GFP_NOWARN has been added everywhere. Moreover GFP_ATOMIC has been
replaced with GFP_NOWAIT in case of stack allocation on tracker free
call.

Signed-off-by: Andrzej Hajda <andrzej.hajda@intel.com>
---
 lib/ref_tracker.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Eric Dumazet Feb. 21, 2022, 11:54 p.m. UTC | #1
On Mon, Feb 21, 2022 at 3:26 PM Andrzej Hajda <andrzej.hajda@intel.com> wrote:
>
> Library can handle allocation failures. To avoid allocation warnings
> __GFP_NOWARN has been added everywhere. Moreover GFP_ATOMIC has been
> replaced with GFP_NOWAIT in case of stack allocation on tracker free
> call.
>
> Signed-off-by: Andrzej Hajda <andrzej.hajda@intel.com>
> ---
>  lib/ref_tracker.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/lib/ref_tracker.c b/lib/ref_tracker.c
> index 2ef4596b6b36f..cae4498fcfd70 100644
> --- a/lib/ref_tracker.c
> +++ b/lib/ref_tracker.c
> @@ -189,7 +189,7 @@ int ref_tracker_alloc(struct ref_tracker_dir *dir,
>         unsigned long entries[REF_TRACKER_STACK_ENTRIES];
>         struct ref_tracker *tracker;
>         unsigned int nr_entries;
> -       gfp_t gfp_mask = gfp;
> +       gfp_t gfp_mask = gfp | __GFP_NOWARN;

SGTM

>         unsigned long flags;
>
>         WARN_ON_ONCE(dir->dead);
> @@ -237,7 +237,8 @@ int ref_tracker_free(struct ref_tracker_dir *dir,
>                 return -EEXIST;
>         }
>         nr_entries = stack_trace_save(entries, ARRAY_SIZE(entries), 1);
> -       stack_handle = stack_depot_save(entries, nr_entries, GFP_ATOMIC);
> +       stack_handle = stack_depot_save(entries, nr_entries,
> +                                       GFP_NOWAIT | __GFP_NOWARN);

Last time I looked at this, __GFP_NOWARN was enforced in __stack_depot_save()

>
>         spin_lock_irqsave(&dir->lock, flags);
>         if (tracker->dead) {
> --
> 2.25.1
>
Andrzej Hajda Feb. 22, 2022, 10:44 a.m. UTC | #2
On 22.02.2022 00:54, Eric Dumazet wrote:
> On Mon, Feb 21, 2022 at 3:26 PM Andrzej Hajda <andrzej.hajda@intel.com> wrote:
>> Library can handle allocation failures. To avoid allocation warnings
>> __GFP_NOWARN has been added everywhere. Moreover GFP_ATOMIC has been
>> replaced with GFP_NOWAIT in case of stack allocation on tracker free
>> call.
>>
>> Signed-off-by: Andrzej Hajda <andrzej.hajda@intel.com>
>> ---
>>   lib/ref_tracker.c | 5 +++--
>>   1 file changed, 3 insertions(+), 2 deletions(-)
>>
>> diff --git a/lib/ref_tracker.c b/lib/ref_tracker.c
>> index 2ef4596b6b36f..cae4498fcfd70 100644
>> --- a/lib/ref_tracker.c
>> +++ b/lib/ref_tracker.c
>> @@ -189,7 +189,7 @@ int ref_tracker_alloc(struct ref_tracker_dir *dir,
>>          unsigned long entries[REF_TRACKER_STACK_ENTRIES];
>>          struct ref_tracker *tracker;
>>          unsigned int nr_entries;
>> -       gfp_t gfp_mask = gfp;
>> +       gfp_t gfp_mask = gfp | __GFP_NOWARN;
> SGTM
>
>>          unsigned long flags;
>>
>>          WARN_ON_ONCE(dir->dead);
>> @@ -237,7 +237,8 @@ int ref_tracker_free(struct ref_tracker_dir *dir,
>>                  return -EEXIST;
>>          }
>>          nr_entries = stack_trace_save(entries, ARRAY_SIZE(entries), 1);
>> -       stack_handle = stack_depot_save(entries, nr_entries, GFP_ATOMIC);
>> +       stack_handle = stack_depot_save(entries, nr_entries,
>> +                                       GFP_NOWAIT | __GFP_NOWARN);
> Last time I looked at this, __GFP_NOWARN was enforced in __stack_depot_save()

You are right, however I am not sure if we should count on unexpected 
(at least for me) and undocumented behavior.
Currently we do not need to rely on some hidden feature.

Regards
Andrzej

>
>>          spin_lock_irqsave(&dir->lock, flags);
>>          if (tracker->dead) {
>> --
>> 2.25.1
>>
diff mbox series

Patch

diff --git a/lib/ref_tracker.c b/lib/ref_tracker.c
index 2ef4596b6b36f..cae4498fcfd70 100644
--- a/lib/ref_tracker.c
+++ b/lib/ref_tracker.c
@@ -189,7 +189,7 @@  int ref_tracker_alloc(struct ref_tracker_dir *dir,
 	unsigned long entries[REF_TRACKER_STACK_ENTRIES];
 	struct ref_tracker *tracker;
 	unsigned int nr_entries;
-	gfp_t gfp_mask = gfp;
+	gfp_t gfp_mask = gfp | __GFP_NOWARN;
 	unsigned long flags;
 
 	WARN_ON_ONCE(dir->dead);
@@ -237,7 +237,8 @@  int ref_tracker_free(struct ref_tracker_dir *dir,
 		return -EEXIST;
 	}
 	nr_entries = stack_trace_save(entries, ARRAY_SIZE(entries), 1);
-	stack_handle = stack_depot_save(entries, nr_entries, GFP_ATOMIC);
+	stack_handle = stack_depot_save(entries, nr_entries,
+					GFP_NOWAIT | __GFP_NOWARN);
 
 	spin_lock_irqsave(&dir->lock, flags);
 	if (tracker->dead) {