Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 10096C33C9E for ; Fri, 17 Jan 2020 18:37:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D8E802072B for ; Fri, 17 Jan 2020 18:37:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="g1VGS5Lk" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729123AbgAQShX (ORCPT ); Fri, 17 Jan 2020 13:37:23 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:34581 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726603AbgAQShX (ORCPT ); Fri, 17 Jan 2020 13:37:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579286241; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cLTS+/3Ohbu8u/u6hwQjq6amgnE2zZD2tJdjwtHQ7Mg=; b=g1VGS5LkPFQE8n3GFRwRHc5eqFmgwrBpkABfagaVbRorWRA1B1usvIcuOATbhRQuSr4cRO uC5D/6aJ+TQ/mB9qY8LUgma0ceUDAv/M9m7ABQWZC0FJoOx9lwltpEdlkbbL4Iw67QW9ks mn3KkUjj4ynx3AixgH6JjONL+nRLPBg= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-26-nXvgQ28bOsiGPhU4uJUwfA-1; Fri, 17 Jan 2020 13:37:20 -0500 X-MC-Unique: nXvgQ28bOsiGPhU4uJUwfA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 71CC014E2; Fri, 17 Jan 2020 18:37:19 +0000 (UTC) Received: from ovpn-118-117.ams2.redhat.com (unknown [10.36.118.117]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4082881200; Fri, 17 Jan 2020 18:37:18 +0000 (UTC) Message-ID: Subject: Re: [PATCH net 3/3] udp: avoid bulk memory scheduling on memory pressure. From: Paolo Abeni To: Eric Dumazet , netdev@vger.kernel.org Cc: "David S. Miller" , Willem de Bruijn Date: Fri, 17 Jan 2020 19:37:17 +0100 In-Reply-To: References: <749f8a12b2caf634249e7590597f0c53e5b37c7a.1579281705.git.pabeni@redhat.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.32.5 (3.32.5-1.fc30) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Hi, On Fri, 2020-01-17 at 09:51 -0800, Eric Dumazet wrote: > On 1/17/20 9:27 AM, Paolo Abeni wrote: > > Williem reported that after commit 0d4a6608f68c ("udp: do rmem bulk > > free even if the rx sk queue is empty") the memory allocated by > > an almost idle system with many UDP sockets can grow a lot. > > > > This change addresses the issue enabling memory pressure tracking > > for UDP and flushing the fwd allocated memory on dequeue if the > > UDP protocol is under memory pressure. > > > > Note that with this patch applied, the system allocates more > > liberally memory for UDP sockets while the total memory usage is > > below udp_mem[1], while the vanilla kernel would allow at most a > > single page per socket when UDP memory usage goes above udp_mem[0] > > - see __sk_mem_raise_allocated(). > > > > Reported-and-diagnosed-by: Willem de Bruijn > > Fixes: commit 0d4a6608f68c ("udp: do rmem bulk free even if the rx sk queue is empty") Thank you for the feedback. > Not a proper Fixes: tag > > Frankly I would rather revert this patch, unless you show how much things were improved. unpatched version: # ensure we will hit memory pressure echo "5000 10000 20000" > /proc/sys/net/ipv4/udp_mem # run the repro from Willem ./repro.py # it get stuck after opening a bunch of sockets, because # __udp_enqueue_schedule_skb() hits the memory limit # and packets are dropped. patched kernel: echo "5000 10000 20000" > /proc/sys/net/ipv4/udp_mem ./repro.py # completes successfully, output trimmed sockets: used 10179 TCP: inuse 4 orphan 0 tw 0 alloc 7 mem 1 UDP: inuse 4 mem 19860 UDPLITE: inuse 0 RAW: inuse 0 FRAG: inuse 0 memory 0 To complete successfully with an unpatched kernel the reproducer requires memory limits 1 or 2 order of magnitude greaters. > Where in the UDP code the forward allocations will be released while udp_memory_pressure > is hit ? fwd memory is released by udp_rmem_release(), so every time some process tries to read from any UDP socket. Surely less effective than the TCP infrastructure, but that other option looks overkill for UDP?!? Thanks, Paolo