From patchwork Thu Oct 10 20:09:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vitaly Wool X-Patchwork-Id: 11184169 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EC18117D4 for ; Thu, 10 Oct 2019 20:09:21 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A2311218AC for ; Thu, 10 Oct 2019 20:09:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SH+HoBZR" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A2311218AC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D3CE28E0007; Thu, 10 Oct 2019 16:09:20 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id CEE428E0003; Thu, 10 Oct 2019 16:09:20 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BB4548E0007; Thu, 10 Oct 2019 16:09:20 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0118.hostedemail.com [216.40.44.118]) by kanga.kvack.org (Postfix) with ESMTP id 94DE68E0003 for ; Thu, 10 Oct 2019 16:09:20 -0400 (EDT) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with SMTP id 2E549181AC9B4 for ; Thu, 10 Oct 2019 20:09:20 +0000 (UTC) X-FDA: 76028964480.10.fruit80_173a1c665d53f X-Spam-Summary: 2,0,0,941ac8b98659c1b7,d41d8cd98f00b204,vitalywool@gmail.com,::akpm@linux-foundation.org:ddstreet@ieee.org:minchan@kernel.org:sergey.senozhatsky.work@gmail.com:linux-kernel@vger.kernel.org:vbabka@suse.cz:shakeelb@google.com:henrywolfeburns@gmail.com:tytso@thunk.org,RULES_HIT:41:355:379:541:800:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1535:1543:1593:1594:1711:1730:1747:1777:1792:2393:2559:2562:3138:3139:3140:3141:3142:3355:3369:3865:3866:3867:3868:3871:4117:4250:4321:4605:5007:6119:6261:6653:7514:7875:7903:8603:9413:10004:10400:11026:11658:11914:12043:12048:12291:12296:12297:12438:12517:12519:12555:12683:12760:12895:12986:13161:13229:13439:13869:13972:14096:14097:14181:14394:14659:14687:14721:21080:21212:21444:21451:21627:21666:30005:30034:30054:30070,0,RBL:209.85.167.68:@gmail.com:.lbl8.mailshell.net-62.18.175.100 66.100.201.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral, Custom_r X-HE-Tag: fruit80_173a1c665d53f X-Filterd-Recvd-Size: 7000 Received: from mail-lf1-f68.google.com (mail-lf1-f68.google.com [209.85.167.68]) by imf39.hostedemail.com (Postfix) with ESMTP for ; Thu, 10 Oct 2019 20:09:19 +0000 (UTC) Received: by mail-lf1-f68.google.com with SMTP id t8so5309049lfc.13 for ; Thu, 10 Oct 2019 13:09:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=30hz3u6HKVQsiTqmh/RFo8C++yvFx01bv6SBJxIy2V8=; b=SH+HoBZRgBKYncT5ELFt9CejheKjs+0Ekv4JGeAw5r6KbOR5CB5WsrhKvxcb+JBSFX wLduQNQTvNPiFvzQ9cmhENZaegY9EvdapgVvRmcCHI/dHFAIvs8n4rad8UIARmpVzARm 7Gk3udm9WhelqGOhjiEA/4N6fJwMVdkz8Y3RinmWx6E3ohR6v6ENlcVV9NgIiBfMg08q o+bbwChuzjoFyLcO0aPRXNykVBqohh+qhnkVD4lmewA00dJ1lLcngLsyqJON33nzg9Ll iJunuE0/pJ3V6NGDnZATvkDOUwA+rvt5dz7pNDWIYQ+TBRftcEPqExkOZbiV6Uu7XF0n Mayw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=30hz3u6HKVQsiTqmh/RFo8C++yvFx01bv6SBJxIy2V8=; b=GMvWj6nTbk3xU0lWc+3GdVz7hYCAj8vzT2Uoc+JtdVPLJB8B9YuC7NSsy5MmRtyad8 TmVdWe+p4QvCrHbLIL7FuWd1e7JQ2in1iNiuNlJu+wyXNRaPYs4rgxE/sx84HPyUuLLL XJpGrrnW3V9hpHqAgKVb5CyO1rpKIXEpjK+/vsHEiIjr28K13Bp3bHewbZcxn5TobENy FvjvA4IXH2bQMIZXvPKylLJWOEgTitaliX9CCk27msl3D2AGBubbkPFvg4zOVAFd8f2A I5DeWYHbF+yW99P2Yq98GpoHp3Bx4kI0VgVuSWLmcU82xUB8fKWwpJj5zw750rPAp09D w8RA== X-Gm-Message-State: APjAAAXSWowp9V+sB8g6pwUDb0a0V5wkcCiiVSqipw/sMgOJGlmmIsbC vQ+MsmiFk1TsFjSwyNXaTC3ZDqc8ONfiwA== X-Google-Smtp-Source: APXvYqyi5UGtrwouzNPae0v9xOAN80h6C1gzyxknZjfPCdeHHIFdBqki6pp7lhHiVirvOhINpJdMtA== X-Received: by 2002:ac2:5924:: with SMTP id v4mr6919119lfi.29.1570738157797; Thu, 10 Oct 2019 13:09:17 -0700 (PDT) Received: from vitaly-Dell-System-XPS-L322X (c188-150-241-161.bredband.comhem.se. [188.150.241.161]) by smtp.gmail.com with ESMTPSA id i6sm1501422lfo.83.2019.10.10.13.09.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2019 13:09:16 -0700 (PDT) Date: Thu, 10 Oct 2019 23:09:15 +0300 From: Vitaly Wool To: Linux-MM , Andrew Morton , Dan Streetman , Minchan Kim Cc: Sergey Senozhatsky , LKML , Vlastimil Babka , Shakeel Butt , Henry Burns , Theodore Ts'o Subject: [PATCH 1/3] zpool: extend API to match zsmalloc Message-Id: <20191010230915.f68401e9c9e0fa053dcbe199@gmail.com> In-Reply-To: <20191010230414.647c29f34665ca26103879c4@gmail.com> References: <20191010230414.647c29f34665ca26103879c4@gmail.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: This patch adds the following functions to the zpool API: - zpool_compact() - zpool_get_num_compacted() - zpool_huge_class_size() The first one triggers compaction for the underlying allocator, the second retrieves the number of pages migrated due to compaction for the whole time of this pool's existence and the third one returns the huge class size. This API extension is done to align zpool API with zsmalloc API. Signed-off-by: Vitaly Wool Reviewed-by: Dan Streetman --- include/linux/zpool.h | 14 +++++++++++++- mm/zpool.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/include/linux/zpool.h b/include/linux/zpool.h index 51bf43076165..31f0c1360569 100644 --- a/include/linux/zpool.h +++ b/include/linux/zpool.h @@ -61,8 +61,13 @@ void *zpool_map_handle(struct zpool *pool, unsigned long handle, void zpool_unmap_handle(struct zpool *pool, unsigned long handle); +unsigned long zpool_compact(struct zpool *pool); + +unsigned long zpool_get_num_compacted(struct zpool *pool); + u64 zpool_get_total_size(struct zpool *pool); +size_t zpool_huge_class_size(struct zpool *zpool); /** * struct zpool_driver - driver implementation for zpool @@ -75,7 +80,10 @@ u64 zpool_get_total_size(struct zpool *pool); * @shrink: shrink the pool. * @map: map a handle. * @unmap: unmap a handle. - * @total_size: get total size of a pool. + * @compact: try to run compaction over a pool + * @get_num_compacted: get amount of compacted pages for a pool + * @total_size: get total size of a pool + * @huge_class_size: huge class threshold for pool pages. * * This is created by a zpool implementation and registered * with zpool. @@ -104,7 +112,11 @@ struct zpool_driver { enum zpool_mapmode mm); void (*unmap)(void *pool, unsigned long handle); + unsigned long (*compact)(void *pool); + unsigned long (*get_num_compacted)(void *pool); + u64 (*total_size)(void *pool); + size_t (*huge_class_size)(void *pool); }; void zpool_register_driver(struct zpool_driver *driver); diff --git a/mm/zpool.c b/mm/zpool.c index 863669212070..55e69213c2eb 100644 --- a/mm/zpool.c +++ b/mm/zpool.c @@ -362,6 +362,30 @@ void zpool_unmap_handle(struct zpool *zpool, unsigned long handle) zpool->driver->unmap(zpool->pool, handle); } + /** + * zpool_compact() - try to run compaction over zpool + * @pool The zpool to compact + * + * Returns: the number of migrated pages + */ +unsigned long zpool_compact(struct zpool *zpool) +{ + return zpool->driver->compact ? zpool->driver->compact(zpool->pool) : 0; +} + + +/** + * zpool_get_num_compacted() - get the number of migrated/compacted pages + * @pool The zpool to get compaction statistic for + * + * Returns: the total number of migrated pages for the pool + */ +unsigned long zpool_get_num_compacted(struct zpool *zpool) +{ + return zpool->driver->get_num_compacted ? + zpool->driver->get_num_compacted(zpool->pool) : 0; +} + /** * zpool_get_total_size() - The total size of the pool * @zpool: The zpool to check @@ -375,6 +399,18 @@ u64 zpool_get_total_size(struct zpool *zpool) return zpool->driver->total_size(zpool->pool); } +/** + * zpool_huge_class_size() - get size for the "huge" class + * @pool The zpool to check + * + * Returns: size of the huge class + */ +size_t zpool_huge_class_size(struct zpool *zpool) +{ + return zpool->driver->huge_class_size ? + zpool->driver->huge_class_size(zpool->pool) : 0; +} + /** * zpool_evictable() - Test if zpool is potentially evictable * @zpool: The zpool to test From patchwork Thu Oct 10 20:11:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vitaly Wool X-Patchwork-Id: 11184171 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D04B617D4 for ; Thu, 10 Oct 2019 20:11:48 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8FB26214E0 for ; Thu, 10 Oct 2019 20:11:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="AMPzRcMz" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8FB26214E0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B8DCE8E0005; Thu, 10 Oct 2019 16:11:47 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B3DBF8E0003; Thu, 10 Oct 2019 16:11:47 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A53458E0005; Thu, 10 Oct 2019 16:11:47 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0218.hostedemail.com [216.40.44.218]) by kanga.kvack.org (Postfix) with ESMTP id 854FD8E0003 for ; Thu, 10 Oct 2019 16:11:47 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with SMTP id 3092182437C9 for ; Thu, 10 Oct 2019 20:11:47 +0000 (UTC) X-FDA: 76028970654.29.view28_2ca145453724b X-Spam-Summary: 75,0,0,8bf8bead4e550617,d41d8cd98f00b204,vitalywool@gmail.com,::akpm@linux-foundation.org:ddstreet@ieee.org:minchan@kernel.org:sergey.senozhatsky.work@gmail.com:linux-kernel@vger.kernel.org:vbabka@suse.cz:shakeelb@google.com:henrywolfeburns@gmail.com:tytso@thunk.org,RULES_HIT:41:355:379:541:800:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2393:2559:2562:3138:3139:3140:3141:3142:3352:3369:3865:3867:3870:4250:4321:5007:6261:6653:7514:9413:10004:10400:11026:11658:11914:12043:12048:12291:12296:12297:12438:12517:12519:12555:12760:12895:12986:13069:13311:13357:13439:14096:14097:14181:14394:14659:14687:14721:21080:21212:21444:21451:21627:21666:30054,0,RBL:209.85.208.195-irl.urbl.hostedemail.com-127.0.0.175,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:25,LUA_SUMMARY:none X-HE-Tag: view28_2ca145453724b X-Filterd-Recvd-Size: 4851 Received: from mail-lj1-f195.google.com (mail-lj1-f195.google.com [209.85.208.195]) by imf27.hostedemail.com (Postfix) with ESMTP for ; Thu, 10 Oct 2019 20:11:46 +0000 (UTC) Received: by mail-lj1-f195.google.com with SMTP id l21so7529827lje.4 for ; Thu, 10 Oct 2019 13:11:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QJWOGN1T52H0uvWMZ9lrHPVpqM+o1MdQipUB8ycg4N0=; b=AMPzRcMzP0Q+ZRjBMDxm6q1DmMC6OYTMxAQ3EOwa/E47MuDYSz2TtMCOR2T/COr3eU EuHk30dqlS5g9nWsWRCUTKpuO9evJY5KqKWYfnevUFz2iEQHIL6QQ33AjYfU6yl/EA3N 8bCaMqIE66VwOapMYxDbhgwUshFNpesAOP8teGjM3JHZB2MQJtNP3si1uzA+taJLCcu3 5rn7t9yzAgoPSxXQgZN3T2RSou9+hGP9BfUhQzaxACPi+hnL8FofC4Gz2ebJ7VCBLySZ sQkByQJs/3CdOoJz/8rTfekiYBySlvQ39Qi+M8yNfpkTFepUFIe2I1ME5BT7LRvFlPHJ 7Xlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QJWOGN1T52H0uvWMZ9lrHPVpqM+o1MdQipUB8ycg4N0=; b=ULMZnGHAte7XtFIpw84F2wUG/kHZ2lQqQ4Ez6+s1/mvl+FG1AXZVDvG9TkT3ffmN35 NSUZia351ZNU29ISYphk2kynah+ZnriNsPe0wnjM8PijupDhRLyfpvozA0h+kpYx+I97 K6w0hI7j77pVDL+mznsDUS0hQ3+EkQM5bNY5cOmjKb5mQGKdpNIzZ+Zi6j3VG65o4me8 +/JkfISkOiXGsxYxjJDVj5jvWGDG+85IViDa1w0l9h0aGtjor79IvXnpDlVFGPoltFPf ZQVMd55sv6ygqcONUchI9+i3+3fjFpkebWrOjM42wYAvaWPaFVNzExIwPYyAOfHtt8KI zTeQ== X-Gm-Message-State: APjAAAX/nSDmRA9pd0V5TUvXPxrEvSddW/2yo21tuM9UBVBh9CPdg4P9 C2sCPUtG0l11UVllenylfayA/PvXTIJaXA== X-Google-Smtp-Source: APXvYqzN+Eo38GYZjgQvgyjVNpEmWykAfXX1SXTS5NplM6jQi15Q1eur5GZoG7DxYI04DSCojiWjxw== X-Received: by 2002:a2e:3014:: with SMTP id w20mr7572909ljw.115.1570738304765; Thu, 10 Oct 2019 13:11:44 -0700 (PDT) Received: from vitaly-Dell-System-XPS-L322X (c188-150-241-161.bredband.comhem.se. [188.150.241.161]) by smtp.gmail.com with ESMTPSA id o13sm1457581lji.31.2019.10.10.13.11.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2019 13:11:44 -0700 (PDT) Date: Thu, 10 Oct 2019 23:11:43 +0300 From: Vitaly Wool To: Linux-MM , Andrew Morton , Dan Streetman , Minchan Kim Cc: Sergey Senozhatsky , LKML , Vlastimil Babka , Shakeel Butt , Henry Burns , Theodore Ts'o Subject: [PATCH 2/3] zsmalloc: add compaction and huge class callbacks Message-Id: <20191010231143.09e4a2bd52f331efd0c4baf9@gmail.com> In-Reply-To: <20191010230414.647c29f34665ca26103879c4@gmail.com> References: <20191010230414.647c29f34665ca26103879c4@gmail.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Add compaction callbacks for zpool compaction API extension. Add huge_class_size callback too to be fully aligned. With these in place, we can proceed with ZRAM modification to use the universal (zpool) API. Signed-off-by: Vitaly Wool --- mm/zsmalloc.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index 2b2b9aae8a3c..43f43272b998 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -437,11 +437,29 @@ static void zs_zpool_unmap(void *pool, unsigned long handle) zs_unmap_object(pool, handle); } +static unsigned long zs_zpool_compact(void *pool) +{ + return zs_compact(pool); +} + +static unsigned long zs_zpool_get_compacted(void *pool) +{ + struct zs_pool_stats stats; + + zs_pool_stats(pool, &stats); + return stats.pages_compacted; +} + static u64 zs_zpool_total_size(void *pool) { return zs_get_total_pages(pool) << PAGE_SHIFT; } +static size_t zs_zpool_huge_class_size(void *pool) +{ + return zs_huge_class_size(pool); +} + static struct zpool_driver zs_zpool_driver = { .type = "zsmalloc", .owner = THIS_MODULE, @@ -453,6 +471,9 @@ static struct zpool_driver zs_zpool_driver = { .map = zs_zpool_map, .unmap = zs_zpool_unmap, .total_size = zs_zpool_total_size, + .compact = zs_zpool_compact, + .get_num_compacted = zs_zpool_get_compacted, + .huge_class_size = zs_zpool_huge_class_size, }; MODULE_ALIAS("zpool-zsmalloc"); From patchwork Thu Oct 10 20:20:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vitaly Wool X-Patchwork-Id: 11184173 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7525913BD for ; Thu, 10 Oct 2019 20:20:37 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1D16B21920 for ; Thu, 10 Oct 2019 20:20:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ryxItFlv" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1D16B21920 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 40D4C8E0005; Thu, 10 Oct 2019 16:20:36 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 3BDD68E0003; Thu, 10 Oct 2019 16:20:36 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2AD7D8E0005; Thu, 10 Oct 2019 16:20:36 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0213.hostedemail.com [216.40.44.213]) by kanga.kvack.org (Postfix) with ESMTP id 090258E0003 for ; Thu, 10 Oct 2019 16:20:36 -0400 (EDT) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with SMTP id 7501C180AD805 for ; Thu, 10 Oct 2019 20:20:35 +0000 (UTC) X-FDA: 76028992830.15.house27_7976ababc0923 X-Spam-Summary: 75,0,0,429f2d49a5c166cb,d41d8cd98f00b204,vitalywool@gmail.com,::akpm@linux-foundation.org:ddstreet@ieee.org:minchan@kernel.org:sergey.senozhatsky.work@gmail.com:linux-kernel@vger.kernel.org:vbabka@suse.cz:shakeelb@google.com:henrywolfeburns@gmail.com:tytso@thunk.org,RULES_HIT:1:2:41:69:355:379:541:800:960:966:973:988:989:1260:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1593:1594:1605:1730:1747:1777:1792:2196:2199:2393:2559:2562:3138:3139:3140:3141:3142:3865:3866:3867:3868:3870:3871:3872:4051:4250:4321:4385:5007:6119:6261:6653:7514:7903:8603:9036:9040:9413:9592:10004:11026:11232:11473:11658:11914:12043:12048:12296:12297:12438:12517:12519:12555:12683:12760:12895:12986:13439:13972:14096:14097:14394:14659:14687:21080:21444:21451:21627:21666:30029:30034:30054:30070,0,RBL:209.85.208.195-irl.urbl.hostedemail.com-127.0.0.175,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:26,LUA_SUM MARY:non X-HE-Tag: house27_7976ababc0923 X-Filterd-Recvd-Size: 11776 Received: from mail-lj1-f195.google.com (mail-lj1-f195.google.com [209.85.208.195]) by imf47.hostedemail.com (Postfix) with ESMTP for ; Thu, 10 Oct 2019 20:20:34 +0000 (UTC) Received: by mail-lj1-f195.google.com with SMTP id y23so7508099lje.9 for ; Thu, 10 Oct 2019 13:20:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=80xeYmJXoz8ke/tvchUiNx1pIg6JQ6gSpQxw+B6BHy4=; b=ryxItFlvQpAhiU3n7yNflmHHDCvxFz/gQGPPzl7v7zLfCTGBAduETvbrgHjzqrxWvm 9oI4hQ+OrHS7R6jMfYvAHsy9cYSFB9iFC6q1cy70UDe/O5vJ3ggtRQv3wZu5zNJeXaIY KkxXIqROZB8wzdqcu4PAK92UC8scKvfirQyy2f/W1eKAdFCWlqPjPCZedZPTujHGxaoM sRUxnvU6d/0g6RYdoa80mXtetOPjtVTlgb24CaI1BS5mPW5U31hffzdoN3rkO9z61KaZ hdgCDszgor29Phmbr0zFmiol0y1lILka+gfMF805ZXDEJEcUHdrf1/I3P73dznoaHBPm VRvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=80xeYmJXoz8ke/tvchUiNx1pIg6JQ6gSpQxw+B6BHy4=; b=kiTsLoWmTLLRPZcHFCwBgpbjDvujWKGxewzWQrzCO5NlKGgx0TYBY5Gzhb3aQ9D4FX zQMFZS5RchAUw16MRmhUdjlKurAySYV7C7F86g1+W8glcn5QVARHptCixXe0g+ln3aE2 fv7yNWbpOB/69jRf2ij2j4YRyrm9XQdgTeS3c0HiTWxYNkIxi4ptP93Ed5sZB4u0Bml+ BBmOMUbNyw3hEVaNUfreHdUjXRZGfb9y0IOsQ+lQDC1fA0qv3Yg3kEnZYG9rM2nITv9l 6AAb2A/mhreJlePy5pLpbhrcmse15J53FlR2awf9PDxKTHtfjIYySrrb/8r1v3DvjLPW v8nA== X-Gm-Message-State: APjAAAX4rm1r+hI2y54FKhJIRRnOSJm1o8rSxRkN+cnyV8JvutwMia7G 8L2XYfRhka0xBhNbKvN+xEiO8Xv9fSvY2g== X-Google-Smtp-Source: APXvYqzgE/UisNTKPdcJjjUzTZqbUNEv07HwOJf18mUeTq2LPFZ3a5Pc71onpgghBvDxWxRqXo24bA== X-Received: by 2002:a2e:957:: with SMTP id 84mr7199963ljj.245.1570738832570; Thu, 10 Oct 2019 13:20:32 -0700 (PDT) Received: from vitaly-Dell-System-XPS-L322X (c188-150-241-161.bredband.comhem.se. [188.150.241.161]) by smtp.gmail.com with ESMTPSA id 21sm1444207ljq.15.2019.10.10.13.20.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2019 13:20:31 -0700 (PDT) Date: Thu, 10 Oct 2019 23:20:30 +0300 From: Vitaly Wool To: Linux-MM , Andrew Morton , Dan Streetman , Minchan Kim Cc: Sergey Senozhatsky , LKML , Vlastimil Babka , Shakeel Butt , Henry Burns , Theodore Ts'o Subject: [PATCH 3/3] zram: use common zpool interface Message-Id: <20191010232030.af6444879413e76a780cd27e@gmail.com> In-Reply-To: <20191010230414.647c29f34665ca26103879c4@gmail.com> References: <20191010230414.647c29f34665ca26103879c4@gmail.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Change ZRAM into using zpool API. This patch allows to use any zpool compatible allocation backend with ZRAM. It is meant to make no functional changes to ZRAM. zpool-registered backend can be selected via the module parameter or kernel boot string. 'zsmalloc' is taken by default. Signed-off-by: Vitaly Wool --- drivers/block/zram/Kconfig | 3 ++- drivers/block/zram/zram_drv.c | 64 +++++++++++++++++++---------------- drivers/block/zram/zram_drv.h | 4 +-- 3 files changed, 39 insertions(+), 32 deletions(-) diff --git a/drivers/block/zram/Kconfig b/drivers/block/zram/Kconfig index fe7a4b7d30cf..7248d5aa3468 100644 --- a/drivers/block/zram/Kconfig +++ b/drivers/block/zram/Kconfig @@ -1,8 +1,9 @@ # SPDX-License-Identifier: GPL-2.0 config ZRAM tristate "Compressed RAM block device support" - depends on BLOCK && SYSFS && ZSMALLOC && CRYPTO + depends on BLOCK && SYSFS && CRYPTO select CRYPTO_LZO + select ZPOOL help Creates virtual block devices called /dev/zramX (X = 0, 1, ...). Pages written to these disks are compressed and stored in memory diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index d58a359a6622..881f10f99a5d 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -43,6 +43,9 @@ static DEFINE_MUTEX(zram_index_mutex); static int zram_major; static const char *default_compressor = "lzo-rle"; +#define BACKEND_PAR_BUF_SIZE 32 +static char backend_par_buf[BACKEND_PAR_BUF_SIZE]; + /* Module params (documentation at end) */ static unsigned int num_devices = 1; /* @@ -277,7 +280,7 @@ static ssize_t mem_used_max_store(struct device *dev, down_read(&zram->init_lock); if (init_done(zram)) { atomic_long_set(&zram->stats.max_used_pages, - zs_get_total_pages(zram->mem_pool)); + zpool_get_total_size(zram->mem_pool) >> PAGE_SHIFT); } up_read(&zram->init_lock); @@ -1020,7 +1023,7 @@ static ssize_t compact_store(struct device *dev, return -EINVAL; } - zs_compact(zram->mem_pool); + zpool_compact(zram->mem_pool); up_read(&zram->init_lock); return len; @@ -1048,17 +1051,14 @@ static ssize_t mm_stat_show(struct device *dev, struct device_attribute *attr, char *buf) { struct zram *zram = dev_to_zram(dev); - struct zs_pool_stats pool_stats; u64 orig_size, mem_used = 0; - long max_used; + long max_used, num_compacted = 0; ssize_t ret; - memset(&pool_stats, 0x00, sizeof(struct zs_pool_stats)); - down_read(&zram->init_lock); if (init_done(zram)) { - mem_used = zs_get_total_pages(zram->mem_pool); - zs_pool_stats(zram->mem_pool, &pool_stats); + mem_used = zpool_get_total_size(zram->mem_pool); + num_compacted = zpool_get_num_compacted(zram->mem_pool); } orig_size = atomic64_read(&zram->stats.pages_stored); @@ -1068,11 +1068,11 @@ static ssize_t mm_stat_show(struct device *dev, "%8llu %8llu %8llu %8lu %8ld %8llu %8lu %8llu\n", orig_size << PAGE_SHIFT, (u64)atomic64_read(&zram->stats.compr_data_size), - mem_used << PAGE_SHIFT, + mem_used, zram->limit_pages << PAGE_SHIFT, max_used << PAGE_SHIFT, (u64)atomic64_read(&zram->stats.same_pages), - pool_stats.pages_compacted, + num_compacted, (u64)atomic64_read(&zram->stats.huge_pages)); up_read(&zram->init_lock); @@ -1133,27 +1133,30 @@ static void zram_meta_free(struct zram *zram, u64 disksize) for (index = 0; index < num_pages; index++) zram_free_page(zram, index); - zs_destroy_pool(zram->mem_pool); + zpool_destroy_pool(zram->mem_pool); vfree(zram->table); } static bool zram_meta_alloc(struct zram *zram, u64 disksize) { size_t num_pages; + char *backend; num_pages = disksize >> PAGE_SHIFT; zram->table = vzalloc(array_size(num_pages, sizeof(*zram->table))); if (!zram->table) return false; - zram->mem_pool = zs_create_pool(zram->disk->disk_name); + backend = strlen(backend_par_buf) ? backend_par_buf : "zsmalloc"; + zram->mem_pool = zpool_create_pool(backend, zram->disk->disk_name, + GFP_NOIO, NULL); if (!zram->mem_pool) { vfree(zram->table); return false; } if (!huge_class_size) - huge_class_size = zs_huge_class_size(zram->mem_pool); + huge_class_size = zpool_huge_class_size(zram->mem_pool); return true; } @@ -1197,7 +1200,7 @@ static void zram_free_page(struct zram *zram, size_t index) if (!handle) return; - zs_free(zram->mem_pool, handle); + zpool_free(zram->mem_pool, handle); atomic64_sub(zram_get_obj_size(zram, index), &zram->stats.compr_data_size); @@ -1246,7 +1249,7 @@ static int __zram_bvec_read(struct zram *zram, struct page *page, u32 index, size = zram_get_obj_size(zram, index); - src = zs_map_object(zram->mem_pool, handle, ZS_MM_RO); + src = zpool_map_handle(zram->mem_pool, handle, ZPOOL_MM_RO); if (size == PAGE_SIZE) { dst = kmap_atomic(page); memcpy(dst, src, PAGE_SIZE); @@ -1260,7 +1263,7 @@ static int __zram_bvec_read(struct zram *zram, struct page *page, u32 index, kunmap_atomic(dst); zcomp_stream_put(zram->comp); } - zs_unmap_object(zram->mem_pool, handle); + zpool_unmap_handle(zram->mem_pool, handle); zram_slot_unlock(zram, index); /* Should NEVER happen. Return bio error if it does. */ @@ -1335,7 +1338,7 @@ static int __zram_bvec_write(struct zram *zram, struct bio_vec *bvec, if (unlikely(ret)) { zcomp_stream_put(zram->comp); pr_err("Compression failed! err=%d\n", ret); - zs_free(zram->mem_pool, handle); + zpool_free(zram->mem_pool, handle); return ret; } @@ -1354,33 +1357,34 @@ static int __zram_bvec_write(struct zram *zram, struct bio_vec *bvec, * if we have a 'non-null' handle here then we are coming * from the slow path and handle has already been allocated. */ - if (!handle) - handle = zs_malloc(zram->mem_pool, comp_len, + if (handle == 0) + ret = zpool_malloc(zram->mem_pool, comp_len, __GFP_KSWAPD_RECLAIM | __GFP_NOWARN | __GFP_HIGHMEM | - __GFP_MOVABLE); - if (!handle) { + __GFP_MOVABLE, + &handle); + if (ret) { zcomp_stream_put(zram->comp); atomic64_inc(&zram->stats.writestall); - handle = zs_malloc(zram->mem_pool, comp_len, - GFP_NOIO | __GFP_HIGHMEM | - __GFP_MOVABLE); - if (handle) + ret = zpool_malloc(zram->mem_pool, comp_len, + GFP_NOIO | __GFP_HIGHMEM | __GFP_MOVABLE, + &handle); + if (ret == 0) goto compress_again; return -ENOMEM; } - alloced_pages = zs_get_total_pages(zram->mem_pool); + alloced_pages = zpool_get_total_size(zram->mem_pool) >> PAGE_SHIFT; update_used_max(zram, alloced_pages); if (zram->limit_pages && alloced_pages > zram->limit_pages) { zcomp_stream_put(zram->comp); - zs_free(zram->mem_pool, handle); + zpool_free(zram->mem_pool, handle); return -ENOMEM; } - dst = zs_map_object(zram->mem_pool, handle, ZS_MM_WO); + dst = zpool_map_handle(zram->mem_pool, handle, ZPOOL_MM_WO); src = zstrm->buffer; if (comp_len == PAGE_SIZE) @@ -1390,7 +1394,7 @@ static int __zram_bvec_write(struct zram *zram, struct bio_vec *bvec, kunmap_atomic(src); zcomp_stream_put(zram->comp); - zs_unmap_object(zram->mem_pool, handle); + zpool_unmap_handle(zram->mem_pool, handle); atomic64_add(comp_len, &zram->stats.compr_data_size); out: /* @@ -2136,6 +2140,8 @@ module_exit(zram_exit); module_param(num_devices, uint, 0); MODULE_PARM_DESC(num_devices, "Number of pre-created zram devices"); +module_param_string(backend, backend_par_buf, BACKEND_PAR_BUF_SIZE, S_IRUGO); +MODULE_PARM_DESC(backend, "Compression storage (backend) name"); MODULE_LICENSE("Dual BSD/GPL"); MODULE_AUTHOR("Nitin Gupta "); diff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h index f2fd46daa760..f4f51c6489ba 100644 --- a/drivers/block/zram/zram_drv.h +++ b/drivers/block/zram/zram_drv.h @@ -16,7 +16,7 @@ #define _ZRAM_DRV_H_ #include -#include +#include #include #include "zcomp.h" @@ -91,7 +91,7 @@ struct zram_stats { struct zram { struct zram_table_entry *table; - struct zs_pool *mem_pool; + struct zpool *mem_pool; struct zcomp *comp; struct gendisk *disk; /* Prevent concurrent execution of device init */