Re: [RFC][PATCH] inotify 0.9.2

From: Robert Love
Date: Tue Sep 21 2004 - 13:58:51 EST


On Tue, 2004-09-21 at 12:04 -0400, Robert Love wrote:

> Hey, John.
>
> We are seeing an oops when monitoring a large number of directories.
> The system keeps running, but I/O gets flaky and eventually processes
> start getting stuck.
>
> Also, the ioctl() stops returning new WD after 1024. Thereafter, it
> keeps returning the same value.
>
> I have attached the relevant bits from the syslog. I will debug it, but
> I thought that perhaps you would immediately see the issue.

OK. I fixed the problem with ioctl() failing after 1024 WD's. This may
also fix the oopses. Still checking on that.

The problem was that we were passing the size of dev->bitmask in _bytes_
to find_first_zero_bit(). But find_first_zero_bit()'s second parameter
is the size in _bits_.

I then went ahead and just made dev->bitmask an array, since we know the
size at compile time.

Comments?

Best,

Robert Love

Fix problem with ioctl() failing after 1024 WD's, by giving ffz bits not bytes.
Signed-Off-By: Robert Love <rml@xxxxxxxxxx>

drivers/char/inotify.c | 8 +++-----
1 files changed, 3 insertions(+), 5 deletions(-)

--- linux-inotify-rml/drivers/char/inotify.c 2004-09-20 18:02:32.886258448 -0400
+++ linux/drivers/char/inotify.c 2004-09-21 14:51:11.433908024 -0400
@@ -43,7 +43,6 @@
#define MAX_INOTIFY_DEVS 8 /* We only support X watchers */
#define MAX_INOTIFY_DEV_WATCHERS 8192 /* A dev can only have Y watchers */
#define MAX_INOTIFY_QUEUED_EVENTS 256 /* Only the first Z events will be queued */
-#define __BITMASK_SIZE (MAX_INOTIFY_DEV_WATCHERS / 8)

#define INOTIFY_DEV_TIMER_TIME jiffies + (HZ/4)

@@ -71,7 +70,7 @@
struct timer_list timer;
char read_state;
spinlock_t lock;
- void * bitmask;
+ unsigned long bitmask[MAX_INOTIFY_DEV_WATCHERS / BITS_PER_LONG];
};
#define inotify_device_event_list(pos) list_entry((pos), struct inotify_event, list)

@@ -239,7 +238,7 @@

dev->watcher_count++;

- wd = find_first_zero_bit (dev->bitmask, __BITMASK_SIZE);
+ wd = find_first_zero_bit (dev->bitmask, MAX_INOTIFY_DEV_WATCHERS);

set_bit (wd, dev->bitmask);

@@ -653,8 +652,7 @@
atomic_inc(&watcher_count);

dev = kmalloc(sizeof(struct inotify_device), GFP_KERNEL);
- dev->bitmask = kmalloc(__BITMASK_SIZE, GFP_KERNEL);
- memset(dev->bitmask, 0, __BITMASK_SIZE);
+ memset(dev->bitmask, 0, MAX_INOTIFY_DEV_WATCHERS);

INIT_LIST_HEAD(&dev->events);
INIT_LIST_HEAD(&dev->watchers);