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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D9076C433EF for ; Fri, 22 Oct 2021 07:59:11 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7E8FA610EA for ; Fri, 22 Oct 2021 07:59:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 7E8FA610EA Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 05748900003; Fri, 22 Oct 2021 03:59:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F2230900002; Fri, 22 Oct 2021 03:59:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D4DFB900003; Fri, 22 Oct 2021 03:59:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0111.hostedemail.com [216.40.44.111]) by kanga.kvack.org (Postfix) with ESMTP id C3BD3900002 for ; Fri, 22 Oct 2021 03:59:10 -0400 (EDT) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 795F8182111BB for ; Fri, 22 Oct 2021 07:59:10 +0000 (UTC) X-FDA: 78723322860.10.6B4FAD2 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf16.hostedemail.com (Postfix) with ESMTP id 6A9FEF00008F for ; Fri, 22 Oct 2021 07:59:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1634889549; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kZoWYLLUFZ8JY44SKry8OHyZeTm3yXeRKD2OKegls7I=; b=RxQsVKb/eZ/rRNO/XF2IFs1755HwZpxWUfu+jXCQRGjTpNgnc3UVkGXwgzrxFbCLs6qnve Gz+24vSMSDWizzX3HAWxkFveYhYMdaSmronW+zYk6DTfxoE3c4Mv+jeOtsTXadBiBCZybD o/VWj7Fyk2s7+fSE6KWV+pQJq9ar6YM= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-6-6Lj3Q2Z4PmCbPSU9wlB8Hg-1; Fri, 22 Oct 2021 03:59:07 -0400 X-MC-Unique: 6Lj3Q2Z4PmCbPSU9wlB8Hg-1 Received: by mail-wr1-f72.google.com with SMTP id j19-20020adfb313000000b00160a9de13b3so692990wrd.8 for ; Fri, 22 Oct 2021 00:59:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent :content-language:to:cc:references:from:organization:subject :in-reply-to:content-transfer-encoding; bh=kZoWYLLUFZ8JY44SKry8OHyZeTm3yXeRKD2OKegls7I=; b=y2/o3k68n0c02mtj42YFBUqOK1cHmuW46omv5g33hxgldWwU25OvgnXZTwGCsnBCoe HCbPbt2VovQAFW1jG8E0/gCPMrRnzFeuFu0N5E1fGH7VvliYt0+OuGDq4dAzDI8VkkGi rN2m1NOmK3pz/cHt3GqA2fFF/s2eWFavh0DyJO30FrRtz6PrZZNqVK7B27f53HGqri/J YLd5XOf3EvjOigmLwxaKeOon9TtlKvSLMEaALfmkxhEwdMWVHn68PtpnYAc9FHzf7idM qI7zCKV55ZSuzGKqzYEcj24v1x1zDzIgc19NEVl7sNfTwlhuRfPUXnctjvNTbuqAAI53 LlRA== X-Gm-Message-State: AOAM532tPay7Hoxaai7bvv1/1EvRRA36FLs2VURMxtHAmizFqsw+aF8d hodMR4tlRwHidSj9V0DqIQjBgYc8Ghyt18mmOtAiMbeuhjW+5Hap4N3EkEidJinRTlEmP8Nejzf 6UKhyGzAVLvg= X-Received: by 2002:a5d:6d8f:: with SMTP id l15mr14121153wrs.350.1634889546664; Fri, 22 Oct 2021 00:59:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzLtKFRJX+mIe1fizAqfht37OT+GQUelpvBz5XAYxttgYXk3SlQgfC0gIGg3GDQtW72nlShUA== X-Received: by 2002:a5d:6d8f:: with SMTP id l15mr14121107wrs.350.1634889546352; Fri, 22 Oct 2021 00:59:06 -0700 (PDT) Received: from [192.168.3.132] (p5b0c6324.dip0.t-ipconnect.de. [91.12.99.36]) by smtp.gmail.com with ESMTPSA id i17sm7855993wru.18.2021.10.22.00.59.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 22 Oct 2021 00:59:05 -0700 (PDT) Message-ID: <326b5796-6ef9-a08f-a671-4da4b04a2b4f@redhat.com> Date: Fri, 22 Oct 2021 09:59:05 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.1.0 To: Matthew Wilcox , Johannes Weiner Cc: Kent Overstreet , "Kirill A. Shutemov" , Linus Torvalds , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Andrew Morton , "Darrick J. Wong" , Christoph Hellwig , David Howells , Hugh Dickins References: <20211018231627.kqrnalsi74bgpoxu@box.shutemov.name> From: David Hildenbrand Organization: Red Hat Subject: Re: Folios for 5.15 request - Was: re: Folio discussion recap - In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 6A9FEF00008F X-Stat-Signature: 7tkz9fbn7xbybi8wpxn1eb7g6ojifg63 Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="RxQsVKb/"; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf16.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=david@redhat.com X-HE-Tag: 1634889546-235245 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: On 22.10.21 03:52, Matthew Wilcox wrote: > On Thu, Oct 21, 2021 at 05:37:41PM -0400, Johannes Weiner wrote: >> Here is my summary of the discussion, and my conclusion: > > Thank you for this. It's the clearest, most useful post on this thread, > including my own. It really highlights the substantial points that > should be discussed. > >> The premise of the folio was initially to simply be a type that says: >> I'm the headpage for one or more pages. Never a tailpage. Cool. >> >> However, after we talked about what that actually means, we seem to >> have some consensus on the following: >> >> 1) If folio is to be a generic headpage, it'll be the new >> dumping ground for slab, network, drivers etc. Nobody is >> psyched about this, hence the idea to split the page into >> subtypes which already resulted in the struct slab patches. >> >> 2) If higher-order allocations are going to be the norm, it's >> wasteful to statically allocate full descriptors at a 4k >> granularity. Hence the push to eliminate overloading and do >> on-demand allocation of necessary descriptor space. >> >> I think that's accurate, but for the record: is there anybody who >> disagrees with this and insists that struct folio should continue to >> be the dumping ground for all kinds of memory types? > > I think there's a useful distinction to be drawn between "where we're > going with this patchset", "where we're going in the next six-twelve > months" and "where we're going eventually". I think we have minor > differences of opinion on the answers to those questions, and they can > be resolved as we go, instead of up-front. > > My answer to that question is that, while this full conversion is not > part of this patch, struct folio is logically: > > struct folio { > ... almost everything that's currently in struct page ... > }; > > struct page { > unsigned long flags; > unsigned long compound_head; > union { > struct { /* First tail page only */ > unsigned char compound_dtor; > unsigned char compound_order; > atomic_t compound_mapcount; > unsigned int compound_nr; > }; > struct { /* Second tail page only */ > atomic_t hpage_pinned_refcount; > struct list_head deferred_list; > }; > unsigned long padding1[4]; > }; > unsigned int padding2[2]; > #ifdef CONFIG_MEMCG > unsigned long padding3; > #endif > #ifdef WANT_PAGE_VIRTUAL > void *virtual; > #endif > #ifdef LAST_CPUPID_NOT_IN_PAGE_FLAGS > int _last_cpupid; > #endif > }; > > (I'm open to being told I have some of that wrong, eg maybe _last_cpupid > is actually part of struct folio and isn't a per-page property at all) > > I'd like to get there in the next year. I think dynamically allocating > memory descriptors is more than a year out. > > Now, as far as struct folio being a dumping group, I would like to > split other things out from struct folio. Let me address that below. > >> Let's assume the answer is "no" for now and move on. >> >> If folios are NOT the common headpage type, it begs two questions: >> >> 1) What subtype(s) of page SHOULD it represent? >> >> This is somewhat unclear at this time. Some say file+anon. >> It's also been suggested everything userspace-mappable, but >> that would again bring back major type punning. Who knows? >> >> Vocal proponents of the folio type have made conflicting >> statements on this, which certainly gives me pause. >> >> 2) What IS the common type used for attributes and code shared >> between subtypes? >> >> For example: if a folio is anon+file, then the code that >> maps memory to userspace needs a generic type in order to >> map both folios and network pages. Same as the page table >> walkers, and things like GUP. >> >> Will this common type be struct page? Something new? Are we >> going to duplicate the implementation for each subtype? >> >> Another example: GUP can return tailpages. I don't see how >> it could return folio with even its most generic definition >> of "headpage". >> >> (But bottomline, it's not clear how folio can be the universal >> headpage type and simultaneously avoid being the type dumping ground >> that the page was. Maybe I'm not creative enough?) > > This whole section is predicated on "If it is NOT the headpage type", > but I think this is a great list of why it _should_ be the generic > headpage type. > > To answer a questions in here; GUP should continue to return precise > pages because that's what its callers expect. But we should have a > better interface than GUP which returns a rather more compressed list > (something like today's biovec). > >> Anyway. I can even be convinved that we can figure out the exact fault >> lines along which we split the page down the road. >> >> My worry is more about 2). A shared type and generic code is likely to >> emerge regardless of how we split it. Think about it, the only world >> in which that isn't true would be one in which either >> >> a) page subtypes are all the same, or >> b) the subtypes have nothing in common >> >> and both are clearly bogus. > > Amen! > > I'm convinced that pgtable, slab and zsmalloc uses of struct page can all > be split out into their own types instead of being folios. They have > little-to-nothing in common with anon+file; they can't be mapped into > userspace and they can't be on the LRU. The only situation you can find > them in is something like compaction which walks PFNs. > > I don't think we can split out ZONE_DEVICE and netpool into their own > types. While they can't be on the LRU, they can be mapped to userspace, > like random device drivers. So they can be found by GUP, and we want > (need) to be able to go to folio from there in order to get, lock and > set a folio as dirty. Also, they have a mapcount as well as a refcount. > > The real question, I think, is whether it's worth splitting anon & file > pages out from generic pages. I can see arguments for it, but I can also > see arguments against it (whether it's two types: lru_mem and folio, > three types: anon_mem, file_mem and folio or even four types: ksm_mem, > anon_mem and file_mem). I don't think a compelling argument has been > made either way. > > Perhaps you could comment on how you'd see separate anon_mem and > file_mem types working for the memcg code? Would you want to have > separate lock_anon_memcg() and lock_file_memcg(), or would you want > them to be cast to a common type like lock_folio_memcg()? FWIW, something like this would roughly express what I've been mumbling about: anon_mem file_mem | | ------|------ lru_mem slab | | ------------- | page I wouldn't include folios in this picture, because IMHO folios as of now are actually what we want to be "lru_mem", just which a much clearer name+description (again, IMHO). Going from file_mem -> page is easy, just casting pointers. Going from page -> file_mem requires going to the head page if it's a compound page. But we expect most interfaces to pass around a proper type (e.g., lru_mem) instead of a page, which avoids having to lookup the compund head page. And each function can express which type it actually wants to consume. The filmap API wants to consume file_mem, so it should use that. And IMHO, with something above in mind and not having a clue which additional layers we'll really need, or which additional leaves we want to have, we would start with the leaves (e.g., file_mem, anon_mem, slab) and work our way towards the root. Just like we already started with slab. Maybe that makes sense. -- Thanks, David / dhildenb