Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp2687635rdb; Wed, 4 Oct 2023 08:32:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFt8TMuKjSCFOQzeazzNqbQAC1aEHa0tmx4Yc9uzngV14s8XE54f4nWoBMOQ+pRQiTNDjfb X-Received: by 2002:a17:903:41cc:b0:1bc:6861:d746 with SMTP id u12-20020a17090341cc00b001bc6861d746mr3461265ple.58.1696433569645; Wed, 04 Oct 2023 08:32:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696433569; cv=none; d=google.com; s=arc-20160816; b=QU2MO1/BosW1O0o3GwLDu8M5X+4H+v135gF2n+pm4G5xxq5D2WQNepewGB/ibdnTcH Vg9ayz74Gaegr5xp8Zlg3eQr4TXn+gHYWAnGLYMYVN+nttO349VN3bhxDwjlSAgph5Mi Y0UQJySJ5zohS6IcXvzEY/GE5fSO4BXSZTt4MCZFe6I+JTzYnxI0xdhs8eok1Q2cvjmY p4kiIw2ixQV23kBHfuxcRtHwc/OCR5YTMrWjxpJ5GYiLYRdiKcq+EccOnpFdola3484C 6CSjvvLDKzS5gptzh4RgVBAK51uY5kvPUcyTB02vL2ThTxxFtffRxJqYVQlQXAJ5Mdep WtqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :dkim-signature; bh=E7rPN2B6EKTGm9PeH9o/j7eO/9ZZxPutpFnqoFCKJ3c=; fh=MBE0jQANScWwt2X7OdNT+yE90t8XwxYUiTs9q4k4ltc=; b=AIohgcoVt8ux6EzLki2kqBeZwDFT54Jpdrq/XLK710PqZ6SmR18pOHXKh+X7CPkjmk kjTin/JD/Zx7PfJjKvAwVZjSKagzHJa/gsKJfSdPKqoHGx5fpGohAG+XbC7+Uewvsyi7 xzesvSntWvl27o8UgJed4mdJ5XXxglzyRWVwzLTHeKMRIuX3pbzTiZ1+8M2KsZfYATXN Wvhyv4BOqUCc/75SaSDWpjWtuSUlWIgrXc2cVmJN0g4hDJ3Hb5HtYWkptou4d9FW8qN6 FmS4LuXmXwGlVhtl4c6lFnrsBu55Erl6K0yFsejErA44uXJBLIYz0NdCRAdVRvB8zWSk a05g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=PWNpNgIS; dkim=neutral (no key) header.i=@suse.cz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id q12-20020a17090311cc00b001bbab2e5a27si4202271plh.290.2023.10.04.08.32.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 08:32:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=PWNpNgIS; dkim=neutral (no key) header.i=@suse.cz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 2E754821A17D; Wed, 4 Oct 2023 08:32:48 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233550AbjJDPci (ORCPT + 99 others); Wed, 4 Oct 2023 11:32:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233530AbjJDPch (ORCPT ); Wed, 4 Oct 2023 11:32:37 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA0CDDC; Wed, 4 Oct 2023 08:32:33 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 331071F88D; Wed, 4 Oct 2023 15:32:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1696433552; h=from:from:reply-to: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=E7rPN2B6EKTGm9PeH9o/j7eO/9ZZxPutpFnqoFCKJ3c=; b=PWNpNgIS0ejpZaWNfc0RvB2fG2vV8czGrqfLFnVTWcWRavWyJ4QgAKcXC6NTyqjpPPXLIR ctspLD8VBoyOKiAiK+atQY00RcObsQ/ufJFWQxDaExXcReriBuPYwsegsPUtk0sKuldjvw NaontetfPZBnTsqhYoaH2uSIFUYt+XI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1696433552; h=from:from:reply-to: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=E7rPN2B6EKTGm9PeH9o/j7eO/9ZZxPutpFnqoFCKJ3c=; b=/a/QgrmLqwF9uzFD93sACvd/cUymLm7NK62R1MpzNFNbQH5uu3qguAu7sOD1484Ey2FveJ RH6ttpyXbHMa7yDw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 2219813A2E; Wed, 4 Oct 2023 15:32:32 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id jbpJCJCFHWUhIAAAMHmgww (envelope-from ); Wed, 04 Oct 2023 15:32:32 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id AA6E8A07CC; Wed, 4 Oct 2023 17:32:31 +0200 (CEST) Date: Wed, 4 Oct 2023 17:32:31 +0200 From: Jan Kara To: Hugh Dickins Cc: Andrew Morton , Tim Chen , Dave Chinner , "Darrick J. Wong" , Christian Brauner , Carlos Maiolino , Chuck Lever , Jan Kara , Matthew Wilcox , Johannes Weiner , Axel Rasmussen , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH 8/8] shmem,percpu_counter: add _limited_add(fbc, limit, amount) Message-ID: <20231004153231.gj5ds6r2tdjwjdwd@quack3> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 04 Oct 2023 08:32:48 -0700 (PDT) On Fri 29-09-23 20:42:45, Hugh Dickins wrote: > Percpu counter's compare and add are separate functions: without locking > around them (which would defeat their purpose), it has been possible to > overflow the intended limit. Imagine all the other CPUs fallocating > tmpfs huge pages to the limit, in between this CPU's compare and its add. > > I have not seen reports of that happening; but tmpfs's recent addition > of dquot_alloc_block_nodirty() in between the compare and the add makes > it even more likely, and I'd be uncomfortable to leave it unfixed. > > Introduce percpu_counter_limited_add(fbc, limit, amount) to prevent it. > > I believe this implementation is correct, and slightly more efficient > than the combination of compare and add (taking the lock once rather > than twice when nearing full - the last 128MiB of a tmpfs volume on a > machine with 128 CPUs and 4KiB pages); but it does beg for a better > design - when nearing full, there is no new batching, but the costly > percpu counter sum across CPUs still has to be done, while locked. > > Follow __percpu_counter_sum()'s example, including cpu_dying_mask as > well as cpu_online_mask: but shouldn't __percpu_counter_compare() and > __percpu_counter_limited_add() then be adding a num_dying_cpus() to > num_online_cpus(), when they calculate the maximum which could be held > across CPUs? But the times when it matters would be vanishingly rare. > > Signed-off-by: Hugh Dickins > Cc: Tim Chen > Cc: Dave Chinner > Cc: Darrick J. Wong Looks good to me. Feel free to add: Reviewed-by: Jan Kara Honza -- Jan Kara SUSE Labs, CR