From nobody Sat Feb 7 21:08:22 2026 Received: from mail-dy1-f170.google.com (mail-dy1-f170.google.com [74.125.82.170]) (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 D67C62C0284 for ; Wed, 7 Jan 2026 21:02:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767819737; cv=none; b=WFfudXI7ZVxfss39DfHMP2k/wJENRHuEBwZ51QSLJrpFbAIPIgpSmfvbHUEFkOIvqZuGUqyftB2Y9l6o6cJw0WbYvZyaAJ0QvKWVcn2a0TZlS4RKPql9VeFEotSaDbQnqIfHeNoz5qhVpYZK707oq9m9gHZSJxf5UJDSSrEDDHU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767819737; c=relaxed/simple; bh=M+v5Vw0Jil/rA486zu+DiAOWZxQZQJUjs4l0t3TZ4tM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=puZFRO5F8NgwTcBp4/eKqDpMQ4ldIGHOzPMAKEcL3808397WRGf1SwEZLauOL/HjxVgJv4PZ0XIu7HRl/7ao7vyduxaxEj9suz9m4N7Yi/pEHB2mf+LEk0gyPLiilGH4j7V7qs2dQZGpQjlS8oXKyxZ/UZv1vJvCpcnvZYNAKbw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=dWVABuWR; arc=none smtp.client-ip=74.125.82.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dWVABuWR" Received: by mail-dy1-f170.google.com with SMTP id 5a478bee46e88-2ac3d5ab81bso1525528eec.1 for ; Wed, 07 Jan 2026 13:02:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767819734; x=1768424534; 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=0iYD+ioNTt6TfLHqUAr1a4Xg5XGaJpAZluY0IKqvlcs=; b=dWVABuWR+7O63Lh8EcYuo/R1NAj/wPU8/8jK03w9z4XHU0tXWlWvBgfW3eIXfAJwwi 6Fzqvifj4oqYmYdoSUXwH9nARwY3kX9oK+bQ++OqoG4zSI4OUjRKRcmQee4c5l7g1JPC h5K8e0wBOmUL6deZpS0Sf+Oh3gw7r/iEj9+ONDzaDEKxRT5HzhWVtHapaW9TMgc0w9t5 U+qZF6KN2GeJDr2bitwh7ytEdQlFxhMFMglHnMn+AUDUbbtdHOlhdNIGGempgG4fEmfz lXQFipsdmCD3ZTQ4abntp/K8E0bAIJZjFzyHCXIsr2bS6UJUf2M3bs2d2hdldDIKER+p W/oQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767819734; x=1768424534; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=0iYD+ioNTt6TfLHqUAr1a4Xg5XGaJpAZluY0IKqvlcs=; b=cIrFtVB66n9So+ymEmGl8WPrcF0Rh39v/n4iOa+Xr02PwZSGCbzmxSkZABnB6KCvjW p6VTmkL3KtnxjXgRehJqnWklWH0KaDh5W0EhtLK0IlwcctABWzG9wADW7U5ogJKHyMp4 mJlYs3oDMRwREo4N3ekVwEbgPzNFaodJecUXQRsXOn2VQHFywmLkvLKwTDxIhhAhKWvs 1Y+qihbYU6EinUVL8AhuLHvOTVI727/26QVNyRQHyDG3xTUJw3WqyaVoxdG8jrBkMjfY HrLm4FKz5GRn3KgWTzNwentEO1HV5QUw6NLuXiBsirQkwFE9nv/hbCvfMpqBcnzNxyCH 8Wbg== X-Forwarded-Encrypted: i=1; AJvYcCUbb4vYDA2Aq8Vlg0VtrL5lfou96DlpXvTFgoYMu1Ga+glbhoMbuU0iQ+dLT7Ycj+HAploptI6JxF4WhTM=@vger.kernel.org X-Gm-Message-State: AOJu0YwOSJk31COd8S4aJAQOUm3YBwPB4USEkLkMINTklBXn7ShVl0Vv udcwp5MDlBSfQQQq864UCi+kaCx5ypv06xp7Dm0Aj24YW+g2bBzTWkIn X-Gm-Gg: AY/fxX6qGIA31zbWmH/Yj8CgoEHqF7UtSuD6t5+R9ufAMUW0lEf2j4oewBP1cvh8wFr iCeQ8KHZX06xlho/bzL6qRi1bjFpinSHmfcl9Eo9kMk67njv0sqQYDX1p257cnT4cEiHHW8uUlH FFvdUGV8rxNSaDNL7Q3u8ZAbPeMZPAMvVTUvdJJCHT4w90a6L9DJTlmdlSrVsmQgPhjDRob961t MmgTn4xWbEHGLxKJA0k9xvTlCXEKTknzU9n5xvHNdPeGvS3cIVFpfsXwKlSWGbhKBaqHenQ2uwv VY9FLnqP6xLdilvFwPb5yZthut5jgCZ/0Bbg/cuIaklZkI1uyUNTQa+tsN3dZIWCSeYpgwSUkG0 NSeovt47C9KFmy3Qyw+Nqt+nxzv+5ofR/XWZL35tt27PCtiX/lrmao6KscKOrFeVgLNj5mohq8Q TStjuueX/xV1MQxhwihepoXHftQgOxaLSVwaeJYwTFDu1Kn5Sj9IdC6pJ4JTyE X-Google-Smtp-Source: AGHT+IERp97W8qGccAbwxhXAxSLBpLHQVl7RhoNKnrA6Fsbg0/9438GYXF8rBuCdpX/av5RsA8yPMA== X-Received: by 2002:a05:7300:2d15:b0:2b0:5bce:2f44 with SMTP id 5a478bee46e88-2b17d25199amr2080567eec.10.1767819733776; Wed, 07 Jan 2026 13:02:13 -0800 (PST) Received: from celestia.turtle.lan (static-23-234-115-121.cust.tzulo.com. [23.234.115.121]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2b170673b2esm7730320eec.6.2026.01.07.13.02.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jan 2026 13:02:13 -0800 (PST) From: Sam Edwards X-Google-Original-From: Sam Edwards To: Xiubo Li , Ilya Dryomov Cc: Viacheslav Dubeyko , Christian Brauner , Milind Changire , Jeff Layton , ceph-devel@vger.kernel.org, linux-kernel@vger.kernel.org, Sam Edwards Subject: [PATCH v2 4/6] ceph: Split out page-array discarding to a function Date: Wed, 7 Jan 2026 13:01:37 -0800 Message-ID: <20260107210139.40554-5-CFSworks@gmail.com> X-Mailer: git-send-email 2.51.2 In-Reply-To: <20260107210139.40554-1-CFSworks@gmail.com> References: <20260107210139.40554-1-CFSworks@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Discarding a page array (i.e. after failure to submit it) is a little complex: - Every folio in the batch needs to be redirtied and unlocked. - Some folios are bounce pages created for fscrypt; the underlying plaintext folios also need to be redirtied and unlocked. - The array itself can come either from the mempool or general kalloc, so different free functions need to be used depending on which. Although currently only ceph_submit_write() does this, this logic is complex enough to warrant its own function. Move it to a new ceph_discard_page_array() function that is called by ceph_submit_write() instead. Suggested-by: Viacheslav Dubeyko Signed-off-by: Sam Edwards Reviewed-by: Viacheslav Dubeyko --- fs/ceph/addr.c | 67 ++++++++++++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 29 deletions(-) diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c index 467aa7242b49..3becb13a09fe 100644 --- a/fs/ceph/addr.c +++ b/fs/ceph/addr.c @@ -1222,6 +1222,43 @@ void ceph_allocate_page_array(struct address_space *= mapping, ceph_wbc->len =3D 0; } =20 +static inline +void ceph_discard_page_array(struct writeback_control *wbc, + struct ceph_writeback_ctl *ceph_wbc) +{ + int i; + struct page *page; + + for (i =3D 0; i < folio_batch_count(&ceph_wbc->fbatch); i++) { + struct folio *folio =3D ceph_wbc->fbatch.folios[i]; + + if (!folio) + continue; + + page =3D &folio->page; + redirty_page_for_writepage(wbc, page); + unlock_page(page); + } + + for (i =3D 0; i < ceph_wbc->locked_pages; i++) { + page =3D ceph_fscrypt_pagecache_page(ceph_wbc->pages[i]); + + if (!page) + continue; + + redirty_page_for_writepage(wbc, page); + unlock_page(page); + } + + if (ceph_wbc->from_pool) { + mempool_free(ceph_wbc->pages, ceph_wb_pagevec_pool); + ceph_wbc->from_pool =3D false; + } else + kfree(ceph_wbc->pages); + ceph_wbc->pages =3D NULL; + ceph_wbc->locked_pages =3D 0; +} + static inline bool is_folio_index_contiguous(const struct ceph_writeback_ctl *ceph_wbc, const struct folio *folio) @@ -1445,35 +1482,7 @@ int ceph_submit_write(struct address_space *mapping, BUG_ON(len < ceph_fscrypt_page_offset(page) + thp_size(page) - offset); =20 if (!ceph_inc_osd_stopping_blocker(fsc->mdsc)) { - for (i =3D 0; i < folio_batch_count(&ceph_wbc->fbatch); i++) { - struct folio *folio =3D ceph_wbc->fbatch.folios[i]; - - if (!folio) - continue; - - page =3D &folio->page; - redirty_page_for_writepage(wbc, page); - unlock_page(page); - } - - for (i =3D 0; i < ceph_wbc->locked_pages; i++) { - page =3D ceph_fscrypt_pagecache_page(ceph_wbc->pages[i]); - - if (!page) - continue; - - redirty_page_for_writepage(wbc, page); - unlock_page(page); - } - - if (ceph_wbc->from_pool) { - mempool_free(ceph_wbc->pages, ceph_wb_pagevec_pool); - ceph_wbc->from_pool =3D false; - } else - kfree(ceph_wbc->pages); - ceph_wbc->pages =3D NULL; - ceph_wbc->locked_pages =3D 0; - + ceph_discard_page_array(wbc, ceph_wbc); ceph_osdc_put_request(req); return -EIO; } --=20 2.51.2