Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp654799pxf; Thu, 25 Mar 2021 10:52:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxq389nV9K4GhZ3oggQPZfG7xnbYm/gE24Lt0jJMu9878np+dU5CySAI99PE6SosYMaQ9Ly X-Received: by 2002:a17:907:2bdd:: with SMTP id gv29mr10449477ejc.259.1616694751750; Thu, 25 Mar 2021 10:52:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616694751; cv=none; d=google.com; s=arc-20160816; b=wSXYlVAsq1ZsgCXRGfWaXibc8+gyroZN5gFlQj2H/IovyFKrOas3MDOTzxTqNPaKbg PdUa8uwWmvtZxZvVotnAlyVZ8YHTWPkCqlEh3h4SRZ5RiTWWuWAo1PojLmxAfU9+yPT+ X2G8AkrZoRfLd8uRVW2ch+1eIHn1VFsqa8ALbqmPyedW7pPjpgrM4ZqRsv5o7AF208o3 Y2aCizzabpbF0kZPXL/Wzr4pxaskioS6w6Sl9O2y0Ky6q0DBuoQw9ph7oIx2JY0y7h2Q eEFrPhXEEnk9q+WOi8IgY2FB6sEv9GkSnbr9wBFq1pT1ufcl3gdVE8b+X5RXomf02/M2 u2qg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=1FeCnC7WnMeWEj1gEjR7GjHOI7D/MTEeLRIo3/QZ87I=; b=EHhLV6XrGBtvFuVrXtdUKg2/6ZZJ58A9tCDa8e49n0iV5pqnp2tredpunzbvDJOj7n UHWqrCVr7A06PFQIoOBmU/awU4cnMg62V4Qej1ES2dmbzmIkjgVyZkl4s7jEW+lzgqKa scAJhkBYEt/agmBruN/9egB7PcVbHV94zsFzTv9OfrM61Sw46I8RxyHz+O5b9K1SjRcE YvuCDta7UEgSiXB8Itp1hYpTWF2Azf2mNOzeA+4ugCCjAcf47x1y5LffXEcLlI2YgeVr yK0BsV6WUSVlQ3cMnK34Ha5dlA5czHkcVA3S9LI38MEEIxMhNRVCghvBHMECtdwLM5JH G8NQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=bZAJb6mL; 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=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b5si4750825edz.154.2021.03.25.10.52.08; Thu, 25 Mar 2021 10:52:31 -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=@suse.com header.s=susede1 header.b=bZAJb6mL; 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=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229744AbhCYRvC (ORCPT + 99 others); Thu, 25 Mar 2021 13:51:02 -0400 Received: from mx2.suse.de ([195.135.220.15]:51262 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229547AbhCYRuk (ORCPT ); Thu, 25 Mar 2021 13:50:40 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1616694638; h=from:from:reply-to: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=1FeCnC7WnMeWEj1gEjR7GjHOI7D/MTEeLRIo3/QZ87I=; b=bZAJb6mLyiAMxcYv0r40lqxfJfIz0ihLWV4bk7vzIJNh5hPJ+eEuKDstI9YikR9cKGp6Ll TcgCo2d5VBwmadG4q4RyCi0yXJ+VP4ewWHYbqcT0TYOGWe0SgOquLhuLOnytimqlhZVJUk 2M+e8raAOYjJaSFiw4KyiNuQ+mb6z9I= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 52C86AC16; Thu, 25 Mar 2021 17:50:38 +0000 (UTC) Date: Thu, 25 Mar 2021 18:50:30 +0100 From: Michal Hocko To: Johannes Weiner Cc: Arjun Roy , Arjun Roy , Andrew Morton , David Miller , netdev , Linux Kernel Mailing List , Cgroups , Linux MM , Shakeel Butt , Eric Dumazet , Soheil Hassas Yeganeh , Jakub Kicinski , Yang Shi , Roman Gushchin Subject: Re: [mm, net-next v2] mm: net: memcg accounting for TCP rx zerocopy Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu 25-03-21 12:47:04, Johannes Weiner wrote: > On Thu, Mar 25, 2021 at 10:02:28AM +0100, Michal Hocko wrote: > > On Wed 24-03-21 15:49:15, Arjun Roy wrote: > > > On Wed, Mar 24, 2021 at 2:24 PM Johannes Weiner wrote: > > > > > > > > On Wed, Mar 24, 2021 at 10:12:46AM +0100, Michal Hocko wrote: > > > > > On Tue 23-03-21 11:47:54, Arjun Roy wrote: > > > > > > On Tue, Mar 23, 2021 at 7:34 AM Michal Hocko wrote: > > > > > > > > > > > > > > On Wed 17-03-21 18:12:55, Johannes Weiner wrote: > > > > > > > [...] > > > > > > > > Here is an idea of how it could work: > > > > > > > > > > > > > > > > struct page already has > > > > > > > > > > > > > > > > struct { /* page_pool used by netstack */ > > > > > > > > /** > > > > > > > > * @dma_addr: might require a 64-bit value even on > > > > > > > > * 32-bit architectures. > > > > > > > > */ > > > > > > > > dma_addr_t dma_addr; > > > > > > > > }; > > > > > > > > > > > > > > > > and as you can see from its union neighbors, there is quite a bit more > > > > > > > > room to store private data necessary for the page pool. > > > > > > > > > > > > > > > > When a page's refcount hits zero and it's a networking page, we can > > > > > > > > feed it back to the page pool instead of the page allocator. > > > > > > > > > > > > > > > > From a first look, we should be able to use the PG_owner_priv_1 page > > > > > > > > flag for network pages (see how this flag is overloaded, we can add a > > > > > > > > PG_network alias). With this, we can identify the page in __put_page() > > > > > > > > and __release_page(). These functions are already aware of different > > > > > > > > types of pages and do their respective cleanup handling. We can > > > > > > > > similarly make network a first-class citizen and hand pages back to > > > > > > > > the network allocator from in there. > > > > > > > > > > > > > > For compound pages we have a concept of destructors. Maybe we can extend > > > > > > > that for order-0 pages as well. The struct page is heavily packed and > > > > > > > compound_dtor shares the storage without other metadata > > > > > > > int pages; /* 16 4 */ > > > > > > > unsigned char compound_dtor; /* 16 1 */ > > > > > > > atomic_t hpage_pinned_refcount; /* 16 4 */ > > > > > > > pgtable_t pmd_huge_pte; /* 16 8 */ > > > > > > > void * zone_device_data; /* 16 8 */ > > > > > > > > > > > > > > But none of those should really require to be valid when a page is freed > > > > > > > unless I am missing something. It would really require to check their > > > > > > > users whether they can leave the state behind. But if we can establish a > > > > > > > contract that compound_dtor can be always valid when a page is freed > > > > > > > this would be really a nice and useful abstraction because you wouldn't > > > > > > > have to care about the specific type of page. > > > > > > > > Yeah technically nobody should leave these fields behind, but it > > > > sounds pretty awkward to manage an overloaded destructor with a > > > > refcounted object: > > > > > > > > Either every put would have to check ref==1 before to see if it will > > > > be the one to free the page, and then set up the destructor before > > > > putting the final ref. But that means we can't support lockless > > > > tryget() schemes like we have in the page cache with a destructor. > > > > I do not follow the ref==1 part. I mean to use the hugetlb model where > > the destructore is configured for the whole lifetime until the page is > > freed back to the allocator (see below). > > That only works if the destructor field doesn't overlap with a member > the page type itself doesn't want to use. Page types that do want to > use it would need to keep that field exclusive. Right. > We couldn't use it for LRU pages e.g. because it overlaps with the > lru.next pointer. Dang, I have completely missed this. I was looking at pahole because struct page is unreadable in the C code but I tricked myself to only look at offset 16. The initial set of candidate looked really promissing. But overlapping with list_head is a deal breaker. This makes use of dtor for most order-0 pages indeed unfeasible. Maybe dtor can be rellocated but that is certain a rabbit hole people (rightfully) avoid as much as possible. So you are right and going with networking specific way is more reasonable. [...] > So again, yes it would be nice to have generic destructors, but I just > don't see how it's practical. just to clarify on this. I didn't really mean to use this mechanism to all/most pages I just wanted to have PageHasDestructor rather than PageNetwork because both would express a special nead for freeing but that would require that the dtor would be outside of lru. Thanks! -- Michal Hocko SUSE Labs