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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C6A26EB64D9 for ; Thu, 15 Jun 2023 14:46:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4E7BF8E0001; Thu, 15 Jun 2023 10:46:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4971D6B0074; Thu, 15 Jun 2023 10:46:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 312818E0001; Thu, 15 Jun 2023 10:46:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 1DE106B0072 for ; Thu, 15 Jun 2023 10:46:22 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id C1D281408EF for ; Thu, 15 Jun 2023 14:46:21 +0000 (UTC) X-FDA: 80905257762.03.544E0A1 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf25.hostedemail.com (Postfix) with ESMTP id 87A88A0009 for ; Thu, 15 Jun 2023 14:46:18 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=GN3vsxd7; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf25.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1686840378; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=PnLmUoyxNluv5/vtd5/0yWU5N0tz3la7jPxFVnmntV4=; b=v8vb6CtN8G/LlA1XC+7lWSt68ETYnr+loWsU6Zm40XnmcrjnnZ5bBln7b1kNplL6H0OyY/ Xt1Cau8uYhCuUyIUUL4Gso+LMmFHKoi4BIJwFQ3FJ3xNe2EOR4leAqQ7SsxD86lnjbXMrC d7UbsoEMFXxE87/mxaZO0V5Go+WX8MM= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=GN3vsxd7; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf25.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1686840378; a=rsa-sha256; cv=none; b=pZNJP0XUf1u7nQRHdPN7/ON0Ax4BLNko9nMcdOQHnY1zvW4l06b/fAA9Oer/+liQJNdvob uTCyJEmq1MKC5fwo6c7n4P7DENt3Q2aeZmK9E4WkRP0H5eNKmCK1mfaRqPLfs9hEpY3cEv Z9tf3Zkj9A+pXpQAR3uKPA6n6xNI6Mw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686840377; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PnLmUoyxNluv5/vtd5/0yWU5N0tz3la7jPxFVnmntV4=; b=GN3vsxd7tUziNwbeW+wr50cCrMpxv9rZo5IPbGZBQofHTaj75XbKvXPSZ38n31ZL88jY9P imIgK9W9mu8nd+eqoTqKDPbmW64eddM0S7/Em28k9UmeEOZwRHx5vV5Dy80UtcHuxQpCTJ YUdwfyOuXNObp6mPJkDQc/sux/TDebo= Received: from mail-lj1-f198.google.com (mail-lj1-f198.google.com [209.85.208.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-531-4irvnk_OOFelBGSF930tsQ-1; Thu, 15 Jun 2023 10:46:13 -0400 X-MC-Unique: 4irvnk_OOFelBGSF930tsQ-1 Received: by mail-lj1-f198.google.com with SMTP id 38308e7fff4ca-2b36ed945abso12515651fa.1 for ; Thu, 15 Jun 2023 07:46:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686840372; x=1689432372; h=content-transfer-encoding:in-reply-to:subject:organization:from :content-language:references:cc:to:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=PnLmUoyxNluv5/vtd5/0yWU5N0tz3la7jPxFVnmntV4=; b=la42v0xX95FdBa7Ow2EtKNgi4LdgUJeYOXcGZD8pyFjMxg2xxUR+fuT1aUCq93fqRe 1q+HbshgW1HlVKA80tzfSadtp/MzvlAFV64V72LmZlhztqBNYz8AoLOQ4B7rFb0fPb6g aTIc1WdB30/gvFGp7esfPm22lhGNNx5LO7bplFOCbKLJsF6CNdMo23UYh8RuVWZ+s/oF J6LcPodeZHy1UccOiSSu+h4PNco2MtEcrTeBDkPMRCcIWs0N41Serqw95jtb22bozsqJ tiuy8N4VlAhh0XHO1+s/OqMZkDBjv9TpChWRfj9TlTvriYuTDcG00HorgbS+GzMpa6lZ n8AQ== X-Gm-Message-State: AC+VfDwODPzjMGhG5BdKrT/okifQ/gQxudoaxuuxb5n41fBCBUFVHf5P Ic5Ft+Kfg1zPrFbVO7bb+VbWqlLMZB4mXIGcpZNxUgWBSmTrYjfxREUzBMsL7cMYD7m5STFqjvW u39lBy+0niv4= X-Received: by 2002:a19:6445:0:b0:4f6:1e9c:cb11 with SMTP id b5-20020a196445000000b004f61e9ccb11mr9778914lfj.14.1686840371889; Thu, 15 Jun 2023 07:46:11 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7+WZ4YUQntw7WMkLcw0eXfwK8H6yFwvqd4w86K2UmyLFpVgf58ZbzhUZDRymx842mwEr515Q== X-Received: by 2002:a19:6445:0:b0:4f6:1e9c:cb11 with SMTP id b5-20020a196445000000b004f61e9ccb11mr9778896lfj.14.1686840371380; Thu, 15 Jun 2023 07:46:11 -0700 (PDT) Received: from ?IPV6:2003:cb:c70b:b500:4648:c96c:d6ba:4b8d? (p200300cbc70bb5004648c96cd6ba4b8d.dip0.t-ipconnect.de. [2003:cb:c70b:b500:4648:c96c:d6ba:4b8d]) by smtp.gmail.com with ESMTPSA id m6-20020adfdc46000000b0030e5bd253aasm21293470wrj.39.2023.06.15.07.46.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 15 Jun 2023 07:46:10 -0700 (PDT) Message-ID: <290d79bb-b1a6-3146-76a7-9938829e6ebe@redhat.com> Date: Thu, 15 Jun 2023 16:46:09 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 To: =?UTF-8?B?6LS65Lit5Z2k?= Cc: minchan@kernel.org, senozhatsky@chromium.org, mhocko@suse.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Matthew Wilcox References: <20230615034830.1361853-1-hezhongkun.hzk@bytedance.com> <3f54542e-235b-8456-f13f-786d21c6c14f@redhat.com> From: David Hildenbrand Organization: Red Hat Subject: Re: [External] Re: [RFC PATCH 1/3] zram: charge the compressed RAM to the page's memcgroup In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 87A88A0009 X-Stat-Signature: gzh39hyd36op9iia78qi8351184g1mkk X-HE-Tag: 1686840378-403612 X-HE-Meta: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ADm8Je0mda404GtrLEGggOA2FFASrT9MK184w5BcjcD8GlQ0JJ2CbLNmarHYIe98BK0E5SYEBe3qW2an4J81YIP/vr6F7w+pLBJUpWtxKcNMk9oOIouOwK4H+MM0keaVE0fLE/DjLWhk+Ykl+80x8qQyrqUzzEMPiGuGU94rhqbA9EBlI9dNrY4/zIM5v6ObvIpB44hlGNN9q4zyeQIJr6lkZriQGq1mFiysYuMLLyeYKJC1ujnTTy71j/UPFcF9HDEybWYEYWXZsewUlQPwuhMTzbyPNRoUSQYWdrZm4Y3KXSdyZmY/aKp 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: On 15.06.23 15:40, 贺中坤 wrote: >> I suspect for the swap->zram we should always get charged pages, because >> we're effectively writing out charged anon/shmem pages only -- without >> any buffer in between. > > Hi David,the charged memory will be released in swap->zram. New pages > are allocated by alloc_zspage(), and we did not charge the page directly,but > the objects(like slab), because the zspage are shared by any memcg. > >> >> For the fs->zram or direct zram access device case I'm not so sure. It >> highly depends on what gets mapped into the bio (e.g., a kernel buffer, >> zeropage, ...). If it's a pagecache page, that should be charged and >> we're good. No so sure about fs metadata or some other fs cases (e.g., >> write() to a file that bypass the pagecache). >> > > Yes, the pagecaches are charged in fs->zram, but will be released if > we drop the cache. the compressed objects are not charged. Yes. But just to stress again, one issue I see is that if there is a page in the BIO that is not charged, you cannot charge the compressed page. Assume you have some FS on that zram block device and you want to make sure it gets properly charged to whoever is reading/writing a file on that filesystem. (imagine something like a compress shmem) If a user (or the filesystem?) can trigger a BIO that has an uncharged page in it, it would not get charged accordingly. The "easy" reproducer would have been O_DIRECT write() using the shared zeropage, but zram_write_page() is smart enough to optimize for that case (page_same_filled()). :) Maybe I'm over-thinking this (well, the we do have partial I/O support, so something seems to be able to trigger such cases), and it would be great if someone with more FS->BIO experience could comment. I'll note that this is fundamentally different to zswap, because with zswap you don't get arbitrary BIOs, you get an anon or shmem page (that should be charged). -- Cheers, David / dhildenb