Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1929964rwi; Tue, 11 Oct 2022 02:22:26 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6a7cYymHy/7/P+J7BnTGCl1pkJ3KrsK8YUTBVbO9kC2ZiO57ISUI6qDIxDz9/p/t+6xga8 X-Received: by 2002:aa7:c58a:0:b0:459:1511:6cff with SMTP id g10-20020aa7c58a000000b0045915116cffmr22213815edq.27.1665480146700; Tue, 11 Oct 2022 02:22:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1665480146; cv=pass; d=google.com; s=arc-20160816; b=LyBzypqJWOjpTfa7jTGbcKxb18zcVtxApE1D6I8fH6ZR1DCNzWL+zyZJxfJytGuIbA SE3/VB4Orv/UBYAYgDXMOOK6UP72m5Ml52CpvKzxknega8OjzQehc0HwDy1oGvNlpDzF eHQ23HgMg+yA1XE7Hmwi62rlA6IU8p0pEhbqL/y6h/qLSk1PNUoF29Y1EZaZtKUS+yQ3 vIE3E2cdEtC0DMXhQRLPEwD8DseV++gHNfWK77Xg6Ki9Lf2yuvEgDoKDISUexoUc9+vj 8tjgGCF+Y6Hk5JoYEXqF11XrhxpM9ymUJquJ6ysEQqQDJRAIBszLQ4uKC3jEWJ7PiZSL 2v+g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :in-reply-to:from:references:cc:to:subject:user-agent:date :message-id:dkim-signature; bh=aveS7Oc2DgajbrPwXJIs0BkKfhw8UP8x8pZe/pkwvuU=; b=sV9tP1+ytaGvPZQznHCo9nBI+IZGZ34uGDBy74jXhp4YIuyvcmg8pBlturNCSiGAPp 66gyDyrI7BZUOjmUpsCh8MVMrIUDlSOlMnfCDJ2ZugXzw6/m+IPtmXAXVOlfiLqYtF1O reme0BasEkRhoxt0t4ngDDHlX+H+CSPqD7z1CtEJyoJYbppmvpbxTBbi5GKT+d5czD64 FBmhgFSugdUptnN9zFoBqNdF5mZhOEawoGXllPm+4K8yoEUZGVXn2scU/xhQPlRLD2Nt AFyCfLg6EGsUsTP74JVYbO22RwQ+8Tzm84n0IBVyYd60OYOWPI3mvXXUDNZ9bleqkMjB 9V1g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=selector2 header.b=fijy0y+Q; arc=pass (i=1 spf=pass spfdomain=virtuozzo.com dkim=pass dkdomain=virtuozzo.com dmarc=pass fromdomain=virtuozzo.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v24-20020aa7dbd8000000b00447a8836a56si10152572edt.208.2022.10.11.02.21.58; Tue, 11 Oct 2022 02:22:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=selector2 header.b=fijy0y+Q; arc=pass (i=1 spf=pass spfdomain=virtuozzo.com dkim=pass dkdomain=virtuozzo.com dmarc=pass fromdomain=virtuozzo.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229506AbiJKJHk (ORCPT + 99 others); Tue, 11 Oct 2022 05:07:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229854AbiJKJHf (ORCPT ); Tue, 11 Oct 2022 05:07:35 -0400 Received: from EUR03-VI1-obe.outbound.protection.outlook.com (mail-vi1eur03on2092.outbound.protection.outlook.com [40.107.103.92]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2DF8D220E1 for ; Tue, 11 Oct 2022 02:07:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Dip6R2dxODmYn+bZdmVl35QRNbjwYHL7/oH6cslTH2+UplLCgjgWzrqOeGTUz8d3QRJBpqhBjHvEI2BQT/WGg6b4nVIXPmvxkDZwHrzpSERixsLaKkXZHkaRGGBxpF0HB/A64lH8zauWmC2gJ212A3FdqrccvWQJiIqyGKegMl6Eth/MD79tfqXRTBkCeHFDVNlfQim0kmwJ7zdg+/h6WULp5eECcLPvRkHQddf9203F55la/J11/ypUvMJrn+BYJoBu8/dL9Of1et3W4pNS3Rl0kGQWTlgHT842nScmasTUcbdVgclboqi3j7OzYd6KMU915d5L/6TtcbHv3bKcvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=aveS7Oc2DgajbrPwXJIs0BkKfhw8UP8x8pZe/pkwvuU=; b=Ltr8jIbMlx9zRzbk4RroGf847fa4iEBu2qQV7AtZy+9An6xEgF43jVTM5bqEFY6O7Wus0qfzFcjrNztNrl+zEfrkhEJFtW2LppWE0Mrv+nwXMR0T+QuCkGykmspKTxfbGatZQIiW/0mxv5bBSck+9U+CArowM6HuRM2FyELlNePn40hmgMotgQ0fvsXXGyhxjhxU/SvhnMHYfCqidk5IX0nuNp+QCEttaeFqgwzJ5R2meWM0omvqsAyFDsrtMYwj513MdY0IdVQMD7nUfheCie4Se9E62dr9bSF9Y+FcKyJmvSKYQlyznGbXY01Gdikqvcbmiv34x43SfmJZyQ4L2A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=aveS7Oc2DgajbrPwXJIs0BkKfhw8UP8x8pZe/pkwvuU=; b=fijy0y+Qc2CJ1Y1Nt7PSy6NxCvMn4WYaSewWyxqwq0h362nAMXjBzokBL4Dn8id/JyQozc/ucg3qyr+UwPq3lhomzlQa+SSdMpkYIMB9OtyeZ+n0xzSel8T2a1v8xj/EMioOzlEGeloNvs/cIOIQPFGQkyEpE0FD5erOb8VO//jO6fzwqNM7b5KFjfMYxmCqDSaqXdveuF9WsQ8EgDrqP1fRW+y6Iz0nTwDVc473tc0pMg2U+fsMZqdYzqGuirn7Rtb3xjFcxW8Lh7CQrm+QaFGDtEXx957BQaK4NgzYCcyLLet42EiI3YkSoqpVrUgwLiFK+n8QOmLcR1rlTQZWrw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from VE1PR08MB4765.eurprd08.prod.outlook.com (2603:10a6:802:a5::16) by DB9PR08MB9729.eurprd08.prod.outlook.com (2603:10a6:10:45c::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5709.15; Tue, 11 Oct 2022 09:07:30 +0000 Received: from VE1PR08MB4765.eurprd08.prod.outlook.com ([fe80::6809:fef7:a205:b08a]) by VE1PR08MB4765.eurprd08.prod.outlook.com ([fe80::6809:fef7:a205:b08a%7]) with mapi id 15.20.5709.019; Tue, 11 Oct 2022 09:07:30 +0000 Message-ID: <7ba328e5-3bc8-cb22-f00c-eddb8aea9a06@virtuozzo.com> Date: Tue, 11 Oct 2022 12:07:28 +0300 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.3.1 Subject: Re: RFC [PATCH v4 2/7] Enable balloon drivers to report inflated memory To: Nadav Amit Cc: "Michael S. Tsirkin" , David Hildenbrand , Andrew Morton , kernel@openvz.org, Linux Virtualization , LKML , Linux MM References: <20221005090158.2801592-1-alexander.atanasov@virtuozzo.com> <20221005090158.2801592-3-alexander.atanasov@virtuozzo.com> <88EDC41D-408F-4ADF-A933-0A6F36E5F262@gmail.com> <42C75E59-696B-41D5-BD77-68EFF0B075C6@gmail.com> <71E14334-CA3B-45FB-A854-7A8D6649C798@gmail.com> <1118F098-972A-4F58-8EE1-270A06E4F9D1@gmail.com> From: Alexander Atanasov In-Reply-To: <1118F098-972A-4F58-8EE1-270A06E4F9D1@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: FR3P281CA0032.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::13) To VE1PR08MB4765.eurprd08.prod.outlook.com (2603:10a6:802:a5::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VE1PR08MB4765:EE_|DB9PR08MB9729:EE_ X-MS-Office365-Filtering-Correlation-Id: d6598222-2a25-443e-79a9-08daab68069a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: R0+0ZhAdcEqt81LoF70VNcU2GkTMzP2RMgARfHPIh2mx7KFellMDjmCkVEAe2v8SVLJ8UzTwOqlT0FZ64pw+dbpMjBDPnHGnavlhxCiYPDdtAaZWDkZ/p3jibCjdRK/en72svzSwvA+soipGPlRSDCgBvYZ9zmnwnapIxA9Ugs8bonVk9mkfuaicEtaK0Lg7TGHdZ3wglRT90hJrOiwDySqHZqkyfZ7h2qGvGF4GjLENIJQg9g5vz7fqxJ7ATY4RCbKGiugrIip7xlFhYClNhn2VZAXZM643e1UoSLHiQu0k5toIEsHIHEyfotVW6hLcXUFJDgxIOe+/2Sb62E2NIHF7yvi97mnVkFSiPPaNdOXtSIjIXLbdBOcoMDBPdIBRCMLL5fUHjY9pPOaLSEQEjKba4i/tDIaKKmnkjGW4TiLNeMohkMChLOj2L6d391xwe8/qR+giJbvMvezT3EzJNbSREzvDVR0+FlQETdT9CZPvNHgxgEEe50/OyyewnSxH7JzknW9jGqTVFOCf/l2DiM4nw75j9X3njxOMapceFGQPYZPJcCwv9CPfb754b2nscEcSQikhp/bEqAioctnFlT3Vt+0oSr/uGq5wBRaUB+yAYb+ZTnawwKm61jkMtEoLUZhl8vlnITe9u2Mhx1YWfvwiOOY4w+b7v1Axko5uoVJQwo9mDS+QZGthlKlIZUAEib46adpwcwM/KQHJa/NXsMrmxrK6GHwaiuTP2de/qnh3ujI+5Vd2oUFS/DcZy73V+y3CI+KnytauiQDyASa0C9FKXD3X8jVsX3wzUrq7KACbyzjRpBe1iFeW+bDZlaTZ X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VE1PR08MB4765.eurprd08.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(366004)(396003)(39850400004)(346002)(376002)(136003)(451199015)(31696002)(86362001)(38100700002)(4326008)(8676002)(66556008)(66476007)(316002)(66946007)(6916009)(2906002)(36756003)(8936002)(44832011)(54906003)(966005)(5660300002)(41300700001)(186003)(2616005)(6486002)(6512007)(83380400001)(478600001)(6506007)(26005)(53546011)(31686004)(43740500002)(45980500001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?dmd0ajZoN1U3Wm5EUWxKZEZUdjM5NUxYWjBBcFVIZnJCMTNRcUJLaElXaW1s?= =?utf-8?B?VkFkQVU3b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U9peFpPMkZTMWw2akRv?= =?utf-8?B?VXZGT21KOFlKeWFKaTIrNFRUcWQ4aGVsaTIvR1h6cXpYSklsUDFmOWc4dFhK?= =?utf-8?B?NGFPc2RDYUFQQzVRUUlldVEzZnBvY3RhNlE3NWFHR29tdzRZbDZ6YVZpc1dy?= =?utf-8?B?cTNnNHNDOVcxa2Yxby9SbEd3VTU2aW5vU2QzYlRiZHNFQ3VOWGZmMVNQNkRm?= =?utf-8?B?NjdZSDVIYVVVdm0xOVBrcnNxc2ErSzZRQXFkVkNvaTJxWUhxcUJvYjBJbzhE?= =?utf-8?B?QkgrR3VNdzZlRnRrbXJMOTBYTmZSK2NOK3dOVEFVL2lqaHZLRi9GUnZJTzZi?= =?utf-8?B?V1E9PQ==?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: d6598222-2a25-443e-79a9-08daab68069a X-MS-Exchange-CrossTenant-AuthSource: VE1PR08MB4765.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2022 09:07:30.3800 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 9cIe5l1x9XcO1jsb0NnLDLe1YVTQkhNsAFZcMbaOsWitM8ROOCHS95XyUimfHyQOTwJnHAjrLlnmWy6UfECI5Ver5UiT4Q5XOIWuVLaSXFFeUq3qG8xXTQBEOhHQCCUA X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR08MB9729 X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO,NICE_REPLY_A, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello, On 10.10.22 17:47, Nadav Amit wrote: > On Oct 10, 2022, at 12:24 AM, Alexander Atanasov wrote: > >> Hello, >> >> On 10.10.22 9:18, Nadav Amit wrote: >>> On Oct 7, 2022, at 3:58 AM, Alexander Atanasov wrote:> [snip] >>> Side-note: That’s not the case for VMware balloon. I actually considered >>> calling adjust_managed_page_count() just to conform with other balloon >>> drivers. But since we use totalram_pages() to communicate to the hypervisor >>> the total-ram, this would create endless (and wrong) feedback loop. I am not >>> claiming it is not possible to VMware balloon driver to call >>> adjust_managed_page_count(), but the chances are that it would create more >>> harm than good. >> >> Virtio does both - depending on the deflate on OOM option. I suggested already to unify all drivers to inflate the used memory as it seems more logical to me since no body expects the totalram_pages() to change but the current state is that both ways are accepted and if changed can break existing users. >> See discussion here https://lore.kernel.org/lkml/20220809095358.2203355-1-alexander.atanasov@virtuozzo.com/. > > Thanks for the reminder. I wish you can somehow summarize all of that into the > cover-letter and/or the commit messages for these patches. I will put excerpts in the next versions and relevant links in the next versions. I see that the more i dig into it the deeper it becomes so it needs more explanations. >> >> >>> Back to the matter at hand. It seems that you wish that the notifiers would >>> be called following any changes that would be reflected in totalram_pages(). >>> So, doesn't it make more sense to call it from adjust_managed_page_count() ? >> >> It will hurt performance - all drivers work page by page , i.e. they update by +1/-1 and they do so under locks which as you already noted can lead to bad things. The notifier will accumulate the change and let its user know how much changed, so the can decide if they have to recalculate - it even can do so async in order to not disturb the drivers. > > So updating the counters by 1 is ok (using atomic operation, which is not > free)? And the reason it is (relatively) cheap is because nobody actually > looks at the value (i.e., nobody actually acts on the value)? > > If nobody considers the value, then doesn’t it make sense just to update it > less frequently, and then call the notifiers? That's my point too. The drivers update managed page count by 1. My goal is when they are done to fire the notifier. All drivers are similiar and work like this: HV sends request inflate up/down driver up/down lock get_page()/put_page() optionally - adjust_managed_page_count(... +-1); unlock update_core and notify_balloon_changed >>>> The difference is here: >>>> >>>> mm/zswap.c: return totalram_pages() * zswap_max_pool_percent / 100 < >>>> mm/zswap.c: return totalram_pages() * zswap_accept_thr_percent / 100 >>>> uses percents and you can recalculate easy with >>>> >>>> +static inline unsigned long totalram_pages_current(void) >>>> +{ >>>> + unsigned long inflated = 0; >>>> +#ifdef CONFIG_MEMORY_BALLOON >>>> + extern atomic_long_t mem_balloon_inflated_free_kb; >>>> + inflated = atomic_long_read(&mem_balloon_inflated_free_kb); >>>> + inflated >>= (PAGE_SHIFT - 10); >>>> +#endif >>>> + return (unsigned long)atomic_long_read(&_totalram_pages) - inflated; >>>> +} > > So we have here two values and it appears there is a hidden assumption that > they are both updated atomically. Otherwise, it appears, inflated > theoretically might be greater that _totalram_pages dn we get negative value > and all hell breaks loose. > > But _totalram_pages and mem_balloon_inflated_free_kb are not updated > atomically together (each one is, but not together). > I do not think that can happen - in that case totalram_pages() is not adjusted and you can never inflate more than total ram. Yes, they are not set atomic but see the use cases: - a driver that does calculations on init. It will use notifier to redo the calculations. The notifier will bring the values and the size of change to help the driver decide if it needs to recalculate. - a user of totalram_pages() that does calculations at run time - i have to research are there any users that could be affected by not setting the two values atomicaly - assuming there can be a slight difference. I.e. do we need precise calculations or they are calculating fractions. >>>> And you are good when you switch to _current version - si_meminfo_current is alike . >>>> >>>> On init (probably) all use some kind of fractions to calculate but when there is a set value via /proc/sys/net/ipv4/tcp_wmem for example it is just a value and you can not recalculate it. And here, please, share your ideas how to solve this. >>> I don’t get all of that. Now that you provided some more explanations, it >>> sounds that what you want is adjust_managed_page_count(), which we already >>> have and affects the output of totalram_pages(). Therefore, totalram_pages() >>> anyhow accounts for the balloon memory (excluding VMware’s). So why do we >>> need to take mem_balloon_inflated_free_kb into account? >> Ok, you have this: >> / totalram >> |----used----|b1|----free------|b2| >> >> drivers can inflate both b1 and b2 - b1 free gets smaller, b2 totalram pages get smaller. so when you need totalram_pages() to do a calculation you need to adjust it with the pages that are inflated in free/used (b1). VMWare is not exception , Virtio does the same. >> And according to to mst and davidh it is okay like this. >> So i am proposing a way to handle both cases. > > Ugh. What about BALLOON_INFLATE and BALLOON_DEFLATE vm-events? Can’t this > information be used instead of yet another counter? Unless, of course, you > get the atomicity that I mentioned before. What do you mean by vm-events ? >>> Sounds to me that all you want is some notifier to be called from >>> adjust_managed_page_count(). What am I missing? >> >> Notifier will act as an accumulator to report size of change and it will make things easier for the drivers and users wrt locking. >> Notifier is similar to the memory hotplug notifier. > > Overall, I am not convinced that there is any value of separating the value > and the notifier. You can batch both or not batch both. In addition, as I > mentioned, having two values seems racy. I have identified two users so far above - may be more to come. One type needs the value to adjust. Also having the value is necessary to report it to users and oom. There are options with callbacks and so on but it will complicate things with no real gain. You are right about the atomicity but i guess if that's a problem for some user it could find a way to ensure it. i am yet to find such place. -- Regards, Alexander Atanasov