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 5A6EBC433EF for ; Mon, 21 Mar 2022 15:45:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A5F0A6B0071; Mon, 21 Mar 2022 11:45:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A0DCB6B0073; Mon, 21 Mar 2022 11:45:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8AEF06B0074; Mon, 21 Mar 2022 11:45:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0078.hostedemail.com [216.40.44.78]) by kanga.kvack.org (Postfix) with ESMTP id 7C1FB6B0071 for ; Mon, 21 Mar 2022 11:45:46 -0400 (EDT) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 2094618259E43 for ; Mon, 21 Mar 2022 15:45:46 +0000 (UTC) X-FDA: 79268818692.26.4F134B3 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf07.hostedemail.com (Postfix) with ESMTP id 6C51C40016 for ; Mon, 21 Mar 2022 15:45:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1647877544; 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=LEcCgqphKYDMQ8nkTkwtZzF2MNThCuORpVyyiw+cLk8=; b=KbXcJTF27TJZeWx+RHm0DmEjVIRMevkReYm8vf7xQCh1tBiHZT1WVoPqaQI7D2R3N/g1Ut PNxO0YdQeLjGO06/pUWYwQe2O5JQgMzMcTbC7tHlMHf8V4M8HdVhM7Og/55UhSSivw8/LA 9e5a7y4WBXu1VnibhphYwdMgTdIdZks= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-637-JFL0FbEpPfqRKpvbZVCorw-1; Mon, 21 Mar 2022 11:45:43 -0400 X-MC-Unique: JFL0FbEpPfqRKpvbZVCorw-1 Received: by mail-wr1-f71.google.com with SMTP id p18-20020adfba92000000b001e8f7697cc7so3194377wrg.20 for ; Mon, 21 Mar 2022 08:45:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent :content-language:to:cc:references:from:organization:subject :in-reply-to:content-transfer-encoding; bh=LEcCgqphKYDMQ8nkTkwtZzF2MNThCuORpVyyiw+cLk8=; b=daBvNJCd9ptRtEZj3H1ZK6fUu3EGVRFFwrwTXX6aecqk81zkCeQbeMGSfVAZJblsG2 Xz4YgNTt62mDCeu8sa0G+2m4rCKUTa4H7Wf8gTOLbfd6K+o2mnXoC0Al4vCgTkPyMPIc j0BhUIZLFZJzBVc6AUuq5fy9m7nz7KMjRROV/zjBL8TgJJgEB4kkz1ihvMzWJBzGq1O5 LEQZEfKhV/tu5cCwyqkQESemfUodYh8BNbJkZDruPyXJrK0SFnXN1AdC8FQL+oXg+/go asIU7IU1zULakFQQcIpZJCUR3z60zOk1zav5uPytmWUkxDl1DQf2XL3Yzc7A47tLt9FF Xrkg== X-Gm-Message-State: AOAM5301chMV1FXoGm4rkg8AjS+ieb3jSzUzCX1lADT6eog7VwJ5ASfE KpUzCggAZinrnFn68O10oks3bzOYQJ0mJD/ln+wUicOKfxEHlpOtb5fJQwMPkyJaSBpY0meJ4p/ 11feULKA3fz0= X-Received: by 2002:a5d:4b88:0:b0:203:e01b:b5ee with SMTP id b8-20020a5d4b88000000b00203e01bb5eemr18483725wrt.55.1647877542406; Mon, 21 Mar 2022 08:45:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwMB9TT7JI28MTYZUSUF+RpxNq0Rxuyljwc00j1MkZkn2gwkPuAEpfei4qhtvACTiw1OW/T+g== X-Received: by 2002:a5d:4b88:0:b0:203:e01b:b5ee with SMTP id b8-20020a5d4b88000000b00203e01bb5eemr18483710wrt.55.1647877542088; Mon, 21 Mar 2022 08:45:42 -0700 (PDT) Received: from ?IPV6:2003:cb:c704:4900:849b:f76e:5e1f:ff95? (p200300cbc7044900849bf76e5e1fff95.dip0.t-ipconnect.de. [2003:cb:c704:4900:849b:f76e:5e1f:ff95]) by smtp.gmail.com with ESMTPSA id r9-20020a05600c35c900b0038c7626c454sm12461150wmq.12.2022.03.21.08.45.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 21 Mar 2022 08:45:41 -0700 (PDT) Message-ID: <0414c610-7f56-2dd2-0d83-ac3a5194eb60@redhat.com> Date: Mon, 21 Mar 2022 16:45:40 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.6.2 To: CGEL Cc: bsingharora@gmail.com, akpm@linux-foundation.org, yang.yang29@zte.com.cn, linux-kernel@vger.kernel.org, linux-mm@kvack.org References: <20220316133420.2131707-1-yang.yang29@zte.com.cn> <412dc01c-8829-eac2-52c7-3f704dbb5a98@redhat.com> <6232970f.1c69fb81.4e365.c9f2@mx.google.com> <4e76476b-1da0-09c5-7dc4-0b2db796a549@redhat.com> <62330402.1c69fb81.d2ba6.0538@mx.google.com> <987bd014-c5ab-52cb-627e-2085560cb327@redhat.com> <6233e342.1c69fb81.692f.6286@mx.google.com> <2bb1c357-5335-9d96-d862-bd51c1014193@redhat.com> <6236c600.1c69fb81.7cd4.a900@mx.google.com> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH] delayacct: track delays from ksm cow In-Reply-To: <6236c600.1c69fb81.7cd4.a900@mx.google.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 6C51C40016 X-Stat-Signature: q4f5em89w4xpwut6pmyso6ojw4w61t9j X-Rspam-User: Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=KbXcJTF2; spf=none (imf07.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-HE-Tag: 1647877545-147312 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 20.03.22 07:13, CGEL wrote: > On Fri, Mar 18, 2022 at 09:24:44AM +0100, David Hildenbrand wrote: >> On 18.03.22 02:41, CGEL wrote: >>> On Thu, Mar 17, 2022 at 11:05:22AM +0100, David Hildenbrand wrote: >>>> On 17.03.22 10:48, CGEL wrote: >>>>> On Thu, Mar 17, 2022 at 09:17:13AM +0100, David Hildenbrand wrote: >>>>>> On 17.03.22 03:03, CGEL wrote: >>>>>>> On Wed, Mar 16, 2022 at 03:56:23PM +0100, David Hildenbrand wrote: >>>>>>>> On 16.03.22 14:34, cgel.zte@gmail.com wrote: >>>>>>>>> From: Yang Yang >>>>>>>>> >>>>>>>>> Delay accounting does not track the delay of ksm cow. When tasks >>>>>>>>> have many ksm pages, it may spend a amount of time waiting for ksm >>>>>>>>> cow. >>>>>>>>> >>>>>>>>> To get the impact of tasks in ksm cow, measure the delay when ksm >>>>>>>>> cow happens. This could help users to decide whether to user ksm >>>>>>>>> or not. >>>>>>>>> >>>>>>>>> Also update tools/accounting/getdelays.c: >>>>>>>>> >>>>>>>>> / # ./getdelays -dl -p 231 >>>>>>>>> print delayacct stats ON >>>>>>>>> listen forever >>>>>>>>> PID 231 >>>>>>>>> >>>>>>>>> CPU count real total virtual total delay total delay average >>>>>>>>> 6247 1859000000 2154070021 1674255063 0.268ms >>>>>>>>> IO count delay total delay average >>>>>>>>> 0 0 0ms >>>>>>>>> SWAP count delay total delay average >>>>>>>>> 0 0 0ms >>>>>>>>> RECLAIM count delay total delay average >>>>>>>>> 0 0 0ms >>>>>>>>> THRASHING count delay total delay average >>>>>>>>> 0 0 0ms >>>>>>>>> KSM count delay total delay average >>>>>>>>> 3635 271567604 0ms >>>>>>>>> >>>>>>>> >>>>>>>> TBH I'm not sure how particularly helpful this is and if we want this. >>>>>>>> >>>>>>> Thanks for replying. >>>>>>> >>>>>>> Users may use ksm by calling madvise(, , MADV_MERGEABLE) when they want >>>>>>> save memory, it's a tradeoff by suffering delay on ksm cow. Users can >>>>>>> get to know how much memory ksm saved by reading >>>>>>> /sys/kernel/mm/ksm/pages_sharing, but they don't know what the costs of >>>>>>> ksm cow delay, and this is important of some delay sensitive tasks. If >>>>>>> users know both saved memory and ksm cow delay, they could better use >>>>>>> madvise(, , MADV_MERGEABLE). >>>>>> >>>>>> But that happens after the effects, no? >>>>>> >>>>>> IOW a user already called madvise(, , MADV_MERGEABLE) and then gets the >>>>>> results. >>>>>> >>>>> Image user are developing or porting their applications on experiment >>>>> machine, they could takes those benchmark as feedback to adjust whether >>>>> to use madvise(, , MADV_MERGEABLE) or it's range. >>>> >>>> And why can't they run it with and without and observe performance using >>>> existing metrics (or even application-specific metrics?)? >>>> >>>> >>> I think the reason why we need this patch, is just like why we need >>> swap,reclaim,thrashing getdelay information. When system is complex, >>> it's hard to precise tell which kernel activity impact the observe >>> performance or application-specific metrics, preempt? cgroup throttle? >>> swap? reclaim? IO? >>> >>> So if we could get the factor's precise impact data, when we are tunning >>> the factor(for this patch it's ksm), it's more efficient. >>> >> >> I'm not convinced that we want to make or write-fault handler more >> complicated for such a corner case with an unclear, eventual use case. > > IIRC, KSM is designed for VM. But recently we found KSM works well for > system with many containers(save about 10%~20% of total memroy), and > container technology is more popular today, so KSM may be used more. > > To reduce the impact for write-fault handler, we may write a new function > with ifdef CONFIG_KSM inside to do this job? Maybe we just want to catch the impact of the write-fault handler when copying more generally? > >> IIRC, whenever using KSM you're already agreeing to eventually pay a >> performance price, and the price heavily depends on other factors in the >> system. Simply looking at the number of write-faults might already give >> an indication what changed with KSM being enabled. >> > While saying "you're already agreeing to pay a performance price", I think > this is the shortcoming of KSM that putting off it being used more widely. > It's not easy for user/app to decide how to use madvise(, ,MADV_MERGEABLE). ... and my point is that the metric you're introducing might absolutely not be expressive for such users playing with MADV_MERGEABLE. IMHO people will look at actual application performance to figure out what "harm" will be done, no? But I do see value in capturing how many COW we have in general -- either via a counter or via a delay as proposed by you. > > Is there a more easy way to use KSM, enjoying memory saving while minimum > the performance price for container? We think it's possible, and are working > for a new patch: provide a knob for cgroup to enable/disable KSM for all tasks > in this cgroup, so if your container is delay sensitive just leave it, and if > not you can easy to enable KSM without modify app code. > > Before using the new knob, user might want to know the precise impact of KSM. > I think write-faults is indirection. If indirection is good enough, why we need > taskstats and PSI? By the way, getdelays support container statistics. Would anything speak against making this more generic and capturing the delay for any COW, not just for KSM? -- Thanks, David / dhildenb