Permit filesystem local caching [ver #46]
Subsystems (15)
David Howells
maintainercover Permit filesystem local caching [ver #46]
These patches add local caching for network filesystems such as NFS. To give a really quick overview of the way the facility works:
+---------+ | | | NFS |--+ | | | +---------+ | +----------+ | | | +---------+ +-->| | | | | | | AFS |----->| FS-Cache | | | | |--+ +---------+ +-->| | | | | | | +--------------+ +--------------+ +---------+ | +----------+ | | | | | | | | +-->| CacheFiles |-->| Ext3 | | ISOFS |--+ | /var/cache | | /dev/sda6 | | | +--------------+ +--------------+ +---------+
(1) NFS, say, asks FS-Cache to store/retrieve data for it;
(2) FS-Cache asks the cache backend, in this case CacheFiles to honour the
operation;
(3) CacheFiles 'opens' a file in a mounted filesystem, say Ext3, and does read
and write operations of a sort on it;
(4) Ext3 decides how the cache data is laid out on disk - CacheFiles just attempts to use one sparse file per netfs inode.
(5) If NFS asks for data from the cache, but the file has a hole in it, NFS falls back to asking the server. The data obtained from the server is then written over the hole in the file.
To look at it another way:
+---------+ | | | Server | | | +---------+ | NETWORK ~~~~~|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | +----------+ V | | +---------+ | | | | | | | NFS |----->| FS-Cache | | | | |--+ +---------+ | | | +--------------+ +--------------+ | | | | | | | | V +----------+ +-->| CacheFiles |-->| Ext3 | +---------+ | /var/cache | | /dev/sda6 | | | +--------------+ +--------------+ | VFS | ^ ^ | | | | +---------+ +--------------+ | | KERNEL SPACE | | ~~~~~|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|~~~~~~|~~~~ | USER SPACE | | V | | +---------+ +--------------+ | | | | | Process | | cachefilesd | | | | | +---------+ +--------------+
FS-Cache attempts to provide a caching facility to a network filesystem such that it's transparent to the users of that network filesystem.
The patches can roughly be broken down into a number of sets:
(*) 01-slow-work.diff
(*) 02-slow-work-dynamic.diff
(*) 03-slow-work-config.diff
(*) 04-slow-work-doc.diff
A thread pool for (very) slow work items, such as batches of lookup, mkdir, create and [sg]etxattr calls.
It doesn't make sense to use an ordinary work queue because I want more than one thread, but I don't want to be limited to 1 thread per CPU. The work items in question take a long time, most of which is spent sleeping on I/O. For the duration the worker thread is unable to do anything else.
These four patches add the basic facility, make it dynamic, make it configurable and document it.
(*) 05-release-page.diff
Call the page release function after a failed readahead.
(*) 06-fscache-page-flags.diff
Add two extra page flags that FS-Cache then uses to keep track of two bits of per-cached-page information:
(1) This page is known by the cache, and that the cache must be informed if the page is going to go away. It's an indication to the netfs that the cache has an interest in this page, where an interest may be a pointer to it, resources allocated or reserved for it, or I/O in progress upon it.
(2) This page is being written to disk by the cache, and that it cannot be released until completion. Ideally it shouldn't be changed until completion either so as to maintain the known state of the cache. This cannot be unified with PG_writeback as the page may be being written to both the server and the cache at the same time or at different times.
To avoid using extra page bits, I could, for example, set up a radix tree per data storage object to keep track of both these bits, however this would mean that the netfs would have to do a call, spinlock, conditional jumps, etc to find out either state.
On the other hand, if we can spare two page flags, those are sufficient.
Note that the cache doesn't necessarily need to be able to find the netfs pages, but may have to allocate/pin resources for backing them.
Further note that PG_private may not be used as I want to be able to use caching with ISOFS eventually, and PG_private is owned by the block buffer code.
These bits can be otherwise used by any filesystem that doesn't want to use FS-Cache.
(*) 07-fscache-netfs-api.diff
(*) 08-fscache-backend-api.diff
(*) 09-fscache-kconfig.diff
(*) 10-fscache-proc.diff
(*) 11-fscache-fsdef.diff
(*) 12-fscache-tag-handling.diff
(*) 13-fscache-cache-handling.diff
(*) 14-fscache-cookie-jar.diff
(*) 15-fscache-netfs-reg.diff
(*) 16-fscache-bits.diff
(*) 17-fscache-object.diff
(*) 18-fscache-cookie.diff
(*) 19-fscache-operation.diff
(*) 20-fscache-io.diff
Patches to provide a local caching facility for network filesystems.
FS-Cache is a layer that takes requests from any one of a number of netfs's and passes them to an appropriate cache, if there is one. FS-Cache makes operations requested by the netfs transparently asynchronous where possible.
FS-Cache also protects the netfs against (a) there being no cache, (b) the cache suffering a fatal I/O error and (c) the cache being removed; and protects the cache against (d) the netfs uncaching pages that the cache is using and (e) conflicting operations from the netfs, some of which may be queued for asynchronous processing.
Five documents in text file format that describe the FS-Cache interface are added by these patches:
Documentation/filesystems/caching/fscache.txt gives an overview of the facility and describes the statistical data it makes available.
Documentation/filesystems/caching/netfs-api.txt describes the API by which a network filesystem would make use of the FS-Cache facility.
Documentation/filesystems/caching/backend-api.txt describes the API that a cache backend must implement to provide caching services through FS-Cache.
Documentation/filesystems/caching/object.txt describes the object management state machine used.
Documentation/filesystems/caching/operations.txt describes the operation scheduling facility provided and used by FS-Cache that can also be used by cache backend modules.
The patches provide the following components of the FS-Cache facility:
(07) The netfs API header file and documentation. A netfs can actually be built and run against just this patch. It won't actually do anything without the later patches, though, but it will compile.
(08) The cache backend API header file and documentation.
(09) The main selector configuration option, the main module load/unload hooks and the debugging code declarations. With this patch applied, it is possible to enable caching in a client netfs, though it won't actually do anything.
(10) The /proc files for statistics presentation, plus the internal interfaces for driving it.
(11) The top level index definition.
(12) Cache reference tag handling.
(13) Cache (un)registration and error handling.
(14) Cookie (de)allocator and initialisation.
(15) Netfs (un)registration handling. This is partly usable. Without a later patch, however, a cookie will be leaked from unregistration.
(16) Bit waiting utility functions.
(17) The object management state machine implementation and documentation.
(18) Implementation of the cookie management part of the netfs API. With this, it's possible for netfs's to actually be granted cookies and to release them without error.
(19) Cache I/O operation scheduler and documentation.
(20) Implementation of the data I/O part of the netfs API.
(*) 21-cachefiles-ext3-f_mapping.diff
(*) 22-cachefiles-write.diff
(*) 23-cachefiles-monitor.diff
(*) 24-cachefiles-export.diff
(*) 25-cachefiles.diff
Patches to provide a local cache in a directory of an already mounted filesystem.
The latter patch adds a document in text file format that describes the CacheFiles cache backend and gives instructions on how it is set up and used. This will be Documentation/filesystems/caching/cachefiles.txt when the patch is applied.
(*) 26-afs-fscache.diff
Patches to provide AFS with local caching.
(*) 27-nfs-comment.diff
(*) 28-nfs-fscache-option.diff
(*) 29-nfs-fscache-kconfig.diff
(*) 30-nfs-fscache-top-index.diff
(*) 31-nfs-fscache-server-obj.diff
(*) 32-nfs-fscache-super-obj.diff
(*) 33-nfs-fscache-inode-obj.diff
(*) 34-nfs-fscache-use-inode.diff
(*) 35-nfs-fscache-invalidate-pages.diff
(*) 36-nfs-fscache-iostats.diff
(*) 37-nfs-fscache-page-management.diff
(*) 38-nfs-fscache-read-context.diff
(*) 39-nfs-fscache-read-fallback.diff
(*) 40-nfs-fscache-read-from-cache.diff
(*) 41-nfs-fscache-store-to-cache.diff
(*) 42-nfs-fscache-display.diff
(*) 43-nfs-fscache-mount.diff
Patches to provide NFS with local caching.
I've renamed the files in fs/fscache/ from fsc-XXX to XXX, and similarly the files called cf-XXX to XXX in fs/cachefiles/.
I've also fixed some minor conflicts with NFS changes that have gone in to Linus's tree.
I've been testing these patches by throwing batches of eight parallel "tar cf" commands across three different 350MB NFS-based kernel trees (3 tars on first tree, 3 on second, 2 on third), sometimes with one or more of the trees preloaded into the cache. The complete working data set does not fit into the RAM of my test machine, so even three tars that can be entirely satisfied from the cache may have to reread everything from disk.
I've also been running tars against AFS mounted kernel trees.
--
A tarball of the patches is available at:
http://people.redhat.com/~dhowells/fscache/patches/nfs+fscache-46.tar.bz2
This builds on top of Linus's current kernel.
The code can also be obtained by GIT from:
git://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-2.6-fscache.git
http://www.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-2.6-fscache.git
tagged as 'fscache-46'.
To use this version of CacheFiles, the cachefilesd-0.9 is also required. It is available as an SRPM:
http://people.redhat.com/~dhowells/fscache/cachefilesd-0.9-1.fc7.src.rpm
Or as individual bits:
http://people.redhat.com/~dhowells/fscache/cachefilesd-0.9.tar.bz2
http://people.redhat.com/~dhowells/fscache/cachefilesd.fc
http://people.redhat.com/~dhowells/fscache/cachefilesd.if
http://people.redhat.com/~dhowells/fscache/cachefilesd.te
http://people.redhat.com/~dhowells/fscache/cachefilesd.spec
The .fc, .if and .te files are for manipulating SELinux.
David
David Howells
maintainerPATCH 1/43 Create a dynamically sized pool of threads for doing very slow work items [ver #46]
Create a dynamically sized pool of threads for doing very slow work items, such as invoking mkdir() or rmdir() - things that may take a long time and may sleep, holding mutexes/semaphores and hogging a thread, and are thus unsuitable for workqueues.
The number of threads is always at least a settable minimum, but more are started when there's more work to do, up to a limit. Because of the nature of the load, it's not suitable for a 1-thread-per-CPU type pool. A system with one CPU may well want several threads.
This is used by FS-Cache to do slow caching operations in the background, such as looking up, creating or deleting cache objects.
---
include/linux/slow-work.h | 88 ++++++++++ init/Kconfig | 12 + kernel/Makefile | 1 kernel/slow-work.c | 388 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 489 insertions(+), 0 deletions(-) create mode 100644 include/linux/slow-work.h create mode 100644 kernel/slow-work.c
include/linux/slow-work.h new file +88 -0
@@ -0,0 +1,88 @@ +/* Worker thread pool for slow items, such as filesystem lookups or mkdirs +* +* Copyright (C) 2008 Red Hat, Inc. All Rights Reserved. +* Written by David Howells ([email protected]) +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public Licence +* as published by the Free Software Foundation; either version +* 2 of the Licence, or (at your option) any later version. +*/ + +#ifndef _LINUX_SLOW_WORK_H +#define _LINUX_SLOW_WORK_H + +#ifdef CONFIG_SLOW_WORK + +struct slow_work ; + +/* +* The operations used to support slow work items +*/ +struct slow_work_ops { +/* get a ref on a work item +* - return 0 if successful, -ve if not +*/ +int (*get_ref)(struct slow_work *work); + +/* discard a ref to a work item */ +void (*put_ref)(struct slow_work *work); + +/* execute a work item */ +void (*execute)(struct slow_work *work); +}; + +/* +* A slow work item +* - A reference is held on the parent object by the thread pool when it is +* queued +*/ +struct slow_work { +unsigned long flags; +#define SLOW_WORK_PENDING 0/* item pending (further) execution */ +#define SLOW_WORK_EXECUTING 1/* item currently executing */ +#define SLOW_WORK_ENQ_DEFERRED 2/* item enqueue deferred */ +#define SLOW_WORK_VERY_SLOW 3/* item is very slow */ +const struct slow_work_ops *ops;/* operations table for this item */ +struct list_head link;/* link in queue */ +}; + +/** +* slow_work_init - Initialise a slow work item +* @work: The work item to initialise +* @ops: The operations to use to handle the slow work item +* +* Initialise a slow work item. +*/ +static inline void slow_work_init (struct slow_work *work, +const struct slow_work_ops *ops) +{ + work->flags =0 ; + work->ops = ops; +INIT_LIST_HEAD (&work->link); +} + +/** +* slow_work_init - Initialise a very slow work item +* @work: The work item to initialise +* @ops: The operations to use to handle the slow work item +* +* Initialise a very slow work item. This item will be restricted such that +* only a certain number of the pool threads will be able to execute items of +* this type. +*/ +static inline void vslow_work_init (struct slow_work *work, +const struct slow_work_ops *ops) +{ + work->flags =1 <<SLOW_WORK_VERY_SLOW ; + work->ops = ops; +INIT_LIST_HEAD (&work->link); +} + +extern int slow_work_enqueue (struct slow_work *work); +extern int slow_work_register_user (void ); +extern void slow_work_unregister_user (void ); + + +#endif /* CONFIG_SLOW_WORK */ +#endif /* _LINUX_SLOW_WORK_H */
init/Kconfig +12 -0
@@ -1012,6 +1012,18 @@ config MARKERS source "arch/Kconfig" +config SLOW_WORK + default n + bool "Enable slow work thread pool" + help + The slow work thread pool provides a number of dynamically allocated + threads that can be used by the kernel to perform operations that + take a relatively long time. + + An example of this would be CacheFiles doing a path lookup followed + by a series of mkdirs and a create call, all of which have to touch + disk. + endmenu # General setup config HAVE_GENERIC_DMA_COHERENT
kernel/Makefile +1 -0
@@ -93,6 +93,7 @@ obj-$(CONFIG_HAVE_GENERIC_DMA_COHERENT) += dma-coherent.o obj-$(CONFIG_FUNCTION_TRACER) += trace/ obj-$(CONFIG_TRACING) += trace/ obj-$(CONFIG_SMP) += sched_cpupri.o +obj-$(CONFIG_SLOW_WORK) += slow-work.o ifneq ($(CONFIG_SCHED_OMIT_FRAME_POINTER),y) # According to Alan Modra <[email protected]>, the -fno-omit-frame-pointer is
kernel/slow-work.c new file +388 -0
388 lines not on this page · raw message
David Howells
maintainerPATCH 2/43 Make slow-work thread pool actually dynamic [ver #46]
In reply to David HowellsMake the slow-work thread pool actually dynamic in the number of threads it contains. With this patch, it will both create additional threads when it has extra work to do, and cull excess threads that aren't doing anything.
---
kernel/slow-work.c | 138 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 137 insertions(+), 1 deletions(-)
kernel/slow-work.c +137 -1
@@ -16,6 +16,14 @@#include <linux/wait.h> #include <asm/system.h> +#define SLOW_WORK_CULL_TIMEOUT (5 * HZ)/* cull threads 5s after running out of +* things to do */ +#define SLOW_WORK_OOM_TIMEOUT (5 * HZ)/* can't start new threads for 5s after +* OOM */ + +static void slow_work_cull_timeout (unsigned long ); +static void slow_work_oom_timeout (unsigned long ); +/* * The pool of threads has at least min threads in it as long as someone is * using the facility, and may have as many as max.
@@ -29,6 +37,12 @@ static unsigned vslow_work_proportion = 50; /* % of threads that may processstatic atomic_t slow_work_thread_count;static atomic_t vslow_work_executing_count; +static bool slow_work_may_not_start_new_thread; +static bool slow_work_cull;/* cull a thread due to lack of activity */ +static DEFINE_TIMER(slow_work_cull_timer, slow_work_cull_timeout, 0, 0); +static DEFINE_TIMER(slow_work_oom_timer, slow_work_oom_timeout, 0, 0); +static struct slow_work slow_work_new_thread;/* new thread starter */ +/* * The queues of work items and the lock governing access to them. These are * shared between all the CPUs. It doesn't make sense to have per-CPU queues
@@ -89,6 +103,14 @@ static bool slow_work_execute(void) vsmax =slow_work_calc_vsmax (); +/* see if we can schedule a new thread to be started if we're not +* keeping up with the work */ +if (!waitqueue_active (&slow_work_thread_wq) && + (!list_empty (&slow_work_queue) || !list_empty (&vslow_work_queue)) && +atomic_read (&slow_work_thread_count) < slow_work_max_threads && + !slow_work_may_not_start_new_thread) +slow_work_enqueue (&slow_work_new_thread); +/* find something to execute */ spin_lock_irq (&slow_work_queue_lock); if (!list_empty(&vslow_work_queue) &&
@@ -243,6 +265,33 @@ cant_get_ref:EXPORT_SYMBOL (slow_work_enqueue);/* +* Worker thread culling algorithm +*/ +static bool slow_work_cull_thread (void ) +{ +unsigned long flags; +bool do_cull = false; + +spin_lock_irqsave (&slow_work_queue_lock, flags); + +if (slow_work_cull) { + slow_work_cull = false; + +if (list_empty (&slow_work_queue) && +list_empty (&vslow_work_queue) && +atomic_read (&slow_work_thread_count) > + slow_work_min_threads) { +mod_timer (&slow_work_cull_timer, + jiffies +SLOW_WORK_CULL_TIMEOUT ); + do_cull = true; + } + } + +spin_unlock_irqrestore (&slow_work_queue_lock, flags); +return do_cull; +} + +/* * Determine if there is slow work available for dispatch */ static inline bool slow_work_available (int vsmax)
@@ -273,7 +322,8 @@ static int slow_work_thread(void *_data) TASK_INTERRUPTIBLE);if (!freezing (current) && !slow_work_threads_should_exit && - !slow_work_available (vsmax)) + !slow_work_available (vsmax) && + !slow_work_cull)schedule ();finish_wait (&slow_work_thread_wq, &wait);
@@ -285,11 +335,20 @@ static int slow_work_thread(void *_data)if (slow_work_available (vsmax) &&slow_work_execute ()) {cond_resched (); +if (list_empty (&slow_work_queue) && +list_empty (&vslow_work_queue) && +atomic_read (&slow_work_thread_count) > + slow_work_min_threads) +mod_timer (&slow_work_cull_timer, + jiffies +SLOW_WORK_CULL_TIMEOUT );continue ; }if (slow_work_threads_should_exit)break ; + +if (slow_work_cull &&slow_work_cull_thread ()) +break ; }if (atomic_dec_and_test (&slow_work_thread_count))
@@ -297,6 +356,77 @@ static int slow_work_thread(void *_data)return 0 ; } +/* +* Handle thread cull timer expiration +*/ +static void slow_work_cull_timeout (unsigned long data) +{ + slow_work_cull = true; +wake_up (&slow_work_thread_wq); +} + +/* +* Get a reference on slow work thread starter +*/ +static int slow_work_new_thread_get_ref (struct slow_work *work) +{ +return 0 ; +} + +/* +* Drop a reference on slow work thread starter +*/ +static void slow_work_new_thread_put_ref (struct slow_work *work) +{ +} + +/* +* Start a new slow work thread +*/ +static void slow_work_new_thread_execute (struct slow_work *work) +{ +struct task_struct *p; + +if (slow_work_threads_should_exit) +return ; + +if (atomic_read (&slow_work_thread_count) >= slow_work_max_threads) +return ; + +if (!mutex_trylock (&slow_work_user_lock)) +return ; + + slow_work_may_not_start_new_thread = true; +atomic_inc (&slow_work_thread_count); + p =kthread_run (slow_work_thread,NULL ,"kslowd" ); +if (IS_ERR (p)) { +printk (KERN_DEBUG "Slow work thread pool: OOM\n" ); +if (atomic_dec_and_test (&slow_work_thread_count)) +BUG ();/* we're running on a slow work thread... */ +mod_timer (&slow_work_oom_timer, + jiffies +SLOW_WORK_OOM_TIMEOUT ); + }else { +/* ratelimit the starting of new threads */ +mod_timer (&slow_work_oom_timer, jiffies +1 ); + } + +mutex_unlock (&slow_work_user_lock); +} + +static const struct slow_work_ops slow_work_new_thread_ops = { + .get_ref = slow_work_new_thread_get_ref, + .put_ref = slow_work_new_thread_put_ref, + .execute = slow_work_new_thread_execute, +}; + +/* +* post-OOM new thread start suppression expiration +*/ +static void slow_work_oom_timeout (unsigned long data) +{ + slow_work_may_not_start_new_thread = false; +} +/** * slow_work_register_user - Register a user of the facility *
@@ -316,6 +446,10 @@ int slow_work_register_user(void)init_completion (&slow_work_last_thread_exited); slow_work_threads_should_exit = false; +slow_work_init (&slow_work_new_thread, + &slow_work_new_thread_ops); + slow_work_may_not_start_new_thread = false; + slow_work_cull = false;/* start the minimum number of threads */ for (loop =0 ; loop < slow_work_min_threads; loop++) {
@@ -369,6 +503,8 @@ void slow_work_unregister_user(void) " Shut down complete\n"); } +del_timer_sync (&slow_work_cull_timer); +mutex_unlock (&slow_work_user_lock); }EXPORT_SYMBOL (slow_work_unregister_user);
David Howells
maintainerPATCH 3/43 Make the slow work pool configurable [ver #46]
In reply to David HowellsMake the slow work pool configurable through /proc/sys/kernel/slow-work.
(*) /proc/sys/kernel/slow-work/min-threads
The minimum number of threads that should be in the pool as long as it is in use. This may be anywhere between 2 and max-threads.
(*) /proc/sys/kernel/slow-work/max-threads
The maximum number of threads that should in the pool. This may be anywhere between min-threads and 255 or NR_CPUS * 2, whichever is greater.
(*) /proc/sys/kernel/slow-work/vslow-percentage
The percentage of active threads in the pool that may be used to execute very slow work items. This may be between 1 and 99. The resultant number is bounded to between 1 and one fewer than the number of active threads. This ensures there is always at least one thread that can process very slow work items, and always at least one thread that won't.
---
include/linux/slow-work.h | 5 ++ kernel/slow-work.c | 118 ++++++++++++++++++++++++++++++++++++++++++++- kernel/sysctl.c | 9 +++ 3 files changed, 130 insertions(+), 2 deletions(-)
include/linux/slow-work.h +5 -0
@@ -14,6 +14,8 @@#ifdef CONFIG_SLOW_WORK +#include <linux/sysctl.h> +struct slow_work ;/*
@@ -83,6 +85,9 @@ extern int slow_work_enqueue(struct slow_work *work);extern int slow_work_register_user (void );extern void slow_work_unregister_user (void ); +#ifdef CONFIG_SYSCTL +extern ctl_table slow_work_sysctls[]; +#endif #endif /* CONFIG_SLOW_WORK */ #endif /* _LINUX_SLOW_WORK_H */
kernel/slow-work.c +116 -2
149 lines not on this page · raw message
kernel/sysctl.c +9 -0
@@ -48,6 +48,7 @@#include <linux/acpi.h> #include <linux/reboot.h> #include <linux/ftrace.h> +#include <linux/slow-work.h> #include <asm/uaccess.h> #include <asm/processor.h>
@@ -900,6 +901,14 @@ static struct ctl_table kern_table[] = { .proc_handler = &scan_unevictable_handler, },#endif +#ifdef CONFIG_SLOW_WORK + { + .ctl_name = CTL_UNNUMBERED, + .procname = "slow-work", + .mode = 0555, + .child = slow_work_sysctls, + }, +#endif /* * NOTE: do not add new entries to this table unless you have read * Documentation/sysctl/ctl_unnumbered.txt
David Howells
maintainerPATCH 4/43 Document the slow work thread pool [ver #46]
In reply to David HowellsDocument the slow work thread pool.
---
Documentation/slow-work.txt | 174 +++++++++++++++++++++++++++++++++++++++++++ include/linux/slow-work.h | 2 kernel/slow-work.c | 2 3 files changed, 178 insertions(+), 0 deletions(-) create mode 100644 Documentation/slow-work.txt
Documentation/slow-work.txt new file +174 -0
@@ -0,0 +1,174 @@ + ==================================== + SLOW WORK ITEM EXECUTION THREAD POOL + ==================================== + +By: David Howells <[email protected]> + +The slow work item execution thread pool is a pool of threads for performing +things that take a relatively long time, such as making mkdir calls. +Typically, when processing something, these items will spend a lot of time +blocking a thread on I/O, thus making that thread unavailable for doing other +work. + +The standard workqueue model is unsuitable for this class of work item as that +limits the owner to a single thread or a single thread per CPU. For some +tasks, however, more threads - or fewer - are required. + +There is just one pool per system. It contains no threads unless something +wants to use it - and that something must register its interest first. When +the pool is active, the number of threads it contains is dynamic, varying +between a maximum and minimum setting, depending on the load. + + +==================== +CLASSES OF WORK ITEM +==================== + +This pool support two classes of work items: + + (*) Slow work items. + + (*) Very slow work items. + +The former are expected to finish much quicker than the latter. + +An operation of the very slow class may do a batch combination of several +lookups, mkdirs, and a create for instance. + +An operation of the ordinarily slow class may, for example, write stuff or +expand files, provided the time taken to do so isn't too long. + +Operations of both types may sleep during execution, thus tying up the thread +loaned to it. + + +THREAD-TO-CLASS ALLOCATION +-------------------------- + +Not all the threads in the pool are available to work on very slow work items. +The number will be between one and one fewer than the number of active threads. +This is configurable (see the "Pool Configuration" section). + +All the threads are available to work on ordinarily slow work items, but a +percentage of the threads will prefer to work on very slow work items. + +The configuration ensures that at least one thread will be available to work on +very slow work items, and at least one thread will be available that won't work +on very slow work items at all. + + +===================== +USING SLOW WORK ITEMS +===================== + +Firstly, a module or subsystem wanting to make use of slow work items must +register its interest: + + int ret = slow_work_register_user(); + +This will return 0 if successful, or a -ve error upon failure. + + +Slow work items may then be set up by: + + (1) Declaring a slow_work struct type variable: + + #include <linux/slow-work.h> + + struct slow_work myitem; + + (2) Declaring the operations to be used for this item: + + struct slow_work_ops myitem_ops = { + .get_ref = myitem_get_ref, + .put_ref = myitem_put_ref, + .execute = myitem_execute, + }; + + [*] For a description of the ops, see section "Item Operations". + + (3) Initialising the item: + + slow_work_init(&myitem, &myitem_ops); + + or: + + vslow_work_init(&myitem, &myitem_ops); + + depending on its class. + +A suitably set up work item can then be enqueued for processing: + + int ret = slow_work_enqueue(&myitem); + +This will return a -ve error if the thread pool is unable to gain a reference +on the item, 0 otherwise. + + +The items are reference counted, so there ought to be no need for a flush +operation. When all a module's slow work items have been processed, and the +module has no further interest in the facility, it should unregister its +interest: + + slow_work_unregister_user(); + + +=============== +ITEM OPERATIONS +=============== + +Each work item requires a table of operations of type struct slow_work_ops. +All members are required: + + (*) Get a reference on an item: + + int (*get_ref)(struct slow_work *work); + + This allows the thread pool to attempt to pin an item by getting a + reference on it. This function should return 0 if the reference was + granted, or a -ve error otherwise. If an error is returned, + slow_work_enqueue() will fail. + + The reference is held whilst the item is queued and whilst it is being + executed. The item may then be requeued with the same reference held, or + the reference will be released. + + (*) Release a reference on an item: + + void (*put_ref)(struct slow_work *work); + + This allows the thread pool to unpin an item by releasing the reference on + it. The thread pool will not touch the item again once this has been + called. + + (*) Execute an item: + + void (*execute)(struct slow_work *work); + + This should perform the work required of the item. It may sleep, it may + perform disk I/O and it may wait for locks. + + +================== +POOL CONFIGURATION +================== + +The slow-work thread pool has a number of configurables: + + (*) /proc/sys/kernel/slow-work/min-threads + + The minimum number of threads that should be in the pool whilst it is in + use. This may be anywhere between 2 and max-threads. + + (*) /proc/sys/kernel/slow-work/max-threads + + The maximum number of threads that should in the pool. This may be + anywhere between min-threads and 255 or NR_CPUS * 2, whichever is greater. + + (*) /proc/sys/kernel/slow-work/vslow-percentage + + The percentage of active threads in the pool that may be used to execute + very slow work items. This may be between 1 and 99. The resultant number + is bounded to between 1 and one fewer than the number of active threads. + This ensures there is always at least one thread that can process very + slow work items, and always at least one thread that won't.
include/linux/slow-work.h +2 -0
@@ -7,6 +7,8 @@* modify it under the terms of the GNU General Public Licence * as published by the Free Software Foundation; either version * 2 of the Licence, or (at your option) any later version. +* +* See Documentation/slow-work.txt */ #ifndef _LINUX_SLOW_WORK_H
kernel/slow-work.c +2 -0
@@ -7,6 +7,8 @@* modify it under the terms of the GNU General Public Licence * as published by the Free Software Foundation; either version * 2 of the Licence, or (at your option) any later version. +* +* See Documentation/slow-work.txt */ #include <linux/module.h>
David Howells
maintainerPATCH 5/43 FS-Cache: Release page->private after failed readahead [ver #46]
In reply to David HowellsThe attached patch causes read_cache_pages() to release page-private data on a page for which add_to_page_cache() fails or the filler function fails. This permits pages with caching references associated with them to be cleaned up.
The invalidatepage() address space op is called (indirectly) to do the honours.
---
include/linux/page-flags.h | 2 +- mm/readahead.c | 39 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 3 deletions(-)
include/linux/page-flags.h +1 -1
@@ -182,7 +182,7 @@ static inline int TestClearPage##uname(struct page *page) { return 0; }struct page ;/* forward declaration */ -TESTPAGEFLAG(Locked, locked) +TESTPAGEFLAG(Locked, locked) TESTSETFLAG(Locked, locked) PAGEFLAG(Error, error) PAGEFLAG(Referenced, referenced) TESTCLEARFLAG(Referenced, referenced) PAGEFLAG(Dirty, dirty) TESTSCFLAG(Dirty, dirty) __CLEARPAGEFLAG(Dirty, dirty)
mm/readahead.c +37 -2
@@ -31,6 +31,41 @@ EXPORT_SYMBOL_GPL(file_ra_state_init);#define list_to_page (head) (list_entry((head)->prev, struct page, lru)) +/* +* see if a page needs releasing upon read_cache_pages() failure +* - the caller of read_cache_pages() may have set PG_private before calling, +* such as the NFS fs marking pages that are cached locally on disk, thus we +* need to give the fs a chance to clean up in the event of an error +*/ +static void read_cache_pages_invalidate_page (struct address_space *mapping, +struct page *page) +{ +if (PagePrivate (page)) { +if (!trylock_page (page)) +BUG (); + page->mapping = mapping; +do_invalidatepage (page,0 ); + page->mapping =NULL ; +unlock_page (page); + } +page_cache_release (page); +} + +/* +* release a list of pages, invalidating them first if need be +*/ +static void read_cache_pages_invalidate_pages (struct address_space *mapping, +struct list_head *pages) +{ +struct page *victim; + +while (!list_empty (pages)) { + victim =list_to_page (pages); +list_del (&victim->lru); +read_cache_pages_invalidate_page (mapping, victim); + } +} +/** * read_cache_pages - populate an address space with some pages & start reads against them * @mapping: the address_space
@@ -52,14 +87,14 @@ int read_cache_pages(struct address_space *mapping, struct list_head *pages,list_del (&page->lru);if (add_to_page_cache_lru (page, mapping, page->index,GFP_KERNEL )) { -page_cache_release (page); +read_cache_pages_invalidate_page (mapping, page);continue ; }page_cache_release (page); ret =filler (data, page);if (unlikely (ret)) { -put_pages_list (pages); +read_cache_pages_invalidate_pages (mapping, pages);break ; }task_io_account_read (PAGE_CACHE_SIZE );
Re: [PATCH 05/43] FS-Cache: Release page->private after failed readahead [ver #46]
Quoted 2 lines · On Thursday 02 April 2009 10:03:47 David Howells wrote:
The attached patch causes
read_cache_pages()to release page-private data on a page for whichadd_to_page_cache()fails or the filler function
fails.
Quoted 5 lines
This permits pages with caching references associated with them to be cleaned up.
The
invalidatepage()address space op is called (indirectly) to do the honours.
This does not release the page for which the filler function fails. It releases for all pages that do not get put on the LRU.
I guess that's just a changelog bug.
I don't have a problem with this if it is significantly easier to do here than the caller -- it should be a slowpath.
Quoted 36 lines
Signed-off-by David Howells <[email protected]>Acked-by Steve Dickson <[email protected]>Acked-by Trond Myklebust <[email protected]>---
include/linux/page-flags.h | 2 +- mm/readahead.c | 39 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 3 deletions(-)include/linux/page-flags.h +1
-1@@ -182,7 +182,7 @@ static inline int TestClearPage##uname(struct page *page) { return 0; } struct page; /* forward declaration */ -TESTPAGEFLAG(Locked, locked) +TESTPAGEFLAG(Locked, locked) TESTSETFLAG(Locked, locked) PAGEFLAG(Error, error) PAGEFLAG(Referenced, referenced) TESTCLEARFLAG(Referenced, referenced)
PAGEFLAG(Dirty, dirty)TESTSCFLAG(Dirty, dirty)__CLEARPAGEFLAG(Dirty,
dirty) diff --gita/mm/readahead.cb/mm/readahead.c
index 9ce303d..6be9275 100644mm/readahead.c +3
-0@@ -31,6 +31,41 @@ EXPORT_SYMBOL_GPL(file_ra_state_init);#define list_to_page (head) (list_entry((head)->prev, struct page, lru)) +/* +* see if a page needs releasing upon read_cache_pages() failure +* - the caller of read_cache_pages() may have set PG_private before
Quoted 5 lines
calling, + * such as the NFS fs marking pages that are cached locally on
disk, thus we + * need to give the fs a chance to clean up in the event
of an error + */
+static void read_cache_pages_invalidate_page(structaddress_space
*mapping, + struct page
*page)
Quoted 16 lines
mm/readahead.c +16
-0+{ +if (PagePrivate (page)) { +if (!trylock_page (page)) +BUG (); + page->mapping = mapping; +do_invalidatepage (page,0 ); + page->mapping =NULL ; +unlock_page (page); + } +page_cache_release (page); +} + +/* +* release a list of pages, invalidating them first if need be +*/ +static void read_cache_pages_invalidate_pages(struct address_space
Quoted 1 line
*mapping, + struct
list_head *pages)
Quoted 14 lines
mm/readahead.c +10
-0+{ +struct page *victim; + +while (!list_empty (pages)) { + victim =list_to_page (pages); +list_del (&victim->lru); +read_cache_pages_invalidate_page (mapping, victim); + } +} +/** * read_cache_pages - populate an address space with some pages & start reads against them * @mapping: the
address_space
mm/readahead.c int read_cache_pages(struct address_space *mapping, · line 89
Quoted 3 lines
mm/readahead.c +0
-0@@ -52,14 +87,14 @@ int read_cache_pages(struct address_space *mapping, struct list_head *pages, list_del(&page->lru);if (add_to_page_cache_lru (page, mapping, page->index,GFP_KERNEL ))
{
mm/readahead.c int read_cache_pages(struct address_space *mapping, · line 90
Quoted 2 lines
mm/readahead.c +1
-1-page_cache_release (page); + read_cache_pages_invalidate_page(mapping,
page);
mm/readahead.c int read_cache_pages(struct address_space *mapping, struct list_head *pages, · line 96
Quoted 6 lines
mm/readahead.c +0
-0continue ; }page_cache_release (page); ret =filler (data, page);if (unlikely (ret)) {
_______________________________________________
NFSv4 mailing list
[email protected]
http://linux-nfs.org/cgi-bin/mailman/listinfo/nfsv4
David Howells
maintainerRe: [PATCH 05/43] FS-Cache: Release page->private after failed readahead [ver #46]
Quoted 1 line · Nick Piggin
This does not release the page for which the filler function fails.
That's a good point. That page is attached to the pagecache and the LRU by that point. I suppose the page could be removed (but someone else may be trying to reference it by this point), or I could amend the patch text to:
The attached patch causes read_cache_pages() to release page-private data on a page for which add_to_page_cache() fails. If the filler function fails, then the problematic page is left attached to the pagecache (with appropriate flags set, one presumes) and the remaining to-be-attached pages are invalidated and discarded. This permits pages with caching references associated with them to be cleaned up.
The invalidatepage() address space op is called (indirectly) to do the honours.
How about that?
Quoted 2 lines
I don't have a problem with this if it is significantly easier to do here than the caller -- it should be a slowpath.
It could be done in the caller - every caller of read_cache_pages() that might have the pages pre-annotated. But the changes are all in the error handling path. If read_cache_pages() doesn't see an error, these changes are not activated.
David
Re: [PATCH 05/43] FS-Cache: Release page->private after failed readahead [ver #46]
In reply to David HowellsQuoted 10 lines · David Howells
The attached patch causes
read_cache_pages()to release page-private data on a page for whichadd_to_page_cache()fails or the filler function fails. This permits pages with caching references associated with them to be cleaned up.The
invalidatepage()address space op is called (indirectly) to do the honours.Signed-off-by David Howells <[email protected]>Acked-by Steve Dickson <[email protected]>Acked-by Trond Myklebust <[email protected]>
David Howells
maintainerPATCH 6/43 FS-Cache: Recruit a couple of page flags for cache management [ver #46]
In reply to David HowellsRecruit a couple of page flags to aid in cache management. The following extra flags are defined:
(1) PG_fscache (PG_private_2)
The marked page is backed by a local cache and is pinning resources in the cache driver.
(2) PG_fscache_write (PG_owner_priv_2)
The marked page is being written to the local cache. The page may not be modified whilst this is in progress.
If PG_fscache is set, then things that checked for PG_private will now also check for that. This includes things like truncation and page invalidation. The function page_has_private() had been added to make the checks for both PG_private and PG_private_2 at the same time.
---
fs/splice.c | 3 ++- include/linux/page-flags.h | 41 ++++++++++++++++++++++++++++++++++++----- include/linux/pagemap.h | 14 ++++++++++++++ mm/filemap.c | 18 ++++++++++++++++++ mm/migrate.c | 10 +++++----- mm/readahead.c | 9 +++++---- mm/swap.c | 4 ++-- mm/truncate.c | 10 +++++----- mm/vmscan.c | 6 +++--- 9 files changed, 90 insertions(+), 25 deletions(-)
fs/splice.c +2 -1
@@ -59,7 +59,8 @@ static int page_cache_pipe_buf_steal(struct pipe_inode_info *pipe,*/ wait_on_page_writeback (page); -if (PagePrivate (page) && !try_to_release_page (page,GFP_KERNEL )) +if (page_has_private (page) && + !try_to_release_page (page,GFP_KERNEL )) goto out_unlock;/*
include/linux/page-flags.h +36 -5
78 lines not on this page · raw message
include/linux/pagemap.h +14 -0
@@ -379,6 +379,20 @@ static inline void wait_on_page_writeback(struct page *page)extern void end_page_writeback (struct page *page); +/** +* wait_on_page_owner_priv_2 - Wait for PG_owner_priv_2 to become clear +* @page: The page to monitor +* +* Wait for a PG_owner_priv_2 to become clear on the specified page. +*/ +static inline void wait_on_page_owner_priv_2 (struct page *page) +{ +if (PageOwnerPriv2 (page)) +wait_on_page_bit (page, PG_owner_priv_2); +} + +extern void end_page_owner_priv_2 (struct page *page); +/* * Fault a userspace page into pagetables. Return non-zero on a fault. *
mm/filemap.c +18 -0
@@ -603,6 +603,21 @@ void end_page_writeback(struct page *page)EXPORT_SYMBOL (end_page_writeback);/** +* end_page_owner_priv_2 - Clear PG_owner_priv_2 and wake up any waiters +* @page: the page +* +* Clear PG_owner_priv_2 and wake up any processes waiting for that event. +*/ +void end_page_owner_priv_2 (struct page *page) +{ +if (!TestClearPageOwnerPriv2 (page)) +BUG (); +smp_mb__after_clear_bit (); +wake_up_page (page, PG_owner_priv_2); +} +EXPORT_SYMBOL (end_page_owner_priv_2); + +/** * __lock_page - get a lock on the page, assuming we need to sleep to get it * @page: the page to lock *
@@ -2463,6 +2478,9 @@ EXPORT_SYMBOL(generic_file_aio_write);* (presumably at page->private). If the release was successful, return `1'. * Otherwise return zero. * +* This may also be called if PG_fscache is set on a page, indicating that the +* page is known to the local caching routines. +* * The @gfp_mask argument specifies whether I/O may be performed to release * this page (__GFP_IO), and whether the call may block (__GFP_WAIT & __GFP_FS). *
mm/migrate.c +5 -5
@@ -250,7 +250,7 @@ out:* The number of remaining references must be: * 1 for anonymous pages without a mapping * 2 for pages with a mapping -* 3 for pages with a mapping and PagePrivate set. +* 3 for pages with a mapping and PagePrivate/PagePrivate2 set. */ static int migrate_page_move_mapping (struct address_space *mapping,struct page *newpage,struct page *page)
@@ -270,7 +270,7 @@ static int migrate_page_move_mapping(struct address_space *mapping, pslot =radix_tree_lookup_slot (&mapping->page_tree,page_index (page)); - expected_count =2 + !!PagePrivate (page); + expected_count =2 + !!page_has_private (page);if (page_count (page) != expected_count || (struct page *)radix_tree_deref_slot (pslot) != page) {spin_unlock_irq (&mapping->tree_lock);
@@ -386,7 +386,7 @@ EXPORT_SYMBOL(fail_migrate_page);/* * Common logic to directly migrate a single page suitable for -* pages that do not use PagePrivate. +* pages that do not use PagePrivate/PagePrivate2. * * Pages are locked upon entry and exit. */
@@ -522,7 +522,7 @@ static int fallback_migrate_page(struct address_space *mapping,* Buffers may be managed in a filesystem specific way. * We must have no buffers or drop them. */ -if (PagePrivate (page) && +if (page_has_private (page) && !try_to_release_page (page,GFP_KERNEL ))return -EAGAIN ;
@@ -655,7 +655,7 @@ static int unmap_and_move(new_page_t get_new_page, unsigned long private,* free the metadata, so the page can be freed. */ if (!page->mapping) { -if (!PageAnon (page) &&PagePrivate (page)) { +if (!PageAnon (page) &&page_has_private (page)) {/* * Go direct to try_to_free_buffers() here because * a) that's what try_to_release_page() would do anyway
mm/readahead.c +5 -4
@@ -33,14 +33,15 @@ EXPORT_SYMBOL_GPL(file_ra_state_init);/* * see if a page needs releasing upon read_cache_pages() failure -* - the caller of read_cache_pages() may have set PG_private before calling, -* such as the NFS fs marking pages that are cached locally on disk, thus we -* need to give the fs a chance to clean up in the event of an error +* - the caller of read_cache_pages() may have set PG_private or PG_fscache +* before calling, such as the NFS fs marking pages that are cached locally +* on disk, thus we need to give the fs a chance to clean up in the event of +* an error */ static void read_cache_pages_invalidate_page (struct address_space *mapping,struct page *page) { -if (PagePrivate (page)) { +if (page_has_private (page)) {if (!trylock_page (page))BUG (); page->mapping = mapping;
mm/swap.c +2 -2
@@ -448,8 +448,8 @@ void pagevec_strip(struct pagevec *pvec)for (i =0 ; i <pagevec_count (pvec); i++) {struct page *page = pvec->pages[i]; -if (PagePrivate (page) &&trylock_page (page)) { -if (PagePrivate (page)) +if (page_has_private (page) &&trylock_page (page)) { +if (page_has_private (page))try_to_release_page (page,0 );unlock_page (page); }
mm/truncate.c +5 -5
@@ -50,7 +50,7 @@ void do_invalidatepage(struct page *page, unsigned long offset)static inline void truncate_partial_page (struct page *page,unsigned partial) {zero_user_segment (page, partial,PAGE_CACHE_SIZE ); -if (PagePrivate (page)) +if (page_has_private (page))do_invalidatepage (page, partial); }
@@ -99,7 +99,7 @@ truncate_complete_page(struct address_space *mapping, struct page *page)if (page->mapping != mapping)return ; -if (PagePrivate (page)) +if (page_has_private (page))do_invalidatepage (page,0 );cancel_dirty_page (page,PAGE_CACHE_SIZE );
@@ -126,7 +126,7 @@ invalidate_complete_page(struct address_space *mapping, struct page *page)if (page->mapping != mapping)return 0 ; -if (PagePrivate (page) && !try_to_release_page (page,0 )) +if (page_has_private (page) && !try_to_release_page (page,0 ))return 0 ;clear_page_mlock (page);
@@ -348,7 +348,7 @@ invalidate_complete_page2(struct address_space *mapping, struct page *page)if (page->mapping != mapping)return 0 ; -if (PagePrivate (page) && !try_to_release_page (page,GFP_KERNEL )) +if (page_has_private (page) && !try_to_release_page (page,GFP_KERNEL ))return 0 ;spin_lock_irq (&mapping->tree_lock);
@@ -356,7 +356,7 @@ invalidate_complete_page2(struct address_space *mapping, struct page *page) goto failed;clear_page_mlock (page); -BUG_ON (PagePrivate (page)); +BUG_ON (page_has_private (page));__remove_from_page_cache (page);spin_unlock_irq (&mapping->tree_lock);page_cache_release (page);/* pagecache ref */
mm/vmscan.c +3 -3
@@ -283,7 +283,7 @@ static inline int page_mapping_inuse(struct page *page)static inline int is_page_cache_freeable (struct page *page) { -return page_count (page) - !!PagePrivate (page) ==2 ; +return page_count (page) - !!page_has_private (page) ==2 ; }static int may_write_to_queue (struct backing_dev_info *bdi)
@@ -367,7 +367,7 @@ static pageout_t pageout(struct page *page, struct address_space *mapping,* Some data journaling orphaned pages can have * page->mapping == NULL while being dirty with clean buffers. */ -if (PagePrivate (page)) { +if (page_has_private (page)) {if (try_to_free_buffers (page)) {ClearPageDirty (page);printk ("%s: orphaned page\n" , __func__);
@@ -727,7 +727,7 @@ static unsigned long shrink_page_list(struct list_head *page_list,* process address space (page_count == 1) it can be freed. * Otherwise, leave the page on the LRU so it is swappable. */ -if (PagePrivate (page)) { +if (page_has_private (page)) {if (!try_to_release_page (page, sc->gfp_mask)) goto activate_locked;if (!mapping &&page_count (page) ==1 ) {
Re: [PATCH 06/43] FS-Cache: Recruit a couple of page flags for cache management [ver #46]
Quoted 6 lines · On Thursday 02 April 2009 10:03:52 David Howells wrote:
Recruit a couple of page flags to aid in cache management. The following extra flags are defined:
(1)
PG_fscache(PG_private_2)The marked page is backed by a local cache and is pinning resources
in
Quoted 5 lines
the cache driver.
(2)
PG_fscache_write(PG_owner_priv_2)The marked page is being written to the local cache. The page may
not
Quoted 3 lines
be modified whilst this is in progress.
If
PG_fscacheis set, then things that checked forPG_privatewill now
also
Quoted 3 lines
check for that. This includes things like truncation and page invalidation. The function
page_has_private()had been added to make the checks for bothPG_privateandPG_private_2at the same time.
2 new page flags? Ouch.
1) PG_mappedtodisk is basically PG_owner_priv_2. Please alias that and use it? Then at least we're down to 1 extra flag.
2) Why do you need another PG_private? PG_private for pagecache means that it should call into the filesystem when it needs to handle fs data attached to the page, right? So PG_private_2 doesn't really make sense in that respect. Can't you just keep another flag privately in the fs and distinguish what to do based on that?
Quoted 8 lines
Signed-off-by David Howells <[email protected]>Acked-by Steve Dickson <[email protected]>Acked-by Trond Myklebust <[email protected]>---
fs/splice.c | 3 ++- include/linux/page-flags.h | 41++++++++++++++++++++++++++++++++++++-----
include/linux/pagemap.h|
14
Quoted 8 lines
++++++++++++++
mm/filemap.c | 18 ++++++++++++++++++ mm/migrate.c | 10 +++++----- mm/readahead.c | 9 +++++---- mm/swap.c | 4 ++-- mm/truncate.c | 10 +++++----- mm/vmscan.c | 6 +++--- 9 files changed, 90 insertions(+), 25 deletions(-)
_______________________________________________
NFSv4 mailing list
[email protected]
http://linux-nfs.org/cgi-bin/mailman/listinfo/nfsv4
David Howells
maintainerRe: [PATCH 06/43] FS-Cache: Recruit a couple of page flags for cache management [ver #46]
Quoted 6 lines · Nick Piggin
1)
PG_mappedtodiskis basicallyPG_owner_priv_2. Please alias that and use it? Then at least we're down to 1 extra flag.
2) Why do you need anotherPG_private?PG_privatefor pagecache means that it should call into the filesystem when it needs to handle fs data attached to the page, right? SoPG_private_2doesn't really make sense in that respect.
Won't that either break fs/buffer.c and fs/mpage.c or preclude the use of FS-Cache with block-based filesystems that use the standard buffer wangling routines?
As I've previously stated, I want to be able to make ISO9660 use FS-Cache. That rules out use of PG_mappedtodisk and PG_private for anything FS-Cache related.
We can actually reclaim PG_private, I think. There are patches to do that. At the very least, we can probably reclaim the std buffering code's use of it.
If anything, avoiding the need for PG_fscache_write is probably easier - just more memory intensive and slower. I could build a second radix tree for each inode that kept track of which pages from that inode FS-Cache knows about, and use the status bits in that node to keep track of what pages are being written out to the cache.
We still need a way of triggering the page invalidation callbacks for in-use pages, however. PG_private, as I've said, is not currently a viable option.
David
Re: [PATCH 06/43] FS-Cache: Recruit a couple of page flags for cache management [ver #46]
[sorry for that html crap :(]
Quoted 9 lines · On Friday 03 April 2009 01:36:12 David Howells wrote:
Quoted 6 lines · Nick Piggin
1)
PG_mappedtodiskis basicallyPG_owner_priv_2. Please alias that and use it? Then at least we're down to 1 extra flag.
2) Why do you need anotherPG_private?PG_privatefor pagecache means that it should call into the filesystem when it needs to handle fs data attached to the page, right? SoPG_private_2doesn't really make sense in that respect.
Quoted 3 lines
Won't that either break
fs/buffer.candfs/mpage.cor preclude the use of FS-Cache with block-based filesystems that use the standard buffer wangling routines?
Haven't looked closely at how fscache works. Possibly you can't reuse mappedtodisk....
But PG_private. PG_private from the vm/vfs side means to call into the filesystem. So from that point, the filesystem should handle it. It just doesn't seem to make sense to have 2 flags for this.
I mean, there is only the single aop that can be called, so having 2 VM visible flags doesn't help the VM do anything, and presumably your aop knows how to handle this, so it should be an fs private bit.
Just give me a situation of why it won't work.
Quoted 6 lines
As I've previously stated, I want to be able to make ISO9660 use FS-Cache. That rules out use of
PG_mappedtodiskandPG_privatefor anything FS-Cache related.We can actually reclaim
PG_private, I think. There are patches to do that. At the very least, we can probably reclaim the std buffering code's use of it.
But that's peripheral issue.
Quoted 5 lines
If anything, avoiding the need for
PG_fscache_writeis probably easier - just more memory intensive and slower. I could build a second radix tree for each inode that kept track of which pages from that inode FS-Cache knows about, and use the status bits in that node to keep track of what pages are being written out to the cache.
If it's not much slower, that would be nice.
Quoted 2 lines
We still need a way of triggering the page invalidation callbacks for in-use pages, however.
PG_private, as I've said, is not currently a viable option.
Can you say exactly why not?
David Howells
maintainerRe: [PATCH 06/43] FS-Cache: Recruit a couple of page flags for cache management [ver #46]
Quoted 1 line · Nick Piggin
Haven't looked closely at how fscache works.
It's fairly simple. FS-Cache sets PG_private_2 (PageFsCache) on pages that the netfs tells it about, if it retains an interest in the page. This causes invalidatepage() and suchlike to be invoked on that page when the page is discarded.
The netfs can check for the page being in use by calling PageFsCache() and then uncache the page if it is in use:
#ifdef CONFIG_AFS_FSCACHE
if (PageFsCache(page)) {
struct afs_vnode *vnode = AFS_FS_I(page->mapping->host);
wait_on_page_fscache_write(page);
fscache_uncache_page(vnode->cache, page);
}
#endifwhich clears the bit.
Furthermore, when FS-Cache is asked to store a page to the cache, it immediately marks it with PG_owner_priv_2 (PageFsCacheWrite). This is cleared when FS-Cache no longer needs the data in the page for writing to the cache.
This allows (1) invalidatepage() to wait until the page is written before it is returned to the memory allocator, and (2) releasepage() to indicate that the page is busy if __GFP_WAIT is not given.
Quoted 1 line
Possibly you can't reuse mappedtodisk....
PG_mappedtodisk has a very specific meaning to fs/buffer.c and fs/mpage.c. I can't also easily make it mean that a page is backed by the cache. A page can be cached and not mapped to disk.
Quoted 4 lines
Quoted 2 lines
We still need a way of triggering the page invalidation callbacks for in-use pages, however.
PG_private, as I've said, is not currently a viable option.Can you say exactly why not?
fs/buffer.c owns PG_private in filesystems that use standard buffering. It sets it, clears it and tests it at its own behest without recourse to the filesystem using it.
ISO9660 uses fs/buffer.c.
I want to get ISO9660 to use FS-Cache.
Also NFS uses PG_private for its own nefarious purposes. Making PG_private be the conjunction of both purposes entailed some fairly messy patching.
David
Re: [PATCH 06/43] FS-Cache: Recruit a couple of page flags for cache management [ver #46]
Quoted 20 lines · On Friday 03 April 2009 02:51:02 David Howells wrote:
Quoted 1 line · Nick Piggin
Haven't looked closely at how fscache works.
It's fairly simple. FS-Cache sets
PG_private_2(PageFsCache) on pages that the netfs tells it about, if it retains an interest in the page. This causesinvalidatepage()and suchlike to be invoked on that page when the page is discarded.The netfs can check for the page being in use by calling
PageFsCache()and then uncache the page if it is in use:#ifdef CONFIG_AFS_FSCACHE if (PageFsCache(page)) { struct afs_vnode *vnode = AFS_FS_I(page->mapping->host); wait_on_page_fscache_write(page); fscache_uncache_page(vnode->cache, page); } #endif
Quoted 1 line
which clears the bit.
OK, then you just use PG_private for that, and have the netfs use a PG_owner_private or some such bit to tell that it is an fscache page.
Quoted 7 lines
Furthermore, when FS-Cache is asked to store a page to the cache, it immediately marks it with
PG_owner_priv_2(PageFsCacheWrite). This is cleared when FS-Cache no longer needs the data in the page for writing to the cache.This allows (1)
invalidatepage()to wait until the page is written before it is returned to the memory allocator, and (2)releasepage()to indicate that the page is busy if__GFP_WAITis not given.
So it isn't written synchronously at invalidatepage-time? OK.
Quoted 5 lines
Quoted 1 line
Possibly you can't reuse mappedtodisk....
PG_mappedtodiskhas a very specific meaning tofs/buffer.candfs/mpage.c. I can't also easily make it mean that a page is backed by the cache. A page can be cached and not mapped to disk.
You have 2 types of pagecache pages you are dealing with here, right? The netfs and the backingfs pages. From what you write above, am I to take it that you need to know whether a backingfs page is "backed by the cache"? WTF for? And what cache is it backed by if it is the backing store?
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
We still need a way of triggering the page invalidation callbacks for in-use pages, however.
PG_private, as I've said, is not currently a viable option.Can you say exactly why not?
fs/buffer.cownsPG_privatein filesystems that use standard buffering. It sets it, clears it and tests it at its own behest without recourse to the filesystem using it.
One of us is confused about how this works. Firstly, from your description above, you're needing the invalidatepage call from the *netfs* page. This is not using fs/buffer.c presumably, that is the backing store fs.
Secondly, I repeat again, PG_private is only to tell the VM to call the fs aop, so if you just think you can override this without changing the aop then you are mistaken: buffer.c will blow up in serveral places if its page aops are called without buffers being attached to the page (try_to_release_page being one of them).
Thirdly, buffer layer is just a library for the filesystem to use. Of course it has recourse to override things just by giving different aops (which could then call into buffer.c if PG_fscache is not set or whatever you require).
Quoted 2 lines
Also NFS uses
PG_privatefor its own nefarious purposes. MakingPG_privatebe the conjunction of both purposes entailed some fairly messy patching.
This is basically an NFS mess, so that's where it belongs. But anyway I don't see how it could be less messy to add this in the VM because NFS aops *still* need to distinguish between cases anyway.
David Howells
maintainerWhat I mean by a 'netfs' when dealing with FS-Cache
I think I see the problem. I think you're misunderstanding what I mean by netfs.
Note that when I say 'netfs' I don't necessarily _mean_ it has to be a network fs. It could be NFS, AFS, CIFS, but it might also be ISO9660. Look at these two diagrams (taken from the docs added by patch 07):
+---------+ | | +--------------+ | NFS |--+ | | | | | +-->| CacheFS | +---------+ | +----------+ | | /dev/hda5 | | | | | +--------------+ +---------+ +-->| | | | | | |--+ | AFS |----->| FS-Cache | | | | |--+ +---------+ +-->| | | | | | | +--------------+ +---------+ | +----------+ | | | | | | +-->| CacheFiles | | ISOFS |--+ | /var/cache | | | +--------------+ +---------+
NFS, AFS and ISOFS in this diagram all fill the roll of 'netfs'. CacheFS (cache on blockdev) and CacheFiles (cache on filesystem) fill the roll of 'backingfs'.
And:
+---------+ | | | Server | | | +---------+ | NETWORK ~~~~~|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | +----------+ V | | +---------+ | | | | | | | NFS |----->| FS-Cache | | | | |--+ +---------+ | | | +--------------+ +--------------+ | | | | | | | | V +----------+ +-->| CacheFiles |-->| Ext3 | +---------+ | /var/cache | | /dev/sda6 | | | +--------------+ +--------------+ | VFS | ^ ^ | | | | +---------+ +--------------+ | | KERNEL SPACE | | ~~~~~|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|~~~~~~|~~~~ | USER SPACE | | V | | +---------+ +--------------+ | | | | | Process | | cachefilesd | | | | | +---------+ +--------------+
FS-Cache tracks pages from the 'netfs' because it may want to keep metadata on them (such as where in the backingfs the pages are to be stored). In many ways, PG_fscache is equivalent of PG_mappedtodisk. You could think of it as PG_mappedtocache if you like.
The procedure for the netfs to use the cache on a page is that it calls one of:
fscache_read_or_alloc_page()
fscache_read_or_alloc_pages()
fscache_alloc_page()
to either read pages from the cache or reserve space in the cache into which the page can be written.
Then, the netfs calls:
fscache_write_page()
to write pages back to the cache as often as it likes. This may only be called if read/alloc has been called first, and is permitted, inside the caching backend (eg CacheFiles), to cache metadata about the read/alloc.
Finally, to polish off, the netfs calls:
fscache_uncache_page()
to tell FS-Cache to release any metadata it might hold on that page.
As I've been saying, I want to be able to make iso9660 be a client of FS-Cache
- ie: fill the roll of a netfs.
David
David Howells
maintainerRe: What I mean by a 'netfs' when dealing with FS-Cache
Quoted 1 line · David Howells
NFS, AFS and ISOFS in this diagram all fill the roll of 'netfs'.
Make that 'role', not 'roll'. Or 'rôle' if you prefer.
David
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 06/43] FS-Cache: Recruit a couple of page flags for cache management [ver #46]
In reply to Nick PigginQuoted 5 lines · On Friday 03 April 2009 03:15:02 Nick Piggin wrote:
Quoted 4 lines · On Friday 03 April 2009 02:51:02 David Howells wrote:
Quoted 1 line · Nick Piggin
Possibly you can't reuse mappedtodisk....
Quoted 8 lines
Quoted 3 lines
PG_mappedtodiskhas a very specific meaning tofs/buffer.candfs/mpage.c. I can't also easily make it mean that a page is backed by the cache. A page can be cached and not mapped to disk.You have 2 types of pagecache pages you are dealing with here, right? The netfs and the backingfs pages. From what you write above, am I to take it that you need to know whether a backingfs page is "backed by the cache"? WTF for? And what cache is it backed by if it is the backing store?
Ah, sorry you want isofs to be cached by another backing store. All this talk of netfs confused me. Yes that's fair enough and could put PG_mappedtodisk out of reach. OTOH, is isofs important? Enough that it can't be done with fuse or something?
Comments about PG_private still stand.
David Howells
maintainerRe: [PATCH 06/43] FS-Cache: Recruit a couple of page flags for cache management [ver #46]
Quoted 1 line · Nick Piggin
Comments about
PG_privatestill stand.
Replies about PG_private still stand.
It's owned by fs/buffer.c, and if the 'netfs' uses that, then PG_private is not available. Though, as I said, fs/buffer.c could be broken of its control of the bit.
David
Re: [PATCH 06/43] FS-Cache: Recruit a couple of page flags for cache management [ver #46]
Quoted 8 lines · On Friday 03 April 2009 04:09:15 David Howells wrote:
Quoted 1 line · Nick Piggin
Comments about
PG_privatestill stand.Replies about
PG_privatestill stand.It's owned by
fs/buffer.c, and if the 'netfs' uses that, thenPG_privateis not available.
Well in theory I still think it would be cleanest to modify buffer to play more nicely with it. But maybe that ends up being harder to distinguish the 3 cases of attached metadata on the page. I don't know, you haven't posted any isofs code so either way it is inappropriate to use up this extra page flag here.
Is isofs cache worth a page flag?
David Howells
maintainerRe: [PATCH 06/43] FS-Cache: Recruit a couple of page flags for cache management [ver #46]
Quoted 7 lines · Nick Piggin
Well in theory I still think it would be cleanest to modify buffer to play more nicely with it. But maybe that ends up being harder to distinguish the 3 cases of attached metadata on the page. I don't know, you haven't posted any isofs code so either way it is inappropriate to use up this extra page flag here.
Is isofs cache worth a page flag?
Well, isofs was something I wanted at the time.
Besides, as I said NFS uses PG_private for its own purposes, and entangling the two wasn't the most fun I've had. Trond didn't like it either.
David
Re: [PATCH 06/43] FS-Cache: Recruit a couple of page flags for cache management [ver #46]
Quoted 11 lines · On Friday 03 April 2009 04:40:57 David Howells wrote:
Quoted 7 lines · Nick Piggin
Well in theory I still think it would be cleanest to modify buffer to play more nicely with it. But maybe that ends up being harder to distinguish the 3 cases of attached metadata on the page. I don't know, you haven't posted any isofs code so either way it is inappropriate to use up this extra page flag here.
Is isofs cache worth a page flag?
Well, isofs was something I wanted at the time.
It can't be done with FUSE?
Quoted 2 lines
Besides, as I said NFS uses
PG_privatefor its own purposes, and entangling the two wasn't the most fun I've had. Trond didn't like it either.
IMO that is quite OK to make them go through the pain of that if it avoids resulting in a new page flag that is probably unusable to most other filesystems.
But... I guess I won't get hung up on it. If you avoid at least one of these flags it would be a good start.
David Howells
maintainerRe: [PATCH 06/43] FS-Cache: Recruit a couple of page flags for cache management [ver #46]
Quoted 9 lines · Nick Piggin
Quoted 2 lines
Besides, as I said NFS uses
PG_privatefor its own purposes, and entangling the two wasn't the most fun I've had. Trond didn't like it either.IMO that is quite OK to make them go through the pain of that if it avoids resulting in a new page flag that is probably unusable to most other filesystems.
But... I guess I won't get hung up on it. If you avoid at least one of these flags it would be a good start.
Okay, the attached patch allows PageFsCacheWrite to be dispensed with. I have a radix tree already to track pages that need writing, so I just extend the use of that.
It does make waiting for a page to be written more tricky, though, as I can't now just wait on a page flag. It's also theoretically slower as I now have to take extra spinlocks.
I've benchmarked it three times:
Fri Apr 3 01:42:16 BST 2009 Fri Apr 3 01:44:25 BST 2009 2m 9s Fri Apr 3 01:46:45 BST 2009 Fri Apr 3 01:48:24 BST 2009 1m 39s Fri Apr 3 01:50:28 BST 2009 Fri Apr 3 01:52:40 BST 2009 2m 12s
using the same benchmark as for the patch to use the write() file op.
David
---
commit 9a10592512b01b42eb65f32c1028c57a1a6c864e
Author: David Howells <[email protected]> Date: Fri Apr 3 02:04:15 2009 +0100
FS-Cache: Use a radix tree to track pages being written rather than a page flag
Use a radix tree attached to struct fscache_cookie to track what pages are undergoing write, rather than using a page flag.
The radix tree that was resident in struct fscache_object to track pages that need writing is moved to fscache_cookie. Pages that need writing and pages that are being written are both held in there. The difference being that the former are tagged with FSCACHE_COOKIE_PENDING_TAG.
Documentation/filesystems/caching/netfs-api.txt +33 -55
@@ -640,7 +640,18 @@ Note that pages can't be explicitly deleted from the a data file. The whole data file must be retired (see the relinquish cookie function below). Furthermore, note that this does not cancel the asynchronous read or write -operation started by the read/alloc and write functions. +operation started by the read/alloc and write functions, so the page +invalidation and release functions must use: + + bool fscache_check_page_write(struct fscache_cookie *cookie, + struct page *page); + +to see if a page is being written to the cache, and: + + void fscache_wait_on_page_write(struct fscache_cookie *cookie, + struct page *page); + +to wait for it to finish if it is. ==========================
@@ -730,52 +741,32 @@ this, the caller should relinquish and retire the cookie they have, and then acquire a new one. -============================ -FS-CACHE SPECIFIC PAGE FLAGS -============================ - -FS-Cache makes use of two page flags, PG_private_2 and PG_owner_priv_2, for -its own purpose. The first is given the alternative name PG_fscache and the -second PG_fscache_write. - -FS-Cache uses these flags to keep track of two bits of information per cached -netfs page: +=========================== +FS-CACHE SPECIFIC PAGE FLAG +=========================== - (1) PG_fscache. +FS-Cache makes use of a page flag, PG_private_2, for its own purpose. This is +given the alternative name PG_fscache. - This indicates that the page is known by the cache, and that the cache - must be informed if the page is going to go away. It's an indication to - the netfs that the cache has an interest in this page, where an interest - may be a pointer to it, resources allocated or reserved for it, or I/O in - progress upon it. +PG_fscache is used to indicate that the page is known by the cache, and that +the cache must be informed if the page is going to go away. It's an indication +to the netfs that the cache has an interest in this page, where an interest may +be a pointer to it, resources allocated or reserved for it, or I/O in progress +upon it. - The netfs can use this information in methods such as releasepage() to - determine whether it needs to uncache a page or update it. +The netfs can use this information in methods such as releasepage() to +determine whether it needs to uncache a page or update it. - Furthermore, if this bit is set, releasepage() and invalidatepage() - operations will be called on a page to get rid of it, even if PG_private - is not set. This allows caching to attempted on a page before - read_cache_pages() to be called after fscache_read_or_alloc_pages() as - the former will try and release pages it was given under certain - circumstances. +Furthermore, if this bit is set, releasepage() and invalidatepage() operations +will be called on a page to get rid of it, even if PG_private is not set. This +allows caching to attempted on a page before read_cache_pages() to be called +after fscache_read_or_alloc_pages() as the former will try and release pages it +was given under certain circumstances. - (2) PG_fscache_write. +This bit does not overlap with such as PG_private. This means that FS-Cache +can be used with a filesystem that uses the block buffering code. - This indicates that the page is being written to disk by the cache, and - that it cannot be released until completion. Ideally it shouldn't be - changed until completion either so as to maintain the known state of the - cache. This cannot be unified with PG_writeback as the page may be being - written to both the server and the cache at the same time or at different - times. - - This can be used by the netfs to wait for a page to be written out to the - cache before, say, releasing or invalidating it, or before allowing - someone to modify it in page_mkwrite(), say. - -Neither of these two bits overlaps with such as PG_private. This means that -FS-Cache can be used with a filesystem that uses the block buffering code. - -There are a number of operations defined on these two bits: +There are a number of operations defined on this flag: int PageFsCache(struct page *page); void SetPageFsCache(struct page *page)
@@ -783,18 +774,5 @@ There are a number of operations defined on these two bits: int TestSetPageFsCache(struct page *page) int TestClearPageFsCache(struct page *page) - int PageFsCacheWrite(struct page *page) - void SetPageFsCacheWrite(struct page *page) - void ClearPageFsCacheWrite(struct page *page) - int TestSetPageFsCacheWrite(struct page *page) - int TestClearPageFsCacheWrite(struct page *page) - These functions are bit test, bit set, bit clear, bit test and set and bit -test and clear operations on PG_fscache and PG_fscache_write. - - void wait_on_page_fscache_write(struct page *page) - void end_page_fscache_write(struct page *page) - -The first of these two functions waits uninterruptibly for PG_fscache_write to -become clear, if it isn't already so. The second clears PG_fscache_write and -wakes up anyone waiting for it. +test and clear operations on PG_fscache.
fs/afs/file.c +3 -3
@@ -299,7 +299,7 @@ static void afs_invalidatepage(struct page *page, unsigned long offset)#ifdef CONFIG_AFS_FSCACHE if (PageFsCache (page)) {struct afs_vnode *vnode =AFS_FS_I (page->mapping->host); -wait_on_page_fscache_write (page); +fscache_wait_on_page_write (vnode->cache, page);fscache_uncache_page (vnode->cache, page);ClearPageFsCache (page); }
@@ -336,12 +336,12 @@ static int afs_releasepage(struct page *page, gfp_t gfp_flags)* elected to wait */ #ifdef CONFIG_AFS_FSCACHE if (PageFsCache (page)) { -if (PageFsCacheWrite (page)) { +if (fscache_check_page_write (vnode->cache, page)) {if (!(gfp_flags & __GFP_WAIT)) {_leave (" = F [cache busy]" );return 0 ; } -wait_on_page_fscache_write (page); +fscache_wait_on_page_write (vnode->cache, page); }fscache_uncache_page (vnode->cache, page);
fs/afs/write.c +1 -1
@@ -795,7 +795,7 @@ int afs_page_mkwrite(struct vm_area_struct *vma, struct page *page)/* wait for the page to be written to the cache before we allow it to * be modified */ #ifdef CONFIG_AFS_FSCACHE -wait_on_page_fscache_write (page); +fscache_wait_on_page_write (vnode->cache, page);#endif _leave (" = 0" );
fs/fscache/cookie.c +2 -0
@@ -102,6 +102,8 @@ struct fscache_cookie *__fscache_acquire_cookie( cookie->netfs_data = netfs_data; cookie->flags =0 ; +INIT_RADIX_TREE (&cookie->stores,GFP_NOFS ); +switch (cookie->def->type) {case FSCACHE_COOKIE_TYPE_INDEX :fscache_stat (&fscache_n_cookie_index);
fs/fscache/page.c +61 -16
136 lines not on this page · raw message
fs/nfs/file.c +3 -2
@@ -456,11 +456,12 @@ static int nfs_release_page(struct page *page, gfp_t gfp)static int nfs_launder_page (struct page *page) {struct inode *inode = page->mapping->host; +struct nfs_inode *nfsi =NFS_I (inode);dfprintk (PAGECACHE ,"NFS: launder_page(%ld, %llu)\n" , inode->i_ino, (long long )page_offset (page)); -wait_on_page_fscache_write (page); +nfs_fscache_wait_on_page_write (nfsi, page);return nfs_wb_page (inode, page); }
@@ -498,7 +499,7 @@ static int nfs_vm_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf) (long long)page_offset(page));/* make sure the cache has finished storing the page */ -wait_on_page_fscache_write (page); +nfs_fscache_wait_on_page_write (NFS_I (dentry->d_inode), page);lock_page (page); mapping = page->mapping;
fs/nfs/fscache.c +14 -12
@@ -337,21 +337,22 @@ void nfs_fscache_reset_inode_cookie(struct inode *inode)*/ int nfs_fscache_release_page (struct page *page,gfp_t gfp) { -if (PageFsCacheWrite (page)) { +struct nfs_inode *nfsi =NFS_I (page->mapping->host); +struct fscache_cookie *cookie = nfsi->fscache; + +BUG_ON (!cookie); + +if (fscache_check_page_write (cookie, page)) {if (!(gfp & __GFP_WAIT))return 0 ; -wait_on_page_fscache_write (page); +fscache_wait_on_page_write (cookie, page); }if (PageFsCache (page)) { -struct nfs_inode *nfsi =NFS_I (page->mapping->host); - -BUG_ON (!nfsi->fscache); -dfprintk (FSCACHE ,"NFS: fscache releasepage (0x%p/0x%p/0x%p)\n" , - nfsi->fscache, page, nfsi); + cookie, page, nfsi); -fscache_uncache_page (nfsi->fscache, page); +fscache_uncache_page (cookie, page);nfs_add_fscache_stats (page->mapping->host,NFSIOS_FSCACHE_PAGES_UNCACHED ,1 ); }
@@ -366,16 +367,17 @@ int nfs_fscache_release_page(struct page *page, gfp_t gfp)void __nfs_fscache_invalidate_page (struct page *page,struct inode *inode) {struct nfs_inode *nfsi =NFS_I (inode); +struct fscache_cookie *cookie = nfsi->fscache; -BUG_ON (!nfsi->fscache); +BUG_ON (!cookie);dfprintk (FSCACHE ,"NFS: fscache invalidatepage (0x%p/0x%p/0x%p)\n" , - nfsi->fscache, page, nfsi); + cookie, page, nfsi); -wait_on_page_fscache_write (page); +fscache_wait_on_page_write (cookie, page);BUG_ON (!PageLocked (page)); -fscache_uncache_page (nfsi->fscache, page); +fscache_uncache_page (cookie, page);nfs_add_fscache_stats (page->mapping->host,NFSIOS_FSCACHE_PAGES_UNCACHED ,1 ); }
fs/nfs/fscache.h +12 -0
@@ -94,6 +94,16 @@ extern int __nfs_readpages_from_fscache(struct nfs_open_context *,extern void __nfs_readpage_to_fscache (struct inode *,struct page *,int );/* +* wait for a page to complete writing to the cache +*/ +static inline void nfs_fscache_wait_on_page_write (struct nfs_inode *nfsi, +struct page *page) +{ +if (PageFsCache (page)) +fscache_wait_on_page_write (nfsi->fscache, page); +} + +/* * release the caching state associated with a page if undergoing complete page * invalidation */
@@ -181,6 +191,8 @@ static inline int nfs_fscache_release_page(struct page *page, gfp_t gfp) }static inline void nfs_fscache_invalidate_page (struct page *page,struct inode *inode) {} +static inline void nfs_fscache_wait_on_page_write (struct nfs_inode *nfsi, +struct page *page) {} static inline int nfs_readpage_from_fscache(struct nfs_open_context *ctx, struct inode *inode,
include/linux/fscache-cache.h +3 -2
@@ -301,6 +301,9 @@ struct fscache_cookie {const struct fscache_cookie_def *def;/* definition */ struct fscache_cookie *parent;/* parent of this entry */ void *netfs_data;/* back pointer to netfs */ +struct radix_tree_root stores;/* pages to be stored on this cookie */ +#define FSCACHE_COOKIE_PENDING_TAG 0/* pages tag: pending write to cache */ +unsigned long flags;#define FSCACHE_COOKIE_LOOKING_UP 0/* T if non-index cookie being looked up still */ #define FSCACHE_COOKIE_CREATING 1/* T if non-index object being created still */
@@ -370,7 +373,6 @@ struct fscache_object {struct list_head dependents;/* FIFO of dependent objects */ struct list_head dep_link;/* link in parent's dependents list */ struct list_head pending_ops;/* unstarted operations on this object */ -struct radix_tree_root stores;/* data to be stored */ pgoff_t store_limit;/* current storage limit */ };
@@ -407,7 +409,6 @@ void fscache_object_init(struct fscache_object *object,INIT_LIST_HEAD (&object->dependents);INIT_LIST_HEAD (&object->dep_link);INIT_LIST_HEAD (&object->pending_ops); -INIT_RADIX_TREE (&object->stores,GFP_NOFS ); object->n_children =0 ; object->n_ops = object->n_in_progress = object->n_exclusive =0 ; object->events = object->event_mask =0 ;
include/linux/fscache.h +40 -14
70 lines not on this page · raw message
include/linux/page-flags.h +0 -3
@@ -79,7 +79,6 @@ enum pageflags { PG_active, PG_slab, PG_owner_priv_1,/* Owner use. If pagecache, fs may use*/ - PG_owner_priv_2,/* Owner use. fs may use in pagecache */ PG_arch_1, PG_reserved, PG_private, /* If pagecache, has fs-private data */
@@ -115,7 +114,6 @@ enum pageflags {* when those inodes are being locally cached. */ PG_fscache = PG_private_2,/* page backed by cache */ - PG_fscache_write = PG_owner_priv_2,/* page being written to cache */ /* XEN */ PG_pinned = PG_owner_priv_1,
@@ -220,7 +218,6 @@ PAGEFLAG(Private, private) __SETPAGEFLAG(Private, private) __CLEARPAGEFLAG(Private, private) PAGEFLAG(Private2, private_2) TESTSCFLAG(Private2, private_2) PAGEFLAG(OwnerPriv1, owner_priv_1) TESTCLEARFLAG(OwnerPriv1, owner_priv_1) -PAGEFLAG(OwnerPriv2, owner_priv_2) TESTSCFLAG(OwnerPriv2, owner_priv_2)/* * Only test-and-set exist for PG_writeback. The unconditional operators are
include/linux/pagemap.h +0 -16
@@ -379,22 +379,6 @@ static inline void wait_on_page_writeback(struct page *page)extern void end_page_writeback (struct page *page); -/** -* wait_on_page_owner_priv_2 - Wait for PG_owner_priv_2 to become clear -* @page: The page to monitor -* -* Wait for a PG_owner_priv_2 to become clear on the specified page. This is -* also used to monitor PG_fscache_write (which is an alternate name for the -* same bit). -*/ -static inline void wait_on_page_owner_priv_2 (struct page *page) -{ -if (PageOwnerPriv2 (page)) -wait_on_page_bit (page, PG_owner_priv_2); -} - -extern void end_page_owner_priv_2 (struct page *page); -/* * Add an arbitrary waiter to a page's wait queue */
mm/filemap.c +0 -17
@@ -621,23 +621,6 @@ void end_page_writeback(struct page *page)EXPORT_SYMBOL (end_page_writeback);/** -* end_page_owner_priv_2 - Clear PG_owner_priv_2 and wake up any waiters -* @page: the page -* -* Clear PG_owner_priv_2 and wake up any processes waiting for that event. -* This is used to indicate - using PG_fscache_write (an alternate name for the -* same bit) - that a page has finished being written to the local disk cache. -*/ -void end_page_owner_priv_2 (struct page *page) -{ -if (!TestClearPageOwnerPriv2 (page)) -BUG (); -smp_mb__after_clear_bit (); -wake_up_page (page, PG_owner_priv_2); -} -EXPORT_SYMBOL (end_page_owner_priv_2); - -/** * __lock_page - get a lock on the page, assuming we need to sleep to get it * @page: the page to lock *
Re: [PATCH 06/43] FS-Cache: Recruit a couple of page flags for cache management [ver #46]
In reply to David HowellsQuoted 8 lines · David Howells
Quoted 6 lines · Nick Piggin
Well in theory I still think it would be cleanest to modify buffer to play more nicely with it. But maybe that ends up being harder to distinguish the 3 cases of attached metadata on the page. I don't know, you haven't posted any isofs code so either way it is inappropriate to use up this extra page flag here.
Quoted 6 lines
Quoted 1 line
Is isofs cache worth a page flag?
Well, isofs was something I wanted at the time.
Besides, as I said NFS uses
PG_privatefor its own purposes, and entangling the two wasn't the most fun I've had. Trond didn't like it either.
We use it for exactly the same purpose as everyone else: to signal that we need a callback to ->releasepage() if the VM wants to truncate the page.
Trond
Re: [PATCH 06/43] FS-Cache: Recruit a couple of page flags for cache management [ver #46]
In reply to David HowellsQuoted 8 lines · David Howells
If
PG_fscacheis set, then things that checked forPG_privatewill now also check for that. This includes things like truncation and page invalidation. The functionpage_has_private()had been added to make the checks for bothPG_privateandPG_private_2at the same time.Signed-off-by David Howells <[email protected]>Acked-by Steve Dickson <[email protected]>Acked-by Trond Myklebust <[email protected]>
David Howells
maintainerPATCH 7/43 FS-Cache: Add the FS-Cache netfs API and documentation [ver #46]
In reply to David HowellsAdd the API for a generic facility (FS-Cache) by which filesystems (such as AFS or NFS) may call on local caching capabilities without having to know anything about how the cache works, or even if there is a cache:
+---------+ | | +--------------+ | NFS |--+ | | | | | +-->| CacheFS | +---------+ | +----------+ | | /dev/hda5 | | | | | +--------------+ +---------+ +-->| | | | | | |--+ | AFS |----->| FS-Cache | | | | |--+ +---------+ +-->| | | | | | | +--------------+ +---------+ | +----------+ | | | | | | +-->| CacheFiles | | ISOFS |--+ | /var/cache | | | +--------------+ +---------+
General documentation and documentation of the netfs specific API are provided in addition to the header files.
As this patch stands, it is possible to build a filesystem against the facility and attempt to use it. All that will happen is that all requests will be immediately denied as if no cache is present.
Further patches will implement the core of the facility. The facility will transfer requests from networking filesystems to appropriate caches if possible, or else gracefully deny them.
If this facility is disabled in the kernel configuration, then all its operations will trivially reduce to nothing during compilation.
WHY NOT I_MAPPING?
==================
I have added my own API to implement caching rather than using i_mapping to do this for a number of reasons. These have been discussed a lot on the LKML and CacheFS mailing lists, but to summarise the basics:
(1) Most filesystems don't do hole reportage. Holes in files are treated as blocks of zeros and can't be distinguished otherwise, making it difficult to distinguish blocks that have been read from the network and cached from those that haven't.
(2) The backing inode must be fully populated before being exposed to userspace through the main inode because the VM/VFS goes directly to the backing inode and does not interrogate the front inode's VM ops.
Therefore:
(a) The backing inode must fit entirely within the cache.
(b) All backed files currently open must fit entirely within the cache at the same time.
(c) A working set of files in total larger than the cache may not be cached.
(d) A file may not grow larger than the available space in the cache.
(e) A file that's open and cached, and remotely grows larger than the cache is potentially stuffed.
(3) Writes go to the backing filesystem, and can only be transferred to the network when the file is closed.
(4) There's no record of what changes have been made, so the whole file must be written back.
(5) The pages belong to the backing filesystem, and all metadata associated with that page are relevant only to the backing filesystem, and not anything stacked atop it.
OVERVIEW
========
FS-Cache provides (or will provide) the following facilities:
(1) Caches can be added / removed at any time, even whilst in use.
(2) Adds a facility by which tags can be used to refer to caches, even if they're not available yet.
(3) More than one cache can be used at once. Caches can be selected explicitly by use of tags.
(4) The netfs is provided with an interface that allows either party to withdraw caching facilities from a file (required for (1)).
(5) A netfs may annotate cache objects that belongs to it. This permits the storage of coherency maintenance data.
(6) Cache objects will be pinnable and space reservations will be possible.
(7) The interface to the netfs returns as few errors as possible, preferring rather to let the netfs remain oblivious.
(8) Cookies are used to represent indices, files and other objects to the netfs. The simplest cookie is just a NULL pointer - indicating nothing cached there.
(9) The netfs is allowed to propose - dynamically - any index hierarchy it desires, though it must be aware that the index search function is recursive, stack space is limited, and indices can only be children of indices.
(10) Indices can be used to group files together to reduce key size and to make group invalidation easier. The use of indices may make lookup quicker, but that's cache dependent.
(11) Data I/O is effectively done directly to and from the netfs's pages. The netfs indicates that page A is at index B of the data-file represented by cookie C, and that it should be read or written. The cache backend may or may not start I/O on that page, but if it does, a netfs callback will be invoked to indicate completion. The I/O may be either synchronous or asynchronous.
(12) Cookies can be "retired" upon release. At this point FS-Cache will mark them as obsolete and the index hierarchy rooted at that point will get recycled.
(13) The netfs provides a "match" function for index searches. In addition to saying whether a match was made or not, this can also specify that an entry should be updated or deleted.
FS-Cache maintains a virtual index tree in which all indices, files, objects and pages are kept. Bits of this tree may actually reside in one or more caches.
FSDEF
|
+------------------------------------+
| |
NFS AFS
| |
+--------------------------+ +-----------+
| | | |
homedir mirror afs.org redhat.com
| | |
+------------+ +---------------+ +----------+
| | | | | |
00001 00002 00007 00125 vol00001 vol00002
| | | | |
+---+---+ +-----+ +---+ +------+------+ +-----+----+
| | | | | | | | | | | | |
PG0 PG1 PG2 PG0 XATTR PG0 PG1 DIRENT DIRENT DIRENT R/W R/O Bak
| |
PG0 +-------+
| |
00001 00003
|
+---+---+
| | |
PG0 PG1 PG2In the example above, two netfs's can be seen to be backed: NFS and AFS. These have different index hierarchies:
(*) The NFS primary index will probably contain per-server indices. Each
server index is indexed by NFS file handles to get data file objects. Each data file objects can have an array of pages, but may also have further child objects, such as extended attributes and directory entries. Extended attribute objects themselves have page-array contents.
(*) The AFS primary index contains per-cell indices. Each cell index contains
per-logical-volume indices. Each of volume index contains up to three indices for the read-write, read-only and backup mirrors of those volumes. Each of these contains vnode data file objects, each of which contains an array of pages.
The very top index is the FS-Cache master index in which individual netfs's have entries.
Any index object may reside in more than one cache, provided it only has index children. Any index with non-index object children will be assumed to only reside in one cache.
The FS-Cache overview can be found in:
Documentation/filesystems/caching/fscache.txt
The netfs API to FS-Cache can be found in:
Documentation/filesystems/caching/netfs-api.txt
---
Documentation/filesystems/caching/fscache.txt | 330 +++++++++ Documentation/filesystems/caching/netfs-api.txt | 800 +++++++++++++++++++++++ include/linux/fscache.h | 528 +++++++++++++++ include/linux/pagemap.h | 4 mm/filemap.c | 2 5 files changed, 1663 insertions(+), 1 deletions(-) create mode 100644 Documentation/filesystems/caching/fscache.txt create mode 100644 Documentation/filesystems/caching/netfs-api.txt create mode 100644 include/linux/fscache.h
Documentation/filesystems/caching/fscache.txt new file +330 -0
@@ -0,0 +1,330 @@ + ========================== + General Filesystem Caching + ========================== + +======== +OVERVIEW +======== + +This facility is a general purpose cache for network filesystems, though it +could be used for caching other things such as ISO9660 filesystems too. + +FS-Cache mediates between cache backends (such as CacheFS) and network +filesystems: + + +---------+ + | | +--------------+ + | NFS |--+ | | + | | | +-->| CacheFS | + +---------+ | +----------+ | | /dev/hda5 | + | | | | +--------------+ + +---------+ +-->| | | + | | | |--+ + | AFS |----->| FS-Cache | + | | | |--+ + +---------+ +-->| | | + | | | | +--------------+ + +---------+ | +----------+ | | | + | | | +-->| CacheFiles | + | ISOFS |--+ | /var/cache | + | | +--------------+ + +---------+ + +Or to look at it another way, FS-Cache is a module that provides a caching +facility to a network filesystem such that the cache is transparent to the +user: + + +---------+ + | | + | Server | + | | + +---------+ + | NETWORK + ~~~~~|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + | + | +----------+ + V | | + +---------+ | | + | | | | + | NFS |----->| FS-Cache | + | | | |--+ + +---------+ | | | +--------------+ +--------------+ + | | | | | | | | + V +----------+ +-->| CacheFiles |-->| Ext3 | + +---------+ | /var/cache | | /dev/sda6 | + | | +--------------+ +--------------+ + | VFS | ^ ^ + | | | | + +---------+ +--------------+ | + | KERNEL SPACE | | + ~~~~~|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|~~~~~~|~~~~ + | USER SPACE | | + V | | + +---------+ +--------------+ + | | | | + | Process | | cachefilesd | + | | | | + +---------+ +--------------+ + + +FS-Cache does not follow the idea of completely loading every netfs file +opened in its entirety into a cache before permitting it to be accessed and +then serving the pages out of that cache rather than the netfs inode because: + + (1) It must be practical to operate without a cache. + + (2) The size of any accessible file must not be limited to the size of the + cache. + + (3) The combined size of all opened files (this includes mapped libraries) + must not be limited to the size of the cache. + + (4) The user should not be forced to download an entire file just to do a + one-off access of a small portion of it (such as might be done with the + "file" program). + +It instead serves the cache out in PAGE_SIZE chunks as and when requested by +the netfs('s) using it. + + +FS-Cache provides the following facilities: + + (1) More than one cache can be used at once. Caches can be selected + explicitly by use of tags. + + (2) Caches can be added / removed at any time. + + (3) The netfs is provided with an interface that allows either party to + withdraw caching facilities from a file (required for (2)). + + (4) The interface to the netfs returns as few errors as possible, preferring + rather to let the netfs remain oblivious. + + (5) Cookies are used to represent indices, files and other objects to the + netfs. The simplest cookie is just a NULL pointer - indicating nothing + cached there. + + (6) The netfs is allowed to propose - dynamically - any index hierarchy it + desires, though it must be aware that the index search function is + recursive, stack space is limited, and indices can only be children of + indices. + + (7) Data I/O is done direct to and from the netfs's pages. The netfs + indicates that page A is at index B of the data-file represented by cookie + C, and that it should be read or written. The cache backend may or may + not start I/O on that page, but if it does, a netfs callback will be + invoked to indicate completion. The I/O may be either synchronous or + asynchronous. + + (8) Cookies can be "retired" upon release. At this point FS-Cache will mark + them as obsolete and the index hierarchy rooted at that point will get + recycled. + + (9) The netfs provides a "match" function for index searches. In addition to + saying whether a match was made or not, this can also specify that an + entry should be updated or deleted. + +(10) As much as possible is done asynchronously. + + +FS-Cache maintains a virtual indexing tree in which all indices, files, objects +and pages are kept. Bits of this tree may actually reside in one or more +caches. + + FSDEF + | + +------------------------------------+ + | | + NFS AFS + | | + +--------------------------+ +-----------+ + | | | | + homedir mirror afs.org redhat.com + | | | + +------------+ +---------------+ +----------+ + | | | | | | + 00001 00002 00007 00125 vol00001 vol00002 + | | | | | + +---+---+ +-----+ +---+ +------+------+ +-----+----+ + | | | | | | | | | | | | | +PG0 PG1 PG2 PG0 XATTR PG0 PG1 DIRENT DIRENT DIRENT R/W R/O Bak + | | + PG0 +-------+ + | | + 00001 00003 + | + +---+---+ + | | | + PG0 PG1 PG2 + +In the example above, you can see two netfs's being backed: NFS and AFS. These +have different index hierarchies: + + (*) The NFS primary index contains per-server indices. Each server index is + indexed by NFS file handles to get data file objects. Each data file + objects can have an array of pages, but may also have further child + objects, such as extended attributes and directory entries. Extended + attribute objects themselves have page-array contents. + + (*) The AFS primary index contains per-cell indices. Each cell index contains + per-logical-volume indices. Each of volume index contains up to three + indices for the read-write, read-only and backup mirrors of those volumes. + Each of these contains vnode data file objects, each of which contains an + array of pages. + +The very top index is the FS-Cache master index in which individual netfs's +have entries. + +Any index object may reside in more than one cache, provided it only has index +children. Any index with non-index object children will be assumed to only +reside in one cache. + + +The netfs API to FS-Cache can be found in: + + Documentation/filesystems/caching/netfs-api.txt + +The cache backend API to FS-Cache can be found in: + + Documentation/filesystems/caching/backend-api.txt + + +======================= +STATISTICAL INFORMATION +======================= + +If FS-Cache is compiled with the following options enabled: + + CONFIG_FSCACHE_PROC=y (implied by the following two) + CONFIG_FSCACHE_STATS=y + CONFIG_FSCACHE_HISTOGRAM=y + +then it will gather certain statistics and display them through a number of +proc files. + + (*) /proc/fs/fscache/stats + + This shows counts of a number of events that can happen in FS-Cache: + + CLASS EVENT MEANING + ======= ======= ======================================================= + Cookies idx=N Number of index cookies allocated + dat=N Number of data storage cookies allocated + spc=N Number of special cookies allocated + Objects alc=N Number of objects allocated + nal=N Number of object allocation failures + avl=N Number of objects that reached the available state + ded=N Number of objects that reached the dead state + ChkAux non=N Number of objects that didn't have a coherency check + ok=N Number of objects that passed a coherency check + upd=N Number of objects that needed a coherency data update + obs=N Number of objects that were declared obsolete + Pages mrk=N Number of pages marked as being cached + unc=N Number of uncache page requests seen + Acquire n=N Number of acquire cookie requests seen + nul=N Number of acq reqs given a NULL parent + noc=N Number of acq reqs rejected due to no cache available + ok=N Number of acq reqs succeeded + nbf=N Number of acq reqs rejected due to error + oom=N Number of acq reqs failed on ENOMEM + Lookups n=N Number of lookup calls made on cache backends + neg=N Number of negative lookups made + pos=N Number of positive lookups made + crt=N Number of objects created by lookup + Updates n=N Number of update cookie requests seen + nul=N Number of upd reqs given a NULL parent + run=N Number of upd reqs granted CPU time + Relinqs n=N Number of relinquish cookie requests seen + nul=N Number of rlq reqs given a NULL parent + wcr=N Number of rlq reqs waited on completion of creation + AttrChg n=N Number of attribute changed requests seen + ok=N Number of attr changed requests queued + nbf=N Number of attr changed rejected -ENOBUFS + oom=N Number of attr changed failed -ENOMEM + run=N Number of attr changed ops given CPU time + Allocs n=N Number of allocation requests seen + ok=N Number of successful alloc reqs + wt=N Number of alloc reqs that waited on lookup completion + nbf=N Number of alloc reqs rejected -ENOBUFS + ops=N Number of alloc reqs submitted + owt=N Number of alloc reqs waited for CPU time + Retrvls n=N Number of retrieval (read) requests seen + ok=N Number of successful retr reqs + wt=N Number of retr reqs that waited on lookup completion + nod=N Number of retr reqs returned -ENODATA + nbf=N Number of retr reqs rejected -ENOBUFS + int=N Number of retr reqs aborted -ERESTARTSYS + oom=N Number of retr reqs failed -ENOMEM + ops=N Number of retr reqs submitted + owt=N Number of retr reqs waited for CPU time + Stores n=N Number of storage (write) requests seen + ok=N Number of successful store reqs + agn=N Number of store reqs on a page already pending storage + nbf=N Number of store reqs rejected -ENOBUFS + oom=N Number of store reqs failed -ENOMEM + ops=N Number of store reqs submitted + run=N Number of store reqs granted CPU time + Ops pend=N Number of times async ops added to pending queues + run=N Number of times async ops given CPU time + enq=N Number of times async ops queued for processing + dfr=N Number of async ops queued for deferred release + rel=N Number of async ops released + gc=N Number of deferred-release async ops garbage collected + + + (*) /proc/fs/fscache/histogram + + cat /proc/fs/fscache/histogram + +HZ +TIME OBJ INST OP RUNS OBJ RUNS RETRV DLY RETRIEVLS + ===== ===== ========= ========= ========= ========= ========= + + This shows the breakdown of the number of times each amount of time + between 0 jiffies and HZ-1 jiffies a variety of tasks took to run. The + columns are as follows: + + COLUMN TIME MEASUREMENT + ======= ======================================================= + OBJ INST Length of time to instantiate an object + OP RUNS Length of time a call to process an operation took + OBJ RUNS Length of time a call to process an object event took + RETRV DLY Time between an requesting a read and lookup completing + RETRIEVLS Time between beginning and end of a retrieval + + Each row shows the number of events that took a particular range of times. + Each step is 1 jiffy in size. The +HZ column indicates the particular + jiffy range covered, and the +TIME field the equivalent number of seconds. + + +========= +DEBUGGING +========= + +The FS-Cache facility can have runtime debugging enabled by adjusting the value +in: + + /sys/module/fscache/parameters/debug + +This is a bitmask of debugging streams to enable: + + BIT VALUE STREAM POINT + ======= ======= =============================== ======================= + 0 1 Cache management Function entry trace + 1 2 Function exit trace + 2 4 General + 3 8 Cookie management Function entry trace + 4 16 Function exit trace + 5 32 General + 6 64 Page handling Function entry trace + 7 128 Function exit trace + 8 256 General + 9 512 Operation management Function entry trace + 10 1024 Function exit trace + 11 2048 General + +The appropriate set of values should be OR'd together and the result written to +the control file. For example: + + echo $((1|8|64)) >/sys/module/fscache/parameters/debug + +will turn on all function entry debugging. +
Documentation/filesystems/caching/netfs-api.txt new file +800 -0
800 lines not on this page · raw message
include/linux/fscache.h new file +528 -0
528 lines not on this page · raw message
include/linux/pagemap.h +3 -1
@@ -383,7 +383,9 @@ extern void end_page_writeback(struct page *page);* wait_on_page_owner_priv_2 - Wait for PG_owner_priv_2 to become clear * @page: The page to monitor * -* Wait for a PG_owner_priv_2 to become clear on the specified page. +* Wait for a PG_owner_priv_2 to become clear on the specified page. This is +* also used to monitor PG_fscache_write (which is an alternate name for the +* same bit). */ static inline void wait_on_page_owner_priv_2 (struct page *page) {
mm/filemap.c +2 -0
@@ -607,6 +607,8 @@ EXPORT_SYMBOL(end_page_writeback);* @page: the page * * Clear PG_owner_priv_2 and wake up any processes waiting for that event. +* This is used to indicate - using PG_fscache_write (an alternate name for the +* same bit) - that a page has finished being written to the local disk cache. */ void end_page_owner_priv_2 (struct page *page) {
David Howells
maintainerPATCH 8/43 FS-Cache: Add the FS-Cache cache backend API and documentation [ver #46]
In reply to David HowellsAdd the API for a generic facility (FS-Cache) by which caches may declare them selves open for business, and may obtain work to be done from network filesystems. The header file is included by:
#include <linux/fscache-cache.h>
Documentation for the API is also added to:
Documentation/filesystems/caching/backend-api.txt
This API is not usable without the implementation of the utility functions which will be added in further patches.
---
Documentation/filesystems/caching/backend-api.txt | 664 +++++++++++++++++++++ include/linux/fscache-cache.h | 508 ++++++++++++++++ 2 files changed, 1172 insertions(+), 0 deletions(-) create mode 100644 Documentation/filesystems/caching/backend-api.txt create mode 100644 include/linux/fscache-cache.h
Documentation/filesystems/caching/backend-api.txt new file +664 -0
@@ -0,0 +1,664 @@ + ========================== + FS-CACHE CACHE BACKEND API + ========================== + +The FS-Cache system provides an API by which actual caches can be supplied to +FS-Cache for it to then serve out to network filesystems and other interested +parties. + +This API is declared in <linux/fscache-cache.h>. + + +==================================== +INITIALISING AND REGISTERING A CACHE +==================================== + +To start off, a cache definition must be initialised and registered for each +cache the backend wants to make available. For instance, CacheFS does this in +the fill_super() operation on mounting. + +The cache definition (struct fscache_cache) should be initialised by calling: + + void fscache_init_cache(struct fscache_cache *cache, + struct fscache_cache_ops *ops, + const char *idfmt, + ...); + +Where: + + (*) "cache" is a pointer to the cache definition; + + (*) "ops" is a pointer to the table of operations that the backend supports on + this cache; and + + (*) "idfmt" is a format and printf-style arguments for constructing a label + for the cache. + + +The cache should then be registered with FS-Cache by passing a pointer to the +previously initialised cache definition to: + + int fscache_add_cache(struct fscache_cache *cache, + struct fscache_object *fsdef, + const char *tagname); + +Two extra arguments should also be supplied: + + (*) "fsdef" which should point to the object representation for the FS-Cache + master index in this cache. Netfs primary index entries will be created + here. FS-Cache keeps the caller's reference to the index object if + successful and will release it upon withdrawal of the cache. + + (*) "tagname" which, if given, should be a text string naming this cache. If + this is NULL, the identifier will be used instead. For CacheFS, the + identifier is set to name the underlying block device and the tag can be + supplied by mount. + +This function may return -ENOMEM if it ran out of memory or -EEXIST if the tag +is already in use. 0 will be returned on success. + + +===================== +UNREGISTERING A CACHE +===================== + +A cache can be withdrawn from the system by calling this function with a +pointer to the cache definition: + + void fscache_withdraw_cache(struct fscache_cache *cache); + +In CacheFS's case, this is called by put_super(). + + +======== +SECURITY +======== + +The cache methods are executed one of two contexts: + + (1) that of the userspace process that issued the netfs operation that caused + the cache method to be invoked, or + + (2) that of one of the processes in the FS-Cache thread pool. + +In either case, this may not be an appropriate context in which to access the +cache. + +The calling process's fsuid, fsgid and SELinux security identities may need to +be masqueraded for the duration of the cache driver's access to the cache. +This is left to the cache to handle; FS-Cache makes no effort in this regard. + + +=================================== +CONTROL AND STATISTICS PRESENTATION +=================================== + +The cache may present data to the outside world through FS-Cache's interfaces +in sysfs and procfs - the former for control and the latter for statistics. + +A sysfs directory called /sys/fs/fscache/<cachetag>/ is created if CONFIG_SYSFS +is enabled. This is accessible through the kobject struct fscache_cache::kobj +and is for use by the cache as it sees fit. + +The cache driver may create itself a directory named for the cache type in the +/proc/fs/fscache/ directory. This is available if CONFIG_FSCACHE_PROC is +enabled and is accessible through: + + struct proc_dir_entry *proc_fscache; + + +======================== +RELEVANT DATA STRUCTURES +======================== + + (*) Index/Data file FS-Cache representation cookie: + + struct fscache_cookie { + struct fscache_object_def *def; + struct fscache_netfs *netfs; + void *netfs_data; + ... + }; + + The fields that might be of use to the backend describe the object + definition, the netfs definition and the netfs's data for this cookie. + The object definition contain functions supplied by the netfs for loading + and matching index entries; these are required to provide some of the + cache operations. + + + (*) In-cache object representation: + + struct fscache_object { + int debug_id; + enum { + FSCACHE_OBJECT_RECYCLING, + ... + } state; + spinlock_t lock + struct fscache_cache *cache; + struct fscache_cookie *cookie; + ... + }; + + Structures of this type should be allocated by the cache backend and + passed to FS-Cache when requested by the appropriate cache operation. In + the case of CacheFS, they're embedded in CacheFS's internal object + structures. + + The debug_id is a simple integer that can be used in debugging messages + that refer to a particular object. In such a case it should be printed + using "OBJ%x" to be consistent with FS-Cache. + + Each object contains a pointer to the cookie that represents the object it + is backing. An object should retired when put_object() is called if it is + in state FSCACHE_OBJECT_RECYCLING. The fscache_object struct should be + initialised by calling fscache_object_init(object). + + + (*) FS-Cache operation record: + + struct fscache_operation { + atomic_t usage; + struct fscache_object *object; + unsigned long flags; + #define FSCACHE_OP_EXCLUSIVE + void (*processor)(struct fscache_operation *op); + void (*release)(struct fscache_operation *op); + ... + }; + + FS-Cache has a pool of threads that it uses to give CPU time to the + various asynchronous operations that need to be done as part of driving + the cache. These are represented by the above structure. The processor + method is called to give the op CPU time, and the release method to get + rid of it when its usage count reaches 0. + + An operation can be made exclusive upon an object by setting the + appropriate flag before enqueuing it with fscache_enqueue_operation(). If + an operation needs more processing time, it should be enqueued again. + + + (*) FS-Cache retrieval operation record: + + struct fscache_retrieval { + struct fscache_operation op; + struct address_space *mapping; + struct list_head *to_do; + ... + }; + + A structure of this type is allocated by FS-Cache to record retrieval and + allocation requests made by the netfs. This struct is then passed to the + backend to do the operation. The backend may get extra refs to it by + calling fscache_get_retrieval() and refs may be discarded by calling + fscache_put_retrieval(). + + A retrieval operation can be used by the backend to do retrieval work. To + do this, the retrieval->op.processor method pointer should be set + appropriately by the backend and fscache_enqueue_retrieval() called to + submit it to the thread pool. CacheFiles, for example, uses this to queue + page examination when it detects PG_lock being cleared. + + The to_do field is an empty list available for the cache backend to use as + it sees fit. + + + (*) FS-Cache storage operation record: + + struct fscache_storage { + struct fscache_operation op; + pgoff_t store_limit; + ... + }; + + A structure of this type is allocated by FS-Cache to record outstanding + writes to be made. FS-Cache itself enqueues this operation and invokes + the write_page() method on the object at appropriate times to effect + storage. + + +================ +CACHE OPERATIONS +================ + +The cache backend provides FS-Cache with a table of operations that can be +performed on the denizens of the cache. These are held in a structure of type: + + struct fscache_cache_ops + + (*) Name of cache provider [mandatory]: + + const char *name + + This isn't strictly an operation, but should be pointed at a string naming + the backend. + + + (*) Allocate a new object [mandatory]: + + struct fscache_object *(*alloc_object)(struct fscache_cache *cache, + struct fscache_cookie *cookie) + + This method is used to allocate a cache object representation to back a + cookie in a particular cache. fscache_object_init() should be called on + the object to initialise it prior to returning. + + This function may also be used to parse the index key to be used for + multiple lookup calls to turn it into a more convenient form. FS-Cache + will call the lookup_complete() method to allow the cache to release the + form once lookup is complete or aborted. + + + (*) Look up and create object [mandatory]: + + void (*lookup_object)(struct fscache_object *object) + + This method is used to look up an object, given that the object is already + allocated and attached to the cookie. This should instantiate that object + in the cache if it can. + + The method should call fscache_object_lookup_negative() as soon as + possible if it determines the object doesn't exist in the cache. If the + object is found to exist and the netfs indicates that it is valid then + fscache_obtained_object() should be called once the object is in a + position to have data stored in it. Similarly, fscache_obtained_object() + should also be called once a non-present object has been created. + + If a lookup error occurs, fscache_object_lookup_error() should be called + to abort the lookup of that object. + + + (*) Release lookup data [mandatory]: + + void (*lookup_complete)(struct fscache_object *object) + + This method is called to ask the cache to release any resources it was + using to perform a lookup. + + + (*) Increment object refcount [mandatory]: + + struct fscache_object *(*grab_object)(struct fscache_object *object) + + This method is called to increment the reference count on an object. It + may fail (for instance if the cache is being withdrawn) by returning NULL. + It should return the object pointer if successful. + + + (*) Lock/Unlock object [mandatory]: + + void (*lock_object)(struct fscache_object *object) + void (*unlock_object)(struct fscache_object *object) + + These methods are used to exclusively lock an object. It must be possible + to schedule with the lock held, so a spinlock isn't sufficient. + + + (*) Pin/Unpin object [optional]: + + int (*pin_object)(struct fscache_object *object) + void (*unpin_object)(struct fscache_object *object) + + These methods are used to pin an object into the cache. Once pinned an + object cannot be reclaimed to make space. Return -ENOSPC if there's not + enough space in the cache to permit this. + + + (*) Update object [mandatory]: + + int (*update_object)(struct fscache_object *object) + + This is called to update the index entry for the specified object. The + new information should be in object->cookie->netfs_data. This can be + obtained by calling object->cookie->def->get_aux()/get_attr(). + + + (*) Discard object [mandatory]: + + void (*drop_object)(struct fscache_object *object) + + This method is called to indicate that an object has been unbound from its + cookie, and that the cache should release the object's resources and + retire it if it's in state FSCACHE_OBJECT_RECYCLING. + + This method should not attempt to release any references held by the + caller. The caller will invoke the put_object() method as appropriate. + + + (*) Release object reference [mandatory]: + + void (*put_object)(struct fscache_object *object) + + This method is used to discard a reference to an object. The object may + be freed when all the references to it are released. + + + (*) Synchronise a cache [mandatory]: + + void (*sync)(struct fscache_cache *cache) + + This is called to ask the backend to synchronise a cache with its backing + device. + + + (*) Dissociate a cache [mandatory]: + + void (*dissociate_pages)(struct fscache_cache *cache) + + This is called to ask a cache to perform any page dissociations as part of + cache withdrawal. + + + (*) Notification that the attributes on a netfs file changed [mandatory]: + + int (*attr_changed)(struct fscache_object *object); + + This is called to indicate to the cache that certain attributes on a netfs + file have changed (for example the maximum size a file may reach). The + cache can read these from the netfs by calling the cookie's get_attr() + method. + + The cache may use the file size information to reserve space on the cache. + It should also call fscache_set_store_limit() to indicate to FS-Cache the + highest byte it's willing to store for an object. + + This method may return -ve if an error occurred or the cache object cannot + be expanded. In such a case, the object will be withdrawn from service. + + This operation is run asynchronously from FS-Cache's thread pool, and + storage and retrieval operations from the netfs are excluded during the + execution of this operation. + + + (*) Reserve cache space for an object's data [optional]: + + int (*reserve_space)(struct fscache_object *object, loff_t size); + + This is called to request that cache space be reserved to hold the data + for an object and the metadata used to track it. Zero size should be + taken as request to cancel a reservation. + + This should return 0 if successful, -ENOSPC if there isn't enough space + available, or -ENOMEM or -EIO on other errors. + + The reservation may exceed the current size of the object, thus permitting + future expansion. If the amount of space consumed by an object would + exceed the reservation, it's permitted to refuse requests to allocate + pages, but not required. An object may be pruned down to its reservation + size if larger than that already. + + + (*) Request page be read from cache [mandatory]: + + int (*read_or_alloc_page)(struct fscache_retrieval *op, + struct page *page, + gfp_t gfp) + + This is called to attempt to read a netfs page from the cache, or to + reserve a backing block if not. FS-Cache will have done as much checking + as it can before calling, but most of the work belongs to the backend. + + If there's no page in the cache, then -ENODATA should be returned if the + backend managed to reserve a backing block; -ENOBUFS or -ENOMEM if it + didn't. + + If there is suitable data in the cache, then a read operation should be + queued and 0 returned. When the read finishes, fscache_end_io() should be + called. + + The fscache_mark_pages_cached() should be called for the page if any cache + metadata is retained. This will indicate to the netfs that the page needs + explicit uncaching. This operation takes a pagevec, thus allowing several + pages to be marked at once. + + The retrieval record pointed to by op should be retained for each page + queued and released when I/O on the page has been formally ended. + fscache_get/put_retrieval() are available for this purpose. + + The retrieval record may be used to get CPU time via the FS-Cache thread + pool. If this is desired, the op->op.processor should be set to point to + the appropriate processing routine, and fscache_enqueue_retrieval() should + be called at an appropriate point to request CPU time. For instance, the + retrieval routine could be enqueued upon the completion of a disk read. + The to_do field in the retrieval record is provided to aid in this. + + If an I/O error occurs, fscache_io_error() should be called and -ENOBUFS + returned if possible or fscache_end_io() called with a suitable error + code.. + + + (*) Request pages be read from cache [mandatory]: + + int (*read_or_alloc_pages)(struct fscache_retrieval *op, + struct list_head *pages, + unsigned *nr_pages, + gfp_t gfp) + + This is like the read_or_alloc_page() method, except it is handed a list + of pages instead of one page. Any pages on which a read operation is + started must be added to the page cache for the specified mapping and also + to the LRU. Such pages must also be removed from the pages list and + *nr_pages decremented per page. + + If there was an error such as -ENOMEM, then that should be returned; else + if one or more pages couldn't be read or allocated, then -ENOBUFS should + be returned; else if one or more pages couldn't be read, then -ENODATA + should be returned. If all the pages are dispatched then 0 should be + returned. + + + (*) Request page be allocated in the cache [mandatory]: + + int (*allocate_page)(struct fscache_retrieval *op, + struct page *page, + gfp_t gfp) + + This is like the read_or_alloc_page() method, except that it shouldn't + read from the cache, even if there's data there that could be retrieved. + It should, however, set up any internal metadata required such that + the write_page() method can write to the cache. + + If there's no backing block available, then -ENOBUFS should be returned + (or -ENOMEM if there were other problems). If a block is successfully + allocated, then the netfs page should be marked and 0 returned. + + + (*) Request pages be allocated in the cache [mandatory]: + + int (*allocate_pages)(struct fscache_retrieval *op, + struct list_head *pages, + unsigned *nr_pages, + gfp_t gfp) + + This is an multiple page version of the allocate_page() method. pages and + nr_pages should be treated as for the read_or_alloc_pages() method. + + + (*) Request page be written to cache [mandatory]: + + int (*write_page)(struct fscache_storage *op, + struct page *page); + + This is called to write from a page on which there was a previously + successful read_or_alloc_page() call or similar. FS-Cache filters out + pages that don't have mappings. + + This method is called asynchronously from the FS-Cache thread pool. It is + not required to actually store anything, provided -ENODATA is then + returned to the next read of this page. + + If an error occurred, then a negative error code should be returned, + otherwise zero should be returned. FS-Cache will take appropriate action + in response to an error, such as withdrawing this object. + + If this method returns success then FS-Cache will inform the netfs + appropriately. + + + (*) Discard retained per-page metadata [mandatory]: + + void (*uncache_page)(struct fscache_object *object, struct page *page) + + This is called when a netfs page is being evicted from the pagecache. The + cache backend should tear down any internal representation or tracking it + maintains for this page. + + +================== +FS-CACHE UTILITIES +================== + +FS-Cache provides some utilities that a cache backend may make use of: + + (*) Note occurrence of an I/O error in a cache: + + void fscache_io_error(struct fscache_cache *cache) + + This tells FS-Cache that an I/O error occurred in the cache. After this + has been called, only resource dissociation operations (object and page + release) will be passed from the netfs to the cache backend for the + specified cache. + + This does not actually withdraw the cache. That must be done separately. + + + (*) Invoke the retrieval I/O completion function: + + void fscache_end_io(struct fscache_retrieval *op, struct page *page, + int error); + + This is called to note the end of an attempt to retrieve a page. The + error value should be 0 if successful and an error otherwise. + + + (*) Set highest store limit: + + void fscache_set_store_limit(struct fscache_object *object, + loff_t i_size); + + This sets the limit FS-Cache imposes on the highest byte it's willing to + try and store for a netfs. Any page over this limit is automatically + rejected by fscache_read_alloc_page() and co with -ENOBUFS. + + + (*) Mark pages as being cached: + + void fscache_mark_pages_cached(struct fscache_retrieval *op, + struct pagevec *pagevec); + + This marks a set of pages as being cached. After this has been called, + the netfs must call fscache_uncache_page() to unmark the pages. + + + (*) Perform coherency check on an object: + + enum fscache_checkaux fscache_check_aux(struct fscache_object *object, + const void *data, + uint16_t datalen); + + This asks the netfs to perform a coherency check on an object that has + just been looked up. The cookie attached to the object will determine the + netfs to use. data and datalen should specify where the auxiliary data + retrieved from the cache can be found. + + One of three values will be returned: + + (*) FSCACHE_CHECKAUX_OKAY + + The coherency data indicates the object is valid as is. + + (*) FSCACHE_CHECKAUX_NEEDS_UPDATE + + The coherency data needs updating, but otherwise the object is + valid. + + (*) FSCACHE_CHECKAUX_OBSOLETE + + The coherency data indicates that the object is obsolete and should + be discarded. + + + (*) Initialise a freshly allocated object: + + void fscache_object_init(struct fscache_object *object); + + This initialises all the fields in an object representation. + + + (*) Indicate the destruction of an object: + + void fscache_object_destroyed(struct fscache_cache *cache); + + This must be called to inform FS-Cache that an object that belonged to a + cache has been destroyed and deallocated. This will allow continuation + of the cache withdrawal process when it is stopped pending destruction of + all the objects. + + + (*) Indicate negative lookup on an object: + + void fscache_object_lookup_negative(struct fscache_object *object); + + This is called to indicate to FS-Cache that a lookup process for an object + found a negative result. + + This changes the state of an object to permit reads pending on lookup + completion to go off and start fetching data from the netfs server as it's + known at this point that there can't be any data in the cache. + + This may be called multiple times on an object. Only the first call is + significant - all subsequent calls are ignored. + + + (*) Indicate an object has been obtained: + + void fscache_obtained_object(struct fscache_object *object); + + This is called to indicate to FS-Cache that a lookup process for an object + produced a positive result, or that an object was created. This should + only be called once for any particular object. + + This changes the state of an object to indicate: + + (1) if no call to fscache_object_lookup_negative() has been made on + this object, that there may be data available, and that reads can + now go and look for it; and + + (2) that writes may now proceed against this object. + + + (*) Indicate that object lookup failed: + + void fscache_object_lookup_error(struct fscache_object *object); + + This marks an object as having encountered a fatal error (usually EIO) + and causes it to move into a state whereby it will be withdrawn as soon + as possible. + + + (*) Get and release references on a retrieval record: + + void fscache_get_retrieval(struct fscache_retrieval *op); + void fscache_put_retrieval(struct fscache_retrieval *op); + + These two functions are used to retain a retrieval record whilst doing + asynchronous data retrieval and block allocation. + + + (*) Enqueue a retrieval record for processing. + + void fscache_enqueue_retrieval(struct fscache_retrieval *op); + + This enqueues a retrieval record for processing by the FS-Cache thread + pool. One of the threads in the pool will invoke the retrieval record's + op->op.processor callback function. This function may be called from + within the callback function. + + + (*) List of object state names: + + const char *fscache_object_states[]; + + For debugging purposes, this may be used to turn the state that an object + is in into a text string for display purposes.
include/linux/fscache-cache.h new file +508 -0
508 lines not on this page · raw message
David Howells
maintainerPATCH 9/43 FS-Cache: Add main configuration option, module entry points and debugging [ver #46]
In reply to David HowellsAdd the main configuration option, allowing FS-Cache to be selected; the module entry and exit functions and the debugging stuff used by these patches.
The two configuration options added are:
CONFIG_FSCACHE
CONFIG_FSCACHE_DEBUG
The first enables the facility, and the second makes the debugging statements enableable through the "debug" module parameter. The value of this parameter is a bitmask as described in:
Documentation/filesystems/caching/fscache.txt
The module can be loaded at this point, but all it will do at this point in the patch series is to start up the slow work facility and shut it down again.
---
fs/Kconfig | 6 ++ fs/Makefile | 1 fs/fscache/Kconfig | 22 +++++++ fs/fscache/Makefile | 8 ++ fs/fscache/internal.h | 165 +++++++++++++++++++++++++++++++++++++++++++++++++ fs/fscache/main.c | 75 ++++++++++++++++++++++ 6 files changed, 277 insertions(+), 0 deletions(-) create mode 100644 fs/fscache/Kconfig create mode 100644 fs/fscache/Makefile create mode 100644 fs/fscache/internal.h create mode 100644 fs/fscache/main.c
fs/Kconfig +6 -0
@@ -66,6 +66,12 @@ config GENERIC_ACL bool select FS_POSIX_ACL +menu "Caches" + +source "fs/fscache/Kconfig" + +endmenu + if BLOCK menu "CD-ROM/DVD Filesystems"
fs/Makefile +1 -0
@@ -63,6 +63,7 @@ obj-$(CONFIG_PROFILING) += dcookies.o obj-$(CONFIG_DLM) += dlm/ # Do not add any filesystems before this line +obj-$(CONFIG_FSCACHE) += fscache/ obj-$(CONFIG_REISERFS_FS) += reiserfs/ obj-$(CONFIG_EXT3_FS) += ext3/ # Before ext2 so root fs can be ext3 obj-$(CONFIG_EXT2_FS) += ext2/
fs/fscache/Kconfig new file +22 -0
@@ -0,0 +1,22 @@ + +config FSCACHE + tristate "General filesystem local caching manager" + depends on EXPERIMENTAL + select SLOW_WORK + help + This option enables a generic filesystem caching manager that can be + used by various network and other filesystems to cache data locally. + Different sorts of caches can be plugged in, depending on the + resources available. + + See Documentation/filesystems/caching/fscache.txt for more information. + +config FSCACHE_DEBUG + bool "Debug FS-Cache" + depends on FSCACHE + help + This permits debugging to be dynamically enabled in the local caching + management module. If this is set, the debugging output may be + enabled by setting bits in /sys/modules/fscache/parameter/debug. + + See Documentation/filesystems/caching/fscache.txt for more information.
fs/fscache/Makefile new file +8 -0
@@ -0,0 +1,8 @@ +# +# Makefile for general filesystem caching code +# + +fscache-y := \ + main.o + +obj-$(CONFIG_FSCACHE) := fscache.o
fs/fscache/internal.h new file +165 -0
165 lines not on this page · raw message
fs/fscache/main.c new file +75 -0
75 lines not on this page · raw message
David Howells
maintainerPATCH 10/43 FS-Cache: Add use of /proc and presentation of statistics [ver #46]
In reply to David HowellsMake FS-Cache create its /proc interface and present various statistical information through it. Also provide the functions for updating this information.
These features are enabled by:
CONFIG_FSCACHE_PROC
CONFIG_FSCACHE_STATS
CONFIG_FSCACHE_HISTOGRAM
The /proc directory for FS-Cache is also exported so that caching modules can add their own statistics there too.
The FS-Cache module is loadable at this point, and the statistics files can be examined by userspace:
cat /proc/fs/fscache/stats
cat /proc/fs/fscache/histogram
---
Documentation/filesystems/caching/backend-api.txt | 6 - Documentation/filesystems/caching/fscache.txt | 12 - fs/fscache/Kconfig | 34 +++ fs/fscache/Makefile | 4 fs/fscache/histogram.c | 109 +++++++++++ fs/fscache/internal.h | 127 +++++++++++++ fs/fscache/main.c | 7 + fs/fscache/proc.c | 68 +++++++ fs/fscache/stats.c | 212 +++++++++++++++++++++ include/linux/fscache-cache.h | 4 10 files changed, 566 insertions(+), 17 deletions(-) create mode 100644 fs/fscache/histogram.c create mode 100644 fs/fscache/proc.c create mode 100644 fs/fscache/stats.c
Documentation/filesystems/caching/backend-api.txt +0 -6
@@ -100,12 +100,6 @@ A sysfs directory called /sys/fs/fscache/<cachetag>/ is created if CONFIG_SYSFS is enabled. This is accessible through the kobject struct fscache_cache::kobj and is for use by the cache as it sees fit. -The cache driver may create itself a directory named for the cache type in the -/proc/fs/fscache/ directory. This is available if CONFIG_FSCACHE_PROC is -enabled and is accessible through: - - struct proc_dir_entry *proc_fscache; - ======================== RELEVANT DATA STRUCTURES
Documentation/filesystems/caching/fscache.txt +5 -7
@@ -195,7 +195,6 @@ STATISTICAL INFORMATION If FS-Cache is compiled with the following options enabled: - CONFIG_FSCACHE_PROC=y (implied by the following two) CONFIG_FSCACHE_STATS=y CONFIG_FSCACHE_HISTOGRAM=y
@@ -275,7 +274,7 @@ proc files. (*) /proc/fs/fscache/histogram cat /proc/fs/fscache/histogram - +HZ +TIME OBJ INST OP RUNS OBJ RUNS RETRV DLY RETRIEVLS + JIFS SECS OBJ INST OP RUNS OBJ RUNS RETRV DLY RETRIEVLS ===== ===== ========= ========= ========= ========= ========= This shows the breakdown of the number of times each amount of time
@@ -291,16 +290,16 @@ proc files. RETRIEVLS Time between beginning and end of a retrieval Each row shows the number of events that took a particular range of times. - Each step is 1 jiffy in size. The +HZ column indicates the particular - jiffy range covered, and the +TIME field the equivalent number of seconds. + Each step is 1 jiffy in size. The JIFS column indicates the particular + jiffy range covered, and the SECS field the equivalent number of seconds. ========= DEBUGGING ========= -The FS-Cache facility can have runtime debugging enabled by adjusting the value -in: +If CONFIG_FSCACHE_DEBUG is enabled, the FS-Cache facility can have runtime +debugging enabled by adjusting the value in: /sys/module/fscache/parameters/debug
@@ -327,4 +326,3 @@ the control file. For example: echo $((1|8|64)) >/sys/module/fscache/parameters/debug will turn on all function entry debugging. -
fs/fscache/Kconfig +34 -0
@@ -11,6 +11,40 @@ config FSCACHE See Documentation/filesystems/caching/fscache.txt for more information. +config FSCACHE_STATS + bool "Gather statistical information on local caching" + depends on FSCACHE && PROC_FS + help + This option causes statistical information to be gathered on local + caching and exported through file: + + /proc/fs/fscache/stats + + The gathering of statistics adds a certain amount of overhead to + execution as there are a quite a few stats gathered, and on a + multi-CPU system these may be on cachelines that keep bouncing + between CPUs. On the other hand, the stats are very useful for + debugging purposes. Saying 'Y' here is recommended. + + See Documentation/filesystems/caching/fscache.txt for more information. + +config FSCACHE_HISTOGRAM + bool "Gather latency information on local caching" + depends on FSCACHE && PROC_FS + help + This option causes latency information to be gathered on local + caching and exported through file: + + /proc/fs/fscache/histogram + + The generation of this histogram adds a certain amount of overhead to + execution as there are a number of points at which data is gathered, + and on a multi-CPU system these may be on cachelines that keep + bouncing between CPUs. On the other hand, the histogram may be + useful for debugging purposes. Saying 'N' here is recommended. + + See Documentation/filesystems/caching/fscache.txt for more information. + config FSCACHE_DEBUG bool "Debug FS-Cache" depends on FSCACHE
fs/fscache/Makefile +4 -0
@@ -5,4 +5,8 @@ fscache-y := \ main.o +fscache-$(CONFIG_PROC_FS) += proc.o +fscache-$(CONFIG_FSCACHE_STATS) += stats.o +fscache-$(CONFIG_FSCACHE_HISTOGRAM) += histogram.o + obj-$(CONFIG_FSCACHE) := fscache.o
fs/fscache/histogram.c new file +109 -0
109 lines not on this page · raw message
fs/fscache/internal.h +127 -0
139 lines not on this page · raw message
fs/fscache/main.c +7 -0
@@ -52,9 +52,15 @@ static int __init fscache_init(void)if (ret <0 ) goto error_slow_work; + ret =fscache_proc_init (); +if (ret <0 ) + goto error_proc; +printk (KERN_NOTICE "FS-Cache: Loaded\n" );return 0 ; +error_proc: +slow_work_unregister_user (); error_slow_work:return ret; }
@@ -68,6 +74,7 @@ static void __exit fscache_exit(void) {_enter ("" ); +fscache_proc_cleanup ();slow_work_unregister_user ();printk (KERN_NOTICE "FS-Cache: Unloaded\n" ); }
fs/fscache/proc.c new file +68 -0
68 lines not on this page · raw message
fs/fscache/stats.c new file +212 -0
212 lines not on this page · raw message
include/linux/fscache-cache.h +0 -4
@@ -29,10 +29,6 @@ struct fscache_cache_ops;struct fscache_object ;struct fscache_operation ; -#ifdef CONFIG_FSCACHE_PROC -extern struct proc_dir_entry *proc_fscache; -#endif -/* * cache tag definition */
David Howells
maintainerPATCH 11/43 FS-Cache: Root index definition [ver #46]
In reply to David HowellsAdd a description of the root index of the cache for later patches to make use of.
The root index is owned by FS-Cache itself. When a netfs requests caching facilities, FS-Cache will, if one doesn't already exist, create an entry in the root index with the key being the name of the netfs ("AFS" for example), and the auxiliary data holding the index structure version supplied by the netfs:
FSDEF | +-----------+ | | NFS AFS [v=1] [v=1]
If an entry with the appropriate name does already exist, the version is compared. If the version is different, the entire subtree from that entry will be discarded and a new entry created.
The new entry will be an index, and a cookie referring to it will be passed to the netfs. This is then the root handle by which the netfs accesses the cache. It can create whatever objects it likes in that index, including further indices.
---
fs/fscache/Makefile | 1 fs/fscache/fsdef.c | 144 +++++++++++++++++++++++++++++++++++++++++++++++++ fs/fscache/internal.h | 6 ++ 3 files changed, 151 insertions(+), 0 deletions(-) create mode 100644 fs/fscache/fsdef.c
fs/fscache/Makefile +1 -0
@@ -3,6 +3,7 @@ # fscache-y := \ + fsdef.o \ main.o fscache-$(CONFIG_PROC_FS) += proc.o
fs/fscache/fsdef.c new file +144 -0
144 lines not on this page · raw message
fs/fscache/internal.h +6 -0
@@ -28,6 +28,12 @@#define FSCACHE_MAX_THREADS 32/* +* fsc-fsdef.c +*/ +extern struct fscache_cookie fscache_fsdef_index; +extern struct fscache_cookie_def fscache_fsdef_netfs_def; + +/* * fsc-histogram.c */ #ifdef CONFIG_FSCACHE_HISTOGRAM
David Howells
maintainerPATCH 12/43 FS-Cache: Add cache tag handling [ver #46]
In reply to David HowellsImplement two features of FS-Cache:
(1) The ability to request and release cache tags - names by which a cache may be known to a netfs, and thus selected for use.
(2) An internal function by which a cache is selected by consulting the netfs, if the netfs wishes to be consulted.
---
fs/fscache/Makefile | 1 fs/fscache/cache.c | 166 +++++++++++++++++++++++++++++++++++++++++++++++ fs/fscache/internal.h | 20 ++++++ include/linux/fscache.h | 9 ++- 4 files changed, 195 insertions(+), 1 deletions(-) create mode 100644 fs/fscache/cache.c
fs/fscache/Makefile +1 -0
@@ -3,6 +3,7 @@ # fscache-y := \ + cache.o \ fsdef.o \ main.o
fs/fscache/cache.c new file +166 -0
166 lines not on this page · raw message
fs/fscache/internal.h +20 -0
@@ -28,6 +28,15 @@#define FSCACHE_MAX_THREADS 32/* +* fsc-cache.c +*/ +extern struct list_head fscache_cache_list; +extern struct rw_semaphore fscache_addremove_sem; + +extern struct fscache_cache *fscache_select_cache_for_object ( +struct fscache_cookie *); + +/* * fsc-fsdef.c */ extern struct fscache_cookie fscache_fsdef_index;
@@ -168,6 +177,17 @@ extern const struct file_operations fscache_stats_fops;#define fscache_stat (stat) do {} while (0)#endif +/* +* raise an event on an object +* - if the event is not masked for that object, then the object is +* queued for attention by the thread pool. +*/ +static inline void fscache_raise_event (struct fscache_object *object, +unsigned event) +{ +BUG ();// TODO +} +/*****************************************************************************/ /* * debug tracing
include/linux/fscache.h +8 -1
@@ -187,6 +187,8 @@ struct fscache_netfs {* - these are undefined symbols when FS-Cache is not configured and the * optimiser takes care of not using them */ +extern struct fscache_cache_tag *__fscache_lookup_cache_tag (const char *); +extern void __fscache_release_cache_tag (struct fscache_cache_tag *);/** * fscache_register_netfs - Register a filesystem as desiring caching services
@@ -232,7 +234,10 @@ void fscache_unregister_netfs(struct fscache_netfs *netfs)static inline struct fscache_cache_tag *fscache_lookup_cache_tag (const char *name) { -return NULL ; +if (fscache_available ()) +return __fscache_lookup_cache_tag (name); +else +return NULL ; }/**
@@ -247,6 +252,8 @@ struct fscache_cache_tag *fscache_lookup_cache_tag(const char *name)static inline void fscache_release_cache_tag (struct fscache_cache_tag *tag) { +if (fscache_available ()) +__fscache_release_cache_tag (tag); }/**
David Howells
maintainerPATCH 13/43 FS-Cache: Add cache management [ver #46]
In reply to David HowellsImplement the entry points by which a cache backend may initialise, add, declare an error upon and withdraw a cache.
Further, an object is created in sysfs under which each cache added will get an object created:
/sys/fs/fscache/<cachetag>/
All of this is described in Documentation/filesystems/caching/backend-api.txt added by a previous patch.
---
fs/fscache/cache.c | 249 ++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/fscache/main.c | 7 + 2 files changed, 256 insertions(+), 0 deletions(-)
fs/fscache/cache.c +249 -0
@@ -16,6 +16,8 @@LIST_HEAD (fscache_cache_list);DECLARE_RWSEM (fscache_addremove_sem); +DECLARE_WAIT_QUEUE_HEAD (fscache_cache_cleared_wq); +EXPORT_SYMBOL (fscache_cache_cleared_wq);static LIST_HEAD (fscache_cache_tag_list);
@@ -164,3 +166,250 @@ no_preference:_leave (" = %p [first]" , cache);return cache; } + +/** +* fscache_init_cache - Initialise a cache record +* @cache: The cache record to be initialised +* @ops: The cache operations to be installed in that record +* @idfmt: Format string to define identifier +* @...: sprintf-style arguments +* +* Initialise a record of a cache and fill in the name. +* +* See Documentation/filesystems/caching/backend-api.txt for a complete +* description. +*/ +void fscache_init_cache (struct fscache_cache *cache, +const struct fscache_cache_ops *ops, +const char *idfmt, + ...) +{ +va_list va; + +memset (cache,0 ,sizeof (*cache)); + + cache->ops = ops; + +va_start (va, idfmt); +vsnprintf (cache->identifier,sizeof (cache->identifier), idfmt, va); +va_end (va); + +INIT_WORK (&cache->op_gc,NULL ); +INIT_LIST_HEAD (&cache->link); +INIT_LIST_HEAD (&cache->object_list); +INIT_LIST_HEAD (&cache->op_gc_list); +spin_lock_init (&cache->object_list_lock); +spin_lock_init (&cache->op_gc_list_lock); +} +EXPORT_SYMBOL (fscache_init_cache); + +/** +* fscache_add_cache - Declare a cache as being open for business +* @cache: The record describing the cache +* @ifsdef: The record of the cache object describing the top-level index +* @tagname: The tag describing this cache +* +* Add a cache to the system, making it available for netfs's to use. +* +* See Documentation/filesystems/caching/backend-api.txt for a complete +* description. +*/ +int fscache_add_cache (struct fscache_cache *cache, +struct fscache_object *ifsdef, +const char *tagname) +{ +struct fscache_cache_tag *tag; + +BUG_ON (!cache->ops); +BUG_ON (!ifsdef); + + cache->flags =0 ; + ifsdef->event_mask =ULONG_MAX & ~(1 <<FSCACHE_OBJECT_EV_CLEARED ); + ifsdef->state =FSCACHE_OBJECT_ACTIVE ; + +if (!tagname) + tagname = cache->identifier; + +BUG_ON (!tagname[0 ]); + +_enter ("{%s.%s},,%s" , cache->ops->name, cache->identifier, tagname); + +/* we use the cache tag to uniquely identify caches */ + tag =__fscache_lookup_cache_tag (tagname); +if (IS_ERR (tag)) + goto nomem; + +if (test_and_set_bit (FSCACHE_TAG_RESERVED , &tag->flags)) + goto tag_in_use; + + cache->kobj =kobject_create_and_add (tagname, fscache_root); +if (!cache->kobj) + goto error; + + ifsdef->cookie = &fscache_fsdef_index; + ifsdef->cache = cache; + cache->fsdef = ifsdef; + +down_write (&fscache_addremove_sem); + + tag->cache = cache; + cache->tag = tag; + +/* add the cache to the list */ +list_add (&cache->link, &fscache_cache_list); + +/* add the cache's netfs definition index object to the cache's +* list */ +spin_lock (&cache->object_list_lock); +list_add_tail (&ifsdef->cache_link, &cache->object_list); +spin_unlock (&cache->object_list_lock); + +/* add the cache's netfs definition index object to the top level index +* cookie as a known backing object */ +spin_lock (&fscache_fsdef_index.lock); + +hlist_add_head (&ifsdef->cookie_link, + &fscache_fsdef_index.backing_objects); + +atomic_inc (&fscache_fsdef_index.usage); + +/* done */ +spin_unlock (&fscache_fsdef_index.lock); +up_write (&fscache_addremove_sem); + +printk (KERN_NOTICE "FS-Cache: Cache \"%s\" added (type %s)\n" , + cache->tag->name, cache->ops->name); +kobject_uevent (cache->kobj,KOBJ_ADD ); + +_leave (" = 0 [%s]" , cache->identifier); +return 0 ; + +tag_in_use: +printk (KERN_ERR "FS-Cache: Cache tag '%s' already in use\n" , tagname); +__fscache_release_cache_tag (tag); +_leave (" = -EXIST" ); +return -EEXIST ; + +error: +__fscache_release_cache_tag (tag); +_leave (" = -EINVAL" ); +return -EINVAL ; + +nomem: +_leave (" = -ENOMEM" ); +return -ENOMEM ; +} +EXPORT_SYMBOL (fscache_add_cache); + +/** +* fscache_io_error - Note a cache I/O error +* @cache: The record describing the cache +* +* Note that an I/O error occurred in a cache and that it should no longer be +* used for anything. This also reports the error into the kernel log. +* +* See Documentation/filesystems/caching/backend-api.txt for a complete +* description. +*/ +void fscache_io_error (struct fscache_cache *cache) +{ +set_bit (FSCACHE_IOERROR , &cache->flags); + +printk (KERN_ERR "FS-Cache: Cache %s stopped due to I/O error\n" , + cache->ops->name); +} +EXPORT_SYMBOL (fscache_io_error); + +/* +* request withdrawal of all the objects in a cache +* - all the objects being withdrawn are moved onto the supplied list +*/ +static void fscache_withdraw_all_objects (struct fscache_cache *cache, +struct list_head *dying_objects) +{ +struct fscache_object *object; + +spin_lock (&cache->object_list_lock); + +while (!list_empty (&cache->object_list)) { + object =list_entry (cache->object_list.next, + struct fscache_object, cache_link); +list_move_tail (&object->cache_link, dying_objects); + +_debug ("withdraw %p" , object->cookie); + +spin_lock (&object->lock); +spin_unlock (&cache->object_list_lock); +fscache_raise_event (object,FSCACHE_OBJECT_EV_WITHDRAW ); +spin_unlock (&object->lock); + +cond_resched (); +spin_lock (&cache->object_list_lock); + } + +spin_unlock (&cache->object_list_lock); +} + +/** +* fscache_withdraw_cache - Withdraw a cache from the active service +* @cache: The record describing the cache +* +* Withdraw a cache from service, unbinding all its cache objects from the +* netfs cookies they're currently representing. +* +* See Documentation/filesystems/caching/backend-api.txt for a complete +* description. +*/ +void fscache_withdraw_cache (struct fscache_cache *cache) +{ +LIST_HEAD (dying_objects); + +_enter ("" ); + +printk (KERN_NOTICE "FS-Cache: Withdrawing cache \"%s\"\n" , + cache->tag->name); + +/* make the cache unavailable for cookie acquisition */ +if (test_and_set_bit (FSCACHE_CACHE_WITHDRAWN , &cache->flags)) +BUG (); + +down_write (&fscache_addremove_sem); +list_del_init (&cache->link); + cache->tag->cache =NULL ; +up_write (&fscache_addremove_sem); + +/* make sure all pages pinned by operations on behalf of the netfs are +* written to disk */ + cache->ops->sync_cache (cache); + +/* dissociate all the netfs pages backed by this cache from the block +* mappings in the cache */ + cache->ops->dissociate_pages (cache); + +/* we now have to destroy all the active objects pertaining to this +* cache - which we do by passing them off to thread pool to be +* disposed of */ +_debug ("destroy" ); + +fscache_withdraw_all_objects (cache, &dying_objects); + +/* wait for all extant objects to finish their outstanding operations +* and go away */ +_debug ("wait for finish" ); +wait_event (fscache_cache_cleared_wq, +atomic_read (&cache->object_count) ==0 ); +_debug ("wait for clearance" ); +wait_event (fscache_cache_cleared_wq, +list_empty (&cache->object_list)); +_debug ("cleared" ); +ASSERT (list_empty (&dying_objects)); + +kobject_put (cache->kobj); + +clear_bit (FSCACHE_TAG_RESERVED , &cache->tag->flags); +fscache_release_cache_tag (cache->tag); + cache->tag =NULL ; + +_leave ("" ); +} +EXPORT_SYMBOL (fscache_withdraw_cache);
fs/fscache/main.c +7 -0
@@ -56,9 +56,15 @@ static int __init fscache_init(void)if (ret <0 ) goto error_proc; + fscache_root =kobject_create_and_add ("fscache" , kernel_kobj); +if (!fscache_root) + goto error_kobj; +printk (KERN_NOTICE "FS-Cache: Loaded\n" );return 0 ; +error_kobj: +fscache_proc_cleanup (); error_proc:slow_work_unregister_user (); error_slow_work:
@@ -74,6 +80,7 @@ static void __exit fscache_exit(void) {_enter ("" ); +kobject_put (fscache_root);fscache_proc_cleanup ();slow_work_unregister_user ();printk (KERN_NOTICE "FS-Cache: Unloaded\n" );
David Howells
maintainerPATCH 14/43 FS-Cache: Provide a slab for cookie allocation [ver #46]
In reply to David HowellsProvide a slab from which can be allocated the FS-Cache cookies that will be presented to the netfs.
Also provide a slab constructor and a function to recursively discard a cookie and its ancestor chain.
---
fs/fscache/Makefile | 1 + fs/fscache/cookie.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++ fs/fscache/internal.h | 8 +++++++ fs/fscache/main.c | 15 +++++++++++++ 4 files changed, 80 insertions(+), 0 deletions(-) create mode 100644 fs/fscache/cookie.c
fs/fscache/Makefile +1 -0
@@ -4,6 +4,7 @@ fscache-y := \ cache.o \ + cookie.o \ fsdef.o \ main.o
fs/fscache/cookie.c new file +56 -0
56 lines not on this page · raw message
fs/fscache/internal.h +8 -0
@@ -37,6 +37,14 @@ extern struct fscache_cache *fscache_select_cache_for_object( struct fscache_cookie *);/* +* fsc-cookie.c +*/ +extern struct kmem_cache *fscache_cookie_jar; + +extern void fscache_cookie_init_once (void *); +extern void __fscache_cookie_put (struct fscache_cookie *); + +/* * fsc-fsdef.c */ extern struct fscache_cookie fscache_fsdef_index;
fs/fscache/main.c +15 -0
@@ -56,6 +56,18 @@ static int __init fscache_init(void)if (ret <0 ) goto error_proc; + fscache_cookie_jar =kmem_cache_create ("fscache_cookie_jar" , +sizeof (struct fscache_cookie ), +0 , +0 , + fscache_cookie_init_once); +if (!fscache_cookie_jar) { +printk (KERN_NOTICE +"FS-Cache: Failed to allocate a cookie jar\n" ); + ret = -ENOMEM ; + goto error_cookie_jar; + } + fscache_root =kobject_create_and_add ("fscache" , kernel_kobj);if (!fscache_root) goto error_kobj;
@@ -64,6 +76,8 @@ static int __init fscache_init(void)return 0 ; error_kobj: +kmem_cache_destroy (fscache_cookie_jar); +error_cookie_jar:fscache_proc_cleanup (); error_proc:slow_work_unregister_user ();
@@ -81,6 +95,7 @@ static void __exit fscache_exit(void)_enter ("" );kobject_put (fscache_root); +kmem_cache_destroy (fscache_cookie_jar);fscache_proc_cleanup ();slow_work_unregister_user ();printk (KERN_NOTICE "FS-Cache: Unloaded\n" );
David Howells
maintainerPATCH 15/43 FS-Cache: Add netfs registration [ver #46]
In reply to David HowellsAdd functions to register and unregister a network filesystem or other client of the FS-Cache service. This allocates and releases the cookie representing the top-level index for a netfs, and makes it available to the netfs.
If the FS-Cache facility is disabled, then the calls are optimised away at compile time.
Note that whilst this patch may appear to work with FS-Cache enabled and a netfs attempting to use it, it will leak the cookie it allocates for the netfs as fscache_relinquish_cookie() is implemented in a later patch. This will cause the slab code to emit a warning when the module is removed.
---
fs/fscache/Makefile | 3 + fs/fscache/netfs.c | 103 +++++++++++++++++++++++++++++++++++++++++++++++ include/linux/fscache.h | 9 ++++ 3 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 fs/fscache/netfs.c
fs/fscache/Makefile +2 -1
@@ -6,7 +6,8 @@ fscache-y := \ cache.o \ cookie.o \ fsdef.o \ - main.o + main.o \ + netfs.o fscache-$(CONFIG_PROC_FS) += proc.o fscache-$(CONFIG_FSCACHE_STATS) += stats.o
fs/fscache/netfs.c new file +103 -0
103 lines not on this page · raw message
include/linux/fscache.h +8 -1
@@ -187,6 +187,8 @@ struct fscache_netfs {* - these are undefined symbols when FS-Cache is not configured and the * optimiser takes care of not using them */ +extern int __fscache_register_netfs (struct fscache_netfs *); +extern void __fscache_unregister_netfs (struct fscache_netfs *);extern struct fscache_cache_tag *__fscache_lookup_cache_tag (const char *);extern void __fscache_release_cache_tag (struct fscache_cache_tag *);
@@ -202,7 +204,10 @@ extern void __fscache_release_cache_tag(struct fscache_cache_tag *);static inline int fscache_register_netfs (struct fscache_netfs *netfs) { -return 0 ; +if (fscache_available ()) +return __fscache_register_netfs (netfs); +else +return 0 ; }/**
@@ -219,6 +224,8 @@ int fscache_register_netfs(struct fscache_netfs *netfs)static inline void fscache_unregister_netfs (struct fscache_netfs *netfs) { +if (fscache_available ()) +__fscache_unregister_netfs (netfs); }/**
David Howells
maintainerPATCH 16/43 FS-Cache: Bit waiting helpers [ver #46]
In reply to David HowellsAdd helpers for use with wait_on_bit().
---
fs/fscache/internal.h | 3 +++ fs/fscache/main.c | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 0 deletions(-)
fs/fscache/internal.h +3 -0
@@ -82,6 +82,9 @@ extern unsigned fscache_defer_create;extern unsigned fscache_debug;extern struct kobject *fscache_root; +extern int fscache_wait_bit (void *); +extern int fscache_wait_bit_interruptible (void *); +/* * fsc-proc.c */
fs/fscache/main.c +20 -0
@@ -102,3 +102,23 @@ static void __exit fscache_exit(void) }module_exit (fscache_exit); + +/* +* wait_on_bit() sleep function for uninterruptible waiting +*/ +int fscache_wait_bit (void *flags) +{ +schedule (); +return 0 ; +} +EXPORT_SYMBOL (fscache_wait_bit); + +/* +* wait_on_bit() sleep function for interruptible waiting +*/ +int fscache_wait_bit_interruptible (void *flags) +{ +schedule (); +return signal_pending (current); +} +EXPORT_SYMBOL (fscache_wait_bit_interruptible);
David Howells
maintainerPATCH 17/43 FS-Cache: Object management state machine [ver #46]
In reply to David HowellsImplement the cache object management state machine.
The following documentation is added to illuminate the working of this state machine. It will also be added as:
Documentation/filesystems/caching/object.txt ==================================================== IN-KERNEL CACHE OBJECT REPRESENTATION AND MANAGEMENT ====================================================
==============
REPRESENTATION
==============
FS-Cache maintains an in-kernel representation of each object that a netfs is currently interested in. Such objects are represented by the fscache_cookie struct and are referred to as cookies.
FS-Cache also maintains a separate in-kernel representation of the objects that a cache backend is currently actively caching. Such objects are represented by the fscache_object struct. The cache backends allocate these upon request, and are expected to embed them in their own representations. These are referred to as objects.
There is a 1:N relationship between cookies and objects. A cookie may be represented by multiple objects - an index may exist in more than one cache - or even by no objects (it may not be cached).
Furthermore, both cookies and objects are hierarchical. The two hierarchies correspond, but the cookies tree is a superset of the union of the object trees of multiple caches:
NETFS INDEX TREE : CACHE 1 : CACHE 2 : : : +-----------+ : +----------->| IObject | : +-----------+ | : +-----------+ : | ICookie |-------+ : | : +-----------+ | : | : +-----------+ | +------------------------------>| IObject | | : | : +-----------+ | : V : | | : +-----------+ : | V +----------->| IObject | : | +-----------+ | : +-----------+ : | | ICookie |-------+ : | : V +-----------+ | : | : +-----------+ | +------------------------------>| IObject | +-----+-----+ : | : +-----------+ | | : | : | V | : V : | +-----------+ | : +-----------+ : | | ICookie |------------------------->| IObject | : | +-----------+ | : +-----------+ : | | V : | : V | +-----------+ : | : +-----------+ | | ICookie |-------------------------------->| IObject | | +-----------+ : | : +-----------+ V | : V : | +-----------+ | : +-----------+ : | | DCookie |------------------------->| DObject | : | +-----------+ | : +-----------+ : | | : : | +-------+-------+ : : | | | : : | V V : : V +-----------+ +-----------+ : : +-----------+ | DCookie | | DCookie |------------------------>| DObject | +-----------+ +-----------+ : : +-----------+ : :
In the above illustration, ICookie and IObject represent indices and DCookie and DObject represent data storage objects. Indices may have representation in multiple caches, but currently, non-index objects may not. Objects of any type may also be entirely unrepresented.
As far as the netfs API goes, the netfs is only actually permitted to see pointers to the cookies. The cookies themselves and any objects attached to those cookies are hidden from it.
===============================
OBJECT MANAGEMENT STATE MACHINE
===============================
Within FS-Cache, each active object is managed by its own individual state machine. The state for an object is kept in the fscache_object struct, in object->state. A cookie may point to a set of objects that are in different states.
Each state has an action associated with it that is invoked when the machine wakes up in that state. There are four logical sets of states:
(1) Preparation: states that wait for the parent objects to become ready. The representations are hierarchical, and it is expected that an object must be created or accessed with respect to its parent object.
(2) Initialisation: states that perform lookups in the cache and validate what's found and that create on disk any missing metadata.
(3) Normal running: states that allow netfs operations on objects to proceed and that update the state of objects.
(4) Termination: states that detach objects from their netfs cookies, that delete objects from disk, that handle disk and system errors and that free up in-memory resources.
In most cases, transitioning between states is in response to signalled events. When a state has finished processing, it will usually set the mask of events in which it is interested (object->event_mask) and relinquish the worker thread. Then when an event is raised (by calling fscache_raise_event()), if the event is not masked, the object will be queued for processing (by calling fscache_enqueue_object()).
PROVISION OF CPU TIME
---------------------
The work to be done by the various states is given CPU time by the threads of the slow work facility (see Documentation/slow-work.txt). This is used in preference to the workqueue facility because:
(1) Threads may be completely occupied for very long periods of time by a particular work item. These state actions may be doing sequences of synchronous, journalled disk accesses (lookup, mkdir, create, setxattr, getxattr, truncate, unlink, rmdir, rename).
(2) Threads may do little actual work, but may rather spend a lot of time sleeping on I/O. This means that single-threaded and 1-per-CPU-threaded workqueues don't necessarily have the right numbers of threads.
LOCKING SIMPLIFICATION
----------------------
Because only one worker thread may be operating on any particular object's state machine at once, this simplifies the locking, particularly with respect to disconnecting the netfs's representation of a cache object (fscache_cookie) from the cache backend's representation (fscache_object) - which may be requested from either end.
=================
THE SET OF STATES
=================
The object state machine has a set of states that it can be in. There are preparation states in which the object sets itself up and waits for its parent object to transit to a state that allows access to its children:
(1) State FSCACHE_OBJECT_INIT.
Initialise the object and wait for the parent object to become active. In the cache, it is expected that it will not be possible to look an object up from the parent object, until that parent object itself has been looked up.
There are initialisation states in which the object sets itself up and accesses disk for the object metadata:
(2) State FSCACHE_OBJECT_LOOKING_UP.
Look up the object on disk, using the parent as a starting point. FS-Cache expects the cache backend to probe the cache to see whether this object is represented there, and if it is, to see if it's valid (coherency management).
The cache should call fscache_object_lookup_negative() to indicate lookup failure for whatever reason, and should call fscache_obtained_object() to indicate success.
At the completion of lookup, FS-Cache will let the netfs go ahead with read operations, no matter whether the file is yet cached. If not yet cached, read operations will be immediately rejected with ENODATA until the first known page is uncached - as to that point there can be no data to be read out of the cache for that file that isn't currently also held in the pagecache.
(3) State FSCACHE_OBJECT_CREATING.
Create an object on disk, using the parent as a starting point. This happens if the lookup failed to find the object, or if the object's coherency data indicated what's on disk is out of date. In this state, FS-Cache expects the cache to create
The cache should call fscache_obtained_object() if creation completes successfully, fscache_object_lookup_negative() otherwise.
At the completion of creation, FS-Cache will start processing write operations the netfs has queued for an object. If creation failed, the write ops will be transparently discarded, and nothing recorded in the cache.
There are some normal running states in which the object spends its time servicing netfs requests:
(4) State FSCACHE_OBJECT_AVAILABLE.
A transient state in which pending operations are started, child objects are permitted to advance from FSCACHE_OBJECT_INIT state, and temporary lookup data is freed.
(5) State FSCACHE_OBJECT_ACTIVE.
The normal running state. In this state, requests the netfs makes will be passed on to the cache.
(6) State FSCACHE_OBJECT_UPDATING.
The state machine comes here to update the object in the cache from the netfs's records. This involves updating the auxiliary data that is used to maintain coherency.
And there are terminal states in which an object cleans itself up, deallocates memory and potentially deletes stuff from disk:
(7) State FSCACHE_OBJECT_LC_DYING.
The object comes here if it is dying because of a lookup or creation error. This would be due to a disk error or system error of some sort. Temporary data is cleaned up, and the parent is released.
(8) State FSCACHE_OBJECT_DYING.
The object comes here if it is dying due to an error, because its parent cookie has been relinquished by the netfs or because the cache is being withdrawn.
Any child objects waiting on this one are given CPU time so that they too can destroy themselves. This object waits for all its children to go away before advancing to the next state.
(9) State FSCACHE_OBJECT_ABORT_INIT.
The object comes to this state if it was waiting on its parent in FSCACHE_OBJECT_INIT, but its parent died. The object will destroy itself so that the parent may proceed from the FSCACHE_OBJECT_DYING state.
(10) State FSCACHE_OBJECT_RELEASING.
(11) State FSCACHE_OBJECT_RECYCLING.
The object comes to one of these two states when dying once it is rid of all its children, if it is dying because the netfs relinquished its cookie. In the first state, the cached data is expected to persist, and in the second it will be deleted.
(12) State FSCACHE_OBJECT_WITHDRAWING.
The object transits to this state if the cache decides it wants to withdraw the object from service, perhaps to make space, but also due to error or just because the whole cache is being withdrawn.
(13) State FSCACHE_OBJECT_DEAD.
The object transits to this state when the in-memory object record is ready to be deleted. The object processor shouldn't ever see an object in this state.
THE SET OF EVENTS
-----------------
There are a number of events that can be raised to an object state machine:
(*) FSCACHE_OBJECT_EV_UPDATE
The netfs requested that an object be updated. The state machine will ask the cache backend to update the object, and the cache backend will ask the netfs for details of the change through its cookie definition ops.
(*) FSCACHE_OBJECT_EV_CLEARED
This is signalled in two circumstances:
(a) when an object's last child object is dropped and
(b) when the last operation outstanding on an object is completed.
This is used to proceed from the dying state.
(*) FSCACHE_OBJECT_EV_ERROR
This is signalled when an I/O error occurs during the processing of some object.
(*) FSCACHE_OBJECT_EV_RELEASE
(*) FSCACHE_OBJECT_EV_RETIRE
These are signalled when the netfs relinquishes a cookie it was using. The event selected depends on whether the netfs asks for the backing object to be retired (deleted) or retained.
(*) FSCACHE_OBJECT_EV_WITHDRAW
This is signalled when the cache backend wants to withdraw an object. This means that the object will have to be detached from the netfs's cookie.
Because the withdrawing releasing/retiring events are all handled by the object state machine, it doesn't matter if there's a collision with both ends trying to sever the connection at the same time. The state machine can just pick which one it wants to honour, and that effects the other.
---
Documentation/filesystems/caching/fscache.txt | 5 Documentation/filesystems/caching/object.txt | 313 ++++++++++ fs/fscache/Makefile | 3 fs/fscache/internal.h | 26 + fs/fscache/object.c | 810 +++++++++++++++++++++++++ 5 files changed, 1155 insertions(+), 2 deletions(-) create mode 100644 Documentation/filesystems/caching/object.txt create mode 100644 fs/fscache/object.c
Documentation/filesystems/caching/fscache.txt +5 -0
@@ -188,6 +188,11 @@ The cache backend API to FS-Cache can be found in: Documentation/filesystems/caching/backend-api.txt +A description of the internal representations and object state machine can be +found in: + + Documentation/filesystems/caching/object.txt + ======================= STATISTICAL INFORMATION
Documentation/filesystems/caching/object.txt new file +313 -0
313 lines not on this page · raw message
fs/fscache/Makefile +2 -1
@@ -7,7 +7,8 @@ fscache-y := \ cookie.o \ fsdef.o \ main.o \ - netfs.o + netfs.o \ + object.o fscache-$(CONFIG_PROC_FS) += proc.o fscache-$(CONFIG_FSCACHE_STATS) += stats.o
fs/fscache/internal.h +25 -1
@@ -86,6 +86,18 @@ extern int fscache_wait_bit(void *);extern int fscache_wait_bit_interruptible (void *);/* +* fsc-object.c +*/ +extern void fscache_withdrawing_object (struct fscache_cache *, +struct fscache_object *); +extern void fscache_enqueue_object (struct fscache_object *); + +/* +* fsc-operation.c +*/ +#define fscache_start_operations (obj) BUG() + +/* * fsc-proc.c */ #ifdef CONFIG_PROC_FS
@@ -196,7 +208,19 @@ extern const struct file_operations fscache_stats_fops;static inline void fscache_raise_event (struct fscache_object *object,unsigned event) { -BUG ();// TODO +if (!test_and_set_bit (event, &object->events) && +test_bit (event, &object->event_mask)) +fscache_enqueue_object (object); +} + +/* +* drop a reference to a cookie +*/ +static inline void fscache_cookie_put (struct fscache_cookie *cookie) +{ +BUG_ON (atomic_read (&cookie->usage) <=0 ); +if (atomic_dec_and_test (&cookie->usage)) +__fscache_cookie_put (cookie); }/*****************************************************************************/
fs/fscache/object.c new file +810 -0
810 lines not on this page · raw message
David Howells
maintainerPATCH 18/43 FS-Cache: Implement the cookie management part of the netfs API [ver #46]
In reply to David HowellsImplement the cookie management part of the FS-Cache netfs client API. The documentation and API header file were added in a previous patch.
This patch implements the following three functions:
(1) fscache_acquire_cookie().
Acquire a cookie to represent an object to the netfs. If the object in question is a non-index object, then that object and its parent indices will be created on disk at this point if they don't already exist. Index creation is deferred because an index may reside in multiple caches.
(2) fscache_relinquish_cookie().
Retire or release a cookie previously acquired. At this point, the object on disk may be destroyed.
(3) fscache_update_cookie().
Update the in-cache representation of a cookie. This is used to update the auxiliary data for coherency management purposes.
With this patch it is possible to have a netfs instruct a cache backend to look up, validate and create metadata on disk and to destroy it again. The ability to actually store and retrieve data in the objects so created is added in later patches.
Note that these functions will never return an error. _All_ errors are handled internally to FS-Cache.
The worst that can happen is that fscache_acquire_cookie() may return a NULL pointer - which is considered a negative cookie pointer and can be passed back to any function that takes a cookie without harm. A negative cookie pointer merely suppresses caching at that level.
The stub in linux/fscache.h will detect inline the negative cookie pointer and abort the operation as fast as possible. This means that the compiler doesn't have to set up for a call in that case.
See the documentation in Documentation/filesystems/caching/netfs-api.txt for more information.
---
fs/fscache/cookie.c | 442 +++++++++++++++++++++++++++++++++++++++++++++++ include/linux/fscache.h | 16 ++ 2 files changed, 457 insertions(+), 1 deletions(-)
fs/fscache/cookie.c +442 -0
@@ -7,6 +7,9 @@* modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. +* +* See Documentation/filesystems/caching/netfs-api.txt for more information on +* the netfs API. */ #define FSCACHE_DEBUG_LEVEL COOKIE
@@ -16,6 +19,14 @@struct kmem_cache *fscache_cookie_jar; +static atomic_t fscache_object_debug_id =ATOMIC_INIT (0 ); + +static int fscache_acquire_non_index_cookie (struct fscache_cookie *cookie); +static int fscache_alloc_object (struct fscache_cache *cache, +struct fscache_cookie *cookie); +static int fscache_attach_object (struct fscache_cookie *cookie, +struct fscache_object *object); +/* * initialise an cookie jar slab element prior to any use */
@@ -29,6 +40,437 @@ void fscache_cookie_init_once(void *_cookie) }/* +* request a cookie to represent an object (index, datafile, xattr, etc) +* - parent specifies the parent object +* - the top level index cookie for each netfs is stored in the fscache_netfs +* struct upon registration +* - def points to the definition +* - the netfs_data will be passed to the functions pointed to in *def +* - all attached caches will be searched to see if they contain this object +* - index objects aren't stored on disk until there's a dependent file that +* needs storing +* - other objects are stored in a selected cache immediately, and all the +* indices forming the path to it are instantiated if necessary +* - we never let on to the netfs about errors +* - we may set a negative cookie pointer, but that's okay +*/ +struct fscache_cookie *__fscache_acquire_cookie ( +struct fscache_cookie *parent, +const struct fscache_cookie_def *def, +void *netfs_data) +{ +struct fscache_cookie *cookie; + +BUG_ON (!def); + +_enter ("{%s},{%s},%p" , + parent ? (char *) parent->def->name :"<no-parent>" , + def->name, netfs_data); + +fscache_stat (&fscache_n_acquires); + +/* if there's no parent cookie, then we don't create one here either */ +if (!parent) { +fscache_stat (&fscache_n_acquires_null); +_leave (" [no parent]" ); +return NULL ; + } + +/* validate the definition */ +BUG_ON (!def->get_key); +BUG_ON (!def->name[0 ]); + +BUG_ON (def->type ==FSCACHE_COOKIE_TYPE_INDEX && + parent->def->type !=FSCACHE_COOKIE_TYPE_INDEX ); + +/* allocate and initialise a cookie */ + cookie =kmem_cache_alloc (fscache_cookie_jar,GFP_KERNEL ); +if (!cookie) { +fscache_stat (&fscache_n_acquires_oom); +_leave (" [ENOMEM]" ); +return NULL ; + } + +atomic_set (&cookie->usage,1 ); +atomic_set (&cookie->n_children,0 ); + +atomic_inc (&parent->usage); +atomic_inc (&parent->n_children); + + cookie->def = def; + cookie->parent = parent; + cookie->netfs_data = netfs_data; + cookie->flags =0 ; + +switch (cookie->def->type) { +case FSCACHE_COOKIE_TYPE_INDEX : +fscache_stat (&fscache_n_cookie_index); +break ; +case FSCACHE_COOKIE_TYPE_DATAFILE : +fscache_stat (&fscache_n_cookie_data); +break ; +default : +fscache_stat (&fscache_n_cookie_special); +break ; + } + +/* if the object is an index then we need do nothing more here - we +* create indices on disk when we need them as an index may exist in +* multiple caches */ +if (cookie->def->type !=FSCACHE_COOKIE_TYPE_INDEX ) { +if (fscache_acquire_non_index_cookie (cookie) <0 ) { +atomic_dec (&parent->n_children); +__fscache_cookie_put (cookie); +fscache_stat (&fscache_n_acquires_nobufs); +_leave (" = NULL" ); +return NULL ; + } + } + +fscache_stat (&fscache_n_acquires_ok); +_leave (" = %p" , cookie); +return cookie; +} +EXPORT_SYMBOL (__fscache_acquire_cookie); + +/* +* acquire a non-index cookie +* - this must make sure the index chain is instantiated and instantiate the +* object representation too +*/ +static int fscache_acquire_non_index_cookie (struct fscache_cookie *cookie) +{ +struct fscache_object *object; +struct fscache_cache *cache; +uint64_t i_size; +int ret; + +_enter ("" ); + + cookie->flags =1 <<FSCACHE_COOKIE_UNAVAILABLE ; + +/* now we need to see whether the backing objects for this cookie yet +* exist, if not there'll be nothing to search */ +down_read (&fscache_addremove_sem); + +if (list_empty (&fscache_cache_list)) { +up_read (&fscache_addremove_sem); +_leave (" = 0 [no caches]" ); +return 0 ; + } + +/* select a cache in which to store the object */ + cache =fscache_select_cache_for_object (cookie->parent); +if (!cache) { +up_read (&fscache_addremove_sem); +fscache_stat (&fscache_n_acquires_no_cache); +_leave (" = -ENOMEDIUM [no cache]" ); +return -ENOMEDIUM ; + } + +_debug ("cache %s" , cache->tag->name); + + cookie->flags = + (1 <<FSCACHE_COOKIE_LOOKING_UP ) | + (1 <<FSCACHE_COOKIE_CREATING ) | + (1 <<FSCACHE_COOKIE_NO_DATA_YET ); + +/* ask the cache to allocate objects for this cookie and its parent +* chain */ + ret =fscache_alloc_object (cache, cookie); +if (ret <0 ) { +up_read (&fscache_addremove_sem); +_leave (" = %d" , ret); +return ret; + } + +/* pass on how big the object we're caching is supposed to be */ + cookie->def->get_attr (cookie->netfs_data, &i_size); + +spin_lock (&cookie->lock); +if (hlist_empty (&cookie->backing_objects)) { +spin_unlock (&cookie->lock); + goto unavailable; + } + + object =hlist_entry (cookie->backing_objects.first, + struct fscache_object, cookie_link); + +fscache_set_store_limit (object, i_size); + +/* initiate the process of looking up all the objects in the chain +* (done by fscache_initialise_object()) */ +fscache_enqueue_object (object); + +spin_unlock (&cookie->lock); + +/* we may be required to wait for lookup to complete at this point */ +if (!fscache_defer_lookup) { +_debug ("non-deferred lookup %p" , &cookie->flags); +wait_on_bit (&cookie->flags,FSCACHE_COOKIE_LOOKING_UP , + fscache_wait_bit,TASK_UNINTERRUPTIBLE ); +_debug ("complete" ); +if (test_bit (FSCACHE_COOKIE_UNAVAILABLE , &cookie->flags)) + goto unavailable; + } + +up_read (&fscache_addremove_sem); +_leave (" = 0 [deferred]" ); +return 0 ; + +unavailable: +up_read (&fscache_addremove_sem); +_leave (" = -ENOBUFS" ); +return -ENOBUFS ; +} + +/* +* recursively allocate cache object records for a cookie/cache combination +* - caller must be holding the addremove sem +*/ +static int fscache_alloc_object (struct fscache_cache *cache, +struct fscache_cookie *cookie) +{ +struct fscache_object *object; +struct hlist_node *_n; +int ret; + +_enter ("%p,%p{%s}" , cache, cookie, cookie->def->name); + +spin_lock (&cookie->lock); +hlist_for_each_entry (object, _n, &cookie->backing_objects, + cookie_link) { +if (object->cache == cache) + goto object_already_extant; + } +spin_unlock (&cookie->lock); + +/* ask the cache to allocate an object (we may end up with duplicate +* objects at this stage, but we sort that out later) */ + object = cache->ops->alloc_object (cache, cookie); +if (IS_ERR (object)) { +fscache_stat (&fscache_n_object_no_alloc); + ret =PTR_ERR (object); + goto error; + } + +fscache_stat (&fscache_n_object_alloc); + + object->debug_id =atomic_inc_return (&fscache_object_debug_id); + +_debug ("ALLOC OBJ%x: %s {%lx}" , + object->debug_id, cookie->def->name, object->events); + + ret =fscache_alloc_object (cache, cookie->parent); +if (ret <0 ) + goto error_put; + +/* only attach if we managed to allocate all we needed, otherwise +* discard the object we just allocated and instead use the one +* attached to the cookie */ +if (fscache_attach_object (cookie, object) <0 ) + cache->ops->put_object (object); + +_leave (" = 0" ); +return 0 ; + +object_already_extant: + ret = -ENOBUFS ; +if (object->state >=FSCACHE_OBJECT_DYING ) { +spin_unlock (&cookie->lock); + goto error; + } +spin_unlock (&cookie->lock); +_leave (" = 0 [found]" ); +return 0 ; + +error_put: + cache->ops->put_object (object); +error: +_leave (" = %d" , ret); +return ret; +} + +/* +* attach a cache object to a cookie +*/ +static int fscache_attach_object (struct fscache_cookie *cookie, +struct fscache_object *object) +{ +struct fscache_object *p; +struct fscache_cache *cache = object->cache; +struct hlist_node *_n; +int ret; + +_enter ("{%s},{OBJ%x}" , cookie->def->name, object->debug_id); + +spin_lock (&cookie->lock); + +/* there may be multiple initial creations of this object, but we only +* want one */ + ret = -EEXIST ; +hlist_for_each_entry (p, _n, &cookie->backing_objects, cookie_link) { +if (p->cache == object->cache) { +if (p->state >=FSCACHE_OBJECT_DYING ) + ret = -ENOBUFS ; + goto cant_attach_object; + } + } + +/* pin the parent object */ +spin_lock_nested (&cookie->parent->lock,1 ); +hlist_for_each_entry (p, _n, &cookie->parent->backing_objects, + cookie_link) { +if (p->cache == object->cache) { +if (p->state >=FSCACHE_OBJECT_DYING ) { + ret = -ENOBUFS ; +spin_unlock (&cookie->parent->lock); + goto cant_attach_object; + } + object->parent = p; +spin_lock (&p->lock); + p->n_children++; +spin_unlock (&p->lock); +break ; + } + } +spin_unlock (&cookie->parent->lock); + +/* attach to the cache's object list */ +if (list_empty (&object->cache_link)) { +spin_lock (&cache->object_list_lock); +list_add (&object->cache_link, &cache->object_list); +spin_unlock (&cache->object_list_lock); + } + +/* attach to the cookie */ + object->cookie = cookie; +atomic_inc (&cookie->usage); +hlist_add_head (&object->cookie_link, &cookie->backing_objects); + ret =0 ; + +cant_attach_object: +spin_unlock (&cookie->lock); +_leave (" = %d" , ret); +return ret; +} + +/* +* update the index entries backing a cookie +*/ +void __fscache_update_cookie (struct fscache_cookie *cookie) +{ +struct fscache_object *object; +struct hlist_node *_p; + +fscache_stat (&fscache_n_updates); + +if (!cookie) { +fscache_stat (&fscache_n_updates_null); +_leave (" [no cookie]" ); +return ; + } + +_enter ("{%s}" , cookie->def->name); + +BUG_ON (!cookie->def->get_aux); + +spin_lock (&cookie->lock); + +/* update the index entry on disk in each cache backing this cookie */ +hlist_for_each_entry (object, _p, + &cookie->backing_objects, cookie_link) { +fscache_raise_event (object,FSCACHE_OBJECT_EV_UPDATE ); + } + +spin_unlock (&cookie->lock); +_leave ("" ); +} +EXPORT_SYMBOL (__fscache_update_cookie); + +/* +* release a cookie back to the cache +* - the object will be marked as recyclable on disk if retire is true +* - all dependents of this cookie must have already been unregistered +* (indices/files/pages) +*/ +void __fscache_relinquish_cookie (struct fscache_cookie *cookie,int retire) +{ +struct fscache_cache *cache; +struct fscache_object *object; +unsigned long event; + +fscache_stat (&fscache_n_relinquishes); + +if (!cookie) { +fscache_stat (&fscache_n_relinquishes_null); +_leave (" [no cookie]" ); +return ; + } + +_enter ("%p{%s,%p},%d" , + cookie, cookie->def->name, cookie->netfs_data, retire); + +if (atomic_read (&cookie->n_children) !=0 ) { +printk (KERN_ERR "FS-Cache: Cookie '%s' still has children\n" , + cookie->def->name); +BUG (); + } + +/* wait for the cookie to finish being instantiated (or to fail) */ +if (test_bit (FSCACHE_COOKIE_CREATING , &cookie->flags)) { +fscache_stat (&fscache_n_relinquishes_waitcrt); +wait_on_bit (&cookie->flags,FSCACHE_COOKIE_CREATING , + fscache_wait_bit,TASK_UNINTERRUPTIBLE ); + } + + event = retire ?FSCACHE_OBJECT_EV_RETIRE :FSCACHE_OBJECT_EV_RELEASE ; + +/* detach pointers back to the netfs */ +spin_lock (&cookie->lock); + + cookie->netfs_data =NULL ; + cookie->def =NULL ; + +/* break links with all the active objects */ +while (!hlist_empty (&cookie->backing_objects)) { + object =hlist_entry (cookie->backing_objects.first, + struct fscache_object, + cookie_link); + +_debug ("RELEASE OBJ%x" , object->debug_id); + +/* detach each cache object from the object cookie */ +spin_lock (&object->lock); +hlist_del_init (&object->cookie_link); + + cache = object->cache; + object->cookie =NULL ; +fscache_raise_event (object, event); +spin_unlock (&object->lock); + +if (atomic_dec_and_test (&cookie->usage)) +/* the cookie refcount shouldn't be reduced to 0 yet */ +BUG (); + } + +spin_unlock (&cookie->lock); + +if (cookie->parent) { + ASSERTCMP(atomic_read(&cookie->parent->usage), >, 0); + ASSERTCMP(atomic_read(&cookie->parent->n_children), >, 0); +atomic_dec (&cookie->parent->n_children); + } + +/* finally dispose of the cookie */ + ASSERTCMP(atomic_read(&cookie->usage), >, 0); +fscache_cookie_put (cookie); + +_leave ("" ); +} +EXPORT_SYMBOL (__fscache_relinquish_cookie); + +/* * destroy a cookie */ void __fscache_cookie_put (struct fscache_cookie *cookie)
include/linux/fscache.h +15 -1
@@ -192,6 +192,13 @@ extern void __fscache_unregister_netfs(struct fscache_netfs *);extern struct fscache_cache_tag *__fscache_lookup_cache_tag (const char *);extern void __fscache_release_cache_tag (struct fscache_cache_tag *); +extern struct fscache_cookie *__fscache_acquire_cookie ( +struct fscache_cookie *, +const struct fscache_cookie_def *, +void *); +extern void __fscache_relinquish_cookie (struct fscache_cookie *,int ); +extern void __fscache_update_cookie (struct fscache_cookie *); +/** * fscache_register_netfs - Register a filesystem as desiring caching services * @netfs: The description of the filesystem
@@ -283,7 +290,10 @@ struct fscache_cookie *fscache_acquire_cookie( const struct fscache_cookie_def *def, void *netfs_data) { -return NULL ; + if (fscache_cookie_valid(parent)) + return __fscache_acquire_cookie(parent, def, netfs_data); + else + return NULL; }/**
@@ -301,6 +311,8 @@ struct fscache_cookie *fscache_acquire_cookie(static inline void fscache_relinquish_cookie (struct fscache_cookie *cookie,int retire) { +if (fscache_cookie_valid (cookie)) +__fscache_relinquish_cookie (cookie, retire); }/**
@@ -316,6 +328,8 @@ void fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)static inline void fscache_update_cookie (struct fscache_cookie *cookie) { +if (fscache_cookie_valid (cookie)) +__fscache_update_cookie (cookie); }/**
David Howells
maintainerPATCH 19/43 FS-Cache: Add and document asynchronous operation handling [ver #46]
In reply to David HowellsAdd and document asynchronous operation handling for use by FS-Cache's data storage and retrieval routines.
The following documentation is added to:
Documentation/filesystems/caching/operations.txt ================================ ASYNCHRONOUS OPERATIONS HANDLING ================================
========
OVERVIEW
========
FS-Cache has an asynchronous operations handling facility that it uses for its data storage and retrieval routines. Its operations are represented by fscache_operation structs, though these are usually embedded into some other structure.
This facility is available to and expected to be be used by the cache backends, and FS-Cache will create operations and pass them off to the appropriate cache backend for completion.
To make use of this facility, <linux/fscache-cache.h> should be #included.
===============================
OPERATION RECORD INITIALISATION
===============================
An operation is recorded in an fscache_operation struct:
struct fscache_operation {
union {
struct work_struct fast_work;
struct slow_work slow_work;
};
unsigned long flags;
fscache_operation_processor_t processor;
...
};Someone wanting to issue an operation should allocate something with this struct embedded in it. They should initialise it by calling:
void fscache_operation_init(struct fscache_operation *op, fscache_operation_release_t release);
with the operation to be initialised and the release function to use.
The op->flags parameter should be set to indicate the CPU time provision and the exclusivity (see the Parameters section).
The op->fast_work, op->slow_work and op->processor flags should be set as appropriate for the CPU time provision (see the Parameters section).
FSCACHE_OP_WAITING may be set in op->flags prior to each submission of the operation and waited for afterwards.
==========
PARAMETERS
==========
There are a number of parameters that can be set in the operation record's flag parameter. There are three options for the provision of CPU time in these operations:
(1) The operation may be done synchronously (FSCACHE_OP_MYTHREAD). A thread may decide it wants to handle an operation itself without deferring it to another thread.
This is, for example, used in read operations for calling readpages() on the backing filesystem in CacheFiles. Although readpages() does an asynchronous data fetch, the determination of whether pages exist is done synchronously - and the netfs does not proceed until this has been determined.
If this option is to be used, FSCACHE_OP_WAITING must be set in op->flags before submitting the operation, and the operating thread must wait for it to be cleared before proceeding:
wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
fscache_wait_bit, TASK_UNINTERRUPTIBLE);
(2) The operation may be fast asynchronous (FSCACHE_OP_FAST), in which case it will be given to keventd to process. Such an operation is not permitted to sleep on I/O.
This is, for example, used by CacheFiles to copy data from a backing fs page to a netfs page after the backing fs has read the page in.
If this option is used, op->fast_work and op->processor must be initialised before submitting the operation:
INIT_WORK(&op->fast_work, do_some_work);
(3) The operation may be slow asynchronous (FSCACHE_OP_SLOW), in which case it will be given to the slow work facility to process. Such an operation is permitted to sleep on I/O.
This is, for example, used by FS-Cache to handle background writes of pages that have just been fetched from a remote server.
If this option is used, op->slow_work and op->processor must be initialised before submitting the operation:
fscache_operation_init_slow(op, processor)
Furthermore, operations may be one of two types:
(1) Exclusive (FSCACHE_OP_EXCLUSIVE). Operations of this type may not run in conjunction with any other operation on the object being operated upon.
An example of this is the attribute change operation, in which the file being written to may need truncation.
(2) Shareable. Operations of this type may be running simultaneously. It's up to the operation implementation to prevent interference between other operations running at the same time.
=========
PROCEDURE
=========
Operations are used through the following procedure:
(1) The submitting thread must allocate the operation and initialise it itself. Normally this would be part of a more specific structure with the generic op embedded within.
(2) The submitting thread must then submit the operation for processing using one of the following two functions:
int fscache_submit_op(struct fscache_object *object,
struct fscache_operation *op);
int fscache_submit_exclusive_op(struct fscache_object *object,
struct fscache_operation *op);
The first function should be used to submit non-exclusive ops and the second to submit exclusive ones. The caller must still set the FSCACHE_OP_EXCLUSIVE flag.
If successful, both functions will assign the operation to the specified object and return 0. -ENOBUFS will be returned if the object specified is permanently unavailable.
The operation manager will defer operations on an object that is still undergoing lookup or creation. The operation will also be deferred if an operation of conflicting exclusivity is in progress on the object.
If the operation is asynchronous, the manager will retain a reference to it, so the caller should put their reference to it by passing it to:
void fscache_put_operation(struct fscache_operation *op);
(3) If the submitting thread wants to do the work itself, and has marked the operation with FSCACHE_OP_MYTHREAD, then it should monitor FSCACHE_OP_WAITING as described above and check the state of the object if necessary (the object might have died whilst the thread was waiting).
When it has finished doing its processing, it should call fscache_put_operation() on it.
(4) The operation holds an effective lock upon the object, preventing other exclusive ops conflicting until it is released. The operation can be enqueued for further immediate asynchronous processing by adjusting the CPU time provisioning option if necessary, eg:
op->flags &= ~FSCACHE_OP_TYPE;
op->flags |= ~FSCACHE_OP_FAST;
and calling:
void fscache_enqueue_operation(struct fscache_operation *op)
This can be used to allow other things to have use of the worker thread pools.
=====================
ASYNCHRONOUS CALLBACK
=====================
When used in asynchronous mode, the worker thread pool will invoke the processor method with a pointer to the operation. This should then get at the container struct by using container_of():
static void fscache_write_op(struct fscache_operation *_op)
{
struct fscache_storage *op =
container_of(_op, struct fscache_storage, op);
...
}The caller holds a reference on the operation, and will invoke fscache_put_operation() when the processor function returns. The processor function is at liberty to call fscache_enqueue_operation() or to take extra references.
---
Documentation/filesystems/caching/operations.txt | 213 ++++++++++ fs/fscache/Makefile | 3 fs/fscache/cache.c | 2 fs/fscache/internal.h | 8 fs/fscache/operation.c | 459 ++++++++++++++++++++++ 5 files changed, 682 insertions(+), 3 deletions(-) create mode 100644 Documentation/filesystems/caching/operations.txt create mode 100644 fs/fscache/operation.c
Documentation/filesystems/caching/operations.txt new file +213 -0
@@ -0,0 +1,213 @@ + ================================ + ASYNCHRONOUS OPERATIONS HANDLING + ================================ + +By: David Howells <[email protected]> + +Contents: + + (*) Overview. + + (*) Operation record initialisation. + + (*) Parameters. + + (*) Procedure. + + (*) Asynchronous callback. + + +======== +OVERVIEW +======== + +FS-Cache has an asynchronous operations handling facility that it uses for its +data storage and retrieval routines. Its operations are represented by +fscache_operation structs, though these are usually embedded into some other +structure. + +This facility is available to and expected to be be used by the cache backends, +and FS-Cache will create operations and pass them off to the appropriate cache +backend for completion. + +To make use of this facility, <linux/fscache-cache.h> should be #included. + + +=============================== +OPERATION RECORD INITIALISATION +=============================== + +An operation is recorded in an fscache_operation struct: + + struct fscache_operation { + union { + struct work_struct fast_work; + struct slow_work slow_work; + }; + unsigned long flags; + fscache_operation_processor_t processor; + ... + }; + +Someone wanting to issue an operation should allocate something with this +struct embedded in it. They should initialise it by calling: + + void fscache_operation_init(struct fscache_operation *op, + fscache_operation_release_t release); + +with the operation to be initialised and the release function to use. + +The op->flags parameter should be set to indicate the CPU time provision and +the exclusivity (see the Parameters section). + +The op->fast_work, op->slow_work and op->processor flags should be set as +appropriate for the CPU time provision (see the Parameters section). + +FSCACHE_OP_WAITING may be set in op->flags prior to each submission of the +operation and waited for afterwards. + + +========== +PARAMETERS +========== + +There are a number of parameters that can be set in the operation record's flag +parameter. There are three options for the provision of CPU time in these +operations: + + (1) The operation may be done synchronously (FSCACHE_OP_MYTHREAD). A thread + may decide it wants to handle an operation itself without deferring it to + another thread. + + This is, for example, used in read operations for calling readpages() on + the backing filesystem in CacheFiles. Although readpages() does an + asynchronous data fetch, the determination of whether pages exist is done + synchronously - and the netfs does not proceed until this has been + determined. + + If this option is to be used, FSCACHE_OP_WAITING must be set in op->flags + before submitting the operation, and the operating thread must wait for it + to be cleared before proceeding: + + wait_on_bit(&op->flags, FSCACHE_OP_WAITING, + fscache_wait_bit, TASK_UNINTERRUPTIBLE); + + + (2) The operation may be fast asynchronous (FSCACHE_OP_FAST), in which case it + will be given to keventd to process. Such an operation is not permitted + to sleep on I/O. + + This is, for example, used by CacheFiles to copy data from a backing fs + page to a netfs page after the backing fs has read the page in. + + If this option is used, op->fast_work and op->processor must be + initialised before submitting the operation: + + INIT_WORK(&op->fast_work, do_some_work); + + + (3) The operation may be slow asynchronous (FSCACHE_OP_SLOW), in which case it + will be given to the slow work facility to process. Such an operation is + permitted to sleep on I/O. + + This is, for example, used by FS-Cache to handle background writes of + pages that have just been fetched from a remote server. + + If this option is used, op->slow_work and op->processor must be + initialised before submitting the operation: + + fscache_operation_init_slow(op, processor) + + +Furthermore, operations may be one of two types: + + (1) Exclusive (FSCACHE_OP_EXCLUSIVE). Operations of this type may not run in + conjunction with any other operation on the object being operated upon. + + An example of this is the attribute change operation, in which the file + being written to may need truncation. + + (2) Shareable. Operations of this type may be running simultaneously. It's + up to the operation implementation to prevent interference between other + operations running at the same time. + + +========= +PROCEDURE +========= + +Operations are used through the following procedure: + + (1) The submitting thread must allocate the operation and initialise it + itself. Normally this would be part of a more specific structure with the + generic op embedded within. + + (2) The submitting thread must then submit the operation for processing using + one of the following two functions: + + int fscache_submit_op(struct fscache_object *object, + struct fscache_operation *op); + + int fscache_submit_exclusive_op(struct fscache_object *object, + struct fscache_operation *op); + + The first function should be used to submit non-exclusive ops and the + second to submit exclusive ones. The caller must still set the + FSCACHE_OP_EXCLUSIVE flag. + + If successful, both functions will assign the operation to the specified + object and return 0. -ENOBUFS will be returned if the object specified is + permanently unavailable. + + The operation manager will defer operations on an object that is still + undergoing lookup or creation. The operation will also be deferred if an + operation of conflicting exclusivity is in progress on the object. + + If the operation is asynchronous, the manager will retain a reference to + it, so the caller should put their reference to it by passing it to: + + void fscache_put_operation(struct fscache_operation *op); + + (3) If the submitting thread wants to do the work itself, and has marked the + operation with FSCACHE_OP_MYTHREAD, then it should monitor + FSCACHE_OP_WAITING as described above and check the state of the object if + necessary (the object might have died whilst the thread was waiting). + + When it has finished doing its processing, it should call + fscache_put_operation() on it. + + (4) The operation holds an effective lock upon the object, preventing other + exclusive ops conflicting until it is released. The operation can be + enqueued for further immediate asynchronous processing by adjusting the + CPU time provisioning option if necessary, eg: + + op->flags &= ~FSCACHE_OP_TYPE; + op->flags |= ~FSCACHE_OP_FAST; + + and calling: + + void fscache_enqueue_operation(struct fscache_operation *op) + + This can be used to allow other things to have use of the worker thread + pools. + + +===================== +ASYNCHRONOUS CALLBACK +===================== + +When used in asynchronous mode, the worker thread pool will invoke the +processor method with a pointer to the operation. This should then get at the +container struct by using container_of(): + + static void fscache_write_op(struct fscache_operation *_op) + { + struct fscache_storage *op = + container_of(_op, struct fscache_storage, op); + ... + } + +The caller holds a reference on the operation, and will invoke +fscache_put_operation() when the processor function returns. The processor +function is at liberty to call fscache_enqueue_operation() or to take extra +references.
fs/fscache/Makefile +2 -1
@@ -8,7 +8,8 @@ fscache-y := \ fsdef.o \ main.o \ netfs.o \ - object.o + object.o \ + operation.o fscache-$(CONFIG_PROC_FS) += proc.o fscache-$(CONFIG_FSCACHE_STATS) += stats.o
fs/fscache/cache.c +1 -1
@@ -194,7 +194,7 @@ void fscache_init_cache(struct fscache_cache *cache,vsnprintf (cache->identifier,sizeof (cache->identifier), idfmt, va);va_end (va); -INIT_WORK (&cache->op_gc,NULL ); +INIT_WORK (&cache->op_gc, fscache_operation_gc);INIT_LIST_HEAD (&cache->link);INIT_LIST_HEAD (&cache->object_list);INIT_LIST_HEAD (&cache->op_gc_list);
fs/fscache/internal.h +7 -1
@@ -95,7 +95,13 @@ extern void fscache_enqueue_object(struct fscache_object *);/* * fsc-operation.c */ -#define fscache_start_operations (obj) BUG() +extern int fscache_submit_exclusive_op (struct fscache_object *, +struct fscache_operation *); +extern int fscache_submit_op (struct fscache_object *, +struct fscache_operation *); +extern void fscache_abort_object (struct fscache_object *); +extern void fscache_start_operations (struct fscache_object *); +extern void fscache_operation_gc (struct work_struct *);/* * fsc-proc.c
fs/fscache/operation.c new file +459 -0
459 lines not on this page · raw message
David Howells
maintainerPATCH 20/43 FS-Cache: Implement data I/O part of netfs API [ver #46]
In reply to David HowellsImplement the data I/O part of the FS-Cache netfs API. The documentation and API header file were added in a previous patch.
This patch implements the following functions for the netfs to call:
(*) fscache_attr_changed().
Indicate that the object has changed its attributes. The only attribute currently recorded is the file size. Only pages within the set file size will be stored in the cache.
This operation is submitted for asynchronous processing, and will return immediately. It will return -ENOMEM if an out of memory error is encountered, -ENOBUFS if the object is not actually cached, or 0 if the operation is successfully queued.
(*) fscache_read_or_alloc_page().
(*) fscache_read_or_alloc_pages().
Request data be fetched from the disk, and allocate internal metadata to track the netfs pages and reserve disk space for unknown pages.
These operations perform semi-asynchronous data reads. Upon returning they will indicate which pages they think can be retrieved from disk, and will have set in progress attempts to retrieve those pages.
These will return, in order of preference, -ENOMEM on memory allocation error, -ERESTARTSYS if a signal interrupted proceedings, -ENODATA if one or more requested pages are not yet cached, -ENOBUFS if the object is not actually cached or if there isn't space for future pages to be cached on this object, or 0 if successful.
In the case of the multipage function, the pages for which reads are set in progress will be removed from the list and the page count decreased appropriately.
If any read operations should fail, the completion function will be given an error, and will also be passed contextual information to allow the netfs to fall back to querying the server for the absent pages.
For each successful read, the page completion function will also be called.
Any pages subsequently tracked by the cache will have PG_fscache set upon them on return. fscache_uncache_page() must be called for such pages.
If supplied by the netfs, the mark_pages_cached() cookie op will be invoked for any pages now tracked.
(*) fscache_alloc_page().
Allocate internal metadata to track a netfs page and reserve disk space.
This will return -ENOMEM on memory allocation error, -ERESTARTSYS on signal, -ENOBUFS if the object isn't cached, or there isn't enough space in the cache, or 0 if successful.
Any pages subsequently tracked by the cache will have PG_fscache set upon them on return. fscache_uncache_page() must be called for such pages.
If supplied by the netfs, the mark_pages_cached() cookie op will be invoked for any pages now tracked.
(*) fscache_write_page().
Request data be stored to disk. This may only be called on pages that have been read or alloc'd by the above three functions and have not yet been uncached.
This will return -ENOMEM on memory allocation error, -ERESTARTSYS on signal, -ENOBUFS if the object isn't cached, or there isn't immediately enough space in the cache, or 0 if successful.
On a successful return, this operation will have queued the page for asynchronous writing to the cache. The page will be returned with PG_fscache_write set until the write completes one way or another. The caller will not be notified if the write fails due to an I/O error. If that happens, the object will become available and all pending writes will be aborted.
Note that the cache may batch up page writes, and so it may take a while to get around to writing them out.
The caller must assume that until PG_fscache_write is cleared the page is use by the cache. Any changes made to the page may be reflected on disk. The page may even be under DMA.
(*) fscache_uncache_page().
Indicate that the cache should stop tracking a page previously read or alloc'd from the cache. If the page was alloc'd only, but unwritten, it will not appear on disk.
---
fs/fscache/Makefile | 3 fs/fscache/internal.h | 21 + fs/fscache/page.c | 771 +++++++++++++++++++++++++++++++++++++++++++++++ include/linux/fscache.h | 46 ++- 4 files changed, 835 insertions(+), 6 deletions(-) create mode 100644 fs/fscache/page.c
fs/fscache/Makefile +2 -1
@@ -9,7 +9,8 @@ fscache-y := \ main.o \ netfs.o \ object.o \ - operation.o + operation.o \ + page.o fscache-$(CONFIG_PROC_FS) += proc.o fscache-$(CONFIG_FSCACHE_STATS) += stats.o
fs/fscache/internal.h +21 -0
@@ -229,6 +229,27 @@ static inline void fscache_cookie_put(struct fscache_cookie *cookie)__fscache_cookie_put (cookie); } +/* +* get an extra reference to a netfs retrieval context +*/ +static inline +void *fscache_get_context (struct fscache_cookie *cookie,void *context) +{ +if (cookie->def->get_context) + cookie->def->get_context (cookie->netfs_data, context); +return context; +} + +/* +* release a reference to a netfs retrieval context +*/ +static inline +void fscache_put_context (struct fscache_cookie *cookie,void *context) +{ +if (cookie->def->put_context) + cookie->def->put_context (cookie->netfs_data, context); +} +/*****************************************************************************/ /* * debug tracing
fs/fscache/page.c new file +771 -0
771 lines not on this page · raw message
include/linux/fscache.h +41 -5
88 lines not on this page · raw message
David Howells
maintainerPATCH 21/43 CacheFiles: Be consistent about the use of mapping vs file->f_mapping in Ext3 [ver #46]
In reply to David HowellsChange all the usages of file->f_mapping in ext3_*write_end() functions to use the mapping argument directly. This has two consequences:
(*) Consistency. Without this patch sometimes one is used and sometimes the
other is.
(*) A NULL file pointer can be passed. This feature is then made use of by
the generic hook in the next patch, which is used by CacheFiles to write pages to a file without setting up a file struct.
---
fs/ext3/inode.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
fs/ext3/inode.c +3 -3
@@ -1231,7 +1231,7 @@ static int ext3_generic_write_end(struct file *file, loff_t pos, unsigned len, unsigned copied, struct page *page, void *fsdata) { - struct inode *inode = file->f_mapping->host; + struct inode *inode = mapping->host; copied =block_write_end (file, mapping, pos, len, copied, page, fsdata);
@@ -1256,7 +1256,7 @@ static int ext3_ordered_write_end(struct file *file, struct page *page, void *fsdata) { handle_t *handle = ext3_journal_current_handle(); -struct inode *inode = file->f_mapping->host; +struct inode *inode = mapping->host;unsigned from, to;int ret =0 , ret2;
@@ -1298,7 +1298,7 @@ static int ext3_writeback_write_end(struct file *file, struct page *page, void *fsdata) { handle_t *handle = ext3_journal_current_handle(); -struct inode *inode = file->f_mapping->host; +struct inode *inode = mapping->host;int ret =0 , ret2;loff_t new_i_size;
Re: [PATCH 21/43] CacheFiles: Be consistent about the use of mapping vs file->f_mapping in Ext3 [ver #46]
Quoted 6 lines · David Howells
Change all the usages of
file->f_mappingin ext3_*write_end() functions to use the mapping argument directly. This has two consequences:(*) Consistency. Without this patch sometimes one is used and sometimes the
other is.
Quoted 7 lines
(*) A NULL file pointer can be passed. This feature is then made use of by
the generic hook in the next patch, which is used by CacheFiles to write pages to a file without setting up a file struct.Signed-off-by David Howells <[email protected]>Acked-by Steve Dickson <[email protected]>Acked-by Trond Myklebust <[email protected]>
David Howells
maintainerPATCH 22/43 CacheFiles: Add a hook to write a single page of data to an inode [ver #46]
In reply to David HowellsAdd an address space operation to write one single page of data to an inode at a page-aligned location (thus permitting the implementation to be highly optimised). The data source is a single page.
This is used by CacheFiles to store the contents of netfs pages into their backing file pages.
Supply a generic implementation for this that uses the write_begin() and write_end() address_space operations to bind a copy directly into the page cache.
Hook the Ext2 and Ext3 operations to the generic implementation.
---
fs/ext2/inode.c | 2 ++ fs/ext3/inode.c | 3 +++ include/linux/fs.h | 7 ++++++ mm/filemap.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 73 insertions(+), 0 deletions(-)
fs/ext2/inode.c +2 -0
@@ -817,6 +817,8 @@ const struct address_space_operations ext2_nobh_aops = { .direct_IO = ext2_direct_IO, .writepages = ext2_writepages, .migratepage = buffer_migrate_page, + .write_one_page = generic_file_buffered_write_one_page, + .write_one_page = generic_file_buffered_write_one_page, };/*
fs/ext3/inode.c +3 -0
@@ -1803,6 +1803,7 @@ static const struct address_space_operations ext3_ordered_aops = { .direct_IO = ext3_direct_IO, .migratepage = buffer_migrate_page, .is_partially_uptodate = block_is_partially_uptodate, + .write_one_page = generic_file_buffered_write_one_page, };static const struct address_space_operations ext3_writeback_aops = {
@@ -1818,6 +1819,7 @@ static const struct address_space_operations ext3_writeback_aops = { .direct_IO = ext3_direct_IO, .migratepage = buffer_migrate_page, .is_partially_uptodate = block_is_partially_uptodate, + .write_one_page = generic_file_buffered_write_one_page, };static const struct address_space_operations ext3_journalled_aops = {
@@ -1832,6 +1834,7 @@ static const struct address_space_operations ext3_journalled_aops = { .invalidatepage = ext3_invalidatepage, .releasepage = ext3_releasepage, .is_partially_uptodate = block_is_partially_uptodate, + .write_one_page = generic_file_buffered_write_one_page, };void ext3_set_aops (struct inode *inode)
include/linux/fs.h +7 -0
@@ -532,6 +532,11 @@ struct address_space_operations {int (*launder_page) (struct page *);int (*is_partially_uptodate) (struct page *,read_descriptor_t *,unsigned long ); + +/* write the contents of the source page over the page at the specified +* index in the target address space (the source page does not need to +* be related to the target address space) */ +int (*write_one_page)(struct address_space *,pgoff_t ,struct page *); };/*
@@ -2119,6 +2124,8 @@ extern ssize_t generic_file_direct_write(struct kiocb *, const struct iovec *, unsigned long *, loff_t, loff_t *, size_t, size_t);extern ssize_t generic_file_buffered_write (struct kiocb *,const struct iovec *,unsigned long ,loff_t ,loff_t *,size_t ,ssize_t ); +extern int generic_file_buffered_write_one_page (struct address_space *, +pgoff_t ,struct page *);extern ssize_t do_sync_read (struct file *filp,char __user *buf,size_t len,loff_t *ppos);extern ssize_t do_sync_write (struct file *filp,const char __user *buf,size_t len,loff_t *ppos); extern int generic_segment_checks(const struct iovec *iov,
mm/filemap.c +61 -0
67 lines not on this page · raw message
Re: [PATCH 22/43] CacheFiles: Add a hook to write a single page of data to an inode [ver #46]
Quoted 4 lines · On Thursday 02 April 2009 10:05:15 David Howells wrote:
Add an address space operation to write one single page of data to an inode at a page-aligned location (thus permitting the implementation to be highly optimised). The data source is a single page.
Quoted 8 lines
This is used by CacheFiles to store the contents of netfs pages into their backing file pages.
Supply a generic implementation for this that uses the
write_begin()andwrite_end()address_spaceoperations to bind a copy directly into the page cache.Hook the Ext2 and Ext3 operations to the generic implementation.
Is this really worthwhile? What do you do that write_begin/write_end doesn't? I have a patch around somewhere enable splice stealing into the pagecache with write_begin/write_end if you are worried about the copy. But how about you put this at the end of the series justified with some numbers?
_______________________________________________
NFSv4 mailing list
[email protected]
http://linux-nfs.org/cgi-bin/mailman/listinfo/nfsv4
David Howells
maintainerRe: [PATCH 22/43] CacheFiles: Add a hook to write a single page of data to an inode [ver #46]
Quoted 3 lines · Nick Piggin
Quoted 1 line
Hook the Ext2 and Ext3 operations to the generic implementation.
Is this really worthwhile?
I seem to remember being told that I'm not allowed to call such directly (by Christoph Hellwig perhaps?), and that I should add an address space op to do this.
Quoted 1 line
What do you do that write_begin/write_end doesn't?
This code calls write_begin() and write_end().
write_begin() and write_end() don't actually update the target page, and don't so the osync stuff.
My code assumed file can be passed as NULL to write_begin() and write_end(). If file is, however, necessary then the backing fs can do something different. cachefiles doesn't know.
Creating loads of file structs gives you ENFILE problems if you start opening lots of files internally. This caused lots of argument when I proposed a patch to allow the kernels to open files not on account.
I'm quite happy to ditch the extra address space op and put this code in cachefiles itself. Doing it there would perhaps allow me to handle multiple pages more easily.
Quoted 2 lines
I have a patch around somewhere enable splice stealing into the pagecache with write_begin/write_end if you are worried about the copy.
I'm not sure what you mean.
Quoted 2 lines
But how about you put this at the end of the series justified with some numbers?
I don't see how that helps. cachefiles has to do something to get the data out.
David
Re: [PATCH 22/43] CacheFiles: Add a hook to write a single page of data to an inode [ver #46]
Quoted 9 lines · On Friday 03 April 2009 01:55:53 David Howells wrote:
Quoted 3 lines · Nick Piggin
Quoted 1 line
Hook the Ext2 and Ext3 operations to the generic implementation.
Is this really worthwhile?
I seem to remember being told that I'm not allowed to call such directly (by Christoph Hellwig perhaps?), and that I should add an address space op to do this.
Hmm, I guess not all filesystems define write_begin/write_end. But if you only need to use ones that do define them?
Quoted 4 lines
Quoted 2 lines
What do you do that write_begin/write_end doesn't?
This code calls
write_begin()andwrite_end().
Yes, you framed the changelog as introducing this new callback because it allows a highly optimised code that takes advantage of page aligned write. So I went on a tangent thinking you were going to use it later to avoid the data copy or something.
Quoted 6 lines
write_begin()andwrite_end()don't actually update the target page, and don't so the osync stuff.My code assumed file can be passed as NULL to
write_begin()andwrite_end(). If file is, however, necessary then the backing fs can do something different. cachefiles doesn't know.
You are knowingly squashing together fscache and the backing filesystem if you do something like introduce a flag like PG_owner_priv_2 and disallow the backing filesystem from reusing it. So at which point you don't have to keep up illusions about being totally filesystem agnostic.
Many filesystems don't need the file argument to write_begin/write_end.
David Howells
maintainerRe: [PATCH 22/43] CacheFiles: Add a hook to write a single page of data to an inode [ver #46]
Quoted 2 lines · Nick Piggin
Hmm, I guess not all filesystems define write_begin/write_end. But if you only need to use ones that do define them?
That would be a reasonable restriction. As would excluding NFS, AFS, CIFS, etc..
Quoted 4 lines
Yes, you framed the changelog as introducing this new callback because it allows a highly optimised code that takes advantage of page aligned write. So I went on a tangent thinking you were going to use it later to avoid the data copy or something.
I would love to avoid the data copies and do asynchronous direct I/O. However the DIO interface appears very highly userspace centric, and is very hard to use from within the kernel.
Quoted 3 lines
You are knowingly squashing together fscache and the backing filesystem if you do something like introduce a flag like
PG_owner_priv_2and disallow the backing filesystem from reusing it.
The backing filesystem isn't disallowed from reusing it; the *netfs* is.
Understand that there are two filesystems involved: The netfs, which makes requests of FS-Cache, and the backing filesystem which cachefiles uses to store data.
FS-Cache places restrictions such as having to yield up FS_private_2 and FS_owner_priv_2 on the netfs.
Cachefiles places restrictions such as must have bmap(), setxattr(), write_one_page() on the backing fs.
Quoted 2 lines
So at which point you don't have to keep up illusions about being totally filesystem agnostic.
I'm trying to keep things as filesystem agnostic as I can, at both ends.
Quoted 1 line
Many filesystems don't need the file argument to write_begin/write_end.
That probably includes all those I care about for supporting the backing fs. The problem is how does cachefiles tell? Perhaps a file_system_type flag?
#define FS_SUPPORTS_CACHEFILES 65536
or
#define FS_NULL_FILEPTR_OKAY 65536
perhaps.
David
Re: [PATCH 22/43] CacheFiles: Add a hook to write a single page of data to an inode [ver #46]
In reply to Nick PigginQuoted 2 lines · Nick Piggin
Hmm, I guess not all filesystems define write_begin/write_end. But if you only need to use ones that do define them?
No. write_begin/write_end are simply callbacks for the write helpers, and locking for them is entirely filesystem-defined. E.g. xfs and the cluster filesystems require additional locks taken first, and some network filesystems require inode revalidations first.
They really should be taken out of the address_space_operations and passed as callbacks to generic_file_aio_write & co.
Re: [PATCH 22/43] CacheFiles: Add a hook to write a single page of data to an inode [ver #46]
Quoted 8 lines · On Friday 03 April 2009 03:37:12 Christoph Hellwig wrote:
Quoted 2 lines · Nick Piggin
Hmm, I guess not all filesystems define write_begin/write_end. But if you only need to use ones that do define them?
No. write_begin/write_end are simply callbacks for the write helpers, and locking for them is entirely filesystem-defined. E.g. xfs and the cluster filesystems require additional locks taken first, and some network filesystems require inode revalidations first.
Well they now are quite well filesystem defined. We no longer take the page lock before calling them. Not saying it's perfect, but if the backing fs is just using a known subset of ones that work (like loop does).
Quoted 2 lines
They really should be taken out of the
address_space_operationsand passed as callbacks togeneric_file_aio_write& co.
Probably yes. But it seems like it should have more discussion IMO (unless it has already been had and I missed it).
I don't think "write_one_page" sounds like a particularly good new API addition.
In the meantime, I would prefer cachefs use writebegin/end and it can be converted to a new API with everyone else rather than having to rush a new API in with it.
Re: [PATCH 22/43] CacheFiles: Add a hook to write a single page of data to an inode [ver #46]
Quoted 4 lines · Nick Piggin
Well they now are quite well filesystem defined. We no longer take the page lock before calling them. Not saying it's perfect, but if the backing fs is just using a known subset of ones that work (like loop does).
The page lock doesn't matter. What matters is locks protecting the io. Like the XFS iolock or cluster locks in the cluster filesystems, and you will get silent data corruption that way.
I would have sworn loop was fixed by now as gfs people were seeing these issues and submitting patches, but it looks like we never sorted this out upstream.
Quoted 2 lines
Probably yes. But it seems like it should have more discussion IMO (unless it has already been had and I missed it).
This came up plenty of times.
Quoted 2 lines
I don't think "
write_one_page" sounds like a particularly good new API addition.
I also thing it's not a nice one. I still haven't seen a really good explanation of why it can't just use plain ->write
Re: [PATCH 22/43] CacheFiles: Add a hook to write a single page of data to an inode [ver #46]
Quoted 9 lines · On Friday 03 April 2009 03:55:05 Christoph Hellwig wrote:
Quoted 4 lines · Nick Piggin
Well they now are quite well filesystem defined. We no longer take the page lock before calling them. Not saying it's perfect, but if the backing fs is just using a known subset of ones that work (like loop does).
The page lock doesn't matter. What matters is locks protecting the io. Like the XFS iolock or cluster locks in the cluster filesystems, and you will get silent data corruption that way.
Hmm, I can see i_mutex being a problem, but can't see how a filesystem takes any other locks down that chain?
Naturally a random in-kernel user misses other important things, so yes a simple write sounds like the best option.
Quoted 4 lines
Quoted 2 lines
Probably yes. But it seems like it should have more discussion IMO (unless it has already been had and I missed it).
This came up plenty of times.
I mean, unless the discussion agreed on write_one_page being the right API to add, then it should not be added in fscache and fscache should just take a workaround for the meantime.
Quoted 5 lines
Quoted 2 lines
I don't think "
write_one_page" sounds like a particularly good new API addition.I also thing it's not a nice one. I still haven't seen a really good explanation of why it can't just use plain ->write
Good question.
Jan Kara
maintainerRe: [PATCH 22/43] CacheFiles: Add a hook to write a single page of data to an inode [ver #46]
Quoted 7 lines · On Friday 03 April 2009 03:55:05 Christoph Hellwig wrote:
Quoted 6 lines · Nick Piggin
Quoted 4 lines
Well they now are quite well filesystem defined. We no longer take the page lock before calling them. Not saying it's perfect, but if the backing fs is just using a known subset of ones that work (like loop does).
Quoted 6 lines
Quoted 3 lines
The page lock doesn't matter. What matters is locks protecting the io. Like the XFS iolock or cluster locks in the cluster filesystems, and you will get silent data corruption that way.
Hmm, I can see
i_mutexbeing a problem, but can't see how a filesystem takes any other locks down that chain?
Yes, i_mutex is one problem. Then filesystems may take other locks
in their ->aio_write callbacks - as Christoph mentioned, for example OCFS2 has to do some network messaging to synchronize nodes in the cluster accessing the file. I could imagine some clever filesystem doing more clever locking than just one i_mutex covering the whole file...
Quoted 2 lines
Naturally a random in-kernel user misses other important things, so yes a simple write sounds like the best option.
Definitely. IMO it's hard to get the locking right without calling
->aio_write callback.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SuSE CR Labs
David Howells
maintainerRe: [PATCH 22/43] CacheFiles: Add a hook to write a single page of data to an inode [ver #46]
In reply to Christoph HellwigQuoted 5 lines · Christoph Hellwig
Quoted 2 lines
I don't think "
write_one_page" sounds like a particularly good new API addition.I also thing it's not a nice one. I still haven't seen a really good explanation of why it can't just use plain ->write
->write requires:
(1) A struct file. Refer to the ENFILE problem that my patch to do this raised. The problem is that doing a tar of, say, a kernel tree immediately opens ~30000 files internally, and then userspace falls over with ENFILE all over the place. My tests multiply that by 8.
You (at least I think it was you) refused to countenance allocating file structs internally to the kernel that weren't accounted.
(2) A pointer to a buffer. That means kmapping a page for the duration of the write.
->write is quite heavy. For something like ext3 it goes down through quite a few layers, in and out of the fs, VM and VFS. All this takes both time and stack space.
I want to write a whole page from the kernel at a page-boundary in the file. That means it is possible to use an extremely optimised aop to do that.
Really, what I want to do is have the filesystem issue its BIOs directly on the netfs page, but the Ext3 people I talked to at the time thought that would be too difficult to track.
David
David Howells
maintainerRe: [PATCH 22/43] CacheFiles: Add a hook to write a single page of data to an inode [ver #46]
In reply to Christoph HellwigQuoted 5 lines · Christoph Hellwig
Quoted 2 lines
I don't think "
write_one_page" sounds like a particularly good new API addition.I also thing it's not a nice one. I still haven't seen a really good explanation of why it can't just use plain ->write
So, I can apply the attached patch. It opens a file each time it wants to write a page and then closes it again, but it's the best way to avoid the ENFILE problem. I'm benchmarking it at the moment.
David
---
fs/cachefiles/rdwr.c +34 -8
@@ -9,6 +9,8 @@* 2 of the Licence, or (at your option) any later version. */ +#include <linux/mount.h> +#include <linux/file.h> #include "internal.h" /*
@@ -796,7 +798,11 @@ int cachefiles_allocate_pages(struct fscache_retrieval *op,int cachefiles_write_page (struct fscache_storage *op,struct page *page) {struct cachefiles_object *object; -struct address_space *mapping; +struct cachefiles_cache *cache; +mm_segment_t old_fs; +struct file *file; +loff_t pos; +void *data;int ret;ASSERT (op !=NULL );
@@ -814,13 +820,33 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)ASSERT (S_ISREG (object->backer->d_inode->i_mode)); -/* copy the page to ext3 and let it store it in its own time */ - mapping = object->backer->d_inode->i_mapping; - ret = -EIO ; -if (mapping->a_ops->write_one_page) { - ret = mapping->a_ops->write_one_page (mapping, page->index, - page); -_debug ("write_one_page -> %d" , ret); + cache =container_of (object->fscache.cache, + struct cachefiles_cache, cache); + +/* write the page to the backing filesystem and let it store it in its +* own time */ +dget (object->backer); +mntget (cache->mnt); + file =dentry_open (object->backer, cache->mnt,O_RDWR , + cache->cache_cred); +if (IS_ERR (file)) { + ret =PTR_ERR (file); + }else { + ret = -EIO ; +if (file->f_op->write) { + pos = (loff_t ) page->index <<PAGE_SHIFT ; + data =kmap (page); + old_fs =get_fs (); +set_fs (KERNEL_DS ); + ret = file->f_op->write ( + file, (const void __user *) data,PAGE_SIZE , + &pos); +set_fs (old_fs); +kunmap (page); +if (ret !=PAGE_SIZE ) + ret = -EIO ; + } +fput (file); }if (ret <0 ) {
David Howells
maintainerRe: [PATCH 22/43] CacheFiles: Add a hook to write a single page of data to an inode [ver #46]
Quoted 3 lines · David Howells
So, I can apply the attached patch. It opens a file each time it wants to write a page and then closes it again, but it's the best way to avoid the ENFILE problem. I'm benchmarking it at the moment.
Okay. I'm not sure why, but using ->write() in that patch appears to be _much_ better than using ->write_one_page(), despite the latter doing much less work.
The benchmark was:
mke2fs -j -O dir_index -b 4096 /dev/sda6 tune2fs -o user_xattr /dev/sda6 setenforce 0
mount /dev/sda6 /var/fscache/ -o user_xattr insmod /tmp/sunrpc.ko
insmod /tmp/lockd.ko
insmod /tmp/nfs_acl.ko
insmod /tmp/auth_rpcgss.ko
insmod /tmp/fscache.ko
insmod /tmp/nfs.ko
insmod /tmp/cachefiles.ko
sync
service cachefilesd start
sync
mount warthog:/warthog /warthog -o fsc -t nfs4 date;
tar cf - /warthog/aaa >/dev/zero & tar cf - /warthog/aaa2 >/dev/zero & tar cf - /warthog/aaa3 >/dev/zero & tar cf - /warthog/aaa >/dev/zero & tar cf - /warthog/aaa2 >/dev/zero & tar cf - /warthog/aaa3 >/dev/zero & tar cf - /warthog/aaa >/dev/zero & tar cf - /warthog/aaa2 >/dev/zero; wait;
date
sync
echo b >/proc/sysrq-trigger
Where each of /warthog/aaa{,2,3} is about 340MB of kernel tree. The test box only has 1GB of RAM. The server has the whole data set in RAM and is connected by GigE with more or less no other traffic on the line.
Runs without and with the patch were alternated, and the following results were produced:
Using write_one_page():
Thu Apr 2 22:56:45 BST 2009 Thu Apr 2 23:01:03 BST 2009 4m 18s Thu Apr 2 23:11:12 BST 2009 Thu Apr 2 23:15:12 BST 2009 4m 0s Thu Apr 2 23:28:39 BST 2009 Thu Apr 2 23:32:01 BST 2009 3m 22s
Using write():
Thu Apr 2 23:05:19 BST 2009 Thu Apr 2 23:07:31 BST 2009 2m 12s Thu Apr 2 23:18:28 BST 2009 Thu Apr 2 23:20:18 BST 2009 1m 50s Thu Apr 2 23:22:52 BST 2009 Thu Apr 2 23:25:24 BST 2009 2m 32s
So the patch improves performance by about 2x, it would appear. The disk holding the backing fs was much more continually on with the patch, so I think write() must be promoting some disk I/O.
Or maybe, fput() calling release() is the difference. Any thoughts?
David
David Howells
maintainerRe: [PATCH 22/43] CacheFiles: Add a hook to write a single page of data to an inode [ver #46]
In reply to David Howellsfs/cachefiles/rdwr.c int cachefiles_write_page(struct fscache_storage *op, struct page *page) · line 845
Quoted 8 lines · David Howells
fs/cachefiles/rdwr.c +8
-0+ data =kmap (page); + old_fs =get_fs (); +set_fs (KERNEL_DS ); + ret = file->f_op->write ( + file, (const void __user *) data,PAGE_SIZE , + &pos); +set_fs (old_fs); +kunmap (page);
Hmmm... Now I've thought about it some more, I'm not sure this is a good idea. Can this run a system out of kmap() resources? These are run by a dynamic thread pool, where each thread in the pool can do a kmap and issue a write, but the write may get delayed for a significant amount of time for a number of reasons - such as block allocation, data fetching and memory allocation.
David
Re: [PATCH 22/43] CacheFiles: Add a hook to write a single page of data to an inode [ver #46]
In reply to David HowellsQuoted 30 lines · David Howells
Add an address space operation to write one single page of data to an inode at a page-aligned location (thus permitting the implementation to be highly optimised). The data source is a single page.
This is used by CacheFiles to store the contents of netfs pages into their backing file pages.
Supply a generic implementation for this that uses the
write_begin()andwrite_end()address_spaceoperations to bind a copy directly into the page cache.Hook the Ext2 and Ext3 operations to the generic implementation.
Signed-off-by David Howells <[email protected]>Acked-by Steve Dickson <[email protected]>Acked-by Trond Myklebust <[email protected]>---
fs/ext2/inode.c | 2 ++ fs/ext3/inode.c | 3 +++ include/linux/fs.h | 7 ++++++ mm/filemap.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 73 insertions(+), 0 deletions(-)fs/ext2/inode.c +0
-0
fs/ext2/inode.c const struct address_space_operations ext2_nobh_aops = { · line 822
Quoted 6 lines
fs/ext2/inode.c +2
-0@@ -817,6 +817,8 @@ const struct address_space_operations ext2_nobh_aops = { .direct_IO = ext2_direct_IO, .writepages = ext2_writepages, .migratepage = buffer_migrate_page, + .write_one_page = generic_file_buffered_write_one_page, + .write_one_page = generic_file_buffered_write_one_page,
You probably only need one of these lines, don't you?
Thanx...
psQuoted 134 lines
fs/ext2/inode.c +0
-0};/*
fs/ext3/inode.c +3
-0@@ -1803,6 +1803,7 @@ static const struct address_space_operations ext3_ordered_aops = { .direct_IO = ext3_direct_IO, .migratepage = buffer_migrate_page, .is_partially_uptodate = block_is_partially_uptodate, + .write_one_page = generic_file_buffered_write_one_page, };static const struct address_space_operations ext3_writeback_aops = {@@ -1818,6 +1819,7 @@ static const struct address_space_operations ext3_writeback_aops = { .direct_IO = ext3_direct_IO, .migratepage = buffer_migrate_page, .is_partially_uptodate = block_is_partially_uptodate, + .write_one_page = generic_file_buffered_write_one_page, };static const struct address_space_operations ext3_journalled_aops = {@@ -1832,6 +1834,7 @@ static const struct address_space_operations ext3_journalled_aops = { .invalidatepage = ext3_invalidatepage, .releasepage = ext3_releasepage, .is_partially_uptodate = block_is_partially_uptodate, + .write_one_page = generic_file_buffered_write_one_page, };void ext3_set_aops (struct inode *inode)include/linux/fs.h +7
-0@@ -532,6 +532,11 @@ struct address_space_operations {int (*launder_page) (struct page *);int (*is_partially_uptodate) (struct page *,read_descriptor_t *,unsigned long ); + +/* write the contents of the source page over the page at the specified +* index in the target address space (the source page does not need to +* be related to the target address space) */ +int (*write_one_page)(struct address_space *,pgoff_t ,struct page *); };/* @@ -2119,6 +2124,8 @@ extern ssize_t generic_file_direct_write(struct kiocb *, const struct iovec *, unsigned long *, loff_t, loff_t *, size_t, size_t);extern ssize_t generic_file_buffered_write (struct kiocb *,const struct iovec *,unsigned long ,loff_t ,loff_t *,size_t ,ssize_t ); +extern int generic_file_buffered_write_one_page (struct address_space *, +pgoff_t ,struct page *);extern ssize_t do_sync_read (struct file *filp,char __user *buf,size_t len,loff_t *ppos);extern ssize_t do_sync_write (struct file *filp,const char __user *buf,size_t len,loff_t *ppos); extern int generic_segment_checks(const struct iovec *iov,mm/filemap.c +61
-0@@ -2320,6 +2320,67 @@ generic_file_buffered_write(struct kiocb *iocb, const struct iovec *iov, }EXPORT_SYMBOL (generic_file_buffered_write); +/** +* generic_file_buffered_write_one_page - Write a single page of data to an +* inode +* @mapping - The address space of the target inode +* @index - The target page in the target inode to fill +* @source - The data to write into the target page +* +* Write the data from the source page to the page in the nominated address +* space at the @index specified. Note that the file will not be extended if +* the page crosses the EOF marker, in which case only the first part of the +* page will be written. +* +* The @source page does not need to have any association with the file or the +* target page offset. +*/ +int generic_file_buffered_write_one_page (struct address_space *mapping, +pgoff_t index, +struct page *source) +{ +const struct address_space_operations *a_ops = mapping->a_ops; +struct page *page; +unsigned len; +loff_t isize, pos; +void *fsdata; +int ret; + + pos = index; + pos <<=PAGE_CACHE_SHIFT ; + + len =PAGE_CACHE_SIZE ; + isize =i_size_read (mapping->host); +if ((isize >>PAGE_CACHE_SHIFT ) == index) + len = isize & (PAGE_CACHE_SIZE -1 ); + + ret =pagecache_write_begin (NULL , mapping, pos, len, +AOP_FLAG_UNINTERRUPTIBLE , &page, &fsdata); +if (ret <0 ) + goto sync; + +copy_highpage (page, source); + + ret =pagecache_write_end (NULL , mapping, pos, len, len, page, fsdata); +if (ret <0 ) + goto sync; + +balance_dirty_pages_ratelimited (mapping); +cond_resched (); + +sync: +/* the caller must handle O_SYNC themselves, but we handle S_SYNC and +* MS_SYNCHRONOUS here */ +if (unlikely (IS_SYNC (mapping->host)) && !a_ops->writepage) + ret =generic_osync_inode (mapping->host, mapping, +OSYNC_METADATA |OSYNC_DATA ); + +/* the caller must handle O_DIRECT for themselves */ + +return ret; +} +EXPORT_SYMBOL (generic_file_buffered_write_one_page); +static ssize_t __generic_file_aio_write_nolock (struct kiocb *iocb,const struct iovec *iov,unsigned long nr_segs,loff_t *ppos)_______________________________________________
NFSv4 mailing list
[email protected]
http://linux-nfs.org/cgi-bin/mailman/listinfo/nfsv4
David Howells
maintainerRe: [PATCH 22/43] CacheFiles: Add a hook to write a single page of data to an inode [ver #46]
Quoted 5 lines · Peter Staubach
fs/ext2/inode.c const struct address_space_operations ext2_nobh_aops = { · line 821
Quoted 3 lines
fs/ext2/inode.c +2
-0+ .write_one_page = generic_file_buffered_write_one_page, + .write_one_page = generic_file_buffered_write_one_page,You probably only need one of these lines, don't you?
Yes: one should be in ext2_aops, thanks.
David
Re: [PATCH 22/43] CacheFiles: Add a hook to write a single page of data to an inode [ver #46]
In reply to David HowellsQuoted 9 lines · David Howells
Add an address space operation to write one single page of data to an inode at a page-aligned location (thus permitting the implementation to be highly optimised). The data source is a single page.
fs/ext2/inode.c +0
-0
fs/ext2/inode.c const struct address_space_operations ext2_nobh_aops = { · line 821
Quoted 5 lines
fs/ext2/inode.c +2
-0@@ -817,6 +817,8 @@ const struct address_space_operations ext2_nobh_aops = { .direct_IO = ext2_direct_IO, .writepages = ext2_writepages, .migratepage = buffer_migrate_page, + .write_one_page = generic_file_buffered_write_one_page, + .write_one_page = generic_file_buffered_write_one_page
Adding the same function pointer twice seems a bit excessive.
Other than that, the patch looks good :)
David Howells
maintainerPATCH 23/43 CacheFiles: Permit the page lock state to be monitored [ver #46]
In reply to David HowellsAdd a function to install a monitor on the page lock waitqueue for a particular page, thus allowing the page being unlocked to be detected.
This is used by CacheFiles to detect read completion on a page in the backing filesystem so that it can then copy the data to the waiting netfs page.
---
include/linux/pagemap.h | 5 +++++ mm/filemap.c | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 0 deletions(-)
include/linux/pagemap.h +5 -0
@@ -396,6 +396,11 @@ static inline void wait_on_page_owner_priv_2(struct page *page)extern void end_page_owner_priv_2 (struct page *page);/* +* Add an arbitrary waiter to a page's wait queue +*/ +extern void add_page_wait_queue (struct page *page,wait_queue_t *waiter); + +/* * Fault a userspace page into pagetables. Return non-zero on a fault. * * This assumes that two userspace pages are always sufficient. That's
mm/filemap.c +18 -0
@@ -565,6 +565,24 @@ void wait_on_page_bit(struct page *page, int bit_nr)EXPORT_SYMBOL (wait_on_page_bit);/** +* add_page_wait_queue - Add an arbitrary waiter to a page's wait queue +* @page - Page defining the wait queue of interest +* @waiter - Waiter to add to the queue +* +* Add an arbitrary @waiter to the wait queue for the nominated @page. +*/ +void add_page_wait_queue (struct page *page,wait_queue_t *waiter) +{ +wait_queue_head_t *q =page_waitqueue (page); +unsigned long flags; + +spin_lock_irqsave (&q->lock, flags); +__add_wait_queue (q, waiter); +spin_unlock_irqrestore (&q->lock, flags); +} +EXPORT_SYMBOL_GPL (add_page_wait_queue); + +/** * unlock_page - unlock a locked page * @page: the page *
Re: [PATCH 23/43] CacheFiles: Permit the page lock state to be monitored [ver #46]
Quoted 5 lines · On Thursday 02 April 2009 10:05:20 David Howells wrote:
Add a function to install a monitor on the page lock waitqueue for a particular page, thus allowing the page being unlocked to be detected.
This is used by CacheFiles to detect read completion on a page in the backing filesystem so that it can then copy the data to the waiting netfs page.
I prefer to nack this because it is exporting details of the page locking mechanism. unlock_page is very heavyweight in large part because of the memory barriers and cacheline required to check the waitqueue. I have patches to avoid all that if the page lock is not contended.
What's wrong with using wait_on_page_locked, like everyone else does?
David Howells
maintainerRe: [PATCH 23/43] CacheFiles: Permit the page lock state to be monitored [ver #46]
Quoted 7 lines · Nick Piggin
I prefer to nack this because it is exporting details of the page locking mechanism.
unlock_pageis very heavyweight in large part because of the memory barriers and cacheline required to check the waitqueue. I have patches to avoid all that if the page lock is not contended.What's wrong with using
wait_on_page_locked, like everyone else does?
When fscache_read_or_alloc_pages() is called from, say, nfs_readpages(), and is given a few hundred pages to readahead from the cache, who does the wait_on_page_locked() on each of the _backing_ fs's pages?
The way I've arranged things to work is for the backing fs pages to be copied to the netfs pages and released in the order they're read from the disk.
There's a small pool of threads that processes the pages. I don't want to have to create a thread for each readpages(), and I don't want readpages() to have to wait for all the requests it makes.
Ideally, I'd like to ask the backing fs to read directly into netfs pages, but that's not particularly feasible at the moment.
David
Re: [PATCH 23/43] CacheFiles: Permit the page lock state to be monitored [ver #46]
Quoted 8 lines · On Friday 03 April 2009 03:14:52 David Howells wrote:
Quoted 6 lines · Nick Piggin
I prefer to nack this because it is exporting details of the page locking mechanism.
unlock_pageis very heavyweight in large part because of the memory barriers and cacheline required to check the waitqueue. I have patches to avoid all that if the page lock is not contended.
Quoted 5 lines
Quoted 1 line
What's wrong with using
wait_on_page_locked, like everyone else does?When
fscache_read_or_alloc_pages()is called from, say,nfs_readpages(), and is given a few hundred pages to readahead from the cache, who does thewait_on_page_locked()on each of the _backing_ fs's pages?
Presumably: at the point where data is needed.
Quoted 6 lines
The way I've arranged things to work is for the backing fs pages to be copied to the netfs pages and released in the order they're read from the disk.
There's a small pool of threads that processes the pages. I don't want to have to create a thread for each
readpages(), and I don't wantreadpages()to have to wait for all the requests it makes.
Or do you actually have numbers showing a problem if you just read the pages then copy them?
If there is a problem, then why doesn't fscache_read_or_alloc_pages caller do the work itself, then you get as many threads as you have indivisible work units, so completing some part of the request before another wouldn't gain you anything anyway...
David Howells
maintainerRe: [PATCH 23/43] CacheFiles: Permit the page lock state to be monitored [ver #46]
Quoted 1 line · Nick Piggin
Presumably: at the point where data is needed.
But the point where the data is needed is where filemap.c is waiting on a netfs page. Maybe the sync_page() aop can deal with it
There's also the problem of recording and pinning the backing page I'm waiting for. Currently I can do that by hooking the monitor block into the page unlock watching list. If I don't do that, I have to use up yet more memory to track those some other way. It's not impossible, but I'd like to keep memory usage down.
Quoted 2 lines
Or do you actually have numbers showing a problem if you just read the pages then copy them?
I did, years ago. It wasn't particularly good, but fscache_read_or_alloc_pages() was completely synchronous.
Quoted 4 lines
If there is a problem, then why doesn't
fscache_read_or_alloc_pagescaller do the work itself, then you get as many threads as you have indivisible work units, so completing some part of the request before another wouldn't gain you anything anyway...
(1) Trond stipulated FS-Cache had to be asynchronous, and it is, as far as I can make it. I still have to invoke bmap() synchronously, though, to find out whether I have a page in the cache to read:-/
(2) You lose the advantage of being able to process what you've got whilst the disk is fetching stuff in the background.
David
Re: [PATCH 23/43] CacheFiles: Permit the page lock state to be monitored [ver #46]
Quoted 6 lines · On Friday 03 April 2009 04:05:07 David Howells wrote:
Quoted 1 line · Nick Piggin
Presumably: at the point where data is needed.
But the point where the data is needed is where
filemap.cis waiting on a netfs page. Maybe thesync_page()aop can deal with it
I was thinking of more like just have some threads submitting the reads and unlocking the waiters.
Quoted 11 lines
There's also the problem of recording and pinning the backing page I'm waiting for. Currently I can do that by hooking the monitor block into the page unlock watching list. If I don't do that, I have to use up yet more memory to track those some other way. It's not impossible, but I'd like to keep memory usage down.
Quoted 2 lines
Or do you actually have numbers showing a problem if you just read the pages then copy them?
I did, years ago. It wasn't particularly good, but
fscache_read_or_alloc_pages()was completely synchronous.
Performance wasn't good? Why?
Quoted 8 lines
Quoted 4 lines
If there is a problem, then why doesn't
fscache_read_or_alloc_pagescaller do the work itself, then you get as many threads as you have indivisible work units, so completing some part of the request before another wouldn't gain you anything anyway...(1) Trond stipulated FS-Cache had to be asynchronous, and it is, as far as I can make it. I still have to invoke
bmap()synchronously, though, to find out whether I have a page in the cache to read:-/
Why does it have to be asynchronous? Seems like an incredible complexity. ->readpage is called only in synchonous contexts, and ->readpages not but do you even have the netfs filesystem request readahead on the backing filesystem? (which then presumably tries to do readahead of its own)
Quoted 2 lines
(2) You lose the advantage of being able to process what you've got whilst the disk is fetching stuff in the background.
This should happen via readahead on the underlying filesystem, shouldn't it?
Re: [PATCH 23/43] CacheFiles: Permit the page lock state to be monitored [ver #46]
In reply to David HowellsQuoted 9 lines · David Howells
Add a function to install a monitor on the page lock waitqueue for a particular page, thus allowing the page being unlocked to be detected.
This is used by CacheFiles to detect read completion on a page in the backing filesystem so that it can then copy the data to the waiting netfs page.
Signed-off-by David Howells <[email protected]>Acked-by Steve Dickson <[email protected]>Acked-by Trond Myklebust <[email protected]>
David Howells
maintainerPATCH 24/43 CacheFiles: Export things for CacheFiles [ver #46]
In reply to David HowellsExport a number of functions for CacheFiles's use.
---
fs/super.c | 1 + security/security.c | 2 ++ 2 files changed, 3 insertions(+), 0 deletions(-)
fs/super.c +1 -0
@@ -287,6 +287,7 @@ int fsync_super(struct super_block *sb)__fsync_super (sb);return sync_blockdev (sb->s_bdev); } +EXPORT_SYMBOL_GPL (fsync_super);/** * generic_shutdown_super - common helper for ->kill_sb()
security/security.c +2 -0
@@ -445,6 +445,7 @@ int security_inode_create(struct inode *dir, struct dentry *dentry, int mode)return 0 ;return security_ops->inode_create (dir, dentry, mode); } +EXPORT_SYMBOL_GPL (security_inode_create);int security_inode_link (struct dentry *old_dentry,struct inode *dir,struct dentry *new_dentry)
@@ -475,6 +476,7 @@ int security_inode_mkdir(struct inode *dir, struct dentry *dentry, int mode)return 0 ;return security_ops->inode_mkdir (dir, dentry, mode); } +EXPORT_SYMBOL_GPL (security_inode_mkdir);int security_inode_rmdir (struct inode *dir,struct dentry *dentry) {
Re: [PATCH 24/43] CacheFiles: Export things for CacheFiles [ver #46]
Quoted 6 lines · David Howells
Export a number of functions for CacheFiles's use.
Signed-off-by David Howells <[email protected]>Acked-by Steve Dickson <[email protected]>Acked-by Trond Myklebust <[email protected]>
David Howells
maintainerPATCH 25/43 CacheFiles: A cache that backs onto a mounted filesystem [ver #46]
In reply to David HowellsAdd an FS-Cache cache-backend that permits a mounted filesystem to be used as a backing store for the cache.
CacheFiles uses a userspace daemon to do some of the cache management - such as reaping stale nodes and culling. This is called cachefilesd and lives in /sbin. The source for the daemon can be downloaded from:
http://people.redhat.com/~dhowells/cachefs/cachefilesd.c
And an example configuration from:
http://people.redhat.com/~dhowells/cachefs/cachefilesd.conf
The filesystem and data integrity of the cache are only as good as those of the filesystem providing the backing services. Note that CacheFiles does not attempt to journal anything since the journalling interfaces of the various filesystems are very specific in nature.
CacheFiles creates a misc character device - "/dev/cachefiles" - that is used to communication with the daemon. Only one thing may have this open at once, and whilst it is open, a cache is at least partially in existence. The daemon opens this and sends commands down it to control the cache.
CacheFiles is currently limited to a single cache.
CacheFiles attempts to maintain at least a certain percentage of free space on the filesystem, shrinking the cache by culling the objects it contains to make space if necessary - see the "Cache Culling" section. This means it can be placed on the same medium as a live set of data, and will expand to make use of spare space and automatically contract when the set of data requires more space.
============
REQUIREMENTS
============
The use of CacheFiles and its daemon requires the following features to be available in the system and in the cache filesystem:
- dnotify.
- extended attributes (xattrs).
- openat() and friends.
- bmap() support on files in the filesystem (FIBMAP ioctl).
- The use of bmap() to detect a partial page at the end of the file.
It is strongly recommended that the "dir_index" option is enabled on Ext3 filesystems being used as a cache.
=============
CONFIGURATION
=============
The cache is configured by a script in /etc/cachefilesd.conf. These commands set up cache ready for use. The following script commands are available:
(*) brun <N>%
(*) bcull <N>%
(*) bstop <N>%
(*) frun <N>%
(*) fcull <N>%
(*) fstop <N>%
Configure the culling limits. Optional. See the section on culling The defaults are 7% (run), 5% (cull) and 1% (stop) respectively.
The commands beginning with a 'b' are file space (block) limits, those beginning with an 'f' are file count limits.
(*) dir <path>
Specify the directory containing the root of the cache. Mandatory.
(*) tag <name>
Specify a tag to FS-Cache to use in distinguishing multiple caches. Optional. The default is "CacheFiles".
(*) debug <mask>
Specify a numeric bitmask to control debugging in the kernel module. Optional. The default is zero (all off). The following values can be OR'd into the mask to collect various information:
1 Turn on trace of function entry (_enter() macros)
2 Turn on trace of function exit (_leave() macros)
4 Turn on trace of internal debug points (_debug())
This mask can also be set through sysfs, eg:
echo 5 >/sys/modules/cachefiles/parameters/debug
==================
STARTING THE CACHE
==================
The cache is started by running the daemon. The daemon opens the cache device, configures the cache and tells it to begin caching. At that point the cache binds to fscache and the cache becomes live.
The daemon is run as follows:
/sbin/cachefilesd [-d]* [-s] [-n] [-f <configfile>]
The flags are:
(*) -d
Increase the debugging level. This can be specified multiple times and is cumulative with itself.
(*) -s
Send messages to stderr instead of syslog.
(*) -n
Don't daemonise and go into background.
(*) -f <configfile>
Use an alternative configuration file rather than the default one.
===============
THINGS TO AVOID
===============
Do not mount other things within the cache as this will cause problems. The kernel module contains its own very cut-down path walking facility that ignores mountpoints, but the daemon can't avoid them.
Do not create, rename or unlink files and directories in the cache whilst the cache is active, as this may cause the state to become uncertain.
Renaming files in the cache might make objects appear to be other objects (the filename is part of the lookup key).
Do not change or remove the extended attributes attached to cache files by the cache as this will cause the cache state management to get confused.
Do not create files or directories in the cache, lest the cache get confused or serve incorrect data.
Do not chmod files in the cache. The module creates things with minimal permissions to prevent random users being able to access them directly.
=============
CACHE CULLING
=============
The cache may need culling occasionally to make space. This involves discarding objects from the cache that have been used less recently than anything else. Culling is based on the access time of data objects. Empty directories are culled if not in use.
Cache culling is done on the basis of the percentage of blocks and the percentage of files available in the underlying filesystem. There are six "limits":
(*) brun
(*) frun
If the amount of free space and the number of available files in the cache rises above both these limits, then culling is turned off.
(*) bcull
(*) fcull
If the amount of available space or the number of available files in the cache falls below either of these limits, then culling is started.
(*) bstop
(*) fstop
If the amount of available space or the number of available files in the cache falls below either of these limits, then no further allocation of disk space or files is permitted until culling has raised things above these limits again.
These must be configured thusly:
0 <= bstop < bcull < brun < 100 0 <= fstop < fcull < frun < 100
Note that these are percentages of available space and available files, and do _not_ appear as 100 minus the percentage displayed by the "df" program.
The userspace daemon scans the cache to build up a table of cullable objects. These are then culled in least recently used order. A new scan of the cache is started as soon as space is made in the table. Objects will be skipped if their atimes have changed or if the kernel module says it is still using them.
===============
CACHE STRUCTURE
===============
The CacheFiles module will create two directories in the directory it was given:
(*) cache/
(*) graveyard/
The active cache objects all reside in the first directory. The CacheFiles kernel module moves any retired or culled objects that it can't simply unlink to the graveyard from which the daemon will actually delete them.
The daemon uses dnotify to monitor the graveyard directory, and will delete anything that appears therein.
The module represents index objects as directories with the filename "I..." or "J...". Note that the "cache/" directory is itself a special index.
Data objects are represented as files if they have no children, or directories if they do. Their filenames all begin "D..." or "E...". If represented as a directory, data objects will have a file in the directory called "data" that actually holds the data.
Special objects are similar to data objects, except their filenames begin "S..." or "T...".
If an object has children, then it will be represented as a directory. Immediately in the representative directory are a collection of directories named for hash values of the child object keys with an '@' prepended. Into this directory, if possible, will be placed the representations of the child objects:
INDEX INDEX INDEX DATA FILES ========= ========== ================================= ================ cache/@4a/I03nfs/@30/Ji000000000000000--fHg8hi8400 cache/@4a/I03nfs/@30/Ji000000000000000--fHg8hi8400/@75/Es0g000w...DB1ry cache/@4a/I03nfs/@30/Ji000000000000000--fHg8hi8400/@75/Es0g000w...N22ry cache/@4a/I03nfs/@30/Ji000000000000000--fHg8hi8400/@75/Es0g000w...FP1ry
If the key is so long that it exceeds NAME_MAX with the decorations added on to it, then it will be cut into pieces, the first few of which will be used to make a nest of directories, and the last one of which will be the objects inside the last directory. The names of the intermediate directories will have '+' prepended:
J1223/@23/+xy...z/+kl...m/Epqr
Note that keys are raw data, and not only may they exceed NAME_MAX in size, they may also contain things like '/' and NUL characters, and so they may not be suitable for turning directly into a filename.
To handle this, CacheFiles will use a suitably printable filename directly and "base-64" encode ones that aren't directly suitable. The two versions of object filenames indicate the encoding:
OBJECT TYPE PRINTABLE ENCODED =============== =============== =============== Index "I..." "J..." Data "D..." "E..." Special "S..." "T..."
Intermediate directories are always "@" or "+" as appropriate.
Each object in the cache has an extended attribute label that holds the object type ID (required to distinguish special objects) and the auxiliary data from the netfs. The latter is used to detect stale objects in the cache and update or retire them.
Note that CacheFiles will erase from the cache any file it doesn't recognise or any file of an incorrect type (such as a FIFO file or a device file).
==========================
SECURITY MODEL AND SELINUX
==========================
CacheFiles is implemented to deal properly with the LSM security features of the Linux kernel and the SELinux facility.
One of the problems that CacheFiles faces is that it is generally acting on behalf of a process, and running in that process's context, and that includes a security context that is not appropriate for accessing the cache - either because the files in the cache are inaccessible to that process, or because if the process creates a file in the cache, that file may be inaccessible to other processes.
The way CacheFiles works is to temporarily change the security context (fsuid, fsgid and actor security label) that the process acts as - without changing the security context of the process when it the target of an operation performed by some other process (so signalling and suchlike still work correctly).
When the CacheFiles module is asked to bind to its cache, it:
(1) Finds the security label attached to the root cache directory and uses that as the security label with which it will create files. By default, this is:
cachefiles_var_t
(2) Finds the security label of the process which issued the bind request (presumed to be the cachefilesd daemon), which by default will be:
cachefilesd_t
and asks LSM to supply a security ID as which it should act given the daemon's label. By default, this will be:
cachefiles_kernel_t
SELinux transitions the daemon's security ID to the module's security ID based on a rule of this form in the policy.
type_transition <daemon's-ID> kernel_t : process <module's-ID>;
For instance:
type_transition cachefilesd_t kernel_t : process cachefiles_kernel_t;
The module's security ID gives it permission to create, move and remove files and directories in the cache, to find and access directories and files in the cache, to set and access extended attributes on cache objects, and to read and write files in the cache.
The daemon's security ID gives it only a very restricted set of permissions: it may scan directories, stat files and erase files and directories. It may not read or write files in the cache, and so it is precluded from accessing the data cached therein; nor is it permitted to create new files in the cache.
There are policy source files available in:
http://people.redhat.com/~dhowells/fscache/cachefilesd-0.8.tar.bz2
and later versions. In that tarball, see the files:
cachefilesd.te
cachefilesd.fc
cachefilesd.if
They are built and installed directly by the RPM.
If a non-RPM based system is being used, then copy the above files to their own directory and run:
make -f /usr/share/selinux/devel/Makefile
semodule -i cachefilesd.pp
You will need checkpolicy and selinux-policy-devel installed prior to the build.
By default, the cache is located in /var/fscache, but if it is desirable that it should be elsewhere, than either the above policy files must be altered, or an auxiliary policy must be installed to label the alternate location of the cache.
For instructions on how to add an auxiliary policy to enable the cache to be located elsewhere when SELinux is in enforcing mode, please see:
/usr/share/doc/cachefilesd-*/move-cache.txt
When the cachefilesd rpm is installed; alternatively, the document can be found in the sources.
==================
A NOTE ON SECURITY
==================
CacheFiles makes use of the split security in the task_struct. It allocates its own task_security structure, and redirects current->act_as to point to it when it acts on behalf of another process, in that process's context.
The reason it does this is that it calls vfs_mkdir() and suchlike rather than bypassing security and calling inode ops directly. Therefore the VFS and LSM may deny the CacheFiles access to the cache data because under some circumstances the caching code is running in the security context of whatever process issued the original syscall on the netfs.
Furthermore, should CacheFiles create a file or directory, the security parameters with that object is created (UID, GID, security label) would be derived from that process that issued the system call, thus potentially preventing other processes from accessing the cache - including CacheFiles's cache management daemon (cachefilesd).
What is required is to temporarily override the security of the process that issued the system call. We can't, however, just do an in-place change of the security data as that affects the process as an object, not just as a subject. This means it may lose signals or ptrace events for example, and affects what the process looks like in /proc.
So CacheFiles makes use of a logical split in the security between the objective security (task->sec) and the subjective security (task->act_as). The objective security holds the intrinsic security properties of a process and is never overridden. This is what appears in /proc, and is what is used when a process is the target of an operation by some other process (SIGKILL for example).
The subjective security holds the active security properties of a process, and may be overridden. This is not seen externally, and is used whan a process acts upon another object, for example SIGKILLing another process or opening a file.
LSM hooks exist that allow SELinux (or Smack or whatever) to reject a request for CacheFiles to run in a context of a specific security label, or to create files and directories with another security label.
This documentation is added by the patch to:
Documentation/filesystems/caching/cachefiles.txt
---
Documentation/filesystems/caching/cachefiles.txt | 501 +++++++++++++ fs/Kconfig | 1 fs/Makefile | 1 fs/cachefiles/Kconfig | 39 + fs/cachefiles/Makefile | 18 fs/cachefiles/bind.c | 286 +++++++ fs/cachefiles/daemon.c | 754 +++++++++++++++++++ fs/cachefiles/interface.c | 449 ++++++++++++ fs/cachefiles/internal.h | 360 +++++++++ fs/cachefiles/key.c | 159 ++++ fs/cachefiles/main.c | 106 +++ fs/cachefiles/namei.c | 772 ++++++++++++++++++++ fs/cachefiles/proc.c | 134 +++ fs/cachefiles/rdwr.c | 853 ++++++++++++++++++++++ fs/cachefiles/security.c | 116 +++ fs/cachefiles/xattr.c | 291 ++++++++ 16 files changed, 4840 insertions(+), 0 deletions(-) create mode 100644 Documentation/filesystems/caching/cachefiles.txt create mode 100644 fs/cachefiles/Kconfig create mode 100644 fs/cachefiles/Makefile create mode 100644 fs/cachefiles/bind.c create mode 100644 fs/cachefiles/daemon.c create mode 100644 fs/cachefiles/interface.c create mode 100644 fs/cachefiles/internal.h create mode 100644 fs/cachefiles/key.c create mode 100644 fs/cachefiles/main.c create mode 100644 fs/cachefiles/namei.c create mode 100644 fs/cachefiles/proc.c create mode 100644 fs/cachefiles/rdwr.c create mode 100644 fs/cachefiles/security.c create mode 100644 fs/cachefiles/xattr.c
Documentation/filesystems/caching/cachefiles.txt new file +501 -0
@@ -0,0 +1,501 @@ + =============================================== + CacheFiles: CACHE ON ALREADY MOUNTED FILESYSTEM + =============================================== + +Contents: + + (*) Overview. + + (*) Requirements. + + (*) Configuration. + + (*) Starting the cache. + + (*) Things to avoid. + + (*) Cache culling. + + (*) Cache structure. + + (*) Security model and SELinux. + + (*) A note on security. + + (*) Statistical information. + + (*) Debugging. + + +======== +OVERVIEW +======== + +CacheFiles is a caching backend that's meant to use as a cache a directory on +an already mounted filesystem of a local type (such as Ext3). + +CacheFiles uses a userspace daemon to do some of the cache management - such as +reaping stale nodes and culling. This is called cachefilesd and lives in +/sbin. + +The filesystem and data integrity of the cache are only as good as those of the +filesystem providing the backing services. Note that CacheFiles does not +attempt to journal anything since the journalling interfaces of the various +filesystems are very specific in nature. + +CacheFiles creates a misc character device - "/dev/cachefiles" - that is used +to communication with the daemon. Only one thing may have this open at once, +and whilst it is open, a cache is at least partially in existence. The daemon +opens this and sends commands down it to control the cache. + +CacheFiles is currently limited to a single cache. + +CacheFiles attempts to maintain at least a certain percentage of free space on +the filesystem, shrinking the cache by culling the objects it contains to make +space if necessary - see the "Cache Culling" section. This means it can be +placed on the same medium as a live set of data, and will expand to make use of +spare space and automatically contract when the set of data requires more +space. + + +============ +REQUIREMENTS +============ + +The use of CacheFiles and its daemon requires the following features to be +available in the system and in the cache filesystem: + + - dnotify. + + - extended attributes (xattrs). + + - openat() and friends. + + - bmap() support on files in the filesystem (FIBMAP ioctl). + + - The use of bmap() to detect a partial page at the end of the file. + +It is strongly recommended that the "dir_index" option is enabled on Ext3 +filesystems being used as a cache. + + +============= +CONFIGURATION +============= + +The cache is configured by a script in /etc/cachefilesd.conf. These commands +set up cache ready for use. The following script commands are available: + + (*) brun <N>% + (*) bcull <N>% + (*) bstop <N>% + (*) frun <N>% + (*) fcull <N>% + (*) fstop <N>% + + Configure the culling limits. Optional. See the section on culling + The defaults are 7% (run), 5% (cull) and 1% (stop) respectively. + + The commands beginning with a 'b' are file space (block) limits, those + beginning with an 'f' are file count limits. + + (*) dir <path> + + Specify the directory containing the root of the cache. Mandatory. + + (*) tag <name> + + Specify a tag to FS-Cache to use in distinguishing multiple caches. + Optional. The default is "CacheFiles". + + (*) debug <mask> + + Specify a numeric bitmask to control debugging in the kernel module. + Optional. The default is zero (all off). The following values can be + OR'd into the mask to collect various information: + + 1 Turn on trace of function entry (_enter() macros) + 2 Turn on trace of function exit (_leave() macros) + 4 Turn on trace of internal debug points (_debug()) + + This mask can also be set through sysfs, eg: + + echo 5 >/sys/modules/cachefiles/parameters/debug + + +================== +STARTING THE CACHE +================== + +The cache is started by running the daemon. The daemon opens the cache device, +configures the cache and tells it to begin caching. At that point the cache +binds to fscache and the cache becomes live. + +The daemon is run as follows: + + /sbin/cachefilesd [-d]* [-s] [-n] [-f <configfile>] + +The flags are: + + (*) -d + + Increase the debugging level. This can be specified multiple times and + is cumulative with itself. + + (*) -s + + Send messages to stderr instead of syslog. + + (*) -n + + Don't daemonise and go into background. + + (*) -f <configfile> + + Use an alternative configuration file rather than the default one. + + +=============== +THINGS TO AVOID +=============== + +Do not mount other things within the cache as this will cause problems. The +kernel module contains its own very cut-down path walking facility that ignores +mountpoints, but the daemon can't avoid them. + +Do not create, rename or unlink files and directories in the cache whilst the +cache is active, as this may cause the state to become uncertain. + +Renaming files in the cache might make objects appear to be other objects (the +filename is part of the lookup key). + +Do not change or remove the extended attributes attached to cache files by the +cache as this will cause the cache state management to get confused. + +Do not create files or directories in the cache, lest the cache get confused or +serve incorrect data. + +Do not chmod files in the cache. The module creates things with minimal +permissions to prevent random users being able to access them directly. + + +============= +CACHE CULLING +============= + +The cache may need culling occasionally to make space. This involves +discarding objects from the cache that have been used less recently than +anything else. Culling is based on the access time of data objects. Empty +directories are culled if not in use. + +Cache culling is done on the basis of the percentage of blocks and the +percentage of files available in the underlying filesystem. There are six +"limits": + + (*) brun + (*) frun + + If the amount of free space and the number of available files in the cache + rises above both these limits, then culling is turned off. + + (*) bcull + (*) fcull + + If the amount of available space or the number of available files in the + cache falls below either of these limits, then culling is started. + + (*) bstop + (*) fstop + + If the amount of available space or the number of available files in the + cache falls below either of these limits, then no further allocation of + disk space or files is permitted until culling has raised things above + these limits again. + +These must be configured thusly: + + 0 <= bstop < bcull < brun < 100 + 0 <= fstop < fcull < frun < 100 + +Note that these are percentages of available space and available files, and do +_not_ appear as 100 minus the percentage displayed by the "df" program. + +The userspace daemon scans the cache to build up a table of cullable objects. +These are then culled in least recently used order. A new scan of the cache is +started as soon as space is made in the table. Objects will be skipped if +their atimes have changed or if the kernel module says it is still using them. + + +=============== +CACHE STRUCTURE +=============== + +The CacheFiles module will create two directories in the directory it was +given: + + (*) cache/ + + (*) graveyard/ + +The active cache objects all reside in the first directory. The CacheFiles +kernel module moves any retired or culled objects that it can't simply unlink +to the graveyard from which the daemon will actually delete them. + +The daemon uses dnotify to monitor the graveyard directory, and will delete +anything that appears therein. + + +The module represents index objects as directories with the filename "I..." or +"J...". Note that the "cache/" directory is itself a special index. + +Data objects are represented as files if they have no children, or directories +if they do. Their filenames all begin "D..." or "E...". If represented as a +directory, data objects will have a file in the directory called "data" that +actually holds the data. + +Special objects are similar to data objects, except their filenames begin +"S..." or "T...". + + +If an object has children, then it will be represented as a directory. +Immediately in the representative directory are a collection of directories +named for hash values of the child object keys with an '@' prepended. Into +this directory, if possible, will be placed the representations of the child +objects: + + INDEX INDEX INDEX DATA FILES + ========= ========== ================================= ================ + cache/@4a/I03nfs/@30/Ji000000000000000--fHg8hi8400 + cache/@4a/I03nfs/@30/Ji000000000000000--fHg8hi8400/@75/Es0g000w...DB1ry + cache/@4a/I03nfs/@30/Ji000000000000000--fHg8hi8400/@75/Es0g000w...N22ry + cache/@4a/I03nfs/@30/Ji000000000000000--fHg8hi8400/@75/Es0g000w...FP1ry + + +If the key is so long that it exceeds NAME_MAX with the decorations added on to +it, then it will be cut into pieces, the first few of which will be used to +make a nest of directories, and the last one of which will be the objects +inside the last directory. The names of the intermediate directories will have +'+' prepended: + + J1223/@23/+xy...z/+kl...m/Epqr + + +Note that keys are raw data, and not only may they exceed NAME_MAX in size, +they may also contain things like '/' and NUL characters, and so they may not +be suitable for turning directly into a filename. + +To handle this, CacheFiles will use a suitably printable filename directly and +"base-64" encode ones that aren't directly suitable. The two versions of +object filenames indicate the encoding: + + OBJECT TYPE PRINTABLE ENCODED + =============== =============== =============== + Index "I..." "J..." + Data "D..." "E..." + Special "S..." "T..." + +Intermediate directories are always "@" or "+" as appropriate. + + +Each object in the cache has an extended attribute label that holds the object +type ID (required to distinguish special objects) and the auxiliary data from +the netfs. The latter is used to detect stale objects in the cache and update +or retire them. + + +Note that CacheFiles will erase from the cache any file it doesn't recognise or +any file of an incorrect type (such as a FIFO file or a device file). + + +========================== +SECURITY MODEL AND SELINUX +========================== + +CacheFiles is implemented to deal properly with the LSM security features of +the Linux kernel and the SELinux facility. + +One of the problems that CacheFiles faces is that it is generally acting on +behalf of a process, and running in that process's context, and that includes a +security context that is not appropriate for accessing the cache - either +because the files in the cache are inaccessible to that process, or because if +the process creates a file in the cache, that file may be inaccessible to other +processes. + +The way CacheFiles works is to temporarily change the security context (fsuid, +fsgid and actor security label) that the process acts as - without changing the +security context of the process when it the target of an operation performed by +some other process (so signalling and suchlike still work correctly). + + +When the CacheFiles module is asked to bind to its cache, it: + + (1) Finds the security label attached to the root cache directory and uses + that as the security label with which it will create files. By default, + this is: + + cachefiles_var_t + + (2) Finds the security label of the process which issued the bind request + (presumed to be the cachefilesd daemon), which by default will be: + + cachefilesd_t + + and asks LSM to supply a security ID as which it should act given the + daemon's label. By default, this will be: + + cachefiles_kernel_t + + SELinux transitions the daemon's security ID to the module's security ID + based on a rule of this form in the policy. + + type_transition <daemon's-ID> kernel_t : process <module's-ID>; + + For instance: + + type_transition cachefilesd_t kernel_t : process cachefiles_kernel_t; + + +The module's security ID gives it permission to create, move and remove files +and directories in the cache, to find and access directories and files in the +cache, to set and access extended attributes on cache objects, and to read and +write files in the cache. + +The daemon's security ID gives it only a very restricted set of permissions: it +may scan directories, stat files and erase files and directories. It may +not read or write files in the cache, and so it is precluded from accessing the +data cached therein; nor is it permitted to create new files in the cache. + + +There are policy source files available in: + + http://people.redhat.com/~dhowells/fscache/cachefilesd-0.8.tar.bz2 + +and later versions. In that tarball, see the files: + + cachefilesd.te + cachefilesd.fc + cachefilesd.if + +They are built and installed directly by the RPM. + +If a non-RPM based system is being used, then copy the above files to their own +directory and run: + + make -f /usr/share/selinux/devel/Makefile + semodule -i cachefilesd.pp + +You will need checkpolicy and selinux-policy-devel installed prior to the +build. + + +By default, the cache is located in /var/fscache, but if it is desirable that +it should be elsewhere, than either the above policy files must be altered, or +an auxiliary policy must be installed to label the alternate location of the +cache. + +For instructions on how to add an auxiliary policy to enable the cache to be +located elsewhere when SELinux is in enforcing mode, please see: + + /usr/share/doc/cachefilesd-*/move-cache.txt + +When the cachefilesd rpm is installed; alternatively, the document can be found +in the sources. + + +================== +A NOTE ON SECURITY +================== + +CacheFiles makes use of the split security in the task_struct. It allocates +its own task_security structure, and redirects current->act_as to point to it +when it acts on behalf of another process, in that process's context. + +The reason it does this is that it calls vfs_mkdir() and suchlike rather than +bypassing security and calling inode ops directly. Therefore the VFS and LSM +may deny the CacheFiles access to the cache data because under some +circumstances the caching code is running in the security context of whatever +process issued the original syscall on the netfs. + +Furthermore, should CacheFiles create a file or directory, the security +parameters with that object is created (UID, GID, security label) would be +derived from that process that issued the system call, thus potentially +preventing other processes from accessing the cache - including CacheFiles's +cache management daemon (cachefilesd). + +What is required is to temporarily override the security of the process that +issued the system call. We can't, however, just do an in-place change of the +security data as that affects the process as an object, not just as a subject. +This means it may lose signals or ptrace events for example, and affects what +the process looks like in /proc. + +So CacheFiles makes use of a logical split in the security between the +objective security (task->sec) and the subjective security (task->act_as). The +objective security holds the intrinsic security properties of a process and is +never overridden. This is what appears in /proc, and is what is used when a +process is the target of an operation by some other process (SIGKILL for +example). + +The subjective security holds the active security properties of a process, and +may be overridden. This is not seen externally, and is used whan a process +acts upon another object, for example SIGKILLing another process or opening a +file. + +LSM hooks exist that allow SELinux (or Smack or whatever) to reject a request +for CacheFiles to run in a context of a specific security label, or to create +files and directories with another security label. + + +======================= +STATISTICAL INFORMATION +======================= + +If FS-Cache is compiled with the following option enabled: + + CONFIG_CACHEFILES_HISTOGRAM=y + +then it will gather certain statistics and display them through a proc file. + + (*) /proc/fs/cachefiles/histogram + + cat /proc/fs/cachefiles/histogram + JIFS SECS LOOKUPS MKDIRS CREATES + ===== ===== ========= ========= ========= + + This shows the breakdown of the number of times each amount of time + between 0 jiffies and HZ-1 jiffies a variety of tasks took to run. The + columns are as follows: + + COLUMN TIME MEASUREMENT + ======= ======================================================= + LOOKUPS Length of time to perform a lookup on the backing fs + MKDIRS Length of time to perform a mkdir on the backing fs + CREATES Length of time to perform a create on the backing fs + + Each row shows the number of events that took a particular range of times. + Each step is 1 jiffy in size. The JIFS column indicates the particular + jiffy range covered, and the SECS field the equivalent number of seconds. + + +========= +DEBUGGING +========= + +If CONFIG_CACHEFILES_DEBUG is enabled, the CacheFiles facility can have runtime +debugging enabled by adjusting the value in: + + /sys/module/cachefiles/parameters/debug + +This is a bitmask of debugging streams to enable: + + BIT VALUE STREAM POINT + ======= ======= =============================== ======================= + 0 1 General Function entry trace + 1 2 Function exit trace + 2 4 General + +The appropriate set of values should be OR'd together and the result written to +the control file. For example: + + echo $((1|4|8)) >/sys/module/cachefiles/parameters/debug + +will turn on all function entry debugging.
fs/Kconfig +1 -0
@@ -69,6 +69,7 @@ config GENERIC_ACL menu "Caches" source "fs/fscache/Kconfig" +source "fs/cachefiles/Kconfig" endmenu
fs/Makefile +1 -0
@@ -117,6 +117,7 @@ obj-$(CONFIG_AFS_FS) += afs/ obj-$(CONFIG_BEFS_FS) += befs/ obj-$(CONFIG_HOSTFS) += hostfs/ obj-$(CONFIG_HPPFS) += hppfs/ +obj-$(CONFIG_CACHEFILES) += cachefiles/ obj-$(CONFIG_DEBUG_FS) += debugfs/ obj-$(CONFIG_OCFS2_FS) += ocfs2/ obj-$(CONFIG_BTRFS_FS) += btrfs/
fs/cachefiles/Kconfig new file +39 -0
@@ -0,0 +1,39 @@ + +config CACHEFILES + tristate "Filesystem caching on files" + depends on FSCACHE && BLOCK + help + This permits use of a mounted filesystem as a cache for other + filesystems - primarily networking filesystems - thus allowing fast + local disk to enhance the speed of slower devices. + + See Documentation/filesystems/caching/cachefiles.txt for more + information. + +config CACHEFILES_DEBUG + bool "Debug CacheFiles" + depends on CACHEFILES + help + This permits debugging to be dynamically enabled in the filesystem + caching on files module. If this is set, the debugging output may be + enabled by setting bits in /sys/modules/cachefiles/parameter/debug or + by including a debugging specifier in /etc/cachefilesd.conf. + +config CACHEFILES_HISTOGRAM + bool "Gather latency information on CacheFiles" + depends on CACHEFILES && PROC_FS + help + + This option causes latency information to be gathered on CacheFiles + operation and exported through file: + + /proc/fs/cachefiles/histogram + + The generation of this histogram adds a certain amount of overhead to + execution as there are a number of points at which data is gathered, + and on a multi-CPU system these may be on cachelines that keep + bouncing between CPUs. On the other hand, the histogram may be + useful for debugging purposes. Saying 'N' here is recommended. + + See Documentation/filesystems/caching/cachefiles.txt for more + information.
fs/cachefiles/Makefile new file +18 -0
@@ -0,0 +1,18 @@ +# +# Makefile for caching in a mounted filesystem +# + +cachefiles-y := \ + bind.o \ + daemon.o \ + interface.o \ + key.o \ + main.o \ + namei.o \ + rdwr.o \ + security.o \ + xattr.o + +cachefiles-$(CONFIG_CACHEFILES_HISTOGRAM) += proc.o + +obj-$(CONFIG_CACHEFILES) := cachefiles.o
fs/cachefiles/bind.c new file +286 -0
286 lines not on this page · raw message
fs/cachefiles/daemon.c new file +754 -0
754 lines not on this page · raw message
fs/cachefiles/interface.c new file +449 -0
449 lines not on this page · raw message
fs/cachefiles/internal.h new file +360 -0
360 lines not on this page · raw message
fs/cachefiles/key.c new file +159 -0
159 lines not on this page · raw message
fs/cachefiles/main.c new file +106 -0
106 lines not on this page · raw message
fs/cachefiles/namei.c new file +772 -0
314 lines not on this page · raw message
fs/cachefiles/proc.c new file +134 -0
134 lines not on this page · raw message
fs/cachefiles/rdwr.c new file +853 -0
853 lines not on this page · raw message
fs/cachefiles/security.c new file +116 -0
116 lines not on this page · raw message
fs/cachefiles/xattr.c new file +291 -0
291 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.
David Howells
maintainerPATCH 26/43 FS-Cache: Make kAFS use FS-Cache [ver #46]
In reply to David HowellsThe attached patch makes the kAFS filesystem in fs/afs/ use FS-Cache, and through it any attached caches. The kAFS filesystem will use caching automatically if it's available.
---
fs/afs/Kconfig | 8 + fs/afs/Makefile | 3 fs/afs/cache.c | 503 ++++++++++++++++++++++++++++++++++------------------ fs/afs/cache.h | 15 -- fs/afs/cell.c | 16 +- fs/afs/file.c | 220 +++++++++++++++-------- fs/afs/inode.c | 31 ++- fs/afs/internal.h | 53 +++-- fs/afs/main.c | 27 +-- fs/afs/mntpt.c | 4 fs/afs/vlocation.c | 25 +-- fs/afs/volume.c | 14 + fs/afs/write.c | 21 ++ 13 files changed, 582 insertions(+), 358 deletions(-)
fs/afs/Kconfig +8 -0
@@ -19,3 +19,11 @@ config AFS_DEBUG See <file:Documentation/filesystems/afs.txt> for more information. If unsure, say N. + +config AFS_FSCACHE + bool "Provide AFS client caching support (EXPERIMENTAL)" + depends on EXPERIMENTAL + depends on AFS_FS=m && FSCACHE || AFS_FS=y && FSCACHE=y + help + Say Y here if you want AFS data to be cached locally on disk through + the generic filesystem cache manager
fs/afs/Makefile +3 -0
@@ -2,7 +2,10 @@ # Makefile for Red Hat Linux AFS client. # +afs-cache-$(CONFIG_AFS_FSCACHE) := cache.o + kafs-objs := \ + $(afs-cache-y) \ callback.o \ cell.o \ cmservice.o \
fs/afs/cache.c +325 -178
579 lines not on this page · raw message
fs/afs/cache.h +2 -13
@@ -1,6 +1,6 @@/* AFS local cache management interface * -* Copyright (C) 2002 Red Hat, Inc. All Rights Reserved. +* Copyright (C) 2008 Red Hat, Inc. All Rights Reserved. * Written by David Howells ([email protected]) * * This program is free software; you can redistribute it and/or
@@ -9,15 +9,4 @@* 2 of the License, or (at your option) any later version. */ -#ifndef AFS_CACHE_H -#define AFS_CACHE_H - -#undef AFS_CACHING_SUPPORT - -#include <linux/mm.h> -#ifdef AFS_CACHING_SUPPORT -#include <linux/cachefs.h> -#endif -#include "types.h" - -#endif /* AFS_CACHE_H */ +#include <linux/fscache.h>
fs/afs/cell.c +7 -9
@@ -147,12 +147,11 @@ struct afs_cell *afs_cell_create(const char *name, char *vllist)if (ret <0 ) goto error; -#ifdef AFS_CACHING_SUPPORT -/* put it up for caching */ -cachefs_acquire_cookie (afs_cache_netfs.primary_index, - &afs_vlocation_cache_index_def, - cell, - &cell->cache); +#ifdef CONFIG_AFS_FSCACHE +/* put it up for caching (this never returns an error) */ + cell->cache =fscache_acquire_cookie (afs_cache_netfs.primary_index, + &afs_cell_cache_index_def, + cell);#endif /* add to the cell lists */
@@ -362,10 +361,9 @@ static void afs_cell_destroy(struct afs_cell *cell)list_del_init (&cell->proc_link);up_write (&afs_proc_cells_sem); -#ifdef AFS_CACHING_SUPPORT -cachefs_relinquish_cookie (cell->cache,0 ); +#ifdef CONFIG_AFS_FSCACHE +fscache_relinquish_cookie (cell->cache,0 );#endif -key_put (cell->anonymous_key);kfree (cell);
fs/afs/file.c +143 -77
307 lines not on this page · raw message
fs/afs/inode.c +20 -11
@@ -61,6 +61,11 @@ static int afs_inode_map_status(struct afs_vnode *vnode, struct key *key)return -EBADMSG ; } +#ifdef CONFIG_AFS_FSCACHE +if (vnode->status.size != inode->i_size) +fscache_attr_changed (vnode->cache); +#endif + inode->i_nlink = vnode->status.nlink; inode->i_uid = vnode->status.owner; inode->i_gid =0 ;
@@ -149,15 +154,6 @@ struct inode *afs_iget(struct super_block *sb, struct key *key,return inode; } -#ifdef AFS_CACHING_SUPPORT -/* set up caching before reading the status, as fetch-status reads the -* first page of symlinks to see if they're really mntpts */ -cachefs_acquire_cookie (vnode->volume->cache, -NULL , - vnode, - &vnode->cache); -#endif -if (!status) {/* it's a remotely extant inode */ set_bit (AFS_VNODE_CB_BROKEN , &vnode->flags);
@@ -183,6 +179,15 @@ struct inode *afs_iget(struct super_block *sb, struct key *key, } } +/* set up caching before mapping the status, as map-status reads the +* first page of symlinks to see if they're really mountpoints */ + inode->i_size = vnode->status.size; +#ifdef CONFIG_AFS_FSCACHE + vnode->cache =fscache_acquire_cookie (vnode->volume->cache, + &afs_vnode_cache_index_def, + vnode); +#endif + ret =afs_inode_map_status (vnode, key);if (ret <0 ) goto bad_inode;
@@ -196,6 +201,10 @@ struct inode *afs_iget(struct super_block *sb, struct key *key,/* failure */ bad_inode: +#ifdef CONFIG_AFS_FSCACHE +fscache_relinquish_cookie (vnode->cache,0 ); + vnode->cache =NULL ; +#endif iget_failed (inode);_leave (" = %d [bad]" , ret);return ERR_PTR (ret);
@@ -340,8 +349,8 @@ void afs_clear_inode(struct inode *inode)ASSERT (list_empty (&vnode->writebacks));ASSERT (!vnode->cb_promised); -#ifdef AFS_CACHING_SUPPORT -cachefs_relinquish_cookie (vnode->cache,0 ); +#ifdef CONFIG_AFS_FSCACHE +fscache_relinquish_cookie (vnode->cache,0 ); vnode->cache =NULL ;#endif
fs/afs/internal.h +25 -28
119 lines not on this page · raw message
fs/afs/main.c +7 -20
@@ -1,6 +1,6 @@/* AFS client file system * -* Copyright (C) 2002 Red Hat, Inc. All Rights Reserved. +* Copyright (C) 2002,5 Red Hat, Inc. All Rights Reserved. * Written by David Howells ([email protected]) * * This program is free software; you can redistribute it and/or
@@ -29,18 +29,6 @@ static char *rootcell;module_param (rootcell, charp,0 );MODULE_PARM_DESC (rootcell,"root AFS cell name and VL server IP addr list" ); -#ifdef AFS_CACHING_SUPPORT -static struct cachefs_netfs_operations afs_cache_ops = { - .get_page_cookie = afs_cache_get_page_cookie, -}; - -struct cachefs_netfs afs_cache_netfs = { - .name ="afs" , - .version =0 , - .ops = &afs_cache_ops, -}; -#endif -struct afs_uuid afs_uuid;/*
@@ -104,10 +92,9 @@ static int __init afs_init(void)if (ret <0 )return ret; -#ifdef AFS_CACHING_SUPPORT +#ifdef CONFIG_AFS_FSCACHE /* we want to be able to cache */ - ret =cachefs_register_netfs (&afs_cache_netfs, - &afs_cache_cell_index_def); + ret =fscache_register_netfs (&afs_cache_netfs);if (ret <0 ) goto error_cache;#endif
@@ -142,8 +129,8 @@ error_fs: error_open_socket: error_vl_update_init: error_cell_init: -#ifdef AFS_CACHING_SUPPORT -cachefs_unregister_netfs (&afs_cache_netfs); +#ifdef CONFIG_AFS_FSCACHE +fscache_unregister_netfs (&afs_cache_netfs); error_cache:#endif afs_callback_update_kill ();
@@ -175,8 +162,8 @@ static void __exit afs_exit(void)afs_vlocation_purge ();flush_scheduled_work ();afs_cell_purge (); -#ifdef AFS_CACHING_SUPPORT -cachefs_unregister_netfs (&afs_cache_netfs); +#ifdef CONFIG_AFS_FSCACHE +fscache_unregister_netfs (&afs_cache_netfs);#endif afs_proc_cleanup ();rcu_barrier ();
fs/afs/mntpt.c +2 -2
@@ -173,9 +173,9 @@ static struct vfsmount *afs_mntpt_do_automount(struct dentry *mntpt)if (PageError (page)) goto error; - buf =kmap (page); + buf =kmap_atomic (page,KM_USER0 );memcpy (devname, buf, size); -kunmap (page); +kunmap_atomic (buf,KM_USER0 );page_cache_release (page); page =NULL ;
fs/afs/vlocation.c +13 -12
@@ -281,9 +281,8 @@ static void afs_vlocation_apply_update(struct afs_vlocation *vl, vl->vldb = *vldb; -#ifdef AFS_CACHING_SUPPORT -/* update volume entry in local cache */ -cachefs_update_cookie (vl->cache); +#ifdef CONFIG_AFS_FSCACHE +fscache_update_cookie (vl->cache);#endif }
@@ -304,11 +303,9 @@ static int afs_vlocation_fill_in_record(struct afs_vlocation *vl,memset (&vldb,0 ,sizeof (vldb));/* see if we have an in-cache copy (will set vl->valid if there is) */ -#ifdef AFS_CACHING_SUPPORT -cachefs_acquire_cookie (cell->cache, - &afs_volume_cache_index_def, - vlocation, - &vl->cache); +#ifdef CONFIG_AFS_FSCACHE + vl->cache =fscache_acquire_cookie (vl->cell->cache, + &afs_vlocation_cache_index_def, vl);#endif if (vl->valid) {
@@ -420,6 +417,11 @@ fill_in_record:spin_unlock (&vl->lock);wake_up (&vl->waitq); +/* update volume entry in local cache */ +#ifdef CONFIG_AFS_FSCACHE +fscache_update_cookie (vl->cache); +#endif +/* schedule for regular updates */ afs_vlocation_queue_for_updates (vl); goto success;
@@ -465,7 +467,7 @@ found_in_memory:spin_unlock (&vl->lock); success: -_leave (" = %p" ,vl); +_leave (" = %p" , vl);return vl; error_abandon:
@@ -523,10 +525,9 @@ static void afs_vlocation_destroy(struct afs_vlocation *vl) {_enter ("%p" , vl); -#ifdef AFS_CACHING_SUPPORT -cachefs_relinquish_cookie (vl->cache,0 ); +#ifdef CONFIG_AFS_FSCACHE +fscache_relinquish_cookie (vl->cache,0 );#endif -afs_put_cell (vl->cell);kfree (vl); }
fs/afs/volume.c +6 -8
@@ -124,13 +124,11 @@ struct afs_volume *afs_volume_lookup(struct afs_mount_params *params) }/* attach the cache and volume location */ -#ifdef AFS_CACHING_SUPPORT -cachefs_acquire_cookie (vlocation->cache, - &afs_vnode_cache_index_def, - volume, - &volume->cache); +#ifdef CONFIG_AFS_FSCACHE + volume->cache =fscache_acquire_cookie (vlocation->cache, + &afs_volume_cache_index_def, + volume);#endif -afs_get_vlocation (vlocation); volume->vlocation = vlocation;
@@ -194,8 +192,8 @@ void afs_put_volume(struct afs_volume *volume)up_write (&vlocation->cell->vl_sem);/* finish cleaning up the volume */ -#ifdef AFS_CACHING_SUPPORT -cachefs_relinquish_cookie (volume->cache,0 ); +#ifdef CONFIG_AFS_FSCACHE +fscache_relinquish_cookie (volume->cache,0 );#endif afs_put_vlocation (vlocation);
fs/afs/write.c +21 -0
@@ -780,3 +780,24 @@ int afs_fsync(struct file *file, struct dentry *dentry, int datasync)_leave (" = %d" , ret);return ret; } + +/* +* notification that a previously read-only page is about to become writable +* - if it returns an error, the caller will deliver a bus error signal +*/ +int afs_page_mkwrite (struct vm_area_struct *vma,struct page *page) +{ +struct afs_vnode *vnode =AFS_FS_I (vma->vm_file->f_mapping->host); + +_enter ("{{%x:%u}},{%lx}" , + vnode->fid.vid, vnode->fid.vnode, page->index); + +/* wait for the page to be written to the cache before we allow it to +* be modified */ +#ifdef CONFIG_AFS_FSCACHE +wait_on_page_fscache_write (page); +#endif + +_leave (" = 0" ); +return 0 ; +}
David Howells
maintainerPATCH 27/43 NFS: Add comment banners to some NFS functions [ver #46]
In reply to David HowellsAdd comment banners to some NFS functions so that they can be modified by the NFS fscache patches for further information.
---
fs/nfs/file.c | 26 ++++++++++++++++++++++++++ 1 files changed, 26 insertions(+), 0 deletions(-)
fs/nfs/file.c +26 -0
@@ -409,6 +409,13 @@ static int nfs_write_end(struct file *file, struct address_space *mapping,return copied; } +/* +* Partially or wholly invalidate a page +* - Release the private state associated with a page if undergoing complete +* page invalidation +* - Called if either PG_private or PG_private_2 is set on the page +* - Caller holds page lock +*/ static void nfs_invalidate_page (struct page *page,unsigned long offset) {dfprintk (PAGECACHE ,"NFS: invalidate_page(%p, %lu)\n" , page, offset);
@@ -419,6 +426,12 @@ static void nfs_invalidate_page(struct page *page, unsigned long offset)nfs_wb_page_cancel (page->mapping->host, page); } +/* +* Attempt to release the private state associated with a page +* - Called if either PG_private or PG_private_2 is set on the page +* - Caller holds page lock +* - Return true (may release page) or false (may not) +*/ static int nfs_release_page (struct page *page,gfp_t gfp) {dfprintk (PAGECACHE ,"NFS: release_page(%p)\n" , page);
@@ -427,6 +440,14 @@ static int nfs_release_page(struct page *page, gfp_t gfp)return 0 ; } +/* +* Attempt to clear the private state associated with a page when an error +* occurs that requires the cached contents of an inode to be written back or +* destroyed +* - Called if either PG_private or PG_private_2 is set on the page +* - Caller holds page lock +* - Return 0 if successful, -error otherwise +*/ static int nfs_launder_page (struct page *page) {struct inode *inode = page->mapping->host;
@@ -451,6 +472,11 @@ const struct address_space_operations nfs_file_aops = { .launder_page = nfs_launder_page, }; +/* +* Notification that a PTE pointing to an NFS page is about to be made +* writable, implying that someone is about to modify the page through a +* shared-writable mapping +*/ static int nfs_vm_page_mkwrite (struct vm_area_struct *vma,struct vm_fault *vmf) {struct page *page = vmf->page;
David Howells
maintainerPATCH 28/43 NFS: Add FS-Cache option bit and debug bit [ver #46]
In reply to David HowellsAdd FS-Cache option bit to nfs_server struct. This is set to indicate local on-disk caching is enabled for a particular superblock.
Also add debug bit for local caching operations.
---
include/linux/nfs_fs.h | 1 + include/linux/nfs_fs_sb.h | 2 ++ 2 files changed, 3 insertions(+), 0 deletions(-)
include/linux/nfs_fs.h +1 -0
@@ -583,6 +583,7 @@ extern void * nfs_root_data(void);#define NFSDBG_CALLBACK 0x0100#define NFSDBG_CLIENT 0x0200#define NFSDBG_MOUNT 0x0400 +#define NFSDBG_FSCACHE 0x0800#define NFSDBG_ALL 0xFFFF#ifdef __KERNEL__
include/linux/nfs_fs_sb.h +2 -0
@@ -96,6 +96,8 @@ struct nfs_server {unsigned int acdirmin;unsigned int acdirmax;unsigned int namelen; +unsigned int options;/* extra options enabled by mount */ +#define NFS_OPTION_FSCACHE 0x00000001/* - local caching enabled */ struct nfs_fsid fsid;__u64 maxfilesize;/* maximum file size */
David Howells
maintainerPATCH 29/43 NFS: Permit local filesystem caching to be enabled for NFS [ver #46]
In reply to David HowellsPermit local filesystem caching to be enabled for NFS in the kernel configuration.
---
fs/nfs/Kconfig | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-)
fs/nfs/Kconfig +8 -0
@@ -84,3 +84,11 @@ config ROOT_NFS <file:Documentation/filesystems/nfsroot.txt>. Most people say N here. + +config NFS_FSCACHE + bool "Provide NFS client caching support (EXPERIMENTAL)" + depends on EXPERIMENTAL + depends on NFS_FS=m && FSCACHE || NFS_FS=y && FSCACHE=y + help + Say Y here if you want NFS data to be cached locally on disc through + the general filesystem cache manager
David Howells
maintainerPATCH 30/43 NFS: Register NFS for caching and retrieve the top-level index [ver #46]
In reply to David HowellsRegister NFS for caching and retrieve the top-level cache index object cookie.
---
fs/nfs/Makefile | 1 + fs/nfs/fscache-index.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ fs/nfs/fscache.h | 35 ++++++++++++++++++++++++++++++++++ fs/nfs/inode.c | 8 ++++++++ 4 files changed, 93 insertions(+), 0 deletions(-) create mode 100644 fs/nfs/fscache-index.c create mode 100644 fs/nfs/fscache.h
fs/nfs/Makefile +1 -0
@@ -15,3 +15,4 @@ nfs-$(CONFIG_NFS_V4) += nfs4proc.o nfs4xdr.o nfs4state.o nfs4renewd.o \ callback.o callback_xdr.o callback_proc.o \ nfs4namespace.o nfs-$(CONFIG_SYSCTL) += sysctl.o +nfs-$(CONFIG_NFS_FSCACHE) += fscache-index.o
fs/nfs/fscache-index.c new file +49 -0
49 lines not on this page · raw message
fs/nfs/fscache.h new file +35 -0
@@ -0,0 +1,35 @@ +/* NFS filesystem cache interface definitions +* +* Copyright (C) 2008 Red Hat, Inc. All Rights Reserved. +* Written by David Howells ([email protected]) +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public Licence +* as published by the Free Software Foundation; either version +* 2 of the Licence, or (at your option) any later version. +*/ + +#ifndef _NFS_FSCACHE_H +#define _NFS_FSCACHE_H + +#include <linux/nfs_fs.h> +#include <linux/nfs_mount.h> +#include <linux/nfs4_mount.h> +#include <linux/fscache.h> + +#ifdef CONFIG_NFS_FSCACHE + +/* +* fscache-index.c +*/ +extern struct fscache_netfs nfs_fscache_netfs; + +extern int nfs_fscache_register (void ); +extern void nfs_fscache_unregister (void ); + +#else /* CONFIG_NFS_FSCACHE */ +static inline int nfs_fscache_register (void ) {return 0 ; } +static inline void nfs_fscache_unregister (void ) {} + +#endif /* CONFIG_NFS_FSCACHE */ +#endif /* _NFS_FSCACHE_H */
fs/nfs/inode.c +8 -0
@@ -46,6 +46,7 @@#include "delegation.h" #include "iostat.h" #include "internal.h" +#include "fscache.h" #define NFSDBG_FACILITY NFSDBG_VFS
@@ -1436,6 +1437,10 @@ static int __init init_nfs_fs(void) {int err; + err =nfs_fscache_register (); +if (err <0 ) + goto out7; + err =nfsiod_start ();if (err) goto out6;
@@ -1488,6 +1493,8 @@ out4: out5:nfsiod_stop (); out6: +nfs_fscache_unregister (); +out7:return err; }
@@ -1498,6 +1505,7 @@ static void __exit exit_nfs_fs(void)nfs_destroy_readpagecache ();nfs_destroy_inodecache ();nfs_destroy_nfspagecache (); +nfs_fscache_unregister ();#ifdef CONFIG_PROC_FS rpc_proc_unregister ("nfs" );#endif
David Howells
maintainerPATCH 31/43 NFS: Define and create server-level objects [ver #46]
In reply to David HowellsDefine and create server-level cache index objects (as managed by nfs_client structs).
Each server object is created in the NFS top-level index object and is itself an index into which superblock-level objects are inserted.
Ideally there would be one superblock-level object per server, and the former would be folded into the latter; however, since the "nosharecache" option exists this isn't possible.
The server object key is a sequence consisting of:
(1) NFS version
(2) Server address family (eg: AF_INET or AF_INET6)
(3) Server port.
(4) Server IP address.
The key blob is of variable length, depending on the length of (4).
The server object is given no coherency data to carry in the auxiliary data permitted by the cache.
---
fs/nfs/Makefile | 2 + fs/nfs/client.c | 5 +++ fs/nfs/fscache-index.c | 65 +++++++++++++++++++++++++++++++++++++++++++++ fs/nfs/fscache.c | 52 ++++++++++++++++++++++++++++++++++++ fs/nfs/fscache.h | 10 +++++++ include/linux/nfs_fs_sb.h | 4 +++ 6 files changed, 137 insertions(+), 1 deletions(-) create mode 100644 fs/nfs/fscache.c
fs/nfs/Makefile +1 -1
@@ -15,4 +15,4 @@ nfs-$(CONFIG_NFS_V4) += nfs4proc.o nfs4xdr.o nfs4state.o nfs4renewd.o \ callback.o callback_xdr.o callback_proc.o \ nfs4namespace.o nfs-$(CONFIG_SYSCTL) += sysctl.o -nfs-$(CONFIG_NFS_FSCACHE) += fscache-index.o +nfs-$(CONFIG_NFS_FSCACHE) += fscache.o fscache-index.o
fs/nfs/client.c +5 -0
@@ -45,6 +45,7 @@#include "delegation.h" #include "iostat.h" #include "internal.h" +#include "fscache.h" #define NFSDBG_FACILITY NFSDBG_CLIENT
@@ -154,6 +155,8 @@ static struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *cl_if (!IS_ERR (cred)) clp->cl_machine_cred = cred; +nfs_fscache_get_client_cookie (clp); +return clp; error_3:
@@ -187,6 +190,8 @@ static void nfs_free_client(struct nfs_client *clp)nfs4_shutdown_client (clp); +nfs_fscache_release_client_cookie (clp); +/* -EIO all pending I/O */ if (!IS_ERR (clp->cl_rpcclient))rpc_shutdown_client (clp->cl_rpcclient);
fs/nfs/fscache-index.c +65 -0
68 lines not on this page · raw message
fs/nfs/fscache.c new file +52 -0
52 lines not on this page · raw message
fs/nfs/fscache.h +10 -0
@@ -23,13 +23,23 @@* fscache-index.c */ extern struct fscache_netfs nfs_fscache_netfs; +extern const struct fscache_cookie_def nfs_fscache_server_index_def;extern int nfs_fscache_register (void );extern void nfs_fscache_unregister (void ); +/* +* fscache.c +*/ +extern void nfs_fscache_get_client_cookie (struct nfs_client *); +extern void nfs_fscache_release_client_cookie (struct nfs_client *); +#else /* CONFIG_NFS_FSCACHE */ static inline int nfs_fscache_register (void ) {return 0 ; }static inline void nfs_fscache_unregister (void ) {} +static inline void nfs_fscache_get_client_cookie (struct nfs_client *clp) {} +static inline void nfs_fscache_release_client_cookie (struct nfs_client *clp) {} +#endif /* CONFIG_NFS_FSCACHE */ #endif /* _NFS_FSCACHE_H */
include/linux/nfs_fs_sb.h +4 -0
@@ -64,6 +64,10 @@ struct nfs_client {char cl_ipaddr[48 ];unsigned char cl_id_uniquifier;#endif + +#ifdef CONFIG_NFS_FSCACHE +struct fscache_cookie *fscache;/* client index cache cookie */ +#endif };/*
David Howells
maintainerPATCH 32/43 NFS: Define and create superblock-level objects [ver #46]
In reply to David HowellsDefine and create superblock-level cache index objects (as managed by nfs_server structs).
Each superblock object is created in a server level index object and is itself an index into which inode-level objects are inserted.
Ideally there would be one superblock-level object per server, and the former would be folded into the latter; however, since the "nosharecache" option exists this isn't possible.
The superblock object key is a sequence consisting of:
(1) Certain superblock s_flags.
(2) Various connection parameters that serve to distinguish superblocks for
sget().
(3) The volume FSID.
(4) The security flavour.
(5) The uniquifier length.
(6) The uniquifier text. This is normally an empty string, unless the fsc=xyz mount option was used to explicitly specify a uniquifier.
The key blob is of variable length, depending on the length of (6).
The superblock object is given no coherency data to carry in the auxiliary data permitted by the cache. It is assumed that the superblock is always coherent.
This patch also adds uniquification handling such that two otherwise identical superblocks, at least one of which is marked "nosharecache", won't end up trying to share the on-disk cache. It will be possible to manually provide a uniquifier through a mount option with a later patch to avoid the error otherwise produced.
---
fs/nfs/fscache-index.c | 34 +++++++++++++ fs/nfs/fscache.c | 116 +++++++++++++++++++++++++++++++++++++++++++++ fs/nfs/fscache.h | 49 +++++++++++++++++++ fs/nfs/internal.h | 3 + fs/nfs/super.c | 9 +++ include/linux/nfs_fs_sb.h | 5 ++ 6 files changed, 214 insertions(+), 2 deletions(-)
fs/nfs/fscache-index.c +34 -0
@@ -112,3 +112,37 @@ const struct fscache_cookie_def nfs_fscache_server_index_def = { .type = FSCACHE_COOKIE_TYPE_INDEX, .get_key = nfs_server_get_key, }; + +/* +* Generate a key to describe a superblock key in the main NFS index +*/ +static uint16_t nfs_super_get_key (const void *cookie_netfs_data, +void *buffer,uint16_t bufmax) +{ +const struct nfs_fscache_key *key; +const struct nfs_server *nfss = cookie_netfs_data; +uint16_t len; + + key = nfss->fscache_key; + len =sizeof (key->key) + key->key.uniq_len; +if (len > bufmax) { + len =0 ; + }else { +memcpy (buffer, &key->key,sizeof (key->key)); +memcpy (buffer +sizeof (key->key), + key->key.uniquifier, key->key.uniq_len); + } + +return len; +} + +/* +* Define the superblock object for FS-Cache. This is used to describe a +* superblock object to fscache_acquire_cookie(). It is keyed by all the NFS +* parameters that might cause a separate superblock. +*/ +const struct fscache_cookie_def nfs_fscache_super_index_def = { + .name ="NFS.super" , + .type =FSCACHE_COOKIE_TYPE_INDEX , + .get_key = nfs_super_get_key, +};
fs/nfs/fscache.c +116 -0
125 lines not on this page · raw message
fs/nfs/fscache.h +49 -0
70 lines not on this page · raw message
fs/nfs/internal.h +3 -0
@@ -5,6 +5,8 @@#include <linux/mount.h> #include <linux/security.h> +#define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS) +struct nfs_string ;/* Maximum number of readahead requests
@@ -41,6 +43,7 @@ struct nfs_parsed_mount_data {unsigned int auth_flavor_len;rpc_authflavor_t auth_flavors[1 ];char *client_address; +char *fscache_uniq;struct {struct sockaddr_storage address;
fs/nfs/super.c +7 -2
@@ -60,6 +60,7 @@#include "delegation.h" #include "iostat.h" #include "internal.h" +#include "fscache.h" #define NFSDBG_FACILITY NFSDBG_VFS
@@ -1870,8 +1871,6 @@ static void nfs_clone_super(struct super_block *sb,nfs_initialise_sb (sb); } -#define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS) -static int nfs_compare_mount_options (const struct super_block *s,const struct nfs_server *b,int flags) {const struct nfs_server *a = s->s_fs_info;
@@ -2036,6 +2035,7 @@ static int nfs_get_sb(struct file_system_type *fs_type,if (!s->s_root) {/* initial superblock/root creation */ nfs_fill_super (s, data); +nfs_fscache_get_super_cookie (s, data); } mntroot =nfs_get_root (s, mntfh);
@@ -2056,6 +2056,7 @@ static int nfs_get_sb(struct file_system_type *fs_type, out:kfree (data->nfs_server.hostname);kfree (data->mount_server.hostname); +kfree (data->fscache_uniq);security_free_mnt_opts (&data->lsm_opts); out_free_fh:kfree (mntfh);
@@ -2083,6 +2084,7 @@ static void nfs_kill_super(struct super_block *s)bdi_unregister (&server->backing_dev_info);kill_anon_super (s); +nfs_fscache_release_super_cookie (s);nfs_free_server (server); }
@@ -2390,6 +2392,7 @@ static int nfs4_get_sb(struct file_system_type *fs_type,if (!s->s_root) {/* initial superblock/root creation */ nfs4_fill_super (s); +nfs_fscache_get_super_cookie (s, data); } mntroot =nfs4_get_root (s, mntfh);
@@ -2411,6 +2414,7 @@ out:kfree (data->client_address);kfree (data->nfs_server.export_path);kfree (data->nfs_server.hostname); +kfree (data->fscache_uniq);security_free_mnt_opts (&data->lsm_opts); out_free_fh:kfree (mntfh);
@@ -2437,6 +2441,7 @@ static void nfs4_kill_super(struct super_block *sb)kill_anon_super (sb);nfs4_renewd_prepare_shutdown (server); +nfs_fscache_release_super_cookie (sb);nfs_free_server (server); }
include/linux/nfs_fs_sb.h +5 -0
@@ -108,6 +108,11 @@ struct nfs_server {unsigned long mount_time;/* when this fs was mounted */ dev_t s_dev;/* superblock dev numbers */ +#ifdef CONFIG_NFS_FSCACHE +struct nfs_fscache_key *fscache_key;/* unique key for superblock */ +struct fscache_cookie *fscache;/* superblock cookie */ +#endif +#ifdef CONFIG_NFS_V4 u32 attr_bitmask[2 ];/* V4 bitmask representing the set of attributes supported on this
David Howells
maintainerPATCH 33/43 NFS: Define and create inode-level cache objects [ver #46]
In reply to David HowellsDefine and create inode-level cache data storage objects (as managed by nfs_inode structs).
Each inode-level object is created in a superblock-level index object and is itself a data storage object into which pages from the inode are stored.
The inode object key is the NFS file handle for the inode.
The inode object is given coherency data to carry in the auxiliary data permitted by the cache. This is a sequence made up of:
(1) i_mtime from the NFS inode.
(2) i_ctime from the NFS inode.
(3) i_size from the NFS inode.
(4) change_attr from the NFSv4 attribute data.
As the cache is a persistent cache, the auxiliary data is checked when a new NFS in-memory inode is set up that matches an already existing data storage object in the cache. If the coherency data is the same, the on-disk object is retained and used; if not, it is scrapped and a new one created.
---
fs/nfs/fscache-index.c | 123 ++++++++++++++++++++++++++++++++++++++++++++++++ fs/nfs/fscache.h | 1 2 files changed, 124 insertions(+), 0 deletions(-)
fs/nfs/fscache-index.c +123 -0
@@ -146,3 +146,126 @@ const struct fscache_cookie_def nfs_fscache_super_index_def = { .type = FSCACHE_COOKIE_TYPE_INDEX, .get_key = nfs_super_get_key, }; + +/* +* Definition of the auxiliary data attached to NFS inode storage objects +* within the cache. +* +* The contents of this struct are recorded in the on-disk local cache in the +* auxiliary data attached to the data storage object backing an inode. This +* permits coherency to be managed when a new inode binds to an already extant +* cache object. +*/ +struct nfs_fscache_inode_auxdata { +struct timespec mtime; +struct timespec ctime; +loff_t size; +u64 change_attr; +}; + +/* +* Generate a key to describe an NFS inode in an NFS server's index +*/ +static uint16_t nfs_fscache_inode_get_key (const void *cookie_netfs_data, +void *buffer,uint16_t bufmax) +{ +const struct nfs_inode *nfsi = cookie_netfs_data; +uint16_t nsize; + +/* use the inode's NFS filehandle as the key */ + nsize = nfsi->fh.size; +memcpy (buffer, nfsi->fh.data, nsize); +return nsize; +} + +/* +* Get certain file attributes from the netfs data +* - This function can be absent for an index +* - Not permitted to return an error +* - The netfs data from the cookie being used as the source is presented +*/ +static void nfs_fscache_inode_get_attr (const void *cookie_netfs_data, +uint64_t *size) +{ +const struct nfs_inode *nfsi = cookie_netfs_data; + + *size = nfsi->vfs_inode.i_size; +} + +/* +* Get the auxiliary data from netfs data +* - This function can be absent if the index carries no state data +* - Should store the auxiliary data in the buffer +* - Should return the amount of amount stored +* - Not permitted to return an error +* - The netfs data from the cookie being used as the source is presented +*/ +static uint16_t nfs_fscache_inode_get_aux (const void *cookie_netfs_data, +void *buffer,uint16_t bufmax) +{ +struct nfs_fscache_inode_auxdata auxdata; +const struct nfs_inode *nfsi = cookie_netfs_data; + +memset (&auxdata,0 ,sizeof (auxdata)); + auxdata.size = nfsi->vfs_inode.i_size; + auxdata.mtime = nfsi->vfs_inode.i_mtime; + auxdata.ctime = nfsi->vfs_inode.i_ctime; + +if (NFS_SERVER (&nfsi->vfs_inode)->nfs_client->rpc_ops->version ==4 ) + auxdata.change_attr = nfsi->change_attr; + +if (bufmax >sizeof (auxdata)) + bufmax =sizeof (auxdata); + +memcpy (buffer, &auxdata, bufmax); +return bufmax; +} + +/* +* Consult the netfs about the state of an object +* - This function can be absent if the index carries no state data +* - The netfs data from the cookie being used as the target is +* presented, as is the auxiliary data +*/ +static +enum fscache_checkaux nfs_fscache_inode_check_aux (void *cookie_netfs_data, +const void *data, +uint16_t datalen) +{ +struct nfs_fscache_inode_auxdata auxdata; +struct nfs_inode *nfsi = cookie_netfs_data; + +if (datalen !=sizeof (auxdata)) +return FSCACHE_CHECKAUX_OBSOLETE ; + +memset (&auxdata,0 ,sizeof (auxdata)); + auxdata.size = nfsi->vfs_inode.i_size; + auxdata.mtime = nfsi->vfs_inode.i_mtime; + auxdata.ctime = nfsi->vfs_inode.i_ctime; + +if (NFS_SERVER (&nfsi->vfs_inode)->nfs_client->rpc_ops->version ==4 ) + auxdata.change_attr = nfsi->change_attr; + +if (memcmp (data, &auxdata, datalen) !=0 ) +return FSCACHE_CHECKAUX_OBSOLETE ; + +return FSCACHE_CHECKAUX_OKAY ; +} + +/* +* Define the inode object for FS-Cache. This is used to describe an inode +* object to fscache_acquire_cookie(). It is keyed by the NFS file handle for +* an inode. +* +* Coherency is managed by comparing the copies of i_size, i_mtime and i_ctime +* held in the cache auxiliary data for the data storage object with those in +* the inode struct in memory. +*/ +const struct fscache_cookie_def nfs_fscache_inode_object_def = { + .name ="NFS.fh" , + .type =FSCACHE_COOKIE_TYPE_DATAFILE , + .get_key = nfs_fscache_inode_get_key, + .get_attr = nfs_fscache_inode_get_attr, + .get_aux = nfs_fscache_inode_get_aux, + .check_aux = nfs_fscache_inode_check_aux, +};
fs/nfs/fscache.h +1 -0
@@ -62,6 +62,7 @@ struct nfs_fscache_key {extern struct fscache_netfs nfs_fscache_netfs;extern const struct fscache_cookie_def nfs_fscache_server_index_def;extern const struct fscache_cookie_def nfs_fscache_super_index_def; +extern const struct fscache_cookie_def nfs_fscache_inode_object_def;extern int nfs_fscache_register (void );extern void nfs_fscache_unregister (void );
David Howells
maintainerPATCH 34/43 NFS: Use local disk inode cache [ver #46]
In reply to David HowellsBind data storage objects in the local cache to NFS inodes.
---
fs/nfs/fscache.c | 162 ++++++++++++++++++++++++++++++++++++++++++++++++ fs/nfs/fscache.h | 13 ++++ fs/nfs/inode.c | 6 ++ include/linux/nfs_fs.h | 10 +++ 4 files changed, 191 insertions(+), 0 deletions(-)
fs/nfs/fscache.c +162 -0
@@ -166,3 +166,165 @@ void nfs_fscache_release_super_cookie(struct super_block *sb) nfss->fscache_key =NULL ; } } + +/* +* Initialise the per-inode cache cookie pointer for an NFS inode. +*/ +void nfs_fscache_init_inode_cookie (struct inode *inode) +{ +NFS_I (inode)->fscache =NULL ; +if (S_ISREG (inode->i_mode)) +set_bit (NFS_INO_FSCACHE , &NFS_I (inode)->flags); +} + +/* +* Get the per-inode cache cookie for an NFS inode. +*/ +static void nfs_fscache_enable_inode_cookie (struct inode *inode) +{ +struct super_block *sb = inode->i_sb; +struct nfs_inode *nfsi =NFS_I (inode); + +if (nfsi->fscache || !NFS_FSCACHE (inode)) +return ; + +if ((NFS_SB (sb)->options &NFS_OPTION_FSCACHE )) { + nfsi->fscache =fscache_acquire_cookie ( +NFS_SB (sb)->fscache, + &nfs_fscache_inode_object_def, + nfsi); + +dfprintk (FSCACHE ,"NFS: get FH cookie (0x%p/0x%p/0x%p)\n" , + sb, nfsi, nfsi->fscache); + } +} + +/* +* Release a per-inode cookie. +*/ +void nfs_fscache_release_inode_cookie (struct inode *inode) +{ +struct nfs_inode *nfsi =NFS_I (inode); + +dfprintk (FSCACHE ,"NFS: clear cookie (0x%p/0x%p)\n" , + nfsi, nfsi->fscache); + +fscache_relinquish_cookie (nfsi->fscache,0 ); + nfsi->fscache =NULL ; +} + +/* +* Retire a per-inode cookie, destroying the data attached to it. +*/ +void nfs_fscache_zap_inode_cookie (struct inode *inode) +{ +struct nfs_inode *nfsi =NFS_I (inode); + +dfprintk (FSCACHE ,"NFS: zapping cookie (0x%p/0x%p)\n" , + nfsi, nfsi->fscache); + +fscache_relinquish_cookie (nfsi->fscache,1 ); + nfsi->fscache =NULL ; +} + +/* +* Turn off the cache with regard to a per-inode cookie if opened for writing, +* invalidating all the pages in the page cache relating to the associated +* inode to clear the per-page caching. +*/ +static void nfs_fscache_disable_inode_cookie (struct inode *inode) +{ +clear_bit (NFS_INO_FSCACHE , &NFS_I (inode)->flags); + +if (NFS_I (inode)->fscache) { +dfprintk (FSCACHE , +"NFS: nfsi 0x%p turning cache off\n" ,NFS_I (inode)); + +/* Need to invalidate any mapped pages that were read in before +* turning off the cache. +*/ +if (inode->i_mapping && inode->i_mapping->nrpages) +invalidate_inode_pages2 (inode->i_mapping); + +nfs_fscache_zap_inode_cookie (inode); + } +} + +/* +* wait_on_bit() sleep function for uninterruptible waiting +*/ +static int nfs_fscache_wait_bit (void *flags) +{ +schedule (); +return 0 ; +} + +/* +* Lock against someone else trying to also acquire or relinquish a cookie +*/ +static inline void nfs_fscache_inode_lock (struct inode *inode) +{ +struct nfs_inode *nfsi =NFS_I (inode); + +while (test_and_set_bit (NFS_INO_FSCACHE_LOCK , &nfsi->flags)) +wait_on_bit (&nfsi->flags,NFS_INO_FSCACHE_LOCK , + nfs_fscache_wait_bit,TASK_UNINTERRUPTIBLE ); +} + +/* +* Unlock cookie management lock +*/ +static inline void nfs_fscache_inode_unlock (struct inode *inode) +{ +struct nfs_inode *nfsi =NFS_I (inode); + +smp_mb__before_clear_bit (); +clear_bit (NFS_INO_FSCACHE_LOCK , &nfsi->flags); +smp_mb__after_clear_bit (); +wake_up_bit (&nfsi->flags,NFS_INO_FSCACHE_LOCK ); +} + +/* +* Decide if we should enable or disable local caching for this inode. +* - For now, with NFS, only regular files that are open read-only will be able +* to use the cache. +* - May be invoked multiple times in parallel by parallel nfs_open() functions. +*/ +void nfs_fscache_set_inode_cookie (struct inode *inode,struct file *filp) +{ +if (NFS_FSCACHE (inode)) { +nfs_fscache_inode_lock (inode); +if ((filp->f_flags &O_ACCMODE ) !=O_RDONLY ) +nfs_fscache_disable_inode_cookie (inode); +else +nfs_fscache_enable_inode_cookie (inode); +nfs_fscache_inode_unlock (inode); + } +} + +/* +* Replace a per-inode cookie due to revalidation detecting a file having +* changed on the server. +*/ +void nfs_fscache_reset_inode_cookie (struct inode *inode) +{ +struct nfs_inode *nfsi =NFS_I (inode); +struct nfs_server *nfss =NFS_SERVER (inode); +struct fscache_cookie *old = nfsi->fscache; + +nfs_fscache_inode_lock (inode); +if (nfsi->fscache) { +/* retire the current fscache cache and get a new one */ +fscache_relinquish_cookie (nfsi->fscache,1 ); + + nfsi->fscache =fscache_acquire_cookie ( + nfss->nfs_client->fscache, + &nfs_fscache_inode_object_def, + nfsi); + +dfprintk (FSCACHE , +"NFS: revalidation new cookie (0x%p/0x%p/0x%p/0x%p)\n" , + nfss, nfsi, old, nfsi->fscache); + } +nfs_fscache_inode_unlock (inode); +}
fs/nfs/fscache.h +13 -0
@@ -77,6 +77,12 @@ extern void nfs_fscache_get_super_cookie(struct super_block *, struct nfs_parsed_mount_data *);extern void nfs_fscache_release_super_cookie (struct super_block *); +extern void nfs_fscache_init_inode_cookie (struct inode *); +extern void nfs_fscache_release_inode_cookie (struct inode *); +extern void nfs_fscache_zap_inode_cookie (struct inode *); +extern void nfs_fscache_set_inode_cookie (struct inode *,struct file *); +extern void nfs_fscache_reset_inode_cookie (struct inode *); +#else /* CONFIG_NFS_FSCACHE */ static inline int nfs_fscache_register (void ) {return 0 ; }static inline void nfs_fscache_unregister (void ) {}
@@ -91,5 +97,12 @@ static inline void nfs_fscache_get_super_cookie( }static inline void nfs_fscache_release_super_cookie (struct super_block *sb) {} +static inline void nfs_fscache_init_inode_cookie (struct inode *inode) {} +static inline void nfs_fscache_release_inode_cookie (struct inode *inode) {} +static inline void nfs_fscache_zap_inode_cookie (struct inode *inode) {} +static inline void nfs_fscache_set_inode_cookie (struct inode *inode, +struct file *filp) {} +static inline void nfs_fscache_reset_inode_cookie (struct inode *inode) {} +#endif /* CONFIG_NFS_FSCACHE */ #endif /* _NFS_FSCACHE_H */
fs/nfs/inode.c +6 -0
@@ -122,6 +122,7 @@ void nfs_clear_inode(struct inode *inode)BUG_ON (!list_empty (&NFS_I (inode)->open_files));nfs_zap_acl_cache (inode);nfs_access_zap_cache (inode); +nfs_fscache_release_inode_cookie (inode); }/**
@@ -356,6 +357,8 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr) nfsi->attrtimeo_timestamp = now; nfsi->access_cache =RB_ROOT ; +nfs_fscache_init_inode_cookie (inode); +unlock_new_inode (inode); }else nfs_refresh_inode (inode, fattr);
@@ -687,6 +690,7 @@ int nfs_open(struct inode *inode, struct file *filp) ctx->mode = filp->f_mode;nfs_file_set_open_context (filp, ctx);put_nfs_open_context (ctx); +nfs_fscache_set_inode_cookie (inode, filp);return 0 ; }
@@ -787,6 +791,7 @@ static int nfs_invalidate_mapping_nolock(struct inode *inode, struct address_spamemset (nfsi->cookieverf,0 ,sizeof (nfsi->cookieverf));spin_unlock (&inode->i_lock);nfs_inc_stats (inode,NFSIOS_DATAINVALIDATE ); +nfs_fscache_reset_inode_cookie (inode);dfprintk (PAGECACHE ,"NFS: (%s/%Ld) data cache invalidated\n" , inode->i_sb->s_id, (long long )NFS_FILEID (inode));return 0 ;
@@ -1031,6 +1036,7 @@ int nfs_refresh_inode(struct inode *inode, struct nfs_fattr *fattr)spin_lock (&inode->i_lock); status =nfs_refresh_inode_locked (inode, fattr);spin_unlock (&inode->i_lock); +return status; }
include/linux/nfs_fs.h +10 -0
@@ -185,6 +185,9 @@ struct nfs_inode {fmode_t delegation_state;struct rw_semaphore rwsem;#endif /* CONFIG_NFS_V4*/ +#ifdef CONFIG_NFS_FSCACHE +struct fscache_cookie *fscache; +#endif struct inode vfs_inode; };
@@ -207,6 +210,8 @@ struct nfs_inode {#define NFS_INO_ACL_LRU_SET (2)/* Inode is on the LRU list */ #define NFS_INO_MOUNTPOINT (3)/* inode is remote mountpoint */ #define NFS_INO_FLUSHING (4)/* inode is flushing out data */ +#define NFS_INO_FSCACHE (5)/* inode can be cached by FS-Cache */ +#define NFS_INO_FSCACHE_LOCK (6)/* FS-Cache cookie management lock */ static inline struct nfs_inode *NFS_I (const struct inode *inode) {
@@ -260,6 +265,11 @@ static inline int NFS_STALE(const struct inode *inode)return test_bit (NFS_INO_STALE , &NFS_I (inode)->flags); } +static inline int NFS_FSCACHE (const struct inode *inode) +{ +return test_bit (NFS_INO_FSCACHE , &NFS_I (inode)->flags); +} +static inline __u64 NFS_FILEID (const struct inode *inode) {return NFS_I (inode)->fileid;
David Howells
maintainerPATCH 35/43 NFS: Invalidate FsCache page flags when cache removed [ver #46]
In reply to David HowellsInvalidate the FsCache page flags on the pages belonging to an inode when the cache backing that NFS inode is removed.
This allows a live cache to be withdrawn.
---
fs/nfs/fscache-index.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 files changed, 40 insertions(+), 0 deletions(-)
fs/nfs/fscache-index.c +40 -0
@@ -253,6 +253,45 @@ enum fscache_checkaux nfs_fscache_inode_check_aux(void *cookie_netfs_data, }/* +* Indication from FS-Cache that the cookie is no longer cached +* - This function is called when the backing store currently caching a cookie +* is removed +* - The netfs should use this to clean up any markers indicating cached pages +* - This is mandatory for any object that may have data +*/ +static void nfs_fscache_inode_now_uncached (void *cookie_netfs_data) +{ +struct nfs_inode *nfsi = cookie_netfs_data; +struct pagevec pvec; +pgoff_t first; +int loop, nr_pages; + +pagevec_init (&pvec,0 ); + first =0 ; + +dprintk ("NFS: nfs_inode_now_uncached: nfs_inode 0x%p\n" , nfsi); + +for (;;) { +/* grab a bunch of pages to unmark */ + nr_pages =pagevec_lookup (&pvec, + nfsi->vfs_inode.i_mapping, + first, +PAGEVEC_SIZE -pagevec_count (&pvec)); +if (!nr_pages) +break ; + +for (loop =0 ; loop < nr_pages; loop++) +ClearPageFsCache (pvec.pages[loop]); + + first = pvec.pages[nr_pages -1 ]->index +1 ; + + pvec.nr = nr_pages; +pagevec_release (&pvec); +cond_resched (); + } +} + +/* * Define the inode object for FS-Cache. This is used to describe an inode * object to fscache_acquire_cookie(). It is keyed by the NFS file handle for * an inode.
@@ -268,4 +307,5 @@ const struct fscache_cookie_def nfs_fscache_inode_object_def = { .get_attr = nfs_fscache_inode_get_attr, .get_aux = nfs_fscache_inode_get_aux, .check_aux = nfs_fscache_inode_check_aux, + .now_uncached = nfs_fscache_inode_now_uncached, };
David Howells
maintainerPATCH 36/43 NFS: Add some new I/O counters for FS-Cache doing things for NFS [ver #46]
In reply to David HowellsAdd some new NFS I/O counters for FS-Cache doing things for NFS. A new line is emitted into /proc/pid/mountstats if caching is enabled that looks like:
fsc: <rok> <rfl> <wok> <wfl> <unc>
Where <rok> is the number of pages read successfully from the cache, <rfl> is the number of failed page reads against the cache, <wok> is the number of successful page writes to the cache, <wfl> is the number of failed page writes to the cache, and <unc> is the number of NFS pages that have been disconnected from the cache.
---
fs/nfs/iostat.h | 18 ++++++++++++++++++ fs/nfs/super.c | 11 +++++++++++ include/linux/nfs_iostat.h | 12 ++++++++++++ 3 files changed, 41 insertions(+), 0 deletions(-)
fs/nfs/iostat.h +18 -0
@@ -16,6 +16,9 @@struct nfs_iostats {unsigned long long bytes[__NFSIOS_BYTESMAX]; +#ifdef CONFIG_NFS_FSCACHE +unsigned long long fscache[__NFSIOS_FSCACHEMAX]; +#endif unsigned long events[__NFSIOS_COUNTSMAX]; }____cacheline_aligned ;
@@ -57,6 +60,21 @@ static inline void nfs_add_stats(const struct inode *inode,nfs_add_server_stats (NFS_SERVER (inode), stat, addend); } +#ifdef CONFIG_NFS_FSCACHE +static inline void nfs_add_fscache_stats (struct inode *inode, +enum nfs_stat_fscachecounters stat, +unsigned long addend) +{ +struct nfs_iostats *iostats; +int cpu; + + cpu =get_cpu (); + iostats =per_cpu_ptr (NFS_SERVER (inode)->io_stats, cpu); + iostats->fscache[stat] += addend; +put_cpu_no_resched (); +} +#endif +static inline struct nfs_iostats *nfs_alloc_iostats (void ) { return alloc_percpu(struct nfs_iostats);
fs/nfs/super.c +11 -0
@@ -642,6 +642,10 @@ static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt) totals.events[i] += stats->events[i];for (i =0 ; i < __NFSIOS_BYTESMAX; i++) totals.bytes[i] += stats->bytes[i]; +#ifdef CONFIG_NFS_FSCACHE +for (i =0 ; i < __NFSIOS_FSCACHEMAX; i++) + totals.fscache[i] += stats->fscache[i]; +#endif preempt_enable (); }
@@ -652,6 +656,13 @@ static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)seq_printf (m,"\n\tbytes:\t" );for (i =0 ; i < __NFSIOS_BYTESMAX; i++)seq_printf (m,"%Lu " , totals.bytes[i]); +#ifdef CONFIG_NFS_FSCACHE +if (nfss->options &NFS_OPTION_FSCACHE ) { +seq_printf (m,"\n\tfsc:\t" ); +for (i =0 ; i < __NFSIOS_FSCACHEMAX; i++) +seq_printf (m,"%Lu " , totals.bytes[i]); + } +#endif seq_printf (m,"\n" );rpc_print_iostats (m, nfss->client);
include/linux/nfs_iostat.h +12 -0
@@ -116,4 +116,16 @@ enum nfs_stat_eventcounters { __NFSIOS_COUNTSMAX, }; +/* +* NFS local caching servicing counters +*/ +enum nfs_stat_fscachecounters { +NFSIOS_FSCACHE_PAGES_READ_OK , +NFSIOS_FSCACHE_PAGES_READ_FAIL , +NFSIOS_FSCACHE_PAGES_WRITTEN_OK , +NFSIOS_FSCACHE_PAGES_WRITTEN_FAIL , +NFSIOS_FSCACHE_PAGES_UNCACHED , + __NFSIOS_FSCACHEMAX, +}; +#endif /* _LINUX_NFS_IOSTAT */
David Howells
maintainerPATCH 37/43 NFS: FS-Cache page management [ver #46]
In reply to David HowellsFS-Cache page management for NFS. This includes hooking the releasing and invalidation of pages marked with PG_fscache (aka PG_private_2) and waiting for completion of the write-to-cache flag (PG_fscache_write aka PG_owner_priv_2).
---
fs/nfs/file.c | 17 +++++++++++++---- fs/nfs/fscache.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ fs/nfs/fscache.h | 22 ++++++++++++++++++++++ 3 files changed, 86 insertions(+), 4 deletions(-)
fs/nfs/file.c +13 -4
@@ -35,6 +35,7 @@#include "delegation.h" #include "internal.h" #include "iostat.h" +#include "fscache.h" #define NFSDBG_FACILITY NFSDBG_FILE
@@ -413,7 +414,7 @@ static int nfs_write_end(struct file *file, struct address_space *mapping,* Partially or wholly invalidate a page * - Release the private state associated with a page if undergoing complete * page invalidation -* - Called if either PG_private or PG_private_2 is set on the page +* - Called if either PG_private or PG_fscache is set on the page * - Caller holds page lock */ static void nfs_invalidate_page (struct page *page,unsigned long offset)
@@ -424,11 +425,13 @@ static void nfs_invalidate_page(struct page *page, unsigned long offset)return ;/* Cancel any unstarted writes on this page */ nfs_wb_page_cancel (page->mapping->host, page); + +nfs_fscache_invalidate_page (page, page->mapping->host); }/* * Attempt to release the private state associated with a page -* - Called if either PG_private or PG_private_2 is set on the page +* - Called if either PG_private or PG_fscache is set on the page * - Caller holds page lock * - Return true (may release page) or false (may not) */
@@ -437,14 +440,16 @@ static int nfs_release_page(struct page *page, gfp_t gfp)dfprintk (PAGECACHE ,"NFS: release_page(%p)\n" , page);/* If PagePrivate() is set, then the page is not freeable */ -return 0 ; +if (PagePrivate (page)) +return 0 ; +return nfs_fscache_release_page (page, gfp); }/* * Attempt to clear the private state associated with a page when an error * occurs that requires the cached contents of an inode to be written back or * destroyed -* - Called if either PG_private or PG_private_2 is set on the page +* - Called if either PG_private or fscache is set on the page * - Caller holds page lock * - Return 0 if successful, -error otherwise */
@@ -455,6 +460,7 @@ static int nfs_launder_page(struct page *page)dfprintk (PAGECACHE ,"NFS: launder_page(%ld, %llu)\n" , inode->i_ino, (long long )page_offset (page)); +wait_on_page_fscache_write (page);return nfs_wb_page (inode, page); }
@@ -491,6 +497,9 @@ static int nfs_vm_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf) filp->f_mapping->host->i_ino, (long long)page_offset(page)); +/* make sure the cache has finished storing the page */ +wait_on_page_fscache_write (page); +lock_page (page); mapping = page->mapping;if (mapping != dentry->d_inode->i_mapping)
fs/nfs/fscache.c +51 -0
60 lines not on this page · raw message
fs/nfs/fscache.h +22 -0
@@ -83,6 +83,21 @@ extern void nfs_fscache_zap_inode_cookie(struct inode *);extern void nfs_fscache_set_inode_cookie (struct inode *,struct file *);extern void nfs_fscache_reset_inode_cookie (struct inode *); +extern void __nfs_fscache_invalidate_page (struct page *,struct inode *); +extern int nfs_fscache_release_page (struct page *,gfp_t ); + +/* +* release the caching state associated with a page if undergoing complete page +* invalidation +*/ +static inline void nfs_fscache_invalidate_page (struct page *page, +struct inode *inode) +{ +if (PageFsCache (page)) +__nfs_fscache_invalidate_page (page, inode); +} + +#else /* CONFIG_NFS_FSCACHE */ static inline int nfs_fscache_register (void ) {return 0 ; }static inline void nfs_fscache_unregister (void ) {}
@@ -104,5 +119,12 @@ static inline void nfs_fscache_set_inode_cookie(struct inode *inode, struct file *filp) {}static inline void nfs_fscache_reset_inode_cookie (struct inode *inode) {} +static inline int nfs_fscache_release_page (struct page *page,gfp_t gfp) +{ +return 1 ;/* True: may release page */ +} +static inline void nfs_fscache_invalidate_page (struct page *page, +struct inode *inode) {} +#endif /* CONFIG_NFS_FSCACHE */ #endif /* _NFS_FSCACHE_H */
David Howells
maintainerPATCH 38/43 NFS: Add read context retention for FS-Cache to call back with [ver #46]
In reply to David HowellsAdd read context retention so that FS-Cache can call back into NFS when a read operation on the cache fails EIO rather than reading data. This permits NFS to then fetch the data from the server instead using the appropriate security context.
---
fs/nfs/fscache-index.c | 26 ++++++++++++++++++++++++++ 1 files changed, 26 insertions(+), 0 deletions(-)
fs/nfs/fscache-index.c +26 -0
@@ -292,6 +292,30 @@ static void nfs_fscache_inode_now_uncached(void *cookie_netfs_data) }/* +* Get an extra reference on a read context. +* - This function can be absent if the completion function doesn't require a +* context. +* - The read context is passed back to NFS in the event that a data read on the +* cache fails with EIO - in which case the server must be contacted to +* retrieve the data, which requires the read context for security. +*/ +static void nfs_fh_get_context (void *cookie_netfs_data,void *context) +{ +get_nfs_open_context (context); +} + +/* +* Release an extra reference on a read context. +* - This function can be absent if the completion function doesn't require a +* context. +*/ +static void nfs_fh_put_context (void *cookie_netfs_data,void *context) +{ +if (context) +put_nfs_open_context (context); +} + +/* * Define the inode object for FS-Cache. This is used to describe an inode * object to fscache_acquire_cookie(). It is keyed by the NFS file handle for * an inode.
@@ -308,4 +332,6 @@ const struct fscache_cookie_def nfs_fscache_inode_object_def = { .get_aux = nfs_fscache_inode_get_aux, .check_aux = nfs_fscache_inode_check_aux, .now_uncached = nfs_fscache_inode_now_uncached, + .get_context = nfs_fh_get_context, + .put_context = nfs_fh_put_context, };
David Howells
maintainerPATCH 39/43 NFS: nfs_readpage_async() needs to be accessible as a fallback for local caching [ver #46]
In reply to David Howellsnfs_readpage_async() needs to be non-static so that it can be used as a fallback for the local on-disk caching should an EIO crop up when reading the cache.
---
fs/nfs/read.c | 4 ++-- include/linux/nfs_fs.h | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-)
fs/nfs/read.c +2 -2
@@ -111,8 +111,8 @@ static void nfs_readpage_truncate_uninitialised_page(struct nfs_read_data *data) } } -static int nfs_readpage_async (struct nfs_open_context *ctx,struct inode *inode, -struct page *page) +int nfs_readpage_async (struct nfs_open_context *ctx,struct inode *inode, +struct page *page) {LIST_HEAD (one_request);struct nfs_page *new;
include/linux/nfs_fs.h +2 -0
@@ -516,6 +516,8 @@ extern int nfs_readpages(struct file *, struct address_space *, struct list_head *, unsigned);extern int nfs_readpage_result (struct rpc_task *,struct nfs_read_data *);extern void nfs_readdata_release (void *data); +extern int nfs_readpage_async (struct nfs_open_context *,struct inode *, +struct page *);/* * Allocate nfs_read_data structures
David Howells
maintainerPATCH 40/43 NFS: Read pages from FS-Cache into an NFS inode [ver #46]
In reply to David HowellsRead pages from an FS-Cache data storage object representing an inode into an NFS inode.
---
fs/nfs/fscache.c | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/nfs/fscache.h | 47 +++++++++++++++++++++++ fs/nfs/read.c | 18 +++++++++ 3 files changed, 177 insertions(+), 0 deletions(-)
fs/nfs/fscache.c +112 -0
@@ -379,3 +379,115 @@ void __nfs_fscache_invalidate_page(struct page *page, struct inode *inode)nfs_add_fscache_stats (page->mapping->host,NFSIOS_FSCACHE_PAGES_UNCACHED ,1 ); } + +/* +* Handle completion of a page being read from the cache. +* - Called in process (keventd) context. +*/ +static void nfs_readpage_from_fscache_complete (struct page *page, +void *context, +int error) +{ +dfprintk (FSCACHE , +"NFS: readpage_from_fscache_complete (0x%p/0x%p/%d)\n" , + page, context, error); + +/* if the read completes with an error, we just unlock the page and let +* the VM reissue the readpage */ +if (!error) { +SetPageUptodate (page); +unlock_page (page); + }else { + error =nfs_readpage_async (context, page->mapping->host, page); +if (error) +unlock_page (page); + } +} + +/* +* Retrieve a page from fscache +*/ +int __nfs_readpage_from_fscache (struct nfs_open_context *ctx, +struct inode *inode,struct page *page) +{ +int ret; + +dfprintk (FSCACHE , +"NFS: readpage_from_fscache(fsc:%p/p:%p(i:%lx f:%lx)/0x%p)\n" , +NFS_I (inode)->fscache, page, page->index, page->flags, inode); + + ret =fscache_read_or_alloc_page (NFS_I (inode)->fscache, + page, + nfs_readpage_from_fscache_complete, + ctx, +GFP_KERNEL ); + +switch (ret) { +case 0 :/* read BIO submitted (page in fscache) */ +dfprintk (FSCACHE , +"NFS: readpage_from_fscache: BIO submitted\n" ); +nfs_add_fscache_stats (inode,NFSIOS_FSCACHE_PAGES_READ_OK ,1 ); +return ret; + +case -ENOBUFS :/* inode not in cache */ +case -ENODATA :/* page not in cache */ +nfs_add_fscache_stats (inode,NFSIOS_FSCACHE_PAGES_READ_FAIL ,1 ); +dfprintk (FSCACHE , +"NFS: readpage_from_fscache %d\n" , ret); +return 1 ; + +default : +dfprintk (FSCACHE ,"NFS: readpage_from_fscache %d\n" , ret); +nfs_add_fscache_stats (inode,NFSIOS_FSCACHE_PAGES_READ_FAIL ,1 ); + } +return ret; +} + +/* +* Retrieve a set of pages from fscache +*/ +int __nfs_readpages_from_fscache (struct nfs_open_context *ctx, +struct inode *inode, +struct address_space *mapping, +struct list_head *pages, +unsigned *nr_pages) +{ +int ret, npages = *nr_pages; + +dfprintk (FSCACHE ,"NFS: nfs_getpages_from_fscache (0x%p/%u/0x%p)\n" , +NFS_I (inode)->fscache, npages, inode); + + ret =fscache_read_or_alloc_pages (NFS_I (inode)->fscache, + mapping, pages, nr_pages, + nfs_readpage_from_fscache_complete, + ctx, +mapping_gfp_mask (mapping)); +if (*nr_pages < npages) +nfs_add_fscache_stats (inode,NFSIOS_FSCACHE_PAGES_READ_OK , + npages); +if (*nr_pages >0 ) +nfs_add_fscache_stats (inode,NFSIOS_FSCACHE_PAGES_READ_FAIL , + *nr_pages); + +switch (ret) { +case 0 :/* read submitted to the cache for all pages */ +BUG_ON (!list_empty (pages)); +BUG_ON (*nr_pages !=0 ); +dfprintk (FSCACHE , +"NFS: nfs_getpages_from_fscache: submitted\n" ); + +return ret; + +case -ENOBUFS :/* some pages aren't cached and can't be */ +case -ENODATA :/* some pages aren't cached */ +dfprintk (FSCACHE , +"NFS: nfs_getpages_from_fscache: no page: %d\n" , ret); +return 1 ; + +default : +dfprintk (FSCACHE , +"NFS: nfs_getpages_from_fscache: ret %d\n" , ret); + } + +return ret; +}
fs/nfs/fscache.h +47 -0
64 lines not on this page · raw message
fs/nfs/read.c +18 -0
@@ -24,6 +24,7 @@#include "internal.h" #include "iostat.h" +#include "fscache.h" #define NFSDBG_FACILITY NFSDBG_PAGECACHE
@@ -510,8 +511,15 @@ int nfs_readpage(struct file *file, struct page *page) }else ctx =get_nfs_open_context (nfs_file_open_context (file)); +if (!IS_SYNC (inode)) { + error =nfs_readpage_from_fscache (ctx, inode, page); +if (error ==0 ) + goto out; + } + error =nfs_readpage_async (ctx, inode, page); +out:put_nfs_open_context (ctx);return error; out_unlock:
@@ -584,6 +592,15 @@ int nfs_readpages(struct file *filp, struct address_space *mapping,return -EBADF ; }else desc.ctx =get_nfs_open_context (nfs_file_open_context (filp)); + +/* attempt to read as many of the pages as possible from the cache +* - this returns -ENOBUFS immediately if the cookie is negative +*/ + ret =nfs_readpages_from_fscache (desc.ctx, inode, mapping, + pages, &nr_pages); +if (ret ==0 ) + goto read_complete;/* all pages were read */ +if (rsize <PAGE_CACHE_SIZE )nfs_pageio_init (&pgio, inode, nfs_pagein_multi, rsize,0 );else
@@ -594,6 +611,7 @@ int nfs_readpages(struct file *filp, struct address_space *mapping,nfs_pageio_complete (&pgio); npages = (pgio.pg_bytes_written +PAGE_CACHE_SIZE -1 ) >>PAGE_CACHE_SHIFT ;nfs_add_stats (inode,NFSIOS_READPAGES , npages); +read_complete:put_nfs_open_context (desc.ctx); out:return ret;
David Howells
maintainerPATCH 41/43 NFS: Store pages from an NFS inode into a local cache [ver #46]
In reply to David HowellsStore pages from an NFS inode into the cache data storage object associated with that inode.
---
fs/nfs/fscache.c | 28 ++++++++++++++++++++++++++++ fs/nfs/fscache.h | 16 ++++++++++++++++ fs/nfs/read.c | 5 +++++ 3 files changed, 49 insertions(+), 0 deletions(-)
fs/nfs/fscache.c +28 -0
@@ -491,3 +491,31 @@ int __nfs_readpages_from_fscache(struct nfs_open_context *ctx,return ret; } + +/* +* Store a newly fetched page in fscache +* - PG_fscache must be set on the page +*/ +void __nfs_readpage_to_fscache (struct inode *inode,struct page *page,int sync) +{ +int ret; + +dfprintk (FSCACHE , +"NFS: readpage_to_fscache(fsc:%p/p:%p(i:%lx f:%lx)/%d)\n" , +NFS_I (inode)->fscache, page, page->index, page->flags, sync); + + ret =fscache_write_page (NFS_I (inode)->fscache, page,GFP_KERNEL ); +dfprintk (FSCACHE , +"NFS: readpage_to_fscache: p:%p(i:%lu f:%lx) ret %d\n" , + page, page->index, page->flags, ret); + +if (ret !=0 ) { +fscache_uncache_page (NFS_I (inode)->fscache, page); +nfs_add_fscache_stats (inode, +NFSIOS_FSCACHE_PAGES_WRITTEN_FAIL ,1 ); +nfs_add_fscache_stats (inode,NFSIOS_FSCACHE_PAGES_UNCACHED ,1 ); + }else { +nfs_add_fscache_stats (inode, +NFSIOS_FSCACHE_PAGES_WRITTEN_OK ,1 ); + } +}
fs/nfs/fscache.h +16 -0
@@ -91,6 +91,7 @@ extern int __nfs_readpage_from_fscache(struct nfs_open_context *,extern int __nfs_readpages_from_fscache (struct nfs_open_context *,struct inode *,struct address_space *,struct list_head *,unsigned *); +extern void __nfs_readpage_to_fscache (struct inode *,struct page *,int );/* * release the caching state associated with a page if undergoing complete page
@@ -130,6 +131,19 @@ static inline int nfs_readpages_from_fscache(struct nfs_open_context *ctx, return -ENOBUFS; } +/* +* Store a page newly fetched from the server in an inode data storage object +* in the cache. +*/ +static inline void nfs_readpage_to_fscache (struct inode *inode, +struct page *page, +int sync) +{ +if (PageFsCache (page)) +__nfs_readpage_to_fscache (inode, page, sync); +} + +#else /* CONFIG_NFS_FSCACHE */ static inline int nfs_fscache_register (void ) {return 0 ; }static inline void nfs_fscache_unregister (void ) {}
@@ -172,6 +186,8 @@ static inline int nfs_readpages_from_fscache(struct nfs_open_context *ctx, {return -ENOBUFS ; } +static inline void nfs_readpage_to_fscache (struct inode *inode, +struct page *page,int sync) {}#endif /* CONFIG_NFS_FSCACHE */ #endif /* _NFS_FSCACHE_H */
fs/nfs/read.c +5 -0
@@ -140,6 +140,11 @@ int nfs_readpage_async(struct nfs_open_context *ctx, struct inode *inode,static void nfs_readpage_release (struct nfs_page *req) { +struct inode *d_inode = req->wb_context->path.dentry->d_inode; + +if (PageUptodate (req->wb_page)) +nfs_readpage_to_fscache (d_inode, req->wb_page,0 ); +unlock_page (req->wb_page); dprintk("NFS: read done (%s/%Ld %d@%Ld)\n",
David Howells
maintainerPATCH 42/43 NFS: Display local caching state [ver #46]
In reply to David HowellsDisplay the local caching state in /proc/fs/nfsfs/volumes.
---
fs/nfs/client.c | 7 ++++--- fs/nfs/fscache.h | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-)
fs/nfs/client.c +4 -3
@@ -1564,7 +1564,7 @@ static int nfs_volume_list_show(struct seq_file *m, void *v)/* display header on line 1 */ if (v == &nfs_volume_list) { -seq_puts (m,"NV SERVER PORT DEV FSID\n" ); +seq_puts (m,"NV SERVER PORT DEV FSID FSC\n" );return 0 ; }/* display one transport per line on subsequent lines */
@@ -1578,12 +1578,13 @@ static int nfs_volume_list_show(struct seq_file *m, void *v) (unsigned long long ) server->fsid.major, (unsigned long long) server->fsid.minor); -seq_printf (m,"v%u %s %s %-7s %-17s\n" , +seq_printf (m,"v%u %s %s %-7s %-17s %s\n" , clp->rpc_ops->version,rpc_peeraddr2str (clp->cl_rpcclient,RPC_DISPLAY_HEX_ADDR ),rpc_peeraddr2str (clp->cl_rpcclient,RPC_DISPLAY_HEX_PORT ), dev, - fsid); + fsid, +nfs_server_fscache_state (server));return 0 ; }
fs/nfs/fscache.h +15 -0
@@ -143,6 +143,16 @@ static inline void nfs_readpage_to_fscache(struct inode *inode, __nfs_readpage_to_fscache(inode, page, sync); } +/* +* indicate the client caching state as readable text +*/ +static inline const char *nfs_server_fscache_state (struct nfs_server *server) +{ +if (server->fscache && (server->options &NFS_OPTION_FSCACHE )) +return "yes" ; +return "no " ; +} +#else /* CONFIG_NFS_FSCACHE */ static inline int nfs_fscache_register (void ) {return 0 ; }
@@ -189,5 +199,10 @@ static inline int nfs_readpages_from_fscache(struct nfs_open_context *ctx,static inline void nfs_readpage_to_fscache (struct inode *inode,struct page *page,int sync) {} +static inline const char *nfs_server_fscache_state (struct nfs_server *server) +{ +return "no " ; +} +#endif /* CONFIG_NFS_FSCACHE */ #endif /* _NFS_FSCACHE_H */
David Howells
maintainerPATCH 43/43 NFS: Add mount options to enable local caching on NFS [ver #46]
In reply to David HowellsAdd NFS mount options to allow the local caching support to be enabled.
The attached patch makes it possible for the NFS filesystem to be told to make use of the network filesystem local caching service (FS-Cache).
To be able to use this, a recent nfsutils package is required.
There are three variant NFS mount options that can be added to a mount command to control caching for a mount. Only the last one specified takes effect:
(*) Adding "fsc" will request caching.
(*) Adding "fsc=<string>" will request caching and also specify a uniquifier.
(*) Adding "nofsc" will disable caching.
For example:
mount warthog:/ /a -o fsc
The cache of a particular superblock (NFS FSID) will be shared between all mounts of that volume, provided they have the same connection parameters and are not marked 'nosharecache'.
Where it is otherwise impossible to distinguish superblocks because all the parameters are identical, but the 'nosharecache' option is supplied, a uniquifying string must be supplied, else only the first mount will be permitted to use the cache.
If there's a key collision, then the second mount will disable caching and give a warning into the kernel log.
---
fs/nfs/client.c | 2 ++ fs/nfs/internal.h | 1 + fs/nfs/super.c | 25 +++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 0 deletions(-)
fs/nfs/client.c +2 -0
@@ -765,6 +765,7 @@ static int nfs_init_server(struct nfs_server *server,/* Initialise the client representation from the mount data */ server->flags = data->flags; + server->options = data->options;if (data->rsize) server->rsize =nfs_block_size (data->rsize,NULL );
@@ -1153,6 +1154,7 @@ static int nfs4_init_server(struct nfs_server *server,/* Initialise the client representation from the mount data */ server->flags = data->flags; server->caps |=NFS_CAP_ATOMIC_OPEN ; + server->options = data->options;/* Get a client record */ error = nfs4_set_client(server,
fs/nfs/internal.h +1 -0
@@ -39,6 +39,7 @@ struct nfs_parsed_mount_data {int acregmin, acregmax, acdirmin, acdirmax;int namlen; +unsigned int options;unsigned int bsize;unsigned int auth_flavor_len;rpc_authflavor_t auth_flavors[1 ];
fs/nfs/super.c +25 -0
@@ -77,6 +77,7 @@ enum { Opt_rdirplus, Opt_nordirplus, Opt_sharecache, Opt_nosharecache, Opt_resvport, Opt_noresvport, + Opt_fscache, Opt_nofscache,/* Mount options that take integer arguments */ Opt_port,
@@ -94,6 +95,7 @@ enum { Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost, Opt_addr, Opt_mountaddr, Opt_clientaddr, Opt_lookupcache, + Opt_fscache_uniq,/* Special mount options */ Opt_userspace, Opt_deprecated, Opt_sloppy,
@@ -133,6 +135,9 @@ static const match_table_t nfs_mount_option_tokens = { { Opt_nosharecache, "nosharecache" }, { Opt_resvport, "resvport" }, { Opt_noresvport, "noresvport" }, + { Opt_fscache, "fsc" }, + { Opt_fscache_uniq, "fsc=%s" }, + { Opt_nofscache, "nofsc" }, { Opt_port, "port=%u" }, { Opt_rsize, "rsize=%u" },
@@ -564,6 +569,8 @@ static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,if (clp->rpc_ops->version ==4 )seq_printf (m,",clientaddr=%s" , clp->cl_ipaddr);#endif +if (nfss->options &NFS_OPTION_FSCACHE ) +seq_printf (m,",fsc" ); }/*
@@ -1056,6 +1063,24 @@ static int nfs_parse_mount_options(char *raw,case Opt_noresvport: mnt->flags |=NFS_MOUNT_NORESVPORT ;break ; +case Opt_fscache: + mnt->options |=NFS_OPTION_FSCACHE ; +kfree (mnt->fscache_uniq); + mnt->fscache_uniq =NULL ; +break ; +case Opt_nofscache: + mnt->options &= ~NFS_OPTION_FSCACHE ; +kfree (mnt->fscache_uniq); + mnt->fscache_uniq =NULL ; +break ; +case Opt_fscache_uniq: + string =match_strdup (args); +if (!string) + goto out_nomem; +kfree (mnt->fscache_uniq); + mnt->fscache_uniq = string; + mnt->options |=NFS_OPTION_FSCACHE ; +break ;/* * options that take numeric values