Frontswap: core code
PATCH v3 2/4 Frontswap: core code
[PATCH V3 2/4] Frontswap: core code
Core frontswap interface between swap subsystem hooks and frontswap backend via frontswap_ops.
Credits: Frontswap_ops design derived from Jeremy Fitzhardinge design for tmem; sysfs code modelled after mm/ksm.c
Signed-off-by Dan Magenheimer <[email protected]>
Diffstat:
include/linux/frontswap.h | 86 +++++ mm/frontswap.c | 331 +++++++++++++++++++++ 2 files changed, 417 insertions(+)
include/linux/frontswap.h +86 -0
@@ -0,0 +1,86 @@ +#ifndef _LINUX_FRONTSWAP_H +#define _LINUX_FRONTSWAP_H + +#include <linux/swap.h> +#include <linux/mm.h> + +struct frontswap_ops { +void (*init)(unsigned ); +int (*put_page)(unsigned ,pgoff_t ,struct page *); +int (*get_page)(unsigned ,pgoff_t ,struct page *); +void (*flush_page)(unsigned ,pgoff_t ); +void (*flush_area)(unsigned ); +}; + +extern int frontswap_enabled; +extern struct frontswap_ops +frontswap_register_ops (struct frontswap_ops *ops); +extern void frontswap_shrink (unsigned long ); +extern unsigned long frontswap_curr_pages (void ); + +extern void frontswap_init (unsigned type); +extern int __frontswap_put_page (struct page *page); +extern int __frontswap_get_page (struct page *page); +extern void __frontswap_flush_page (unsigned ,pgoff_t ); +extern void __frontswap_flush_area (unsigned ); + +#ifndef CONFIG_FRONTSWAP +/* all inline routines become no-ops and all externs are ignored */ +#define frontswap_enabled (0) +#endif + +static inline int frontswap_test (struct swap_info_struct *sis,pgoff_t offset) +{ +int ret =0 ; + +if (frontswap_enabled && sis->frontswap_map) + ret =test_bit (offset %BITS_PER_LONG , + &sis->frontswap_map[offset/BITS_PER_LONG ]); +return ret; +} + +static inline void frontswap_set (struct swap_info_struct *sis,pgoff_t offset) +{ +if (frontswap_enabled && sis->frontswap_map) +set_bit (offset %BITS_PER_LONG , + &sis->frontswap_map[offset/BITS_PER_LONG ]); +} + +static inline void frontswap_clear (struct swap_info_struct *sis,pgoff_t offset) +{ +if (frontswap_enabled && sis->frontswap_map) +clear_bit (offset %BITS_PER_LONG , + &sis->frontswap_map[offset/BITS_PER_LONG ]); +} + +static inline int frontswap_put_page (struct page *page) +{ +int ret =-1 ; + +if (frontswap_enabled) + ret =__frontswap_put_page (page); +return ret; +} + +static inline int frontswap_get_page (struct page *page) +{ +int ret =-1 ; + +if (frontswap_enabled) + ret =__frontswap_get_page (page); +return ret; +} + +static inline void frontswap_flush_page (unsigned type,pgoff_t offset) +{ +if (frontswap_enabled) +__frontswap_flush_page (type, offset); +} + +static inline void frontswap_flush_area (unsigned type) +{ +if (frontswap_enabled) +__frontswap_flush_area (type); +} + +#endif /* _LINUX_FRONTSWAP_H */
mm/frontswap.c +331 -0
331 lines not on this page · raw message
--
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>