2002-10-08 18:02:32

by Theodore Y. Ts'o

[permalink] [raw]
Subject: [RFC] [PATCH 1/4] Add extended attributes to ext2/3


This is the first of four patches which add extended attribute support
to the ext2 and ext3 filesystems. It is a port of Andreas Gruenbacher's
patches, which have been well tested and in a number of distributions
(including RH 8, if I'm not mistaken) already. I just ported it to 2.5
(these patches are versus 2.5.40). As always, since I touched the code
last, any problems in it are my fault. :-)

These patches are prerequisite for the port of the Andreas Gruenbacher's
ACL patches to 2.5, which I'm currently working on. But given the short
time-frame before feature freeze, I'd like to get these out for review
ASAP. Please comment and bleed on them.

This first patch creates a generic interface for registering caches with
the VM subsystem so that they can react appropriately to memory
pressure.


# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
#
# include/linux/cache_def.h | 15 +++++++++++++++
# kernel/ksyms.c | 3 +++
# mm/vmscan.c | 29 +++++++++++++++++++++++++++++
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 02/10/04 [email protected] 1.665
# Port of the 0.8.50 cache-def patch.
# --------------------------------------------
#
diff -Nru a/include/linux/cache_def.h b/include/linux/cache_def.h
--- /dev/null Wed Dec 31 16:00:00 1969
+++ b/include/linux/cache_def.h Tue Oct 8 13:52:08 2002
@@ -0,0 +1,15 @@
+/*
+ * linux/cache_def.h
+ * Handling of caches defined in drivers, filesystems, ...
+ *
+ * Copyright (C) 2002 by Andreas Gruenbacher, <[email protected]>
+ */
+
+struct cache_definition {
+ const char *name;
+ void (*shrink)(int, unsigned int);
+ struct list_head link;
+};
+
+extern void register_cache(struct cache_definition *);
+extern void unregister_cache(struct cache_definition *);
diff -Nru a/kernel/ksyms.c b/kernel/ksyms.c
--- a/kernel/ksyms.c Tue Oct 8 13:52:08 2002
+++ b/kernel/ksyms.c Tue Oct 8 13:52:08 2002
@@ -31,6 +31,7 @@
#include <linux/genhd.h>
#include <linux/blkpg.h>
#include <linux/swap.h>
+#include <linux/cache_def.h>
#include <linux/ctype.h>
#include <linux/file.h>
#include <linux/iobuf.h>
@@ -106,6 +107,8 @@
EXPORT_SYMBOL(kmem_cache_alloc);
EXPORT_SYMBOL(kmem_cache_free);
EXPORT_SYMBOL(kmem_cache_size);
+EXPORT_SYMBOL(register_cache);
+EXPORT_SYMBOL(unregister_cache);
EXPORT_SYMBOL(kmalloc);
EXPORT_SYMBOL(kfree);
EXPORT_SYMBOL(vfree);
diff -Nru a/mm/vmscan.c b/mm/vmscan.c
--- a/mm/vmscan.c Tue Oct 8 13:52:08 2002
+++ b/mm/vmscan.c Tue Oct 8 13:52:08 2002
@@ -15,6 +15,7 @@
#include <linux/slab.h>
#include <linux/kernel_stat.h>
#include <linux/swap.h>
+#include <linux/cache_def.h>
#include <linux/pagemap.h>
#include <linux/init.h>
#include <linux/highmem.h>
@@ -76,6 +77,33 @@
#define shrink_dqcache_memory(ratio, gfp_mask) do { } while (0)
#endif

+static LIST_HEAD(cache_definitions);
+
+/* BKL must be held */
+void register_cache(struct cache_definition *cache)
+{
+ list_add(&cache->link, &cache_definitions);
+}
+
+/* BLK must be held */
+void unregister_cache(struct cache_definition *cache)
+{
+ list_del(&cache->link);
+}
+
+static void shrink_other_caches(int ratio, int gfp_mask)
+{
+ struct list_head *p = cache_definitions.prev;
+
+ while (p != &cache_definitions) {
+ struct cache_definition *cache =
+ list_entry(p, struct cache_definition, link);
+
+ cache->shrink(ratio, gfp_mask); /* BLK held */
+ p = p->prev;
+ }
+}
+
/* Must be called with page's pte_chain_lock held. */
static inline int page_mapping_inuse(struct page * page)
{
@@ -614,6 +642,7 @@
shrink_dcache_memory(ratio, gfp_mask);
shrink_icache_memory(ratio, gfp_mask);
shrink_dqcache_memory(ratio, gfp_mask);
+ shrink_other_caches(ratio, gfp_mask);
return nr_pages;
}


2002-10-08 18:13:22

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [Ext2-devel] [RFC] [PATCH 1/4] Add extended attributes to ext2/3

On Tue, Oct 08, 2002 at 02:08:11PM -0400, [email protected] wrote:
>
> This is the first of four patches which add extended attribute support
> to the ext2 and ext3 filesystems. It is a port of Andreas Gruenbacher's
> patches, which have been well tested and in a number of distributions
> (including RH 8, if I'm not mistaken) already.

RH backed it out after the second or third beta due to bugginess..

> This first patch creates a generic interface for registering caches with
> the VM subsystem so that they can react appropriately to memory
> pressure.

I'd suggest Ed Tomlinson's much saner interface that adds a third callbackj
to kmem_cache_t (similar to the Solaris implementation) instead.

Doing this outside slab is not a good idea (and XFS currently does
it too - in it's own code which should be replaced with Ed's one)

2002-10-08 18:15:43

by Rik van Riel

[permalink] [raw]
Subject: Re: [RFC] [PATCH 1/4] Add extended attributes to ext2/3

On Tue, 8 Oct 2002 [email protected] wrote:

> This first patch creates a generic interface for registering caches with
> the VM subsystem so that they can react appropriately to memory
> pressure.

> +/* BKL must be held */

... but it isn't. Also, kswapd isn't holding the bkl while
traversing the list.

> +void register_cache(struct cache_definition *cache)
> +{
> + list_add(&cache->link, &cache_definitions);
> +}

I suspect you'll want a semaphore for the cache_definitions
list.

cheers,

Rik
--
A: No.
Q: Should I include quotations after my reply?

http://www.surriel.com/ http://distro.conectiva.com/

2002-10-08 18:35:08

by Theodore Y. Ts'o

[permalink] [raw]
Subject: Re: [Ext2-devel] [RFC] [PATCH 1/4] Add extended attributes to ext2/3

On Tue, Oct 08, 2002 at 07:19:00PM +0100, Christoph Hellwig wrote:
> > This first patch creates a generic interface for registering caches with
> > the VM subsystem so that they can react appropriately to memory
> > pressure.
>
> I'd suggest Ed Tomlinson's much saner interface that adds a third callbackj
> to kmem_cache_t (similar to the Solaris implementation) instead.

Can you give me a pointer to his stuff? Thanks!

- Ted

> Doing this outside slab is not a good idea (and XFS currently does
> it too - in it's own code which should be replaced with Ed's one)

2002-10-08 18:53:43

by Andreas Gruenbacher

[permalink] [raw]
Subject: Re: [Ext2-devel] Re: [RFC] [PATCH 1/4] Add extended attributes to ext2/3

On Tuesday 08 October 2002 20:21, Rik van Riel wrote:
> On Tue, 8 Oct 2002 [email protected] wrote:
> > This first patch creates a generic interface for registering caches with
> > the VM subsystem so that they can react appropriately to memory
> > pressure.
> >
> > +/* BKL must be held */
>
> ... but it isn't. Also, kswapd isn't holding the bkl while
> traversing the list.
>
> > +void register_cache(struct cache_definition *cache)
> > +{
> > + list_add(&cache->link, &cache_definitions);
> > +}
>
> I suspect you'll want a semaphore for the cache_definitions
> list.

My apologies. This has slipped me; I had in fact added a semaphore in a
different branch. Here is a fixed version.

--Andreas.

diff -Nru a/include/linux/cache_def.h b/include/linux/cache_def.h
--- /dev/null Wed Dec 31 16:00:00 1969
+++ b/include/linux/cache_def.h Tue Oct 8 13:52:08 2002
@@ -0,0 +1,15 @@
+/*
+ * linux/cache_def.h
+ * Handling of caches defined in drivers, filesystems, ...
+ *
+ * Copyright (C) 2002 by Andreas Gruenbacher, <[email protected]>
+ */
+
+struct cache_definition {
+ const char *name;
+ void (*shrink)(int, unsigned int);
+ struct list_head link;
+};
+
+extern void register_cache(struct cache_definition *);
+extern void unregister_cache(struct cache_definition *);
--- a/kernel/ksyms.c Tue Oct 8 13:52:08 2002
+++ b/kernel/ksyms.c Tue Oct 8 13:52:08 2002
@@ -31,6 +31,7 @@
#include <linux/genhd.h>
#include <linux/blkpg.h>
#include <linux/swap.h>
+#include <linux/cache_def.h>
#include <linux/ctype.h>
#include <linux/file.h>
#include <linux/iobuf.h>
@@ -106,6 +107,8 @@
EXPORT_SYMBOL(kmem_cache_alloc);
EXPORT_SYMBOL(kmem_cache_free);
EXPORT_SYMBOL(kmem_cache_size);
+EXPORT_SYMBOL(register_cache);
+EXPORT_SYMBOL(unregister_cache);
EXPORT_SYMBOL(kmalloc);
EXPORT_SYMBOL(kfree);
EXPORT_SYMBOL(vfree);
--- a/mm/vmscan.c Tue Oct 8 13:52:08 2002
+++ b/mm/vmscan.c Tue Oct 8 13:52:08 2002
@@ -15,6 +15,7 @@
#include <linux/slab.h>
#include <linux/kernel_stat.h>
#include <linux/swap.h>
+#include <linux/cache_def.h>
#include <linux/pagemap.h>
#include <linux/init.h>
#include <linux/highmem.h>
@@ -76,6 +77,39 @@
#define shrink_dqcache_memory(ratio, gfp_mask) do { } while (0)
#endif

+static DECLARE_MUTEX(other_caches_sem);
+static LIST_HEAD(cache_definitions);
+
+void register_cache(struct cache_definition *cache)
+{
+ down(&other_caches_sem);
+ list_add(&cache->link, &cache_definitions);
+ up(&other_caches_sem);
+}
+
+void unregister_cache(struct cache_definition *cache)
+{
+ down(&other_caches_sem);
+ list_del(&cache->link);
+ up(&other_caches_sem);
+}
+
+static void shrink_other_caches(int ratio, int gfp_mask)
+{
+ struct list_head *p;
+
+ down(&other_caches_sem);
+ p = cache_definitions.prev;
+ while (p != &cache_definitions) {
+ struct cache_definition *cache =
+ list_entry(p, struct cache_definition, link);
+
+ cache->shrink(ratio, gfp_mask);
+ p = p->prev;
+ }
+ up(&other_caches_sem);
+}
+
/* Must be called with page's pte_chain_lock held. */
static inline int page_mapping_inuse(struct page * page)
{
@@ -614,6 +648,7 @@
shrink_dcache_memory(ratio, gfp_mask);
shrink_icache_memory(ratio, gfp_mask);
shrink_dqcache_memory(ratio, gfp_mask);
+ shrink_other_caches(ratio, gfp_mask);
return nr_pages;
}

2002-10-08 18:45:50

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [Ext2-devel] [RFC] [PATCH 1/4] Add extended attributes to ext2/3

On Tue, Oct 08, 2002 at 02:40:39PM -0400, Theodore Ts'o wrote:
> On Tue, Oct 08, 2002 at 07:19:00PM +0100, Christoph Hellwig wrote:
> > > This first patch creates a generic interface for registering caches with
> > > the VM subsystem so that they can react appropriately to memory
> > > pressure.
> >
> > I'd suggest Ed Tomlinson's much saner interface that adds a third callbackj
> > to kmem_cache_t (similar to the Solaris implementation) instead.
>
> Can you give me a pointer to his stuff? Thanks!

It is/was in akpm's -mm tree (http://www.zip.com.au/~akpm/linux/patches/2.5/).
Ed, do you have a pointer to your most recent patch?

2002-10-08 22:36:58

by Ed Tomlinson

[permalink] [raw]
Subject: Re: [Ext2-devel] [RFC] [PATCH 1/4] Add extended attributes to ext2/3

On October 8, 2002 02:50 pm, Christoph Hellwig wrote:
> On Tue, Oct 08, 2002 at 02:40:39PM -0400, Theodore Ts'o wrote:
> > On Tue, Oct 08, 2002 at 07:19:00PM +0100, Christoph Hellwig wrote:
> > > > This first patch creates a generic interface for registering caches
> > > > with the VM subsystem so that they can react appropriately to memory
> > > > pressure.
> > >
> > > I'd suggest Ed Tomlinson's much saner interface that adds a third
> > > callbackj to kmem_cache_t (similar to the Solaris implementation)
> > > instead.
> >
> > Can you give me a pointer to his stuff? Thanks!
>
> It is/was in akpm's -mm tree
> (http://www.zip.com.au/~akpm/linux/patches/2.5/). Ed, do you have a pointer
> to your most recent patch?

Its in Andrew's tree.

Ed