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 A3926C433F5 for ; Wed, 13 Oct 2021 19:58:01 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3C35861165 for ; Wed, 13 Oct 2021 19:58:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 3C35861165 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=cmpxchg.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id AF0806B006C; Wed, 13 Oct 2021 15:58:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A9E596B0071; Wed, 13 Oct 2021 15:58:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 917E46B0072; Wed, 13 Oct 2021 15:58:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0126.hostedemail.com [216.40.44.126]) by kanga.kvack.org (Postfix) with ESMTP id 81E7A6B006C for ; Wed, 13 Oct 2021 15:58:00 -0400 (EDT) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 3C44A31EB2 for ; Wed, 13 Oct 2021 19:58:00 +0000 (UTC) X-FDA: 78692475120.07.EDB24FB Received: from mail-qt1-f172.google.com (mail-qt1-f172.google.com [209.85.160.172]) by imf13.hostedemail.com (Postfix) with ESMTP id 3F7F9103F80D for ; Wed, 13 Oct 2021 19:57:59 +0000 (UTC) Received: by mail-qt1-f172.google.com with SMTP id r17so3722149qtx.10 for ; Wed, 13 Oct 2021 12:57:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=k+BonliAPowDteyZoYp6dggycLLuWAlBJRnflFJEQYs=; b=OteN24zYQGdCBWBUvva9p/uxqvsPD4xBMRDCgqmLJXmAOareEtIZMtv/SuOkrKPre3 Jjjyl82NyDVM6Lv8sT1AWLw+dBK9tt3wBEYRtadefApyb/83xnozOxK0OkGcu6l0Ei9U +mx5MOlU2ec3h0i4iuJ8HAWcUwbZpN0cNjjzZpB7PdKpbppD4ykRmGgdB4sRye5qWFaf LRqQgmCD0GXDqZeGDh2yPUSERpkIad8PW0scOhZTYYIccVFY3BS1kI2ZJY88wpds4FMr O+EA6f8vb7PI0AIiuC/3dDXc4mG/oQfNwSieDEBb+vAX7ydcz823A0kTT1paNJabp256 +5Mg== 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=k+BonliAPowDteyZoYp6dggycLLuWAlBJRnflFJEQYs=; b=zThwYYcD7cA6MtQqFMvYsuzJYDIdemla6YI/xvRbUGG/3QNLtK1oUX42XtH7Xxvna6 GyURY/dPw2P/tfCp7F5viJl4nJi779067urpbOKFxQN/yiza4NZ49UMy+GjuAVa6s8lP tYrST56IywE3NqA+wQuFXyvfPzt6Lg2A5//TmuRbUmXpC/a/5noS3PKA9ESvTP1/3gM2 oRyuTVucdAN+VcaxNKqFnWC6lvYkeOrQK47t61JkB1GbFFkLP9ZFDWyNLXDEbc4mCCFo EK9AuNJ9oFIViEhKG/6eXiGF8qDzOM1QBrz+BJdJCHE9Fo+bHCLLNqw7h4piq1MnWj3/ mYZw== X-Gm-Message-State: AOAM533u+4SN+AXh1SFyaI8K9x4U58bK66jHhky9tewhT90k2VygQZ8A VsEIjyDQeIwWwbmFo8wOsKR5xg== X-Google-Smtp-Source: ABdhPJzYZGdj4hq/G8MSGkPG+Shb6zvY/ZX8F3yPhiaWCwiQ8cGru71Ht/OXceJbj7EgwZ5c4p4eHw== X-Received: by 2002:ac8:6112:: with SMTP id a18mr1519579qtm.401.1634155078959; Wed, 13 Oct 2021 12:57:58 -0700 (PDT) Received: from localhost (cpe-98-15-154-102.hvc.res.rr.com. [98.15.154.102]) by smtp.gmail.com with ESMTPSA id h2sm294792qkf.106.2021.10.13.12.57.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Oct 2021 12:57:58 -0700 (PDT) Date: Wed, 13 Oct 2021 15:57:57 -0400 From: Johannes Weiner To: Matthew Wilcox Cc: linux-mm@kvack.org, Kent Overstreet , "Kirill A. Shutemov" , Vlastimil Babka , Michal Hocko , Roman Gushchin , linux-kernel@vger.kernel.org, kernel-team@fb.com Subject: Re: [PATCH 00/11] PageSlab: eliminate unnecessary compound_head() calls Message-ID: References: <20211012180148.1669685-1-hannes@cmpxchg.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=cmpxchg-org.20210112.gappssmtp.com header.s=20210112 header.b=OteN24zY; spf=pass (imf13.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.160.172 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org; dmarc=pass (policy=none) header.from=cmpxchg.org X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 3F7F9103F80D X-Stat-Signature: irmy1sxn8jnmtefh334n9pw9gz1m54a1 X-HE-Tag: 1634155079-832462 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 Wed, Oct 13, 2021 at 03:33:00PM -0400, Johannes Weiner wrote: > On Wed, Oct 13, 2021 at 06:55:46PM +0100, Matthew Wilcox wrote: > > On Wed, Oct 13, 2021 at 09:49:31AM -0400, Johannes Weiner wrote: > > > On Wed, Oct 13, 2021 at 04:19:18AM +0100, Matthew Wilcox wrote: > > > > For today, testing PageSlab on the tail page helps the test proceed > > > > in parallel with the action. Looking at slub's kfree() for an example: > > > > > > > > page = virt_to_head_page(x); > > > > if (unlikely(!PageSlab(page))) { > > > > free_nonslab_page(page, object); > > > > return; > > > > } > > > > slab_free(page->slab_cache, page, object, NULL, 1, _RET_IP_); > > > > > > > > Your proposal is certainly an improvement (since gcc doesn't know > > > > that compound_head(compound_head(x)) == compound_head(x)), but I > > > > think checking on the tail page is even better: > > > > > > > > page = virt_to_page(x); > > > > if (unlikely(!PageSlab(page))) { > > > > free_nonslab_page(compound_head(page), object); > > > > return; > > > > } > > > > slab = page_slab(page); > > > > slab_free(slab->slab_cache, slab, object, NULL, 1, _RET_IP_); > > > > > > > > The compound_head() parts can proceed in parallel with the check of > > > > PageSlab(). > > > > > > > > As far as the cost of setting PageSlab, those cachelines are already > > > > dirty because we set compound_head on each of those pages already > > > > (or in the case of freeing, we're about to clear compound_head on > > > > each of those pages). > > > > > > ... but this is not. I think the performance gains from this would > > > have to be significant to justify complicating page flags further. > > > > My argument isn't really "this is more efficient", because I think > > the performance gains are pretty minimal. More that I would like to > > be able to write code in the style which we'll want to use when we're > > using dynamically allocated memory descriptors. It's all just code, > > and we can change it at any time, but better to change it to something > > that continues to work well in the future. > > > > I don't think we end up with "virt_to_head_page()" in a dynamically > > allocated memory descriptor world. The head page contains no different > > information from the tail pages, and indeed the tail pages don't know > > that they're tail pages, or where the head page is. Or maybe they're > > all tail pages. > > I agree with that, but future-provisioning is a tradeoff. > > It'll be trivial to replace virt_to_head_page() with virt_to_page() > and remove compound_head() calls when whatever is left of struct page > will unconditionally point to a memory descriptor. And that can be > part of the changes that make it so. I.e. remove all the *to_head() stuff when head/tail pages actually cease to be a thing, not earlier. Essentially, I think it's the right direction to pursue, but I'm not sure yet that it's exactly where we will end up. > > I could see a world where we had a virt_to_memdesc() which returned > > a generic memory descriptor that could be cast to a struct slab if > > the flags within that memdesc said it was a slab. But I think it works > > out better to tag the memory descriptor pointer with a discriminator > > that defines what the pointer is. Plus it saves a page flag. > > > > Maybe that's the best way to approach it -- how would you want to write > > this part of kfree() when memory descriptors are dynamically allocated? Yeah, or as Kent put it "how would you like the code to look like with infinite refactoring?" But that also implies we can do it in incremental, self-contained steps that each leave the code base in a better place than before. Which avoids building up dependencies on future code and unimplemented ideas that are vague, likely look different in everybody's head, or may not pan out at all.