Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2783134rwb; Fri, 9 Dec 2022 06:20:52 -0800 (PST) X-Google-Smtp-Source: AA0mqf4r1ii0SkYHswt/jBHqjOQrWQfKpwGXnvj50AZuaMxUQS1xVwsNnAP8XlxU6WYwPeYDO4hs X-Received: by 2002:a17:906:828f:b0:7c1:652:d109 with SMTP id h15-20020a170906828f00b007c10652d109mr5399564ejx.35.1670595651866; Fri, 09 Dec 2022 06:20:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670595651; cv=none; d=google.com; s=arc-20160816; b=cK12vslM3GIkk/rzOEB7nNVr2cWkr/JF1hgdmeIGHafhubuyElVKaU0AqEuS91YKqY H1n85SdjDlP37SZpRcsKO+I8oLgalWZW4Br2JBErWxKbbNIBdDQne53DLxnX1IPzxcaM S2+4YNgAxgR3Z0h6vUNWF5EA5YE0PIu980gwSg7IEblldN8Lw0F4FvEfx1U/QKZN1Dwb s//lwWtkqBfm+tUqS9r94azM+jqS6xEpUJZe3SaxJXyiaKNr/tv1ngnJj7AxK/SAfDgg MaUj44VhvqvqBSCXjHv+TujwvHkC3HmQarDdpjqmLh4Fpxbe16rHhxpviVnZE4gGwkGt wTXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=Q7LlfAQWpPNLuhOgcUZ4tUXnEA1fFuup+0DIajKdSqk=; b=NpyP0lsdmbZDeGVA3yDg32XDhB2MKVxoCkRyvPNyf5phjkjnAFt346NaGN4Y4/hew5 RYFWEcF53vaK66uI+W4y7xciR5ACpxpEu1qQ3FJbmIewjTea2P39Q+LVWs8BQPSlJBaw PsgTuTckRuVOW+5DSBFqmiXE+2sdVI8UeAj71G4VNjfldh0o8peDp0LfzqyvxL1tGEEY rTitPGtmAxRR9kWeV3Zb/ZApl0B6PpANT0HAq92dFeOiqbuEr1WAmlxRFcStLdpVE8g3 vi/oySoqoWPQQizBrA5U7Xi94OZ7o21XST8zkFbpMNIdkkUfAMGJTtcZyQz/WthbnUoJ o9GQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=fGQBPTJJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ga35-20020a1709070c2300b007c0e0d7abe5si1286812ejc.782.2022.12.09.06.20.29; Fri, 09 Dec 2022 06:20:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=fGQBPTJJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230048AbiLIORY (ORCPT + 75 others); Fri, 9 Dec 2022 09:17:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229545AbiLIORD (ORCPT ); Fri, 9 Dec 2022 09:17:03 -0500 Received: from mail-yb1-xb33.google.com (mail-yb1-xb33.google.com [IPv6:2607:f8b0:4864:20::b33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD734263 for ; Fri, 9 Dec 2022 06:16:48 -0800 (PST) Received: by mail-yb1-xb33.google.com with SMTP id b16so5710271yba.0 for ; Fri, 09 Dec 2022 06:16:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=Q7LlfAQWpPNLuhOgcUZ4tUXnEA1fFuup+0DIajKdSqk=; b=fGQBPTJJzLXlXiBSV/dp2MY0Y7S9JALxm7neMKI6NAPPeM6sjCXwJ97CJkvftDVqQV j+pwbzD7mmLknkWlCNQWgJZWPtwuGSynrExWnipZNN4LoqH+/6cLgBTbdR4Sgzs9ih9N t0gCEBt2YbnKHbwmYcMjgg8eiaqEn80lNuxOplx8uaDb1+5Cl1p+mrjbWOpHo31LlJxP dRojfE15wK7U3RFp21T7t8aOOGRWQrARkBHNukcMpjxcNonLxmx4ycHxEI3PeXV+mhFH /rGYeLD+SbM2OdTR7UcFAGJLChheMYK0iuNnrWipVZFEE7QssIW1TweRD6nHyB1QjtRK uiWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Q7LlfAQWpPNLuhOgcUZ4tUXnEA1fFuup+0DIajKdSqk=; b=l8DX9sCmjb+Oh4kUwZlgr9bOCw7x3jHao/nMGJEOMUV9YSOJrpA6GitksxwXkUpaKU fSQUcnATA2oiQi8Gcw0SzZutWKVXLbg1DJX9rqfI6lzcQme6JBLdJ46F7KtH7dU41GRB 0qt7bprzS6kS8TDE6SoCOd3P+m8I5mQam/EABiSQnnEpWzYhr84HkVjpnZsGvvjIzj66 yArE0tG9HID6Rzw1Gd1CN+pQsJjzECvOT38Tfhh4QAtS5kN9TF6SNl1c8oNqeO9fS5hu DIpH7vWu3/B6wQD1CDNvwGGUO0Bj9DeK+9Mfh8hsTmf7yP6tl29mM0HV4gZr23d6eqq+ TGqg== X-Gm-Message-State: ANoB5pmpI/TG+sZMbBHyKaZ6LZ0V2OWpqR6eaVQQzX7tADxzeJ6fVWUx KCq/rCr55K++cVtknQPxMy4S2HcZVCM8OrqXo1E2zg== X-Received: by 2002:a25:445:0:b0:703:657f:9c91 with SMTP id 66-20020a250445000000b00703657f9c91mr9904740ybe.387.1670595407569; Fri, 09 Dec 2022 06:16:47 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Eric Dumazet Date: Fri, 9 Dec 2022 15:16:36 +0100 Message-ID: Subject: Re: [PATCH v1 1/3] net: Introduce sk_use_task_frag in struct sock. To: Paolo Abeni Cc: Benjamin Coddington , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "David S. Miller" , Jakub Kicinski , Soheil Hassas Yeganeh , Shakeel Butt , Pavel Begunkov , Kuniyuki Iwashima , =?UTF-8?Q?Maciej_=C5=BBenczykowski?= , Menglong Dong , Akhmat Karakotov , Alexander Duyck Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Dec 9, 2022 at 1:09 PM Paolo Abeni wrote: > > On Mon, 2022-11-21 at 08:35 -0500, Benjamin Coddington wrote: > > From: Guillaume Nault > > > > Sockets that can be used while recursing into memory reclaim, like > > those used by network block devices and file systems, mustn't use > > current->task_frag: if the current process is already using it, then > > the inner memory reclaim call would corrupt the task_frag structure. > > > > To avoid this, sk_page_frag() uses ->sk_allocation to detect sockets > > that mustn't use current->task_frag, assuming that those used during > > memory reclaim had their allocation constraints reflected in > > ->sk_allocation. > > > > This unfortunately doesn't cover all cases: in an attempt to remove all > > usage of GFP_NOFS and GFP_NOIO, sunrpc stopped setting these flags in > > ->sk_allocation, and used memalloc_nofs critical sections instead. > > This breaks the sk_page_frag() heuristic since the allocation > > constraints are now stored in current->flags, which sk_page_frag() > > can't read without risking triggering a cache miss and slowing down > > TCP's fast path. > > > > This patch creates a new field in struct sock, named sk_use_task_frag, > > which sockets with memory reclaim constraints can set to false if they > > can't safely use current->task_frag. In such cases, sk_page_frag() now > > always returns the socket's page_frag (->sk_frag). The first user is > > sunrpc, which needs to avoid using current->task_frag but can keep > > ->sk_allocation set to GFP_KERNEL otherwise. > > > > Eventually, it might be possible to simplify sk_page_frag() by only > > testing ->sk_use_task_frag and avoid relying on the ->sk_allocation > > heuristic entirely (assuming other sockets will set ->sk_use_task_frag > > according to their constraints in the future). > > > > The new ->sk_use_task_frag field is placed in a hole in struct sock and > > belongs to a cache line shared with ->sk_shutdown. Therefore it should > > be hot and shouldn't have negative performance impacts on TCP's fast > > path (sk_shutdown is tested just before the while() loop in > > tcp_sendmsg_locked()). > > > > Link: https://lore.kernel.org/netdev/b4d8cb09c913d3e34f853736f3f5628abfd7f4b6.1656699567.git.gnault@redhat.com/ > > Signed-off-by: Guillaume Nault > > --- > > include/net/sock.h | 11 +++++++++-- > > net/core/sock.c | 1 + > > 2 files changed, 10 insertions(+), 2 deletions(-) > > > > diff --git a/include/net/sock.h b/include/net/sock.h > > index d08cfe190a78..ffba9e95470d 100644 > > --- a/include/net/sock.h > > +++ b/include/net/sock.h > > @@ -318,6 +318,9 @@ struct sk_filter; > > * @sk_stamp: time stamp of last packet received > > * @sk_stamp_seq: lock for accessing sk_stamp on 32 bit architectures only > > * @sk_tsflags: SO_TIMESTAMPING flags > > + * @sk_use_task_frag: allow sk_page_frag() to use current->task_frag. > > + Sockets that can be used under memory reclaim should > > + set this to false. > > * @sk_bind_phc: SO_TIMESTAMPING bind PHC index of PTP virtual clock > > * for timestamping > > * @sk_tskey: counter to disambiguate concurrent tstamp requests > > @@ -504,6 +507,7 @@ struct sock { > > #endif > > u16 sk_tsflags; > > u8 sk_shutdown; > > + bool sk_use_task_frag; > > atomic_t sk_tskey; > > atomic_t sk_zckey; > > I think the above should be fine from a data locality PoV, as the used > cacheline should be hot at sk_page_frag_refill() usage time, as > sk_tsflags has been accessed just before. > > @Eric, does the above fit with the planned sock fields reordering? Do not worry about that, this can be handled later if needed. > > Jakub noted we could use a bitfield here to be future proof for > additional flags addition. I think in this specific case a bool is > preferable, because we actually wont to discourage people to add more > of such flags, and the search for holes (or the bool -> bitflag > conversion) should give to such eventual future changes some additional > thoughts. > > Thanks! > > Paolo >