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 9480BC5479D for ; Wed, 11 Jan 2023 17:08:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 184328E0003; Wed, 11 Jan 2023 12:08:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1350C8E0001; Wed, 11 Jan 2023 12:08:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F3DE78E0003; Wed, 11 Jan 2023 12:08:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id E3D6A8E0001 for ; Wed, 11 Jan 2023 12:08:17 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id ABDA4160864 for ; Wed, 11 Jan 2023 17:08:17 +0000 (UTC) X-FDA: 80343151434.23.5372D72 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf25.hostedemail.com (Postfix) with ESMTP id 9F92CA0003 for ; Wed, 11 Jan 2023 17:08:15 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=VMnPYD0v; spf=pass (imf25.hostedemail.com: domain of mtosatti@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=mtosatti@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1673456895; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=IducYfddzH6lMplxq5YrX0OgBDUYvrG6JVse4EUppbE=; b=dqmRuvLls4wEvyH6gRgTU2zIPmQl42GtmY4bz3QQYP0mELtGFU6Yvoieizl07Z4TVNEuQ9 ayVnz8ghEAyHt/VHt5QHrWoTbOK7nVz82cZjwUIivyj0EO780mAldtaByvbdWdtHIjXWg0 uWVy3+MVdmxcwgOb7e9Cg+489500K0M= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=VMnPYD0v; spf=pass (imf25.hostedemail.com: domain of mtosatti@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=mtosatti@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1673456895; a=rsa-sha256; cv=none; b=wotPprjf91YWqrmFNWZr3JkaKe3s5LcmSzH4UniLueyXQQv2n7HsJSahqZKXFnaLmOYe9S YhNKYPvlSddFvL3dMuqjbpFjx5DM1BnB5I/fnu7xVDEay6Y80HFskc5dEfEkVVf+WmnwKk BvSBhPzFFVbONNPbrw4XlyxC56wJIcI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673456894; 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: in-reply-to:in-reply-to:references:references; bh=IducYfddzH6lMplxq5YrX0OgBDUYvrG6JVse4EUppbE=; b=VMnPYD0vjx3Y7Eev8jCYHRajRPdR3gmQ4+ES6q5wmGFTzRxSz+L5j7tGi4AfCx9sMFOyZI Afdh6N0jJce5WM+JBZiypO6iuEFXNsPlLheqqNjXLqhQTcRxUg7FLdVoSMBhA8G9aaNgWL RVNDA3Sk8Jy3xCRDj9BbVP2R0CmzTnE= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-84-h6Akq_tMN7yf2EHiQ2PiFw-1; Wed, 11 Jan 2023 12:08:06 -0500 X-MC-Unique: h6Akq_tMN7yf2EHiQ2PiFw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5E6463C4220B; Wed, 11 Jan 2023 17:08:05 +0000 (UTC) Received: from tpad.localdomain (ovpn-112-3.gru2.redhat.com [10.97.112.3]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 100EBC0328F; Wed, 11 Jan 2023 17:08:05 +0000 (UTC) Received: by tpad.localdomain (Postfix, from userid 1000) id 8E81E401A035B; Wed, 11 Jan 2023 14:07:47 -0300 (-03) Date: Wed, 11 Jan 2023 14:07:47 -0300 From: Marcelo Tosatti To: Christoph Lameter Cc: Frederic Weisbecker , atomlin@atomlin.com, tglx@linutronix.de, mingo@kernel.org, peterz@infradead.org, pauld@redhat.com, neelx@redhat.com, oleksandr@natalenko.name, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v13 2/6] mm/vmstat: Use vmstat_dirty to track CPU-specific vmstat discrepancies Message-ID: References: <20230105125218.031928326@redhat.com> <20230105125248.813825852@redhat.com> <7c2af941-42a9-a59b-6a20-b331a4934a3@gentwo.de> <60183179-3a28-6bf9-a6ab-8a8976f283d@gentwo.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <60183179-3a28-6bf9-a6ab-8a8976f283d@gentwo.de> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Rspamd-Queue-Id: 9F92CA0003 X-Stat-Signature: fx8k3h5c8jmixdbzsah57rytwy6g6yct X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1673456895-819067 X-HE-Meta: U2FsdGVkX18SD2AxZvkOjxYuVNV1vSowmRHvsHrbHW6h1+KnB7r8/0LCLeQavAhaWFpD0kJFsgVxw9u8sETCswXzT0c7dEaPDBGpGmqzpV9dUHfZLwFyXA0k+1UWccZX05lC4TS3DHu9i8d40mE76rxaboJnQ/24Xu+Qm0/z5B1KuNSRSZ/X2lLUNMgNJsvz8XVEF09XzJ5yAt/PWShNpmvozgJZnqZIzL8sZd7cQGgrxJTFtoXS+T5zBvA5sfr/iT6x01JbvUi/rgAJ0x+Gi61IsrZdMF3um9yEjC9ABmXlB4akt+Vg9vvseVspXPgfXk78AupIgeOjQO3QI3Tcr/UNT2kTISJQi+HEHR3mQPTiktHp6iXLzxkpHW7JhjZX+f6SjN99UcwjPj+TPjgQlZLLZuoeLuFE4HCB6CFS4t8tCYpoXrzP65yAXsQVSLXEDo15FYXCqOvyLQW5InRJY/Z/JR0lKnw2eBZ9iqblTbXdEIenku+oLQG0UFlhi9HGaluQZ5TqAEm3CkAtE/qzFKNc/rqhRVa4l3hZrNJ/89ccehEvPDItiqSHVSCS6oSTVVQWgrPKD6fZmmTVGAnTf4LOCZJ3lSWLMUXZ19ydmuSTu7Lx9N/dIuRxNLK72Wa5dZfK/ldF17sFAvql3FDAy2Mm8uZS687XTsZd6c+Cbpui3hIgKLUWmt/hozb3Z6PQ/ATp/zfh5bywUJk3PaJryMvM/J2n1YVumeZdtkkDRgJQTT0JFINuW9v25qEILMSfQqUafHQbhk4lzXoh0oeq/v6iI27SuwGH9SzLBu4Ateg1hj6EwDiHopBO8Ihj7h+A/TjOE27HRpmK8M61cjSXbs4CGm7OtDrhnl0RBpmy2W8jIT/PPCJI10izq6WTauyDsGKoHtUBuT8z+/PCpsrBQu0pFO7JOSzNH52YQ0rQGMM= 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 Wed, Jan 11, 2023 at 09:42:18AM +0100, Christoph Lameter wrote: > On Tue, 10 Jan 2023, Marcelo Tosatti wrote: > > > > The basic primitives add a lot of weight. > > > > Can't see any alternative given the necessity to avoid interruption > > by the work to sync per-CPU vmstats to global vmstats. > > this_cpu operations are designed to operate on a *single* value (a counter) and can > be run on an arbitrary cpu, There is no preemption or interrupt > disable required since the counters of all cpus will be added up at the > end. > > You want *two* values (the counter and the dirty flag) to be modified > together and want to use the counters/flag to identify the cpu where > these events occurred. this_cpu_xxx operations are not suitable for that > purpose. You would need a way to ensure that both operations occur on the > same cpu. Which is either preempt_disable (CONFIG_HAVE_CMPXCHG_LOCAL case), or local_irq_disable (!CONFIG_HAVE_CMPXCHG_LOCAL case). > > > > And the pre cpu atomic updates operations require the modification > > > of multiple values. The operation > > > cannot be "atomic" in that sense anymore and we need some other form of > > > synchronization that can > > > span multiple instructions. > > > > So use this_cpu_cmpxchg() to avoid the overhead. Since we can no longer > > count on preremption being disabled we still have some minor issues. > > The fetching of the counter thresholds is racy. > > A threshold from another cpu may be applied if we happen to be > > rescheduled on another cpu. However, the following vmstat operation > > will then bring the counter again under the threshold limit. > > > > Those small issues are gone, OTOH. > > Well you could use this_cpu_cmpxchg128 to update a 64 bit counter and a > flag at the same time. But then you transform the "per-CPU vmstat is dirty" bit (bool) into a number of flags that must be scanned (when returning to userspace). Which increases the overhead of a fast path (return to userspace). > Otherwise you will have to switch off preemption or > interrupts when incrementing the counters and updating the dirty flag. > > Thus you do not really need the this_cpu operations anymore. It would > best to use a preempt_disable section and uuse C operators -- ++ for the > counter and do regular assignment for the flag. OK, can replace this_cpu operations with this_cpu_ptr + standard C operators (and in fact can do that for interrupt disabled functions as well, that is CONFIG_HAVE_CMPXCHG_LOCAL not defined). Is that it?