From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (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 37053399348 for ; Wed, 15 Jul 2026 14:35:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784126149; cv=none; b=j2HbhlyhWNggIcYrBtAVMByZauFvmX5gA1jH+I9OVXjcvcougUTr5+M7wuCBYLy6+/MRVe/Cdm8RL/+UEHAODSBA5Y1sJ5VL8ewkdyPEwu+jF9/87yvMCslMLVvlGzja8aCiV2ioGkG3X9pioPf8W6LDvGVUIPEFYFK4Vm6Et4I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784126149; c=relaxed/simple; bh=Y54nOIx9mMVxcTwhAtaUtY293lG/py/OCs16JGVD36U=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=CUrFo2S6URVLOdXUQwxldP0nu98DPHfyR/0ceyj011JVgoXOBwcNUeXmo05gSEqANaG3LrTfFpFENnaFui6XAyZg+eWzzu/WOgmAvaSH3tGpHvyiCdthQq1bIiKzYZE4PNTKK1pZ0uglpiELSN1nQasQ1d/F8MCmrKWWnkICe/8= 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=BaIETx6a; arc=none smtp.client-ip=209.85.210.201 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="BaIETx6a" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-848474825ffso3144426b3a.0 for ; Wed, 15 Jul 2026 07:35:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1784126147; x=1784730947; 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=du9357juXhGcu9dn4Att57AwyAuxnwB17QWxTnC6+90=; b=BaIETx6aGygg4xeUY0oC1Ghf1vjeompR967szGpsOqlpvd2LVfOFr6p1nfVH0TTB9F 7bOu5K4Pum9Ge0t5dm0lQh6DndhVcEDLBRHW+YKPANdzHg1OQCp9XcdI4A0Dsn7bdv3v QnNg93V6R8Q64zo4USFMOXtN5vwE6b9h7NP1pSGZj+o+lVMoH6f1qiv7NdxJDAS0Wc6n QtIXNVEeeKpObXmwc6IwMJBM1d9NnmAzTJNfGG3N05192StvCyXtujQ6Ho4WtcDDLnMm maCpExbdXuduNgsUSIDKkfZfw76E3w8pLr/m+EwRqkW49FsA6CM3frjwvUPtTnuosCiz l7dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784126147; x=1784730947; 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=du9357juXhGcu9dn4Att57AwyAuxnwB17QWxTnC6+90=; b=bGtTohgcQ0eq4eumRhOLcGEfashsXOL+FYJ7FuEFFAP2ncIVvKvvm6jPzyfDm8pLUR ttjb2g1opHHQhauoh8zI9nXqDXQA90mb3pO4mvdJMpH1ASBjqFNDLLFpdvmEjKctJW6f LhvEesaoqPKblajrX3q3JKDDyX1ejFP5TgxB6dYeiH9nD1I0Lbz3rqXIDJLHs/TkyRMr PrlTEV5YNwNFRkh9SXG0tD0BHEwDHqdeKrbZapyLqXAsXoqTzI0dbUpY2YHPE7t8Dxaw hjI2fkHLXJucuq+v9bT8uU1BYTDasNNC/yTzTaM9DnUWrdGGTRerX6hSIe4t99C+3ksP tkmA== X-Forwarded-Encrypted: i=1; AHgh+RraDgY48J364mYUaqzKmNufI5iarVcglnHfhUjpLuGbcjEUJCkSf+v9L8L3K/GEqmO5bmvs1SY+WfmE@vger.kernel.org X-Gm-Message-State: AOJu0YwcVYichoVBV6A3redbr5bIay2C1AIW2v7F2jn7v/3IkKod2lbK 6LXI6SmXXo3kL1vbHUXQJgFP+m5s+nZy4CZAfTMTAp9fq2eGHAXZL87D3Sb5MYVmOWRdQRqeV2L Fvg== X-Received: from pfwz12.prod.google.com ([2002:a05:6a00:1d8c:b0:847:ac08:fdf6]) (user=praan job=prod-delivery.src-stubby-dispatcher) by 2002:aa7:88c9:0:b0:847:b45b:fef3 with SMTP id d2e1a72fcca58-8488acd4d8amr16851338b3a.27.1784126147105; Wed, 15 Jul 2026 07:35:47 -0700 (PDT) Date: Wed, 15 Jul 2026 14:35:37 +0000 In-Reply-To: <20260715143540.3597616-1-praan@google.com> Precedence: bulk X-Mailing-List: linux-rdma@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260715143540.3597616-1-praan@google.com> X-Mailer: git-send-email 2.55.0.229.g6434b31f56-goog Message-ID: <20260715143540.3597616-3-praan@google.com> Subject: [PATCH v3 2/5] nfs: Track number of pinned pages in nfs_page From: Pranjal Shrivastava To: Trond Myklebust , Anna Schumaker , linux-nfs@vger.kernel.org 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 --- fs/nfs/pagelist.c | 9 +++++++-- include/linux/nfs_page.h | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/fs/nfs/pagelist.c b/fs/nfs/pagelist.c index faa8bc1c6526..7d51e10fe97a 100644 --- a/fs/nfs/pagelist.c +++ b/fs/nfs/pagelist.c @@ -455,6 +455,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); @@ -487,6 +489,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); @@ -565,14 +570,14 @@ static void nfs_clear_request(struct nfs_page *req) if (folio != NULL) { if (test_and_clear_bit(PG_PINNED, &req->wb_flags)) - unpin_user_folio(folio, 1); + unpin_user_folio(folio, req->wb_nr_pinned); else folio_put(folio); req->wb_folio = NULL; clear_bit(PG_FOLIO, &req->wb_flags); } else if (page != NULL) { if (test_and_clear_bit(PG_PINNED, &req->wb_flags)) - unpin_user_page(page); + unpin_user_pages(&page, req->wb_nr_pinned); else put_page(page); req->wb_page = NULL; 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.229.g6434b31f56-goog