Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp12182168rwd; Fri, 23 Jun 2023 02:30:24 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7nu0OrN0jJAKciXXZl9hiBfPelBb63qTnTxlqIt2IENYYYJrG3nSoOxlJzQp1tNc6KBkLW X-Received: by 2002:a17:903:228f:b0:1b6:4bbd:c3a7 with SMTP id b15-20020a170903228f00b001b64bbdc3a7mr12720832plh.66.1687512624439; Fri, 23 Jun 2023 02:30:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687512624; cv=none; d=google.com; s=arc-20160816; b=GfS6fMHmluGdoxUDEUdq104Mz6hSRNhhanZ/H964cMJdcrS6CGr6uIX2V7eNip8Y9g c1/W1UdsxaGt0pEOnl0AxfjEBWEoamIaCC14A2Yek0OPl7ssNEjzHSCVcs0i5KLrPjd3 ZeJa1p8ObZk9j6JlkBXRYFRJ0HJzZrvJtpxNEVIj8sNHRV3TSd0tNR7ua77fqAeYYZ66 Q4xnuMG8v+PS0IPzqr+1abv8yiVe2ydD0zd/46ZDlY4oayGcU9lAQt8nYKQNmPM5kWDj 7CXNm8wzyRZFaodi6mNJ6ivncLXuemvq3Fg1hWNgNhOcKZyZFSpLtRawjM95wqXxPddu na2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:content-id:mime-version:subject :cc:to:references:in-reply-to:from:organization:dkim-signature; bh=4/G8RHNBY78+Px5wdz6dNBoCO3mzGUQrI4D5gpZgUjI=; b=HWJKmj55i0emgxz9Sgs5GL7ljbbyLKFbjR/u7Xl5NSPnW9bBtjeVpMHokNZNz/m3hS B4ruuta094Rdcl7HEnXOYjAEx6TuWpVigrwokdDBsLY/m+cZ93skdOHc8iIeDg4GdOem 4avGhV+UrPVr6Oz788m2YvdHbnE+XTj6kwZvZ6yBLfb3dEjA3CNmMcvPQyPkGblZdscy 1luK65d6Yqne5JlvrgUa62Ormmk5n2cybqZdkCYfWjgL7EyfTxvpVWjBROioN3bW6wPc /TT8pOjZ5QyVx8Qr/PeVs3oW0ayM8RLj0/uf8JnIPwjH8P6clYSUSBG9FAUHBkuc0qDJ WYYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=eMIFvo3d; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n17-20020a170902d2d100b001a6b6085041si9548839plc.512.2023.06.23.02.30.09; Fri, 23 Jun 2023 02:30:24 -0700 (PDT) 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=@redhat.com header.s=mimecast20190719 header.b=eMIFvo3d; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231145AbjFWJH5 (ORCPT + 99 others); Fri, 23 Jun 2023 05:07:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230081AbjFWJH4 (ORCPT ); Fri, 23 Jun 2023 05:07:56 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0D49AC for ; Fri, 23 Jun 2023 02:07:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687511232; 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: in-reply-to:in-reply-to:references:references; bh=4/G8RHNBY78+Px5wdz6dNBoCO3mzGUQrI4D5gpZgUjI=; b=eMIFvo3dpbhXI9C7siInK4wQVx4lwAfxZ2OuOvK+u0Cr5YbYa7THRORY3bwp3buYBryBvm Pr+P+5/Dfbu3qkuM2DoWAOVeTRHfRqleJaHSEL7rty4Ebf87UTgNZVFAtgxZwncalyoArd Gz5VL88bpKfpUWxe1kqDsmbqR40i+pY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-620-Yf1WUi0tMI6-F5303-p1OA-1; Fri, 23 Jun 2023 05:07:05 -0400 X-MC-Unique: Yf1WUi0tMI6-F5303-p1OA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3BEC98E44EE; Fri, 23 Jun 2023 09:07:04 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id B254C15230A0; Fri, 23 Jun 2023 09:06:59 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 From: David Howells In-Reply-To: <634c885ccfb2e49e284aedc60e157bb12e5f3530.camel@redhat.com> References: <634c885ccfb2e49e284aedc60e157bb12e5f3530.camel@redhat.com> <20230620145338.1300897-1-dhowells@redhat.com> <20230620145338.1300897-2-dhowells@redhat.com> To: Paolo Abeni Cc: dhowells@redhat.com, netdev@vger.kernel.org, Alexander Duyck , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Willem de Bruijn , David Ahern , Matthew Wilcox , Jens Axboe , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Menglong Dong Subject: Re: [PATCH net-next v3 01/18] net: Copy slab data for sendmsg(MSG_SPLICE_PAGES) MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1969719.1687511219.1@warthog.procyon.org.uk> Date: Fri, 23 Jun 2023 10:06:59 +0100 Message-ID: <1969720.1687511219@warthog.procyon.org.uk> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE 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 Paolo Abeni wrote: > IMHO this function uses a bit too much labels and would be more easy to > read, e.g. moving the above chunk of code in conditional branch. Maybe. I was trying to put the fast path up at the top without the slow path bits in it, but I can put the "insufficient_space" bit there. > Even without such change, I think the above 'goto try_again;' > introduces an unneeded conditional, as at this point we know 'fragsz <= > fsize'. Good point. > > + cache->pfmemalloc = folio_is_pfmemalloc(spare); > > + if (cache->folio) > > + goto reload; > > I think there is some problem with the above. > > If cache->folio is != NULL, and cache->folio was not pfmemalloc-ed > while the spare one is, it looks like the wrong policy will be used. > And should be even worse if folio was pfmemalloc-ed while spare is not. > > I think moving 'cache->pfmemalloc' initialization... > > > + } > > + > > ... here should fix the above. Yeah. We might have raced with someone else or been moved to another cpu and there might now be a folio we can allocate from. > > + /* Reset page count bias and offset to start of new frag */ > > + cache->pagecnt_bias = PAGE_FRAG_CACHE_MAX_SIZE + 1; > > + offset = folio_size(folio); > > + goto try_again; > > What if fragsz > PAGE_SIZE, we are consistently unable to allocate an > high order page, but order-0, pfmemalloc-ed page allocation is > successful? It looks like this could become an unbounded loop? It shouldn't. It should go: try_again: if (fragsz > offset) goto insufficient_space; insufficient_space: /* See if we can refurbish the current folio. */ ... fsize = folio_size(folio); if (unlikely(fragsz > fsize)) goto frag_too_big; frag_too_big: ... return NULL; Though for safety's sake, it would make sense to put in a size check in the case we fail to allocate a larger-order folio. > > do { > > struct page *page = pages[i++]; > > size_t part = min_t(size_t, PAGE_SIZE - off, len); > > - > > - ret = -EIO; > > - if (WARN_ON_ONCE(!sendpage_ok(page))) > > + bool put = false; > > + > > + if (PageSlab(page)) { > > I'm a bit concerned from the above. If I read correctly, tcp 0-copy Well, splice()-to-tcp will; MSG_ZEROCOPY is unaffected. > will go through that for every page, even if the expected use-case is > always !PageSlub(page). compound_head() could be costly if the head > page is not hot on cache and I'm not sure if that could be the case for > tcp 0-copy. The bottom line is that I fear a possible regression here. I can put the PageSlab() check inside the sendpage_ok() so the page flag is only checked once. But PageSlab() doesn't check the headpage, only the page it is given. sendpage_ok() is more the problem as it also calls page_count(). I could drop the check. David