From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) (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 4942D32939C for ; Tue, 16 Jun 2026 13:40:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781617209; cv=none; b=pkiHxkzumXvWY0Ckw/WPw0HpuLwR5EKGBPROVx6nEnQ+g2r2fBMrahm6XqfqKBUJQ0mMXtkFxCNsUz50+3CBJSGz9oamXzVQYI4cYaUWEb9DHmTW2EID83dimhjdIFMYX+qOpYNFkx1lYVNp0te7JG11IZvDWLlKIVbz/mVx93k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781617209; c=relaxed/simple; bh=y4SrqlcQUH1NTWAOkVX8IcfVRt/JvGwglpqKLAgS46c=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=BGY2B2Q8/mzw6fV9rqbtI8n5XZoegNSIuF/MILhHqgwHHJdPZODqwiiSy84jaLxZ9IgXk5f5tjFEWUuOTewKT9/xH6pu5Jjf0NkcPxA0YjIftPPlC/uLKbDiHm45akTv+w6dkqXfDv/ifx3UfevyJTNJpsWrNiNydRGWTLJoIkg= 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=KVs6wcke; arc=none smtp.client-ip=209.85.215.202 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="KVs6wcke" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-c85a366b61fso2688790a12.3 for ; Tue, 16 Jun 2026 06:40:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1781617208; x=1782222008; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=3SVlvry5FcOzYHP8fF1VVoNZ4UfIPPvWckgyb5sjBA8=; b=KVs6wckemJoFrj42FYunCmgzwAjBtmFZxCaXkhDmrPpj5Q549siglNP/SbPTONwfvj 6cAh7AbLrqdszaT7ODDQCd//R8IyM8Hpk+Cp3YimVEmzo/hg0LoRm8T7ZE8BEcZhMSJT kTFuPiGTrbU8dXlIwjXfV5bFbd4l8ohbYbYXphrNmjWbpHCq4hicIVcQTPJAutInvomi 6TmpnKGS7AwQkM+tPWGhs0o+GcZBMVPQ3F5zeWvXbbtY+udcXs9JBnPSJFjvtdu9fQBl cZXMEYV4ViyMRLxK1n7eLvpOHTRgimkpYS8LyLkDo9V20CzAe1H1rDmUiL2elXA03RDN Hjdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781617208; x=1782222008; h=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; bh=3SVlvry5FcOzYHP8fF1VVoNZ4UfIPPvWckgyb5sjBA8=; b=rqLFBeDn882y4qrAag7HfPgVDiUdsykj6ZTY12UMk2v7SqXQz8gIiy1mpPpVSfTH7W rZOwjxk60HgjNA7VjOc/UvyDcGtzEcSK266ihHY/RN+2akYnynagdnll1Sq+lJAiRBfo X8aaVvGDkWDZ9Idr8PsbUhfDDBSO0mMMZGifAclWRhsOy2Td7b5yh1dBuW9Vd2Xn+lhC 3WW2q33GaTSsFyHUWVTBa0/p62rAHSCPx8TTv3Y1LYBeGiogOJM008PzEKHckVAp0n68 EBLQ91XNwXeIUcnGWzKd/KUAWvDeAaAeuAL7g5cl9aBOUg2jaNVyisFex9X+lrlmfC4u PH3w== X-Forwarded-Encrypted: i=1; AFNElJ+7N/xR72edVG953k67O1nooKXCfa+pGWjCX8OkA2Ih1DOQjCQrRhdi23cfh3jr89N1Byk/RLY4TDnnHe4=@vger.kernel.org X-Gm-Message-State: AOJu0YxsjjACRGPgjj+BqyFlaTvU+dzNg7pjVuuZoTN2+yvS05mtfHja dR83tiVMfEtWBlsdLlF1C/0kzyI4qfPG0G+Aln2EOlMS/3WJSUSLtAFsYxzLpHZg15f+qiPKlDK N+A== X-Received: from pgjh21.prod.google.com ([2002:a63:df55:0:b0:c85:6b39:d407]) (user=praan job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:492:b0:3b4:6a31:6d0f with SMTP id adf61e73a8af0-3b7e4deb96bmr4370444637.41.1781617207383; Tue, 16 Jun 2026 06:40:07 -0700 (PDT) Date: Tue, 16 Jun 2026 13:39:55 +0000 In-Reply-To: <20260616134000.2733403-1-praan@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260616134000.2733403-1-praan@google.com> X-Mailer: git-send-email 2.54.0.1136.gdb2ca164c4-goog Message-ID: <20260616134000.2733403-3-praan@google.com> Subject: [PATCH v2 2/7] nfs: Track number of pinned pages in nfs_page From: Pranjal Shrivastava To: linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Trond Myklebust , Anna Schumaker , Christoph Hellwig , Christoph Hellwig , 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.54.0.1136.gdb2ca164c4-goog