Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp47254pxf; Wed, 24 Mar 2021 20:32:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzrWQQGugXgMhGlKV8oqDOjbvU5iPJJTwrRY+i/hpOeDXwPNJzFSkUOfwO8ljskKAJIQ7OJ X-Received: by 2002:a17:907:72d5:: with SMTP id du21mr7324333ejc.167.1616643171775; Wed, 24 Mar 2021 20:32:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616643171; cv=none; d=google.com; s=arc-20160816; b=QldxHP0PhRkSAtkzt5Vb0ynzOVWuTYudhWTTYrZ5YOkv8Cln+kiadYaCt51dmDrsLa qYcOd2Bsat2rNDm4iMq9Z+q6GoWrjp0adOnp1d9Av+Q8+srPT2FJljRwYw7M7TuFHwPV agpJgRRZ9o2zzpd36mxfv13BZRUMCVMVrfhpuvUarId1VqgoX95QubgBsZ5PbNdC674C C6UJArT/oleOvDPnIPYzxbrPrwLjjemU4EILjSi66MpEQGajA5Whx45rmDCuwYwhoUcZ Y10nb+lxdFiSRTtcZsgfW7LmDYP8tenx6JBa2b7D0uarFX9sHIh6RM2NWF7NGS6eTDKo 7HSQ== 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=jIDPF7ri84OLFsNd4OhxmJPSCi5FNfpE4FjtwEiJamI=; b=slh2i0WJh1/wjLZ0su8W1dtKvoZRvkd08CjLb155GFlVv8IddtNvowWpOh2tyDL1HB IG/4toGzAQSc9fCskLiaf+thCfcZu3BMSiCyO0I8b716ZUY+EcOc94lGgEWghP3ASdwh 1sLkCdpAnD4g3lHj2mh+Z8yvSGVvxH0IEcwdF/Mk4FlqMLP+iavxlHuR8qImU5MGY544 5xriX5J5nJj2dGO5NGA0ZwYJKuTREgp3R/U6u9aGqBPk4I4816G1/mCNm/vtHb0DRCJq CVcvwT8u2NlBpZCQdyDo7Vg4z43hiEAxtZRsiV0WsWWOsnQ6/V0roKcaLpZODpS+1QuG y4JA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=RiBXhaen; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id du1si2622780ejc.12.2021.03.24.20.32.29; Wed, 24 Mar 2021 20:32:51 -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=@google.com header.s=20161025 header.b=RiBXhaen; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238801AbhCXWVj (ORCPT + 99 others); Wed, 24 Mar 2021 18:21:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238835AbhCXWVh (ORCPT ); Wed, 24 Mar 2021 18:21:37 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9658C0613DF for ; Wed, 24 Mar 2021 15:21:36 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id j6-20020a17090adc86b02900cbfe6f2c96so93961pjv.1 for ; Wed, 24 Mar 2021 15:21:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=jIDPF7ri84OLFsNd4OhxmJPSCi5FNfpE4FjtwEiJamI=; b=RiBXhaenM9VBbNf7Ikof8uRUzpei4NDWIP7Ov/61XaLR+CqRNKdKd7fevMR7JsPQSn dak0k7Il33xba+i95mj9167kOtqh9O/gBnyrBpD3mYXz+NZec2sWUmXXD+jKJMkdYHmZ S+kX+o7ONkaASTwWepkBXvtypIYfNzOTkqHPjiHglI7PlYC22lTTYnLEDwcMwTCgkxec wRO9mcct/h+YU/KkpwyhIU78PUQXyAKvNNIsc77BBuYWU+MYo1EK/fOQTtdF7aj/WVKb qWktnXp87q3dMVTR2qYDoRBCoPIB64pUP9Gyq3wDM/GVZaCK+gv6QQIbZe8N95o3IkGQ IQ+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=jIDPF7ri84OLFsNd4OhxmJPSCi5FNfpE4FjtwEiJamI=; b=SwAYRCLJ9A/T3cGr0FuGIGxVU1lLEAhqxZEC2i06kcjMG9pjsw6U6dEak/zzvNpQKv Ui9bfO4R36ZuJcIp2jnRqB9qRaV0YlPiiSdk8cPxNjoApIVMZsHC9cuT6TfgcyxVFCbu 9nW4MFU/RFIG/cvk+e6n0OGdm3LK4jU3RB3LMh3JLDXn/J1oHSOSHB0JW0WGPMQABjSD FKagyBYl1pnE71zIoaZKwAZQX96xFrHVC5Y9AyWkcgviDuZ/DKVjDOlEUG3mweHq5juP Hi7irfK+nGMayuVOCFdOPazW+gp4jIGQN6W6L1eZkVmgGVhzaxyaXsJJkrqsieixJwFR apWA== X-Gm-Message-State: AOAM531745BwwCvLFOayGyuLPYqNqXN6p+wguVLdqlR47DHYKbwfEQKw tKDq8LEo1YVEcEphtOh/wjl3GXMcLR7V5xa0+Hnc6w== X-Received: by 2002:a17:90b:947:: with SMTP id dw7mr5682193pjb.178.1616624496196; Wed, 24 Mar 2021 15:21:36 -0700 (PDT) MIME-Version: 1.0 References: <20210316041645.144249-1-arjunroy.kdev@gmail.com> In-Reply-To: From: Arjun Roy Date: Wed, 24 Mar 2021 15:21:25 -0700 Message-ID: Subject: Re: [mm, net-next v2] mm: net: memcg accounting for TCP rx zerocopy To: Shakeel Butt Cc: Johannes Weiner , Arjun Roy , Andrew Morton , David Miller , netdev , Linux Kernel Mailing List , Cgroups , Linux MM , Eric Dumazet , Soheil Hassas Yeganeh , Jakub Kicinski , Michal Hocko , Yang Shi , Roman Gushchin Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 24, 2021 at 11:26 AM Shakeel Butt wrote: > > On Tue, Mar 23, 2021 at 11:42 AM Arjun Roy wrote: > > > [...] > > > > To summarize then, it seems to me that we're on the same page now. > > I'll put together a tentative v3 such that: > > 1. It uses pre-charging, as previously discussed. > > 2. It uses a page flag to delineate pages of a certain networking sort > > (ie. this mechanism). > > 3. It avails itself of up to 4 words of data inside struct page, > > inside the networking specific struct. > > 4. And it sets up this opt-in lifecycle notification for drivers that > > choose to use it, falling back to existing behaviour without. > > > > Arjun, if you don't mind, can you explain how the lifetime of such a > page will look like? > > For example: > > Driver: > page = dev_alloc_page() > /* page has 1 ref */ Yes, this is the case. > dev_map_page(page) > /* I don't think dev_map_page() takes a ref on page, so the ref remains 1. */ > To be clear, do you mean things like DMA setup here? Or specifically what do you mean by dev_map_page? > On incoming traffic the page goes to skb and which then gets assigned > to a struct sock. Does the kernel increase refcnt of the page on these > operations? > Adding a page to an skb will mean that, when the skb is cleaned up, a page ref is dropped: https://github.com/torvalds/linux/blob/master/net/core/skbuff.c#L666 So a driver may bump the refcount for the page, before adding it to the skb: https://github.com/torvalds/linux/blob/master/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c#L442 > The page gets mapped into user space which increments its refcnt. > Yes. > After processing the data, the application unmaps the page and its > refcnt will be decremented. > Yes. > __put_page() will be called when refcnt reaches 0, so, the initial > refcnt which the driver has acquired, has to be transferred to the > next layer. So, I am trying to understand how that will work? Ah, I see - there was a miscommunication. Johannes mentioned __put_page() but I read put_page(). That is where I was planning on adding the interposition for these network pages. So in put_page(), if it turns out it's a network page, we do our handling then as I described in prior emails. Sorry for the confusion. Thanks, -Arjun