Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1445051pxj; Sat, 15 May 2021 15:21:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyinqrYGwuO+0VVJWzdQILhv6JMObNqSaQVUZ+xqiot8YutDIUNAmYkr0PWGYb8aGNQVgGi X-Received: by 2002:a50:d54c:: with SMTP id f12mr39507933edj.301.1621117299301; Sat, 15 May 2021 15:21:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621117299; cv=none; d=google.com; s=arc-20160816; b=TNvP1lXPKRUaTTARAHg45VJp0W0Qu+CNYodPfyNJBpPB+ivOgVwQCO+2gbYJ2GZhdM 5AQX0Fzaq6LjYbPxxnMnongu3phU7uSrxlwQDb4wJP93BltXWuBtU/NAo38wE/7FWNes inr6KHWt0D1EM9txEALhmeurhsCi5Fyg4rrhl/1iQfWcaksRYuoK5uyM/veLJSho/sZU TNsOezxBLERmxXOX27TZhfnAYrRDT6tJJ+6+9hKAIYAwtzTyOv6FgKuKY03wdJaVjYP6 km2iTYATgjKtdeP5mVcjtIO7Yu/b+9f91sqgbyhslpUkKfzGNT1mw/HaALzgdNPLHUlY TB7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:subject:message-id:date:from:mime-version :dkim-signature; bh=aQBg6T7d9Y0+Xn06ivGBtdjETmzJrfo4DD7Uy3V5ikU=; b=RUDjFGKn7JEWte/UzTo7vEhuQUMyvA9wtjsx4xDmCD13CfWpNcCQTo43WyKfm2K8nV xrZY1kLnvYTMc317xotIY9OLNvwtEDOnYOzekLoYuBnsT0/UPkSYBFO3TrBDDiTMHqC3 wcwByEH38DCv9XXtLeRBSnI5+L4kQAsIMCqdwT52TGPoj93DDiZpFLIge/8V5Xf8QLxc HLAZSgZ0M9MzxIuqWMWba7/0T7BB2qqweOWZnQSAja5RdD6GuHPBo8I7DNKFW6B9qLdP vjvzaekPsktj2XTN6C88+beGMBBDnDO0JJxHnKVW7URojwYryXmMTz4ChIt6DeIZpT0W R7Nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=DRbNvSfK; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t9si9497119edd.64.2021.05.15.15.21.15; Sat, 15 May 2021 15:21: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=20161025 header.b=DRbNvSfK; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232717AbhEOPfA (ORCPT + 99 others); Sat, 15 May 2021 11:35:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232479AbhEOPe6 (ORCPT ); Sat, 15 May 2021 11:34:58 -0400 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 695B3C061573 for ; Sat, 15 May 2021 08:33:43 -0700 (PDT) Received: by mail-ed1-x533.google.com with SMTP id df21so1873344edb.3 for ; Sat, 15 May 2021 08:33:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=aQBg6T7d9Y0+Xn06ivGBtdjETmzJrfo4DD7Uy3V5ikU=; b=DRbNvSfKgW7wWtguAL+RxF7O56fKmVFhWoka97yCLnnKqAFTdsPnQQpp0SkDq0lHSt legr+bRzSV8Uab51GrQrScomILgWMDQ4VUOoBSxngt4JR2QUKJIdJJvzFz9cenQvdCCX OYsFtNsrAB29fXqkJ6oFND6+seB06/wLir3rXG5VX58upevML/D/uRuxz31Qv1ugSEVw NOhedLuA2m1Q2fom5jp5FYJNGzEzvmmzsH0kOpct+Xt0gSELZ8urO7N1WG9pHzrFfUSw v/HFfosdmc6MnYRsWzGyBY9S/gu3yg53BpNE88/C/s7Ibu84aMZLLbnKGcek1Zwu2zCz IG8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=aQBg6T7d9Y0+Xn06ivGBtdjETmzJrfo4DD7Uy3V5ikU=; b=sMNFhZYrPE2ejSwIa0uGtQZmHe7K5eGVde5t8H5ytLJacfRuzqAAypsbbK+y2NKpwM ef5ATj8JYJWuiDf6F6k58v+UJ3zRVxGgUzdkAtoc6nD7OgmqhkMUCAXyWgKJ9XlQYO+s gs+LfAKP2mw3SlsBNZR3GPRhH7t2064Z+KYUBIjETfri4BFs9bjg4eiOmMC0dZk1fO7c GuiPydJ61PlaiY1CEMBxudk3Fek9XhOmwAIrLCro5CNl/TKOpnNHAch82I80xeoSETsh wyssD4pkyKQLKzwyX2oIhMgJ3D3LpG7PJgLb3z/3qK5mpLrcfXh2Pil2g5TfA+LYc5eW X5gA== X-Gm-Message-State: AOAM530Lcz4/MoG+PIFi0Uu9EgfB+/fKn7Kg8MhkavS/6Kcnkn+fqSVF Nyome5hUU+zlZNZMD8Po6vFVn2t6WY914veYwPceOpuRfZNUKg== X-Received: by 2002:a50:f388:: with SMTP id g8mr4040008edm.236.1621092821757; Sat, 15 May 2021 08:33:41 -0700 (PDT) MIME-Version: 1.0 From: yong w Date: Sat, 15 May 2021 23:33:29 +0800 Message-ID: Subject: How to calculate available memory when zram is used? To: linux-kernel@vger.kernel.org, minchan@kernel.org, ngupta@vflare.org, sergey.senozhatsky.work@gmail.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org How to calculate available memory when zram is used? Available+Swap free memeory is obviously bigger than I actually can use, because zram can compress memory by compression algorithm and zram compressed data will occupy memeory too. Is there any way to calculate available memory accurately? I think of a way is to count the compression rate of zram in the kernel. The available memory is calculated as follows: available + swapfree - swapfree * compress ratio Is it reasonable?