[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <BD3E2B25-B09B-497B-A017-C95C59BDEB83@dilger.ca>
Date: Thu, 14 Dec 2017 16:59:23 -0700
From: Andreas Dilger <adilger@...ger.ca>
To: Krzysztof Opasiak <k.opasiak@...sung.com>
Cc: Greg KH <gregkh@...uxfoundation.org>,
Al Viro <viro@...iv.linux.org.uk>,
Arnd Bergmann <arnd@...db.de>, linux-kernel@...r.kernel.org,
linux-fsdevel@...r.kernel.org, linux-arch@...r.kernel.org,
k.lewandowsk@...sung.com, l.stelmach@...sung.com,
p.szewczyk@...sung.com
Subject: Re: [RFC PATCH v2 4/4] Allow to trace fd usage with rlimit-events
On Dec 14, 2017, at 3:00 PM, Krzysztof Opasiak <k.opasiak@...sung.com> wrote:
>
> Add rlimit-events calls to file descriptors management
> code to allow tracing of FD usage.
>
> This allows userspace process (monitor) to get notification when
> other process (subject) uses given amount of file descriptors.
>
> This can be used to for example asynchronously monitor number
> of open FD's in system services instead of polling with
> predefined interval.
I'm not involved in this area of code, but one optimization question:
> +static unsigned int count_open_fds(struct fdtable *fdt)
> +{
> + unsigned int maxfd = fdt->max_fds;
> + unsigned int maxbit = maxfd / BITS_PER_LONG;
> + unsigned int count = 0;
> + int i;
> +
> + i = find_next_zero_bit(fdt->full_fds_bits, maxbit, 0);
> + /* If there is no free fds */
> + if (i > maxbit)
> + return maxfd;
> +#if BITS_PER_LONG == 32
> +#define HWEIGHT_LONG hweight32
> +#else
> +#define HWEIGHT_LONG hweight64
> +#endif
> +
> + count += i * BITS_PER_LONG;
> + for (; i < maxbit; ++i)
> + count += HWEIGHT_LONG(fdt->open_fds[i]);
> +
> +#undef HWEIGHT_LONG
> + return count;
> +}
Since find_next_zero_bit() needs to process all of the words anyway
as well as lots of extra operations that add overhead, it looks more
efficient to just compute HWEIGHT_LONG(open_fds[]) for the whole array.
Cheers, Andreas
Download attachment "signature.asc" of type "application/pgp-signature" (196 bytes)
Powered by blists - more mailing lists