Received: by 2002:a05:7208:3003:b0:81:def:69cd with SMTP id f3csp4294663rba; Tue, 2 Apr 2024 12:38:47 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVGu2vl/YhOqO+OrcCW/W7RDc0lRWb1PdBKWTVyNJO3X7FSdcPag/VEOIe4onKQ2tB5efCLWOLlces7vZXViVo/dYhzQ+HnS0wAbkHRbw== X-Google-Smtp-Source: AGHT+IFOTVJco6T0B7i7M2Qntugse4Y9e8gCXJSOo1N60XfFZBZ2KzbAnidOe40KsxFBr+0exUwL X-Received: by 2002:a50:9993:0:b0:56b:cf26:3af0 with SMTP id m19-20020a509993000000b0056bcf263af0mr7993642edb.17.1712086727431; Tue, 02 Apr 2024 12:38:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712086727; cv=pass; d=google.com; s=arc-20160816; b=zHVo+oV3cw+iRBmL8ULcuyRi9L0j0Fc3wvKpDaOxat40A2VQv2RxTdGBp2NAwWNwJr kx/fMPzft/ubAm1KspXU/Gv7M78xrrG5H5jssFDmVYqxF1ocicw6A8YlA+7yjapqMGGh SjRGgLU+lQEwrAdYAya7Y7enLoj200Ill3ZFy7S142Y8EM5XupinDGr3npnOYJ0upQ1L UEsKxkfxXVW2qrW9vfRlNOPOi4/qMvnwJmWnArrSlkwVFMi4UTQCNvRAUyG2j3+B3LiM QGZIIj0/4boruntLosA5Z/18jJpABJB5ut8Zk95eGxGNS/Sv6Ah/efTE16RCme1XwvRm yM5w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:user-agent:message-id:date:cc:to :from:subject:dkim-signature; bh=VGByJXIBhCED8DpzlbLVfd9F1WCbYmjNgPyYBTdrIQg=; fh=ZZi0jdeLAttkugp1LuhI0ud5A+MAd9tnNEF+aKTRxCA=; b=S2EHshvo6isZWeLTC+qkyowqDNnhbRpQa1GMB5lP5d94ebLEMm4iv2s8DAjFdNC8O/ +h4vEtW4H92+u+anl4bbxmaa3WXU2jyMcUNf0LtugDrhDf0EaWJkfV8KU6Yd9pdsJm/K 11MwY4+B6GGO65M8+M9Leg9cakKhJ+iln2GDQxNZQspmEho+m6UCYCPUQSTNQHuuBFQt CsbApsLmJq2pPPBwqqkElLK6AmaT9nkWZcGQ2EW5cPbU+MM1qLy4yoBlLI4wKatYnCOb OJE4QyQrAttLd3P8zfKDxYWfJkp2cJAtlFDDErUOxeyOeSe8i4GjSbqUsjUUaVvwZ8pz JYkg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Cu/Ehmbq"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-nfs+bounces-2605-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-nfs+bounces-2605-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id b15-20020a056402350f00b0056bfe9ba68dsi6081050edd.270.2024.04.02.12.38.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Apr 2024 12:38:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs+bounces-2605-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Cu/Ehmbq"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-nfs+bounces-2605-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-nfs+bounces-2605-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 17DA31F20F12 for ; Tue, 2 Apr 2024 19:38:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8603515B962; Tue, 2 Apr 2024 19:38:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Cu/Ehmbq" X-Original-To: linux-nfs@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 60B0656458 for ; Tue, 2 Apr 2024 19:38:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712086724; cv=none; b=gpaWRK/fvG9xL074PeMbekRnpgHGNKfVe9WkGULrsXgp8DPJpKYOOO/X0loU0jnSZidD5P1BPfvFyiiHNMWZemh5q1Bl399W3+RYANG6K4KKvb5Qrr8DtgOtQXe1iuK7YQmYSjRi2Rz2eDW1cjW/xWIJwi4K2HQO9SOPHkbl2Ds= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712086724; c=relaxed/simple; bh=8ei3sMVHzU89xrTJg4MS9srEbYDxpJn7C8dSxsIhMfI=; h=Subject:From:To:Cc:Date:Message-ID:MIME-Version:Content-Type; b=VxefU4LV0t7H8x4NTHjLeFzWOAsdBlLT1ENvI+TUCsB4EtD4C3wEHLiVjujEuQGnoGKXDTEk4eHl0I2SV4TDcq8NW+Jo1RO73NaQdkp6mqMzA3oJs96dhRYvWfHB+cyxGxLmZ0xcTxFR8E8XwU/l7BOXR2HmlKeEBe0LYmFSM3o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Cu/Ehmbq; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id B02B7C433F1; Tue, 2 Apr 2024 19:38:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712086724; bh=8ei3sMVHzU89xrTJg4MS9srEbYDxpJn7C8dSxsIhMfI=; h=Subject:From:To:Cc:Date:From; b=Cu/EhmbqZ058XeU6hPNo98yZfDCl5QV2P+WhV3V+WgBCcQhIOhvfejNVoMLOXoKQW MnBQYYxn/ybp1aZ9VRSdXOZFPvUNU9AC4+Sm20yacg9jlJ7IGTuCPcMMXqalI9fj88 YnK4aLBitmDz44lE/625HbHDnjBxidSMlv3GgskUSckv/tZAoQ8+2CF6z/0AHY8jLu ZbIkxaBnjarN7hPvRN48/Uz9KfRWWDQEuWebWHbCnyEug+ElWA17XLg9dem9Xxdv7M UykKrYx16sser/2F60k6gRJP/36d4U6HeAp+APjCejxg9FEcAlCXmvq2Gojc4h2obr 8pygn700Ii32g== Subject: [PATCH RFC] SUNRPC: Fix a slow server-side memory leak with RPC-over-TCP From: Chuck Lever To: linux-nfs@vger.kernel.org Cc: Jan Schunk , Alexander Duyck , Jakub Kacinski , David Howells , Chuck Lever Date: Tue, 02 Apr 2024 15:38:42 -0400 Message-ID: <171208672277.1654.1052289246945629541.stgit@klimt.1015granger.net> User-Agent: StGit/1.5 Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit From: Chuck Lever Jan Schunk reports that his small NFS servers suffer from memory exhaustion after just a few days. A bisect shows that commit e18e157bb5c8 ("SUNRPC: Send RPC message on TCP with a single sock_sendmsg() call") is the first bad commit. That commit assumed that sock_sendmsg() releases all the pages in the underlying bio_vec array, but the reality is that it doesn't. svc_xprt_release() releases the rqst's response pages, but the record marker page fragment isn't one of those, so it was never released. This is a narrow fix that can be applied to stable kernels. A more extensive fix is in the works. Reported-by: Jan Schunk Closes: https://bugzilla.kernel.org/show_bug.cgi?id=218671 Fixes: e18e157bb5c8 ("SUNRPC: Send RPC message on TCP with a single sock_sendmsg() call") Cc: Alexander Duyck Cc: Jakub Kacinski Cc: David Howells Signed-off-by: Chuck Lever --- net/sunrpc/svcsock.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c index 545017a3daa4..be6c6ee85c8f 100644 --- a/net/sunrpc/svcsock.c +++ b/net/sunrpc/svcsock.c @@ -130,6 +130,8 @@ static void svc_reclassify_socket(struct socket *sock) */ static void svc_tcp_release_ctxt(struct svc_xprt *xprt, void *ctxt) { + if (ctxt) + page_frag_free(ctxt); } /** @@ -1237,6 +1239,7 @@ static int svc_tcp_sendmsg(struct svc_sock *svsk, struct svc_rqst *rqstp, return -ENOMEM; memcpy(buf, &marker, sizeof(marker)); bvec_set_virt(rqstp->rq_bvec, buf, sizeof(marker)); + rqstp->rq_xprt_ctxt = buf; count = xdr_buf_to_bvec(rqstp->rq_bvec + 1, ARRAY_SIZE(rqstp->rq_bvec) - 1, &rqstp->rq_res);