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 9C340C433EF for ; Tue, 5 Oct 2021 20:13:17 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 35DA661090 for ; Tue, 5 Oct 2021 20:13:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 35DA661090 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id C83A86B006C; Tue, 5 Oct 2021 16:13:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C3301900002; Tue, 5 Oct 2021 16:13:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B21316B0073; Tue, 5 Oct 2021 16:13:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0082.hostedemail.com [216.40.44.82]) by kanga.kvack.org (Postfix) with ESMTP id A364B6B006C for ; Tue, 5 Oct 2021 16:13:16 -0400 (EDT) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 64CEA8249980 for ; Tue, 5 Oct 2021 20:13:16 +0000 (UTC) X-FDA: 78663483192.14.FCDDED0 Received: from mail-qv1-f45.google.com (mail-qv1-f45.google.com [209.85.219.45]) by imf15.hostedemail.com (Postfix) with ESMTP id 1CCE5D000CCD for ; Tue, 5 Oct 2021 20:13:15 +0000 (UTC) Received: by mail-qv1-f45.google.com with SMTP id a9so502245qvf.0 for ; Tue, 05 Oct 2021 13:13:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=OrX4xdPx3ymxJpzFB7U4JNrUNb/A4iRv7TDCrWWPBno=; b=hjpirae51df0dhDMsLfr2zOy5oUwgpf8cdAZ0MyhpsnRJu2/9h7YS/LA2QdiGvAiOu BqLxok0lUEjRBBRIJ4DfLsjAYbWYQruSo4c92+Qtpb16T1+kkUrHgjJ+ESeJODIOFR5w ThMXplcy8tNmTar5WigqqMQFObB84ymF3EffCs5UY2PfWQZJX6APDxv4ioxLi5bGqOfy 7n80HMJIjG1P8ncGIjhGPUJWkUqRDbAYGPkLwTt4zay7KnyyQg9Z3WiPhDAVK70aEbba v4Y7Flre8RHU6Lj2kJwDrhvYz3O02U4ygq7ZNr+ILz57BzeUlNB+4ZVdpyJBhOj9vd9m eAVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=OrX4xdPx3ymxJpzFB7U4JNrUNb/A4iRv7TDCrWWPBno=; b=LOPPg7oScAznob6Bz6FJmryACbVGqsMZLmKlqya6jORO0M6/yjNPxjYD4HwhzE8CC6 qsu/SzMt/tX86ddka29ye4V8VoEztsfe8FyhI33hF36AUhhtSWv8tuzfQwWsN2yhyJFP FtaCECteFiLgJsE+2eG2+e/7kINuIV6udOYKOYtEmi6p/zT9X9SoB/gRCx11u5vMAxB/ VsDX3heLu2a5zbcI1deP3C4FYCUI6KrBDYp1+r53lUHHF7cPhFF6FrRvS5tsxSw/341d Ul8KKFYnKBSTz4JVTzYhVZsCi4Dk34hXBpR+eDXMTTzqV5rHl+uT5Iz25ktSlTdM/qvJ RFTQ== X-Gm-Message-State: AOAM532j4n0RiieAzR+QHLEaGDUV4dTXXid7Nxd4e95QPpo8M4WQu8hY 23HgcYiDPTc389E6YQJigw== X-Google-Smtp-Source: ABdhPJxAO+dHNPcL8ZY7s+MCFIUwxZ6WNKcUKob+Bj4mQtL/XOFOVn7LCjsCjdcdu50RYgZ+jIhk5Q== X-Received: by 2002:a05:6214:176d:: with SMTP id et13mr1711781qvb.62.1633464795459; Tue, 05 Oct 2021 13:13:15 -0700 (PDT) Received: from moria.home.lan (c-73-219-103-14.hsd1.vt.comcast.net. [73.219.103.14]) by smtp.gmail.com with ESMTPSA id c6sm12079668qtx.72.2021.10.05.13.13.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Oct 2021 13:13:14 -0700 (PDT) Date: Tue, 5 Oct 2021 16:13:12 -0400 From: Kent Overstreet To: Matthew Wilcox Cc: linux-mm@kvack.org, Minchan Kim , Nitin Gupta , Sergey Senozhatsky , Johannes Weiner Subject: Re: pageless memory & zsmalloc Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Queue-Id: 1CCE5D000CCD X-Stat-Signature: b8g6qzawiibtbmppjh36pqp91is883qc Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=hjpirae5; spf=pass (imf15.hostedemail.com: domain of kent.overstreet@gmail.com designates 209.85.219.45 as permitted sender) smtp.mailfrom=kent.overstreet@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam06 X-HE-Tag: 1633464795-465589 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 Tue, Oct 05, 2021 at 06:51:32PM +0100, Matthew Wilcox wrote: > We're trying to tidy up the mess in struct page, and as part of removing > slab from struct page, zsmalloc came on my radar because it's using some > of slab's fields. The eventual endgame is to get struct page down to a > single word which points to the "memory descriptor" (ie the current > zspage). > > zsmalloc, like vmalloc, allocates order-0 pages. Unlike vmalloc, > zsmalloc allows compaction. Currently (from the file): > > * Usage of struct page fields: > * page->private: points to zspage > * page->freelist(index): links together all component pages of a zspage > * For the huge page, this is always 0, so we use this field > * to store handle. > * page->units: first object offset in a subpage of zspage > * > * Usage of struct page flags: > * PG_private: identifies the first component page > * PG_owner_priv_1: identifies the huge component page > > This isn't quite everything. For compaction, zsmalloc also uses > page->mapping (set in __SetPageMovable()), PG_lock (to sync with > compaction) and page->_refcount (compaction gets a refcount on the page). > > Since zsmalloc is so well-contained, I propose we completely stop > using struct page in it, as we intend to do for the rest of the users > of struct page. That is, the _only_ element of struct page we use is > compound_head and it points to struct zspage. > > That means every single page allocated by zsmalloc is PageTail(). Also it > means that when isolate_movable_page() calls trylock_page(), it redirects > to the zspage. That means struct zspage must now have page flags as its > first element. Also, zspage->_refcount, and zspage->mapping must match > their locations in struct page. That's something that we'll get cleaned > up eventually, but for now, we're relying on offsetof() assertions. > > The good news is that trylock_zspage() no longer needs to walk the > list of pages, calling trylock_page() on each of them. > > Anyway, is there a good test suite for zsmalloc()? Particularly something > that would exercise its interactions with compaction / migration? > I don't have any code written yet. This is some deep hackery. So to restate - and making sure I understand correctly - the reason for doing it this way is that the compaction code calls lock_page(); by using compound_head (instead of page->private) for the pointer to the zspage is so that compound_head() will return the pointer to zspage, and lock_page() uses compound_page(), so the compaction code, when it calls lock_page(), will actually be taking the lock in struct zspage. So on the one hand, getting struct page down to two words means that we're going to be moving the page lock bit into those external structs (maybe we _should_ be doing some kind of inheritence thing, for the allocatee interface?) - so it is cool that that all lines up. But long term, we're going to need two words in struct page, not just one: We need to store the order of the allocation, and a type tagged pointer, and I don't think we can realistically cram compound_order into the same word as the type tagged pointer. Plus, transparently using slab for larger allocations - that today use the buddy allocator interface - means slab can't be using the allocatee pointer field. And in my mind, compound_head is allocator state, not allocatee state, and it's always been using for getting to the head page, which... this is not, so using it this way, as slick as it is... eh, not sure that's quite what we want to do. Q: should lock_page() be calling compound_head() at all? If the goal of the type system stuff that we're doing is to move the compound_head() calls up to where we're dealing with tail pages and never more after that, then that call in lock_page() should go - and we'll need to figure out something different for the migration code to take the lock in the allocatee-private structure. I've been kind of feeling that since folios are furthest along, separately allocating them and figuring out how to make that all work might be the logical next step.