From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f71.google.com (mail-pj1-f71.google.com [209.85.216.71]) (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 5B067476CD4 for ; Fri, 14 Aug 2026 14:33:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.71 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786717991; cv=none; b=NM20KbwBJl6/FOEmuXuywgzTrNAo/IgqX4mE7smkegIiPQdRx5VVZcrLjzswr+OuRFMTKNXY2W2d2dnCBN+Rth41km2gx5ADEov9WeHoxiuEDVub/S/cZYNf4dlBv5fe45MbZVUWSuPdJUcPjn9Rsz6AN79yauhEvbHBefNr8Kw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786717991; c=relaxed/simple; bh=u0MKNRKgDVwVPGRV+6Ey10B0Yv0u0Jn1oxVRulYF4u0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=mXc46IVbARlde9m60jw5iZNLdIH0ZrHvDgW6sYVNAZQdcBibjRG0IJPLDHpXte0axvMnadMXiQLwrSXdHpYBW2wlda9BAwDJ0OGypyIQDmgwTfRwgZPQLoL4ktH03fC2TyA261flSM+zrp2NOzwgZGWa4RzhOUIT16EI3ulTvk8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--praan.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=N093Uj+4; arc=none smtp.client-ip=209.85.216.71 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--praan.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="N093Uj+4" Received: by mail-pj1-f71.google.com with SMTP id 98e67ed59e1d1-38ea32e57e2so1945656a91.1 for ; Fri, 14 Aug 2026 07:33:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1786717984; x=1787322784; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=VC79kGoXaLgBrqdL04SZQWwyFvo3s0PHCta3qnTuB/A=; b=N093Uj+4IjrFgJc79huP/de34mPTNZp6wxRZ9DEFJTnqjRJineALuS/FHHiZPLoWd8 zfFczokF79jY7V8jB54JKboRE7DDKpmADkm6/ajUFn3N7HzzZ9urUhIS6Yht7Cki4zkc I1mUf6b+efJFVDnAU1Mpqg04wFeYxBgjepKBkamOImCTUW9uidUVhDOpcJTHpG4uh1u0 kBVITEOkIeNl4J3IwxXYVcm5XNvKZZ4abheXvzPLb2MT4/pFvNmTkIviHIG0e/9AyvNB cYLZzVwedMU0++Y64T7127b+RLpOgd5IJJkdeh49w3yOyhaUwUyqbutp2Ws+5l4KV6TJ QYlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786717984; x=1787322784; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=VC79kGoXaLgBrqdL04SZQWwyFvo3s0PHCta3qnTuB/A=; b=eq86STjKYr8mwVXh3zy614D1yGvyWNTDvK0+77hRj/FSj5snK+Ru1Tr04uHSIMfK5O eaymDc5CqAJemADBT2L4j8JfVHP0DfJ/QE38xC2wcQZngj4OnT2dxu+AlfCFafhm2i+B 3ShZarS1SxlZXePZqoVI8ce/doofaD4d68caxOCBPerXXZitI3rQ/E66E73rFYOjYRO4 MAocD8uowLFvjL3WWpRNB5w70MfHNtNUHdiy5kG+2Fw72uIv2W8s1l24WEuExctHho43 DiAx7MlkY7JqidOmVStxWBITK3E+6+5paiJoGW70Q4ksoj0qnN/VD4EfVFrmK3bFFCaQ NttA== X-Forwarded-Encrypted: i=1; AHgh+Rp9PhKsf8B+50ezY7MgIRPttkUQd3Ou+IIOAr6h5Fgc2Gs9/t+PPkF883EwaFCASozFNQPOVLIq/ps=@vger.kernel.org X-Gm-Message-State: AOJu0Ywe/iW4XlfxKILIh85XP1tSNT9mThi+Qs94R7b4IRbZadHuGiVT uOXs/JwgYYqRw5oPwPp1aH4EUd4OJBqpmFlthKEWYdVShtBLhRzYShG94+Vlips18RoFVoHDTeZ Wfw== X-Received: from pjbnl15.prod.google.com ([2002:a17:90b:384f:b0:38f:a3cc:f600]) (user=praan job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:1b47:b0:38e:5964:97a8 with SMTP id 98e67ed59e1d1-3933e63167amr6649209a91.16.1786717983830; Fri, 14 Aug 2026 07:33:03 -0700 (PDT) Date: Fri, 14 Aug 2026 14:32:52 +0000 In-Reply-To: <20260814143255.861084-1-praan@google.com> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260814143255.861084-1-praan@google.com> X-Mailer: git-send-email 2.55.0.691.gc56d675ccc-goog Message-ID: <20260814143255.861084-3-praan@google.com> Subject: [PATCH v6 2/5] nfs: track number of pinned pages in nfs_page From: Pranjal Shrivastava To: linux-nfs@vger.kernel.org, Trond Myklebust , Anna Schumaker Cc: Chuck Lever , Jeff Layton , linux-kernel@vger.kernel.org, Christoph Hellwig , Logan Gunthorpe , Jason Gunthorpe , linux-pci@vger.kernel.org, linux-rdma@vger.kernel.org, Shivaji Kant , Pranjal Shrivastava Content-Type: text/plain; charset="UTF-8" Track the number of pinned pages in nfs_page to handle unpinning correctly, ensuring that only primary requests perform the final unpinning operation, preventing subrequests from incorrectly performing unpinning on behalf of their parent requests. Add wb_nr_pinned to struct nfs_page to store the count of pinned pages owned by the request. Update request creation and cleanup helpers to initialize and use wb_nr_pinned for primary requests. Use the nfs_page_array_len() helper to calculate the number of pages spanned by a request's offset and length. Signed-off-by: Pranjal Shrivastava Reviewed-by: Christoph Hellwig --- fs/nfs/pagelist.c | 13 +++++++++---- include/linux/nfs_page.h | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/fs/nfs/pagelist.c b/fs/nfs/pagelist.c index a562cfe2a126..b9ccf2a87e3c 100644 --- a/fs/nfs/pagelist.c +++ b/fs/nfs/pagelist.c @@ -457,6 +457,8 @@ struct nfs_page *nfs_page_create_from_page(struct nfs_open_context *ctx, offset_in_page(offset), count); if (!IS_ERR(ret)) { nfs_page_assign_page(ret, page, pinned); + if (pinned) + ret->wb_nr_pinned = 1; nfs_page_group_init(ret, NULL); } nfs_put_lock_context(l_ctx); @@ -489,6 +491,9 @@ struct nfs_page *nfs_page_create_from_folio(struct nfs_open_context *ctx, ret = nfs_page_create(l_ctx, offset, folio->index, offset, count); if (!IS_ERR(ret)) { nfs_page_assign_folio(ret, folio, pinned); + if (pinned) + ret->wb_nr_pinned = nfs_page_array_len(offset_in_page(offset), + count); nfs_page_group_init(ret, NULL); } nfs_put_lock_context(l_ctx); @@ -567,8 +572,8 @@ static void nfs_clear_request(struct nfs_page *req) if (folio != NULL) { if (test_and_clear_bit(PG_PINNED, &req->wb_flags)) { - if (req == req->wb_head) - unpin_user_folio(folio, 1); + if (req->wb_nr_pinned > 0) + unpin_user_folio(folio, req->wb_nr_pinned); } else { folio_put(folio); } @@ -576,8 +581,8 @@ static void nfs_clear_request(struct nfs_page *req) clear_bit(PG_FOLIO, &req->wb_flags); } else if (page != NULL) { if (test_and_clear_bit(PG_PINNED, &req->wb_flags)) { - if (req == req->wb_head) - unpin_user_page(page); + if (req->wb_nr_pinned > 0) + unpin_user_pages(&page, req->wb_nr_pinned); } else { put_page(page); } diff --git a/include/linux/nfs_page.h b/include/linux/nfs_page.h index fd7aafe7cb54..080fa3e23580 100644 --- a/include/linux/nfs_page.h +++ b/include/linux/nfs_page.h @@ -59,6 +59,7 @@ struct nfs_page { struct nfs_page *wb_this_page; /* list of reqs for this page */ struct nfs_page *wb_head; /* head pointer for req list */ unsigned short wb_nio; /* Number of I/O attempts */ + unsigned int wb_nr_pinned; /* Number of pinned pages */ }; struct nfs_pgio_mirror; -- 2.55.0.691.gc56d675ccc-goog