{"push_id":1038658570,"size":5,"distinct_size":5,"ref":"refs/heads/test","head":"c9acfca5405c3b0e36612441365789741a1677f3","before":"c02706a37dca181122664f8f60544bcbec428319","commits":[{"sha":"19787d384ff27d40a4f5e558dd343f77605bb387","author":{"email":"eee62f459f15dcddf87a8df69e8328e2a2562028@kernel.org","name":"Minchan Kim"},"message":"Rebase zram and zsmalloc from 3.15.\n\n3.15 upstream has many patches to zram that significantly improve\nperformance. Rebase zram and zsmalloc from that time.\n\nzsmalloc: move it under mm\n\nThis patch moves zsmalloc under mm directory.\n\nBefore that, description will explain why we have needed custom\nallocator.\n\nZsmalloc is a new slab-based memory allocator for storing compressed\npages.  It is designed for low fragmentation and high allocation success\nrate on large object, but <= PAGE_SIZE allocations.\n\nzsmalloc differs from the kernel slab allocator in two primary ways to\nachieve these design goals.\n\nzsmalloc never requires high order page allocations to back slabs, or\n\"size classes\" in zsmalloc terms.  Instead it allows multiple\nsingle-order pages to be stitched together into a \"zspage\" which backs\nthe slab.  This allows for higher allocation success rate under memory\npressure.\n\nAlso, zsmalloc allows objects to span page boundaries within the zspage.\nThis allows for lower fragmentation than could be had with the kernel\nslab allocator for objects between PAGE_SIZE/2 and PAGE_SIZE.  With the\nkernel slab allocator, if a page compresses to 60% of it original size,\nthe memory savings gained through compression is lost in fragmentation\nbecause another object of the same size can't be stored in the leftover\nspace.\n\nThis ability to span pages results in zsmalloc allocations not being\ndirectly addressable by the user.  The user is given an\nnon-dereferencable handle in response to an allocation request.  That\nhandle must be mapped, using zs_map_object(), which returns a pointer to\nthe mapped region that can be used.  The mapping is necessary since the\nobject data may reside in two different noncontigious pages.\n\nThe zsmalloc fulfills the allocation needs for zram perfectly\n\n[sjenning@linux.vnet.ibm.com: borrow Seth's quote]\nSigned-off-by: Minchan Kim <minchan@kernel.org>\nAcked-by: Nitin Gupta <ngupta@vflare.org>\nReviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>\nCc: Bob Liu <bob.liu@oracle.com>\nCc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>\nCc: Hugh Dickins <hughd@google.com>\nCc: Jens Axboe <axboe@kernel.dk>\nCc: Luigi Semenzato <semenzato@google.com>\nCc: Mel Gorman <mgorman@suse.de>\nCc: Pekka Enberg <penberg@kernel.org>\nCc: Rik van Riel <riel@redhat.com>\nCc: Seth Jennings <sjenning@linux.vnet.ibm.com>\nSigned-off-by: Andrew Morton <akpm@linux-foundation.org>\nSigned-off-by: Linus Torvalds <torvalds@linux-foundation.org>\n\n(cherry picked from commit bcf1647d0899666f0fb90d176abf63bae22abb7c)\n\nChange-Id: Id6d44d6b743131eac94009d6765dcf2ae097501e\n\nzsmalloc: add copyright\n\nAdd my copyright to the zsmalloc source code which I maintain.\n\nSigned-off-by: Minchan Kim <minchan@kernel.org>\nCc: Nitin Gupta <ngupta@vflare.org>\nSigned-off-by: Andrew Morton <akpm@linux-foundation.org>\nSigned-off-by: Linus Torvalds <torvalds@linux-foundation.org>\n(cherry picked from commit 31fc00bb788ffde7d8d861d8b2bba798ab445992)\n\nzsmalloc: Fix CPU hotplug callback registration\n\nSubsystems that want to register CPU hotplug callbacks, as well as perform\ninitialization for the CPUs that are already online, often do it as shown\nbelow:\n\n\tget_online_cpus();\n\n\tfor_each_online_cpu(cpu)\n\t\tinit_cpu(cpu);\n\n\tregister_cpu_notifier(&foobar_cpu_notifier);\n\n\tput_online_cpus();\n\nThis is wrong, since it is prone to ABBA deadlocks involving the\ncpu_add_remove_lock and the cpu_hotplug.lock (when running concurrently\nwith CPU hotplug operations).\n\nInstead, the correct and race-free way of performing the callback\nregistration is:\n\n\tcpu_notifier_register_begin();\n\n\tfor_each_online_cpu(cpu)\n\t\tinit_cpu(cpu);\n\n\t/* Note the use of the double underscored version of the API */\n\t__register_cpu_notifier(&foobar_cpu_notifier);\n\n\tcpu_notifier_register_done();\n\nFix the zsmalloc code by using this latter form of callback registration.\n\nCc: Nitin Gupta <ngupta@vflare.org>\nCc: Ingo Molnar <mingo@kernel.org>\nSigned-off-by: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>\nAcked-by: Minchan Kim <minchan@kernel.org>\nSigned-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>\n(cherry picked from commit f0e71fcd0fa6f3f5495cd9ad3f1e4acd94446a55)\n\nzram: remove drivers/staging/zram.\n\nPrepare for rebase to newer zram.\n\nChange-Id: I1985eb6c9abacf018e5ff597314723f68828f1e9\n\nzram: promote zram from staging\n\nZram has lived in staging for a LONG LONG time and have been\nfixed/improved by many contributors so code is clean and stable now.  Of\ncourse, there are lots of product using zram in real practice.\n\nThe major TV companys have used zram as swap since two years ago and\nrecently our production team released android smart phone with zram\nwhich is used as swap, too and recently Android Kitkat start to use zram\nfor small memory smart phone.  And there was a report Google released\ntheir ChromeOS with zram, too and cyanogenmod have been used zram long\ntime ago.  And I heard some disto have used zram block device for tmpfs.\nIn addition, I saw many report from many other peoples.  For example,\nLubuntu start to use it.\n\nThe benefit of zram is very clear.  With my experience, one of the\nbenefit was to remove jitter of video application with backgroud memory\npressure.  It would be effect of efficient memory usage by compression\nbut more issue is whether swap is there or not in the system.  Recent\nmobile platforms have used JAVA so there are many anonymous pages.  But\nembedded system normally are reluctant to use eMMC or SDCard as swap\nbecause there is wear-leveling and latency issues so if we do not use\nswap, it means we can't reclaim anoymous pages and at last, we could\nencounter OOM kill.  :(\n\nAlthough we have real storage as swap, it was a problem, too.  Because\nit sometime ends up making system very unresponsible caused by slow swap\nstorage performance.\n\nQuote from Luigi on Google\n \"Since Chrome OS was mentioned: the main reason why we don't use swap\n  to a disk (rotating or SSD) is because it doesn't degrade gracefully\n  and leads to a bad interactive experience.  Generally we prefer to\n  manage RAM at a higher level, by transparently killing and restarting\n  processes.  But we noticed that zram is fast enough to be competitive\n  with the latter, and it lets us make more efficient use of the\n  available RAM.  \" and he announced.\nhttp://www.spinics.net/lists/linux-mm/msg57717.html\n\nOther uses case is to use zram for block device.  Zram is block device\nso anyone can format the block device and mount on it so some guys on\nthe internet start zram as /var/tmp.\nhttp://forums.gentoo.org/viewtopic-t-838198-start-0.html\n\nLet's promote zram and enhance/maintain it instead of removing.\n\nSigned-off-by: Minchan Kim <minchan@kernel.org>\nReviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>\nAcked-by: Nitin Gupta <ngupta@vflare.org>\nAcked-by: Pekka Enberg <penberg@kernel.org>\nCc: Bob Liu <bob.liu@oracle.com>\nCc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>\nCc: Hugh Dickins <hughd@google.com>\nCc: Jens Axboe <axboe@kernel.dk>\nCc: Luigi Semenzato <semenzato@google.com>\nCc: Mel Gorman <mgorman@suse.de>\nCc: Rik van Riel <riel@redhat.com>\nCc: Seth Jennings <sjenning@linux.vnet.ibm.com>\nSigned-off-by: Andrew Morton <akpm@linux-foundation.org>\nSigned-off-by: Linus Torvalds <torvalds@linux-foundation.org>\n(cherry picked from commit cd67e10ac6997c6d1e1504e3c111b693bfdbc148)\n\nChange-Id: Ic5311ef825799d48c52fe9ea9e96b8277e7001fb\n\nzram: remove old private project comment\n\nRemove the old private compcache project address so upcoming patches\nshould be sent to LKML because we Linux kernel community will take care.\n\nSigned-off-by: Minchan Kim <minchan@kernel.org>\nCc: Nitin Gupta <ngupta@vflare.org>\nSigned-off-by: Andrew Morton <akpm@linux-foundation.org>\nSigned-off-by: Linus Torvalds <torvalds@linux-foundation.org>\n(cherry picked from commit 49061236a9c2e18b31617cef10d27ba136068bac)\n\nzram: add copyright\n\nAdd my copyright to the zram source code which I maintain.\n\nSigned-off-by: Minchan Kim <minchan@kernel.org>\nCc: Nitin Gupta <ngupta@vflare.org>\nSigned-off-by: Andrew Morton <akpm@linux-foundation.org>\nSigned-off-by: Linus Torvalds <torvalds@linux-foundation.org>\n(cherry picked from commit 7bfb3de8a1b3bebc2dc68d381efe27448c0584c5)\n\nzram: fix race between reset and flushing pending work\n\nDan and Sergey reported that there is a racy between reset and flushing\nof pending work so that it could make oops by freeing zram->meta in\nreset while zram_slot_free can access zram->meta if new request is\nadding during the race window.\n\nThis patch moves flush after taking init_lock so it prevents new request\nso that it closes the race.\n\nSigned-off-by: Minchan Kim <minchan@kernel.org>\nReported-by: Dan Carpenter <dan.carpenter@oracle.com>\nCc: Nitin Gupta <ngupta@vflare.org>\nCc: Jerome Marchand <jmarchan@redhat.com>\nTested-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>\nCc: <stable@vger.kernel.org>\nSigned-off-by: Andrew Morton <akpm@linux-foundation.org>\nSigned-off-by: Linus Torvalds <torvalds@linux-foundation.org>\n(cherry picked from commit da4a04126baa3be03bc566d4a2ee0944c5e783d0)\n\nzram: delay pending free request in read path\n\nSergey reported we don't need to handle pending free request every I/O\nso that this patch removes it in read path while we remain it in write\npath.\n\nLet's consider below example.\n\nSwap subsystem ask to zram \"A\" block free by swap_slot_free_notify but\nzram had been pended it without real freeing.  Swap subsystem allocates\n\"A\" block for new data but request pended for a long time just handled\nand zram blindly free new data on the \"A\" block.  :(\n\nThat's why we couldn't remove handle pending free request right before\nzram-write.\n\nSigned-off-by: Minchan Kim <minchan@kernel.org>\nReported-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>\nTested-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>\nCc: Nitin Gupta <ngupta@vflare.org>\nCc: Jerome Marchand <jmarchan@redhat.com>\nSigned-off-by: Andrew Morton <akpm@linux-foundation.org>\nSigned-off-by: Linus Torvalds <torvalds@linux-foundation.org>\n(cherry picked from commit 9b353db16d18f87242337e3e61a948c023505a65)\n\nzram: remove unnecessary free\n\nCommit a0c516cbfc74 (\"zram: don't grab mutex in zram_slot_free_noity\")\nintroduced pending zram slot free in zram's write path in case of\nmissing slot free by memory allocation failure in zram_slot_free_notify\nbut it is not necessary because we have already freed the slot right\nbefore overwriting.\n\nSigned-off-by: Minchan Kim <minchan@kernel.org>\nCc: Nitin Gupta <ngupta@vflare.org>\nCc: Jerome Marchand <jmarchan@redhat.com>\nTested-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>\nSigned-off-by: Andrew Morton <akpm@linux-foundation.org>\nSigned-off-by: Linus Torvalds <torvalds@linux-foundation.org>\n(cherry picked from commit 874e3cddc33f0c0f9cc08ad2b73fa0cbe7dfaa63)\n\nzram: use atomic operation for stat\n\nSome of fields in zram->stats are protected by zram->lock which is\nrather coarse-grained so let's use atomic operation without explict\nlocking.\n\nThis patch is ready for removing dependency of zram->lock in read path\nwhich is very coarse-grained rw_semaphore.  Of course, this patch adds\nnew atomic operation so it might make slow but my 12CPU test couldn't\nspot any regression.  All gain/lose is marginal within stddev.\n\n  iozone -t -T -l 12 -u 12 -r 16K -s 60M -I +Z -V 0\n\n  ==Initial write                ==Initial write\n  records: 50                    records: 50\n  avg:  412875.17                avg:  415638.23\n  std:   38543.12 (9.34%)        std:   36601.11 (8.81%)\n  max:  521262.03                max:  502976.72\n  min:  343263.13                min:  351389.12\n  ==Rewrite                      ==Rewrite\n  records: 50                    records: 50\n  avg:  416640.34                avg:  397914.33\n  std:   60798.92 (14.59%)       std:   46150.42 (11.60%)\n  max:  543057.07                max:  522669.17\n  min:  304071.67                min:  316588.77\n  ==Read                         ==Read\n  records: 50                    records: 50\n  avg: 4147338.63                avg: 4070736.51\n  std:  179333.25 (4.32%)        std:  223499.89 (5.49%)\n  max: 4459295.28                max: 4539514.44\n  min: 3753057.53                min: 3444686.31\n  ==Re-read                      ==Re-read\n  records: 50                    records: 50\n  avg: 4096706.71                avg: 4117218.57\n  std:  229735.04 (5.61%)        std:  171676.25 (4.17%)\n  max: 4430012.09                max: 4459263.94\n  min: 2987217.80                min: 3666904.28\n  ==Reverse Read                 ==Reverse Read\n  records: 50                    records: 50\n  avg: 4062763.83                avg: 4078508.32\n  std:  186208.46 (4.58%)        std:  172684.34 (4.23%)\n  max: 4401358.78                max: 4424757.22\n  min: 3381625.00                min: 3679359.94\n  ==Stride read                  ==Stride read\n  records: 50                    records: 50\n  avg: 4094933.49                avg: 4082170.22\n  std:  185710.52 (4.54%)        std:  196346.68 (4.81%)\n  max: 4478241.25                max: 4460060.97\n  min: 3732593.23                min: 3584125.78\n  ==Random read                  ==Random read\n  records: 50                    records: 50\n  avg: 4031070.04                avg: 4074847.49\n  std:  192065.51 (4.76%)        std:  206911.33 (5.08%)\n  max: 4356931.16                max: 4399442.56\n  min: 3481619.62                min: 3548372.44\n  ==Mixed workload               ==Mixed workload\n  records: 50                    records: 50\n  avg:  149925.73                avg:  149675.54\n  std:    7701.26 (5.14%)        std:    6902.09 (4.61%)\n  max:  191301.56                max:  175162.05\n  min:  133566.28                min:  137762.87\n  ==Random write                 ==Random write\n  records: 50                    records: 50\n  avg:  404050.11                avg:  393021.47\n  std:   58887.57 (14.57%)       std:   42813.70 (10.89%)\n  max:  601798.09                max:  524533.43\n  min:  325176.99                min:  313255.34\n  ==Pwrite                       ==Pwrite\n  records: 50                    records: 50\n  avg:  411217.70                avg:  411237.96\n  std:   43114.99 (10.48%)       std:   33136.29 (8.06%)\n  max:  530766.79                max:  471899.76\n  min:  320786.84                min:  317906.94\n  ==Pread                        ==Pread\n  records: 50                    records: 50\n  avg: 4154908.65                avg: 4087121.92\n  std:  151272.08 (3.64%)        std:  219505.04 (5.37%)\n  max: 4459478.12                max: 4435857.38\n  min: 3730512.41                min: 3101101.67\n\nSigned-off-by: Minchan Kim <minchan@kernel.org>\nCc: Nitin Gupta <ngupta@vflare.org>\nTested-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>\nCc: Jerome Marchand <jmarchan@redhat.com>\nSigned-off-by: Andrew Morton <akpm@linux-foundation.org>\nSigned-off-by: Linus Torvalds <torvalds@linux-foundation.org>\n(cherry picked from commit deb0bdeb2f3d6b81d37fc778316dae46b6daab56)\n\nzram: introduce zram->tb_lock\n\nCurrently, the zram table is protected by zram->lock but it's rather\ncoarse-grained lock and it makes hard for scalibility.\n\nLet's use own rwlock instead of depending on zram->lock.  This patch\nadds new locking so obviously, it would make slow but this patch is just\nprepartion for removing coarse-grained rw_semaphore(ie, zram->lock)\nwhich is hurdle about zram scalability.\n\nFinal patch in this patchset series will remove the lock from read-path\nand change rw_semaphore with mutex in write path.  With bonus, we could\ndrop pending slot free mess in next patch.\n\nSigned-off-by: Minchan Kim <minchan@kernel.org>\nCc: Nitin Gupta <ngupta@vflare.org>\nTested-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>\nCc: Jerome Marchand <jmarchan@redhat.com>\nSigned-off-by: Andrew Morton <akpm@linux-foundation.org>\nSigned-off-by: Linus Torvalds <torvalds@linux-foundation.org>\n(cherry picked from commit 92967471b67163bb1654e9b7fe99449ab70a4aaa)\n\nzram: remove workqueue for freeing removed pending slot\n\nCommit a0c516cbfc74 (\"zram: don't grab mutex in zram_slot_free_noity\")\nintroduced free request pending code to avoid scheduling by mutex under\nspinlock and it was a mess which made code lenghty and increased\noverhead.\n\nNow, we don't need zram->lock any more to free slot so this patch\nreverts it and then, tb_lock should protect it.\n\nSigned-off-by: Minchan Kim <minchan@kernel.org>\nCc: Nitin Gupta <ngupta@vflare.org>\nTested-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>\nCc: Jerome Marchand <jmarchan@redhat.com>\nSigned-off-by: Andrew Morton <akpm@linux-foundation.org>\nSigned-off-by: Linus Torvalds <torvalds@linux-foundation.org>\n(cherry picked from commit f614a9f48dedd2b80d1dc8bae8094842fcdb39dd)\n\nzram: remove zram->lock in read path and change it with mutex\n\nFinally, we separated zram->lock dependency from 32bit stat/ table\nhandling so there is no reason to use rw_semaphore between read and\nwrite path so this patch removes the lock from read path totally and\nchanges rw_semaphore with mutex.  So, we could do\n\nold:\n\n  read-read: OK\n  read-write: NO\n  write-write: NO\n\nNow:\n\n  read-read: OK\n  read-write: OK\n  write-write: NO\n\nThe below data proves mixed workload performs well 11 times and there is\nalso enhance on write-write path because current rw-semaphore doesn't\nsupport SPIN_ON_OWNER.  It's side effect but anyway good thing for us.\n\nWrite-related tests perform better (from 61% to 1058%) but read path has\ngood/bad(from -2.22% to 1.45%) but they are all marginal within stddev.\n\n  CPU 12\n  iozone -t -T -l 12 -u 12 -r 16K -s 60M -I +Z -V 0\n\n  ==Initial write                ==Initial write\n  records: 10                    records: 10\n  avg:  516189.16                avg:  839907.96\n  std:   22486.53 (4.36%)        std:   47902.17 (5.70%)\n  max:  546970.60                max:  909910.35\n  min:  481131.54                min:  751148.38\n  ==Rewrite                      ==Rewrite\n  records: 10                    records: 10\n  avg:  509527.98                avg: 1050156.37\n  std:   45799.94 (8.99%)        std:   40695.44 (3.88%)\n  max:  611574.27                max: 1111929.26\n  min:  443679.95                min:  980409.62\n  ==Read                         ==Read\n  records: 10                    records: 10\n  avg: 4408624.17                avg: 4472546.76\n  std:  281152.61 (6.38%)        std:  163662.78 (3.66%)\n  max: 4867888.66                max: 4727351.03\n  min: 4058347.69                min: 4126520.88\n  ==Re-read                      ==Re-read\n  records: 10                    records: 10\n  avg: 4462147.53                avg: 4363257.75\n  std:  283546.11 (6.35%)        std:  247292.63 (5.67%)\n  max: 4912894.44                max: 4677241.75\n  min: 4131386.50                min: 4035235.84\n  ==Reverse Read                 ==Reverse Read\n  records: 10                    records: 10\n  avg: 4565865.97                avg: 4485818.08\n  std:  313395.63 (6.86%)        std:  248470.10 (5.54%)\n  max: 5232749.16                max: 4789749.94\n  min: 4185809.62                min: 3963081.34\n  ==Stride read                  ==Stride read\n  records: 10                    records: 10\n  avg: 4515981.80                avg: 4418806.01\n  std:  211192.32 (4.68%)        std:  212837.97 (4.82%)\n  max: 4889287.28                max: 4686967.22\n  min: 4210362.00                min: 4083041.84\n  ==Random read                  ==Random read\n  records: 10                    records: 10\n  avg: 4410525.23                avg: 4387093.18\n  std:  236693.22 (5.37%)        std:  235285.23 (5.36%)\n  max: 4713698.47                max: 4669760.62\n  min: 4057163.62                min: 3952002.16\n  ==Mixed workload               ==Mixed workload\n  records: 10                    records: 10\n  avg:  243234.25                avg: 2818677.27\n  std:   28505.07 (11.72%)       std:  195569.70 (6.94%)\n  max:  288905.23                max: 3126478.11\n  min:  212473.16                min: 2484150.69\n  ==Random write                 ==Random write\n  records: 10                    records: 10\n  avg:  555887.07                avg: 1053057.79\n  std:   70841.98 (12.74%)       std:   35195.36 (3.34%)\n  max:  683188.28                max: 1096125.73\n  min:  437299.57                min:  992481.93\n  ==Pwrite                       ==Pwrite\n  records: 10                    records: 10\n  avg:  501745.93                avg:  810363.09\n  std:   16373.54 (3.26%)        std:   19245.01 (2.37%)\n  max:  518724.52                max:  833359.70\n  min:  464208.73                min:  765501.87\n  ==Pread                        ==Pread\n  records: 10                    records: 10\n  avg: 4539894.60                avg: 4457680.58\n  std:  197094.66 (4.34%)        std:  188965.60 (4.24%)\n  max: 4877170.38                max: 4689905.53\n  min: 4226326.03                min: 4095739.72\n\nSigned-off-by: Minchan Kim <minchan@kernel.org>\nCc: Nitin Gupta <ngupta@vflare.org>\nTested-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>\nCc: Jerome Marchand <jmarchan@redhat.com>\nSigned-off-by: Andrew Morton <akpm@linux-foundation.org>\nSigned-off-by: Linus Torvalds <torvalds@linux-foundation.org>\n(cherry picked from commit e46e33152eb82b8e2db7ffb3790a2a2653c34513)\n\nzram: avoid null access when fail to alloc meta\n\nzram_meta_alloc could fail so caller should check it.  Otherwise, your\nsystem will hang.\n\nSigned-off-by: Minchan Kim <minchan@kernel.org>\nAcked-by: Jerome Marchand <jmarchan@redhat.com>\nCc: <stable@vger.kernel.org>\nSigned-off-by: Andrew Morton <akpm@linux-foundation.org>\nSigned-off-by: Linus Torvalds <torvalds@linux-foundation.org>\n(cherry picked from commit db5d711e2db776f18219b033e5dc4fb7e4264dd7)\n\nzram: drop `init_done' struct zram member\n\nIntroduce init_done() helper function which allows us to drop `init_done'\nstruct zram member.  init_done() uses the fact that ->init_done == 1\nequals to ->meta != NULL.\n\nSigned-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>\nAcked-by: Minchan Kim <minchan@kernel.org>\nAcked-by: Jerome Marchand <jmarchan@redhat.com>\nCc: Nitin Gupta <ngupta@vflare.org>\nSigned-off-by: Andrew Morton <akpm@linux-foundation.org>\nSigned-off-by: Linus Torvalds <torvalds@linux-foundation.org>\n(cherry picked from commit be2d1d56c82d8cf20e6c77515eb499f8e86eb5be)\n\nzram: do not pass rw argument to __zram_make_request()\n\nDo not pass rw argument down the __zram_make_request() -> zram_bvec_rw()\nchain, decode it in zram_bvec_rw() instead.  Besides, this is the place\nwhere we distinguish READ and WRITE bio data directions, so account zram\nRW stats here, instead of __zram_make_request().  This also allows to\naccount a real number of zram READ/WRITE operations, not just requests\n(single RW request may cause a number of zram RW ops with separate\nlocking, compression/decompression, etc).\n\nSigned-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>\nAcked-by: Minchan Kim <minchan@kernel.org>\nAcked-by: Jerome Marchand <jmarchan@redhat.com>\nCc: Nitin Gupta <ngupta@vflare.org>\nSigned-off-by: Andrew Morton <akpm@linux-foundation.org>\nSigned-off-by: Linus Torvalds <torvalds@linux-foundation.org>\n(cherry picked from commit be257c61306750d11c20d2ac567bf63304c696a3)\n\nzram: remove good and bad compress stats\n\nRemove `good' and `bad' compressed sub-requests stats.  RW request may\ncause a number of RW sub-requests.  zram used to account `good' compressed\nsub-queries (with compressed size less than 50% of original size), `bad'\ncompressed sub-queries (with compressed size greater that 75% of original\nsize), leaving sub-requests with compression size between 50% and 75% of\noriginal size not accounted and not reported.  zram already accounts each\nsub-request's compression size so we can calculate real device compression\nratio.\n\nSigned-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>\nAcked-by: Minchan Kim <minchan@kernel.org>\nAcked-by: Jerome Marchand <jmarchan@redhat.com>\nCc: Nitin Gupta <ngupta@vflare.org>\nSigned-off-by: Andrew Morton <akpm@linux-foundation.org>\nSigned-off-by: Linus Torvalds <torvalds@linux-foundation.org>\n(cherry picked from commit b7cccf8b4009bf74df61f3c9d86b95fabd807c11)\n\nzram: use atomic64_t for all zram stats\n\nThis is a preparation patch for stats code duplication removal.\n\n1) use atomic64_t for `pages_zero' and `pages_stored' zram stats.\n\n2) `compr_size' and `pages_zero' struct zram_stats members did not\n   follow the existing device attr naming scheme: zram_stats.ATTR has\n   ATTR_show() function.  rename them:\n\n   -- compr_size -> compr_data_size\n   -- pages_zero -> zero_pages\n\nMinchan Kim's note:\n If we really have trouble with atomic stat operation, we could\n change it with percpu_counter so that it could solve atomic overhead and\n unnecessary memory space by introducing unsigned long instead of 64bit\n atomic_t.\n\nSigned-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>\nAcked-by: Minchan Kim <minchan@kernel.org>\nAcked-by: Jerome Marchand <jmarchan@redhat.com>\nCc: Nitin Gupta <ngupta@vflare.org>\nSigned-off-by: Andrew Morton <akpm@linux-foundation.org>\nSigned-off-by: Linus Torvalds <torvalds@linux-foundation.org>\n(cherry picked from commit 90a7806ea9b9f7cb4751859cc2506e2d80e36ef1)\n\nzram: remove zram stats code duplication\n\nIntroduce ZRAM_ATTR_RO macro that generates device_attribute and default\nATTR show() function for existing atomic64_t zram stats.\n\nSigned-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>\nAcked-by: Minchan Kim <minchan@kernel.org>\nCc: Jerome Marchand <jmarchan@redhat.com>\nCc: Nitin Gupta <ngupta@vflare.org>\nSigned-off-by: Andrew Morton <akpm@linux-foundation.org>\nSigned-off-by: Linus Torvalds <torvalds@linux-foundation.org>\n(cherry picked from commit a68eb3b65e658406d386bebef02277f4007b2f45)\n\nzram: report failed read and write stats\n\nzram accounted but did not report numbers of failed read and write\nqueries.  make these stats available as failed_reads and failed_writes\nattrs.\n\nSigned-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>\nAcked-by: Minchan Kim <minchan@kernel.org>\nAcked-by: Jerome Marchand <jmarchan@redhat.com>\nCc: Nitin Gupta <ngupta@vflare.org>\nSigned-off-by: Andrew Morton <akpm@linux-foundation.org>\nSigned-off-by: Linus Torvalds <torvalds@linux-foundation.org>\n(cherry picked from commit 6444724939db5de7390c90f7b4a657159b3b4465)\n\nzram: drop not used table `count' member\n\nstruct table `count' member is not used.\n\nSigned-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>\nCc: Minchan Kim <minchan@kernel.org>\nAcked-by: Jerome Marchand <jmarchan@redhat.com>\nCc: Nitin Gupta <ngupta@vflare.org>\nSigned-off-by: Andrew Morton <akpm@linux-foundation.org>\nSigned-off-by: Linus Torvalds <torvalds@linux-foundation.org>\n(cherry picked from commit 59fc86a4922f1a1c0f69eac758a7e2b2b138aab4)\n\nzram: move zram size warning to documentation\n\nMove zram warning about disksize and size of memory correlation to zram\ndocumentation.\n\nSigned-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>\nAcked-by: Minchan Kim <minchan@kernel.org>\nCc: Jerome Marchand <jmarchan@redhat.com>\nCc: Nitin Gupta <ngupta@vflare.org>\nSigned-off-by: Andrew Morton <akpm@linux-foundation.org>\nSigned-off-by: Linus Torvalds <torvalds@linux-foundation.org>\n(cherry picked from commit e64cd51d2fa87733176246101df871a8ac5c7c20)\n\nzram: delete zram_init_device()\n\nallocate new `zram_meta' in disksize_store() only for uninitialised zram\ndevice, saving a number of allocations and deallocations in case if\ndisksize_store() was called on currently used device.  at the same time\nzram_meta stack variable is not necessary, because we can set ->meta\ndirectly.  there is also no need in setting QUEUE_FLAG_NONROT queue on\nevery disksize_store(), set it once during device creation.\n\n[minchan@kernel.org: handle zram->meta alloc fail case]\n[minchan@kernel.org: prevent lockdep spew of init_lock]\nSigned-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>\nSigned-off-by: Minchan Kim <minchan@kernel.org>\nAcked-by: Jerome Marchand <jmarchan@redhat.com>\nCc: Sasha Levin <sasha.levin@oracle.com>\nSigned-off-by: Andrew Morton <akpm@linux-foundation.org>\nSigned-off-by: Linus Torvalds <torvalds@linux-foundation.org>\n\n(cherry picked from commit b67d1ec189ffb92cdad9b2bd29475fb1e0166983)\n\nzram: introduce compressing backend abstraction\n\nZRAM performs direct LZO compression algorithm calls, making it the one\nand only option.  While LZO is generally performs well, LZ4 algorithm\ntends to have a faster decompression (see http://code.google.com/p/lz4/\nfor full report)\n\n\tName            Ratio  C.speed D.speed\n\t                        MB/s    MB/s\n\tLZ4 (r101)      2.084    422    1820\n\tLZO 2.06        2.106    414     600\n\nThus, users who have mostly read (decompress) usage scenarious or mixed\nworkflow (writes with relatively high read ops number) will benefit from\nusing LZ4 compression backend.\n\nIntroduce compressing backend abstraction zcomp in order to support\nmultiple compression algorithms with the following set of operations:\n\n        .create\n        .destroy\n        .compress\n        .decompress\n\nSchematically zram write() usually contains the following steps:\n0) preparation (decompression of partioal IO, etc.)\n1) lock buffer_lock mutex (protects meta compress buffers)\n2) compress (using meta compress buffers)\n3) alloc and map zs_pool object\n4) copy compressed data (from meta compress buffers) to object allocated by 3)\n5) free previous pool page, assign a new one\n6) unlock buffer_lock mutex\n\nAs we can see, compressing buffers must remain untouched from 1) to 4),\nbecause, otherwise, concurrent write() can overwrite data.  At the same\ntime, zram_meta must be aware of a) specific compression algorithm memory\nrequirements and b) necessary locking to protect compression buffers.  To\nremove requirement a) new struct zcomp_strm introduced, which contains a\ncompress/decompress `buffer' and compression algorithm `private' part.\nWhile struct zcomp implements zcomp_strm stream handling and locking and\nremoves requirement b) from zram meta.  zcomp ->create() and ->destroy(),\nrespectively, allocate and deallocate algorithm specific zcomp_strm\n`private' part.\n\nEvery zcomp has zcomp stream and mutex to protect its compression stream.\nStream usage semantics remains the same -- only one write can hold stream\nlock and use its buffers.  zcomp_strm_find() turns caller into exclusive\nuser of a stream (holding stream mutex until zram release stream), and\nzcomp_strm_release() makes zcomp stream available (unlock the stream\nmutex).  Hence no concurrent write (compression) operations possible at\nthe moment.\n\niozone -t 3 -R -r 16K -s 60M -I +Z\n\n       test            base           patched\n--------------------------------------------------\n  Initial write      597992.91       591660.58\n        Rewrite      609674.34       616054.97\n           Read     2404771.75      2452909.12\n        Re-read     2459216.81      2470074.44\n   Reverse Read     1652769.66      1589128.66\n    Stride read     2202441.81      2202173.31\n    Random read     2236311.47      2276565.31\n Mixed workload     1423760.41      1709760.06\n   Random write      579584.08       615933.86\n         Pwrite      597550.02       594933.70\n          Pread     1703672.53      1718126.72\n         Fwrite     1330497.06      1461054.00\n          Fread     3922851.00      3957242.62\n\nUsage examples:\n\n\tcomp = zcomp_create(NAME) /* NAME e.g. \"lzo\" */\n\nwhich initialises compressing backend if requested algorithm is supported.\n\nCompress:\n\tzstrm = zcomp_strm_find(comp)\n\tzcomp_compress(comp, zstrm, src, &dst_len)\n\t[..] /* copy compressed data */\n\tzcomp_strm_release(comp, zstrm)\n\nDecompress:\n\tzcomp_decompress(comp, src, src_len, dst);\n\nFree compessing backend and its zcomp stream:\n\tzcomp_destroy(comp)\n\nSigned-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>\nAcked-by: Minchan Kim <minchan@kernel.org>\nCc: Jerome Marchand <jmarchan@redhat.com>\nCc: Nitin Gupta <ngupta@vflare.org>\nSigned-off-by: Andrew Morton <akpm@linux-foundation.org>\nSigned-off-by: Linus Torvalds <torvalds@linux-foundation.org>\n(cherry picked from commit e7e1ef439d18f9a21521116ea9f2b976d7230e54)\n\nzram: use zcomp compressing backends\n\nDo not perform direct LZO compress/decompress calls, initialise\nand use zcomp LZO backend (single compression stream) instead.\n\n[akpm@linux-foundation.org: resolve conflicts with zram-delete-zram_init_device-fix.patch]\nSigned-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>\nAcked-by: Minchan Kim <minchan@kernel.org>\nCc: Jerome Marchand <jmarchan@redhat.com>\nCc: Nitin Gupta <ngupta@vflare.org>\nSigned-off-by: Andrew Morton <akpm@linux-foundation.org>\nSigned-off-by: Linus Torvalds <torvalds@linux-foundation.org>\n\n(cherry picked from commit b7ca232ee7e85ed3b18e39eb20a7f458ee1d6047)\n\nzram: factor out single stream compression\n\nThis is preparation patch to add multi stream support to zcomp.\n\nIntroduce struct zcomp_strm_single and a set of functions to manage\nzcomp_strm stream access.  zcomp_strm_single implements single compession\nstream, same way as current zcomp implementation.  This moves zcomp_strm\nstream control and locking from zcomp, so compressing backend zcomp is not\naware of required locking.\n\nSingle and multi streams require different locking schemes.  Minchan Kim\nreported that spinlock-based locking scheme (which is used in multi stream\nimplementation) has demonstrated a severe perfomance regression for single\ncompression stream case, comparing to mutex-based.  see\nhttps://lkml.org/lkml/2014/2/18/16\n\nThe following set of functions added:\n- zcomp_strm_single_find()/zcomp_strm_single_release()\n  find and release a compression stream, implement required locking\n- zcomp_strm_single_create()/zcomp_strm_single_destroy()\n  create and destroy zcomp_strm_single\n\nNew ->strm_find() and ->strm_release() callbacks added to zcomp, which are\nset to zcomp_strm_single_find() and zcomp_strm_single_release() during\ninitialisation.  Instead of direct locking and zcomp_strm access from\nzcomp_strm_find() and zcomp_strm_release(), zcomp now calls ->strm_find()\nand ->strm_release() correspondingly.\n\nSigned-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>\nAcked-by: Minchan Kim <minchan@kernel.org>\nCc: Jerome Marchand <jmarchan@redhat.com>\nCc: Nitin Gupta <ngupta@vflare.org>\nSigned-off-by: Andrew Morton <akpm@linux-foundation.org>\nSigned-off-by: Linus Torvalds <torvalds@linux-foundation.org>\n(cherry picked from commit 9cc97529a180b369fcb7e5265771b6ba7e01f05b)\n\nzram: document failed_reads, failed_writes stats\n\nDocument `failed_reads' and `failed_writes' device attributes.\nRemove info about `discard' - there is no such zram attr.\n\nSigned-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>\nCc: Minchan Kim <minchan@kernel.org>\nCc: Jerome Marchand <jmarchan@redhat.com>\nCc: Nitin Gupta <ngupta@vflare.org>\nSigned-off-by: Andrew Morton <akpm@linux-foundation.org>\nSigned-off-by: Linus Torvalds <torvalds@linux-foundation.org>\n(cherry picked from commit 8dd1d3247e6c00b50ef83934ea8b22a1590015de)\n\nzram: add multi stream functionality\n\nExisting zram (zcomp) implementation has only one compression stream\n(buffer and algorithm private part), so in order to prevent data\ncorruption only one write (compress operation) can use this compression\nstream, forcing all concurrent write operations to wait for stream lock\nto be released.  This patch changes zcomp to keep a compression streams\nlist of user-defined size (via sysfs device attr).  Each write operation\nstill exclusively holds compression stream, the difference is that we\ncan have N write operations (depending on size of streams list)\nexecuting in parallel.  See TEST section later in commit message for\nperformance data.\n\nIntroduce struct zcomp_strm_multi and a set of functions to manage\nzcomp_strm stream access.  zcomp_strm_multi has a list of idle\nzcomp_strm structs, spinlock to protect idle list and wait queue, making\nit possible to perform parallel compressions.\n\nThe following set of functions added:\n- zcomp_strm_multi_find()/zcomp_strm_multi_release()\n  find and release a compression stream, implement required locking\n- zcomp_strm_multi_create()/zcomp_strm_multi_destroy()\n  create and destroy zcomp_strm_multi\n\nzcomp ->strm_find() and ->strm_release() callbacks are set during\ninitialisation to zcomp_strm_multi_find()/zcomp_strm_multi_release()\ncorrespondingly.\n\nEach time zcomp issues a zcomp_strm_multi_find() call, the following set\nof operations performed:\n\n- spin lock strm_lock\n- if idle list is not empty, remove zcomp_strm from idle list, spin\n  unlock and return zcomp stream pointer to caller\n- if idle list is empty, current adds itself to wait queue. it will be\n  awaken by zcomp_strm_multi_release() caller.\n\nzcomp_strm_multi_release():\n- spin lock strm_lock\n- add zcomp stream to idle list\n- spin unlock, wake up sleeper\n\nMinchan Kim reported that spinlock-based locking scheme has demonstrated\na severe perfomance regression for single compression stream case,\ncomparing to mutex-based (see https://lkml.org/lkml/2014/2/18/16)\n\nbase                      spinlock                    mutex\n\n==Initial write           ==Initial write             ==Initial  write\nrecords:  5               records:  5                 records:   5\navg:      1642424.35      avg:      699610.40         avg:       1655583.71\nstd:      39890.95(2.43%) std:      232014.19(33.16%) std:       52293.96\nmax:      1690170.94      max:      1163473.45        max:       1697164.75\nmin:      1568669.52      min:      573429.88         min:       1553410.23\n==Rewrite                 ==Rewrite                   ==Rewrite\nrecords:  5               records:  5                 records:   5\navg:      1611775.39      avg:      501406.64         avg:       1684419.11\nstd:      17144.58(1.06%) std:      15354.41(3.06%)   std:       18367.42\nmax:      1641800.95      max:      531356.78         max:       1706445.84\nmin:      1593515.27      min:      488817.78         min:       1655335.73\n\nWhen only one compression stream available, mutex with spin on owner\ntends to perform much better than frequent wait_event()/wake_up().  This\nis why single stream implemented as a special case with mutex locking.\n\nIntroduce and document zram device attribute max_comp_streams.  This\nattr shows and stores current zcomp's max number of zcomp streams\n(max_strm).  Extend zcomp's zcomp_create() with `max_strm' parameter.\n`max_strm' limits the number of zcomp_strm structs in compression\nbackend's idle list (max_comp_streams).\n\nmax_comp_streams used during initialisation as follows:\n-- passing to zcomp_create() max_strm equals to 1 will initialise zcomp\nusing single compression stream zcomp_strm_single (mutex-based locking).\n-- passing to zcomp_create() max_strm greater than 1 will initialise zcomp\nusing multi compression stream zcomp_strm_multi (spinlock-based locking).\n\ndefault max_comp_streams value is 1, meaning that zram with single stream\nwill be initialised.\n\nLater patch will introduce configuration knob to change max_comp_streams\non already initialised and used zcomp.\n\nTEST\niozone -t 3 -R -r 16K -s 60M -I +Z\n\n       test           base       1 strm (mutex)     3 strm (spinlock)\n-----------------------------------------------------------------------\n Initial write      589286.78       583518.39          718011.05\n       Rewrite      604837.97       596776.38         1515125.72\n  Random write      584120.11       595714.58         1388850.25\n        Pwrite      535731.17       541117.38          739295.27\n        Fwrite     1418083.88      1478612.72         1484927.06\n\nUsage example:\nset max_comp_streams to 4\n        echo 4 > /sys/block/zram0/max_comp_streams\n\nshow current max_comp_streams (default value is 1).\n        cat /sys/block/zram0/max_comp_streams\n\nSigned-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>\nAcked-by: Minchan Kim <minchan@kernel.org>\nCc: Jerome Marchand <jmarchan@redhat.com>\nCc: Nitin Gupta <ngupta@vflare.org>\nSigned-off-by: Andrew Morton <akpm@linux-foundation.org>\nSigned-off-by: Linus Torvalds <torvalds@linux-foundation.org>\n(cherry picked from commit beca3ec71fe5490ee9237dc42400f50402baf83e)\n\nzram: add set_max_streams knob\n\nThis patch allows to change max_comp_streams on initialised zcomp.\n\nIntroduce zcomp set_max_streams() knob, zcomp_strm_multi_set_max_streams()\nand zcomp_strm_single_set_max_streams() callbacks to change streams limit\nfor zcomp_strm_multi and zcomp_strm_single, accordingly.  set_max_streams\nfor single steam zcomp does nothing.\n\nIf user has lowered the limit, then zcomp_strm_multi_set_max_streams()\nattempts to immediately free extra streams (as much as it can, depending\non idle streams availability).\n\nNote, this patch does not allow to change stream 'policy' from single to\nmulti stream (or vice versa) on already initialised compression backend.\n\nSigned-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>\nAcked-by: Minchan Kim <minchan@kernel.org>\nCc: Jerome Marchand <jmarchan@redhat.com>\nCc: Nitin Gupta <ngupta@vflare.org>\nSigned-off-by: Andrew Morton <akpm@linux-foundation.org>\nSigned-off-by: Linus Torvalds <torvalds@linux-foundation.org>\n(cherry picked from commit fe8eb122c82b2049c460fc6df6e8583a2f935cff)\n\nzram: make compression algorithm selection possible\n\nAdd and document `comp_algorithm' device attribute.  This attribute allows\nto show supported compression and currently selected compression\nalgorithms:\n\n\tcat /sys/block/zram0/comp_algorithm\n\t[lzo] lz4\n\nand change selected compression algorithm:\n\techo lzo > /sys/block/zram0/comp_algorithm\n\nSigned-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>\nAcked-by: Minchan Kim <minchan@kernel.org>\nCc: Jerome Marchand <jmarchan@redhat.com>\nCc: Nitin Gupta <ngupta@vflare.org>\nSigned-off-by: Andrew Morton <akpm@linux-foundation.org>\nSigned-off-by: Linus Torvalds <torvalds@linux-foundation.org>\n(cherry picked from commit e46b8a030d76d3c94156c545c3f4c3676d813435)\n\nzram: add lz4 algorithm backend\n\nIntroduce LZ4 compression backend and make it available for selection.\nLZ4 support is optional and requires user to set ZRAM_LZ4_COMPRESS config\noption.  The default compression backend is LZO.\n\nTEST\n\n(x86_64, core i5, 2 cores + 2 hyperthreading, zram disk size 1G,\next4 file system, 3 compression streams)\n\niozone -t 3 -R -r 16K -s 60M -I +Z\n\n       Test           LZO           LZ4\n----------------------------------------------\n  Initial write   1642744.62    1317005.09\n        Rewrite   2498980.88    1800645.16\n           Read   3957026.38    5877043.75\n        Re-read   3950997.38    5861847.00\n   Reverse Read   2937114.56    5047384.00\n    Stride read   2948163.19    4929587.38\n    Random read   3292692.69    4880793.62\n Mixed workload   1545602.62    3502940.38\n   Random write   2448039.75    1758786.25\n         Pwrite   1670051.03    1338329.69\n          Pread   2530682.00    5097177.62\n         Fwrite   3232085.62    3275942.56\n          Fread   6306880.25    6645271.12\n\nSo on my system LZ4 is slower in write-only tests, while it performs\nbetter in read-only and mixed (reads + writes) tests.\n\nOfficial LZ4 benchmarks available here http://code.google.com/p/lz4/\n(linux kernel uses revision r90).\n\nSigned-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>\nAcked-by: Minchan Kim <minchan@kernel.org>\nCc: Jerome Marchand <jmarchan@redhat.com>\nCc: Nitin Gupta <ngupta@vflare.org>\nSigned-off-by: Andrew Morton <akpm@linux-foundation.org>\nSigned-off-by: Linus Torvalds <torvalds@linux-foundation.org>\n(cherry picked from commit 6e76668e415adf799839f0ab205142ad7002d260)\n\nzram: move comp allocation out of init_lock\n\nWhile fixing lockdep spew of ->init_lock reported by Sasha Levin [1],\nMinchan Kim noted [2] that it's better to move compression backend\nallocation (using GPF_KERNEL) out of the ->init_lock lock, same way as\nwith zram_meta_alloc(), in order to prevent the same lockdep spew.\n\n[1] https://lkml.org/lkml/2014/2/27/337\n[2] https://lkml.org/lkml/2014/3/3/32\n\nSigned-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>\nReported-by: Minchan Kim <minchan@kernel.org>\nAcked-by: Minchan Kim <minchan@kernel.org>\nCc: Sasha Levin <sasha.levin@oracle.com>\nAcked-by: Jerome Marchand <jmarchan@redhat.com>\nSigned-off-by: Andrew Morton <akpm@linux-foundation.org>\nSigned-off-by: Linus Torvalds <torvalds@linux-foundation.org>\n(cherry picked from commit d61f98c70e8b0d324e8e83be2ed546d6295e63f3)\n\nzram: return error-valued pointer from zcomp_create()\n\nInstead of returning just NULL, return ERR_PTR from zcomp_create() if\ncompressing backend creation has failed.  ERR_PTR(-EINVAL) for unsupported\ncompression algorithm request, ERR_PTR(-ENOMEM) for allocation (zcomp or\ncompression stream) error.\n\nPerform IS_ERR() check of returned from zcomp_create() value in\ndisksize_store() and set return code to PTR_ERR().\n\nChange suggested by Jerome Marchand.\n\n[akpm@linux-foundation.org: clean up error recovery flow]\nSigned-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>\nReported-by: Jerome Marchand <jmarchan@redhat.com>\nCc: Minchan Kim <minchan@kernel.org>\nCc: Nitin Gupta <ngupta@vflare.org>\nCc: Arnd Bergmann <arnd@arndb.de>\nSigned-off-by: Andrew Morton <akpm@linux-foundation.org>\nSigned-off-by: Linus Torvalds <torvalds@linux-foundation.org>\n\n(cherry picked from commit fcfa8d95cacf5cbbe6dee6b8d229fe86142266e0)\n\nzram: propagate error to user\n\nWhen we initialized zcomp with single, we couldn't change\nmax_comp_streams without zram reset but current interface doesn't show\nany error to user and even it changes max_comp_streams's value without\nany effect so it would make user very confusing.\n\nThis patch prevents max_comp_streams's change when zcomp was initialized\nas single zcomp and emit the error to user(ex, echo).\n\n[akpm@linux-foundation.org: don't return with the lock held, per Sergey]\n[fengguang.wu@intel.com: fix coccinelle warnings]\nSigned-off-by: Minchan Kim <minchan@kernel.org>\nCc: Nitin Gupta <ngupta@vflare.org>\nCc: Jerome Marchand <jmarchan@redhat.com>\nAcked-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>\nSigned-off-by: Fengguang Wu <fengguang.wu@intel.com>\nCc: Stephen Rothwell <sfr@canb.auug.org.au>\nSigned-off-by: Andrew Morton <akpm@linux-foundation.org>\nSigned-off-by: Linus Torvalds <torvalds@linux-foundation.org>\n\n(cherry picked from commit 60a726e33375a1096e85399cfa1327081b4c38be)\n\nzram: use scnprintf() in attrs show() methods\n\nsysfs.txt documentation lists the following requirements:\n\n - The buffer will always be PAGE_SIZE bytes in length. On i386, this\n   is 4096.\n\n - show() methods should return the number of bytes printed into the\n   buffer. This is the return value of scnprintf().\n\n - show() should always use scnprintf().\n\nUse scnprintf() in show() functions.\n\nSigned-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>\nAcked-by: Minchan Kim <minchan@kernel.org>\nCc: Jerome Marchand <jmarchan@redhat.com>\nCc: Nitin Gupta <ngupta@vflare.org>\nSigned-off-by: Andrew Morton <akpm@linux-foundation.org>\nSigned-off-by: Linus Torvalds <torvalds@linux-foundation.org>\n(cherry picked from commit 56b4e8cb85827a2ccc4752a2a7148e56b62b7e96)\n\nzram: support REQ_DISCARD\n\nzram is ram based block device and can be used by backend of filesystem.\nWhen filesystem deletes a file, it normally doesn't do anything on data\nblock of that file.  It just marks on metadata of that file.  This\nbehavior has no problem on disk based block device, but has problems on\nram based block device, since we can't free memory used for data block.\nTo overcome this disadvantage, there is REQ_DISCARD functionality.  If\nblock device support REQ_DISCARD and filesystem is mounted with discard\noption, filesystem sends REQ_DISCARD to block device whenever some data\nblocks are discarded.  All we have to do is to handle this request.\n\nThis patch implements to flag up QUEUE_FLAG_DISCARD and handle this\nREQ_DISCARD request.  With it, we can free memory used by zram if it isn't\nused.\n\n[akpm@linux-foundation.org: tweak comments]\nSigned-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>\nCc: Minchan Kim <minchan@kernel.org>\nCc: Nitin Gupta <ngupta@vflare.org>\nCc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>\nCc: Jerome Marchand <jmarchan@redhat.com>\nSigned-off-by: Andrew Morton <akpm@linux-foundation.org>\nSigned-off-by: Linus Torvalds <torvalds@linux-foundation.org>\n\n(cherry picked from commit f4659d8e620d08bd1a84a8aec5d2f5294a242764)","distinct":true,"url":"https://api.github.com/repos/benschhold/android_kernel_oneplus_msm8994_custom/commits/19787d384ff27d40a4f5e558dd343f77605bb387"},{"sha":"96eb9ca49bc72a7403b091b7a9ff9d4367760b98","author":{"email":"fc967dd1b0265d0311b05dbb56de7d3bd8ed4e2b@google.com","name":"Tim Murray"},"message":"zram: remove bvec_iters from zram.\n\nWe're still on 3.10, so we can't use bvec_iters.\n\nChange-Id: Ib4c102ead45c49cb0e1bafa6e79228bd1cd750f4","distinct":true,"url":"https://api.github.com/repos/benschhold/android_kernel_oneplus_msm8994_custom/commits/96eb9ca49bc72a7403b091b7a9ff9d4367760b98"},{"sha":"6f8c86171cb2a92f2ae1806add70c1101d3e61b5","author":{"email":"51b0aed1a48556115b152d4619664105ddea9243@lge.com","name":"Kyungsik Lee"},"message":"lz4: add lz4 module.\n\nlz4 is significantly faster than lzo, which makes it ideal for zram.\n\ndecompressor: add LZ4 decompressor module\n\nAdd support for LZ4 decompression in the Linux Kernel.  LZ4 Decompression\nAPIs for kernel are based on LZ4 implementation by Yann Collet.\n\nBenchmark Results(PATCH v3)\nCompiler: Linaro ARM gcc 4.6.2\n\n1. ARMv7, 1.5GHz based board\n   Kernel: linux 3.4\n   Uncompressed Kernel Size: 14MB\n        Compressed Size  Decompression Speed\n   LZO  6.7MB            20.1MB/s, 25.2MB/s(UA)\n   LZ4  7.3MB            29.1MB/s, 45.6MB/s(UA)\n\n2. ARMv7, 1.7GHz based board\n   Kernel: linux 3.7\n   Uncompressed Kernel Size: 14MB\n        Compressed Size  Decompression Speed\n   LZO  6.0MB            34.1MB/s, 52.2MB/s(UA)\n   LZ4  6.5MB            86.7MB/s\n- UA: Unaligned memory Access support\n- Latest patch set for LZO applied\n\nThis patch set is for adding support for LZ4-compressed Kernel.  LZ4 is a\nvery fast lossless compression algorithm and it also features an extremely\nfast decoder [1].\n\nBut we have five of decompressors already and one question which does\narise, however, is that of where do we stop adding new ones?  This issue\nhad been discussed and came to the conclusion [2].\n\nRussell King said that we should have:\n\n - one decompressor which is the fastest\n - one decompressor for the highest compression ratio\n - one popular decompressor (eg conventional gzip)\n\nIf we have a replacement one for one of these, then it should do exactly\nthat: replace it.\n\nThe benchmark shows that an 8% increase in image size vs a 66% increase\nin decompression speed compared to LZO(which has been known as the\nfastest decompressor in the Kernel).  Therefore the \"fast but may not be\nsmall\" compression title has clearly been taken by LZ4 [3].\n\n[1] http://code.google.com/p/lz4/\n[2] http://thread.gmane.org/gmane.linux.kbuild.devel/9157\n[3] http://thread.gmane.org/gmane.linux.kbuild.devel/9347\n\nLZ4 homepage: http://fastcompression.blogspot.com/p/lz4.html\nLZ4 source repository: http://code.google.com/p/lz4/\n\nSigned-off-by: Kyungsik Lee <kyungsik.lee@lge.com>\nSigned-off-by: Yann Collet <yann.collet.73@gmail.com>\nCc: \"H. Peter Anvin\" <hpa@zytor.com>\nCc: Ingo Molnar <mingo@elte.hu>\nCc: Thomas Gleixner <tglx@linutronix.de>\nCc: Russell King <rmk@arm.linux.org.uk>\nCc: Borislav Petkov <bp@alien8.de>\nCc: Florian Fainelli <florian@openwrt.org>\nSigned-off-by: Andrew Morton <akpm@linux-foundation.org>\nSigned-off-by: Linus Torvalds <torvalds@linux-foundation.org>\n(cherry picked from commit cffb78b0e0b3a30b059b27a1d97500cf6464efa9)\n\nChange-Id: I75ab38092ec016a22d0e5f09fcd60ce83a24c947\n\nlib: add lz4 compressor module\n\nThis patchset is for supporting LZ4 compression and the crypto API using\nit.\n\nAs shown below, the size of data is a little bit bigger but compressing\nspeed is faster under the enabled unaligned memory access.  We can use\nlz4 de/compression through crypto API as well.  Also, It will be useful\nfor another potential user of lz4 compression.\n\nlz4 Compression Benchmark:\nCompiler: ARM gcc 4.6.4\nARMv7, 1 GHz based board\n   Kernel: linux 3.4\n   Uncompressed data Size: 101 MB\n         Compressed Size  compression Speed\n   LZO   72.1MB\t\t  32.1MB/s, 33.0MB/s(UA)\n   LZ4   75.1MB\t\t  30.4MB/s, 35.9MB/s(UA)\n   LZ4HC 59.8MB\t\t   2.4MB/s,  2.5MB/s(UA)\n- UA: Unaligned memory Access support\n- Latest patch set for LZO applied\n\nThis patch:\n\nAdd support for LZ4 compression in the Linux Kernel.  LZ4 Compression APIs\nfor kernel are based on LZ4 implementation by Yann Collet and were changed\nfor kernel coding style.\n\nLZ4 homepage : http://fastcompression.blogspot.com/p/lz4.html\nLZ4 source repository : http://code.google.com/p/lz4/\nsvn revision : r90\n\nTwo APIs are added:\n\nlz4_compress() support basic lz4 compression whereas lz4hc_compress()\nsupport high compression or CPU performance get lower but compression\nratio get higher.  Also, we require the pre-allocated working memory with\nthe defined size and destination buffer must be allocated with the size of\nlz4_compressbound.\n\n[akpm@linux-foundation.org: make lz4_compresshcctx() static]\nSigned-off-by: Chanho Min <chanho.min@lge.com>\nCc: \"Darrick J. Wong\" <djwong@us.ibm.com>\nCc: Bob Pearson <rpearson@systemfabricworks.com>\nCc: Richard Weinberger <richard@nod.at>\nCc: Herbert Xu <herbert@gondor.hengli.com.au>\nCc: Yann Collet <yann.collet.73@gmail.com>\nCc: Kyungsik Lee <kyungsik.lee@lge.com>\nSigned-off-by: Andrew Morton <akpm@linux-foundation.org>\nSigned-off-by: Linus Torvalds <torvalds@linux-foundation.org>\n\n(cherry picked from commit c72ac7a1a926dbffb59daf0f275450e5eecce16f)\n\nlib: add support for LZ4-compressed kernel\n\nAdd support for extracting LZ4-compressed kernel images, as well as\nLZ4-compressed ramdisk images in the kernel boot process.\n\nSigned-off-by: Kyungsik Lee <kyungsik.lee@lge.com>\nCc: \"H. Peter Anvin\" <hpa@zytor.com>\nCc: Ingo Molnar <mingo@elte.hu>\nCc: Thomas Gleixner <tglx@linutronix.de>\nCc: Russell King <rmk@arm.linux.org.uk>\nCc: Borislav Petkov <bp@alien8.de>\nCc: Florian Fainelli <florian@openwrt.org>\nCc: Yann Collet <yann.collet.73@gmail.com>\nSigned-off-by: Andrew Morton <akpm@linux-foundation.org>\nSigned-off-by: Linus Torvalds <torvalds@linux-foundation.org>\n(cherry picked from commit e76e1fdfa8f8dc1ea6699923cf5d92b5bee9c936)\n\nChange-Id: I280ccb95d3399c2e3ed529e60ae3c53190337bea\n\nlib/lz4: correct the LZ4 license\n\nThe LZ4 code is listed as using the \"BSD 2-Clause License\".\n\nSigned-off-by: Richard Laager <rlaager@wiktel.com>\nAcked-by: Kyungsik Lee <kyungsik.lee@lge.com>\nCc: Chanho Min <chanho.min@lge.com>\nCc: Richard Yao <ryao@gentoo.org>\nSigned-off-by: Andrew Morton <akpm@linux-foundation.org>\n[ The 2-clause BSD can be just converted into GPL, but that's rude and\n  pointless, so don't do it   - Linus ]\nSigned-off-by: Linus Torvalds <torvalds@linux-foundation.org>\n\n(cherry picked from commit ee8a99bdb47f32327bdfaffe35b900ca7161ba4e)\n\nlz4: fix compression/decompression signedness mismatch\n\nLZ4 compression and decompression functions require different in\nsignedness input/output parameters: unsigned char for compression and\nsigned char for decompression.\n\nChange decompression API to require \"(const) unsigned char *\".\n\nSigned-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>\nCc: Kyungsik Lee <kyungsik.lee@lge.com>\nCc: Geert Uytterhoeven <geert@linux-m68k.org>\nCc: Yann Collet <yann.collet.73@gmail.com>\nSigned-off-by: Andrew Morton <akpm@linux-foundation.org>\nSigned-off-by: Linus Torvalds <torvalds@linux-foundation.org>\n(cherry picked from commit b34081f1cd59585451efaa69e1dff1b9507e6c89)\n\nlz4: ensure length does not wrap\n\nGiven some pathologically compressed data, lz4 could possibly decide to\nwrap a few internal variables, causing unknown things to happen.  Catch\nthis before the wrapping happens and abort the decompression.\n\nReported-by: \"Don A. Bailey\" <donb@securitymouse.com>\nCc: stable <stable@vger.kernel.org>\nSigned-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>\n(cherry picked from commit 206204a1162b995e2185275167b22468c00d6b36)\n\nlz4: fix another possible overrun\n\nThere is one other possible overrun in the lz4 code as implemented by\nLinux at this point in time (which differs from the upstream lz4\ncodebase, but will get synced at in a future kernel release.)  As\npointed out by Don, we also need to check the overflow in the data\nitself.\n\nWhile we are at it, replace the odd error return value with just a\n\"simple\" -1 value as the return value is never used for anything other\nthan a basic \"did this work or not\" check.\n\nReported-by: \"Don A. Bailey\" <donb@securitymouse.com>\nReported-by: Willy Tarreau <w@1wt.eu>\nCc: stable <stable@vger.kernel.org>\nSigned-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>\n(cherry picked from commit 4148c1f67abf823099b2d7db6851e4aea407f5ee)","distinct":true,"url":"https://api.github.com/repos/benschhold/android_kernel_oneplus_msm8994_custom/commits/6f8c86171cb2a92f2ae1806add70c1101d3e61b5"},{"sha":"d38354a7a76683a1d7653a8a7066e406a415b40b","author":{"email":"d6c79f9a480ad4ed830bd25494dbd47136403d90@gmail.com","name":"benschhold"},"message":"change defconfig for zram","distinct":true,"url":"https://api.github.com/repos/benschhold/android_kernel_oneplus_msm8994_custom/commits/d38354a7a76683a1d7653a8a7066e406a415b40b"},{"sha":"c9acfca5405c3b0e36612441365789741a1677f3","author":{"email":"e6e4f086157115175bc8c304dfd5c76422bee466@outlook.com","name":"AudioGod"},"message":"Add more Zram\n\nSigned-off-by: AudioGod <audiogod@sonic-developers.com>","distinct":true,"url":"https://api.github.com/repos/benschhold/android_kernel_oneplus_msm8994_custom/commits/c9acfca5405c3b0e36612441365789741a1677f3"}]}