Commit e3483a5f3a8ef448c229a2aceca9b2ad6a46b8ec

Authored by Dan Magenheimer
Committed by Konrad Rzeszutek Wilk
1 parent a00bb1e9fc

frontswap: support exclusive gets if tmem backend is capable

Tmem, as originally specified, assumes that "get" operations
performed on persistent pools never flush the page of data out
of tmem on a successful get, waiting instead for a flush
operation.  This is intended to mimic the model of a swap
disk, where a disk read is non-destructive.  Unlike a
disk, however, freeing up the RAM can be valuable.  Over
the years that frontswap was in the review process, several
reviewers (and notably Hugh Dickins in 2010) pointed out that
this would result, at least temporarily, in two copies of the
data in RAM: one (compressed for zcache) copy in tmem,
and one copy in the swap cache.  We wondered if this could
be done differently, at least optionally.

This patch allows tmem backends to instruct the frontswap
code that this backend performs exclusive gets.  Zcache2
already contains hooks to support this feature.  Other
backends are completely unaffected unless/until they are
updated to support this feature.

While it is not clear that exclusive gets are a performance
win on all workloads at all times, this small patch allows for
experimentation by backends.

P.S. Let's not quibble about the naming of "get" vs "read" vs
"load" etc.  The naming is currently horribly inconsistent between
cleancache and frontswap and existing tmem backends, so will need
to be straightened out as a separate patch.  "Get" is used
by the tmem architecture spec, existing backends, and
all documentation and presentation material so I am
using it in this patch.

Signed-off-by: Dan Magenheimer <dan.magenheimer@oracle.com>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>

Showing 2 changed files with 24 additions and 1 deletions Side-by-side Diff

include/linux/frontswap.h
... ... @@ -19,6 +19,8 @@
19 19 extern void frontswap_shrink(unsigned long);
20 20 extern unsigned long frontswap_curr_pages(void);
21 21 extern void frontswap_writethrough(bool);
  22 +#define FRONTSWAP_HAS_EXCLUSIVE_GETS
  23 +extern void frontswap_tmem_exclusive_gets(bool);
22 24  
23 25 extern void __frontswap_init(unsigned type);
24 26 extern int __frontswap_store(struct page *page);
... ... @@ -44,6 +44,13 @@
44 44 */
45 45 static bool frontswap_writethrough_enabled __read_mostly;
46 46  
  47 +/*
  48 + * If enabled, the underlying tmem implementation is capable of doing
  49 + * exclusive gets, so frontswap_load, on a successful tmem_get must
  50 + * mark the page as no longer in frontswap AND mark it dirty.
  51 + */
  52 +static bool frontswap_tmem_exclusive_gets_enabled __read_mostly;
  53 +
47 54 #ifdef CONFIG_DEBUG_FS
48 55 /*
49 56 * Counters available via /sys/kernel/debug/frontswap (if debugfs is
... ... @@ -97,6 +104,15 @@
97 104 EXPORT_SYMBOL(frontswap_writethrough);
98 105  
99 106 /*
  107 + * Enable/disable frontswap exclusive gets (see above).
  108 + */
  109 +void frontswap_tmem_exclusive_gets(bool enable)
  110 +{
  111 + frontswap_tmem_exclusive_gets_enabled = enable;
  112 +}
  113 +EXPORT_SYMBOL(frontswap_tmem_exclusive_gets);
  114 +
  115 +/*
100 116 * Called when a swap device is swapon'd.
101 117 */
102 118 void __frontswap_init(unsigned type)
103 119  
... ... @@ -174,8 +190,13 @@
174 190 BUG_ON(sis == NULL);
175 191 if (frontswap_test(sis, offset))
176 192 ret = frontswap_ops.load(type, offset, page);
177   - if (ret == 0)
  193 + if (ret == 0) {
178 194 inc_frontswap_loads();
  195 + if (frontswap_tmem_exclusive_gets_enabled) {
  196 + SetPageDirty(page);
  197 + frontswap_clear(sis, offset);
  198 + }
  199 + }
179 200 return ret;
180 201 }
181 202 EXPORT_SYMBOL(__frontswap_load);