Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp103095pxb; Wed, 22 Sep 2021 17:11:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyLx44Y4U0rEJBu5hTXnQhKgpetQQ+EvLrvL3ZvZbDnCm38oOCBk1ohjTHfF6hinPaIefef X-Received: by 2002:a05:6602:2182:: with SMTP id b2mr1424463iob.45.1632355899522; Wed, 22 Sep 2021 17:11:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632355899; cv=none; d=google.com; s=arc-20160816; b=JhMmKi8ocxKQw5yEHeZa1UWk2cEk+ynaZy+a75WlGTIZUM9nT6Owqlqn42YjsRLhV5 MhPAHPbF8pdwrFgKVcilSND0/3KvdmD3okT4SQ/z3NpVJEO8T6+RRyIdevU5Hp8ucw8+ T3/d+Ujgaizzua+Y+UO4w0KA4GSOTUZkfPlHz49OmA7kVyGhU+tp7XIsPPVijPeMyNqs 3rnfq+8qoGbPgrK4lZ3ZYgGv9PSBPLFitBE/mQGiWewNoOS+wVTcrhEU+LFwiYkZjTgB ofDsuKGusdouHhCMWeFHJxfmE0Irl7bRtB4Y/aqDqH70VAzbufnzZvH6duAhrdE3BOo7 HQPQ== 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:sender:dkim-signature; bh=iFkB5fme+CelwvcZTt3G4GpebT1AmOGCopDfcgu4IMY=; b=Xhkkar+1L8tCgzxs1NMFuzMncf6QY3JLb1DiH1SIn0AsIMuhKkjse0ULTq8RX+xfMa mp5H8Gd8MKKQO5Y2uuon/xGnXPpQHZ9Lyp0FGemYBWjQcc5DDMnqsRMSC169GfmTJtDB 8V77lhL69ho6sOQ0/lePOs/cpubI1HKbaFMLSuqeR3wBCC3SNKkhXJNq4LvezOFM7fjq VRFOekjPADUYxX+kkHD7qQXjZzYlkiDimWz0gdgAZTsAFzAgOO87LlTq12dQkpfPXLBL k61tkfzKMJoxslNq1AelI2kxAsidn7EJL0HlSCvShi2r1YzoEjVOGNrirJA/U/FSmvpW LHiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="K85On/qx"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x6si4536276ilv.42.2021.09.22.17.11.09; Wed, 22 Sep 2021 17:11:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="K85On/qx"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238613AbhIWALJ (ORCPT + 99 others); Wed, 22 Sep 2021 20:11:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234042AbhIWALI (ORCPT ); Wed, 22 Sep 2021 20:11:08 -0400 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 446C4C061574; Wed, 22 Sep 2021 17:09:38 -0700 (PDT) Received: by mail-pl1-x633.google.com with SMTP id x8so40149plv.8; Wed, 22 Sep 2021 17:09:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=iFkB5fme+CelwvcZTt3G4GpebT1AmOGCopDfcgu4IMY=; b=K85On/qxOX5mja29mIJTCOx8QbuXtejSE7cjRrSsQykEb5pzC2EsDIvMD7GR2F9UHf l/YnAm83eAPIyHB4fwfoDGdmRhB/iQwJ+Vn5Bv4C9iLSUuCjdHfd8Sf+PrZH8oTHBJoa WwQ52oYukfwPNtGV/UjasT3IZwZaP18E9fTsezick9dHV4wMdL+pEEd9e7+cmaJdE0cl NKnk/Gu4pX5mLbD+5xzB85t2KKTepllut9hWx+SXtdFQD/asR0ysVfW8lhVS+pg77oDH YiKATt58h+TJZftlgupWn1MoSCgB41r3rHhDFLGXhang2400Ndags2bYCIhuXq3dWsTh Li6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to; bh=iFkB5fme+CelwvcZTt3G4GpebT1AmOGCopDfcgu4IMY=; b=4i0AbHw3eH41kpjDWHhBeeKpZmTD49A57APn7ezr9fzRGPId28L490bGKGfX6n5cBX bxMXwFrtqE/jRtdB1cr+ymgNIGhpGbQPgVbEbIjNU4CtaEuvH4ZxGTIsVE0xgDkdXHIg XwzE1H+eAa0qCbIPOOeoIYHj6CJxCVNcqQo3Il8CUbgA8OaLpl2Y60ezszN1i75Nok/1 iMvsXxYnZpid0UAI1C6jIiDLxSCT/XUo3KXrJgviyMKsv1oLJIsP2GYEAhSsthHsDyhm pNFU36PeglFin2JpDBjrCgO1MPBUW3fQsCEMW3PQtFajYNKPwUrzSTrNurvE9w2ZYs0d w4eA== X-Gm-Message-State: AOAM532JT8YUH1UFJ6Dp74cxg8z5DhWP5o21K6qerY8tpCqFBrdW0j7i g7Qv3ntNbA9YuQ/6L8GDuhU= X-Received: by 2002:a17:902:ea10:b0:13c:ac71:386 with SMTP id s16-20020a170902ea1000b0013cac710386mr1333653plg.65.1632355777661; Wed, 22 Sep 2021 17:09:37 -0700 (PDT) Received: from google.com ([2620:15c:211:201:6a2a:9e3c:d2c:e8bc]) by smtp.gmail.com with ESMTPSA id nm23sm3443344pjb.26.2021.09.22.17.09.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Sep 2021 17:09:36 -0700 (PDT) Sender: Minchan Kim Date: Wed, 22 Sep 2021 17:09:34 -0700 From: Minchan Kim To: Brian Geffon Cc: Andrew Morton , Nitin Gupta , Sergey Senozhatsky , Jonathan Corbet , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-block@vger.kernel.org, Suleiman Souhlal , Jesse Barnes Subject: Re: [PATCH v3] zram: Introduce an aged idle interface Message-ID: References: <20210917210640.214211-1-bgeffon@google.com> <20210921194336.947226-1-bgeffon@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210921194336.947226-1-bgeffon@google.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 21, 2021 at 12:43:36PM -0700, Brian Geffon wrote: > This change introduces an aged idle interface to the existing > idle sysfs file for zram. > > When CONFIG_ZRAM_MEMORY_TRACKING is enabled the idle file > now also accepts an integer argument. This integer is the > age (in seconds) of pages to mark as idle. The idle file > still supports 'all' as it always has. This new approach > allows for much more control over which pages get marked > as idle. > > v2 -> v3: > - Correct unused variable warning when > CONFIG_ZRAM_MEMORY_TRACKING is not enabled. > v1 -> v2: > - Switch to using existing idle file. > - Dont compare ktime directly. > > Signed-off-by: Brian Geffon > --- > Documentation/admin-guide/blockdev/zram.rst | 8 +++ > drivers/block/zram/zram_drv.c | 60 +++++++++++++++------ > 2 files changed, 52 insertions(+), 16 deletions(-) > > diff --git a/Documentation/admin-guide/blockdev/zram.rst b/Documentation/admin-guide/blockdev/zram.rst > index 700329d25f57..8c8a92e5c00c 100644 > --- a/Documentation/admin-guide/blockdev/zram.rst > +++ b/Documentation/admin-guide/blockdev/zram.rst > @@ -328,6 +328,14 @@ as idle:: > From now on, any pages on zram are idle pages. The idle mark > will be removed until someone requests access of the block. > IOW, unless there is access request, those pages are still idle pages. > +Additionally, when CONFIG_ZRAM_MEMORY_TRACKING is enabled pages can be > +marked as idle based on how long (in seconds) it's been since they were > +last accessed, in seconds:: > + > + echo 86400 > /sys/block/zramX/idle > + > +In this example all pages which haven't been accessed in more than 86400 > +seconds (one day) will be marked idle. > > Admin can request writeback of those idle pages at right timing via:: > > diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c > index fcaf2750f68f..2af5cdb8da1a 100644 > --- a/drivers/block/zram/zram_drv.c > +++ b/drivers/block/zram/zram_drv.c > @@ -291,22 +291,16 @@ static ssize_t mem_used_max_store(struct device *dev, > return len; > } > > -static ssize_t idle_store(struct device *dev, > - struct device_attribute *attr, const char *buf, size_t len) > +/* > + * Mark all pages which are older than or equal to cutoff as IDLE. > + * Callers should hold the zram init lock in read mode > + **/ > +static void mark_idle(struct zram *zram, ktime_t cutoff) > { > - struct zram *zram = dev_to_zram(dev); > + int is_idle = 1; > unsigned long nr_pages = zram->disksize >> PAGE_SHIFT; > int index; > > - if (!sysfs_streq(buf, "all")) > - return -EINVAL; > - > - down_read(&zram->init_lock); > - if (!init_done(zram)) { > - up_read(&zram->init_lock); > - return -EINVAL; > - } > - > for (index = 0; index < nr_pages; index++) { > /* > * Do not mark ZRAM_UNDER_WB slot as ZRAM_IDLE to close race. > @@ -314,14 +308,48 @@ static ssize_t idle_store(struct device *dev, > */ > zram_slot_lock(zram, index); > if (zram_allocated(zram, index) && > - !zram_test_flag(zram, index, ZRAM_UNDER_WB)) > - zram_set_flag(zram, index, ZRAM_IDLE); > + !zram_test_flag(zram, index, ZRAM_UNDER_WB)) { > +#ifdef CONFIG_ZRAM_MEMORY_TRACKING > + is_idle = (!cutoff || ktime_after(cutoff, zram->table[index].ac_time)); > +#endif > + if (is_idle) > + zram_set_flag(zram, index, ZRAM_IDLE); > + } > zram_slot_unlock(zram, index); > } > +} > > - up_read(&zram->init_lock); > +static ssize_t idle_store(struct device *dev, > + struct device_attribute *attr, const char *buf, size_t len) > +{ > + struct zram *zram = dev_to_zram(dev); > + ktime_t cutoff_time = 0; > + ssize_t rv = -EINVAL; > > - return len; > + if (!sysfs_streq(buf, "all")) { > +#ifdef CONFIG_ZRAM_MEMORY_TRACKING > + u64 age_sec; > + /* If it did not parse as 'all' try to treat it as an integer */ > + if (!kstrtoull(buf, 10, &age_sec)) nit: Do we need such limit base which work with only 10 base? Passing 0 would give more flexibility. Otherwise, looks good to me. Thanks, Brian. > + cutoff_time = ktime_sub(ktime_get_boottime(), > + ns_to_ktime(age_sec * NSEC_PER_SEC)); > + else > +#endif > + goto out; > + } > + > + down_read(&zram->init_lock); > + if (!init_done(zram)) > + goto out_unlock; > + > + /* A age_sec of 0 marks everything as idle, this is the "all" behavior */ > + mark_idle(zram, cutoff_time); > + rv = len; > + > +out_unlock: > + up_read(&zram->init_lock); > +out: > + return rv; > } > > #ifdef CONFIG_ZRAM_WRITEBACK > -- > 2.33.0.464.g1972c5931b-goog >