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 4E3E8C433FE for ; Thu, 3 Nov 2022 16:53:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D21BE6B0072; Thu, 3 Nov 2022 12:53:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CD1736B0073; Thu, 3 Nov 2022 12:53:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B99B56B0074; Thu, 3 Nov 2022 12:53:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id A74C46B0072 for ; Thu, 3 Nov 2022 12:53:57 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 4027D1A14AE for ; Thu, 3 Nov 2022 16:53:57 +0000 (UTC) X-FDA: 80092728114.27.46C4656 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf04.hostedemail.com (Postfix) with ESMTP id 8D19640007 for ; Thu, 3 Nov 2022 16:53:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667494435; 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=gERfL0EPpR1L5+55Qs7xdMhql2jPX0zv2LAyPLcrgS0=; b=HAK5G8ZyM913X3rMZd11f6Z9CXPNGvI5iA60Yj3C+DxNqE5GLqTCl4OprqUjFeVTsgNAHG HXcoskXhS+qhx/NxGyCzv8CtSE+HNscpLJS5i1ha3Z5302FOCz3ntCt3YtYfRWd/hnwd8X ujNOO6slWFx/ydhklC8K686diEjv6Bk= Received: from mail-ot1-f69.google.com (mail-ot1-f69.google.com [209.85.210.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-528-Wydre0eAML-K4nePdUVrww-1; Thu, 03 Nov 2022 12:53:49 -0400 X-MC-Unique: Wydre0eAML-K4nePdUVrww-1 Received: by mail-ot1-f69.google.com with SMTP id l4-20020a9d7344000000b0066ac21d7252so918105otk.12 for ; Thu, 03 Nov 2022 09:53:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=gERfL0EPpR1L5+55Qs7xdMhql2jPX0zv2LAyPLcrgS0=; b=5uKney2tdJop0Agh3IyqN69nL8Bc4sl0a6iqiHF+4MOeOKXwblhG21tbRtZgpFz6LB ZpJg7gq8VXn78oitI25sedgpn6IlnmGv61eItA6de4vEcy6cBRu8BkOiy91MdZ/y8HJ6 VuWuqEMLNFz1kcNASkyZ6RTsNgz2LNPkfW5BmeNUdSZ/I9e4//5AW5loRoXjLlEGnvob /EPbxLVEqk3JZHKGbPl08CRZuJbzwsCkGbmWFezLUTwvMoTvE7RuIU968a4toDfN4G5+ ZMQjKu643MEixn+Q49VI+PMyvR3WxfSuJAGjpDRl5R0pbKH+35EwgTKhJXzdbzRNLwcV pIsg== X-Gm-Message-State: ACrzQf1EXzwLFQ1JOezSUC2Jqy52gNqHeVcyfe+kB/ZlAS2S+J26pmHh loaMuXqocvcMH/YOTKMLA3YerTGsnuew2s95VmPrAPtfH4mVy4v/Z01ZE3wr/GOhD9yAmDUc/Qo qPEmIycRJdxk= X-Received: by 2002:a05:6870:b029:b0:13b:9097:6764 with SMTP id y41-20020a056870b02900b0013b90976764mr27632614oae.98.1667494428584; Thu, 03 Nov 2022 09:53:48 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7yjXFdmgY0WpH5o7ZQGlBv7lPO2P5kT/y3cFxqJ0WqkLHJHC7P6j8VDosoFcC2xmCLRGEVGQ== X-Received: by 2002:a05:6870:b029:b0:13b:9097:6764 with SMTP id y41-20020a056870b02900b0013b90976764mr27632591oae.98.1667494428325; Thu, 03 Nov 2022 09:53:48 -0700 (PDT) Received: from ?IPv6:2804:1b3:a802:1099:7cb2:3a49:6197:5307? ([2804:1b3:a802:1099:7cb2:3a49:6197:5307]) by smtp.gmail.com with ESMTPSA id kv43-20020a056870fbab00b0011bde9f5745sm612757oab.23.2022.11.03.09.53.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Nov 2022 09:53:47 -0700 (PDT) Message-ID: <0183b60e79cda3a0f992d14b4db5a818cd096e33.camel@redhat.com> Subject: Re: [PATCH v1 0/3] Avoid scheduling cache draining to isolated cpus From: Leonardo =?ISO-8859-1?Q?Br=E1s?= To: Michal Hocko Cc: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , Johannes Weiner , Roman Gushchin , Shakeel Butt , Muchun Song , Andrew Morton , Frederic Weisbecker , Phil Auld , Marcelo Tosatti , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org Date: Thu, 03 Nov 2022 13:53:41 -0300 In-Reply-To: References: <20221102020243.522358-1-leobras@redhat.com> <07810c49ef326b26c971008fb03adf9dc533a178.camel@redhat.com> User-Agent: Evolution 3.46.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667494436; 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=gERfL0EPpR1L5+55Qs7xdMhql2jPX0zv2LAyPLcrgS0=; b=3dr78XJmJiX5Iz52IzlZgdO8ByZWn3tvDdOFPKiB6jkiPGLmGmeaheFBhwKdNcNZ7jG+TL hfzyM0uJgFzixS+9BtCFv2csoUUfLhwDmbyZ2TuopAz4h0DQe6S7izgVu3BUMUcXwe/3dw r0ijCz4jgI67A28aTouhS8Knf5ooVtc= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HAK5G8Zy; spf=pass (imf04.hostedemail.com: domain of leobras@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=leobras@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667494436; a=rsa-sha256; cv=none; b=iXYCXjy/6oxGm614Li3ecYun7DkVoPrGyh3Y2BdqaTQWWMaYZqYWaUIFkKKuc4E+EK5FYp nrDOOZILY6mQgRE8vejFL5QXA4sFd8Z3CvsMzVGAoj4N3qdKvMQ30NcLcMRt5BdM+m2yDA imUxb4P3euIDVBwFh/5zi+yaGDO1AdI= X-Rspam-User: X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 8D19640007 Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HAK5G8Zy; spf=pass (imf04.hostedemail.com: domain of leobras@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=leobras@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Stat-Signature: tesjoufdkez4ib1p6waj3ikg1zepp8gd X-HE-Tag: 1667494436-81333 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 Thu, 2022-11-03 at 16:31 +0100, Michal Hocko wrote: > On Thu 03-11-22 11:59:20, Leonardo Br=C3=A1s wrote: > > On Wed, 2022-11-02 at 09:53 +0100, Michal Hocko wrote: > > > On Tue 01-11-22 23:02:40, Leonardo Bras wrote: > > > > Patch #1 expands housekeep=C3=ADng_any_cpu() so we can find houseke= eping cpus > > > > closer (NUMA) to any desired CPU, instead of only the current CPU. > > > >=20 > > > > ### Performance argument that motivated the change: > > > > There could be an argument of why would that be needed, since the c= urrent > > > > CPU is probably acessing the current cacheline, and so having a CPU= closer > > > > to the current one is always the best choice since the cache invali= dation > > > > will take less time. OTOH, there could be cases like this which use= s > > > > perCPU variables, and we can have up to 3 different CPUs touching t= he > > > > cacheline: > > > >=20 > > > > C1 - Isolated CPU: The perCPU data 'belongs' to this one > > > > C2 - Scheduling CPU: Schedule some work to be done elsewhere, curre= nt cpu > > > > C3 - Housekeeping CPU: This one will do the work > > > >=20 > > > > Most of the times the cacheline is touched, it should be by C1. Som= e times > > > > a C2 will schedule work to run on C3, since C1 is isolated. > > > >=20 > > > > If C1 and C2 are in different NUMA nodes, we could have C3 either i= n > > > > C2 NUMA node (housekeeping_any_cpu()) or in C1 NUMA node=20 > > > > (housekeeping_any_cpu_from(C1).=20 > > > >=20 > > > > If C3 is in C2 NUMA node, there will be a faster invalidation when = C3 > > > > tries to get cacheline exclusivity, and then a slower invalidation = when > > > > this happens in C1, when it's working in its data. > > > >=20 > > > > If C3 is in C1 NUMA node, there will be a slower invalidation when = C3 > > > > tries to get cacheline exclusivity, and then a faster invalidation = when > > > > this happens in C1. > > > >=20 > > > > The thing is: it should be better to wait less when doing kernel wo= rk > > > > on an isolated CPU, even at the cost of some housekeeping CPU waiti= ng > > > > a few more cycles. > > > > ### > > > >=20 > > > > Patch #2 changes the locking strategy of memcg_stock_pcp->stock_loc= k from > > > > local_lock to spinlocks, so it can be later used to do remote percp= u > > > > cache draining on patch #3. Most performance concerns should be poi= nted > > > > in the commit log. > > > >=20 > > > > Patch #3 implements the remote per-CPU cache drain, making use of b= oth=20 > > > > patches #2 and #3. Performance-wise, in non-isolated scenarios, it = should > > > > introduce an extra function call and a single test to check if the = CPU is > > > > isolated.=20 > > > >=20 > > > > On scenarios with isolation enabled on boot, it will also introduce= an > > > > extra test to check in the cpumask if the CPU is isolated. If it is= , > > > > there will also be an extra read of the cpumask to look for a > > > > housekeeping CPU. > > >=20 > >=20 > > Hello Michael, thanks for reviewing! > >=20 > > > This is a rather deep dive in the cache line usage but the most > > > important thing is really missing. Why do we want this change? From t= he > > > context it seems that this is an actual fix for isolcpu=3D setup when > > > remote (aka non isolated activity) interferes with isolated cpus by > > > scheduling pcp charge caches on those cpus. > > >=20 > > > Is this understanding correct? > >=20 > > That's correct! The idea is to avoid scheduling work to isolated CPUs. > >=20 > > > If yes, how big of a problem that is? > >=20 > > The use case I have been following requires both isolcpus=3D and PREEMP= T_RT, since > > the isolated CPUs will be running a real-time workload. In this scenari= o, > > getting any work done instead of the real-time workload may cause the s= ystem to > > miss a deadline, which can be bad.=20 >=20 > OK, I see. But is memcg charging actually a RT friendly operation in the > first place? Please note that this path can trigger memory reclaim and > that is when any RT expectations are simply going down the drain. I understand the spent time for charging is unpredictable as you said, sinc= e a lot of slow stuff may or may not happen.=20 >=20 > > > If you want a remote draining then > > > you need some sort of locking (currently we rely on local lock). How > > > come this locking is not going to cause a different form of disturban= ce? > >=20 > > If I did everything right, most of the extra work should be done either= in non- > > isolated (housekeeping) CPUs, or during a syscall. I mean, the pcp char= ge caches > > will be happening on a housekeeping CPU, and the locking cost should be= paid > > there as we want to avoid doing that in the isolated CPUs.=20 Sorry, I think this caused a misunderstanding: I meant "the pcp charge cach= e drain will be happening on a housekeeping CPU, ..." > >=20 > > I understand there will be a locking cost being paid in the isolated CP= Us when: > > a) The isolated CPU is requesting the stock drain, > > b) When the isolated CPUs do a syscall and end up using the protected s= tructure > > the first time after a remote drain. >=20 > And anytime the charging path (consume_stock resp. refill_stock) > contends with the remote draining which is out of control of the RT > task. It is true that the RT kernel will turn that spin lock into a > sleeping RT lock and that could help with potential priority inversions > but still quite costly thing I would expect. >=20 > > Both (a) and (b) should happen during a syscall, and IIUC the a rt work= load > > should not expect the syscalls to be have a predictable time, so it sho= uld be > > fine. >=20 > Now I am not sure I understand. If you do not consider charging path to > be RT sensitive then why is this needed in the first place? What else > would be populating the pcp cache on the isolated cpu? IRQs? I am mostly trying to deal with drain_all_stock() calling schedule_work_on(= ) at isolated_cpus. Since the scheduled drain_local_stock() will be competing fo= r cpu time with the RT workload, we can have preemption of the RT workload, which= is a problem for meeting the deadlines. One way I thought to solve that was introducing a remote drain, which would require a different strategy for locking, since not all accesses to the pcp caches would happen on a local CPU.=20 Then I tried to weight the costs of this, so the solution would introduce a= s little overhead as possible on no-isolation scenarios. Also, for isolation scenarios, I tried to put most of the overheads into the housekeeping CPUs,= and the remaining on the syscalls, which are also expected to be non-predictabl= e. Not sure if I could answer your question, though. Please let me know in cas= e I missed anything. Thanks for helping me make it more clear! Best regards, Leo