[PATCHv13,3/4] zswap: add to mm/
diff mbox series

Message ID 1370291585-26102-4-git-send-email-sjenning@linux.vnet.ibm.com
State New, archived
Headers show
Series
  • zswap: compressed swap caching
Related show

Commit Message

Seth Jennings June 3, 2013, 8:33 p.m. UTC
zswap is a thin backend for frontswap that takes pages that are in the process
of being swapped out and attempts to compress them and store them in a
RAM-based memory pool.  This can result in a significant I/O reduction on the
swap device and, in the case where decompressing from RAM is faster than
reading from the swap device, can also improve workload performance.

It also has support for evicting swap pages that are currently compressed in
zswap to the swap device on an LRU(ish) basis. This functionality makes zswap a
true cache in that, once the cache is full, the oldest pages can be moved out
of zswap to the swap device so newer pages can be compressed and stored in
zswap.

This patch adds the zswap driver to mm/

Signed-off-by: Seth Jennings <sjenning@linux.vnet.ibm.com>
Acked-by: Rik van Riel <riel@redhat.com>
---
 mm/Kconfig  |   20 ++
 mm/Makefile |    1 +
 mm/zswap.c  |  943 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 964 insertions(+)
 create mode 100644 mm/zswap.c

Comments

Bob Liu June 17, 2013, 6:20 a.m. UTC | #1
Hi Seth,

On Tue, Jun 4, 2013 at 4:33 AM, Seth Jennings
<sjenning@linux.vnet.ibm.com> wrote:
> zswap is a thin backend for frontswap that takes pages that are in the process
> of being swapped out and attempts to compress them and store them in a
> RAM-based memory pool.  This can result in a significant I/O reduction on the
> swap device and, in the case where decompressing from RAM is faster than
> reading from the swap device, can also improve workload performance.
>
> It also has support for evicting swap pages that are currently compressed in
> zswap to the swap device on an LRU(ish) basis. This functionality makes zswap a
> true cache in that, once the cache is full, the oldest pages can be moved out
> of zswap to the swap device so newer pages can be compressed and stored in
> zswap.
>
> This patch adds the zswap driver to mm/
>

Do you have any more benchmark can share with me ? To figure out that
we can benefit from zswap.

I found zswap will cause performance drop when using mmtests-0.10 to test it.
The config file I'm using is: config-global-dhp__parallelio-memcachetest

The result is:
(v3.10-rc4-2G-nozswap was without zswap but the performance is better.)

                                         v3.10-rc4                   v3.10-rc4
                                     2G-zswap-base                  2G-nozswap
Ops memcachetest-0M               604.00 (  0.00%)           1077.00 ( 78.31%)
Ops memcachetest-198M             630.00 (  0.00%)           1007.00 ( 59.84%)
Ops memcachetest-430M             609.00 (  0.00%)            939.00 ( 54.19%)
Ops memcachetest-661M             604.00 (  0.00%)            845.00 ( 39.90%)
Ops memcachetest-893M             591.00 (  0.00%)            839.00 ( 41.96%)
Ops memcachetest-1125M            599.00 (  0.00%)            781.00 ( 30.38%)
Ops memcachetest-1356M            588.00 (  0.00%)            771.00 ( 31.12%)
Ops io-duration-0M                  0.00 (  0.00%)              1.00 (-99.00%)
Ops io-duration-198M              177.00 (  0.00%)             21.00 ( 88.14%)
Ops io-duration-430M              168.00 (  0.00%)             25.00 ( 85.12%)
Ops io-duration-661M              214.00 (  0.00%)             30.00 ( 85.98%)
Ops io-duration-893M              186.00 (  0.00%)             32.00 ( 82.80%)
Ops io-duration-1125M             175.00 (  0.00%)             42.00 ( 76.00%)
Ops io-duration-1356M             245.00 (  0.00%)             51.00 ( 79.18%)
Ops swaptotal-0M               487760.00 (  0.00%)         459754.00 (  5.74%)
Ops swaptotal-198M             563581.00 (  0.00%)         485194.00 ( 13.91%)
Ops swaptotal-430M             579472.00 (  0.00%)         500817.00 ( 13.57%)
Ops swaptotal-661M             568086.00 (  0.00%)         524209.00 (  7.72%)
Ops swaptotal-893M             584405.00 (  0.00%)         509846.00 ( 12.76%)
Ops swaptotal-1125M            572992.00 (  0.00%)         534115.00 (  6.78%)
Ops swaptotal-1356M            573259.00 (  0.00%)         529814.00 (  7.58%)
Ops swapin-0M                  231250.00 (  0.00%)         236069.00 ( -2.08%)
Ops swapin-198M                312259.00 (  0.00%)         239149.00 ( 23.41%)
Ops swapin-430M                327178.00 (  0.00%)         246803.00 ( 24.57%)
Ops swapin-661M                319575.00 (  0.00%)         273644.00 ( 14.37%)
Ops swapin-893M                328195.00 (  0.00%)         257327.00 ( 21.59%)
Ops swapin-1125M               317345.00 (  0.00%)         271109.00 ( 14.57%)
Ops swapin-1356M               312858.00 (  0.00%)         266050.00 ( 14.96%)
Ops minorfaults-0M             592150.00 (  0.00%)         646076.00 ( -9.11%)
Ops minorfaults-198M           637339.00 (  0.00%)         676441.00 ( -6.14%)
Ops minorfaults-430M           626228.00 (  0.00%)         684715.00 ( -9.34%)
Ops minorfaults-661M           625089.00 (  0.00%)         670639.00 ( -7.29%)
Ops minorfaults-893M           612877.00 (  0.00%)         669723.00 ( -9.28%)
Ops minorfaults-1125M          624800.00 (  0.00%)         667025.00 ( -6.76%)
Ops minorfaults-1356M          618800.00 (  0.00%)         657600.00 ( -6.27%)
Ops majorfaults-0M              67664.00 (  0.00%)          40060.00 ( 40.80%)
Ops majorfaults-198M            72377.00 (  0.00%)          39517.00 ( 45.40%)
Ops majorfaults-430M            71822.00 (  0.00%)          38895.00 ( 45.85%)
Ops majorfaults-661M            70009.00 (  0.00%)          39625.00 ( 43.40%)
Ops majorfaults-893M            74988.00 (  0.00%)          38073.00 ( 49.23%)
Ops majorfaults-1125M           72458.00 (  0.00%)          38206.00 ( 47.27%)
Ops majorfaults-1356M           70549.00 (  0.00%)          37430.00 ( 46.94%)

Regards,
-Bob
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
Andrew Morton June 17, 2013, 11:02 p.m. UTC | #2
On Mon, 17 Jun 2013 14:20:05 +0800 Bob Liu <lliubbo@gmail.com> wrote:

> Hi Seth,
> 
> On Tue, Jun 4, 2013 at 4:33 AM, Seth Jennings
> <sjenning@linux.vnet.ibm.com> wrote:
> > zswap is a thin backend for frontswap that takes pages that are in the process
> > of being swapped out and attempts to compress them and store them in a
> > RAM-based memory pool.  This can result in a significant I/O reduction on the
> > swap device and, in the case where decompressing from RAM is faster than
> > reading from the swap device, can also improve workload performance.
> >
> > It also has support for evicting swap pages that are currently compressed in
> > zswap to the swap device on an LRU(ish) basis. This functionality makes zswap a
> > true cache in that, once the cache is full, the oldest pages can be moved out
> > of zswap to the swap device so newer pages can be compressed and stored in
> > zswap.
> >
> > This patch adds the zswap driver to mm/
> >
> 
> Do you have any more benchmark can share with me ? To figure out that
> we can benefit from zswap.
> 
> I found zswap will cause performance drop when using mmtests-0.10 to test it.
> The config file I'm using is: config-global-dhp__parallelio-memcachetest

Thanks for testing.

> The result is:
> (v3.10-rc4-2G-nozswap was without zswap but the performance is better.)
> 
>                                          v3.10-rc4                   v3.10-rc4
>                                      2G-zswap-base                  2G-nozswap
> Ops memcachetest-0M               604.00 (  0.00%)           1077.00 ( 78.31%)
> Ops memcachetest-198M             630.00 (  0.00%)           1007.00 ( 59.84%)
> Ops memcachetest-430M             609.00 (  0.00%)            939.00 ( 54.19%)
> Ops memcachetest-661M             604.00 (  0.00%)            845.00 ( 39.90%)
> Ops memcachetest-893M             591.00 (  0.00%)            839.00 ( 41.96%)
> Ops memcachetest-1125M            599.00 (  0.00%)            781.00 ( 30.38%)
> Ops memcachetest-1356M            588.00 (  0.00%)            771.00 ( 31.12%)
> Ops io-duration-0M                  0.00 (  0.00%)              1.00 (-99.00%)
> Ops io-duration-198M              177.00 (  0.00%)             21.00 ( 88.14%)
> Ops io-duration-430M              168.00 (  0.00%)             25.00 ( 85.12%)
> Ops io-duration-661M              214.00 (  0.00%)             30.00 ( 85.98%)
> Ops io-duration-893M              186.00 (  0.00%)             32.00 ( 82.80%)
> Ops io-duration-1125M             175.00 (  0.00%)             42.00 ( 76.00%)
> Ops io-duration-1356M             245.00 (  0.00%)             51.00 ( 79.18%)
> Ops swaptotal-0M               487760.00 (  0.00%)         459754.00 (  5.74%)
> Ops swaptotal-198M             563581.00 (  0.00%)         485194.00 ( 13.91%)
> Ops swaptotal-430M             579472.00 (  0.00%)         500817.00 ( 13.57%)
> Ops swaptotal-661M             568086.00 (  0.00%)         524209.00 (  7.72%)
> Ops swaptotal-893M             584405.00 (  0.00%)         509846.00 ( 12.76%)
> Ops swaptotal-1125M            572992.00 (  0.00%)         534115.00 (  6.78%)
> Ops swaptotal-1356M            573259.00 (  0.00%)         529814.00 (  7.58%)
> Ops swapin-0M                  231250.00 (  0.00%)         236069.00 ( -2.08%)
> Ops swapin-198M                312259.00 (  0.00%)         239149.00 ( 23.41%)
> Ops swapin-430M                327178.00 (  0.00%)         246803.00 ( 24.57%)
> Ops swapin-661M                319575.00 (  0.00%)         273644.00 ( 14.37%)
> Ops swapin-893M                328195.00 (  0.00%)         257327.00 ( 21.59%)
> Ops swapin-1125M               317345.00 (  0.00%)         271109.00 ( 14.57%)
> Ops swapin-1356M               312858.00 (  0.00%)         266050.00 ( 14.96%)
> Ops minorfaults-0M             592150.00 (  0.00%)         646076.00 ( -9.11%)
> Ops minorfaults-198M           637339.00 (  0.00%)         676441.00 ( -6.14%)
> Ops minorfaults-430M           626228.00 (  0.00%)         684715.00 ( -9.34%)
> Ops minorfaults-661M           625089.00 (  0.00%)         670639.00 ( -7.29%)
> Ops minorfaults-893M           612877.00 (  0.00%)         669723.00 ( -9.28%)
> Ops minorfaults-1125M          624800.00 (  0.00%)         667025.00 ( -6.76%)
> Ops minorfaults-1356M          618800.00 (  0.00%)         657600.00 ( -6.27%)
> Ops majorfaults-0M              67664.00 (  0.00%)          40060.00 ( 40.80%)
> Ops majorfaults-198M            72377.00 (  0.00%)          39517.00 ( 45.40%)
> Ops majorfaults-430M            71822.00 (  0.00%)          38895.00 ( 45.85%)
> Ops majorfaults-661M            70009.00 (  0.00%)          39625.00 ( 43.40%)
> Ops majorfaults-893M            74988.00 (  0.00%)          38073.00 ( 49.23%)
> Ops majorfaults-1125M           72458.00 (  0.00%)          38206.00 ( 47.27%)
> Ops majorfaults-1356M           70549.00 (  0.00%)          37430.00 ( 46.94%)

So the minor fault rate improved and everything else got worse?

I'm not sure how representative this is of real workloads, but it does
look rather fatal for zswap.  The differences are so large, I wonder if
it's just some silly bug or config issue.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
Bob Liu June 18, 2013, 11:50 a.m. UTC | #3
>
> So the minor fault rate improved and everything else got worse?

I did the test again, in a new clean environment.
I'm sure the config files are the same except enabled zswap.

                                         v3.10-rc4                   v3.10-rc4
                             2G-parallio-zswapbas         2G-parallio-nozswap
Ops memcachetest-0M               819.00 (  0.00%)           1041.00 ( 27.11%)
Ops memcachetest-198M             736.00 (  0.00%)            973.00 ( 32.20%)
Ops memcachetest-430M             700.00 (  0.00%)            892.00 ( 27.43%)
Ops memcachetest-661M             672.00 (  0.00%)            819.00 ( 21.88%)
Ops memcachetest-893M             675.00 (  0.00%)            775.00 ( 14.81%)
Ops memcachetest-1125M            665.00 (  0.00%)            764.00 ( 14.89%)
Ops memcachetest-1356M            641.00 (  0.00%)            749.00 ( 16.85%)
Ops io-duration-0M                  0.00 (  0.00%)              0.00 (  0.00%)
Ops io-duration-198M              111.00 (  0.00%)             21.00 ( 81.08%)
Ops io-duration-430M              125.00 (  0.00%)             29.00 ( 76.80%)
Ops io-duration-661M              153.00 (  0.00%)             34.00 ( 77.78%)
Ops io-duration-893M              118.00 (  0.00%)             36.00 ( 69.49%)
Ops io-duration-1125M             142.00 (  0.00%)             43.00 ( 69.72%)
Ops io-duration-1356M             156.00 (  0.00%)             50.00 ( 67.95%)
Ops swaptotal-0M               462237.00 (  0.00%)         469193.00 ( -1.50%)
Ops swaptotal-198M             490462.00 (  0.00%)         496201.00 ( -1.17%)
Ops swaptotal-430M             500469.00 (  0.00%)         520400.00 ( -3.98%)
Ops swaptotal-661M             506038.00 (  0.00%)         538872.00 ( -6.49%)
Ops swaptotal-893M             514930.00 (  0.00%)         522590.00 ( -1.49%)
Ops swaptotal-1125M            521010.00 (  0.00%)         526934.00 ( -1.14%)
Ops swaptotal-1356M            513128.00 (  0.00%)         525241.00 ( -2.36%)
Ops swapin-0M                  246425.00 (  0.00%)         251226.00 ( -1.95%)
Ops swapin-198M                266446.00 (  0.00%)         236126.00 ( 11.38%)
Ops swapin-430M                271586.00 (  0.00%)         265193.00 (  2.35%)
Ops swapin-661M                263404.00 (  0.00%)         280281.00 ( -6.41%)
Ops swapin-893M                263958.00 (  0.00%)         263004.00 (  0.36%)
Ops swapin-1125M               276149.00 (  0.00%)         261962.00 (  5.14%)
Ops swapin-1356M               264214.00 (  0.00%)         262571.00 (  0.62%)
Ops minorfaults-0M             629965.00 (  0.00%)         625759.00 (  0.67%)
Ops minorfaults-198M           641320.00 (  0.00%)         769752.00 (-20.03%)
Ops minorfaults-430M           635270.00 (  0.00%)         678590.00 ( -6.82%)
Ops minorfaults-661M           625123.00 (  0.00%)         669308.00 ( -7.07%)
Ops minorfaults-893M           625165.00 (  0.00%)         656343.00 ( -4.99%)
Ops minorfaults-1125M          624358.00 (  0.00%)         657954.00 ( -5.38%)
Ops minorfaults-1356M          619724.00 (  0.00%)         672035.00 ( -8.44%)
Ops majorfaults-0M              57664.00 (  0.00%)          39395.00 ( 31.68%)
Ops majorfaults-198M            59747.00 (  0.00%)          38758.00 ( 35.13%)
Ops majorfaults-430M            63453.00 (  0.00%)          39819.00 ( 37.25%)
Ops majorfaults-661M            61310.00 (  0.00%)          40171.00 ( 34.48%)
Ops majorfaults-893M            62544.00 (  0.00%)          37576.00 ( 39.92%)
Ops majorfaults-1125M           60866.00 (  0.00%)          36891.00 ( 39.39%)
Ops majorfaults-1356M           66598.00 (  0.00%)          37123.00 ( 44.26%)

It shows clearly that swaptotal and minorfaults get improved a little
if enabled zswap.
But with the cost that the performance of everything else dropped a lot.

--
Regards,
--Bob
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
Bob Liu June 18, 2013, 12:29 p.m. UTC | #4
>
> I'm not sure how representative this is of real workloads, but it does
> look rather fatal for zswap.  The differences are so large, I wonder if
> it's just some silly bug or config issue.
>

In my observation, zswap_pool_pages always close to zswap_stored_pages
in this testing.
I think it means that the fragmentation of zswap is heavy.
Since in idea state number of zswap pool pages should be half of stored pages.

The reason may be this workload is not suitable for compression.
The data of it can't be compressed to a low percent.
It can only compressed to around 70% percent(not exactly but at least
above 50%).

I made a simple patch to limit the fragment of zswap to 70%.
The result can be better but still not positive.
                                         v3.10-rc4                   v3.10-rc4
                               2G-parallio-nozswap     2G-parallio-zswapdefrag
Ops memcachetest-0M              1041.00 (  0.00%)           1058.00 (  1.63%)
Ops memcachetest-198M             973.00 (  0.00%)           1019.00 (  4.73%)
Ops memcachetest-430M             892.00 (  0.00%)            831.00 ( -6.84%)
Ops memcachetest-661M             819.00 (  0.00%)            850.00 (  3.79%)
Ops memcachetest-893M             775.00 (  0.00%)            784.00 (  1.16%)
Ops memcachetest-1125M            764.00 (  0.00%)            766.00 (  0.26%)
Ops memcachetest-1356M            749.00 (  0.00%)            782.00 (  4.41%)
Ops io-duration-0M                  0.00 (  0.00%)              0.00 (  0.00%)
Ops io-duration-198M               21.00 (  0.00%)             28.00 (-33.33%)
Ops io-duration-430M               29.00 (  0.00%)             32.00 (-10.34%)
Ops io-duration-661M               34.00 (  0.00%)             34.00 (  0.00%)
Ops io-duration-893M               36.00 (  0.00%)             42.00 (-16.67%)
Ops io-duration-1125M              43.00 (  0.00%)             47.00 ( -9.30%)
Ops io-duration-1356M              50.00 (  0.00%)             49.00 (  2.00%)
Ops swaptotal-0M               469193.00 (  0.00%)         461146.00 (  1.72%)
Ops swaptotal-198M             496201.00 (  0.00%)         495692.00 (  0.10%)
Ops swaptotal-430M             520400.00 (  0.00%)         520252.00 (  0.03%)
Ops swaptotal-661M             538872.00 (  0.00%)         513541.00 (  4.70%)
Ops swaptotal-893M             522590.00 (  0.00%)         532311.00 ( -1.86%)
Ops swaptotal-1125M            526934.00 (  0.00%)         527089.00 ( -0.03%)
Ops swaptotal-1356M            525241.00 (  0.00%)         525747.00 ( -0.10%)
Ops swapin-0M                  251226.00 (  0.00%)         248426.00 (  1.11%)
Ops swapin-198M                236126.00 (  0.00%)         239031.00 ( -1.23%)
Ops swapin-430M                265193.00 (  0.00%)         266174.00 ( -0.37%)
Ops swapin-661M                280281.00 (  0.00%)         263151.00 (  6.11%)
Ops swapin-893M                263004.00 (  0.00%)         268473.00 ( -2.08%)
Ops swapin-1125M               261962.00 (  0.00%)         264925.00 ( -1.13%)
Ops swapin-1356M               262571.00 (  0.00%)         266695.00 ( -1.57%)
Ops minorfaults-0M             625759.00 (  0.00%)         620448.00 (  0.85%)
Ops minorfaults-198M           769752.00 (  0.00%)         703458.00 (  8.61%)
Ops minorfaults-430M           678590.00 (  0.00%)         686257.00 ( -1.13%)
Ops minorfaults-661M           669308.00 (  0.00%)         668845.00 (  0.07%)
Ops minorfaults-893M           656343.00 (  0.00%)         680286.00 ( -3.65%)
Ops minorfaults-1125M          657954.00 (  0.00%)         655280.00 (  0.41%)
Ops minorfaults-1356M          672035.00 (  0.00%)         659861.00 (  1.81%)
Ops majorfaults-0M              39395.00 (  0.00%)          38828.00 (  1.44%)
Ops majorfaults-198M            38758.00 (  0.00%)          42876.00 (-10.62%)
Ops majorfaults-430M            39819.00 (  0.00%)          38668.00 (  2.89%)
Ops majorfaults-661M            40171.00 (  0.00%)          38443.00 (  4.30%)
Ops majorfaults-893M            37576.00 (  0.00%)          37664.00 ( -0.23%)
Ops majorfaults-1125M           36891.00 (  0.00%)          37527.00 ( -1.72%)
Ops majorfaults-1356M           37123.00 (  0.00%)          37779.00 ( -1.77%)

--
Regards,
--Bob
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
Seth Jennings June 19, 2013, 2:09 p.m. UTC | #5
On Mon, Jun 17, 2013 at 02:20:05PM +0800, Bob Liu wrote:
> Hi Seth,
> 
> On Tue, Jun 4, 2013 at 4:33 AM, Seth Jennings
> <sjenning@linux.vnet.ibm.com> wrote:
> > zswap is a thin backend for frontswap that takes pages that are in the process
> > of being swapped out and attempts to compress them and store them in a
> > RAM-based memory pool.  This can result in a significant I/O reduction on the
> > swap device and, in the case where decompressing from RAM is faster than
> > reading from the swap device, can also improve workload performance.
> >
> > It also has support for evicting swap pages that are currently compressed in
> > zswap to the swap device on an LRU(ish) basis. This functionality makes zswap a
> > true cache in that, once the cache is full, the oldest pages can be moved out
> > of zswap to the swap device so newer pages can be compressed and stored in
> > zswap.
> >
> > This patch adds the zswap driver to mm/
> >
> 
> Do you have any more benchmark can share with me ? To figure out that
> we can benefit from zswap.

The two I've done or kernbench and SPECjbb.  I'm trying out the memtests
now.  I'd like to be able to explain the numbers you are seeing at least.

Sorry for the delay.  I'll get back to you once I've figured out how
to using mmtests and get some results/explanations.

Also, how much physical RAM did this box have? I see 2G in the profile name
but not sure if that is the workload size or the RAM size.  I seems that the
test is overcommitted from the beginning as indicated by the swap activity.
I know that the parallelio-memcachetest default profile only uses 80% of
physical memory, so you have apparently made a change yes?

Seth

> 
> I found zswap will cause performance drop when using mmtests-0.10 to test it.
> The config file I'm using is: config-global-dhp__parallelio-memcachetest
> 
> The result is:
> (v3.10-rc4-2G-nozswap was without zswap but the performance is better.)
> 
>                                          v3.10-rc4                   v3.10-rc4
>                                      2G-zswap-base                  2G-nozswap
> Ops memcachetest-0M               604.00 (  0.00%)           1077.00 ( 78.31%)
> Ops memcachetest-198M             630.00 (  0.00%)           1007.00 ( 59.84%)
> Ops memcachetest-430M             609.00 (  0.00%)            939.00 ( 54.19%)
> Ops memcachetest-661M             604.00 (  0.00%)            845.00 ( 39.90%)
> Ops memcachetest-893M             591.00 (  0.00%)            839.00 ( 41.96%)
> Ops memcachetest-1125M            599.00 (  0.00%)            781.00 ( 30.38%)
> Ops memcachetest-1356M            588.00 (  0.00%)            771.00 ( 31.12%)
> Ops io-duration-0M                  0.00 (  0.00%)              1.00 (-99.00%)
> Ops io-duration-198M              177.00 (  0.00%)             21.00 ( 88.14%)
> Ops io-duration-430M              168.00 (  0.00%)             25.00 ( 85.12%)
> Ops io-duration-661M              214.00 (  0.00%)             30.00 ( 85.98%)
> Ops io-duration-893M              186.00 (  0.00%)             32.00 ( 82.80%)
> Ops io-duration-1125M             175.00 (  0.00%)             42.00 ( 76.00%)
> Ops io-duration-1356M             245.00 (  0.00%)             51.00 ( 79.18%)
> Ops swaptotal-0M               487760.00 (  0.00%)         459754.00 (  5.74%)
> Ops swaptotal-198M             563581.00 (  0.00%)         485194.00 ( 13.91%)
> Ops swaptotal-430M             579472.00 (  0.00%)         500817.00 ( 13.57%)
> Ops swaptotal-661M             568086.00 (  0.00%)         524209.00 (  7.72%)
> Ops swaptotal-893M             584405.00 (  0.00%)         509846.00 ( 12.76%)
> Ops swaptotal-1125M            572992.00 (  0.00%)         534115.00 (  6.78%)
> Ops swaptotal-1356M            573259.00 (  0.00%)         529814.00 (  7.58%)
> Ops swapin-0M                  231250.00 (  0.00%)         236069.00 ( -2.08%)
> Ops swapin-198M                312259.00 (  0.00%)         239149.00 ( 23.41%)
> Ops swapin-430M                327178.00 (  0.00%)         246803.00 ( 24.57%)
> Ops swapin-661M                319575.00 (  0.00%)         273644.00 ( 14.37%)
> Ops swapin-893M                328195.00 (  0.00%)         257327.00 ( 21.59%)
> Ops swapin-1125M               317345.00 (  0.00%)         271109.00 ( 14.57%)
> Ops swapin-1356M               312858.00 (  0.00%)         266050.00 ( 14.96%)
> Ops minorfaults-0M             592150.00 (  0.00%)         646076.00 ( -9.11%)
> Ops minorfaults-198M           637339.00 (  0.00%)         676441.00 ( -6.14%)
> Ops minorfaults-430M           626228.00 (  0.00%)         684715.00 ( -9.34%)
> Ops minorfaults-661M           625089.00 (  0.00%)         670639.00 ( -7.29%)
> Ops minorfaults-893M           612877.00 (  0.00%)         669723.00 ( -9.28%)
> Ops minorfaults-1125M          624800.00 (  0.00%)         667025.00 ( -6.76%)
> Ops minorfaults-1356M          618800.00 (  0.00%)         657600.00 ( -6.27%)
> Ops majorfaults-0M              67664.00 (  0.00%)          40060.00 ( 40.80%)
> Ops majorfaults-198M            72377.00 (  0.00%)          39517.00 ( 45.40%)
> Ops majorfaults-430M            71822.00 (  0.00%)          38895.00 ( 45.85%)
> Ops majorfaults-661M            70009.00 (  0.00%)          39625.00 ( 43.40%)
> Ops majorfaults-893M            74988.00 (  0.00%)          38073.00 ( 49.23%)
> Ops majorfaults-1125M           72458.00 (  0.00%)          38206.00 ( 47.27%)
> Ops majorfaults-1356M           70549.00 (  0.00%)          37430.00 ( 46.94%)
> 
> Regards,
> -Bob

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
Bob Liu June 19, 2013, 2:17 p.m. UTC | #6
On Wed, Jun 19, 2013 at 10:09 PM, Seth Jennings
<sjenning@linux.vnet.ibm.com> wrote:
> On Mon, Jun 17, 2013 at 02:20:05PM +0800, Bob Liu wrote:
>> Hi Seth,
>>
>> On Tue, Jun 4, 2013 at 4:33 AM, Seth Jennings
>> <sjenning@linux.vnet.ibm.com> wrote:
>> > zswap is a thin backend for frontswap that takes pages that are in the process
>> > of being swapped out and attempts to compress them and store them in a
>> > RAM-based memory pool.  This can result in a significant I/O reduction on the
>> > swap device and, in the case where decompressing from RAM is faster than
>> > reading from the swap device, can also improve workload performance.
>> >
>> > It also has support for evicting swap pages that are currently compressed in
>> > zswap to the swap device on an LRU(ish) basis. This functionality makes zswap a
>> > true cache in that, once the cache is full, the oldest pages can be moved out
>> > of zswap to the swap device so newer pages can be compressed and stored in
>> > zswap.
>> >
>> > This patch adds the zswap driver to mm/
>> >
>>
>> Do you have any more benchmark can share with me ? To figure out that
>> we can benefit from zswap.
>
> The two I've done or kernbench and SPECjbb.  I'm trying out the memtests

Thanks, I'll try to setup them.

> now.  I'd like to be able to explain the numbers you are seeing at least.
>
> Sorry for the delay.  I'll get back to you once I've figured out how
> to using mmtests and get some results/explanations.
>
> Also, how much physical RAM did this box have? I see 2G in the profile name
> but not sure if that is the workload size or the RAM size.  I seems that the

2G RAM size.

> test is overcommitted from the beginning as indicated by the swap activity.
> I know that the parallelio-memcachetest default profile only uses 80% of
> physical memory, so you have apparently made a change yes?
>

No, I just "cp configs/config-global-dhp__parallelio-memcachetest
config" and then run mmtests.sh with monitor.
I'm using mmtests version 0.10.

--
Regards,
--Bob
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
Seth Jennings June 20, 2013, 2:37 a.m. UTC | #7
On Mon, Jun 17, 2013 at 02:20:05PM +0800, Bob Liu wrote:
> Hi Seth,
> 
> On Tue, Jun 4, 2013 at 4:33 AM, Seth Jennings
> <sjenning@linux.vnet.ibm.com> wrote:
> > zswap is a thin backend for frontswap that takes pages that are in the process
> > of being swapped out and attempts to compress them and store them in a
> > RAM-based memory pool.  This can result in a significant I/O reduction on the
> > swap device and, in the case where decompressing from RAM is faster than
> > reading from the swap device, can also improve workload performance.
> >
> > It also has support for evicting swap pages that are currently compressed in
> > zswap to the swap device on an LRU(ish) basis. This functionality makes zswap a
> > true cache in that, once the cache is full, the oldest pages can be moved out
> > of zswap to the swap device so newer pages can be compressed and stored in
> > zswap.
> >
> > This patch adds the zswap driver to mm/
> >
> 
> Do you have any more benchmark can share with me ? To figure out that
> we can benefit from zswap.
> 
> I found zswap will cause performance drop when using mmtests-0.10 to test it.
> The config file I'm using is: config-global-dhp__parallelio-memcachetest
> 
> The result is:
> (v3.10-rc4-2G-nozswap was without zswap but the performance is better.)
> 
>                                          v3.10-rc4                   v3.10-rc4
>                                      2G-zswap-base                  2G-nozswap
> Ops memcachetest-0M               604.00 (  0.00%)           1077.00 ( 78.31%)
> Ops memcachetest-198M             630.00 (  0.00%)           1007.00 ( 59.84%)
> Ops memcachetest-430M             609.00 (  0.00%)            939.00 ( 54.19%)
> Ops memcachetest-661M             604.00 (  0.00%)            845.00 ( 39.90%)
> Ops memcachetest-893M             591.00 (  0.00%)            839.00 ( 41.96%)
> Ops memcachetest-1125M            599.00 (  0.00%)            781.00 ( 30.38%)
> Ops memcachetest-1356M            588.00 (  0.00%)            771.00 ( 31.12%)
> Ops io-duration-0M                  0.00 (  0.00%)              1.00 (-99.00%)
> Ops io-duration-198M              177.00 (  0.00%)             21.00 ( 88.14%)
> Ops io-duration-430M              168.00 (  0.00%)             25.00 ( 85.12%)
> Ops io-duration-661M              214.00 (  0.00%)             30.00 ( 85.98%)
> Ops io-duration-893M              186.00 (  0.00%)             32.00 ( 82.80%)
> Ops io-duration-1125M             175.00 (  0.00%)             42.00 ( 76.00%)
> Ops io-duration-1356M             245.00 (  0.00%)             51.00 ( 79.18%)
> Ops swaptotal-0M               487760.00 (  0.00%)         459754.00 (  5.74%)
> Ops swaptotal-198M             563581.00 (  0.00%)         485194.00 ( 13.91%)
> Ops swaptotal-430M             579472.00 (  0.00%)         500817.00 ( 13.57%)
> Ops swaptotal-661M             568086.00 (  0.00%)         524209.00 (  7.72%)
> Ops swaptotal-893M             584405.00 (  0.00%)         509846.00 ( 12.76%)
> Ops swaptotal-1125M            572992.00 (  0.00%)         534115.00 (  6.78%)
> Ops swaptotal-1356M            573259.00 (  0.00%)         529814.00 (  7.58%)
> Ops swapin-0M                  231250.00 (  0.00%)         236069.00 ( -2.08%)
> Ops swapin-198M                312259.00 (  0.00%)         239149.00 ( 23.41%)
> Ops swapin-430M                327178.00 (  0.00%)         246803.00 ( 24.57%)
> Ops swapin-661M                319575.00 (  0.00%)         273644.00 ( 14.37%)
> Ops swapin-893M                328195.00 (  0.00%)         257327.00 ( 21.59%)
> Ops swapin-1125M               317345.00 (  0.00%)         271109.00 ( 14.57%)
> Ops swapin-1356M               312858.00 (  0.00%)         266050.00 ( 14.96%)
> Ops minorfaults-0M             592150.00 (  0.00%)         646076.00 ( -9.11%)
> Ops minorfaults-198M           637339.00 (  0.00%)         676441.00 ( -6.14%)
> Ops minorfaults-430M           626228.00 (  0.00%)         684715.00 ( -9.34%)
> Ops minorfaults-661M           625089.00 (  0.00%)         670639.00 ( -7.29%)
> Ops minorfaults-893M           612877.00 (  0.00%)         669723.00 ( -9.28%)
> Ops minorfaults-1125M          624800.00 (  0.00%)         667025.00 ( -6.76%)
> Ops minorfaults-1356M          618800.00 (  0.00%)         657600.00 ( -6.27%)
> Ops majorfaults-0M              67664.00 (  0.00%)          40060.00 ( 40.80%)
> Ops majorfaults-198M            72377.00 (  0.00%)          39517.00 ( 45.40%)
> Ops majorfaults-430M            71822.00 (  0.00%)          38895.00 ( 45.85%)
> Ops majorfaults-661M            70009.00 (  0.00%)          39625.00 ( 43.40%)
> Ops majorfaults-893M            74988.00 (  0.00%)          38073.00 ( 49.23%)
> Ops majorfaults-1125M           72458.00 (  0.00%)          38206.00 ( 47.27%)
> Ops majorfaults-1356M           70549.00 (  0.00%)          37430.00 ( 46.94%)

Just made a mmtests run of my own and got very different results:

parallelio-memcachetest
                                         v3.10-rc6                   v3.10-rc6
                                              base                       zswap
Ops memcachetest-0M              7815.00 (  0.00%)           7843.00 (  0.36%)
Ops memcachetest-596M           12116.00 (  0.00%)          12158.00 (  0.35%)
Ops memcachetest-1989M           2226.00 (  0.00%)           5314.00 (138.72%)
Ops memcachetest-3382M           1910.00 (  0.00%)           4427.00 (131.78%)
Ops io-duration-0M                  0.00 (  0.00%)              0.00 (  0.00%)
Ops io-duration-596M               18.00 (  0.00%)             12.00 ( 33.33%)
Ops io-duration-1989M              82.00 (  0.00%)             57.00 ( 30.49%)
Ops io-duration-3382M              91.00 (  0.00%)             94.00 ( -3.30%)
Ops swaptotal-0M                    0.00 (  0.00%)              0.00 (  0.00%)
Ops swaptotal-596M                  0.00 (  0.00%)              0.00 (  0.00%)
Ops swaptotal-1989M            305182.00 (  0.00%)          91508.00 ( 70.02%)
Ops swaptotal-3382M            353389.00 (  0.00%)          74932.00 ( 78.80%)
Ops swapin-0M                       0.00 (  0.00%)              0.00 (  0.00%)
Ops swapin-596M                     0.00 (  0.00%)              0.00 (  0.00%)
Ops swapin-1989M               131071.00 (  0.00%)          45657.00 ( 65.17%)
Ops swapin-3382M               135003.00 (  0.00%)          37245.00 ( 72.41%)
Ops minorfaults-0M            1201113.00 (  0.00%)        1201229.00 ( -0.01%)
Ops minorfaults-596M          1218437.00 (  0.00%)        1218824.00 ( -0.03%)
Ops minorfaults-1989M         1260652.00 (  0.00%)        1270762.00 ( -0.80%)
Ops minorfaults-3382M         1251389.00 (  0.00%)        1248756.00 (  0.21%)
Ops majorfaults-0M                  0.00 (  0.00%)              0.00 (  0.00%)
Ops majorfaults-596M               34.00 (  0.00%)              0.00 (  0.00%)
Ops majorfaults-1989M           16561.00 (  0.00%)           7789.00 ( 52.97%)
Ops majorfaults-3382M           17031.00 (  0.00%)           6372.00 ( 62.59%)

Basically the results show that once swapping starts (which happens even in the
0MB case in your results which is puzzling), zswap reduces swapins by around
70% (and as a result swaptotal and majorfaults) and increases memcached
throughput by over 130% compared to the normal swapping case w/o zswap.

This test illustrates a great use case for zswap.  The test is really designed
to detect suboptimal page reclaim decisions.  Ideally the memcached pages would
never reach the end of the inactive LRU and be swapped out.  However, since
there is a lot of I/O going on, if a memcached page does get put on the
inactive list, it can quickly move to the end.  In this case, zswap catches the
page and memcached has a chance to fault it back in from the compressed cache
before actual swapping to disk occurs.

Seth

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
Bob Liu June 20, 2013, 9:42 a.m. UTC | #8
On Thu, Jun 20, 2013 at 10:37 AM, Seth Jennings
<sjenning@linux.vnet.ibm.com> wrote:
> On Mon, Jun 17, 2013 at 02:20:05PM +0800, Bob Liu wrote:
>> Hi Seth,
>>
>> On Tue, Jun 4, 2013 at 4:33 AM, Seth Jennings
>> <sjenning@linux.vnet.ibm.com> wrote:
>> > zswap is a thin backend for frontswap that takes pages that are in the process
>> > of being swapped out and attempts to compress them and store them in a
>> > RAM-based memory pool.  This can result in a significant I/O reduction on the
>> > swap device and, in the case where decompressing from RAM is faster than
>> > reading from the swap device, can also improve workload performance.
>> >
>> > It also has support for evicting swap pages that are currently compressed in
>> > zswap to the swap device on an LRU(ish) basis. This functionality makes zswap a
>> > true cache in that, once the cache is full, the oldest pages can be moved out
>> > of zswap to the swap device so newer pages can be compressed and stored in
>> > zswap.
>> >
>> > This patch adds the zswap driver to mm/
>> >
>>
>> Do you have any more benchmark can share with me ? To figure out that
>> we can benefit from zswap.
>>
>> I found zswap will cause performance drop when using mmtests-0.10 to test it.
>> The config file I'm using is: config-global-dhp__parallelio-memcachetest
>>
>> The result is:
>> (v3.10-rc4-2G-nozswap was without zswap but the performance is better.)
>>
>>                                          v3.10-rc4                   v3.10-rc4
>>                                      2G-zswap-base                  2G-nozswap
>> Ops memcachetest-0M               604.00 (  0.00%)           1077.00 ( 78.31%)
>> Ops memcachetest-198M             630.00 (  0.00%)           1007.00 ( 59.84%)
>> Ops memcachetest-430M             609.00 (  0.00%)            939.00 ( 54.19%)
>> Ops memcachetest-661M             604.00 (  0.00%)            845.00 ( 39.90%)
>> Ops memcachetest-893M             591.00 (  0.00%)            839.00 ( 41.96%)
>> Ops memcachetest-1125M            599.00 (  0.00%)            781.00 ( 30.38%)
>> Ops memcachetest-1356M            588.00 (  0.00%)            771.00 ( 31.12%)
>> Ops io-duration-0M                  0.00 (  0.00%)              1.00 (-99.00%)
>> Ops io-duration-198M              177.00 (  0.00%)             21.00 ( 88.14%)
>> Ops io-duration-430M              168.00 (  0.00%)             25.00 ( 85.12%)
>> Ops io-duration-661M              214.00 (  0.00%)             30.00 ( 85.98%)
>> Ops io-duration-893M              186.00 (  0.00%)             32.00 ( 82.80%)
>> Ops io-duration-1125M             175.00 (  0.00%)             42.00 ( 76.00%)
>> Ops io-duration-1356M             245.00 (  0.00%)             51.00 ( 79.18%)
>> Ops swaptotal-0M               487760.00 (  0.00%)         459754.00 (  5.74%)
>> Ops swaptotal-198M             563581.00 (  0.00%)         485194.00 ( 13.91%)
>> Ops swaptotal-430M             579472.00 (  0.00%)         500817.00 ( 13.57%)
>> Ops swaptotal-661M             568086.00 (  0.00%)         524209.00 (  7.72%)
>> Ops swaptotal-893M             584405.00 (  0.00%)         509846.00 ( 12.76%)
>> Ops swaptotal-1125M            572992.00 (  0.00%)         534115.00 (  6.78%)
>> Ops swaptotal-1356M            573259.00 (  0.00%)         529814.00 (  7.58%)
>> Ops swapin-0M                  231250.00 (  0.00%)         236069.00 ( -2.08%)
>> Ops swapin-198M                312259.00 (  0.00%)         239149.00 ( 23.41%)
>> Ops swapin-430M                327178.00 (  0.00%)         246803.00 ( 24.57%)
>> Ops swapin-661M                319575.00 (  0.00%)         273644.00 ( 14.37%)
>> Ops swapin-893M                328195.00 (  0.00%)         257327.00 ( 21.59%)
>> Ops swapin-1125M               317345.00 (  0.00%)         271109.00 ( 14.57%)
>> Ops swapin-1356M               312858.00 (  0.00%)         266050.00 ( 14.96%)
>> Ops minorfaults-0M             592150.00 (  0.00%)         646076.00 ( -9.11%)
>> Ops minorfaults-198M           637339.00 (  0.00%)         676441.00 ( -6.14%)
>> Ops minorfaults-430M           626228.00 (  0.00%)         684715.00 ( -9.34%)
>> Ops minorfaults-661M           625089.00 (  0.00%)         670639.00 ( -7.29%)
>> Ops minorfaults-893M           612877.00 (  0.00%)         669723.00 ( -9.28%)
>> Ops minorfaults-1125M          624800.00 (  0.00%)         667025.00 ( -6.76%)
>> Ops minorfaults-1356M          618800.00 (  0.00%)         657600.00 ( -6.27%)
>> Ops majorfaults-0M              67664.00 (  0.00%)          40060.00 ( 40.80%)
>> Ops majorfaults-198M            72377.00 (  0.00%)          39517.00 ( 45.40%)
>> Ops majorfaults-430M            71822.00 (  0.00%)          38895.00 ( 45.85%)
>> Ops majorfaults-661M            70009.00 (  0.00%)          39625.00 ( 43.40%)
>> Ops majorfaults-893M            74988.00 (  0.00%)          38073.00 ( 49.23%)
>> Ops majorfaults-1125M           72458.00 (  0.00%)          38206.00 ( 47.27%)
>> Ops majorfaults-1356M           70549.00 (  0.00%)          37430.00 ( 46.94%)
>
> Just made a mmtests run of my own and got very different results:
>

It's strange, I'll update to rc6 and try again.
By the way, are you using 824 hardware compressor instead of lzo?

> parallelio-memcachetest
>                                          v3.10-rc6                   v3.10-rc6
>                                               base                       zswap
> Ops memcachetest-0M              7815.00 (  0.00%)           7843.00 (  0.36%)
> Ops memcachetest-596M           12116.00 (  0.00%)          12158.00 (  0.35%)
> Ops memcachetest-1989M           2226.00 (  0.00%)           5314.00 (138.72%)
> Ops memcachetest-3382M           1910.00 (  0.00%)           4427.00 (131.78%)
> Ops io-duration-0M                  0.00 (  0.00%)              0.00 (  0.00%)
> Ops io-duration-596M               18.00 (  0.00%)             12.00 ( 33.33%)
> Ops io-duration-1989M              82.00 (  0.00%)             57.00 ( 30.49%)
> Ops io-duration-3382M              91.00 (  0.00%)             94.00 ( -3.30%)
> Ops swaptotal-0M                    0.00 (  0.00%)              0.00 (  0.00%)
> Ops swaptotal-596M                  0.00 (  0.00%)              0.00 (  0.00%)
> Ops swaptotal-1989M            305182.00 (  0.00%)          91508.00 ( 70.02%)
> Ops swaptotal-3382M            353389.00 (  0.00%)          74932.00 ( 78.80%)
> Ops swapin-0M                       0.00 (  0.00%)              0.00 (  0.00%)
> Ops swapin-596M                     0.00 (  0.00%)              0.00 (  0.00%)
> Ops swapin-1989M               131071.00 (  0.00%)          45657.00 ( 65.17%)
> Ops swapin-3382M               135003.00 (  0.00%)          37245.00 ( 72.41%)
> Ops minorfaults-0M            1201113.00 (  0.00%)        1201229.00 ( -0.01%)
> Ops minorfaults-596M          1218437.00 (  0.00%)        1218824.00 ( -0.03%)
> Ops minorfaults-1989M         1260652.00 (  0.00%)        1270762.00 ( -0.80%)
> Ops minorfaults-3382M         1251389.00 (  0.00%)        1248756.00 (  0.21%)
> Ops majorfaults-0M                  0.00 (  0.00%)              0.00 (  0.00%)
> Ops majorfaults-596M               34.00 (  0.00%)              0.00 (  0.00%)
> Ops majorfaults-1989M           16561.00 (  0.00%)           7789.00 ( 52.97%)
> Ops majorfaults-3382M           17031.00 (  0.00%)           6372.00 ( 62.59%)
>
> Basically the results show that once swapping starts (which happens even in the
> 0MB case in your results which is puzzling), zswap reduces swapins by around
> 70% (and as a result swaptotal and majorfaults) and increases memcached
> throughput by over 130% compared to the normal swapping case w/o zswap.
>
> This test illustrates a great use case for zswap.  The test is really designed
> to detect suboptimal page reclaim decisions.  Ideally the memcached pages would
> never reach the end of the inactive LRU and be swapped out.  However, since
> there is a lot of I/O going on, if a memcached page does get put on the
> inactive list, it can quickly move to the end.  In this case, zswap catches the
> page and memcached has a chance to fault it back in from the compressed cache
> before actual swapping to disk occurs.
>
> Seth
>

--
Regards,
--Bob
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
Seth Jennings June 20, 2013, 2:23 p.m. UTC | #9
On Thu, Jun 20, 2013 at 05:42:04PM +0800, Bob Liu wrote:
> > Just made a mmtests run of my own and got very different results:
> >
> 
> It's strange, I'll update to rc6 and try again.
> By the way, are you using 824 hardware compressor instead of lzo?

My results where using lzo software compression.

Seth

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
Bob Liu June 20, 2013, 2:35 p.m. UTC | #10
On Thu, Jun 20, 2013 at 10:23 PM, Seth Jennings
<sjenning@linux.vnet.ibm.com> wrote:
> On Thu, Jun 20, 2013 at 05:42:04PM +0800, Bob Liu wrote:
>> > Just made a mmtests run of my own and got very different results:
>> >
>>
>> It's strange, I'll update to rc6 and try again.
>> By the way, are you using 824 hardware compressor instead of lzo?
>
> My results where using lzo software compression.
>

Thanks, and today I used another machine to test zswap.
The total ram size of that machine is around 4G.
This time the result is better:
                                               rc6                         rc6
                                             zswap                        base
Ops memcachetest-0M             14619.00 (  0.00%)          15602.00 (  6.72%)
Ops memcachetest-435M           14727.00 (  0.00%)          15860.00 (  7.69%)
Ops memcachetest-944M           12452.00 (  0.00%)          11812.00 ( -5.14%)
Ops memcachetest-1452M          12183.00 (  0.00%)           9829.00 (-19.32%)
Ops memcachetest-1961M          11953.00 (  0.00%)           9337.00 (-21.89%)
Ops memcachetest-2469M          11201.00 (  0.00%)           7509.00 (-32.96%)
Ops memcachetest-2978M           9738.00 (  0.00%)           5981.00 (-38.58%)
Ops io-duration-0M                  0.00 (  0.00%)              0.00 (  0.00%)
Ops io-duration-435M               10.00 (  0.00%)              6.00 ( 40.00%)
Ops io-duration-944M               19.00 (  0.00%)             19.00 (  0.00%)
Ops io-duration-1452M              31.00 (  0.00%)             26.00 ( 16.13%)
Ops io-duration-1961M              40.00 (  0.00%)             35.00 ( 12.50%)
Ops io-duration-2469M              45.00 (  0.00%)             43.00 (  4.44%)
Ops io-duration-2978M              58.00 (  0.00%)             53.00 (  8.62%)
Ops swaptotal-0M                56711.00 (  0.00%)              8.00 ( 99.99%)
Ops swaptotal-435M              19218.00 (  0.00%)           2101.00 ( 89.07%)
Ops swaptotal-944M              53233.00 (  0.00%)          98055.00 (-84.20%)
Ops swaptotal-1452M             52064.00 (  0.00%)         145624.00 (-179.70%)
Ops swaptotal-1961M             54960.00 (  0.00%)         153907.00 (-180.03%)
Ops swaptotal-2469M             57485.00 (  0.00%)         176340.00 (-206.76%)
Ops swaptotal-2978M             77704.00 (  0.00%)         182996.00 (-135.50%)
Ops swapin-0M                   24834.00 (  0.00%)              8.00 ( 99.97%)
Ops swapin-435M                  9038.00 (  0.00%)              0.00 (  0.00%)
Ops swapin-944M                 26230.00 (  0.00%)          42953.00 (-63.76%)
Ops swapin-1452M                25766.00 (  0.00%)          68440.00 (-165.62%)
Ops swapin-1961M                27258.00 (  0.00%)          68129.00 (-149.94%)
Ops swapin-2469M                28508.00 (  0.00%)          82234.00 (-188.46%)
Ops swapin-2978M                37970.00 (  0.00%)          89280.00 (-135.13%)
Ops minorfaults-0M            1460163.00 (  0.00%)         927966.00 ( 36.45%)
Ops minorfaults-435M           954058.00 (  0.00%)         936182.00 (  1.87%)
Ops minorfaults-944M           972818.00 (  0.00%)        1005956.00 ( -3.41%)
Ops minorfaults-1452M          966597.00 (  0.00%)        1035465.00 ( -7.12%)
Ops minorfaults-1961M          976158.00 (  0.00%)        1049441.00 ( -7.51%)
Ops minorfaults-2469M          967815.00 (  0.00%)        1051752.00 ( -8.67%)
Ops minorfaults-2978M          988712.00 (  0.00%)        1034615.00 ( -4.64%)
Ops majorfaults-0M               5899.00 (  0.00%)              9.00 ( 99.85%)
Ops majorfaults-435M             2684.00 (  0.00%)             67.00 ( 97.50%)
Ops majorfaults-944M             4380.00 (  0.00%)           5790.00 (-32.19%)
Ops majorfaults-1452M            4161.00 (  0.00%)           9222.00 (-121.63%)
Ops majorfaults-1961M            4435.00 (  0.00%)           8800.00 (-98.42%)
Ops majorfaults-2469M            4555.00 (  0.00%)          10541.00 (-131.42%)
Ops majorfaults-2978M            6182.00 (  0.00%)          11618.00 (-87.93%)


But the performance of the first machine I used whose total ram size
is 2G is still bad.
I need more time to summarize those testing results.

Maybe you can also have a try with lower total ram size.

--
Regards,
--Bob
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
Dan Magenheimer June 21, 2013, 3:20 p.m. UTC | #11
> From: Bob Liu [mailto:lliubbo@gmail.com]
 Subject: Re: [PATCHv13 3/4] zswap: add to mm/
> 
> On Thu, Jun 20, 2013 at 10:23 PM, Seth Jennings
> <sjenning@linux.vnet.ibm.com> wrote:
> > On Thu, Jun 20, 2013 at 05:42:04PM +0800, Bob Liu wrote:
> >> > Just made a mmtests run of my own and got very different results:
> >> >
> >>
> >> It's strange, I'll update to rc6 and try again.
> >> By the way, are you using 824 hardware compressor instead of lzo?
> >
> > My results where using lzo software compression.
> >
> 
> Thanks, and today I used another machine to test zswap.
> The total ram size of that machine is around 4G.
> This time the result is better:
>                                                rc6                         rc6
>                                              zswap                        base
> Ops memcachetest-0M             14619.00 (  0.00%)          15602.00 (  6.72%)
> Ops memcachetest-435M           14727.00 (  0.00%)          15860.00 (  7.69%)
> Ops memcachetest-944M           12452.00 (  0.00%)          11812.00 ( -5.14%)
> Ops memcachetest-1452M          12183.00 (  0.00%)           9829.00 (-19.32%)
> Ops memcachetest-1961M          11953.00 (  0.00%)           9337.00 (-21.89%)
> Ops memcachetest-2469M          11201.00 (  0.00%)           7509.00 (-32.96%)
> Ops memcachetest-2978M           9738.00 (  0.00%)           5981.00 (-38.58%)
> Ops io-duration-0M                  0.00 (  0.00%)              0.00 (  0.00%)
> Ops io-duration-435M               10.00 (  0.00%)              6.00 ( 40.00%)
> Ops io-duration-944M               19.00 (  0.00%)             19.00 (  0.00%)
> Ops io-duration-1452M              31.00 (  0.00%)             26.00 ( 16.13%)
> Ops io-duration-1961M              40.00 (  0.00%)             35.00 ( 12.50%)
> Ops io-duration-2469M              45.00 (  0.00%)             43.00 (  4.44%)
> Ops io-duration-2978M              58.00 (  0.00%)             53.00 (  8.62%)
> Ops swaptotal-0M                56711.00 (  0.00%)              8.00 ( 99.99%)
> Ops swaptotal-435M              19218.00 (  0.00%)           2101.00 ( 89.07%)
> Ops swaptotal-944M              53233.00 (  0.00%)          98055.00 (-84.20%)
> Ops swaptotal-1452M             52064.00 (  0.00%)         145624.00 (-179.70%)
> Ops swaptotal-1961M             54960.00 (  0.00%)         153907.00 (-180.03%)
> Ops swaptotal-2469M             57485.00 (  0.00%)         176340.00 (-206.76%)
> Ops swaptotal-2978M             77704.00 (  0.00%)         182996.00 (-135.50%)
> Ops swapin-0M                   24834.00 (  0.00%)              8.00 ( 99.97%)
> Ops swapin-435M                  9038.00 (  0.00%)              0.00 (  0.00%)
> Ops swapin-944M                 26230.00 (  0.00%)          42953.00 (-63.76%)
> Ops swapin-1452M                25766.00 (  0.00%)          68440.00 (-165.62%)
> Ops swapin-1961M                27258.00 (  0.00%)          68129.00 (-149.94%)
> Ops swapin-2469M                28508.00 (  0.00%)          82234.00 (-188.46%)
> Ops swapin-2978M                37970.00 (  0.00%)          89280.00 (-135.13%)
> Ops minorfaults-0M            1460163.00 (  0.00%)         927966.00 ( 36.45%)
> Ops minorfaults-435M           954058.00 (  0.00%)         936182.00 (  1.87%)
> Ops minorfaults-944M           972818.00 (  0.00%)        1005956.00 ( -3.41%)
> Ops minorfaults-1452M          966597.00 (  0.00%)        1035465.00 ( -7.12%)
> Ops minorfaults-1961M          976158.00 (  0.00%)        1049441.00 ( -7.51%)
> Ops minorfaults-2469M          967815.00 (  0.00%)        1051752.00 ( -8.67%)
> Ops minorfaults-2978M          988712.00 (  0.00%)        1034615.00 ( -4.64%)
> Ops majorfaults-0M               5899.00 (  0.00%)              9.00 ( 99.85%)
> Ops majorfaults-435M             2684.00 (  0.00%)             67.00 ( 97.50%)
> Ops majorfaults-944M             4380.00 (  0.00%)           5790.00 (-32.19%)
> Ops majorfaults-1452M            4161.00 (  0.00%)           9222.00 (-121.63%)
> Ops majorfaults-1961M            4435.00 (  0.00%)           8800.00 (-98.42%)
> Ops majorfaults-2469M            4555.00 (  0.00%)          10541.00 (-131.42%)
> Ops majorfaults-2978M            6182.00 (  0.00%)          11618.00 (-87.93%)
> 
> 
> But the performance of the first machine I used whose total ram size
> is 2G is still bad.
> I need more time to summarize those testing results.
> 
> Maybe you can also have a try with lower total ram size.
> 
> --
> Regards,
> --Bob


A very important factor that you are not considering and
that might account for your different results is the
"initial conditions".  For example, I always ran my benchmarks
after a default-configured EL6 boot, which launches many services
at boot time, each of which creates many anonymous pages,
and these "service anonymous pages" are often the pages
that are selected by LRU for swapping, and compressed by zcache/zswap.
Someone else may run the benchmarks on a minimally-configured
embedded system, and someone else on a single-user system
with no services running at all.  A single-user system with
no services is often best for reproducing benchmark results but
may not be at all representative of the real world.

At a minimum, it would be good to always record "Active(anon)"
and "Inactive(anon)" in addition to the amount of physical
RAM in the system.  (Note, in /proc/meminfo on my system,
the sum of these don't add up to "AnonPages"... I'm not sure
why.)

And of course, even if the number of anonymous pages is
the same, the _contents_ of those pages may be very different,
which will affect zcache/zswap density which may have
a large impact on benchmark results.

Thanks,
Dan (T-minus two weeks and counting)

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
Konrad Rzeszutek Wilk June 21, 2013, 6:33 p.m. UTC | #12
On Fri, Jun 21, 2013 at 08:20:34AM -0700, Dan Magenheimer wrote:
> > From: Bob Liu [mailto:lliubbo@gmail.com]
>  Subject: Re: [PATCHv13 3/4] zswap: add to mm/
> > 
> > On Thu, Jun 20, 2013 at 10:23 PM, Seth Jennings
> > <sjenning@linux.vnet.ibm.com> wrote:
> > > On Thu, Jun 20, 2013 at 05:42:04PM +0800, Bob Liu wrote:
> > >> > Just made a mmtests run of my own and got very different results:
> > >> >
> > >>
> > >> It's strange, I'll update to rc6 and try again.
> > >> By the way, are you using 824 hardware compressor instead of lzo?
> > >
> > > My results where using lzo software compression.
> > >
> > 
> > Thanks, and today I used another machine to test zswap.
> > The total ram size of that machine is around 4G.
> > This time the result is better:
> >                                                rc6                         rc6
> >                                              zswap                        base
> > Ops memcachetest-0M             14619.00 (  0.00%)          15602.00 (  6.72%)
> > Ops memcachetest-435M           14727.00 (  0.00%)          15860.00 (  7.69%)
> > Ops memcachetest-944M           12452.00 (  0.00%)          11812.00 ( -5.14%)
> > Ops memcachetest-1452M          12183.00 (  0.00%)           9829.00 (-19.32%)
> > Ops memcachetest-1961M          11953.00 (  0.00%)           9337.00 (-21.89%)
> > Ops memcachetest-2469M          11201.00 (  0.00%)           7509.00 (-32.96%)
> > Ops memcachetest-2978M           9738.00 (  0.00%)           5981.00 (-38.58%)
> > Ops io-duration-0M                  0.00 (  0.00%)              0.00 (  0.00%)
> > Ops io-duration-435M               10.00 (  0.00%)              6.00 ( 40.00%)
> > Ops io-duration-944M               19.00 (  0.00%)             19.00 (  0.00%)
> > Ops io-duration-1452M              31.00 (  0.00%)             26.00 ( 16.13%)
> > Ops io-duration-1961M              40.00 (  0.00%)             35.00 ( 12.50%)
> > Ops io-duration-2469M              45.00 (  0.00%)             43.00 (  4.44%)
> > Ops io-duration-2978M              58.00 (  0.00%)             53.00 (  8.62%)
> > Ops swaptotal-0M                56711.00 (  0.00%)              8.00 ( 99.99%)
> > Ops swaptotal-435M              19218.00 (  0.00%)           2101.00 ( 89.07%)
> > Ops swaptotal-944M              53233.00 (  0.00%)          98055.00 (-84.20%)
> > Ops swaptotal-1452M             52064.00 (  0.00%)         145624.00 (-179.70%)
> > Ops swaptotal-1961M             54960.00 (  0.00%)         153907.00 (-180.03%)
> > Ops swaptotal-2469M             57485.00 (  0.00%)         176340.00 (-206.76%)
> > Ops swaptotal-2978M             77704.00 (  0.00%)         182996.00 (-135.50%)
> > Ops swapin-0M                   24834.00 (  0.00%)              8.00 ( 99.97%)
> > Ops swapin-435M                  9038.00 (  0.00%)              0.00 (  0.00%)
> > Ops swapin-944M                 26230.00 (  0.00%)          42953.00 (-63.76%)
> > Ops swapin-1452M                25766.00 (  0.00%)          68440.00 (-165.62%)
> > Ops swapin-1961M                27258.00 (  0.00%)          68129.00 (-149.94%)
> > Ops swapin-2469M                28508.00 (  0.00%)          82234.00 (-188.46%)
> > Ops swapin-2978M                37970.00 (  0.00%)          89280.00 (-135.13%)
> > Ops minorfaults-0M            1460163.00 (  0.00%)         927966.00 ( 36.45%)
> > Ops minorfaults-435M           954058.00 (  0.00%)         936182.00 (  1.87%)
> > Ops minorfaults-944M           972818.00 (  0.00%)        1005956.00 ( -3.41%)
> > Ops minorfaults-1452M          966597.00 (  0.00%)        1035465.00 ( -7.12%)
> > Ops minorfaults-1961M          976158.00 (  0.00%)        1049441.00 ( -7.51%)
> > Ops minorfaults-2469M          967815.00 (  0.00%)        1051752.00 ( -8.67%)
> > Ops minorfaults-2978M          988712.00 (  0.00%)        1034615.00 ( -4.64%)
> > Ops majorfaults-0M               5899.00 (  0.00%)              9.00 ( 99.85%)
> > Ops majorfaults-435M             2684.00 (  0.00%)             67.00 ( 97.50%)
> > Ops majorfaults-944M             4380.00 (  0.00%)           5790.00 (-32.19%)
> > Ops majorfaults-1452M            4161.00 (  0.00%)           9222.00 (-121.63%)
> > Ops majorfaults-1961M            4435.00 (  0.00%)           8800.00 (-98.42%)
> > Ops majorfaults-2469M            4555.00 (  0.00%)          10541.00 (-131.42%)
> > Ops majorfaults-2978M            6182.00 (  0.00%)          11618.00 (-87.93%)
> > 
> > 
> > But the performance of the first machine I used whose total ram size
> > is 2G is still bad.
> > I need more time to summarize those testing results.
> > 
> > Maybe you can also have a try with lower total ram size.
> > 
> > --
> > Regards,
> > --Bob
> 
> 
> A very important factor that you are not considering and
> that might account for your different results is the
> "initial conditions".  For example, I always ran my benchmarks
> after a default-configured EL6 boot, which launches many services
> at boot time, each of which creates many anonymous pages,
> and these "service anonymous pages" are often the pages
> that are selected by LRU for swapping, and compressed by zcache/zswap.
> Someone else may run the benchmarks on a minimally-configured
> embedded system, and someone else on a single-user system
> with no services running at all.  A single-user system with
> no services is often best for reproducing benchmark results but
> may not be at all representative of the real world.


Right. And interestingly enough the kernbench recommends
that model so that it is easier to reproduce.

> 
> At a minimum, it would be good to always record "Active(anon)"
> and "Inactive(anon)" in addition to the amount of physical
> RAM in the system.  (Note, in /proc/meminfo on my system,
> the sum of these don't add up to "AnonPages"... I'm not sure
> why.)
> 
> And of course, even if the number of anonymous pages is
> the same, the _contents_ of those pages may be very different,
> which will affect zcache/zswap density which may have
> a large impact on benchmark results.
> 
> Thanks,
> Dan (T-minus two weeks and counting)
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Patch
diff mbox series

diff --git a/mm/Kconfig b/mm/Kconfig
index 3367ac3..eec97f2 100644
--- a/mm/Kconfig
+++ b/mm/Kconfig
@@ -487,3 +487,23 @@  config ZBUD
 	  page.  While this design limits storage density, it has simple and
 	  deterministic reclaim properties that make it preferable to a higher
 	  density approach when reclaim will be used.
+
+config ZSWAP
+	bool "Compressed cache for swap pages (EXPERIMENTAL)"
+	depends on FRONTSWAP && CRYPTO
+	select CRYPTO_LZO
+	select ZBUD
+	default n
+	help
+	  A lightweight compressed cache for swap pages.  It takes
+	  pages that are in the process of being swapped out and attempts to
+	  compress them into a dynamically allocated RAM-based memory pool.
+	  This can result in a significant I/O reduction on swap device and,
+	  in the case where decompressing from RAM is faster that swap device
+	  reads, can also improve workload performance.
+
+	  This is marked experimental because it is a new feature (as of
+	  v3.11) that interacts heavily with memory reclaim.  While these
+	  interactions don't cause any known issues on simple memory setups,
+	  they have not be fully explored on the large set of potential
+	  configurations and workloads that exist.
diff --git a/mm/Makefile b/mm/Makefile
index 95f0197..f008033 100644
--- a/mm/Makefile
+++ b/mm/Makefile
@@ -32,6 +32,7 @@  obj-$(CONFIG_HAVE_MEMBLOCK) += memblock.o
 obj-$(CONFIG_BOUNCE)	+= bounce.o
 obj-$(CONFIG_SWAP)	+= page_io.o swap_state.o swapfile.o
 obj-$(CONFIG_FRONTSWAP)	+= frontswap.o
+obj-$(CONFIG_ZSWAP)	+= zswap.o
 obj-$(CONFIG_HAS_DMA)	+= dmapool.o
 obj-$(CONFIG_HUGETLBFS)	+= hugetlb.o
 obj-$(CONFIG_NUMA) 	+= mempolicy.o
diff --git a/mm/zswap.c b/mm/zswap.c
new file mode 100644
index 0000000..deda2b6
--- /dev/null
+++ b/mm/zswap.c
@@ -0,0 +1,943 @@ 
+/*
+ * zswap.c - zswap driver file
+ *
+ * zswap is a backend for frontswap that takes pages that are in the process
+ * of being swapped out and attempts to compress and store them in a
+ * RAM-based memory pool.  This can result in a significant I/O reduction on
+ * the swap device and, in the case where decompressing from RAM is faster
+ * than reading from the swap device, can also improve workload performance.
+ *
+ * Copyright (C) 2012  Seth Jennings <sjenning@linux.vnet.ibm.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+*/
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <linux/module.h>
+#include <linux/cpu.h>
+#include <linux/highmem.h>
+#include <linux/slab.h>
+#include <linux/spinlock.h>
+#include <linux/types.h>
+#include <linux/atomic.h>
+#include <linux/frontswap.h>
+#include <linux/rbtree.h>
+#include <linux/swap.h>
+#include <linux/crypto.h>
+#include <linux/mempool.h>
+#include <linux/zbud.h>
+
+#include <linux/mm_types.h>
+#include <linux/page-flags.h>
+#include <linux/swapops.h>
+#include <linux/writeback.h>
+#include <linux/pagemap.h>
+
+/*********************************
+* statistics
+**********************************/
+/* Number of memory pages used by the compressed pool */
+static u64 zswap_pool_pages;
+/* The number of compressed pages currently stored in zswap */
+static atomic_t zswap_stored_pages = ATOMIC_INIT(0);
+
+/*
+ * The statistics below are not protected from concurrent access for
+ * performance reasons so they may not be a 100% accurate.  However,
+ * they do provide useful information on roughly how many times a
+ * certain event is occurring.
+*/
+
+/* Pool limit was hit (see zswap_max_pool_percent) */
+static u64 zswap_pool_limit_hit;
+/* Pages written back when pool limit was reached */
+static u64 zswap_written_back_pages;
+/* Store failed due to a reclaim failure after pool limit was reached */
+static u64 zswap_reject_reclaim_fail;
+/* Compressed page was too big for the allocator to (optimally) store */
+static u64 zswap_reject_compress_poor;
+/* Store failed because underlying allocator could not get memory */
+static u64 zswap_reject_alloc_fail;
+/* Store failed because the entry metadata could not be allocated (rare) */
+static u64 zswap_reject_kmemcache_fail;
+/* Duplicate store was encountered (rare) */
+static u64 zswap_duplicate_entry;
+
+/*********************************
+* tunables
+**********************************/
+/* Enable/disable zswap (disabled by default, fixed at boot for now) */
+static bool zswap_enabled __read_mostly;
+module_param_named(enabled, zswap_enabled, bool, 0);
+
+/* Compressor to be used by zswap (fixed at boot for now) */
+#define ZSWAP_COMPRESSOR_DEFAULT "lzo"
+static char *zswap_compressor = ZSWAP_COMPRESSOR_DEFAULT;
+module_param_named(compressor, zswap_compressor, charp, 0);
+
+/* The maximum percentage of memory that the compressed pool can occupy */
+static unsigned int zswap_max_pool_percent = 20;
+module_param_named(max_pool_percent,
+			zswap_max_pool_percent, uint, 0644);
+
+/*********************************
+* compression functions
+**********************************/
+/* per-cpu compression transforms */
+static struct crypto_comp * __percpu *zswap_comp_pcpu_tfms;
+
+enum comp_op {
+	ZSWAP_COMPOP_COMPRESS,
+	ZSWAP_COMPOP_DECOMPRESS
+};
+
+static int zswap_comp_op(enum comp_op op, const u8 *src, unsigned int slen,
+				u8 *dst, unsigned int *dlen)
+{
+	struct crypto_comp *tfm;
+	int ret;
+
+	tfm = *per_cpu_ptr(zswap_comp_pcpu_tfms, get_cpu());
+	switch (op) {
+	case ZSWAP_COMPOP_COMPRESS:
+		ret = crypto_comp_compress(tfm, src, slen, dst, dlen);
+		break;
+	case ZSWAP_COMPOP_DECOMPRESS:
+		ret = crypto_comp_decompress(tfm, src, slen, dst, dlen);
+		break;
+	default:
+		ret = -EINVAL;
+	}
+
+	put_cpu();
+	return ret;
+}
+
+static int __init zswap_comp_init(void)
+{
+	if (!crypto_has_comp(zswap_compressor, 0, 0)) {
+		pr_info("%s compressor not available\n", zswap_compressor);
+		/* fall back to default compressor */
+		zswap_compressor = ZSWAP_COMPRESSOR_DEFAULT;
+		if (!crypto_has_comp(zswap_compressor, 0, 0))
+			/* can't even load the default compressor */
+			return -ENODEV;
+	}
+	pr_info("using %s compressor\n", zswap_compressor);
+
+	/* alloc percpu transforms */
+	zswap_comp_pcpu_tfms = alloc_percpu(struct crypto_comp *);
+	if (!zswap_comp_pcpu_tfms)
+		return -ENOMEM;
+	return 0;
+}
+
+static void zswap_comp_exit(void)
+{
+	/* free percpu transforms */
+	if (zswap_comp_pcpu_tfms)
+		free_percpu(zswap_comp_pcpu_tfms);
+}
+
+/*********************************
+* data structures
+**********************************/
+/*
+ * struct zswap_entry
+ *
+ * This structure contains the metadata for tracking a single compressed
+ * page within zswap.
+ *
+ * rbnode - links the entry into red-black tree for the appropriate swap type
+ * refcount - the number of outstanding reference to the entry. This is needed
+ *            to protect against premature freeing of the entry by code
+ *            concurent calls to load, invalidate, and writeback.  The lock
+ *            for the zswap_tree structure that contains the entry must
+ *            be held while changing the refcount.  Since the lock must
+ *            be held, there is no reason to also make refcount atomic.
+ * offset - the swap offset for the entry.  Index into the red-black tree.
+ * handle - zsmalloc allocation handle that stores the compressed page data
+ * length - the length in bytes of the compressed page data.  Needed during
+ *           decompression
+ */
+struct zswap_entry {
+	struct rb_node rbnode;
+	pgoff_t offset;
+	int refcount;
+	unsigned int length;
+	unsigned long handle;
+};
+
+struct zswap_header {
+	swp_entry_t swpentry;
+};
+
+/*
+ * The tree lock in the zswap_tree struct protects a few things:
+ * - the rbtree
+ * - the refcount field of each entry in the tree
+ */
+struct zswap_tree {
+	struct rb_root rbroot;
+	spinlock_t lock;
+	struct zbud_pool *pool;
+};
+
+static struct zswap_tree *zswap_trees[MAX_SWAPFILES];
+
+/*********************************
+* zswap entry functions
+**********************************/
+static struct kmem_cache *zswap_entry_cache;
+
+static int zswap_entry_cache_create(void)
+{
+	zswap_entry_cache = KMEM_CACHE(zswap_entry, 0);
+	return (zswap_entry_cache == NULL);
+}
+
+static void zswap_entry_cache_destory(void)
+{
+	kmem_cache_destroy(zswap_entry_cache);
+}
+
+static struct zswap_entry *zswap_entry_cache_alloc(gfp_t gfp)
+{
+	struct zswap_entry *entry;
+	entry = kmem_cache_alloc(zswap_entry_cache, gfp);
+	if (!entry)
+		return NULL;
+	entry->refcount = 1;
+	return entry;
+}
+
+static void zswap_entry_cache_free(struct zswap_entry *entry)
+{
+	kmem_cache_free(zswap_entry_cache, entry);
+}
+
+/* caller must hold the tree lock */
+static void zswap_entry_get(struct zswap_entry *entry)
+{
+	entry->refcount++;
+}
+
+/* caller must hold the tree lock */
+static int zswap_entry_put(struct zswap_entry *entry)
+{
+	entry->refcount--;
+	return entry->refcount;
+}
+
+/*********************************
+* rbtree functions
+**********************************/
+static struct zswap_entry *zswap_rb_search(struct rb_root *root, pgoff_t offset)
+{
+	struct rb_node *node = root->rb_node;
+	struct zswap_entry *entry;
+
+	while (node) {
+		entry = rb_entry(node, struct zswap_entry, rbnode);
+		if (entry->offset > offset)
+			node = node->rb_left;
+		else if (entry->offset < offset)
+			node = node->rb_right;
+		else
+			return entry;
+	}
+	return NULL;
+}
+
+/*
+ * In the case that a entry with the same offset is found, a pointer to
+ * the existing entry is stored in dupentry and the function returns -EEXIST
+ */
+static int zswap_rb_insert(struct rb_root *root, struct zswap_entry *entry,
+			struct zswap_entry **dupentry)
+{
+	struct rb_node **link = &root->rb_node, *parent = NULL;
+	struct zswap_entry *myentry;
+
+	while (*link) {
+		parent = *link;
+		myentry = rb_entry(parent, struct zswap_entry, rbnode);
+		if (myentry->offset > entry->offset)
+			link = &(*link)->rb_left;
+		else if (myentry->offset < entry->offset)
+			link = &(*link)->rb_right;
+		else {
+			*dupentry = myentry;
+			return -EEXIST;
+		}
+	}
+	rb_link_node(&entry->rbnode, parent, link);
+	rb_insert_color(&entry->rbnode, root);
+	return 0;
+}
+
+/*********************************
+* per-cpu code
+**********************************/
+static DEFINE_PER_CPU(u8 *, zswap_dstmem);
+
+static int __zswap_cpu_notifier(unsigned long action, unsigned long cpu)
+{
+	struct crypto_comp *tfm;
+	u8 *dst;
+
+	switch (action) {
+	case CPU_UP_PREPARE:
+		tfm = crypto_alloc_comp(zswap_compressor, 0, 0);
+		if (IS_ERR(tfm)) {
+			pr_err("can't allocate compressor transform\n");
+			return NOTIFY_BAD;
+		}
+		*per_cpu_ptr(zswap_comp_pcpu_tfms, cpu) = tfm;
+		dst = kmalloc(PAGE_SIZE * 2, GFP_KERNEL);
+		if (!dst) {
+			pr_err("can't allocate compressor buffer\n");
+			crypto_free_comp(tfm);
+			*per_cpu_ptr(zswap_comp_pcpu_tfms, cpu) = NULL;
+			return NOTIFY_BAD;
+		}
+		per_cpu(zswap_dstmem, cpu) = dst;
+		break;
+	case CPU_DEAD:
+	case CPU_UP_CANCELED:
+		tfm = *per_cpu_ptr(zswap_comp_pcpu_tfms, cpu);
+		if (tfm) {
+			crypto_free_comp(tfm);
+			*per_cpu_ptr(zswap_comp_pcpu_tfms, cpu) = NULL;
+		}
+		dst = per_cpu(zswap_dstmem, cpu);
+		kfree(dst);
+		per_cpu(zswap_dstmem, cpu) = NULL;
+		break;
+	default:
+		break;
+	}
+	return NOTIFY_OK;
+}
+
+static int zswap_cpu_notifier(struct notifier_block *nb,
+				unsigned long action, void *pcpu)
+{
+	unsigned long cpu = (unsigned long)pcpu;
+	return __zswap_cpu_notifier(action, cpu);
+}
+
+static struct notifier_block zswap_cpu_notifier_block = {
+	.notifier_call = zswap_cpu_notifier
+};
+
+static int zswap_cpu_init(void)
+{
+	unsigned long cpu;
+
+	get_online_cpus();
+	for_each_online_cpu(cpu)
+		if (__zswap_cpu_notifier(CPU_UP_PREPARE, cpu) != NOTIFY_OK)
+			goto cleanup;
+	register_cpu_notifier(&zswap_cpu_notifier_block);
+	put_online_cpus();
+	return 0;
+
+cleanup:
+	for_each_online_cpu(cpu)
+		__zswap_cpu_notifier(CPU_UP_CANCELED, cpu);
+	put_online_cpus();
+	return -ENOMEM;
+}
+
+/*********************************
+* helpers
+**********************************/
+static bool zswap_is_full(void)
+{
+	return (totalram_pages * zswap_max_pool_percent / 100 <
+		zswap_pool_pages);
+}
+
+/*
+ * Carries out the common pattern of freeing and entry's zsmalloc allocation,
+ * freeing the entry itself, and decrementing the number of stored pages.
+ */
+static void zswap_free_entry(struct zswap_tree *tree, struct zswap_entry *entry)
+{
+	zbud_free(tree->pool, entry->handle);
+	zswap_entry_cache_free(entry);
+	atomic_dec(&zswap_stored_pages);
+	zswap_pool_pages = zbud_get_pool_size(tree->pool);
+}
+
+/*********************************
+* writeback code
+**********************************/
+/* return enum for zswap_get_swap_cache_page */
+enum zswap_get_swap_ret {
+	ZSWAP_SWAPCACHE_NEW,
+	ZSWAP_SWAPCACHE_EXIST,
+	ZSWAP_SWAPCACHE_NOMEM
+};
+
+/*
+ * zswap_get_swap_cache_page
+ *
+ * This is an adaption of read_swap_cache_async()
+ *
+ * This function tries to find a page with the given swap entry
+ * in the swapper_space address space (the swap cache).  If the page
+ * is found, it is returned in retpage.  Otherwise, a page is allocated,
+ * added to the swap cache, and returned in retpage.
+ *
+ * If success, the swap cache page is returned in retpage
+ * Returns 0 if page was already in the swap cache, page is not locked
+ * Returns 1 if the new page needs to be populated, page is locked
+ * Returns <0 on error
+ */
+static int zswap_get_swap_cache_page(swp_entry_t entry,
+				struct page **retpage)
+{
+	struct page *found_page, *new_page = NULL;
+	struct address_space *swapper_space = &swapper_spaces[swp_type(entry)];
+	int err;
+
+	*retpage = NULL;
+	do {
+		/*
+		 * First check the swap cache.  Since this is normally
+		 * called after lookup_swap_cache() failed, re-calling
+		 * that would confuse statistics.
+		 */
+		found_page = find_get_page(swapper_space, entry.val);
+		if (found_page)
+			break;
+
+		/*
+		 * Get a new page to read into from swap.
+		 */
+		if (!new_page) {
+			new_page = alloc_page(GFP_KERNEL);
+			if (!new_page)
+				break; /* Out of memory */
+		}
+
+		/*
+		 * call radix_tree_preload() while we can wait.
+		 */
+		err = radix_tree_preload(GFP_KERNEL);
+		if (err)
+			break;
+
+		/*
+		 * Swap entry may have been freed since our caller observed it.
+		 */
+		err = swapcache_prepare(entry);
+		if (err == -EEXIST) { /* seems racy */
+			radix_tree_preload_end();
+			continue;
+		}
+		if (err) { /* swp entry is obsolete ? */
+			radix_tree_preload_end();
+			break;
+		}
+
+		/* May fail (-ENOMEM) if radix-tree node allocation failed. */
+		__set_page_locked(new_page);
+		SetPageSwapBacked(new_page);
+		err = __add_to_swap_cache(new_page, entry);
+		if (likely(!err)) {
+			radix_tree_preload_end();
+			lru_cache_add_anon(new_page);
+			*retpage = new_page;
+			return ZSWAP_SWAPCACHE_NEW;
+		}
+		radix_tree_preload_end();
+		ClearPageSwapBacked(new_page);
+		__clear_page_locked(new_page);
+		/*
+		 * add_to_swap_cache() doesn't return -EEXIST, so we can safely
+		 * clear SWAP_HAS_CACHE flag.
+		 */
+		swapcache_free(entry, NULL);
+	} while (err != -ENOMEM);
+
+	if (new_page)
+		page_cache_release(new_page);
+	if (!found_page)
+		return ZSWAP_SWAPCACHE_NOMEM;
+	*retpage = found_page;
+	return ZSWAP_SWAPCACHE_EXIST;
+}
+
+/*
+ * Attempts to free an entry by adding a page to the swap cache,
+ * decompressing the entry data into the page, and issuing a
+ * bio write to write the page back to the swap device.
+ *
+ * This can be thought of as a "resumed writeback" of the page
+ * to the swap device.  We are basically resuming the same swap
+ * writeback path that was intercepted with the frontswap_store()
+ * in the first place.  After the page has been decompressed into
+ * the swap cache, the compressed version stored by zswap can be
+ * freed.
+ */
+static int zswap_writeback_entry(struct zbud_pool *pool, unsigned long handle)
+{
+	struct zswap_header *zhdr;
+	swp_entry_t swpentry;
+	struct zswap_tree *tree;
+	pgoff_t offset;
+	struct zswap_entry *entry;
+	struct page *page;
+	u8 *src, *dst;
+	unsigned int dlen;
+	int ret, refcount;
+	struct writeback_control wbc = {
+		.sync_mode = WB_SYNC_NONE,
+	};
+
+	/* extract swpentry from data */
+	zhdr = zbud_map(pool, handle);
+	swpentry = zhdr->swpentry; /* here */
+	zbud_unmap(pool, handle);
+	tree = zswap_trees[swp_type(swpentry)];
+	offset = swp_offset(swpentry);
+	BUG_ON(pool != tree->pool);
+
+	/* find and ref zswap entry */
+	spin_lock(&tree->lock);
+	entry = zswap_rb_search(&tree->rbroot, offset);
+	if (!entry) {
+		/* entry was invalidated */
+		spin_unlock(&tree->lock);
+		return 0;
+	}
+	zswap_entry_get(entry);
+	spin_unlock(&tree->lock);
+	BUG_ON(offset != entry->offset);
+
+	/* try to allocate swap cache page */
+	switch (zswap_get_swap_cache_page(swpentry, &page)) {
+	case ZSWAP_SWAPCACHE_NOMEM: /* no memory */
+		ret = -ENOMEM;
+		goto fail;
+
+	case ZSWAP_SWAPCACHE_EXIST: /* page is unlocked */
+		/* page is already in the swap cache, ignore for now */
+		page_cache_release(page);
+		ret = -EEXIST;
+		goto fail;
+
+	case ZSWAP_SWAPCACHE_NEW: /* page is locked */
+		/* decompress */
+		dlen = PAGE_SIZE;
+		src = (u8 *)zbud_map(tree->pool, entry->handle) +
+			sizeof(struct zswap_header);
+		dst = kmap_atomic(page);
+		ret = zswap_comp_op(ZSWAP_COMPOP_DECOMPRESS, src,
+				entry->length, dst, &dlen);
+		kunmap_atomic(dst);
+		zbud_unmap(tree->pool, entry->handle);
+		BUG_ON(ret);
+		BUG_ON(dlen != PAGE_SIZE);
+
+		/* page is up to date */
+		SetPageUptodate(page);
+	}
+
+	/* start writeback */
+	__swap_writepage(page, &wbc, end_swap_bio_write);
+	page_cache_release(page);
+	zswap_written_back_pages++;
+
+	spin_lock(&tree->lock);
+
+	/* drop local reference */
+	zswap_entry_put(entry);
+	/* drop the initial reference from entry creation */
+	refcount = zswap_entry_put(entry);
+
+	/*
+	 * There are three possible values for refcount here:
+	 * (1) refcount is 1, load is in progress, unlink from rbtree,
+	 *     load will free
+	 * (2) refcount is 0, (normal case) entry is valid,
+	 *     remove from rbtree and free entry
+	 * (3) refcount is -1, invalidate happened during writeback,
+	 *     free entry
+	 */
+	if (refcount >= 0) {
+		/* no invalidate yet, remove from rbtree */
+		rb_erase(&entry->rbnode, &tree->rbroot);
+	}
+	spin_unlock(&tree->lock);
+	if (refcount <= 0) {
+		/* free the entry */
+		zswap_free_entry(tree, entry);
+		return 0;
+	}
+	return -EAGAIN;
+
+fail:
+	spin_lock(&tree->lock);
+	zswap_entry_put(entry);
+	spin_unlock(&tree->lock);
+	return ret;
+}
+
+/*********************************
+* frontswap hooks
+**********************************/
+/* attempts to compress and store an single page */
+static int zswap_frontswap_store(unsigned type, pgoff_t offset,
+				struct page *page)
+{
+	struct zswap_tree *tree = zswap_trees[type];
+	struct zswap_entry *entry, *dupentry;
+	int ret;
+	unsigned int dlen = PAGE_SIZE, len;
+	unsigned long handle;
+	char *buf;
+	u8 *src, *dst;
+	struct zswap_header *zhdr;
+
+	if (!tree) {
+		ret = -ENODEV;
+		goto reject;
+	}
+
+	/* reclaim space if needed */
+	if (zswap_is_full()) {
+		zswap_pool_limit_hit++;
+		if (zbud_reclaim_page(tree->pool, 8)) {
+			zswap_reject_reclaim_fail++;
+			ret = -ENOMEM;
+			goto reject;
+		}
+	}
+
+	/* allocate entry */
+	entry = zswap_entry_cache_alloc(GFP_KERNEL);
+	if (!entry) {
+		zswap_reject_kmemcache_fail++;
+		ret = -ENOMEM;
+		goto reject;
+	}
+
+	/* compress */
+	dst = get_cpu_var(zswap_dstmem);
+	src = kmap_atomic(page);
+	ret = zswap_comp_op(ZSWAP_COMPOP_COMPRESS, src, PAGE_SIZE, dst, &dlen);
+	kunmap_atomic(src);
+	if (ret) {
+		ret = -EINVAL;
+		goto freepage;
+	}
+
+	/* store */
+	len = dlen + sizeof(struct zswap_header);
+	ret = zbud_alloc(tree->pool, len, __GFP_NORETRY | __GFP_NOWARN,
+		&handle);
+	if (ret == -ENOSPC) {
+		zswap_reject_compress_poor++;
+		goto freepage;
+	}
+	if (ret) {
+		zswap_reject_alloc_fail++;
+		goto freepage;
+	}
+	zhdr = zbud_map(tree->pool, handle);
+	zhdr->swpentry = swp_entry(type, offset);
+	buf = (u8 *)(zhdr + 1);
+	memcpy(buf, dst, dlen);
+	zbud_unmap(tree->pool, handle);
+	put_cpu_var(zswap_dstmem);
+
+	/* populate entry */
+	entry->offset = offset;
+	entry->handle = handle;
+	entry->length = dlen;
+
+	/* map */
+	spin_lock(&tree->lock);
+	do {
+		ret = zswap_rb_insert(&tree->rbroot, entry, &dupentry);
+		if (ret == -EEXIST) {
+			zswap_duplicate_entry++;
+			/* remove from rbtree */
+			rb_erase(&dupentry->rbnode, &tree->rbroot);
+			if (!zswap_entry_put(dupentry)) {
+				/* free */
+				zswap_free_entry(tree, dupentry);
+			}
+		}
+	} while (ret == -EEXIST);
+	spin_unlock(&tree->lock);
+
+	/* update stats */
+	atomic_inc(&zswap_stored_pages);
+	zswap_pool_pages = zbud_get_pool_size(tree->pool);
+
+	return 0;
+
+freepage:
+	put_cpu_var(zswap_dstmem);
+	zswap_entry_cache_free(entry);
+reject:
+	return ret;
+}
+
+/*
+ * returns 0 if the page was successfully decompressed
+ * return -1 on entry not found or error
+*/
+static int zswap_frontswap_load(unsigned type, pgoff_t offset,
+				struct page *page)
+{
+	struct zswap_tree *tree = zswap_trees[type];
+	struct zswap_entry *entry;
+	u8 *src, *dst;
+	unsigned int dlen;
+	int refcount, ret;
+
+	/* find */
+	spin_lock(&tree->lock);
+	entry = zswap_rb_search(&tree->rbroot, offset);
+	if (!entry) {
+		/* entry was written back */
+		spin_unlock(&tree->lock);
+		return -1;
+	}
+	zswap_entry_get(entry);
+	spin_unlock(&tree->lock);
+
+	/* decompress */
+	dlen = PAGE_SIZE;
+	src = (u8 *)zbud_map(tree->pool, entry->handle) +
+			sizeof(struct zswap_header);
+	dst = kmap_atomic(page);
+	ret = zswap_comp_op(ZSWAP_COMPOP_DECOMPRESS, src, entry->length,
+		dst, &dlen);
+	kunmap_atomic(dst);
+	zbud_unmap(tree->pool, entry->handle);
+	BUG_ON(ret);
+
+	spin_lock(&tree->lock);
+	refcount = zswap_entry_put(entry);
+	if (likely(refcount)) {
+		spin_unlock(&tree->lock);
+		return 0;
+	}
+	spin_unlock(&tree->lock);
+
+	/*
+	 * We don't have to unlink from the rbtree because
+	 * zswap_writeback_entry() or zswap_frontswap_invalidate page()
+	 * has already done this for us if we are the last reference.
+	 */
+	/* free */
+
+	zswap_free_entry(tree, entry);
+
+	return 0;
+}
+
+/* frees an entry in zswap */
+static void zswap_frontswap_invalidate_page(unsigned type, pgoff_t offset)
+{
+	struct zswap_tree *tree = zswap_trees[type];
+	struct zswap_entry *entry;
+	int refcount;
+
+	/* find */
+	spin_lock(&tree->lock);
+	entry = zswap_rb_search(&tree->rbroot, offset);
+	if (!entry) {
+		/* entry was written back */
+		spin_unlock(&tree->lock);
+		return;
+	}
+
+	/* remove from rbtree */
+	rb_erase(&entry->rbnode, &tree->rbroot);
+
+	/* drop the initial reference from entry creation */
+	refcount = zswap_entry_put(entry);
+
+	spin_unlock(&tree->lock);
+
+	if (refcount) {
+		/* writeback in progress, writeback will free */
+		return;
+	}
+
+	/* free */
+	zswap_free_entry(tree, entry);
+}
+
+/* frees all zswap entries for the given swap type */
+static void zswap_frontswap_invalidate_area(unsigned type)
+{
+	struct zswap_tree *tree = zswap_trees[type];
+	struct rb_node *node;
+	struct zswap_entry *entry;
+
+	if (!tree)
+		return;
+
+	/* walk the tree and free everything */
+	spin_lock(&tree->lock);
+	/*
+	 * TODO: Even though this code should not be executed because
+	 * the try_to_unuse() in swapoff should have emptied the tree,
+	 * it is very wasteful to rebalance the tree after every
+	 * removal when we are freeing the whole tree.
+	 *
+	 * If post-order traversal code is ever added to the rbtree
+	 * implementation, it should be used here.
+	 */
+	while ((node = rb_first(&tree->rbroot))) {
+		entry = rb_entry(node, struct zswap_entry, rbnode);
+		rb_erase(&entry->rbnode, &tree->rbroot);
+		zbud_free(tree->pool, entry->handle);
+		zswap_entry_cache_free(entry);
+		atomic_dec(&zswap_stored_pages);
+	}
+	tree->rbroot = RB_ROOT;
+	spin_unlock(&tree->lock);
+}
+
+static struct zbud_ops zswap_zbud_ops = {
+	.evict = zswap_writeback_entry
+};
+
+static void zswap_frontswap_init(unsigned type)
+{
+	struct zswap_tree *tree;
+
+	tree = kzalloc(sizeof(struct zswap_tree), GFP_KERNEL);
+	if (!tree)
+		goto err;
+	tree->pool = zbud_create_pool(GFP_KERNEL, &zswap_zbud_ops);
+	if (!tree->pool)
+		goto freetree;
+	tree->rbroot = RB_ROOT;
+	spin_lock_init(&tree->lock);
+	zswap_trees[type] = tree;
+	return;
+
+freetree:
+	kfree(tree);
+err:
+	pr_err("alloc failed, zswap disabled for swap type %d\n", type);
+}
+
+static struct frontswap_ops zswap_frontswap_ops = {
+	.store = zswap_frontswap_store,
+	.load = zswap_frontswap_load,
+	.invalidate_page = zswap_frontswap_invalidate_page,
+	.invalidate_area = zswap_frontswap_invalidate_area,
+	.init = zswap_frontswap_init
+};
+
+/*********************************
+* debugfs functions
+**********************************/
+#ifdef CONFIG_DEBUG_FS
+#include <linux/debugfs.h>
+
+static struct dentry *zswap_debugfs_root;
+
+static int __init zswap_debugfs_init(void)
+{
+	if (!debugfs_initialized())
+		return -ENODEV;
+
+	zswap_debugfs_root = debugfs_create_dir("zswap", NULL);
+	if (!zswap_debugfs_root)
+		return -ENOMEM;
+
+	debugfs_create_u64("pool_limit_hit", S_IRUGO,
+			zswap_debugfs_root, &zswap_pool_limit_hit);
+	debugfs_create_u64("reject_reclaim_fail", S_IRUGO,
+			zswap_debugfs_root, &zswap_reject_reclaim_fail);
+	debugfs_create_u64("reject_alloc_fail", S_IRUGO,
+			zswap_debugfs_root, &zswap_reject_alloc_fail);
+	debugfs_create_u64("reject_kmemcache_fail", S_IRUGO,
+			zswap_debugfs_root, &zswap_reject_kmemcache_fail);
+	debugfs_create_u64("reject_compress_poor", S_IRUGO,
+			zswap_debugfs_root, &zswap_reject_compress_poor);
+	debugfs_create_u64("written_back_pages", S_IRUGO,
+			zswap_debugfs_root, &zswap_written_back_pages);
+	debugfs_create_u64("duplicate_entry", S_IRUGO,
+			zswap_debugfs_root, &zswap_duplicate_entry);
+	debugfs_create_u64("pool_pages", S_IRUGO,
+			zswap_debugfs_root, &zswap_pool_pages);
+	debugfs_create_atomic_t("stored_pages", S_IRUGO,
+			zswap_debugfs_root, &zswap_stored_pages);
+
+	return 0;
+}
+
+static void __exit zswap_debugfs_exit(void)
+{
+	debugfs_remove_recursive(zswap_debugfs_root);
+}
+#else
+static int __init zswap_debugfs_init(void)
+{
+	return 0;
+}
+
+static void __exit zswap_debugfs_exit(void) { }
+#endif
+
+/*********************************
+* module init and exit
+**********************************/
+static int __init init_zswap(void)
+{
+	if (!zswap_enabled)
+		return 0;
+
+	pr_info("loading zswap\n");
+	if (zswap_entry_cache_create()) {
+		pr_err("entry cache creation failed\n");
+		goto error;
+	}
+	if (zswap_comp_init()) {
+		pr_err("compressor initialization failed\n");
+		goto compfail;
+	}
+	if (zswap_cpu_init()) {
+		pr_err("per-cpu initialization failed\n");
+		goto pcpufail;
+	}
+	frontswap_register_ops(&zswap_frontswap_ops);
+	if (zswap_debugfs_init())
+		pr_warn("debugfs initialization failed\n");
+	return 0;
+pcpufail:
+	zswap_comp_exit();
+compfail:
+	zswap_entry_cache_destory();
+error:
+	return -ENOMEM;
+}
+/* must be late so crypto has time to come up */
+late_initcall(init_zswap);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Seth Jennings <sjenning@linux.vnet.ibm.com>");
+MODULE_DESCRIPTION("Compressed cache for swap pages");