Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp747509lqt; Fri, 19 Apr 2024 09:12:40 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVWcyGidph64rmbN7pu8znHpbB3sHDmFO38F5BfVPO0S4z8n0vNQl6auWA7CPYjUd7JZxZyhUKynZxd5L/E257TuBAOp7JJiXe+VsXBsQ== X-Google-Smtp-Source: AGHT+IGscuwTXEX1olOtfaR6vJdA/0f+Xo4QkeyW0uy+GIVloVlB3xVt+tNwbqaK/uEErPkZjgPd X-Received: by 2002:a05:6a00:b89:b0:6ea:ed70:46b4 with SMTP id g9-20020a056a000b8900b006eaed7046b4mr3707799pfj.29.1713543159856; Fri, 19 Apr 2024 09:12:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713543159; cv=pass; d=google.com; s=arc-20160816; b=zvE9+9cWjC/6PnoHgk1bYUlUsjnypeyvhYargY3OFt49HtoQUwnbaIhQesv8VtycA2 dWOUtqB4KW84aJwjw640ynqEIESE+5mtsGG6lOT5ZFIrBUvrQ3PdgyYqWH5tP3QJPIjq SjKFUfHpZYk40Tk1cYFL9uTto5I0yjzeV3URJf0vITiQmat23GSDJsP9nA7iOImpcjNg 8dGJjWgdjglaznfhQ9FXZ+PV46OdRFdUgfxq672/p1ZRUEimmp10Q2a95kiB0XPtJGax IHci9FiIUUujN4c1CWUn3b5qhUx90mtrd52274DN+eZq5rREvtqtDCO1RFmyv4OTJS88 hZ7Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:dkim-signature:date; bh=1M1JrcjILmKzY/pZvXVWiYtUaqkIh9p05oVmfNf0rww=; fh=nGUocZvDufSpVLZTdzYjI8fXYMul0To4lCL4Uq3xcfw=; b=EgNyYtwRdX3w9icQyF4lwICEgouhOX8ZBVl0VjLgCnURKlKwC8f8/EUmKn0jBCedNn KMPka+riZ7QojvI1fc+QebKnLVqOqNct/n7B1YLBCxdJvGPh6Vgxulh95ZN5sRKVgk7u c9hfSmfnEGharuNigGoMwVblHWX7X/hiFsnwxTXsjrIuhqBnBI9zyfVWsq9Vvbo7o1NY zqWHSD9/nXzICHqqWaZUncLQLf2HUbo7OGvJQa5a96tdNYdajoGwf5zrGDF8mzfvWVIM JMbFtpsgvXipi0BYQBJN875pw5TBzFuURlpsAlwIntEhy8+ub/8MUfcilRstKe6poP0o Yq+w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=K1flVzQT; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-151727-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151727-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id q28-20020aa7983c000000b006ecfb733245si3471436pfl.136.2024.04.19.09.12.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 09:12:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-151727-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=K1flVzQT; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-151727-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151727-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 5BBFD2847D8 for ; Fri, 19 Apr 2024 16:12:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A387A131E3D; Fri, 19 Apr 2024 16:11:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="K1flVzQT" Received: from out-171.mta1.migadu.com (out-171.mta1.migadu.com [95.215.58.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ECDD6130AFE for ; Fri, 19 Apr 2024 16:11:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713543104; cv=none; b=OH0XmCWMcX5d2xTIV6BBNduWqMgFkuputMxSac3y7ybYe47JRydv05yerJesDHLgaTCAEyKcld9CMeHH9fpkWLpTlLJTtviqC9BanqOqCV677NkunP+5OhzAdq/It0VUeTvTzkegVogr06H/HNMVUdD3AGjDiCO8pWh0tz1fN/M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713543104; c=relaxed/simple; bh=YiIo7bwh+JygPxi96MWkEdF0Xun4ILTm7Qlbps8sJxU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=D5z4YrGRdriYPpWEuFuOOXcNOeUFwfDfnm3DKl/i26snMGAwacQxcLWbTao7Hvv7vFiXkBlNcR+DYzLULunjvxtH+rBn39QNfCXRllWQzVU/X1dPcG+MFhETnW8UaalrRSQVl2BP523XRBmBvqi3D4VzQ57n3UhiDsMvt+D+37s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=K1flVzQT; arc=none smtp.client-ip=95.215.58.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Date: Fri, 19 Apr 2024 09:11:35 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1713543100; 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=1M1JrcjILmKzY/pZvXVWiYtUaqkIh9p05oVmfNf0rww=; b=K1flVzQTM+oFA2r7zbEZfWL1Cx45FZeshKvy/vWeELZmkSdsf1KvuEo2B1ZxDCkvrBw2te R6sUPQwVqPUrsBOcAs0PiOqaZKW0Z3YrHoCJbASaz+8VkxORdept/DSJTLhjQW4N4ye1xQ 25T+Xm6zatF7tmP04YMcsMfql4Xb+M0= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Shakeel Butt To: Jesper Dangaard Brouer Cc: Yosry Ahmed , tj@kernel.org, hannes@cmpxchg.org, lizefan.x@bytedance.com, cgroups@vger.kernel.org, longman@redhat.com, netdev@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@cloudflare.com, Arnaldo Carvalho de Melo , Sebastian Andrzej Siewior , mhocko@kernel.org Subject: Re: [PATCH v1 2/3] cgroup/rstat: convert cgroup_rstat_lock back to mutex Message-ID: References: <171328983017.3930751.9484082608778623495.stgit@firesoul> <171328989335.3930751.3091577850420501533.stgit@firesoul> <651a52ac-b545-4b25-b82f-ad3a2a57bf69@kernel.org> <6392f7e8-d14c-40f4-8a19-110dfffb9707@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <6392f7e8-d14c-40f4-8a19-110dfffb9707@kernel.org> X-Migadu-Flow: FLOW_OUT On Fri, Apr 19, 2024 at 03:15:01PM +0200, Jesper Dangaard Brouer wrote: > > > On 18/04/2024 22.39, Yosry Ahmed wrote: > > On Thu, Apr 18, 2024 at 7:49 AM Shakeel Butt wrote: > > > > > > On Thu, Apr 18, 2024 at 11:02:06AM +0200, Jesper Dangaard Brouer wrote: > > > > > > > > > > > > On 18/04/2024 04.19, Yosry Ahmed wrote: > > > [...] > > > > > > > > > > I will keep the high-level conversation about using the mutex here in > > > > > the cover letter thread, but I am wondering why we are keeping the > > > > > lock dropping logic here with the mutex? > > > > > > > > > > > > > I agree that yielding the mutex in the loop makes less sense. > > > > Especially since the raw_spin_unlock_irqrestore(cpu_lock, flags) call > > > > will be a preemption point for my softirq. But I kept it because, we > > > > are running a CONFIG_PREEMPT_VOLUNTARY kernel, so I still worried that > > > > there was no sched point for other userspace processes while holding the > > > > mutex, but I don't fully know the sched implication when holding a mutex. > > > > > > > > > > Are the softirqs you are interested in, raised from the same cpu or > > > remote cpu? What about local_softirq_pending() check in addition to > > > need_resched() and spin_needbreak() checks? If softirq can only be > > > raised on local cpu then convert the spin_lock to non-irq one (Please > > > correct me if I am wrong but on return from hard irq and not within bh > > > or irq disabled spin_lock, the kernel will run the pending softirqs, > > > right?). Did you get the chance to test these two changes or something > > > similar in your prod environment? > > > > I tried making the spinlock a non-irq lock before, but Tejun objected [1]. > > [1] https://lore.kernel.org/lkml/ZBz%2FV5a7%2F6PZeM7S@slm.duckdns.org/ > > > > After reading [1], I think using a mutex is a better approach (than non-irq > spinlock). > > > > Perhaps we could experiment with always dropping the lock at CPU > > boundaries instead? > > > > I don't think this will be enough (always dropping the lock at CPU > boundaries). My measured "lock-hold" times that is blocking IRQ (and > softirq) for too long. When looking at prod with my new cgroup > tracepoint script[2]. When contention occurs, I see many Yields > happening and with same magnitude as Contended. But still see events > with long "lock-hold" times, even-though yields are high. > > [2] https://github.com/xdp-project/xdp-project/blob/master/areas/latency/cgroup_rstat_tracepoint.bt > > Example output: > > 12:46:56 High Lock-contention: wait: 739 usec (0 ms) on CPU:56 comm:kswapd7 > 12:46:56 Long lock-hold time: 6381 usec (6 ms) on CPU:27 comm:kswapd3 > 12:46:56 Long lock-hold time: 18905 usec (18 ms) on CPU:100 > comm:kworker/u261:12 > > 12:46:56 time elapsed: 36 sec (interval = 1 sec) > Flushes(2051) 15/interval (avg 56/sec) > Locks(44464) 1340/interval (avg 1235/sec) > Yields(42413) 1325/interval (avg 1178/sec) > Contended(42112) 1322/interval (avg 1169/sec) > > There is reported 15 flushes/sec, but locks are yielded quickly. > > More problematically (for softirq latency) we see a Long lock-hold time > reaching 18 ms. For network RX softirq I need lower than 0.5ms latency, > to avoid RX-ring HW queue overflows. > > > --Jesper > p.s. I'm seeing a pattern with kswapdN contending on this lock. > > @stack[697, kswapd3]: > __cgroup_rstat_lock+107 > __cgroup_rstat_lock+107 > cgroup_rstat_flush_locked+851 > cgroup_rstat_flush+35 > shrink_node+226 > balance_pgdat+807 > kswapd+521 > kthread+228 > ret_from_fork+48 > ret_from_fork_asm+27 > > @stack[698, kswapd4]: > __cgroup_rstat_lock+107 > __cgroup_rstat_lock+107 > cgroup_rstat_flush_locked+851 > cgroup_rstat_flush+35 > shrink_node+226 > balance_pgdat+807 > kswapd+521 > kthread+228 > ret_from_fork+48 > ret_from_fork_asm+27 > > @stack[699, kswapd5]: > __cgroup_rstat_lock+107 > __cgroup_rstat_lock+107 > cgroup_rstat_flush_locked+851 > cgroup_rstat_flush+35 > shrink_node+226 > balance_pgdat+807 > kswapd+521 > kthread+228 > ret_from_fork+48 > ret_from_fork_asm+27 > Can you simply replace mem_cgroup_flush_stats() in prepare_scan_control() with the ratelimited version and see if the issue still persists for your production traffic? Also were you able to get which specific stats are getting the most updates?