Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2026051pxa; Mon, 3 Aug 2020 05:43:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxZULVmxwNYB57kVNcybFX6BwrZ+qAU3na6gnXSc6EOVrmRIVUvERiaTVL7jpvJUR0d/Xyf X-Received: by 2002:a50:ed8d:: with SMTP id h13mr15251500edr.68.1596458618949; Mon, 03 Aug 2020 05:43:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596458618; cv=none; d=google.com; s=arc-20160816; b=eIF6BPdBnGkpaBvZ8PQqJIccebg0088i5gf8mFHA8zhdKT+U7vzSjFSXAMRYLgL9mH KGfWOEjVBwXc2vligBy5eA+Ur0r1pS8DpizRuxOKt3DRiuGXNnGK+7D1mhbeCDgbqgnS 4zFSN6UO+UTuns4s9mJ5Ix3B9KaqRIOTeLNvz1Z/pwxDvvlM+VXUEMZIn2yWUntFTy2j Utya2l85cKEXrE1mVTO7nI/c2zK5jJaR0fWZaMbZJHWmaCKPVHcUZtFkx0cjjNKebAQJ e0QSdUSLexdyvL+8dv9qZwm27N7Lm+UtN1G85pfEEPL9SN3YFqFlYiXZ2+DScdcIq1Fc +1iQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=LskP3pS81/4HYhyiZLldIRANqKeG/r/rW4cqTpZdoA0=; b=xPkvLbCG/ctRJrOsEcBPjkkmIujNjIjHSP39zyyVzdm/HalQA5USFIjtXpDjtg1yKC bzutnFss5HsQzO6lQbjRpVn2tiEjWS3oVkpNoqfEYCmOhs2hcb5nrg7fF+OwddEb+i9L gkkDaOppVMS8SM1mBzIOtz4FMWM6uhD541d+3OAw470gYHTatRno/KvCNA2jIPFjq4fu cUlBBJzkZBlaM5/4pp8d9aJOgJZKEYrE/LyvwhahkXZYlGmihyvnxJ/LQOaFHaUOxrYZ Z4gYBA2zkI8Vy4Yw6RAKTgcNCc4H5Iwdnr+VLLQge9wcrrgRRdpd34LX/MNXyoXPq5xE M8NA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=DEUKfXjf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r21si11308307edc.313.2020.08.03.05.43.16; Mon, 03 Aug 2020 05:43:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=DEUKfXjf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729437AbgHCMmg (ORCPT + 99 others); Mon, 3 Aug 2020 08:42:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:58398 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729145AbgHCMbE (ORCPT ); Mon, 3 Aug 2020 08:31:04 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C169E204EC; Mon, 3 Aug 2020 12:31:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1596457863; bh=x8SQ6fLnmFmHi/7O0TIoixVz2StNQj93pC7LpaYtCec=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DEUKfXjfXIrohnYXnRoqvaa7mxKFCc7JRjOFuWG9GQFa9erCy7JzG9joBRLkqw5VA QNmL2rXacWu7aAF+RUd6QHQRbmcEGtrGY92IxD2HNZtjZn1M1KD0o+Fq7DyMGM9lAl f2ViM4NQnf13qkeGEBKylWV+ZF+YIMgwOlHt7E6I= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Matteo Croce , Neil Horman , Marcelo Ricardo Leitner , Xin Long , "David S. Miller" , Sasha Levin Subject: [PATCH 4.19 10/56] sctp: implement memory accounting on tx path Date: Mon, 3 Aug 2020 14:19:25 +0200 Message-Id: <20200803121850.821743926@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200803121850.306734207@linuxfoundation.org> References: <20200803121850.306734207@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xin Long [ Upstream commit 1033990ac5b2ab6cee93734cb6d301aa3a35bcaa ] Now when sending packets, sk_mem_charge() and sk_mem_uncharge() have been used to set sk_forward_alloc. We just need to call sk_wmem_schedule() to check if the allocated should be raised, and call sk_mem_reclaim() to check if the allocated should be reduced when it's under memory pressure. If sk_wmem_schedule() returns false, which means no memory is allowed to allocate, it will block and wait for memory to become available. Note different from tcp, sctp wait_for_buf happens before allocating any skb, so memory accounting check is done with the whole msg_len before it too. Reported-by: Matteo Croce Tested-by: Matteo Croce Acked-by: Neil Horman Acked-by: Marcelo Ricardo Leitner Signed-off-by: Xin Long Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/sctp/socket.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/net/sctp/socket.c b/net/sctp/socket.c index c93be3ba5df29..df4a7d7c5ec04 100644 --- a/net/sctp/socket.c +++ b/net/sctp/socket.c @@ -1931,7 +1931,10 @@ static int sctp_sendmsg_to_asoc(struct sctp_association *asoc, if (sctp_wspace(asoc) < (int)msg_len) sctp_prsctp_prune(asoc, sinfo, msg_len - sctp_wspace(asoc)); - if (sctp_wspace(asoc) <= 0) { + if (sk_under_memory_pressure(sk)) + sk_mem_reclaim(sk); + + if (sctp_wspace(asoc) <= 0 || !sk_wmem_schedule(sk, msg_len)) { timeo = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT); err = sctp_wait_for_sndbuf(asoc, &timeo, msg_len); if (err) @@ -8515,7 +8518,10 @@ static int sctp_wait_for_sndbuf(struct sctp_association *asoc, long *timeo_p, goto do_error; if (signal_pending(current)) goto do_interrupted; - if ((int)msg_len <= sctp_wspace(asoc)) + if (sk_under_memory_pressure(sk)) + sk_mem_reclaim(sk); + if ((int)msg_len <= sctp_wspace(asoc) && + sk_wmem_schedule(sk, msg_len)) break; /* Let another process have a go. Since we are going -- 2.25.1