From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.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 D385F37BE80 for ; Wed, 3 Jun 2026 05:30:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780464643; cv=none; b=jg6Zhvf8qFKPFnW83iaNag7K7RnelEM9JLOHYXQwCAtHJDP60ARYELRJhw+ZQFta5KRdlC+dCBR2q69cRXnY+3gsD9+/A50tCGjC0zaJxIm1o3a+EFrxkQtDC5RYMbGrC3cpUGBBaUiTnxtWZtXbyfYKjJ0Fojstu1wxOCqQYPg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780464643; c=relaxed/simple; bh=n0mH3N7dN+6P/rXhifQricOYElYnonXD4V1GRu+wSQ8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=LOLNtYuCRYtwztA+xxzASgSbY/6V74PIHhHUCBiZEcbpkZVoEwb90QwME4bU22yEHQiB7jkDQFBAYTsq1oV5sGmnY+pdTQxZCETCbIfAplwgmHGnnUH0vOx7mn0xE7i/4uB5DPhVWfYrbnQc4pPsMQG62XhiPD00j4DckDh0Slk= 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=r9IaPBOM; arc=none smtp.client-ip=209.85.215.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="r9IaPBOM" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-c85a2bf5388so1971989a12.1 for ; Tue, 02 Jun 2026 22:30:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780464641; x=1781069441; 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=aUizU4Vsty2onsNNFrCgDH72BT/u0SfXPzmHgHi1tzY=; b=r9IaPBOMnm49cjBY8ijsGoglRei5LU2mtt3hUL/hvGKjkHgKLmHLr9rqCQz5gs8dHJ //eKIGL/BkxryXO2TJju1BqBgTFViJ7xAZ6wyZ4KyPg42PIWlUrC8M8RVjXZcGZZ/j+H EIoJj/zJcM0xvrFgigbbaMOvb+srDKnuq4GRq487sZFdVwCoQJRYL7RJlvZXRZNZOkqX BByRdj7iGttWON/B9wo4bu5FOCV5El/Kf+SAmeSG5WbaYp9tdEF7Vh/78d2dokADR9qr gIQJfwl4Qc7JfEJ5WSBiVJk4P5RpzuEtK+noPZ2owTEFrgxQHI9CAOCJvTfx0TpZOmA7 4FQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780464641; x=1781069441; 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=aUizU4Vsty2onsNNFrCgDH72BT/u0SfXPzmHgHi1tzY=; b=UwK+P4W/KhGySfmEEsGeZHg3ZpO1r2nSBtuCsICjZ65cPPtGzF0vwcUbamFa2Oat9Z diuWgq9FwsU3waX+1NvOOxoCZXgyyqHM0fNi4cI2hEgvdGuKt9ivv8ryX2s51QTJluI9 EXNklNJx5uG4KxW/BRsHb4BPrcCG7u6zjSz3A8r/gCPFuMm6HowzMKBfOOcuq0Id4Kwo fBzsH89kViU3/rrFk6gah+G1JzuWFKMaX6sO4+QW6c+oGoAkL9xf0mH5pJP93gG0D/sR ZZ2hq86VQ5AkyWfjhLygeLWtLFH6JMBpqxPUoj3hHWD0DzHqBN3Tn0Fed9E+quyI6rnW VjXA== X-Forwarded-Encrypted: i=1; AFNElJ9PH37AaR1vUbO0GBg8OlHCbKaLkcfvkYuKsy2lDEtFpj2AolR7iBPWry56cstaJTf6mcMm07fCYlcw/is=@vger.kernel.org X-Gm-Message-State: AOJu0YyXa1Ag4noXKFaITsWUtr1yt8yGMsFAG4G+NeEhvktnaDMM/TVp eK22/u89aT+9V5EKG54PzuENgZunVn7VkvNsLQ3lABXCgO9cqXtdZoOAGOrGePofSm/RN1XYCeq WJQ== X-Received: from pgbcp1.prod.google.com ([2002:a05:6a02:4001:b0:c73:8295:1401]) (user=praan job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:549b:b0:3b4:7eb0:47a1 with SMTP id adf61e73a8af0-3b49742220emr2047732637.19.1780464640786; Tue, 02 Jun 2026 22:30:40 -0700 (PDT) Date: Wed, 3 Jun 2026 05:30:28 +0000 In-Reply-To: <20260603053033.3300318-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: <20260603053033.3300318-1-praan@google.com> X-Mailer: git-send-email 2.54.0.1013.g208068f2d8-goog Message-ID: <20260603053033.3300318-3-praan@google.com> Subject: [PATCH v1 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 5c5601a27663..f59449918be7 100644 --- a/fs/nfs/pagelist.c +++ b/fs/nfs/pagelist.c @@ -454,6 +454,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); @@ -485,6 +487,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); @@ -563,14 +568,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 9ece78f1b788..295280fe9571 100644 --- a/include/linux/nfs_page.h +++ b/include/linux/nfs_page.h @@ -58,6 +58,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.1013.g208068f2d8-goog