Make frontswap+cleancache and its friend be modularized.
Subsystems (4)
PATCH v3 1/1 Make frontswap+cleancache and its friend be modularized.
Greg, I am CC-ing you here since there is one patch that touches the staging tree:
[PATCH 02/11] frontswap: Make frontswap_init use a pointer for the
I am hoping that for #2 you are OK ACK-ing - it is a simple fix that ought to have been a long time ago.
I am hoping that these patches are ready for the v3.9 merge window and would very much appreciate feedback. If I had missed somebodies comments
- please remind me as these last two weeks have been quite busy for me.
Back to the description:
Parts of this patch have been posted in the post (way back in November), but this patchset expanded it a bit. The goal of the patches is to make the different frontswap/cleancache API backends be modules - and load way way after the swap system (or filesystem) has been initialized. Naturally one can still build the frontswap+cleancache backend devices in the kernel. The next goal (after these patches) is to also be able to unload the backend drivers - but that places some interesting requirements to "reload" the swap device with swap pages (don't need to worry that much about cleancache as it is a "secondary" cache and can be dumped). Seth had posted some patches for that in the zswap backend - and they could be more generally repurporsed.
Anyhow, I did not want to lose the authorship of some of the patches so I didn't squash the ones that were made by Dan and mine. I can do it for review if it would make it easier, but from my recollection on how Linus likes things run he would prefer to keep the history (even the kludge parts).
The general flow prior to these patches was [I am concentrating on the frontswap here, but the cleancache is similar, just s/swapon/mount/]:
1) kernel inits frontswap_init
2) kernel inits zcache (or some other backend)
3) user does swapon /dev/XX and the writes to the swap disk end up in frontswap and then in the backend.
With the module loading, the 1) is still part of the bootup, but the
2) or 3) can be run at anytime. This means one could load the backend _after_ the swap disk has been initialized and running along. Or _before_ the swap disk has been setup - but that is similar to the existing case so not that exciting.
To deal with that scenario the frontswap keeps an queue (actually an atomic bitmap of the swap disks that have been init) and when the backend registers - frontswap runs the backend init on the queued up swap disks.
The interesting thing is that we can be to certain degree racy when the swap system starts steering pages to frontswap. Meaning after the backend has registered it is OK if the pages are still hitting the disk instead of the backend. Naturally this is unacceptable if one were to unload the backend (not yet supported) - as we need to be quite atomic at that stage and need to stop processing the pages the moment the backend is being unloaded. To support this, the frontswap is using the struct static_key which are incredibly light when they are in usage. They are incredibly heavy when the value switches (on/off), but that is OK. The next part of unloading is also taking the pages that are in the backend and feed them in the swap storage (and Seth's patches do some of this).
Also attached is one patch from Minchan that fixes the condition where the backend was constricted in allocating memory at init - b/c we were holding a spin-lock. His patch fixes that and we are just holding the swapon_mutex instead. It has been rebased on top of my patches.
This patchset is based on what is going in general for #linux-next for v3.9 (and can be merged alongside Greg's staging tree).
drivers/staging/zcache/zcache-main.c | 19 +-- drivers/xen/Kconfig | 4 +- drivers/xen/tmem.c | 53 +++++--- drivers/xen/xen-selfballoon.c | 13 +- include/linux/cleancache.h | 27 ++-- include/linux/frontswap.h | 31 ++--- include/xen/tmem.h | 8 ++ mm/cleancache.c | 241 ++++++++++++++++++++++++++++++----- mm/frontswap.c | 126 ++++++++++++++---- mm/swapfile.c | 18 +-- 10 files changed, 417 insertions(+), 123 deletions(-)
Dan Magenheimer (3):
mm: frontswap: lazy initialization to allow tmem backends to build/run as modules
mm: cleancache: lazy initialization to allow tmem backends to build/run as modules
xen: tmem: enable Xen tmem shim to be built/loaded as a module
Konrad Rzeszutek Wilk (7):
frontswap: Make frontswap_init use a pointer for the ops.
frontswap: Remove the check for frontswap_enabled.
frontswap: Use static_key instead of frontswap_enabled and frontswap_ops
cleancache: Make cleancache_init use a pointer for the ops
cleancache: Remove the check for cleancache_enabled.
cleancache: Use static_key instead of cleancache_ops and cleancache_enabled.
zcache/tmem: Better error checking on frontswap_register_ops return value.
Minchan Kim (1):
frontswap: Get rid of swap_lock dependency
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 1/11 mm: frontswap: lazy initialization to allow tmem backends to build/run as modules
From: Dan Magenheimer <[email protected]>
With the goal of allowing tmem backends (zcache, ramster, Xen tmem) to be built/loaded as modules rather than built-in and enabled by a boot parameter, this patch provides "lazy initialization", allowing backends to register to frontswap even after swapon was run. Before a backend registers all calls to init are recorded and the creation of tmem_pools delayed until a backend registers or until a frontswap store is attempted.
--- mm/frontswap.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 85 insertions(+), 10 deletions(-)
mm/frontswap.c +85 -10
@@ -80,6 +80,46 @@ static inline void inc_frontswap_succ_stores(void) { }static inline void inc_frontswap_failed_stores (void ) { }static inline void inc_frontswap_invalidates (void ) { }#endif + +/* +* Due to the asynchronous nature of the backends loading potentially +* _after_ the swap system has been activated, we have chokepoints +* on all frontswap functions to not call the backend until the backend +* has registered. +* +* Specifically when no backend is registered (nobody called +* frontswap_register_ops) all calls to frontswap_init (which is done via +* swapon -> enable_swap_info -> frontswap_init) are registered and remembered +* (via the setting of need_init bitmap) but fail to create tmem_pools. When a +* backend registers with frontswap at some later point the previous +* calls to frontswap_init are executed (by iterating over the need_init +* bitmap) to create tmem_pools and set the respective poolids. All of that is +* guarded by us using atomic bit operations on the 'need_init' bitmap. +* +* This would not guards us against the user deciding to call swapoff right as +* we are calling the backend to initialize (so swapon is in action). +* Fortunatly for us, the swapon_mutex has been taked by the callee so we are +* OK. The other scenario where calls to frontswap_store (called via +* swap_writepage) is racing with frontswap_invalidate_area (called via +* swapoff) is again guarded by the swap subsystem. +* +* While no backend is registered all calls to frontswap_[store|load| +* invalidate_area|invalidate_page] are ignored or fail. +* +* The time between the backend being registered and the swap file system +* calling the backend (via the frontswap_* functions) is indeterminate as +* backend_registered is not atomic_t (or a value guarded by a spinlock). +* That is OK as we are comfortable missing some of these calls to the newly +* registered backend. +* +* Obviously the opposite (unloading the backend) must be done after all +* the frontswap_[store|load|invalidate_area|invalidate_page] start +* ignorning or failing the requests - at which point backend_registered +* would have to be made in some fashion atomic. +*/ +static DECLARE_BITMAP(need_init, MAX_SWAPFILES); +static bool backend_registered__read_mostly ; +/* * Register operations for frontswap, returning previous thus allowing * detection of multiple backends and possible nesting.
@@ -87,9 +127,22 @@ static inline void inc_frontswap_invalidates(void) { }struct frontswap_ops frontswap_register_ops (struct frontswap_ops *ops) {struct frontswap_ops old = frontswap_ops; +int i; frontswap_ops = *ops; frontswap_enabled = true; + +for (i =0 ; i <MAX_SWAPFILES ; i++) { +if (test_and_clear_bit (i, need_init)) + (*frontswap_ops.init)(i); + } +/* +* We MUST have backend_registered set _after_ the frontswap_init's +* have been called. Otherwise __frontswap_store might fail. Hence +* the barrier to make sure compiler does not re-order us. +*/ +barrier (); + backend_registered = true;return old; }EXPORT_SYMBOL (frontswap_register_ops);
@@ -119,10 +172,17 @@ void __frontswap_init(unsigned type) {struct swap_info_struct *sis = swap_info[type]; -BUG_ON (sis ==NULL ); -if (sis->frontswap_map ==NULL ) -return ; - frontswap_ops.init (type); +if (backend_registered) { +BUG_ON (sis ==NULL ); +if (sis->frontswap_map ==NULL ) +return ; + (*frontswap_ops.init)(type); + } +else { +BUG_ON (type >MAX_SWAPFILES ); +set_bit (type, need_init); + } + }EXPORT_SYMBOL (__frontswap_init);
@@ -147,6 +207,11 @@ int __frontswap_store(struct page *page)struct swap_info_struct *sis = swap_info[type];pgoff_t offset =swp_offset (entry); +if (!backend_registered) { +inc_frontswap_failed_stores (); +return ret; + } +BUG_ON (!PageLocked (page));BUG_ON (sis ==NULL );if (frontswap_test (sis, offset))
@@ -186,6 +251,9 @@ int __frontswap_load(struct page *page)struct swap_info_struct *sis = swap_info[type];pgoff_t offset =swp_offset (entry); +if (!backend_registered) +return ret; +BUG_ON (!PageLocked (page));BUG_ON (sis ==NULL );if (frontswap_test (sis, offset))
@@ -209,6 +277,9 @@ void __frontswap_invalidate_page(unsigned type, pgoff_t offset) {struct swap_info_struct *sis = swap_info[type]; +if (!backend_registered) +return ; +BUG_ON (sis ==NULL );if (frontswap_test (sis, offset)) { frontswap_ops.invalidate_page (type, offset);
@@ -226,12 +297,15 @@ void __frontswap_invalidate_area(unsigned type) {struct swap_info_struct *sis = swap_info[type]; -BUG_ON (sis ==NULL ); -if (sis->frontswap_map ==NULL ) -return ; - frontswap_ops.invalidate_area (type); -atomic_set (&sis->frontswap_pages,0 ); -memset (sis->frontswap_map,0 , sis->max /sizeof (long )); +if (backend_registered) { +BUG_ON (sis ==NULL ); +if (sis->frontswap_map ==NULL ) +return ; + (*frontswap_ops.invalidate_area)(type); +atomic_set (&sis->frontswap_pages,0 ); +memset (sis->frontswap_map,0 , sis->max /sizeof (long )); + } +clear_bit (type, need_init); }EXPORT_SYMBOL (__frontswap_invalidate_area);
@@ -364,6 +438,7 @@ static int __init init_frontswap(void)debugfs_create_u64 ("invalidates" ,S_IRUGO , root, &frontswap_invalidates);#endif + frontswap_enabled =1 ;return 0 ; }
Signature · 7 lines
1.8.0.2 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 2/11 frontswap: Make frontswap_init use a pointer for the ops.
In reply to Konrad Rzeszutek WilkThis simplifies the code in the frontswap - we can get rid of the 'backend_registered' test and instead check against frontswap_ops.
[v1: Rebase on top of 703ba7fe5e085f2c85eeb451c2ac13cf275c7cb2 (ramster->zcache move]
--- drivers/staging/zcache/zcache-main.c | 8 ++++---- drivers/xen/tmem.c | 6 +++--- include/linux/frontswap.h | 2 +- mm/frontswap.c | 38 +++++++++++++++++------------------- 4 files changed, 26 insertions(+), 28 deletions(-)
drivers/staging/zcache/zcache-main.c +4 -4
@@ -1825,9 +1825,9 @@ static struct frontswap_ops zcache_frontswap_ops = { .init = zcache_frontswap_init }; -struct frontswap_ops zcache_frontswap_register_ops (void ) +struct frontswap_ops *zcache_frontswap_register_ops (void ) { -struct frontswap_ops old_ops = +struct frontswap_ops *old_ops =frontswap_register_ops (&zcache_frontswap_ops);return old_ops;
@@ -1994,7 +1994,7 @@ static int __init zcache_init(void)pr_warn ("%s: cleancache_ops overridden\n" , namestr); }if (zcache_enabled && !disable_frontswap) { -struct frontswap_ops old_ops; +struct frontswap_ops *old_ops; old_ops =zcache_frontswap_register_ops ();if (frontswap_has_exclusive_gets)
@@ -2006,7 +2006,7 @@ static int __init zcache_init(void) namestr, frontswap_has_exclusive_gets, !disable_frontswap_ignore_nonactive);#endif -if (old_ops.init !=NULL ) +if (old_ops !=NULL )pr_warn ("%s: frontswap_ops overridden\n" , namestr); }if (ramster_enabled)
drivers/xen/tmem.c +3 -3
@@ -362,7 +362,7 @@ static int __init no_frontswap(char *s) }__setup ("nofrontswap" , no_frontswap); -static struct frontswap_ops __initdata tmem_frontswap_ops = { +static struct frontswap_ops tmem_frontswap_ops = { .store = tmem_frontswap_store, .load = tmem_frontswap_load, .invalidate_page = tmem_frontswap_flush_page,
@@ -378,11 +378,11 @@ static int __init xen_tmem_init(void)#ifdef CONFIG_FRONTSWAP if (tmem_enabled && use_frontswap) {char *s ="" ; -struct frontswap_ops old_ops = +struct frontswap_ops *old_ops =frontswap_register_ops (&tmem_frontswap_ops); tmem_frontswap_poolid =-1 ; -if (old_ops.init !=NULL ) +if (old_ops) s =" (WARNING: frontswap_ops overridden)" ;printk (KERN_INFO "frontswap enabled, RAM provided by " "Xen Transcendent Memory\n" );
include/linux/frontswap.h +1 -1
@@ -14,7 +14,7 @@ struct frontswap_ops { };extern bool frontswap_enabled; -extern struct frontswap_ops +extern struct frontswap_ops *frontswap_register_ops (struct frontswap_ops *ops);extern void frontswap_shrink (unsigned long );extern unsigned long frontswap_curr_pages (void );
mm/frontswap.c +18 -20
@@ -24,7 +24,7 @@* frontswap_ops is set by frontswap_register_ops to contain the pointers * to the frontswap "backend" implementation functions. */ -static struct frontswap_ops frontswap_ops__read_mostly ; +static struct frontswap_ops *frontswap_ops__read_mostly ;/* * This global enablement flag reduces overhead on systems where frontswap_ops
@@ -108,41 +108,39 @@ static inline void inc_frontswap_invalidates(void) { }* * The time between the backend being registered and the swap file system * calling the backend (via the frontswap_* functions) is indeterminate as -* backend_registered is not atomic_t (or a value guarded by a spinlock). +* frontswap_ops is not atomic_t (or a value guarded by a spinlock). * That is OK as we are comfortable missing some of these calls to the newly * registered backend. * * Obviously the opposite (unloading the backend) must be done after all * the frontswap_[store|load|invalidate_area|invalidate_page] start -* ignorning or failing the requests - at which point backend_registered +* ignorning or failing the requests - at which point frontswap_ops * would have to be made in some fashion atomic. */ static DECLARE_BITMAP(need_init, MAX_SWAPFILES); -static bool backend_registered__read_mostly ;/* * Register operations for frontswap, returning previous thus allowing * detection of multiple backends and possible nesting. */ -struct frontswap_ops frontswap_register_ops (struct frontswap_ops *ops) +struct frontswap_ops *frontswap_register_ops (struct frontswap_ops *ops) { -struct frontswap_ops old = frontswap_ops; +struct frontswap_ops *old = frontswap_ops;int i; - frontswap_ops = *ops; frontswap_enabled = true;for (i =0 ; i <MAX_SWAPFILES ; i++) {if (test_and_clear_bit (i, need_init)) - (*frontswap_ops.init)(i); + ops->init (i); }/* -* We MUST have backend_registered set _after_ the frontswap_init's +* We MUST have frontswap_ops set _after_ the frontswap_init's * have been called. Otherwise __frontswap_store might fail. Hence * the barrier to make sure compiler does not re-order us. */ barrier (); - backend_registered = true; + frontswap_ops = ops;return old; }EXPORT_SYMBOL (frontswap_register_ops);
@@ -172,11 +170,11 @@ void __frontswap_init(unsigned type) {struct swap_info_struct *sis = swap_info[type]; -if (backend_registered) { +if (frontswap_ops) {BUG_ON (sis ==NULL );if (sis->frontswap_map ==NULL )return ; - (*frontswap_ops.init)(type); + frontswap_ops->init (type); }else {BUG_ON (type >MAX_SWAPFILES );
@@ -207,7 +205,7 @@ int __frontswap_store(struct page *page)struct swap_info_struct *sis = swap_info[type];pgoff_t offset =swp_offset (entry); -if (!backend_registered) { +if (!frontswap_ops) {inc_frontswap_failed_stores ();return ret; }
@@ -216,7 +214,7 @@ int __frontswap_store(struct page *page)BUG_ON (sis ==NULL );if (frontswap_test (sis, offset)) dup =1 ; - ret = frontswap_ops.store (type, offset, page); + ret = frontswap_ops->store (type, offset, page);if (ret ==0 ) {frontswap_set (sis, offset);inc_frontswap_succ_stores ();
@@ -251,13 +249,13 @@ int __frontswap_load(struct page *page)struct swap_info_struct *sis = swap_info[type];pgoff_t offset =swp_offset (entry); -if (!backend_registered) +if (!frontswap_ops)return ret;BUG_ON (!PageLocked (page));BUG_ON (sis ==NULL );if (frontswap_test (sis, offset)) - ret = frontswap_ops.load (type, offset, page); + ret = frontswap_ops->load (type, offset, page);if (ret ==0 ) {inc_frontswap_loads ();if (frontswap_tmem_exclusive_gets_enabled) {
@@ -277,12 +275,12 @@ void __frontswap_invalidate_page(unsigned type, pgoff_t offset) {struct swap_info_struct *sis = swap_info[type]; -if (!backend_registered) +if (!frontswap_ops)return ;BUG_ON (sis ==NULL );if (frontswap_test (sis, offset)) { - frontswap_ops.invalidate_page (type, offset); + frontswap_ops->invalidate_page (type, offset);__frontswap_clear (sis, offset);inc_frontswap_invalidates (); }
@@ -297,11 +295,11 @@ void __frontswap_invalidate_area(unsigned type) {struct swap_info_struct *sis = swap_info[type]; -if (backend_registered) { +if (frontswap_ops) {BUG_ON (sis ==NULL );if (sis->frontswap_map ==NULL )return ; - (*frontswap_ops.invalidate_area)(type); + frontswap_ops->invalidate_area (type);atomic_set (&sis->frontswap_pages,0 );memset (sis->frontswap_map,0 , sis->max /sizeof (long )); }
Signature · 7 lines
1.8.0.2 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 3/11 frontswap: Remove the check for frontswap_enabled.
In reply to Konrad Rzeszutek WilkWith the support for loading of backends as modules (see for example:
"staging: zcache: enable zcache to be built/loaded as a module"), the frontswap_enabled is always set to true ("mm: frontswap: lazy initialization to allow tmem backends to build/run as modules").
The next patch "frontswap: Use static_key instead of frontswap_enabled and frontswap_ops" is are going to convert the frontswap_enabled to be a bit more selective and be on/off depending on whether the backend has registered - and not whether the frontswap API is enabled.
The two functions: frontswap_init and frontswap_invalidate_area can be called anytime - they queue up which of the swap devices are active and can use the frontswap API - once the backend is loaded.
As such there is no need to check for 'frontswap_enabled' at all.
--- include/linux/frontswap.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
include/linux/frontswap.h +2 -4
@@ -116,14 +116,12 @@ static inline void frontswap_invalidate_page(unsigned type, pgoff_t offset)static inline void frontswap_invalidate_area (unsigned type) { -if (frontswap_enabled) -__frontswap_invalidate_area (type); +__frontswap_invalidate_area (type); }static inline void frontswap_init (unsigned type) { -if (frontswap_enabled) -__frontswap_init (type); +__frontswap_init (type); }#endif /* _LINUX_FRONTSWAP_H */
Signature · 7 lines
1.8.0.2 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 4/11 frontswap: Use static_key instead of frontswap_enabled and frontswap_ops
In reply to Konrad Rzeszutek WilkAs ways to determine whether to allow certain functions to be called. This makes it easier to understand the code - the two functions that can be called irregardless whether a backend is set or not is the frontswap_init and frontswap_invalidate_area. The rest of the frontswap functions end up being NOPs if the backend has not yet registered.
--- include/linux/frontswap.h | 17 ++++++++------ mm/frontswap.c | 58 ++++++++++++++++++++--------------------------- 2 files changed, 34 insertions(+), 41 deletions(-)
include/linux/frontswap.h +10 -7
@@ -12,8 +12,6 @@ struct frontswap_ops {void (*invalidate_page)(unsigned ,pgoff_t );void (*invalidate_area)(unsigned ); }; - -extern bool frontswap_enabled;extern struct frontswap_ops *frontswap_register_ops (struct frontswap_ops *ops);extern void frontswap_shrink (unsigned long );
@@ -29,25 +27,30 @@ extern void __frontswap_invalidate_page(unsigned, pgoff_t);extern void __frontswap_invalidate_area (unsigned );#ifdef CONFIG_FRONTSWAP +#include <linux/jump_label.h> + +extern struct static_key frontswap_key; + +#define frontswap_enabled (1)static inline bool frontswap_test (struct swap_info_struct *sis,pgoff_t offset) {bool ret = false; -if (frontswap_enabled && sis->frontswap_map) +if (static_key_false (&frontswap_key) && sis->frontswap_map) ret =test_bit (offset, sis->frontswap_map);return ret; }static inline void frontswap_set (struct swap_info_struct *sis,pgoff_t offset) { -if (frontswap_enabled && sis->frontswap_map) +if (static_key_false (&frontswap_key) && sis->frontswap_map)set_bit (offset, sis->frontswap_map); }static inline void frontswap_clear (struct swap_info_struct *sis,pgoff_t offset) { -if (frontswap_enabled && sis->frontswap_map) +if (static_key_false (&frontswap_key) && sis->frontswap_map)clear_bit (offset, sis->frontswap_map); }
@@ -94,7 +97,7 @@ static inline int frontswap_store(struct page *page) {int ret =-1 ; -if (frontswap_enabled) +if (static_key_false (&frontswap_key)) ret =__frontswap_store (page);return ret; }
@@ -103,7 +106,7 @@ static inline int frontswap_load(struct page *page) {int ret =-1 ; -if (frontswap_enabled) +if (static_key_false (&frontswap_key)) ret =__frontswap_load (page);return ret; }
mm/frontswap.c +24 -34
140 lines not on this page · raw message
Signature · 7 lines
1.8.0.2 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 5/11 frontswap: Get rid of swap_lock dependency
In reply to Konrad Rzeszutek WilkFrom: Minchan Kim <[email protected]>
Frontswap initialization routine depends on swap_lock, which want to be atomic about frontswap's first appearance.
IOW, frontswap is not present and will fail all calls OR frontswap is fully functional but if new swap_info_struct isn't registered by enable_swap_info, swap subsystem doesn't start I/O so there is no race
between init procedure and page I/O working on frontswap.
So let's remove unnecessary swap_lock dependency.
--- include/linux/frontswap.h | 6 +++--- mm/frontswap.c | 29 ++++++++++++++++++++++------- mm/swapfile.c | 18 +++++++++--------- 3 files changed, 34 insertions(+), 19 deletions(-)
include/linux/frontswap.h +3 -3
@@ -20,7 +20,7 @@ extern void frontswap_writethrough(bool);#define FRONTSWAP_HAS_EXCLUSIVE_GETS extern void frontswap_tmem_exclusive_gets (bool ); -extern void __frontswap_init (unsigned type); +extern void __frontswap_init (unsigned type,unsigned long *map);extern int __frontswap_store (struct page *page);extern int __frontswap_load (struct page *page);extern void __frontswap_invalidate_page (unsigned ,pgoff_t );
@@ -122,9 +122,9 @@ static inline void frontswap_invalidate_area(unsigned type) __frontswap_invalidate_area(type); } -static inline void frontswap_init (unsigned type) +static inline void frontswap_init (unsigned type,unsigned long *map) { -__frontswap_init (type); +__frontswap_init (type, map); }#endif /* _LINUX_FRONTSWAP_H */
mm/frontswap.c +22 -7
@@ -127,8 +127,13 @@ struct frontswap_ops *frontswap_register_ops(struct frontswap_ops *ops)int i;for (i =0 ; i <MAX_SWAPFILES ; i++) { -if (test_and_clear_bit (i, need_init)) +if (test_and_clear_bit (i, need_init)) { +struct swap_info_struct *sis = swap_info[i]; +/* __frontswap_init _should_ have set it! */ +if (!sis->frontswap_map) +return ERR_PTR (-EINVAL ); ops->init (i); + } }/* * We MUST have frontswap_ops set _after_ the frontswap_init's
@@ -166,16 +171,26 @@ EXPORT_SYMBOL(frontswap_tmem_exclusive_gets);* * Can be called without any backend driver is registered. */ -void __frontswap_init (unsigned type) +void __frontswap_init (unsigned type,unsigned long *map) {struct swap_info_struct *sis = swap_info[type]; -if (static_key_false (&frontswap_key)) { -BUG_ON (sis ==NULL ); -if (sis->frontswap_map ==NULL ) -return ; +BUG_ON (sis ==NULL ); + +/* +* p->frontswap is a bitmap that we MUST have to figure out which page +* has gone in frontswap. Without it there is no point of continuing. +*/ +if (WARN_ON (!map)) +return ; +/* +* Irregardless of whether the frontswap backend has been loaded +* before this function or it will be later, we _MUST_ have the +* p->frontswap set to something valid to work properly. +*/ +frontswap_map_set (sis, map); +if (static_key_false (&frontswap_key)) frontswap_ops->init (type); - }else {BUG_ON (type >MAX_SWAPFILES );set_bit (type, need_init);
mm/swapfile.c +9 -9
@@ -1444,8 +1444,7 @@ static int setup_swap_extents(struct swap_info_struct *sis, sector_t *span) }static void _enable_swap_info (struct swap_info_struct *p,int prio, -unsigned char *swap_map, -unsigned long *frontswap_map) +unsigned char *swap_map) {int i, prev;
@@ -1454,11 +1453,9 @@ static void _enable_swap_info(struct swap_info_struct *p, int prio,else p->prio = --least_priority; p->swap_map = swap_map; -frontswap_map_set (p, frontswap_map); p->flags |=SWP_WRITEOK ; nr_swap_pages += p->pages; total_swap_pages += p->pages; -/* insert swap space into swap_list: */ prev =-1 ;for (i = swap_list.head; i >=0 ; i = swap_info[i]->next) {
@@ -1477,16 +1474,16 @@ static void enable_swap_info(struct swap_info_struct *p, int prio,unsigned char *swap_map, unsigned long *frontswap_map) { + frontswap_init(p->type, frontswap_map);spin_lock (&swap_lock); -_enable_swap_info (p, prio, swap_map, frontswap_map); -frontswap_init (p->type); +_enable_swap_info (p, prio, swap_map);spin_unlock (&swap_lock); }static void reinsert_swap_info (struct swap_info_struct *p) {spin_lock (&swap_lock); -_enable_swap_info (p, p->prio, p->swap_map,frontswap_map_get (p)); +_enable_swap_info (p, p->prio, p->swap_map);spin_unlock (&swap_lock); }
@@ -1494,6 +1491,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile) {struct swap_info_struct *p =NULL ;unsigned char *swap_map; +unsigned long *frontswap_map;struct file *swap_file, *victim;struct address_space *mapping;struct inode *inode;
@@ -1588,11 +1586,13 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile) swap_map = p->swap_map; p->swap_map =NULL ; p->flags =0 ; -frontswap_invalidate_area (type); + frontswap_map =frontswap_map_get (p); +frontswap_map_set (p,NULL );spin_unlock (&swap_lock); +frontswap_invalidate_area (type);mutex_unlock (&swapon_mutex);vfree (swap_map); -vfree (frontswap_map_get (p)); +vfree (frontswap_map);/* Destroy swap account informatin */ swap_cgroup_swapoff (type);
Signature · 7 lines
1.8.0.2 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 6/11 mm: cleancache: lazy initialization to allow tmem backends to build/run as modules
In reply to Konrad Rzeszutek WilkFrom: Dan Magenheimer <[email protected]>
With the goal of allowing tmem backends (zcache, ramster, Xen tmem) to be built/loaded as modules rather than built-in and enabled by a boot parameter, this patch provides "lazy initialization", allowing backends to register to cleancache even after filesystems were mounted. Calls to init_fs and init_shared_fs are remembered as fake poolids but no real tmem_pools created. On backend registration the fake poolids are mapped to real poolids and respective tmem_pools.
--- mm/cleancache.c | 240 +++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 219 insertions(+), 21 deletions(-)
mm/cleancache.c +219 -21
@@ -45,15 +45,99 @@ static u64 cleancache_puts;static u64 cleancache_invalidates;/* -* register operations for cleancache, returning previous thus allowing -* detection of multiple backends and possible nesting +* When no backend is registered all calls to init_fs and init_shared_fs +* are registered and fake poolids (FAKE_FS_POOLID_OFFSET or +* FAKE_SHARED_FS_POOLID_OFFSET, plus offset in the respective array +* [shared_|]fs_poolid_map) are given to the respective super block +* (sb->cleancache_poolid) and no tmem_pools are created. When a backend +* registers with cleancache the previous calls to init_fs and init_shared_fs +* are executed to create tmem_pools and set the respective poolids. While no +* backend is registered all "puts", "gets" and "flushes" are ignored or failed. +*/ +#define MAX_INITIALIZABLE_FS 32 +#define FAKE_FS_POOLID_OFFSET 1000 +#define FAKE_SHARED_FS_POOLID_OFFSET 2000 + +#define FS_NO_BACKEND (-1) +#define FS_UNKNOWN (-2) +static int fs_poolid_map[MAX_INITIALIZABLE_FS ]; +static int shared_fs_poolid_map[MAX_INITIALIZABLE_FS ]; +static char *uuids[MAX_INITIALIZABLE_FS ]; +/* +* Mutex for the [shared_|]fs_poolid_map to guard against multiple threads +* invoking umount (and ending in __cleancache_invalidate_fs) and also multiple +* threads calling mount (and ending up in __cleancache_init_[shared|]fs). +*/ +static DEFINE_MUTEX (poolid_mutex); +/* +* When set to false (default) all calls to the cleancache functions, except +* the __cleancache_invalidate_fs and __cleancache_init_[shared|]fs are guarded +* by the if (!backend_registered) return. This means multiple threads (from +* different filesystems) will be checking backend_registered. The usage of a +* bool instead of a atomic_t or a bool guarded by a spinlock is OK - we are +* OK if the time between the backend's have been initialized (and +* backend_registered has been set to true) and when the filesystems start +* actually calling the backends. The inverse (when unloading) is obviously +* not good - but this shim does not do that (yet). +*/ +static bool backend_registered__read_mostly ; + +/* +* The backends and filesystems work all asynchronously. This is b/c the +* backends can be built as modules. +* The usual sequence of events is: +* a) mount / -> __cleancache_init_fs is called. We set the +* [shared_|]fs_poolid_map and uuids for. +* +* b). user does I/Os -> we call the rest of __cleancache_* functions +* which return immediately as backend_registered is false. +* +* c). modprobe zcache -> cleancache_register_ops. We init the backend +* and set backend_registered to true, and for any fs_poolid_map +* (which is set by __cleancache_init_fs) we initialize the poolid. +* +* d). user does I/Os -> now that backend_registered is true all the +* __cleancache_* functions can call the backend. They all check +* that fs_poolid_map is valid and if so invoke the backend. +* +* e). umount / -> __cleancache_invalidate_fs, the fs_poolid_map is +* reset (which is the second check in the __cleancache_* ops +* to call the backend). +* +* The sequence of event could also be c), followed by a), and d). and e). The +* c) would not happen anymore. There is also the chance of c), and one thread +* doing a) + d), and another doing e). For that case we depend on the +* filesystem calling __cleancache_invalidate_fs in the proper sequence (so +* that it handles all I/Os before it invalidates the fs (which is last part +* of unmounting process). +* +* Note: The acute reader will notice that there is no "rmmod zcache" case. +* This is b/c the functionality for that is not yet implemented and when +* done, will require some extra locking not yet devised. +*/ + +/* +* Register operations for cleancache, returning previous thus allowing +* detection of multiple backends and possible nesting. */ struct cleancache_ops cleancache_register_ops (struct cleancache_ops *ops) {struct cleancache_ops old = cleancache_ops; +int i; +mutex_lock (&poolid_mutex); cleancache_ops = *ops; - cleancache_enabled =1 ; + + backend_registered = true; +for (i =0 ; i <MAX_INITIALIZABLE_FS ; i++) { +if (fs_poolid_map[i] ==FS_NO_BACKEND ) + fs_poolid_map[i] = (*cleancache_ops.init_fs)(PAGE_SIZE ); +if (shared_fs_poolid_map[i] ==FS_NO_BACKEND ) + shared_fs_poolid_map[i] = (*cleancache_ops.init_shared_fs) + (uuids[i],PAGE_SIZE ); + } +out: +mutex_unlock (&poolid_mutex);return old; }EXPORT_SYMBOL (cleancache_register_ops);
@@ -61,15 +145,42 @@ EXPORT_SYMBOL(cleancache_register_ops);/* Called by a cleancache-enabled filesystem at time of mount */ void __cleancache_init_fs (struct super_block *sb) { - sb->cleancache_poolid = (*cleancache_ops.init_fs)(PAGE_SIZE ); +int i; + +mutex_lock (&poolid_mutex); +for (i =0 ; i <MAX_INITIALIZABLE_FS ; i++) { +if (fs_poolid_map[i] ==FS_UNKNOWN ) { + sb->cleancache_poolid = i +FAKE_FS_POOLID_OFFSET ; +if (backend_registered) + fs_poolid_map[i] = (*cleancache_ops.init_fs)(PAGE_SIZE ); +else + fs_poolid_map[i] =FS_NO_BACKEND ; +break ; + } + } +mutex_unlock (&poolid_mutex); }EXPORT_SYMBOL (__cleancache_init_fs);/* Called by a cleancache-enabled clustered filesystem at time of mount */ void __cleancache_init_shared_fs (char *uuid,struct super_block *sb) { - sb->cleancache_poolid = - (*cleancache_ops.init_shared_fs)(uuid,PAGE_SIZE ); +int i; + +mutex_lock (&poolid_mutex); +for (i =0 ; i <MAX_INITIALIZABLE_FS ; i++) { +if (shared_fs_poolid_map[i] ==FS_UNKNOWN ) { + sb->cleancache_poolid = i +FAKE_SHARED_FS_POOLID_OFFSET ; + uuids[i] = uuid; +if (backend_registered) + shared_fs_poolid_map[i] = (*cleancache_ops.init_shared_fs) + (uuid,PAGE_SIZE ); +else + shared_fs_poolid_map[i] =FS_NO_BACKEND ; +break ; + } + } +mutex_unlock (&poolid_mutex); }EXPORT_SYMBOL (__cleancache_init_shared_fs);
@@ -99,27 +210,53 @@ static int cleancache_get_key(struct inode *inode, }/* +* Returns a pool_id that is associated with a given fake poolid. +*/ +static int get_poolid_from_fake (int fake_pool_id) +{ +if (fake_pool_id >=FAKE_SHARED_FS_POOLID_OFFSET ) +return shared_fs_poolid_map[fake_pool_id - +FAKE_SHARED_FS_POOLID_OFFSET ]; +else if (fake_pool_id >=FAKE_FS_POOLID_OFFSET ) +return fs_poolid_map[fake_pool_id -FAKE_FS_POOLID_OFFSET ]; +return FS_NO_BACKEND ; +} + +/* * "Get" data from cleancache associated with the poolid/inode/index * that were specified when the data was put to cleanache and, if * successful, use it to fill the specified page with data and return 0. * The pageframe is unchanged and returns -1 if the get fails. * Page must be locked by caller. +* +* The function has two checks before any action is taken - whether +* a backend is registered and whether the sb->cleancache_poolid +* is correct. */ int __cleancache_get_page (struct page *page) {int ret =-1 ;int pool_id; +int fake_pool_id;struct cleancache_filekey key = { .u.key = {0 } }; +if (!backend_registered) { + cleancache_failed_gets++; + goto out; + } +VM_BUG_ON (!PageLocked (page)); - pool_id = page->mapping->host->i_sb->cleancache_poolid; -if (pool_id <0 ) + fake_pool_id = page->mapping->host->i_sb->cleancache_poolid; +if (fake_pool_id <0 ) goto out; + pool_id =get_poolid_from_fake (fake_pool_id);if (cleancache_get_key (page->mapping->host, &key) <0 ) goto out; - ret = (*cleancache_ops.get_page)(pool_id, key, page->index, page); +if (pool_id >=0 ) + ret = (*cleancache_ops.get_page)(pool_id, + key, page->index, page);if (ret ==0 ) cleancache_succ_gets++;else
@@ -134,16 +271,31 @@ EXPORT_SYMBOL(__cleancache_get_page);* (previously-obtained per-filesystem) poolid and the page's, * inode and page index. Page must be locked. Note that a put_page * always "succeeds", though a subsequent get_page may succeed or fail. +* +* The function has two checks before any action is taken - whether +* a backend is registered and whether the sb->cleancache_poolid +* is correct. */ void __cleancache_put_page (struct page *page) {int pool_id; +int fake_pool_id;struct cleancache_filekey key = { .u.key = {0 } }; +if (!backend_registered) { + cleancache_puts++; +return ; + } +VM_BUG_ON (!PageLocked (page)); - pool_id = page->mapping->host->i_sb->cleancache_poolid; + fake_pool_id = page->mapping->host->i_sb->cleancache_poolid; +if (fake_pool_id <0 ) +return ; + + pool_id =get_poolid_from_fake (fake_pool_id); +if (pool_id >=0 && -cleancache_get_key (page->mapping->host, &key) >=0 ) { +cleancache_get_key (page->mapping->host, &key) >=0 ) { (*cleancache_ops.put_page)(pool_id, key, page->index, page); cleancache_puts++; }
@@ -153,19 +305,31 @@ EXPORT_SYMBOL(__cleancache_put_page);/* * Invalidate any data from cleancache associated with the poolid and the * page's inode and page index so that a subsequent "get" will fail. +* +* The function has two checks before any action is taken - whether +* a backend is registered and whether the sb->cleancache_poolid +* is correct. */ void __cleancache_invalidate_page (struct address_space *mapping,struct page *page) {/* careful... page->mapping is NULL sometimes when this is called */ -int pool_id = mapping->host->i_sb->cleancache_poolid; +int pool_id; +int fake_pool_id = mapping->host->i_sb->cleancache_poolid;struct cleancache_filekey key = { .u.key = {0 } }; -if (pool_id >=0 ) { +if (!backend_registered) +return ; + +if (fake_pool_id >=0 ) { + pool_id =get_poolid_from_fake (fake_pool_id); +if (pool_id <0 ) +return ; +VM_BUG_ON (!PageLocked (page));if (cleancache_get_key (mapping->host, &key) >=0 ) { (*cleancache_ops.invalidate_page)(pool_id, - key, page->index); + key, page->index); cleancache_invalidates++; } }
@@ -176,12 +340,25 @@ EXPORT_SYMBOL(__cleancache_invalidate_page);* Invalidate all data from cleancache associated with the poolid and the * mappings's inode so that all subsequent gets to this poolid/inode * will fail. +* +* The function has two checks before any action is taken - whether +* a backend is registered and whether the sb->cleancache_poolid +* is correct. */ void __cleancache_invalidate_inode (struct address_space *mapping) { -int pool_id = mapping->host->i_sb->cleancache_poolid; +int pool_id; +int fake_pool_id = mapping->host->i_sb->cleancache_poolid;struct cleancache_filekey key = { .u.key = {0 } }; +if (!backend_registered) +return ; + +if (fake_pool_id <0 ) +return ; + + pool_id =get_poolid_from_fake (fake_pool_id); +if (pool_id >=0 &&cleancache_get_key (mapping->host, &key) >=0 ) (*cleancache_ops.invalidate_inode)(pool_id, key); }
@@ -189,21 +366,37 @@ EXPORT_SYMBOL(__cleancache_invalidate_inode);/* * Called by any cleancache-enabled filesystem at time of unmount; -* note that pool_id is surrendered and may be reutrned by a subsequent -* cleancache_init_fs or cleancache_init_shared_fs +* note that pool_id is surrendered and may be returned by a subsequent +* cleancache_init_fs or cleancache_init_shared_fs. */ void __cleancache_invalidate_fs (struct super_block *sb) { -if (sb->cleancache_poolid >=0 ) { -int old_poolid = sb->cleancache_poolid; - sb->cleancache_poolid =-1 ; - (*cleancache_ops.invalidate_fs)(old_poolid); +int index; +int fake_pool_id = sb->cleancache_poolid; +int old_poolid = fake_pool_id; + +mutex_lock (&poolid_mutex); +if (fake_pool_id >=FAKE_SHARED_FS_POOLID_OFFSET ) { + index = fake_pool_id -FAKE_SHARED_FS_POOLID_OFFSET ; + old_poolid = shared_fs_poolid_map[index]; + shared_fs_poolid_map[index] =FS_UNKNOWN ; + uuids[index] =NULL ; + }else if (fake_pool_id >=FAKE_FS_POOLID_OFFSET ) { + index = fake_pool_id -FAKE_FS_POOLID_OFFSET ; + old_poolid = fs_poolid_map[index]; + fs_poolid_map[index] =FS_UNKNOWN ; } + sb->cleancache_poolid =-1 ; +if (backend_registered) + (*cleancache_ops.invalidate_fs)(old_poolid); +mutex_unlock (&poolid_mutex); }EXPORT_SYMBOL (__cleancache_invalidate_fs);static int __init init_cleancache (void ) { +int i; +#ifdef CONFIG_DEBUG_FS struct dentry *root =debugfs_create_dir ("cleancache" ,NULL );if (root ==NULL )
@@ -215,6 +408,11 @@ static int __init init_cleancache(void)debugfs_create_u64 ("invalidates" ,S_IRUGO , root, &cleancache_invalidates);#endif +for (i =0 ; i <MAX_INITIALIZABLE_FS ; i++) { + fs_poolid_map[i] =FS_UNKNOWN ; + shared_fs_poolid_map[i] =FS_UNKNOWN ; + } + cleancache_enabled =1 ;return 0 ; }module_init (init_cleancache)
Signature · 7 lines
1.8.0.2 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 7/11 cleancache: Make cleancache_init use a pointer for the ops
In reply to Konrad Rzeszutek WilkInstead of using a backend_registered to determine whether a backend is enabled. This allows us to remove the backend_register check and just do 'if (cleancache_ops)'
[v1: Rebase on top of b97c4b430b0a405a57c78607b520d8000329e259 (ramster->zcache move]
--- drivers/staging/zcache/zcache-main.c | 8 ++--- drivers/xen/tmem.c | 6 ++-- include/linux/cleancache.h | 2 +- mm/cleancache.c | 62 +++++++++++++++++++----------------- 4 files changed, 40 insertions(+), 38 deletions(-)
drivers/staging/zcache/zcache-main.c +4 -4
@@ -1694,9 +1694,9 @@ static struct cleancache_ops zcache_cleancache_ops = { .init_fs = zcache_cleancache_init_fs }; -struct cleancache_ops zcache_cleancache_register_ops (void ) +struct cleancache_ops *zcache_cleancache_register_ops (void ) { -struct cleancache_ops old_ops = +struct cleancache_ops *old_ops =cleancache_register_ops (&zcache_cleancache_ops);return old_ops;
@@ -1980,7 +1980,7 @@ static int __init zcache_init(void) }zbud_init ();if (zcache_enabled && !disable_cleancache) { -struct cleancache_ops old_ops; +struct cleancache_ops *old_ops;register_shrinker (&zcache_shrinker); old_ops =zcache_cleancache_register_ops ();
@@ -1990,7 +1990,7 @@ static int __init zcache_init(void)pr_info ("%s: cleancache: ignorenonactive = %d\n" , namestr, !disable_cleancache_ignore_nonactive);#endif -if (old_ops.init_fs !=NULL ) +if (old_ops !=NULL )pr_warn ("%s: cleancache_ops overridden\n" , namestr); }if (zcache_enabled && !disable_frontswap) {
drivers/xen/tmem.c +3 -3
@@ -236,7 +236,7 @@ static int __init no_cleancache(char *s) }__setup ("nocleancache" , no_cleancache); -static struct cleancache_ops __initdata tmem_cleancache_ops = { +static struct cleancache_ops tmem_cleancache_ops = { .put_page = tmem_cleancache_put_page, .get_page = tmem_cleancache_get_page, .invalidate_page = tmem_cleancache_flush_page,
@@ -392,9 +392,9 @@ static int __init xen_tmem_init(void)BUG_ON (sizeof (struct cleancache_filekey ) !=sizeof (struct tmem_oid ));if (tmem_enabled && use_cleancache) {char *s ="" ; -struct cleancache_ops old_ops = +struct cleancache_ops *old_ops =cleancache_register_ops (&tmem_cleancache_ops); -if (old_ops.init_fs !=NULL ) +if (old_ops) s =" (WARNING: cleancache_ops overridden)" ;printk (KERN_INFO "cleancache enabled, RAM provided by " "Xen Transcendent Memory%s\n" , s);
include/linux/cleancache.h +1 -1
@@ -33,7 +33,7 @@ struct cleancache_ops {void (*invalidate_fs)(int ); }; -extern struct cleancache_ops +extern struct cleancache_ops *cleancache_register_ops (struct cleancache_ops *ops);extern void __cleancache_init_fs (struct super_block *);extern void __cleancache_init_shared_fs (char *,struct super_block *);
mm/cleancache.c +32 -30
170 lines not on this page · raw message
Signature · 7 lines
1.8.0.2 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 8/11 cleancache: Remove the check for cleancache_enabled.
In reply to Konrad Rzeszutek WilkWith the support for loading of backends as modules, the cleancache_enabled is always set to true. The next subsequent patches are going to convert the cleancache_enabled to be a bit more selective and be on/off depending on whether the backend has registered - and not whether the cleancache API is enabled.
The three functions: cleancache_init_[shared|]fs and cleancache_invalidate_fs can be called anytime - they queue up which of the filesystems are active and can use the cleancache API - and when the backend is registered they will know which filesystem to process.
--- include/linux/cleancache.h | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
include/linux/cleancache.h +3 -6
@@ -74,14 +74,12 @@ static inline bool cleancache_fs_enabled_mapping(struct address_space *mapping)static inline void cleancache_init_fs (struct super_block *sb) { -if (cleancache_enabled) -__cleancache_init_fs (sb); +__cleancache_init_fs (sb); }static inline void cleancache_init_shared_fs (char *uuid,struct super_block *sb) { -if (cleancache_enabled) -__cleancache_init_shared_fs (uuid, sb); +__cleancache_init_shared_fs (uuid, sb); }static inline int cleancache_get_page (struct page *page)
@@ -115,8 +113,7 @@ static inline void cleancache_invalidate_inode(struct address_space *mapping)static inline void cleancache_invalidate_fs (struct super_block *sb) { -if (cleancache_enabled) -__cleancache_invalidate_fs (sb); +__cleancache_invalidate_fs (sb); }#endif /* _LINUX_CLEANCACHE_H */
Signature · 7 lines
1.8.0.2 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 9/11 cleancache: Use static_key instead of cleancache_ops and cleancache_enabled.
In reply to Konrad Rzeszutek WilkAs ways to determine whether to allow certain functions to be called.
This makes it easier to understand the code - the three functions that can be called by the filesystem irregardless whether a backend is set or not cleancache_init_fs, cleancache_init_shared_fs, and cleancache_invalidate_fs.
The rest of the cleancache functions end up being NOPs when the backend has not yet registered.
--- include/linux/cleancache.h | 16 +++++++++----- include/linux/frontswap.h | 2 +- mm/cleancache.c | 53 +++++++++++++++------------------------------- 3 files changed, 29 insertions(+), 42 deletions(-)
include/linux/cleancache.h +11 -5
@@ -42,9 +42,15 @@ extern void __cleancache_put_page(struct page *);extern void __cleancache_invalidate_page (struct address_space *,struct page *);extern void __cleancache_invalidate_inode (struct address_space *);extern void __cleancache_invalidate_fs (struct super_block *); -extern int cleancache_enabled;#ifdef CONFIG_CLEANCACHE +#include <linux/jump_label.h> +extern struct static_key cleancache_key; + +static inline bool cleancache_enabled (void ) +{ +return static_key_false (&cleancache_key); +}static inline bool cleancache_fs_enabled (struct page *page) {return page->mapping->host->i_sb->cleancache_poolid >=0 ;
@@ -86,14 +92,14 @@ static inline int cleancache_get_page(struct page *page) {int ret =-1 ; -if (cleancache_enabled &&cleancache_fs_enabled (page)) +if (cleancache_enabled () &&cleancache_fs_enabled (page)) ret =__cleancache_get_page (page);return ret; }static inline void cleancache_put_page (struct page *page) { -if (cleancache_enabled &&cleancache_fs_enabled (page)) +if (cleancache_enabled () &&cleancache_fs_enabled (page))__cleancache_put_page (page); }
@@ -101,13 +107,13 @@ static inline void cleancache_invalidate_page(struct address_space *mapping, struct page *page) {/* careful... page->mapping is NULL sometimes when this is called */ -if (cleancache_enabled &&cleancache_fs_enabled_mapping (mapping)) +if (cleancache_enabled () &&cleancache_fs_enabled_mapping (mapping))__cleancache_invalidate_page (mapping, page); }static inline void cleancache_invalidate_inode (struct address_space *mapping) { -if (cleancache_enabled &&cleancache_fs_enabled_mapping (mapping)) +if (cleancache_enabled () &&cleancache_fs_enabled_mapping (mapping))__cleancache_invalidate_inode (mapping); }
include/linux/frontswap.h +1 -1
@@ -113,7 +113,7 @@ static inline int frontswap_load(struct page *page)static inline void frontswap_invalidate_page (unsigned type,pgoff_t offset) { -if (frontswap_enabled) +if (static_key_false (&frontswap_key))__frontswap_invalidate_page (type, offset); }
mm/cleancache.c +17 -36
125 lines not on this page · raw message
Signature · 7 lines
1.8.0.2 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 10/11 xen: tmem: enable Xen tmem shim to be built/loaded as a module
In reply to Konrad Rzeszutek WilkFrom: Dan Magenheimer <[email protected]>
Allow Xen tmem shim to be built/loaded as a module. Xen self-ballooning and frontswap-selfshrinking are now also "lazily" initialized when the Xen tmem shim is loaded as a module, unless explicitly disabled by module parameters.
Note runtime dependency disallows loading if cleancache/frontswap lazy initialization patches are not present.
If built-in (not built as a module), the original mechanism of enabling via a kernel boot parameter is retained, but this should be considered deprecated.
Note that module unload is explicitly not yet supported.
--- drivers/xen/Kconfig | 4 ++-- drivers/xen/tmem.c | 38 +++++++++++++++++++++++++++++--------- drivers/xen/xen-selfballoon.c | 13 +++++-------- include/xen/tmem.h | 8 ++++++++ 4 files changed, 44 insertions(+), 19 deletions(-)
drivers/xen/Kconfig +2 -2
@@ -145,9 +145,9 @@ config SWIOTLB_XEN select SWIOTLB config XEN_TMEM - bool + tristate depends on !ARM - default y if (CLEANCACHE || FRONTSWAP) + default m if (CLEANCACHE || FRONTSWAP) help Shim to interface in-kernel Transcendent Memory hooks (e.g. cleancache and frontswap) to Xen tmem hypercalls.
drivers/xen/tmem.c +29 -9
@@ -5,6 +5,7 @@* Author: Dan Magenheimer */ +#include <linux/module.h> #include <linux/kernel.h> #include <linux/types.h> #include <linux/init.h>
@@ -128,6 +129,7 @@ static int xen_tmem_flush_object(u32 pool_id, struct tmem_oid oid)return xen_tmem_op (TMEM_FLUSH_OBJECT , pool_id, oid,0 ,0 ,0 ,0 ,0 ); } +#ifndef CONFIG_XEN_TMEM_MODULE bool __read_mostly tmem_enabled = false;static int __init enable_tmem (char *s)
@@ -136,6 +138,7 @@ static int __init enable_tmem(char *s) return 1; }__setup ("tmem" , enable_tmem); +#endif #ifdef CONFIG_CLEANCACHE static int xen_tmem_destroy_pool (u32 pool_id)
@@ -227,14 +230,19 @@ static int tmem_cleancache_init_shared_fs(char *uuid, size_t pagesize)return xen_tmem_new_pool (shared_uuid,TMEM_POOL_SHARED , pagesize); } -static bool __initdata use_cleancache = true; - +static bool disable_cleancache__read_mostly ; +static bool disable_selfballooning__read_mostly ; +#ifdef CONFIG_XEN_TMEM_MODULE +module_param (disable_cleancache, bool,S_IRUGO ); +module_param (disable_selfballooning, bool,S_IRUGO ); +#else static int __init no_cleancache (char *s) { - use_cleancache = false; + disable_cleancache = true;return 1 ; }__setup ("nocleancache" , no_cleancache); +#endif static struct cleancache_ops tmem_cleancache_ops = { .put_page = tmem_cleancache_put_page,
@@ -353,14 +361,19 @@ static void tmem_frontswap_init(unsigned ignored)xen_tmem_new_pool (private,TMEM_POOL_PERSIST ,PAGE_SIZE ); } -static bool __initdata use_frontswap = true; - +static bool disable_frontswap__read_mostly ; +static bool disable_frontswap_selfshrinking__read_mostly ; +#ifdef CONFIG_XEN_TMEM_MODULE +module_param (disable_frontswap, bool,S_IRUGO ); +module_param (disable_frontswap_selfshrinking, bool,S_IRUGO ); +#else static int __init no_frontswap (char *s) { - use_frontswap = false; + disable_frontswap = true;return 1 ; }__setup ("nofrontswap" , no_frontswap); +#endif static struct frontswap_ops tmem_frontswap_ops = { .store = tmem_frontswap_store,
@@ -371,12 +384,12 @@ static struct frontswap_ops tmem_frontswap_ops = { };#endif -static int __init xen_tmem_init (void ) +static int xen_tmem_init (void ) {if (!xen_domain ())return 0 ;#ifdef CONFIG_FRONTSWAP -if (tmem_enabled && use_frontswap) { +if (tmem_enabled && !disable_frontswap) {char *s ="" ;struct frontswap_ops *old_ops =frontswap_register_ops (&tmem_frontswap_ops);
@@ -390,7 +403,7 @@ static int __init xen_tmem_init(void)#endif #ifdef CONFIG_CLEANCACHE BUG_ON (sizeof (struct cleancache_filekey ) !=sizeof (struct tmem_oid )); -if (tmem_enabled && use_cleancache) { +if (tmem_enabled && !disable_cleancache) {char *s ="" ;struct cleancache_ops *old_ops =cleancache_register_ops (&tmem_cleancache_ops);
@@ -400,7 +413,14 @@ static int __init xen_tmem_init(void) "Xen Transcendent Memory%s\n", s); }#endif +#ifdef CONFIG_XEN_SELFBALLOONING +xen_selfballoon_init (!disable_selfballooning, + !disable_frontswap_selfshrinking); +#endif return 0 ; } module_init(xen_tmem_init) +MODULE_LICENSE("GPL"); +MODULE_AUTHOR ("Dan Magenheimer <[email protected]>" ); +MODULE_DESCRIPTION ("Shim to Xen transcendent memory" );
drivers/xen/xen-selfballoon.c +5 -8
@@ -121,7 +121,7 @@ static DECLARE_DELAYED_WORK(selfballoon_worker, selfballoon_process);static bool frontswap_selfshrinking__read_mostly ;/* Enable/disable with kernel boot option. */ -static bool use_frontswap_selfshrink__initdata = true; +static bool use_frontswap_selfshrink = true;/* * The default values for the following parameters were deemed reasonable
@@ -185,7 +185,7 @@ static int __init xen_nofrontswap_selfshrink_setup(char *s)__setup ("noselfshrink" , xen_nofrontswap_selfshrink_setup);/* Disable with kernel boot option. */ -static bool use_selfballooning__initdata = true; +static bool use_selfballooning = true;static int __init xen_noselfballooning_setup (char *s) {
@@ -196,7 +196,7 @@ static int __init xen_noselfballooning_setup(char *s)__setup ("noselfballooning" , xen_noselfballooning_setup);#else /* !CONFIG_FRONTSWAP */ /* Enable with kernel boot option. */ -static bool use_selfballooning__initdata = false; +static bool use_selfballooning;static int __init xen_selfballooning_setup (char *s) {
@@ -537,7 +537,7 @@ int register_xen_selfballooning(struct device *dev) }EXPORT_SYMBOL (register_xen_selfballooning); -static int __init xen_selfballoon_init (void ) +int xen_selfballoon_init (bool use_selfballooning,bool use_frontswap_selfshrink) {bool enable = false;
@@ -571,7 +571,4 @@ static int __init xen_selfballoon_init(void)return 0 ; } - -subsys_initcall (xen_selfballoon_init); - -MODULE_LICENSE ("GPL" ); +EXPORT_SYMBOL (xen_selfballoon_init);
include/xen/tmem.h +8 -0
@@ -3,7 +3,15 @@#include <linux/types.h> +#ifdef CONFIG_XEN_TMEM_MODULE +#define tmem_enabled true +#else /* defined in drivers/xen/tmem.c */ extern bool tmem_enabled; +#endif + +#ifdef CONFIG_XEN_SELFBALLOONING +extern int xen_selfballoon_init (bool ,bool ); +#endif #endif /* _XEN_TMEM_H */
Signature · 7 lines
1.8.0.2 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 11/11 zcache/tmem: Better error checking on frontswap_register_ops return value.
In reply to Konrad Rzeszutek WilkIn the past it either used to be NULL or the "older" backend. Now we also return -Exx error codes.
--- drivers/staging/zcache/zcache-main.c | 5 ++++- drivers/xen/tmem.c | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-)
drivers/staging/zcache/zcache-main.c +4 -1
@@ -2006,8 +2006,11 @@ static int __init zcache_init(void) namestr, frontswap_has_exclusive_gets, !disable_frontswap_ignore_nonactive);#endif -if (old_ops !=NULL ) +if (IS_ERR (old_ops) || old_ops) { +if (IS_ERR (old_ops)) +return PTR_RET (old_ops);pr_warn ("%s: frontswap_ops overridden\n" , namestr); + } }if (ramster_enabled) ramster_init(!disable_cleancache, !disable_frontswap,
drivers/xen/tmem.c +4 -1
@@ -395,8 +395,11 @@ static int xen_tmem_init(void)frontswap_register_ops (&tmem_frontswap_ops); tmem_frontswap_poolid =-1 ; -if (old_ops) +if (IS_ERR (old_ops) || old_ops) { +if (IS_ERR (old_ops)) +return PTR_ERR (old_ops); s =" (WARNING: frontswap_ops overridden)" ; + }printk (KERN_INFO "frontswap enabled, RAM provided by " "Xen Transcendent Memory\n" ); }
Signature · 7 lines
1.8.0.2 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>