Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp1056501rwi; Wed, 2 Nov 2022 23:51:28 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4Kk7T7GiPbJsZEpDDVAU5OLzcl4Wq/MpXIL+UGMFtd8DTdOtpAWYjIaBgIbsf9/z2CLRKe X-Received: by 2002:a63:d34c:0:b0:462:589b:b27e with SMTP id u12-20020a63d34c000000b00462589bb27emr25226522pgi.418.1667458287862; Wed, 02 Nov 2022 23:51:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667458287; cv=none; d=google.com; s=arc-20160816; b=tnzDqPqnID3HoAim4gpv1VO1XiJnTrrif9RIt2zMQUI/ALRcarQlUploNr15NIn7gk ZDBa28fb3fOCdcHmylw+AeI9yVGJmu4qJ6vKnNRG+MBp7FFQoV8E5poHUMGX3XR9vg8W HQiVImNz+ySHXA6xNyWjmA3XyPY8vBDBZ4G4cm2nRbql3MnfP/4CDlK8yGcFFVB28sXj GMGZLxQQu66lF6PWuyS7bcP4ItzV6Y1ixs+MDcBpWIx3/RESzt7Cp5BYtjl7FDuuiWsJ kM1EaEYKO7sjOBU+/y8/RXXQeplh7XZmk5L1bPfvRIz4WqMqI/hdfTLBQH/1nF5GHulw fOVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=vcRPdTV+WHrAGCtQC2DiKk2qf+ALI9TLfQTYJZ4jJzU=; b=LmbwkqrEZnufIvnfOt17S5+Z+/tF7t1ecNqRqdUZ5ah9SE4ApOp71CsTsI2yEgaUoo FY3/c3gi8v7sH6tTmMnRLT7jD69Ij1iYoJHYa/pAG5r6p+msycKJvCNMkFFYrDca/i9k Fc63dRMUG0maGgRo3ZKBT3SKpFq3yntkkWXB83BAzsZYqwdjOaW8Q5Rf5M1uOYMzDbHx fwH0cu1kHjwZZld2ahXr/+QEwPDcwEI7MI8wNJnzSyFQ6mFJGkA9T2tqPOsN9guTAAvr b63abC+hASomecn0+t1S9flk9RzC+ucB8FSV9yEmQu/GYyQ3zMa301+HJQtD6oVKVHyl D4aw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=nHMjJVtM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id px16-20020a17090b271000b0020d4b43d8b5si4455462pjb.103.2022.11.02.23.51.15; Wed, 02 Nov 2022 23:51:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=nHMjJVtM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230419AbiKCGD5 (ORCPT + 97 others); Thu, 3 Nov 2022 02:03:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229875AbiKCGDy (ORCPT ); Thu, 3 Nov 2022 02:03:54 -0400 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BA4A19280 for ; Wed, 2 Nov 2022 23:03:53 -0700 (PDT) Received: by mail-pj1-x1032.google.com with SMTP id o7so716868pjj.1 for ; Wed, 02 Nov 2022 23:03:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=vcRPdTV+WHrAGCtQC2DiKk2qf+ALI9TLfQTYJZ4jJzU=; b=nHMjJVtMxmTIzf2SCJTSZI8zPM1b+mG2EXn9V6MK0pgbT7qfY3VOu+H/BmRcHFvppS 9Un+JTe85Imf4beW1yi4D9Ips5UD9pcQk82+5ZOPH3hh4QF8UUfYCS2ibY1R/hLdGkMs yywa47cffiRjPj6E2Ai5H2WJ84Pn7cyrNqhas= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=vcRPdTV+WHrAGCtQC2DiKk2qf+ALI9TLfQTYJZ4jJzU=; b=PZqnL3wjhmtSUbxmLCHSz61Kc4Ab2jgFw81UBDg88COBZvGCbjEl/W2jEJKQ+47sGQ jZ8l28Cb2+7x9i85VONuevolCfP6iz3dKnrBvzyBRZLRXVVlxD8AieGwR5eFTBHtnXfN 9Q4bcvszf/Wdd+IfYFnZdEwEHbhhX3z+07dTy3EPWpO1F6m+PeskejqhZwu6/0a8Y8Wv otq0XSxMVUs3R2sbiX6Og5nBm+ZadbKswuDpx84iyWrzbqBw/C0dqhnsbp/7JUqLKRnm ZAf+4FAbcE3lFCXY6j8amfcW+74Sm6ju1MmrBNuzr4F0MYZKeMnN6RP+h9vqw842vJrT BAEg== X-Gm-Message-State: ACrzQf0LrsNycpQHh/Ztq8Pz2WQZtfK+zaU/sD8i35lN0dR42l5v3QnG Wxz6Gmql4a4WwS2Q8PvrClOQfQ== X-Received: by 2002:a17:902:ce92:b0:187:2938:2fca with SMTP id f18-20020a170902ce9200b0018729382fcamr16935349plg.7.1667455432892; Wed, 02 Nov 2022 23:03:52 -0700 (PDT) Received: from google.com ([240f:75:7537:3187:f22:e30:374d:5a2b]) by smtp.gmail.com with ESMTPSA id q16-20020a17090311d000b001745662d568sm9359633plh.278.2022.11.02.23.03.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Nov 2022 23:03:52 -0700 (PDT) Date: Thu, 3 Nov 2022 15:03:48 +0900 From: Sergey Senozhatsky To: Minchan Kim Cc: Andrew Morton , Nitin Gupta , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Sergey Senozhatsky Subject: Re: [PATCHv4 4/9] zram: Introduce recompress sysfs knob Message-ID: References: <20221018045533.2396670-1-senozhatsky@chromium.org> <20221018045533.2396670-5-senozhatsky@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On (22/11/03 12:25), Sergey Senozhatsky wrote: > > or we can introduce the threshold with action item. > > > > echo "idle 888" > /sys/block/zram0/recompress > > echo "huge 888" > /sys/block/zram0/recompress > > echo "normal 888" > /sys/block/zram0/recompress > > I like the latter one, when threshold is an optional argument. > I probably would even go a bit further and add keywords: > > type=STRING threshold=INT E.g. recompress support for type= and optional threshold= We kind of don't have a use case of type=normal, as it is an equivalent of no type. So we have huge, idle, huge_idle and no param means all pages (which is sort of logical). threshold is optional. --- drivers/block/zram/zram_drv.c | 55 ++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 9a614253de07..12f03745baf9 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1688,7 +1688,7 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, * Corresponding ZRAM slot should be locked. */ static int zram_recompress(struct zram *zram, u32 index, struct page *page, - int size_watermark) + int size_threshold) { unsigned long handle_prev; unsigned long handle_next; @@ -1708,7 +1708,7 @@ static int zram_recompress(struct zram *zram, u32 index, struct page *page, /* * Do not recompress objects that are already "small enough". */ - if (comp_len_prev < size_watermark) + if (comp_len_prev < size_threshold) return 0; ret = zram_read_from_zspool(zram, page, index); @@ -1780,29 +1780,42 @@ static ssize_t recompress_store(struct device *dev, { struct zram *zram = dev_to_zram(dev); unsigned long nr_pages = zram->disksize >> PAGE_SHIFT; + char *args, *param, *val; unsigned long index; struct page *page; ssize_t ret; - int mode, size_watermark = 0; - - if (sysfs_streq(buf, "idle")) { - mode = RECOMPRESS_IDLE; - } else if (sysfs_streq(buf, "huge")) { - mode = RECOMPRESS_HUGE; - } else if (sysfs_streq(buf, "huge_idle")) { - mode = RECOMPRESS_IDLE | RECOMPRESS_HUGE; - } else { - /* - * We will re-compress only idle objects equal or greater - * in size than watermark. - */ - ret = kstrtoint(buf, 10, &size_watermark); - if (ret) - return ret; - mode = RECOMPRESS_IDLE; + int mode = 0, size_threshold = 0; + + args = skip_spaces(buf); + while (*args) { + args = next_arg(args, ¶m, &val); + + if (!*val) + return -EINVAL; + + if (!strcmp(param, "type")) { + if (!strcmp(val, "idle")) + mode = RECOMPRESS_IDLE; + if (!strcmp(val, "huge")) + mode = RECOMPRESS_HUGE; + if (!strcmp(val, "huge_idle")) + mode = RECOMPRESS_IDLE | RECOMPRESS_HUGE; + continue; + } + + if (!strcmp(param, "threshold")) { + /* + * We will re-compress only idle objects equal or + * greater in size than watermark. + */ + ret = kstrtoint(val, 10, &size_threshold); + if (ret) + return ret; + continue; + } } - if (size_watermark > PAGE_SIZE) + if (size_threshold > PAGE_SIZE) return -EINVAL; down_read(&zram->init_lock); @@ -1841,7 +1854,7 @@ static ssize_t recompress_store(struct device *dev, zram_test_flag(zram, index, ZRAM_RECOMP_SKIP)) goto next; - err = zram_recompress(zram, index, page, size_watermark); + err = zram_recompress(zram, index, page, size_threshold); next: zram_slot_unlock(zram, index); if (err) { -- 2.38.1.273.g43a17bfeac-goog