lkml.org 
[lkml]   [2020]   [Jan]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH] perf/core: fix mlock accounting in perf_mmap()
Date
Song Liu <songliubraving@fb.com> writes:

> Actually, I think this is cleaner.

I don't think multiple conditional blocks are cleaner, at least in this
case.

> diff --git i/kernel/events/core.c w/kernel/events/core.c
> index 2173c23c25b4..debd84fcf9cc 100644
> --- i/kernel/events/core.c
> +++ w/kernel/events/core.c
> @@ -5916,14 +5916,18 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma)
> */
> user_lock_limit *= num_online_cpus();
>
> - user_locked = atomic_long_read(&user->locked_vm) + user_extra;
> + user_locked = atomic_long_read(&user->locked_vm);
>
> if (user_locked > user_lock_limit) {
> + /* charge all to pinned_vm */
> + extra = user_extra;
> + user_extra = 0;
> + } else if (user_lock + user_extra > user_lock_limit)

You probably mean "user_locked" here.

> /*
> * charge locked_vm until it hits user_lock_limit;
> * charge the rest from pinned_vm
> */
> - extra = user_locked - user_lock_limit;
> + extra = user_locked + user_extra - user_lock_limit;

To me, this is a bit harder to read.

> user_extra -= extra;
> }
>
> Alexander, does this look good to you?

I like to think of this as: we charge the pages to locked_vm until we
exhaust user_lock_limit, and the rest we charge to pinned_vm. Everything
else are just corner cases, and they fit into the same general case. When
we start calculating each corner case in its own block, we just multiply
the potential errors. And there have been errors in this particular path
before. So, the shorter, and the fewer the "if...else if..." statements,
the better it looks to me. Otherwise, it's a matter of preference.

Thanks,
--
Alex

\
 
 \ /
  Last update: 2020-01-22 09:51    [W:0.059 / U:0.220 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site