Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1008675pxb; Thu, 23 Sep 2021 15:54:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyFZJlJT6I2F4nCbtmzVnua7w6DXheEeJ53XPYpv6vrxvdyb7uz/2ghE/AfvYYc00+4iJ6i X-Received: by 2002:a05:6e02:1a21:: with SMTP id g1mr5454833ile.308.1632437647924; Thu, 23 Sep 2021 15:54:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632437647; cv=none; d=google.com; s=arc-20160816; b=mwmFT0eKReiOObaSW9diQFClvRkANCroUuPwHM8op9mhlZDkEq/eRuuDL66Nh7dbhL GrPkp8etCDwR3ra2XPv5yigXxWSe/19RERdPF2i9sL//hp6Fysu7DgS+CcVDUvotCgq4 vQuiYVtSJC80P/q8/8vjon/Ci0B0JwzCmANzF7CCwk+R01toRYkvDUAOZ1k02wvjDLq1 tZb9f5WWfeh0q3ZFyNR8/U8zH3vAjcW8naGY/Ztc0847LxbJycvwHkrbWEjgQRke/sAg ckGokqD0+GPlBIkLzW3QgdebqUqn1yK55b3F1kD9FJY9R7qFxpHvzTDQcC/Zovj/1ylI LPpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=pW6NSmZm/xKfsym8juUkHYF0o9u/1jWQyZoEVShQfWk=; b=jSZ0RmrKdAXYAUrTa7yB0992XpKg24IJeJcmkUieAiGuIalyETfuv4Rni7Q+ZSCm9M klVFAxbhJ3W7Ez0xJG9IKrnrJ3sdEaXByDl6GU1bb+EN+joJSEgoo2sfSqYrdHyR3sBp WbvX4tJ/YojD4g9himARrSIRqbtn82ZJEpxr1KoojSfxV3X5APhTzBQ4ZDx092L9y2ix CNpRjLOJ+v1+9LAaXQGL0/2E1/+Zsl8FW+cfSsHsU6vLLRnE/W011RRjYH88bW3PpBf/ ogfs1yuWtTgvjImIXCZNmRPQzU1djJT2FU5mIsapy/QJ5Hnsdkt9wKZrLTp7+P/Sz7/b g67A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=KZ3gMZwg; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o12si8460768ilj.142.2021.09.23.15.53.55; Thu, 23 Sep 2021 15:54:07 -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=@linux-foundation.org header.s=korg header.b=KZ3gMZwg; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243505AbhIWWym (ORCPT + 99 others); Thu, 23 Sep 2021 18:54:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:40624 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236363AbhIWWyl (ORCPT ); Thu, 23 Sep 2021 18:54:41 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4D4EA61050; Thu, 23 Sep 2021 22:53:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1632437589; bh=C3SYeyDKvKpb/ztYsrD8obNOu9dSdXZY8PFIa55n+74=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=KZ3gMZwg4rgJ9cLecymJdeyv6i54jC7zVxLOfjkazVUlux9mYsa73ABGN59P4idUi vuuJ7LslTKcm3niLg6ci5tCI5QkH6FfZMbvf+dXZp6sZAMKa4FePEb/vV/DSlnR+t8 rrRhkFGxbVQbFrgWJXjxie+JOSrcd/pPdSnyGya8= Date: Thu, 23 Sep 2021 15:53:08 -0700 From: Andrew Morton To: Brian Geffon Cc: Minchan Kim , 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 v4] zram: Introduce an aged idle interface Message-Id: <20210923155308.9b522a77a02ee13b76e9e613@linux-foundation.org> In-Reply-To: <20210923130115.1344361-1-bgeffon@google.com> References: <20210917210640.214211-1-bgeffon@google.com> <20210923130115.1344361-1-bgeffon@google.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 23 Sep 2021 06:01:15 -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. > > @@ -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 > + **/ A simple "*/" is conventional. > +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, 0, &age_sec)) > + cutoff_time = ktime_sub(ktime_get_boottime(), > + ns_to_ktime(age_sec * NSEC_PER_SEC)); > + else > +#endif > + goto out; > + } The ifdef tricks are pretty ugly. Can things be improved with IS_ENABLED()?