From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E0ADEB64D7 for ; Fri, 23 Jun 2023 09:07:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B90358D0002; Fri, 23 Jun 2023 05:07:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B18E08D0001; Fri, 23 Jun 2023 05:07:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9B9948D0002; Fri, 23 Jun 2023 05:07:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 862508D0001 for ; Fri, 23 Jun 2023 05:07:15 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 42F6FB086C for ; Fri, 23 Jun 2023 09:07:15 +0000 (UTC) X-FDA: 80933433630.04.29E1F05 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf15.hostedemail.com (Postfix) with ESMTP id E83D4A0011 for ; Fri, 23 Jun 2023 09:07:12 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=eMIFvo3d; spf=pass (imf15.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687511233; a=rsa-sha256; cv=none; b=euf0r/EyB1iv0tAJ5oW7VvtHcQZw5Oloe4Jk7GzummBmfHtBBypaScehTFLaUnzg2OF+YR AxwO6DS/UeDSGtYIwNBSBScqc3Ywzp7Zfsip8D/rN2w/faNizXM0u08HIuFnEUkSvKsOt8 PD4V0gfBTs8Fjo1uf2aeLOOppQJ+sPY= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=eMIFvo3d; spf=pass (imf15.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687511233; h=from:from:sender: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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=4/G8RHNBY78+Px5wdz6dNBoCO3mzGUQrI4D5gpZgUjI=; b=1NWc/xxe+e1+lb/z515d5+c+N3HDpgkFAmWS+pjNzISwuriCg05OxijYTwKAT+DBIPJfq5 0hV3Secpoz5U0QF+BgRZ5FQdHqvK/hxeEW+DiN7Lk3elW/Wgfqsi80Q0Wc/SdrtgxjKSuT rsoYUGHo5kAvgsRemJoZDbWxkP87jGc= 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-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dn7PjvZzW9CqiNRSpK7CXMi9cbSoZRP cwdDrqaL /4oxobRsKblByvxE/dB4vt0Kv9v0oNgN1lO3eSbKR2vyNzO0yv6l9Lr5qpaNYOJ345Br02GUfqGDaLwxczyMq2gSIzB70yqEJiAaRky+pcu2ATD3C0ND8u5KKKIk5ciMBbBGjjU8FrF3GyiyY/cdtMtu/p8yIc6Nu3xQ09YdUoBiXOheI3QAhoHyIxvt4x2k/6fUBcLvM2XMwM6su0YsgyZGX4YXjz6EPl49s5WcpRVZyaHBm0CcIOde/qj0xEwDM7cdf5AFuwI7QFBJqB8rjercuuvWsLvu9nT4812okHK8yU3o= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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