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 84EC0C433EF for ; Wed, 11 May 2022 02:19:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BC4346B0071; Tue, 10 May 2022 22:19:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B72A56B0072; Tue, 10 May 2022 22:19:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A14006B0073; Tue, 10 May 2022 22:19:39 -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 93C3C6B0071 for ; Tue, 10 May 2022 22:19:39 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 6BFDD61F05 for ; Wed, 11 May 2022 02:19:39 +0000 (UTC) X-FDA: 79451856078.28.51A9297 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by imf15.hostedemail.com (Postfix) with ESMTP id DEF81A0092 for ; Wed, 11 May 2022 02:19:26 +0000 (UTC) Received: by mail-pl1-f174.google.com with SMTP id s14so502079plk.8 for ; Tue, 10 May 2022 19:19:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:from:to:cc:subject:references:mime-version :content-disposition:in-reply-to; bh=iOQsmKhE+QYLxlfOvaiJ7/uZihyRqcydotN8UT2grzk=; b=ckn4xqwpqLh1KdI/cP99nep/Gpf0f4YULWG2yE1siFHCa56FOuA/1bRjNSSpaZA4pW fAxEH+XM1mGBsAkVwHob3tml3YTmD+xRqUvY64xGIONsysx82gG3NeLMchX35vb3SkCQ GGtU9Yoi7+GhmjMXRQrkkofCC4tWRHH0uLBCDNPzb1gYVGlwqY+83xG9Q4BB7zUzxNvg Pw0LgbAUpctjdTmtf4v42EGIE9D0vqnBLwaNsi7ndpM67zmubzkz+EosmphbVbYBr2w+ LgjS1ZRlqf8Yn29EIKiH2vvXuMzQIVuyVzSIeXEeyhrZs4yffXp/+1P45ADC0y0I6OCF XhHA== 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:from:to:cc:subject:references :mime-version:content-disposition:in-reply-to; bh=iOQsmKhE+QYLxlfOvaiJ7/uZihyRqcydotN8UT2grzk=; b=mie2vSODufy40aG9wF7b8GnQVpwG/4zHWx48jfRPimJRz2GeFK9JLbHzje2n3AMS8t 0fbeQF9Hom2PRruTT/jFZdd6MUPCG/gy6vOgbkl0/l3NTAf21AhvLduZlaULzd4UiJUP f9U+fdfiPdwZlijfahdgjK8DZVttbelvqBokwptSgmtpP7OjHsVSPKGdCueM0RCofF3t xZAayXhN9F79mt2095zwsaW4h37F+cyqIPxxX/0/iQluGRcHrFzEGVmQxwslgqV0fPdx OPBnjzekHD4NYSvAonk9kz9iVpSp+QvSq+L8otaiUE1388LG85MdKzhL4J3uAeYjWndA 1KEw== X-Gm-Message-State: AOAM532GNfjQHKkblI6TluHigY+e4hjlUokg444XaufIV5R1vTVx7RNK q/AD4sXw/LO0tSIcQZwuOGg= X-Google-Smtp-Source: ABdhPJyMjXaaGlEXDYH18mv/ajTq/1UvUnBk6wpaczQ3e/UYYg+Elxnz3yP4MVw5aiAbDChiC2E5cQ== X-Received: by 2002:a17:90a:b78d:b0:1d9:4f4f:bc2a with SMTP id m13-20020a17090ab78d00b001d94f4fbc2amr2839800pjr.155.1652235577926; Tue, 10 May 2022 19:19:37 -0700 (PDT) Received: from localhost ([193.203.214.57]) by smtp.gmail.com with ESMTPSA id s10-20020a17090a880a00b001cd4989fee6sm2470062pjn.50.2022.05.10.19.19.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 May 2022 19:19:37 -0700 (PDT) Message-ID: <627b1d39.1c69fb81.fe952.6426@mx.google.com> X-Google-Original-Message-ID: <20220511021936.GB1482876@cgel.zte@gmail.com> Date: Wed, 11 May 2022 02:19:36 +0000 From: CGEL To: Yang Shi Cc: Michal Hocko , Andrew Morton , Johannes Weiner , Matthew Wilcox , Roman Gushchin , Shakeel Butt , Miaohe Lin , William Kucharski , Peter Xu , Hugh Dickins , Vlastimil Babka , Muchun Song , Suren Baghdasaryan , Linux Kernel Mailing List , Linux MM , Cgroups , Yang Yang Subject: Re: [PATCH] mm/memcg: support control THP behaviour in cgroup References: <20220505033814.103256-1-xu.xin16@zte.com.cn> <6275d3e7.1c69fb81.1d62.4504@mx.google.com> <6278fa75.1c69fb81.9c598.f794@mx.google.com> <6279c354.1c69fb81.7f6c1.15e0@mx.google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Stat-Signature: ogd6c6on7w4c7g3znfs58doouk1du8un X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: DEF81A0092 Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=ckn4xqwp; spf=pass (imf15.hostedemail.com: domain of cgel.zte@gmail.com designates 209.85.214.174 as permitted sender) smtp.mailfrom=cgel.zte@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspam-User: X-HE-Tag: 1652235566-875226 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 Tue, May 10, 2022 at 12:34:20PM -0700, Yang Shi wrote: > On Mon, May 9, 2022 at 6:43 PM CGEL wrote: > > > > On Mon, May 09, 2022 at 01:48:39PM +0200, Michal Hocko wrote: > > > On Mon 09-05-22 11:26:43, CGEL wrote: > > > > On Mon, May 09, 2022 at 12:00:28PM +0200, Michal Hocko wrote: > > > > > On Sat 07-05-22 02:05:25, CGEL wrote: > > > > > [...] > > > > > > If there are many containers to run on one host, and some of them have high > > > > > > performance requirements, administrator could turn on thp for them: > > > > > > # docker run -it --thp-enabled=always > > > > > > Then all the processes in those containers will always use thp. > > > > > > While other containers turn off thp by: > > > > > > # docker run -it --thp-enabled=never > > > > > > > > > > I do not know. The THP config space is already too confusing and complex > > > > > and this just adds on top. E.g. is the behavior of the knob > > > > > hierarchical? What is the policy if parent memcg says madivise while > > > > > child says always? How does the per-application configuration aligns > > > > > with all that (e.g. memcg policy madivise but application says never via > > > > > prctl while still uses some madvised - e.g. via library). > > > > > > > > > > > > > The cgroup THP behavior is align to host and totally independent just likes > > > > /sys/fs/cgroup/memory.swappiness. That means if one cgroup config 'always' > > > > for thp, it has no matter with host or other cgroup. This make it simple for > > > > user to understand or control. > > > > > > All controls in cgroup v2 should be hierarchical. This is really > > > required for a proper delegation semantic. > > > > > > > Could we align to the semantic of /sys/fs/cgroup/memory.swappiness? > > Some distributions like Ubuntu is still using cgroup v1. > > Other than enable flag, how would you handle the defrag flag > hierarchically? It is much more complicated. Refer to memory.swappiness for cgroup, this new interface better be independent. > > > > > > If memcg policy madivise but application says never, just like host, the result > > > > is no THP for that application. > > > > > > > > > > By doing this we could promote important containers's performance with less > > > > > > footprint of thp. > > > > > > > > > > Do we really want to provide something like THP based QoS? To me it > > > > > sounds like a bad idea and if the justification is "it might be useful" > > > > > then I would say no. So you really need to come with a very good usecase > > > > > to promote this further. > > > > > > > > At least on some 5G(communication technology) machine, it's useful to provide > > > > THP based QoS. Those 5G machine use micro-service software architecture, in > > > > other words one service application runs in one container. > > > > > > I am not really sure I understand. If this is one application per > > > container (cgroup) then why do you really need per-group setting? > > > Does the application is a set of different processes which are only very > > > loosely tight? > > > > > For micro-service architecture, the application in one container is not a > > set of loosely tight processes, it's aim at provide one certain service, > > so different containers means different service, and different service > > has different QoS demand. > > > > The reason why we need per-group(per-container) setting is because most > > container are managed by compose software, the compose software provide > > UI to decide how to run a container(likes setting swappiness value). For > > example the docker compose: > > https://docs.docker.com/compose/#compose-v2-and-the-new-docker-compose-command > > > > To make it clearer, I try to make a summary for why container needs this patch: > > 1.one machine can run different containers; > > 2.for some scenario, container runs only one service inside(can be only one > > application); > > 3.different containers provide different services, different services have > > different QoS demands; > > 4.THP has big influence on QoS. It's fast for memory access, but eat more > > memory; > > I have been involved in this kind of topic discussion offline a couple > of times. But TBH I don't see how you could achieve QoS by this flag. > THP allocation is *NOT* guaranteed. And the overhead may be quite > high. It depends on how fragmented the system is. For THP, the word 'QoS' maybe too absolute, so let's describe it in the way why user need THP: seeking for better memory performance. Yes as you said THP may be quite overhead, and madvise() may not be suitable some time (see PR_SET_THP_DISABLE https://man7.org/linux/man-pages/man2/prctl.2.html). So I think this is just the reason why we need the patch: give user a method to use THP with more precise range(only the performance sensitive containers) and reduce overhead. > > > 5.containers usually managed by compose software, which treats container as > > base management unit; > > 6.this patch provide cgroup THP controller, which can be a method to adjust > > container memory QoS. > > > > > > Container becomes > > > > the suitable management unit but not the whole host. And some performance > > > > sensitive containers desiderate THP to provide low latency communication. > > > > But if we use THP with 'always', it will consume more memory(on our machine > > > > that is about 10% of total memory). And unnecessary huge pages will increase > > > > memory pressure, add latency for minor pages faults, and add overhead when > > > > splitting huge pages or coalescing normal sized pages into huge pages. > > > > > > It is still not really clear to me how do you achieve that the whole > > > workload in the said container has the same THP requirements. > > > -- > > > Michal Hocko > > > SUSE Labs