From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3A4762376F8 for ; Wed, 2 Jul 2025 21:11:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751490715; cv=none; b=IJX3HHuO/PN7r9H74jtOXjSI2ecKLVKKu7G6JZxlQLHIpM77DU5jDt8x2QjpHyqI1IMGNofPy5aikFBkflGScMBCpjR8GZ4e2pZQjHXeiHiqz8p1jzE2iqv+XQFdMwyKeGdkyGDn7r6LU9GNuWntnWp7DdsZN9iltLoHOOmSnpQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751490715; c=relaxed/simple; bh=r4ycxoolYmuKX0m2fIW1oV8sY58bOT134WmsNhkmxdo=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=W/seeKYvqHkifNP0qlfLMO5Q+59hsMTeDV8Q14MqDmkcVngTeZNeyJV5fuO0+LbgNYb7UigCUD5xfTn5OSvvi16KDyxt4kyKbiQzJRn4uvvLQYi8TWELFa4rXPi4J+nSSvmloMxqEmzy8u0tNrOXRrIaQiPaB6aIjIYn05MXZqg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=purestorage.com; spf=fail smtp.mailfrom=purestorage.com; dkim=pass (2048-bit key) header.d=purestorage.com header.i=@purestorage.com header.b=eJuEA5uR; arc=none smtp.client-ip=209.85.214.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=purestorage.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=purestorage.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=purestorage.com header.i=@purestorage.com header.b="eJuEA5uR" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-2369dd5839dso12901405ad.3 for ; Wed, 02 Jul 2025 14:11:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1751490713; x=1752095513; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=sHPw+gFNU4kcte4+DjGEOa7pSlzMKOzoy1+5anqcCg0=; b=eJuEA5uRye4ewsbqqtf3mko+4VCMtWArFtfxu+IphRRxyCpyR19cUc+9vvbruZq5v2 eDHL0HK2i/e0kibposvkeF/M9zToe21sUJ4XygzHek51RnbkGB/GVlcLHlDd/b8kag2H UsKnWEqPtgzn8QH5NY/yVYcjNs7cSyeB6FPdBArimfEnPWJvi1kwbQiVK/7pRIUyrRBf wvlNiMEaaDxkZQFN1Ccrxs8UrujlKG49AdzAn/95s0ALMgXyRQh4Pu2DyFQ9zc4loIUs bmWV0OUROTySQP377KJNTEwM6p1oZ3aLEsFMDq9KGtndcnpzp5vt906JNTe0LoVQG9Qg By2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751490713; x=1752095513; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sHPw+gFNU4kcte4+DjGEOa7pSlzMKOzoy1+5anqcCg0=; b=tuFI6gze0bRtCP3Q1MkRlLQTeGl3g3KgSfvJ9E+a/UmPxpAmDmEz+ZYxjNraGvCbHJ T+r80JdFnB8Lh8lYDGYeqoAdTUXrbYBcsg/c05zM/Su9XJwGH7VkwabZr2tHlej8Yuuc mj9+nx05AxKFncdZBvQfMoogtKbt6ApdGKlubapFaW3HKtESWdpxumDak75mX0+08U5F UbhB2qAXttc6/vBezzXDM/89uocLvEnilsVjA96aR4orHuiXJ/MJvVg9acuEFzU6J5Di frecfzkmoaAOS2XOlBalIaIcEWF15PlyOz2bHsRRzW23HQj6jZy9DKiULvu19PogVuod LagQ== X-Gm-Message-State: AOJu0YxNlPgyEtePEQ+ONnWYoGi0je2rvESKlWFcVepwquDg8Jo3fQ9O Fva/mEiT26KAKdiDDN4v7890dAiOss8KcXbLJb41sZ3DLeyHYSOBzZasoQi3ZK+7xJjmz5Nu7z+ 8+98DUQQOoo5jqNx6bcucrUj1KX+kVyGgbQphaCpBxwBs4KKR1qQlcQc= X-Gm-Gg: ASbGncsaCGQRCKv+f1UfTNs2+RBpo19g6jfq52nu2itEQfdepmSxT3VvoVMsyQOUWd3 M8vd4jpAk2NyJIhUaT9FXBWCHNwJrTOyrSkr76LM36pLTfKK0X5S0H/17/uR3jpYAmEvs2u5Q10 k0609qcxHfBLwgcOTi9PAIkHzs6+/fVsE92nh2/TiDGX7J+t0hr2hA5A== X-Google-Smtp-Source: AGHT+IFuNZwePMXtrGGiy+Lal9FBipRUHE+tVSTERSi9lHrrMb5JTmkuRgmPnmoBG4HWQ7kRECEakR5dz4NREEM6yVA= X-Received: by 2002:a17:902:d4c5:b0:234:db06:ab5 with SMTP id d9443c01a7336-23c6e50f8bcmr28811895ad.12.1751490713407; Wed, 02 Jul 2025 14:11:53 -0700 (PDT) Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20250619143435.3474028-1-csander@purestorage.com> In-Reply-To: <20250619143435.3474028-1-csander@purestorage.com> From: Caleb Sander Mateos Date: Wed, 2 Jul 2025 17:11:42 -0400 X-Gm-Features: Ac12FXyYeIjTfBC7VX_f4PgJXEIGElJPaVB7WXMGWA-c8qyxwbh-DBbEEDN0jU0 Message-ID: Subject: Re: [PATCH] io_uring/rsrc: skip atomic refcount for uncloned buffers To: Jens Axboe Cc: io-uring@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Jens, Any concerns with this one? I thought it was a fairly straightforward optimization in the ublk zero-copy I/O path. Thanks, Caleb On Thu, Jun 19, 2025 at 10:34=E2=80=AFAM Caleb Sander Mateos wrote: > > io_buffer_unmap() performs an atomic decrement of the io_mapped_ubuf's > reference count in case it has been cloned into another io_ring_ctx's > registered buffer table. This is an expensive operation and unnecessary > in the common case that the io_mapped_ubuf is only registered once. > Load the reference count first and check whether it's 1. In that case, > skip the atomic decrement and immediately free the io_mapped_ubuf. > > Signed-off-by: Caleb Sander Mateos > --- > io_uring/rsrc.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c > index 94a9db030e0e..9a1f24a43035 100644 > --- a/io_uring/rsrc.c > +++ b/io_uring/rsrc.c > @@ -133,12 +133,14 @@ static void io_free_imu(struct io_ring_ctx *ctx, st= ruct io_mapped_ubuf *imu) > kvfree(imu); > } > > static void io_buffer_unmap(struct io_ring_ctx *ctx, struct io_mapped_ub= uf *imu) > { > - if (!refcount_dec_and_test(&imu->refs)) > - return; > + if (unlikely(refcount_read(&imu->refs) > 1)) { > + if (!refcount_dec_and_test(&imu->refs)) > + return; > + } > > if (imu->acct_pages) > io_unaccount_mem(ctx, imu->acct_pages); > imu->release(imu->priv); > io_free_imu(ctx, imu); > -- > 2.45.2 >