From patchwork Sun Sep 15 15:22:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13804837 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (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 304661C8FA6 for ; Sun, 15 Sep 2024 15:23:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726413804; cv=none; b=XI6ms+hHAUjMv5KnZowmccZ0tKaIFTLaDTc0Yu5cCFZbKtft4/sbzN6rv2Rpk+Zjnl85JUCvN8VrPRU5l28qrwGusED+6CEPOXOm3HlLetOSd7zU7gc9si4fi4NRj5cwRA9pULCTN5CUKw9w4Sh6W4gzPz9TvvHZuq8oCJIKdiU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726413804; c=relaxed/simple; bh=PFVEqTRwmoEFJ58JZGtxCQiSxQGvZyj2plGvAfO8If4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZcVICgmrUqCEaXbQ0XwGtv8TNtXEKs1Nimz8nW6WjErKdUwwSPxhEbchFnHWq6hT4fi+pF+sLdn5BxaPh6PWMmY4vIeX5ATPGTr90YXkak7S0Cd/9bMtnHcMbxC8JmGNNRraU1IdW2Gcza8RhE4gvSjqKdt4biYg8Srme+9keUw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk; spf=pass smtp.mailfrom=kernel.dk; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b=t29wSH1E; arc=none smtp.client-ip=209.85.214.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b="t29wSH1E" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-201d5af11a4so41076535ad.3 for ; Sun, 15 Sep 2024 08:23:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1726413801; x=1727018601; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/ltK6eCpctxMLHRTitX0PPoUMOCF4iLvkdaO1XE7mEM=; b=t29wSH1EMIhSHfbCeSBRwQ4l6LlXGmw42BO5PkX0JpZcpXjhLrL6GqDhxD3AzPylHR FTGfhswgD2PcdJysbXXaHS/s8qBW5Srhq3nHEK4Ur7PSGFoC3euOjQv6r13GZJzN64P3 UhAntVp6t8O8SVxsFD548Nzi+spTjr8lzoqcRpgno0AbMpkK86OkQvbFqz10PvSFAOxs /AOicPM4xfCDGS16pgGHIriwhRlVJDJhyK62zhITg+04Tw4zeTlEDQ8hJrFGN3jrK3sM sWtU3HzoXPy8mAZu63zJdGMXmjj3UDPaULTD+rGD/+hFwukGYI4/bfUTLP+OJaDUFujR NlBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726413801; x=1727018601; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/ltK6eCpctxMLHRTitX0PPoUMOCF4iLvkdaO1XE7mEM=; b=utMgzOcHvNmsixtw7gSe4l21OV0tROiHdOxTv65ORTVBEyVJIACBU/mpwzBqWH86yY z59cTh9+sztIFfkK89GhDnqBAJIlJaxA0EBSmh/1cdJZkDGjOPPDCTqaKG6UMrsqrIX/ 8YipHZSfDQyFOCUflzL9bd/hG4UyzdCy9RzuKp09rcuy0ualvIEFUJmrsB+5p43SFxYo 1S6KMWYmKbpKzSgNeINBv2pa/yrs4FuL3f2gavCBYViup3iZ3UuuYzi02c2r62Rn6z8R P17W4hdtJWvNtgJ1zt6OrFLYhqnBB6TI2SoFm5cIG5EbA3LSpqnmJcbHlGR9HHliyKwl 97kA== X-Gm-Message-State: AOJu0YyuJ6l5V60wtrD6vuW+9Nk37CR615U2y6hxjrqZShxsiwjHNuzJ 3bJ6HOgvSchBjJk8O2DAdoOZyZ0MILklBiA1JDoKy7FdhAnEX89tTc4/yHVb5lLeNAEzPz99nip w X-Google-Smtp-Source: AGHT+IE0orYMTeXqQj55khnbxu0K4XohcoplOtOPdMtkKE9bMN5ME2TZa3dlwpgh36AWl+9LR/dqdQ== X-Received: by 2002:a17:902:d4cd:b0:1fd:8eaf:ea73 with SMTP id d9443c01a7336-2076e393a6amr192304475ad.35.1726413800863; Sun, 15 Sep 2024 08:23:20 -0700 (PDT) Received: from localhost.localdomain ([198.8.77.157]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-207964a5ec4sm22083755ad.232.2024.09.15.08.23.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Sep 2024 08:23:19 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: cliang01.li@samsung.com, Jens Axboe Subject: [PATCH 1/2] io_uring/rsrc: get rid of io_mapped_ubuf->folio_mask Date: Sun, 15 Sep 2024 09:22:34 -0600 Message-ID: <20240915152315.821382-2-axboe@kernel.dk> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240915152315.821382-1-axboe@kernel.dk> References: <20240915152315.821382-1-axboe@kernel.dk> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 We don't really need to cache this, let's reclaim 8 bytes from struct io_mapped_ubuf and just calculate it when we need it. The only hot path here is io_import_fixed(). Signed-off-by: Jens Axboe --- io_uring/rsrc.c | 9 +++------ io_uring/rsrc.h | 1 - 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c index 9264e555ae59..2477995e2d65 100644 --- a/io_uring/rsrc.c +++ b/io_uring/rsrc.c @@ -988,13 +988,10 @@ static int io_sqe_buffer_register(struct io_ring_ctx *ctx, struct iovec *iov, imu->ubuf_end = imu->ubuf + iov->iov_len; imu->nr_bvecs = nr_pages; imu->folio_shift = PAGE_SHIFT; - imu->folio_mask = PAGE_MASK; - if (coalesced) { + if (coalesced) imu->folio_shift = data.folio_shift; - imu->folio_mask = ~((1UL << data.folio_shift) - 1); - } refcount_set(&imu->refs, 1); - off = (unsigned long) iov->iov_base & ~imu->folio_mask; + off = (unsigned long) iov->iov_base & ((1UL << imu->folio_shift) - 1); *pimu = imu; ret = 0; @@ -1132,7 +1129,7 @@ int io_import_fixed(int ddir, struct iov_iter *iter, iter->bvec = bvec + seg_skip; iter->nr_segs -= seg_skip; iter->count -= bvec->bv_len + offset; - iter->iov_offset = offset & ~imu->folio_mask; + iter->iov_offset = offset & ((1UL << imu->folio_shift) - 1); } } diff --git a/io_uring/rsrc.h b/io_uring/rsrc.h index eb4803e473b0..e290d2be3285 100644 --- a/io_uring/rsrc.h +++ b/io_uring/rsrc.h @@ -46,7 +46,6 @@ struct io_mapped_ubuf { unsigned int nr_bvecs; unsigned int folio_shift; unsigned long acct_pages; - unsigned long folio_mask; refcount_t refs; struct bio_vec bvec[] __counted_by(nr_bvecs); }; From patchwork Sun Sep 15 15:22:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13804838 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (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 C81971C8FA6 for ; Sun, 15 Sep 2024 15:23:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726413807; cv=none; b=JR4XIYF9zT2SIYFSd6MDLpPhmCU8UWz1NgQ2ZM3Q83uSBsImkrQwcIkhYH/8G5XBcgHe5Q8O3E/bBhad1LvukeKTq55pvQQiHMobaUNIBsNTzQoFSJ2N0tra/qd68FbcJyWuS2UkbaSEzeq/gxWvL4HZM38T1H1lRFGNIX3D1l8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726413807; c=relaxed/simple; bh=S2F1uBzjRNQnrkV7+JPFKaUnkMKjLRDrjZAMd/eXRHU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FR9/Uc8uTbnaF0lBo0qZhTEzsrb/vPYVKPfq8IAkfBz3aPNMyqwzZEpS5CnE1D3e0VSO2d3tc0VvVCw9sLqLFVn4+9Cle5XUqRbCMauPqca6JK49ZFuB/alLlbIw7Z6Vx5J1wUUKvzPGJo6MkWja+H0coQ9ZISS54UXOM46BiH0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk; spf=pass smtp.mailfrom=kernel.dk; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b=rO/FXFOh; arc=none smtp.client-ip=209.85.214.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b="rO/FXFOh" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-2068acc8a4fso21987425ad.1 for ; Sun, 15 Sep 2024 08:23:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1726413803; x=1727018603; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=OVU30hcfgfZmc5/oV8zT/i63y8UtewElLCRs86OSyV0=; b=rO/FXFOhnuRlqb4d3lfVlAutNLi7xkE7LC6rLF8pLsPl9fkUq/yDWe5a/x01h5XiVG Q0AlOxYiISCTPeySF1aFahMuVkcT0IRA8wvA34vCcUFzhQAsql5yIK4Wu8byFnlYMTMC 9I3ztboBMIbi0A+biqolPcG2kCZRy1t3u5WrLHTW892OgN5/biBCCVWjHaXoJ1PFNtVO IUfuN7UHC9o+qYdchMB93RUeeaqKxNuCgR15YXdo0jD4kxDVAEMlgexsT556CVPbHMtn Nf/KUTbL26fBqnVxXGXC9YRLfZTYmcX5hDezXMV1QskX62C2RyJsov3ogvmLxhX1WYUV 8BIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726413803; x=1727018603; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OVU30hcfgfZmc5/oV8zT/i63y8UtewElLCRs86OSyV0=; b=AwWm3sJajiwiLq5AC20fYTmlpa3uAf0J5x/mB/Rxe7HA04m0Jrk0Ht3P8m3jYWKrOV NLoMvvS2T1kKs5bCvv7Edloa3ruqqzYgbEeVPTWyGmIUGFiyD7/vZkKilyylPMGH8waK N06U06hupjiUxCtyXAyj8LFAbUpg1ekYqK5DIELE/kjuGuIfxlmHhIxkM72scX+QyHJ4 6ItM1CY9Yh9JoqvG9IlsGINO2aaxHD6tASRCzOaJyH8XIRreSR3Q7+pr6uTGApFGKHQr lAfVeQBewg0ik90bN5vP1miuufDI1GgquGAw+MsAyY0BQT3vuDBvGgJcDe9it41sMbc9 oSjw== X-Gm-Message-State: AOJu0YyAMjUXGaK7pz04vOqATTjs5XCSjEcxjNQSZ+pdT1AMISFM+ilK vNBHfqpIm0sNkXdYyQTLwRUH/WYjZvKIbUQgWfPENVFXiE1TxgqWWz+0cPKg9DGHe0vxsTeXqEp P X-Google-Smtp-Source: AGHT+IGGloJOUgPGHVr2ZQcxEV+vId5Pjt+IjLRf+dzLpmnIIGBTQSvcnV4zeWsOWCPrdrxWxBHQXg== X-Received: by 2002:a17:902:e54e:b0:206:c8dc:e334 with SMTP id d9443c01a7336-20782be4dc3mr131963805ad.39.1726413802604; Sun, 15 Sep 2024 08:23:22 -0700 (PDT) Received: from localhost.localdomain ([198.8.77.157]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-207964a5ec4sm22083755ad.232.2024.09.15.08.23.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Sep 2024 08:23:21 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: cliang01.li@samsung.com, Jens Axboe Subject: [PATCH 2/2] io_uring/rsrc: change ubuf->ubuf_end to length tracking Date: Sun, 15 Sep 2024 09:22:35 -0600 Message-ID: <20240915152315.821382-3-axboe@kernel.dk> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240915152315.821382-1-axboe@kernel.dk> References: <20240915152315.821382-1-axboe@kernel.dk> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 If we change it to tracking ubuf->start + ubuf->len, then we can reduce the size of struct io_mapped_ubuf by another 4 bytes, effectively 8 bytes, as a hole is eliminated too. This shrinks io_mapped_ubuf to 32 bytes. Signed-off-by: Jens Axboe --- io_uring/fdinfo.c | 3 +-- io_uring/rsrc.c | 6 +++--- io_uring/rsrc.h | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/io_uring/fdinfo.c b/io_uring/fdinfo.c index d43e1b5fcb36..6b1247664b35 100644 --- a/io_uring/fdinfo.c +++ b/io_uring/fdinfo.c @@ -177,9 +177,8 @@ __cold void io_uring_show_fdinfo(struct seq_file *m, struct file *file) seq_printf(m, "UserBufs:\t%u\n", ctx->nr_user_bufs); for (i = 0; has_lock && i < ctx->nr_user_bufs; i++) { struct io_mapped_ubuf *buf = ctx->user_bufs[i]; - unsigned int len = buf->ubuf_end - buf->ubuf; - seq_printf(m, "%5u: 0x%llx/%u\n", i, buf->ubuf, len); + seq_printf(m, "%5u: 0x%llx/%u\n", i, buf->ubuf, buf->len); } if (has_lock && !xa_empty(&ctx->personalities)) { unsigned long index; diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c index 2477995e2d65..131bcdda577a 100644 --- a/io_uring/rsrc.c +++ b/io_uring/rsrc.c @@ -38,7 +38,7 @@ static int io_sqe_buffer_register(struct io_ring_ctx *ctx, struct iovec *iov, static const struct io_mapped_ubuf dummy_ubuf = { /* set invalid range, so io_import_fixed() fails meeting it */ .ubuf = -1UL, - .ubuf_end = 0, + .len = UINT_MAX, }; int __io_account_mem(struct user_struct *user, unsigned long nr_pages) @@ -985,7 +985,7 @@ static int io_sqe_buffer_register(struct io_ring_ctx *ctx, struct iovec *iov, size = iov->iov_len; /* store original address for later verification */ imu->ubuf = (unsigned long) iov->iov_base; - imu->ubuf_end = imu->ubuf + iov->iov_len; + imu->len = iov->iov_len; imu->nr_bvecs = nr_pages; imu->folio_shift = PAGE_SHIFT; if (coalesced) @@ -1086,7 +1086,7 @@ int io_import_fixed(int ddir, struct iov_iter *iter, if (unlikely(check_add_overflow(buf_addr, (u64)len, &buf_end))) return -EFAULT; /* not inside the mapped region */ - if (unlikely(buf_addr < imu->ubuf || buf_end > imu->ubuf_end)) + if (unlikely(buf_addr < imu->ubuf || buf_end > (imu->ubuf + imu->len))) return -EFAULT; /* diff --git a/io_uring/rsrc.h b/io_uring/rsrc.h index e290d2be3285..8ed588036210 100644 --- a/io_uring/rsrc.h +++ b/io_uring/rsrc.h @@ -42,11 +42,11 @@ struct io_rsrc_node { struct io_mapped_ubuf { u64 ubuf; - u64 ubuf_end; + unsigned int len; unsigned int nr_bvecs; unsigned int folio_shift; - unsigned long acct_pages; refcount_t refs; + unsigned long acct_pages; struct bio_vec bvec[] __counted_by(nr_bvecs); };