From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44361C48BCF for ; Wed, 9 Jun 2021 14:23:53 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C8CB4613B1 for ; Wed, 9 Jun 2021 14:23:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C8CB4613B1 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 200E16B0036; Wed, 9 Jun 2021 10:23:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1BD896B006C; Wed, 9 Jun 2021 10:23:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 004226B0070; Wed, 9 Jun 2021 10:23:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0164.hostedemail.com [216.40.44.164]) by kanga.kvack.org (Postfix) with ESMTP id BD8886B0036 for ; Wed, 9 Jun 2021 10:23:51 -0400 (EDT) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 4DDCA181AEF21 for ; Wed, 9 Jun 2021 14:23:51 +0000 (UTC) X-FDA: 78234404262.06.3FF885B Received: from mail-ej1-f49.google.com (mail-ej1-f49.google.com [209.85.218.49]) by imf14.hostedemail.com (Postfix) with ESMTP id AF6E6C0042ED for ; Wed, 9 Jun 2021 14:23:46 +0000 (UTC) Received: by mail-ej1-f49.google.com with SMTP id g20so38837591ejt.0 for ; Wed, 09 Jun 2021 07:23:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=jtL1+5VQHHT8bzDFTG2ayogpB519w3lSL+Ow8WttPMA=; b=bmayfmCa0b8f9xI0EN93lA+4Gr8gdpDsGMUtuuHdKOBRuNHiElMrY97YuAXFpkVpgl 1H+aeXWXejLcxhKStK8Iei4Mc8+Q+Y8abAmOGxF3/Wub3CTT6IpzeDljPidc3GF3mb1+ ekWE3VxjK6/3QOye90lKkdGejbfI+Kei0nDjmTYaL39jK0hcjrKrYSbjvNWOCUB/PLEQ UQTOn/OADOX5FdqH8vEpDQrsTammsbdJghutnEujOC91yNzdbyWkkzMT5Vms5McQlSHm MD3/bxryn7X5hfCb/LIwtkBnhMGXrLgA9iRcE+vDGQwc/5Qou3awCa4MbnajTJDYjjDL 9dTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=jtL1+5VQHHT8bzDFTG2ayogpB519w3lSL+Ow8WttPMA=; b=KdzilDHfDagebquWE4PXLrH5MoCIQTxt+dfIwEcMp4R3bqHkVegqbw7qTS0S6dzrZc 5MjOTNvVDX0yxB009VGSDllvsm78IZC2wFL7yhriYOWtd5arPaEYBGGHUOXE63KEAVI+ QfN+PIsKqM/qRbGm1MNmFidJwPNmmun+te4+RxsDFuSEGSuTh6lIJqPF5aAGivAkRnkF LvEIZ7H3QajIvkIkdgDmnzjXuf1scrjor2uTTVA2qP79aoE1zueVP+gUbvra8Ie2EDoL dFqO8E1gkRKtrhX3aZPM7b8BaBk13QUgqKMcvdakNApyiQFKLwrp//odOuXzsaP4AjXz 7zeQ== X-Gm-Message-State: AOAM533JOphmnX+/2kEZfJ3Dpg3qhs540+vO3p8VVgvRJb1bDFXTu0es f173E9jaeu2ViXareHCz9jahiDs0yzLN7T9qzzY= X-Google-Smtp-Source: ABdhPJxup4vdQ3fDE/7P6t/FNZhoFn65HkkE9BnRji/N8/MGMInqiSMlbelQzof1+ZT715dm1myxEI3Bv7rwTDgIckU= X-Received: by 2002:a17:906:cc14:: with SMTP id ml20mr91751ejb.515.1623248629776; Wed, 09 Jun 2021 07:23:49 -0700 (PDT) MIME-Version: 1.0 References: <1623080354-21453-1-git-send-email-yongw.pur@gmail.com> In-Reply-To: From: yong w Date: Wed, 9 Jun 2021 22:23:36 +0800 Message-ID: Subject: Re: [RFC PATCH V3] zram:calculate available memory when zram is used To: Greg KH Cc: minchan@kernel.org, ngupta@vflare.org, senozhatsky@chromium.org, axboe@kernel.dk, akpm@linux-foundation.org, songmuchun@bytedance.com, David Hildenbrand , linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-mm@kvack.org, willy@infradead.org, linux-api@vger.kernel.org, lu.zhongjun@zte.com.cn, yang.yang29@zte.com.cn, zhang.wenya1@zte.com.cn, wang.yong12@zte.com.cn Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=bmayfmCa; spf=pass (imf14.hostedemail.com: domain of yongwpur@gmail.com designates 209.85.218.49 as permitted sender) smtp.mailfrom=yongwpur@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Stat-Signature: 3uzudftibigmxwpkan8cx4h81my7fedf X-Rspamd-Queue-Id: AF6E6C0042ED X-Rspamd-Server: rspam06 X-HE-Tag: 1623248626-526374 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: Greg KH =E4=BA=8E2021=E5=B9=B46=E6=9C=888=E6= =97=A5=E5=91=A8=E4=BA=8C =E4=B8=8B=E5=8D=885:29=E5=86=99=E9=81=93=EF=BC=9A > > On Mon, Jun 07, 2021 at 08:39:14AM -0700, yongw.pur@gmail.com wrote: > > From: wangyong > > > > When zram is used, available+Swap free memory is obviously bigger than = we > > actually can use, because zram can compress memory by compression > > algorithm and zram compressed data will occupy memory too. > > > > So, we can count the compression ratio of zram in the kernel. The space > > will be saved by zram and other swap device are calculated as follows: > > zram[swapfree - swapfree * compress ratio] + swapdev[swapfree] > > We can evaluate the available memory of the whole system as: > > MemAvailable+zram[swapfree - swapfree * compress ratio]+swapdev[swapfre= e] > > Why is this needed to be exported by userspace? Who is going to use > this information and why can't they just calculate it from the exported > information already? In embedded devices, it is necessary to assess how much memory is available= . If the memory allocation is based on available+swapfree, it may cause oom a= nd affect the normal use of the devices. And it is more accurate and safe to calculate the swap available memory through minimum compression ratio. Although mm_stat interface provides compressed information=EF=BC=8Cbut it i= s not easy to get the minimum compression ratio during swaping out. Kernel provides a com= mon interface, which makes it easier to use and judge the state of system memor= y > What tool requires this new information and what is it going to be used > for? It can be used in embedded devices to evaluate the memory condition and avoid causing oom; Also If we wants to know more accurate available memory information when zram is used. > And why add a block driver's information to a core proc file? Shouldn't > the information only be in the block driver's sysfs directory only? > > thanks, > > greg k-h I thought it would be better to put it there. In the first patch, MemAvailable returned with swap available memory, and David recommended a separate interface. thanks